NE unable to run macro

46 views
Skip to first unread message

Aleksa Petrovic

unread,
Jun 30, 2022, 5:33:06 AM6/30/22
to niceeditor
Hi,
has anyone experienced this, sometimes NE will fail running a macro that is located in your default directory and you need to either rename it or copy it, then it will work, if it has a different name, and sometimes it will work even with the same name, after renaming. I wonder why, for example a macro is called ip and it works rarely, while the same macro named ii works all the time.

todd_...@unc.edu

unread,
Jun 30, 2022, 7:08:49 AM6/30/22
to niceeditor
I have not experienced the behavior you describe, but several things come to mind.

Are these macros under active development, or have they remained unchanged? This matters because ne caches its macros. So if you've already loaded a macro named "ip", then changing or deleting the file containing that macro will have no effect; ne will continue to use the cached version until you either run the UnloadMacros command or quit ne.

Saying a macro fails is a bit ambiguous. It could mean either that there's an issue finding and loading the macro, or that one of the commands in the macro fails which causes the macro to stop without running any more commands. In the latter case, whether a macro runs to completion depends on the context in which it is invoked. For example, if the macro contains the command "LineDown", then the macro will stop if the cursor is already at the bottom of the document.

Could you post the contents of your "ip" macro? It would help to note the document state when it "works rarely" vs "works all the time", so if you can please also provide a minimal sample document in which it fails? Be sure to note the cursor position and X,Y size of your terminal window, as these are all factors in determining whether a macro will run to completion.

I'm looking forward to understanding the behaviour you've described.

Aleksa Petrovic

