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

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

[nongnu] elpa/julia-mode 3ae6315 046/352: improving indenting of block s


From: ELPA Syncer
Subject: [nongnu] elpa/julia-mode 3ae6315 046/352: improving indenting of block syntax inside parens
Date: Sun, 29 Aug 2021 11:22:13 -0400 (EDT)

branch: elpa/julia-mode
commit 3ae6315aa1e76674fe95136acefe86aa404be78b
Author: Jeff Bezanson <bezanson@post.harvard.edu>
Commit: Yichao Yu <yyc1992@gmail.com>

    improving indenting of block syntax inside parens
    some cleanup
    improving some error messages
    less use of jl_show_to_string
---
 julia-mode.el | 44 ++++++++++++++++++++++++++++++--------------
 1 file changed, 30 insertions(+), 14 deletions(-)

diff --git a/julia-mode.el b/julia-mode.el
index daa1fde..f217f32 100644
--- a/julia-mode.el
+++ b/julia-mode.el
@@ -84,8 +84,8 @@
        (not (in-comment))
        (member (current-word) kw-list)))
 
-; get the column of the last open block
-(defun last-open-block (min)
+; get the position of the last open block
+(defun last-open-block-pos (min)
   (do ((count 0
              (cond ((at-keyword julia-block-start-keywords)
                     (+ count 1))
@@ -95,10 +95,18 @@
                    (t count))))
       ((or (> count 0) (<= (point) min))
        (if (> count 0)
-          (+ 4 (current-indentation))
+          (point)
         nil))
     (backward-word 1)))
 
+; get indent for last open block
+(defun last-open-block (min)
+  (let ((pos (last-open-block-pos min)))
+    (and pos
+        (progn
+          (goto-char pos)
+          (+ 4 (current-indentation))))))
+
 ; return indent implied by a special form opening on the previous line, if any
 (defun form-indent ()
   (forward-line -1)
@@ -121,8 +129,14 @@
 (defmacro error2nil (body) `(condition-case nil ,body (error nil)))
 
 (defun paren-indent ()
-  (let* ((p (parse-partial-sexp (point-min) (progn (beginning-of-line)
-                                                   (point))))
+  (let* ((p (parse-partial-sexp (save-excursion
+                                 ;; only indent by paren if the last open
+                                 ;; paren is closer than the last open
+                                 ;; block
+                                 (or (last-open-block-pos (point-min))
+                                     (point-min)))
+                               (progn (beginning-of-line)
+                                      (point))))
          (pos (cadr p)))
     (if (or (= 0 (car p)) (null pos))
         nil
@@ -151,19 +165,21 @@
                            (at-keyword julia-block-end-keywords))))
              (error2nil (+ (last-open-block (point-min))
                            (if endtok -4 0)))))
+        ;; previous line ends in =
+        (save-excursion
+          (if (and (not (equal (point-min) (line-beginning-position)))
+                   (progn
+                     (forward-line -1)
+                     (end-of-line) (backward-char 1)
+                     (equal (char-after (point)) ?=)))
+              (+ 4 (current-indentation))
+            nil))
         ;; take same indentation as previous line
         (save-excursion (forward-line -1)
                         (current-indentation))
-                ;(save-excursion
-                ;  (if (and (not (equal (point-min) (line-beginning-position)))
-               ;                       (progn
-               ;                         (forward-line -1)
-               ;                         (end-of-line) (backward-char 1)
-               ;                         (equal (char-after (point)) ?=)))
-               ;          4 nil))
          0))
-       (when (at-keyword julia-block-end-keywords)
-         (forward-word 1)))
+    (when (at-keyword julia-block-end-keywords)
+      (forward-word 1)))
 
 (defun julia-mode ()
   "Major mode for editing julia code"



reply via email to

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