使用 emacs 在本地禁用自动填充模式(或取消填充段落)

发布于 2024-09-18 00:46:47 字数 202 浏览 9 评论 0原文

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

在组织模式下,我有时会输入 [[非常长的 HTML][带空格的名称]],对于“带空格的名称”,自动填充模式会根据插入的空格打破整行,这使得它非常丑陋。

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

I use M-q for fill-paragraph, can I do the un-fill-paragraph in auto-fill-mode?

With org mode, I sometimes enter [[Very long HTML][Name with spaces]], and for the 'Name with spaces' the auto-fill mode break the whole line based on the inserted space, which makes it very ugly.

Is there a command something like un-fill-paragraph? Or, is there a way disable auto-fill-mode temporarily/locally?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

不再让梦枯萎 2024-09-25 00:46:47

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

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

  • 选择区域
  • CM-% Cq Cj RET 空格 RET

Emacs does not record what was your line before calling fill-paragraph. So the only thing you can do is C-_ which runs the command undo. It can undo your fill-paragraph command but only if it is the preceding command call.

If you want to put a multi-line paragraph on one line you could do like this :

  • Select the region
  • C-M-% C-q C-j RET SPACE RET !
梦中楼上月下 2024-09-25 00:46:47

自 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)))))

Xah Lee has updated his code since monotux's answer, and I refactored it somewhat for readability:

(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)))))
森林散布 2024-09-25 00:46:47

为了在组织模式下从段落中重新制作长行,我给了自己一个新命令。以下是相关的 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)

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

To remake a long line out of a paragraph in Org mode, I gave myself a new command. Here is the associated Emacs Lisp code:

(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)

Of course, you adjust the command keybinding as you see fit!

紙鸢 2024-09-25 00:46:47

我使用以下代码片段来填充和取消填充段落(仅使用 Mq),它真的非常方便。我从 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)

I use the following snippet to fill and un-fill paragraphs (using only M-q), it is really, really handy. I borrowed it from Xah Lee, but removed some comments and whitespace in order to make it fit in here. The link in the first comment goes to his original code.

;; 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)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文