Do not display * compile * buffers in Emacs until the process terminates with an error or warning

I am looking for a way to force the Emacs compilation buffer to start using Mx compilation, recompile Mx or compilation while saving the script, only when the compilation fails or with an error.

Please note that I am not looking for a way to close the compilation buffer if there are no errors or warnings, as described in [1]. No. I want the buffer to never appear until the compilation is complete and only appears if an error or warning occurs.

The reasons are simple: the compilation flicker buffer is alarming and changes the position of the code on the screen. It becomes more annoying if you compile while saving.

The compilation buffer contains many different types of compilation processes from make to pdflatex, so it would be great if the function that determines whether the buffer should be displayed works across the board.

[1] Automatically close emacs buffer?

+6
source share
3 answers

It looks like you can achieve what you want by temporarily disabling display-buffer via compilation-start .

This is a combination of what sds said and posted something in the comments @ here

The comment has a nasty problem with point jump in the original source buffer, which I apparently developed, also blocking set-window-point and goto-char . This sounds like a dirty hack, but it still works. YMMV!

 (defun brian-compile-finish (buffer outstr) (unless (string-match "finished" outstr) (switch-to-buffer-other-window buffer)) t) (setq compilation-finish-functions 'brian-compile-finish) (require 'cl) (defadvice compilation-start (around inhibit-display (command &optional mode name-function highlight-regexp)) (if (not (string-match "^\\(find\\|grep\\)" command)) (flet ((display-buffer) (set-window-point) (goto-char)) (fset 'display-buffer 'ignore) (fset 'goto-char 'ignore) (fset 'set-window-point 'ignore) (save-window-excursion ad-do-it)) ad-do-it)) (ad-activate 'compilation-start) 

Now you should see that all compilation buffers will be displayed only if outstr does not return the status of completed completion or a command launched using "find" or "grep."

+4
source

The compilation-start function calls display-buffer in the compilation buffer. This should give you all the control you need.

Ie, you need to configure one of the action variables ( display-buffer-overriding-action et al) so that it handles compilation buffers, especially buying them to be displayed in a separate frame and not displaying the frame itself.

Then you need to configure compilation-filter-hook so that whenever a warning or error is inserted in the compilation buffer, the compilation buffer is visible (for example, popping up the aforementioned single frame). Remember to bind the action variable to nil there!

+1
source

The assects response was a bit ahead of the curve .

The core of Emacs in its wisdom decided to abandon the flet . Suggested alternative to cl-flet . However, as discussed in this post, this seems to be lexically embraced, rather than dynamically. We clearly want dynamic scaling.

Should I replace flet with cl-flet or cl-letf?

This page suggests replacing flet with noflet , a third-party library.

This, apparently, supports only the definition of functions and their bodies. So the flet answer in assem will be

(noflet ((display-buffer ()) ....

0
source

Source: https://habr.com/ru/post/949481/


All Articles