diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2015-09-17 06:31:26 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2015-09-17 06:31:26 -0700 |
commit | a5ce85ec38c7cb6e4e11e599fb9ed37c871947c1 (patch) | |
tree | 785a66a6e1c0b317c494a4f8dee0367b8a78abb4 | |
parent | 4e9ce389c2ccb3677957c7903bb633ebb503f394 (diff) | |
download | txr-a5ce85ec38c7cb6e4e11e599fb9ed37c871947c1.tar.gz txr-a5ce85ec38c7cb6e4e11e599fb9ed37c871947c1.tar.bz2 txr-a5ce85ec38c7cb6e4e11e599fb9ed37c871947c1.zip |
Listener configuration variables.
* linenoise/linenoise.c (lino_get_multiline): New function.
* linenoise/linenoise.h (lino_get_multiline): Declared.
* parser.c (listener_hist_len, listener_multi_line_p_s): New
symbol global variables.
(repl): Set linenoise history length and multi-line mode from
the *listener-hist-len* and *listener-multi-line-p* variables
on each call. Set the *listener-multi-line* variable from
the lino_t object's current state after each linenoise call.
(parse_init): Initialize new global variables and register
them as special variables.
* txr.1: Update sentence which says that history is fixed
at 100 lines. Document listener configuration variables.
-rw-r--r-- | linenoise/linenoise.c | 4 | ||||
-rw-r--r-- | linenoise/linenoise.h | 1 | ||||
-rw-r--r-- | parser.c | 12 | ||||
-rw-r--r-- | txr.1 | 46 |
4 files changed, 56 insertions, 7 deletions
diff --git a/linenoise/linenoise.c b/linenoise/linenoise.c index a8ed8ba1..cc291d38 100644 --- a/linenoise/linenoise.c +++ b/linenoise/linenoise.c @@ -128,6 +128,10 @@ void lino_set_multiline(lino_t *ls, int ml) { ls->mlmode = ml; } +int lino_get_multiline(lino_t *ls) { + return ls->mlmode; +} + static void atexit_handler(void); /* Raw mode: 1960 magic shit. */ diff --git a/linenoise/linenoise.h b/linenoise/linenoise.h index cfd03542..688ed64c 100644 --- a/linenoise/linenoise.h +++ b/linenoise/linenoise.h @@ -69,3 +69,4 @@ int lino_hist_save(lino_t *, const char *filename); int lino_hist_load(lino_t *, const char *filename); int lino_clear_screen(lino_t *); void lino_set_multiline(lino_t *, int ml); +int lino_get_multiline(lino_t *); @@ -56,6 +56,7 @@ #endif val parser_s, unique_s; +val listener_hist_len_s, listener_multi_line_p_s; static val stream_parser_hash; @@ -578,6 +579,8 @@ val repl(val bindings, val in_stream, val out_stream) char *histfile_u8 = utf8_dup_to(c_str(histfile)); val rcfile = if2(home, format(nil, lit("~a/.txr_profile"), home, nao)); val old_sig_handler = set_sig_handler(num(SIGINT), func_n2(repl_intr)); + val hist_len_var = lookup_global_var(listener_hist_len_s); + val multi_line_var = lookup_global_var(listener_multi_line_p_s); reg_varl(result_hash_sym, result_hash); @@ -598,12 +601,17 @@ val repl(val bindings, val in_stream, val out_stream) char *prompt_u8 = utf8_dup_to(c_str(prompt)); + lino_hist_set_max_len(ls, c_num(cdr(hist_len_var))); + lino_set_multiline(ls, cdr(multi_line_var) != nil); + reg_varl(counter_sym, counter); reg_varl(var_counter_sym, var_counter); line_u8 = linenoise(ls, prompt_u8); free (prompt_u8); prompt_u8 = 0; + rplacd(multi_line_var, tnil(lino_get_multiline(ls))); + if (line_u8 == 0) { switch (lino_get_error(ls)) { case lino_intr: @@ -721,9 +729,13 @@ val parser_eof(val parser) void parse_init(void) { parser_s = intern(lit("parser"), user_package); + listener_hist_len_s = intern(lit("*listener-hist-len*"), user_package); + listener_multi_line_p_s = intern(lit("*listener-multi-line-p*"), user_package); unique_s = gensym(nil); prot1(&stream_parser_hash); prot1(&unique_s); stream_parser_hash = make_hash(t, nil, nil); parser_l_init(); + reg_var(listener_hist_len_s, num_fast(500)); + reg_var(listener_multi_line_p_s, nil); } @@ -33487,11 +33487,13 @@ or a command character. .NP* History Recall -The most recent one hundred lines submitted to the interactive listener are +By default, the most recent 500 lines submitted to the interactive listener are remembered in a history. This history is available for recall, making it -convenient to repair mistakes, or compose new lines which are based on -previous lines. Note that the the history suppresses consecutive duplicate -lines. +convenient to repair mistakes, or compose new lines which are based on previous +lines. Note that the the history suppresses consecutive duplicate lines. +The number of lines retained may be customized using the +.code *listener-hist-len* +variable. If the up arrow is used while editing a line, the contents of the line are placed into a temporary save area. The line display is then updated to @@ -33627,8 +33629,12 @@ content is handled properly. (See the following section, Multi-Line Mode). .SS* Multi-Line Mode -The listener operates in one of two modes: line mode and multi-line mode. The -default operation on start-up is line mode. It is possible to toggle between +The listener operates in one of two modes: line mode and multi-line mode. +This is determined by the special variable +.code *listener-multi-line-p* +whose default value is +.code nil +(line mode). It is possible to toggle between line mode and multi-line mode using the Ctrl-J command. In line mode, all input given to a single prompt appears to be on a single @@ -33738,7 +33744,6 @@ environment variable. If this variable doesn't exist, or the user doesn't have permissions to write to this directory or to an existing history file in that directory, then the history isn't saved. - .SS* Parenthesis Matching A feature of the listener is visual parenthesis matching in the form of a @@ -33761,6 +33766,33 @@ lexical conventions and syntax of the \*(TL programming language. For instance, a closing parenthesis outside a string literal may match match an opening one inside a string literal. +.SS* Listener Configuration Variables + +The listener's behavior can be influenced through values of certain +global variables. The settings can be made persistent by means +of setting these variables in the interactive profile file. + +.coNP Special variable @ *listener-hist-len* +.desc +This special variable determines how many lines of history are +retained by the listener. Changing this variable from within the listener +has an instant effect. If the number is reduced from its current value, +history lines are immediately discarded. The default value is 500. +.code + +.coNP Special variable @ *listener-multi-line-p* +.desc +This is a boolean variable which indicates whether the listener is +in multi-line mode. The default value is +.codn nil . + +Changing this variable from within the listener takes effect +immediately for the next line of input. + +If multi-line mode is toggled interactively from within the listener, +the variable is updated to reflect the latest state. This happens +when the command is submitted for evaluation. + .SH* DEBUGGER \*(TX has a simple, crude, built-in debugger. The debugger is invoked by adding the |