unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Should prefix variable be used in function argument list
@ 2022-07-08 17:12 carlmarcos--- via Users list for the GNU Emacs text editor
  2022-07-08 17:40 ` Philip Kaludercic
  2022-07-08 17:41 ` Emanuel Berg
  0 siblings, 2 replies; 10+ messages in thread
From: carlmarcos--- via Users list for the GNU Emacs text editor @ 2022-07-08 17:12 UTC (permalink / raw)
  To: Help Gnu Emacs

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

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?






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

* Re: Should prefix variable be used in function argument list
  2022-07-08 17:12 Should prefix variable be used in function argument list carlmarcos--- via Users list for the GNU Emacs text editor
@ 2022-07-08 17:40 ` Philip Kaludercic
  2022-07-08 17:53   ` Emanuel Berg
  2022-07-08 17:41 ` Emanuel Berg
  1 sibling, 1 reply; 10+ messages in thread
From: Philip Kaludercic @ 2022-07-08 17:40 UTC (permalink / raw)
  To: carlmarcos--- via Users list for the GNU Emacs text editor; +Cc: carlmarcos

carlmarcos--- via Users list for the GNU Emacs text editor
<help-gnu-emacs@gnu.org> 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)
  (interactive
   (list (if current-prefix-arg
	     (read-string "Option: ")
	   "default")))
  (do-something-with option))
--8<---------------cut here---------------end--------------->8---



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

* Re: Should prefix variable be used in function argument list
  2022-07-08 17:12 Should prefix variable be used in function argument list carlmarcos--- via Users list for the GNU Emacs text editor
  2022-07-08 17:40 ` Philip Kaludercic
@ 2022-07-08 17:41 ` Emanuel Berg
  2022-07-08 18:09   ` Emanuel Berg
  2022-07-08 21:08   ` carlmarcos--- via Users list for the GNU Emacs text editor
  1 sibling, 2 replies; 10+ messages in thread
From: Emanuel Berg @ 2022-07-08 17:41 UTC (permalink / raw)
  To: help-gnu-emacs

carlmarcos--- via Users list for the GNU Emacs text editor wrote:

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

Yes, almost always. Keep the function body the same for
interactive/non-interactive by it referring to the function
args and not caring which of those ways they got there.

> Furthermore, should the prefix argument be defined as
> optional?

Yes, when possible, especially when it defaults to something
that makes sense.

All arguments that have a nil they can take on and that makes
sense, all those cand be optional if they appear to the right
of the last argument from that isn't optional. What will
happen it will just be nil which.

> How would one call the function non-interactively for such
> function?

By typing it's name between parenthesis and evaluating it.

> Is it always necessary to have the prefix argument as the
> first argument in the function argument list?

No.

-- 
underground experts united
https://dataswamp.org/~incal




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

* Re: Should prefix variable be used in function argument list
  2022-07-08 17:40 ` Philip Kaludercic
@ 2022-07-08 17:53   ` Emanuel Berg
  2022-07-08 18:11     ` Emanuel Berg
  0 siblings, 1 reply; 10+ messages in thread
From: Emanuel Berg @ 2022-07-08 17:53 UTC (permalink / raw)
  To: help-gnu-emacs

Philip Kaludercic wrote:

> No, I don't think there is any general rule here.
> Some functions are meant for interactive use only

Don't pick up a habit doing that ...

-- 
underground experts united
https://dataswamp.org/~incal




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

