bug-gnu-emacs
[Top][All Lists]
Advanced

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

bug#51089: 28.0.60; Using read-symbol-shorthands (("-" . "foo-")) should


From: João Távora
Subject: bug#51089: 28.0.60; Using read-symbol-shorthands (("-" . "foo-")) shouldn't shadow the '-' symbol
Date: Mon, 11 Oct 2021 01:49:46 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.60 (gnu/linux)

João Távora <joaotavora@gmail.com> writes:

> On Sat, Oct 9, 2021 at 12:53 PM Eli Zaretskii <eliz@gnu.org> wrote:
>
>  > You mean iterate the string being analysed by bytes, and use strchr() on
>  > byte_i and a constant you'll provide me?  And if we reach a byte that's
>  > part of a multibyte one, we bail, knowing that it's not all ASCII
>  > punctuation...  Is that the idea?  Should work, yes.
>
>  Yes.  But I think we could use strcspn for an easier, one-line, test
>  of the same.
>
> I tried to use strcspn() to discover if a C string is entirely comprised
> of punctuation (as is required by your idea), but couldn't. That function
> deals with prefixes, it's not a "every()" kind of operation.  If you're
> seeing something clever to do with it, please tell me, because I'm not.

Seems I didn't try very hard :-)  Using strspn() instead of strcpsn() does
work.  Patch below, which a constant string of ASCII punctuation that
you'll probably want to tweak.

João

diff --git a/doc/lispref/symbols.texi b/doc/lispref/symbols.texi
index 9c33e2c8ec..5494b042e5 100644
--- a/doc/lispref/symbols.texi
+++ b/doc/lispref/symbols.texi
@@ -675,6 +675,11 @@ Shorthands
 
 This variable may only be set in file-local variables (@pxref{File Variables, ,
 Local Variables in Files, emacs, The GNU Emacs Manual}).
+
+As an exception to the above rule, symbol forms comprised entirely of
+ASCII punctuation are exempt from this transformation.  This avoids
+shadowing important symbols like @code{-} or @code{/} when using
+these strings as shorthand prefixes..
 @end defvar
 
 Here's an example of shorthands usage in a hypothetical string
diff --git a/src/lread.c b/src/lread.c
index 07580d11d1..8d23761a4b 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -3805,7 +3805,9 @@ read1 (Lisp_Object readcharfun, int *pch, bool 
first_in_list)
              ptrdiff_t longhand_bytes = 0;
 
              Lisp_Object tem;
-             if (skip_shorthand)
+
+             if (skip_shorthand ||
+                 strspn(read_buffer, "!@#$%&^*_+-/=<>") >= nbytes)
                tem = oblookup (obarray, read_buffer, nchars, nbytes);
              else
                tem = oblookup_considering_shorthand (obarray, read_buffer,
diff --git a/test/lisp/progmodes/elisp-mode-tests.el 
b/test/lisp/progmodes/elisp-mode-tests.el
index e816d3c1b0..ebdfe5f067 100644
--- a/test/lisp/progmodes/elisp-mode-tests.el
+++ b/test/lisp/progmodes/elisp-mode-tests.el
@@ -1094,7 +1094,6 @@ elisp-shorthand-escape
     (should (unintern "f-test4---"))))
 
 (ert-deftest elisp-dont-shadow-punctuation-only-symbols ()
-  :expected-result :failed ;  bug#51089
   (let* ((shorthanded-form '(- 42 (-foo 42)))
          (expected-longhand-form '(- 42 (fooey-foo 42)))
          (observed (let ((read-symbol-shorthands






reply via email to

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