/[emacs]/emacs/lisp/diff-mode.el
ViewVC logotype

Diff of /emacs/lisp/diff-mode.el

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.45 by pj, Tue Jan 1 22:12:19 2002 UTC revision 1.45.4.1 by miles, Fri Apr 4 06:20:01 2003 UTC
# Line 1  Line 1 
1  ;;; diff-mode.el --- a mode for viewing/editing context diffs  ;;; diff-mode.el --- a mode for viewing/editing context diffs
2    
3  ;; Copyright (C) 1998, 1999, 2000, 2001  Free Software Foundation, Inc.  ;; Copyright (C) 1998, 1999, 2000, 2001, 2002  Free Software Foundation, Inc.
4    
5  ;; Author: Stefan Monnier <monnier@cs.yale.edu>  ;; Author: Stefan Monnier <monnier@cs.yale.edu>
6  ;; Keywords: convenience patch diff  ;; Keywords: convenience patch diff
# Line 417  If the prefix ARG is given, restrict the Line 417  If the prefix ARG is given, restrict the
417                (number-to-string newstart2) ",1 @@\n")                (number-to-string newstart2) ",1 @@\n")
418        ;; Fix the original hunk-header.        ;; Fix the original hunk-header.
419        (diff-fixup-modifs start pos))))        (diff-fixup-modifs start pos))))
420          
421    
422  ;;;;  ;;;;
423  ;;;; jump to other buffers  ;;;; jump to other buffers
# Line 519  Non-nil OLD means that we want the old f Line 519  Non-nil OLD means that we want the old f
519        (ediff-patch-file nil (current-buffer))        (ediff-patch-file nil (current-buffer))
520      (wrong-number-of-arguments (ediff-patch-file))))      (wrong-number-of-arguments (ediff-patch-file))))
521    
522  ;;;;  ;;;;
523  ;;;; Conversion functions  ;;;; Conversion functions
524  ;;;;  ;;;;
525    
526  ;;(defvar diff-inhibit-after-change nil  ;;(defvar diff-inhibit-after-change nil
527  ;;  "Non-nil means inhibit `diff-mode's after-change functions.")  ;;  "Non-nil means inhibit `diff-mode's after-change functions.")
# Line 742  else cover the whole bufer." Line 742  else cover the whole bufer."
742                             (delete-char 1) (insert "-") t)                             (delete-char 1) (insert "-") t)
743                         ((?\\ ?#) t)                         ((?\\ ?#) t)
744                         (t (when (and first last (< first last))                         (t (when (and first last (< first last))
745                              (let ((str                              (insert (delete-and-extract-region first last)))
                                    (save-excursion  
                                      (delete-and-extract-region first last))))  
                               (insert str)))  
746                            (setq first nil last nil)                            (setq first nil last nil)
747                            (equal ?\  c)))                            (equal ?\  c)))
748                  (forward-line 1))))))))))                  (forward-line 1))))))))))
# Line 794  else cover the whole bufer." Line 791  else cover the whole bufer."
791                    (unless (string= new old) (replace-match new t t nil 2))))))                    (unless (string= new old) (replace-match new t t nil 2))))))
792              (setq space 0 plus 0 minus 0 bang 0)))))))              (setq space 0 plus 0 minus 0 bang 0)))))))
793    
794  ;;;;  ;;;;
795  ;;;; Hooks  ;;;; Hooks
796  ;;;;  ;;;;
797    
798  (defun diff-write-contents-hooks ()  (defun diff-write-contents-hooks ()
799    "Fixup hunk headers if necessary."    "Fixup hunk headers if necessary."
# Line 819  See `after-change-functions' for the mea Line 816  See `after-change-functions' for the mea
816      (if diff-unhandled-changes      (if diff-unhandled-changes
817          (setq diff-unhandled-changes          (setq diff-unhandled-changes
818                (cons (min beg (car diff-unhandled-changes))                (cons (min beg (car diff-unhandled-changes))
819                      (max beg (cdr diff-unhandled-changes))))                      (max end (cdr diff-unhandled-changes))))
820        (setq diff-unhandled-changes (cons beg end)))))        (setq diff-unhandled-changes (cons beg end)))))
821    
822  (defun diff-post-command-hook ()  (defun diff-post-command-hook ()
# Line 828  See `after-change-functions' for the mea Line 825  See `after-change-functions' for the mea
825      (ignore-errors      (ignore-errors
826        (save-excursion        (save-excursion
827          (goto-char (car diff-unhandled-changes))          (goto-char (car diff-unhandled-changes))
828            ;; Maybe we've cut the end of the hunk before point.
829            (if (and (bolp) (not (bobp))) (backward-char 1))
830          ;; We used to fixup modifs on all the changes, but it turns out          ;; We used to fixup modifs on all the changes, but it turns out
831          ;; that it's safer not to do it on big changes, for example          ;; that it's safer not to do it on big changes, for example
832          ;; when yanking a big diff, since we might then screw up perfectly          ;; when yanking a big diff, since we might then screw up perfectly
# Line 844  See `after-change-functions' for the mea Line 843  See `after-change-functions' for the mea
843          (diff-beginning-of-hunk)          (diff-beginning-of-hunk)
844          (when (save-excursion          (when (save-excursion
845                  (diff-end-of-hunk)                  (diff-end-of-hunk)
846                  (> (point) (cdr diff-unhandled-changes)))                  (>= (point) (cdr diff-unhandled-changes)))
847            (diff-fixup-modifs (point) (cdr diff-unhandled-changes)))))            (diff-fixup-modifs (point) (cdr diff-unhandled-changes)))))
848      (setq diff-unhandled-changes nil)))      (setq diff-unhandled-changes nil)))
849    
850  ;;;;  ;;;;
851  ;;;; The main function  ;;;; The main function
852  ;;;;  ;;;;
853    
854  ;;;###autoload  ;;;###autoload
855  (define-derived-mode diff-mode fundamental-mode "Diff"  (define-derived-mode diff-mode fundamental-mode "Diff"
856    "Major mode for viewing/editing context diffs.    "Major mode for viewing/editing context diffs.
857  Supports unified and context diffs as well as (to a lesser extent)  Supports unified and context diffs as well as (to a lesser extent)
858  normal diffs.  normal diffs.
859  When the buffer is read-only, the ESC prefix is not necessary."  When the buffer is read-only, the ESC prefix is not necessary.
860    IF you edit the buffer manually, diff-mode will try to update the hunk
861    headers for you on-the-fly.
862    
863    You can also switch between context diff and unified diff with \\[diff-context->unified],
864    or vice versa with \\[diff-unified->context] and you can also revert the direction of
865    a diff with \\[diff-reverse-direction]."
866    (set (make-local-variable 'font-lock-defaults) diff-font-lock-defaults)    (set (make-local-variable 'font-lock-defaults) diff-font-lock-defaults)
867    (set (make-local-variable 'outline-regexp) diff-outline-regexp)    (set (make-local-variable 'outline-regexp) diff-outline-regexp)
868    (set (make-local-variable 'imenu-generic-expression)    (set (make-local-variable 'imenu-generic-expression)
# Line 873  When the buffer is read-only, the ESC pr Line 878  When the buffer is read-only, the ESC pr
878    ;;   (set (make-local-variable 'page-delimiter) "--- [^\t]+\t")    ;;   (set (make-local-variable 'page-delimiter) "--- [^\t]+\t")
879    ;; compile support    ;; compile support
880    
881    ;;;; compile support is not good enough yet.  Also it can be annoying    ;;;; compile support is not good enough yet.  It should be merged
882    ;; and should thus only be enabled conditionally.    ;;;; with diff.el's support.
883    ;; (set (make-local-variable 'compilation-file-regexp-alist)    (set (make-local-variable 'compilation-file-regexp-alist)
884    ;;      diff-file-regexp-alist)         diff-file-regexp-alist)
885    ;; (set (make-local-variable 'compilation-error-regexp-alist)    (set (make-local-variable 'compilation-error-regexp-alist)
886    ;;      diff-error-regexp-alist)         diff-error-regexp-alist)
887    ;; (when (string-match "\\.rej\\'" (or buffer-file-name ""))    (when (string-match "\\.rej\\'" (or buffer-file-name ""))
888    ;;   (set (make-local-variable 'compilation-current-file)      (set (make-local-variable 'compilation-current-file)
889    ;;     (substring buffer-file-name 0 (match-beginning 0))))           (substring buffer-file-name 0 (match-beginning 0))))
890    ;; (compilation-shell-minor-mode 1)    ;; Be careful not to change compilation-last-buffer when we're just
891      ;; doing a C-x v = (for example).
892      (if (boundp 'compilation-last-buffer)
893          (let ((compilation-last-buffer compilation-last-buffer))
894            (compilation-minor-mode 1))
895        (compilation-minor-mode 1))
896      ;; M-RET and RET should be done by diff-mode because the `compile'
897      ;; support is significantly less good.
898      (add-to-list 'minor-mode-overriding-map-alist
899                   (cons 'compilation-minor-mode (make-sparse-keymap)))
900    
901    (when (and (> (point-max) (point-min)) diff-default-read-only)    (when (and (> (point-max) (point-min)) diff-default-read-only)
902      (toggle-read-only t))      (toggle-read-only t))
# Line 893  When the buffer is read-only, the ESC pr Line 907  When the buffer is read-only, the ESC pr
907      (add-hook 'after-change-functions 'diff-after-change-function nil t)      (add-hook 'after-change-functions 'diff-after-change-function nil t)
908      (add-hook 'post-command-hook 'diff-post-command-hook nil t))      (add-hook 'post-command-hook 'diff-post-command-hook nil t))
909    ;; 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:
910    (add-to-list (make-local-variable 'minor-mode-overriding-map-alist)    (add-to-list 'minor-mode-overriding-map-alist
911                 (cons 'buffer-read-only diff-mode-shared-map))                 (cons 'buffer-read-only diff-mode-shared-map))
912    ;; add-log support    ;; add-log support
913    (set (make-local-variable 'add-log-current-defun-function)    (set (make-local-variable 'add-log-current-defun-function)
# Line 1183  For use in `add-log-current-defun-functi Line 1197  For use in `add-log-current-defun-functi
1197              (let ((old (if switched dst src)))              (let ((old (if switched dst src)))
1198                (with-temp-buffer                (with-temp-buffer
1199                  (insert (car old))                  (insert (car old))
                 (goto-char (cdr old))  
1200                  (funcall (with-current-buffer buf major-mode))                  (funcall (with-current-buffer buf major-mode))
1201                    (goto-char (+ (point-min) (cdr old)))
1202                  (add-log-current-defun))))                  (add-log-current-defun))))
1203            (with-current-buffer buf            (with-current-buffer buf
1204              (goto-char (+ (car pos) (cdr src)))              (goto-char (+ (car pos) (cdr src)))

Legend:
Removed from v.1.45  
changed lines
  Added in v.1.45.4.1

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26