blob: 45d3e019b9af0d0ff399eb6046036fc1457fc096 [file] [log] [blame]
Chris Allegretta07fcc4c2008-07-10 20:13:04 +00001/* $Id$ */
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00002/**************************************************************************
3 * global.c *
4 * *
Chris Allegretta8a07a962009-12-02 03:36:22 +00005 * Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, *
Benno Schulenberg7a9f4a42014-04-30 20:18:26 +00006 * 2008, 2009, 2010, 2011, 2013, 2014 Free Software Foundation, Inc. *
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00007 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
David Lawrence Ramseyd0035b42007-08-11 05:17:36 +00009 * the Free Software Foundation; either version 3, or (at your option) *
Chris Allegrettaa2ea1932000-06-06 05:53:49 +000010 * any later version. *
11 * *
David Lawrence Ramsey6e925cf2005-05-15 19:57:17 +000012 * This program is distributed in the hope that it will be useful, but *
13 * WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
15 * General Public License for more details. *
Chris Allegrettaa2ea1932000-06-06 05:53:49 +000016 * *
17 * You should have received a copy of the GNU General Public License *
18 * along with this program; if not, write to the Free Software *
David Lawrence Ramsey6e925cf2005-05-15 19:57:17 +000019 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
20 * 02110-1301, USA. *
Chris Allegrettaa2ea1932000-06-06 05:53:49 +000021 * *
22 **************************************************************************/
23
Chris Allegrettaa855fa22008-07-12 02:13:22 +000024#include "proto.h"
25
Chris Allegretta79a33bb2008-03-05 07:34:01 +000026#include <ctype.h>
Chris Allegrettaeb643142008-03-12 04:44:14 +000027#include <string.h>
Chris Allegretta79a33bb2008-03-05 07:34:01 +000028#include <strings.h>
29#include "assert.h"
Chris Allegrettaa2ea1932000-06-06 05:53:49 +000030
David Lawrence Ramseyfc0f8f82006-05-10 13:41:53 +000031/* Global variables. */
32#ifndef NANO_TINY
David Lawrence Ramsey1c5af642006-05-10 15:15:06 +000033sigjmp_buf jump_buf;
David Lawrence Ramseyb6fb6882006-11-27 07:28:52 +000034 /* Used to return to either main() or the unjustify routine in
David Lawrence Ramseyfc0f8f82006-05-10 13:41:53 +000035 * do_justify() after a SIGWINCH. */
David Lawrence Ramsey1c5af642006-05-10 15:15:06 +000036bool jump_buf_main = FALSE;
37 /* Have we set jump_buf so that we return to main() after a
38 * SIGWINCH? */
David Lawrence Ramseyfc0f8f82006-05-10 13:41:53 +000039#endif
40
Benno Schulenberg7e5324d2014-06-30 18:04:33 +000041bool meta_key;
42 /* Whether the current keystroke is a Meta key. */
43bool func_key;
44 /* Whether the current keystroke is an extended keypad value. */
45
David Lawrence Ramseyf5b256b2003-10-03 20:26:25 +000046#ifndef DISABLE_WRAPJUSTIFY
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +000047ssize_t fill = 0;
48 /* The column where we will wrap lines. */
David Lawrence Ramsey691698a2005-07-24 19:57:51 +000049ssize_t wrap_at = -CHARS_FROM_EOL;
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +000050 /* The position where we will wrap lines. fill is equal to this
51 * if it's greater than zero, and equal to (COLS + this) if it
52 * isn't. */
David Lawrence Ramseyf5b256b2003-10-03 20:26:25 +000053#endif
54
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +000055char *last_search = NULL;
56 /* The last string we searched for. */
57char *last_replace = NULL;
58 /* The last replacement string we searched for. */
Chris Allegretta6df90f52002-07-19 01:08:59 +000059
Chris Allegrettaa48507d2009-08-14 03:18:29 +000060unsigned flags[4] = {0, 0, 0, 0};
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +000061 /* Our flag containing the states of all global options. */
62WINDOW *topwin;
63 /* The top portion of the window, where we display the version
64 * number of nano, the name of the current file, and whether the
65 * current file has been modified. */
66WINDOW *edit;
David Lawrence Ramseyb159f942006-07-28 17:06:27 +000067 /* The middle portion of the window, i.e. the edit window, where
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +000068 * we display the current file we're editing. */
69WINDOW *bottomwin;
70 /* The bottom portion of the window, where we display statusbar
71 * messages, the statusbar prompt, and a list of shortcuts. */
72int editwinrows = 0;
73 /* How many rows does the edit window take up? */
Chris Allegretta8c1edd12009-11-16 04:28:40 +000074int maxrows = 0;
Benno Schulenberg7f873932014-02-25 21:27:22 +000075 /* How many usable lines there are (due to soft wrapping). */
David Lawrence Ramsey5db0cdc2002-06-28 22:45:14 +000076
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +000077filestruct *cutbuffer = NULL;
78 /* The buffer where we store cut text. */
Chris Allegretta12dc8ca2008-07-31 04:24:04 +000079filestruct *cutbottom = NULL;
David Lawrence Ramsey93c84052004-11-23 04:08:28 +000080#ifndef DISABLE_JUSTIFY
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +000081filestruct *jusbuffer = NULL;
82 /* The buffer where we store unjustified text. */
David Lawrence Ramsey93c84052004-11-23 04:08:28 +000083#endif
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +000084partition *filepart = NULL;
85 /* The partition where we store a portion of the current
86 * file. */
David Lawrence Ramsey64661ac2005-07-08 19:57:25 +000087openfilestruct *openfile = NULL;
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +000088 /* The list of all open file buffers. */
Chris Allegretta2d7893d2001-07-11 02:08:33 +000089
David Lawrence Ramseyd89617f2006-01-06 21:51:10 +000090#ifndef NANO_TINY
91char *matchbrackets = NULL;
92 /* The opening and closing brackets that can be found by bracket
93 * searches. */
94#endif
95
Benno Schulenbergeea09082014-04-13 20:50:20 +000096#if !defined(NANO_TINY) && !defined(DISABLE_NANORC)
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +000097char *whitespace = NULL;
98 /* The characters used when displaying the first characters of
99 * tabs and spaces. */
100int whitespace_len[2];
101 /* The length of these characters. */
David Lawrence Ramsey89bb9372004-05-29 16:47:52 +0000102#endif
103
Chris Allegrettae4f940d2002-03-03 22:36:36 +0000104#ifndef DISABLE_JUSTIFY
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +0000105char *punct = NULL;
106 /* The closing punctuation that can end sentences. */
107char *brackets = NULL;
108 /* The closing brackets that can follow closing punctuation and
109 * can end sentences. */
110char *quotestr = NULL;
111 /* The quoting string. The default value is set in main(). */
David Lawrence Ramsey819c7f02004-07-30 03:54:34 +0000112#ifdef HAVE_REGEX_H
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +0000113regex_t quotereg;
114 /* The compiled regular expression from the quoting string. */
115int quoterc;
David Lawrence Ramsey88165642006-05-22 18:30:09 +0000116 /* Whether it was compiled successfully. */
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +0000117char *quoteerr = NULL;
118 /* The error message, if it didn't. */
David Lawrence Ramsey819c7f02004-07-30 03:54:34 +0000119#else
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +0000120size_t quotelen;
121 /* The length of the quoting string in bytes. */
David Lawrence Ramsey819c7f02004-07-30 03:54:34 +0000122#endif
Chris Allegretta6df90f52002-07-19 01:08:59 +0000123#endif
Chris Allegrettae4f940d2002-03-03 22:36:36 +0000124
Chris Allegretta0dc26dc2009-01-24 22:40:41 +0000125bool nodelay_mode = FALSE;
Benno Schulenberg71c9a522014-05-13 20:14:01 +0000126 /* Are we checking for a cancel wile doing something? */
Chris Allegretta0dc26dc2009-01-24 22:40:41 +0000127
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +0000128char *answer = NULL;
David Lawrence Ramsey6335fb52007-01-01 05:15:32 +0000129 /* The answer string used by the statusbar prompt. */
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +0000130
131ssize_t tabsize = -1;
132 /* The width of a tab in spaces. The default value is set in
133 * main(). */
134
David Lawrence Ramseyebe34252005-11-15 03:17:35 +0000135#ifndef NANO_TINY
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +0000136char *backup_dir = NULL;
137 /* The directory where we store backup files. */
Chris Allegrettabf88d272013-01-01 03:24:39 +0000138
Chris Allegretta3116d2f2013-01-03 04:36:39 +0000139const char *locking_prefix = ".";
Benno Schulenberg71c9a522014-05-13 20:14:01 +0000140 /* Prefix of how to store the vim-style lock file. */
Chris Allegretta3116d2f2013-01-03 04:36:39 +0000141const char *locking_suffix = ".swp";
Benno Schulenberg71c9a522014-05-13 20:14:01 +0000142 /* Suffix of the vim-style lock file. */
David Lawrence Ramsey04e42a62004-02-28 16:24:31 +0000143#endif
Chris Allegrettae1f14522001-09-19 03:19:43 +0000144#ifndef DISABLE_OPERATINGDIR
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +0000145char *operating_dir = NULL;
146 /* The relative path to the operating directory, which we can't
147 * move outside of. */
148char *full_operating_dir = NULL;
149 /* The full path to it. */
Chris Allegrettae1f14522001-09-19 03:19:43 +0000150#endif
151
Chris Allegretta8d8e0122001-04-18 04:28:54 +0000152#ifndef DISABLE_SPELLER
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +0000153char *alt_speller = NULL;
154 /* The command to use for the alternate spell checker. */
Chris Allegretta8d8e0122001-04-18 04:28:54 +0000155#endif
156
Benno Schulenberg00389922014-04-04 11:59:03 +0000157#ifndef DISABLE_COLOR
David Lawrence Ramsey9b13ff32002-12-22 16:30:00 +0000158syntaxtype *syntaxes = NULL;
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +0000159 /* The global list of color syntaxes. */
David Lawrence Ramsey9b13ff32002-12-22 16:30:00 +0000160char *syntaxstr = NULL;
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +0000161 /* The color syntax name specified on the command line. */
Chris Allegretta8ce24132001-04-30 11:28:46 +0000162#endif
163
Benno Schulenberg275bd282014-05-16 10:34:05 +0000164bool edit_refresh_needed = FALSE;
Chris Allegretta2ad1de02012-12-30 19:20:10 +0000165 /* Did a command mangle enough of the buffer refresh that we
Benno Schulenberg7f873932014-02-25 21:27:22 +0000166 * should repaint the screen? */
Chris Allegrettafd265af2009-02-06 03:41:02 +0000167
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000168int currmenu;
Benno Schulenberg7f873932014-02-25 21:27:22 +0000169 /* The currently loaded menu. */
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000170sc *sclist = NULL;
Benno Schulenberg20b1e922014-04-26 18:41:43 +0000171 /* Pointer to the start of the shortcuts list. */
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000172subnfunc *allfuncs = NULL;
Benno Schulenberg20b1e922014-04-26 18:41:43 +0000173 /* Pointer to the start of the functions list. */
174subnfunc *tailfunc;
175 /* Pointer to the last function in the list. */
Benno Schulenberg11d76442014-04-26 19:01:18 +0000176subnfunc *exitfunc;
177 /* Pointer to the special Exit/Close item. */
Benno Schulenbergbc6e9aa2014-04-07 09:02:22 +0000178subnfunc *uncutfunc;
179 /* Pointer to the special Uncut/Unjustify item. */
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000180
Benno Schulenbergb341f292014-06-19 20:05:24 +0000181#ifndef DISABLE_HISTORIES
David Lawrence Ramsey934f9682005-05-23 16:30:06 +0000182filestruct *search_history = NULL;
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +0000183 /* The search string history list. */
David Lawrence Ramsey934f9682005-05-23 16:30:06 +0000184filestruct *searchage = NULL;
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +0000185 /* The top of the search string history list. */
David Lawrence Ramsey934f9682005-05-23 16:30:06 +0000186filestruct *searchbot = NULL;
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +0000187 /* The bottom of the search string history list. */
David Lawrence Ramsey934f9682005-05-23 16:30:06 +0000188filestruct *replace_history = NULL;
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +0000189 /* The replace string history list. */
David Lawrence Ramsey934f9682005-05-23 16:30:06 +0000190filestruct *replaceage = NULL;
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +0000191 /* The top of the replace string history list. */
David Lawrence Ramsey934f9682005-05-23 16:30:06 +0000192filestruct *replacebot = NULL;
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +0000193 /* The bottom of the replace string history list. */
Chris Allegretta9bfda912011-02-16 06:52:30 +0000194poshiststruct *poshistory;
Benno Schulenberg7f873932014-02-25 21:27:22 +0000195 /* The cursor position history list. */
Chris Allegretta5beed502003-01-05 20:41:21 +0000196#endif
197
David Lawrence Ramseyfc0f8f82006-05-10 13:41:53 +0000198/* Regular expressions. */
Chris Allegretta805c26d2000-09-06 13:39:17 +0000199#ifdef HAVE_REGEX_H
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +0000200regex_t search_regexp;
201 /* The compiled regular expression to use in searches. */
202regmatch_t regmatches[10];
203 /* The match positions for parenthetical subexpressions, 10
204 * maximum, used in regular expression searches. */
Chris Allegretta6df90f52002-07-19 01:08:59 +0000205#endif
Chris Allegretta3533a342002-03-24 23:19:32 +0000206
Benno Schulenbergc9700352014-05-04 08:53:06 +0000207int hilite_attribute = A_REVERSE;
David Lawrence Ramsey4d72de72006-04-12 15:27:40 +0000208 /* The curses attribute we use for reverse video. */
Benno Schulenberg16639942014-05-03 18:24:45 +0000209#ifndef DISABLE_COLOR
210char* specified_color_combo[] = {};
211 /* The color combinations as specified in the rcfile. */
212#endif
Benno Schulenberge7d6e552014-05-10 19:15:04 +0000213color_pair interface_color_pair[] = {};
Benno Schulenberg16639942014-05-03 18:24:45 +0000214 /* The processed color pairs for the interface elements. */
Chris Allegrettaa0d89972003-02-03 03:32:08 +0000215
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +0000216char *homedir = NULL;
David Lawrence Ramseyc1c818e2006-05-14 18:22:01 +0000217 /* The user's home directory, from $HOME or /etc/passwd. */
David Lawrence Ramseya27bd652004-08-17 05:23:38 +0000218
Benno Schulenberg7f873932014-02-25 21:27:22 +0000219/* Return the number of entries in the shortcut list for a given menu. */
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000220size_t length_of_list(int menu)
Chris Allegrettaa8c22572002-02-15 19:17:02 +0000221{
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000222 subnfunc *f;
David Lawrence Ramseyebd0d7c2004-07-01 18:59:52 +0000223 size_t i = 0;
David Lawrence Ramseye21adfa2002-09-13 18:14:04 +0000224
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000225 for (f = allfuncs; f != NULL; f = f->next)
Chris Allegretta0018d8e2008-03-13 08:23:52 +0000226 if ((f->menus & menu) != 0
227#ifndef DISABLE_HELP
228 && strlen(f->help) > 0
229#endif
230 ) {
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000231 i++;
232 }
Chris Allegrettaa8c22572002-02-15 19:17:02 +0000233 return i;
234}
235
Benno Schulenberge6a4a642014-07-01 18:52:21 +0000236/* To make the functions and shortcuts lists clearer. */
237#define VIEW TRUE /* Is allowed in view mode. */
238#define NOVIEW FALSE
239#define BLANKAFTER TRUE /* A blank line after this one. */
240#define TOGETHER FALSE
241
Benno Schulenberg7f873932014-02-25 21:27:22 +0000242/* Just throw this here. */
Chris Allegretta637daa82011-02-07 14:45:56 +0000243void case_sens_void(void)
244{
245}
246void regexp_void(void)
247{
248}
Benno Schulenbergd1238c02014-05-13 20:51:19 +0000249void backwards_void(void)
250{
251}
Chris Allegretta637daa82011-02-07 14:45:56 +0000252void gototext_void(void)
253{
254}
Benno Schulenbergd1238c02014-05-13 20:51:19 +0000255#ifndef DISABLE_BROWSER
Chris Allegretta637daa82011-02-07 14:45:56 +0000256void to_files_void(void)
257{
258}
Benno Schulenbergd1238c02014-05-13 20:51:19 +0000259void goto_dir_void(void)
260{
261}
262#endif
Chris Allegretta637daa82011-02-07 14:45:56 +0000263void dos_format_void(void)
264{
265}
266void mac_format_void(void)
267{
268}
269void append_void(void)
270{
271}
272void prepend_void(void)
273{
274}
275void backup_file_void(void)
276{
277}
278void new_buffer_void(void)
279{
280}
Benno Schulenberga0f66c02014-06-23 18:30:35 +0000281void flip_replace_void(void)
Chris Allegretta637daa82011-02-07 14:45:56 +0000282{
283}
Benno Schulenberg04a38da2014-06-04 19:15:16 +0000284void flip_execute_void(void)
Chris Allegretta637daa82011-02-07 14:45:56 +0000285{
286}
287
Benno Schulenberg80750632014-07-27 19:18:00 +0000288/* Add a function to the function list. */
Chris Allegretta637daa82011-02-07 14:45:56 +0000289void add_to_funcs(void (*func)(void), int menus, const char *desc, const char *help,
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000290 bool blank_after, bool viewok)
291{
Benno Schulenberg1eb23d42014-06-04 16:30:11 +0000292 subnfunc *f = (subnfunc *)nmalloc(sizeof(subnfunc));
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000293
Benno Schulenberg20b1e922014-04-26 18:41:43 +0000294 if (allfuncs == NULL)
295 allfuncs = f;
296 else
297 tailfunc->next = f;
298 tailfunc = f;
299
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000300 f->next = NULL;
301 f->scfunc = func;
302 f->menus = menus;
303 f->desc = desc;
304 f->viewok = viewok;
Chris Allegretta1d778232008-08-30 21:00:00 +0000305#ifndef DISABLE_HELP
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000306 f->help = help;
307 f->blank_after = blank_after;
308#endif
309
310#ifdef DEBUG
Benno Schulenberg5c2b44a2014-04-15 20:01:19 +0000311 fprintf(stderr, "Added func %ld (%s) for menus %x\n", (long)func, f->desc, menus);
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000312#endif
313}
314
Benno Schulenbergd23283e2014-07-27 19:13:46 +0000315/* Add a key combo to the shortcut list. */
Benno Schulenbergd4623f32014-06-28 14:42:18 +0000316void add_to_sclist(int menu, const char *scstring, void (*func)(void), int toggle)
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000317{
Benno Schulenbergd23283e2014-07-27 19:13:46 +0000318 static sc *tailsc;
319 sc *s = (sc *)nmalloc(sizeof(sc));
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000320
Benno Schulenbergd23283e2014-07-27 19:13:46 +0000321 /* Start the list, or tack on the next item. */
322 if (sclist == NULL)
323 sclist = s;
324 else
325 tailsc->next = s;
326 tailsc = s;
327 s->next = NULL;
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000328
Benno Schulenbergd23283e2014-07-27 19:13:46 +0000329 /* Fill in the data. */
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000330 s->menu = menu;
Benno Schulenbergd23283e2014-07-27 19:13:46 +0000331 s->scfunc = func;
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000332 s->toggle = toggle;
Chris Allegretta5a018f02009-11-29 06:13:22 +0000333 s->keystr = (char *) scstring;
Benno Schulenbergd23283e2014-07-27 19:13:46 +0000334 s->type = strtokeytype(scstring);
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000335 assign_keyinfo(s);
336
337#ifdef DEBUG
Benno Schulenberg6af5bde2014-06-09 20:41:15 +0000338 fprintf(stderr, "Setting sequence to %d for shortcut \"%s\" in menu %x\n", s->seq, scstring, (int)s->menu);
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000339#endif
340}
341
Benno Schulenberg74541032014-05-13 20:20:51 +0000342/* Assign one function's shortcuts to another function. */
Chris Allegretta5575bfa2014-02-24 10:18:15 +0000343void replace_scs_for(void (*oldfunc)(void), void (*newfunc)(void))
344{
345 sc *s;
346
Benno Schulenberg74541032014-05-13 20:20:51 +0000347 for (s = sclist; s != NULL; s = s->next)
Benno Schulenberg492e9f62014-06-20 10:48:26 +0000348 if (s->scfunc == oldfunc)
Chris Allegretta5575bfa2014-02-24 10:18:15 +0000349 s->scfunc = newfunc;
Chris Allegretta5575bfa2014-02-24 10:18:15 +0000350}
351
Benno Schulenbergdbb5e7c2014-07-27 19:23:41 +0000352/* Return the first shortcut in the list of shortcuts that
353 * matches the given func in the given menu. */
354const sc *first_sc_for(int menu, void (*func)(void))
355{
356 const sc *s;
357
358 for (s = sclist; s != NULL; s = s->next)
359 if ((s->menu & menu) && s->scfunc == func)
360 return s;
361
362#ifdef DEBUG
363 fprintf(stderr, "Whoops, returning null given func %ld in menu %x\n", (long)func, menu);
364#endif
365 /* Otherwise... */
366 return NULL;
367}
368
Chris Allegrettae347efb2008-03-09 02:52:40 +0000369/* Return the given menu's first shortcut sequence, or the default value
Benno Schulenberg7f873932014-02-25 21:27:22 +0000370 * (2nd arg). Assumes currmenu for the menu to check. */
Benno Schulenberg505125e2014-06-09 14:23:53 +0000371int sc_seq_or(void (*func)(void), int defaultval)
Chris Allegrettae347efb2008-03-09 02:52:40 +0000372{
373 const sc *s = first_sc_for(currmenu, func);
374
Benno Schulenberg776931a2014-06-30 18:20:32 +0000375 if (s) {
376 meta_key = (s->type == META);
Chris Allegrettae347efb2008-03-09 02:52:40 +0000377 return s->seq;
Benno Schulenberg776931a2014-06-30 18:20:32 +0000378 }
Chris Allegrettae347efb2008-03-09 02:52:40 +0000379 /* else */
380 return defaultval;
Chris Allegrettae347efb2008-03-09 02:52:40 +0000381}
382
Benno Schulenberg3933a302014-07-02 08:47:09 +0000383/* Return a pointer to the function that is bound to the given key. */
384functionptrtype func_from_key(int *kbinput)
385{
386 const sc *s = get_shortcut(kbinput);
387
388 if (s)
389 return s->scfunc;
390 else
391 return NULL;
392}
393
Benno Schulenberg80750632014-07-27 19:18:00 +0000394/* Return the type of command key based on the given string. */
395key_type strtokeytype(const char *str)
396{
397 if (str[0] == '^')
398 return CONTROL;
399 else if (str[0] == 'M')
400 return META;
401 else if (str[0] == 'F')
402 return FKEY;
403 else
404 return RAWINPUT;
405}
406
Benno Schulenberg7f873932014-02-25 21:27:22 +0000407/* Assign the info to the shortcut struct.
408 * Assumes keystr is already assigned, naturally. */
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000409void assign_keyinfo(sc *s)
410{
411 if (s->type == CONTROL) {
412 assert(strlen(s->keystr) > 1);
413 s->seq = s->keystr[1] - 64;
414 } else if (s->type == META) {
415 assert(strlen(s->keystr) > 2);
416 s->seq = tolower((int) s->keystr[2]);
417 } else if (s->type == FKEY) {
418 assert(strlen(s->keystr) > 1);
419 s->seq = KEY_F0 + atoi(&s->keystr[1]);
Chris Allegretta3bd12e32011-02-26 14:22:37 +0000420 } else /* RAWINPUT */
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000421 s->seq = (int) s->keystr[0];
Chris Allegretta9b422202008-03-05 17:15:33 +0000422
Benno Schulenberg75ff3a92014-04-21 15:22:14 +0000423 /* Override some keys which don't bind as easily as we'd like. */
Chris Allegretta9b422202008-03-05 17:15:33 +0000424 if (s->type == CONTROL && (!strcasecmp(&s->keystr[1], "space")))
425 s->seq = 0;
426 else if (s->type == META && (!strcasecmp(&s->keystr[2], "space")))
427 s->seq = (int) ' ';
Benno Schulenberg75ff3a92014-04-21 15:22:14 +0000428 else if (s->type == RAWINPUT) {
Benno Schulenbergd6308802014-04-21 15:45:23 +0000429 if (!strcasecmp(s->keystr, "Up"))
Benno Schulenberg75ff3a92014-04-21 15:22:14 +0000430 s->seq = KEY_UP;
Benno Schulenbergd6308802014-04-21 15:45:23 +0000431 else if (!strcasecmp(s->keystr, "Down"))
Benno Schulenberg75ff3a92014-04-21 15:22:14 +0000432 s->seq = KEY_DOWN;
Benno Schulenbergd6308802014-04-21 15:45:23 +0000433 else if (!strcasecmp(s->keystr, "Left"))
Benno Schulenberg75ff3a92014-04-21 15:22:14 +0000434 s->seq = KEY_LEFT;
Benno Schulenbergd6308802014-04-21 15:45:23 +0000435 else if (!strcasecmp(s->keystr, "Right"))
Benno Schulenberg75ff3a92014-04-21 15:22:14 +0000436 s->seq = KEY_RIGHT;
Benno Schulenberg94b1d012014-04-21 18:05:11 +0000437 else if (!strcasecmp(s->keystr, "Ins"))
Benno Schulenberg75ff3a92014-04-21 15:22:14 +0000438 s->seq = KEY_IC;
Benno Schulenbergd6308802014-04-21 15:45:23 +0000439 else if (!strcasecmp(s->keystr, "Del"))
Benno Schulenberg75ff3a92014-04-21 15:22:14 +0000440 s->seq = KEY_DC;
Benno Schulenbergd6308802014-04-21 15:45:23 +0000441 else if (!strcasecmp(s->keystr, "Bsp"))
Benno Schulenberg75ff3a92014-04-21 15:22:14 +0000442 s->seq = KEY_BACKSPACE;
Benno Schulenbergd6308802014-04-21 15:45:23 +0000443 else if (!strcasecmp(s->keystr, "Enter"))
Benno Schulenberg75ff3a92014-04-21 15:22:14 +0000444 s->seq = KEY_ENTER;
Benno Schulenbergd6308802014-04-21 15:45:23 +0000445 else if (!strcasecmp(s->keystr, "PgUp"))
Benno Schulenberg75ff3a92014-04-21 15:22:14 +0000446 s->seq = KEY_PPAGE;
Benno Schulenbergd6308802014-04-21 15:45:23 +0000447 else if (!strcasecmp(s->keystr, "PgDn"))
Benno Schulenberg75ff3a92014-04-21 15:22:14 +0000448 s->seq = KEY_NPAGE;
Chris Allegretta17436ce2008-03-11 03:03:53 +0000449#ifdef KEY_HOME
Benno Schulenbergd6308802014-04-21 15:45:23 +0000450 else if (!strcasecmp(s->keystr, "Home"))
Benno Schulenberg75ff3a92014-04-21 15:22:14 +0000451 s->seq = KEY_HOME;
Chris Allegretta17436ce2008-03-11 03:03:53 +0000452#endif
453#ifdef KEY_END
Benno Schulenbergd6308802014-04-21 15:45:23 +0000454 else if (!strcasecmp(s->keystr, "End"))
Benno Schulenberg75ff3a92014-04-21 15:22:14 +0000455 s->seq = KEY_END;
Chris Allegretta17436ce2008-03-11 03:03:53 +0000456#endif
Benno Schulenberg75ff3a92014-04-21 15:22:14 +0000457 }
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000458}
459
460#ifdef DEBUG
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000461void print_sclist(void)
462{
463 sc *s;
464 const subnfunc *f;
465
Benno Schulenberga85b6da2014-03-26 10:57:11 +0000466 for (s = sclist; s != NULL; s = s->next) {
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000467 f = sctofunc(s);
Benno Schulenberga85b6da2014-03-26 10:57:11 +0000468 if (f)
Benno Schulenberg70d21672014-03-26 10:53:10 +0000469 fprintf(stderr, "Shortcut \"%s\", function: %s, menus %x\n", s->keystr, f->desc, f->menus);
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000470 else
Benno Schulenbergd0dec312014-04-08 12:35:18 +0000471 fprintf(stderr, "Hmm, didn't find a func for \"%s\"\n", s->keystr);
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000472 }
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000473}
474#endif
475
Benno Schulenberg11d76442014-04-26 19:01:18 +0000476/* TRANSLATORS: Try to keep the next four strings at most 10 characters. */
477const char *exit_tag = N_("Exit");
478const char *close_tag = N_("Close");
Benno Schulenbergbc6e9aa2014-04-07 09:02:22 +0000479const char *uncut_tag = N_("Uncut Text");
480#ifndef DISABLE_JUSITIFY
481const char *unjust_tag = N_("Unjustify");
482#endif
Benno Schulenberg2ff9dc72014-04-06 20:55:21 +0000483#ifndef NANO_TINY
Benno Schulenberg9aebd272014-04-22 10:44:24 +0000484/* TRANSLATORS: Try to keep this at most 12 characters. */
Benno Schulenberg9fc713b2014-04-22 10:18:48 +0000485const char *whereis_next_tag = N_("WhereIs Next");
Benno Schulenberg2ff9dc72014-04-06 20:55:21 +0000486#endif
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000487
Benno Schulenberga2dcd6e2014-04-07 09:24:10 +0000488/* Initialize the list of functions and the list of shortcuts. */
489void shortcut_init(void)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000490{
Benno Schulenberg48223592014-05-28 19:02:00 +0000491 /* TRANSLATORS: Try to keep the next eight strings at most 10 characters. */
Benno Schulenberg9fc713b2014-04-22 10:18:48 +0000492 const char *whereis_tag = N_("Where Is");
Benno Schulenberg61758e92014-04-27 14:21:57 +0000493 const char *replace_tag = N_("Replace");
494 const char *gotoline_tag = N_("Go To Line");
Benno Schulenberg12da94c2014-04-22 10:02:55 +0000495 const char *prev_line_tag = N_("Prev Line");
496 const char *next_line_tag = N_("Next Line");
Benno Schulenbergff6b92c2014-05-28 15:35:00 +0000497 const char *read_file_tag = N_("Read File");
Benno Schulenberg5f655da2014-04-27 15:26:25 +0000498#ifndef DISABLE_JUSTIFY
Benno Schulenberg61758e92014-04-27 14:21:57 +0000499 const char *fulljustify_tag = N_("FullJstify");
Benno Schulenberg5f655da2014-04-27 15:26:25 +0000500#endif
Benno Schulenberg9fc713b2014-04-22 10:18:48 +0000501 const char *refresh_tag = N_("Refresh");
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000502
Benno Schulenberg8c5f5042014-05-28 20:31:06 +0000503#ifndef DISABLE_HELP
Chris Allegretta1d778232008-08-30 21:00:00 +0000504#ifndef DISABLE_JUSTIFY
Benno Schulenberg7f873932014-02-25 21:27:22 +0000505 /* TRANSLATORS: The next long series of strings are shortcut descriptions;
506 * they are best kept shorter than 56 characters, but may be longer. */
Chris Allegretta1d778232008-08-30 21:00:00 +0000507 const char *nano_justify_msg = N_("Justify the current paragraph");
508#endif
David Lawrence Ramsey804e1072006-03-29 19:43:32 +0000509 const char *nano_cancel_msg = N_("Cancel the current function");
David Lawrence Ramsey57c9afb2006-04-14 20:21:45 +0000510 const char *nano_help_msg = N_("Display this help text");
David Lawrence Ramsey576bf332004-07-12 03:10:30 +0000511 const char *nano_exit_msg =
Benno Schulenberg0636d7b2014-04-03 20:23:07 +0000512#ifndef DISABLE_MULTIBUFFER
David Lawrence Ramseybe231d32006-05-21 21:37:21 +0000513 N_("Close the current file buffer / Exit from nano")
Chris Allegretta2d7893d2001-07-11 02:08:33 +0000514#else
Benno Schulenberga65ef422014-03-17 21:36:37 +0000515 N_("Exit from nano")
Chris Allegretta2d7893d2001-07-11 02:08:33 +0000516#endif
David Lawrence Ramsey576bf332004-07-12 03:10:30 +0000517 ;
David Lawrence Ramsey9b108c22005-06-06 18:38:16 +0000518 const char *nano_writeout_msg =
519 N_("Write the current file to disk");
David Lawrence Ramsey576bf332004-07-12 03:10:30 +0000520 const char *nano_insert_msg =
521 N_("Insert another file into the current one");
David Lawrence Ramsey9b108c22005-06-06 18:38:16 +0000522 const char *nano_whereis_msg =
David Lawrence Ramseybe231d32006-05-21 21:37:21 +0000523 N_("Search for a string or a regular expression");
Benno Schulenbergd1238c02014-05-13 20:51:19 +0000524#ifndef DISABLE_BROWSER
Benno Schulenberg960a1202014-03-18 22:04:41 +0000525 const char *nano_browser_whereis_msg =
526 N_("Search for a string");
Benno Schulenbergd1238c02014-05-13 20:51:19 +0000527#endif
Benno Schulenberg63716122014-04-27 19:51:03 +0000528 const char *nano_prevpage_msg = N_("Go one screenful up");
529 const char *nano_nextpage_msg = N_("Go one screenful down");
David Lawrence Ramsey576bf332004-07-12 03:10:30 +0000530 const char *nano_cut_msg =
531 N_("Cut the current line and store it in the cutbuffer");
532 const char *nano_uncut_msg =
533 N_("Uncut from the cutbuffer into the current line");
Benno Schulenberg022d32a2014-05-26 10:07:00 +0000534 const char *nano_cursorpos_msg = N_("Display the position of the cursor");
Benno Schulenbergb8b29ff2014-04-03 21:06:30 +0000535#ifndef DISABLE_SPELLER
Benno Schulenberg022d32a2014-05-26 10:07:00 +0000536 const char *nano_spell_msg = N_("Invoke the spell checker, if available");
Benno Schulenbergb8b29ff2014-04-03 21:06:30 +0000537#endif
Benno Schulenberg022d32a2014-05-26 10:07:00 +0000538 const char *nano_replace_msg = N_("Replace a string or a regular expression");
Benno Schulenbergf803ef52014-04-13 12:16:37 +0000539 const char *nano_gotoline_msg = N_("Go to line and column number");
David Lawrence Ramseyebe34252005-11-15 03:17:35 +0000540#ifndef NANO_TINY
Benno Schulenberg4da24342014-04-27 15:20:57 +0000541 const char *nano_mark_msg = N_("Mark text starting from the cursor position");
542 const char *nano_whereis_next_msg = N_("Repeat the last search");
David Lawrence Ramseycf1879b2006-04-27 23:39:49 +0000543 const char *nano_copy_msg =
544 N_("Copy the current line and store it in the cutbuffer");
David Lawrence Ramseyaee00d42006-07-05 18:42:22 +0000545 const char *nano_indent_msg = N_("Indent the current line");
546 const char *nano_unindent_msg = N_("Unindent the current line");
Chris Allegretta07fcc4c2008-07-10 20:13:04 +0000547 const char *nano_undo_msg = N_("Undo the last operation");
548 const char *nano_redo_msg = N_("Redo the last undone operation");
David Lawrence Ramsey4b4b6082004-11-01 22:54:40 +0000549#endif
David Lawrence Ramsey9f1db5d2007-02-01 13:40:59 +0000550 const char *nano_forward_msg = N_("Go forward one character");
551 const char *nano_back_msg = N_("Go back one character");
David Lawrence Ramsey854a44a2006-04-24 21:14:55 +0000552#ifndef NANO_TINY
David Lawrence Ramsey9f1db5d2007-02-01 13:40:59 +0000553 const char *nano_nextword_msg = N_("Go forward one word");
554 const char *nano_prevword_msg = N_("Go back one word");
David Lawrence Ramsey854a44a2006-04-24 21:14:55 +0000555#endif
David Lawrence Ramsey9f1db5d2007-02-01 13:40:59 +0000556 const char *nano_prevline_msg = N_("Go to previous line");
557 const char *nano_nextline_msg = N_("Go to next line");
558 const char *nano_home_msg = N_("Go to beginning of current line");
559 const char *nano_end_msg = N_("Go to end of current line");
David Lawrence Ramseydb6015c2004-09-11 21:41:13 +0000560#ifndef DISABLE_JUSTIFY
561 const char *nano_parabegin_msg =
David Lawrence Ramsey9f1db5d2007-02-01 13:40:59 +0000562 N_("Go to beginning of paragraph; then of previous paragraph");
David Lawrence Ramseydb6015c2004-09-11 21:41:13 +0000563 const char *nano_paraend_msg =
David Lawrence Ramsey9f1db5d2007-02-01 13:40:59 +0000564 N_("Go just beyond end of paragraph; then of next paragraph");
David Lawrence Ramseydb6015c2004-09-11 21:41:13 +0000565#endif
Benno Schulenberg022d32a2014-05-26 10:07:00 +0000566 const char *nano_firstline_msg = N_("Go to the first line of the file");
567 const char *nano_lastline_msg = N_("Go to the last line of the file");
David Lawrence Ramsey854a44a2006-04-24 21:14:55 +0000568#ifndef NANO_TINY
David Lawrence Ramsey9f1db5d2007-02-01 13:40:59 +0000569 const char *nano_bracket_msg = N_("Go to the matching bracket");
David Lawrence Ramsey854a44a2006-04-24 21:14:55 +0000570 const char *nano_scrollup_msg =
571 N_("Scroll up one line without scrolling the cursor");
572 const char *nano_scrolldown_msg =
573 N_("Scroll down one line without scrolling the cursor");
574#endif
Benno Schulenberg0636d7b2014-04-03 20:23:07 +0000575#ifndef DISABLE_MULTIBUFFER
Benno Schulenberg022d32a2014-05-26 10:07:00 +0000576 const char *nano_prevfile_msg = N_("Switch to the previous file buffer");
577 const char *nano_nextfile_msg = N_("Switch to the next file buffer");
David Lawrence Ramseydb6015c2004-09-11 21:41:13 +0000578#endif
Benno Schulenberg022d32a2014-05-26 10:07:00 +0000579 const char *nano_verbatim_msg = N_("Insert the next keystroke verbatim");
580 const char *nano_tab_msg = N_("Insert a tab at the cursor position");
581 const char *nano_enter_msg = N_("Insert a newline at the cursor position");
582 const char *nano_delete_msg = N_("Delete the character under the cursor");
David Lawrence Ramsey854a44a2006-04-24 21:14:55 +0000583 const char *nano_backspace_msg =
584 N_("Delete the character to the left of the cursor");
David Lawrence Ramseyebe34252005-11-15 03:17:35 +0000585#ifndef NANO_TINY
Benno Schulenberg95e77a92014-06-30 20:39:27 +0000586 const char *nano_cut_till_eof_msg =
David Lawrence Ramsey295d1722005-01-01 07:43:32 +0000587 N_("Cut from the cursor position to the end of the file");
588#endif
David Lawrence Ramseydb6015c2004-09-11 21:41:13 +0000589#ifndef DISABLE_JUSTIFY
590 const char *nano_fulljustify_msg = N_("Justify the entire file");
David Lawrence Ramsey576bf332004-07-12 03:10:30 +0000591#endif
David Lawrence Ramseyc5c52302005-11-15 23:45:29 +0000592#ifndef NANO_TINY
David Lawrence Ramsey854a44a2006-04-24 21:14:55 +0000593 const char *nano_wordcount_msg =
594 N_("Count the number of words, lines, and characters");
David Lawrence Ramsey576bf332004-07-12 03:10:30 +0000595#endif
David Lawrence Ramsey854a44a2006-04-24 21:14:55 +0000596 const char *nano_refresh_msg =
597 N_("Refresh (redraw) the current screen");
Chris Allegretta0018d8e2008-03-13 08:23:52 +0000598 const char *nano_suspend_msg =
599 N_("Suspend the editor (if suspend is enabled)");
David Lawrence Ramseyebe34252005-11-15 03:17:35 +0000600#ifndef NANO_TINY
David Lawrence Ramsey576bf332004-07-12 03:10:30 +0000601 const char *nano_case_msg =
David Lawrence Ramsey69e1ce52006-06-08 02:37:45 +0000602 N_("Toggle the case sensitivity of the search");
David Lawrence Ramsey576bf332004-07-12 03:10:30 +0000603 const char *nano_reverse_msg =
David Lawrence Ramsey69e1ce52006-06-08 02:37:45 +0000604 N_("Reverse the direction of the search");
David Lawrence Ramseyc10d8ff2005-06-03 20:51:39 +0000605#endif
David Lawrence Ramsey576bf332004-07-12 03:10:30 +0000606#ifdef HAVE_REGEX_H
David Lawrence Ramsey69e1ce52006-06-08 02:37:45 +0000607 const char *nano_regexp_msg =
608 N_("Toggle the use of regular expressions");
David Lawrence Ramsey576bf332004-07-12 03:10:30 +0000609#endif
Benno Schulenbergb341f292014-06-19 20:05:24 +0000610#ifndef DISABLE_HISTORIES
David Lawrence Ramsey305d8892006-05-24 19:48:03 +0000611 const char *nano_prev_history_msg =
David Lawrence Ramsey7b0531a2006-07-31 01:30:31 +0000612 N_("Recall the previous search/replace string");
David Lawrence Ramsey305d8892006-05-24 19:48:03 +0000613 const char *nano_next_history_msg =
David Lawrence Ramsey7b0531a2006-07-31 01:30:31 +0000614 N_("Recall the next search/replace string");
David Lawrence Ramseyc10d8ff2005-06-03 20:51:39 +0000615#endif
David Lawrence Ramsey576bf332004-07-12 03:10:30 +0000616#ifndef DISABLE_BROWSER
617 const char *nano_tofiles_msg = N_("Go to file browser");
618#endif
David Lawrence Ramseyebe34252005-11-15 03:17:35 +0000619#ifndef NANO_TINY
David Lawrence Ramsey69e1ce52006-06-08 02:37:45 +0000620 const char *nano_dos_msg = N_("Toggle the use of DOS format");
621 const char *nano_mac_msg = N_("Toggle the use of Mac format");
David Lawrence Ramsey69e1ce52006-06-08 02:37:45 +0000622 const char *nano_append_msg = N_("Toggle appending");
623 const char *nano_prepend_msg = N_("Toggle prepending");
Benno Schulenberg022d32a2014-05-26 10:07:00 +0000624 const char *nano_backup_msg = N_("Toggle backing up of the original file");
David Lawrence Ramsey576bf332004-07-12 03:10:30 +0000625 const char *nano_execute_msg = N_("Execute external command");
626#endif
Benno Schulenberg0636d7b2014-04-03 20:23:07 +0000627#ifndef DISABLE_MULTIBUFFER
Benno Schulenberg022d32a2014-05-26 10:07:00 +0000628 const char *nano_multibuffer_msg = N_("Toggle the use of a new buffer");
David Lawrence Ramsey576bf332004-07-12 03:10:30 +0000629#endif
630#ifndef DISABLE_BROWSER
David Lawrence Ramseyc41d4282004-07-23 12:51:40 +0000631 const char *nano_exitbrowser_msg = N_("Exit from the file browser");
Benno Schulenberg022d32a2014-05-26 10:07:00 +0000632 const char *nano_firstfile_msg = N_("Go to the first file in the list");
633 const char *nano_lastfile_msg = N_("Go to the last file in the list");
Chris Allegretta8d41fb82009-12-23 05:03:09 +0000634 const char *nano_backfile_msg = N_("Go to the previous file in the list");
Benno Schulenberg022d32a2014-05-26 10:07:00 +0000635 const char *nano_forwardfile_msg = N_("Go to the next file in the list");
David Lawrence Ramseyc41d4282004-07-23 12:51:40 +0000636 const char *nano_gotodir_msg = N_("Go to directory");
Chris Allegretta2bef1822001-09-28 19:53:11 +0000637#endif
Benno Schulenberg00389922014-04-04 11:59:03 +0000638#ifndef DISABLE_COLOR
Benno Schulenberg91ee10a2014-03-27 21:35:18 +0000639 const char *nano_lint_msg = N_("Invoke the linter, if available");
Chris Allegretta5575bfa2014-02-24 10:18:15 +0000640 const char *nano_prevlint_msg = N_("Go to previous linter msg");
641 const char *nano_nextlint_msg = N_("Go to next linter msg");
642#endif
Chris Allegrettadab017e2002-04-23 10:56:06 +0000643#endif /* !DISABLE_HELP */
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000644
David Lawrence Ramseyea43a1d2004-03-02 22:52:57 +0000645#ifndef DISABLE_HELP
Chris Allegretta0018d8e2008-03-13 08:23:52 +0000646#define IFSCHELP(help) help
David Lawrence Ramseyea43a1d2004-03-02 22:52:57 +0000647#else
Chris Allegretta0018d8e2008-03-13 08:23:52 +0000648#define IFSCHELP(help) ""
Chris Allegrettadab017e2002-04-23 10:56:06 +0000649#endif
David Lawrence Ramseya593f532003-11-28 19:47:42 +0000650
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000651 while (allfuncs != NULL) {
652 subnfunc *f = allfuncs;
Benno Schulenberg24bc59f2014-05-13 18:06:09 +0000653 allfuncs = allfuncs->next;
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000654 free(f);
655 }
David Lawrence Ramsey576bf332004-07-12 03:10:30 +0000656
Benno Schulenbergf803ef52014-04-13 12:16:37 +0000657 /* Start populating the different menus with functions. */
658
Benno Schulenbergf6a3ab02014-04-16 09:55:16 +0000659 add_to_funcs(do_help_void, MMOST,
Benno Schulenbergc8b60ce2014-04-22 11:57:11 +0000660 /* TRANSLATORS: Try to keep the following strings at most 10 characters. */
Benno Schulenberge6a4a642014-07-01 18:52:21 +0000661 N_("Get Help"), IFSCHELP(nano_help_msg), TOGETHER, VIEW);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000662
Benno Schulenbergf6a3ab02014-04-16 09:55:16 +0000663 add_to_funcs(do_cancel, ((MMOST & ~MMAIN & ~MBROWSER) | MYESNO),
Benno Schulenberge6a4a642014-07-01 18:52:21 +0000664 N_("Cancel"), IFSCHELP(nano_cancel_msg), TOGETHER, VIEW);
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000665
Chris Allegretta637daa82011-02-07 14:45:56 +0000666 add_to_funcs(do_exit, MMAIN,
Benno Schulenberge6a4a642014-07-01 18:52:21 +0000667 exit_tag, IFSCHELP(nano_exit_msg), TOGETHER, VIEW);
Benno Schulenberg11d76442014-04-26 19:01:18 +0000668 /* Remember the entry for Exit, to be able to replace it with Close. */
669 exitfunc = tailfunc;
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000670
Chris Allegrettadcd19c92008-03-20 04:51:26 +0000671#ifndef DISABLE_BROWSER
Benno Schulenbergf470c902014-05-28 21:02:39 +0000672 add_to_funcs(do_exit, MBROWSER,
Benno Schulenberge6a4a642014-07-01 18:52:21 +0000673 exit_tag, IFSCHELP(nano_exitbrowser_msg), TOGETHER, VIEW);
Chris Allegrettadcd19c92008-03-20 04:51:26 +0000674#endif
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000675
Benno Schulenbergf470c902014-05-28 21:02:39 +0000676 add_to_funcs(do_writeout_void, MMAIN,
Benno Schulenberge6a4a642014-07-01 18:52:21 +0000677 N_("Write Out"), IFSCHELP(nano_writeout_msg), TOGETHER, NOVIEW);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000678
David Lawrence Ramsey32e3b882004-05-29 01:20:17 +0000679 /* We allow inserting files in view mode if multibuffers are
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +0000680 * available, so that we can view multiple files. If we're using
681 * restricted mode, inserting files is disabled, since it allows
682 * reading from or writing to files not specified on the command
683 * line. */
Benno Schulenbergf470c902014-05-28 21:02:39 +0000684 add_to_funcs(do_insertfile_void, MMAIN,
Benno Schulenberge6a4a642014-07-01 18:52:21 +0000685 read_file_tag, IFSCHELP(nano_insert_msg), BLANKAFTER,
Benno Schulenberg0636d7b2014-04-03 20:23:07 +0000686#ifndef DISABLE_MULTIBUFFER
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000687 VIEW);
Chris Allegretta32da4562002-01-02 15:12:21 +0000688#else
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000689 NOVIEW);
Chris Allegretta32da4562002-01-02 15:12:21 +0000690#endif
Chris Allegrettaaf6414a2001-02-11 19:05:05 +0000691
Benno Schulenbergf470c902014-05-28 21:02:39 +0000692 add_to_funcs(do_search, MMAIN,
Benno Schulenberge6a4a642014-07-01 18:52:21 +0000693 whereis_tag, IFSCHELP(nano_whereis_msg), TOGETHER, VIEW);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000694
Benno Schulenbergf470c902014-05-28 21:02:39 +0000695 add_to_funcs(do_replace, MMAIN,
Benno Schulenberge6a4a642014-07-01 18:52:21 +0000696 replace_tag, IFSCHELP(nano_replace_msg), TOGETHER, NOVIEW);
Benno Schulenberg63716122014-04-27 19:51:03 +0000697
698#ifndef DISABLE_BROWSER
Benno Schulenbergf470c902014-05-28 21:02:39 +0000699 add_to_funcs(do_search, MBROWSER,
Benno Schulenberge6a4a642014-07-01 18:52:21 +0000700 whereis_tag, IFSCHELP(nano_browser_whereis_msg), TOGETHER, VIEW);
Benno Schulenberg960a1202014-03-18 22:04:41 +0000701
Benno Schulenberg63716122014-04-27 19:51:03 +0000702 add_to_funcs(goto_dir_void, MBROWSER,
Benno Schulenberge6a4a642014-07-01 18:52:21 +0000703 N_("Go To Dir"), IFSCHELP(nano_gotodir_msg), BLANKAFTER, VIEW);
Benno Schulenbergcae7aea2014-02-26 20:37:40 +0000704#endif
705
Benno Schulenberg5c2b44a2014-04-15 20:01:19 +0000706#ifndef DISABLE_HELP
Benno Schulenberg12da94c2014-04-22 10:02:55 +0000707 /* The description ("x") and blank_after (0) are irrelevant,
708 * because the help viewer does not have a help text. */
Benno Schulenberg9fc713b2014-04-22 10:18:48 +0000709 add_to_funcs(do_exit, MHELP, exit_tag, "x", 0, VIEW);
Benno Schulenberg5c2b44a2014-04-15 20:01:19 +0000710
Benno Schulenberg9fc713b2014-04-22 10:18:48 +0000711 add_to_funcs(total_refresh, MHELP, refresh_tag, "x", 0, VIEW);
Benno Schulenberg12da94c2014-04-22 10:02:55 +0000712
713 add_to_funcs(do_up_void, MHELP, prev_line_tag, "x", 0, VIEW);
714 add_to_funcs(do_down_void, MHELP, next_line_tag, "x" , 0, VIEW);
Benno Schulenberg5c2b44a2014-04-15 20:01:19 +0000715#endif
716
Benno Schulenbergf470c902014-05-28 21:02:39 +0000717 add_to_funcs(do_cut_text_void, MMAIN,
Benno Schulenberge6a4a642014-07-01 18:52:21 +0000718 N_("Cut Text"), IFSCHELP(nano_cut_msg), TOGETHER, NOVIEW);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000719
Benno Schulenbergf470c902014-05-28 21:02:39 +0000720 add_to_funcs(do_uncut_text, MMAIN,
Benno Schulenberge6a4a642014-07-01 18:52:21 +0000721 uncut_tag, IFSCHELP(nano_uncut_msg), BLANKAFTER, NOVIEW);
Benno Schulenbergbc6e9aa2014-04-07 09:02:22 +0000722 /* Remember the entry for Uncut, to be able to replace it with Unjustify. */
Benno Schulenberg20b1e922014-04-26 18:41:43 +0000723 uncutfunc = tailfunc;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000724
Benno Schulenberg63716122014-04-27 19:51:03 +0000725#ifndef DISABLE_JUSTIFY
Benno Schulenbergf470c902014-05-28 21:02:39 +0000726 add_to_funcs(do_justify_void, MMAIN,
Benno Schulenberge6a4a642014-07-01 18:52:21 +0000727 N_("Justify"), IFSCHELP(nano_justify_msg), TOGETHER, NOVIEW);
Chris Allegrettae347efb2008-03-09 02:52:40 +0000728#endif
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000729
David Lawrence Ramseyd893fa92004-04-30 04:49:02 +0000730#ifndef DISABLE_SPELLER
Benno Schulenberg48223592014-05-28 19:02:00 +0000731 add_to_funcs(do_spell, MMAIN,
Benno Schulenberge6a4a642014-07-01 18:52:21 +0000732 N_("To Spell"), IFSCHELP(nano_spell_msg), TOGETHER, NOVIEW);
David Lawrence Ramseyd893fa92004-04-30 04:49:02 +0000733#endif
David Lawrence Ramseya593f532003-11-28 19:47:42 +0000734
Benno Schulenberg00389922014-04-04 11:59:03 +0000735#ifndef DISABLE_COLOR
Benno Schulenberg48223592014-05-28 19:02:00 +0000736 add_to_funcs(do_linter, MMAIN,
Benno Schulenberge6a4a642014-07-01 18:52:21 +0000737 N_("To Linter"), IFSCHELP(nano_lint_msg), BLANKAFTER, NOVIEW);
Chris Allegretta5575bfa2014-02-24 10:18:15 +0000738#endif
739
Benno Schulenberg61758e92014-04-27 14:21:57 +0000740#ifndef NANO_TINY
Benno Schulenbergb0957252014-07-01 16:24:01 +0000741 add_to_funcs(case_sens_void, MWHEREIS|MREPLACE,
Benno Schulenberge6a4a642014-07-01 18:52:21 +0000742 N_("Case Sens"), IFSCHELP(nano_case_msg), TOGETHER, VIEW);
Benno Schulenberg61758e92014-04-27 14:21:57 +0000743#endif
744
745#ifdef HAVE_REGEX_H
Benno Schulenbergb0957252014-07-01 16:24:01 +0000746 add_to_funcs(regexp_void, MWHEREIS|MREPLACE,
Benno Schulenberge6a4a642014-07-01 18:52:21 +0000747 N_("Regexp"), IFSCHELP(nano_regexp_msg), TOGETHER, VIEW);
Benno Schulenberg61758e92014-04-27 14:21:57 +0000748#endif
749
750#ifndef NANO_TINY
Benno Schulenbergb0957252014-07-01 16:24:01 +0000751 add_to_funcs(backwards_void, MWHEREIS|MREPLACE,
Benno Schulenberge6a4a642014-07-01 18:52:21 +0000752 N_("Backwards"), IFSCHELP(nano_reverse_msg), TOGETHER, VIEW);
Benno Schulenberg61758e92014-04-27 14:21:57 +0000753#endif
754
Benno Schulenberga0f66c02014-06-23 18:30:35 +0000755 add_to_funcs(flip_replace_void, MWHEREIS,
Benno Schulenberge6a4a642014-07-01 18:52:21 +0000756 replace_tag, IFSCHELP(nano_replace_msg), TOGETHER, VIEW);
Benno Schulenberg61758e92014-04-27 14:21:57 +0000757
Benno Schulenberga0f66c02014-06-23 18:30:35 +0000758 add_to_funcs(flip_replace_void, MREPLACE,
Benno Schulenberge6a4a642014-07-01 18:52:21 +0000759 N_("No Replace"), IFSCHELP(nano_whereis_msg), TOGETHER, VIEW);
Benno Schulenberg61758e92014-04-27 14:21:57 +0000760
761#ifndef DISABLE_JUSTIFY
Benno Schulenbergf470c902014-05-28 21:02:39 +0000762 add_to_funcs(do_full_justify, MWHEREIS,
Benno Schulenberge6a4a642014-07-01 18:52:21 +0000763 fulljustify_tag, IFSCHELP(nano_fulljustify_msg), TOGETHER, NOVIEW);
Benno Schulenberg61758e92014-04-27 14:21:57 +0000764#endif
765
Benno Schulenbergf470c902014-05-28 21:02:39 +0000766 add_to_funcs(do_cursorpos_void, MMAIN,
Benno Schulenberge6a4a642014-07-01 18:52:21 +0000767 N_("Cur Pos"), IFSCHELP(nano_cursorpos_msg), TOGETHER, VIEW);
Benno Schulenberg63716122014-04-27 19:51:03 +0000768
Benno Schulenberg0d5e7322014-05-27 12:17:49 +0000769#if !defined(NANO_TINY) || defined(DISABLE_COLOR)
770 /* Conditionally placing this one here or further on, to keep the
771 * help items nicely paired in most conditions. */
Benno Schulenberg63716122014-04-27 19:51:03 +0000772 add_to_funcs(do_gotolinecolumn_void, MMAIN|MWHEREIS,
Benno Schulenberge6a4a642014-07-01 18:52:21 +0000773 gotoline_tag, IFSCHELP(nano_gotoline_msg), BLANKAFTER, VIEW);
Benno Schulenberg0d5e7322014-05-27 12:17:49 +0000774#endif
Benno Schulenberg63716122014-04-27 19:51:03 +0000775
776 add_to_funcs(do_page_up, MMAIN|MHELP|MBROWSER,
Benno Schulenberge6a4a642014-07-01 18:52:21 +0000777 N_("Prev Page"), IFSCHELP(nano_prevpage_msg), TOGETHER, VIEW);
Benno Schulenberg63716122014-04-27 19:51:03 +0000778 add_to_funcs(do_page_down, MMAIN|MHELP|MBROWSER,
Benno Schulenberge6a4a642014-07-01 18:52:21 +0000779 N_("Next Page"), IFSCHELP(nano_nextpage_msg), TOGETHER, VIEW);
Benno Schulenberg61758e92014-04-27 14:21:57 +0000780
Benno Schulenbergf470c902014-05-28 21:02:39 +0000781 add_to_funcs(do_first_line, MMAIN|MHELP|MWHEREIS|MREPLACE|MREPLACEWITH|MGOTOLINE,
Benno Schulenberge6a4a642014-07-01 18:52:21 +0000782 N_("First Line"), IFSCHELP(nano_firstline_msg), TOGETHER, VIEW);
Benno Schulenbergf470c902014-05-28 21:02:39 +0000783 add_to_funcs(do_last_line, MMAIN|MHELP|MWHEREIS|MREPLACE|MREPLACEWITH|MGOTOLINE,
Benno Schulenberge6a4a642014-07-01 18:52:21 +0000784 N_("Last Line"), IFSCHELP(nano_lastline_msg), BLANKAFTER, VIEW);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000785
David Lawrence Ramseyebe34252005-11-15 03:17:35 +0000786#ifndef NANO_TINY
Benno Schulenbergf470c902014-05-28 21:02:39 +0000787 add_to_funcs(do_research, MMAIN,
Benno Schulenberge6a4a642014-07-01 18:52:21 +0000788 whereis_next_tag, IFSCHELP(nano_whereis_next_msg), TOGETHER, VIEW);
Benno Schulenberg4da24342014-04-27 15:20:57 +0000789
Benno Schulenbergf470c902014-05-28 21:02:39 +0000790 add_to_funcs(do_find_bracket, MMAIN,
Benno Schulenberge6a4a642014-07-01 18:52:21 +0000791 N_("To Bracket"), IFSCHELP(nano_bracket_msg), TOGETHER, VIEW);
Benno Schulenberg4da24342014-04-27 15:20:57 +0000792
Benno Schulenbergf470c902014-05-28 21:02:39 +0000793 add_to_funcs(do_mark, MMAIN,
Benno Schulenberge6a4a642014-07-01 18:52:21 +0000794 N_("Mark Text"), IFSCHELP(nano_mark_msg), TOGETHER, VIEW);
David Lawrence Ramseycf1879b2006-04-27 23:39:49 +0000795
Benno Schulenbergf470c902014-05-28 21:02:39 +0000796 add_to_funcs(do_copy_text, MMAIN,
Benno Schulenberge6a4a642014-07-01 18:52:21 +0000797 N_("Copy Text"), IFSCHELP(nano_copy_msg), BLANKAFTER, NOVIEW);
David Lawrence Ramseyf85001a2006-04-28 13:19:56 +0000798
Benno Schulenbergf470c902014-05-28 21:02:39 +0000799 add_to_funcs(do_indent_void, MMAIN,
Benno Schulenberge6a4a642014-07-01 18:52:21 +0000800 N_("Indent Text"), IFSCHELP(nano_indent_msg), TOGETHER, NOVIEW);
Benno Schulenbergf470c902014-05-28 21:02:39 +0000801 add_to_funcs(do_unindent, MMAIN,
Benno Schulenberge6a4a642014-07-01 18:52:21 +0000802 N_("Unindent Text"), IFSCHELP(nano_unindent_msg), BLANKAFTER, NOVIEW);
Chris Allegretta07fcc4c2008-07-10 20:13:04 +0000803
Benno Schulenberg736fbf22014-06-13 15:20:26 +0000804 add_to_funcs(do_undo, MMAIN,
Benno Schulenberge6a4a642014-07-01 18:52:21 +0000805 N_("Undo"), IFSCHELP(nano_undo_msg), TOGETHER, NOVIEW);
Benno Schulenberg736fbf22014-06-13 15:20:26 +0000806 add_to_funcs(do_redo, MMAIN,
Benno Schulenberge6a4a642014-07-01 18:52:21 +0000807 N_("Redo"), IFSCHELP(nano_redo_msg), BLANKAFTER, NOVIEW);
Benno Schulenberge4c34c32014-03-17 14:15:57 +0000808#endif /* !NANO_TINY */
David Lawrence Ramsey1df3e2d2006-04-22 19:45:26 +0000809
Benno Schulenbergf470c902014-05-28 21:02:39 +0000810 add_to_funcs(do_left, MMAIN,
Benno Schulenberge6a4a642014-07-01 18:52:21 +0000811 N_("Back"), IFSCHELP(nano_back_msg), TOGETHER, VIEW);
Benno Schulenbergf470c902014-05-28 21:02:39 +0000812 add_to_funcs(do_right, MMAIN,
Benno Schulenberge6a4a642014-07-01 18:52:21 +0000813 N_("Forward"), IFSCHELP(nano_forward_msg), TOGETHER, VIEW);
Chris Allegretta8d41fb82009-12-23 05:03:09 +0000814
815#ifndef DISABLE_BROWSER
Benno Schulenbergf470c902014-05-28 21:02:39 +0000816 add_to_funcs(do_left, MBROWSER,
Benno Schulenberge6a4a642014-07-01 18:52:21 +0000817 N_("Back"), IFSCHELP(nano_backfile_msg), TOGETHER, VIEW);
Benno Schulenbergf470c902014-05-28 21:02:39 +0000818 add_to_funcs(do_right, MBROWSER,
Benno Schulenberge6a4a642014-07-01 18:52:21 +0000819 N_("Forward"), IFSCHELP(nano_forwardfile_msg), TOGETHER, VIEW);
Chris Allegretta8d41fb82009-12-23 05:03:09 +0000820#endif
821
David Lawrence Ramsey1df3e2d2006-04-22 19:45:26 +0000822#ifndef NANO_TINY
Benno Schulenbergf470c902014-05-28 21:02:39 +0000823 add_to_funcs(do_prev_word_void, MMAIN,
Benno Schulenberge6a4a642014-07-01 18:52:21 +0000824 N_("Prev Word"), IFSCHELP(nano_prevword_msg), TOGETHER, VIEW);
Benno Schulenbergf470c902014-05-28 21:02:39 +0000825 add_to_funcs(do_next_word_void, MMAIN,
Benno Schulenberge6a4a642014-07-01 18:52:21 +0000826 N_("Next Word"), IFSCHELP(nano_nextword_msg), TOGETHER, VIEW);
Chris Allegretta8d990b52001-09-22 22:14:25 +0000827#endif
David Lawrence Ramseye0497062003-08-23 21:11:06 +0000828
Benno Schulenbergf470c902014-05-28 21:02:39 +0000829 add_to_funcs(do_home, MMAIN,
Benno Schulenberge6a4a642014-07-01 18:52:21 +0000830 N_("Home"), IFSCHELP(nano_home_msg), TOGETHER, VIEW);
Benno Schulenbergf470c902014-05-28 21:02:39 +0000831 add_to_funcs(do_end, MMAIN,
Benno Schulenberge6a4a642014-07-01 18:52:21 +0000832 N_("End"), IFSCHELP(nano_end_msg), TOGETHER, VIEW);
Benno Schulenberg63716122014-04-27 19:51:03 +0000833
Benno Schulenbergf470c902014-05-28 21:02:39 +0000834 add_to_funcs(do_up_void, MMAIN|MBROWSER,
Benno Schulenberge6a4a642014-07-01 18:52:21 +0000835 prev_line_tag, IFSCHELP(nano_prevline_msg), TOGETHER, VIEW);
Benno Schulenbergf470c902014-05-28 21:02:39 +0000836 add_to_funcs(do_down_void, MMAIN|MBROWSER,
Benno Schulenberge6a4a642014-07-01 18:52:21 +0000837 next_line_tag, IFSCHELP(nano_nextline_msg), BLANKAFTER, VIEW);
David Lawrence Ramsey1df3e2d2006-04-22 19:45:26 +0000838
David Lawrence Ramseydb6015c2004-09-11 21:41:13 +0000839#ifndef DISABLE_JUSTIFY
Benno Schulenbergf470c902014-05-28 21:02:39 +0000840 add_to_funcs(do_para_begin_void, MMAIN|MWHEREIS,
Benno Schulenberge6a4a642014-07-01 18:52:21 +0000841 N_("Beg of Par"), IFSCHELP(nano_parabegin_msg), TOGETHER, VIEW);
Benno Schulenbergf470c902014-05-28 21:02:39 +0000842 add_to_funcs(do_para_end_void, MMAIN|MWHEREIS,
Benno Schulenberge6a4a642014-07-01 18:52:21 +0000843 N_("End of Par"), IFSCHELP(nano_paraend_msg), TOGETHER, VIEW);
David Lawrence Ramseydb6015c2004-09-11 21:41:13 +0000844#endif
David Lawrence Ramseye0497062003-08-23 21:11:06 +0000845
David Lawrence Ramsey1df3e2d2006-04-22 19:45:26 +0000846#ifndef NANO_TINY
Benno Schulenbergf470c902014-05-28 21:02:39 +0000847 add_to_funcs(do_scroll_up, MMAIN,
Benno Schulenberge6a4a642014-07-01 18:52:21 +0000848 N_("Scroll Up"), IFSCHELP(nano_scrollup_msg), TOGETHER, VIEW);
Benno Schulenbergf470c902014-05-28 21:02:39 +0000849 add_to_funcs(do_scroll_down, MMAIN,
Benno Schulenberge6a4a642014-07-01 18:52:21 +0000850 N_("Scroll Down"), IFSCHELP(nano_scrolldown_msg), BLANKAFTER, VIEW);
David Lawrence Ramsey1df3e2d2006-04-22 19:45:26 +0000851#endif
David Lawrence Ramseydf453652006-04-21 02:05:09 +0000852
Benno Schulenberg0636d7b2014-04-03 20:23:07 +0000853#ifndef DISABLE_MULTIBUFFER
Benno Schulenbergf470c902014-05-28 21:02:39 +0000854 add_to_funcs(switch_to_prev_buffer_void, MMAIN,
Benno Schulenberge6a4a642014-07-01 18:52:21 +0000855 N_("Prev File"), IFSCHELP(nano_prevfile_msg), TOGETHER, VIEW);
Benno Schulenbergf470c902014-05-28 21:02:39 +0000856 add_to_funcs(switch_to_next_buffer_void, MMAIN,
Benno Schulenberge6a4a642014-07-01 18:52:21 +0000857 N_("Next File"), IFSCHELP(nano_nextfile_msg), BLANKAFTER, VIEW);
Chris Allegrettaa8c22572002-02-15 19:17:02 +0000858#endif
Chris Allegrettab3655b42001-10-22 03:15:31 +0000859
Benno Schulenberg0d5e7322014-05-27 12:17:49 +0000860#if defined(NANO_TINY) && !defined(DISABLE_COLOR)
861 add_to_funcs(do_gotolinecolumn_void, MMAIN|MWHEREIS,
Benno Schulenberge6a4a642014-07-01 18:52:21 +0000862 gotoline_tag, IFSCHELP(nano_gotoline_msg), BLANKAFTER, VIEW);
Benno Schulenberg0d5e7322014-05-27 12:17:49 +0000863#endif
864
Benno Schulenbergf470c902014-05-28 21:02:39 +0000865 add_to_funcs(do_verbatim_input, MMAIN,
Benno Schulenberge6a4a642014-07-01 18:52:21 +0000866 N_("Verbatim"), IFSCHELP(nano_verbatim_msg), TOGETHER, NOVIEW);
Chris Allegrettaaa17df02008-03-17 05:50:04 +0000867
Benno Schulenbergf470c902014-05-28 21:02:39 +0000868 add_to_funcs(do_tab, MMAIN,
Benno Schulenberge6a4a642014-07-01 18:52:21 +0000869 N_("Tab"), IFSCHELP(nano_tab_msg), TOGETHER, NOVIEW);
Benno Schulenbergf470c902014-05-28 21:02:39 +0000870 add_to_funcs(do_enter_void, MMAIN,
Benno Schulenberge6a4a642014-07-01 18:52:21 +0000871 N_("Enter"), IFSCHELP(nano_enter_msg), TOGETHER, NOVIEW);
Benno Schulenbergf470c902014-05-28 21:02:39 +0000872 add_to_funcs(do_delete, MMAIN,
Benno Schulenberge6a4a642014-07-01 18:52:21 +0000873 N_("Delete"), IFSCHELP(nano_delete_msg), TOGETHER, NOVIEW);
Benno Schulenbergf470c902014-05-28 21:02:39 +0000874 add_to_funcs(do_backspace, MMAIN,
875 N_("Backspace"), IFSCHELP(nano_backspace_msg),
David Lawrence Ramseybf487982006-04-24 20:50:52 +0000876#ifndef NANO_TINY
Benno Schulenberge6a4a642014-07-01 18:52:21 +0000877 TOGETHER,
David Lawrence Ramseybf487982006-04-24 20:50:52 +0000878#else
Benno Schulenberge6a4a642014-07-01 18:52:21 +0000879 BLANKAFTER,
David Lawrence Ramseybf487982006-04-24 20:50:52 +0000880#endif
Chris Allegrettaeb643142008-03-12 04:44:14 +0000881 NOVIEW);
882
David Lawrence Ramsey2ca23562006-04-23 19:15:15 +0000883#ifndef NANO_TINY
Benno Schulenberg95e77a92014-06-30 20:39:27 +0000884 add_to_funcs(do_cut_till_eof, MMAIN,
Benno Schulenberge6a4a642014-07-01 18:52:21 +0000885 N_("CutTillEnd"), IFSCHELP(nano_cut_till_eof_msg), BLANKAFTER, NOVIEW);
David Lawrence Ramsey2ca23562006-04-23 19:15:15 +0000886#endif
887
David Lawrence Ramseydb6015c2004-09-11 21:41:13 +0000888#ifndef DISABLE_JUSTIFY
Benno Schulenbergf470c902014-05-28 21:02:39 +0000889 add_to_funcs(do_full_justify, MMAIN,
Benno Schulenberge6a4a642014-07-01 18:52:21 +0000890 fulljustify_tag, IFSCHELP(nano_fulljustify_msg), TOGETHER, NOVIEW);
David Lawrence Ramseydb6015c2004-09-11 21:41:13 +0000891#endif
892
David Lawrence Ramseyc5c52302005-11-15 23:45:29 +0000893#ifndef NANO_TINY
Benno Schulenbergf470c902014-05-28 21:02:39 +0000894 add_to_funcs(do_wordlinechar_count, MMAIN,
Benno Schulenberge6a4a642014-07-01 18:52:21 +0000895 N_("Word Count"), IFSCHELP(nano_wordcount_msg), TOGETHER, VIEW);
David Lawrence Ramsey1df3e2d2006-04-22 19:45:26 +0000896#endif
David Lawrence Ramseyefb4b0a2006-04-19 14:09:01 +0000897
Benno Schulenbergf470c902014-05-28 21:02:39 +0000898 add_to_funcs(total_refresh, MMAIN,
Benno Schulenberge6a4a642014-07-01 18:52:21 +0000899 refresh_tag, IFSCHELP(nano_refresh_msg), TOGETHER, VIEW);
Chris Allegretta0018d8e2008-03-13 08:23:52 +0000900
Benno Schulenbergf470c902014-05-28 21:02:39 +0000901 add_to_funcs(do_suspend_void, MMAIN,
Benno Schulenberge6a4a642014-07-01 18:52:21 +0000902 N_("Suspend"), IFSCHELP(nano_suspend_msg), BLANKAFTER, VIEW);
David Lawrence Ramsey8faf3052003-09-04 20:25:29 +0000903
Benno Schulenbergb341f292014-06-19 20:05:24 +0000904#ifndef DISABLE_HISTORIES
Chris Allegretta637daa82011-02-07 14:45:56 +0000905 add_to_funcs(get_history_older_void,
Benno Schulenberge167afe2014-04-16 09:26:15 +0000906 (MWHEREIS|MREPLACE|MREPLACEWITH|MWHEREISFILE),
Benno Schulenberge6a4a642014-07-01 18:52:21 +0000907 N_("PrevHstory"), IFSCHELP(nano_prev_history_msg), TOGETHER, VIEW);
Chris Allegretta637daa82011-02-07 14:45:56 +0000908 add_to_funcs(get_history_newer_void,
Benno Schulenberge167afe2014-04-16 09:26:15 +0000909 (MWHEREIS|MREPLACE|MREPLACEWITH|MWHEREISFILE),
Benno Schulenberge6a4a642014-07-01 18:52:21 +0000910 N_("NextHstory"), IFSCHELP(nano_next_history_msg), TOGETHER, VIEW);
David Lawrence Ramseyc10d8ff2005-06-03 20:51:39 +0000911#endif
David Lawrence Ramsey02085d72004-11-07 16:04:18 +0000912
Chris Allegretta637daa82011-02-07 14:45:56 +0000913 add_to_funcs(gototext_void, MGOTOLINE,
Benno Schulenberge6a4a642014-07-01 18:52:21 +0000914 N_("Go To Text"), IFSCHELP(nano_whereis_msg), BLANKAFTER, VIEW);
David Lawrence Ramsey576bf332004-07-12 03:10:30 +0000915
David Lawrence Ramseyebe34252005-11-15 03:17:35 +0000916#ifndef NANO_TINY
David Lawrence Ramsey32e3b882004-05-29 01:20:17 +0000917 /* If we're using restricted mode, the DOS format, Mac format,
918 * append, prepend, and backup toggles are disabled. The first and
919 * second are useless since inserting files is disabled, the third
920 * and fourth are disabled because they allow writing to files not
921 * specified on the command line, and the fifth is useless since
922 * backups are disabled. */
Benno Schulenberg91ee10a2014-03-27 21:35:18 +0000923 if (!ISSET(RESTRICTED)) {
Chris Allegretta637daa82011-02-07 14:45:56 +0000924 add_to_funcs(dos_format_void, MWRITEFILE,
Benno Schulenberge6a4a642014-07-01 18:52:21 +0000925 N_("DOS Format"), IFSCHELP(nano_dos_msg), TOGETHER, NOVIEW);
Chris Allegrettaa8c22572002-02-15 19:17:02 +0000926
Chris Allegretta637daa82011-02-07 14:45:56 +0000927 add_to_funcs(mac_format_void, MWRITEFILE,
Benno Schulenberge6a4a642014-07-01 18:52:21 +0000928 N_("Mac Format"), IFSCHELP(nano_mac_msg), TOGETHER, NOVIEW);
Chris Allegrettaa8c22572002-02-15 19:17:02 +0000929
Benno Schulenberge34ac8e2014-03-17 12:15:23 +0000930 add_to_funcs(append_void, MWRITEFILE,
Benno Schulenberge6a4a642014-07-01 18:52:21 +0000931 N_("Append"), IFSCHELP(nano_append_msg), TOGETHER, NOVIEW);
Benno Schulenberge34ac8e2014-03-17 12:15:23 +0000932 add_to_funcs(prepend_void, MWRITEFILE,
Benno Schulenberge6a4a642014-07-01 18:52:21 +0000933 N_("Prepend"), IFSCHELP(nano_prepend_msg), TOGETHER, NOVIEW);
Chris Allegretta0e9b7aa2002-04-16 03:15:47 +0000934
Benno Schulenberge34ac8e2014-03-17 12:15:23 +0000935 add_to_funcs(backup_file_void, MWRITEFILE,
Benno Schulenberge6a4a642014-07-01 18:52:21 +0000936 N_("Backup File"), IFSCHELP(nano_backup_msg), TOGETHER, NOVIEW);
Benno Schulenberg91ee10a2014-03-27 21:35:18 +0000937 }
David Lawrence Ramseya593f532003-11-28 19:47:42 +0000938
Benno Schulenberg91ee10a2014-03-27 21:35:18 +0000939 /* If we're using restricted mode, file insertion is disabled, and
940 * thus command execution and the multibuffer toggle have no place. */
941 if (!ISSET(RESTRICTED)) {
Benno Schulenberg04a38da2014-06-04 19:15:16 +0000942 add_to_funcs(flip_execute_void, MINSERTFILE,
Benno Schulenberge6a4a642014-07-01 18:52:21 +0000943 N_("Execute Command"), IFSCHELP(nano_execute_msg), TOGETHER, NOVIEW);
David Lawrence Ramseya593f532003-11-28 19:47:42 +0000944
Benno Schulenberg04a38da2014-06-04 19:15:16 +0000945 add_to_funcs(flip_execute_void, MEXTCMD,
Benno Schulenberge6a4a642014-07-01 18:52:21 +0000946 read_file_tag, IFSCHELP(nano_insert_msg), TOGETHER, NOVIEW);
Benno Schulenbergff6b92c2014-05-28 15:35:00 +0000947
Benno Schulenberg0636d7b2014-04-03 20:23:07 +0000948#ifndef DISABLE_MULTIBUFFER
Benno Schulenberg91ee10a2014-03-27 21:35:18 +0000949 add_to_funcs(new_buffer_void, MINSERTFILE|MEXTCMD,
Benno Schulenberge6a4a642014-07-01 18:52:21 +0000950 N_("New Buffer"), IFSCHELP(nano_multibuffer_msg), TOGETHER, NOVIEW);
David Lawrence Ramseye21adfa2002-09-13 18:14:04 +0000951#endif
Benno Schulenberg91ee10a2014-03-27 21:35:18 +0000952 }
Benno Schulenberge4c34c32014-03-17 14:15:57 +0000953#endif /* !NANO_TINY */
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000954
Rocco Corsiaf5c3022001-01-12 07:51:05 +0000955#ifndef DISABLE_BROWSER
Benno Schulenberg63716122014-04-27 19:51:03 +0000956 if (!ISSET(RESTRICTED))
957 add_to_funcs(to_files_void, MWRITEFILE|MINSERTFILE,
Benno Schulenberge6a4a642014-07-01 18:52:21 +0000958 N_("To Files"), IFSCHELP(nano_tofiles_msg), TOGETHER, VIEW);
Benno Schulenberg63716122014-04-27 19:51:03 +0000959
Benno Schulenberge34ac8e2014-03-17 12:15:23 +0000960 add_to_funcs(do_first_file, (MBROWSER|MWHEREISFILE),
Benno Schulenberge6a4a642014-07-01 18:52:21 +0000961 N_("First File"), IFSCHELP(nano_firstfile_msg), TOGETHER, VIEW);
Benno Schulenberge34ac8e2014-03-17 12:15:23 +0000962 add_to_funcs(do_last_file, (MBROWSER|MWHEREISFILE),
Benno Schulenberge6a4a642014-07-01 18:52:21 +0000963 N_("Last File"), IFSCHELP(nano_lastfile_msg), TOGETHER, VIEW);
Benno Schulenberg63716122014-04-27 19:51:03 +0000964#endif
Chris Allegrettab3655b42001-10-22 03:15:31 +0000965
Benno Schulenberg63716122014-04-27 19:51:03 +0000966#if !defined(NANO_TINY) && !defined(DISABLE_BROWSER)
Benno Schulenbergf470c902014-05-28 21:02:39 +0000967 add_to_funcs(do_research, MBROWSER,
Benno Schulenberge6a4a642014-07-01 18:52:21 +0000968 whereis_next_tag, IFSCHELP(nano_whereis_next_msg), TOGETHER, VIEW);
Benno Schulenberg63716122014-04-27 19:51:03 +0000969#endif
970
971#ifndef DISABLE_COLOR
Benno Schulenberg48223592014-05-28 19:02:00 +0000972 /* TRANSLATORS: Try to keep the next two strings at most 20 characters. */
Benno Schulenberg63716122014-04-27 19:51:03 +0000973 add_to_funcs(do_page_up, MLINTER,
Benno Schulenberge6a4a642014-07-01 18:52:21 +0000974 N_("Prev Lint Msg"), IFSCHELP(nano_prevlint_msg), TOGETHER, VIEW);
Benno Schulenberg63716122014-04-27 19:51:03 +0000975 add_to_funcs(do_page_down, MLINTER,
Benno Schulenberge6a4a642014-07-01 18:52:21 +0000976 N_("Next Lint Msg"), IFSCHELP(nano_nextlint_msg), TOGETHER, VIEW);
David Lawrence Ramseye38b8082006-03-30 07:03:04 +0000977#endif
978
Benno Schulenbergf803ef52014-04-13 12:16:37 +0000979 /* Start associating key combos with functions in specific menus. */
980
Benno Schulenbergd4623f32014-06-28 14:42:18 +0000981 add_to_sclist(MMOST, "^G", do_help_void, 0);
982 add_to_sclist(MMOST, "F1", do_help_void, 0);
983 add_to_sclist(MMAIN|MHELP|MBROWSER, "^X", do_exit, 0);
984 add_to_sclist(MMAIN|MHELP|MBROWSER, "F2", do_exit, 0);
985 add_to_sclist(MMAIN, "^O", do_writeout_void, 0);
986 add_to_sclist(MMAIN, "F3", do_writeout_void, 0);
987 add_to_sclist(MMAIN, "^R", do_insertfile_void, 0);
988 add_to_sclist(MMAIN, "F5", do_insertfile_void, 0);
989 add_to_sclist(MMAIN, "Ins", do_insertfile_void, 0);
990 add_to_sclist(MMAIN|MBROWSER, "^W", do_search, 0);
991 add_to_sclist(MMAIN|MBROWSER, "F6", do_search, 0);
992 add_to_sclist(MMAIN, "^\\", do_replace, 0);
993 add_to_sclist(MMAIN, "M-R", do_replace, 0);
994 add_to_sclist(MMAIN, "F14", do_replace, 0);
995 add_to_sclist(MMOST, "^K", do_cut_text_void, 0);
996 add_to_sclist(MMOST, "F9", do_cut_text_void, 0);
997 add_to_sclist(MMAIN, "^U", do_uncut_text, 0);
998 add_to_sclist(MMAIN, "F10", do_uncut_text, 0);
Benno Schulenberg523598a2014-05-03 19:19:31 +0000999#ifndef DISABLE_JUSTIFY
Benno Schulenbergd4623f32014-06-28 14:42:18 +00001000 add_to_sclist(MMAIN, "^J", do_justify_void, 0);
1001 add_to_sclist(MMAIN, "F4", do_justify_void, 0);
Benno Schulenberg523598a2014-05-03 19:19:31 +00001002#endif
1003#ifndef DISABLE_SPELLER
Benno Schulenbergd4623f32014-06-28 14:42:18 +00001004 add_to_sclist(MMAIN, "^T", do_spell, 0);
1005 add_to_sclist(MMAIN, "F12", do_spell, 0);
Benno Schulenberg387b2092014-05-09 15:14:29 +00001006#else
1007#ifndef DISABLE_COLOR
Benno Schulenbergd4623f32014-06-28 14:42:18 +00001008 add_to_sclist(MMAIN, "^T", do_linter, 0);
1009 add_to_sclist(MMAIN, "F12", do_linter, 0);
Benno Schulenberg387b2092014-05-09 15:14:29 +00001010#endif
Benno Schulenberg523598a2014-05-03 19:19:31 +00001011#endif
Benno Schulenbergd4623f32014-06-28 14:42:18 +00001012 add_to_sclist(MMAIN, "^C", do_cursorpos_void, 0);
1013 add_to_sclist(MMAIN, "F11", do_cursorpos_void, 0);
1014 add_to_sclist(MMAIN, "^_", do_gotolinecolumn_void, 0);
1015 add_to_sclist(MMAIN, "M-G", do_gotolinecolumn_void, 0);
1016 add_to_sclist(MMAIN, "F13", do_gotolinecolumn_void, 0);
1017 add_to_sclist(MMAIN|MBROWSER|MHELP|MWHEREISFILE|MLINTER, "^Y", do_page_up, 0);
1018 add_to_sclist(MMAIN|MBROWSER|MHELP|MWHEREISFILE|MLINTER, "F7", do_page_up, 0);
1019 add_to_sclist(MMAIN|MBROWSER|MHELP|MWHEREISFILE|MLINTER, "PgUp", do_page_up, 0);
1020 add_to_sclist(MMAIN|MBROWSER|MHELP|MWHEREISFILE|MLINTER, "^V", do_page_down, 0);
1021 add_to_sclist(MMAIN|MBROWSER|MHELP|MWHEREISFILE|MLINTER, "F8", do_page_down, 0);
1022 add_to_sclist(MMAIN|MBROWSER|MHELP|MWHEREISFILE|MLINTER, "PgDn", do_page_down, 0);
1023 add_to_sclist(MMAIN|MHELP, "M-\\", do_first_line, 0);
1024 add_to_sclist(MMAIN|MHELP, "M-|", do_first_line, 0);
1025 add_to_sclist(MMAIN|MHELP, "M-/", do_last_line, 0);
1026 add_to_sclist(MMAIN|MHELP, "M-?", do_last_line, 0);
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001027#ifndef NANO_TINY
Benno Schulenbergd4623f32014-06-28 14:42:18 +00001028 add_to_sclist(MMAIN|MBROWSER, "M-W", do_research, 0);
1029 add_to_sclist(MMAIN|MBROWSER, "F16", do_research, 0);
1030 add_to_sclist(MMAIN, "M-]", do_find_bracket, 0);
1031 add_to_sclist(MMAIN, "^^", do_mark, 0);
1032 add_to_sclist(MMAIN, "M-A", do_mark, 0);
1033 add_to_sclist(MMAIN, "F15", do_mark, 0);
1034 add_to_sclist(MMAIN, "M-^", do_copy_text, 0);
1035 add_to_sclist(MMAIN, "M-6", do_copy_text, 0);
1036 add_to_sclist(MMAIN, "M-}", do_indent_void, 0);
1037 add_to_sclist(MMAIN, "M-{", do_unindent, 0);
1038 add_to_sclist(MMAIN, "M-U", do_undo, 0);
1039 add_to_sclist(MMAIN, "M-E", do_redo, 0);
Benno Schulenbergc3e4a1f2014-03-17 11:47:49 +00001040#endif
Benno Schulenbergd4623f32014-06-28 14:42:18 +00001041 add_to_sclist(MMOST, "^B", do_left, 0);
1042 add_to_sclist(MMOST, "Left", do_left, 0);
1043 add_to_sclist(MMOST, "^F", do_right, 0);
1044 add_to_sclist(MMOST, "Right", do_right, 0);
Benno Schulenbergc3e4a1f2014-03-17 11:47:49 +00001045#ifndef NANO_TINY
Benno Schulenbergd4623f32014-06-28 14:42:18 +00001046 add_to_sclist(MMOST, "M-Space", do_prev_word_void, 0);
1047 add_to_sclist(MMOST, "^Space", do_next_word_void, 0);
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001048#endif
Benno Schulenbergd4623f32014-06-28 14:42:18 +00001049 add_to_sclist(MMOST, "^A", do_home, 0);
1050 add_to_sclist(MMOST, "Home", do_home, 0);
1051 add_to_sclist(MMOST, "^E", do_end, 0);
1052 add_to_sclist(MMOST, "End", do_end, 0);
1053 add_to_sclist(MMAIN|MHELP|MBROWSER, "^P", do_up_void, 0);
1054 add_to_sclist(MMAIN|MHELP|MBROWSER, "Up", do_up_void, 0);
1055 add_to_sclist(MMAIN|MHELP|MBROWSER, "^N", do_down_void, 0);
1056 add_to_sclist(MMAIN|MHELP|MBROWSER, "Down", do_down_void, 0);
Benno Schulenberg523598a2014-05-03 19:19:31 +00001057#ifndef DISABLE_JUSTIFY
Benno Schulenbergd4623f32014-06-28 14:42:18 +00001058 add_to_sclist(MMAIN, "M-(", do_para_begin_void, 0);
1059 add_to_sclist(MMAIN, "M-9", do_para_begin_void, 0);
1060 add_to_sclist(MMAIN, "M-)", do_para_end_void, 0);
1061 add_to_sclist(MMAIN, "M-0", do_para_end_void, 0);
Benno Schulenberg523598a2014-05-03 19:19:31 +00001062#endif
1063#ifndef NANO_TINY
Benno Schulenbergd4623f32014-06-28 14:42:18 +00001064 add_to_sclist(MMAIN, "M--", do_scroll_up, 0);
1065 add_to_sclist(MMAIN, "M-_", do_scroll_up, 0);
1066 add_to_sclist(MMAIN, "M-+", do_scroll_down, 0);
1067 add_to_sclist(MMAIN, "M-=", do_scroll_down, 0);
Benno Schulenberg523598a2014-05-03 19:19:31 +00001068#endif
1069#ifndef DISABLE_MULTIBUFFER
Benno Schulenbergd4623f32014-06-28 14:42:18 +00001070 add_to_sclist(MMAIN, "M-<", switch_to_prev_buffer_void, 0);
1071 add_to_sclist(MMAIN, "M-,", switch_to_prev_buffer_void, 0);
1072 add_to_sclist(MMAIN, "M->", switch_to_next_buffer_void, 0);
1073 add_to_sclist(MMAIN, "M-.", switch_to_next_buffer_void, 0);
Benno Schulenberg523598a2014-05-03 19:19:31 +00001074#endif
Benno Schulenbergd4623f32014-06-28 14:42:18 +00001075 add_to_sclist(MMOST, "M-V", do_verbatim_input, 0);
Benno Schulenberg523598a2014-05-03 19:19:31 +00001076#ifndef NANO_TINY
Benno Schulenberg95e77a92014-06-30 20:39:27 +00001077 add_to_sclist(MMAIN, "M-T", do_cut_till_eof, 0);
Benno Schulenbergd4623f32014-06-28 14:42:18 +00001078 add_to_sclist(MMAIN, "M-D", do_wordlinechar_count, 0);
Benno Schulenberg523598a2014-05-03 19:19:31 +00001079#endif
1080#ifndef DISABLE_JUSTIFY
Benno Schulenbergd4623f32014-06-28 14:42:18 +00001081 add_to_sclist(MMAIN|MWHEREIS, "M-J", do_full_justify, 0);
Benno Schulenberg523598a2014-05-03 19:19:31 +00001082#endif
Benno Schulenbergd4623f32014-06-28 14:42:18 +00001083 add_to_sclist(MMAIN|MHELP, "^L", total_refresh, 0);
1084 add_to_sclist(MMAIN, "^Z", do_suspend_void, 0);
Benno Schulenberg523598a2014-05-03 19:19:31 +00001085
1086#ifndef NANO_TINY
Benno Schulenberga6804b52014-05-09 20:33:49 +00001087 /* Group of "Appearance" toggles. */
Benno Schulenbergd4623f32014-06-28 14:42:18 +00001088 add_to_sclist(MMAIN, "M-X", do_toggle_void, NO_HELP);
1089 add_to_sclist(MMAIN, "M-C", do_toggle_void, CONST_UPDATE);
1090 add_to_sclist(MMAIN, "M-O", do_toggle_void, MORE_SPACE);
1091 add_to_sclist(MMAIN, "M-S", do_toggle_void, SMOOTH_SCROLL);
1092 add_to_sclist(MMAIN, "M-$", do_toggle_void, SOFTWRAP);
1093 add_to_sclist(MMAIN, "M-P", do_toggle_void, WHITESPACE_DISPLAY);
Benno Schulenbergd16f9af2014-05-09 12:20:20 +00001094#ifndef DISABLE_COLOR
Benno Schulenbergd4623f32014-06-28 14:42:18 +00001095 add_to_sclist(MMAIN, "M-Y", do_toggle_void, NO_COLOR_SYNTAX);
Benno Schulenbergd16f9af2014-05-09 12:20:20 +00001096#endif
Benno Schulenberg523598a2014-05-03 19:19:31 +00001097
Benno Schulenberga6804b52014-05-09 20:33:49 +00001098 /* Group of "Editing-behavior" toggles. */
Benno Schulenbergd4623f32014-06-28 14:42:18 +00001099 add_to_sclist(MMAIN, "M-H", do_toggle_void, SMART_HOME);
1100 add_to_sclist(MMAIN, "M-I", do_toggle_void, AUTOINDENT);
1101 add_to_sclist(MMAIN, "M-K", do_toggle_void, CUT_TO_END);
Benno Schulenbergd16f9af2014-05-09 12:20:20 +00001102#ifndef DISABLE_WRAPPING
Benno Schulenbergd4623f32014-06-28 14:42:18 +00001103 add_to_sclist(MMAIN, "M-L", do_toggle_void, NO_WRAP);
Benno Schulenbergd16f9af2014-05-09 12:20:20 +00001104#endif
Benno Schulenbergd4623f32014-06-28 14:42:18 +00001105 add_to_sclist(MMAIN, "M-Q", do_toggle_void, TABS_TO_SPACES);
Benno Schulenberg523598a2014-05-03 19:19:31 +00001106
Benno Schulenberga6804b52014-05-09 20:33:49 +00001107 /* Group of "Peripheral-feature" toggles. */
Benno Schulenbergd4623f32014-06-28 14:42:18 +00001108 add_to_sclist(MMAIN, "M-B", do_toggle_void, BACKUP_FILE);
Benno Schulenbergd16f9af2014-05-09 12:20:20 +00001109#ifndef DISABLE_MULTIBUFFER
Benno Schulenbergd4623f32014-06-28 14:42:18 +00001110 add_to_sclist(MMAIN, "M-F", do_toggle_void, MULTIBUFFER);
Benno Schulenbergd16f9af2014-05-09 12:20:20 +00001111#endif
1112#ifndef DISABLE_MOUSE
Benno Schulenbergd4623f32014-06-28 14:42:18 +00001113 add_to_sclist(MMAIN, "M-M", do_toggle_void, USE_MOUSE);
Benno Schulenbergd16f9af2014-05-09 12:20:20 +00001114#endif
Benno Schulenbergd4623f32014-06-28 14:42:18 +00001115 add_to_sclist(MMAIN, "M-N", do_toggle_void, NO_CONVERT);
1116 add_to_sclist(MMAIN, "M-Z", do_toggle_void, SUSPEND);
Benno Schulenberg523598a2014-05-03 19:19:31 +00001117#endif /* !NANO_TINY */
1118
Benno Schulenbergd4623f32014-06-28 14:42:18 +00001119 add_to_sclist(MMAIN, "^Q", xon_complaint, 0);
1120 add_to_sclist(MMAIN, "^S", xoff_complaint, 0);
Benno Schulenberg523598a2014-05-03 19:19:31 +00001121
Benno Schulenbergd4623f32014-06-28 14:42:18 +00001122 add_to_sclist(((MMOST & ~MMAIN & ~MBROWSER) | MYESNO), "^C", do_cancel, 0);
Benno Schulenberg523598a2014-05-03 19:19:31 +00001123
Benno Schulenberg8c5f5042014-05-28 20:31:06 +00001124#ifndef NANO_TINY
Benno Schulenbergb0957252014-07-01 16:24:01 +00001125 add_to_sclist(MWHEREIS|MREPLACE, "M-B", backwards_void, 0);
1126 add_to_sclist(MWHEREIS|MREPLACE, "M-C", case_sens_void, 0);
Benno Schulenberg8c5f5042014-05-28 20:31:06 +00001127#endif
Benno Schulenbergb0957252014-07-01 16:24:01 +00001128 add_to_sclist(MWHEREIS|MREPLACE, "M-R", regexp_void, 0);
Benno Schulenbergd4623f32014-06-28 14:42:18 +00001129 add_to_sclist(MWHEREIS|MREPLACE, "^R", flip_replace_void, 0);
1130 add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH|MGOTOLINE, "^Y", do_first_line, 0);
1131 add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH|MGOTOLINE, "^V", do_last_line, 0);
Benno Schulenberg523598a2014-05-03 19:19:31 +00001132#ifndef DISABLE_JUSTIFY
Benno Schulenbergd4623f32014-06-28 14:42:18 +00001133 add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH, "^W", do_para_begin_void, 0);
1134 add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH, "^O", do_para_end_void, 0);
Benno Schulenberg523598a2014-05-03 19:19:31 +00001135#endif
Benno Schulenbergd4623f32014-06-28 14:42:18 +00001136 add_to_sclist(MWHEREIS, "^T", do_gotolinecolumn_void, 0);
1137 add_to_sclist(MGOTOLINE, "^T", gototext_void, 0);
Benno Schulenbergb341f292014-06-19 20:05:24 +00001138#ifndef DISABLE_HISTORIES
Benno Schulenbergd4623f32014-06-28 14:42:18 +00001139 add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH|MWHEREISFILE, "^P", get_history_older_void, 0);
1140 add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH|MWHEREISFILE, "Up", get_history_older_void, 0);
1141 add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH|MWHEREISFILE, "^N", get_history_newer_void, 0);
1142 add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH|MWHEREISFILE, "Down", get_history_newer_void, 0);
Chris Allegretta1b6ed072008-06-03 08:09:05 +00001143#endif
Chris Allegretta637daa82011-02-07 14:45:56 +00001144#ifndef DISABLE_BROWSER
Benno Schulenbergd4623f32014-06-28 14:42:18 +00001145 add_to_sclist(MBROWSER|MWHEREISFILE, "M-\\", do_first_file, 0);
1146 add_to_sclist(MBROWSER|MWHEREISFILE, "M-|", do_first_file, 0);
1147 add_to_sclist(MBROWSER|MWHEREISFILE, "M-/", do_last_file, 0);
1148 add_to_sclist(MBROWSER|MWHEREISFILE, "M-?", do_last_file, 0);
1149 add_to_sclist(MBROWSER|MWHEREISFILE, "^_", goto_dir_void, 0);
1150 add_to_sclist(MBROWSER|MWHEREISFILE, "M-G", goto_dir_void, 0);
1151 add_to_sclist(MBROWSER|MWHEREISFILE, "F13", goto_dir_void, 0);
Benno Schulenberge34ac8e2014-03-17 12:15:23 +00001152#endif
Benno Schulenbergd4623f32014-06-28 14:42:18 +00001153 add_to_sclist(MWRITEFILE, "M-D", dos_format_void, 0);
1154 add_to_sclist(MWRITEFILE, "M-M", mac_format_void, 0);
1155 add_to_sclist(MWRITEFILE, "M-A", append_void, 0);
1156 add_to_sclist(MWRITEFILE, "M-P", prepend_void, 0);
1157 add_to_sclist(MWRITEFILE, "M-B", backup_file_void, 0);
Benno Schulenbergd1238c02014-05-13 20:51:19 +00001158#ifndef DISABLE_BROWSER
Benno Schulenbergd4623f32014-06-28 14:42:18 +00001159 add_to_sclist(MWRITEFILE|MINSERTFILE, "^T", to_files_void, 0);
Benno Schulenbergd1238c02014-05-13 20:51:19 +00001160#endif
Benno Schulenbergd4623f32014-06-28 14:42:18 +00001161 add_to_sclist(MINSERTFILE|MEXTCMD, "^X", flip_execute_void, 0);
1162 add_to_sclist(MINSERTFILE|MEXTCMD, "M-F", new_buffer_void, 0);
1163 add_to_sclist(MHELP|MBROWSER, "^C", do_exit, 0);
Benno Schulenberg8c5f5042014-05-28 20:31:06 +00001164#ifndef DISABLE_HELP
Benno Schulenbergd4623f32014-06-28 14:42:18 +00001165 add_to_sclist(MHELP, "^G", do_exit, 0);
Benno Schulenberg8c5f5042014-05-28 20:31:06 +00001166#endif
Benno Schulenbergd4623f32014-06-28 14:42:18 +00001167 add_to_sclist(MMOST, "^I", do_tab, 0);
1168 add_to_sclist(MMOST, "^M", do_enter_void, 0);
1169 add_to_sclist(MMOST, "Enter", do_enter_void, 0);
1170 add_to_sclist(MMOST, "^D", do_delete, 0);
1171 add_to_sclist(MMOST, "Del", do_delete, 0);
1172 add_to_sclist(MMOST, "^H", do_backspace, 0);
1173 add_to_sclist(MMOST, "Bsp", do_backspace, 0);
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001174
1175#ifdef DEBUG
1176 print_sclist();
1177#endif
Chris Allegrettadab017e2002-04-23 10:56:06 +00001178}
Chris Allegrettaf5de33a2002-02-27 04:14:16 +00001179
Benno Schulenberg00389922014-04-04 11:59:03 +00001180#ifndef DISABLE_COLOR
Chris Allegretta5575bfa2014-02-24 10:18:15 +00001181void set_lint_shortcuts(void)
1182{
1183#ifndef DISABLE_SPELLER
1184 replace_scs_for(do_spell, do_linter);
1185#endif
1186}
1187
1188void set_spell_shortcuts(void)
1189{
1190#ifndef DISABLE_SPELLER
1191 replace_scs_for(do_linter, do_spell);
1192#endif
1193}
1194#endif
1195
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001196const subnfunc *sctofunc(sc *s)
David Lawrence Ramsey576bf332004-07-12 03:10:30 +00001197{
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001198 subnfunc *f;
David Lawrence Ramsey576bf332004-07-12 03:10:30 +00001199
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001200 for (f = allfuncs; f != NULL && s->scfunc != f->scfunc; f = f->next)
1201 ;
1202
1203 return f;
1204}
1205
1206#ifndef NANO_TINY
Benno Schulenbergd19be5a2014-04-08 18:38:45 +00001207/* Now let's come up with a single (hopefully) function to get a string
1208 * for each flag. */
Chris Allegretta5a018f02009-11-29 06:13:22 +00001209const char *flagtostr(int flag)
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001210{
Benno Schulenberg492e9f62014-06-20 10:48:26 +00001211 switch (flag) {
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001212 case NO_HELP:
Benno Schulenbergc8b60ce2014-04-22 11:57:11 +00001213 /* TRANSLATORS: The next seventeen strings are toggle descriptions;
1214 * they are best kept shorter than 40 characters, but may be longer. */
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001215 return N_("Help mode");
1216 case CONST_UPDATE:
1217 return N_("Constant cursor position display");
1218 case MORE_SPACE:
1219 return N_("Use of one more line for editing");
1220 case SMOOTH_SCROLL:
1221 return N_("Smooth scrolling");
Benno Schulenberga6804b52014-05-09 20:33:49 +00001222 case SOFTWRAP:
1223 return N_("Soft wrapping of overlong lines");
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001224 case WHITESPACE_DISPLAY:
1225 return N_("Whitespace display");
1226 case NO_COLOR_SYNTAX:
1227 return N_("Color syntax highlighting");
1228 case SMART_HOME:
1229 return N_("Smart home key");
1230 case AUTOINDENT:
1231 return N_("Auto indent");
1232 case CUT_TO_END:
1233 return N_("Cut to end");
1234 case NO_WRAP:
Benno Schulenberg9df76722014-04-23 20:37:32 +00001235 return N_("Hard wrapping of overlong lines");
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001236 case TABS_TO_SPACES:
1237 return N_("Conversion of typed tabs to spaces");
1238 case BACKUP_FILE:
1239 return N_("Backup files");
1240 case MULTIBUFFER:
1241 return N_("Multiple file buffers");
1242 case USE_MOUSE:
1243 return N_("Mouse support");
1244 case NO_CONVERT:
1245 return N_("No conversion from DOS/Mac format");
1246 case SUSPEND:
1247 return N_("Suspension");
1248 default:
1249 return "?????";
1250 }
1251}
Benno Schulenberge4c34c32014-03-17 14:15:57 +00001252#endif /* !NANO_TINY */
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001253
Benno Schulenberg353dd212014-05-25 19:47:46 +00001254#ifndef DISABLE_NANORC
Benno Schulenberg1f934e32014-04-13 11:56:08 +00001255/* Interpret a function string given in the rc file, and return a
Benno Schulenbergd4623f32014-06-28 14:42:18 +00001256 * shortcut struct with the corresponding function filled in. */
Benno Schulenberg1f934e32014-04-13 11:56:08 +00001257sc *strtosc(char *input)
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001258{
Benno Schulenberg1f934e32014-04-13 11:56:08 +00001259 sc *s;
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001260
1261 s = (sc *)nmalloc(sizeof(sc));
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001262
Chris Allegrettae347efb2008-03-09 02:52:40 +00001263#ifndef DISABLE_HELP
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001264 if (!strcasecmp(input, "help"))
Chris Allegretta637daa82011-02-07 14:45:56 +00001265 s->scfunc = do_help_void;
1266 else
Chris Allegrettae347efb2008-03-09 02:52:40 +00001267#endif
Benno Schulenbergd48d84a2014-06-28 15:34:10 +00001268 if (!strcasecmp(input, "cancel"))
Chris Allegretta637daa82011-02-07 14:45:56 +00001269 s->scfunc = do_cancel;
Benno Schulenbergd48d84a2014-06-28 15:34:10 +00001270 else if (!strcasecmp(input, "exit"))
Chris Allegretta637daa82011-02-07 14:45:56 +00001271 s->scfunc = do_exit;
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001272 else if (!strcasecmp(input, "writeout"))
Chris Allegretta637daa82011-02-07 14:45:56 +00001273 s->scfunc = do_writeout_void;
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001274 else if (!strcasecmp(input, "insert"))
Chris Allegretta637daa82011-02-07 14:45:56 +00001275 s->scfunc = do_insertfile_void;
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001276 else if (!strcasecmp(input, "whereis"))
Chris Allegretta637daa82011-02-07 14:45:56 +00001277 s->scfunc = do_search;
Benno Schulenberg5f655da2014-04-27 15:26:25 +00001278#ifndef NANO_TINY
Benno Schulenberg618051c2014-04-26 20:16:17 +00001279 else if (!strcasecmp(input, "searchagain") ||
1280 !strcasecmp(input, "research"))
1281 s->scfunc = do_research;
Benno Schulenberg5f655da2014-04-27 15:26:25 +00001282#endif
Benno Schulenberg618051c2014-04-26 20:16:17 +00001283 else if (!strcasecmp(input, "replace"))
1284 s->scfunc = do_replace;
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001285 else if (!strcasecmp(input, "cut"))
Chris Allegretta637daa82011-02-07 14:45:56 +00001286 s->scfunc = do_cut_text_void;
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001287 else if (!strcasecmp(input, "uncut"))
Chris Allegretta637daa82011-02-07 14:45:56 +00001288 s->scfunc = do_uncut_text;
Benno Schulenberg5f655da2014-04-27 15:26:25 +00001289#ifndef NANO_TINY
Benno Schulenbergf8507bb2014-05-05 19:54:34 +00001290 else if (!strcasecmp(input, "cutrestoffile"))
Benno Schulenberg95e77a92014-06-30 20:39:27 +00001291 s->scfunc = do_cut_till_eof;
Benno Schulenberg5f655da2014-04-27 15:26:25 +00001292 else if (!strcasecmp(input, "copytext"))
1293 s->scfunc = do_copy_text;
Benno Schulenberg618051c2014-04-26 20:16:17 +00001294 else if (!strcasecmp(input, "mark"))
1295 s->scfunc = do_mark;
Benno Schulenberg387b2092014-05-09 15:14:29 +00001296#endif
1297#ifndef DISABLE_SPELLER
Benno Schulenberg301c4ef2014-04-26 19:33:11 +00001298 else if (!strcasecmp(input, "tospell") ||
1299 !strcasecmp(input, "speller"))
1300 s->scfunc = do_spell;
Benno Schulenberg5f655da2014-04-27 15:26:25 +00001301#endif
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001302 else if (!strcasecmp(input, "curpos") ||
Benno Schulenberg3aea69d2014-02-28 20:08:59 +00001303 !strcasecmp(input, "cursorpos"))
Chris Allegretta637daa82011-02-07 14:45:56 +00001304 s->scfunc = do_cursorpos_void;
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001305 else if (!strcasecmp(input, "gotoline"))
Chris Allegretta637daa82011-02-07 14:45:56 +00001306 s->scfunc = do_gotolinecolumn_void;
Chris Allegrettac656e9d2008-03-16 12:55:41 +00001307#ifndef DISABLE_JUSTIFY
Chris Allegrettae347efb2008-03-09 02:52:40 +00001308 else if (!strcasecmp(input, "justify"))
Chris Allegretta637daa82011-02-07 14:45:56 +00001309 s->scfunc = do_justify_void;
Benno Schulenberg618051c2014-04-26 20:16:17 +00001310 else if (!strcasecmp(input, "fulljustify"))
1311 s->scfunc = do_full_justify;
Chris Allegrettac656e9d2008-03-16 12:55:41 +00001312 else if (!strcasecmp(input, "beginpara"))
Chris Allegretta637daa82011-02-07 14:45:56 +00001313 s->scfunc = do_para_begin_void;
Chris Allegrettac656e9d2008-03-16 12:55:41 +00001314 else if (!strcasecmp(input, "endpara"))
Chris Allegretta637daa82011-02-07 14:45:56 +00001315 s->scfunc = do_para_end_void;
Chris Allegrettac656e9d2008-03-16 12:55:41 +00001316#endif
1317#ifndef NANO_TINY
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001318 else if (!strcasecmp(input, "indent"))
Chris Allegretta637daa82011-02-07 14:45:56 +00001319 s->scfunc = do_indent_void;
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001320 else if (!strcasecmp(input, "unindent"))
Chris Allegretta637daa82011-02-07 14:45:56 +00001321 s->scfunc = do_unindent;
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001322 else if (!strcasecmp(input, "scrollup"))
Chris Allegretta637daa82011-02-07 14:45:56 +00001323 s->scfunc = do_scroll_up;
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001324 else if (!strcasecmp(input, "scrolldown"))
Chris Allegretta637daa82011-02-07 14:45:56 +00001325 s->scfunc = do_scroll_down;
Chris Allegrettae347efb2008-03-09 02:52:40 +00001326 else if (!strcasecmp(input, "prevword"))
Chris Allegretta637daa82011-02-07 14:45:56 +00001327 s->scfunc = do_prev_word_void;
Benno Schulenberg3064db22014-04-21 12:06:20 +00001328 else if (!strcasecmp(input, "nextword"))
1329 s->scfunc = do_next_word_void;
Chris Allegrettae347efb2008-03-09 02:52:40 +00001330 else if (!strcasecmp(input, "findbracket"))
Chris Allegretta637daa82011-02-07 14:45:56 +00001331 s->scfunc = do_find_bracket;
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001332 else if (!strcasecmp(input, "wordcount"))
Chris Allegretta637daa82011-02-07 14:45:56 +00001333 s->scfunc = do_wordlinechar_count;
Chris Allegretta70859f42008-07-13 01:36:06 +00001334 else if (!strcasecmp(input, "undo"))
Chris Allegretta637daa82011-02-07 14:45:56 +00001335 s->scfunc = do_undo;
Benno Schulenbergcf8a2962014-06-20 16:03:38 +00001336 else if (!strcasecmp(input, "redo"))
Chris Allegretta637daa82011-02-07 14:45:56 +00001337 s->scfunc = do_redo;
Benno Schulenberg492e9f62014-06-20 10:48:26 +00001338#endif
Chris Allegrettae347efb2008-03-09 02:52:40 +00001339 else if (!strcasecmp(input, "left") ||
Benno Schulenberg3aea69d2014-02-28 20:08:59 +00001340 !strcasecmp(input, "back"))
Chris Allegretta637daa82011-02-07 14:45:56 +00001341 s->scfunc = do_left;
Benno Schulenberg47be8c22014-04-22 19:07:32 +00001342 else if (!strcasecmp(input, "right") ||
1343 !strcasecmp(input, "forward"))
1344 s->scfunc = do_right;
Chris Allegrettae347efb2008-03-09 02:52:40 +00001345 else if (!strcasecmp(input, "up") ||
Benno Schulenberg3aea69d2014-02-28 20:08:59 +00001346 !strcasecmp(input, "prevline"))
Chris Allegretta637daa82011-02-07 14:45:56 +00001347 s->scfunc = do_up_void;
Chris Allegrettae347efb2008-03-09 02:52:40 +00001348 else if (!strcasecmp(input, "down") ||
Benno Schulenberg3aea69d2014-02-28 20:08:59 +00001349 !strcasecmp(input, "nextline"))
Chris Allegretta637daa82011-02-07 14:45:56 +00001350 s->scfunc = do_down_void;
Chris Allegrettae347efb2008-03-09 02:52:40 +00001351 else if (!strcasecmp(input, "home"))
Chris Allegretta637daa82011-02-07 14:45:56 +00001352 s->scfunc = do_home;
Chris Allegrettae347efb2008-03-09 02:52:40 +00001353 else if (!strcasecmp(input, "end"))
Chris Allegretta637daa82011-02-07 14:45:56 +00001354 s->scfunc = do_end;
Benno Schulenberg618051c2014-04-26 20:16:17 +00001355 else if (!strcasecmp(input, "pageup") ||
1356 !strcasecmp(input, "prevpage"))
1357 s->scfunc = do_page_up;
1358 else if (!strcasecmp(input, "pagedown") ||
1359 !strcasecmp(input, "nextpage"))
1360 s->scfunc = do_page_down;
1361 else if (!strcasecmp(input, "firstline"))
1362 s->scfunc = do_first_line;
1363 else if (!strcasecmp(input, "lastline"))
1364 s->scfunc = do_last_line;
Benno Schulenberg0636d7b2014-04-03 20:23:07 +00001365#ifndef DISABLE_MULTIBUFFER
Chris Allegrettae347efb2008-03-09 02:52:40 +00001366 else if (!strcasecmp(input, "prevbuf"))
Chris Allegretta637daa82011-02-07 14:45:56 +00001367 s->scfunc = switch_to_prev_buffer_void;
Chris Allegrettae347efb2008-03-09 02:52:40 +00001368 else if (!strcasecmp(input, "nextbuf"))
Chris Allegretta637daa82011-02-07 14:45:56 +00001369 s->scfunc = switch_to_next_buffer_void;
Chris Allegrettae347efb2008-03-09 02:52:40 +00001370#endif
1371 else if (!strcasecmp(input, "verbatim"))
Chris Allegretta637daa82011-02-07 14:45:56 +00001372 s->scfunc = do_verbatim_input;
Chris Allegrettae347efb2008-03-09 02:52:40 +00001373 else if (!strcasecmp(input, "tab"))
Chris Allegretta637daa82011-02-07 14:45:56 +00001374 s->scfunc = do_tab;
Chris Allegrettae347efb2008-03-09 02:52:40 +00001375 else if (!strcasecmp(input, "enter"))
Chris Allegretta637daa82011-02-07 14:45:56 +00001376 s->scfunc = do_enter_void;
Chris Allegrettae347efb2008-03-09 02:52:40 +00001377 else if (!strcasecmp(input, "delete"))
Chris Allegretta637daa82011-02-07 14:45:56 +00001378 s->scfunc = do_delete;
Chris Allegrettafa406942008-07-13 16:44:19 +00001379 else if (!strcasecmp(input, "backspace"))
Chris Allegretta637daa82011-02-07 14:45:56 +00001380 s->scfunc = do_backspace;
Chris Allegrettae347efb2008-03-09 02:52:40 +00001381 else if (!strcasecmp(input, "refresh"))
Chris Allegretta637daa82011-02-07 14:45:56 +00001382 s->scfunc = total_refresh;
Benno Schulenberg5a393392014-05-27 12:38:32 +00001383 else if (!strcasecmp(input, "suspend"))
1384 s->scfunc = do_suspend_void;
Benno Schulenbergd48d84a2014-06-28 15:34:10 +00001385 else if (!strcasecmp(input, "casesens"))
Chris Allegretta637daa82011-02-07 14:45:56 +00001386 s->scfunc = case_sens_void;
Benno Schulenberg769e81c2014-05-27 12:34:43 +00001387#ifndef NANO_TINY
Benno Schulenbergd48d84a2014-06-28 15:34:10 +00001388 else if (!strcasecmp(input, "regexp") ||
1389 !strcasecmp(input, "regex"))
Chris Allegretta637daa82011-02-07 14:45:56 +00001390 s->scfunc = regexp_void;
Benno Schulenbergd48d84a2014-06-28 15:34:10 +00001391 else if (!strcasecmp(input, "backwards"))
Benno Schulenberg08465832014-05-04 12:20:51 +00001392 s->scfunc = backwards_void;
Benno Schulenberg769e81c2014-05-27 12:34:43 +00001393#endif
Benno Schulenbergd48d84a2014-06-28 15:34:10 +00001394 else if (!strcasecmp(input, "flipreplace") ||
1395 !strcasecmp(input, "dontreplace"))
Benno Schulenberga0f66c02014-06-23 18:30:35 +00001396 s->scfunc = flip_replace_void;
Benno Schulenbergd48d84a2014-06-28 15:34:10 +00001397 else if (!strcasecmp(input, "gototext"))
Chris Allegretta637daa82011-02-07 14:45:56 +00001398 s->scfunc = gototext_void;
Benno Schulenbergd48d84a2014-06-28 15:34:10 +00001399#ifndef DISABLE_HISTORIES
1400 else if (!strcasecmp(input, "prevhistory"))
1401 s->scfunc = get_history_older_void;
1402 else if (!strcasecmp(input, "nexthistory"))
1403 s->scfunc = get_history_newer_void;
1404#endif
1405 else if (!strcasecmp(input, "dosformat"))
Chris Allegretta637daa82011-02-07 14:45:56 +00001406 s->scfunc = dos_format_void;
Benno Schulenbergd48d84a2014-06-28 15:34:10 +00001407 else if (!strcasecmp(input, "macformat"))
Benno Schulenberg492e9f62014-06-20 10:48:26 +00001408 s->scfunc = mac_format_void;
Benno Schulenbergd48d84a2014-06-28 15:34:10 +00001409 else if (!strcasecmp(input, "append"))
Benno Schulenberg492e9f62014-06-20 10:48:26 +00001410 s->scfunc = append_void;
Benno Schulenbergd48d84a2014-06-28 15:34:10 +00001411 else if (!strcasecmp(input, "prepend"))
Benno Schulenberg492e9f62014-06-20 10:48:26 +00001412 s->scfunc = prepend_void;
Benno Schulenbergd48d84a2014-06-28 15:34:10 +00001413 else if (!strcasecmp(input, "backup"))
Benno Schulenberg492e9f62014-06-20 10:48:26 +00001414 s->scfunc = backup_file_void;
Benno Schulenberg04a38da2014-06-04 19:15:16 +00001415#ifndef ENABLE_TINY
Benno Schulenbergd48d84a2014-06-28 15:34:10 +00001416 else if (!strcasecmp(input, "flipexecute"))
Benno Schulenberg04a38da2014-06-04 19:15:16 +00001417 s->scfunc = flip_execute_void;
Benno Schulenberg04a38da2014-06-04 19:15:16 +00001418#endif
Benno Schulenberg0636d7b2014-04-03 20:23:07 +00001419#ifndef DISABLE_MULTIBUFFER
Benno Schulenbergd48d84a2014-06-28 15:34:10 +00001420 else if (!strcasecmp(input, "flipnewbuffer") ||
1421 !strcasecmp(input, "newbuffer"))
Benno Schulenberg492e9f62014-06-20 10:48:26 +00001422 s->scfunc = new_buffer_void;
Chris Allegrettae347efb2008-03-09 02:52:40 +00001423#endif
Chris Allegretta637daa82011-02-07 14:45:56 +00001424#ifndef DISABLE_BROWSER
Benno Schulenbergd48d84a2014-06-28 15:34:10 +00001425 else if (!strcasecmp(input, "tofiles") ||
1426 !strcasecmp(input, "browser"))
Benno Schulenbergef162232014-06-23 20:03:25 +00001427 s->scfunc = to_files_void;
Benno Schulenbergd48d84a2014-06-28 15:34:10 +00001428 else if (!strcasecmp(input, "gotodir"))
Benno Schulenbergef162232014-06-23 20:03:25 +00001429 s->scfunc = goto_dir_void;
Benno Schulenbergd48d84a2014-06-28 15:34:10 +00001430 else if (!strcasecmp(input, "firstfile"))
Benno Schulenberg492e9f62014-06-20 10:48:26 +00001431 s->scfunc = do_first_file;
Benno Schulenbergd48d84a2014-06-28 15:34:10 +00001432 else if (!strcasecmp(input, "lastfile"))
Chris Allegretta637daa82011-02-07 14:45:56 +00001433 s->scfunc = do_last_file;
Chris Allegretta637daa82011-02-07 14:45:56 +00001434#endif
Benno Schulenberg0a1e56e2014-06-28 15:00:29 +00001435#ifndef NANO_TINY
Benno Schulenbergd48d84a2014-06-28 15:34:10 +00001436 else {
Benno Schulenberg0a1e56e2014-06-28 15:00:29 +00001437 s->scfunc = do_toggle_void;
Benno Schulenbergd48d84a2014-06-28 15:34:10 +00001438 if (!strcasecmp(input, "nohelp"))
Benno Schulenbergb71cf982014-06-28 15:22:41 +00001439 s->toggle = NO_HELP;
Benno Schulenbergd48d84a2014-06-28 15:34:10 +00001440 else if (!strcasecmp(input, "constupdate"))
Benno Schulenbergb71cf982014-06-28 15:22:41 +00001441 s->toggle = CONST_UPDATE;
Benno Schulenbergd48d84a2014-06-28 15:34:10 +00001442 else if (!strcasecmp(input, "morespace"))
Benno Schulenbergb71cf982014-06-28 15:22:41 +00001443 s->toggle = MORE_SPACE;
Benno Schulenbergd48d84a2014-06-28 15:34:10 +00001444 else if (!strcasecmp(input, "smoothscroll"))
Benno Schulenbergb71cf982014-06-28 15:22:41 +00001445 s->toggle = SMOOTH_SCROLL;
Benno Schulenbergd48d84a2014-06-28 15:34:10 +00001446 else if (!strcasecmp(input, "softwrap"))
Benno Schulenbergb71cf982014-06-28 15:22:41 +00001447 s->toggle = SOFTWRAP;
Benno Schulenbergd48d84a2014-06-28 15:34:10 +00001448 else if (!strcasecmp(input, "whitespacedisplay"))
Benno Schulenbergb71cf982014-06-28 15:22:41 +00001449 s->toggle = WHITESPACE_DISPLAY;
Benno Schulenberg0a1e56e2014-06-28 15:00:29 +00001450#ifndef DISABLE_COLOR
Benno Schulenbergd48d84a2014-06-28 15:34:10 +00001451 else if (!strcasecmp(input, "nosyntax"))
Benno Schulenbergb71cf982014-06-28 15:22:41 +00001452 s->toggle = NO_COLOR_SYNTAX;
Benno Schulenberg0a1e56e2014-06-28 15:00:29 +00001453#endif
Benno Schulenbergd48d84a2014-06-28 15:34:10 +00001454 else if (!strcasecmp(input, "smarthome"))
Benno Schulenbergb71cf982014-06-28 15:22:41 +00001455 s->toggle = SMART_HOME;
Benno Schulenbergd48d84a2014-06-28 15:34:10 +00001456 else if (!strcasecmp(input, "autoindent"))
Benno Schulenbergb71cf982014-06-28 15:22:41 +00001457 s->toggle = AUTOINDENT;
Benno Schulenbergd48d84a2014-06-28 15:34:10 +00001458 else if (!strcasecmp(input, "cuttoend"))
Benno Schulenbergb71cf982014-06-28 15:22:41 +00001459 s->toggle = CUT_TO_END;
Benno Schulenberg0a1e56e2014-06-28 15:00:29 +00001460#ifndef DISABLE_WRAPPING
Benno Schulenbergd48d84a2014-06-28 15:34:10 +00001461 else if (!strcasecmp(input, "nowrap"))
Benno Schulenbergb71cf982014-06-28 15:22:41 +00001462 s->toggle = NO_WRAP;
Benno Schulenberg0a1e56e2014-06-28 15:00:29 +00001463#endif
Benno Schulenbergd48d84a2014-06-28 15:34:10 +00001464 else if (!strcasecmp(input, "tabstospaces"))
Benno Schulenbergb71cf982014-06-28 15:22:41 +00001465 s->toggle = TABS_TO_SPACES;
Benno Schulenbergd48d84a2014-06-28 15:34:10 +00001466 else if (!strcasecmp(input, "backupfile"))
Benno Schulenbergb71cf982014-06-28 15:22:41 +00001467 s->toggle = BACKUP_FILE;
Benno Schulenberg0a1e56e2014-06-28 15:00:29 +00001468#ifndef DISABLE_MULTIBUFFER
Benno Schulenbergd48d84a2014-06-28 15:34:10 +00001469 else if (!strcasecmp(input, "multibuffer"))
Benno Schulenbergb71cf982014-06-28 15:22:41 +00001470 s->toggle = MULTIBUFFER;
Benno Schulenberg0a1e56e2014-06-28 15:00:29 +00001471#endif
1472#ifndef DISABLE_MOUSE
Benno Schulenbergd48d84a2014-06-28 15:34:10 +00001473 else if (!strcasecmp(input, "mouse"))
Benno Schulenbergb71cf982014-06-28 15:22:41 +00001474 s->toggle = USE_MOUSE;
Benno Schulenberg0a1e56e2014-06-28 15:00:29 +00001475#endif
Benno Schulenbergd48d84a2014-06-28 15:34:10 +00001476 else if (!strcasecmp(input, "noconvert"))
Benno Schulenbergb71cf982014-06-28 15:22:41 +00001477 s->toggle = NO_CONVERT;
Benno Schulenbergd48d84a2014-06-28 15:34:10 +00001478 else if (!strcasecmp(input, "suspendenable"))
Benno Schulenbergb71cf982014-06-28 15:22:41 +00001479 s->toggle = SUSPEND;
Benno Schulenberg0a1e56e2014-06-28 15:00:29 +00001480#endif /* !NANO_TINY */
Benno Schulenbergd48d84a2014-06-28 15:34:10 +00001481 else {
Benno Schulenbergb71cf982014-06-28 15:22:41 +00001482 free(s);
1483 return NULL;
1484 }
1485#ifndef NANO_TINY
David Lawrence Ramsey576bf332004-07-12 03:10:30 +00001486 }
Benno Schulenbergb71cf982014-06-28 15:22:41 +00001487#endif
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001488 return s;
David Lawrence Ramsey576bf332004-07-12 03:10:30 +00001489}
1490
Benno Schulenberg353dd212014-05-25 19:47:46 +00001491/* Interpret a menu name and return the corresponding menu flag. */
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001492int strtomenu(char *input)
David Lawrence Ramsey576bf332004-07-12 03:10:30 +00001493{
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001494 if (!strcasecmp(input, "all"))
Benno Schulenberg4c9573d2014-04-16 09:12:13 +00001495 return (MMOST|MHELP|MYESNO);
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001496 else if (!strcasecmp(input, "main"))
1497 return MMAIN;
1498 else if (!strcasecmp(input, "search"))
1499 return MWHEREIS;
1500 else if (!strcasecmp(input, "replace"))
1501 return MREPLACE;
1502 else if (!strcasecmp(input, "replace2") ||
Benno Schulenbergf803ef52014-04-13 12:16:37 +00001503 !strcasecmp(input, "replacewith"))
Benno Schulenberge167afe2014-04-16 09:26:15 +00001504 return MREPLACEWITH;
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001505 else if (!strcasecmp(input, "gotoline"))
1506 return MGOTOLINE;
1507 else if (!strcasecmp(input, "writeout"))
1508 return MWRITEFILE;
1509 else if (!strcasecmp(input, "insert"))
1510 return MINSERTFILE;
1511 else if (!strcasecmp(input, "externalcmd") ||
Benno Schulenbergf803ef52014-04-13 12:16:37 +00001512 !strcasecmp(input, "extcmd"))
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001513 return MEXTCMD;
Benno Schulenberg353dd212014-05-25 19:47:46 +00001514#ifndef DISABLE_HELP
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001515 else if (!strcasecmp(input, "help"))
1516 return MHELP;
Benno Schulenberg353dd212014-05-25 19:47:46 +00001517#endif
1518#ifndef DISABLE_SPELLER
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001519 else if (!strcasecmp(input, "spell"))
1520 return MSPELL;
Benno Schulenberg353dd212014-05-25 19:47:46 +00001521#endif
Benno Schulenberg3064db22014-04-21 12:06:20 +00001522 else if (!strcasecmp(input, "linter"))
1523 return MLINTER;
Benno Schulenberg353dd212014-05-25 19:47:46 +00001524#ifndef DISABLE_BROWSER
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001525 else if (!strcasecmp(input, "browser"))
1526 return MBROWSER;
1527 else if (!strcasecmp(input, "whereisfile"))
1528 return MWHEREISFILE;
1529 else if (!strcasecmp(input, "gotodir"))
1530 return MGOTODIR;
Benno Schulenberg353dd212014-05-25 19:47:46 +00001531#endif
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001532 return -1;
David Lawrence Ramsey576bf332004-07-12 03:10:30 +00001533}
Benno Schulenberg353dd212014-05-25 19:47:46 +00001534#endif /* !DISABLE_NANORC */
David Lawrence Ramsey576bf332004-07-12 03:10:30 +00001535
Chris Allegrettae347efb2008-03-09 02:52:40 +00001536
David Lawrence Ramseye6757b92006-04-19 13:36:56 +00001537#ifdef DEBUG
1538/* This function is used to gracefully return all the memory we've used.
1539 * It should be called just before calling exit(). Practically, the
Chris Allegretta6232d662002-05-12 19:52:15 +00001540 * only effect is to cause a segmentation fault if the various data
1541 * structures got bolloxed earlier. Thus, we don't bother having this
Chris Allegretta6df90f52002-07-19 01:08:59 +00001542 * function unless debugging is turned on. */
Chris Allegretta6df90f52002-07-19 01:08:59 +00001543void thanks_for_all_the_fish(void)
Chris Allegrettaf5de33a2002-02-27 04:14:16 +00001544{
David Lawrence Ramsey576bf332004-07-12 03:10:30 +00001545 delwin(topwin);
1546 delwin(edit);
1547 delwin(bottomwin);
1548
Chris Allegretta7662c862003-01-13 01:35:15 +00001549#ifndef DISABLE_JUSTIFY
1550 if (quotestr != NULL)
1551 free(quotestr);
David Lawrence Ramsey819c7f02004-07-30 03:54:34 +00001552#ifdef HAVE_REGEX_H
1553 regfree(&quotereg);
David Lawrence Ramsey31b159c2005-05-26 05:17:13 +00001554 if (quoteerr != NULL)
1555 free(quoteerr);
David Lawrence Ramsey819c7f02004-07-30 03:54:34 +00001556#endif
Chris Allegretta7662c862003-01-13 01:35:15 +00001557#endif
David Lawrence Ramseyebe34252005-11-15 03:17:35 +00001558#ifndef NANO_TINY
David Lawrence Ramsey04e42a62004-02-28 16:24:31 +00001559 if (backup_dir != NULL)
1560 free(backup_dir);
1561#endif
Chris Allegretta2598c662002-03-28 01:59:34 +00001562#ifndef DISABLE_OPERATINGDIR
Chris Allegrettaf5de33a2002-02-27 04:14:16 +00001563 if (operating_dir != NULL)
1564 free(operating_dir);
1565 if (full_operating_dir != NULL)
1566 free(full_operating_dir);
1567#endif
1568 if (last_search != NULL)
1569 free(last_search);
1570 if (last_replace != NULL)
1571 free(last_replace);
Chris Allegrettaf5de33a2002-02-27 04:14:16 +00001572#ifndef DISABLE_SPELLER
1573 if (alt_speller != NULL)
1574 free(alt_speller);
1575#endif
Chris Allegrettaf5de33a2002-02-27 04:14:16 +00001576 if (answer != NULL)
1577 free(answer);
1578 if (cutbuffer != NULL)
Chris Allegretta7662c862003-01-13 01:35:15 +00001579 free_filestruct(cutbuffer);
David Lawrence Ramsey93c84052004-11-23 04:08:28 +00001580#ifndef DISABLE_JUSTIFY
1581 if (jusbuffer != NULL)
1582 free_filestruct(jusbuffer);
1583#endif
David Lawrence Ramsey5d8d0b12005-05-26 05:53:29 +00001584 /* Free the memory associated with each open file buffer. */
David Lawrence Ramsey6ad59cd2005-07-08 20:09:16 +00001585 if (openfile != NULL)
David Lawrence Ramsey64661ac2005-07-08 19:57:25 +00001586 free_openfilestruct(openfile);
Benno Schulenberg00389922014-04-04 11:59:03 +00001587#ifndef DISABLE_COLOR
David Lawrence Ramsey31b159c2005-05-26 05:17:13 +00001588 if (syntaxstr != NULL)
1589 free(syntaxstr);
Chris Allegretta6df90f52002-07-19 01:08:59 +00001590 while (syntaxes != NULL) {
1591 syntaxtype *bill = syntaxes;
1592
1593 free(syntaxes->desc);
1594 while (syntaxes->extensions != NULL) {
Benno Schulenberg1d5134d2014-05-12 14:31:54 +00001595 regexlisttype *bob = syntaxes->extensions;
Chris Allegretta6df90f52002-07-19 01:08:59 +00001596 syntaxes->extensions = bob->next;
David Lawrence Ramsey2385c1a2005-07-29 21:42:08 +00001597 free(bob->ext_regex);
David Lawrence Ramsey7fc0ada2005-08-29 18:52:06 +00001598 if (bob->ext != NULL) {
1599 regfree(bob->ext);
1600 free(bob->ext);
1601 }
Chris Allegretta6df90f52002-07-19 01:08:59 +00001602 free(bob);
1603 }
Benno Schulenberg1d5134d2014-05-12 14:31:54 +00001604 while (syntaxes->headers != NULL) {
1605 regexlisttype *bob = syntaxes->headers;
1606 syntaxes->headers = bob->next;
1607 free(bob->ext_regex);
1608 if (bob->ext != NULL) {
1609 regfree(bob->ext);
1610 free(bob->ext);
1611 }
1612 free(bob);
1613 }
1614 while (syntaxes->magics != NULL) {
1615 regexlisttype *bob = syntaxes->magics;
1616 syntaxes->magics = bob->next;
1617 free(bob->ext_regex);
1618 if (bob->ext != NULL) {
1619 regfree(bob->ext);
1620 free(bob->ext);
1621 }
1622 free(bob);
1623 }
Chris Allegretta6df90f52002-07-19 01:08:59 +00001624 while (syntaxes->color != NULL) {
1625 colortype *bob = syntaxes->color;
1626
1627 syntaxes->color = bob->next;
David Lawrence Ramsey2385c1a2005-07-29 21:42:08 +00001628 free(bob->start_regex);
David Lawrence Ramseydb958022005-07-13 20:18:46 +00001629 if (bob->start != NULL) {
1630 regfree(bob->start);
1631 free(bob->start);
1632 }
David Lawrence Ramseyd2361f02005-07-14 18:33:51 +00001633 if (bob->end_regex != NULL)
1634 free(bob->end_regex);
David Lawrence Ramseydb958022005-07-13 20:18:46 +00001635 if (bob->end != NULL) {
Chris Allegrettace452fb2003-02-03 02:56:44 +00001636 regfree(bob->end);
David Lawrence Ramseydb958022005-07-13 20:18:46 +00001637 free(bob->end);
1638 }
Chris Allegretta6df90f52002-07-19 01:08:59 +00001639 free(bob);
1640 }
1641 syntaxes = syntaxes->next;
1642 free(bill);
1643 }
Benno Schulenberg00389922014-04-04 11:59:03 +00001644#endif /* !DISABLE_COLOR */
Benno Schulenberg3f816ee2014-06-19 21:01:39 +00001645#ifndef DISABLE_HISTORIES
David Lawrence Ramsey40e4acf2005-05-26 06:09:07 +00001646 /* Free the search and replace history lists. */
David Lawrence Ramsey31b159c2005-05-26 05:17:13 +00001647 if (searchage != NULL)
1648 free_filestruct(searchage);
1649 if (replaceage != NULL)
1650 free_filestruct(replaceage);
Chris Allegretta5beed502003-01-05 20:41:21 +00001651#endif
Benno Schulenberg24bc59f2014-05-13 18:06:09 +00001652 /* Free the functions and shortcuts lists. */
1653 while (allfuncs != NULL) {
1654 subnfunc *f = allfuncs;
1655 allfuncs = allfuncs->next;
1656 free(f);
1657 }
1658 while (sclist != NULL) {
Benno Schulenberg678b2212014-05-13 18:31:13 +00001659 sc *s = sclist;
Benno Schulenberg24bc59f2014-05-13 18:06:09 +00001660 sclist = sclist->next;
Benno Schulenberg678b2212014-05-13 18:31:13 +00001661 free(s);
Benno Schulenberg24bc59f2014-05-13 18:06:09 +00001662 }
Benno Schulenbergeea09082014-04-13 20:50:20 +00001663#ifndef DISABLE_NANORC
David Lawrence Ramsey31b159c2005-05-26 05:17:13 +00001664 if (homedir != NULL)
1665 free(homedir);
David Lawrence Ramseya27bd652004-08-17 05:23:38 +00001666#endif
Chris Allegrettaf5de33a2002-02-27 04:14:16 +00001667}
Chris Allegretta637daa82011-02-07 14:45:56 +00001668
Chris Allegretta6232d662002-05-12 19:52:15 +00001669#endif /* DEBUG */