From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?= Newsgroups: gmane.emacs.bugs 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 Message-ID: <87tuho5qs5.fsf@gmail.com> References: <871r4w8sza.fsf@gmail.com> <83ee8wysk5.fsf@gnu.org> <87v9286jwt.fsf@gmail.com> <835yu7zsiz.fsf@gnu.org> <83r1cvy07v.fsf@gnu.org> <83fstbxrmd.fsf@gnu.org> <87ee8u78an.fsf@gmail.com> <83sfxawh2j.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="24981"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.60 (gnu/linux) Cc: 51089@debbugs.gnu.org, Richard Stallman To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Oct 11 02:50:16 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mZjWC-0006KR-5K for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 11 Oct 2021 02:50:16 +0200 Original-Received: from localhost ([::1]:35480 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mZjWA-0006e1-7y for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 10 Oct 2021 20:50:14 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:47696) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mZjVy-0006cD-AE for bug-gnu-emacs@gnu.org; Sun, 10 Oct 2021 20:50:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:44581) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mZjVy-0004Do-1x for bug-gnu-emacs@gnu.org; Sun, 10 Oct 2021 20:50:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mZjVx-0000Qw-Vn for bug-gnu-emacs@gnu.org; Sun, 10 Oct 2021 20:50:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: =?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 11 Oct 2021 00:50:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 51089 X-GNU-PR-Package: emacs Original-Received: via spool by 51089-submit@debbugs.gnu.org id=B51089.16339133921643 (code B ref 51089); Mon, 11 Oct 2021 00:50:01 +0000 Original-Received: (at 51089) by debbugs.gnu.org; 11 Oct 2021 00:49:52 +0000 Original-Received: from localhost ([127.0.0.1]:56127 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mZjVo-0000QP-6a for submit@debbugs.gnu.org; Sun, 10 Oct 2021 20:49:52 -0400 Original-Received: from mail-wr1-f46.google.com ([209.85.221.46]:42893) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mZjVm-0000QA-L2 for 51089@debbugs.gnu.org; Sun, 10 Oct 2021 20:49:51 -0400 Original-Received: by mail-wr1-f46.google.com with SMTP id v17so50327349wrv.9 for <51089@debbugs.gnu.org>; Sun, 10 Oct 2021 17:49:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version:content-transfer-encoding; bh=Og0SifSCvVx/KkZmUe0faEa+VvRg6Gc3Ukv4zXVEvTY=; b=fKVcGYKfcUJnAzaP+16VziRNOuL545Bo19NUlmm8/E8OGV6Wq9M0D8Pu8i0W9hEE0E KwOAVjam5jb55Aq036wsLQlmYGXnsRtVvpyz6H724FprjLEPbUFG6gZW7EQ4p0y047hi 6rF2Dmp7wezMjnSy6PMgH5dlBBtKMvXrnsT133iYSfAzQg6cw6ICtzuEoKsQ2grb2G6M foq5APj7Ms2IeaYKZo3ID2gJMTdTb6Pn772bVeSmWoLd10Qqd3gLH6q08lb0IGM/zAW3 U+geHikQD/00PSxOxdY0dpRcGp+1Tv0/2GlEtu+8oE0Al7jZqE0kSpzq4F3SrvSUNRgV X7EA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version:content-transfer-encoding; bh=Og0SifSCvVx/KkZmUe0faEa+VvRg6Gc3Ukv4zXVEvTY=; b=M+aEioGIui3MGZMkdfcT21RBqgP3vnKDFXO1LZ3dpgftCy0SBkmHih+/Dr/DaDvhqw a5zd8c1rxTP1F903+/TBoim1EluN4H67HBfxJ2X7XqnJDezWDSWLSfU17gmQUKcRAH1p 9HrR1ZNKkRwJPEm/3fatGUMzFq8hltCsAWVI0NnNCM2z2zFPdqRqMOBPiK8QJmt7GSyD JNtIAwiGQLxMsnPdbUzpilwqSGxIZLTR1boP1GFnpYyHlSzfw36I9F6HRMjFl8PWkBO+ qTiOGjlQdJGx+jrzw3RarGc3xTyX65LOjURftE7vWdT0B4TcFXWYz701BmDoypGKXAxl ERuw== X-Gm-Message-State: AOAM531tVrbM3Urnn5bMUEN138QxziEJIAuRG08pxVbP71fJArZMCNfI bHHrcetQfoh2zZRdKd/sdcc= X-Google-Smtp-Source: ABdhPJwQpYB5W8XmnqykcjwHjpbpeE0xuOIEbPaY03cjRiZaNB6EufWMFlqNcv771JDGTb0rXPr1MQ== X-Received: by 2002:a05:600c:378a:: with SMTP id o10mr5731911wmr.77.1633913384561; Sun, 10 Oct 2021 17:49:44 -0700 (PDT) Original-Received: from krug (a83-132-196-192.cpe.netcabo.pt. [83.132.196.192]) by smtp.gmail.com with ESMTPSA id j4sm6356364wrt.67.2021.10.10.17.49.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Oct 2021 17:49:43 -0700 (PDT) In-Reply-To: ("=?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?="'s message of "Mon, 11 Oct 2021 01:18:43 +0100") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:216846 Archived-At: Jo=C3=A3o T=C3=A1vora writes: > On Sat, Oct 9, 2021 at 12:53 PM Eli Zaretskii 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=C3=A3o 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 =20 This variable may only be set in file-local variables (@pxref{File Variabl= es, , 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 =20 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 =3D 0; =20 Lisp_Object tem; - if (skip_shorthand) + + if (skip_shorthand || + strspn(read_buffer, "!@#$%&^*_+-/=3D<>") >=3D nbytes) tem =3D oblookup (obarray, read_buffer, nchars, nbytes); else tem =3D 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---")))) =20 (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