3

I would like to fill justify all paragraphs in the current buffer if no region is selected. I wrote the the following function which performs this job.

Is there a better way to write this function? Is there a build-in function which performs this job?

(defun my-fill-buffer () 
  (interactive)
  (if (not (region-active-p))
      (save-excursion
        (mark-whole-buffer)
        (call-interactively 'fill-region))))
Drew
  • 75,699
  • 9
  • 109
  • 225
Name
  • 7,689
  • 4
  • 38
  • 84
  • 1
    The key sequence for indenting the whole buffer is already quite short: `C-x h `. So I don't need a special command for that. – Tobias Feb 07 '18 at 16:53
  • @Tobias the effect of `C-x h ` and `C-x h M-x fill-region` is different. What I need is the latter. – Name Feb 07 '18 at 16:56
  • 1
    Sorry my bad, meant `C-x h M-q`. (See doc of `fill-paragraph`: `The REGION argument is non-nil if called interactively; in that case, if Transient Mark mode is enabled and the mark is active, call ‘fill-region’ to fill each of the paragraphs in the active region, instead of just filling the current paragraph.`) – Tobias Feb 07 '18 at 17:00
  • @Tobias Thank you for your illuminating explanation. – Name Feb 07 '18 at 17:10
  • 3
    IOW, `C-x h` followed by `C-u M-q` will justify each paragraph in the buffer. – Drew Feb 07 '18 at 18:35

0 Answers0