[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Nano-devel] [PATCH] interpolate functions in string binds

From: Brand Huntsman
Subject: [Nano-devel] [PATCH] interpolate functions in string binds
Date: Thu, 30 Aug 2018 05:15:05 -0600

I don't know if Marco is still working on this or if he ran into problems, so I 
took a shot at it.

The first patch simply moves shortcut handling for edit, prompt, help and 
browser to separate functions that can be called in second patch.

$$ is used to escape '$' characters that should be raw text.
One or more space-delimited functions are put inside ${}. This looks so much 
better than wrapping every function in ${}.
  ${up} calls do_up
  ${up down} calls do_up and then do_down
A ! before a function name tells the function that shift key is pressed.
  ${!left !left} selects previous two characters

The string bind will print an error and won't be created if it can't be parsed. 
This avoids creating broken binds that do the wrong thing.

All shortcuts are now checked when used to prevent using functions in menus 
that don't support them. The search prompt does not support ${up}, you must use 
${prevhistory}. If you use an invalid function, it will beep and stop 
processing the string bind. This avoids continued processing of a now broken 
bind which might do the wrong thing. If this happens in a prompt, the prompt is 
left open so you can debug where it went wrong.

String binds can call other string binds, sort of. A fragment is a string of 
keycodes or a single function. "a${up up}b" is 4 fragments. The called bind can 
be chained to the end of any bind and single fragment binds can be inserted 
anywhere into any bind.
  bind ^A "x"
  bind ^B "x${enter}"
  bind ^C "^A"
  bind ^D "^B"
  bind ^E "^A${enter}"
  bind ^F "^B${enter}"
C and D can call any string bind because the call is at the end. E can call A 
because A only contains a single fragment. F will fail because B has two 
fragments and F has an additional fragment.

Example string binds:

repeat previous search and replace
  "${replace prevhistory enter prevhistory enter}"
replace 4-spaces with 1-tab
  "${replace}    ${enter verbatim}    ${enter}"
  - the second set of 4 spaces is a tab
open prompt to execute external command
  "${insert flipexecute}"
cut to start of line
  "${enter left cut}"
cut to end of line
  "${enter cut left}"


add_to_sclist(get_history_older_void) has more menus than
add_to_funcs(get_history_older_void), which is missing MFINDINHELP and MEXTCMD. 
There are other functions missing from some menus. The patch uses the list 
created by add_to_funcs to check if function is in a menu. This causes up/down 
arrows in help-search and external-cmd prompts to beep, but they still work. 
But any string bind using ${prevhistory} in these menus will abort. Is this an 
oversight or is there a reason these functions aren't in those menus?

The help menu hides the unbound error message for modifier-less keys such as 
'a'. Is there a reason for this? When I press a key and it does nothing, should 
I assume it is unbound or just doesn't work in the current context? Anyway, 
string binds that use unbound modifier-less keys in help menu won't notify the 
user why it failed. The third patch fixes this, unless of course there is a 
reason not to.


${tab} does not work in prompts, you must use ${verbatim} following by a tab 
character. This can still cause problems copy/pasting binds, but it would be 
pretty easy to add something like $\t or $t to interpolate control characters.

I don't know how the undo code works, but would it be easily possible to force 
several actions to occupy a single undo? $[...] could be used to wrap a bunch 
of stuff in a single undo.
 "$[${enter cut left}]"

I don't know how useful it would be, but a number inside ${} could repeat the 
function after it. ${4 !right} or maybe ${!right 4} selects next 4 characters.

Attachment: 0001-move-menu-shortcut-processing-to-separate-functions.patch
Description: Text Data

Attachment: 0002-interpolate-functions-in-string-binds.patch
Description: Text Data

Attachment: 0003-show-unbound-key-error-for-all-keys-in-help.patch
Description: Text Data

reply via email to

[Prev in Thread] Current Thread [Next in Thread]