Commit fef8c55b authored by Stefan Monnier's avatar Stefan Monnier
Browse files

(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.
parent 6e1d0d15
2000-02-06 Stefan Monnier <monnier@cs.yale.edu> 2000-02-06 Stefan Monnier <monnier@cs.yale.edu>
* diff-mode.el (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.
* font-lock.el (font-lock-keywords): Fix doc for multiline matches. * font-lock.el (font-lock-keywords): Fix doc for multiline matches.
(font-lock-add-keywords): Make it work even if font-lock-mode is nil, (font-lock-add-keywords): Make it work even if font-lock-mode is nil,
so that it can be used more easily in <foo>-mode-hook. Also make sure so that it can be used more easily in <foo>-mode-hook. Also make sure
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
;; Author: Stefan Monnier <monnier@cs.yale.edu> ;; Author: Stefan Monnier <monnier@cs.yale.edu>
;; Keywords: patch diff ;; Keywords: patch diff
;; Revision: $Id$ ;; Revision: $Id: diff-mode.el,v 1.4 1999/12/07 07:04:03 monnier Exp $
;; This file is part of GNU Emacs. ;; This file is part of GNU Emacs.
...@@ -369,6 +369,21 @@ If the prefix ARG is given, restrict the view to the current file instead." ...@@ -369,6 +369,21 @@ If the prefix ARG is given, restrict the view to the current file instead."
(diff-end-of-file) (diff-end-of-file)
(kill-region start (point)))) (kill-region start (point))))
(defun diff-kill-junk ()
"Kill spurious empty diffs."
(interactive)
(save-excursion
(let ((inhibit-read-only t))
(goto-char (point-min))
(while (re-search-forward (concat "^\\(Index: .*\n\\)"
"\\([^-+!* <>].*\n\\)*?"
"\\(\\(Index:\\) \\|"
diff-file-header-re "\\)")
nil t)
(delete-region (if (match-end 4) (match-beginning 0) (match-end 1))
(match-beginning 3))
(beginning-of-line)))))
;;;; ;;;;
;;;; jump to other buffers ;;;; jump to other buffers
;;;; ;;;;
...@@ -693,8 +708,7 @@ else cover the whole bufer." ...@@ -693,8 +708,7 @@ else cover the whole bufer."
(while (looking-at "[-! \\][ \t]") (while (looking-at "[-! \\][ \t]")
(when (= (char-after) ?-) (delete-char 1) (insert "+")) (when (= (char-after) ?-) (delete-char 1) (insert "+"))
(forward-line 1)) (forward-line 1))
(let ((half1 (buffer-substring half1s (point)))) (let ((half1 (delete-and-extract-region half1s (point))))
(delete-region half1s (point))
(unless (looking-at "^--- \\([0-9]+,-?[0-9]+\\) ----$") (unless (looking-at "^--- \\([0-9]+,-?[0-9]+\\) ----$")
(insert half1) (insert half1)
(error "Can't find matching `--- n1,n2 ----' line")) (error "Can't find matching `--- n1,n2 ----' line"))
...@@ -705,8 +719,7 @@ else cover the whole bufer." ...@@ -705,8 +719,7 @@ else cover the whole bufer."
(while (looking-at "[!+ \\][ \t]") (while (looking-at "[!+ \\][ \t]")
(when (= (char-after) ?+) (delete-char 1) (insert "-")) (when (= (char-after) ?+) (delete-char 1) (insert "-"))
(forward-line 1)) (forward-line 1))
(let ((half2 (buffer-substring half2s (point)))) (let ((half2 (delete-and-extract-region half2s (point))))
(delete-region half2s (point))
(insert half1) (insert half1)
(goto-char half1s) (goto-char half1s)
(insert half2))) (insert half2)))
...@@ -724,8 +737,9 @@ else cover the whole bufer." ...@@ -724,8 +737,9 @@ else cover the whole bufer."
(delete-char 1) (insert "-") t) (delete-char 1) (insert "-") t)
(?\\ t) (?\\ t)
(t (when (and first last (< first last)) (t (when (and first last (< first last))
(let ((str (buffer-substring first last))) (let ((str
(save-excursion (delete-region first last)) (save-excursion
(delete-and-extract-region first last))))
(insert str))) (insert str)))
(setq first nil last nil) (setq first nil last nil)
(equal ?\ c))) (equal ?\ c)))
...@@ -784,9 +798,6 @@ else cover the whole bufer." ...@@ -784,9 +798,6 @@ else cover the whole bufer."
(if (buffer-modified-p) (diff-fixup-modifs (point-min) (point-max))) (if (buffer-modified-p) (diff-fixup-modifs (point-min) (point-max)))
nil) nil)
;; XEmacs doesn't seem to have this feature
(defvar undo-in-progress nil)
;; It turns out that making changes in the buffer from within an ;; It turns out that making changes in the buffer from within an
;; *-change-function is asking for trouble, whereas making them ;; *-change-function is asking for trouble, whereas making them
;; from a post-command-hook doesn't pose much problems ;; 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,7 +817,15 @@ See `after-change-functions' for the meaning of BEG, END and LEN."
(when (consp diff-unhandled-changes) (when (consp diff-unhandled-changes)
(ignore-errors (ignore-errors
(save-excursion (save-excursion
(goto-char (car diff-unhandled-changes)) (diff-beginning-of-hunk) (goto-char (car diff-unhandled-changes))
(unless (ignore-errors
(diff-beginning-of-hunk)
(save-excursion
(diff-end-of-hunk)
(> (point) (car diff-unhandled-changes))))
(goto-char (car diff-unhandled-changes))
(re-search-forward diff-hunk-header-re (cdr diff-unhandled-changes))
(diff-beginning-of-hunk))
(diff-fixup-modifs (point) (cdr diff-unhandled-changes)))) (diff-fixup-modifs (point) (cdr diff-unhandled-changes))))
(setq diff-unhandled-changes nil))) (setq diff-unhandled-changes nil)))
...@@ -837,8 +856,8 @@ This mode runs `diff-mode-hook'. ...@@ -837,8 +856,8 @@ This mode runs `diff-mode-hook'.
(set (make-local-variable 'compilation-current-file) (set (make-local-variable 'compilation-current-file)
(substring buffer-file-name 0 (match-beginning 0)))) (substring buffer-file-name 0 (match-beginning 0))))
(compilation-shell-minor-mode 1) (compilation-shell-minor-mode 1)
;; ;; setup change hooks
(setq buffer-read-only t) (toggle-read-only t)
(if (not diff-update-on-the-fly-flag) (if (not diff-update-on-the-fly-flag)
(add-hook 'write-contents-hooks 'diff-write-contents-hooks) (add-hook 'write-contents-hooks 'diff-write-contents-hooks)
(make-local-variable 'diff-unhandled-changes) (make-local-variable 'diff-unhandled-changes)
...@@ -847,9 +866,8 @@ This mode runs `diff-mode-hook'. ...@@ -847,9 +866,8 @@ This mode runs `diff-mode-hook'.
(add-hook (make-local-hook 'post-command-hook) (add-hook (make-local-hook 'post-command-hook)
'diff-post-command-hook nil t)) 'diff-post-command-hook nil t))
;; Neat trick from Dave Love to add more bindings in read-only mode: ;; Neat trick from Dave Love to add more bindings in read-only mode:
(add-to-list (make-local-variable 'minor-mode-map-alist) (add-to-list (make-local-variable 'minor-mode-overriding-map-alist)
(cons 'buffer-read-only diff-mode-shared-map)) (cons 'buffer-read-only diff-mode-shared-map))
;;
(run-hooks 'diff-mode-hook)) (run-hooks 'diff-mode-hook))
;;;###autoload ;;;###autoload
...@@ -858,8 +876,14 @@ This mode runs `diff-mode-hook'. ...@@ -858,8 +876,14 @@ This mode runs `diff-mode-hook'.
\\{diff-minor-mode-map}" \\{diff-minor-mode-map}"
nil " Diff" nil nil " Diff" nil
;; FIXME: setup font-lock ;; FIXME: setup font-lock
;; FIXME: setup change hooks ;; setup change hooks
) (if (not diff-update-on-the-fly-flag)
(add-hook 'write-contents-hooks 'diff-write-contents-hooks)
(make-local-variable 'diff-unhandled-changes)
(add-hook (make-local-hook 'after-change-functions)
'diff-after-change-function nil t)
(add-hook (make-local-hook 'post-command-hook)
'diff-post-command-hook nil t)))
;; provide the package ;; provide the package
...@@ -867,6 +891,17 @@ This mode runs `diff-mode-hook'. ...@@ -867,6 +891,17 @@ This mode runs `diff-mode-hook'.
;;; Change Log: ;;; Change Log:
;; $Log: diff-mode.el,v $ ;; $Log: diff-mode.el,v $
;; Revision 1.4 1999/12/07 07:04:03 monnier
;; * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
;; (diff-minor-mode, diff-minor-mode-prefix, diff-minor-mode-map):
;; New code to support the minor mode version.
;; (diff-recenter): New function.
;; (diff-next-hunk, diff-next-file): Use it.
;; (diff-remembered-files-alist): New var.
;; (diff-merge-strings): New function.
;; (diff-find-file-name): Make it smarter and use the user's input more.
;; (diff-mode): Cosmetic changes.
;;
;; Revision 1.11 1999/10/09 23:38:29 monnier ;; Revision 1.11 1999/10/09 23:38:29 monnier
;; (diff-mode-load-hook): dropped. ;; (diff-mode-load-hook): dropped.
;; (auto-mode-alist): also catch *.diffs. ;; (auto-mode-alist): also catch *.diffs.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment