[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/julia-mode a95b06b 252/352: Merge pull request #20 from tp
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/julia-mode a95b06b 252/352: Merge pull request #20 from tpapp/indent-export |
Date: |
Sun, 29 Aug 2021 11:22:56 -0400 (EDT) |
branch: elpa/julia-mode
commit a95b06bacac7a78da3dbff45c0f36f7a03768112
Merge: 2d860b1 d3366f4
Author: Yichao Yu <yyc1992@gmail.com>
Commit: GitHub <noreply@github.com>
Merge pull request #20 from tpapp/indent-export
Add indent for import and export.
---
julia-mode-tests.el | 21 +++++++++++++++++++++
julia-mode.el | 35 +++++++++++++++++++++++++++++++++++
2 files changed, 56 insertions(+)
diff --git a/julia-mode-tests.el b/julia-mode-tests.el
index 647323b..faeaf66 100644
--- a/julia-mode-tests.el
+++ b/julia-mode-tests.el
@@ -292,6 +292,27 @@ a = 1"
"# if foo
a = 1"))
+(ert-deftest julia--test-indent-import-export-using ()
+ "Toplevel using, export, and import."
+ (julia--should-indent
+ "
+export bar, baz,
+quux"
+ "
+export bar, baz,
+ quux")
+ (julia--should-indent
+ "
+using Foo: bar ,
+baz,
+quux
+notpartofit"
+ "
+using Foo: bar ,
+ baz,
+ quux
+notpartofit"))
+
(defun julia--run-tests ()
(interactive)
(if (featurep 'ert)
diff --git a/julia-mode.el b/julia-mode.el
index abc7c4e..a8ab0c6 100644
--- a/julia-mode.el
+++ b/julia-mode.el
@@ -416,6 +416,34 @@ 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-using ()
+ "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."
+ ;; Implementation accepts a single Module: right after the keyword, and saves
+ ;; the module name for future use, but does not enforce that `export` has no
+ ;; module name.
+ (let ((done nil) ; find keyword or give up
+ (module nil)) ; found "Module:"
+ (save-excursion
+ (beginning-of-line)
+ (while (and (not done) (< 0 (point)))
+ (julia-safe-backward-sexp)
+ (cond
+ ((looking-at (rx (or "import" "export" "using")))
+ (setf done (point)))
+ ((looking-at (rx (group (* (or word (syntax symbol)))) (0+ space)
":"))
+ (if module
+ (setf done 'broken)
+ (setf module (match-string-no-properties 1))))
+ ((looking-at (rx (* (or word (syntax symbol))) (0+ space) ","))
+ (when module (setf done 'broken)))
+ (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 +564,11 @@ meaning always increase indent on TAB and decrease on
S-TAB."
;; indenting inside strings
(current-indentation)))))
+(defun julia-indent-import-export-using ()
+ "Indent offset for lines that follow `import` or `export`, otherwise nil."
+ (when (julia-following-import-export-using)
+ julia-indent-offset))
+
(defun julia-indent-line ()
"Indent current line of julia code."
(interactive)
@@ -550,6 +583,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-using)
;; Indent according to how many nested blocks we are in.
(save-excursion
(beginning-of-line)
- [nongnu] elpa/julia-mode 76d5d75 183/352: Optimising julia-at-keyword., (continued)
- [nongnu] elpa/julia-mode 76d5d75 183/352: Optimising julia-at-keyword., ELPA Syncer, 2021/08/29
- [nongnu] elpa/julia-mode 9cdad57 187/352: Make julia-char-regex stricter., ELPA Syncer, 2021/08/29
- [nongnu] elpa/julia-mode ff5fc36 202/352: julia-mode.el: allow space or no space after :: and <:, ELPA Syncer, 2021/08/29
- [nongnu] elpa/julia-mode 05f002c 203/352: When indenting code, limit how far back we search., ELPA Syncer, 2021/08/29
- [nongnu] elpa/julia-mode 70bbe82 204/352: Adding unit tests for indentation., ELPA Syncer, 2021/08/29
- [nongnu] elpa/julia-mode ff8adf5 221/352: Add tests for #11684. [ci skip], ELPA Syncer, 2021/08/29
- [nongnu] elpa/julia-mode 8ab2a60 222/352: julia-paren-indent skips blanks after paren, ELPA Syncer, 2021/08/29
- [nongnu] elpa/julia-mode c8dfbe2 227/352: Declare indentation as customizable, ELPA Syncer, 2021/08/29
- [nongnu] elpa/julia-mode 011435c 237/352: julia-mode: Fix indent for hanging ops and module, ELPA Syncer, 2021/08/29
- [nongnu] elpa/julia-mode c2f0ed8 235/352: julia-mode: Fix prompt regexp, ELPA Syncer, 2021/08/29
- [nongnu] elpa/julia-mode a95b06b 252/352: Merge pull request #20 from tpapp/indent-export,
ELPA Syncer <=
- [nongnu] elpa/julia-mode 847908e 249/352: Add indent for import and export., ELPA Syncer, 2021/08/29
- [nongnu] elpa/julia-mode 7b1d3fb 253/352: Merge pull request #21 from kshramt/python-paren-indent, ELPA Syncer, 2021/08/29
- [nongnu] elpa/julia-mode f591c6d 275/352: Merge pull request #41 from rfourquet/rf/where-return, ELPA Syncer, 2021/08/29
- [nongnu] elpa/julia-mode 8449c95 295/352: Merge pull request #69 from emmt/master, ELPA Syncer, 2021/08/29
- [nongnu] elpa/julia-mode 47d2fb0 282/352: Merge pull request #51 from non-Jedi/arg-list, ELPA Syncer, 2021/08/29
- [nongnu] elpa/julia-mode e27e6d2 290/352: fix compilation error, silence byte-compiler warnings in emacs>23, ELPA Syncer, 2021/08/29
- [nongnu] elpa/julia-mode 7102542 304/352: fix tests, ELPA Syncer, 2021/08/29
- [nongnu] elpa/julia-mode 646f758 156/352: Don't skip over end keywords., ELPA Syncer, 2021/08/29
- [nongnu] elpa/julia-mode 11e3904 176/352: Backporting regexp-opt functionality to Emacs 23., ELPA Syncer, 2021/08/29
- [nongnu] elpa/julia-mode 36aa038 181/352: Fix julia-in-brackets so it isn't confused by strings, characters or comments., ELPA Syncer, 2021/08/29