leo-editor / leo-editor

Leo is an Outliner, Editor, IDE and PIM written in 100% Python.
https://leo-editor.github.io/leo-editor/
Other
1.49k stars 155 forks source link

Enhance command line option --select #842

Closed ghost closed 6 years ago

ghost commented 6 years ago

Extending the idea behind:

leo ~/already_existing_file.leo --select knownNodeName

How would I deliver a text payload to that selected node from the terminal?

ie. the current selection or an arbitrary string passed on the command line or even the current contents of the clipboard. Selectable would be best of course.

--selection, --string "This string here.", --clipboard

The ultimate, I think, would be to spawn a standalone body editor with something like leo --jot with one or none of the above text payload methods and prompt on save for leo_filename, parent node (if any), and headLine (node created if not existing), with @file ../current_directory/leo_filename.txt as a reasonable default.

Suppression of creation of or saving of the node to the Leo file should also be optional, allowing the saving of a text file directly by itself.

leo --text-only

Would this be a useful extension of the status quo? And before I get seriously started, am I missing a way to achieve this from current capabilities?

Chris

edreamleo commented 6 years ago

On Tue, Mar 27, 2018 at 10:42 PM, Chris George notifications@github.com wrote:

Extending the idea behind:

leo ~/already_existing_file.leo --select knownNodeName

How would I deliver a text payload to that selected node from the terminal?

​I don't understand why this is important. Is this supposed to be some form of interprocess communication? What's the real use case?

Edward

ghost commented 6 years ago

I often find myself needing a text editor for something while working at the command prompt.

Whether it be opening a config file for a quick edit or a handy place to paste something for further work after I am finished. I will 99 times out of 100 simply fire up kate and get it done.

Leo can open, create and manipulate text files. But sometimes it is simply too much editor for the small task at hand. The use case is to make Leo the only editor I need for all uses.

Chris

On Wed, Mar 28, 2018 at 3:33 AM, Edward K. Ream notifications@github.com wrote:

On Tue, Mar 27, 2018 at 10:42 PM, Chris George notifications@github.com wrote:

Extending the idea behind:

leo ~/already_existing_file.leo --select knownNodeName

How would I deliver a text payload to that selected node from the terminal?

​I don't understand why this is important. Is this supposed to be some form of interprocess communication? What's the real use case?

Edward

— You are receiving this because you were assigned. Reply to this email directly, view it on GitHub https://github.com/leo-editor/leo-editor/issues/842#issuecomment-376840017, or mute the thread https://github.com/notifications/unsubscribe-auth/AFikEbJ5sPrXyGLDc1TogXQDT1TjWS2pks5ti2bkgaJpZM4S9-Jn .

edreamleo commented 6 years ago

On Wed, Mar 28, 2018 at 7:49 AM, Chris George notifications@github.com wrote:

I often find myself needing a text editor for something while working at the command prompt.

Whether it be opening a config file for a quick edit or a handy place to paste something for further work after I am finished. I will 99 times out of 100 simply fire up kate and get it done.

Leo can open, create and manipulate text files. But sometimes it is simply too much editor for the small task at hand. The use case is to make Leo the only editor I need for all uses.

​Why not just keep a copy of Leo open, so you can paste text into it easily?

Edward

tbnorth commented 6 years ago

On Wed, 28 Mar 2018 05:49:34 -0700 Chris George notifications@github.com wrote:

I often find myself needing a text editor for something while working at the command prompt.

Whether it be opening a config file for a quick edit or a handy place to paste something for further work after I am finished. I will 99 times out of 100 simply fire up kate and get it done.

Leo can open, create and manipulate text files. But sometimes it is simply too much editor for the small task at hand. The use case is to make Leo the only editor I need for all uses.

There's a mechanism for loading a file in a running Leo from the command line. It would need a bit more work to have the property of hanging the command line process until the file was saved / closed, but if you don't need that it's quite straight forward.

https://github.com/leo-editor/snippets/blob/master/utils/led.sh

contacts the running Leo through the mod_http plugin. It checks for an existing copy of the file in the Leo instance, adds it if needed.

That's a bash script, we could easily make a Python version if you are in a Windows environment that doesn't have bash.

NOTE: the mod_http plugin is allows code to be executed in the running Leo by a remote process.

Cheers -Terry

Chris

On Wed, Mar 28, 2018 at 3:33 AM, Edward K. Ream notifications@github.com wrote:

On Tue, Mar 27, 2018 at 10:42 PM, Chris George notifications@github.com wrote:

Extending the idea behind:

leo ~/already_existing_file.leo --select knownNodeName

