[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Indentation and visual-line-mode
From: |
Stefan Monnier |
Subject: |
Re: Indentation and visual-line-mode |
Date: |
Fri, 25 Nov 2011 09:52:19 -0500 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.0.91 (gnu/linux) |
>>> (assuming you never want to change the indentation during editing).
>> A while ago there was a thread about implementing a minor mode to get
>> visual indentation with wrap-prefix using fill-context-prefix, in
>> which I proposed an adaptation of the above; see
>> <http://permalink.gmane.org/gmane.emacs.devel/125268>. AFAIK there
>> was no followup to my proposal.
Indeed I didn't find the time to look at it and it ended up on my long
list of "things to do when hell finally freezes over".
> I've just tried that code, and it's exactly what I've been looking for.
I've just looked at it and it looks really nice and simple.
It can even be simplified further (see below).
Sadly, this can't be generalized to programming languages, in the sense
that you can't use foo-indent-calculate to set a wrap-prefix property
since the wrap-prefix to use depends on the place where the line
is wrapped.
> I'd appreciate if that feature would ship with Emacs.
It's too late for 24.1, but I've added it (under name "awp-mode.el"
which provides adaptive-wrap-prefix-mode) to ELPA.
Stefan
(defun srb-adaptive-indent (beg end)
"Indent the region between BEG and END with adaptive filling."
(goto-char beg)
(while (< (point) end)
(let ((blp (line-beginning-position)))
(put-text-property (point)
(progn (search-forward "\n" end 'move) (point))
'wrap-prefix
(fill-context-prefix
blp (point))))))
(define-minor-mode srb-adaptive-wrap-mode
"Wrap the buffer text with adaptive filling."
:lighter ""
(if srb-adaptive-wrap-mode
(jit-lock-register #'srb-adaptive-indent)
(jit-lock-unregister #'srb-adaptive-indent)
(with-silent-modifications
(save-restriction
(widen)
(remove-text-properties (point-min) (point-max) '(wrap-prefix nil))))))
Re: Indentation and visual-line-mode, Lennart Borgman, 2011/11/25
Re: Indentation and visual-line-mode, Stefan Monnier, 2011/11/25