help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Run function in background.


From: Deniz Dogan
Subject: Re: Run function in background.
Date: Wed, 01 Jun 2011 13:06:46 +0200
User-agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.17) Gecko/20110414 Thunderbird/3.1.10

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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]