all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* `call-interactively' and prefix args
@ 2014-06-03 12:46 Thorsten Jolitz
  2014-06-03 12:58 ` Nicolas Richard
  0 siblings, 1 reply; 4+ messages in thread
From: Thorsten Jolitz @ 2014-06-03 12:46 UTC (permalink / raw)
  To: help-gnu-emacs


Hi List, 

,---------------------------------------------------------
| (call-interactively FUNCTION &optional RECORD-FLAG KEYS)
`---------------------------------------------------------

does not have an (optional) ARG argument for passing prefix args to the
called command.

#+BEGIN_SRC emacs-lisp
(defun foo (&optional arg)
  (interactive "P")
  (print arg))
#+END_SRC

#+results:
: foo

#+begin_src emacs-lisp :results output
 (call-interactively 'foo )
#+end_src

Evaluated with C-u C-c C-c the code block actually results in 

#+results:
: (4)

otherwise in nil.

So, when I have an (interactive) command cmd1 that calls a
non-interactive function fun that calls another (interactive "P")
command cmd2 with `call-interactively' - can I assume that a prefix arg
(e.g. by C-u) given before calling cmd1 will be transferred to cmd2?

-- 
cheers,
Thorsten




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

* Re: `call-interactively' and prefix args
  2014-06-03 12:46 `call-interactively' and prefix args Thorsten Jolitz
@ 2014-06-03 12:58 ` Nicolas Richard
  2014-06-03 13:15   ` Thorsten Jolitz
  0 siblings, 1 reply; 4+ messages in thread
From: Nicolas Richard @ 2014-06-03 12:58 UTC (permalink / raw)
  To: Thorsten Jolitz; +Cc: help-gnu-emacs

Thorsten Jolitz <tjolitz@gmail.com> writes:
> So, when I have an (interactive) command cmd1 that calls a
> non-interactive function fun that calls another (interactive "P")
> command cmd2 with `call-interactively' - can I assume that a prefix arg
> (e.g. by C-u) given before calling cmd1 will be transferred to cmd2?

current-prefix-arg is used. If cmd1 changes it, anything can happen.

e.g.

(global-set-key (kbd "<f6>") (lambda () (interactive) (yffoo)))
(defun yffoo () (setq current-prefix-arg '(5)) (call-interactively 'yfbar))
(defun yfbar (&optional arg) (interactive "P") (message "arg is %S" arg))

hitting f6 will show that arg is (5) (which doesn't make sense in an
true interactive call)

-- 
Nico.



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

* Re: `call-interactively' and prefix args
  2014-06-03 12:58 ` Nicolas Richard
@ 2014-06-03 13:15   ` Thorsten Jolitz
  2014-06-03 13:55     ` Stefan Monnier
  0 siblings, 1 reply; 4+ messages in thread
From: Thorsten Jolitz @ 2014-06-03 13:15 UTC (permalink / raw)
  To: help-gnu-emacs

Nicolas Richard <theonewiththeevillook@yahoo.fr> writes:

> Thorsten Jolitz <tjolitz@gmail.com> writes:
>> So, when I have an (interactive) command cmd1 that calls a
>> non-interactive function fun that calls another (interactive "P")
>> command cmd2 with `call-interactively' - can I assume that a prefix arg
>> (e.g. by C-u) given before calling cmd1 will be transferred to cmd2?
>
> current-prefix-arg is used. If cmd1 changes it, anything can happen.
>
> e.g.
>
> (global-set-key (kbd "<f6>") (lambda () (interactive) (yffoo)))
> (defun yffoo () (setq current-prefix-arg '(5)) (call-interactively 'yfbar))
> (defun yfbar (&optional arg) (interactive "P") (message "arg is %S" arg))
>
> hitting f6 will show that arg is (5) (which doesn't make sense in an
> true interactive call)

Ok, thanks! Then misbehaviour must be coded explicitly, otherwise things
should work as expected ... what is good. 

-- 
cheers,
Thorsten




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

* Re: `call-interactively' and prefix args
  2014-06-03 13:15   ` Thorsten Jolitz
@ 2014-06-03 13:55     ` Stefan Monnier
  0 siblings, 0 replies; 4+ messages in thread
From: Stefan Monnier @ 2014-06-03 13:55 UTC (permalink / raw)
  To: help-gnu-emacs

> Ok, thanks! Then misbehaviour must be coded explicitly, otherwise things
> should work as expected ... what is good. 

Right.  The key to understanding the behavior is that prefix-arg is
handled (i.e. set and reset) by the top-level "read-eval" loop (which
ends up calling call-interactively) rather than by
call-interactively itself.


        Stefan




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

end of thread, other threads:[~2014-06-03 13:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-06-03 12:46 `call-interactively' and prefix args Thorsten Jolitz
2014-06-03 12:58 ` Nicolas Richard
2014-06-03 13:15   ` Thorsten Jolitz
2014-06-03 13:55     ` Stefan Monnier

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.