Importing files and folders with Leo

442 views
Skip to first unread message

Fidel N

unread,
Nov 21, 2013, 5:07:58 AM11/21/13
to leo-e...@googlegroups.com
I have just spent a couple hours trying to automatically import a folder with all its sub-folders and python files into Leo, and i couldnt.

My aim is to drop a folder into Leo (a @path node appears with the folder path) then recursively load all its files as @auto or any other filesistem that will allow me to edit them without inserting sentinels. ( since this is one of the first steps a programmer interested in leo would want to take, the default command to do this shouldnt use sentinels or edit the imported files)

I got as far as enabling (as per recent suggestions on another post) the activepath plugin, then I could recursively have a list of files, but only names, no file will be imported.

There is no command in Leo (out of the box) to recursively import a folder. There is no related command in the menu/cmds/Files and directories.
There is no guide on Leo documentation on how to do this.
I found some older post talking about a leo script within it scripts folder, but dont know how to call those from a Leo file.

So I really think it would be great to have a video on how to import-export files from/to leo, not only because I really want to use that Leo feature, but because there is no "File" tutorial yet and whenever any new user comes, the first thing he will want to do is to import his files to Leo!! I really think plugins should not be required in order to do so btw.

Sorry for the unorganized post, just wanted to share the thought, Im back to keep trying.

Fidel N

unread,
Nov 21, 2013, 5:12:09 AM11/21/13
to leo-e...@googlegroups.com
lol just after posting this, I double-clicked one of the item names,and it was loaded as an @auto file, just what i needed hehehe... (with activepath plugin loaded)

Well now most of the post loses its meaning... I talked a double-click too early.

duf...@gmail.com

unread,
Nov 21, 2013, 7:18:17 AM11/21/13
to leo-e...@googlegroups.com
When you complete your importing function, could you please write a tutorial on how to use it? A video tutorial would be nice, like Edward's tutorial. Otherwise, a text tutorial would be fine too.

Fidel N

unread,
Nov 21, 2013, 7:44:30 AM11/21/13
to leo-e...@googlegroups.com
Hey:
I gladly share what I learned today, but Im not yet qualified for a file importing/exporting tutorial on the subject hehe.

Here is what I found to be the most comfortable way to import files and folders yet:

## ACTIVATE THE PLUGIN ##

-Go to myleosettings (Help -> myleosettings) and enable the plugin "active_path.py".
To enable the plugin, you must find the node with header "@enabled-plugins", then substitute the line:
  • #active_path.py
for:
  • active_path.py
-Now restart Leo for the plugin to be in effect.

## Load your files into Leo ##

-Now, you can drop folders from file browsers (such as the one that comes with windows) and they will generate a "@path" node, pointing to those folders.
-Right-click the "@path" node you created by dropping your folder, and in the popup menu click "path" then click "load recursive". This will load all the sub-files and sub-folders under your "@path" node. You can navigate them but cant edit them yet.
-For editing any of the loaded files, just navigate to it under your "@path" node, and double-click it. It will become an @auto file containing the information your original file has.

Chris George

unread,
Nov 21, 2013, 8:47:46 AM11/21/13
to leo-e...@googlegroups.com
This was one of the very first things I needed to do on adoption of Leo. I had been "organizing" my work and flow using a file system tree and the "Sessions" function in kate. So every directory in my study tree had text files in it of assignment instructions, research notes etc. The procedure you just discovered took me about 40 minutes to figure out and no time at all to import all of my pre-existing content. I would second the motion for a video tutorial and perhaps the plugin should be activated by default.

Chris

duf...@gmail.com

unread,
Nov 21, 2013, 9:01:35 AM11/21/13
to leo-e...@googlegroups.com
Chris, if Fidel does not make that video, why don't you? ;)

Kent Tenney

unread,
Nov 21, 2013, 10:18:35 AM11/21/13
to leo-editor
I think activepath plugin is great, an ideal entry point
for examining a project.

What about a 'Import Recursive' option?

@path is great for examining code trees, 'Load Recursive' provides
access to the tree structure and file names.

'Import Recursive' would also offer the capability to
search within the files, a feature I'd really like.
> --
> You received this message because you are subscribed to the Google Groups
> "leo-editor" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to leo-editor+...@googlegroups.com.
> To post to this group, send email to leo-e...@googlegroups.com.
> Visit this group at http://groups.google.com/group/leo-editor.
> For more options, visit https://groups.google.com/groups/opt_out.

