[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/julia-mode fe6f6f7 348/352: Allow block indentation inside
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/julia-mode fe6f6f7 348/352: Allow block indentation inside of parentheticals (#152) |
Date: |
Sun, 29 Aug 2021 11:23:16 -0400 (EDT) |
branch: elpa/julia-mode
commit fe6f6f7a80f8d60ecffa5b2cb43667bb9dc11705
Author: Colin Gilgenbach <colin@gilgenbach.net>
Commit: GitHub <noreply@github.com>
Allow block indentation inside of parentheticals (#152)
* Allow block indentation inside of parentheticals
* Style changes
---
julia-mode-tests.el | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++
julia-mode.el | 48 ++++++++++++++++++-----------
2 files changed, 117 insertions(+), 18 deletions(-)
diff --git a/julia-mode-tests.el b/julia-mode-tests.el
index 72713f1..9befc9d 100644
--- a/julia-mode-tests.el
+++ b/julia-mode-tests.el
@@ -494,6 +494,93 @@ if c in ('\'')
end
"))
+(ert-deftest julia--test-indent-block-inside-paren ()
+ "We should indent a block inside of a parenthetical."
+ (julia--should-indent "
+variable = func(
+arg1,
+arg2,
+if cond
+statement()
+arg3
+else
+arg3
+end,
+arg4
+)" "
+variable = func(
+ arg1,
+ arg2,
+ if cond
+ statement()
+ arg3
+ else
+ arg3
+ end,
+ arg4
+)"))
+
+(ert-deftest julia--test-indent-block-inside-hanging-paren ()
+ "We should indent a block inside of a hanging parenthetical."
+ (julia--should-indent "
+variable = func(arg1,
+arg2,
+if cond
+statement()
+arg3
+else
+arg3
+end,
+arg4
+)" "
+variable = func(arg1,
+ arg2,
+ if cond
+ statement()
+ arg3
+ else
+ arg3
+ end,
+ arg4
+ )"))
+
+(ert-deftest julia--test-indent-nested-block-inside-paren ()
+ "We should indent a nested block inside of a parenthetical."
+ (julia--should-indent "
+variable = func(
+arg1,
+if cond1
+statement()
+if cond2
+statement()
+end
+arg3
+end,
+arg4
+)" "
+variable = func(
+ arg1,
+ if cond1
+ statement()
+ if cond2
+ statement()
+ end
+ arg3
+ end,
+ arg4
+)"))
+
+(ert-deftest julia--test-indent-block-next-to-paren ()
+ (julia--should-indent "
+var = func(begin
+test
+end
+)" "
+var = func(begin
+ test
+ end
+ )"))
+
;;; font-lock tests
(ert-deftest julia--test-symbol-font-locking-at-bol ()
diff --git a/julia-mode.el b/julia-mode.el
index 377c9ce..a8f8e78 100644
--- a/julia-mode.el
+++ b/julia-mode.el
@@ -459,7 +459,19 @@ Do not move back beyond MIN."
(and pos
(progn
(goto-char pos)
- (+ julia-indent-offset (current-indentation))))))
+ (+ julia-indent-offset (julia-block-open-indentation))))))
+
+(defun julia-block-open-indentation ()
+ "Get the current indentation or the start of a parenthetical block."
+ (save-excursion
+ (save-restriction
+ ;; narrow to one line to only search syntax on that line
+ (narrow-to-region (line-beginning-position) (line-end-position))
+ (condition-case nil
+ (progn
+ (backward-up-list)
+ (1+ (current-column)))
+ (error (current-indentation))))))
(defcustom julia-max-block-lookback 20000
"When indenting, don't look back more than this many characters
@@ -585,27 +597,27 @@ meaning always increase indent on TAB and decrease on
S-TAB."
;; note: if this first function returns nil the beginning of the line
;; cannot be in a string
(julia-indent-in-string)
- ;; If we're inside an open paren, indent to line up arguments. After
this,
- ;; we cannot be inside parens which includes brackets
- (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)
- ;; jump out of any comments
- (let ((state (syntax-ppss)))
- (when (nth 4 state)
- (goto-char (nth 8 state))))
- (forward-to-indentation 0)
- (let ((endtok (julia-at-keyword julia-block-end-keywords))
- (last-open-block (julia-last-open-block (- (point)
julia-max-block-lookback))))
- (max 0 (+ (or last-open-block 0)
- (if (or endtok
- (julia-at-keyword
julia-block-start-keywords-no-indent))
- (- julia-indent-offset) 0)))))))
+ ;; use julia-paren-indent along with block indentation
+ (let ((paren-indent (or (julia-paren-indent) 0)))
+ ;; Indent according to how many nested blocks we are in.
+ (save-excursion
+ (beginning-of-line)
+ ;; jump out of any comments
+ (let ((state (syntax-ppss)))
+ (when (nth 4 state)
+ (goto-char (nth 8 state))))
+ (forward-to-indentation 0)
+ (let ((endtok (julia-at-keyword julia-block-end-keywords))
+ (last-open-block (julia-last-open-block (- (point)
julia-max-block-lookback))))
+ (max paren-indent (- (or last-open-block paren-indent)
+ ;; subtract indentation if we're at the end
of a block
+ (if (or endtok
+ (julia-at-keyword
julia-block-start-keywords-no-indent))
+ julia-indent-offset 0))))))))
;; Point is now at the beginning of indentation, restore it
;; to its original position (relative to indentation).
(when (>= point-offset 0)
- [nongnu] elpa/julia-mode b66f8a4 274/352: Insertion of math symbols in julia using auctex's mechanism, (continued)
- [nongnu] elpa/julia-mode b66f8a4 274/352: Insertion of math symbols in julia using auctex's mechanism, ELPA Syncer, 2021/08/29
- [nongnu] elpa/julia-mode 864e124 311/352: remove newline, ELPA Syncer, 2021/08/29
- [nongnu] elpa/julia-mode 686bed3 309/352: remove unused lexical args that gave a warning, ELPA Syncer, 2021/08/29
- [nongnu] elpa/julia-mode 4515765 320/352: add a changelog (#96), ELPA Syncer, 2021/08/29
- [nongnu] elpa/julia-mode bfa54b2 331/352: Minor point about preferring the rx macro for regexs., ELPA Syncer, 2021/08/29
- [nongnu] elpa/julia-mode 88d7d87 332/352: Merge pull request #121 from JuliaEditorSupport/tp/prefer-rx, ELPA Syncer, 2021/08/29
- [nongnu] elpa/julia-mode d91f1d0 324/352: Remove regexp-opt workarounds for Emacs < 24 (#101), ELPA Syncer, 2021/08/29
- [nongnu] elpa/julia-mode d69b095 342/352: Removed require statement for auctex that broke prettify. Fixes #99 (#116), ELPA Syncer, 2021/08/29
- [nongnu] elpa/julia-mode 8ea90c7 347/352: Rec/quoted quote (#143), ELPA Syncer, 2021/08/29
- [nongnu] elpa/julia-mode 5cccdbd 350/352: Fixed installation documentation (#147), ELPA Syncer, 2021/08/29
- [nongnu] elpa/julia-mode fe6f6f7 348/352: Allow block indentation inside of parentheticals (#152),
ELPA Syncer <=
- [nongnu] elpa/julia-mode b5f5983 346/352: Indent lines after hanging operator even if previous line contains # (#115), ELPA Syncer, 2021/08/29
- [nongnu] elpa/julia-mode 69bc337 270/352: add support for `where` keyword, ELPA Syncer, 2021/08/29