all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Joseph Turner via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Jonas Bernoulli <jonas@bernoul.li>
Cc: 67390@debbugs.gnu.org, "Adam Porter" <adam@alphapapa.net>,
	"João Távora" <joaotavora@gmail.com>
Subject: bug#67390: 28; shorthands-font-lock-shorthands assumes shorthand uses same separator
Date: Sat, 25 Nov 2023 14:42:48 -0800	[thread overview]
Message-ID: <875y1po3nk.fsf@ushin.org> (raw)
In-Reply-To: <87sf4tg6ts.fsf@bernoul.li>

[-- Attachment #1: Type: text/plain, Size: 512 bytes --]

Jonas Bernoulli <jonas@bernoul.li> writes:

> Joseph Turner <joseph@ushin.org> writes:
>
>> +                          (car (shorthands--find-if
>> +                                (lambda (short)
>> +                                  (string-prefix-p short (match-string 1)))
>> +                                read-symbol-shorthands #'car)))))
>
> Or simply:
>   (car (assoc (match-string 1)
>               read-symbol-shorthands
>               #'string-prefix-p))

Much nicer - see patch.  Thanks, Jonas!


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Support-shorthand-prefixes-besides.patch --]
[-- Type: text/x-diff, Size: 2341 bytes --]

From 5033a0e14950ed1622db78df1828c40de4b5a23a Mon Sep 17 00:00:00 2001
From: Joseph Turner <joseph@breatheoutbreathe.in>
Date: Fri, 24 Nov 2023 19:17:13 -0800
Subject: [PATCH] Support shorthand prefixes besides "-"

* lisp/emacs-lisp/shorthands.el (shorthands-font-lock-shorthands):
Add font locking to the shorthand prefix by checking if any of the
shorthand prefixes in read-symbol-shorthands are a prefix for the
current symbol name (bug#67390).

Co-authored-by: Jonas Bernoulli <jonas@bernoul.li>
---
 lisp/emacs-lisp/shorthands.el | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)

diff --git a/lisp/emacs-lisp/shorthands.el b/lisp/emacs-lisp/shorthands.el
index 82200ab88e9..6ce9984a353 100644
--- a/lisp/emacs-lisp/shorthands.el
+++ b/lisp/emacs-lisp/shorthands.el
@@ -52,13 +52,6 @@
   :version "28.1"
   :group 'font-lock-faces)
 
-(defun shorthands--mismatch-from-end (str1 str2)
-  (cl-loop with l1 = (length str1) with l2 = (length str2)
-           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))))
-
 (defun shorthands-font-lock-shorthands (limit)
   (when read-symbol-shorthands
     (while (re-search-forward
@@ -69,10 +62,14 @@
                                                font-lock-string-face)))
                          (intern-soft (match-string 1))))
              (sname (and probe (symbol-name probe)))
-             (mm (and sname (shorthands--mismatch-from-end
-                             (match-string 1) sname))))
-        (unless (or (null mm) (= mm (length sname)))
-          (add-face-text-property (match-beginning 1) (1+ (- (match-end 1) mm))
+             (prefix (and sname
+                          (not (string-equal (match-string 1) sname))
+                          (car (assoc (match-string 1)
+                                      read-symbol-shorthands
+                                      #'string-prefix-p)))))
+        (when prefix
+          (add-face-text-property (match-beginning 1)
+                                  (+ (match-beginning 1) (length prefix))
                                   'elisp-shorthand-font-lock-face))))))
 
 (font-lock-add-keywords 'emacs-lisp-mode '((shorthands-font-lock-shorthands)) t)
-- 
2.41.0


  reply	other threads:[~2023-11-25 22:42 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-22 22:18 bug#67390: 28; shorthands-font-lock-shorthands assumes shorthand uses same separator Jonas Bernoulli via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-11-23 12:57 ` João Távora
2023-11-24 21:51   ` Jonas Bernoulli via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-11-25  0:03     ` João Távora
2023-11-25  3:26       ` Joseph Turner via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-11-25 16:01         ` Jonas Bernoulli via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-11-25 22:42           ` Joseph Turner via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2023-11-26 13:52             ` João Távora
2023-11-26 20:35               ` Joseph Turner via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-11-26 22:02                 ` João Távora
2023-11-27  3:48                   ` Joseph Turner via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-11-27 12:10                   ` Eli Zaretskii
2023-11-29  8:21                     ` João Távora
2023-11-29  9:12                       ` Joseph Turner via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-11-29 13:56                         ` João Távora
2023-11-29 13:30           ` João Távora
2023-11-29 23:27             ` João Távora
2023-11-30 14:16               ` João Távora
2023-11-30 15:23                 ` Eli Zaretskii
2023-11-30 15:29                   ` João Távora
2023-12-09 18:50                 ` Joseph Turner via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-02-03  7:10                   ` Joseph Turner via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-02-03 14:50                     ` João Távora
2024-02-03 19:43                       ` Joseph Turner via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-02-03 22:25                         ` João Távora
2024-02-03 23:48                           ` Joseph Turner via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-21 22:05                             ` Joseph Turner via Bug reports for GNU Emacs, the Swiss army knife of text editors

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

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

  git send-email \
    --in-reply-to=875y1po3nk.fsf@ushin.org \
    --to=bug-gnu-emacs@gnu.org \
    --cc=67390@debbugs.gnu.org \
    --cc=adam@alphapapa.net \
    --cc=joaotavora@gmail.com \
    --cc=jonas@bernoul.li \
    --cc=joseph@ushin.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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.