all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#63626: [PATCH] Make forward and backward-to-word arg optional
@ 2023-05-21  4:33 Zaz Brown
  2023-05-26 11:24 ` Eli Zaretskii
  0 siblings, 1 reply; 8+ messages in thread
From: Zaz Brown @ 2023-05-21  4:33 UTC (permalink / raw)
  To: 63626; +Cc: dalanicolai

(forward-to-word) throws (wrong-number-of-arguments forward-to-word 0)
in spite of the doc string stating:

> Move forward until encountering the beginning of a word.
> With argument, do this that many times.

This behaviour is present in Spacemacs 28.2, and has been confirmed by
Daniel Nicolai on Emacs 30. It's also evident in the latest source code.

The same issue exists for (backward-to-word). But running each command
with M-x works with no argument.

I'm new to Emacs, so please take this with a grain of salt.  Thank you!

---
 lisp/misc.el | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git master/lisp/misc.el arg-optional/lisp/misc.el
index ca013d5..f97240e 100644
--- a/lisp/misc.el
+++ b/lisp/misc.el
@@ -166,18 +166,20 @@ is an upper-case character."
     (upcase-region (point) (progn (forward-char arg) (point)))))

 ;;;###autoload
-(defun forward-to-word (arg)
+(defun forward-to-word (&optional arg)
   "Move forward until encountering the beginning of a word.
 With argument, do this that many times."
   (interactive "^p")
+  (unless arg (setq arg 1))
   (or (re-search-forward (if (> arg 0) "\\W\\b" "\\b\\W") nil t arg)
       (goto-char (if (> arg 0) (point-max) (point-min)))))

 ;;;###autoload
-(defun backward-to-word (arg)
+(defun backward-to-word (&optional arg)
   "Move backward until encountering the end of a word.
 With argument, do this that many times."
   (interactive "^p")
+  (unless arg (setq arg 1))
   (forward-to-word (- arg)))

 ;;;###autoload
--
2.40.1





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

* bug#63626: [PATCH] Make forward and backward-to-word arg optional
  2023-05-21  4:33 bug#63626: [PATCH] Make forward and backward-to-word arg optional Zaz Brown
@ 2023-05-26 11:24 ` Eli Zaretskii
       [not found]   ` <CACTmS+g93z7ns6AD9v-a+-TRVkVuTLt5RGi5YVTGUA8J1BM3dw@mail.gmail.com>
  0 siblings, 1 reply; 8+ messages in thread
From: Eli Zaretskii @ 2023-05-26 11:24 UTC (permalink / raw)
  To: Zaz Brown; +Cc: dalanicolai, 63626

> Cc: dalanicolai@gmail.com
> From: Zaz Brown <zazbrown@zazbrown.com>
> Date: Sat, 20 May 2023 21:33:51 -0700
> 
> (forward-to-word) throws (wrong-number-of-arguments forward-to-word 0)
> in spite of the doc string stating:
> 
> > Move forward until encountering the beginning of a word.
> > With argument, do this that many times.
> 
> This behaviour is present in Spacemacs 28.2, and has been confirmed by
> Daniel Nicolai on Emacs 30. It's also evident in the latest source code.
> 
> The same issue exists for (backward-to-word). But running each command
> with M-x works with no argument.

Thank you for your report.

Please tell why you think we should allow non-interactive invocation
of these functions with no argument.  IOW, what exactly is wrong with
the current code, and in what situations you have found this to be a
problem?





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

* bug#63626: [PATCH] Make forward and backward-to-word arg optional
       [not found]   ` <CACTmS+g93z7ns6AD9v-a+-TRVkVuTLt5RGi5YVTGUA8J1BM3dw@mail.gmail.com>
@ 2023-05-27  7:02     ` Eli Zaretskii
  2023-05-27 18:39       ` Zaz Brown
  0 siblings, 1 reply; 8+ messages in thread
From: Eli Zaretskii @ 2023-05-27  7:02 UTC (permalink / raw)
  To: Zaz Brown; +Cc: dalanicolai, 63626

[Please use Reply All to reply, to keep everyone on the CC list.]

> From: Zaz Brown <zazbrown@zazbrown.com>
> Date: Fri, 26 May 2023 12:54:19 -0700
> 
> It's more convenient to be able to use forward-to-word without the
> argument.  For example, this would allow passing the function
> forward-to-word without having to use a lambda.
> 
> Most importantly, though, the current definition of forward-to-word
> does not match the doc string.  The doc string implies that with no
> argument, it goes forward 1 word.  And this has already caused
> confusion.

The doc string says "with argument", most probably meaning "with
prefix numeric argument".  IOW, it talks about interactive invocation.
In any case, the doc string is easy to fix/clarify.

But I'm still not convinced we need to change the signature of the
function.  What are the use cases where you'd want to pass
forward-to-word as a function argument to another function?





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

* bug#63626: [PATCH] Make forward and backward-to-word arg optional
  2023-05-27  7:02     ` Eli Zaretskii
@ 2023-05-27 18:39       ` Zaz Brown
  2023-05-28  5:16         ` Eli Zaretskii
  0 siblings, 1 reply; 8+ messages in thread
From: Zaz Brown @ 2023-05-27 18:39 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: dalanicolai, 63626

On Sat, May 27, 2023 at 12:02 AM Eli Zaretskii <eliz@gnu.org> wrote:
> But I'm still not convinced we need to change the signature of the
> function.  What are the use cases where you'd want to pass
> forward-to-word as a function argument to another function?

I can't think of a good example and wasn't able to find an example of
a forward-to-word lambda on GitHub code search.  So perhaps I'm
mistaken that this would be useful.  I'll have to leave that
discussion to those who are more familiar with Emacs and Lisp.





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

* bug#63626: [PATCH] Make forward and backward-to-word arg optional
  2023-05-27 18:39       ` Zaz Brown
