-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathdiff-setting.el
138 lines (133 loc) · 4.81 KB
/
diff-setting.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
;; -*- coding: utf-8 -*-
;; File: diff-setting.el
;;
;; Author: Denny(https://www.dennyzhang.com/contact)
;;
;; Copyright 2020, https://DennyZhang.com
;; Created:2012-04-22
;; Updated: Time-stamp: <2020-02-03 15:37:48>
;; --8<-------------------------- separator ------------------------>8--
;; compare vertically in ediff
(require 'ediff)
(setq ediff-split-window-function 'split-window-horizontally)
(setq ediff-merge-split-window-function 'split-window-horizontally)
;; do everything in one frame, instead of multiframe
(setq ediff-window-setup-function (quote ediff-setup-windows-plain))
;; when comparing, ignore all white space, and output the unified context
(setq diff-switches "-u -w")
(setq diff-default-read-only t)
;; set face coloring
(eval-after-load 'diff-mode
'(progn
(set-face-foreground 'diff-added "green4")
(set-face-foreground 'diff-removed "red3")))
;; --8<-------------------------- separator ------------------------>8--
;;(add-to-list 'load-path (concat CONF-EMACS-VENDOR "/magit"))
;;(require 'magit)
;;(eval-after-load 'magit
;; '(progn
;; (autoload 'mo-git-blame-file "mo-git-blame" nil t)
;; (autoload 'mo-git-blame-current "mo-git-blame" nil t)
;; (setq magit-diff-options "-w") ;; when comparing, ignore all white space
;; ))
;; set face coloring
(eval-after-load 'magit
'(progn
(custom-set-faces
'(magit-diff-add
((t (:foreground "lime green"))))
'(magit-diff-del
((t (:foreground "tomato"))))
;; '(magit-item-highlight ((t (:background "gray25"))))
'(magit-log-head-label-patches
((t (:background "DarkGoldenrod1" :foreground "DarkOrange4" :box 1))))
'(magit-log-tag-label
((t (:background "blue violet")))))
))
(eval-after-load 'magit
'(progn
(set-face-foreground 'magit-diff-add "green3")
(set-face-foreground 'magit-diff-del "red3")
(when (not window-system)
(set-face-background 'magit-item-highlight "white"))))
(defun git-commit-changes ()
(start-process "*git commit*" nil "git" "commit" "-a" "-m" "changes"))
;; TODO
;; when diff-mode, set buffers readonly
;;(add-hook 'diff-mode-hook (lambda () (view-mode)))
;;(define-key view-mode-map "j" 'ido-dired)
;;(define-key view-mode-map "n" 'scroll-up-command)
;;(define-key view-mode-map "p" 'scroll-down-command)
;; --8<-------------------------- separator ------------------------>8--
(defun ediff-sequent-lines ()
"Compare two sequent lines in the same buffer, by calling ediff-regions-internal"
(interactive)
(let ((fc (current-frame-configuration)))
(eval
`(defun rfc ()
(set-frame-configuration ',fc)
(remove-hook 'ediff-after-quit-hook-internal 'rfc)))
(add-hook 'ediff-after-quit-hook-internal 'rfc)
(ediff-regions-internal
(current-buffer) (line-beginning-position) (line-end-position)
(current-buffer) (line-beginning-position 2) (line-end-position 2)
nil 'ediff-windows-wordwise 'word-mode nil)))
;; --8<-------------------------- separator ------------------------>8--
(defun keep-mine ()
(interactive)
(beginning-of-line)
(assert (or (looking-at "<<<<<<")
(re-search-backward "^<<<<<<" nil t)
(re-search-forward "^<<<<<<" nil t)))
(goto-char (match-beginning 0))
(let ((beg (point))
(hashes (re-search-forward "^#######" (+ (point) 10000) t)))
(forward-line)
(delete-region beg (point))
(re-search-forward (if hashes "^>>>>>>>" "^======="))
(setq beg (match-beginning 0))
(re-search-forward (if hashes "^=======" "^>>>>>>>"))
(forward-line)
(delete-region beg (point))))
(defun keep-theirs ()
(interactive)
(beginning-of-line)
(assert (or (looking-at "<<<<<<")
(re-search-backward "^<<<<<<" nil t)
(re-search-forward "^<<<<<<" nil t)))
(goto-char (match-beginning 0))
(let ((beg (point))
(hashes (re-search-forward "^#######" (+ (point) 10000) t)))
(re-search-forward (if hashes "^>>>>>>>" "^======="))
(forward-line)
(delete-region beg (point))
(re-search-forward (if hashes "^#######" "^>>>>>>>"))
(beginning-of-line)
(setq beg (point))
(when hashes
(re-search-forward "^=======")
(beginning-of-line))
(forward-line)
(delete-region beg (point))))
(defun keep-both ()
(interactive)
(beginning-of-line)
(assert (or (looking-at "<<<<<<")
(re-search-backward "^<<<<<<" nil t)
(re-search-forward "^<<<<<<" nil t)))
(beginning-of-line)
(let ((beg (point)))
(forward-line)
(delete-region beg (point))
(re-search-forward "^>>>>>>>")
(beginning-of-line)
(setq beg (point))
(forward-line)
(delete-region beg (point))
(re-search-forward "^#######")
(beginning-of-line)
(setq beg (point))
(re-search-forward "^=======")
(beginning-of-line)
(forward-line)
(delete-region beg (point))))