Emanuel Berg
2018-12-05 02:48:59 UTC
Here [1] is a function I once wrote. My mind
isn't what it was back then, but testing it
with the different options (the `C-u' combos)
I understand it from a user's perspective and
it seems to do what it says.
Only one thing is missing what I can see, and
that is, when nothing happens (i e the piece of
text is already in the desired shape), the
buffer is still marked as modified (the `**')!
What is the correct way to prevent that?
(defun fill-down (start end &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 fill it!)
With \\[universal-argument] thrice, center."
(interactive
(if (use-region-p)
(list (region-beginning) (region-end) current-prefix-arg)
(list (line-beginning-position)
(save-excursion (forward-paragraph) (point))
current-prefix-arg)))
(if (equal justify '(16)) ; C-u C-u -> unjustify
(canonically-space-region start end)
(fill-region
start end
(pcase justify
(`(4) 'full) ; C-u -> justify
(`(64) 'center) )))) ; C-u C-u C-u -> center
;; no C-u -> none (i e just fill)
[1] http://user.it.uu.se/~embe8573/emacs-init/fill-new.el
isn't what it was back then, but testing it
with the different options (the `C-u' combos)
I understand it from a user's perspective and
it seems to do what it says.
Only one thing is missing what I can see, and
that is, when nothing happens (i e the piece of
text is already in the desired shape), the
buffer is still marked as modified (the `**')!
What is the correct way to prevent that?
(defun fill-down (start end &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 fill it!)
With \\[universal-argument] thrice, center."
(interactive
(if (use-region-p)
(list (region-beginning) (region-end) current-prefix-arg)
(list (line-beginning-position)
(save-excursion (forward-paragraph) (point))
current-prefix-arg)))
(if (equal justify '(16)) ; C-u C-u -> unjustify
(canonically-space-region start end)
(fill-region
start end
(pcase justify
(`(4) 'full) ; C-u -> justify
(`(64) 'center) )))) ; C-u C-u C-u -> center
;; no C-u -> none (i e just fill)
[1] http://user.it.uu.se/~embe8573/emacs-init/fill-new.el
--
underground experts united
http://user.it.uu.se/~embe8573
underground experts united
http://user.it.uu.se/~embe8573