How would I deliver a text payload to that selected node from the
terminal?

​I don't understand why this is important. Is this supposed to be some form of interprocess communication? What's the real use case?

Edward

— You are receiving this because you were assigned. Reply to this email directly, view it on GitHub https://github.com/leo-editor/leo-editor/issues/842#issuecomment-376840017, or mute the thread https://github.com/notifications/unsubscribe-auth/AFikEbJ5sPrXyGLDc1TogXQDT1TjWS2pks5ti2bkgaJpZM4S9-Jn .

ghost commented 6 years ago

Heh. I just opened a new issue. I can't open any non-leo files from the command line. At first blush it appears it might be a result of your recent directory related work around themes. If so, this tells me how often current Leo users actually try to use Leo to edit text files from the command line. :-)

I also cannot figure out how to open Leo with only an untitled new file open in the editor instead of the workbook.

When I try to use Leo to create a new text file from the command line, I get unintuitive results.

From my home directory:

leo config.txt opens leo with /home/chris/leo-editor/config.txt.leo#@edit /home/chris/leo-editor/config.txt

leo ~/config.txt opens leo with /home/chris/config.txt.leo#@edit /home/chris/config.txt.

leo ~/config.txt or leo /home/chris/config.txt or leo config.txt or leo ./config.txt to attempt to reopen that file (or any non-leo file), gets this traceback:

Traceback (most recent call last): File "./launchLeo.py", line 8, in leo.core.runLeo.run() File "/home/chris/leo-editor/leo/core/runLeo.py", line 74, in run g.app.loadManager.load(fileName, pymacs) File "/home/chris/leo-editor/leo/core/leoApp.py", line 2275, in load lm.doPrePluginsInit(fileName, pymacs) File "/home/chris/leo-editor/leo/core/leoApp.py", line 2453, in doPrePluginsInit lm.readGlobalSettingsFiles() File "/home/chris/leo-editor/leo/core/leoApp.py", line 2213, in readGlobalSettingsFiles theme_path = lm.computeThemeFilePath() File "/home/chris/leo-editor/leo/core/leoApp.py", line 1829, in computeThemeFilePath theme_c = lm.openSettingsFile(path) File "/home/chris/leo-editor/leo/core/leoApp.py", line 2181, in openSettingsFile readAtFileNodesFlag=False, silent=True) File "/home/chris/leo-editor/leo/core/leoFileCommands.py", line 874, in openLeoFile silent=silent, File "/home/chris/leo-editor/leo/core/leoFileCommands.py", line 732, in getLeoFile theFile.close() AttributeError: 'NoneType' object has no attribute 'close'

A simple test from any directory that is not leo-editor:

leo test.txt (don't create, just to see the default path, should be the terminal's CWD) leo ~/test.txt (Ctrl-s to create the file) leo test.txt (should open the file just created.)

In all cases of creating a text file from the command line, an additional .leo file is created as well.

Back to my use case. At its core, I would like to be able to quickly create or open and then save a text file without saving a .leo file. This would allow me to intuitively use leo for system administration.

Automating the process of putting text into the body pane as described above would be a bonus, but likely not terribly useful for most.

ghost commented 6 years ago

I tried your script Terry.

led.sh curl: (52) Empty reply from server curl: (52) Empty reply from server led.sh --ask curl: (52) Empty reply from server led.sh use filename curl: (52) Empty reply from server curl: (52) Empty reply from server

Chris

tbnorth commented 6 years ago

On Wed, 28 Mar 2018 15:49:18 +0000 (UTC) Chris George notifications@github.com wrote:

I tried your script Terry.

led.sh curl: (52) Empty reply from server curl: (52) Empty reply from server

With the mod_http plugin enabled and Leo running already? You need the former of course - the latter could be handled by the script but isn't currently.

Cheers -Terry

led.sh --ask curl: (52) Empty reply from server led.sh use filename curl: (52) Empty reply from server curl: (52) Empty reply from server

Chris

ghost commented 6 years ago

With mod_http plugin enabled and Leo running already.

Leo 5.8 devel, build 20180327092315, Tue Mar 27 09:23:15 CDT 2018

Git repo info: branch = devel, commit = 24ce677076ef

Python 3.6.4, PyQt version 5.10.1

linux

isPython3: True

I modified your script a bit by changing curl --silent --show-error http://localhost:8130/_/exec/commanders/ | cat -n to curl --silent --show-error http://localhost:8130/ | cat -n

I received the entire html page, so I know it is mainly working.

Chris