Edward K. Ream

unread,
Nov 21, 2013, 12:06:02 PM11/21/13
to leo-editor
On Thu, Nov 21, 2013 at 4:07 AM, Fidel N <fidel...@gmail.com> wrote:
I have just spent a couple hours trying to automatically import a folder with all its sub-folders and python files into Leo, and i couldnt.

​Thanks for this post, and the follow-ons.

It's important to see mistakes.  So instructive.

I'll make a screencast of this, for sure.

Edward

Edward K. Ream

unread,
Nov 21, 2013, 12:43:14 PM11/21/13
to leo-editor
On Thu, Nov 21, 2013 at 9:18 AM, Kent Tenney <kte...@gmail.com> wrote:
I think activepath plugin is great, an ideal entry point
for examining a project.

​I'll show this in the screencast, if convenient.  It's on the list.​
 

What about a 'Import Recursive' option?

​I've wanted that forever.  The problem is that there is no easy way to get the args.  That's why we are (presently) stuck with the recursive import script.

But as I write this, I see that this may be important enough to warrant it's own pane in the log window.  Just like the Find pane, but for imports.

An alternative would be something like minibuffer-find.   But given that imports are about the very first non-trivial thing a newbie is likely to want to do, an Import pane seem far better.

Thanks for this comment.  It's going to make a big difference.

Edward

Terry Brown

unread,
Nov 21, 2013, 1:06:06 PM11/21/13
to leo-e...@googlegroups.com
On Thu, 21 Nov 2013 11:43:14 -0600
"Edward K. Ream" <edre...@gmail.com> wrote:

> On Thu, Nov 21, 2013 at 9:18 AM, Kent Tenney <kte...@gmail.com> wrote:
>
> > I think activepath plugin is great, an ideal entry point
> > for examining a project.
> >
>
> I'll show this in the screencast, if convenient. It's on the list.

active_path.py is (intended to be) a complete solution to project
browsing / importing, so really it would make sense to have two
separate screencasts, if active_path.py and the recursive import script
are to be used

> > What about a 'Import Recursive' option?
>
> I've wanted that forever. The problem is that there is no easy way to get
> the args. That's why we are (presently) stuck with the recursive import
> script.

This is not a problem for active_path.py, seeing there's a one to one
mapping between the tree and the filesystem, the recursive import
should happen where it's invoked.

> But as I write this, I see that this may be important enough to warrant
> it's own pane in the log window. Just like the Find pane, but for imports.

As Kent mentioned on IRC, by using the tree to represent the file
system, and the tree context ment, active_path.py has all the interface
it needs without another panel.

It could do with some polishing, but I think it addresses this task in
a way most people will find quite intuitive.

Cheers -Terry

Kent Tenney

unread,
Nov 21, 2013, 1:15:11 PM11/21/13
to leo-editor
active_path offers a rich set of operations, I've used most
all at one time or another, Import Recursive would ice the cake.

The rclick access has the benefit of being inherently 'findable'
it's pretty universal to try an rclick, when looking for capabilities.

Fidel N

unread,
Nov 21, 2013, 1:16:29 PM11/21/13
to leo-e...@googlegroups.com
Yes, I totally agree with this comment, the only missing thing is a pointer for the newbies to know that they have to activate it then use it in order to get the files, may it be a video or an entry in the documentation teaching how to import files.

And while we are on it, I would also remind about the "export from leo" tutorial. It would be great to know/see practical ways of exporting outlines into html,  or any other useful formats. We now have a very good rst tuto,but I guess Leo can export to many more things hehe.

Cheers.

holge...@googlemail.com

unread,
Jul 19, 2015, 7:21:50 AM7/19/15
to leo-e...@googlegroups.com
Hello everybody,

I'm new to this editor and try to import my python files. I can create a @clean node (really cool feature btw) with the file name and replace the new file with my already written python program. Unfortunately this only creates a node with a lot of text. On the search for more structured import I stumbled across this thread.

I tried this on a Mac

(Leo Log Window:
Leo 5.1-final, build 20150706110823, Mon Jul  6 11:08:23 CDT 2015
Git repo info: branch = master, commit = 2ce861dd01c9
Python 2.7.9, PyQt version 4.8.6
darwin)

but after dropping a file nothing happens in the outline-pane and the log-pane tells me:

"not found: /.file/id=6571367.1791824"

