From e2eff00a9c0d89a196bb297b4958473a681ddfee Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Mon, 30 Dec 2024 05:00:44 +0300 Subject: support +line[,column] and filename:line:column syntaxes when opening files * This is done via the new opener.tes in the standard library. * Some programs that use $EDITOR expect the +line syntax to work. * You can copy filename:line:column directly from GCC error messages and filename:line from grep output. * Since there may be safe file names beginning with "+" or containing colons, there needs to be a way to turn this off, especially for scripts that don't know anything about the filenames to open. This is done with "--". Unfortunately, the first "--", that stops parameter processing, is always removed from the command line and not passed down into TECO land. This is not a problem for stand-alone scripts, since the script filename is already stopping option processing, so "--" would get passed down. But when calling the profile via `sciteco -- ...`, you could prevent leading minus signs to cause problems but since the `--` is removed, opener.tes cannot use it as a hint. Therefore, we introduced `-S` as a new alternative to `--`, that's always passed down as `--` (i.e. it is equivalent to "-- --"). In other words, `sciteco -S *` will always open exactly the specified files without any danger of misinterpreting certain file names. Should we ever switch to a custom option parsing algorithm, we might preserve "--" (unless after --mung) and thus get rid of "-S". * This advanced behavior can be tweaked by the user relatively easily. In the easiest case, we could replace M[opener] with <:L;R 0X.f [* @EB/^EN.f/ ]* L> in ~/.teco_ini to completely disable the special syntax. --- lib/Makefile.am | 4 ++-- lib/opener.tes | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 lib/opener.tes (limited to 'lib') diff --git a/lib/Makefile.am b/lib/Makefile.am index 8bf80be..70f39b7 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -1,6 +1,6 @@ -dist_scitecolib_DATA = color.tes lexer.tes session.tes fnkeys.tes -dist_scitecolib_DATA += string.tes getopt.tes +dist_scitecolib_DATA = color.tes lexer.tes session.tes opener.tes \ + fnkeys.tes string.tes getopt.tes # Helper script for creating lexer definitions EXTRA_DIST = scite2co.lua diff --git a/lib/opener.tes b/lib/opener.tes new file mode 100644 index 0000000..6a57317 --- /dev/null +++ b/lib/opener.tes @@ -0,0 +1,37 @@ +!*$ + * M[opener] -- Open a number of files from the current buffer + * + * This is usually the unnamed buffer as initialized from the command line. + * It supports both the +line[,column] and filename:line[:column] syntaxes. + * Since this may make it hard to open files with certain file names, all + * filenames after "--" are interpreted verbatim. + *! +@[opener]{ + <.-Z; + !* --/-S stops processing of special arguments *! + 0A--"= 1A--"= 2A-10"= + L <:L;R 0X.f [* EBN.f ]* L> 1; + ''' + + 1U.l 1U.c + !* +line[,column] *! + 0A-+"= + C 0A"D \U.l W 0A-,"= C \U.c ' 0A-10"=L' ' + ' + + !* filename:line[:column][:] *! + LR -A-:"=R' <-A"DR|1;'> -A-:"= + \U.a R <-A"DR|1;'> -A-:"= + \U.l Q.aU.c R + | + Q.aU.l 1U.c + ' + | + LR + ' + + 0X.f [* + EBN.f Q.c-1,Q.l-1ESFINDCOLUMN:J + ]* + L> +} -- cgit v1.2.3