mohkale / compile-multi

Multi target interface to compile.
GNU General Public License v3.0
23 stars 3 forks source link

Support recompile and some recompile on save mode #8

Open terlar opened 3 months ago

terlar commented 3 months ago

Would it make sense to add support for recompile, basically re-running the previous compile command that was used?

With this there could be a command similar to what recompile is to compile.

Also for compile I have created something like:

  (defun compile-on-save-start ()
    (let ((compile-buffer (compilation-find-buffer)))
      (unless (get-buffer-process compile-buffer)
        (let ((display-buffer-alist '(("^*compilation*" . (display-buffer-no-window)))))
          (recompile)))))

  (define-minor-mode compile-on-save-mode
    "Minor mode to automatically call `recompile' whenever the
current buffer is saved. When there is ongoing compilation,
nothing happens."
    :lighter " CoS"
    (if compile-on-save-mode
        (progn  (make-local-variable 'after-save-hook)
                (add-hook 'after-save-hook 'compile-on-save-start nil t))
      (kill-local-variable 'after-save-hook)))

With recompile functionality something similar could be added to compile-multi. Do you think it makes sense?

mohkale commented 3 months ago

Hi,

Thanks for opening this issue.

Would it make sense to add support for recompile, basically re-running the previous compile command that was used?

Could you clarify your intentions a little more. If you use compile-multi to run something that eventually calls compile then you should just be able to use M-x recompile already. If the goal is M-x recompile but for compile-multi targets that are interactive commands then that will be a little trickier. A nicer interface might just be to figure out a way to bind that to M-x repeat.

compile-on-save-mode

That's neat, although a little specific to what kind of compilation you mean to run. A web server for example would make sense, but I think you'll have a better UX by using something like watchdog to respawn the command than relying on Emacs. There's also the complication that this mode can't be active in 2 buffers at once without conflicts :thinking:. If you'd like I can open up the wiki for this repo and you can share this there. Others might benefit from it.

terlar commented 3 months ago

I would like to be able to re-run the last compile-multi command that was executed for a specific buffer. I guess the tricky thing with repeat would be that I assume you cannot run any other commands in-between?

The use case are manifold, it could be for example working on a diagram like D2/Mermaid/PlantUML and then you have configured compile-multi to hook up to one of the corresponding functions. Or you are executing some tests via compile-multi and are making changes to the test/implementation.

You might have multiple commands defined (of course), then instead of having to select every time, it could remember the last one and you could rerun that one.

If there was a re-run last compile-multi command you could also hook it up to something like I describe up there, where you re-run the last compile-multi command on save.

I agree, that there are cases for some targets where it would not make sense. Many of the targets will be elisp functions and thus won't be convenient to trigger in another way.

mohkale commented 3 months ago

I'd be willing to accept a PR for this so long as the end result isn't too configusing but have no plans to priorities it myself :-).

MassimoLauria commented 2 months ago

My low-tech solution for recompiling is this code here. Unfortunately, it only works with shell command and not with elisp functions. There is no caching of the last function called.

(defun mxl/compile-multi-recompile ()
  (interactive)
  (if (and compile-command
           (equal compilation-directory
                  (or (funcall compile-multi-default-directory)  ;; in a project
                      default-directory                          ;; not in a project
                      )))
      (recompile)
    (compile-multi)))