|
36 | 36 |
|
37 | 37 | ;;; Code: |
38 | 38 |
|
39 | | -(require 'diff-hl-show-hunk-inline) |
40 | 39 | (require 'diff-hl) |
41 | 40 |
|
42 | 41 | (defvar diff-hl-show-hunk-mouse-mode-map |
|
73 | 72 | (defconst diff-hl-show-hunk-boundary "^@@.*@@") |
74 | 73 | (defconst diff-hl-show-hunk--no-lines-removed-message (list "<<no lines removed>>")) |
75 | 74 |
|
76 | | -(defcustom diff-hl-show-hunk-inline-hide-hunk nil |
77 | | - "If t, inline-popup is shown over the hunk, hiding it." |
78 | | - :type 'boolean) |
79 | | - |
80 | | -(defcustom diff-hl-show-hunk-inline-smart-lines t |
81 | | - "If t, inline-popup tries to show only the deleted lines of the |
82 | | -hunk. The added lines are shown when scrolling the popup. If |
83 | | -the hunk consist only on added lines, then |
84 | | -`diff-hl-show-hunk--no-lines-removed-message' it is shown." |
85 | | - :type 'boolean) |
86 | | - |
87 | 75 | (defcustom diff-hl-show-hunk-function 'diff-hl-show-hunk-inline |
88 | 76 | "The function used to render the hunk. |
89 | 77 | The function receives as first parameter a buffer with the |
@@ -226,70 +214,6 @@ Returns a list with the buffer and the line number of the clicked line." |
226 | 214 | (define-key map (kbd "S") #'diff-hl-show-hunk-stage-hunk) |
227 | 215 | map)) |
228 | 216 |
|
229 | | -(defvar diff-hl-show-hunk--hide-function) |
230 | | - |
231 | | -;;;###autoload |
232 | | -(defun diff-hl-show-hunk-inline (buffer &optional _ignored-line) |
233 | | - "Implementation to show the hunk in a inline popup. |
234 | | -BUFFER is a buffer with the hunk." |
235 | | - ;; prevent diff-hl-inline-popup-hide from being called twice |
236 | | - (let ((diff-hl-inline-popup--close-hook nil)) |
237 | | - (diff-hl-inline-popup-hide)) |
238 | | - (setq diff-hl-show-hunk--hide-function #'diff-hl-inline-popup-hide) |
239 | | - (let* ((lines (split-string (with-current-buffer buffer (buffer-string)) "[\n\r]+" )) |
240 | | - (smart-lines diff-hl-show-hunk-inline-smart-lines) |
241 | | - (original-lines-number (cl-count-if (lambda (s) (string-prefix-p "-" s)) lines)) |
242 | | - (lines (if (string= (car (last lines)) "" ) (butlast lines) lines)) |
243 | | - (lines (if (and (eq original-lines-number 0) smart-lines) |
244 | | - diff-hl-show-hunk--no-lines-removed-message |
245 | | - lines)) |
246 | | - (overlay diff-hl-show-hunk--original-overlay) |
247 | | - (type (overlay-get overlay 'diff-hl-hunk-type)) |
248 | | - (point (if (eq type 'delete) (overlay-start overlay) (overlay-end overlay))) |
249 | | - (propertize-line (lambda (l) |
250 | | - (propertize l 'face |
251 | | - (cond ((string-prefix-p "+" l) |
252 | | - 'diff-added) |
253 | | - ((string-prefix-p "-" l) |
254 | | - 'diff-removed))))) |
255 | | - (propertized-lines (mapcar propertize-line lines))) |
256 | | - |
257 | | - (save-excursion |
258 | | - ;; Save point in case the hunk is hidden, so next/previous works as expected |
259 | | - ;; If the hunk is delete type, then don't hide the hunk |
260 | | - ;; (because the hunk is located in a non deleted line) |
261 | | - (when (and diff-hl-show-hunk-inline-hide-hunk |
262 | | - (not (eq type 'delete))) |
263 | | - (let* ((invisible-overlay (make-overlay (overlay-start overlay) |
264 | | - (overlay-end overlay)))) |
265 | | - ;; Make new overlay, since the diff-hl overlay can be changed by diff-hl-flydiff |
266 | | - (overlay-put invisible-overlay 'invisible t) |
267 | | - ;; Change default hide popup function, to make the overlay visible |
268 | | - (setq diff-hl-show-hunk--hide-function |
269 | | - (lambda () |
270 | | - (overlay-put invisible-overlay 'invisible nil) |
271 | | - (delete-overlay invisible-overlay) |
272 | | - (diff-hl-show-hunk-inline-hide))))) |
273 | | - (diff-hl-show-hunk--goto-hunk-overlay overlay) |
274 | | - (let ((height |
275 | | - (when smart-lines |
276 | | - (when (not (eq 0 original-lines-number)) |
277 | | - original-lines-number))) |
278 | | - (footer "(q)Quit (p)Previous (n)Next (r)Revert (c)Copy original")) |
279 | | - (unless diff-hl-show-staged-changes |
280 | | - (setq footer (concat footer " (S)Stage"))) |
281 | | - (diff-hl-show-hunk-inline-show |
282 | | - propertized-lines |
283 | | - (if (and (boundp 'diff-hl-reference-revision) diff-hl-reference-revision) |
284 | | - (concat "Diff with " diff-hl-reference-revision) |
285 | | - "Diff with HEAD") |
286 | | - footer |
287 | | - diff-hl-show-hunk-map |
288 | | - #'diff-hl-show-hunk-hide |
289 | | - point |
290 | | - height)) |
291 | | - ))) |
292 | | - |
293 | 217 | (defun diff-hl-show-hunk-copy-original-text () |
294 | 218 | "Extracts all the lines from BUFFER starting with '-' to the kill ring." |
295 | 219 | (interactive) |
|
0 commit comments