代码之家  ›  专栏  ›  技术社区  ›  prosseek

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

  •  4
  • prosseek  · 技术社区  · 14 年前

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

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

    是否有类似取消填充段落的命令?或者,是否有方法临时/本地禁用自动填充模式?

    4 回复  |  直到 11 年前
        1
  •  6
  •   Jérôme Radix    14 年前

    Emacs不会在呼叫之前记录您的线路 fill-paragraph . 所以你唯一能做的就是 C-- 它运行命令undo。它可以撤销您的 填充段落 命令,但仅当它是前面的命令调用时。

    如果要在一行上放置多行段落,可以这样做:

    • 选择区域
    • C-M%% C-Q C-J 雷特 空间 雷特 !
        2
  •  3
  •   phils    11 年前

    XahLee在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
  •  2
  •   slfan Sandy Shrestha    11 年前

    为了在组织模式下从一个段落中重排一行,我给了自己一个新的命令。以下是关联的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
  •  1
  •   monotux    14 年前

    我使用以下代码段填充和取消填充段落(仅使用 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)