* Run function in background.
@ 2011-06-01 10:19 Oleksandr Gavenko
2011-06-01 10:40 ` Oleksandr Gavenko
0 siblings, 1 reply; 3+ messages in thread
From: Oleksandr Gavenko @ 2011-06-01 10:19 UTC (permalink / raw)
To: help-gnu-emacs
I need use auto update for GNU Global:
$ global -u
There described how this done:
http://www.emacswiki.org/emacs/GnuGlobal
But this:
(defun gtags-root-dir ()
"Returns GTAGS root directory or nil if doesn't exist."
(with-temp-buffer
(if (zerop (call-process "global" nil t nil "-pr"))
(buffer-substring (point-min) (1- (point-max)))
nil)))
(defun gtags-update ()
"Make GTAGS incremental update"
(call-process "global" nil nil nil "-u"))
(defun gtags-update-hook ()
(when (gtags-root-dir)
(gtags-update)))
(add-hook 'after-save-hook #'gtags-update-hook)
cause freezing Emacs for about 2-3 sec. How run this in background
so I can still complete Emacs editing?
Write sh script and start-process-shell-command for asynchronous job?
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Run function in background.
2011-06-01 10:19 Run function in background Oleksandr Gavenko
@ 2011-06-01 10:40 ` Oleksandr Gavenko
2011-06-01 11:06 ` Deniz Dogan
0 siblings, 1 reply; 3+ messages in thread
From: Oleksandr Gavenko @ 2011-06-01 10:40 UTC (permalink / raw)
To: help-gnu-emacs
On 01.06.2011 13:19, Oleksandr Gavenko wrote:
> I need use auto update for GNU Global:
>
> $ global -u
>
> There described how this done:
>
> http://www.emacswiki.org/emacs/GnuGlobal
>
> But this:
>
> (defun gtags-root-dir ()
> "Returns GTAGS root directory or nil if doesn't exist."
> (with-temp-buffer
> (if (zerop (call-process "global" nil t nil "-pr"))
> (buffer-substring (point-min) (1- (point-max)))
> nil)))
>
> (defun gtags-update ()
> "Make GTAGS incremental update"
> (call-process "global" nil nil nil "-u"))
>
> (defun gtags-update-hook ()
> (when (gtags-root-dir)
> (gtags-update)))
>
> (add-hook 'after-save-hook #'gtags-update-hook)
>
> cause freezing Emacs for about 2-3 sec. How run this in background
> so I can still complete Emacs editing?
>
> Write sh script and start-process-shell-command for asynchronous job?
>
I write:
(defun gtags-update ()
(start-process-shell-command "/bin/sh" nil "if global -pr; then
global -u; fi")
)
(add-hook 'after-save-hook #'gtags-update)
; (remove-hook 'after-save-hook #'gtags-update)
Seems this help but how in general case when I need run elisp code
in background (synchronization issue is not essential).
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Run function in background.
2011-06-01 10:40 ` Oleksandr Gavenko
@ 2011-06-01 11:06 ` Deniz Dogan
0 siblings, 0 replies; 3+ messages in thread
From: Deniz Dogan @ 2011-06-01 11:06 UTC (permalink / raw)
To: help-gnu-emacs
On 2011-06-01 12:40, Oleksandr Gavenko wrote:
> On 01.06.2011 13:19, Oleksandr Gavenko wrote:
>> I need use auto update for GNU Global:
>>
>> $ global -u
>>
>> There described how this done:
>>
>> http://www.emacswiki.org/emacs/GnuGlobal
>>
>> But this:
>>
>> (defun gtags-root-dir ()
>> "Returns GTAGS root directory or nil if doesn't exist."
>> (with-temp-buffer
>> (if (zerop (call-process "global" nil t nil "-pr"))
>> (buffer-substring (point-min) (1- (point-max)))
>> nil)))
>>
>> (defun gtags-update ()
>> "Make GTAGS incremental update"
>> (call-process "global" nil nil nil "-u"))
>>
>> (defun gtags-update-hook ()
>> (when (gtags-root-dir)
>> (gtags-update)))
>>
>> (add-hook 'after-save-hook #'gtags-update-hook)
>>
>> cause freezing Emacs for about 2-3 sec. How run this in background
>> so I can still complete Emacs editing?
>>
>> Write sh script and start-process-shell-command for asynchronous job?
>>
> I write:
>
> (defun gtags-update ()
> (start-process-shell-command "/bin/sh" nil "if global -pr; then
> global -u; fi")
> )
>
> (add-hook 'after-save-hook #'gtags-update)
> ; (remove-hook 'after-save-hook #'gtags-update)
>
> Seems this help but how in general case when I need run elisp code
> in background (synchronization issue is not essential).
>
Read: (info "(elisp) Asynchronous Processes")
I haven't really tested this, but I think something like this should work:
(defun gtags-process-sentinel (process event)
(when (string= event "finished\n"))
(kill-buffer (process-buffer process))))
(defun gtags-update ()
"Make GTAGS incremental update."
(let ((gtags-process (start-process "Global" "*Global output*" "dir")))
(set-process-sentinel gtags-process 'gtags-process-sentinel)))
/Deniz
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-06-01 11:06 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-06-01 10:19 Run function in background Oleksandr Gavenko
2011-06-01 10:40 ` Oleksandr Gavenko
2011-06-01 11:06 ` Deniz Dogan
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).