]> git.eshelyaron.com Git - emacs.git/commit
Improve shorthands-font-lock-shorthands (bug#67390)
authorJoão Távora <joaotavora@gmail.com>
Wed, 29 Nov 2023 22:48:34 +0000 (16:48 -0600)
committerEshel Yaron <me@eshelyaron.com>
Sun, 4 Feb 2024 11:05:17 +0000 (12:05 +0100)
commit5f627f85306856c0c09783297d0b312337ca93af
tree0a5bfb68d38599b48b04140cd2c920199855b1e6
parent37e7a602b6732aa0c28e61559cc435c2b5a3b227
Improve shorthands-font-lock-shorthands (bug#67390)

Add font locking to the shorthand prefix of a given printed symbol
name by checking if any of the shorthand prefixes in
read-symbol-shorthands are a prefix for that print name.  Although
this does more string comparisons, it didn't prove to be any slower
than the existing approach, and is more correct.

This version is more accurate when highlighting files with many
overlapping shorthands.   Given:

;; Local Variables:
;; read-symbol-shorthands: (("bc-" . "breadcrumb-")
;;                          ("aw-" . "ace-window-")
;;                          ("zorglub/" . "ace-window-")
;;                          ("he//" . "hyperdrive-entry--")
;;                          ("h//"  . "hyperdrive--")
;;                          ("he/"  . "hyperdrive-entry-")
;;                          ("h/"   . "hyperdrive-"))
;; End:

The following are correct highlights on print names

'(zorglub/blerh ; hilits "zorglub/" reads to 'ace-window-blerh'
  he/foo        ; hilits "he/"      reads to 'hyperdrive-entry-foo'
  he//bar       ; hilits "he//"     reads to 'hyperdrive-entry--bar'
  h/coiso       ; hilits "h/"       reads to 'hyperdrive-coiso'
  h//thingy     ; hilits "h//"      reads to 'hyperdrive--thingy'
  bc-yo         ; hilits "bc-"      reads to 'breadcrumb-yo'
  aw-thingy     ; hilits "aw-"      reads to 'ace-window-thingy'
  )

Co-authored-by: Jonas Bernoulli <jonas@bernoul.li>
Co-authored-by: Joseph Turner <joseph@ushin.org>
* lisp/emacs-lisp/shorthands.el (shorthands-font-lock-shorthands):

(cherry picked from commit 0f715f9c154a47de57a2f24f19b4a402604e6dc0)
lisp/emacs-lisp/shorthands.el