[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] New option to make C-x 4 a use file-less ChangeLog buffers (was
From: |
João Távora |
Subject: |
[PATCH] New option to make C-x 4 a use file-less ChangeLog buffers (was Re: git history tracking across renames (and emacs support)) |
Date: |
Sat, 14 Jul 2018 18:36:57 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) |
Eli Zaretskii <address@hidden> writes:
> [...] perhaps add-log.el could be extended to be able to use a buffer
> name, not just a file name, for where to put the log messages. It
> already allows you to customize the file name; it could do something
> similar with a buffer name, and that buffer could have no file name.
> Then a large part of your problems would go away, AFAIU.
Hi Eli,
Find attached a patch that does exactly this. It is only lightly
tested, so I need a clinical eye that I didn't break anything.
Fortunately, it is quite short. Appropriately, I used it to compose the
commit message (and I don't have any ChangeLog files lying around).
If this is accepted, I can submit more patches for more related
functionality. The next two I imagine, in this order, are:
* C-c C-c (commit-time in vc-log) somehow disables the entries collected
by C-c C-a in the ChangeLog buffer.
* Use a single ChangeLog buffer indexed by projects (Stefan's idea)
Thanks,
João
>From 867540c9310ee12ca477e744571d93f56f5f888d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jo=C3=A3o=20T=C3=A1vora?= <address@hidden>
Date: Sat, 14 Jul 2018 18:29:48 +0100
Subject: [PATCH] New option to make C-x 4 a use file-less ChangeLog buffers
* lisp/vc/add-log.el (add-log-file-name): Update docstring.
(add-log-use-pseudo-changelog): New defcustom.
(add-log-find-changelog-buffer): New helper.
(add-change-log-entry): Can work with ChangeLog file-less
buffers. Change name of argument FILE-NAME arg to be more
explicit. Explain new meaning of arg in docstring.
(add-log--changelog-buffer-p): New helper.
* lisp/vc/log-edit.el (log-edit-changelog-entries): Use
add-log-use-pseudo-changelog and add-log-find-changelog-buffer.
---
lisp/vc/add-log.el | 67 +++++++++++++++++++++++++++++++++++++--------
lisp/vc/log-edit.el | 6 ++--
2 files changed, 59 insertions(+), 14 deletions(-)
diff --git a/lisp/vc/add-log.el b/lisp/vc/add-log.el
index 4d69aac454..983024327c 100644
--- a/lisp/vc/add-log.el
+++ b/lisp/vc/add-log.el
@@ -744,6 +744,7 @@ find-change-log
file-name)
(defun add-log-file-name (buffer-file log-file)
+ "Compute file-name of BUFFER-FILE as displayed in LOG-FILE."
;; Never want to add a change log entry for the ChangeLog file itself.
(unless (or (null buffer-file) (string= buffer-file log-file))
(if add-log-file-name-function
@@ -767,15 +768,49 @@ add-log-file-name
(file-name-sans-versions buffer-file)
buffer-file))))
+(defcustom add-log-use-pseudo-changelog nil
+ "If non-nil, don't create ChangeLog files for log entries."
+ :type :boolean)
+
+(put 'add-log-use-pseudo-changelog 'safe-local-variable 'booleanp)
+
+(defun add-log--pseudo-changelog-buffer-name (changelog-file-name)
+ "Compute suitable name for a pseudo-ChangeLog buffer."
+ (format "*PseudoChangeLog for %s*"
+ (file-name-directory changelog-file-name)))
+
+(defun add-log--changelog-buffer-p (changelog-file-name buffer)
+ "Tell if BUFFER is a ChangeLog for CHANGELOG-FILE-NAME."
+ (with-current-buffer buffer
+ (if buffer-file-name
+ (equal buffer-file-name changelog-file-name)
+ (equal (add-log--pseudo-changelog-buffer-name changelog-file-name)
+ (buffer-name)))))
+
+(defun add-log-find-changelog-buffer (changelog-file-name)
+ "Find a ChangeLog buffer for CHANGELOG-FILE-NAME.
+Respect `add-log-use-pseudo-changelog', which see."
+ (if (or (file-exists-p changelog-file-name)
+ (not add-log-use-pseudo-changelog))
+ (find-file-noselect changelog-file-name)
+ (get-buffer-create
+ (add-log--pseudo-changelog-buffer-name changelog-file-name))))
+
;;;###autoload
-(defun add-change-log-entry (&optional whoami file-name other-window new-entry
+(defun add-change-log-entry (&optional whoami
+ changelog-file-name
+ other-window new-entry
put-new-entry-on-new-line)
- "Find change log file, and add an entry for today and an item for this file.
-Optional arg WHOAMI (interactive prefix) non-nil means prompt for user
-name and email (stored in `add-log-full-name' and `add-log-mailing-address').
+ "Find ChangeLog buffer, add an entry for today and an item for this file.
+Optional arg WHOAMI (interactive prefix) non-nil means prompt for
+user name and email (stored in `add-log-full-name' and
+`add-log-mailing-address').
-Second arg FILE-NAME is file name of the change log.
-If nil, use the value of `change-log-default-name'.
+Second arg CHANGELOG-FILE-NAME is file name of the change log.
+If nil, use the value of `change-log-default-name'. If the file
+thus named exists, it's used for the new entry. If it doesn't
+exist, it is created, unless `add-log-use-pseudo-changelog' in
+which case a suitably named file-less buffer is used.
Third arg OTHER-WINDOW non-nil means visit in other window.
@@ -804,20 +839,28 @@ add-change-log-entry
(change-log-version-number-search)))
(buf-file-name (funcall add-log-buffer-file-name-function))
(buffer-file (if buf-file-name (expand-file-name buf-file-name)))
- (file-name (expand-file-name (find-change-log file-name buffer-file)))
+ (changelog-file-name (expand-file-name (find-change-log
+ changelog-file-name
+ buffer-file)))
;; Set ITEM to the file name to use in the new item.
- (item (add-log-file-name buffer-file file-name)))
+ (item (add-log-file-name buffer-file changelog-file-name)))
- (unless (equal file-name buffer-file-name)
+ ;; don't add entries from the ChangeLog file/buffer to itself.
+ (unless (equal changelog-file-name buffer-file-name)
(cond
- ((equal file-name (buffer-file-name (window-buffer)))
+ ((add-log--changelog-buffer-p
+ changelog-file-name
+ (window-buffer))
;; If the selected window already shows the desired buffer don't show
;; it again (particularly important if other-window is true).
;; This is important for diff-add-change-log-entries-other-window.
(set-buffer (window-buffer)))
((or other-window (window-dedicated-p))
- (find-file-other-window file-name))
- (t (find-file file-name))))
+ (switch-to-buffer-other-window
+ (add-log-find-changelog-buffer changelog-file-name)))
+ (t
+ (switch-to-buffer
+ (add-log-find-changelog-buffer changelog-file-name)))))
(or (derived-mode-p 'change-log-mode)
(change-log-mode))
(undo-boundary)
diff --git a/lisp/vc/log-edit.el b/lisp/vc/log-edit.el
index 6ff782a606..f071d029a5 100644
--- a/lisp/vc/log-edit.el
+++ b/lisp/vc/log-edit.el
@@ -913,8 +913,10 @@ log-edit-changelog-entries
(setq change-log-default-name nil)
(find-change-log)))))
(when (or (find-buffer-visiting changelog-file-name)
- (file-exists-p changelog-file-name))
- (with-current-buffer (find-file-noselect changelog-file-name)
+ (file-exists-p changelog-file-name)
+ add-log-use-pseudo-changelog)
+ (with-current-buffer
+ (add-log-find-changelog-buffer changelog-file-name)
(unless (eq major-mode 'change-log-mode) (change-log-mode))
(goto-char (point-min))
(if (looking-at "\\s-*\n") (goto-char (match-end 0)))
--
2.17.1
- Re: git history tracking across renames (and emacs support), (continued)
- Re: git history tracking across renames (and emacs support), Stefan Monnier, 2018/07/12
- Re: git history tracking across renames (and emacs support), João Távora, 2018/07/12
- Re: git history tracking across renames (and emacs support), Eli Zaretskii, 2018/07/12
- Re: git history tracking across renames (and emacs support), Ted Zlatanov, 2018/07/12
- Re: git history tracking across renames (and emacs support), Eli Zaretskii, 2018/07/13
- Re: git history tracking across renames (and emacs support), Stefan Monnier, 2018/07/12
- Re: git history tracking across renames (and emacs support), João Távora, 2018/07/12
- Re: git history tracking across renames (and emacs support), Stefan Monnier, 2018/07/13
- [PATCH] New option to make C-x 4 a use file-less ChangeLog buffers (was Re: git history tracking across renames (and emacs support)),
João Távora <=
- Re: [PATCH] New option to make C-x 4 a use file-less ChangeLog buffers, Basil L. Contovounesios, 2018/07/15
- Re: [PATCH] New option to make C-x 4 a use file-less ChangeLog buffers, João Távora, 2018/07/15
- Re: [PATCH] New option to make C-x 4 a use file-less ChangeLog buffers, Basil L. Contovounesios, 2018/07/15
- Re: [PATCH] New option to make C-x 4 a use file-less ChangeLog buffers (was Re: git history tracking across renames (and emacs support)), Stefan Monnier, 2018/07/15
- Re: [PATCH] New option to make C-x 4 a use file-less ChangeLog buffers (was Re: git history tracking across renames (and emacs support)), João Távora, 2018/07/16
- Re: [PATCH] New option to make C-x 4 a use file-less ChangeLog buffers (was Re: git history tracking across renames (and emacs support)), Stefan Monnier, 2018/07/16
- Re: [PATCH] New option to make C-x 4 a use file-less ChangeLog buffers (was Re: git history tracking across renames (and emacs support)), João Távora, 2018/07/16
- Re: [PATCH] New option to make C-x 4 a use file-less ChangeLog buffers (was Re: git history tracking across renames (and emacs support)), Stefan Monnier, 2018/07/16
- Re: [PATCH] New option to make C-x 4 a use file-less ChangeLog buffers (was Re: git history tracking across renames (and emacs support)), João Távora, 2018/07/16
- Re: [PATCH] New option to make C-x 4 a use file-less ChangeLog buffers (was Re: git history tracking across renames (and emacs support)), Stefan Monnier, 2018/07/16