Is there an easy/other way to import python code ? Should I switch systems (try it on unix?)

Greetings,

Holger

Edward K. Ream

unread,
Jul 20, 2015, 7:59:09 AM7/20/15
to leo-editor
On Sat, Jul 18, 2015 at 1:10 PM, <holge...@googlemail.com> wrote:

I'm new to this editor and try to import my python files. I can create a @clean node (really cool feature btw) with the file name and replace the new file with my already written python program. Unfortunately this only creates a node with a lot of text. On the search for more structured import I stumbled across this thread.

​For single files, use the import-file command.  This will prompt for a file, and import it to an @clean node using one of Leo's language-specific importers if possible.

For multiple files, run the following script, changing it as needed:

'''
Recursively import all python files in a directory
and clean the result.
'''
c.recursiveImport(
    dir_ = << absolute path to a directory >>
    kind = '@clean', #'@nosent','@auto','@file',
    one_file = False,
    safe_at_file = False, # True,
    theTypes = ['.py',],
)


Here is the docstring for c.recursiveImport:

'''
Recursively import all python files in a directory and clean the results.

Parameters::
dir_         The root directory or file to import.
kind         One of ('@clean','@edit','@file','@nosent').
one_file     True: import only the file given by dir_.
safe_at_file True: produce @@file nodes instead of
             @file nodes.
theTypes     A list of file extensions to import.
             None is equivalent to ['.py']
   
This method cleans imported files as follows:

- Replace backslashes with forward slashes in headlines.
- Remove empty nodes.
- Add @path directives that reduce the needed path specifiers in descendant nodes.
- Add @file to nodes or replace @file with @@file.
'''


Edward

Terry Brown

unread,
Jul 20, 2015, 10:47:36 AM7/20/15
to leo-e...@googlegroups.com
The active_path plugin lets you browse directories and import files,
once activated you can just call a node:
@path /path/to/somewhere
and double click on that to expand / import. There are also context
menu commands to recursively import whole folders. `@path .` works if
you want to start relative to the .leo file.

Really not sure what's going on with this thread, I think it started in
2013? And seems to contain answers to posts I didn't see - should try
and get to the bottom of that.

Cheers -Terry


On Mon, 20 Jul 2015 06:59:08 -0500
"Edward K. Ream" <edre...@gmail.com> wrote:

Edward K. Ream

unread,
Jul 20, 2015, 2:13:03 PM7/20/15
to leo-editor
On Mon, Jul 20, 2015 at 9:47 AM, 'Terry Brown' via leo-editor <leo-e...@googlegroups.com> wrote:
The active_path plugin lets you browse directories and import files,
once activated you can just call a node:
  @path /path/to/somewhere
and double click on that to expand / import.  There are also context
menu commands to recursively import whole folders.  `@path .` works if
you want to start relative to the .leo file.

Really not sure what's going on with this thread, I think it started in
2013?  And seems to contain answers to posts I didn't see - should try
and get to the bottom of that.

​According to my email reader, the thread started two days ago.

EKR

Terry Brown

unread,
Jul 20, 2015, 4:32:18 PM7/20/15
to leo-e...@googlegroups.com
On Mon, 20 Jul 2015 13:13:02 -0500
"Edward K. Ream" <edre...@gmail.com> wrote:

https://groups.google.com/forum/#!topic/leo-editor/wvXibDvWxVc

But, and very much OT now, it doesn't really matter when it started
(it's obviously a perennial question), I'm just wondering why I
sometimes only see responses to emails, not the original email.
In this case Holger's email resurrecting this thread, but I don't think
the resurrection is the issue, it's happened with de novo posts as well.

Cheers -Terry

Terry Brown

unread,
Jul 20, 2015, 4:50:00 PM7/20/15
to leo-e...@googlegroups.com
On Mon, 20 Jul 2015 15:32:01 -0500
"'Terry Brown' via leo-editor" <leo-e...@googlegroups.com> wrote:

> But, and very much OT now, it doesn't really matter when it started
> (it's obviously a perennial question), I'm just wondering why I
> sometimes only see responses to emails, not the original email.

Well that was a very simple and newbieish issue, when I switched from
POP to IMAP for getting mail from yahoo, I didn't set fetchmail up to
download the yahoo spam folder, from which procmail would rescue
leo-e...@googlegroups.com messages.

Cheers -Terry
Reply all
Reply to author
Forward
0 new messages