From: Mike Bongiovi
Subject: LISP question regarding interactive functions
Date: 
Message-ID: <5ns4kv$8gh@news1.mnsinc.com>
I've written the following LISP code to use within emacs.  I've got the first 
function bound to ^X^C so it runs whenever I exit emacs.  However, when I run 
it in a file that contains the string CHKVER, it doesn't seem to execute 
ask-question-kill-emacs.  I know it gets to it because if I replace the line 
with (message "got here"), it prints out the message.  Also, I can run M-x 
ask-question-kill-emacs separately and it works the way I want.  I just can't 
figure out how to call it from within another function.  Any ideas?


(defun check-for-version()
  "Checks for version code, then calls ask-question-kill-emacs"
  (interactive)
  (top-of-buffer)
  (if (search-forward "CHKVER" nil t)
    (ask-question-kill-emacs)
    (save-buffers-kill-emacs))
)
;
(defun ask-question-kill-emacs(&optional yn)
  "Asks about whether or not version number has been changed, then exits"
  (interactive "sDid you remember to change the version number? ")
  (if (equal yn "y")
    (save-buffers-kill-emacs))
)


Mike Bongiovi

From: Barry Margolin
Subject: Re: LISP question regarding interactive functions
Date: 
Message-ID: <5nsqch$97n@tools.bbnplanet.com>
In article <··········@news1.mnsinc.com>,
Mike Bongiovi <········@neuraltech.com> wrote:
>(defun check-for-version()
>  "Checks for version code, then calls ask-question-kill-emacs"
>  (interactive)
>  (top-of-buffer)
>  (if (search-forward "CHKVER" nil t)
>    (ask-question-kill-emacs)
>    (save-buffers-kill-emacs))
>)
>;
>(defun ask-question-kill-emacs(&optional yn)
>  "Asks about whether or not version number has been changed, then exits"
>  (interactive "sDid you remember to change the version number? ")
>  (if (equal yn "y")
>    (save-buffers-kill-emacs))
>)

You're calling ask-question-kill-emacs with no argument, so yn defaults to
nil.  (equal nil "y") is false, so it doesn't call save-buffer-kill-emacs.

You seem to be expecting ask-question-kill-emacs to prompt the user.  That
only happens when the function is being called interactively, i.e. via M-x
or a key binding.  In this case, it's being called from another function,
so it's not interactive, therefore the parameter is filled in using Lisp's
normal rules.

-- 
Barry Margolin, ······@bbnplanet.com
BBN Corporation, Cambridge, MA
Support the anti-spam movement; see <http://www.cauce.org/>
From: Rolf-Thomas Happe
Subject: Re: LISP question regarding interactive functions
Date: 
Message-ID: <r5bu5a174x.fsf@xtreme.mathematik.uni-freiburg.de>
In article <··········@news1.mnsinc.com> ········@neuraltech.com 
(Mike Bongiovi) writes:

[...]
   run M-x ask-question-kill-emacs separately and it works the way I
   want.  I just can't figure out how to call it from within another 
   function.  Any ideas?
[...]

Use CALL-INTERACTIVELY:

(defun check-for-version ()
  "Checks for version code, then calls ask-question-kill-emacs"
  (interactive)
  ;(top-of-buffer)
  (if (search-forward "CHKVER" nil t)
      (call-interactively 'ask-question-kill-emacs)
      (message "ccc")))

(defun ask-question-kill-emacs (yn)
  "Asks about whether or not version number has been changed, then exits"
  (interactive "sDid you? (y/n) ")
  (if (equal yn "y")
      (message "aaa")
      (message "bbb")))

(In the original version the argument YN is optional, so that 
 (ASK-QUESTION-KILL-EMACS) calls the procedure with the default 
 argument NIL.  Since this call isn't interactive you don't get 
 a prompt.  The conditional 

	(if (equal yn "y") (save-buffers-kill-emacs))

 has no alternative branch. With YN being NIL the proc quits 
 silently.)

rthappe

PS: I send a cc, too, since now and then I had the impression that my 
(infrequent) postings got lost.