branch: elpa/llama
commit 395185850a2de7962db3576a663274ffe0ec9220
Author: Jonas Bernoulli <jo...@bernoul.li>
Commit: Jonas Bernoulli <jo...@bernoul.li>

    Override elisp-mode-syntax-propertize to leave ## alone
    
    In Emacs 29.1 a syntax property rule was added to treat `##' as the
    symbol it is (except in comments and docstrings).  However `##' is
    different from other symbols in that no space has to used in between
    it and the following symbol, to prevent them from becoming one symbol,
    we take advantage of that idiosyncrasy.
    
    We revert this because the feature that depend on `##' having symbol
    syntax are less important than the features that would get confused
    and treat `##' and the following symbol as one symbol.
    
    However, in docstrings and comments `##' (with the `...' around it)
    should be fontified like other symbols, so there we do give it symbol
    syntax - unlike the commented out code, which explicitly prevented
    that.
---
 llama.el | 42 +++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 41 insertions(+), 1 deletion(-)

diff --git a/llama.el b/llama.el
index 85fc1dc496..6d2eb4653e 100644
--- a/llama.el
+++ b/llama.el
@@ -166,6 +166,8 @@ It also looks a bit like #\\='function."
     (seq-doseq (elt data)
       (llama--collect elt args)))))
 
+;;; Advices
+
 (defun llama--expect-function-p (fn pos)
   (or (and (eq (char-before    pos)    ?#)
            (eq (char-before (- pos 1)) ?#))
@@ -176,7 +178,45 @@ It also looks a bit like #\\='function."
 
 (advice-add 'elisp--expect-function-p :around #'llama--expect-function-p)
 
-;;; _
+(when (eval (fboundp 'elisp-mode-syntax-propertize) t)
+  ;; Synced with Emacs up to 6b9510d94f814cacf43793dce76250b5f7e6f64a.
+  (defun llama--elisp-mode-syntax-propertize (start end)
+    "Like `elisp-mode-syntax-propertize' but don't change syntax of `##'."
+    (goto-char start)
+    (let ((case-fold-search nil))
+      (funcall
+       (syntax-propertize-rules
+        ;; Empty symbol.
+        ;; {{ Comment out to prevent the `##' from becoming part of
+        ;;    the following symbol when there is no space in between.
+        ;; ("##" (0 (unless (nth 8 (syntax-ppss))
+        ;;            (string-to-syntax "_"))))
+        ;; }}
+        ;; {{ As for other symbols, use `font-lock-constant-face' in
+        ;;    docstrings and comments.
+        ("##" (0 (when (nth 8 (syntax-ppss))
+                   (string-to-syntax "_"))))
+        ;; }}
+        ;; Prevent the @ from becoming part of a following symbol.
+        ;; {{ Preserve this part, even though it is absent from
+        ;;    this function in 29.1; backporting it by association.
+        (",@" (0 (unless (nth 8 (syntax-ppss))
+                   (string-to-syntax "'"))))
+        ;; }}
+        ;; Unicode character names.  (The longest name is 88 characters
+        ;; long.)
+        ("\\?\\\\N{[-A-Za-z0-9 ]\\{,100\\}}"
+         (0 (unless (nth 8 (syntax-ppss))
+              (string-to-syntax "_"))))
+        ((rx "#" (or (seq (group-n 1 "&" (+ digit)) ?\") ; Bool-vector.
+                     (seq (group-n 1 "s") "(")           ; Record.
+                     (seq (group-n 1 (+ "^")) "[")))     ; Char-table.
+         (1 (unless (save-excursion (nth 8 (syntax-ppss (match-beginning 0))))
+              (string-to-syntax "'")))))
+       start end)))
+  (advice-add 'elisp-mode-syntax-propertize :override
+              'llama--elisp-mode-syntax-propertize))
+
 (provide 'llama)
 ;; Local Variables:
 ;; indent-tabs-mode: nil

Reply via email to