* Show *compilation* only if build did not succeed
@ 2018-12-22 15:12 Amin Bandali
2018-12-22 16:49 ` Stefan Monnier
0 siblings, 1 reply; 7+ messages in thread
From: Amin Bandali @ 2018-12-22 15:12 UTC (permalink / raw)
To: help-gnu-emacs
Hello,
I use a literate init.org configuration for my GNU Emacs, which I
automatically tangle into init.el on each save and then call ‘make’
using something like (compile "make ti").
Here’s my problem: invoking compile creates a new window, and that
annoys me to no end, esp. since I save my init.org frequently while
editing. So I’ve wrapped the call to compile in a call to
save-window-excursion which causes compile to not create a window. But
ideally the window would be created if compilation did not succeed.
Recently I found the following snippet¹ on Stack Overflow:
#+begin_src emacs-lisp
(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)
#+end_src
But the problem with the above is that, if you look at the defadvice, it
uses flet, which has been obsolete since 24.3, and so I get an annoying
warning on every startup (I byte-compile my init.el).
Are there any “modern” solutions for achieving this? If not, it would
be great if one could customize the behaviour of when compile would
create a window, depending on the build result or if the build takes
longer than a certain time threshold.
Thanks,
amin
Footnotes:
¹ https://stackoverflow.com/a/17788551
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Show *compilation* only if build did not succeed
2018-12-22 15:12 Show *compilation* only if build did not succeed Amin Bandali
@ 2018-12-22 16:49 ` Stefan Monnier
2018-12-22 17:52 ` Amin Bandali
0 siblings, 1 reply; 7+ messages in thread
From: Stefan Monnier @ 2018-12-22 16:49 UTC (permalink / raw)
To: help-gnu-emacs
> But the problem with the above is that, if you look at the defadvice, it
> uses flet, which has been obsolete since 24.3, and so I get an annoying
> warning on every startup (I byte-compile my init.el).
> Are there any “modern” solutions for achieving this?
Yes: the two replacements suggested by the warning.
Stefan
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Show *compilation* only if build did not succeed
2018-12-22 16:49 ` Stefan Monnier
@ 2018-12-22 17:52 ` Amin Bandali
2018-12-22 18:21 ` Stefan Monnier
0 siblings, 1 reply; 7+ messages in thread
From: Amin Bandali @ 2018-12-22 17:52 UTC (permalink / raw)
To: Stefan Monnier; +Cc: help-gnu-emacs
On 2018-12-22 11:49 AM, Stefan Monnier wrote:
>
> Yes: the two replacements suggested by the warning.
>
Thanks for the reply, Stefan. I had already tried both, but for some
reason I could not get it to work. I gave it another shot, and it seems
like I got it right this time around.
For future reference, here’s what I ended up with in my config:
#+begin_src emacs-lisp
(defun amin--compilation-finish-function (buffer outstr)
(unless (string-match "finished" outstr)
(switch-to-buffer-other-window buffer))
t)
(setq compilation-finish-functions #'amin--compilation-finish-function)
(require 'cl-macs)
(defadvice compilation-start
(around inhibit-display
(command &optional mode name-function highlight-regexp))
(if (not (string-match "^\\(find\\|grep\\)" command))
(cl-letf (((symbol-function 'display-buffer) #'ignore)
((symbol-function 'set-window-point) #'ignore)
((symbol-function 'goto-char) #'ignore))
(save-window-excursion ad-do-it))
ad-do-it))
(ad-activate 'compilation-start)
#+end_src
Best,
amin
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Show *compilation* only if build did not succeed
2018-12-22 17:52 ` Amin Bandali
@ 2018-12-22 18:21 ` Stefan Monnier
2018-12-22 19:09 ` Amin Bandali
0 siblings, 1 reply; 7+ messages in thread
From: Stefan Monnier @ 2018-12-22 18:21 UTC (permalink / raw)
To: Amin Bandali; +Cc: help-gnu-emacs
> (defadvice compilation-start
> (around inhibit-display
> (command &optional mode name-function highlight-regexp))
> (if (not (string-match "^\\(find\\|grep\\)" command))
> (cl-letf (((symbol-function 'display-buffer) #'ignore)
> ((symbol-function 'set-window-point) #'ignore)
> ((symbol-function 'goto-char) #'ignore))
> (save-window-excursion ad-do-it))
> ad-do-it))
BTW, is the `goto-char` override really effective?
It doesn't affect calls to goto-char made from byte-compiled code, so
there's a good chance that it ends up not doing anything.
Stefan
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Show *compilation* only if build did not succeed
2018-12-22 18:21 ` Stefan Monnier
@ 2018-12-22 19:09 ` Amin Bandali
2018-12-23 14:29 ` Stefan Monnier
0 siblings, 1 reply; 7+ messages in thread
From: Amin Bandali @ 2018-12-22 19:09 UTC (permalink / raw)
To: Stefan Monnier; +Cc: help-gnu-emacs
On 2018-12-22 1:21 PM, Stefan Monnier wrote:
>
> BTW, is the `goto-char` override really effective?
> It doesn't affect calls to goto-char made from byte-compiled code, so
> there's a good chance that it ends up not doing anything.
>
Ha, I think you’re right :) Taking out goto-char and set-window-point
don’t seem to have any effects, that I could tell at least.
Out of curiosity, is there any way to silence the “ad-handle-definition:
‘compilation-start’ got redefined” warning locally? I tried wrapping my
workaround in a (let ((ad-redefinition-action 'accept)) ...), but that
doesn’t seem to do it.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Show *compilation* only if build did not succeed
2018-12-22 19:09 ` Amin Bandali
@ 2018-12-23 14:29 ` Stefan Monnier
2018-12-23 14:59 ` Amin Bandali
0 siblings, 1 reply; 7+ messages in thread
From: Stefan Monnier @ 2018-12-23 14:29 UTC (permalink / raw)
To: Amin Bandali; +Cc: help-gnu-emacs
> Out of curiosity, is there any way to silence the “ad-handle-definition:
> ‘compilation-start’ got redefined” warning locally? I tried wrapping my
> workaround in a (let ((ad-redefinition-action 'accept)) ...), but that
> doesn’t seem to do it.
ad-redefinition-action is consulted when compilation-start is defined
(i.e. when loading compile.el), that's why your let has no effect.
If you use the newer `advice-add` instead of the older `defadvice` you
shouldn't get any warning (it's one of the "features" I didn't bother
to port).
But you can also just do
(setq ad-redefinition-action 'accept)
Stefan
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Show *compilation* only if build did not succeed
2018-12-23 14:29 ` Stefan Monnier
@ 2018-12-23 14:59 ` Amin Bandali
0 siblings, 0 replies; 7+ messages in thread
From: Amin Bandali @ 2018-12-23 14:59 UTC (permalink / raw)
To: Stefan Monnier; +Cc: help-gnu-emacs
Hi Stefan,
On 2018-12-23 9:29 AM, Stefan Monnier wrote:
>> Out of curiosity, is there any way to silence the “ad-handle-definition:
>> ‘compilation-start’ got redefined” warning locally? I tried wrapping my
>> workaround in a (let ((ad-redefinition-action 'accept)) ...), but that
>> doesn’t seem to do it.
>
> ad-redefinition-action is consulted when compilation-start is defined
> (i.e. when loading compile.el), that's why your let has no effect.
>
> If you use the newer `advice-add` instead of the older `defadvice` you
> shouldn't get any warning (it's one of the "features" I didn't bother
> to port).
That makes sense, thanks. And TIL about advice-add! On a side note, it
seems wrapping the workaround in a (with-eval-after-load 'compile ...)
also suppresses the warning, without needing ad-redefinition-action set.
> But you can also just do
>
> (setq ad-redefinition-action 'accept)
Indeed. My reasoning was to try and minimize its effect in my init file
so that I would still be able to see the warning if triggered elsewhere.
>
>
> Stefan
>
Best,
amin
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2018-12-23 14:59 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-12-22 15:12 Show *compilation* only if build did not succeed Amin Bandali
2018-12-22 16:49 ` Stefan Monnier
2018-12-22 17:52 ` Amin Bandali
2018-12-22 18:21 ` Stefan Monnier
2018-12-22 19:09 ` Amin Bandali
2018-12-23 14:29 ` Stefan Monnier
2018-12-23 14:59 ` Amin Bandali
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).