summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--parser.c39
-rw-r--r--txr.119
2 files changed, 58 insertions, 0 deletions
diff --git a/parser.c b/parser.c
index 7e29cce7..221b3562 100644
--- a/parser.c
+++ b/parser.c
@@ -542,6 +542,44 @@ static void provide_completions(const char *data,
}
}
+static char *provide_atom(lino_t *l, const char *str, int n, void *ctx)
+{
+ val catch_all = list(t, nao);
+ val obj = nao;
+ val form;
+ val line = string_utf8(str);
+ char *out = 0;
+
+ (void) l;
+ (void) ctx;
+
+ uw_catch_begin (catch_all, exsym, exvals);
+
+ form = lisp_parse(line, std_null, colon_k, lit("atomcb"), colon_k);
+
+ if (atom(form)) {
+ if (n == 1)
+ obj = form;
+ } else {
+ val fform = flatcar(form);
+ obj = ref(fform, num(-n));
+ }
+
+ if (obj != nao)
+ out = utf8_dup_to(c_str(tostring(obj)));
+
+ uw_catch (exsym, exvals) {
+ (void) exsym;
+ (void) exvals;
+ }
+
+ uw_unwind;
+
+ uw_catch_end;
+
+ return out;
+}
+
static val repl_intr(val signo, val async_p)
{
uw_throw(error_s, lit("intr"));
@@ -594,6 +632,7 @@ val repl(val bindings, val in_stream, val out_stream)
reg_varl(result_hash_sym, result_hash);
lino_set_completion_cb(ls, provide_completions, 0);
+ lino_set_atom_cb(ls, provide_atom, 0);
lino_set_tempfile_suffix(ls, ".tl");
if (histfile)
diff --git a/txr.1 b/txr.1
index a7f3a643..1083ec39 100644
--- a/txr.1
+++ b/txr.1
@@ -33746,6 +33746,25 @@ Only the most recent three decimal digits are retained, so the number can range
from 0 to 999. A value of 0, or a value which exceeds the number of words
causes the Ctrl-W or w to do nothing.
+.NP* Insert Previous Atom
+
+The equivalent command sequences Ctrl-X, a and Ctrl-X, Ctrl-A insert
+an atom from the previous line at the cursor position. A line only
+makes atoms available if it expresses a valid \*(TX form, free of syntax
+errors. A line containing only whitespace or a comment makes no atoms
+available. For the purposes of this editing feature, an atom is defined
+as the printed representation of a Lisp atom taken from the Lisp form
+specified in the previous line. The line is flattened into atoms
+as if by the
+.code flatcar
+function. By default, the last atom is extracted. A numeric argument
+typed between the Ctrl-X and Ctrl-A or a can be used to select a
+atoms by position from the end. The number 1 specifies the last atom,
+2 the second last and so on.
+Only the most recent three decimal digits are retained, so the number can range
+from 0 to 999. A value of 0, or a value which exceeds the number of words
+causes the Ctrl-A or a to do nothing.
+
.NP* Symbolic Completion
If the Tab key is pressed while editing a line, it is interpreted as a