linewrap in headlines

79 views
Skip to first unread message

Stefan Fruehwirth

unread,
Nov 1, 2012, 1:12:25 PM11/1/12
to leo-e...@googlegroups.com
A short question: Is it possible to have linewrap in headlines? Or maybe with a few lines of code?

Thanks,
Stefan

HaveF

unread,
Nov 2, 2012, 12:12:18 PM11/2/12
to leo-e...@googlegroups.com

why do you want to do this?
must to do this?

--
You received this message because you are subscribed to the Google Groups "leo-editor" group.
To view this discussion on the web visit https://groups.google.com/d/msg/leo-editor/-/Dju7HUU_yXEJ.
To post to this group, send email to leo-e...@googlegroups.com.
To unsubscribe from this group, send email to leo-editor+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/leo-editor?hl=en.

Stefan Fruehwirth

unread,
Nov 2, 2012, 2:31:38 PM11/2/12
to leo-e...@googlegroups.com


Am Freitag, 2. November 2012 17:12:19 UTC+1 schrieb HaveF:

why do you want to do this?
must to do this?

 I think an answer to this question doesn't depend on my reasons for asking it, don't you think? If you want to know if it is possible that there is another solution to my problem, then let me explain. But if you want to tell me that it's a bad idea to have line wraps in headlines simply because it's unusual, then please feel free to ignore my question. Thank you!

Background: I use Leo for structuring my thoughts on a specific topic and for this I mainly use headlines. Sometimes the thoughts can be expressed only by rather long sentences. There is no point in putting this ideas, concepts and explanations in the node body because then It is hard to get a grasp of the relationship of these ideas. Besides I wouldn't know how to name headlines for the thoughts I put in the node bodies. Is that hard to imagine? Or is it that unusual? It seems so natural to me.

I know Leo wasn't designed for this purpose but that's not in question. I just can't live without cloning and all the other wonderful possibilities of Leo and therefore I'd like to use it for this kind of work.

I would appreciate any comments. If someone can make clear to me why I shouldn't do this or how it can be done another way - this is also welcome!

Thanks,
Stefan

Terry Brown

unread,
Nov 2, 2012, 2:46:47 PM11/2/12
to leo-e...@googlegroups.com
On Thu, 1 Nov 2012 10:12:25 -0700 (PDT)
Stefan Fruehwirth <stefan.f...@uni-graz.at> wrote:

> A short question: Is it possible to have linewrap in headlines? Or maybe
> with a few lines of code?

It would be easy to write a tiny script that copied the body to the
headline with linebreaks. This test

p.h = 'test\nthis'

which creates a two line headline, shows that the tree can handle
multiline headlines.

In fact I guess the tiny script would be

p.h = p.b

:-) with the only challenge being how to most conveniently get it bound
to a key etc.

Ok, why does software always have to get more complex :-), a better
version would be

p.h = p.b.strip()

Let me know if you want pointers on binding to keys / making buttons.

Cheers -Terry

> Thanks,
> Stefan
>

Stefan Fruehwirth

unread,
Nov 2, 2012, 5:13:19 PM11/2/12
to leo-e...@googlegroups.com

Am Freitag, 2. November 2012 19:46:52 UTC+1 schrieb Terry:

It would be easy to write a tiny script that copied the body to the
headline with linebreaks.  This test

p.h = 'test\nthis'

Thanks for the hint, this works! I was just hoping that there is a way to put line breaks directly in headline edit mode so that I can do Shift-Return and have a line break inserted. But that would be a little more work I guess?
 
which creates a two line headline, shows that the tree can handle
multiline headlines.

In fact I guess the tiny script would be

p.h = p.b

I created two commands, edit-head-in-body and write-body-to-head and bound it to Alt-Shift-E and Alt-Shift-F

p.b = p.h.strip ()
c.executeMinibufferCommand ( "focus-to-body" )

and

p.h = p.b.strip ()
p.b = ""
c.executeMinibufferCommand ( "focus-to-tree" )

I tried mapping Alt-Shift-E to both commands in different panes like

edit-head-in-body ! tree = Alt-Shift-E
write-body-to-head ! body = Alt-Shift-E

But that throws a shortcut conflict error. Isn't that possible? The return key is mapped in a similar way in leoSettings.leo.

Stefan

Terry Brown

unread,
Nov 2, 2012, 5:32:15 PM11/2/12
to leo-e...@googlegroups.com
On Fri, 2 Nov 2012 14:13:19 -0700 (PDT)
Stefan Fruehwirth <stefan.f...@uni-graz.at> wrote:

> Thanks for the hint, this works! I was just hoping that there is a way to
> put line breaks directly in headline edit mode so that I can do
> Shift-Return and have a line break inserted. But that would be a little
> more work I guess?

I'm not sure if the edit widget would support it or not. So there'd be
two parts, tweaking the key handling code to do the line break
insert for Shift-return, and the question of whether the widget editor
would work.

The key handling code's more Edward's area. ;-)

Cheers -Terry

HaveF

unread,
Nov 2, 2012, 9:21:19 PM11/2/12
to leo-e...@googlegroups.com
If there is possible to make leo has the possibility to auto linewrap in headlines?

and adobe reader(or acrobat, I can't remember exactly) has this ability, at the bookmark panel,
you can choose freely from right click menu whether to auto linewrap the bookmark  or not,
then, Stefan would has less shortcuts to bind ;-)

--
You received this message because you are subscribed to the Google Groups "leo-editor" group.

Terry Brown

unread,
Nov 3, 2012, 2:07:41 PM11/3/12
to leo-e...@googlegroups.com
On Sat, 3 Nov 2012 09:21:19 +0800
HaveF <iamap...@gmail.com> wrote:

