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

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

[nongnu] elpa/julia-mode 847908e 249/352: Add indent for import and expo


From: ELPA Syncer
Subject: [nongnu] elpa/julia-mode 847908e 249/352: Add indent for import and export.
Date: Sun, 29 Aug 2021 11:22:55 -0400 (EDT)

branch: elpa/julia-mode
commit 847908eb69cfb54ce3cfccd10592808e64bc4ede
Author: Tamas K. Papp <tkpapp@gmail.com>
Commit: Tamas K. Papp <tkpapp@gmail.com>

    Add indent for import and export.
---
 julia-mode.el | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/julia-mode.el b/julia-mode.el
index abc7c4e..88ca566 100644
--- a/julia-mode.el
+++ b/julia-mode.el
@@ -416,6 +416,30 @@ a keyword if used as a field name, X.word, or quoted, 
:word."
   (if (condition-case nil (backward-sexp) (error t))
       (ignore-errors (backward-char))))
 
+(defun julia-following-import-export ()
+  "If the current line follows an `export` or `import` keyword
+with valid syntax, return the position of the keyword, otherwise
+`nil`. Works by stepping backwards through comma-separated
+symbol, gives up when this is not true."
+  (let ((done nil))
+    (save-excursion
+      (beginning-of-line)
+      (while (and (not done) (< 0 (point)))
+        (julia-safe-backward-sexp)
+        (cond
+         ((looking-at (rx "export"))
+          (setf done (point)))
+         ((looking-at (rx "import"
+                          (+ space)
+                          (opt (* (or word (syntax symbol)))
+                               (0+ space) ":" (0+ space))))
+          (setf done (point)))
+         ((looking-at (rx (* (or word (syntax symbol))) (0+ space) ",")))
+         (t (setf done 'broken)))))
+    (if (eq done 'broken)
+        nil
+      done)))
+
 (defun julia-last-open-block-pos (min)
   "Return the position of the last open block, if one found.
 Do not move back beyond position MIN."
@@ -536,6 +560,11 @@ meaning always increase indent on TAB and decrease on 
S-TAB."
         ;; indenting inside strings
         (current-indentation)))))
 
+(defun julia-indent-import-export ()
+  "Indent offset for lines that follow `import` or `export`, otherwise nil."
+  (when (julia-following-import-export)
+    julia-indent-offset))
+
 (defun julia-indent-line ()
   "Indent current line of julia code."
   (interactive)
@@ -550,6 +579,8 @@ meaning always increase indent on TAB and decrease on 
S-TAB."
       (julia-paren-indent)
       ;; indent due to hanging operators (lines ending in an operator)
       (julia-indent-hanging)
+      ;; indent for import and export
+      (julia-indent-import-export)
       ;; Indent according to how many nested blocks we are in.
       (save-excursion
         (beginning-of-line)



reply via email to

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