【问题标题】:Disable auto-fill-mode locally (or un fill-paragraph) with emacs使用 emacs 在本地禁用自动填充模式(或取消填充段落)
【发布时间】:2011-04-10 06:27:53
【问题描述】:

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

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

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

【问题讨论】:

    标签: emacs org-mode autofill


    【解决方案1】:

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

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

    • 选择地区
    • CM-% Cq Cj RET SPACE RET !

    【讨论】:

      【解决方案2】:

      Xah Lee 已经更新了他的代码,因为 monotux 的回答,我对它进行了一些重构以提高可读性:

      (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)))))
      
      【解决方案3】:

      为了在 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)
      

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

      【讨论】:

        【解决方案4】:

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

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

        【讨论】:

          猜你喜欢
          • 2014-11-13
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2022-01-08
          相关资源
          最近更新 更多