unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: "João Távora" <joaotavora@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 51089@debbugs.gnu.org, Richard Stallman <rms@gnu.org>
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	[thread overview]
Message-ID: <87tuho5qs5.fsf@gmail.com> (raw)
In-Reply-To: <CALDnm52hc_MZuTanveA2Rm+bS6Q3sUc7On6c2LUn+8g289162A@mail.gmail.com> ("João Távora"'s message of "Mon, 11 Oct 2021 01:18:43 +0100")

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	other threads:[~2021-10-11  0:49 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-07 20:44 bug#51089: 28.0.60; Using read-symbol-shorthands (("-" . "foo-")) shouldn't shadow the '-' symbol João Távora
2021-10-08  5:49 ` Eli Zaretskii
2021-10-08  7:43   ` João Távora
2021-10-08 11:04     ` Eli Zaretskii
2021-10-08 14:02       ` João Távora
2021-10-08 16:01         ` Eli Zaretskii
2021-10-08 19:07           ` Eli Zaretskii
2021-10-09 11:21             ` João Távora
2021-10-09 11:52               ` Eli Zaretskii
2021-10-10 13:42                 ` João Távora
2021-10-11  0:18                 ` João Távora
2021-10-11  0:49                   ` João Távora [this message]
2021-10-11 21:36                     ` João Távora
2021-10-12 13:22                       ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87tuho5qs5.fsf@gmail.com \
    --to=joaotavora@gmail.com \
    --cc=51089@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=rms@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).