aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/parser.cpp
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2014-11-22 18:04:35 +0100
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2014-11-22 18:04:35 +0100
commita37daa872ce648f201d26d0d6c3deff2bb54c354 (patch)
tree27da592fca1443ecc1237c9e2f5f5a1b6fb56721 /src/parser.cpp
parent427c9d16ce7e62cbe2671748cd8434132ce60482 (diff)
downloadsciteco-a37daa872ce648f201d26d0d6c3deff2bb54c354.tar.gz
added EJ command: return runtime properties
* main motivation is to have a way of getting the number of buffers in the ring. "EJ" or "1EJ" will do that. This simplifies macros that will have to iterate all the buffers. They no longer have to close the existing buffers to do that. * "0EJ" will get the current user interface. This is useful to select a different color scheme in the startup profile depending on the UI, for instance.
Diffstat (limited to 'src/parser.cpp')
-rw-r--r--src/parser.cpp57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/parser.cpp b/src/parser.cpp
index 6995a6b..66b46c4 100644
--- a/src/parser.cpp
+++ b/src/parser.cpp
@@ -1890,6 +1890,63 @@ StateECommand::custom(gchar chr)
break;
/*$
+ * [key]EJ -> value -- Get and set system properties
+ * -EJ -> value
+ * value,keyEJ
+ *
+ * This command may be used to get and set system
+ * properties.
+ * With one argument, it retrieves a numeric property
+ * identified by \fIkey\fP.
+ * If \fIkey\fP is omitted, the prefix sign is implied
+ * (1 or -1).
+ * With two arguments, it sets property \fIkey\fP to
+ * \fIvalue\fP and returns nothing. Currently, there
+ * are no properties that can be set.
+ *
+ * The following property keys are defined:
+ * .IP 0 4
+ * The current user interface: 1 for Curses, 2 for GTK
+ * .IP 1
+ * The current numbfer of buffers: Also the numeric id
+ * of the last buffer in the ring. This is implied if
+ * no argument is given, so \(lqEJ\(rq returns the number
+ * of buffers in the ring.
+ */
+ case 'J': {
+ BEGIN_EXEC(&States::start);
+
+ tecoInt property;
+
+ expressions.eval();
+ property = expressions.pop_num_calc();
+ if (expressions.args() > 0)
+ throw Error("Cannot set property %" TECO_INTEGER_FORMAT
+ " for <EJ>", property);
+
+ switch (property) {
+ case 0: /* user interface */
+#ifdef INTERFACE_CURSES
+ expressions.push(1);
+#elif defined(INTERFACE_GTK)
+ expressions.push(2);
+#else
+#error Missing value for current interface!
+#endif
+ break;
+
+ case 1: /* number of buffers */
+ expressions.push(ring.get_id(ring.last()));
+ break;
+
+ default:
+ throw Error("Invalid property %" TECO_INTEGER_FORMAT
+ " for <EJ>", property);
+ }
+ break;
+ }
+
+ /*$
* [bool]EX -- Exit program
* -EX
*