* Waiting on compilation to finish before executing another function
@ 2013-08-15 17:36 Rami A
2013-08-15 17:48 ` Dan Espen
` (2 more replies)
0 siblings, 3 replies; 13+ messages in thread
From: Rami A @ 2013-08-15 17:36 UTC (permalink / raw)
To: help-gnu-emacs
Greetings,
I am using compile to pulling new files from source tree using mercurial "hg pull".
I am performing a save of all buffers before the pull and would like to "refresh all opened buffers" after the compilation "pulling" finishes.
I tried experimenting with compilation-finish-functions but found out that the functions added to the list will be executed after "every" compilation. Since I use compile to search IDs "gid" I don't want to refresh opened files on every search.
How can I wait on compilation to finish before refreshing opened files "only" while inside a command and not on every compile outside of the command.
Here is the code:
; From http://www.emacswiki.org/emacs/CompileCommand
(defun compile-pkg (&optional command startdir)
"Compile a package, moving up to the parent directory
containing configure.ac, if it exists. Start in startdir if defined,
else start in the current directory."
(interactive)
(let ((dirname) (dir-buffer nil))
(setq startdir (expand-file-name (if startdir startdir ".")))
(setq command (if command command compile-command))
(setq dirname (upward-find-file "Makefile" startdir))
; (setq dirname (if dirname dirname (upward-find-file "Makefile" startdir)))
; (setq dirname (if dirname dirname (expand-file-name ".")))
; We've now worked out where to start. Now we need to worry about
; calling compile in the right directory
(save-excursion
(setq dir-buffer (find-file-noselect dirname))
(set-buffer dir-buffer)
(compile command)
(kill-buffer dir-buffer)
)))
(defun upward-find-file (filename &optional startdir)
"Move up directories until we find a certain filename. If we
manage to find it, return the containing directory. Else if we
get to the toplevel directory and still can't find it, return
nil. Start at startdir or . if startdir not given"
(let ((dirname (expand-file-name
(if startdir startdir ".")))
(found nil) ; found is set as a flag to leave loop if we find it
(top nil)) ; top is set when we get
; to / so that we only check it once
; While we've neither been at the top last time nor have we found
; the file.
(while (not (or found top))
; If we're at / set top flag.
(if (string= (expand-file-name dirname) "/")
(setq top t))
; Check for the file
(if (file-exists-p (expand-file-name filename dirname))
(setq found t)
; If not, move up a directory
(setq dirname (expand-file-name ".." dirname))))
; return statement
(if found (concat dirname "/") nil)))
(defun compile-hgpull ()
(interactive)
(save-all-buffers)
(compile-pkg "/import/ftap-rust1/tools/bin/hg pull -u")
; if (compile finished) -> (revert-all-buffers)
)
(global-set-key [f1] 'compile-hgpull)
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Waiting on compilation to finish before executing another function
2013-08-15 17:36 Waiting on compilation to finish before executing another function Rami A
@ 2013-08-15 17:48 ` Dan Espen
2013-08-15 17:53 ` Rami A
2013-08-15 21:14 ` Thien-Thi Nguyen
[not found] ` <mailman.113.1376601089.10748.help-gnu-emacs@gnu.org>
2 siblings, 1 reply; 13+ messages in thread
From: Dan Espen @ 2013-08-15 17:48 UTC (permalink / raw)
To: help-gnu-emacs
Rami A <rami.ammari@gmail.com> writes:
> Greetings,
>
> I am using compile to pulling new files from source tree using
> mercurial "hg pull". I am performing a save of all buffers before the
> pull and would like to "refresh all opened buffers" after the
> compilation "pulling" finishes.
I have a couple of compile procedures I run that change the source file.
I generally don't worry about it. If I go to make any kind of a change
to my source file, Emacs detects that the file has changed and asks me
what I want to do.
So, I just start making changes and when the prompt appears I type
"r" (revert). The one extra character doesn't seem like it's worth
worrying about.
--
Dan Espen
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Waiting on compilation to finish before executing another function
2013-08-15 17:48 ` Dan Espen
@ 2013-08-15 17:53 ` Rami A
2013-08-15 18:04 ` Dan Espen
` (2 more replies)
0 siblings, 3 replies; 13+ messages in thread
From: Rami A @ 2013-08-15 17:53 UTC (permalink / raw)
To: help-gnu-emacs
Thanks Dan.
I am aware of the way emacs alert you if a the file changed on disk.
Unfortunately, I do a lot of "code review" before making any change, so looking at stale data is not a good thing.
I could have included (revert-all-buffers) right after the compile command but sometimes pulling take long enough that refreshing the files happened before the completion of updating the files.
I am sure there is a way to wait on compile before proceeding forward.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Waiting on compilation to finish before executing another function
2013-08-15 17:36 Waiting on compilation to finish before executing another function Rami A
2013-08-15 17:48 ` Dan Espen
@ 2013-08-15 21:14 ` Thien-Thi Nguyen
[not found] ` <mailman.113.1376601089.10748.help-gnu-emacs@gnu.org>
2 siblings, 0 replies; 13+ messages in thread
From: Thien-Thi Nguyen @ 2013-08-15 21:14 UTC (permalink / raw)
To: Rami A; +Cc: help-gnu-emacs
[-- Attachment #1: Type: text/plain, Size: 932 bytes --]
() Rami A <rami.ammari@gmail.com>
() Thu, 15 Aug 2013 10:36:21 -0700 (PDT)
I tried experimenting with compilation-finish-functions but found out
that the functions added to the list will be executed after "every"
compilation. Since I use compile to search IDs "gid" I don't want to
refresh opened files on every search.
For the compilation that does the pull, set a buffer-local variable
to note the case. Then add to ‘compilation-finish-function’ a function
that does ‘revert-all-buffers’ only if indicated by that variable.
Actually, ‘compile’ normally sets a bunch of buffer-local variables
itself. For instance, you could check ‘compilation-arguments’.
--
Thien-Thi Nguyen
GPG key: 4C807502
(if you're human and you know it)
read my lisp: (responsep (questions 'technical)
(not (via 'mailing-list)))
=> nil
[-- Attachment #2: Type: application/pgp-signature, Size: 197 bytes --]
^ permalink raw reply [flat|nested] 13+ messages in thread
[parent not found: <mailman.113.1376601089.10748.help-gnu-emacs@gnu.org>]
* Re: Waiting on compilation to finish before executing another function
[not found] ` <mailman.113.1376601089.10748.help-gnu-emacs@gnu.org>
@ 2013-08-15 21:46 ` Rami A
2013-08-15 22:41 ` Rami A
0 siblings, 1 reply; 13+ messages in thread
From: Rami A @ 2013-08-15 21:46 UTC (permalink / raw)
To: help-gnu-emacs
Thien,
That's a good idea.
I am not an expert in elisp. Could you help me implement the local variable as you suggested in this function and conditionally hooking it to‘compilation-finish-functions’ :
(defun compile-hgpull ()
(interactive)
(save-all-buffers)
(compile-pkg "hg pull -u")
; if (compile finished) -> (revert-all-buffers)
)
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Waiting on compilation to finish before executing another function
2013-08-15 21:46 ` Rami A
@ 2013-08-15 22:41 ` Rami A
2013-08-15 23:03 ` Rami A
2013-08-15 23:11 ` Óscar Fuentes
0 siblings, 2 replies; 13+ messages in thread
From: Rami A @ 2013-08-15 22:41 UTC (permalink / raw)
To: help-gnu-emacs
Ok. I tried something like this, but I keep getting errors, any pointers?
(setq compilevar nil)
(defun compile-hgpull ()
(interactive)
(save-all-buffers)
(setq compilevar 1)
(compile-pkg "hg pull -u"))
(defun notify-compilation-result ()
(if compilevar (revert-all-buffers))
(setq compilevar nil)
)
(add-to-list 'compilation-finish-functions
'notify-compilation-result)
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Waiting on compilation to finish before executing another function
2013-08-15 22:41 ` Rami A
@ 2013-08-15 23:03 ` Rami A
2013-08-15 23:11 ` Óscar Fuentes
1 sibling, 0 replies; 13+ messages in thread
From: Rami A @ 2013-08-15 23:03 UTC (permalink / raw)
To: help-gnu-emacs
Ok. I fixed it:
(setq compilevar "Bad")
(defun compile-hgpull ()
(interactive)
(save-all-buffers)
(setq compilevar "Good")
(compile-pkg "hg pull -u"))
(defun notify-compilation-result ()
(if (string-match "Good" compilevar)
(progn (setq compilevar "Bad")
(revert-all-buffers))))
(add-to-list 'compilation-finish-functions
'notify-compilation-result)
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Waiting on compilation to finish before executing another function
2013-08-15 22:41 ` Rami A
2013-08-15 23:03 ` Rami A
@ 2013-08-15 23:11 ` Óscar Fuentes
1 sibling, 0 replies; 13+ messages in thread
From: Óscar Fuentes @ 2013-08-15 23:11 UTC (permalink / raw)
To: help-gnu-emacs
Rami A <rami.ammari@gmail.com> writes:
> Ok. I tried something like this, but I keep getting errors, any pointers?
>
> (setq compilevar nil)
> (defun compile-hgpull ()
> (interactive)
> (save-all-buffers)
> (setq compilevar 1)
> (compile-pkg "hg pull -u"))
>
> (defun notify-compilation-result ()
> (if compilevar (revert-all-buffers))
> (setq compilevar nil)
> )
>
> (add-to-list 'compilation-finish-functions
> 'notify-compilation-result)
For assigning a buffer-local variable you use `setq-local', which sets
the variable associated to the *current* buffer. That's the other piece
missing in your code. So make sure that `compile-pkg' returns the buffer
returned by `compile' and replacing your compile-hgpull with this should
do the trick:
(defun compile-hgpull ()
(interactive)
(save-all-buffers)
(with-current-buffer (compile-pkg "hg pull -u")
(setq-local compilevar 1))
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2013-08-16 1:43 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-08-15 17:36 Waiting on compilation to finish before executing another function Rami A
2013-08-15 17:48 ` Dan Espen
2013-08-15 17:53 ` Rami A
2013-08-15 18:04 ` Dan Espen
2013-08-15 18:11 ` Rami A
2013-08-15 18:41 ` Eli Zaretskii
[not found] ` <mailman.103.1376592065.10748.help-gnu-emacs@gnu.org>
2013-08-15 18:53 ` Rami A
2013-08-16 1:43 ` Stefan Monnier
2013-08-15 21:14 ` Thien-Thi Nguyen
[not found] ` <mailman.113.1376601089.10748.help-gnu-emacs@gnu.org>
2013-08-15 21:46 ` Rami A
2013-08-15 22:41 ` Rami A
2013-08-15 23:03 ` Rami A
2013-08-15 23:11 ` Óscar Fuentes
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).