两个换行后不要缩进

时间:2013-07-03 19:22:29

标签: emacs elisp

我已经将RET绑定到换行符和缩进符。每当我跳过一行时,它会留下一条没有缩进的行并缩进当前行,这就是应该如何。在某些情况下,我希望在跳过后不缩进当前行。一些例子:

Default behavior
    This is a test.

    Line two.

How I'd like it:
    This is a test.

Line two.

我不太确定实施此方法的最佳方法。只有不雅的一种解决方案是尝试连续检测两次按压然后超出当前行。有什么想法吗?

1 个答案:

答案 0 :(得分:2)

此解决方案假设您需要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)))