2011-07-15 9 views
17

M-qのための逆数は、unfill-paragraph-functionの何らかの種類ですか?不完全段落関数M-qの逆数

データを元に戻すことができれば、もちろん簡単です。私が求めているのは、ディスクからファイルを読み込んだ直後に段落の行を1つの長い行にマージする機能です。これにより、各段落に対して1行の改行が予想されるフォーム(Webフォームなど)にテキストを貼り付けることができます。

これまではauto-fillをオフにし、EOLを削除して次の行に移動して繰り返し適用するマクロを作成しましたが、これは疲れています。

答えて

21

Here's the answer

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

更新:一言で言えば、私はhereこれをパッケージ化しましたし、それはMarmaladeMelpaからインストールすることができます。

+0

パーフェクト。ありがとう。 – Calaf

+5

私はその整数が不思議です。それはどこから来ていますか?代わりに、「最も肯定的なfixnum」を使用しない理由がありますか? – phils

+0

元の著者に尋ねる必要がありますが、Emacsのすべてのバージョンとその亜種には 'most-positive-fixnum'が存在しない可能性があります。私も好奇心が強い。 – sanityinc

7

も参照してください。M- ^(delete-indentation)も参照してください。

現在の行を前の行に結合するので、段落の最後の行にあるポイントで始めると、すべての行が結合されるまでM- ^を押し続けることができます。

+0

このアプローチでは、コメント構文のようなものは考慮しませんが、適切な句読点の後に(モードに応じて)空白を挿入するには少なくともスマートです。 – phils

+0

phils: "塗りつぶしプレフィックスがある場合は、この行の先頭から削除してください"。最初のnon-fill-prefixカラムをポイントすると、C-xを使用できます。 (set-fill-prefix)し、M- ^はあなたの望むように動作します。 M- ^のように、M- ^はそれ自身の接頭辞を理解していないのは残念です。 –

+0

きちんとしていて、それは箱の外で働いています。 – Calaf

0

私は最初に@ sanityincの溶液をしばらく使用して、私がaccross Stefan Monnier's Unfill Paragraph in EmacsWikiになるまでしました。より堅牢に見えます

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

(defun unfill-region (beg end) 
    "Unfill the region, joining text paragraphs into a single 
logical line. This is useful, e.g., for use with 
`visual-line-mode'." 
    (interactive "*r") 
    (let ((fill-column (point-max))) 
    (fill-region beg end))) 

;; Handy key definition 
(define-key global-map "\C-\M-Q" 'unfill-region) 

M-Qキーバインディングは、コマンドを非常に簡単にします。