-
Notifications
You must be signed in to change notification settings - Fork 0
/
pel-diff.el
143 lines (119 loc) · 5.12 KB
/
pel-diff.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
139
140
141
142
143
;;; pel-diff.el --- File diff utilities. -*- lexical-binding: t; -*-
;; Created : Friday, March 12 2021.
;; Author : Pierre Rouleau <[email protected]>
;; Time-stamp: <2024-01-05 18:40:23 EST, updated by Pierre Rouleau>
;; This file is part of the PEL package.
;; This file is not part of GNU Emacs.
;; Copyright (C) 2021, 2022, 2023, 2024 Pierre Rouleau
;;
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; --------------------------------------------------------------------------
;;; Commentary:
;;
;; This file provides utilities that speed up the use of Emacs EDiff library.
;;; --------------------------------------------------------------------------
;;; Dependencies:
;;
;;
(require 'pel--base) ; use: pel-current-buffer-filename
(require 'pel-window) ; use: pel-window-direction-for
;; ; pel-window-select
(require 'pel--keys-macros)
;;; --------------------------------------------------------------------------
;;; Code:
;;
;; Key setup - that would normally be placed in pel_keys.el
;; But in case of ediff it must be done here because the hook is
;; passed directly to the ediff commands.
(define-pel-global-prefix pel:for-ediff-mode (kbd "<f11> SPC SPC d e"))
(defun pel--setup-for-ediff-mode ()
"Activate ediff-mode setup, take local variables into account."
(pel-local-set-f12-M-f12 'pel:for-ediff-mode))
(declare-function pel--setup-for-ediff-mode "pel_keys")
(pel--mode-hook-maybe-call
(function pel--setup-for-ediff-mode)
'ediff-mode 'ediff-mode-hook)
;; ---------------------------------------------------------------------------
;;-pel-autoload
(defun pel-ediff-2files (&optional n)
"Run ediff-files on the files of current and other window.
If argument N is specified and in the [2,8] range it identifies
the window in the direction corresponding to the cursor numeric keypad:
- 8 := \\='up
- 4 := \\='left 5 := \\='current 6 := \\='right
- 2 := \\='down "
;; Note: ediff-files is available in Emacs -Q
(interactive "P")
(let ((fname-a (pel-current-buffer-filename))
(fname-b (save-excursion
(pel-window-select
(pel-window-direction-for
(abs (prefix-numeric-value n))
'other))
(pel-current-buffer-filename))))
(ediff-files fname-a fname-b
(list (function pel--setup-for-ediff-mode)))))
;;-pel-autoload
(defun pel-ediff-revision ()
"Run ediff-revision for current file against its last commit version."
;; Note: ediff-revision is available in Emacs -Q
(interactive)
(ediff-revision (pel-current-buffer-filename)
(list (function pel--setup-for-ediff-mode))))
;;-pel-autoload
(defun pel-diff-show-status ()
"Display diff-mode status information."
(interactive)
(message "diff-jump-to-old-file: %s => operate on %s file."
(pel-symbol-on-off-string
'diff-jump-to-old-file nil nil "not loaded")
(if (bound-and-true-p diff-jump-to-old-file)
"OLD"
"new")))
;; ---------------------------------------------------------------------------
;;-pel-autoload
(defun pel-diff-hunk-files-occur (&optional nlines)
"Show hunk files of current path patch inside an occur buffer.
Each line is displayed with NLINES before and after, or -NLINES
before if NLINES is negative.
NLINES defaults to 0 regardless of the current value of
`list-matching-lines-default-context-lines'.
If a region is defined the search is restricted to the region."
(interactive "^P")
(let* ((list-matching-lines-default-context-lines 0)
(boundary (when (use-region-p)
(region-bounds)))
(has-index (save-excursion
(goto-char (point-min))
(re-search-forward "^Index: " boundary :noerror))))
(occur (if has-index
"^Index: "
"^\\+\\+\\+ ")
(or nlines 0)
boundary)))
;; ---------------------------------------------------------------------------
(declare-function diff-ignore-whitespace-hunk "diff-mode")
;;-pel-autoload
(defun pel-diff-ignore-whitespace-in-hunks ()
"Re-diff all hunks, ignoring whitespace differences in all."
(interactive)
(require 'diff-mode)
(save-excursion
(goto-char (point-min))
(while (not (eobp))
(progn
(call-interactively (function diff-ignore-whitespace-hunk))))))
;;; --------------------------------------------------------------------------
(provide 'pel-diff)
;;; pel-diff.el ends here