On Wed, Mar 28, 2018 at 9:12 AM, Terry Brown notifications@github.com wrote:

On Wed, 28 Mar 2018 15:49:18 +0000 (UTC) Chris George notifications@github.com wrote:

I tried your script Terry.

led.sh curl: (52) Empty reply from server curl: (52) Empty reply from server

With the mod_http plugin enabled and Leo running already? You need the former of course - the latter could be handled by the script but isn't currently.

Cheers -Terry

led.sh --ask curl: (52) Empty reply from server led.sh use filename curl: (52) Empty reply from server curl: (52) Empty reply from server

Chris

— You are receiving this because you were assigned. Reply to this email directly, view it on GitHub https://github.com/leo-editor/leo-editor/issues/842#issuecomment-376944505, or mute the thread https://github.com/notifications/unsubscribe-auth/AFikEWTgJwWjNjgK8hkNv6CGv0kvyChBks5ti7ZhgaJpZM4S9-Jn .

tbnorth commented 6 years ago

On Wed, 28 Mar 2018 09:30:31 -0700 Chris George notifications@github.com wrote:

With mod_http plugin enabled and Leo running already.

And of course

led.sh [--ask]

I don't know what it would do without :)

Cheers -Terry

Leo 5.8 devel, build 20180327092315, Tue Mar 27 09:23:15 CDT 2018

Git repo info: branch = devel, commit = 24ce677076ef

Python 3.6.4, PyQt version 5.10.1

linux

isPython3: True

I modified your script a bit by changing curl --silent --show-error http://localhost:8130/_/exec/commanders/ | cat -n to curl --silent --show-error http://localhost:8130/ | cat -n

I received the entire html page, so I know it is mainly working.

Chris

On Wed, Mar 28, 2018 at 9:12 AM, Terry Brown notifications@github.com wrote:

On Wed, 28 Mar 2018 15:49:18 +0000 (UTC) Chris George notifications@github.com wrote:

I tried your script Terry.

led.sh curl: (52) Empty reply from server curl: (52) Empty reply from server

With the mod_http plugin enabled and Leo running already? You need the former of course - the latter could be handled by the script but isn't currently.

Cheers -Terry

led.sh --ask curl: (52) Empty reply from server led.sh use filename curl: (52) Empty reply from server curl: (52) Empty reply from server

Chris

— You are receiving this because you were assigned. Reply to this email directly, view it on GitHub https://github.com/leo-editor/leo-editor/issues/842#issuecomment-376944505, or mute the thread https://github.com/notifications/unsubscribe-auth/AFikEWTgJwWjNjgK8hkNv6CGv0kvyChBks5ti7ZhgaJpZM4S9-Jn .

ghost commented 6 years ago

led.sh --ask config.txt curl: (52) Empty reply from server

Select outline:

If I give it the full name of an open Leo file including the .leo I get:

Select outline: Meta.leo /home/chris/led.sh: line 10: Meta.leo: syntax error: invalid arithmetic operator (error token is ".leo") curl: (52) Empty reply from server curl: (52) Empty reply from server

If I pass only the filename with no .leo I get:

Select outline: Meta curl: (52) Empty reply from server curl: (52) Empty reply from server

Chris

On Wed, Mar 28, 2018 at 9:40 AM, Terry Brown notifications@github.com wrote:

On Wed, 28 Mar 2018 09:30:31 -0700 Chris George notifications@github.com wrote:

With mod_http plugin enabled and Leo running already.

And of course

led.sh [--ask]

I don't know what it would do without :)

Cheers -Terry

Leo 5.8 devel, build 20180327092315, Tue Mar 27 09:23:15 CDT 2018

Git repo info: branch = devel, commit = 24ce677076ef

Python 3.6.4, PyQt version 5.10.1

linux

isPython3: True

I modified your script a bit by changing curl --silent --show-error http://localhost:8130/_/exec/commanders/ | cat -n to curl --silent --show-error http://localhost:8130/ | cat -n

I received the entire html page, so I know it is mainly working.

Chris

On Wed, Mar 28, 2018 at 9:12 AM, Terry Brown notifications@github.com wrote:

On Wed, 28 Mar 2018 15:49:18 +0000 (UTC) Chris George notifications@github.com wrote:

I tried your script Terry.

led.sh curl: (52) Empty reply from server curl: (52) Empty reply from server

With the mod_http plugin enabled and Leo running already? You need the former of course - the latter could be handled by the script but isn't currently.

Cheers -Terry

led.sh --ask curl: (52) Empty reply from server led.sh use filename curl: (52) Empty reply from server curl: (52) Empty reply from server

