summaryrefslogtreecommitdiffstats
Commit message (Collapse)AuthorAgeFilesLines
* linenoise: fix broken move-to-end on Enter.Kaz Kylheku2015-09-251-18/+26
| | | | | | | | | | | | | | | | | | | | | The switch to Ctr-A/Ctrl-E within a logical line breaks when the edit_move_end function is relied upon to go to the end of the buffer. * linenoise/linenoise.c (edit_move_home): Restored to original behavior. (edit_move_sol): New static function that hosts new behavior of edit_move_home: calls edit_move_home in single-line mode, or implements move within logical line in multi-line mode. (edit_move_end): Restored to original behavior. (edit_move_eol): New static function that hosts new behavior of edit_move_end: calls edit_move_end in single-line mode, or implements move within logical line in multi-line mode. (edit): Call edit_move_sol instead of edit_move_home, and in editing functions onyl, call edit_move_eol instead of edit_move_end.
* return and return-from must throw, not abort.Kaz Kylheku2015-09-251-0/+3
| | | | | | * eval.c (op_return, op_return_from): If uw_block_return doesn't find a block, and just returns, then throw an exception rather than aborting.
* Fix two bugs in ifa macro.Kaz Kylheku2015-09-251-3/+3
| | | | | | | | | | * share/txr/stdlib/ifa.tl (ifa): Misplaced parentheses in mapcar call were causing the lists of before and after temporary variables to come up empty, resulting in a misexpansion (in the case when the it-argument is a place). Also, before and after temporaries swapped in the expansion: afters were inserted before the it-argument and vice-versa.
* Add copyright headers to some lib modules.Kaz Kylheku2015-09-254-0/+100
| | | | | | | | | | * share/txr/stlib/path-test.tl: Added header. * share/txr/stlib/struct.tl: Likewise. * share/txr/stlib/txr-case.tl: Likewise. * share/txr/stlib/with-resources.tl: Likewise.
* linemode: multi-line behavior for Ctrl-A/Ctrl-E.Kaz Kylheku2015-09-252-6/+34
| | | | | | | | * linemode/linemode.c (edit_move_home, edit_move_end): Check for multi-line mode and implement movement within the physical line. * txr.1: Documented.
* linenoise: delete previous word fix for multi-line.Kaz Kylheku2015-09-251-4/+3
| | | | | | | | * linenoise/linenoise.c (SPACE): Preprocessor symbol removed; was only referenced in the edit_delete_prev_word function. (edit_delete_prev_word): Recognize carriage return as word-separating whitespace.
* linenoise: fix multi-line issues with long linesKaz Kylheku2015-09-251-34/+44
| | | | | | | | | | | * linenoise/linenoise.c (screen_rows): Restructured. Calculates correct cursor rows (out.rows[1]). It's now possible that the reported cursor row exceeds the number of rows (out.rows[0]), because the cursor is on the last line, which itself doesn't wrap, but the cursor does. (refresh_multiline): Cursor wrapping calculation is simple now: just check that nrow > rows. Coalesced code for dealing with cursor position.
* regex: major optimization for complement operator.Kaz Kylheku2015-09-241-1/+46
| | | | | | | | | | | This change a huge improvement for expressions that use complement, directly or via the non-greedy % operator. * regex.c (reg_matches_all): New static function. (reg_derivative): When the dervative is applied to a complement expression, identify situations when the remaining expression cannot possibly match anything, and convert them to the t expression.
* Version 117.txr-117Kaz Kylheku2015-09-236-254/+303
| | | | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Likewise. * txr.vim, tl.vim: Regenerated.
* linenoise: wrong snprintf argument.Kaz Kylheku2015-09-231-1/+1
| | | | | * linenoise/linenoise.c (refresh_multiline): Fix size_t being passed to %d conversion specifier in snprintf call.
* Fix race in ~/.txr_profile security check.Kaz Kylheku2015-09-231-8/+8
| | | | | | | | * parser.c (load_rcfile): Apply the privacy test to the open stream, rather than the file name, thus guarding against the possibility that a verified file object is replaced by another one before it is opened.
* statf becomes external.Kaz Kylheku2015-09-232-2/+3
| | | | | | | | * sysif.c (statf): Linkage changed to external. Also, fixed wrong name being passed down to stat_impl. * sysif.h (statf): Declaration updated.
* doc: note another race in path-private-to-me-pKaz Kylheku2015-09-231-1/+13
| | | | | | * txr.1: document a TOCTTOU race condition in uses of path-private-to-me-p and how to get around it.
* doc: stat functions return structure.Kaz Kylheku2015-09-231-1/+1
| | | | | | * txr.1: Under Unix Filesystem Object Existence, Type and Access Tests, fix text which implies that the stat functions return a list.
* linenoise: correct tab alignment in multi-line mode.Kaz Kylheku2015-09-231-4/+9
| | | | | | | * linenoise/linenoise.c (sync_data_to_buf): Maintain a colum variable which is reset when a new line is put out and takes into account the prompt length; use this for tabs.
* lack of optional arg defaulting in lazy_sub_str.Kaz Kylheku2015-09-231-2/+2
| | | | | | * lib.c (lazy_sub_str): Check from and to args correctly using null_or_missing_p instead of comparing to nil.
* repl: give details about source of error exception.Kaz Kylheku2015-09-231-0/+10
| | | | | * parser.c (repl): Print location info for exception based on last_form_evaled and last_form_expanded.
* Bugfix: sub function not handling lazy strings.Kaz Kylheku2015-09-221-0/+1
| | | | | | | This bug means that range indexing doesn't work on lazy strings. Ouch! * lib.c (sub): Added missing LSTR switch case.
* linenoise: C++ fixes, including g++ warnings.Kaz Kylheku2015-09-221-10/+10
| | | | | | | | * linenoise/linenoise.c (history_search, sync_data_to_buf, screen_rows, paren_jump, edit_move_matching_paren): Fix signed/unsigned warnings. (edit_in_editor): Avoid using template as a variable name. Use const char * for string literal.
* C++ upkeep: cannot assign to volatile sigset_t.Kaz Kylheku2015-09-221-1/+11
| | | | | | | | | | | | | | | | This is a hack for an ugly problem. A plain old struct is actually a class in C++, and assignment to a struct goes thorugh a generated assignment operator. Unfortunately, C++ doesn't generate an assignment operator for volatile destinations, so assignment to a volatile-qualified struct object is erroneous. * signal.h (copy_sigset): New inline function to copy a sigset_t, even if the left hand side is volatile. This works by stripping the qualifier. (sig_save_enable): Use the function.
* Introduce chk_wmalloc function.Kaz Kylheku2015-09-224-11/+20
| | | | | | | | | | | | | | | Two-fold benefit. Simplifies code which allocates wchar_t arrays. Provides overflow check for the multiplication. * lib.c (chk_wmalloc): New function. (chk_strdup, mkstring, mkustring, upcase_str, downcase_str, sub_str, cat_str, trim_str): Use chk_wmalloc. * lib.h (chk_wmalloc): Declared. * stream.c (make_string_output_stream): Use chk_wmalloc. * utf8.c (utf8_dup_from_uc, utf8_dup_from): Likewise.
* linenoise: forward paren jump too.Kaz Kylheku2015-09-222-2/+14
| | | | | | | | * linenoise/linenoise.c (paren_jump): Scan forward also, if reverse scan turns up nothing, thereby jumping to a closing parenthesis in the forward direction. * txr.1: Documentation updated.
* linenoise: selection endpoint toggle with Ctrl-^.Kaz Kylheku2015-09-222-0/+17
| | | | | | * linenoise/linenoise.c (edit): Implemented. * txr.1: Documented.
* linenoise: jump to matching parenthesisKaz Kylheku2015-09-222-0/+74
| | | | | | | | | * linenoise/linenoise.c (scan_match_fwd, scan_fwd, edit_move_matching_paren): New functions. (edit): New Ctrl-] command implemented using edit_move_matching_paren. * txr.1: Documented.
* linenoise: new Ctrl-X Ctrl-K command to delete line.Kaz Kylheku2015-09-212-0/+38
| | | | | | | | | * linenoise/linenoise.c (edit_delete_line): New static function. (edit): New Ctrl-K extended command case implemented using edit_delete_line. * txr.1: Documented.
* linenoise: multi-line behavior for del to bol/eol.Kaz Kylheku2015-09-212-15/+60
| | | | | | | | | | | | | * linenoise/linenoise.c (edit_delete_prev_all): In multi-line mode, delete only to beginning of physical line, not the entire logical line. Also, detect noop cases and don't do record undo or produce any effect. (edit_delete_to_eol): New function. (edit): Use edit_delete_to_eol function for Ctrl-K instead of inline code. * txr.1: Documented.
* linenoise: squelch some useless undo items.Kaz Kylheku2015-09-211-5/+24
| | | | | | | | | | | | | | | | | | | | | Sometimes edits don't do anything, and so the undo item recorded for them is superfluous. When undo is used nothing appears to happen for a turn. We use two strategies: detect the noop change and avoid recording the undo (or doing anything), or else detecting the noop undo afterward and removing it from the undo stack. * linenoise/linenoise.c (remove_noop_undo): New static function. (edit_delete, edit_backspace): Remove noop undo. (edit_delete_prev_word): Don't record undo, move memory or update vars if there is no word to delete. (edit_in_editor): Remove noop undo. (edit): For Ctrl-T, don't record undo or do anything other than clear the selection if the cursor is leftmost already.
* linenoise: do not undo to empty lineKaz Kylheku2015-09-211-9/+14
| | | | | | * linenoise/linenoise.c (restore_undo): If an undo item wants to produce a completely blank line, then discard and skip it.
* linenoise: much more sane, per-history-item undo.Kaz Kylheku2015-09-212-76/+88
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Undo now works intuitively. It does not perform invisible jumps among history items, restoring instead just the history for the given line being edited. * linenoise/linenoise.c (LINENOISE_MAX_UNDO): Raised from 32 to a more generous 200. Since edits are per-history line, it makes sense to allow a lot more. (delete_undo): New static function. (free_undo): Static function removed to free_undo_stack. Trivial loop around delete_undo. (record_undo): Do not record the current history index; all edits are assigned the index INT_MAX. INT_MAX is an indicator that the edits do not have an assigned history line. The decision of where to assign them depends on whether history navigation is used to move to another history line or Enter is used to submit an edited line. A stinky part of the history trimming code is rewritten simply in terms of delete_undo. (record_triv_undo): Suppress a trivial item only if the top item belongs to the same history line, or is nonspecific (INT_MAX). (undo_pop): Static function removed. (restore_undo): Rewritten to look for the topmost item specific to the current history line or an INT_MAX nonspecific item. Removes undo items for expired lines as it goes. (undo_subst_hist_idx): New static function. (renumber_undo_hist): Renamed to undo_renumber_hist_idx. (edit_history_next): Do not record an undo; history navigation is no longer considered an edit. Rewrite all the INT_MAX entries in the undo stack with the current history index, permanently associating the undo items with the history line away from which we are navigating. (edit): Do not record an undo for a line terminating with Enter. It is not an edit action. When leaving the funtion, renumber any INT_MAX entries in the undo history to history index zero. Thus edits to any line which is submitted via Enter will (correctly) not be associated with that line, which was not in fact edited, but with the new line that was submitted. (lino_cleanup): Follow rename of free_undo. (lino_hist_add): Follow rename of undo_renumber_hist_idx. * txr.1: Documented.
* linenoise: renumber history indices in undo itemsKaz Kylheku2015-09-201-5/+27
| | | | | | | | | | | | | | | This has to be done because each time a history line is added, or taken back, the relative numbers change. * linenoise/linenoise.c (undo_pop): New static function. (restore_undo): Skip undo items which refer to lines of history which no longer exist. Restore history[0] also. (renumber_undo_hist): New static function. (edit): When leaving, and removing the extra history line representing the current line, renumber the undo items by -1. (lino_hist_add): After adding a line, bump the undo item history indices by 1.
* linenoise: single return out of edit.Kaz Kylheku2015-09-201-27/+27
| | | | | | | | * linenoise/linenoise.c (edit): Changing most returns to goto out. We have common clean-up to do, namely removing the last history item which represents the current line. This fixes a bug: not removing the history line in the Ctrl-C case.
* linenoise: move to end in mlmode on Ctrl-C, Ctrl-Z.Kaz Kylheku2015-09-201-4/+17
| | | | | | | | | | If we don't move the cursor to the end, then the shell prompt (Ctrl-Z) or next REPL prompt (Ctrl-C) comes in the middle of the previous input. * linenoise/linenoise.c (edit): in multi-line mode, move to end of input on Ctrl-C. On Ctrl-Z suspend, do the same, but save and restore the position.
* linenoise: undo feature.Kaz Kylheku2015-09-202-0/+151
| | | | | | | | | | | | | | | | | | | | | * linenoise/linenoise.c (LINENOISE_MAX_UNDO): New preprocessor symbol. (struct lino_state): New member, undo_stack. (struct lino_undo): New struct type. (free_undo, record_undo, record_triv_undo, restore_undo): New static functions. (edit_insert): Record trivial undo item with record_triv_undo. (edit_insert_str, edit_history_next, edit_delete, edit_backspace, edit_delete_prev_all, edit_delete_prev_word, edit_in_editor): Record undo item. (edit): Record undo item before Ctrl-R history recall and Ctrl-T twiddle. Also record one final undo item upon Enter, as well as Ctrl-C. New Ctrl-O command to undo. (lino_copy): Do not copy undo_stack, to prevent double freeing. (lino_free): Free the undo history. * txr.1: Documented.
* linenoise: visual select and clipboard copy/paste.Kaz Kylheku2015-09-202-38/+333
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * linenoise/linenoise.c (struc lino_state): New member, clip, sel, end, dsel, dend, need_refresh, selmode. (sync_data_to_buf): Update the sel and end members of the structure based on dsel and dend, the way pos is being updated from dpos. (refresh_singleline, refresh_multiline): If visual selection mode is in effect, show the selected region in inverse video. (update_sel, clear_sel, yank_sel, delete_sel): New static function. (edit_insert): Delete the selection before inserting, so that the character appears to replace the selection. Set need_refresh flag instead of calling refresh_line. (edit_insert_str): New static function. Inserts string, replacing existing selection, if any. (paren_jump, edit_move_left, edit_move_right, edit_move_home, edit_move_end, edit_history_next): Set new need_refresh flag instead of calling refresh_line directly. (edit_delete): If selection is in effect, just delete the selection and return. Set need_refresh flag instead of calling refresh_line. (edit_backspace): If selection is in effect, and selection is not inverted (cursor is to the right of selection) then just delete the selection. Otherwise delete the selection, and perform the backspace. Set need_refresh flag instead of calling refresh_line. (edit_delete_prev_word): Delete the selection and the word before the selection. Set need_refresh flag instead of calling refresh_line. (edit_in_editor): Set need_refresh_flag instead of calling refresh_line, and cancel visual selection mode. (edit): Clear selection mode on entry. Update the selection variables on each loop iteration. Honor the need_refresh flag. New commands implemented: Ctrl-S, Ctrl-Q, Ctrl-X Ctrl-Q. Some commands need to set need_refresh flag. Some need to cancel selection mode. (lino_copy): Set the clip member of the cloned structure to null, otherwise there will be a double free of the clipboard buffer. (lino_cleanup): Free the clipboard and null out the pointer. * txr.1: Documented visual select.
* linenoise: sync_data_to_to_buf loses pointless arg.Kaz Kylheku2015-09-201-8/+8
| | | | | | | | * linenoise/linenoise.c (sync_data_to_buf): prompt argument removed. The value passed is always l->mlmode, and that is what it indicates. (complete_line, complete_line, sync_data_to_buf, refresh_multiline, edit_insert): Updated calls.
* Adding flatcar* function.Kaz Kylheku2015-09-194-9/+62
| | | | | | | | | | | | * eval.c (eval_init): Registered flatcar* intrinsic. * lib.c (lazy_flatcar_scan, lazy_flatcar_func): New static functions. (lazy_flatcar): New function. * lib.h (lazy_flatcar): Declared. * txr.1: Documented, also touching flatten documentation.
* Atom insert feature.Kaz Kylheku2015-09-182-0/+58
| | | | | | | | * parser.c (provide_atom): New static function. (repl): Register provide_atom with linenoise as atom callback. * txr.1: Documented.
* linenoise: atom-gathering callback feature.Kaz Kylheku2015-09-182-1/+38
| | | | | | | | | | | | * linenoise/linenoise.c (struct lino_state): New members atom_callback and ca_ctx. (lino_set_atom_cb): New function. (edit): Ctrl-X Ctrl-A invokes atom callback, and inserts returned string. * linenoise/linenoise.h (lino_atom_cb_t): New function pointer typedef. (lino_set_atom_cb): Declared.
* New function: flatcar.Kaz Kylheku2015-09-184-0/+45
| | | | | | | | | | * eval.c (eval_init): Register flatcar intrinsic. * lib.c (flatcar): New function. * lib.h (flatcar): Declared. * txr.1: Documented.
* linenoise: insert previous word featureKaz Kylheku2015-09-182-3/+57
| | | | | | | | * linenoise/linenoise.c (edit): Ctrl-X Ctrl-W, or Ctrl-X w, with an optional number in between, cause a word from the previous line to be inserted. * txr.1: Documented.
* Set the tempfile suffix.Kaz Kylheku2015-09-181-0/+1
| | | | | * parser.c (repl): Configure the .tl suffix in the linenoise object.
* linenoise: support suffix on temp file name.Kaz Kylheku2015-09-182-2/+19
| | | | | | | | | | | | | | This is so that when a command line is edited in an external editor, editors can choose appropriate syntax highlighting mode based on the suffix. * linenoise/linenoise.c (struct lino_state): New member, suffix. (edit_in_editor): If we have the mkstemps function, then use it to create a suffixed name. (lino_set_tempfile_suffix): New function. * linenoise/linenoise.h (lino_set_tempfile_suffix): Declared.
* Detect mkstemps function.Kaz Kylheku2015-09-181-0/+20
| | | | | | * configure: Add check for mkstemps. (HAVE_MKSTEMPS): New preprocessor symbol, conditionally deposited into config/config.h
* Doc fix under getpwnam.Kaz Kylheku2015-09-181-1/+1
| | | | * txr.1: Description wrongly refers to getpwuid.
* Improved ~/.txr_profile checks, with security.Kaz Kylheku2015-09-182-8/+27
| | | | | | | | | | * parser.c (load_rcfile): Use path-exists-p for the existence check. Since that doesn't throw, it's outside of the catch section. Use path-private-to-me-p to impose a security check on the profile file. If an error exception is caught, show the details. * txr.1: Added notes about security check.
* New function path-private-to-me.Kaz Kylheku2015-09-173-1/+48
| | | | | | | | | * lisplib.c (path_test_set_entries: "path-private-to-me-p" addred to name array. * share/txr/stdlib/path-test.tl (path-private-to-me-p): New function. * txr.1: Documented path-private-to-me.
* Add unix group database functions.Kaz Kylheku2015-09-173-0/+240
| | | | | | | | | | | | | | | | | | * configure (have_grgid): New variable. New tests added for getgrent and the rest. (HAVE_GRGID, HAVE_GRGID_R): New preprocessor symbols conditionally deposited into config/config.h. * sysif.c (group_s, mem_s): New global symbol variables. (setgrent_wrap, endgrent_wrap, fill_group, make_grstruct, get_grent_wrap, getgrgid_wrap, getgrnam_wrap): New static functions. (sysif_init): New global symbol variables initialized. New group struct type instantiated. Intrinsic functions setgrent, endgrent, getgrent, getgrgid and getgrnam registered. * txr.1: Documented group structure and functions.
* Change how error locations are reported in REPL.Kaz Kylheku2015-09-171-2/+2
| | | | | | | | | | | | | | Now that we have a multi-line mode, it no longer works that we use the command line number as the parse line number, so that an error from something that was parsed in command 42 comes out as "line:42". This commit changes to the format "expr-42:3": line 3 of expression 42. The expression number is fixed in the parse name, and the line number is derived from the line divisions in the entry itself. * parser.c (repl): Dynamically compute the parse name, such that it contains the command number. Then when parsing, just leave the parse to begin at line 1.
* Whitespace fix.Kaz Kylheku2015-09-171-1/+1
| | | | * parser.c (load_rcfile): Trailing whitespace after declaration.
* linenoise: Ctrl-X Ctrl-V super verbatim mode.Kaz Kylheku2015-09-172-2/+30
| | | | | | | | * linenoise/linenoise.c (edit): Support a verbatim entry mode with limited commands, in which most characters self-insert, including Enter. * txr.1: Documented.