unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#61274: 29.0.60; dabbrev-capf signals errors
@ 2023-02-04 11:03 Daniel Mendler
  2023-02-04 13:16 ` Eli Zaretskii
  0 siblings, 1 reply; 10+ messages in thread
From: Daniel Mendler @ 2023-02-04 11:03 UTC (permalink / raw)
  To: 61274; +Cc: monnier

The completion-at-point-function `dabbrev-capf' sometimes signals
errors. It would be good if the function would not do that but return
nil if no completions are found, such that the next Capf from the list
of completion functions gets its chance to run.

1. Start emacs -Q
2. Evaluate (require 'dabbrev).
3. Evaluate (setq completion-at-point-functions '(dabbrev-capf)) in the
scratch buffer.
4. Type `x M-TAB` in the scratch buffer. I observe the following error:

Debugger entered--Lisp error: (wrong-type-argument stringp nil)
  dabbrev--goto-start-of-abbrev()
  dabbrev--abbrev-at-point()
  dabbrev-capf()
  completion--capf-wrapper(dabbrev-capf all)
  completion-at-point()
  funcall-interactively(completion-at-point)
  command-execute(completion-at-point)

Furthermore if no completions are found `dabbrev-capf' signals an error.
The messages buffer will then contain:

Scanning for dabbrevs...done
completion--some: No dynamic expansion for "xyz" found

In GNU Emacs 29.0.60 (build 1, x86_64-pc-linux-gnu, X toolkit, cairo
 version 1.16.0, Xaw scroll bars) of 2023-01-26 built on projects
Repository revision: f8c95d1a7681e861fc22d2a040cda0ddfe23eff4
Repository branch: emacs-29
Windowing system distributor 'The X.Org Foundation', version 11.0.12011000
System Description: Debian GNU/Linux 11 (bullseye)





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

* bug#61274: 29.0.60; dabbrev-capf signals errors
  2023-02-04 11:03 bug#61274: 29.0.60; dabbrev-capf signals errors Daniel Mendler
@ 2023-02-04 13:16 ` Eli Zaretskii
  2023-02-04 16:03   ` Daniel Mendler
  0 siblings, 1 reply; 10+ messages in thread
From: Eli Zaretskii @ 2023-02-04 13:16 UTC (permalink / raw)
  To: Daniel Mendler; +Cc: 61274, monnier

> Cc: monnier@iro.umontreal.ca
> From: Daniel Mendler <mail@daniel-mendler.de>
> Date: Sat, 04 Feb 2023 12:03:26 +0100
> 
> The completion-at-point-function `dabbrev-capf' sometimes signals
> errors. It would be good if the function would not do that but return
> nil if no completions are found, such that the next Capf from the list
> of completion functions gets its chance to run.
> 
> 1. Start emacs -Q
> 2. Evaluate (require 'dabbrev).
> 3. Evaluate (setq completion-at-point-functions '(dabbrev-capf)) in the
> scratch buffer.
> 4. Type `x M-TAB` in the scratch buffer. I observe the following error:
> 
> Debugger entered--Lisp error: (wrong-type-argument stringp nil)
>   dabbrev--goto-start-of-abbrev()
>   dabbrev--abbrev-at-point()
>   dabbrev-capf()
>   completion--capf-wrapper(dabbrev-capf all)
>   completion-at-point()
>   funcall-interactively(completion-at-point)
>   command-execute(completion-at-point)
> 
> Furthermore if no completions are found `dabbrev-capf' signals an error.
> The messages buffer will then contain:
> 
> Scanning for dabbrevs...done
> completion--some: No dynamic expansion for "xyz" found

The patch below fixes the error.

Regarding "No dynamic expansion" error: what did you expect to happen
instead and why?  IOW, what is the expected result of having
dabbrev-capf alone in completion-at-point-functions, and then typing
"x M-TAB"?

diff --git a/lisp/dabbrev.el b/lisp/dabbrev.el
index a4b4d07..deba082 100644
--- a/lisp/dabbrev.el
+++ b/lisp/dabbrev.el
@@ -400,6 +400,8 @@ dabbrev-completion
 
 (defun dabbrev-capf ()
   "Dabbrev completion function for `completion-at-point-functions'."
+  (or (stringp dabbrev--abbrev-char-regexp)
+      (dabbrev--reset-global-variables))
   (let* ((abbrev (dabbrev--abbrev-at-point))
          (beg (progn (search-backward abbrev) (point)))
          (end (progn (search-forward abbrev) (point)))





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

* bug#61274: 29.0.60; dabbrev-capf signals errors
  2023-02-04 13:16 ` Eli Zaretskii
@ 2023-02-04 16:03   ` Daniel Mendler
  2023-02-04 16:54     ` Eli Zaretskii
  0 siblings, 1 reply; 10+ messages in thread
From: Daniel Mendler @ 2023-02-04 16:03 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 61274, monnier

On 2/4/23 14:16, Eli Zaretskii wrote:
> The patch below fixes the error.

Thanks!

> Regarding "No dynamic expansion" error: what did you expect to happen
> instead and why?  IOW, what is the expected result of having
> dabbrev-capf alone in completion-at-point-functions, and then typing
> "x M-TAB"?

I would expect the completion UI to show a message, instead of an error
from the Capf. For example if you start emacs -Q, type "nonexistent
M-TAB" in the scratch buffer to access the normal Elisp completions.
Then you will see the message "No match" in the minibuffer. If
`dabbrev-capf' would not throw an error, we would get the same message.

Daniel





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

* bug#61274: 29.0.60; dabbrev-capf signals errors
  2023-02-04 16:03   ` Daniel Mendler
@ 2023-02-04 16:54     ` Eli Zaretskii
  2023-02-04 17:13       ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2023-02-04 17:23       ` Daniel Mendler
  0 siblings, 2 replies; 10+ messages in thread
From: Eli Zaretskii @ 2023-02-04 16:54 UTC (permalink / raw)
  To: Daniel Mendler; +Cc: 61274, monnier

> Date: Sat, 4 Feb 2023 17:03:26 +0100
> Cc: 61274@debbugs.gnu.org, monnier@iro.umontreal.ca
> From: Daniel Mendler <mail@daniel-mendler.de>
> 
> On 2/4/23 14:16, Eli Zaretskii wrote:
> > The patch below fixes the error.
> 
> Thanks!

Should I install it?

> > Regarding "No dynamic expansion" error: what did you expect to happen
> > instead and why?  IOW, what is the expected result of having
> > dabbrev-capf alone in completion-at-point-functions, and then typing
> > "x M-TAB"?
> 
> I would expect the completion UI to show a message, instead of an error
> from the Capf. For example if you start emacs -Q, type "nonexistent
> M-TAB" in the scratch buffer to access the normal Elisp completions.
> Then you will see the message "No match" in the minibuffer. If
> `dabbrev-capf' would not throw an error, we would get the same message.

maybe dabbrev-capf is unsuitable to serve as the value of
completion-at-point-functions?

Stefan, any comments?





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

* bug#61274: 29.0.60; dabbrev-capf signals errors
  2023-02-04 16:54     ` Eli Zaretskii
@ 2023-02-04 17:13       ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2023-02-04 17:17         ` Eli Zaretskii
  2023-02-04 17:23       ` Daniel Mendler
  1 sibling, 1 reply; 10+ messages in thread
From: Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2023-02-04 17:13 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Daniel Mendler, 61274

> maybe dabbrev-capf is unsuitable to serve as the value of
> completion-at-point-functions?

As the name implies, it's a function designed specifically for use on
`completion-at-point-functions`.  Maybe dabbrev is not well adapted
for use within a normal completion UI, but `dabbrev-capf` should do its
best to obey the rules of `completion-at-point-functions`, so I think
the behavior Daniel suggests is indeed what `dabbrev-capf` should try
to do.

Those people who don't like it can use dabbrev via various other UIs.


        Stefan






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

* bug#61274: 29.0.60; dabbrev-capf signals errors
  2023-02-04 17:13       ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2023-02-04 17:17         ` Eli Zaretskii
  2023-02-04 17:30           ` Daniel Mendler
  0 siblings, 1 reply; 10+ messages in thread
From: Eli Zaretskii @ 2023-02-04 17:17 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: mail, 61274

> From: Stefan Monnier <monnier@iro.umontreal.ca>
> Cc: Daniel Mendler <mail@daniel-mendler.de>,  61274@debbugs.gnu.org
> Date: Sat, 04 Feb 2023 12:13:27 -0500
> 
> > maybe dabbrev-capf is unsuitable to serve as the value of
> > completion-at-point-functions?
> 
> As the name implies, it's a function designed specifically for use on
> `completion-at-point-functions`.  Maybe dabbrev is not well adapted
> for use within a normal completion UI, but `dabbrev-capf` should do its
> best to obey the rules of `completion-at-point-functions`, so I think
> the behavior Daniel suggests is indeed what `dabbrev-capf` should try
> to do.

Then there's something here that puzzles me: the recipe presented by
Daniel is basically identical to what dabbrev-completion does.  And
yet dabbrev-completion produces different effects when invoked in the
same buffer with the same text at point.  What is responsible for the
difference in behavior?





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

* bug#61274: 29.0.60; dabbrev-capf signals errors
  2023-02-04 16:54     ` Eli Zaretskii
  2023-02-04 17:13       ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2023-02-04 17:23       ` Daniel Mendler
  1 sibling, 0 replies; 10+ messages in thread
From: Daniel Mendler @ 2023-02-04 17:23 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 61274, monnier

On 2/4/23 17:54, Eli Zaretskii wrote:
>> Date: Sat, 4 Feb 2023 17:03:26 +0100
>> Cc: 61274@debbugs.gnu.org, monnier@iro.umontreal.ca
>> From: Daniel Mendler <mail@daniel-mendler.de>
>>
>> On 2/4/23 14:16, Eli Zaretskii wrote:
>>> The patch below fixes the error.
>>
>> Thanks!
> 
> Should I install it?

Yes, please, if Stefan agrees. He added dabbrev-capf.

Daniel





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

* bug#61274: 29.0.60; dabbrev-capf signals errors
  2023-02-04 17:17         ` Eli Zaretskii
@ 2023-02-04 17:30           ` Daniel Mendler
  2023-02-04 18:09             ` Eli Zaretskii
  0 siblings, 1 reply; 10+ messages in thread
From: Daniel Mendler @ 2023-02-04 17:30 UTC (permalink / raw)
  To: Eli Zaretskii, Stefan Monnier; +Cc: 61274

On 2/4/23 18:17, Eli Zaretskii wrote:
>> From: Stefan Monnier <monnier@iro.umontreal.ca>
>> Cc: Daniel Mendler <mail@daniel-mendler.de>,  61274@debbugs.gnu.org
>> Date: Sat, 04 Feb 2023 12:13:27 -0500
>>
>>> maybe dabbrev-capf is unsuitable to serve as the value of
>>> completion-at-point-functions?
>>
>> As the name implies, it's a function designed specifically for use on
>> `completion-at-point-functions`.  Maybe dabbrev is not well adapted
>> for use within a normal completion UI, but `dabbrev-capf` should do its
>> best to obey the rules of `completion-at-point-functions`, so I think
>> the behavior Daniel suggests is indeed what `dabbrev-capf` should try
>> to do.
> 
> Then there's something here that puzzles me: the recipe presented by
> Daniel is basically identical to what dabbrev-completion does.  And
> yet dabbrev-completion produces different effects when invoked in the
> same buffer with the same text at point.  What is responsible for the
> difference in behavior?

You mean that the stringp type error does not occur? There is some code
in `dabbrev-completion' which sets up Dabbrev (resets variables etc), so
this is likely causing the difference.

However the second issue still occurs even with `dabbrev-completion'.
When I execute `dabbrev-completion' in a buffer where no completions are
found, I get the message "dabbrev--abbrev-at-point: No possible
abbreviation preceding point", while the message should be the usual "No
match" from `completion-at-point'. At this point we are moving into
problematic territory however, since Stefan reimplemented
`dabbrev-completion' based on `dabbrev-capf'. We may want a more
specific error message for `dabbev-completion', while we don't want any
errors signalled by `dabbrev-capf', such that it conforms to the
`completion-at-point-functions' contract.

Daniel





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

* bug#61274: 29.0.60; dabbrev-capf signals errors
  2023-02-04 17:30           ` Daniel Mendler
@ 2023-02-04 18:09             ` Eli Zaretskii
  2023-02-04 18:21               ` Daniel Mendler
  0 siblings, 1 reply; 10+ messages in thread
From: Eli Zaretskii @ 2023-02-04 18:09 UTC (permalink / raw)
  To: Daniel Mendler; +Cc: 61274, monnier

> Date: Sat, 4 Feb 2023 18:30:41 +0100
> Cc: 61274@debbugs.gnu.org
> From: Daniel Mendler <mail@daniel-mendler.de>
> 
> > Then there's something here that puzzles me: the recipe presented by
> > Daniel is basically identical to what dabbrev-completion does.  And
> > yet dabbrev-completion produces different effects when invoked in the
> > same buffer with the same text at point.  What is responsible for the
> > difference in behavior?
> 
> You mean that the stringp type error does not occur? There is some code
> in `dabbrev-completion' which sets up Dabbrev (resets variables etc), so
> this is likely causing the difference.

This is solved by my patch.

I thought there was some difference in behavior even after that, but
it looks like I cannot reproduce it now, so I will consider that my
dream.

> However the second issue still occurs even with `dabbrev-completion'.
> When I execute `dabbrev-completion' in a buffer where no completions are
> found, I get the message "dabbrev--abbrev-at-point: No possible
> abbreviation preceding point", while the message should be the usual "No
> match" from `completion-at-point'.

I see a different message:

  completion--some: No dynamic expansion for "x" found in this-buffer

Which IMO is completely reasonable.





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

* bug#61274: 29.0.60; dabbrev-capf signals errors
  2023-02-04 18:09             ` Eli Zaretskii
@ 2023-02-04 18:21               ` Daniel Mendler
  0 siblings, 0 replies; 10+ messages in thread
From: Daniel Mendler @ 2023-02-04 18:21 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 61274, monnier

On 2/4/23 19:09, Eli Zaretskii wrote:
>> However the second issue still occurs even with `dabbrev-completion'.
>> When I execute `dabbrev-completion' in a buffer where no completions are
>> found, I get the message "dabbrev--abbrev-at-point: No possible
>> abbreviation preceding point", while the message should be the usual "No
>> match" from `completion-at-point'.
> 
> I see a different message:
> 
>   completion--some: No dynamic expansion for "x" found in this-buffer
> 
> Which IMO is completely reasonable.

It is for `dabbrev-completion` but not for `dabbrev-capf', which should
better not throw any errors, such that the next Capf gets its chance to
run as I mentioned in my initial mail. Maybe Stefan has some more
comments on how we could resolve this?

Daniel





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

end of thread, other threads:[~2023-02-04 18:21 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-04 11:03 bug#61274: 29.0.60; dabbrev-capf signals errors Daniel Mendler
2023-02-04 13:16 ` Eli Zaretskii
2023-02-04 16:03   ` Daniel Mendler
2023-02-04 16:54     ` Eli Zaretskii
2023-02-04 17:13       ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-02-04 17:17         ` Eli Zaretskii
2023-02-04 17:30           ` Daniel Mendler
2023-02-04 18:09             ` Eli Zaretskii
2023-02-04 18:21               ` Daniel Mendler
2023-02-04 17:23       ` Daniel Mendler

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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).