Emacs:上下文边距设置或填充文本以缩小列的范围



我想在缓冲区中快速生成文本,如下所示:

(fact                    "This is some text which will hang out
                          only on this part of the screen, ideally
                          automatically flowing to the correct
                          margins as I type."
  (+ 1 1) => 2
  ;; more Clojure tests...
  )

我有一个Elisp键绑定,它可以快速弹出一个开始模板,并将光标放在正确的位置:

(global-set-key "C-of" (lambda ()
                           (interactive)
                           (insert "(fact                               ""nn  )")
                           (backward-char 6)))

现在,当我输入字符串部分("This is some text...")时,如果我能让Emacs自动将文本流到"正确"的页边空白,那就太棒了。有没有什么方法可以让Emacs根据您键入的位置来调整边距和环绕行为?至少,你第一次在那里打字?

除此之外,对于给定的文本选择,我如何才能使用所需的左右边距进行等效的fill-region?当前fill-region删除fact"This is....之间的所有空格,并左对齐其余空格。

我现在可能忽略了一种更简单的方法,但我只想这样做:

  1. 在临时缓冲区中配置文本块,方法是:

    a。将fill-column设置为所需文本块的宽度。

    b。将文本放在行首,即不要缩进。

    c。填充文本。

    d。使用indent-rigidly将文本缩进到所需列(第一行除外)。

  2. (fact插入目标缓冲区,然后插入文本块第一行所需的缩进。然后插入临时缓冲区的内容。然后插入您需要的任何其他文本/代码。

IOW,我会把填充文本块和缩进它分开。

以下内容似乎暂时适用于我的另一种(较弱的)情况:

;; Set up Midje fact with mark inserted at beginning of comment text
;; (refill as needed in appropriate columns, using C-oF).
(global-set-key "C-of" (lambda ()
              (interactive)
              (insert "(fact                               ""nn  )")
              (backward-char 6)
              (set-mark (point))))
;; Perform the refill operation to properly reformat the text string
;; in a Midje fact, started with C-of:
(global-set-key "C-oF" (lambda ()
              (interactive)
              (set-left-margin (mark) (point) 37)
              (fill-region (mark) (point))))

我想当我获得使用经验时,我会不得不调整它,但它非常接近。不过,当我在字符串中键入时,如果能弄清楚如何自动实现这一点,那就太好了。

最新更新