Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable auto-fill-mode locally (or un fill-paragraph) with emacs

I use M-q for fill-paragraph, can I do the un-fill-paragraph in auto-fill-mode?

With org mode, I sometimes enter [[Very long HTML][Name with spaces]], and for the 'Name with spaces' the auto-fill mode break the whole line based on the inserted space, which makes it very ugly.

Is there a command something like un-fill-paragraph? Or, is there a way disable auto-fill-mode temporarily/locally?

like image 643
prosseek Avatar asked Sep 09 '10 13:09

prosseek


2 Answers

Emacs does not record what was your line before calling fill-paragraph. So the only thing you can do is C-_ which runs the command undo. It can undo your fill-paragraph command but only if it is the preceding command call.

If you want to put a multi-line paragraph on one line you could do like this :

  • Select the region
  • C-M-% C-q C-j RET SPACE RET !
like image 170
Jérôme Radix Avatar answered Sep 28 '22 16:09

Jérôme Radix


Xah Lee has updated his code since monotux's answer, and I refactored it somewhat for readability:

(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)))))
like image 31
phils Avatar answered Sep 28 '22 14:09

phils