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

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

[nongnu] elpa/julia-mode 36aa038 181/352: Fix julia-in-brackets so it is


From: ELPA Syncer
Subject: [nongnu] elpa/julia-mode 36aa038 181/352: Fix julia-in-brackets so it isn't confused by strings, characters or comments.
Date: Sun, 29 Aug 2021 11:22:40 -0400 (EDT)

branch: elpa/julia-mode
commit 36aa03807e798e85b6675ab019d68285ca4f2ecb
Author: Wilfred Hughes <me@wilfred.me.uk>
Commit: Yichao Yu <yyc1992@gmail.com>

    Fix julia-in-brackets so it isn't confused by strings, characters or 
comments.
---
 julia-mode.el | 34 ++++++++++++++++++++++------------
 1 file changed, 22 insertions(+), 12 deletions(-)

diff --git a/julia-mode.el b/julia-mode.el
index efbc9df..89216a9 100644
--- a/julia-mode.el
+++ b/julia-mode.el
@@ -35,6 +35,8 @@
 
 ;;; Code:
 
+(require 'cl) ;; incf, decf, plusp
+
 (defvar julia-mode-hook nil)
 
 (defvar julia-basic-offset)
@@ -258,19 +260,27 @@ Handles both single-line and multi-line comments."
               (looking-at julia-char-regex))
           nil))))))
 
-(defun julia-strcount (str chr)
-  (let ((i 0)
-       (c 0))
-    (while (< i (length str))
-      (if (equal (elt str i) chr)
-         (setq c (+ c 1)))
-      (setq i (+ i 1)))
-    c))
-
 (defun julia-in-brackets ()
-  (let ((before (buffer-substring (line-beginning-position) (point))))
-    (> (julia-strcount before ?[)
-       (julia-strcount before ?]))))
+  "Return non-nil if point is inside square brackets."
+  (let ((start-pos (point))
+        (open-count 0))
+    ;; Count all the [ and ] characters on the current line.
+    (save-excursion
+      (beginning-of-line)
+
+      (while (< (point) start-pos)
+        ;; Don't count [ or ] inside strings, characters or comments.
+        (unless (or (julia-in-string) (julia-in-char) (julia-in-comment))
+
+          (when (looking-at (rx "["))
+            (incf open-count))
+          (when (looking-at (rx "]"))
+            (decf open-count)))
+        
+        (forward-char 1)))
+
+    ;; If we've opened more than we've closed, we're inside brackets.
+    (plusp open-count)))
 
 (defun julia-at-keyword (kw-list)
   "Return the word at point if it matches any keyword in KW-LIST.



reply via email to

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