I'm trying to implement qmake-mode using SMIE(https://www.gnu.org/software/emacs/manual/html_node/elisp/SMIE.html), but I have no idea how to control indent width in line-continuation. Block indentation works(yes, I stole block indentation from sh-script.sh(sh-mode))
For example, I expect this
SOURCES += a.cpp \
b.cpp
rather than
SOURCES += a.cpp \
b.cpp
Here is brief code:
(defconst qmake-smie-grammar
(smie-prec2->grammar
(smie-bnf->prec2
'((var)
(value)
(exp (var "+=" value)
(var "=" value)
(var "-=" value))
(inst (exp "||" exp)
(exp "&&" exp))
(insts (inst ";" insts)))
'((assoc "+=" "=" "-="))
'((assoc "||" "&&"))
'((assoc ";"))
)))
(defun qmake-smie-backward-token ()
(let ((bol (line-beginning-position))
pos tok)
(forward-comment (- (point)))
(cond
((< (point) bol)
(cond
((qmake-smie--looking-back-at-continuation-p)
(forward-char -1)
(funcall smie-backward-token-function))
((qmake-smie--newline-semi-p) ";")
(t (funcall smie-backward-token-function))))
(t tok))))
(defun qmake-smie-rules (kind token)
(pcase (cons kind token)
(`(:elem . basic) qmake-indentation)
((and `(:before . ,_)
(guard (when qmake-indent-after-continuation
(save-excursion
(ignore-errors
(skip-chars-backward " \t")
(qmake-smie--looking-back-at-continuation-p))))))
;; After a line-continuation, make sure the rest is indented.
(let* ((qmake-indent-after-continuation nil)
(indent (smie-indent-calculate))
(initial (qmake-smie--continuation-start-indent)))
(when (and (numberp indent) (numberp initial)
(<= indent initial))
`(column . ,(+ initial qmake-indentation)))))
(`(:before . ,(or `"(" `"{" `"["))
(if (smie-rule-hanging-p) (smie-rule-parent)))))
Here is full code: https://gist.github.com/inlinechan/2ff5194d06cfcfb34016