unread,
Jun 30, 2022, 10:23:02 AM6/30/22
to niceeditor
The content of the macro: t sed 's|^|https://|g;s| | https://|g;s/[(,)]//g;s/\[//g;s/]//g;'
I open a file and the first line is this: https://www.minds.com/ https://104.18.17.140 https://104.18.16.140
After opening the file, I position my cursor in front of the second IP address, go to the end of the line, and run ii, it runs ii (adds additional https:// in front of the two IP addresses).
After opening the file, I position my cursor in front of the second IP address, go to the end of the line, and run ip, it says 'No such command.' If I run ii after that, it works.
I am not editing the macros, and they are both identical.

Aleksa Petrovic

unread,
Jun 30, 2022, 10:34:21 AM6/30/22
to niceeditor
I am sorry, when I said second IP address, I actually meant the first IP address.
It is also interesting that this behavior of macros happened when I had the following macro:
ClipNumber
MoveSOL
Mark
MoveEOL
Cut
I named the macro as a single letter, but it wouldn't run, so I renamed it to a different letter and it works, and now the first one works too.

todd_...@unc.edu

unread,
Jun 30, 2022, 8:52:02 PM6/30/22
to niceeditor
I've got your `ii` and `ip` macros (identical) in my `~/.ne` directory, and a file that I named "AleksaP" in my home directory. I run "ne AleksaP" and ne starts and opens the file. Then I move to column 24, which is at the "h" of the 2nd of three "https:" instances, and use ^B to Mark the block. Then MoveEOL to position my cursor just after the last "0".

At this point, invoking either macro via `^k ii <enter>` or `^k ip <enter>` has identical, apparently successful results, as the last two URLs are passed through the `sed` filters.

However, if I exit ne and enter, say, `ls -l > ip`, which creates a file named `ip` in my current (home) directory, then repeat the procedure above, then I do get the "No such command." message.

I believe what's happening here is that you have two `ip` files: one in `~/.ne` (or `~/.ne/macros`) along side your `ii` macro, and another in your current directory which contains at least one line which is not a valid ne command.

Ne first looks in your current directory for unqualified macros (i.e. ones where you don't specify a path), and if it doesn't find a match there, it then looks in `~/.ne` and finally `~/.ne/macros`. I see that last bit is not documented, so I'll fix that shortly. Testing shows that qualified macros don't seem to be loading correctly either, so even if your problem does turn out to be an errant "ip" file in your current directory, you have helped expose another apparent bug, so thanks for that.

todd_...@unc.edu

unread,
Jun 30, 2022, 9:02:22 PM6/30/22
to niceeditor
Now this is a different issue. Do you recall what letter you initially named this macro? And what single letter worked? While I don't think it's a contributing factor for this problem, I'd be curious to know if you stored this macro in your working directory, your `~/.ne` directory, or your `~/.ne/macros` directory.

My guess is the initial single letter you chose is already allocated as an abbreviation for a built-in command. For example, "c" is the short name for the Copy command. You can enter `help c` to bring up the Help page for the Copy command. Likewise, for whatever letter you initially chose, `help <that_letter>` should show you if it's a short name for a built-in command.

John Gabriele

unread,
Jun 30, 2022, 11:41:31 PM6/30/22
to niceeditor
On Thursday, June 30, 2022 at 8:52:02 PM UTC-4 todd_...@unc.edu wrote:

Ne first looks in your current directory for unqualified macros (i.e. ones where you don't specify a path), and if it doesn't find a match there, it then looks in `~/.ne` and finally `~/.ne/macros`.

Hope to not pull this off-topic, but I just created a ~/.ne/macros directory, moved one of my macros into it (new-empty-line), and tried running it, and it failed with "No such command.".

This happens if I use the key combo (^o) that I have mapped to it (in my ~/.ne/.keys I have "KEY f new-empty-line" (where f is ^o), but also happens if I type in the whole macro name with `^k new-empty-line`.

This is with with ne v3.3.1.

Also, hi Todd! :)

-- John

Aleksa Petrovic

unread,
Jul 1, 2022, 5:04:10 AM7/1/22
to niceeditor
In my home directory there is not a file named 'ip', but it still gives me the error 'No such command.' The letters were: original: v for copy-line and d for cut-line, new ones: a and g. I know to use the help command to check if there is already an abbreviated command name so that I do not use that letter. The error was the same 'No such command.', but they (v and d) work all the time now. Also, my ne home directory is ~/ne, so I changed that from the default, if this is important.

Aleksa Petrovic

unread,
Jul 1, 2022, 5:07:12 AM7/1/22
to niceeditor
The one-letter macros, I stored in my NE home directory, which is ~/ne

Aleksa Petrovic

unread,
Jul 2, 2022, 6:58:33 AM7/2/22
to niceeditor
I see that you wrote that NE has trouble running qualified macros, is this a bug that has to do with something other than a file sharing the macros name being in the current directory? I can confirm that my problem was this: I was opening the file using a script, that changes directory to one which contains a file named as the macro. I am sorry for the confusion, it took me a while to learn that this was the case. But now I need to ask, could you please give me advice of where to search, in the source code, (I tried in actions.c first) for the code that looks in the current directory for the macros? I find that since I do not use this feature, and in lots of cases it gives me trouble, I would be better off disabling it. Also, when it comes to files, I would like to ask additional question, is there an easy way that I could add another variable that points to the currently shown document, and modify the system command, making another system command that runs an external utility on the current document, then opens it again (using the full path of the file)?

todd_...@unc.edu

unread,
Jul 3, 2022, 2:52:50 AM7/3/22
to niceeditor
I'm sorry, but I misspoke rather badly before when I wrote about how macros are loaded. Let's say your have a macro stored in a file called "abcd". If you go to the command line ("^k") and type "abcd" and hit Enter, several things will happen:
  1. ne looks for a built-in command by that name. If it doesn't find one, it proceeds to...
  2. looks in its table of already loaded macros for a cached macro by that name. If it doesn't find one, it then...
  3. looks in the current directory for a file by that name. If that doesn't work, it...
  4. looks in your ~/.ne directory for a file by that name. If that also fails, it...
  5. looks in your $NE_GLOBAL_DIR/macros directory for a file by that name.
If none of that works, you get a "No such command" message.

Let's suppose that your "abcd" file is in your ~/my_macros directory. So you go to your command line ("^k") and type "~/my_macros/abcd" and hit Enter. This time, you get nothing! Not even an error! Here's what happened:
  1. ne looked at the command line, saw that the first non-blank character was not an ASCII letter, and considered it a NOP (that is, "No Operation").
To load and execute ~/my_macros/abcd the first time, you have to explicitly use the Macro command:
    ^k macro ~/my_macros/abcd <Enter>
Subsequent times - at least until you run the UnloadMacros command - you can simply type "abcd" on the command line and hit Enter as in the first scenario above. This works because ne looks up named cached macros by their names only, with no regard to their path (or case!).

You could always use the Macro command with the full path to each macro and avoid any ambiguity. This would even allow you to have macros with the same names as built-in commands. Be aware though that even then, named macros are cached and looked up by their names, and their path only matters the first time they are loaded. That remains the case until you end your ne session or you run the UnloadMacros command.*

The easiest thing to do is to put your macros in your ~/.ne directory, and make sure they don't have the same names as any built-in commands or file names you are likely to have in your current directory. If using ~/.ne is problematic, you can set your $NE_GLOBAL_DIR environment variable before starting ne. The About command shows you its current setting on the bottom line of the window.

I hope this clear up any confusion about how macros are loaded.

*It is safe to put UnloadMacros commands inside macros. If that's useful to you, I'd love to know why!

Aleksa Petrovic

unread,
Jul 3, 2022, 7:49:46 AM7/3/22
to niceeditor
Thank you for explaining, I understand now. I do not put UnloadMacros in macros. I suppose it could be useful maybe when testing macros, when editing them. But I am curious if it is possible to disable searching for macros in the current directory, could you give me some advice on how to search the source for this function?

John Gabriele

unread,
Jul 3, 2022, 11:23:35 AM7/3/22
to niceeditor
> 1. ne looks for a built-in command by that name. If it doesn't find one, it proceeds to...

After a quick test, I see that that goes for long command name or short name as well.

Thanks for the detailed explanation!

todd_...@unc.edu

unread,
Jul 3, 2022, 6:30:41 PM7/3/22
to niceeditor
That happens in the load_macro() function in src/commands.c. To keep it from looking in the current directory, change the line
char_stream * cs = load_stream(md->cs, name, false, false);
to
char_stream * cs = NULL;

For the record, I don't recommend it. But, hey, Free Software!
On Sunday, July 3, 2022 at 7:49:46 AM UTC-4 aleksa.petr...@gmail.com wrote:

todd_...@unc.edu

unread,
Jul 3, 2022, 6:36:32 PM7/3/22
to niceeditor
Take a look at the macros/aspell file. It does almost exactly what you describe. Or, it has the same effect. It may take a little study to see all the tricks it does, and it's only 8 commands!

On Saturday, July 2, 2022 at 6:58:33 AM UTC-4 aleksa.petr...@gmail.com wrote:
[...] Also, when it comes to files, I would like to ask additional question, is there an easy way that I could add another variable that points to the currently shown document, and modify the system command, making another system command that runs an external utility on the current document, then opens it again (using the full path of the file)?

Aleksa Petrovic

unread,
Jul 6, 2022, 9:07:30 AM7/6/22
to niceeditor
Hi and Happy Fourth of July! Sorry for the late congratulation. Thank you for your advice. I was searching in the code before and found out about the template for temporary files in /tmp, so I assume the Through command uses temporary files. So I guess, for running some external commands on big parts of a document, we can save the part of the document in a temporary file, and there won't be a big overhead on the resources/speed of execution? I figure not, since the Through command uses temporary files, and so I assume the Through command can be used to modify big parts of a document.

Aleksa Petrovic

unread,
Jul 6, 2022, 9:09:09 AM7/6/22
to niceeditor
Thank you for this advice, I thought it could be useful, since I have a lot of macros, and I will make more, so those that have a one-letter name and other short names could perhaps create conflicts with some directories. Why do you not recommend it though, would there be some problems if I disabled this?

todd_...@unc.edu

unread,
Jul 6, 2022, 9:57:03 AM7/6/22
to niceeditor
It's a patch that you have to carry forward, and it makes your ne behave differently from everyone else's. I think a better solution is to use long descriptive names for your macros. I often save handy one-off macros in the directories where they make sense. You preclude that possibility by taking that call out of the code.

Aleksa Petrovic

unread,
Jul 6, 2022, 11:14:18 AM7/6/22
to niceeditor
I see, thank you for the explanation. Nevertheless, thank you for the advice, I like to experiment with the source a bit.
Reply all
Reply to author
Forward
0 new messages