diff options
| author | João Távora | 2018-07-21 15:54:21 +0100 |
|---|---|---|
| committer | João Távora | 2018-07-21 16:02:57 +0100 |
| commit | f96fe57fb76df8e7282f266d42a0d471780e1d75 (patch) | |
| tree | 606f03b770613c87f7a27345105a1afdaacaa83f | |
| parent | 6eac401c238b9c98550c645f3c60df9a9668dc61 (diff) | |
| download | emacs-f96fe57fb76df8e7282f266d42a0d471780e1d75.tar.gz emacs-f96fe57fb76df8e7282f266d42a0d471780e1d75.zip | |
New option to make 'C-x 4 a' use file-less ChangeLog buffers
* doc/emacs/maintaining.texi (Change Log Commands): Document
add-log-dont-create-changelog-file.
* etc/NEWS (Change Logs Mode): Mention
add-log-dont-create-changelog-file.
* lisp/vc/add-log.el (add-log-file-name): Add comment.
(add-log-dont-create-changelog-file): New variable.
(add-log--pseudo-changelog-buffer-name)
(add-log--changelog-buffer-p): New helpers.
(add-log-find-changelog-buffer): New function.
(add-log--pseudo-changelog-buffer-name): Respect
add-log-dont-create-changelog-file.
* lisp/vc/log-edit.el (log-edit-changelog-entries): Use
add-log-find-changelog-buffer.
| -rw-r--r-- | doc/emacs/maintaining.texi | 14 | ||||
| -rw-r--r-- | etc/NEWS | 7 | ||||
| -rw-r--r-- | lisp/vc/add-log.el | 113 | ||||
| -rw-r--r-- | lisp/vc/log-edit.el | 6 |
4 files changed, 103 insertions, 37 deletions
diff --git a/doc/emacs/maintaining.texi b/doc/emacs/maintaining.texi index 024fd9728c5..c59978ebbe2 100644 --- a/doc/emacs/maintaining.texi +++ b/doc/emacs/maintaining.texi | |||
| @@ -1655,10 +1655,18 @@ not just to the next change log entry. You can also use | |||
| 1655 | log files into a buffer in Change Log Mode, preserving the date | 1655 | log files into a buffer in Change Log Mode, preserving the date |
| 1656 | ordering of entries. | 1656 | ordering of entries. |
| 1657 | 1657 | ||
| 1658 | @vindex add-log-dont-create-changelog-file | ||
| 1658 | Version control systems are another way to keep track of changes in | 1659 | Version control systems are another way to keep track of changes in |
| 1659 | your program and keep a change log. In the VC log buffer, typing | 1660 | your program and keep a change log. In these situations, you may not |
| 1660 | @kbd{C-c C-a} (@code{log-edit-insert-changelog}) inserts the relevant | 1661 | want to keep a separate versioned change log file. If |
| 1661 | change log entry, if one exists. @xref{Log Buffer}. | 1662 | @code{add-log-dont-create-changelog-file} is non-@code{nil}, commands |
| 1663 | like @kbd{C-x 4 a} (@code{add-change-log-entry-other-window}) will | ||
| 1664 | record changes in a suitably named temporary buffer instead of a file, | ||
| 1665 | unless such a file already exists. | ||
| 1666 | |||
| 1667 | In either case, you can type @kbd{C-c C-a} | ||
| 1668 | (@code{log-edit-insert-changelog}) in the VC Log buffer to insert the | ||
| 1669 | relevant change log entries, if they exist. @xref{Log Buffer}. | ||
| 1662 | 1670 | ||
| 1663 | @node Format of ChangeLog | 1671 | @node Format of ChangeLog |
| 1664 | @subsection Format of ChangeLog | 1672 | @subsection Format of ChangeLog |
| @@ -217,6 +217,13 @@ navigation and editing of large files. | |||
| 217 | 217 | ||
| 218 | * Changes in Specialized Modes and Packages in Emacs 27.1 | 218 | * Changes in Specialized Modes and Packages in Emacs 27.1 |
| 219 | 219 | ||
| 220 | ** Change Logs and VC | ||
| 221 | |||
| 222 | *** Recording ChangeLog entries doesn't require an actual file | ||
| 223 | An existing file will be used if it already exists. This is | ||
| 224 | controlled by the defcustom 'add-log-dont-create-changelog-file', | ||
| 225 | which defaults to t. | ||
| 226 | |||
| 220 | ** diff-mode | 227 | ** diff-mode |
| 221 | *** Hunks are now automatically refined by default | 228 | *** Hunks are now automatically refined by default |
| 222 | To disable it, set the new defcustom 'diff-font-lock-refine' to nil. | 229 | To disable it, set the new defcustom 'diff-font-lock-refine' to nil. |
diff --git a/lisp/vc/add-log.el b/lisp/vc/add-log.el index 4d69aac454c..5ed43e8c8c4 100644 --- a/lisp/vc/add-log.el +++ b/lisp/vc/add-log.el | |||
| @@ -744,6 +744,7 @@ Optional arg BUFFER-FILE overrides `buffer-file-name'." | |||
| 744 | file-name) | 744 | file-name) |
| 745 | 745 | ||
| 746 | (defun add-log-file-name (buffer-file log-file) | 746 | (defun add-log-file-name (buffer-file log-file) |
| 747 | "Compute file-name of BUFFER-FILE as displayed in LOG-FILE." | ||
| 747 | ;; Never want to add a change log entry for the ChangeLog file itself. | 748 | ;; Never want to add a change log entry for the ChangeLog file itself. |
| 748 | (unless (or (null buffer-file) (string= buffer-file log-file)) | 749 | (unless (or (null buffer-file) (string= buffer-file log-file)) |
| 749 | (if add-log-file-name-function | 750 | (if add-log-file-name-function |
| @@ -767,36 +768,76 @@ Optional arg BUFFER-FILE overrides `buffer-file-name'." | |||
| 767 | (file-name-sans-versions buffer-file) | 768 | (file-name-sans-versions buffer-file) |
| 768 | buffer-file)))) | 769 | buffer-file)))) |
| 769 | 770 | ||
| 770 | ;;;###autoload | 771 | (defcustom add-log-dont-create-changelog-file t |
| 771 | (defun add-change-log-entry (&optional whoami file-name other-window new-entry | 772 | "If non-nil, don't create ChangeLog files for log entries. |
| 772 | put-new-entry-on-new-line) | 773 | This applies only if no pre-existing ChangeLog is found." |
| 773 | "Find change log file, and add an entry for today and an item for this file. | 774 | :type :boolean |
| 774 | Optional arg WHOAMI (interactive prefix) non-nil means prompt for user | 775 | :version "27.1") |
| 775 | name and email (stored in `add-log-full-name' and `add-log-mailing-address'). | ||
| 776 | |||
| 777 | Second arg FILE-NAME is file name of the change log. | ||
| 778 | If nil, use the value of `change-log-default-name'. | ||
| 779 | |||
| 780 | Third arg OTHER-WINDOW non-nil means visit in other window. | ||
| 781 | 776 | ||
| 782 | Fourth arg NEW-ENTRY non-nil means always create a new entry at the front; | 777 | (put 'add-log-dont-create-changelog-file 'safe-local-variable 'booleanp) |
| 783 | never append to an existing entry. Option `add-log-keep-changes-together' | ||
| 784 | otherwise affects whether a new entry is created. | ||
| 785 | 778 | ||
| 786 | Fifth arg PUT-NEW-ENTRY-ON-NEW-LINE non-nil means that if a new | 779 | (defun add-log--pseudo-changelog-buffer-name (changelog-file-name) |
| 787 | entry is created, put it on a new line by itself, do not put it | 780 | "Compute suitable name for a non-file ChangeLog buffer. |
| 788 | after a comma on an existing line. | 781 | CHANGELOG-FILE-NAME is the file name of the actual ChangeLog file |
| 782 | if it were to exist." | ||
| 783 | (format "*changes to %s*" | ||
| 784 | (abbreviate-file-name | ||
| 785 | (file-name-directory changelog-file-name)))) | ||
| 789 | 786 | ||
| 790 | Option `add-log-always-start-new-record' non-nil means always create a | 787 | (defun add-log--changelog-buffer-p (changelog-file-name buffer) |
| 791 | new record, even when the last record was made on the same date and by | 788 | "Tell if BUFFER holds a ChangeLog for CHANGELOG-FILE-NAME." |
| 792 | the same person. | 789 | (with-current-buffer buffer |
| 793 | 790 | (if buffer-file-name | |
| 794 | The change log file can start with a copyright notice and a copying | 791 | (equal buffer-file-name changelog-file-name) |
| 795 | permission notice. The first blank line indicates the end of these | 792 | (equal (add-log--pseudo-changelog-buffer-name changelog-file-name) |
| 796 | notices. | 793 | (buffer-name))))) |
| 794 | |||
| 795 | (defun add-log-find-changelog-buffer (changelog-file-name) | ||
| 796 | "Find a ChangeLog buffer for CHANGELOG-FILE-NAME. | ||
| 797 | Respect `add-log-use-pseudo-changelog', which see." | ||
| 798 | (if (or (file-exists-p changelog-file-name) | ||
| 799 | (not add-log-dont-create-changelog-file)) | ||
| 800 | (find-file-noselect changelog-file-name) | ||
| 801 | (get-buffer-create | ||
| 802 | (add-log--pseudo-changelog-buffer-name changelog-file-name)))) | ||
| 797 | 803 | ||
| 798 | Today's date is calculated according to `add-log-time-zone-rule' if | 804 | ;;;###autoload |
| 799 | non-nil, otherwise in local time." | 805 | (defun add-change-log-entry (&optional whoami |
| 806 | changelog-file-name | ||
| 807 | other-window new-entry | ||
| 808 | put-new-entry-on-new-line) | ||
| 809 | "Find ChangeLog buffer, add an entry for today and an item for this file. | ||
| 810 | Optional arg WHOAMI (interactive prefix) non-nil means prompt for | ||
| 811 | user name and email (stored in `add-log-full-name' and | ||
| 812 | `add-log-mailing-address'). | ||
| 813 | |||
| 814 | Second arg CHANGELOG-FILE-NAME is file name of the change log. | ||
| 815 | If nil, use the value of `change-log-default-name'. If the file | ||
| 816 | thus named exists, it's used for the new entry. If it doesn't | ||
| 817 | exist, it is created, unless `add-log-dont-create-changelog-file' is t, | ||
| 818 | in which case a suitably named file-less buffer is used for | ||
| 819 | keeping entries pertaining to CHANGELOG-FILE-NAME's directory. | ||
| 820 | |||
| 821 | Third arg OTHER-WINDOW non-nil means visit in other window. | ||
| 822 | |||
| 823 | Fourth arg NEW-ENTRY non-nil means always create a new entry at the front; | ||
| 824 | never append to an existing entry. Option `add-log-keep-changes-together' | ||
| 825 | otherwise affects whether a new entry is created. | ||
| 826 | |||
| 827 | Fifth arg PUT-NEW-ENTRY-ON-NEW-LINE non-nil means that if a new | ||
| 828 | entry is created, put it on a new line by itself, do not put it | ||
| 829 | after a comma on an existing line. | ||
| 830 | |||
| 831 | Option `add-log-always-start-new-record' non-nil means always create a | ||
| 832 | new record, even when the last record was made on the same date and by | ||
| 833 | the same person. | ||
| 834 | |||
| 835 | The change log file can start with a copyright notice and a copying | ||
| 836 | permission notice. The first blank line indicates the end of these | ||
| 837 | notices. | ||
| 838 | |||
| 839 | Today's date is calculated according to `add-log-time-zone-rule' if | ||
| 840 | non-nil, otherwise in local time." | ||
| 800 | (interactive (list current-prefix-arg | 841 | (interactive (list current-prefix-arg |
| 801 | (prompt-for-change-log-name))) | 842 | (prompt-for-change-log-name))) |
| 802 | (let* ((defun (add-log-current-defun)) | 843 | (let* ((defun (add-log-current-defun)) |
| @@ -804,20 +845,28 @@ non-nil, otherwise in local time." | |||
| 804 | (change-log-version-number-search))) | 845 | (change-log-version-number-search))) |
| 805 | (buf-file-name (funcall add-log-buffer-file-name-function)) | 846 | (buf-file-name (funcall add-log-buffer-file-name-function)) |
| 806 | (buffer-file (if buf-file-name (expand-file-name buf-file-name))) | 847 | (buffer-file (if buf-file-name (expand-file-name buf-file-name))) |
| 807 | (file-name (expand-file-name (find-change-log file-name buffer-file))) | 848 | (changelog-file-name (expand-file-name (find-change-log |
| 849 | changelog-file-name | ||
| 850 | buffer-file))) | ||
| 808 | ;; Set ITEM to the file name to use in the new item. | 851 | ;; Set ITEM to the file name to use in the new item. |
| 809 | (item (add-log-file-name buffer-file file-name))) | 852 | (item (add-log-file-name buffer-file changelog-file-name))) |
| 810 | 853 | ||
| 811 | (unless (equal file-name buffer-file-name) | 854 | ;; don't add entries from the ChangeLog file/buffer to itself. |
| 855 | (unless (equal changelog-file-name buffer-file-name) | ||
| 812 | (cond | 856 | (cond |
| 813 | ((equal file-name (buffer-file-name (window-buffer))) | 857 | ((add-log--changelog-buffer-p |
| 858 | changelog-file-name | ||
| 859 | (window-buffer)) | ||
| 814 | ;; If the selected window already shows the desired buffer don't show | 860 | ;; If the selected window already shows the desired buffer don't show |
| 815 | ;; it again (particularly important if other-window is true). | 861 | ;; it again (particularly important if other-window is true). |
| 816 | ;; This is important for diff-add-change-log-entries-other-window. | 862 | ;; This is important for diff-add-change-log-entries-other-window. |
| 817 | (set-buffer (window-buffer))) | 863 | (set-buffer (window-buffer))) |
| 818 | ((or other-window (window-dedicated-p)) | 864 | ((or other-window (window-dedicated-p)) |
| 819 | (find-file-other-window file-name)) | 865 | (switch-to-buffer-other-window |
| 820 | (t (find-file file-name)))) | 866 | (add-log-find-changelog-buffer changelog-file-name))) |
| 867 | (t | ||
| 868 | (switch-to-buffer | ||
| 869 | (add-log-find-changelog-buffer changelog-file-name))))) | ||
| 821 | (or (derived-mode-p 'change-log-mode) | 870 | (or (derived-mode-p 'change-log-mode) |
| 822 | (change-log-mode)) | 871 | (change-log-mode)) |
| 823 | (undo-boundary) | 872 | (undo-boundary) |
diff --git a/lisp/vc/log-edit.el b/lisp/vc/log-edit.el index 6ff782a6061..90860fbdcfe 100644 --- a/lisp/vc/log-edit.el +++ b/lisp/vc/log-edit.el | |||
| @@ -913,8 +913,10 @@ where LOGBUFFER is the name of the ChangeLog buffer, and each | |||
| 913 | (setq change-log-default-name nil) | 913 | (setq change-log-default-name nil) |
| 914 | (find-change-log))))) | 914 | (find-change-log))))) |
| 915 | (when (or (find-buffer-visiting changelog-file-name) | 915 | (when (or (find-buffer-visiting changelog-file-name) |
| 916 | (file-exists-p changelog-file-name)) | 916 | (file-exists-p changelog-file-name) |
| 917 | (with-current-buffer (find-file-noselect changelog-file-name) | 917 | add-log-dont-create-changelog-file) |
| 918 | (with-current-buffer | ||
| 919 | (add-log-find-changelog-buffer changelog-file-name) | ||
| 918 | (unless (eq major-mode 'change-log-mode) (change-log-mode)) | 920 | (unless (eq major-mode 'change-log-mode) (change-log-mode)) |
| 919 | (goto-char (point-min)) | 921 | (goto-char (point-min)) |
| 920 | (if (looking-at "\\s-*\n") (goto-char (match-end 0))) | 922 | (if (looking-at "\\s-*\n") (goto-char (match-end 0))) |