Inverse of M-q, an unfill-paragraph-function

前端 未结 4 2245
渐次进展
渐次进展 2020-12-30 01:48

Is there an inverse for M-q, some kind of unfill-paragraph-function?

If I have undo data, then it\'s of course easy. What I am asking for is

相关标签:
4条回答
  • 2020-12-30 02:11

    See also M-^ (delete-indentation).

    It joins the current line to the previous line, so if you start with point at the last line of the paragraph you can keep pressing M-^ until all the lines are joined up.

    0 讨论(0)
  • 2020-12-30 02:14

    Also see this post

    http://blog.chrislowis.co.uk/2010/03/03/unfill-region-emacs.html

    Which mentions the very useful longlines mode.

    0 讨论(0)
  • 2020-12-30 02:16

    Here's the answer. In short:

    (defun unfill-paragraph ()
      "Replace newline chars in current paragraph by single spaces.
    This command does the reverse of `fill-paragraph'."
      (interactive)
      (let ((fill-column 90002000))
        (fill-paragraph nil)))
    
    (defun unfill-region (start end)
      "Replace newline chars in region by single spaces.
    This command does the reverse of `fill-region'."
      (interactive "r")
      (let ((fill-column 90002000))
        (fill-region start end))) 
    

    Update: I've packaged this up here and it can be installed from Marmalade or Melpa.

    0 讨论(0)
  • 2020-12-30 02:20

    I was first using @sanityinc's solution for a while until I came accross Stefan Monnier's Unfill Paragraph in EmacsWiki. It seems more robust

    ;;; Stefan Monnier <foo at acm.org>. It is the opposite of fill-paragraph    
    (defun unfill-paragraph (&optional region)
      "Takes a multi-line paragraph and makes it into a single line of text."
      (interactive (progn (barf-if-buffer-read-only) '(t)))
      (let ((fill-column (point-max))
            ;; This would override `fill-column' if it's an integer.
            (emacs-lisp-docstring-fill-column t))
        (fill-paragraph nil region)))
    
    ;; Handy key definition
    (define-key global-map "\M-Q" 'unfill-paragraph)
    

    The M-Q key binding makes the command so much easier.

    0 讨论(0)
提交回复
热议问题