* Accessing arg with (interactive "P")
@ 2022-07-06 0:26 carlmarcos--- via Users list for the GNU Emacs text editor
2022-07-06 0:55 ` [External] : " Drew Adams
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: carlmarcos--- via Users list for the GNU Emacs text editor @ 2022-07-06 0:26 UTC (permalink / raw)
To: Help Gnu Emacs
I have the following elisp function, using `current-prefix-arg` to decide subsequent processing.
Having made the command examine it directly, the usual method for accessing it is with
(interactive "P"). The problem is that I do not know how to examine the prefix arg through
the interactive clause.
(defun poke (&optional prefix)
"TODO"
(interactive "P")
(cond
((equal current-prefix-arg nil) ; no C-u
(setq workbench-poke-name-mode 1))
((equal current-prefix-arg '(4)) ; C-u
(arktika-workbench))
^ permalink raw reply [flat|nested] 4+ messages in thread
* RE: [External] : Accessing arg with (interactive "P")
2022-07-06 0:26 Accessing arg with (interactive "P") carlmarcos--- via Users list for the GNU Emacs text editor
@ 2022-07-06 0:55 ` Drew Adams
2022-07-06 1:16 ` Emanuel Berg
[not found] ` <SJ0PR10MB54882137B90C8A6D52ACC83DF3809@SJ0PR10MB5488.namprd10.prod.outlook.com-N6G-MQ_----2>
2 siblings, 0 replies; 4+ messages in thread
From: Drew Adams @ 2022-07-06 0:55 UTC (permalink / raw)
To: carlmarcos@tutanota.com; +Cc: 'Help-Gnu-Emacs (help-gnu-emacs@gnu.org)'
[-- Attachment #1: Type: text/plain, Size: 771 bytes --]
> I have the following elisp function, using `current-prefix-arg` to
> decide subsequent processing.
>
> Having made the command examine it directly, the usual method for
> accessing it is with
> (interactive "P"). The problem is that I do not know how to examine
> the prefix arg through
> the interactive clause.
>
> (defun poke (&optional prefix)
> "TODO"
> (interactive "P")
> (cond
> ((equal current-prefix-arg nil) ; no C-u
> (setq workbench-poke-name-mode 1))
> ((equal current-prefix-arg '(4)) ; C-u
> (arktika-workbench))
Not sure what your question is or what it is that
you want to do. But change `current-prefix-arg'
to `prefix' and your code will do what I'm guessing
you want it to do.
[-- Attachment #2: winmail.dat --]
[-- Type: application/ms-tnef, Size: 13270 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Accessing arg with (interactive "P")
2022-07-06 0:26 Accessing arg with (interactive "P") carlmarcos--- via Users list for the GNU Emacs text editor
2022-07-06 0:55 ` [External] : " Drew Adams
@ 2022-07-06 1:16 ` Emanuel Berg
[not found] ` <SJ0PR10MB54882137B90C8A6D52ACC83DF3809@SJ0PR10MB5488.namprd10.prod.outlook.com-N6G-MQ_----2>
2 siblings, 0 replies; 4+ messages in thread
From: Emanuel Berg @ 2022-07-06 1:16 UTC (permalink / raw)
To: help-gnu-emacs
carlmarcos--- via Users list for the GNU Emacs text editor wrote:
> I have the following elisp function, using
> `current-prefix-arg` to decide subsequent processing.
You can do that but better is to use the argument directly
just as you normally would,
(defun poke (&optional n)
(interactive "P")
(if n
(message "n is set")
(message "n is nil") ))
Try M-x poke RET and C-u M-x poke RET.
Note that this also works from Lisp which ignores the
interactive spec. Try eval these
(poke)
(poke 1)
With (poke) you see that optional arguments defaults to nil.
If you intends to use the arg, and nil doesn't make sense, you
must explicitely set it to some default that does, say 0 which
is common:
(or n (setq n 0))
But in our example nil is fine so no need to do that.
> Having made the command examine it directly, the usual
> method for accessing it is with (interactive "P").
> The problem is that I do not know how to examine the prefix
> arg through the interactive clause.
Try evaluating the interactive form, for example
(interactive "P") ; evals to (nil)
so the list element(s) is/are assigned to the formal
parameters, they become the arguments to the function.
Eval this:
(interactive "sString: \nnNumber: ")
It will assign the data you input to the formal parameters of
a function that looks like this for example
(defun xy-problem (str num) ... )
--
underground experts united
https://dataswamp.org/~incal
^ permalink raw reply [flat|nested] 4+ messages in thread
[parent not found: <SJ0PR10MB54882137B90C8A6D52ACC83DF3809@SJ0PR10MB5488.namprd10.prod.outlook.com-N6G-MQ_----2>]
* RE: [External] : Accessing arg with (interactive "P")
[not found] ` <SJ0PR10MB54882137B90C8A6D52ACC83DF3809@SJ0PR10MB5488.namprd10.prod.outlook.com-N6G-MQ_----2>
@ 2022-07-06 21:01 ` carlmarcos--- via Users list for the GNU Emacs text editor
0 siblings, 0 replies; 4+ messages in thread
From: carlmarcos--- via Users list for the GNU Emacs text editor @ 2022-07-06 21:01 UTC (permalink / raw)
To: Drew Adams; +Cc: 'Help-Gnu-Emacs (help-gnu-emacs@gnu.org)'
Jul 6, 2022, 00:55 by drew.adams@oracle.com:
>> I have the following elisp function, using `current-prefix-arg` to
>> decide subsequent processing.
>>
>> Having made the command examine it directly, the usual method for
>> accessing it is with
>> (interactive "P"). The problem is that I do not know how to examine
>> the prefix arg through
>> the interactive clause.
>>
>> (defun poke (&optional prefix)
>> "TODO"
>> (interactive "P")
>> (cond
>> ((equal current-prefix-arg nil) ; no C-u
>> (setq workbench-poke-name-mode 1))
>> ((equal current-prefix-arg '(4)) ; C-u
>> (arktika-workbench))
>>
>
> Not sure what your question is or what it is that
> you want to do. But change `current-prefix-arg'
> to `prefix' and your code will do what I'm guessing
> you want it to do.
>
It does do what I want.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-07-06 21:01 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-07-06 0:26 Accessing arg with (interactive "P") carlmarcos--- via Users list for the GNU Emacs text editor
2022-07-06 0:55 ` [External] : " Drew Adams
2022-07-06 1:16 ` Emanuel Berg
[not found] ` <SJ0PR10MB54882137B90C8A6D52ACC83DF3809@SJ0PR10MB5488.namprd10.prod.outlook.com-N6G-MQ_----2>
2022-07-06 21:01 ` [External] : " carlmarcos--- via Users list for the GNU Emacs text editor
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.