Subject: bug#21555: 25.0.50; per-project *vc-change-log* buffers

From: Juri Linkov <[email-masked]>
Date: Fri, 30 May 2025 09:38:03 +0300

>>> You can already do something similar by using C-x x u to rename the
>>> *vc-change-log* buffer, and then 'g' inside it works to regenerate it.
>> Or (add-hook 'log-view-mode-hook 'rename-uniquely)
>
> Could we have a function that would do such a renaming, but only when
> project differs? E.g. it would take the base buffer name and add the
> abbreviated project root to it.
>
> We could call it 'rename-prefixed-with-project' or something like that.

I tried it, and this works nicely:

#+begin_src emacs-lisp
(defun project-rename-uniquely ()
  (interactive)
  (if-let* ((project (project-current)))
      (let ((base-name (replace-regexp-in-string
                        "\\`\\*\\(.*\\)\\*\\(?:<[0-9]+>\\)?\\'" "\\1"
                        (buffer-name))))
        (rename-buffer (generate-new-buffer-name
                        (project-prefixed-buffer-name base-name)))
        (force-mode-line-update))
    (rename-uniquely)))

(add-hook 'log-view-mode-hook 'project-rename-uniquely)
(add-hook 'diff-mode-hook 'project-rename-uniquely)
#+end_src

> This way one would only have as many log-view buffers as they have projects
> open.

Ah, you meant one buffer per project?  Then maybe add another
similar function without 'generate-new-buffer-name'?
But then it fails with the error "Buffer name is in use".
This means that for one buffer per project the changes should be
in vc and project like in the patch provided by Matthias.

> Might even fix the revert-buffer issue?

The revert-buffer issue can't be fixed with 'generate-new-buffer-name'.