* Re: Should prefix variable be used in function argument list
  2022-07-08 17:41 ` Emanuel Berg
@ 2022-07-08 18:09   ` Emanuel Berg
  2022-07-08 21:08   ` carlmarcos--- via Users list for the GNU Emacs text editor
  1 sibling, 0 replies; 10+ messages in thread
From: Emanuel Berg @ 2022-07-08 18:09 UTC (permalink / raw)
  To: help-gnu-emacs

> All arguments that have a nil they can take on and that
> makes sense, all those cand be optional if they appear to
> the right of the last argument from that isn't optional.
> What will happen it will just be nil which.

*which will then be used. (zzz :))

You can also check and see if it's nil and, if so, set it to
something else. This can be used to give it a default value,
one can have one for interactive use, and one for
non-interactive, or the same for both.

Here OTOH it's not an shame to one's family to do differently,
on the contrary that can make a lot of sense. E.g.,
interactively the default can be (point) if that feels
intuitive, while non-interactively that would be better set to
(point-min).

Again see this file and I'm happy to add more/better
examples ...

  https://dataswamp.org/~incal/emacs-init/dwim.el

-- 
underground experts united
https://dataswamp.org/~incal




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

* Re: Should prefix variable be used in function argument list
  2022-07-08 17:53   ` Emanuel Berg
@ 2022-07-08 18:11     ` Emanuel Berg
  2022-07-09  8:59       ` Philip Kaludercic
  0 siblings, 1 reply; 10+ messages in thread
From: Emanuel Berg @ 2022-07-08 18:11 UTC (permalink / raw)
  To: help-gnu-emacs

>> No, I don't think there is any general rule here.
>> Some functions are meant for interactive use only
>
> Don't pick up a habit doing that ...

Check out the theory on MVC for why ...

Check out the practice of annoying little Elisp pointers in
help mode for why ...

Actually they are useful! So the annoyance should be directed
at the practice which they try to correct at a later stage.
That would be more fair.

-- 
underground experts united
https://dataswamp.org/~incal




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

* Re: Should prefix variable be used in function argument list
  2022-07-08 17:41 ` Emanuel Berg
  2022-07-08 18:09   ` Emanuel Berg
@ 2022-07-08 21:08   ` carlmarcos--- via Users list for the GNU Emacs text editor
  2022-07-09  4:57     ` tomas
  1 sibling, 1 reply; 10+ messages in thread
From: carlmarcos--- via Users list for the GNU Emacs text editor @ 2022-07-08 21:08 UTC (permalink / raw)
  To: Emanuel Berg; +Cc: help-gnu-emacs


Jul 8, 2022, 17:41 by incal@dataswamp.org:

> carlmarcos--- via Users list for the GNU Emacs text editor wrote:
>
>> When one wants to use the prefix argument when calling an
>> interactive function, should one include a prefix variable in
>> the function argument list?
>>
>
> Yes, almost always. Keep the function body the same for
> interactive/non-interactive by it referring to the function
> args and not caring which of those ways they got there.
>
>> Furthermore, should the prefix argument be defined as
>> optional?
>>
>
> Yes, when possible, especially when it defaults to something
> that makes sense.
>
> All arguments that have a nil they can take on and that makes
> sense, all those cand be optional if they appear to the right
> of the last argument from that isn't optional. What will
> happen it will just be nil which.
>
>> How would one call the function non-interactively for such
>> function?
>>
>
> By typing it's name between parenthesis and evaluating it.
>
Yes, but what should I put for the prefix value when using the function non-interactively?


>> Is it always necessary to have the prefix argument as the
>> first argument in the function argument list?
>>
>
> No.
>
I thought that because the prefix argument in used first (using C-u N myfunc) then it also has
to be the first argument in the function declaration. 



> -- 
> underground experts united
> https://dataswamp.org/~incal
>



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

* Re: Should prefix variable be used in function argument list
  2022-07-08 21:08   ` carlmarcos--- via Users list for the GNU Emacs text editor
@ 2022-07-09  4:57     ` tomas
  0 siblings, 0 replies; 10+ messages in thread
From: tomas @ 2022-07-09  4:57 UTC (permalink / raw)
  To: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 444 bytes --]

On Fri, Jul 08, 2022 at 11:08:18PM +0200, carlmarcos--- via Users list for the GNU Emacs text editor wrote:

[...]

> Yes, but what should I put for the prefix value when using the function non-interactively?

Please, read the manual. There is a section dedicated
exactly to that (which one, that is left as an exercise
to the reader).

It is a prefix *argument*. So non-interactively, you
pass it as an argument.

