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)