unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* signal-USR1-hook woes
@ 2003-09-08  1:20 Bauke Jan Douma
  2003-09-08  6:27 ` Eli Zaretskii
       [not found] ` <mailman.344.1062998727.18171.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 3+ messages in thread
From: Bauke Jan Douma @ 2003-09-08  1:20 UTC (permalink / raw)


Hi,

I am trying to get a list of currently open files in emacs, by
sending it SIGUSR1 (signo=10).  I have the following defines:

(defvar emacs-open-files "/root/emacs/.emacs-open-files" "List of files currently open in Emacs")

(defun list-emacs-open-files ()
	(interactive)
	
	(message "list-emacs-open-files: done")
	(let	(
		 (buf_list (buffer-list))
		)

		(with-temp-file emacs-open-files
			(while buf_list                                             	
				(cond	(
					 (buffer-file-name (car buf_list))
					 (insert (buffer-file-name (car buf_list)))
					 (insert "\n")
					)
				)
				(setq buf_list (cdr buf_list))
			)
		)
	)
)

(add-hook `signal-USR1-hook `list-emacs-open-files nil nil)

Alas, it doesn't work.  It does work from within emacs by
calling M-x list-emacs-open-files or by eval'ing
(signal-process (emacs-pid) 10).
When doing kill -USR1 <emacs-pid>, all that happens is I get a
visual bell, the file is not written.
An strace reveals that the signal is sent allright.

I am doing something wrong, but what?
Thanks!

bjd

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: signal-USR1-hook woes
  2003-09-08  1:20 signal-USR1-hook woes Bauke Jan Douma
@ 2003-09-08  6:27 ` Eli Zaretskii
       [not found] ` <mailman.344.1062998727.18171.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 3+ messages in thread
From: Eli Zaretskii @ 2003-09-08  6:27 UTC (permalink / raw)


> Newsgroups: gnu.emacs.help
> From: bjdouma@xs2.xs4all.nl (Bauke Jan Douma)
> 	
> 	(message "list-emacs-open-files: done")
> 	(let	(
> 		 (buf_list (buffer-list))
> 		)

Yikes!  Why do you insist on formatting Lisp code as if it were C or
(God forbid) Pascal?  It makes it very hard to read and comprehend.

> Alas, it doesn't work.  It does work from within emacs by
> calling M-x list-emacs-open-files or by eval'ing
> (signal-process (emacs-pid) 10).
> When doing kill -USR1 <emacs-pid>, all that happens is I get a
> visual bell, the file is not written.
> An strace reveals that the signal is sent allright.
> 
> I am doing something wrong, but what?

Well, is your function at all called?  Does the message you produce at
the beginning of your function gets inserted into the *Messages*
buffer?

In other words, the first question you should answer is: is the
signal delivered to Emacs and handled, but your function has a bug,
or is the signal itself handled incorrectly by Emacs?

And it will help immensely if you tell what version of Emacs is that
and on what platform.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: signal-USR1-hook woes
       [not found] ` <mailman.344.1062998727.18171.help-gnu-emacs@gnu.org>
@ 2004-02-29  5:50   ` Ed L Cashin
  0 siblings, 0 replies; 3+ messages in thread
From: Ed L Cashin @ 2004-02-29  5:50 UTC (permalink / raw)


I would like to run something like the function below on receiving a
SIGUSR1.  It would help me close gnus cleanly on my work machine
before launching a new emacs remotely for using gnus.

  (defun elc-exit-gnus ()
    "go to the group buffer (if it's there) and exit gnus"
    (interactive)
    (save-excursion 
      (let ((g (get-buffer "*Group*"))
            (gnus-interactive-exit nil))
        (if g
           (gnus-group-exit)))))


I went looking for an emacs feature that lets the user associate
actions with SIGUSR1 and SIGUSR2.  The emacs info docs didn't turn up
anything, but I found some old articles using Google groups, including
the one this post is responding to.  (Link provided below.)

  http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&safe=off&threadm=mailman.344.1062998727.18171.help-gnu-emacs%40gnu.org&rnum=3&prev=/groups%3Fq%3Dsignal-USR1-hook%26ie%3DUTF-8%26oe%3DUTF-8%26hl%3Den%26btnG%3DGoogle%2BSearch


On 08 Sep 2003 08:27:09 +0200 Eli Zaretskii <eliz@elta.co.il> writes:

>> Newsgroups: gnu.emacs.help
>> From: bjdouma@xs2.xs4all.nl (Bauke Jan Douma)
>> 	
>> 	(message "list-emacs-open-files: done")
>> 	(let	(
>> 		 (buf_list (buffer-list))
>> 		)
>
> Yikes!  Why do you insist on formatting Lisp code as if it were C or
> (God forbid) Pascal?  It makes it very hard to read and comprehend.
>
>> Alas, it doesn't work.  It does work from within emacs by
>> calling M-x list-emacs-open-files or by eval'ing
>> (signal-process (emacs-pid) 10).
>> When doing kill -USR1 <emacs-pid>, all that happens is I get a
>> visual bell, the file is not written.
>> An strace reveals that the signal is sent allright.
>> 
>> I am doing something wrong, but what?
>
> Well, is your function at all called?  Does the message you produce at
> the beginning of your function gets inserted into the *Messages*
> buffer?
>
> In other words, the first question you should answer is: is the
> signal delivered to Emacs and handled, but your function has a bug,
> or is the signal itself handled incorrectly by Emacs?
>
> And it will help immensely if you tell what version of Emacs is that
> and on what platform.
>

There is also a gnu.emacs.bug post from Robert Spier on Dec 14, 1997
with the subject "patch for USR1 and USR2 signal handling".  Spier's
patch contains code that shows the hooks being run when emacs receives
a SIGUSR1 or SIGUSR2.  

  http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&safe=off&threadm=199712141954.OAA28984%40blue.seas.upenn.edu&rnum=2&prev=/groups%3Fq%3Dsignal-USR1-hook%26ie%3DUTF-8%26oe%3DUTF-8%26hl%3Den%26btnG%3DGoogle%2BSearch
  
The code that runs the hooks inside the signal handler is no longer in
src/emacs.c.  That makes sense, from what I know about signal
handlers.  In emacs-21.3, the ChangeLog files show some references to
the feature, it looks like instead of running the user-specified
hooks, an event is created for src/keyboard.c to handle later.
However, the example usage in Spier's patch email no longer works.

Here's my SIGUSR1 handler test case, based on Spier's example:

  (add-hook 'signal-USR1-hook (function
      (lambda ()
        (message "HI!!!"))))

After launching emacs 21.2.1 from debian with "emacs -q" and
evaluating the above code, when a SIGUSR1 is sent to the emacs
process, emacs just beeps.  No message appears in the *Messages*
buffer. 

-- 
--Ed L Cashin     PGP public key: http://noserose.net/e/pgp/

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2004-02-29  5:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-09-08  1:20 signal-USR1-hook woes Bauke Jan Douma
2003-09-08  6:27 ` Eli Zaretskii
     [not found] ` <mailman.344.1062998727.18171.help-gnu-emacs@gnu.org>
2004-02-29  5:50   ` Ed L Cashin

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).