Chris

— You are receiving this because you were assigned. Reply to this email directly, view it on GitHub https://github.com/leo-editor/leo-editor/issues/842# issuecomment-376944505, or mute the thread https://github.com/notifications/unsubscribe-auth/ AFikEWTgJwWjNjgK8hkNv6CGv0kvyChBks5ti7ZhgaJpZM4S9-Jn .

— You are receiving this because you were assigned. Reply to this email directly, view it on GitHub https://github.com/leo-editor/leo-editor/issues/842#issuecomment-376953448, or mute the thread https://github.com/notifications/unsubscribe-auth/AFikEQBUswXdZeI58lLQ_JQfes_i5rQjks5ti7z-gaJpZM4S9-Jn .

tbnorth commented 6 years ago

On Wed, 28 Mar 2018 09:53:12 -0700 Chris George notifications@github.com wrote:

led.sh --ask config.txt curl: (52) Empty reply from server

Ah, sorry, looks like you need:

@bool http_allow_remote_exec = True

so it's not quite the gaping security hole I thought, at least until you do that :-)

Cheers -Terry

Select outline:

If I give it the full name of an open Leo file including the .leo I get:

Select outline: Meta.leo /home/chris/led.sh: line 10: Meta.leo: syntax error: invalid arithmetic operator (error token is ".leo") curl: (52) Empty reply from server curl: (52) Empty reply from server

If I pass only the filename with no .leo I get:

Select outline: Meta curl: (52) Empty reply from server curl: (52) Empty reply from server

Chris

On Wed, Mar 28, 2018 at 9:40 AM, Terry Brown notifications@github.com wrote:

On Wed, 28 Mar 2018 09:30:31 -0700 Chris George notifications@github.com wrote:

With mod_http plugin enabled and Leo running already.

And of course

led.sh [--ask]

I don't know what it would do without :)

Cheers -Terry

Leo 5.8 devel, build 20180327092315, Tue Mar 27 09:23:15 CDT 2018

Git repo info: branch = devel, commit = 24ce677076ef

Python 3.6.4, PyQt version 5.10.1

linux

isPython3: True

I modified your script a bit by changing curl --silent --show-error http://localhost:8130/_/exec/commanders/ | cat -n to curl --silent --show-error http://localhost:8130/ | cat -n

I received the entire html page, so I know it is mainly working.

Chris

On Wed, Mar 28, 2018 at 9:12 AM, Terry Brown notifications@github.com wrote:

On Wed, 28 Mar 2018 15:49:18 +0000 (UTC) Chris George notifications@github.com wrote:

I tried your script Terry.

led.sh curl: (52) Empty reply from server curl: (52) Empty reply from server

With the mod_http plugin enabled and Leo running already? You need the former of course - the latter could be handled by the script but isn't currently.

Cheers -Terry

led.sh --ask curl: (52) Empty reply from server led.sh use filename curl: (52) Empty reply from server curl: (52) Empty reply from server

Chris

— You are receiving this because you were assigned. Reply to this email directly, view it on GitHub <https://github.com/leo-editor/leo-editor/issues/842#
issuecomment-376944505>,
or mute the thread <https://github.com/notifications/unsubscribe-auth/
AFikEWTgJwWjNjgK8hkNv6CGv0kvyChBks5ti7ZhgaJpZM4S9-Jn>
.

— You are receiving this because you were assigned. Reply to this email directly, view it on GitHub https://github.com/leo-editor/leo-editor/issues/842#issuecomment-376953448, or mute the thread https://github.com/notifications/unsubscribe-auth/AFikEQBUswXdZeI58lLQ_JQfes_i5rQjks5ti7z-gaJpZM4S9-Jn .

ghost commented 6 years ago

With @bool http_allow_remote_exec = True

led.sh --ask config.txt 1 /home/chris/Dropbox/LeoFiles/Meta.leo 2 /home/chris/Dropbox/LeoFiles/re:Fiction.leo Select outline: 1 curl: (52) Empty reply from server curl: (52) Empty reply from server

Chris

tbnorth commented 6 years ago

On Wed, 28 Mar 2018 10:14:16 -0700 Chris George notifications@github.com wrote:

With @bool http_allow_remote_exec = True

led.sh --ask config.txt 1 /home/chris/Dropbox/LeoFiles/Meta.leo 2 /home/chris/Dropbox/LeoFiles/re:Fiction.leo Select outline: 1 curl: (52) Empty reply from server curl: (52) Empty reply from server

