branch: elpa/julia-mode commit a82e6299bac675e6d006409febf7e2f138897bce Author: justbur <jus...@burkett.cc> Commit: Yichao Yu <yyc1...@gmail.com>
julia-mode: Indent manually inside strings with \n Don't try to automatically indent when inside strings with newline characters. We don't want to add indentation where it is not intended, so any automatic formatting should not assume that we want to indent inside a string. This also fixes #12419, because we won't get confused by keywords in multi-line strings. Because it is still useful, make TAB and <backtab> increase and decrease indentation when called inside a string. --- julia-mode-tests.el | 18 ++++++++++++++++++ julia-mode.el | 24 ++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/julia-mode-tests.el b/julia-mode-tests.el index de68089..239d078 100644 --- a/julia-mode-tests.el +++ b/julia-mode-tests.el @@ -252,6 +252,24 @@ y2 = g(x)" z) y2 = g(x)")) +(ert-deftest julia--test-indentation-of-multi-line-strings () + "Indentation should only affect the first line of a multi-line string." + (julia--should-indent + " a = \"\"\" + description +begin + foo +bar +end +\"\"\"" + "a = \"\"\" + description +begin + foo +bar +end +\"\"\"")) + (defun julia--run-tests () (interactive) (if (featurep 'ert) diff --git a/julia-mode.el b/julia-mode.el index 2f53f29..9bad399 100644 --- a/julia-mode.el +++ b/julia-mode.el @@ -525,12 +525,28 @@ only comments." ;; above (+ julia-indent-offset prev-indent))))))) +(defun julia-indent-in-string () + "Indentation inside strings with newlines is \"manual\", +meaning always increase indent on TAB and decrease on S-TAB." + (save-excursion + (beginning-of-line) + (when (julia-in-string) + (if (member this-command '(julia-latexsub-or-indent + ess-indent-or-complete)) + (+ julia-indent-offset (current-indentation)) + ;; return the current indentation to prevent other functions from + ;; indenting inside strings + (current-indentation))))) + (defun julia-indent-line () "Indent current line of julia code." (interactive) (let* ((point-offset (- (current-column) (current-indentation)))) (indent-line-to (or + ;; 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. (julia-paren-indent) ;; indent due to hanging operators or a line ending in = @@ -602,6 +618,14 @@ only comments." (setq imenu-generic-expression julia-imenu-generic-expression) (imenu-add-to-menubar "Imenu")) +(defun julia-manual-deindent () + "Deindent by `julia-indent-offset' regardless of current +indentation context. To be used to manually indent inside +strings." + (interactive) + (indent-line-to (max 0 (- (current-indentation) julia-indent-offset)))) +(define-key julia-mode-map (kbd "<backtab>") 'julia-manual-deindent) + (defvar julia-latexsubs (make-hash-table :test 'equal)) (defun julia-latexsub ()