【问题标题】:Emacs: contextual margin settings or filling text to narrow range of columns?Emacs:上下文边距设置或填充文本以缩小列范围?
【发布时间】:2014-09-28 13:15:38
【问题描述】:

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

(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                               \"\"\n\n  )")
                           (backward-char 6)))

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

除此之外,对于给定的文本选择,我怎样才能做到相当于fill-region,但具有所需的左右边距?目前fill-region 删除了fact"This is.... 之间的所有空格,并将其余空格左对齐。

【问题讨论】:

    标签: emacs clojure elisp


    【解决方案1】:

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

    1. 在临时缓冲区中配置文本块,在此处执行以下操作:

      一个。将fill-column 设置为您想要的文本块的宽度。

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

      c。填写文本。

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

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

    IOW,我会将填充文本块与缩进分开。

    【讨论】:

      【解决方案2】:

      以下似乎暂时适用于我的替代(较弱)案例:

      ;; 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                               \"\"\n\n  )")
                    (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))))
      

      我希望在获得使用它的经验后我必须对此进行调整,但它非常接近。不过,当我在字符串中输入时,弄清楚如何自动发生这种情况会很好。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-08-23
        • 2011-07-18
        • 1970-01-01
        • 2014-07-23
        • 2015-10-16
        • 2016-07-25
        • 1970-01-01
        • 2012-05-16
        相关资源
        最近更新 更多