@ 2023-05-28  5:16         ` Eli Zaretskii
  2023-05-29 15:24           ` dalanicolai
  0 siblings, 1 reply; 8+ messages in thread
From: Eli Zaretskii @ 2023-05-28  5:16 UTC (permalink / raw)
  To: Zaz Brown; +Cc: dalanicolai, 63626

> From: Zaz Brown <zazbrown@zazbrown.com>
> Date: Sat, 27 May 2023 11:39:35 -0700
> Cc: dalanicolai@gmail.com, 63626@debbugs.gnu.org
> 
> On Sat, May 27, 2023 at 12:02 AM Eli Zaretskii <eliz@gnu.org> wrote:
> > But I'm still not convinced we need to change the signature of the
> > function.  What are the use cases where you'd want to pass
> > forward-to-word as a function argument to another function?
> 
> I can't think of a good example and wasn't able to find an example of
> a forward-to-word lambda on GitHub code search.  So perhaps I'm
> mistaken that this would be useful.  I'll have to leave that
> discussion to those who are more familiar with Emacs and Lisp.

Thanks.

Does anyone else here have an opinion on this changeset?





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

* bug#63626: [PATCH] Make forward and backward-to-word arg optional
  2023-05-28  5:16         ` Eli Zaretskii
@ 2023-05-29 15:24           ` dalanicolai
  2023-05-29 16:46             ` Juri Linkov
  0 siblings, 1 reply; 8+ messages in thread
From: dalanicolai @ 2023-05-29 15:24 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Zaz Brown, 63626

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

I have no opinion about how this 'should work'.
I was just confused by the docstring, and I assumed from the docstring,
that the intention was for the argument to be optional like in
forward-word/line
(the docstring does not say that this command is meant for interactive use
only).

My idea was just to report this very low priority issue about the
'confusing' docstring
(and ask if maybe that argument was intended to be optional).

Here <https://emacs.stackexchange.com/a/77278/26163> is the motive for this
patch. It is used in an evil function, so I guess we could
just have used `evil-forward-WORD-begin` instead, and it is not necessary
to change
the `forward-to-word` function.

[-- Attachment #2: Type: text/html, Size: 893 bytes --]

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

* bug#63626: [PATCH] Make forward and backward-to-word arg optional
  2023-05-29 15:24           ` dalanicolai
@ 2023-05-29 16:46             ` Juri Linkov
  2023-05-31 13:15               ` Eli Zaretskii
  0 siblings, 1 reply; 8+ messages in thread
From: Juri Linkov @ 2023-05-29 16:46 UTC (permalink / raw)
  To: dalanicolai; +Cc: Eli Zaretskii, Zaz Brown, 63626

> I have no opinion about how this 'should work'.
> I was just confused by the docstring, and I assumed from the docstring,
> that the intention was for the argument to be optional like in
> forward-word/line

Aren't all forward-like commands more permissive and allow their arg
to be optional?  It looks like the standard signature, e.g.:

  (defun forward-page (&optional count)
    (interactive "p")
    (or count (setq count 1))

  (defun forward-paragraph (&optional arg)
    (interactive "^p")
    (or arg (setq arg 1))

  (defun forward-sentence (&optional arg)
    (interactive "^p")
    (or arg (setq arg 1))

  ...





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

* bug#63626: [PATCH] Make forward and backward-to-word arg optional
  2023-05-29 16:46             ` Juri Linkov
@ 2023-05-31 13:15               ` Eli Zaretskii
  0 siblings, 0 replies; 8+ messages in thread
From: Eli Zaretskii @ 2023-05-31 13:15 UTC (permalink / raw)
  To: Juri Linkov; +Cc: zazbrown, dalanicolai, 63626-done

> From: Juri Linkov <juri@linkov.net>
> Cc: Eli Zaretskii <eliz@gnu.org>,  Zaz Brown <zazbrown@zazbrown.com>,
>   63626@debbugs.gnu.org
> Date: Mon, 29 May 2023 19:46:59 +0300
> 
> > I have no opinion about how this 'should work'.
> > I was just confused by the docstring, and I assumed from the docstring,
> > that the intention was for the argument to be optional like in
> > forward-word/line
> 
> Aren't all forward-like commands more permissive and allow their arg
> to be optional?  It looks like the standard signature, e.g.:

Thanks for the feedback, all of you.  I've now installed those changes
on the master branch, and I'm therefore closing this bug.





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

end of thread, other threads:[~2023-05-31 13:15 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-21  4:33 bug#63626: [PATCH] Make forward and backward-to-word arg optional Zaz Brown
2023-05-26 11:24 ` Eli Zaretskii
     [not found]   ` <CACTmS+g93z7ns6AD9v-a+-TRVkVuTLt5RGi5YVTGUA8J1BM3dw@mail.gmail.com>
2023-05-27  7:02     ` Eli Zaretskii
2023-05-27 18:39       ` Zaz Brown
2023-05-28  5:16         ` Eli Zaretskii
2023-05-29 15:24           ` dalanicolai
2023-05-29 16:46             ` Juri Linkov
2023-05-31 13:15               ` Eli Zaretskii

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.