emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: project-compilation-buffer-name-function and recompile


From: Dmitry Gutov
Subject: Re: project-compilation-buffer-name-function and recompile
Date: Fri, 19 Jan 2024 02:45:19 +0200
User-agent: Mozilla Thunderbird

Hi!

On 17/01/2024 22:54, Jörg Bornemann wrote:
Hi,

One can use project-compile to build a project and then call recompile
to repeat the compilation.  This reuses the buffer named
"*compilation*".

If I set project-compilation-buffer-name-function to
#'project-prefixed-buffer-name, this creates a compilation buffer
"*myproject-compilation*" when executing project-compile.  Now,
recompile won't re-use "*myproject-compilation*" but create a new
buffer "*compilation*".

To reproduce this behavior, it is enough to start Emacs like this:
$ emacs -Q --eval "(setq project-compilation-buffer-name-function #'project-prefixed-buffer-name)"

It would be nice if recompile could re-use project-compile's buffer name.  I have fixed this locally by setting compilation-buffer-name-function like this:

---snip---
   (defun my-compilation-buffer-name (name-of-mode)
     (if (project-current)
        (apply project-compilation-buffer-name-function (list name-of-mode))
       (compilation--default-buffer-name name-of-mode)))

   (setq compilation-buffer-name-function #'my-compilation-buffer-name)
---snap---

This works.

Alternatively, you could add around-advice to recompile which would temporarily bind compilation-buffer-file-name-function.

Although I'm thinking by now that it might be more consistent to have a separate project-recompile command in addition to
recompile.  What do you think?

The command could look like this:

  (defun project-recompile (&optional edit-command)
    (interactive "P")
(let ((compilation-buffer-name-function project-compilation-buffer-name-function ))
      (recompile edit-command)))

It probably doesn't deserve a default key binding in project-prefix-map, but you could the same way to invoke it as you did with 'recompile'.

TBF, whenever I need to do a recompile-y action, I usually switch to the corresponding compilation buffer and press 'g'. That usually has the same effect and doesn't require remembering an extra command.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]