* Indentation and visual-line-mode
@ 2011-11-25 9:34 Tassilo Horn
2011-11-25 11:52 ` Eli Zaretskii
` (2 more replies)
0 siblings, 3 replies; 13+ messages in thread
From: Tassilo Horn @ 2011-11-25 9:34 UTC (permalink / raw)
To: emacs-devel
Hi all,
in some document that's written by me and others, the convention is that
every paragraph is written on one line, probably because the others
don't use emacs and their editors have no equivalent of `M-q'.
Anyway, when editing such files, I enable visual-line-mode to make my
editing more convenient. However, there's one thing I'm missing. If a
line is visually wrapped around, it always starts at column zero, even
if the logical line is indented.
For example, if the window was 25 columns wide, I get
--8<---------------cut here---------------start------------->8---
\begin{itemize}
\item Foo bar baz foo
bar baz foo
\item Bar baz foo bar
baz
\end{itemize}
--8<---------------cut here---------------end--------------->8---
which looks pretty weird. Is there some option that allows the wrapped
lines to be visually indented relative to the current logical line?
--8<---------------cut here---------------start------------->8---
\begin{itemize}
\item Foo bar baz foo
bar baz foo
\item Bar baz foo bar
baz
\end{itemize}
--8<---------------cut here---------------end--------------->8---
Checking the docs, I think something like that can be achieved using the
variables or text properties `line-prefix' and `wrap-prefix', but what
is a stretch-glyph?
Bye,
Tassilo
--
(What the world needs (I think) is not
(a Lisp (with fewer parentheses))
but (an English (with more.)))
Brian Hayes, http://tinyurl.com/3y9l2kf
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Indentation and visual-line-mode
2011-11-25 9:34 Indentation and visual-line-mode Tassilo Horn
@ 2011-11-25 11:52 ` Eli Zaretskii
2011-11-25 12:38 ` Stephen Berman
2011-11-25 13:49 ` Lennart Borgman
2011-11-25 14:00 ` Stefan Monnier
2 siblings, 1 reply; 13+ messages in thread
From: Eli Zaretskii @ 2011-11-25 11:52 UTC (permalink / raw)
To: Tassilo Horn; +Cc: emacs-devel
> From: Tassilo Horn <tassilo@member.fsf.org>
> Date: Fri, 25 Nov 2011 10:34:25 +0100
>
> --8<---------------cut here---------------start------------->8---
> \begin{itemize}
> \item Foo bar baz foo
> bar baz foo
> \item Bar baz foo bar
> baz
> \end{itemize}
> --8<---------------cut here---------------end--------------->8---
>
> which looks pretty weird. Is there some option that allows the wrapped
> lines to be visually indented relative to the current logical line?
I doubt that, because logical indentation and display-time wrap or
prefixing are two very different features on two very different
levels. Logical indentation is actually present in the buffer, while
display-time features are produced by the display engine on the fly,
without any consideration of previous lines.
> Checking the docs, I think something like that can be achieved using the
> variables or text properties `line-prefix' and `wrap-prefix', but what
> is a stretch-glyph?
That's the empty space generated by the display engine when you use
:width, :relative-width, or :align-to display specs, see the node
"Specified Space" in the ELisp manual. (I will clarify the text in
the manual in this regard.) But the variables you mention are
supposed to have constant values, so you cannot put there a Lisp
expression that needs to be evaluated. Therefore, I think you will
only be able to use them in your situation if you manually set them to
the amount of space derived from the logical indentation, or invoke
some hook that does that when the file is visited (assuming you never
want to change the indentation during editing).
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Indentation and visual-line-mode
2011-11-25 11:52 ` Eli Zaretskii
@ 2011-11-25 12:38 ` Stephen Berman
2011-11-25 13:54 ` Tassilo Horn
0 siblings, 1 reply; 13+ messages in thread
From: Stephen Berman @ 2011-11-25 12:38 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: Tassilo Horn, emacs-devel
On Fri, 25 Nov 2011 13:52:37 +0200 Eli Zaretskii <eliz@gnu.org> wrote:
>> From: Tassilo Horn <tassilo@member.fsf.org>
>> Date: Fri, 25 Nov 2011 10:34:25 +0100
>>
>> --8<---------------cut here---------------start------------->8---
>> \begin{itemize}
>> \item Foo bar baz foo
>> bar baz foo
>> \item Bar baz foo bar
>> baz
>> \end{itemize}
>> --8<---------------cut here---------------end--------------->8---
>>
>> which looks pretty weird. Is there some option that allows the wrapped
>> lines to be visually indented relative to the current logical line?
>
> I doubt that, because logical indentation and display-time wrap or
> prefixing are two very different features on two very different
> levels. Logical indentation is actually present in the buffer, while
> display-time features are produced by the display engine on the fly,
> without any consideration of previous lines.
>
>> Checking the docs, I think something like that can be achieved using the
>> variables or text properties `line-prefix' and `wrap-prefix', but what
>> is a stretch-glyph?
>
> That's the empty space generated by the display engine when you use
> :width, :relative-width, or :align-to display specs, see the node
> "Specified Space" in the ELisp manual. (I will clarify the text in
> the manual in this regard.) But the variables you mention are
> supposed to have constant values, so you cannot put there a Lisp
> expression that needs to be evaluated. Therefore, I think you will
> only be able to use them in your situation if you manually set them to
> the amount of space derived from the logical indentation, or invoke
> some hook that does that when the file is visited
I use the following (added to a major-mode defun) to achieve the visual
effect described:
(defun srb-wrap-and-indent ()
"Use word wrapping on long lines and indent with a wrap prefix.
The amount of indentation is given by user option `srb-indent-to-here'."
(set (make-local-variable 'word-wrap) t)
(set (make-local-variable 'wrap-prefix) (make-string srb-indent-to-here 32))
(unless (member '(continuation) fringe-indicator-alist)
(push '(continuation) fringe-indicator-alist)))
> (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.
Steve Berman
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Indentation and visual-line-mode
2011-11-25 9:34 Indentation and visual-line-mode Tassilo Horn
2011-11-25 11:52 ` Eli Zaretskii
@ 2011-11-25 13:49 ` Lennart Borgman
2011-11-25 14:36 ` Tassilo Horn
2011-11-25 14:00 ` Stefan Monnier
2 siblings, 1 reply; 13+ messages in thread
From: Lennart Borgman @ 2011-11-25 13:49 UTC (permalink / raw)
To: Tassilo Horn; +Cc: emacs-devel
[-- Attachment #1: Type: text/plain, Size: 795 bytes --]
On Fri, Nov 25, 2011 at 10:34, Tassilo Horn <tassilo@member.fsf.org> wrote:
> Hi all,
>
> in some document that's written by me and others, the convention is that
> every paragraph is written on one line, probably because the others
> don't use emacs and their editors have no equivalent of `M-q'.
>
> Checking the docs, I think something like that can be achieved using the
> variables or text properties `line-prefix' and `wrap-prefix', but what
> is a stretch-glyph?
I think I have told here that there is and have been for several years
a minor mode in nXhtml that does this: wrap-to-fill-column-mode.
I have attached an image of how it can look in org-mode. There are two
lines in this image, one in org-mode itself and one in a comment in
org-mode. Both are wrapped the way you want it.
[-- Attachment #2: brene-brown-emacs.PNG --]
[-- Type: image/png, Size: 22593 bytes --]
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Indentation and visual-line-mode
2011-11-25 12:38 ` Stephen Berman
@ 2011-11-25 13:54 ` Tassilo Horn
2011-11-25 14:52 ` Stefan Monnier
0 siblings, 1 reply; 13+ messages in thread
From: Tassilo Horn @ 2011-11-25 13:54 UTC (permalink / raw)
To: Stephen Berman; +Cc: Eli Zaretskii, emacs-devel
Stephen Berman <stephen.berman@gmx.net> writes:
Hi Stephen,
>> (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.
I've just tried that code, and it's exactly what I've been looking for.
I'd appreciate if that feature would ship with emacs.
Bye,
Tassilo
--
(What the world needs (I think) is not
(a Lisp (with fewer parentheses))
but (an English (with more.)))
Brian Hayes, http://tinyurl.com/3y9l2kf
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Indentation and visual-line-mode
2011-11-25 9:34 Indentation and visual-line-mode Tassilo Horn
2011-11-25 11:52 ` Eli Zaretskii
2011-11-25 13:49 ` Lennart Borgman
@ 2011-11-25 14:00 ` Stefan Monnier
2 siblings, 0 replies; 13+ messages in thread
From: Stefan Monnier @ 2011-11-25 14:00 UTC (permalink / raw)
To: Tassilo Horn; +Cc: emacs-devel
> which looks pretty weird. Is there some option that allows the wrapped
> lines to be visually indented relative to the current logical line?
If by "option" you mean a configuration variable: no.
But you can write Elisp code to do that, yes. IIRC Lennart posted some
code to do that a while ago (at least to display email, not sure if it
would work for interactive editing).
Stefan
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Indentation and visual-line-mode
2011-11-25 13:49 ` Lennart Borgman
@ 2011-11-25 14:36 ` Tassilo Horn
2011-11-25 14:47 ` Lennart Borgman
0 siblings, 1 reply; 13+ messages in thread
From: Tassilo Horn @ 2011-11-25 14:36 UTC (permalink / raw)
To: Lennart Borgman; +Cc: emacs-devel
Lennart Borgman <lennart.borgman@gmail.com> writes:
Hi Lennart,
>> Checking the docs, I think something like that can be achieved using
>> the variables or text properties `line-prefix' and `wrap-prefix', but
>> what is a stretch-glyph?
>
> I think I have told here that there is and have been for several years
> a minor mode in nXhtml that does this: wrap-to-fill-column-mode.
Hm, I've just downloaded wrap-to-fill.el, but it depends on mumamo and
possibly other files. I'm not too tempted to install nXhtml mode just
for that single feature, when Stephen's snippet works just fine.
> I have attached an image of how it can look in org-mode. There are
> two lines in this image, one in org-mode itself and one in a comment
> in org-mode. Both are wrapped the way you want it.
Oh, are the second and third # in the comment artifical, i.e., logically
it's only "# one comment starter followed by a very long line"?
Bye,
Tassilo
--
(What the world needs (I think) is not
(a Lisp (with fewer parentheses))
but (an English (with more.)))
Brian Hayes, http://tinyurl.com/3y9l2kf
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Indentation and visual-line-mode
2011-11-25 14:36 ` Tassilo Horn
@ 2011-11-25 14:47 ` Lennart Borgman
2011-11-25 15:37 ` Juanma Barranquero
0 siblings, 1 reply; 13+ messages in thread
From: Lennart Borgman @ 2011-11-25 14:47 UTC (permalink / raw)
To: Tassilo Horn; +Cc: emacs-devel
On Fri, Nov 25, 2011 at 15:36, Tassilo Horn <tassilo@member.fsf.org> wrote:
> Lennart Borgman <lennart.borgman@gmail.com> writes:
>
> Hi Lennart,
>
>>> Checking the docs, I think something like that can be achieved using
>>> the variables or text properties `line-prefix' and `wrap-prefix', but
>>> what is a stretch-glyph?
>>
>> I think I have told here that there is and have been for several years
>> a minor mode in nXhtml that does this: wrap-to-fill-column-mode.
>
> Hm, I've just downloaded wrap-to-fill.el, but it depends on mumamo and
> possibly other files.
It does not depend on mumamo.el. I just forgot to remove the
(eval-when-compile (require 'mumamo)) line.
> I'm not too tempted to install nXhtml mode just
> for that single feature, when Stephen's snippet works just fine.
They do not do the same thing.
>> I have attached an image of how it can look in org-mode. There are
>> two lines in this image, one in org-mode itself and one in a comment
>> in org-mode. Both are wrapped the way you want it.
>
> Oh, are the second and third # in the comment artifical, i.e., logically
> it's only "# one comment starter followed by a very long line"?
Yes.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Indentation and visual-line-mode
2011-11-25 13:54 ` Tassilo Horn
@ 2011-11-25 14:52 ` Stefan Monnier
2011-11-25 14:58 ` Lennart Borgman
2011-11-25 15:15 ` Tassilo Horn
0 siblings, 2 replies; 13+ messages in thread
From: Stefan Monnier @ 2011-11-25 14:52 UTC (permalink / raw)
To: Tassilo Horn; +Cc: Eli Zaretskii, Stephen Berman, emacs-devel
>>> (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))))))
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Indentation and visual-line-mode
2011-11-25 14:52 ` Stefan Monnier
@ 2011-11-25 14:58 ` Lennart Borgman
2011-11-25 15:15 ` Tassilo Horn
1 sibling, 0 replies; 13+ messages in thread
From: Lennart Borgman @ 2011-11-25 14:58 UTC (permalink / raw)
To: Stefan Monnier; +Cc: Tassilo Horn, Stephen Berman, Eli Zaretskii, emacs-devel
On Fri, Nov 25, 2011 at 15:52, Stefan Monnier <monnier@iro.umontreal.ca> wrote:
>>>> (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.
If it is for text modes then I suggest using something like what I
told about above since you also would want a more narrow text for
readability. (Please see the picture I sent.)
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Indentation and visual-line-mode
2011-11-25 14:52 ` Stefan Monnier
2011-11-25 14:58 ` Lennart Borgman
@ 2011-11-25 15:15 ` Tassilo Horn
1 sibling, 0 replies; 13+ messages in thread
From: Tassilo Horn @ 2011-11-25 15:15 UTC (permalink / raw)
To: Stefan Monnier; +Cc: Eli Zaretskii, Stephen Berman, emacs-devel
Stefan Monnier <monnier@IRO.UMontreal.CA> writes:
>>>> (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".
Hell's already frozen over:
http://researchmaniacs.com/Jokes/HellExplained.html
>> 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.
But usually, there are no overly long lines in source code.
>> 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.
Awesome, thank you.
Bye,
Tassilo
--
(What the world needs (I think) is not
(a Lisp (with fewer parentheses))
but (an English (with more.)))
Brian Hayes, http://tinyurl.com/3y9l2kf
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Indentation and visual-line-mode
2011-11-25 14:47 ` Lennart Borgman
@ 2011-11-25 15:37 ` Juanma Barranquero
2011-11-25 15:46 ` Lennart Borgman
0 siblings, 1 reply; 13+ messages in thread
From: Juanma Barranquero @ 2011-11-25 15:37 UTC (permalink / raw)
To: Lennart Borgman; +Cc: Tassilo Horn, emacs-devel
On Fri, Nov 25, 2011 at 15:47, Lennart Borgman
<lennart.borgman@gmail.com> wrote:
> It does not depend on mumamo.el. I just forgot to remove the
> (eval-when-compile (require 'mumamo)) line.
Why does it contain that line if it does not depend on mumamo?
Juanma
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Indentation and visual-line-mode
2011-11-25 15:37 ` Juanma Barranquero
@ 2011-11-25 15:46 ` Lennart Borgman
0 siblings, 0 replies; 13+ messages in thread
From: Lennart Borgman @ 2011-11-25 15:46 UTC (permalink / raw)
To: Juanma Barranquero; +Cc: Tassilo Horn, emacs-devel
On Fri, Nov 25, 2011 at 16:37, Juanma Barranquero <lekktu@gmail.com> wrote:
> On Fri, Nov 25, 2011 at 15:47, Lennart Borgman
> <lennart.borgman@gmail.com> wrote:
>
>> It does not depend on mumamo.el. I just forgot to remove the
>> (eval-when-compile (require 'mumamo)) line.
>
> Why does it contain that line if it does not depend on mumamo?
Because I had trouble getting the automatic faked indentation working
in files with multiple major modes from the beginning.
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2011-11-25 15:46 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-11-25 9:34 Indentation and visual-line-mode Tassilo Horn
2011-11-25 11:52 ` Eli Zaretskii
2011-11-25 12:38 ` Stephen Berman
2011-11-25 13:54 ` Tassilo Horn
2011-11-25 14:52 ` Stefan Monnier
2011-11-25 14:58 ` Lennart Borgman
2011-11-25 15:15 ` Tassilo Horn
2011-11-25 13:49 ` Lennart Borgman
2011-11-25 14:36 ` Tassilo Horn
2011-11-25 14:47 ` Lennart Borgman
2011-11-25 15:37 ` Juanma Barranquero
2011-11-25 15:46 ` Lennart Borgman
2011-11-25 14:00 ` Stefan Monnier
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.