aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2015-03-16 19:41:03 +0100
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2015-03-16 19:44:29 +0100
commit64ee41446def1605a71d49fce6461b8ff3f5c0d2 (patch)
tree78acef7be5dcd510354d61b81d2f6ca84963cbe0
parent746d7d1caf0fd0fb767a359f0eb5534ae2d8e653 (diff)
downloadsciteco-64ee41446def1605a71d49fce6461b8ff3f5c0d2.tar.gz
implemented function key masking (context-sensitive function key macros)
* fnkeys.tes has been updated to enable the command line editing macros (cursor keys, etc.) only in the "start" state. This avoids the annoying effect of inserting the macros into string arguments where they have no effect and must be rubbed out again.
-rw-r--r--README1
-rw-r--r--doc/sciteco.7.template33
-rw-r--r--lib/fnkeys.tes20
-rw-r--r--src/cmdline.cpp30
4 files changed, 78 insertions, 6 deletions
diff --git a/README b/README
index 066a589..cc8957a 100644
--- a/README
+++ b/README
@@ -50,6 +50,7 @@ Features
the command stream.
This also enables navigating with function keys (e.g. cursor keys) as demonstrated
by the standard library `fnkeys.tes`.
+ Function key macros can be context-sensitive, too.
* Many TECO-11 features, like that most commands have a colon-modified form, string-building
characters, exotic match characters
* Interactivity: supports filename completion via immediate editing commands (e.g. `<TAB>` in
diff --git a/doc/sciteco.7.template b/doc/sciteco.7.template
index 288c3dd..a9bc944 100644
--- a/doc/sciteco.7.template
+++ b/doc/sciteco.7.template
@@ -223,6 +223,39 @@ in long Q-Register names.
The names are all derived from key definitions of the curses
library \(em not all of them may be supported on any particular
user interface.
+.LP
+By default function key macros are effective everywhere \(em
+pressing a function key has the same effect as processing
+the characters of the corresponding function key macro as
+immediate editing commands (or self-inserting characters).
+However function key macros that rewrite the current command line
+will only work correctly from specific \*(ST parser states.
+\*(ST therefore allows you to mask function key macros in
+specific parser states by evaluating the Q-Register's numeric
+part, thus allowing you to control \fIwhere\fP a function key
+macro is effective.
+The numeric part represents a bitmask of states where
+function keys are \fIdisabled\fP (so the default value 0
+enables that function key everywhere).
+\*(ST defines the following state flags:
+.IP 1 4
+Bit 0 represents the \(lqstart\(rq state where \*(ST accepts the
+beginning of a command.
+This is the state you will want command line editing macros
+to be enabled in.
+.IP 2
+Bit 1 represents any string argument.
+.LP
+All other bits/flags represent any other parser state.
+Consequently, setting the register to the inverse of a bitmask of
+state flags enables the corresponding macro only for the specified
+states.
+For instance, to enable the \(lq^FRIGHT\(rq function key macro
+only in the \(lqstart\(rq state, you could set:
+.EX
+1^_U[^FRIGHT]
+.EE
+.LP
A set of useful Function Key Macros are provided in the
standard library
.BR fnkeys.tes .
diff --git a/lib/fnkeys.tes b/lib/fnkeys.tes
index 87674e8..4ad653d 100644
--- a/lib/fnkeys.tes
+++ b/lib/fnkeys.tes
@@ -10,24 +10,32 @@
"> Q.c\IC) | -Q.c\IR) '
}}
-! Make DELETE an alternative to ESCAPE !
+! Make DELETE an ESCAPE surrogate.
+ Macro is enabled everywhere. !
@[DC]{}
! Make SHIFT+DELETE a rubout/re-insert key.
- This reverses the ^G modifier for BACKSPACE !
+ This reverses the ^G modifier for BACKSPACE.
+ The macro is enabled everywhere. !
@[SDC]{}
+! Command line editing macros.
+ They are enabled only in the start state (i.e. they
+ have no effect in string arguments, etc.). !
+
@[HOME]{
.ESLINEFROMPOSITIONESPOSITIONFROMLINEU.p
Q.pU.l <Q.l-."U 1; ' Q.l-.AU.c Q.c- "N Q.c-9"N Q.lU.p 1; '' %.l>
Q.p-.M#c
}
@[HOME]{(M[HOME]}
+1U[HOME]
@[END]{
.ESLINEFROMPOSITIONESGETLINEENDPOSITION-.M#c
}
@[END]{(M[END]}
+1U[END]
@[NPAGE]{
.ESLINEFROMPOSITION+(ESLINESONSCREEN)
@@ -35,32 +43,38 @@
Q.p"< Z | Q.p '-.M#c
}
@[NPAGE]{(M[NPAGE]}
+1U[NPAGE]
@[PPAGE]{
.ESLINEFROMPOSITION-(ESLINESONSCREEN)U.l
Q.l"< 0 | Q.lESPOSITIONFROMLINE '-.M#c
}
@[PPAGE]{(M[PPAGE]}
+1U[PPAGE]
@[LEFT]{
."=0|-1'M#c
}
@[LEFT]{(M[LEFT]}
+1U[LEFT]
@[SLEFT]{
0,0,.ESWORDSTARTPOSITIONESWORDSTARTPOSITION-.M#c
}
@[SLEFT]{(M[SLEFT]}
+1U[SLEFT]
@[RIGHT]{
.-Z"=0|1'M#c
}
@[RIGHT]{(M[RIGHT]}
+1U[RIGHT]
@[SRIGHT]{
0,0,.ESWORDENDPOSITIONESWORDENDPOSITION-.M#c
}
@[SRIGHT]{(M[SRIGHT]}
+1U[SRIGHT]
@[UP]{
.ESGETCOLUMN
@@ -68,6 +82,7 @@
ESFINDCOLUMN-.M#c
}
@[UP]{(M[UP]}
+1U[UP]
@[DOWN]{
.ESGETCOLUMN
@@ -75,3 +90,4 @@
ESFINDCOLUMN-.M#c
}
@[DOWN]{(M[DOWN]}
+1U[DOWN]
diff --git a/src/cmdline.cpp b/src/cmdline.cpp
index e7ce066..90fed6e 100644
--- a/src/cmdline.cpp
+++ b/src/cmdline.cpp
@@ -499,21 +499,43 @@ Cmdline::process_edit_cmd(gchar key)
void
Cmdline::fnmacro(const gchar *name)
{
+ enum {
+ FNMACRO_MASK_START = (1 << 0),
+ FNMACRO_MASK_STRING = (1 << 1)
+ };
+
if (!(Flags::ed & Flags::ED_FNKEYS))
+ /* function key macros disabled */
return;
gchar macro_name[1 + strlen(name) + 1];
QRegister *reg;
+ tecoInt mask;
+ gchar *macro;
macro_name[0] = CTL_KEY('F');
g_strlcpy(macro_name + 1, name, sizeof(macro_name) - 1);
reg = QRegisters::globals[macro_name];
- if (reg) {
- gchar *macro = reg->get_string();
- keypress(macro);
- g_free(macro);
+ if (!reg)
+ /* macro undefined */
+ return;
+
+ mask = reg->get_integer();
+ if (States::current == &States::start) {
+ if (mask & FNMACRO_MASK_START)
+ return;
+ } else if (States::is_string()) {
+ if (mask & FNMACRO_MASK_STRING)
+ return;
+ } else if (mask & ~(tecoInt)(FNMACRO_MASK_START | FNMACRO_MASK_STRING)) {
+ /* all other bits refer to any other state */
+ return;
}
+
+ macro = reg->get_string();
+ keypress(macro);
+ g_free(macro);
}
static gchar *