5

我使用 Mq 填充段落,我可以在自动填充模式下执行取消填充段落吗?

在 org 模式下,我有时会输入[[Very long HTML][Name with spaces]],对于“带空格的名称”,自动填充模式会根据插入的空格打破整行,这使得它非常难看。

是否有类似 un-fill-paragraph 的命令?或者,有没有办法暂时/本地禁用自动填充模式?

4

4 回答 4

6

Emacs 不会记录您在调用之前的线路fill-paragraph。所以你唯一能做的就是C-_运行命令撤消。它可以撤消您的fill-paragraph命令,但前提是它是前面的命令调用。

如果您想将多行段落放在一行上,您可以这样做:

  • 选择地区
  • C-M-% C-q C-j RET SPACE RET !
于 2010-09-09T16:03:31.793 回答
4

自从 monotux 的回答以来,Xah Lee 已经更新了他的代码,为了便于阅读,我对其进行了一些重构:

(defun my-toggle-fill-paragraph ()
  ;; Based on http://xahlee.org/emacs/modernization_fill-paragraph.html
  "Fill or unfill the current paragraph, depending upon the current line length.
When there is a text selection, act on the region.
See `fill-paragraph' and `fill-region'."
  (interactive)
  ;; We set a property 'currently-filled-p on this command's symbol
  ;; (i.e. on 'my-toggle-fill-paragraph), thus avoiding the need to
  ;; create a variable for remembering the current fill state.
  (save-excursion
    (let* ((deactivate-mark nil)
           (line-length (- (line-end-position) (line-beginning-position)))
           (currently-filled (if (eq last-command this-command)
                                 (get this-command 'currently-filled-p)
                               (< line-length fill-column)))
           (fill-column (if currently-filled
                            most-positive-fixnum
                          fill-column)))

      (if (region-active-p)
          (fill-region (region-beginning) (region-end))
        (fill-paragraph))

      (put this-command 'currently-filled-p (not currently-filled)))))
于 2013-02-21T00:22:42.910 回答
2

为了在 Org 模式下重新制作一段长行,我给了自己一个新命令。这是相关的 Emacs Lisp 代码:

(defun fp-unfill-paragraph (&optional justify region)
  (interactive (progn
         (barf-if-buffer-read-only)
         (list (if current-prefix-arg 'full) t)))
  (interactive)
  (let ((fill-column 100000))
    (fill-paragraph justify region)))

(global-set-key "\C-ceu" 'fp-unfill-paragraph)

当然,您可以根据需要调整命令键绑定!

于 2013-02-21T12:39:33.693 回答
1

我使用以下代码段来填充和取消填充段落(仅使用M-q),它非常非常方便。我从 Xah Lee 那里借来了它,但删除了一些注释和空格以使其适合这里。第一条评论中的链接指向他的原始代码。

;; http://xahlee.org/emacs/modernization_fill-paragraph.html
(defun compact-uncompact-block ()
  "Remove or add line endings on the current block of text.
This is similar to a toggle for fill-paragraph and unfill-paragraph
When there is a text selection, act on the region.

When in text mode, a paragraph is considered a block. When in programing
language mode, the block defined by between empty lines.

Todo: The programing language behavior is currently not done.
Right now, the code uses fill* functions, so does not work or work well
in programing lang modes. A proper implementation to compact is replacing
newline chars by space when the newline char is not inside string.
"
  (interactive)
  (let (bds currentLineCharCount currentStateIsCompact
            (bigFillColumnVal 4333999) (deactivate-mark nil))
    (save-excursion
      (setq currentLineCharCount
            (progn
              (setq bds (bounds-of-thing-at-point 'line))
              (length (buffer-substring-no-properties (car bds) (cdr bds)))))
      (setq currentStateIsCompact
            (if (eq last-command this-command)
                (get this-command 'stateIsCompact-p)
              (if (> currentLineCharCount fill-column) t nil)))
      (if (and transient-mark-mode mark-active)
          (if currentStateIsCompact
              (fill-region (region-beginning) (region-end))
            (let ((fill-column bigFillColumnVal))
              (fill-region (region-beginning) (region-end)))
            )
        (if currentStateIsCompact
            (fill-paragraph nil)
          (let ((fill-column bigFillColumnVal))
            (fill-paragraph nil))))
      (put this-command 'stateIsCompact-p
           (if currentStateIsCompact
               nil t)))))
(global-set-key (kbd "M-q") 'compact-uncompact-block)
于 2010-09-10T06:55:01.810 回答