help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

fill down


From: Emanuel Berg
Subject: fill down
Date: Sun, 05 Nov 2017 07:13:03 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)

I just wrote this. Or actually it was a couple
of days ago. The idea with the "down" approach
is so that manual edits after fill above won't
be undone (for example putting together the
last two words in "You owe me 500 SEK" on the
same line). Also with DWIM region and heavy use
of the numeric/prefix/universal argument.
There is more to be added - upcase and
downcase, just whatever you can think of - with
minimal effort or change to the code - just
whatever it is, that should be added...

All comments welcome how to improve it,
for sure!

(defun fill-down (&optional justify)
  "Fill the current paragraph from the current line down.\n
With mark active, act upon the region instead.\n
With \\[universal-argument] before invocation, JUSTIFY fully.
With \\[universal-argument] twice, remove full justification. (Or just try to 
fill it!)
With \\[universal-argument] thrice, center.
With any more \\[universal-argument] than that, the sky is the limit!"
  (interactive "P")
  (let*((area (if (region-active-p)
                  `(,(region-beginning)        ,(region-end))
                  `(,(line-beginning-position) ,(save-excursion
                                                  (forward-paragraph)
                                                  (point)))))
        (start (car  area))
        (end   (cadr area)) )
    ;; C-u C-u -> unjustify
    (if (equal justify '(16))
        (canonically-space-region start end)
      (fill-region start end
       ;; can't use cl-case here as compares with `elq' - bummer!
       (cond ((equal justify  '(0))  nil)     ; fill
             ((equal justify  '(4)) 'full)    ; C-u -> justify
             ((equal justify '(64)) 'center)) ; C-u C-u C-u -> center
       ))))

-- 
underground experts united
http://user.it.uu.se/~embe8573




reply via email to

[Prev in Thread] Current Thread [Next in Thread]