Emacsist RSS --- If never, make it ever: C-h C-h

Fill and unfill paragraphs with a single key


这里 查看更多 Emacs 相关推荐文章最新 Emacs 圈的动态. 欢迎关注微信公众账号: Emacsist

[fill-paragraph](http://doc.endlessparentheses.com/Fun/fill-paragraph) is probably among the most underappreciated Emacs commands. I use it dozens of times a day, and never stop to think of just how awesome and practical it is. Still, we can make it a little bit better. Every once in a while I need to “unfill” (or “unwrap”) a paragraph that’s broken over many lines.

By being clever enough, we can make this into a free feature. There’s never any reason to hit M-q twice on the same paragraph, so we can use that as our keybind for the “unfill” command.

(defun endless/fill-or-unfill ()
  "Like `fill-paragraph', but unfill if used twice."
  (let ((fill-column
         (if (eq last-command 'endless/fill-or-unfill)
             (progn (setq this-command nil)
    (call-interactively #'fill-paragraph)))

(global-set-key [remap fill-paragraph]

With this, M-q will act as a toggle. Hitting it once will do its usual thing (even if the paragraph is already filled), but hitting it twice will completely unwrap the current paragraph into a single line.

原文出处: EndlessParenthese
原文地址: http://endlessparentheses.com/fill-and-unfill-paragraphs-with-a-single-key.html?source=rss
原文时间: 2016-05-31 08:00
本文地址: http://emacsist.com/10876
整理时间: 2016-06-05 21:44

本文由 Hick 整理,转载请保留以上信息;
COPYLEFTThe articles on this site come from Internet, thanks to all the original authors.
      If anything about COPYRIGHT, or LEFT, please contact Emacsist at gmail dot com .