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

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

Re: Prefix Argument and optional argument


From: carlmarcos
Subject: Re: Prefix Argument and optional argument
Date: Tue, 5 Jul 2022 22:26:03 +0200 (CEST)

Jul 5, 2022, 06:52 by brubar.cs@gmail.com:

> carlmarcos--- via Users list for the GNU Emacs text editor
> <help-gnu-emacs@gnu.org> writes:
>
>> I am having difficulty figuring out any problems associated with the 
>> following two functions.
>>
>> Can one safely call "M-x name", "C-u M-x name", "C-u 2 M-x name", where name 
>> is either
>> `poke' or `poke-opt'.
>>
>> (defun poke (prefix)
>>   "TODO."
>>   (interactive "P")
>> ...)
>>
>
> You should compile your code; Emacs will say:
>
>  Warning: misplaced interactive spec: ‘(interactive P)’
>

I did call `M-x byte-compile-file file' but did not get the warning you 
desrcibe.


>>
>> (defun poke-opt (&optional prefix)
>>   "TODO."
>>   (interactive "P")
>> ...)
>>
>
> This version is OK. You can call it "M-x name", "C-u M-x name", "C-u 2
> M-x name"; wether it's safe or not depends on its body though ;-)
>
> Bruno
>

Have done as follows

(defun poke (&optional prefix)
  "TODO"
  (interactive "P")

  (cond
   ((equal current-prefix-arg nil)   ; no C-u
    (setq poke-name-mode 1))

   ((equal current-prefix-arg '(4))  ; C-u
    (setq poke-name-mode 0)
    (arktika-workbench))

   ((equal current-prefix-arg 1)     ; C-u 1
    (setq poke-name-mode 0)

    (let* ( (name (read-from-minibuffer " Name: ")) )
      (arktika-workbench name))) ) ))




reply via email to

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