Cheers
-- 
t

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

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

* Re: Should prefix variable be used in function argument list
  2022-07-08 18:11     ` Emanuel Berg
@ 2022-07-09  8:59       ` Philip Kaludercic
  2022-07-10  4:14         ` Emanuel Berg
  0 siblings, 1 reply; 10+ messages in thread
From: Philip Kaludercic @ 2022-07-09  8:59 UTC (permalink / raw)
  To: help-gnu-emacs

Emanuel Berg <incal@dataswamp.org> writes:

>>> No, I don't think there is any general rule here.
>>> Some functions are meant for interactive use only
>>
>> Don't pick up a habit doing that ...

Of course, but sometimes it does make sense to do so (and the `declare'
system allows for that to be done).

> Check out the theory on MVC for why ...
>
> Check out the practice of annoying little Elisp pointers in
> help mode for why ...

I would appreciate it if you could explain what you are talking about
instead of just insinuating points.

> Actually they are useful! So the annoyance should be directed
> at the practice which they try to correct at a later stage.
> That would be more fair.

(Also, why do you always just respond to the list and don't CC the
person you are responding too)



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

* Re: Should prefix variable be used in function argument list
  2022-07-09  8:59       ` Philip Kaludercic
@ 2022-07-10  4:14         ` Emanuel Berg
  0 siblings, 0 replies; 10+ messages in thread
From: Emanuel Berg @ 2022-07-10  4:14 UTC (permalink / raw)
  To: help-gnu-emacs

Philip Kaludercic wrote:

>> Check out the theory on MVC for why ...
>>
>> Check out the practice of annoying little Elisp pointers in
>> help mode for why ...
>
> I would appreciate it if you could explain what you are
> talking about instead of just insinuating points.

MVC = Model View Control.

Model is a word from OO theory, we would call it the program's
state or maybe internals, logic. Yeah, what it is and how that
works, basically.

View = What you see, i.e. the part of the interface that's
presented to you.

Control = the interface from the other side, from you as
a user

Not unlike the Lisp REPL where R (read) would be control,
E (eval) would be the logic acted upon the state, and
P (print) would be what the user sees from his or
her viewpoint.

So these three (MVC) should be separated, modules.

So translated to our case, and not in general but this
specifically, it becomes the control has not one control to do
something, it has two, one interactively and one
non-interactively, and you have to think in terms of the
program and Lisp environment, i.e. in the Model part of MVC
how that would work differently and so.

So you have Lisp in code, its makes up the model, but if the
user do M-: and types some Lisp, that is actually _not_ part
of the Model but is a part of, or an alternative interface.

If your practical reasons one has to have two functions, one
interactively and one non-interactively, what one can do is
having another function, e.g. (bob) and that would in turn do
either (goto-char (point-min)) or do it interactively if there
was some very special situation that called for that.
Such things can pe handled under the hood. But stuff that is
intuitive to the user, like that, one can have that
contra-intuitive and then hope that comments in the help
should remedy that.

>> Actually they are useful! So the annoyance should be
>> directed at the practice which they try to correct at
>> a later stage. That would be more fair.
>
> (Also, why do you always just respond to the list and don't
> CC the person you are responding too)

Often the sad truth is, they just can't handle the truth.

-- 
underground experts united
https://dataswamp.org/~incal




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

end of thread, other threads:[~2022-07-10  4:14 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-07-08 17:12 Should prefix variable be used in function argument list carlmarcos--- via Users list for the GNU Emacs text editor
2022-07-08 17:40 ` Philip Kaludercic
2022-07-08 17:53   ` Emanuel Berg
2022-07-08 18:11     ` Emanuel Berg
2022-07-09  8:59       ` Philip Kaludercic
2022-07-10  4:14         ` Emanuel Berg
2022-07-08 17:41 ` Emanuel Berg
2022-07-08 18:09   ` Emanuel Berg
2022-07-08 21:08   ` carlmarcos--- via Users list for the GNU Emacs text editor
2022-07-09  4:57     ` tomas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).