]> git.eshelyaron.com Git - emacs.git/commitdiff
Process read-symbol-shorthands from longest to shortest (bug#67390)
authorJoão Távora <joaotavora@gmail.com>
Thu, 30 Nov 2023 12:00:38 +0000 (06:00 -0600)
committerEshel Yaron <me@eshelyaron.com>
Sun, 4 Feb 2024 11:05:10 +0000 (12:05 +0100)
This ensures that overlapping shorthands are handled correctly and
consistently even if specified out-of-order by the user.

* doc/lispref/symbols.texi (Shorthands): Describe shorthand sort
order.

* lisp/files.el (hack-local-variables--find-variables): Specially
handle read-symbol-shorthands.

(cherry picked from commit c2aaa8f15aa8fb3415a6c9f421f539ee34b7f52c)

doc/lispref/symbols.texi
lisp/files.el

index 367bd195f16e0ff77670864f6c7fee029b6ba7fe..e95e53d972d83a802280d9fb8a5cf6a5558405be 100644 (file)
@@ -761,6 +761,23 @@ instead of @code{snu-}.
 ;; End:
 @end example
 
+Note that if you have two shorthands in the same file where one is the
+prefix of the other, the longer shorthand will be attempted first.
+This happens regardless of the order you specify shorthands in the
+local variables section of your file.
+
+@example
+'(
+  t//foo ; reads to 'my-tricks--foo', not 'my-tricks-/foo'
+  t/foo  ; reads to 'my-tricks-foo'
+  )
+
+;; Local Variables:
+;; read-symbol-shorthands: (("t/" . "my-tricks-")
+;;                          ("t//" . "my-tricks--")
+;; End:
+@end example
+
 @subsection Exceptions
 
 There are two exceptions to rules governing Shorthand transformations:
index 4c7faf4e0b5d608d4c1e20621459db4f6ad1d412..3be5831ba068c7132bde18f121d1519dcb325bf2 100644 (file)
@@ -4191,6 +4191,13 @@ major-mode."
                                 ;; to use 'thisbuf's name in the
                                 ;; warning message.
                                 (or (buffer-file-name thisbuf) ""))))))
+                          ((eq var 'read-symbol-shorthands)
+                           ;; Sort automatically by shorthand length
+                           ;; descending
+                           (setq val (sort val
+                                           (lambda (sh1 sh2) (> (length (car sh1))
+                                                                (length (car sh2))))))
+                           (push (cons 'read-symbol-shorthands val) result))
                           ((and (eq var 'mode) handle-mode))
                          (t
                           (ignore-errors