branch: elpa/julia-mode
commit 1746c4bbbd4e269b95b554c5ac2cf8db87d1f7da
Author: justbur <jus...@burkett.cc>
Commit: Yichao Yu <yyc1...@gmail.com>

    julia-mode: Improve paren indent perf
    
    Replace julia-paren-indent with a version that uses the higher level
    function backward-up-list to find any previous opening parentheses. This
    function automatically skips balanced expressions like strings, as well
    as comments.
    
    On some test files the time to indent falls by more than 75% with this
    change, even after increasing the threshold for paren lookback to 10k.
    Note the threshold is removed in this version.
---
 julia-mode.el | 45 +++++++++++----------------------------------
 1 file changed, 11 insertions(+), 34 deletions(-)

diff --git a/julia-mode.el b/julia-mode.el
index fb17d4a..2f53f29 100644
--- a/julia-mode.el
+++ b/julia-mode.el
@@ -452,13 +452,6 @@ beginning of the buffer."
   (unless (eq (point) (point-min))
     (backward-char)))
 
-(defvar julia-max-paren-lookback 400
-  "When indenting, don't look back more than this
-many characters to see if there are unclosed parens.
-
-This variable has a major effect on indent performance if set too
-high.")
-
 (defvar julia-max-block-lookback 5000
   "When indenting, don't look back more than this
 many characters to see if there are unclosed blocks.
@@ -471,29 +464,16 @@ high.")
 containing paren before point, so we can align succeeding code
 with it. Returns nil if we're not within nested parens."
   (save-excursion
-    ;; Back up to previous line (beginning-of-line was already called)
-    (backward-char)
-    (let ((min-pos (max (- (point) julia-max-paren-lookback)
-                        (point-min)))
-          (open-count 0))
-      (while (and (> (point) min-pos)
-                  (not (plusp open-count)))
-
-        (when (looking-at (rx (any "[" "]" "(" ")")))
-          (unless (or (julia-in-string) (julia-in-comment))
-            (cond ((looking-at (rx (any "[" "(")))
-                   (incf open-count))
-                  ((looking-at (rx (any "]" ")")))
-                   (decf open-count)))))
-
-        (julia--safe-backward-char))
-
-      (if (plusp open-count)
-          (progn (forward-char 2)
-                 (while (looking-at (rx blank))
-                   (forward-char))
-                 (current-column))
-        nil))))
+    (beginning-of-line)
+    (let ((parser-state (syntax-ppss)))
+      (cond ((nth 3 parser-state) nil)       ;; strings
+            ((= (nth 0 parser-state) 0) nil) ;; top level
+            (t
+             (ignore-errors ;; return nil if any of these movements fail
+               (backward-up-list)
+               (forward-char)
+               (skip-syntax-forward " ")
+               (current-column)))))))
 
 (defun julia-prev-line-skip-blank-or-comment ()
   "Move point to beginning of previous line skipping blank lines
@@ -549,13 +529,10 @@ only comments."
   "Indent current line of julia code."
   (interactive)
   (let* ((point-offset (- (current-column) (current-indentation))))
-    (end-of-line)
     (indent-line-to
      (or
       ;; If we're inside an open paren, indent to line up arguments.
-      (save-excursion
-        (beginning-of-line)
-        (ignore-errors (julia-paren-indent)))
+      (julia-paren-indent)
       ;; indent due to hanging operators or a line ending in =
       (julia-indent-hanging)
       ;; Indent according to how many nested blocks we are in.

Reply via email to