diff options
| author | Stefan Monnier | 2018-02-18 00:47:00 -0500 |
|---|---|---|
| committer | Stefan Monnier | 2018-02-18 00:47:00 -0500 |
| commit | 066e633cb6dacb846c0ac070c8d7d77985af8620 (patch) | |
| tree | d9d1c8c10c71dbfb4532f83e4f2a1fab6ae0e333 | |
| parent | eb3337cdb32c8cd3213738b94df5bc4f0dfd40f2 (diff) | |
| download | emacs-066e633cb6dacb846c0ac070c8d7d77985af8620.tar.gz emacs-066e633cb6dacb846c0ac070c8d7d77985af8620.zip | |
* lisp/vc/diff-mode.el (diff-wiggle): New command.
| -rw-r--r-- | lisp/vc/diff-mode.el | 80 |
1 files changed, 64 insertions, 16 deletions
diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el index 7db5ca9b259..ef13f55b931 100644 --- a/lisp/vc/diff-mode.el +++ b/lisp/vc/diff-mode.el | |||
| @@ -891,7 +891,7 @@ PREFIX is only used internally: don't use it." | |||
| 891 | (if (and newfile (file-exists-p newfile)) (cl-return newfile)))) | 891 | (if (and newfile (file-exists-p newfile)) (cl-return newfile)))) |
| 892 | ;; look for each file in turn. If none found, try again but | 892 | ;; look for each file in turn. If none found, try again but |
| 893 | ;; ignoring the first level of directory, ... | 893 | ;; ignoring the first level of directory, ... |
| 894 | (cl-do* ((files fs (delq nil (mapcar 'diff-filename-drop-dir files))) | 894 | (cl-do* ((files fs (delq nil (mapcar #'diff-filename-drop-dir files))) |
| 895 | (file nil nil)) | 895 | (file nil nil)) |
| 896 | ((or (null files) | 896 | ((or (null files) |
| 897 | (setq file (cl-do* ((files files (cdr files)) | 897 | (setq file (cl-do* ((files files (cdr files)) |
| @@ -1387,12 +1387,12 @@ a diff with \\[diff-reverse-direction]. | |||
| 1387 | ;; (set (make-local-variable 'paragraph-separate) paragraph-start) | 1387 | ;; (set (make-local-variable 'paragraph-separate) paragraph-start) |
| 1388 | ;; (set (make-local-variable 'page-delimiter) "--- [^\t]+\t") | 1388 | ;; (set (make-local-variable 'page-delimiter) "--- [^\t]+\t") |
| 1389 | ;; compile support | 1389 | ;; compile support |
| 1390 | (set (make-local-variable 'next-error-function) 'diff-next-error) | 1390 | (set (make-local-variable 'next-error-function) #'diff-next-error) |
| 1391 | 1391 | ||
| 1392 | (set (make-local-variable 'beginning-of-defun-function) | 1392 | (set (make-local-variable 'beginning-of-defun-function) |
| 1393 | 'diff-beginning-of-file-and-junk) | 1393 | #'diff-beginning-of-file-and-junk) |
| 1394 | (set (make-local-variable 'end-of-defun-function) | 1394 | (set (make-local-variable 'end-of-defun-function) |
| 1395 | 'diff-end-of-file) | 1395 | #'diff-end-of-file) |
| 1396 | 1396 | ||
| 1397 | (diff-setup-whitespace) | 1397 | (diff-setup-whitespace) |
| 1398 | 1398 | ||
| @@ -1400,10 +1400,10 @@ a diff with \\[diff-reverse-direction]. | |||
| 1400 | (setq buffer-read-only t)) | 1400 | (setq buffer-read-only t)) |
| 1401 | ;; setup change hooks | 1401 | ;; setup change hooks |
| 1402 | (if (not diff-update-on-the-fly) | 1402 | (if (not diff-update-on-the-fly) |
| 1403 | (add-hook 'write-contents-functions 'diff-write-contents-hooks nil t) | 1403 | (add-hook 'write-contents-functions #'diff-write-contents-hooks nil t) |
| 1404 | (make-local-variable 'diff-unhandled-changes) | 1404 | (make-local-variable 'diff-unhandled-changes) |
| 1405 | (add-hook 'after-change-functions 'diff-after-change-function nil t) | 1405 | (add-hook 'after-change-functions #'diff-after-change-function nil t) |
| 1406 | (add-hook 'post-command-hook 'diff-post-command-hook nil t)) | 1406 | (add-hook 'post-command-hook #'diff-post-command-hook nil t)) |
| 1407 | ;; Neat trick from Dave Love to add more bindings in read-only mode: | 1407 | ;; Neat trick from Dave Love to add more bindings in read-only mode: |
| 1408 | (let ((ro-bind (cons 'buffer-read-only diff-mode-shared-map))) | 1408 | (let ((ro-bind (cons 'buffer-read-only diff-mode-shared-map))) |
| 1409 | (add-to-list 'minor-mode-overriding-map-alist ro-bind) | 1409 | (add-to-list 'minor-mode-overriding-map-alist ro-bind) |
| @@ -1415,7 +1415,7 @@ a diff with \\[diff-reverse-direction]. | |||
| 1415 | nil t)) | 1415 | nil t)) |
| 1416 | ;; add-log support | 1416 | ;; add-log support |
| 1417 | (set (make-local-variable 'add-log-current-defun-function) | 1417 | (set (make-local-variable 'add-log-current-defun-function) |
| 1418 | 'diff-current-defun) | 1418 | #'diff-current-defun) |
| 1419 | (set (make-local-variable 'add-log-buffer-file-name-function) | 1419 | (set (make-local-variable 'add-log-buffer-file-name-function) |
| 1420 | (lambda () (diff-find-file-name nil 'noprompt))) | 1420 | (lambda () (diff-find-file-name nil 'noprompt))) |
| 1421 | (unless (buffer-file-name) | 1421 | (unless (buffer-file-name) |
| @@ -1433,10 +1433,10 @@ the mode if ARG is omitted or nil. | |||
| 1433 | ;; FIXME: setup font-lock | 1433 | ;; FIXME: setup font-lock |
| 1434 | ;; setup change hooks | 1434 | ;; setup change hooks |
| 1435 | (if (not diff-update-on-the-fly) | 1435 | (if (not diff-update-on-the-fly) |
| 1436 | (add-hook 'write-contents-functions 'diff-write-contents-hooks nil t) | 1436 | (add-hook 'write-contents-functions #'diff-write-contents-hooks nil t) |
| 1437 | (make-local-variable 'diff-unhandled-changes) | 1437 | (make-local-variable 'diff-unhandled-changes) |
| 1438 | (add-hook 'after-change-functions 'diff-after-change-function nil t) | 1438 | (add-hook 'after-change-functions #'diff-after-change-function nil t) |
| 1439 | (add-hook 'post-command-hook 'diff-post-command-hook nil t))) | 1439 | (add-hook 'post-command-hook #'diff-post-command-hook nil t))) |
| 1440 | 1440 | ||
| 1441 | ;;; Handy hook functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 1441 | ;;; Handy hook functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 1442 | 1442 | ||
| @@ -1468,7 +1468,7 @@ modified lines of the diff." | |||
| 1468 | 1468 | ||
| 1469 | (defun diff-delete-empty-files () | 1469 | (defun diff-delete-empty-files () |
| 1470 | "Arrange for empty diff files to be removed." | 1470 | "Arrange for empty diff files to be removed." |
| 1471 | (add-hook 'after-save-hook 'diff-delete-if-empty nil t)) | 1471 | (add-hook 'after-save-hook #'diff-delete-if-empty nil t)) |
| 1472 | 1472 | ||
| 1473 | (defun diff-make-unified () | 1473 | (defun diff-make-unified () |
| 1474 | "Turn context diffs into unified diffs if applicable." | 1474 | "Turn context diffs into unified diffs if applicable." |
| @@ -1693,7 +1693,7 @@ If TEXT isn't found, nil is returned." | |||
| 1693 | Whitespace differences are ignored." | 1693 | Whitespace differences are ignored." |
| 1694 | (let* ((orig (point)) | 1694 | (let* ((orig (point)) |
| 1695 | (re (concat "^[ \t\n]*" | 1695 | (re (concat "^[ \t\n]*" |
| 1696 | (mapconcat 'regexp-quote (split-string text) "[ \t\n]+") | 1696 | (mapconcat #'regexp-quote (split-string text) "[ \t\n]+") |
| 1697 | "[ \t\n]*\n")) | 1697 | "[ \t\n]*\n")) |
| 1698 | (forw (and (re-search-forward re nil t) | 1698 | (forw (and (re-search-forward re nil t) |
| 1699 | (cons (match-beginning 0) (match-end 0)))) | 1699 | (cons (match-beginning 0) (match-end 0)))) |
| @@ -2047,7 +2047,7 @@ Return new point, if it was moved." | |||
| 2047 | (progn (diff--forward-while-leading-char ?\\ end) | 2047 | (progn (diff--forward-while-leading-char ?\\ end) |
| 2048 | (setq end-add (point)))) | 2048 | (setq end-add (point)))) |
| 2049 | (smerge-refine-regions beg-del beg-add beg-add end-add | 2049 | (smerge-refine-regions beg-del beg-add beg-add end-add |
| 2050 | nil 'diff-refine-preproc props-r props-a))))) | 2050 | nil #'diff-refine-preproc props-r props-a))))) |
| 2051 | (`context | 2051 | (`context |
| 2052 | (let* ((middle (save-excursion (re-search-forward "^---"))) | 2052 | (let* ((middle (save-excursion (re-search-forward "^---"))) |
| 2053 | (other middle)) | 2053 | (other middle)) |
| @@ -2060,7 +2060,7 @@ Return new point, if it was moved." | |||
| 2060 | (match-beginning 0)) | 2060 | (match-beginning 0)) |
| 2061 | other | 2061 | other |
| 2062 | (if diff-use-changed-face props-c) | 2062 | (if diff-use-changed-face props-c) |
| 2063 | 'diff-refine-preproc | 2063 | #'diff-refine-preproc |
| 2064 | (unless diff-use-changed-face props-r) | 2064 | (unless diff-use-changed-face props-r) |
| 2065 | (unless diff-use-changed-face props-a))))) | 2065 | (unless diff-use-changed-face props-a))))) |
| 2066 | (_ ;; Normal diffs. | 2066 | (_ ;; Normal diffs. |
| @@ -2069,7 +2069,7 @@ Return new point, if it was moved." | |||
| 2069 | ;; It's a combined add&remove, so there's something to do. | 2069 | ;; It's a combined add&remove, so there's something to do. |
| 2070 | (smerge-refine-regions beg1 (match-beginning 0) | 2070 | (smerge-refine-regions beg1 (match-beginning 0) |
| 2071 | (match-end 0) end | 2071 | (match-end 0) end |
| 2072 | nil 'diff-refine-preproc props-r props-a))))))))) | 2072 | nil #'diff-refine-preproc props-r props-a))))))))) |
| 2073 | 2073 | ||
| 2074 | (defun diff-undo (&optional arg) | 2074 | (defun diff-undo (&optional arg) |
| 2075 | "Perform `undo', ignoring the buffer's read-only status." | 2075 | "Perform `undo', ignoring the buffer's read-only status." |
| @@ -2175,6 +2175,54 @@ fixed, visit it in a buffer." | |||
| 2175 | modified-buffers ", ")) | 2175 | modified-buffers ", ")) |
| 2176 | (message "No trailing whitespace to delete."))))) | 2176 | (message "No trailing whitespace to delete."))))) |
| 2177 | 2177 | ||
| 2178 | ;;; Support for converting a diff to diff3 markers via `wiggle'. | ||
| 2179 | |||
| 2180 | ;; Wiggle can be found at http://neil.brown.name/wiggle/ or in your nearest | ||
| 2181 | ;; Debian repository. | ||
| 2182 | |||
| 2183 | (defun diff-wiggle () | ||
| 2184 | "Use `wiggle' to apply the whole current file diff by hook or by crook. | ||
| 2185 | When a hunk can't cleanly be applied, it gets turned into a diff3-style | ||
| 2186 | conflict." | ||
| 2187 | (interactive) | ||
| 2188 | (let* ((bounds (diff-bounds-of-file)) | ||
| 2189 | (file (diff-find-file-name)) | ||
| 2190 | (tmpbuf (current-buffer)) | ||
| 2191 | (filebuf (find-buffer-visiting file)) | ||
| 2192 | (patchfile (make-temp-file | ||
| 2193 | (expand-file-name "wiggle" (file-name-directory file)) | ||
| 2194 | nil ".diff")) | ||
| 2195 | (errfile (make-temp-file | ||
| 2196 | (expand-file-name "wiggle" (file-name-directory file)) | ||
| 2197 | nil ".error"))) | ||
| 2198 | (unwind-protect | ||
| 2199 | (with-temp-buffer | ||
| 2200 | (set-buffer (prog1 tmpbuf (setq tmpbuf (current-buffer)))) | ||
| 2201 | (when (buffer-modified-p filebuf) | ||
| 2202 | (save-some-buffers nil (lambda () (eq (current-buffer) filebuf))) | ||
| 2203 | (if (buffer-modified-p filebuf) (error "Abort!"))) | ||
| 2204 | (write-region (car bounds) (cadr bounds) patchfile nil 'silent) | ||
| 2205 | (let ((exitcode | ||
| 2206 | (call-process "wiggle" nil (list tmpbuf errfile) nil | ||
| 2207 | file patchfile))) | ||
| 2208 | (if (not (memq exitcode '(0 1))) | ||
| 2209 | (message "diff-wiggle error: %s" | ||
| 2210 | (with-current-buffer tmpbuf | ||
| 2211 | (goto-char (point-min)) | ||
| 2212 | (insert-file-contents errfile) | ||
| 2213 | (buffer-string))) | ||
| 2214 | (with-current-buffer tmpbuf | ||
| 2215 | (write-region nil nil file nil 'silent) | ||
| 2216 | (with-current-buffer filebuf | ||
| 2217 | (revert-buffer t t t) | ||
| 2218 | (save-excursion | ||
| 2219 | (goto-char (point-min)) | ||
| 2220 | (if (re-search-forward "^<<<<<<<" nil t) | ||
| 2221 | (smerge-mode 1))) | ||
| 2222 | (pop-to-buffer filebuf)))))) | ||
| 2223 | (delete-file patchfile) | ||
| 2224 | (delete-file errfile)))) | ||
| 2225 | |||
| 2178 | ;; provide the package | 2226 | ;; provide the package |
| 2179 | (provide 'diff-mode) | 2227 | (provide 'diff-mode) |
| 2180 | 2228 | ||