[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Nano-devel] [PATCH] possible new feature: allow binding a key to a
From: |
Brand Huntsman |
Subject: |
Re: [Nano-devel] [PATCH] possible new feature: allow binding a key to a string |
Date: |
Thu, 1 Feb 2018 17:34:43 -0700 |
On Thu, 1 Feb 2018 17:41:49 -0300
Marco Diego Aurélio Mesquita <address@hidden> wrote:
> > This fulfills https://savannah.gnu.org/bugs/?52931.
> >
> > [ If you would like to see this feature get included, say
> > "Yeah!". ]
I've been using the previous patch since 2.9.3 with the spaces2tabs macro, so
yeah, I want it.
> Second, this feature is very very similar to pre-recorded macros. Now,
> suppose I create a macro to select the char under the cursor and
> perform a search. Now, suppose that some days later I change some of
> my keybidings. The result: the pre-recorded macro no longer works.
> Every keybinding change would force me to review or update all my
> macros. But... I've been thinking on a solution for this problem: a
> command prompt for nano; just like in "ne". In "ne", by pressing "ESC
> :" I get a prompt where I can type commands that "ne" can directly
> execute. So, what I propose is that a command prompt should be
> implemented in nano (just like ne's one) and the keybiding to invoke
> this should be unrebindable. This way we could have macros that do not
> depend on the way keys are bound.
Changing bindings would be an issue but highly unlikely. One problem with these
key bind macros is that they are a little hard to read, need M-V to write, and
can't be copy/pasted to another computer. They could use a sigil to write out
readable function names.
bind M-1 "^[r ^M^[v ^M" main
bind M-1 "${replace} ${enter}${verbatim_input}${tab}${enter}" main
Quite a bit easier to read and copy/paste, and no unrebindable prompt is
needed. But you need to know the function names to do this, which anyone
binding keys would already need to know. The prompt would be nice if you knew a
function name but not which key it was bound to, but that is a separate feature
request.
> First, I'd like to have something like abbreviations in nano. By
> abbreviation I mean "type a few chars and it gets replaced by
> something else". Like been able to type "\for" and a macro is played
> that replaces it by "for ( ;;)" and conveniently positions the cursor.
> The feature in the patch would then just became a single keystroke
> abbreviation.
I don't want nano to interpolate anything I type in the buffer. If nano had a
better understanding of syntaxes then maybe syntax keywords could trigger
macros in the syntax definition to do this. For now, something like
autocomplete could be used to dispatch previous word macros.
macro for "for (;;) {}" 5
You type "for", press some macro-autocomplete key binding, it replaces the
"for" with the text, and moves cursor 5 characters from start of text. A
negative number would move cursor from end of text. This feature could have a
global list in nanorc but also per-syntax lists.
Semi-related: Assume nano can do this
https://savannah.gnu.org/bugs/index.php?53041. And there was an execute
function for bind macros, "${execute my-program}". You could have an external
program process any selection. The macro could even select the previous word
before executing command. And could be enhanced to look for a sequence at start
of command output that contains a cursor movement value. Not quite the same as
the above macro-for example, but similar. But would be global, not per-syntax.