有没有人有一个Emacs宏来缩进(和unindenting)文本块?

mik*_*ike 4 lisp emacs elisp

有没有人有一个Emacs宏来缩进(和unindenting)文本块?

我的意思是"缩进",在通常理解的意义上,而不是在Emacspeak中.换句话说,我想标记一个区域,按Cu 2,运行此宏,并在区域中的每一行之前添加两个空格.

或者在运行宏之前按Cu -2,并从区域中每行的开头删除两个空格.如果线条没有足够的前导空格,则会产生奖励.

Jul*_*res 12

indent-rigidly(绑定到Cx TAB)做你想要的.它位于indent.el中,它应该是标准emacs发行版的一部分.

另外,当某个地方没有足够的空格时让它抱怨/中止,你可以这样做:(快速丑陋的原始缩进代码)

(defun enough-whitespace-to-indent-p (start end arg)
  (save-excursion
    (goto-char end)
    (setq end (point-marker))
    (goto-char start)
    (or (bolp) (forward-line 1))
    (while (and (< (point) end)
                (>= (+ (current-indentation) arg) 0))
      (forward-line 1))
    (>= (point) end)))

(defun indent-rigidly-and-be-picky (start end arg)
  (interactive "r\np")
  (if (or (plusp arg) (enough-whitespace-to-indent-p start end arg))
      (indent-rigidly start end arg)
(message "Not enough whitespace to unindent!")))
Run Code Online (Sandbox Code Playgroud)