diff options
| author | Stefan Monnier | 2008-09-14 21:16:30 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2008-09-14 21:16:30 +0000 |
| commit | 68035b97640be3248dd931e8853e20d642b40bd4 (patch) | |
| tree | 17148de5a81041e14194caae9d73f858c7b4d1b0 /lisp/diff-mode.el | |
| parent | aa5fecb5371e152777e8addcc1e2a7f8d7ae5954 (diff) | |
| download | emacs-68035b97640be3248dd931e8853e20d642b40bd4.tar.gz emacs-68035b97640be3248dd931e8853e20d642b40bd4.zip | |
(diff-find-file-name): Rename `batch' to `noprompt' and
be more honest when we don't know.
(diff-tell-file-name): Don't prompt before the actual prompt.
(diff-mode): Don't prompt in add-log-buffer-file-name-function.
(diff-find-source-location): Add `noprompt' argument.
(diff-current-defun): Don't prompt.
Diffstat (limited to 'lisp/diff-mode.el')
| -rw-r--r-- | lisp/diff-mode.el | 76 |
1 files changed, 40 insertions, 36 deletions
diff --git a/lisp/diff-mode.el b/lisp/diff-mode.el index a32047e70f7..b711b0635d6 100644 --- a/lisp/diff-mode.el +++ b/lisp/diff-mode.el | |||
| @@ -723,7 +723,7 @@ If the OLD prefix arg is passed, tell the file NAME of the old file." | |||
| 723 | (fs (diff-hunk-file-names current-prefix-arg))) | 723 | (fs (diff-hunk-file-names current-prefix-arg))) |
| 724 | (unless fs (error "No file name to look for")) | 724 | (unless fs (error "No file name to look for")) |
| 725 | (list old (read-file-name (format "File for %s: " (car fs)) | 725 | (list old (read-file-name (format "File for %s: " (car fs)) |
| 726 | nil (diff-find-file-name old) t)))) | 726 | nil (diff-find-file-name old 'noprompt) t)))) |
| 727 | (let ((fs (diff-hunk-file-names old))) | 727 | (let ((fs (diff-hunk-file-names old))) |
| 728 | (unless fs (error "No file name to look for")) | 728 | (unless fs (error "No file name to look for")) |
| 729 | (push (cons fs name) diff-remembered-files-alist))) | 729 | (push (cons fs name) diff-remembered-files-alist))) |
| @@ -756,11 +756,10 @@ If the OLD prefix arg is passed, tell the file NAME of the old file." | |||
| 756 | (list (if old (match-string 2) (match-string 4)) | 756 | (list (if old (match-string 2) (match-string 4)) |
| 757 | (if old (match-string 4) (match-string 2))))))))) | 757 | (if old (match-string 4) (match-string 2))))))))) |
| 758 | 758 | ||
| 759 | (defun diff-find-file-name (&optional old batch prefix) | 759 | (defun diff-find-file-name (&optional old noprompt prefix) |
| 760 | "Return the file corresponding to the current patch. | 760 | "Return the file corresponding to the current patch. |
| 761 | Non-nil OLD means that we want the old file. | 761 | Non-nil OLD means that we want the old file. |
| 762 | Non-nil BATCH means to prefer returning an incorrect answer than to prompt | 762 | Non-nil NOPROMPT means to prefer returning nil than to prompt the user. |
| 763 | the user. | ||
| 764 | PREFIX is only used internally: don't use it." | 763 | PREFIX is only used internally: don't use it." |
| 765 | (unless (equal diff-remembered-defdir default-directory) | 764 | (unless (equal diff-remembered-defdir default-directory) |
| 766 | ;; Flush diff-remembered-files-alist if the default-directory is changed. | 765 | ;; Flush diff-remembered-files-alist if the default-directory is changed. |
| @@ -801,16 +800,15 @@ PREFIX is only used internally: don't use it." | |||
| 801 | (boundp 'cvs-pcl-cvs-dirchange-re) | 800 | (boundp 'cvs-pcl-cvs-dirchange-re) |
| 802 | (save-excursion | 801 | (save-excursion |
| 803 | (re-search-backward cvs-pcl-cvs-dirchange-re nil t)) | 802 | (re-search-backward cvs-pcl-cvs-dirchange-re nil t)) |
| 804 | (diff-find-file-name old batch (match-string 1))) | 803 | (diff-find-file-name old noprompt (match-string 1))) |
| 805 | ;; Invent something, if necessary. | ||
| 806 | (when batch | ||
| 807 | (or (car fs) default-directory)) | ||
| 808 | ;; if all else fails, ask the user | 804 | ;; if all else fails, ask the user |
| 809 | (let ((file (read-file-name (format "Use file %s: " (or (first fs) "")) | 805 | (unless noprompt |
| 810 | nil (first fs) t (first fs)))) | 806 | (let ((file (read-file-name (format "Use file %s: " |
| 811 | (set (make-local-variable 'diff-remembered-files-alist) | 807 | (or (first fs) "")) |
| 812 | (cons (cons fs file) diff-remembered-files-alist)) | 808 | nil (first fs) t (first fs)))) |
| 813 | file))))) | 809 | (set (make-local-variable 'diff-remembered-files-alist) |
| 810 | (cons (cons fs file) diff-remembered-files-alist)) | ||
| 811 | file)))))) | ||
| 814 | 812 | ||
| 815 | 813 | ||
| 816 | (defun diff-ediff-patch () | 814 | (defun diff-ediff-patch () |
| @@ -1286,7 +1284,7 @@ a diff with \\[diff-reverse-direction]. | |||
| 1286 | (set (make-local-variable 'add-log-current-defun-function) | 1284 | (set (make-local-variable 'add-log-current-defun-function) |
| 1287 | 'diff-current-defun) | 1285 | 'diff-current-defun) |
| 1288 | (set (make-local-variable 'add-log-buffer-file-name-function) | 1286 | (set (make-local-variable 'add-log-buffer-file-name-function) |
| 1289 | 'diff-find-file-name)) | 1287 | (lambda () (diff-find-file-name nil 'noprompt)))) |
| 1290 | 1288 | ||
| 1291 | ;;;###autoload | 1289 | ;;;###autoload |
| 1292 | (define-minor-mode diff-minor-mode | 1290 | (define-minor-mode diff-minor-mode |
| @@ -1547,7 +1545,7 @@ Whitespace differences are ignored." | |||
| 1547 | 1545 | ||
| 1548 | (defsubst diff-xor (a b) (if a (if (not b) a) b)) | 1546 | (defsubst diff-xor (a b) (if a (if (not b) a) b)) |
| 1549 | 1547 | ||
| 1550 | (defun diff-find-source-location (&optional other-file reverse) | 1548 | (defun diff-find-source-location (&optional other-file reverse noprompt) |
| 1551 | "Find out (BUF LINE-OFFSET POS SRC DST SWITCHED). | 1549 | "Find out (BUF LINE-OFFSET POS SRC DST SWITCHED). |
| 1552 | BUF is the buffer corresponding to the source file. | 1550 | BUF is the buffer corresponding to the source file. |
| 1553 | LINE-OFFSET is the offset between the expected and actual positions | 1551 | LINE-OFFSET is the offset between the expected and actual positions |
| @@ -1555,7 +1553,8 @@ LINE-OFFSET is the offset between the expected and actual positions | |||
| 1555 | POS is a pair (BEG . END) indicating the position of the text in the buffer. | 1553 | POS is a pair (BEG . END) indicating the position of the text in the buffer. |
| 1556 | SRC and DST are the two variants of text as returned by `diff-hunk-text'. | 1554 | SRC and DST are the two variants of text as returned by `diff-hunk-text'. |
| 1557 | SRC is the variant that was found in the buffer. | 1555 | SRC is the variant that was found in the buffer. |
| 1558 | SWITCHED is non-nil if the patch is already applied." | 1556 | SWITCHED is non-nil if the patch is already applied. |
| 1557 | NOPROMPT, if non-nil, means not to prompt the user." | ||
| 1559 | (save-excursion | 1558 | (save-excursion |
| 1560 | (let* ((other (diff-xor other-file diff-jump-to-old-file)) | 1559 | (let* ((other (diff-xor other-file diff-jump-to-old-file)) |
| 1561 | (char-offset (- (point) (progn (diff-beginning-of-hunk 'try-harder) | 1560 | (char-offset (- (point) (progn (diff-beginning-of-hunk 'try-harder) |
| @@ -1565,8 +1564,8 @@ SWITCHED is non-nil if the patch is already applied." | |||
| 1565 | ;; (e.g. because an empty line truncates the hunk mid-course), | 1564 | ;; (e.g. because an empty line truncates the hunk mid-course), |
| 1566 | ;; leading to potentially nasty surprises for the user. | 1565 | ;; leading to potentially nasty surprises for the user. |
| 1567 | (_ (diff-sanity-check-hunk)) | 1566 | (_ (diff-sanity-check-hunk)) |
| 1568 | (hunk (buffer-substring (point) | 1567 | (hunk (buffer-substring |
| 1569 | (save-excursion (diff-end-of-hunk) (point)))) | 1568 | (point) (save-excursion (diff-end-of-hunk) (point)))) |
| 1570 | (old (diff-hunk-text hunk reverse char-offset)) | 1569 | (old (diff-hunk-text hunk reverse char-offset)) |
| 1571 | (new (diff-hunk-text hunk (not reverse) char-offset)) | 1570 | (new (diff-hunk-text hunk (not reverse) char-offset)) |
| 1572 | ;; Find the location specification. | 1571 | ;; Find the location specification. |
| @@ -1578,7 +1577,8 @@ SWITCHED is non-nil if the patch is already applied." | |||
| 1578 | diff-context-mid-hunk-header-re nil t) | 1577 | diff-context-mid-hunk-header-re nil t) |
| 1579 | (error "Can't find the hunk separator")) | 1578 | (error "Can't find the hunk separator")) |
| 1580 | (match-string 1))))) | 1579 | (match-string 1))))) |
| 1581 | (file (or (diff-find-file-name other) (error "Can't find the file"))) | 1580 | (file (or (diff-find-file-name other noprompt) |
| 1581 | (error "Can't find the file"))) | ||
| 1582 | (buf (find-file-noselect file))) | 1582 | (buf (find-file-noselect file))) |
| 1583 | ;; Update the user preference if he so wished. | 1583 | ;; Update the user preference if he so wished. |
| 1584 | (when (> (prefix-numeric-value other-file) 8) | 1584 | (when (> (prefix-numeric-value other-file) 8) |
| @@ -1718,23 +1718,27 @@ For use in `add-log-current-defun-function'." | |||
| 1718 | (when (looking-at diff-hunk-header-re) | 1718 | (when (looking-at diff-hunk-header-re) |
| 1719 | (forward-line 1) | 1719 | (forward-line 1) |
| 1720 | (re-search-forward "^[^ ]" nil t)) | 1720 | (re-search-forward "^[^ ]" nil t)) |
| 1721 | (destructuring-bind (buf line-offset pos src dst &optional switched) | 1721 | (destructuring-bind (&optional buf line-offset pos src dst switched) |
| 1722 | (diff-find-source-location) | 1722 | ;; Use `noprompt' since this is used in which-func-mode and such. |
| 1723 | (beginning-of-line) | 1723 | (ignore-errors ;Signals errors in place of prompting. |
| 1724 | (or (when (memq (char-after) '(?< ?-)) | 1724 | (diff-find-source-location nil nil 'noprompt)) |
| 1725 | ;; Cursor is pointing at removed text. This could be a removed | 1725 | (when buf |
| 1726 | ;; function, in which case, going to the source buffer will | 1726 | (beginning-of-line) |
| 1727 | ;; not help since the function is now removed. Instead, | 1727 | (or (when (memq (char-after) '(?< ?-)) |
| 1728 | ;; try to figure out the function name just from the code-fragment. | 1728 | ;; Cursor is pointing at removed text. This could be a removed |
| 1729 | (let ((old (if switched dst src))) | 1729 | ;; function, in which case, going to the source buffer will |
| 1730 | (with-temp-buffer | 1730 | ;; not help since the function is now removed. Instead, |
| 1731 | (insert (car old)) | 1731 | ;; try to figure out the function name just from the |
| 1732 | (funcall (buffer-local-value 'major-mode buf)) | 1732 | ;; code-fragment. |
| 1733 | (goto-char (+ (point-min) (cdr old))) | 1733 | (let ((old (if switched dst src))) |
| 1734 | (add-log-current-defun)))) | 1734 | (with-temp-buffer |
| 1735 | (with-current-buffer buf | 1735 | (insert (car old)) |
| 1736 | (goto-char (+ (car pos) (cdr src))) | 1736 | (funcall (buffer-local-value 'major-mode buf)) |
| 1737 | (add-log-current-defun)))))) | 1737 | (goto-char (+ (point-min) (cdr old))) |
| 1738 | (add-log-current-defun)))) | ||
| 1739 | (with-current-buffer buf | ||
| 1740 | (goto-char (+ (car pos) (cdr src))) | ||
| 1741 | (add-log-current-defun))))))) | ||
| 1738 | 1742 | ||
| 1739 | (defun diff-ignore-whitespace-hunk () | 1743 | (defun diff-ignore-whitespace-hunk () |
| 1740 | "Re-diff the current hunk, ignoring whitespace differences." | 1744 | "Re-diff the current hunk, ignoring whitespace differences." |