[Top][All Lists]

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

Re: Should prefix variable be used in function argument list

From: Philip Kaludercic
Subject: Re: Should prefix variable be used in function argument list
Date: Fri, 08 Jul 2022 17:40:33 +0000

carlmarcos--- via Users list for the GNU Emacs text editor
<> writes:

> When one wants to use the prefix argument when calling an interactive
> function, should one include a prefix variable in the function
> argument list? 

No, I don't think there is any general rule here.  Some functions are
meant for interactive use only so they don't pass the prefix argument
through the argument list, while functions that are both meant to be
used interactively and by other functions do so to expose the
functionality to both callers. 

> Furthermore, should the prefix argument be defined as optional?  How
> would one call the function non-interactively for such function?  Is
> it always necessary to have the prefix argument as the first argument
> in the function argument list?

Again, most of this depends on the individual case and often is a matter
of individual taste.  You get to design the interactive specification
yourself, so you get to decide what happens.

An option you didn't mention but what I occasionally make use of is to
only use `current-prefix-arg' in an interactive specification, instead
of the body.  E.g. think of something like this:

--8<---------------cut here---------------start------------->8---
(defun foo (option)
   (list (if current-prefix-arg
             (read-string "Option: ")
  (do-something-with option))
--8<---------------cut here---------------end--------------->8---

reply via email to

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