Skip to content

Instantly share code, notes, and snippets.

@sg2002
Last active September 6, 2021 17:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sg2002/43bbd454da3254f4d092e2758057c372 to your computer and use it in GitHub Desktop.
Save sg2002/43bbd454da3254f4d092e2758057c372 to your computer and use it in GitHub Desktop.
Improved version of sh-smie--indent-continuation that on sh-indent-after-continuation = t indents past the beggining of the line variable path
(defun sh-smie--indent-continuation ()
(cond
((not (and sh-indent-after-continuation
(save-excursion
(ignore-errors
(skip-chars-backward " \t")
(sh-smie--looking-back-at-continuation-p)))))
nil)
((eq sh-indent-after-continuation 'always)
(save-excursion
(forward-line -1)
(if (sh-smie--looking-back-at-continuation-p)
(current-indentation)
(+ (current-indentation) sh-basic-offset))))
(t
;; Just make sure a line-continuation is indented deeper.
(save-excursion
(let ((indent (progn
(smie-backward-sexp)
(while (not (smie-rule-bolp))
(smie-backward-sexp))
(smie-forward-sexp)
(while (or (looking-at "\\$")
(eq 4 (syntax-class (syntax-after (point))))
(eq 5 (syntax-class (syntax-after (- (point) 1)))))
(smie-forward-sexp))
(skip-chars-forward " \t")
(current-column)))
(max most-positive-fixnum))
(if (not (numberp indent)) indent
(while (progn
(forward-line -1)
(let ((ci (current-indentation)))
(cond
;; Previous line is less indented, we're good.
((< ci indent) nil)
((sh-smie--looking-back-at-continuation-p)
(setq max (min max ci))
;; Previous line is itself a continuation.
;; If it's indented like us, we're good, otherwise
;; check the line before that one.
(> ci indent))
(t ;Previous line is the beginning of the continued line.
(setq indent (min (+ ci sh-basic-offset) max))
nil)))))
indent))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment