有没有办法在c-derived模式中调整对齐规则,在我的情况下是d-mode来缩进D-style UFCS-Chains,例如
foreach (file; dirPath.expandTilde()
.buildNormalizedPath()
.dirEntries(SpanMode.shallow)()
在这种情况下,我想对这一点进行调整,即。
有关详细信息,请参阅https://github.com/Emacs-D-Mode-Maintainers/Emacs-D-Mode/issues/26
答案 0 :(得分:2)
您必须修改arglist-cont-nonempty
中c-offsets-alist
密钥的值。此外,您可能希望修改statement-cont
密钥以在一般语句(例如分配)中启用相同的缩进:
(add-to-list 'c-offsets-alist '(arglist-cont-nonempty . c-lineup-cascaded-calls))
(add-to-list 'c-offsets-alist '(statement-cont . c-lineup-cascaded-calls))
显然,你可以使用类似的东西:
(add-hook 'd-mode-hook
'(lambda ()
(add-to-list 'c-offsets-alist '(arglist-cont-nonempty . c-lineup-cascaded-calls))
(add-to-list 'c-offsets-alist '(statement-cont . c-lineup-cascaded-calls))))
在每个d模式缓冲区中启用此对齐。
如果你想考虑可选的括号,我相信你必须编写自己的“排队”功能,因为我无法想到内置的解决方案。这是c-lineup-cascaded-calls的脏重写:
(defun d-lineup-cascaded-calls (langelem)
"This is a modified `c-lineup-cascaded-calls' function for the
D programming language which accounts for optional parenthesis
and compile-time parameters in function calls."
(if (and (eq (c-langelem-sym langelem) 'arglist-cont-nonempty)
(not (eq (c-langelem-2nd-pos c-syntactic-element)
(c-most-enclosing-brace (c-parse-state)))))
;; The innermost open paren is not our one, so don't do
;; anything. This can occur for arglist-cont-nonempty with
;; nested arglist starts on the same line.
nil
(save-excursion
(back-to-indentation)
(let ((operator (and (looking-at "\\.")
(regexp-quote (match-string 0))))
(stmt-start (c-langelem-pos langelem)) col)
(when (and operator
(looking-at operator)
(or (and
(zerop (c-backward-token-2 1 t stmt-start))
(eq (char-after) ?\()
(zerop (c-backward-token-2 2 t stmt-start))
(looking-at operator))
(and
(zerop (c-backward-token-2 1 t stmt-start))
(looking-at operator))
(and
(zerop (c-backward-token-2 1 t stmt-start))
(looking-at operator))
)
)
(setq col (current-column))
(while (or (and
(zerop (c-backward-token-2 1 t stmt-start))
(eq (char-after) ?\()
(zerop (c-backward-token-2 2 t stmt-start))
(looking-at operator))
(and
(zerop (c-backward-token-2 1 t stmt-start))
(looking-at operator))
(and
(zerop (c-backward-token-2 1 t stmt-start))
(looking-at operator))
)
(setq col (current-column)))
(vector col))))))
它似乎适用于可选括号和双括号调用(即call!(type)(arg)
)。但也许有一些极端情况,所以不要指望它太多,这只是一个想法。