aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/diff-mode.el
diff options
context:
space:
mode:
authorStefan Monnier2000-02-07 02:01:07 +0000
committerStefan Monnier2000-02-07 02:01:07 +0000
commitfef8c55b166e8d591fa6aab967bb2c783dfacc68 (patch)
tree8fe6754792ef53263c1d844e9dda1571bea5db21 /lisp/diff-mode.el
parent6e1d0d151dbcb24c71654345358be05f797a7841 (diff)
downloademacs-fef8c55b166e8d591fa6aab967bb2c783dfacc68.tar.gz
emacs-fef8c55b166e8d591fa6aab967bb2c783dfacc68.zip
(diff-kill-junk): New interactive function.
(diff-reverse-direction): Use delete-and-extract-region. (diff-post-command-hook): Restrict the area so that the hook also works outside of any diff hunk. This is necessary for the minor-mode. (diff-mode): Use toggle-read-only and minor-mode-overriding-map-alist. (diff-minor-mode): Setup the hooks for header-hunk rewriting.
Diffstat (limited to 'lisp/diff-mode.el')
-rw-r--r--lisp/diff-mode.el71
1 files changed, 53 insertions, 18 deletions
diff --git a/lisp/diff-mode.el b/lisp/diff-mode.el
index 2c0553efcc2..da15ab1fc2e 100644
--- a/lisp/diff-mode.el
+++ b/lisp/diff-mode.el
@@ -4,7 +4,7 @@
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$ 7;; Revision: $Id: diff-mode.el,v 1.4 1999/12/07 07:04:03 monnier Exp $
8 8
9;; This file is part of GNU Emacs. 9;; This file is part of GNU Emacs.
10 10
@@ -369,6 +369,21 @@ If the prefix ARG is given, restrict the view to the current file instead."
369 (diff-end-of-file) 369 (diff-end-of-file)
370 (kill-region start (point)))) 370 (kill-region start (point))))
371 371
372(defun diff-kill-junk ()
373 "Kill spurious empty diffs."
374 (interactive)
375 (save-excursion
376 (let ((inhibit-read-only t))
377 (goto-char (point-min))
378 (while (re-search-forward (concat "^\\(Index: .*\n\\)"
379 "\\([^-+!* <>].*\n\\)*?"
380 "\\(\\(Index:\\) \\|"
381 diff-file-header-re "\\)")
382 nil t)
383 (delete-region (if (match-end 4) (match-beginning 0) (match-end 1))
384 (match-beginning 3))
385 (beginning-of-line)))))
386
372;;;; 387;;;;
373;;;; jump to other buffers 388;;;; jump to other buffers
374;;;; 389;;;;
@@ -693,8 +708,7 @@ else cover the whole bufer."
693 (while (looking-at "[-! \\][ \t]") 708 (while (looking-at "[-! \\][ \t]")
694 (when (= (char-after) ?-) (delete-char 1) (insert "+")) 709 (when (= (char-after) ?-) (delete-char 1) (insert "+"))
695 (forward-line 1)) 710 (forward-line 1))
696 (let ((half1 (buffer-substring half1s (point)))) 711 (let ((half1 (delete-and-extract-region half1s (point))))
697 (delete-region half1s (point))
698 (unless (looking-at "^--- \\([0-9]+,-?[0-9]+\\) ----$") 712 (unless (looking-at "^--- \\([0-9]+,-?[0-9]+\\) ----$")
699 (insert half1) 713 (insert half1)
700 (error "Can't find matching `--- n1,n2 ----' line")) 714 (error "Can't find matching `--- n1,n2 ----' line"))
@@ -705,8 +719,7 @@ else cover the whole bufer."
705 (while (looking-at "[!+ \\][ \t]") 719 (while (looking-at "[!+ \\][ \t]")
706 (when (= (char-after) ?+) (delete-char 1) (insert "-")) 720 (when (= (char-after) ?+) (delete-char 1) (insert "-"))
707 (forward-line 1)) 721 (forward-line 1))
708 (let ((half2 (buffer-substring half2s (point)))) 722 (let ((half2 (delete-and-extract-region half2s (point))))
709 (delete-region half2s (point))
710 (insert half1) 723 (insert half1)
711 (goto-char half1s) 724 (goto-char half1s)
712 (insert half2))) 725 (insert half2)))
@@ -724,8 +737,9 @@ else cover the whole bufer."
724 (delete-char 1) (insert "-") t) 737 (delete-char 1) (insert "-") t)
725 (?\\ t) 738 (?\\ t)
726 (t (when (and first last (< first last)) 739 (t (when (and first last (< first last))
727 (let ((str (buffer-substring first last))) 740 (let ((str
728 (save-excursion (delete-region first last)) 741 (save-excursion
742 (delete-and-extract-region first last))))
729 (insert str))) 743 (insert str)))
730 (setq first nil last nil) 744 (setq first nil last nil)
731 (equal ?\ c))) 745 (equal ?\ c)))
@@ -784,9 +798,6 @@ else cover the whole bufer."
784 (if (buffer-modified-p) (diff-fixup-modifs (point-min) (point-max))) 798 (if (buffer-modified-p) (diff-fixup-modifs (point-min) (point-max)))
785 nil) 799 nil)
786 800
787;; XEmacs doesn't seem to have this feature
788(defvar undo-in-progress nil)
789
790;; It turns out that making changes in the buffer from within an 801;; It turns out that making changes in the buffer from within an
791;; *-change-function is asking for trouble, whereas making them 802;; *-change-function is asking for trouble, whereas making them
792;; from a post-command-hook doesn't pose much problems 803;; from a post-command-hook doesn't pose much problems
@@ -806,7 +817,15 @@ See `after-change-functions' for the meaning of BEG, END and LEN."
806 (when (consp diff-unhandled-changes) 817 (when (consp diff-unhandled-changes)
807 (ignore-errors 818 (ignore-errors
808 (save-excursion 819 (save-excursion
809 (goto-char (car diff-unhandled-changes)) (diff-beginning-of-hunk) 820 (goto-char (car diff-unhandled-changes))
821 (unless (ignore-errors
822 (diff-beginning-of-hunk)
823 (save-excursion
824 (diff-end-of-hunk)
825 (> (point) (car diff-unhandled-changes))))
826 (goto-char (car diff-unhandled-changes))
827 (re-search-forward diff-hunk-header-re (cdr diff-unhandled-changes))
828 (diff-beginning-of-hunk))
810 (diff-fixup-modifs (point) (cdr diff-unhandled-changes)))) 829 (diff-fixup-modifs (point) (cdr diff-unhandled-changes))))
811 (setq diff-unhandled-changes nil))) 830 (setq diff-unhandled-changes nil)))
812 831
@@ -837,8 +856,8 @@ This mode runs `diff-mode-hook'.
837 (set (make-local-variable 'compilation-current-file) 856 (set (make-local-variable 'compilation-current-file)
838 (substring buffer-file-name 0 (match-beginning 0)))) 857 (substring buffer-file-name 0 (match-beginning 0))))
839 (compilation-shell-minor-mode 1) 858 (compilation-shell-minor-mode 1)
840 ;; 859 ;; setup change hooks
841 (setq buffer-read-only t) 860 (toggle-read-only t)
842 (if (not diff-update-on-the-fly-flag) 861 (if (not diff-update-on-the-fly-flag)
843 (add-hook 'write-contents-hooks 'diff-write-contents-hooks) 862 (add-hook 'write-contents-hooks 'diff-write-contents-hooks)
844 (make-local-variable 'diff-unhandled-changes) 863 (make-local-variable 'diff-unhandled-changes)
@@ -847,9 +866,8 @@ This mode runs `diff-mode-hook'.
847 (add-hook (make-local-hook 'post-command-hook) 866 (add-hook (make-local-hook 'post-command-hook)
848 'diff-post-command-hook nil t)) 867 'diff-post-command-hook nil t))
849 ;; Neat trick from Dave Love to add more bindings in read-only mode: 868 ;; Neat trick from Dave Love to add more bindings in read-only mode:
850 (add-to-list (make-local-variable 'minor-mode-map-alist) 869 (add-to-list (make-local-variable 'minor-mode-overriding-map-alist)
851 (cons 'buffer-read-only diff-mode-shared-map)) 870 (cons 'buffer-read-only diff-mode-shared-map))
852 ;;
853 (run-hooks 'diff-mode-hook)) 871 (run-hooks 'diff-mode-hook))
854 872
855;;;###autoload 873;;;###autoload
@@ -858,8 +876,14 @@ This mode runs `diff-mode-hook'.
858\\{diff-minor-mode-map}" 876\\{diff-minor-mode-map}"
859 nil " Diff" nil 877 nil " Diff" nil
860 ;; FIXME: setup font-lock 878 ;; FIXME: setup font-lock
861 ;; FIXME: setup change hooks 879 ;; setup change hooks
862 ) 880 (if (not diff-update-on-the-fly-flag)
881 (add-hook 'write-contents-hooks 'diff-write-contents-hooks)
882 (make-local-variable 'diff-unhandled-changes)
883 (add-hook (make-local-hook 'after-change-functions)
884 'diff-after-change-function nil t)
885 (add-hook (make-local-hook 'post-command-hook)
886 'diff-post-command-hook nil t)))
863 887
864 888
865;; provide the package 889;; provide the package
@@ -867,6 +891,17 @@ This mode runs `diff-mode-hook'.
867 891
868;;; Change Log: 892;;; Change Log:
869;; $Log: diff-mode.el,v $ 893;; $Log: diff-mode.el,v $
894;; Revision 1.4 1999/12/07 07:04:03 monnier
895;; * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
896;; (diff-minor-mode, diff-minor-mode-prefix, diff-minor-mode-map):
897;; New code to support the minor mode version.
898;; (diff-recenter): New function.
899;; (diff-next-hunk, diff-next-file): Use it.
900;; (diff-remembered-files-alist): New var.
901;; (diff-merge-strings): New function.
902;; (diff-find-file-name): Make it smarter and use the user's input more.
903;; (diff-mode): Cosmetic changes.
904;;
870;; Revision 1.11 1999/10/09 23:38:29 monnier 905;; Revision 1.11 1999/10/09 23:38:29 monnier
871;; (diff-mode-load-hook): dropped. 906;; (diff-mode-load-hook): dropped.
872;; (auto-mode-alist): also catch *.diffs. 907;; (auto-mode-alist): also catch *.diffs.