我已经将 RET 绑定到换行和缩进。每当我跳过一行时,它会留下一个没有缩进的行并缩进当前行,这就是它应该的样子。在某些情况下,我希望它在跳过后不缩进当前行。一些例子:
Default behavior
This is a test.
Line two.
How I'd like it:
This is a test.
Line two.
我不太确定实现这一点的最佳方法。一种不优雅的解决方案是尝试检测连续两次按下,然后突出当前行。有任何想法吗?
此解决方案假定您想要更改text-mode
,如果它是不同的模式,请适当调整代码。
(add-hook 'text-mode-hook
(lambda () (setq indent-line-function 'indent-relative-only-when-previous-has-non-whitespace)))
(defun indent-relative-only-when-previous-has-non-whitespace ()
"Only call indent-relative when previous line has non whitespace"
(interactive)
(when (save-excursion
(beginning-of-line 0)
(looking-at "^\\s *\\S "))
(indent-relative)))