emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/julia-mode 107940a19e 09/14: Font-lock const definitions w


From: ELPA Syncer
Subject: [nongnu] elpa/julia-mode 107940a19e 09/14: Font-lock const definitions with font-lock-variable-name-face
Date: Wed, 12 Jul 2023 04:00:17 -0400 (EDT)

branch: elpa/julia-mode
commit 107940a19ecc227be433a953a74b8f5264d3a12f
Author: Adam Beckmeyer <adam_gpg@thebeckmeyers.xyz>
Commit: Adam Beckmeyer <adam_gpg@thebeckmeyers.xyz>

    Font-lock const definitions with font-lock-variable-name-face
    
    This commit also adds a test, so all of the regexes used by imenu should 
have associated
    tests now. Since we're defining this regex for imenu anyway, might as well 
use it for
    font-locking as well.
---
 julia-mode-tests.el |  9 +++++++++
 julia-mode.el       | 20 ++++++++++++--------
 2 files changed, 21 insertions(+), 8 deletions(-)

diff --git a/julia-mode-tests.el b/julia-mode-tests.el
index bafff50f96..06b71cfd19 100644
--- a/julia-mode-tests.el
+++ b/julia-mode-tests.el
@@ -532,6 +532,15 @@ end")
     (julia--should-font-lock string 74 font-lock-type-face) ; B
     ))
 
+(ert-deftest julia--test-const-def-font-lock ()
+  (let ((string "const foo = \"bar\""))
+    (julia--should-font-lock string 1 font-lock-keyword-face) ; const
+    (julia--should-font-lock string 5 font-lock-keyword-face) ; const
+    (julia--should-font-lock string 7 font-lock-variable-name-face) ; foo
+    (julia--should-font-lock string 9 font-lock-variable-name-face) ; foo
+    (julia--should-font-lock string 11 nil) ; =
+    ))
+
 ;;; Movement
 (ert-deftest julia--test-beginning-of-defun-assn-1 ()
   "Point moves to beginning of single-line assignment function."
diff --git a/julia-mode.el b/julia-mode.el
index 24201289f4..b2c6f361a1 100644
--- a/julia-mode.el
+++ b/julia-mode.el
@@ -236,6 +236,13 @@
                        "abstract type" "primitive type" "struct" "mutable 
struct")
       (1+ space) (group (1+ (or word (syntax symbol))))))
 
+(defconst julia-const-def-regex
+  (rx
+   bol (zero-or-more space)
+   "const" space
+   (group (one-or-more alnum)) (zero-or-more space)
+   "=" (not (any "="))))
+
 (defconst julia-type-annotation-regex
   (rx "::" (0+ space) (group (1+ (or word (syntax symbol))))))
 
@@ -283,6 +290,10 @@
    (list julia-function-regex 1 'font-lock-function-name-face)
    (list julia-function-assignment-regex 1 'font-lock-function-name-face)
    (list julia-type-regex 1 'font-lock-type-face)
+   ;; Per the elisp manual, font-lock-variable-name-face is for variables 
being defined or
+   ;; declared. It is difficult identify this consistently in julia (see issue 
#2). For now,
+   ;; we only font-lock constant definitions.
+   (list julia-const-def-regex 1 'font-lock-variable-name-face)
    ;; font-lock-type-face is for the point of type definition rather
    ;; than usage, but using for type annotations is an acceptable pun.
    (list julia-type-annotation-regex 1 'font-lock-type-face)
@@ -700,19 +711,12 @@ Return nil if point is not in a function, otherwise 
point."
       (end-of-line)
       (point))))
 
-(defconst julia-imenu-const
-  (rx
-   bol (zero-or-more space)
-   "const" space
-   (group (one-or-more alnum)) (zero-or-more space)
-   "=" space))
-
 ;;; IMENU
 (defvar julia-imenu-generic-expression
   ;; don't use syntax classes, screws egrep
   `(("Function" ,julia-function-regex 1)
     ("Function" ,julia-function-assignment-regex 1)
-    ("Const" ,julia-imenu-const 1)
+    ("Const" ,julia-const-def-regex 1)
     ("Struct" ,julia-type-regex 1)
     ("Require" " *\\(\\brequire\\)(\\([^ \t\n)]*\\)" 2)
     ("Include" " *\\(\\binclude\\)(\\([^ \t\n)]*\\)" 2)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]