custom braced names for filename and syntax

Benno Schulenberg <[email protected]> Tue, 18 Nov 2025 16:25:01 +0100
Newsgroups gmane.editors.nano.devel
Message-ID <[email protected]>
Op 18-11-2025 om 12:18 schreef Luca Coraggio:
> Indeed, what I typically do is to pipe the highlighted text to the script
> and let it handle the pipe; but I am not sure now if this can be easily
> combined with the "{writeout}" trick.

Ah, no, it can't...  :/  Because when something is marked, then the WriteOut
prompt clears the filename (to avoid overwriting the current file with only
a fragment).  So the {writeout}{copy}{cancel} trick will copy nothing.  :|

Then, instead of your patch, I would suggest the attached one.  It is just
twenty lines, and easier to understand, I think.


Benno
custom-braced-names-for-injecting-filename-or-syntax-into-answer.patch (text/x-patch, 2.5 KB)
diff --git a/src/prompt.c b/src/prompt.c
index 01efcdd2..d890ad4c 100644
--- a/src/prompt.c
+++ b/src/prompt.c
@@ -230,6 +230,19 @@ void inject_into_answer(char *burst, size_t count)
 	typing_x += count;
 }
 
+/* Insert the filename of the current buffer into the answer. */
+void paste_filename(void)
+{
+	inject_into_answer(openfile->filename, strlen(openfile->filename));
+}
+
+/* Insert the name of the current syntax into the answer. */
+void paste_syntax(void)
+{
+	if (openfile->syntax)
+		inject_into_answer(openfile->syntax->name, strlen(openfile->syntax->name));
+}
+
 /* Get a verbatim keystroke and insert it into the answer. */
 void do_statusbar_verbatim_input(void)
 {
diff --git a/src/prototypes.h b/src/prototypes.h
index c83380df..ff630dbd 100644
--- a/src/prototypes.h
+++ b/src/prototypes.h
@@ -444,6 +444,8 @@ void suck_up_input_and_paste_it(void);
 void inject(char *burst, size_t count);
 
 /* Most functions in prompt.c. */
+void paste_filename(void);
+void paste_syntax(void);
 size_t get_statusbar_page_start(size_t base, size_t column);
 void put_cursor_at_end_of_answer(void);
 void add_or_remove_pipe_symbol_from_answer(void);
diff --git a/src/rcfile.c b/src/rcfile.c
index 364d24c9..5022bd73 100644
--- a/src/rcfile.c
+++ b/src/rcfile.c
@@ -404,6 +404,10 @@ keystruct *strtosc(const char *input)
 		s->func = flip_replace;
 	else if (!strcmp(input, "flipgoto"))
 		s->func = flip_goto;
+	else if (!strcmp(input, "filename"))
+		s->func = paste_filename;
+	else if (!strcmp(input, "syntax"))
+		s->func = paste_syntax;
 #ifdef ENABLE_HISTORIES
 	else if (!strcmp(input, "older"))
 		s->func = get_older_item;
diff --git a/syntax/nanorc.nanorc b/syntax/nanorc.nanorc
index 0c16a6be..ad3b9637 100644
--- a/syntax/nanorc.nanorc
+++ b/syntax/nanorc.nanorc
@@ -32,7 +32,7 @@ color crimson "\{(location|gotoline|(begin|end)para|comment|complete|(un)?indent
 color crimson "\{(left|right|up|down|home|end|(scroll|page)(up|down)|(top|bottom)row|center|cycle|(prev|next)(word|block|anchor|buf))\}"
 color crimson "\{(tab|enter|delete|backspace|verbatim|refresh|suspend|casesens|regexp|backwards|older|newer|(dos|mac)format)\}"
 color crimson "\{(append|prepend|backup|flip(goto|replace|execute|pipe|convert|newbuffer)|browser|gotodir|(first|last)(file|line))\}"
-color crimson "\{(nohelp|constantshow|softwrap|linenumbers|whitespacedisplay|nosyntax|zero)\}"
+color crimson "\{(nohelp|constantshow|softwrap|linenumbers|whitespacedisplay|nosyntax|zero|filename|syntax)\}"
 color crimson "\{(smarthome|autoindent|cutfromcursor|breaklonglines|tabstospaces|mouse|\{|\})\}"
 
 # Commands
OpenPGP_signature.asc (application/pgp-signature, 840 B)
-----BEGIN PGP SIGNATURE-----

wsF5BAABCAAjFiEEFo5vQpe/16ea/USWUUu+Lrjhlh8FAmkcj80FAwAAAAAACgkQUUu+Lrjhlh+d
tRAA2Pq1/lLrdZchTUJdFebW0xQzVOa2mJpjy6MN13c44YI1K3TZ+w5bmb9/tdfwNurTZijrcdpE
+EX8R6J7P02Ba2mVIlWOglHVB0uwn+TWBugx4n0BRTlkvLJh7FCEKYqMzGBYgGkriQ6dl3Bw/mHU
+F4Bs7+5TjVFMGSfBncgbg6jzxVo/q51JhXrjRKuXdZPqD8Payzd79E7rQyD6hqhM3Xi7VE1erQ8
bN7SAXxJW9ak7rnb8NCAtn6V+0qYxLsmxxRfjKLpWAydaeY7WcfBmcvyNPg1u3Cujw9MLktmboQj
dKRowXJxnZVwDQVS8CdeoQkMbAWu8SA3WHSyTqHI8w/gR5ya0wJ/Ot5xDEHKVPG5F72xs9BceSfY
Xso8V1Wf4RtQ6J4x8vyy6AmjAareQP2SAVxXEGAKh7FBMsZvOIGigfGXtt2Q2lA6sitcObzwLTmE
9feBSRW1RXI9RtKRMFOLvSWVpEJ2V4zBXbd9RnOLadiN1UYqDVVqtI2HQc888s9D2msrX223Q0+1
DUpDgXlw/tE5YO2sdClfrfGBFdr2WgOU5w1/ggzdl5KsDW/d13U2+5GEBmg7vcr2ubNIxwYJq++1
ylG1PefOpX6v577ALZe4S6mbK4iwVxDD5qAxRF1C4t+Wgocu1KLWfkR/Rx8/1G1GT6H4jg05UdmH
0EM=
=JhIH
-----END PGP SIGNATURE-----