diff options
| author | Stefan Monnier | 2002-10-10 17:45:17 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2002-10-10 17:45:17 +0000 |
| commit | 7cd017baee2d02238a4509f1665be85e88a65b30 (patch) | |
| tree | 770c47aeeba6e301554d55508b430b86f129aa70 | |
| parent | a48402c999f3600e8a6ba63c6fa246e223db138c (diff) | |
| download | emacs-7cd017baee2d02238a4509f1665be85e88a65b30.tar.gz emacs-7cd017baee2d02238a4509f1665be85e88a65b30.zip | |
(add-change-log-entry): Don't call find-file at all
if we're already in the proper buffer.
(change-log-resolve-conflict): New fun.
(change-log-mode): Use it and use define-derived-mode.
(change-log-merge): Allow other-log to be a buffer.
Don't add a \n if there are already enough \n's.
| -rw-r--r-- | lisp/add-log.el | 59 |
1 files changed, 37 insertions, 22 deletions
diff --git a/lisp/add-log.el b/lisp/add-log.el index 1c3f70a9b77..5b69cc90426 100644 --- a/lisp/add-log.el +++ b/lisp/add-log.el | |||
| @@ -464,10 +464,10 @@ non-nil, otherwise in local time." | |||
| 464 | (item (add-log-file-name buffer-file file-name)) | 464 | (item (add-log-file-name buffer-file file-name)) |
| 465 | bound) | 465 | bound) |
| 466 | 466 | ||
| 467 | (if (or (and other-window (not (equal file-name buffer-file-name))) | 467 | (unless (equal file-name buffer-file-name) |
| 468 | (window-dedicated-p (selected-window))) | 468 | (if (or other-window (window-dedicated-p (selected-window))) |
| 469 | (find-file-other-window file-name) | 469 | (find-file-other-window file-name) |
| 470 | (find-file file-name)) | 470 | (find-file file-name))) |
| 471 | (or (eq major-mode 'change-log-mode) | 471 | (or (eq major-mode 'change-log-mode) |
| 472 | (change-log-mode)) | 472 | (change-log-mode)) |
| 473 | (undo-boundary) | 473 | (undo-boundary) |
| @@ -588,22 +588,16 @@ the change log file in another window." | |||
| 588 | ;;;###autoload (define-key ctl-x-4-map "a" 'add-change-log-entry-other-window) | 588 | ;;;###autoload (define-key ctl-x-4-map "a" 'add-change-log-entry-other-window) |
| 589 | 589 | ||
| 590 | ;;;###autoload | 590 | ;;;###autoload |
| 591 | (defun change-log-mode () | 591 | (define-derived-mode change-log-mode text-mode "Change Log" |
| 592 | "Major mode for editing change logs; like Indented Text Mode. | 592 | "Major mode for editing change logs; like Indented Text Mode. |
| 593 | Prevents numeric backups and sets `left-margin' to 8 and `fill-column' to 74. | 593 | Prevents numeric backups and sets `left-margin' to 8 and `fill-column' to 74. |
| 594 | New log entries are usually made with \\[add-change-log-entry] or \\[add-change-log-entry-other-window]. | 594 | New log entries are usually made with \\[add-change-log-entry] or \\[add-change-log-entry-other-window]. |
| 595 | Each entry behaves as a paragraph, and the entries for one day as a page. | 595 | Each entry behaves as a paragraph, and the entries for one day as a page. |
| 596 | Runs `change-log-mode-hook'." | 596 | Runs `change-log-mode-hook'." |
| 597 | (interactive) | 597 | (setq left-margin 8 |
| 598 | (kill-all-local-variables) | ||
| 599 | (indented-text-mode) | ||
| 600 | (setq major-mode 'change-log-mode | ||
| 601 | mode-name "Change Log" | ||
| 602 | left-margin 8 | ||
| 603 | fill-column 74 | 598 | fill-column 74 |
| 604 | indent-tabs-mode t | 599 | indent-tabs-mode t |
| 605 | tab-width 8) | 600 | tab-width 8) |
| 606 | (use-local-map change-log-mode-map) | ||
| 607 | (set (make-local-variable 'fill-paragraph-function) | 601 | (set (make-local-variable 'fill-paragraph-function) |
| 608 | 'change-log-fill-paragraph) | 602 | 'change-log-fill-paragraph) |
| 609 | ;; We really do want "^" in paragraph-start below: it is only the | 603 | ;; We really do want "^" in paragraph-start below: it is only the |
| @@ -616,10 +610,11 @@ Runs `change-log-mode-hook'." | |||
| 616 | ;; is grouped with what follows. | 610 | ;; is grouped with what follows. |
| 617 | (set (make-local-variable 'page-delimiter) "^\\<\\|^\f") | 611 | (set (make-local-variable 'page-delimiter) "^\\<\\|^\f") |
| 618 | (set (make-local-variable 'version-control) 'never) | 612 | (set (make-local-variable 'version-control) 'never) |
| 613 | (set (make-local-variable 'smerge-resolve-function) | ||
| 614 | 'change-log-resolve-conflict) | ||
| 619 | (set (make-local-variable 'adaptive-fill-regexp) "\\s *") | 615 | (set (make-local-variable 'adaptive-fill-regexp) "\\s *") |
| 620 | (set (make-local-variable 'font-lock-defaults) | 616 | (set (make-local-variable 'font-lock-defaults) |
| 621 | '(change-log-font-lock-keywords t nil nil backward-paragraph)) | 617 | '(change-log-font-lock-keywords t nil nil backward-paragraph))) |
| 622 | (run-hooks 'change-log-mode-hook)) | ||
| 623 | 618 | ||
| 624 | ;; It might be nice to have a general feature to replace this. The idea I | 619 | ;; It might be nice to have a general feature to replace this. The idea I |
| 625 | ;; have is a variable giving a regexp matching text which should not be | 620 | ;; have is a variable giving a regexp matching text which should not be |
| @@ -904,18 +899,34 @@ Point is assumed to be at the start of the entry." | |||
| 904 | (error nil))))) | 899 | (error nil))))) |
| 905 | (error "Bad date"))) | 900 | (error "Bad date"))) |
| 906 | 901 | ||
| 902 | (defun change-log-resolve-conflict () | ||
| 903 | "Function to be used in `smerge-resolve-function'." | ||
| 904 | (let ((buf (current-buffer))) | ||
| 905 | (with-temp-buffer | ||
| 906 | (insert-buffer-substring buf (match-beginning 1) (match-end 1)) | ||
| 907 | (save-match-data (change-log-mode)) | ||
| 908 | (let ((other-buf (current-buffer))) | ||
| 909 | (with-current-buffer buf | ||
| 910 | (save-excursion | ||
| 911 | (save-restriction | ||
| 912 | (narrow-to-region (match-beginning 0) (match-end 0)) | ||
| 913 | (replace-match (match-string 3) t t) | ||
| 914 | (change-log-merge other-buf)))))))) | ||
| 915 | |||
| 907 | ;;;###autoload | 916 | ;;;###autoload |
| 908 | (defun change-log-merge (other-log) | 917 | (defun change-log-merge (other-log) |
| 909 | "Merge the contents of ChangeLog file OTHER-LOG with this buffer. | 918 | "Merge the contents of ChangeLog file OTHER-LOG with this buffer. |
| 910 | Both must be found in Change Log mode (since the merging depends on | 919 | Both must be found in Change Log mode (since the merging depends on |
| 911 | the appropriate motion commands). | 920 | the appropriate motion commands). OTHER-LOG can be either a file name |
| 921 | or a buffer. | ||
| 912 | 922 | ||
| 913 | Entries are inserted in chronological order. Both the current and | 923 | Entries are inserted in chronological order. Both the current and |
| 914 | old-style time formats for entries are supported." | 924 | old-style time formats for entries are supported." |
| 915 | (interactive "*fLog file name to merge: ") | 925 | (interactive "*fLog file name to merge: ") |
| 916 | (if (not (eq major-mode 'change-log-mode)) | 926 | (if (not (eq major-mode 'change-log-mode)) |
| 917 | (error "Not in Change Log mode")) | 927 | (error "Not in Change Log mode")) |
| 918 | (let ((other-buf (find-file-noselect other-log)) | 928 | (let ((other-buf (if (bufferp other-log) other-log |
| 929 | (find-file-noselect other-log))) | ||
| 919 | (buf (current-buffer)) | 930 | (buf (current-buffer)) |
| 920 | date1 start end) | 931 | date1 start end) |
| 921 | (save-excursion | 932 | (save-excursion |
| @@ -938,12 +949,16 @@ old-style time formats for entries are supported." | |||
| 938 | (insert-buffer-substring other-buf start end) | 949 | (insert-buffer-substring other-buf start end) |
| 939 | ;; At the end of the original buffer, insert a newline to | 950 | ;; At the end of the original buffer, insert a newline to |
| 940 | ;; separate entries and then the rest of the file being | 951 | ;; separate entries and then the rest of the file being |
| 941 | ;; merged. Move to the end of it to terminate outer loop. | 952 | ;; merged. |
| 942 | (insert "\n") | 953 | (unless (or (bobp) |
| 943 | (insert-buffer-substring other-buf start | 954 | (and (= ?\n (char-before)) |
| 944 | (with-current-buffer other-buf | 955 | (or (<= (1- (point)) (point-min)) |
| 945 | (goto-char (point-max)) | 956 | (= ?\n (char-before (1- (point))))))) |
| 946 | (point))))))))) | 957 | (insert "\n")) |
| 958 | ;; Move to the end of it to terminate outer loop. | ||
| 959 | (with-current-buffer other-buf | ||
| 960 | (goto-char (point-max))) | ||
| 961 | (insert-buffer-substring other-buf start))))))) | ||
| 947 | 962 | ||
| 948 | ;;;###autoload | 963 | ;;;###autoload |
| 949 | (defun change-log-redate () | 964 | (defun change-log-redate () |