comparison lisp/diff-mode.el @ 32063:3fb2a3b13c5e

(diff-test-hunk): Backout previous change. Fix doc string. (diff-apply-hunk): Don't return a value.
author Miles Bader <miles@gnu.org>
date Mon, 02 Oct 2000 06:49:21 +0000
parents cdfabbe10a24
children 161c2ec9f5b2
comparison
equal deleted inserted replaced
32062:3c0a00f2233a 32063:3fb2a3b13c5e
2 2
3 ;; Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc. 3 ;; Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc.
4 4
5 ;; Author: Stefan Monnier <monnier@cs.yale.edu> 5 ;; Author: Stefan Monnier <monnier@cs.yale.edu>
6 ;; Keywords: patch diff 6 ;; Keywords: patch diff
7 ;; Revision: $Id: diff-mode.el,v 1.24 2000/09/29 18:05:27 monnier Exp $ 7 ;; Revision: $Id: diff-mode.el,v 1.25 2000/10/02 03:46:26 miles Exp $
8 8
9 ;; This file is part of GNU Emacs. 9 ;; This file is part of GNU Emacs.
10 10
11 ;; GNU Emacs is free software; you can redistribute it and/or modify 11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by 12 ;; it under the terms of the GNU General Public License as published by
1017 By default, the new source file is patched, but if the variable 1017 By default, the new source file is patched, but if the variable
1018 `diff-jump-to-old-file-flag' is non-nil, then the old source file is 1018 `diff-jump-to-old-file-flag' is non-nil, then the old source file is
1019 patched instead (some commands, such as `diff-goto-source' can change 1019 patched instead (some commands, such as `diff-goto-source' can change
1020 the value of this variable when given an appropriate prefix argument). 1020 the value of this variable when given an appropriate prefix argument).
1021 1021
1022 With a prefix argument, REVERSE the hunk. 1022 With a prefix argument, REVERSE the hunk."
1023
1024 Return value is t if the hunk was sucessfully applied, `reversed' if the
1025 hunk was applied backwards and nil if the hunk wasn't applied."
1026 (interactive "P") 1023 (interactive "P")
1027 (destructuring-bind (buf line-offset pos old new &optional switched) 1024 (destructuring-bind (buf line-offset pos old new &optional switched)
1028 (diff-find-source-location nil reverse) 1025 (diff-find-source-location nil reverse)
1029 (cond 1026 (cond
1030 ((null line-offset) (error "Can't find the text to patch")) 1027 ((null line-offset)
1028 (error "Can't find the text to patch"))
1031 ((and switched 1029 ((and switched
1032 ;; A reversed patch was detected, perhaps apply it in reverse 1030 ;; A reversed patch was detected, perhaps apply it in reverse
1033 (not (save-window-excursion 1031 (not (save-window-excursion
1034 (pop-to-buffer buf) 1032 (pop-to-buffer buf)
1035 (goto-char (+ pos (cdr old))) 1033 (goto-char (+ pos (cdr old)))
1036 (y-or-n-p 1034 (y-or-n-p
1037 (if reverse 1035 (if reverse
1038 "Hunk hasn't been applied yet; apply it now? " 1036 "Hunk hasn't been applied yet; apply it now? "
1039 "Hunk has already been applied; undo it? "))))) 1037 "Hunk has already been applied; undo it? ")))))
1040 (message "(Nothing done)") 1038 (message "(Nothing done)"))
1041 nil)
1042 (t 1039 (t
1043 (let ((reversed (diff-xor switched reverse))) 1040 ;; Apply the hunk
1044 ;; Apply the hunk 1041 (with-current-buffer buf
1045 (with-current-buffer buf 1042 (goto-char pos)
1046 (goto-char pos) 1043 (delete-char (length (car old)))
1047 (delete-char (length (car old))) 1044 (insert (car new)))
1048 (insert (car new))) 1045 ;; Display BUF in a window
1049 ;; Display BUF in a window 1046 (set-window-point (display-buffer buf) (+ pos (cdr new)))
1050 (set-window-point (display-buffer buf) (+ pos (cdr new))) 1047 (diff-hunk-status-msg line-offset (diff-xor switched reverse) nil)
1051 (diff-hunk-status-msg line-offset reversed nil) 1048 (when diff-advance-after-apply-hunk
1052 (when diff-advance-after-apply-hunk 1049 (diff-hunk-next))))))
1053 (diff-hunk-next))
1054 (if reversed 'reversed t))))))
1055 1050
1056 1051
1057 (defun diff-test-hunk (&optional reverse) 1052 (defun diff-test-hunk (&optional reverse)
1058 ;; FIXME: is `reverse' ever useful ??? 1053 ;; FIXME: is `reverse' ever useful ???
1059 "See whether it's possible to apply the current hunk. 1054 "See whether it's possible to apply the current hunk.
1060 With a prefix argument, try to REVERSE the hunk. 1055 With a prefix argument, try to REVERSE the hunk."
1061 Returns t if the hunk can be applied, `reversed' if it's already
1062 applied and nil if it can't be found."
1063 (interactive "P") 1056 (interactive "P")
1064 (destructuring-bind (buf line-offset pos src dst &optional switched) 1057 (destructuring-bind (buf line-offset pos src dst &optional switched)
1065 (diff-find-source-location nil reverse) 1058 (diff-find-source-location nil reverse)
1066 (set-window-point (display-buffer buf) (+ pos (cdr src))) 1059 (set-window-point (display-buffer buf) (+ pos (cdr src)))
1067 (let ((reversed (diff-xor switched reverse))) 1060 (diff-hunk-status-msg line-offset (diff-xor reverse switched) t)))
1068 (diff-hunk-status-msg line-offset (diff-xor reverse switched) t)
1069 (if reversed 'reversed t))))
1070 1061
1071 1062
1072 (defun diff-goto-source (&optional other-file) 1063 (defun diff-goto-source (&optional other-file)
1073 "Jump to the corresponding source line. 1064 "Jump to the corresponding source line.
1074 `diff-jump-to-old-file-flag' (or its opposite if the OTHER-FILE prefix arg 1065 `diff-jump-to-old-file-flag' (or its opposite if the OTHER-FILE prefix arg