Passing current doc name as a parameter

20 views
Skip to first unread message

jula...@gmail.com

unread,
Jan 14, 2019, 7:11:34 PM1/14/19
to niceeditor
Hi,

first of all I want to thank you for creating and maintaining ne, I've used it for a couple of months now and it has become my favourite editor. 

Now to my question:
I want to pass the name of the current opened document to an executable, let's say python, but I don't want to write the name of the file or the full path to it
each time a work on my file again. Is there a way to pass the name of the current document as a parameter to the SYS command? 

i.e. SYS python $current_doc    (or something similar to this)


Thanks for your help

todd_...@unc.edu

unread,
Jan 14, 2019, 9:24:34 PM1/14/19
to niceeditor


On Monday, January 14, 2019 at 7:11:34 PM UTC-5, jula...@gmail.com wrote:
Hi,

first of all I want to thank you for creating and maintaining ne, I've used it for a couple of months now and it has become my favourite editor.

Glad you like it. Thank you for the kind words.

Now to my question:
I want to pass the name of the current opened document to an executable, let's say python, but I don't want to write the name of the file or the full path to it
each time a work on my file again. Is there a way to pass the name of the current document as a parameter to the SYS command? 

i.e. SYS python $current_doc    (or something similar to this)

There is nothing like that I'm afraid. For one thing, the current document may not have a name.

However, depending on what you're actually trying to do, you may get some inspiration from the aspell macro. It should be installed in /usr/share/ne/macros or /usr/local/share/ne/macros, depending on your build parameters or how your packager decided to build ne. I'll just copy that macro here:

# This example macro works with your system's aspell
# command to spell-check the selected block of text.
# The AtomicUndo commands at the beginning and end make
# it possible to undo/redo the entire operation in one
# go. Otherwise the Cut and Paste would each require
# their own undo/redo. Indentation is just for clarity;
# it doesn't affect operation.

AtomicUndo +
  Cut
    SaveClip ~/.ne/ne-aspell.txt
      System aspell --check ~/.ne/ne-aspell.txt
    OpenClip ~/.ne/ne-aspell.txt
    System rm -f ~/.ne/ne-aspell.txt ~/.ne/ne-aspell.txt.bak
  Paste
AtomicUndo -

By selecting a block of text (which could include the whole file), you can effectively pipe a relevant portion of your current document through an executable, then insert the resulting output back into your document. The aspell macro uses a fixed file name to store the temporary data and cleans up after itself. Note that if you always wanted to operate on the entire document you could have your macro mark the whole document for you. But then you'll end up always at the beginning of your document when the macro completes.

If you literally just want to run python on it, then make a macro that sets a bookmark, selects the whole document and does a Copy rather than a Cut, then SaveClip to, say, /tmp/mypythonpgm.py, then invoke python on that. Or perhaps invoke a script that invokes python on it so you can review the output before being popped back into ne. After the System call to your script, use GotoBookmark to restore your cursor position.

If that doesn't work for you, maybe if you describe what you wish to accomplish at a higher level, some other solution might come to mind.
--
Todd
 

jula...@gmail.com

unread,
Jan 15, 2019, 11:32:07 AM1/15/19
to niceeditor
There is nothing like that I'm afraid. For one thing, the current document may not have a name.
Yes, I only want this to work on documents that have been saved to a file.

If that doesn't work for you, maybe if you describe what you wish to accomplish at a higher level, some other solution might come to mind.

The behaviour I was trying to get is that of most IDEs when you use the 'Run/Execute this file this file' option. I know from the docs that ne's purpose isn't this but I still wondered if there was a way to implement this with some sort of 'inner' variable.

I think I can work something out with the aspell macro as a starting point. Thanks so much for your help.
Reply all
Reply to author
Forward
0 new messages