> If there is possible to make leo has the possibility to auto linewrap in
> headlines?

Running the code below (in a @script node or whatever) seems to make
Leo wrap headlines. Please TEST THOROUGHLY ON A BACKUP of your working
file, once run this code causes Leo to wrap every headline as you
unselect it (move to another headline), and that can be quite
destructive on an outline not intended for wrapping.

from textwrap import wrap
hook = 'unselect1'
width = 12

if hasattr(c, '_wrapper'):
g.unregisterHandler(hook, c._wrapper)

def wrapper(tag, kwds, this_c=c):
if not kwds.get('c') == this_c:
return
old_p = kwds.get('old_p')
old_p.h = '\n'.join(wrap(c.p.h, width=width, break_long_words=False))

c._wrapper = wrapper
g.registerHandler(hook, c._wrapper)

Edward K. Ream

unread,
Nov 4, 2012, 6:46:49 AM11/4/12
to leo-e...@googlegroups.com
On Thu, Nov 1, 2012 at 12:12 PM, Stefan Fruehwirth
<stefan.f...@uni-graz.at> wrote:
> A short question: Is it possible to have linewrap in headlines? Or maybe
> with a few lines of code?

Headlines contain one line of code. If you try to paste multiple
lines into a headline Leo will truncate the headline to the first
line.

For very long lines, the behavior depends on the Qt QLineEdit widget.
This widget: http://doc.qt.nokia.com/4.7-snapshot/qlineedit.html
This is a one-line text editor, so the notion of line wrapping does not apply.

HTH.

Edward

Stefan Fruehwirth

unread,
Nov 4, 2012, 12:34:47 PM11/4/12
to leo-e...@googlegroups.com


On Saturday, November 3, 2012 7:07:48 PM UTC+1, Terry wrote:
Running the code below (in a @script node or whatever) seems to make
Leo wrap headlines.  Please TEST THOROUGHLY ON A BACKUP of your working
file, once run this code causes Leo to wrap every headline as you
unselect it (move to another headline), and that can be quite
destructive on an outline not intended for wrapping.


Thank you, that's just great! Works for me, no problems so far. Although I keep wondering why there's no hook like "onHeadlineEditingFinished"...

Stefan

Stefan Fruehwirth

unread,
Nov 4, 2012, 12:39:11 PM11/4/12
to leo-e...@googlegroups.com


On Sunday, November 4, 2012 12:46:50 PM UTC+1, Edward K. Ream wrote:

For very long lines, the behavior depends on the Qt QLineEdit widget.
This widget: http://doc.qt.nokia.com/4.7-snapshot/qlineedit.html
This is a one-line text editor, so the notion of line wrapping does not apply.

I see, but Terry's solution comes close to what I had in mind. One thing I tried to tweak is the vertical alignment of each node's icon. For when I have multiple lines the icon sits in the middle, whereas I'd like it to be on top (for usability reasons). Does the icon have it's own CSS id or class? Is it right to assume that it is a child of QTreeWidgetItem?

Thanks,
Stefan

Edward K. Ream

unread,
Nov 6, 2012, 10:14:24 AM11/6/12
to leo-e...@googlegroups.com
On Sun, Nov 4, 2012 at 11:34 AM, Stefan Fruehwirth
<stefan.f...@uni-graz.at> wrote:

> Thank you, that's just great! Works for me, no problems so far. Although I
> keep wondering why there's no hook like "onHeadlineEditingFinished"...

There is such a hook. It is called "headkey2". For exact details of
how this works, see onHeadChanged in leoTree.py. Note that this hook
can be called even if no actual change has been made to the headline.

Edward

Terry Brown

unread,
Nov 6, 2012, 1:42:46 PM11/6/12
to leo-e...@googlegroups.com
On Tue, 6 Nov 2012 09:14:24 -0600
"Edward K. Ream" <edre...@gmail.com> wrote:

> > Thank you, that's just great! Works for me, no problems so far. Although I
> > keep wondering why there's no hook like "onHeadlineEditingFinished"...
>
> There is such a hook. It is called "headkey2". For exact details of
> how this works, see onHeadChanged in leoTree.py. Note that this hook
> can be called even if no actual change has been made to the headline.

It looks like that's called after every keystroke, which would be
inappropriate timing for wrapping the text, I would think, although it
might work. OP wanted something called on the transition from edit to
non-edit state I think.

Cheers -Terry

Stefan Frühwirth

unread,
Nov 7, 2012, 5:40:28 AM11/7/12
to leo-e...@googlegroups.com
Exactly, I intentionally called it onHeadlineEditingFinished because I
don't want the code executed on every change. And because there is a
clear transition from edit mode to non-edit mode I thought this would be
an appropriate time for an event to get fired.

Thanks,
Stefan

Stefan Frühwirth

unread,
Nov 7, 2012, 5:39:14 AM11/7/12
to leo-e...@googlegroups.com

On 06.11.2012 19:42, Terry Brown wrote:

Edward K. Ream

unread,
Nov 7, 2012, 11:47:16 AM11/7/12
to leo-e...@googlegroups.com
On Tue, Nov 6, 2012 at 12:42 PM, Terry Brown <terry_...@yahoo.com> wrote:

> It looks like that's called after every keystroke, which would be inappropriate timing for wrapping the text, I would think, although it might work. OP wanted something called on the transition from edit to non-edit state I think.

The code isn't going to change, so you will have to be content with
the existing hooks.

This is probably the most fragile code in all of Leo: it is incredibly
easy to break commands with the most seemingly minor of changes here.

Edward
Reply all
Reply to author
Forward
0 new messages