What Was I Working On???

53 views
Skip to first unread message

Thomas Passin

unread,
May 16, 2023, 6:31:04 PM5/16/23
to leo-editor
Today I wanted to continue some work I started a few weeks ago.  I remember clearly what I did.  But I can't remember the outline, and I have not succeeded in finding it even with the help of FileLocatorPro (a terrific Windows program).  Somehow, the Recent Files list hasn't helped either.  Other times I've been able to find the outline but not easily.

I wondered if it would be useful to have Leo keep track of what I was working on when.  Admittedly this situation doesn't happen often, but I thought I'd try it out anyway.  Maybe it would be the start of something more useful.  Or maybe I'll feel like I had a nanny and stop using it.

It's still preliminary.  I have a script to start logging, and another to stop it.  It writes to ~/.leo/temp (and adjusts that path for WIndows).  They could easily be turned into global commands in myLeoSettings.leo, though I haven't done that yet.

The script registers as an idle time handler.  If a minute has elapsed since the last check, the script looks to see if the currently focused outline and node have changed since the last check.  If so, it writes the time and the node's UNL to the log file.

Why the UNL? Because it shows the outline and node in a fairly readable way, and because the UNL can by copied and used to open the outline, or otherwise used by some other Leo script.

Obviously a real logging framework could be used to get better file management, but for exploring this seems good enough.

To use, open the attached outline, select the Start Logging node, and run it with CTRL-b.  To stop logging without closing Leo, select the Stop Logging node and run it with <CTRL-b>
activity_logging.leo

Thomas Passin

unread,
May 16, 2023, 10:40:24 PM5/16/23
to leo-editor
Here's a bug fix.  I didn't update some constant names in the Stop Logging script.
activity_logging.leo

Edward K. Ream

unread,
May 17, 2023, 5:26:25 AM5/17/23
to leo-editor
On Tuesday, May 16, 2023 at 5:31:04 PM UTC-5 tbp1...@gmail.com wrote:

The script registers as an idle time handler.  If a minute has elapsed since the last check, the script looks to see if the currently focused outline and node have changed since the last check.  If so, it writes the time and the node's UNL to the log file.

Clever idea. I use the github issue tracker for almost everything I do. That's usually a good enough reminder :-)

Edward

Thomas Passin

unread,
May 17, 2023, 10:35:54 AM5/17/23
to leo-editor
Trying it out got me to thinking that it would be handy to be able to log quick little notes.  The following script writes the cursor line on the body to a note log file, whose path can optionally be specified in a setting.  The idea is that you could write a brief one-line note and pop it right into the log file with a time stamp -

"""Write cursor line to a log file."""
from pathlib import Path
import time

LOG = c.config.getString('notelog') or '~/.leo/temp/notelog.txt'
ACTUALPATH = Path(LOG).expanduser()

w = c.frame.body.wrapper
j = w.getInsertPoint()
s = c.p.b
beg, end = g.getLine(s, j)
line = s[beg:end]

if line:
    now = time.time()
    localtime = time.strftime("%Y-%m-%d %H:%M", time.localtime(now))
    with open(ACTUALPATH, 'a', encoding = 'utf-8') as f:
        f.write(f'{localtime}\t{line}\n')


You could do the same thing by keeping a text editor window with the log file open all the time, but if you are working with Leo anyway this would be more convenient.

Thomas Passin

unread,
Jun 11, 2023, 5:35:54 PM6/11/23
to leo-editor
After I started using this, I found that I sometimes want to capture multi-line selections from non-Leo sources, like a browser for example.  So I added a modified version of the script that logs the clipboard text to the log file.  I added an item for this script to my custom "Local" menu. A slight complication is how to indent a multi-line selection so that it's easy to read.  This script uses one approach: so far, so good.  Here's the script:

"""Write clipboard text to a log file."""

from pathlib import Path
import time
from textwrap import fill


LOG = c.config.getString('notelog') or '~/.leo/temp/notelog.txt'
ACTUALPATH = Path(LOG).expanduser()

text  = g.app.gui.getTextFromClipboard()
if text.strip():
    if len(text) > 65:
        text = '\n' + fill(text, 70, initial_indent = ' ' * 4, subsequent_indent = ' ' * 4)


    now = time.time()
    localtime = time.strftime("%Y-%m-%d %H:%M", time.localtime(now))
    with open(ACTUALPATH, 'a', encoding = 'utf-8') as f:
        f.write(f'{localtime}\t{text}\n')
        g.es(f'Wrote note to {ACTUALPATH}')


This script also lets you optionally set the location  of the log file with the @string setting notelog.
Reply all
Reply to author
Forward
0 new messages