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))))
5
  • 1
    The key sequence for indenting the whole buffer is already quite short: C-x h <tab>. So I don't need a special command for that.
    – Tobias
    Feb 7, 2018 at 16:53
  • @Tobias the effect of C-x h <tab> and C-x h M-x fill-region is different. What I need is the latter.
    – Name
    Feb 7, 2018 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 7, 2018 at 17:00
  • @Tobias Thank you for your illuminating explanation.
    – Name
    Feb 7, 2018 at 17:10
  • 3
    IOW, C-x h followed by C-u M-q will justify each paragraph in the buffer.
    – Drew
    Feb 7, 2018 at 18:35

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.