Did it load anything in Leo? Should have created a top level 'Edits' node with @auto /some/path/config.txt under it. Might not have made any effort to bring Leo to front etc. Those curl messages might be spurious.

Cheers -Terry

ghost commented 6 years ago

I opened an empty leo. I ran the utility.

led.sh --ask config.txt 1 /home/chris/.leo/workbook.leo Select outline: 1 curl: (52) Empty reply from server curl: (52) Empty reply from server

This is all that appeared in Leo's log and it appeared only once.

127.0.0.1 - - [28/Mar/2018 11:36:41] "GET /_/exec/commanders/ HTTP/1.1" 200

Chris

On Wed, Mar 28, 2018 at 11:27 AM, Terry Brown notifications@github.com wrote:

On Wed, 28 Mar 2018 10:14:16 -0700 Chris George notifications@github.com wrote:

With @bool http_allow_remote_exec = True

led.sh --ask config.txt 1 /home/chris/Dropbox/LeoFiles/Meta.leo 2 /home/chris/Dropbox/LeoFiles/re:Fiction.leo Select outline: 1 curl: (52) Empty reply from server curl: (52) Empty reply from server

Did it load anything in Leo? Should have created a top level 'Edits' node with @auto /some/path/config.txt under it. Might not have made any effort to bring Leo to front etc. Those curl messages might be spurious.

Cheers -Terry

— You are receiving this because you were assigned. Reply to this email directly, view it on GitHub https://github.com/leo-editor/leo-editor/issues/842#issuecomment-376988452, or mute the thread https://github.com/notifications/unsubscribe-auth/AFikEeRklSJLnjXPnNbG0m0Il4SNYHsiks5ti9YRgaJpZM4S9-Jn .

tbnorth commented 6 years ago

On Wed, 28 Mar 2018 18:39:21 +0000 (UTC) Chris George notifications@github.com wrote:

I opened an empty leo. I ran the utility.

You're probably getting sick of trying things, but I'd try it with a .leo file that's been saved first, if that wasn't the case for your "empty" Leo.

Other than that, I'm not sure - I diffed it against the version I use and didn't see any difference, and it is working for me.

Cheers -Terry

led.sh --ask config.txt 1 /home/chris/.leo/workbook.leo Select outline: 1 curl: (52) Empty reply from server curl: (52) Empty reply from server

This is all that appeared in Leo's log and it appeared only once.

127.0.0.1 - - [28/Mar/2018 11:36:41] "GET /_/exec/commanders/ HTTP/1.1" 200 -

Chris

On Wed, Mar 28, 2018 at 11:27 AM, Terry Brown notifications@github.com wrote:

On Wed, 28 Mar 2018 10:14:16 -0700 Chris George notifications@github.com wrote:

With @bool http_allow_remote_exec = True

led.sh --ask config.txt 1 /home/chris/Dropbox/LeoFiles/Meta.leo 2 /home/chris/Dropbox/LeoFiles/re:Fiction.leo Select outline: 1 curl: (52) Empty reply from server curl: (52) Empty reply from server

Did it load anything in Leo? Should have created a top level 'Edits' node with @auto /some/path/config.txt under it. Might not have made any effort to bring Leo to front etc. Those curl messages might be spurious.

Cheers -Terry

— You are receiving this because you were assigned. Reply to this email directly, view it on GitHub https://github.com/leo-editor/leo-editor/issues/842#issuecomment-376988452, or mute the thread https://github.com/notifications/unsubscribe-auth/AFikEeRklSJLnjXPnNbG0m0Il4SNYHsiks5ti9YRgaJpZM4S9-Jn .

ghost commented 6 years ago

Tried with an existing Leo file. Same result.

led.sh --ask config.txt 1 /home/chris/catch.leo Select outline: 1 curl: (52) Empty reply from server curl: (52) Empty reply from server

My installed curl 7.59.0 (x86_64-pc-linux-gnu).

Chris

ghost commented 6 years ago

I am going to close this. I am glad it led to finding a bit of a bug and the possibility of pushing into Leo via the mod_http plugin.

I have solved my problem by using the right tool for the job:

https://wiki.wxpython.org/WxHowtoSmallEditor

104 lines of code. Perfect for my use case.

edreamleo commented 6 years ago

On Wed, Mar 28, 2018 at 7:03 PM, Chris George notifications@github.com wrote:

I am going to close this. I am glad it led to finding a bit of a bug and the possibility of pushing into Leo via the mod_http plugin.

I have solved my problem by using the right tool for the job:

https://wiki.wxpython.org/WxHowtoSmallEditor

104 lines of code. Perfect for my use case.

​Glad to hear it.

Edward