GNU bug report logs - #67390
28; shorthands-font-lock-shorthands assumes shorthand uses same separator

Previous Next

Package: emacs;

Reported by: Jonas Bernoulli <jonas <at> bernoul.li>

Date: Wed, 22 Nov 2023 22:19:01 UTC

Severity: normal

Full log


View this message in rfc822 format

From: Jonas Bernoulli <jonas <at> bernoul.li>
To: João Távora <joaotavora <at> gmail.com>
Cc: joseph <at> ushin.org, adam <at> alphapapa.net, 67390 <at> debbugs.gnu.org
Subject: bug#67390: 28; shorthands-font-lock-shorthands assumes shorthand uses same separator
Date: Fri, 24 Nov 2023 22:51:32 +0100
João Távora <joaotavora <at> gmail.com> writes:

> On Wed, Nov 22, 2023 at 10:18 PM Jonas Bernoulli <jonas <at> bernoul.li> wrote:
>
>> Could we add support for using an alternative separator in shorthands?
>
> I think so, if you can find a patch for it.  This only affects the font-locking
> bits of shorthands right?  IOW all other shorthand-aware functionality like
> eldoc, M-., etc, already works with different separators, right?

I haven't found any issues beside this off-by-one font-lock issue.

So far I have used this beauty:

diff --git a/lisp/emacs-lisp/shorthands.el b/lisp/emacs-lisp/shorthands.el
@@ -57,7 +57,7 @@ shorthands--mismatch-from-end
            for i from 1
            for i1 = (- l1 i) for i2 = (- l2 i)
            while (and (>= i1 0) (>= i2 0) (eq (aref str1 i1) (aref str2 i2)))
-           finally (return (1- i))))
+           finally (return (if (eq (aref str2 (1+ i2)) ?-) (1- i) i))))

Is that good enough?  Depending on how you look at it, this changes what
is being returned, but IMO this function is a bit murky to begin with.

The function name is `shorthands--mismatch-from-end', but it returns the
length of the common suffix, minus one, to account for the separator.
This change ensures that the separator is accounted for, even if it
differs between the shorthand and real symbol.

Since this function returns the length of the *matching* suffix after
the prefixes (including separator), I find it weird that its name
contains *MISmatch*.

It might make more sense to return the length of the shorthand prefix.

Also, have you considered throwing in a
  (not (string-equal (match-string 1) sname))

to avoid having to call `shorthands--mismatch-from-end' at all?
Maybe you have, but concluded it is cheaper to do a bit too much work
for non-shorthands, than to effectively repeat some work for shorthands.

     Jonas




This bug report was last modified 1 year and 24 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.