diff options
author | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2024-12-30 05:00:44 +0300 |
---|---|---|
committer | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2024-12-30 05:00:44 +0300 |
commit | e2eff00a9c0d89a196bb297b4958473a681ddfee (patch) | |
tree | 3260f9a583fae5f77563bc28e434bf23cf4075cd | |
parent | 45cb7da5de3145525c4f33605cb77e76854159a1 (diff) | |
download | sciteco-e2eff00a9c0d89a196bb297b4958473a681ddfee.tar.gz |
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.
-rw-r--r-- | TODO | 8 | ||||
-rw-r--r-- | doc/sciteco.1.in | 28 | ||||
-rw-r--r-- | freebsd/pkg-plist | 1 | ||||
-rw-r--r-- | lib/Makefile.am | 4 | ||||
-rw-r--r-- | lib/opener.tes | 37 | ||||
-rw-r--r-- | sample.teco_ini | 6 | ||||
-rw-r--r-- | src/main.c | 45 |
7 files changed, 94 insertions, 35 deletions
@@ -466,14 +466,6 @@ Features: * Get into mentors.debian.net. First step to being adopted into the Debian repositories. * Get meta-rhaberkorn into https://layers.openembedded.org - * sample.teco_ini: Support opening files on certain lines - (filename:line). - Theoretically, this could also be added to the <EB> syntax, - although the colon character is allowed in filenames under Windows. - In principe there is little need for that in interactive mode, - but it would ease opening filenames copied from compiler errors - or grep -n results. - Other editors use the +line[,col] syntax (see nano). * <:EF> for saving and closing a buffer, similar to <:EX>. * Bash completions. * FreeBSD: rctl(8) theoretically allows setting up per-process actions diff --git a/doc/sciteco.1.in b/doc/sciteco.1.in index 2b3d3bf..cc17237 100644 --- a/doc/sciteco.1.in +++ b/doc/sciteco.1.in @@ -21,7 +21,7 @@ Scintilla-based \fBT\fPext \fBE\fPditor and \fBCO\fPrrector .OP "--no-profile" .OP "-8|--8bit" .RI [ "UI option .\|.\|." ] -.OP "--" +.OP "--|-S" .RI [ script ] .RI [ "argument .\|.\|." ] .YS @@ -86,7 +86,9 @@ In any case the current buffer position (called .IR dot ) is left at the beginning of the buffer. Optionally \(lq\-\-\(rq might be used to explicitly separate \*(ST options and -macro arguments. +macro arguments, but is never passed down as a macro argument. +Since it's sometimes useful to pass down \(rq\-\-\(rq to the profile macro, +you can use \(lq\-S\(rq, which is equivalent to \(lq\-\- \-\-\(rq. . .LP If the munged macro does not request program termination using the @@ -155,7 +157,14 @@ the first non-option argument. The profile will usually set up various Scintilla and \*(ST options, configure syntax highlighting, define commonly used macros and open files specified as arguments to \*(ST. -It will usually leave the editor in interactive mode. +The recommended command-line processor from \(lqopener.tes\(rq allows +opening files on specific lines or lines and columns +(\fB+\fIline\fR[\fB,\fIcolumn\fR] \fIfilename\fP or +\fIfilename\fB:\fIline\fR[\fB:\fIcolumn\fR][\fB:\fR]). +This special syntax can be inhibited by prefixing the files names with the +special \(lq\-S\(rq separator. +.LP +The profile macro will usually leave the editor in interactive mode. Profile execution can be suppressed with the .B \-\-no\-profile option. @@ -289,12 +298,6 @@ on Windows. On all other platforms (including UNIX/Linux) this variable defaults to the standard library installation path at .BR "@scitecolibdir@" . -.TP -.SCITECO_TOPIC "$SCITECO_SCINTILLUA_LEXERS" -.B SCITECO_SCINTILLUA_LEXERS -The Scintillua \(lqlexers/\(rq directory. -This is passed as the \(lqscintillua.lexers\(rq library property when -loading a Scintillua lexer via the \fBSCI_SETILEXER\fP Scintilla message. . .LP The \fBHOME\fP, \fBSCITECOCONFIG\fP and \fBSCITECOPATH\fP environment @@ -321,9 +324,16 @@ environment before initializing Curses, so these variables can be modified in the profile macro. . .LP +.SCITECO_TOPIC "$GTK_CSD" On GTK+, you may turn off the infamous client-side window decorations by setting the environment variable \fBGTK_CSD\fP to \(lq0\(rq. . +.LP +.SCITECO_TOPIC "$SCITECO_SCINTILLUA_LEXERS" +The \fBSCITECO_SCINTILLUA_LEXERS\fP environment variable specifies +the Scintillua \(lqlexers/\(rq directory. +This is passed as the \(lqscintillua.lexers\(rq library property when +loading a Scintillua lexer via the \fBSCI_SETILEXER\fP Scintilla message. . .SH SIGNALS . diff --git a/freebsd/pkg-plist b/freebsd/pkg-plist index c129643..48a4b61 100644 --- a/freebsd/pkg-plist +++ b/freebsd/pkg-plist @@ -91,6 +91,7 @@ share/man/man7/%%PROGRAM_PREFIX%%sciteco.7.gz %%LEXILLA%%%%DATADIR%%/lib/lexers/xml.tes %%LEXILLA%%%%DATADIR%%/lib/lexers/yaml.tes %%DATADIR%%/lib/lexers/woman.tes +%%DATADIR%%/lib/opener.tes %%DATADIR%%/lib/session.tes %%DATADIR%%/lib/string.tes %%DATADIR%%/lib/women/grosciteco.tes.1.woman 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> +} diff --git a/sample.teco_ini b/sample.teco_ini index 0fbf40d..a9caf26 100644 --- a/sample.teco_ini +++ b/sample.teco_ini @@ -7,6 +7,7 @@ EMQ[$SCITECOPATH]/color.tes !* Load lexer and buffer session libraries *! EMQ[$SCITECOPATH]/lexer.tes EMQ[$SCITECOPATH]/session.tes +EMQ[$SCITECOPATH]/opener.tes !* Automatic lexing and session management using ED hooks *! @#ED{ @@ -81,8 +82,5 @@ Z"= M[session.load] | [session.path] !* disables session saving *! - [.f - <:L;R 0X.f [* EBN.f ]* L> - ].f - -EF + M[opener] -EF ' @@ -141,7 +141,7 @@ teco_process_options(gchar ***argv) g_autoptr(GError) error = NULL; - g_autoptr(GOptionContext) options = g_option_context_new("[--] [SCRIPT] [ARGUMENT...]"); + g_autoptr(GOptionContext) options = g_option_context_new("[--|-S] [SCRIPT] [ARGUMENT...]"); g_option_context_set_summary( options, @@ -168,27 +168,48 @@ teco_process_options(gchar ***argv) * in many situations. * It is also strictly required to make hash-bang lines like * #!/usr/bin/sciteco -m - * work. + * work (without additional --). */ g_option_context_set_strict_posix(options, TRUE); + /* + * The first unknown parameter will be left in argv and + * terminates option parsing (see above). + * This means we can use "-S" as an alternative to "--", + * that is always preserved and passed down to the macro. + */ + g_option_context_set_ignore_unknown_options(options, TRUE); + if (!g_option_context_parse_strv(options, argv, &error)) { g_fprintf(stderr, "Option parsing failed: %s\n", error->message); exit(EXIT_FAILURE); } - /* - * GOption will NOT remove "--" if followed by an - * option-argument, which may interfer with scripts - * doing their own option handling and interpreting "--". - * - * NOTE: This is still true if we're parsing in GNU-mode - * and "--" is not the first non-option argument as in - * sciteco foo -- -C bar. - */ - if ((*argv)[0] && !g_strcmp0((*argv)[1], "--")) + if ((*argv)[0] && !g_strcmp0((*argv)[1], "-S")) { + /* translate -S to --, this is always passed down */ + (*argv)[1][1] = '-'; + } else if ((*argv)[0] && !g_strcmp0((*argv)[1], "--")) { + /* + * GOption will NOT remove "--" if followed by an + * option-argument, which may interfer with scripts + * doing their own option handling and interpreting "--". + * Otherwise, GOption will always remove "--". + * + * NOTE: This is still true if we're parsing in GNU-mode + * and "--" is not the first non-option argument as in + * sciteco foo -- -C bar. + */ g_free(teco_strv_remove(*argv, 1)); + } else if ((*argv)[0] && (*argv)[1] && *(*argv)[1] == '-') { + /* + * GOption does not remove "--" if it is followed by "-", + * so if the first parameter starts with "-", we know it's + * not a known built-in parameter. + */ + g_fprintf(stderr, "Unknown option \"%s\"\n", (*argv)[1]); + exit(EXIT_FAILURE); + } gchar *mung_filename = NULL; |