blob: 6430c3437bd5d84d1c1ff8c6bf1e262e626cbfa8 [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
David Lawrence Ramseyf5b256b2003-10-03 20:26:25 +000041#ifndef DISABLE_WRAPJUSTIFY
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +000042ssize_t fill = 0;
43 /* The column where we will wrap lines. */
David Lawrence Ramsey691698a2005-07-24 19:57:51 +000044ssize_t wrap_at = -CHARS_FROM_EOL;
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +000045 /* The position where we will wrap lines. fill is equal to this
46 * if it's greater than zero, and equal to (COLS + this) if it
47 * isn't. */
David Lawrence Ramseyf5b256b2003-10-03 20:26:25 +000048#endif
49
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +000050char *last_search = NULL;
51 /* The last string we searched for. */
52char *last_replace = NULL;
53 /* The last replacement string we searched for. */
Chris Allegretta6df90f52002-07-19 01:08:59 +000054
Chris Allegrettaa48507d2009-08-14 03:18:29 +000055unsigned flags[4] = {0, 0, 0, 0};
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +000056 /* Our flag containing the states of all global options. */
57WINDOW *topwin;
58 /* The top portion of the window, where we display the version
59 * number of nano, the name of the current file, and whether the
60 * current file has been modified. */
61WINDOW *edit;
David Lawrence Ramseyb159f942006-07-28 17:06:27 +000062 /* The middle portion of the window, i.e. the edit window, where
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +000063 * we display the current file we're editing. */
64WINDOW *bottomwin;
65 /* The bottom portion of the window, where we display statusbar
66 * messages, the statusbar prompt, and a list of shortcuts. */
67int editwinrows = 0;
68 /* How many rows does the edit window take up? */
Chris Allegretta8c1edd12009-11-16 04:28:40 +000069int maxrows = 0;
Benno Schulenberg7f873932014-02-25 21:27:22 +000070 /* How many usable lines there are (due to soft wrapping). */
David Lawrence Ramsey5db0cdc2002-06-28 22:45:14 +000071
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +000072filestruct *cutbuffer = NULL;
73 /* The buffer where we store cut text. */
Chris Allegretta12dc8ca2008-07-31 04:24:04 +000074filestruct *cutbottom = NULL;
David Lawrence Ramsey93c84052004-11-23 04:08:28 +000075#ifndef DISABLE_JUSTIFY
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +000076filestruct *jusbuffer = NULL;
77 /* The buffer where we store unjustified text. */
David Lawrence Ramsey93c84052004-11-23 04:08:28 +000078#endif
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +000079partition *filepart = NULL;
80 /* The partition where we store a portion of the current
81 * file. */
David Lawrence Ramsey64661ac2005-07-08 19:57:25 +000082openfilestruct *openfile = NULL;
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +000083 /* The list of all open file buffers. */
Chris Allegretta2d7893d2001-07-11 02:08:33 +000084
David Lawrence Ramseyd89617f2006-01-06 21:51:10 +000085#ifndef NANO_TINY
86char *matchbrackets = NULL;
87 /* The opening and closing brackets that can be found by bracket
88 * searches. */
89#endif
90
Benno Schulenbergeea09082014-04-13 20:50:20 +000091#if !defined(NANO_TINY) && !defined(DISABLE_NANORC)
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +000092char *whitespace = NULL;
93 /* The characters used when displaying the first characters of
94 * tabs and spaces. */
95int whitespace_len[2];
96 /* The length of these characters. */
David Lawrence Ramsey89bb9372004-05-29 16:47:52 +000097#endif
98
Chris Allegrettae4f940d2002-03-03 22:36:36 +000099#ifndef DISABLE_JUSTIFY
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +0000100char *punct = NULL;
101 /* The closing punctuation that can end sentences. */
102char *brackets = NULL;
103 /* The closing brackets that can follow closing punctuation and
104 * can end sentences. */
105char *quotestr = NULL;
106 /* The quoting string. The default value is set in main(). */
David Lawrence Ramsey819c7f02004-07-30 03:54:34 +0000107#ifdef HAVE_REGEX_H
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +0000108regex_t quotereg;
109 /* The compiled regular expression from the quoting string. */
110int quoterc;
David Lawrence Ramsey88165642006-05-22 18:30:09 +0000111 /* Whether it was compiled successfully. */
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +0000112char *quoteerr = NULL;
113 /* The error message, if it didn't. */
David Lawrence Ramsey819c7f02004-07-30 03:54:34 +0000114#else
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +0000115size_t quotelen;
116 /* The length of the quoting string in bytes. */
David Lawrence Ramsey819c7f02004-07-30 03:54:34 +0000117#endif
Chris Allegretta6df90f52002-07-19 01:08:59 +0000118#endif
Chris Allegrettae4f940d2002-03-03 22:36:36 +0000119
Chris Allegretta0dc26dc2009-01-24 22:40:41 +0000120bool nodelay_mode = FALSE;
121 /* Are we in nodelay mode (checking for a cancel wile doing something */
122
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +0000123char *answer = NULL;
David Lawrence Ramsey6335fb52007-01-01 05:15:32 +0000124 /* The answer string used by the statusbar prompt. */
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +0000125
126ssize_t tabsize = -1;
127 /* The width of a tab in spaces. The default value is set in
128 * main(). */
129
David Lawrence Ramseyebe34252005-11-15 03:17:35 +0000130#ifndef NANO_TINY
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +0000131char *backup_dir = NULL;
132 /* The directory where we store backup files. */
Chris Allegrettabf88d272013-01-01 03:24:39 +0000133
Chris Allegretta3116d2f2013-01-03 04:36:39 +0000134const char *locking_prefix = ".";
Chris Allegrettabf88d272013-01-01 03:24:39 +0000135 /* Prefix of how to store the vim-style lock file */
Chris Allegretta3116d2f2013-01-03 04:36:39 +0000136const char *locking_suffix = ".swp";
Chris Allegrettabf88d272013-01-01 03:24:39 +0000137 /* Suffix of the vim-style lock file */
David Lawrence Ramsey04e42a62004-02-28 16:24:31 +0000138#endif
Chris Allegrettae1f14522001-09-19 03:19:43 +0000139#ifndef DISABLE_OPERATINGDIR
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +0000140char *operating_dir = NULL;
141 /* The relative path to the operating directory, which we can't
142 * move outside of. */
143char *full_operating_dir = NULL;
144 /* The full path to it. */
Chris Allegrettae1f14522001-09-19 03:19:43 +0000145#endif
146
Chris Allegretta8d8e0122001-04-18 04:28:54 +0000147#ifndef DISABLE_SPELLER
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +0000148char *alt_speller = NULL;
149 /* The command to use for the alternate spell checker. */
Chris Allegretta8d8e0122001-04-18 04:28:54 +0000150#endif
151
Benno Schulenberg00389922014-04-04 11:59:03 +0000152#ifndef DISABLE_COLOR
David Lawrence Ramsey9b13ff32002-12-22 16:30:00 +0000153syntaxtype *syntaxes = NULL;
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +0000154 /* The global list of color syntaxes. */
David Lawrence Ramsey9b13ff32002-12-22 16:30:00 +0000155char *syntaxstr = NULL;
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +0000156 /* The color syntax name specified on the command line. */
Chris Allegrettafd265af2009-02-06 03:41:02 +0000157
Chris Allegretta8ce24132001-04-30 11:28:46 +0000158#endif
159
Chris Allegretta637daa82011-02-07 14:45:56 +0000160bool edit_refresh_needed = 0;
Chris Allegretta2ad1de02012-12-30 19:20:10 +0000161 /* Did a command mangle enough of the buffer refresh that we
Benno Schulenberg7f873932014-02-25 21:27:22 +0000162 * should repaint the screen? */
Chris Allegrettafd265af2009-02-06 03:41:02 +0000163
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +0000164const shortcut *currshortcut;
165 /* The current shortcut list we're using. */
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000166int currmenu;
Benno Schulenberg7f873932014-02-25 21:27:22 +0000167 /* The currently loaded menu. */
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000168
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000169sc *sclist = NULL;
Benno Schulenberg20b1e922014-04-26 18:41:43 +0000170 /* Pointer to the start of the shortcuts list. */
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000171subnfunc *allfuncs = NULL;
Benno Schulenberg20b1e922014-04-26 18:41:43 +0000172 /* Pointer to the start of the functions list. */
173subnfunc *tailfunc;
174 /* Pointer to the last function in the list. */
Benno Schulenberg11d76442014-04-26 19:01:18 +0000175subnfunc *exitfunc;
176 /* Pointer to the special Exit/Close item. */
Benno Schulenbergbc6e9aa2014-04-07 09:02:22 +0000177subnfunc *uncutfunc;
178 /* Pointer to the special Uncut/Unjustify item. */
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000179
David Lawrence Ramseyebe34252005-11-15 03:17:35 +0000180#ifndef NANO_TINY
David Lawrence Ramsey934f9682005-05-23 16:30:06 +0000181filestruct *search_history = NULL;
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +0000182 /* The search string history list. */
David Lawrence Ramsey934f9682005-05-23 16:30:06 +0000183filestruct *searchage = NULL;
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +0000184 /* The top of the search string history list. */
David Lawrence Ramsey934f9682005-05-23 16:30:06 +0000185filestruct *searchbot = NULL;
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +0000186 /* The bottom of the search string history list. */
David Lawrence Ramsey934f9682005-05-23 16:30:06 +0000187filestruct *replace_history = NULL;
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +0000188 /* The replace string history list. */
David Lawrence Ramsey934f9682005-05-23 16:30:06 +0000189filestruct *replaceage = NULL;
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +0000190 /* The top of the replace string history list. */
David Lawrence Ramsey934f9682005-05-23 16:30:06 +0000191filestruct *replacebot = NULL;
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +0000192 /* The bottom of the replace string history list. */
Chris Allegretta9bfda912011-02-16 06:52:30 +0000193poshiststruct *poshistory;
Benno Schulenberg7f873932014-02-25 21:27:22 +0000194 /* The cursor position history list. */
Chris Allegretta5beed502003-01-05 20:41:21 +0000195#endif
196
David Lawrence Ramseyfc0f8f82006-05-10 13:41:53 +0000197/* Regular expressions. */
Chris Allegretta805c26d2000-09-06 13:39:17 +0000198#ifdef HAVE_REGEX_H
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +0000199regex_t search_regexp;
200 /* The compiled regular expression to use in searches. */
201regmatch_t regmatches[10];
202 /* The match positions for parenthetical subexpressions, 10
203 * maximum, used in regular expression searches. */
Chris Allegretta6df90f52002-07-19 01:08:59 +0000204#endif
Chris Allegretta3533a342002-03-24 23:19:32 +0000205
Benno Schulenbergc9700352014-05-04 08:53:06 +0000206int hilite_attribute = A_REVERSE;
David Lawrence Ramsey4d72de72006-04-12 15:27:40 +0000207 /* The curses attribute we use for reverse video. */
Benno Schulenberg16639942014-05-03 18:24:45 +0000208#ifndef DISABLE_COLOR
209char* specified_color_combo[] = {};
210 /* The color combinations as specified in the rcfile. */
211#endif
Benno Schulenberge7d6e552014-05-10 19:15:04 +0000212color_pair interface_color_pair[] = {};
Benno Schulenberg16639942014-05-03 18:24:45 +0000213 /* The processed color pairs for the interface elements. */
Chris Allegrettaa0d89972003-02-03 03:32:08 +0000214
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +0000215char *homedir = NULL;
David Lawrence Ramseyc1c818e2006-05-14 18:22:01 +0000216 /* The user's home directory, from $HOME or /etc/passwd. */
David Lawrence Ramseya27bd652004-08-17 05:23:38 +0000217
Benno Schulenberg7f873932014-02-25 21:27:22 +0000218/* Return the number of entries in the shortcut list for a given menu. */
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000219size_t length_of_list(int menu)
Chris Allegrettaa8c22572002-02-15 19:17:02 +0000220{
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000221 subnfunc *f;
David Lawrence Ramseyebd0d7c2004-07-01 18:59:52 +0000222 size_t i = 0;
David Lawrence Ramseye21adfa2002-09-13 18:14:04 +0000223
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000224 for (f = allfuncs; f != NULL; f = f->next)
Chris Allegretta0018d8e2008-03-13 08:23:52 +0000225 if ((f->menus & menu) != 0
226#ifndef DISABLE_HELP
227 && strlen(f->help) > 0
228#endif
229 ) {
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000230 i++;
231 }
Chris Allegrettaa8c22572002-02-15 19:17:02 +0000232 return i;
233}
234
Benno Schulenberg7f873932014-02-25 21:27:22 +0000235/* Just throw this here. */
Chris Allegretta637daa82011-02-07 14:45:56 +0000236void case_sens_void(void)
237{
238}
239void regexp_void(void)
240{
241}
242void gototext_void(void)
243{
244}
245void to_files_void(void)
246{
247}
248void dos_format_void(void)
249{
250}
251void mac_format_void(void)
252{
253}
254void append_void(void)
255{
256}
257void prepend_void(void)
258{
259}
260void backup_file_void(void)
261{
262}
263void new_buffer_void(void)
264{
265}
266void backwards_void(void)
267{
268}
269void goto_dir_void(void)
270{
271}
272void no_replace_void(void)
273{
274}
275void ext_cmd_void(void)
276{
277}
278
Benno Schulenberg7f873932014-02-25 21:27:22 +0000279/* Set type of function based on the string. */
Chris Allegretta5a018f02009-11-29 06:13:22 +0000280function_type strtokeytype(const char *str)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000281{
Benno Schulenberg57d773f2014-04-21 11:22:54 +0000282 if (str[0] == '^')
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000283 return CONTROL;
Benno Schulenberg57d773f2014-04-21 11:22:54 +0000284 else if (str[0] == 'M')
285 return META;
286 else if (str[0] == 'F')
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000287 return FKEY;
Chris Allegretta17436ce2008-03-11 03:03:53 +0000288 else
Chris Allegretta3bd12e32011-02-26 14:22:37 +0000289 return RAWINPUT;
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000290}
291
Benno Schulenberg70d21672014-03-26 10:53:10 +0000292/* Add a string to the function list struct.
Benno Schulenberg7f873932014-02-25 21:27:22 +0000293 * Does not allow updates, not yet anyway. */
Chris Allegretta637daa82011-02-07 14:45:56 +0000294void add_to_funcs(void (*func)(void), int menus, const char *desc, const char *help,
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000295 bool blank_after, bool viewok)
296{
Benno Schulenberg20b1e922014-04-26 18:41:43 +0000297 subnfunc *f = nmalloc(sizeof(subnfunc));
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000298
Benno Schulenberg20b1e922014-04-26 18:41:43 +0000299 if (allfuncs == NULL)
300 allfuncs = f;
301 else
302 tailfunc->next = f;
303 tailfunc = f;
304
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000305 f->next = NULL;
306 f->scfunc = func;
307 f->menus = menus;
308 f->desc = desc;
309 f->viewok = viewok;
Chris Allegretta1d778232008-08-30 21:00:00 +0000310#ifndef DISABLE_HELP
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000311 f->help = help;
312 f->blank_after = blank_after;
313#endif
314
315#ifdef DEBUG
Benno Schulenberg5c2b44a2014-04-15 20:01:19 +0000316 fprintf(stderr, "Added func %ld (%s) for menus %x\n", (long)func, f->desc, menus);
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000317#endif
318}
319
Benno Schulenberg86b86862014-04-23 20:03:24 +0000320/* Return the first shortcut in the list of shortcuts that
321 * matches the given func in the given menu. */
Chris Allegrettabf406ff2013-06-14 02:44:54 +0000322const sc *first_sc_for(int menu, void (*func)(void))
323{
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000324 const sc *s;
325
Benno Schulenberg86b86862014-04-23 20:03:24 +0000326 for (s = sclist; s != NULL; s = s->next)
327 if ((s->menu & menu) && s->scfunc == func)
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000328 return s;
Chris Allegrettab775c072008-03-09 05:07:37 +0000329
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000330#ifdef DEBUG
Benno Schulenberg18c252d2014-03-24 20:35:17 +0000331 fprintf(stderr, "Whoops, returning null given func %ld in menu %x\n", (long) func, menu);
David Lawrence Ramseybd28ee42006-07-25 21:13:30 +0000332#endif
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000333 /* Otherwise... */
334 return NULL;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000335}
336
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000337
Benno Schulenberg70d21672014-03-26 10:53:10 +0000338/* Add a string to the shortcut list.
Benno Schulenberg7f873932014-02-25 21:27:22 +0000339 * Allows updates to existing entries in the list. */
Chris Allegretta637daa82011-02-07 14:45:56 +0000340void add_to_sclist(int menu, const char *scstring, void (*func)(void), int toggle, int execute)
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000341{
342 sc *s;
343
344 if (sclist == NULL) {
Chris Allegrettaf86fa862009-02-25 04:32:15 +0000345 sclist = (sc *) nmalloc(sizeof(sc));
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000346 s = sclist;
347 s->next = NULL;
348 } else {
349 for (s = sclist; s->next != NULL; s = s->next)
350 if (s->menu == menu && s->keystr == scstring)
351 break;
352
353 if (s->menu != menu || s->keystr != scstring) { /* i.e. this is not a replace... */
354#ifdef DEBUG
355 fprintf(stderr, "No match found...\n");
356#endif
357 s->next = (sc *)nmalloc(sizeof(sc));
358 s = s->next;
359 s->next = NULL;
360 }
361 }
362
363 s->type = strtokeytype(scstring);
364 s->menu = menu;
365 s->toggle = toggle;
Chris Allegretta5a018f02009-11-29 06:13:22 +0000366 s->keystr = (char *) scstring;
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000367 s->scfunc = func;
368 s->execute = execute;
369 assign_keyinfo(s);
370
371#ifdef DEBUG
Benno Schulenberg18c252d2014-03-24 20:35:17 +0000372 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 +0000373#endif
374}
375
Benno Schulenberg7f873932014-02-25 21:27:22 +0000376/* Assign one menu's shortcuts to another function. */
Chris Allegretta5575bfa2014-02-24 10:18:15 +0000377void replace_scs_for(void (*oldfunc)(void), void (*newfunc)(void))
378{
379 sc *s;
380
381 if (sclist == NULL)
382 return;
383
384 for (s = sclist; s->next != NULL; s = s->next)
385 if (s->scfunc == oldfunc) {
386 s->scfunc = newfunc;
387 }
388}
389
Chris Allegrettae347efb2008-03-09 02:52:40 +0000390/* Return the given menu's first shortcut sequence, or the default value
Benno Schulenberg7f873932014-02-25 21:27:22 +0000391 * (2nd arg). Assumes currmenu for the menu to check. */
Chris Allegretta2ad1de02012-12-30 19:20:10 +0000392int sc_seq_or (void (*func)(void), int defaultval)
Chris Allegrettae347efb2008-03-09 02:52:40 +0000393{
394 const sc *s = first_sc_for(currmenu, func);
395
396 if (s)
397 return s->seq;
398 /* else */
399 return defaultval;
Chris Allegrettae347efb2008-03-09 02:52:40 +0000400}
401
Benno Schulenberg7f873932014-02-25 21:27:22 +0000402/* Assign the info to the shortcut struct.
403 * Assumes keystr is already assigned, naturally. */
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000404void assign_keyinfo(sc *s)
405{
406 if (s->type == CONTROL) {
407 assert(strlen(s->keystr) > 1);
408 s->seq = s->keystr[1] - 64;
409 } else if (s->type == META) {
410 assert(strlen(s->keystr) > 2);
411 s->seq = tolower((int) s->keystr[2]);
412 } else if (s->type == FKEY) {
413 assert(strlen(s->keystr) > 1);
414 s->seq = KEY_F0 + atoi(&s->keystr[1]);
Chris Allegretta3bd12e32011-02-26 14:22:37 +0000415 } else /* RAWINPUT */
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000416 s->seq = (int) s->keystr[0];
Chris Allegretta9b422202008-03-05 17:15:33 +0000417
Benno Schulenberg75ff3a92014-04-21 15:22:14 +0000418 /* Override some keys which don't bind as easily as we'd like. */
Chris Allegretta9b422202008-03-05 17:15:33 +0000419 if (s->type == CONTROL && (!strcasecmp(&s->keystr[1], "space")))
420 s->seq = 0;
421 else if (s->type == META && (!strcasecmp(&s->keystr[2], "space")))
422 s->seq = (int) ' ';
Benno Schulenberg75ff3a92014-04-21 15:22:14 +0000423 else if (s->type == RAWINPUT) {
Benno Schulenbergd6308802014-04-21 15:45:23 +0000424 if (!strcasecmp(s->keystr, "Up"))
Benno Schulenberg75ff3a92014-04-21 15:22:14 +0000425 s->seq = KEY_UP;
Benno Schulenbergd6308802014-04-21 15:45:23 +0000426 else if (!strcasecmp(s->keystr, "Down"))
Benno Schulenberg75ff3a92014-04-21 15:22:14 +0000427 s->seq = KEY_DOWN;
Benno Schulenbergd6308802014-04-21 15:45:23 +0000428 else if (!strcasecmp(s->keystr, "Left"))
Benno Schulenberg75ff3a92014-04-21 15:22:14 +0000429 s->seq = KEY_LEFT;
Benno Schulenbergd6308802014-04-21 15:45:23 +0000430 else if (!strcasecmp(s->keystr, "Right"))
Benno Schulenberg75ff3a92014-04-21 15:22:14 +0000431 s->seq = KEY_RIGHT;
Benno Schulenberg94b1d012014-04-21 18:05:11 +0000432 else if (!strcasecmp(s->keystr, "Ins"))
Benno Schulenberg75ff3a92014-04-21 15:22:14 +0000433 s->seq = KEY_IC;
Benno Schulenbergd6308802014-04-21 15:45:23 +0000434 else if (!strcasecmp(s->keystr, "Del"))
Benno Schulenberg75ff3a92014-04-21 15:22:14 +0000435 s->seq = KEY_DC;
Benno Schulenbergd6308802014-04-21 15:45:23 +0000436 else if (!strcasecmp(s->keystr, "Bsp"))
Benno Schulenberg75ff3a92014-04-21 15:22:14 +0000437 s->seq = KEY_BACKSPACE;
Benno Schulenbergd6308802014-04-21 15:45:23 +0000438 else if (!strcasecmp(s->keystr, "Enter"))
Benno Schulenberg75ff3a92014-04-21 15:22:14 +0000439 s->seq = KEY_ENTER;
Benno Schulenbergd6308802014-04-21 15:45:23 +0000440 else if (!strcasecmp(s->keystr, "PgUp"))
Benno Schulenberg75ff3a92014-04-21 15:22:14 +0000441 s->seq = KEY_PPAGE;
Benno Schulenbergd6308802014-04-21 15:45:23 +0000442 else if (!strcasecmp(s->keystr, "PgDn"))
Benno Schulenberg75ff3a92014-04-21 15:22:14 +0000443 s->seq = KEY_NPAGE;
Chris Allegretta17436ce2008-03-11 03:03:53 +0000444#ifdef KEY_HOME
Benno Schulenbergd6308802014-04-21 15:45:23 +0000445 else if (!strcasecmp(s->keystr, "Home"))
Benno Schulenberg75ff3a92014-04-21 15:22:14 +0000446 s->seq = KEY_HOME;
Chris Allegretta17436ce2008-03-11 03:03:53 +0000447#endif
448#ifdef KEY_END
Benno Schulenbergd6308802014-04-21 15:45:23 +0000449 else if (!strcasecmp(s->keystr, "End"))
Benno Schulenberg75ff3a92014-04-21 15:22:14 +0000450 s->seq = KEY_END;
Chris Allegretta17436ce2008-03-11 03:03:53 +0000451#endif
Benno Schulenberg75ff3a92014-04-21 15:22:14 +0000452 }
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000453}
454
455#ifdef DEBUG
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000456void print_sclist(void)
457{
458 sc *s;
459 const subnfunc *f;
460
Benno Schulenberga85b6da2014-03-26 10:57:11 +0000461 for (s = sclist; s != NULL; s = s->next) {
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000462 f = sctofunc(s);
Benno Schulenberga85b6da2014-03-26 10:57:11 +0000463 if (f)
Benno Schulenberg70d21672014-03-26 10:53:10 +0000464 fprintf(stderr, "Shortcut \"%s\", function: %s, menus %x\n", s->keystr, f->desc, f->menus);
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000465 else
Benno Schulenbergd0dec312014-04-08 12:35:18 +0000466 fprintf(stderr, "Hmm, didn't find a func for \"%s\"\n", s->keystr);
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000467 }
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000468}
469#endif
470
Benno Schulenberg11d76442014-04-26 19:01:18 +0000471/* TRANSLATORS: Try to keep the next four strings at most 10 characters. */
472const char *exit_tag = N_("Exit");
473const char *close_tag = N_("Close");
Benno Schulenbergbc6e9aa2014-04-07 09:02:22 +0000474const char *uncut_tag = N_("Uncut Text");
475#ifndef DISABLE_JUSITIFY
476const char *unjust_tag = N_("Unjustify");
477#endif
Benno Schulenberg2ff9dc72014-04-06 20:55:21 +0000478#ifndef NANO_TINY
Benno Schulenberg9aebd272014-04-22 10:44:24 +0000479/* TRANSLATORS: Try to keep this at most 12 characters. */
Benno Schulenberg9fc713b2014-04-22 10:18:48 +0000480const char *whereis_next_tag = N_("WhereIs Next");
Benno Schulenberg2ff9dc72014-04-06 20:55:21 +0000481#endif
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000482
Benno Schulenberga2dcd6e2014-04-07 09:24:10 +0000483/* Initialize the list of functions and the list of shortcuts. */
484void shortcut_init(void)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000485{
Benno Schulenberg61758e92014-04-27 14:21:57 +0000486 /* TRANSLATORS: Try to keep the next nine strings at most 10 characters. */
Benno Schulenberg9fc713b2014-04-22 10:18:48 +0000487 const char *whereis_tag = N_("Where Is");
Benno Schulenberg61758e92014-04-27 14:21:57 +0000488 const char *replace_tag = N_("Replace");
489 const char *gotoline_tag = N_("Go To Line");
Benno Schulenberg12da94c2014-04-22 10:02:55 +0000490 const char *prev_line_tag = N_("Prev Line");
491 const char *next_line_tag = N_("Next Line");
Benno Schulenberg5f655da2014-04-27 15:26:25 +0000492#ifndef DISABLE_JUSTIFY
Benno Schulenberg61758e92014-04-27 14:21:57 +0000493 const char *fulljustify_tag = N_("FullJstify");
Benno Schulenberg5f655da2014-04-27 15:26:25 +0000494#endif
Benno Schulenberg9fc713b2014-04-22 10:18:48 +0000495 const char *refresh_tag = N_("Refresh");
Benno Schulenbergb8b29ff2014-04-03 21:06:30 +0000496#ifndef DISABLE_SPELLER
Benno Schulenberg9fc713b2014-04-22 10:18:48 +0000497 const char *spell_tag = N_("To Spell");
Benno Schulenbergb8b29ff2014-04-03 21:06:30 +0000498#endif
Benno Schulenberg00389922014-04-04 11:59:03 +0000499#ifndef DISABLE_COLOR
Benno Schulenberg9fc713b2014-04-22 10:18:48 +0000500 const char *lint_tag = N_("To Linter");
Benno Schulenbergc8b60ce2014-04-22 11:57:11 +0000501 /* TRANSLATORS: Try to keep the next two strings at most 14 characters. */
Benno Schulenberg9fc713b2014-04-22 10:18:48 +0000502 const char *prev_lint_tag = N_("Prev Lint Msg");
503 const char *next_lint_tag = N_("Next Lint Msg");
Chris Allegretta5575bfa2014-02-24 10:18:15 +0000504#endif
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000505
Chris Allegretta1d778232008-08-30 21:00:00 +0000506#ifndef DISABLE_JUSTIFY
Benno Schulenberg7f873932014-02-25 21:27:22 +0000507 /* TRANSLATORS: The next long series of strings are shortcut descriptions;
508 * they are best kept shorter than 56 characters, but may be longer. */
Chris Allegretta1d778232008-08-30 21:00:00 +0000509 const char *nano_justify_msg = N_("Justify the current paragraph");
510#endif
Chris Allegrettadab017e2002-04-23 10:56:06 +0000511#ifndef DISABLE_HELP
David Lawrence Ramsey804e1072006-03-29 19:43:32 +0000512 const char *nano_cancel_msg = N_("Cancel the current function");
David Lawrence Ramsey57c9afb2006-04-14 20:21:45 +0000513 const char *nano_help_msg = N_("Display this help text");
David Lawrence Ramsey576bf332004-07-12 03:10:30 +0000514 const char *nano_exit_msg =
Benno Schulenberg0636d7b2014-04-03 20:23:07 +0000515#ifndef DISABLE_MULTIBUFFER
David Lawrence Ramseybe231d32006-05-21 21:37:21 +0000516 N_("Close the current file buffer / Exit from nano")
Chris Allegretta2d7893d2001-07-11 02:08:33 +0000517#else
Benno Schulenberga65ef422014-03-17 21:36:37 +0000518 N_("Exit from nano")
Chris Allegretta2d7893d2001-07-11 02:08:33 +0000519#endif
David Lawrence Ramsey576bf332004-07-12 03:10:30 +0000520 ;
David Lawrence Ramsey9b108c22005-06-06 18:38:16 +0000521 const char *nano_writeout_msg =
522 N_("Write the current file to disk");
David Lawrence Ramsey576bf332004-07-12 03:10:30 +0000523 const char *nano_insert_msg =
524 N_("Insert another file into the current one");
David Lawrence Ramsey9b108c22005-06-06 18:38:16 +0000525 const char *nano_whereis_msg =
David Lawrence Ramseybe231d32006-05-21 21:37:21 +0000526 N_("Search for a string or a regular expression");
Benno Schulenberg960a1202014-03-18 22:04:41 +0000527 const char *nano_browser_whereis_msg =
528 N_("Search for a string");
Benno Schulenberg63716122014-04-27 19:51:03 +0000529 const char *nano_prevpage_msg = N_("Go one screenful up");
530 const char *nano_nextpage_msg = N_("Go one screenful down");
David Lawrence Ramsey576bf332004-07-12 03:10:30 +0000531 const char *nano_cut_msg =
532 N_("Cut the current line and store it in the cutbuffer");
533 const char *nano_uncut_msg =
534 N_("Uncut from the cutbuffer into the current line");
David Lawrence Ramsey9b108c22005-06-06 18:38:16 +0000535 const char *nano_cursorpos_msg =
David Lawrence Ramseyf50bd4b2006-04-14 20:15:44 +0000536 N_("Display the position of the cursor");
Benno Schulenbergb8b29ff2014-04-03 21:06:30 +0000537#ifndef DISABLE_SPELLER
David Lawrence Ramsey9b108c22005-06-06 18:38:16 +0000538 const char *nano_spell_msg =
539 N_("Invoke the spell checker, if available");
Benno Schulenbergb8b29ff2014-04-03 21:06:30 +0000540#endif
David Lawrence Ramseybe231d32006-05-21 21:37:21 +0000541 const char *nano_replace_msg =
542 N_("Replace a string or a regular expression");
Benno Schulenbergf803ef52014-04-13 12:16:37 +0000543 const char *nano_gotoline_msg = N_("Go to line and column number");
David Lawrence Ramseyebe34252005-11-15 03:17:35 +0000544#ifndef NANO_TINY
Benno Schulenberg4da24342014-04-27 15:20:57 +0000545 const char *nano_mark_msg = N_("Mark text starting from the cursor position");
546 const char *nano_whereis_next_msg = N_("Repeat the last search");
David Lawrence Ramseycf1879b2006-04-27 23:39:49 +0000547 const char *nano_copy_msg =
548 N_("Copy the current line and store it in the cutbuffer");
David Lawrence Ramseyaee00d42006-07-05 18:42:22 +0000549 const char *nano_indent_msg = N_("Indent the current line");
550 const char *nano_unindent_msg = N_("Unindent the current line");
Chris Allegretta07fcc4c2008-07-10 20:13:04 +0000551 const char *nano_undo_msg = N_("Undo the last operation");
552 const char *nano_redo_msg = N_("Redo the last undone operation");
David Lawrence Ramsey4b4b6082004-11-01 22:54:40 +0000553#endif
David Lawrence Ramsey9f1db5d2007-02-01 13:40:59 +0000554 const char *nano_forward_msg = N_("Go forward one character");
555 const char *nano_back_msg = N_("Go back one character");
David Lawrence Ramsey854a44a2006-04-24 21:14:55 +0000556#ifndef NANO_TINY
David Lawrence Ramsey9f1db5d2007-02-01 13:40:59 +0000557 const char *nano_nextword_msg = N_("Go forward one word");
558 const char *nano_prevword_msg = N_("Go back one word");
David Lawrence Ramsey854a44a2006-04-24 21:14:55 +0000559#endif
David Lawrence Ramsey9f1db5d2007-02-01 13:40:59 +0000560 const char *nano_prevline_msg = N_("Go to previous line");
561 const char *nano_nextline_msg = N_("Go to next line");
562 const char *nano_home_msg = N_("Go to beginning of current line");
563 const char *nano_end_msg = N_("Go to end of current line");
David Lawrence Ramseydb6015c2004-09-11 21:41:13 +0000564#ifndef DISABLE_JUSTIFY
565 const char *nano_parabegin_msg =
David Lawrence Ramsey9f1db5d2007-02-01 13:40:59 +0000566 N_("Go to beginning of paragraph; then of previous paragraph");
David Lawrence Ramseydb6015c2004-09-11 21:41:13 +0000567 const char *nano_paraend_msg =
David Lawrence Ramsey9f1db5d2007-02-01 13:40:59 +0000568 N_("Go just beyond end of paragraph; then of next paragraph");
David Lawrence Ramseydb6015c2004-09-11 21:41:13 +0000569#endif
David Lawrence Ramsey854a44a2006-04-24 21:14:55 +0000570 const char *nano_firstline_msg =
David Lawrence Ramsey9f1db5d2007-02-01 13:40:59 +0000571 N_("Go to the first line of the file");
David Lawrence Ramsey854a44a2006-04-24 21:14:55 +0000572 const char *nano_lastline_msg =
David Lawrence Ramsey9f1db5d2007-02-01 13:40:59 +0000573 N_("Go to the last line of the file");
David Lawrence Ramsey854a44a2006-04-24 21:14:55 +0000574#ifndef NANO_TINY
David Lawrence Ramsey9f1db5d2007-02-01 13:40:59 +0000575 const char *nano_bracket_msg = N_("Go to the matching bracket");
David Lawrence Ramsey854a44a2006-04-24 21:14:55 +0000576 const char *nano_scrollup_msg =
577 N_("Scroll up one line without scrolling the cursor");
578 const char *nano_scrolldown_msg =
579 N_("Scroll down one line without scrolling the cursor");
580#endif
Benno Schulenberg0636d7b2014-04-03 20:23:07 +0000581#ifndef DISABLE_MULTIBUFFER
David Lawrence Ramsey6ad59cd2005-07-08 20:09:16 +0000582 const char *nano_prevfile_msg =
David Lawrence Ramsey9b108c22005-06-06 18:38:16 +0000583 N_("Switch to the previous file buffer");
David Lawrence Ramsey6ad59cd2005-07-08 20:09:16 +0000584 const char *nano_nextfile_msg =
David Lawrence Ramsey9b108c22005-06-06 18:38:16 +0000585 N_("Switch to the next file buffer");
David Lawrence Ramseydb6015c2004-09-11 21:41:13 +0000586#endif
David Lawrence Ramsey40e05722006-04-23 19:21:12 +0000587 const char *nano_verbatim_msg =
David Lawrence Ramsey939d4232006-04-24 21:00:17 +0000588 N_("Insert the next keystroke verbatim");
David Lawrence Ramsey854a44a2006-04-24 21:14:55 +0000589 const char *nano_tab_msg =
David Lawrence Ramseybf784202006-04-29 13:59:04 +0000590 N_("Insert a tab at the cursor position");
David Lawrence Ramsey854a44a2006-04-24 21:14:55 +0000591 const char *nano_enter_msg =
David Lawrence Ramseycf1879b2006-04-27 23:39:49 +0000592 N_("Insert a newline at the cursor position");
David Lawrence Ramsey854a44a2006-04-24 21:14:55 +0000593 const char *nano_delete_msg =
594 N_("Delete the character under the cursor");
595 const char *nano_backspace_msg =
596 N_("Delete the character to the left of the cursor");
David Lawrence Ramseyebe34252005-11-15 03:17:35 +0000597#ifndef NANO_TINY
David Lawrence Ramsey295d1722005-01-01 07:43:32 +0000598 const char *nano_cut_till_end_msg =
599 N_("Cut from the cursor position to the end of the file");
600#endif
David Lawrence Ramseydb6015c2004-09-11 21:41:13 +0000601#ifndef DISABLE_JUSTIFY
602 const char *nano_fulljustify_msg = N_("Justify the entire file");
David Lawrence Ramsey576bf332004-07-12 03:10:30 +0000603#endif
David Lawrence Ramseyc5c52302005-11-15 23:45:29 +0000604#ifndef NANO_TINY
David Lawrence Ramsey854a44a2006-04-24 21:14:55 +0000605 const char *nano_wordcount_msg =
606 N_("Count the number of words, lines, and characters");
David Lawrence Ramsey576bf332004-07-12 03:10:30 +0000607#endif
David Lawrence Ramsey854a44a2006-04-24 21:14:55 +0000608 const char *nano_refresh_msg =
609 N_("Refresh (redraw) the current screen");
Chris Allegretta0018d8e2008-03-13 08:23:52 +0000610 const char *nano_suspend_msg =
611 N_("Suspend the editor (if suspend is enabled)");
David Lawrence Ramseyebe34252005-11-15 03:17:35 +0000612#ifndef NANO_TINY
David Lawrence Ramsey576bf332004-07-12 03:10:30 +0000613 const char *nano_case_msg =
David Lawrence Ramsey69e1ce52006-06-08 02:37:45 +0000614 N_("Toggle the case sensitivity of the search");
David Lawrence Ramsey576bf332004-07-12 03:10:30 +0000615 const char *nano_reverse_msg =
David Lawrence Ramsey69e1ce52006-06-08 02:37:45 +0000616 N_("Reverse the direction of the search");
David Lawrence Ramseyc10d8ff2005-06-03 20:51:39 +0000617#endif
David Lawrence Ramsey576bf332004-07-12 03:10:30 +0000618#ifdef HAVE_REGEX_H
David Lawrence Ramsey69e1ce52006-06-08 02:37:45 +0000619 const char *nano_regexp_msg =
620 N_("Toggle the use of regular expressions");
David Lawrence Ramsey576bf332004-07-12 03:10:30 +0000621#endif
David Lawrence Ramseyebe34252005-11-15 03:17:35 +0000622#ifndef NANO_TINY
David Lawrence Ramsey305d8892006-05-24 19:48:03 +0000623 const char *nano_prev_history_msg =
David Lawrence Ramsey7b0531a2006-07-31 01:30:31 +0000624 N_("Recall the previous search/replace string");
David Lawrence Ramsey305d8892006-05-24 19:48:03 +0000625 const char *nano_next_history_msg =
David Lawrence Ramsey7b0531a2006-07-31 01:30:31 +0000626 N_("Recall the next search/replace string");
David Lawrence Ramseyc10d8ff2005-06-03 20:51:39 +0000627#endif
David Lawrence Ramsey576bf332004-07-12 03:10:30 +0000628#ifndef DISABLE_BROWSER
629 const char *nano_tofiles_msg = N_("Go to file browser");
630#endif
David Lawrence Ramseyebe34252005-11-15 03:17:35 +0000631#ifndef NANO_TINY
David Lawrence Ramsey69e1ce52006-06-08 02:37:45 +0000632 const char *nano_dos_msg = N_("Toggle the use of DOS format");
633 const char *nano_mac_msg = N_("Toggle the use of Mac format");
David Lawrence Ramsey69e1ce52006-06-08 02:37:45 +0000634 const char *nano_append_msg = N_("Toggle appending");
635 const char *nano_prepend_msg = N_("Toggle prepending");
David Lawrence Ramsey9b108c22005-06-06 18:38:16 +0000636 const char *nano_backup_msg =
David Lawrence Ramsey69e1ce52006-06-08 02:37:45 +0000637 N_("Toggle backing up of the original file");
David Lawrence Ramsey576bf332004-07-12 03:10:30 +0000638 const char *nano_execute_msg = N_("Execute external command");
639#endif
Benno Schulenberg0636d7b2014-04-03 20:23:07 +0000640#ifndef DISABLE_MULTIBUFFER
David Lawrence Ramsey69e1ce52006-06-08 02:37:45 +0000641 const char *nano_multibuffer_msg =
642 N_("Toggle the use of a new buffer");
David Lawrence Ramsey576bf332004-07-12 03:10:30 +0000643#endif
644#ifndef DISABLE_BROWSER
David Lawrence Ramseyc41d4282004-07-23 12:51:40 +0000645 const char *nano_exitbrowser_msg = N_("Exit from the file browser");
David Lawrence Ramseye38b8082006-03-30 07:03:04 +0000646 const char *nano_firstfile_msg =
647 N_("Go to the first file in the list");
648 const char *nano_lastfile_msg =
649 N_("Go to the last file in the list");
Chris Allegretta8d41fb82009-12-23 05:03:09 +0000650 const char *nano_forwardfile_msg = N_("Go to the next file in the list");
651 const char *nano_backfile_msg = N_("Go to the previous file in the list");
David Lawrence Ramseyc41d4282004-07-23 12:51:40 +0000652 const char *nano_gotodir_msg = N_("Go to directory");
Chris Allegretta2bef1822001-09-28 19:53:11 +0000653#endif
Benno Schulenberg00389922014-04-04 11:59:03 +0000654#ifndef DISABLE_COLOR
Benno Schulenberg91ee10a2014-03-27 21:35:18 +0000655 const char *nano_lint_msg = N_("Invoke the linter, if available");
Chris Allegretta5575bfa2014-02-24 10:18:15 +0000656 const char *nano_prevlint_msg = N_("Go to previous linter msg");
657 const char *nano_nextlint_msg = N_("Go to next linter msg");
658#endif
Chris Allegrettadab017e2002-04-23 10:56:06 +0000659#endif /* !DISABLE_HELP */
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000660
David Lawrence Ramseyea43a1d2004-03-02 22:52:57 +0000661#ifndef DISABLE_HELP
Chris Allegretta0018d8e2008-03-13 08:23:52 +0000662#define IFSCHELP(help) help
David Lawrence Ramseyea43a1d2004-03-02 22:52:57 +0000663#else
Chris Allegretta0018d8e2008-03-13 08:23:52 +0000664#define IFSCHELP(help) ""
Chris Allegrettadab017e2002-04-23 10:56:06 +0000665#endif
David Lawrence Ramseya593f532003-11-28 19:47:42 +0000666
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000667 while (allfuncs != NULL) {
668 subnfunc *f = allfuncs;
669 allfuncs = (allfuncs)->next;
670 free(f);
671 }
David Lawrence Ramsey576bf332004-07-12 03:10:30 +0000672
Benno Schulenbergf803ef52014-04-13 12:16:37 +0000673 /* Start populating the different menus with functions. */
674
Benno Schulenbergf6a3ab02014-04-16 09:55:16 +0000675 add_to_funcs(do_help_void, MMOST,
Benno Schulenbergc8b60ce2014-04-22 11:57:11 +0000676 /* TRANSLATORS: Try to keep the following strings at most 10 characters. */
677 N_("Get Help"), IFSCHELP(nano_help_msg), FALSE, VIEW);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000678
Benno Schulenbergf6a3ab02014-04-16 09:55:16 +0000679 add_to_funcs(do_cancel, ((MMOST & ~MMAIN & ~MBROWSER) | MYESNO),
Benno Schulenberg9aebd272014-04-22 10:44:24 +0000680 N_("Cancel"), IFSCHELP(nano_cancel_msg), FALSE, VIEW);
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000681
Chris Allegretta637daa82011-02-07 14:45:56 +0000682 add_to_funcs(do_exit, MMAIN,
Benno Schulenberg9fc713b2014-04-22 10:18:48 +0000683 exit_tag, IFSCHELP(nano_exit_msg), FALSE, VIEW);
Benno Schulenberg11d76442014-04-26 19:01:18 +0000684 /* Remember the entry for Exit, to be able to replace it with Close. */
685 exitfunc = tailfunc;
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000686
Chris Allegrettadcd19c92008-03-20 04:51:26 +0000687#ifndef DISABLE_BROWSER
Benno Schulenberg9fc713b2014-04-22 10:18:48 +0000688 add_to_funcs(do_exit, MBROWSER, exit_tag, IFSCHELP(nano_exitbrowser_msg), FALSE, VIEW);
Chris Allegrettadcd19c92008-03-20 04:51:26 +0000689#endif
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000690
Benno Schulenberg6ae77602014-03-04 10:30:15 +0000691 add_to_funcs(do_writeout_void, MMAIN, N_("Write Out"),
Chris Allegretta0018d8e2008-03-13 08:23:52 +0000692 IFSCHELP(nano_writeout_msg), FALSE, NOVIEW);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000693
David Lawrence Ramsey32e3b882004-05-29 01:20:17 +0000694 /* We allow inserting files in view mode if multibuffers are
David Lawrence Ramsey6d6a36c2005-12-08 07:09:08 +0000695 * available, so that we can view multiple files. If we're using
696 * restricted mode, inserting files is disabled, since it allows
697 * reading from or writing to files not specified on the command
698 * line. */
Chris Allegretta637daa82011-02-07 14:45:56 +0000699 add_to_funcs(do_insertfile_void,
Benno Schulenberg63716122014-04-27 19:51:03 +0000700 MMAIN, N_("Read File"), IFSCHELP(nano_insert_msg), TRUE,
Benno Schulenberg0636d7b2014-04-03 20:23:07 +0000701#ifndef DISABLE_MULTIBUFFER
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000702 VIEW);
Chris Allegretta32da4562002-01-02 15:12:21 +0000703#else
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000704 NOVIEW);
Chris Allegretta32da4562002-01-02 15:12:21 +0000705#endif
Chris Allegrettaaf6414a2001-02-11 19:05:05 +0000706
Benno Schulenberg9fc713b2014-04-22 10:18:48 +0000707 add_to_funcs(do_search, MMAIN, whereis_tag,
Chris Allegretta0018d8e2008-03-13 08:23:52 +0000708 IFSCHELP(nano_whereis_msg), FALSE, VIEW);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000709
Benno Schulenberg63716122014-04-27 19:51:03 +0000710 add_to_funcs(do_replace, MMAIN, replace_tag,
711 IFSCHELP(nano_replace_msg), FALSE, NOVIEW);
712
713#ifndef DISABLE_BROWSER
Benno Schulenberg9fc713b2014-04-22 10:18:48 +0000714 add_to_funcs(do_search, MBROWSER, whereis_tag,
Benno Schulenberg960a1202014-03-18 22:04:41 +0000715 IFSCHELP(nano_browser_whereis_msg), FALSE, VIEW);
716
Benno Schulenberg63716122014-04-27 19:51:03 +0000717 add_to_funcs(goto_dir_void, MBROWSER,
718 N_("Go To Dir"), IFSCHELP(nano_gotodir_msg), TRUE, VIEW);
Benno Schulenbergcae7aea2014-02-26 20:37:40 +0000719#endif
720
Benno Schulenberg5c2b44a2014-04-15 20:01:19 +0000721#ifndef DISABLE_HELP
Benno Schulenberg12da94c2014-04-22 10:02:55 +0000722 /* The description ("x") and blank_after (0) are irrelevant,
723 * because the help viewer does not have a help text. */
Benno Schulenberg9fc713b2014-04-22 10:18:48 +0000724 add_to_funcs(do_exit, MHELP, exit_tag, "x", 0, VIEW);
Benno Schulenberg5c2b44a2014-04-15 20:01:19 +0000725
Benno Schulenberg9fc713b2014-04-22 10:18:48 +0000726 add_to_funcs(total_refresh, MHELP, refresh_tag, "x", 0, VIEW);
Benno Schulenberg12da94c2014-04-22 10:02:55 +0000727
728 add_to_funcs(do_up_void, MHELP, prev_line_tag, "x", 0, VIEW);
729 add_to_funcs(do_down_void, MHELP, next_line_tag, "x" , 0, VIEW);
Benno Schulenberg5c2b44a2014-04-15 20:01:19 +0000730#endif
731
Chris Allegretta637daa82011-02-07 14:45:56 +0000732 add_to_funcs(do_cut_text_void, MMAIN, N_("Cut Text"), IFSCHELP(nano_cut_msg),
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000733 FALSE, NOVIEW);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000734
Benno Schulenbergbc6e9aa2014-04-07 09:02:22 +0000735 add_to_funcs(do_uncut_text, MMAIN, uncut_tag, IFSCHELP(nano_uncut_msg),
Benno Schulenberg63716122014-04-27 19:51:03 +0000736 TRUE, NOVIEW);
Benno Schulenbergbc6e9aa2014-04-07 09:02:22 +0000737 /* Remember the entry for Uncut, to be able to replace it with Unjustify. */
Benno Schulenberg20b1e922014-04-26 18:41:43 +0000738 uncutfunc = tailfunc;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000739
Benno Schulenberg63716122014-04-27 19:51:03 +0000740#ifndef DISABLE_JUSTIFY
741 add_to_funcs(do_justify_void, MMAIN, N_("Justify"),
742 nano_justify_msg, FALSE, NOVIEW);
Chris Allegrettae347efb2008-03-09 02:52:40 +0000743#endif
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000744
David Lawrence Ramseyd893fa92004-04-30 04:49:02 +0000745#ifndef DISABLE_SPELLER
Benno Schulenberg9fc713b2014-04-22 10:18:48 +0000746 add_to_funcs(do_spell, MMAIN, spell_tag, IFSCHELP(nano_spell_msg),
Benno Schulenberg63716122014-04-27 19:51:03 +0000747 FALSE, NOVIEW);
David Lawrence Ramseyd893fa92004-04-30 04:49:02 +0000748#endif
David Lawrence Ramseya593f532003-11-28 19:47:42 +0000749
Benno Schulenberg00389922014-04-04 11:59:03 +0000750#ifndef DISABLE_COLOR
Benno Schulenberg9fc713b2014-04-22 10:18:48 +0000751 add_to_funcs(do_linter, MMAIN, lint_tag, IFSCHELP(nano_lint_msg),
Chris Allegretta5575bfa2014-02-24 10:18:15 +0000752 TRUE, NOVIEW);
753#endif
754
Benno Schulenberg61758e92014-04-27 14:21:57 +0000755#ifndef NANO_TINY
Benno Schulenberg672821c2014-05-03 20:09:47 +0000756 add_to_funcs(case_sens_void, MWHEREIS|MREPLACE,
Benno Schulenberg61758e92014-04-27 14:21:57 +0000757 N_("Case Sens"), IFSCHELP(nano_case_msg), FALSE, VIEW);
758#endif
759
760#ifdef HAVE_REGEX_H
Benno Schulenberg672821c2014-05-03 20:09:47 +0000761 add_to_funcs(regexp_void, MWHEREIS|MREPLACE,
Benno Schulenberg61758e92014-04-27 14:21:57 +0000762 N_("Regexp"), IFSCHELP(nano_regexp_msg), FALSE, VIEW);
763#endif
764
765#ifndef NANO_TINY
Benno Schulenberg672821c2014-05-03 20:09:47 +0000766 add_to_funcs(backwards_void, MWHEREIS|MREPLACE,
Benno Schulenberg61758e92014-04-27 14:21:57 +0000767 N_("Backwards"), IFSCHELP(nano_reverse_msg), FALSE, VIEW);
768#endif
769
770 add_to_funcs(do_replace, MWHEREIS,
771 replace_tag, IFSCHELP(nano_replace_msg), FALSE, VIEW);
772
773 add_to_funcs(no_replace_void, MREPLACE,
774 N_("No Replace"), IFSCHELP(nano_whereis_msg), FALSE, VIEW);
775
776#ifndef DISABLE_JUSTIFY
777 add_to_funcs(do_full_justify, MWHEREIS, fulljustify_tag,
778 IFSCHELP(nano_fulljustify_msg), FALSE, NOVIEW);
779#endif
780
Benno Schulenberg63716122014-04-27 19:51:03 +0000781 add_to_funcs(do_cursorpos_void, MMAIN, N_("Cur Pos"),
782 IFSCHELP(nano_cursorpos_msg), FALSE, VIEW);
783
784 add_to_funcs(do_gotolinecolumn_void, MMAIN|MWHEREIS,
785 gotoline_tag, IFSCHELP(nano_gotoline_msg), TRUE, VIEW);
786
787 add_to_funcs(do_page_up, MMAIN|MHELP|MBROWSER,
788 N_("Prev Page"), IFSCHELP(nano_prevpage_msg), FALSE, VIEW);
789 add_to_funcs(do_page_down, MMAIN|MHELP|MBROWSER,
790 N_("Next Page"), IFSCHELP(nano_nextpage_msg), FALSE, VIEW);
Benno Schulenberg61758e92014-04-27 14:21:57 +0000791
Chris Allegretta637daa82011-02-07 14:45:56 +0000792 add_to_funcs(do_first_line,
Benno Schulenberge167afe2014-04-16 09:26:15 +0000793 (MMAIN|MHELP|MWHEREIS|MREPLACE|MREPLACEWITH|MGOTOLINE),
Benno Schulenbergc8b60ce2014-04-22 11:57:11 +0000794 N_("First Line"), IFSCHELP(nano_firstline_msg), FALSE, VIEW);
Chris Allegretta637daa82011-02-07 14:45:56 +0000795 add_to_funcs(do_last_line,
Benno Schulenberge167afe2014-04-16 09:26:15 +0000796 (MMAIN|MHELP|MWHEREIS|MREPLACE|MREPLACEWITH|MGOTOLINE),
Benno Schulenberg63716122014-04-27 19:51:03 +0000797 N_("Last Line"), IFSCHELP(nano_lastline_msg), TRUE, VIEW);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000798
David Lawrence Ramseyebe34252005-11-15 03:17:35 +0000799#ifndef NANO_TINY
Benno Schulenberg4da24342014-04-27 15:20:57 +0000800 add_to_funcs(do_research, MMAIN, whereis_next_tag,
801 IFSCHELP(nano_whereis_next_msg), FALSE, VIEW);
802
803 add_to_funcs(do_find_bracket, MMAIN, N_("To Bracket"),
804 IFSCHELP(nano_bracket_msg), FALSE, VIEW);
805
Chris Allegretta2ad1de02012-12-30 19:20:10 +0000806 add_to_funcs(do_mark, MMAIN, N_("Mark Text"),
Chris Allegretta1d778232008-08-30 21:00:00 +0000807 IFSCHELP(nano_mark_msg), FALSE, VIEW);
David Lawrence Ramseycf1879b2006-04-27 23:39:49 +0000808
Chris Allegretta637daa82011-02-07 14:45:56 +0000809 add_to_funcs(do_copy_text, MMAIN, N_("Copy Text"),
Benno Schulenberg4da24342014-04-27 15:20:57 +0000810 IFSCHELP(nano_copy_msg), TRUE, NOVIEW);
David Lawrence Ramseyf85001a2006-04-28 13:19:56 +0000811
Chris Allegretta637daa82011-02-07 14:45:56 +0000812 add_to_funcs(do_indent_void, MMAIN, N_("Indent Text"),
Chris Allegretta1d778232008-08-30 21:00:00 +0000813 IFSCHELP(nano_indent_msg), FALSE, NOVIEW);
Chris Allegretta637daa82011-02-07 14:45:56 +0000814 add_to_funcs(do_unindent, MMAIN, N_("Unindent Text"),
Benno Schulenberg4da24342014-04-27 15:20:57 +0000815 IFSCHELP(nano_unindent_msg), TRUE, NOVIEW);
Chris Allegretta07fcc4c2008-07-10 20:13:04 +0000816
Chris Allegrettaa48507d2009-08-14 03:18:29 +0000817 if (ISSET(UNDOABLE)) {
Chris Allegretta637daa82011-02-07 14:45:56 +0000818 add_to_funcs(do_undo, MMAIN, N_("Undo"),
Chris Allegrettaad37e672009-07-12 03:36:58 +0000819 IFSCHELP(nano_undo_msg), FALSE, NOVIEW);
Chris Allegretta637daa82011-02-07 14:45:56 +0000820 add_to_funcs(do_redo, MMAIN, N_("Redo"),
Chris Allegrettaad37e672009-07-12 03:36:58 +0000821 IFSCHELP(nano_redo_msg), TRUE, NOVIEW);
822 }
Benno Schulenberge4c34c32014-03-17 14:15:57 +0000823#endif /* !NANO_TINY */
David Lawrence Ramsey1df3e2d2006-04-22 19:45:26 +0000824
Chris Allegretta637daa82011-02-07 14:45:56 +0000825 add_to_funcs(do_left, MMAIN, N_("Back"), IFSCHELP(nano_back_msg),
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000826 FALSE, VIEW);
Benno Schulenberg88ff6a72014-03-17 21:26:53 +0000827 add_to_funcs(do_right, MMAIN, N_("Forward"), IFSCHELP(nano_forward_msg),
828 FALSE, VIEW);
Chris Allegretta8d41fb82009-12-23 05:03:09 +0000829
830#ifndef DISABLE_BROWSER
Chris Allegretta637daa82011-02-07 14:45:56 +0000831 add_to_funcs(do_left, MBROWSER, N_("Back"), IFSCHELP(nano_backfile_msg),
Chris Allegretta8d41fb82009-12-23 05:03:09 +0000832 FALSE, VIEW);
Benno Schulenberg88ff6a72014-03-17 21:26:53 +0000833 add_to_funcs(do_right, MBROWSER, N_("Forward"), IFSCHELP(nano_forwardfile_msg),
834 FALSE, VIEW);
Chris Allegretta8d41fb82009-12-23 05:03:09 +0000835#endif
836
David Lawrence Ramsey1df3e2d2006-04-22 19:45:26 +0000837#ifndef NANO_TINY
Chris Allegretta637daa82011-02-07 14:45:56 +0000838 add_to_funcs(do_prev_word_void, MMAIN, N_("Prev Word"),
Chris Allegretta1d778232008-08-30 21:00:00 +0000839 IFSCHELP(nano_prevword_msg), FALSE, VIEW);
Benno Schulenbergbe5ab4e2014-02-25 21:30:12 +0000840 add_to_funcs(do_next_word_void, MMAIN, N_("Next Word"),
841 IFSCHELP(nano_nextword_msg), FALSE, VIEW);
Chris Allegretta8d990b52001-09-22 22:14:25 +0000842#endif
David Lawrence Ramseye0497062003-08-23 21:11:06 +0000843
Benno Schulenberg63716122014-04-27 19:51:03 +0000844 add_to_funcs(do_home, MMAIN, N_("Home"), IFSCHELP(nano_home_msg),
845 FALSE, VIEW);
846 add_to_funcs(do_end, MMAIN, N_("End"), IFSCHELP(nano_end_msg),
847 FALSE, VIEW);
848
Benno Schulenberg12da94c2014-04-22 10:02:55 +0000849 add_to_funcs(do_up_void, (MMAIN|MBROWSER), prev_line_tag,
Chris Allegretta0018d8e2008-03-13 08:23:52 +0000850 IFSCHELP(nano_prevline_msg), FALSE, VIEW);
Benno Schulenberg12da94c2014-04-22 10:02:55 +0000851 add_to_funcs(do_down_void, (MMAIN|MBROWSER), next_line_tag,
Chris Allegretta0018d8e2008-03-13 08:23:52 +0000852 IFSCHELP(nano_nextline_msg), TRUE, VIEW);
David Lawrence Ramsey1df3e2d2006-04-22 19:45:26 +0000853
David Lawrence Ramseydb6015c2004-09-11 21:41:13 +0000854#ifndef DISABLE_JUSTIFY
Benno Schulenbergc8b60ce2014-04-22 11:57:11 +0000855 add_to_funcs(do_para_begin_void, (MMAIN|MWHEREIS), N_("Beg of Par"),
Chris Allegretta1d778232008-08-30 21:00:00 +0000856 IFSCHELP(nano_parabegin_msg), FALSE, VIEW);
Benno Schulenbergc8b60ce2014-04-22 11:57:11 +0000857 add_to_funcs(do_para_end_void, (MMAIN|MWHEREIS), N_("End of Par"),
Chris Allegretta1d778232008-08-30 21:00:00 +0000858 IFSCHELP(nano_paraend_msg), FALSE, VIEW);
David Lawrence Ramseydb6015c2004-09-11 21:41:13 +0000859#endif
David Lawrence Ramseye0497062003-08-23 21:11:06 +0000860
David Lawrence Ramsey1df3e2d2006-04-22 19:45:26 +0000861#ifndef NANO_TINY
Chris Allegretta637daa82011-02-07 14:45:56 +0000862 add_to_funcs(do_scroll_up, MMAIN, N_("Scroll Up"),
Chris Allegretta1d778232008-08-30 21:00:00 +0000863 IFSCHELP(nano_scrollup_msg), FALSE, VIEW);
Chris Allegretta637daa82011-02-07 14:45:56 +0000864 add_to_funcs(do_scroll_down, MMAIN, N_("Scroll Down"),
Benno Schulenberg4da24342014-04-27 15:20:57 +0000865 IFSCHELP(nano_scrolldown_msg), TRUE, VIEW);
David Lawrence Ramsey1df3e2d2006-04-22 19:45:26 +0000866#endif
David Lawrence Ramseydf453652006-04-21 02:05:09 +0000867
Benno Schulenberg0636d7b2014-04-03 20:23:07 +0000868#ifndef DISABLE_MULTIBUFFER
Benno Schulenbergc8b60ce2014-04-22 11:57:11 +0000869 add_to_funcs(switch_to_prev_buffer_void, MMAIN, N_("Prev File"),
Chris Allegretta2cca4832008-03-31 06:25:14 +0000870 IFSCHELP(nano_prevfile_msg), FALSE, VIEW);
Chris Allegretta637daa82011-02-07 14:45:56 +0000871 add_to_funcs(switch_to_next_buffer_void, MMAIN, N_("Next File"),
Chris Allegretta2cca4832008-03-31 06:25:14 +0000872 IFSCHELP(nano_nextfile_msg), TRUE, VIEW);
Chris Allegrettaa8c22572002-02-15 19:17:02 +0000873#endif
Chris Allegrettab3655b42001-10-22 03:15:31 +0000874
Benno Schulenbergc8b60ce2014-04-22 11:57:11 +0000875 add_to_funcs(do_verbatim_input, MMAIN, N_("Verbatim"),
Chris Allegretta0018d8e2008-03-13 08:23:52 +0000876 IFSCHELP(nano_verbatim_msg), FALSE, NOVIEW);
Chris Allegrettaaa17df02008-03-17 05:50:04 +0000877
Chris Allegretta637daa82011-02-07 14:45:56 +0000878 add_to_funcs(do_tab, MMAIN, N_("Tab"), IFSCHELP(nano_tab_msg),
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000879 FALSE, NOVIEW);
Chris Allegretta637daa82011-02-07 14:45:56 +0000880 add_to_funcs(do_enter_void, MMAIN, N_("Enter"), IFSCHELP(nano_enter_msg),
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000881 FALSE, NOVIEW);
Chris Allegretta637daa82011-02-07 14:45:56 +0000882 add_to_funcs(do_delete, MMAIN, N_("Delete"), IFSCHELP(nano_delete_msg),
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000883 FALSE, NOVIEW);
Chris Allegretta637daa82011-02-07 14:45:56 +0000884 add_to_funcs(do_backspace, MMAIN, N_("Backspace"), IFSCHELP(nano_backspace_msg),
David Lawrence Ramseybf487982006-04-24 20:50:52 +0000885#ifndef NANO_TINY
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000886 FALSE,
David Lawrence Ramseybf487982006-04-24 20:50:52 +0000887#else
Chris Allegretta79a33bb2008-03-05 07:34:01 +0000888 TRUE,
David Lawrence Ramseybf487982006-04-24 20:50:52 +0000889#endif
Chris Allegrettaeb643142008-03-12 04:44:14 +0000890 NOVIEW);
891
David Lawrence Ramsey2ca23562006-04-23 19:15:15 +0000892#ifndef NANO_TINY
Chris Allegretta637daa82011-02-07 14:45:56 +0000893 add_to_funcs(do_cut_till_end, MMAIN, N_("CutTillEnd"),
Chris Allegretta1d778232008-08-30 21:00:00 +0000894 IFSCHELP(nano_cut_till_end_msg), TRUE, NOVIEW);
David Lawrence Ramsey2ca23562006-04-23 19:15:15 +0000895#endif
896
David Lawrence Ramseydb6015c2004-09-11 21:41:13 +0000897#ifndef DISABLE_JUSTIFY
Benno Schulenberg61758e92014-04-27 14:21:57 +0000898 add_to_funcs(do_full_justify, MMAIN, fulljustify_tag,
Chris Allegretta1d778232008-08-30 21:00:00 +0000899 IFSCHELP(nano_fulljustify_msg), FALSE, NOVIEW);
David Lawrence Ramseydb6015c2004-09-11 21:41:13 +0000900#endif
901
David Lawrence Ramseyc5c52302005-11-15 23:45:29 +0000902#ifndef NANO_TINY
Chris Allegretta637daa82011-02-07 14:45:56 +0000903 add_to_funcs(do_wordlinechar_count, MMAIN, N_("Word Count"),
Chris Allegretta1d778232008-08-30 21:00:00 +0000904 IFSCHELP(nano_wordcount_msg), FALSE, VIEW);
David Lawrence Ramsey1df3e2d2006-04-22 19:45:26 +0000905#endif
David Lawrence Ramseyefb4b0a2006-04-19 14:09:01 +0000906
Benno Schulenberg9fc713b2014-04-22 10:18:48 +0000907 add_to_funcs(total_refresh, MMAIN, refresh_tag,
Chris Allegretta0018d8e2008-03-13 08:23:52 +0000908 IFSCHELP(nano_refresh_msg), FALSE, VIEW);
909
Benno Schulenbergc8b60ce2014-04-22 11:57:11 +0000910 add_to_funcs(do_suspend_void, MMAIN, N_("Suspend"),
Chris Allegretta0018d8e2008-03-13 08:23:52 +0000911 IFSCHELP(nano_suspend_msg), TRUE, VIEW);
David Lawrence Ramsey8faf3052003-09-04 20:25:29 +0000912
David Lawrence Ramseyebe34252005-11-15 03:17:35 +0000913#ifndef NANO_TINY
Chris Allegretta637daa82011-02-07 14:45:56 +0000914 add_to_funcs(get_history_older_void,
Benno Schulenberge167afe2014-04-16 09:26:15 +0000915 (MWHEREIS|MREPLACE|MREPLACEWITH|MWHEREISFILE),
Benno Schulenberg9aebd272014-04-22 10:44:24 +0000916 N_("PrevHstory"), IFSCHELP(nano_prev_history_msg), FALSE, VIEW);
David Lawrence Ramsey305d8892006-05-24 19:48:03 +0000917
Chris Allegretta637daa82011-02-07 14:45:56 +0000918 add_to_funcs(get_history_newer_void,
Benno Schulenberge167afe2014-04-16 09:26:15 +0000919 (MWHEREIS|MREPLACE|MREPLACEWITH|MWHEREISFILE),
Benno Schulenberg9aebd272014-04-22 10:44:24 +0000920 N_("NextHstory"), IFSCHELP(nano_next_history_msg), FALSE, VIEW);
David Lawrence Ramseyc10d8ff2005-06-03 20:51:39 +0000921#endif
David Lawrence Ramsey02085d72004-11-07 16:04:18 +0000922
Chris Allegretta637daa82011-02-07 14:45:56 +0000923 add_to_funcs(gototext_void, MGOTOLINE,
Benno Schulenberg9aebd272014-04-22 10:44:24 +0000924 N_("Go To Text"), IFSCHELP(nano_whereis_msg), TRUE, VIEW);
David Lawrence Ramsey576bf332004-07-12 03:10:30 +0000925
David Lawrence Ramseyebe34252005-11-15 03:17:35 +0000926#ifndef NANO_TINY
David Lawrence Ramsey32e3b882004-05-29 01:20:17 +0000927 /* If we're using restricted mode, the DOS format, Mac format,
928 * append, prepend, and backup toggles are disabled. The first and
929 * second are useless since inserting files is disabled, the third
930 * and fourth are disabled because they allow writing to files not
931 * specified on the command line, and the fifth is useless since
932 * backups are disabled. */
Benno Schulenberg91ee10a2014-03-27 21:35:18 +0000933 if (!ISSET(RESTRICTED)) {
Chris Allegretta637daa82011-02-07 14:45:56 +0000934 add_to_funcs(dos_format_void, MWRITEFILE,
Benno Schulenberg9aebd272014-04-22 10:44:24 +0000935 N_("DOS Format"), IFSCHELP(nano_dos_msg), FALSE, NOVIEW);
Chris Allegrettaa8c22572002-02-15 19:17:02 +0000936
Chris Allegretta637daa82011-02-07 14:45:56 +0000937 add_to_funcs(mac_format_void, MWRITEFILE,
Benno Schulenberg9aebd272014-04-22 10:44:24 +0000938 N_("Mac Format"), IFSCHELP(nano_mac_msg), FALSE, NOVIEW);
Chris Allegrettaa8c22572002-02-15 19:17:02 +0000939
Benno Schulenberge34ac8e2014-03-17 12:15:23 +0000940 add_to_funcs(append_void, MWRITEFILE,
Benno Schulenberg9aebd272014-04-22 10:44:24 +0000941 N_("Append"), IFSCHELP(nano_append_msg), FALSE, NOVIEW);
Benno Schulenberge34ac8e2014-03-17 12:15:23 +0000942 add_to_funcs(prepend_void, MWRITEFILE,
Benno Schulenberg9aebd272014-04-22 10:44:24 +0000943 N_("Prepend"), IFSCHELP(nano_prepend_msg), FALSE, NOVIEW);
Chris Allegretta0e9b7aa2002-04-16 03:15:47 +0000944
Benno Schulenberge34ac8e2014-03-17 12:15:23 +0000945 add_to_funcs(backup_file_void, MWRITEFILE,
Benno Schulenberg9aebd272014-04-22 10:44:24 +0000946 N_("Backup File"), IFSCHELP(nano_backup_msg), FALSE, NOVIEW);
Benno Schulenberg91ee10a2014-03-27 21:35:18 +0000947 }
David Lawrence Ramseya593f532003-11-28 19:47:42 +0000948
Benno Schulenberg91ee10a2014-03-27 21:35:18 +0000949 /* If we're using restricted mode, file insertion is disabled, and
950 * thus command execution and the multibuffer toggle have no place. */
951 if (!ISSET(RESTRICTED)) {
Benno Schulenberge34ac8e2014-03-17 12:15:23 +0000952 add_to_funcs(ext_cmd_void, MINSERTFILE,
Benno Schulenberg9aebd272014-04-22 10:44:24 +0000953 N_("Execute Command"), IFSCHELP(nano_execute_msg), FALSE, NOVIEW);
David Lawrence Ramseya593f532003-11-28 19:47:42 +0000954
Benno Schulenberg0636d7b2014-04-03 20:23:07 +0000955#ifndef DISABLE_MULTIBUFFER
Benno Schulenberg91ee10a2014-03-27 21:35:18 +0000956 add_to_funcs(new_buffer_void, MINSERTFILE|MEXTCMD,
Benno Schulenberg9aebd272014-04-22 10:44:24 +0000957 N_("New Buffer"), IFSCHELP(nano_multibuffer_msg), FALSE, NOVIEW);
David Lawrence Ramseye21adfa2002-09-13 18:14:04 +0000958#endif
Benno Schulenberg91ee10a2014-03-27 21:35:18 +0000959 }
Benno Schulenberge4c34c32014-03-17 14:15:57 +0000960#endif /* !NANO_TINY */
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000961
Rocco Corsiaf5c3022001-01-12 07:51:05 +0000962#ifndef DISABLE_BROWSER
Benno Schulenberg63716122014-04-27 19:51:03 +0000963 if (!ISSET(RESTRICTED))
964 add_to_funcs(to_files_void, MWRITEFILE|MINSERTFILE,
965 N_("To Files"), IFSCHELP(nano_tofiles_msg), FALSE, VIEW);
966
Benno Schulenberge34ac8e2014-03-17 12:15:23 +0000967 add_to_funcs(do_first_file, (MBROWSER|MWHEREISFILE),
Benno Schulenberg9aebd272014-04-22 10:44:24 +0000968 N_("First File"), IFSCHELP(nano_firstfile_msg), FALSE, VIEW);
Benno Schulenberge34ac8e2014-03-17 12:15:23 +0000969 add_to_funcs(do_last_file, (MBROWSER|MWHEREISFILE),
Benno Schulenberg9aebd272014-04-22 10:44:24 +0000970 N_("Last File"), IFSCHELP(nano_lastfile_msg), FALSE, VIEW);
Benno Schulenberg63716122014-04-27 19:51:03 +0000971#endif
Chris Allegrettab3655b42001-10-22 03:15:31 +0000972
Benno Schulenberg63716122014-04-27 19:51:03 +0000973#if !defined(NANO_TINY) && !defined(DISABLE_BROWSER)
974 add_to_funcs(do_research, MBROWSER, whereis_next_tag,
975 IFSCHELP(nano_whereis_next_msg), FALSE, VIEW);
976#endif
977
978#ifndef DISABLE_COLOR
979 add_to_funcs(do_page_up, MLINTER,
980 prev_lint_tag, IFSCHELP(nano_prevlint_msg), FALSE, VIEW);
981 add_to_funcs(do_page_down, MLINTER,
982 next_lint_tag, IFSCHELP(nano_nextlint_msg), FALSE, VIEW);
David Lawrence Ramseye38b8082006-03-30 07:03:04 +0000983#endif
984
Benno Schulenbergf803ef52014-04-13 12:16:37 +0000985 /* Start associating key combos with functions in specific menus. */
986
Benno Schulenbergf6a3ab02014-04-16 09:55:16 +0000987 add_to_sclist(MMOST, "^G", do_help_void, 0, TRUE);
988 add_to_sclist(MMOST, "F1", do_help_void, 0, TRUE);
Chris Allegretta637daa82011-02-07 14:45:56 +0000989 add_to_sclist(MMAIN|MHELP|MBROWSER, "^X", do_exit, 0, TRUE);
990 add_to_sclist(MMAIN|MHELP|MBROWSER, "F2", do_exit, 0, TRUE);
Chris Allegretta637daa82011-02-07 14:45:56 +0000991 add_to_sclist(MMAIN, "^O", do_writeout_void, 0, TRUE);
992 add_to_sclist(MMAIN, "F3", do_writeout_void, 0, TRUE);
Chris Allegretta637daa82011-02-07 14:45:56 +0000993 add_to_sclist(MMAIN, "^R", do_insertfile_void, 0, TRUE);
994 add_to_sclist(MMAIN, "F5", do_insertfile_void, 0, TRUE);
Benno Schulenberg94b1d012014-04-21 18:05:11 +0000995 add_to_sclist(MMAIN, "Ins", do_insertfile_void, 0, TRUE);
Chris Allegretta637daa82011-02-07 14:45:56 +0000996 add_to_sclist(MMAIN|MBROWSER, "^W", do_search, 0, TRUE);
997 add_to_sclist(MMAIN|MBROWSER, "F6", do_search, 0, TRUE);
Benno Schulenberg523598a2014-05-03 19:19:31 +0000998 add_to_sclist(MMAIN, "^\\", do_replace, 0, TRUE);
999 add_to_sclist(MMAIN, "M-R", do_replace, 0, TRUE);
1000 add_to_sclist(MMAIN, "F14", do_replace, 0, TRUE);
1001 add_to_sclist(MMAIN, "^K", do_cut_text_void, 0, TRUE);
1002 add_to_sclist(MMAIN, "F9", do_cut_text_void, 0, TRUE);
1003 add_to_sclist(MMAIN, "^U", do_uncut_text, 0, TRUE);
1004 add_to_sclist(MMAIN, "F10", do_uncut_text, 0, TRUE);
1005#ifndef DISABLE_JUSTIFY
1006 add_to_sclist(MMAIN, "^J", do_justify_void, 0, TRUE);
1007 add_to_sclist(MMAIN, "F4", do_justify_void, 0, TRUE);
1008#endif
1009#ifndef DISABLE_SPELLER
1010 add_to_sclist(MMAIN, "^T", do_spell, 0, TRUE);
1011 add_to_sclist(MMAIN, "F12", do_spell, 0, TRUE);
Benno Schulenberg387b2092014-05-09 15:14:29 +00001012#else
1013#ifndef DISABLE_COLOR
1014 add_to_sclist(MMAIN, "^T", do_linter, 0, TRUE);
1015 add_to_sclist(MMAIN, "F12", do_linter, 0, TRUE);
1016#endif
Benno Schulenberg523598a2014-05-03 19:19:31 +00001017#endif
1018 add_to_sclist(MMAIN, "^C", do_cursorpos_void, 0, TRUE);
1019 add_to_sclist(MMAIN, "F11", do_cursorpos_void, 0, TRUE);
1020 add_to_sclist(MMAIN, "^_", do_gotolinecolumn_void, 0, TRUE);
1021 add_to_sclist(MMAIN, "M-G", do_gotolinecolumn_void, 0, TRUE);
1022 add_to_sclist(MMAIN, "F13", do_gotolinecolumn_void, 0, TRUE);
Chris Allegretta5575bfa2014-02-24 10:18:15 +00001023 add_to_sclist(MMAIN|MBROWSER|MHELP|MWHEREISFILE|MLINTER, "^Y", do_page_up, 0, TRUE);
1024 add_to_sclist(MMAIN|MBROWSER|MHELP|MWHEREISFILE|MLINTER, "F7", do_page_up, 0, TRUE);
Benno Schulenbergd6308802014-04-21 15:45:23 +00001025 add_to_sclist(MMAIN|MBROWSER|MHELP|MWHEREISFILE|MLINTER, "PgUp", do_page_up, 0, TRUE);
Chris Allegretta5575bfa2014-02-24 10:18:15 +00001026 add_to_sclist(MMAIN|MBROWSER|MHELP|MWHEREISFILE|MLINTER, "^V", do_page_down, 0, TRUE);
1027 add_to_sclist(MMAIN|MBROWSER|MHELP|MWHEREISFILE|MLINTER, "F8", do_page_down, 0, TRUE);
Benno Schulenbergd6308802014-04-21 15:45:23 +00001028 add_to_sclist(MMAIN|MBROWSER|MHELP|MWHEREISFILE|MLINTER, "PgDn", do_page_down, 0, TRUE);
Benno Schulenberg523598a2014-05-03 19:19:31 +00001029 add_to_sclist(MMAIN|MHELP, "M-\\", do_first_line, 0, TRUE);
1030 add_to_sclist(MMAIN|MHELP, "M-|", do_first_line, 0, TRUE);
1031 add_to_sclist(MMAIN|MHELP, "M-/", do_last_line, 0, TRUE);
1032 add_to_sclist(MMAIN|MHELP, "M-?", do_last_line, 0, TRUE);
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001033#ifndef NANO_TINY
Benno Schulenberg523598a2014-05-03 19:19:31 +00001034 add_to_sclist(MMAIN|MBROWSER, "M-W", do_research, 0, TRUE);
1035 add_to_sclist(MMAIN|MBROWSER, "F16", do_research, 0, TRUE);
1036 add_to_sclist(MMAIN, "M-]", do_find_bracket, 0, TRUE);
Chris Allegretta637daa82011-02-07 14:45:56 +00001037 add_to_sclist(MMAIN, "^^", do_mark, 0, TRUE);
Chris Allegretta637daa82011-02-07 14:45:56 +00001038 add_to_sclist(MMAIN, "M-A", do_mark, 0, TRUE);
Benno Schulenberg9c0f9de2014-04-22 19:10:26 +00001039 add_to_sclist(MMAIN, "F15", do_mark, 0, TRUE);
Chris Allegretta637daa82011-02-07 14:45:56 +00001040 add_to_sclist(MMAIN, "M-^", do_copy_text, 0, TRUE);
1041 add_to_sclist(MMAIN, "M-6", do_copy_text, 0, TRUE);
1042 add_to_sclist(MMAIN, "M-}", do_indent_void, 0, TRUE);
1043 add_to_sclist(MMAIN, "M-{", do_unindent, 0, TRUE);
Chris Allegrettaa48507d2009-08-14 03:18:29 +00001044 if (ISSET(UNDOABLE)) {
Chris Allegretta637daa82011-02-07 14:45:56 +00001045 add_to_sclist(MMAIN, "M-U", do_undo, 0, TRUE);
Benno Schulenberga65ef422014-03-17 21:36:37 +00001046 add_to_sclist(MMAIN, "M-E", do_redo, 0, TRUE);
Chris Allegrettaad37e672009-07-12 03:36:58 +00001047 }
Benno Schulenbergc3e4a1f2014-03-17 11:47:49 +00001048#endif
Benno Schulenberg4c9573d2014-04-16 09:12:13 +00001049 add_to_sclist(MMOST, "^B", do_left, 0, TRUE);
Benno Schulenberg47be8c22014-04-22 19:07:32 +00001050 add_to_sclist(MMOST, "^F", do_right, 0, TRUE);
Benno Schulenbergd6308802014-04-21 15:45:23 +00001051 add_to_sclist(MMOST, "Left", do_left, 0, TRUE);
Benno Schulenberg47be8c22014-04-22 19:07:32 +00001052 add_to_sclist(MMOST, "Right", do_right, 0, TRUE);
Benno Schulenbergc3e4a1f2014-03-17 11:47:49 +00001053#ifndef NANO_TINY
Chris Allegretta637daa82011-02-07 14:45:56 +00001054 add_to_sclist(MMAIN, "^Space", do_next_word_void, 0, TRUE);
1055 add_to_sclist(MMAIN, "M-Space", do_prev_word_void, 0, TRUE);
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001056#endif
Benno Schulenberg4c9573d2014-04-16 09:12:13 +00001057 add_to_sclist(MMOST, "^A", do_home, 0, TRUE);
Benno Schulenbergd6308802014-04-21 15:45:23 +00001058 add_to_sclist(MMOST, "Home", do_home, 0, TRUE);
Benno Schulenberg4c9573d2014-04-16 09:12:13 +00001059 add_to_sclist(MMOST, "^E", do_end, 0, TRUE);
Benno Schulenbergd6308802014-04-21 15:45:23 +00001060 add_to_sclist(MMOST, "End", do_end, 0, TRUE);
Benno Schulenberg523598a2014-05-03 19:19:31 +00001061 add_to_sclist(MMAIN|MHELP|MBROWSER, "^P", do_up_void, 0, TRUE);
1062 add_to_sclist(MMAIN|MHELP|MBROWSER, "Up", do_up_void, 0, TRUE);
1063 add_to_sclist(MMAIN|MHELP|MBROWSER, "^N", do_down_void, 0, TRUE);
1064 add_to_sclist(MMAIN|MHELP|MBROWSER, "Down", do_down_void, 0, TRUE);
1065#ifndef DISABLE_JUSTIFY
Benno Schulenbergbe3e3022014-05-03 20:27:25 +00001066 add_to_sclist(MMAIN, "M-(", do_para_begin_void, 0, TRUE);
1067 add_to_sclist(MMAIN, "M-9", do_para_begin_void, 0, TRUE);
1068 add_to_sclist(MMAIN, "M-)", do_para_end_void, 0, TRUE);
1069 add_to_sclist(MMAIN, "M-0", do_para_end_void, 0, TRUE);
Benno Schulenberg523598a2014-05-03 19:19:31 +00001070#endif
1071#ifndef NANO_TINY
1072 add_to_sclist(MMAIN, "M--", do_scroll_up, 0, TRUE);
1073 add_to_sclist(MMAIN, "M-_", do_scroll_up, 0, TRUE);
1074 add_to_sclist(MMAIN, "M-+", do_scroll_down, 0, TRUE);
1075 add_to_sclist(MMAIN, "M-=", do_scroll_down, 0, TRUE);
1076#endif
1077#ifndef DISABLE_MULTIBUFFER
1078 add_to_sclist(MMAIN, "M-<", switch_to_prev_buffer_void, 0, TRUE);
1079 add_to_sclist(MMAIN, "M-,", switch_to_prev_buffer_void, 0, TRUE);
1080 add_to_sclist(MMAIN, "M->", switch_to_next_buffer_void, 0, TRUE);
1081 add_to_sclist(MMAIN, "M-.", switch_to_next_buffer_void, 0, TRUE);
1082#endif
1083 add_to_sclist(MMOST, "M-V", do_verbatim_input, 0, TRUE);
1084#ifndef NANO_TINY
1085 add_to_sclist(MMAIN, "M-T", do_cut_till_end, 0, TRUE);
1086 add_to_sclist(MMAIN, "M-D", do_wordlinechar_count, 0, TRUE);
1087#endif
1088#ifndef DISABLE_JUSTIFY
1089 add_to_sclist(MMAIN|MWHEREIS, "M-J", do_full_justify, 0, TRUE);
1090#endif
1091 add_to_sclist(MMAIN|MHELP, "^L", total_refresh, 0, FALSE);
1092 add_to_sclist(MMAIN, "^Z", do_suspend_void, 0, FALSE);
1093
1094#ifndef NANO_TINY
Benno Schulenberga6804b52014-05-09 20:33:49 +00001095 /* Group of "Appearance" toggles. */
Benno Schulenberg523598a2014-05-03 19:19:31 +00001096 add_to_sclist(MMAIN, "M-X", do_toggle_void, NO_HELP, TRUE);
1097 add_to_sclist(MMAIN, "M-C", do_toggle_void, CONST_UPDATE, TRUE);
1098 add_to_sclist(MMAIN, "M-O", do_toggle_void, MORE_SPACE, TRUE);
1099 add_to_sclist(MMAIN, "M-S", do_toggle_void, SMOOTH_SCROLL, TRUE);
Benno Schulenberga6804b52014-05-09 20:33:49 +00001100 add_to_sclist(MMAIN, "M-$", do_toggle_void, SOFTWRAP, TRUE);
Benno Schulenberg523598a2014-05-03 19:19:31 +00001101 add_to_sclist(MMAIN, "M-P", do_toggle_void, WHITESPACE_DISPLAY, TRUE);
Benno Schulenbergd16f9af2014-05-09 12:20:20 +00001102#ifndef DISABLE_COLOR
Benno Schulenberg523598a2014-05-03 19:19:31 +00001103 add_to_sclist(MMAIN, "M-Y", do_toggle_void, NO_COLOR_SYNTAX, TRUE);
Benno Schulenbergd16f9af2014-05-09 12:20:20 +00001104#endif
Benno Schulenberg523598a2014-05-03 19:19:31 +00001105
Benno Schulenberga6804b52014-05-09 20:33:49 +00001106 /* Group of "Editing-behavior" toggles. */
Benno Schulenberg523598a2014-05-03 19:19:31 +00001107 add_to_sclist(MMAIN, "M-H", do_toggle_void, SMART_HOME, TRUE);
1108 add_to_sclist(MMAIN, "M-I", do_toggle_void, AUTOINDENT, TRUE);
1109 add_to_sclist(MMAIN, "M-K", do_toggle_void, CUT_TO_END, TRUE);
Benno Schulenbergd16f9af2014-05-09 12:20:20 +00001110#ifndef DISABLE_WRAPPING
Benno Schulenberg523598a2014-05-03 19:19:31 +00001111 add_to_sclist(MMAIN, "M-L", do_toggle_void, NO_WRAP, TRUE);
Benno Schulenbergd16f9af2014-05-09 12:20:20 +00001112#endif
Benno Schulenberg523598a2014-05-03 19:19:31 +00001113 add_to_sclist(MMAIN, "M-Q", do_toggle_void, TABS_TO_SPACES, TRUE);
1114
Benno Schulenberga6804b52014-05-09 20:33:49 +00001115 /* Group of "Peripheral-feature" toggles. */
Benno Schulenberg523598a2014-05-03 19:19:31 +00001116 add_to_sclist(MMAIN, "M-B", do_toggle_void, BACKUP_FILE, TRUE);
Benno Schulenbergd16f9af2014-05-09 12:20:20 +00001117#ifndef DISABLE_MULTIBUFFER
Benno Schulenberg523598a2014-05-03 19:19:31 +00001118 add_to_sclist(MMAIN, "M-F", do_toggle_void, MULTIBUFFER, TRUE);
Benno Schulenbergd16f9af2014-05-09 12:20:20 +00001119#endif
1120#ifndef DISABLE_MOUSE
Benno Schulenberg523598a2014-05-03 19:19:31 +00001121 add_to_sclist(MMAIN, "M-M", do_toggle_void, USE_MOUSE, TRUE);
Benno Schulenbergd16f9af2014-05-09 12:20:20 +00001122#endif
Benno Schulenberg523598a2014-05-03 19:19:31 +00001123 add_to_sclist(MMAIN, "M-N", do_toggle_void, NO_CONVERT, TRUE);
1124 add_to_sclist(MMAIN, "M-Z", do_toggle_void, SUSPEND, TRUE);
1125#endif /* !NANO_TINY */
1126
1127 add_to_sclist(MMAIN, "^Q", xon_complaint, 0, TRUE);
1128 add_to_sclist(MMAIN, "^S", xoff_complaint, 0, TRUE);
1129
1130 add_to_sclist(((MMOST & ~MMAIN & ~MBROWSER) | MYESNO), "^C", do_cancel, 0, FALSE);
1131
Benno Schulenberg672821c2014-05-03 20:09:47 +00001132 add_to_sclist(MWHEREIS|MREPLACE, "M-C", case_sens_void, 0, FALSE);
1133 add_to_sclist(MWHEREIS|MREPLACE, "M-R", regexp_void, 0, FALSE);
1134 add_to_sclist(MWHEREIS|MREPLACE, "M-B", backwards_void, 0, FALSE);
Benno Schulenberg523598a2014-05-03 19:19:31 +00001135 add_to_sclist(MWHEREIS, "^R", do_replace, 0, FALSE);
1136 add_to_sclist(MREPLACE, "^R", no_replace_void, 0, FALSE);
1137 add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH|MGOTOLINE, "^Y", do_first_line, 0, TRUE);
1138 add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH|MGOTOLINE, "^V", do_last_line, 0, TRUE);
1139#ifndef DISABLE_JUSTIFY
1140 add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH, "^W", do_para_begin_void, 0, TRUE);
1141 add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH, "^O", do_para_end_void, 0, TRUE);
1142#endif
1143 add_to_sclist(MWHEREIS, "^T", do_gotolinecolumn_void, 0, FALSE);
1144 add_to_sclist(MGOTOLINE, "^T", gototext_void, 0, FALSE);
Chris Allegretta1b6ed072008-06-03 08:09:05 +00001145#ifndef NANO_TINY
Benno Schulenberge167afe2014-04-16 09:26:15 +00001146 add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH|MWHEREISFILE, "^P", get_history_older_void, 0, FALSE);
Benno Schulenbergd6308802014-04-21 15:45:23 +00001147 add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH|MWHEREISFILE, "Up", get_history_older_void, 0, FALSE);
Benno Schulenberge167afe2014-04-16 09:26:15 +00001148 add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH|MWHEREISFILE, "^N", get_history_newer_void, 0, FALSE);
Benno Schulenbergd6308802014-04-21 15:45:23 +00001149 add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH|MWHEREISFILE, "Down", get_history_newer_void, 0, FALSE);
Chris Allegretta1b6ed072008-06-03 08:09:05 +00001150#endif
Chris Allegretta637daa82011-02-07 14:45:56 +00001151#ifndef DISABLE_BROWSER
1152 add_to_sclist(MBROWSER|MWHEREISFILE, "M-\\", do_first_file, 0, TRUE);
1153 add_to_sclist(MBROWSER|MWHEREISFILE, "M-|", do_first_file, 0, TRUE);
1154 add_to_sclist(MBROWSER|MWHEREISFILE, "M-/", do_last_file, 0, TRUE);
1155 add_to_sclist(MBROWSER|MWHEREISFILE, "M-?", do_last_file, 0, TRUE);
Chris Allegretta637daa82011-02-07 14:45:56 +00001156 add_to_sclist(MBROWSER|MWHEREISFILE, "^_", goto_dir_void, 0, TRUE);
Chris Allegretta637daa82011-02-07 14:45:56 +00001157 add_to_sclist(MBROWSER|MWHEREISFILE, "M-G", goto_dir_void, 0, TRUE);
Benno Schulenberg9c0f9de2014-04-22 19:10:26 +00001158 add_to_sclist(MBROWSER|MWHEREISFILE, "F13", goto_dir_void, 0, TRUE);
Benno Schulenberge34ac8e2014-03-17 12:15:23 +00001159#endif
Benno Schulenberg70d21672014-03-26 10:53:10 +00001160 add_to_sclist(MWRITEFILE, "M-D", dos_format_void, 0, FALSE);
1161 add_to_sclist(MWRITEFILE, "M-M", mac_format_void, 0, FALSE);
1162 add_to_sclist(MWRITEFILE, "M-A", append_void, 0, FALSE);
1163 add_to_sclist(MWRITEFILE, "M-P", prepend_void, 0, FALSE);
1164 add_to_sclist(MWRITEFILE, "M-B", backup_file_void, 0, FALSE);
Benno Schulenbergf803ef52014-04-13 12:16:37 +00001165 add_to_sclist(MWRITEFILE|MINSERTFILE, "^T", to_files_void, 0, FALSE);
Benno Schulenberg70d21672014-03-26 10:53:10 +00001166 add_to_sclist(MINSERTFILE, "^X", ext_cmd_void, 0, FALSE);
Benno Schulenberg523598a2014-05-03 19:19:31 +00001167 add_to_sclist(MINSERTFILE|MEXTCMD, "M-F", new_buffer_void, 0, FALSE);
Benno Schulenbergf6a3ab02014-04-16 09:55:16 +00001168 add_to_sclist(MHELP|MBROWSER, "^C", do_exit, 0, TRUE);
1169 add_to_sclist(MHELP, "^G", do_exit, 0, TRUE);
Benno Schulenberg4c9573d2014-04-16 09:12:13 +00001170 add_to_sclist(MMOST, "^I", do_tab, 0, TRUE);
1171 add_to_sclist(MMOST, "^M", do_enter_void, 0, TRUE);
Benno Schulenbergd6308802014-04-21 15:45:23 +00001172 add_to_sclist(MMOST, "Enter", do_enter_void, 0, TRUE);
Benno Schulenberg4c9573d2014-04-16 09:12:13 +00001173 add_to_sclist(MMOST, "^D", do_delete, 0, TRUE);
Benno Schulenbergd6308802014-04-21 15:45:23 +00001174 add_to_sclist(MMOST, "Del", do_delete, 0, TRUE);
Benno Schulenberg4c9573d2014-04-16 09:12:13 +00001175 add_to_sclist(MMOST, "^H", do_backspace, 0, TRUE);
Benno Schulenbergd6308802014-04-21 15:45:23 +00001176 add_to_sclist(MMOST, "Bsp", do_backspace, 0, TRUE);
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001177
1178#ifdef DEBUG
1179 print_sclist();
1180#endif
Chris Allegrettadab017e2002-04-23 10:56:06 +00001181}
Chris Allegrettaf5de33a2002-02-27 04:14:16 +00001182
Benno Schulenberg00389922014-04-04 11:59:03 +00001183#ifndef DISABLE_COLOR
Chris Allegretta5575bfa2014-02-24 10:18:15 +00001184void set_lint_shortcuts(void)
1185{
1186#ifndef DISABLE_SPELLER
1187 replace_scs_for(do_spell, do_linter);
1188#endif
1189}
1190
1191void set_spell_shortcuts(void)
1192{
1193#ifndef DISABLE_SPELLER
1194 replace_scs_for(do_linter, do_spell);
1195#endif
1196}
1197#endif
1198
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001199const subnfunc *sctofunc(sc *s)
David Lawrence Ramsey576bf332004-07-12 03:10:30 +00001200{
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001201 subnfunc *f;
David Lawrence Ramsey576bf332004-07-12 03:10:30 +00001202
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001203 for (f = allfuncs; f != NULL && s->scfunc != f->scfunc; f = f->next)
1204 ;
1205
1206 return f;
1207}
1208
1209#ifndef NANO_TINY
Benno Schulenbergd19be5a2014-04-08 18:38:45 +00001210/* Now let's come up with a single (hopefully) function to get a string
1211 * for each flag. */
Chris Allegretta5a018f02009-11-29 06:13:22 +00001212const char *flagtostr(int flag)
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001213{
1214 switch (flag) {
1215 case NO_HELP:
Benno Schulenbergc8b60ce2014-04-22 11:57:11 +00001216 /* TRANSLATORS: The next seventeen strings are toggle descriptions;
1217 * they are best kept shorter than 40 characters, but may be longer. */
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001218 return N_("Help mode");
1219 case CONST_UPDATE:
1220 return N_("Constant cursor position display");
1221 case MORE_SPACE:
1222 return N_("Use of one more line for editing");
1223 case SMOOTH_SCROLL:
1224 return N_("Smooth scrolling");
Benno Schulenberga6804b52014-05-09 20:33:49 +00001225 case SOFTWRAP:
1226 return N_("Soft wrapping of overlong lines");
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001227 case WHITESPACE_DISPLAY:
1228 return N_("Whitespace display");
1229 case NO_COLOR_SYNTAX:
1230 return N_("Color syntax highlighting");
1231 case SMART_HOME:
1232 return N_("Smart home key");
1233 case AUTOINDENT:
1234 return N_("Auto indent");
1235 case CUT_TO_END:
1236 return N_("Cut to end");
1237 case NO_WRAP:
Benno Schulenberg9df76722014-04-23 20:37:32 +00001238 return N_("Hard wrapping of overlong lines");
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001239 case TABS_TO_SPACES:
1240 return N_("Conversion of typed tabs to spaces");
1241 case BACKUP_FILE:
1242 return N_("Backup files");
1243 case MULTIBUFFER:
1244 return N_("Multiple file buffers");
1245 case USE_MOUSE:
1246 return N_("Mouse support");
1247 case NO_CONVERT:
1248 return N_("No conversion from DOS/Mac format");
1249 case SUSPEND:
1250 return N_("Suspension");
1251 default:
1252 return "?????";
1253 }
1254}
Benno Schulenberge4c34c32014-03-17 14:15:57 +00001255#endif /* !NANO_TINY */
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001256
Benno Schulenberg1f934e32014-04-13 11:56:08 +00001257/* Interpret a function string given in the rc file, and return a
1258 * shortcut struct, complete with the proper value for execute. */
1259sc *strtosc(char *input)
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001260{
Benno Schulenberg1f934e32014-04-13 11:56:08 +00001261 sc *s;
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001262
1263 s = (sc *)nmalloc(sizeof(sc));
Benno Schulenberg1f934e32014-04-13 11:56:08 +00001264 s->execute = TRUE; /* will be overridden as needed below */
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001265
Chris Allegrettae347efb2008-03-09 02:52:40 +00001266#ifndef DISABLE_HELP
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001267 if (!strcasecmp(input, "help"))
Chris Allegretta637daa82011-02-07 14:45:56 +00001268 s->scfunc = do_help_void;
1269 else
Chris Allegrettae347efb2008-03-09 02:52:40 +00001270#endif
1271 if (!strcasecmp(input, "cancel")) {
Chris Allegretta637daa82011-02-07 14:45:56 +00001272 s->scfunc = do_cancel;
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001273 s->execute = FALSE;
1274 } else if (!strcasecmp(input, "exit"))
Chris Allegretta637daa82011-02-07 14:45:56 +00001275 s->scfunc = do_exit;
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001276 else if (!strcasecmp(input, "writeout"))
Chris Allegretta637daa82011-02-07 14:45:56 +00001277 s->scfunc = do_writeout_void;
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001278 else if (!strcasecmp(input, "insert"))
Chris Allegretta637daa82011-02-07 14:45:56 +00001279 s->scfunc = do_insertfile_void;
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001280 else if (!strcasecmp(input, "whereis"))
Chris Allegretta637daa82011-02-07 14:45:56 +00001281 s->scfunc = do_search;
Benno Schulenberg5f655da2014-04-27 15:26:25 +00001282#ifndef NANO_TINY
Benno Schulenberg618051c2014-04-26 20:16:17 +00001283 else if (!strcasecmp(input, "searchagain") ||
1284 !strcasecmp(input, "research"))
1285 s->scfunc = do_research;
Benno Schulenberg5f655da2014-04-27 15:26:25 +00001286#endif
Benno Schulenberg618051c2014-04-26 20:16:17 +00001287 else if (!strcasecmp(input, "replace"))
1288 s->scfunc = do_replace;
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001289 else if (!strcasecmp(input, "cut"))
Chris Allegretta637daa82011-02-07 14:45:56 +00001290 s->scfunc = do_cut_text_void;
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001291 else if (!strcasecmp(input, "uncut"))
Chris Allegretta637daa82011-02-07 14:45:56 +00001292 s->scfunc = do_uncut_text;
Benno Schulenberg5f655da2014-04-27 15:26:25 +00001293#ifndef NANO_TINY
Benno Schulenbergf8507bb2014-05-05 19:54:34 +00001294 else if (!strcasecmp(input, "cutrestoffile"))
1295 s->scfunc = do_cut_till_end;
Benno Schulenberg5f655da2014-04-27 15:26:25 +00001296 else if (!strcasecmp(input, "copytext"))
1297 s->scfunc = do_copy_text;
Benno Schulenberg618051c2014-04-26 20:16:17 +00001298 else if (!strcasecmp(input, "mark"))
1299 s->scfunc = do_mark;
Benno Schulenberg387b2092014-05-09 15:14:29 +00001300#endif
1301#ifndef DISABLE_SPELLER
Benno Schulenberg301c4ef2014-04-26 19:33:11 +00001302 else if (!strcasecmp(input, "tospell") ||
1303 !strcasecmp(input, "speller"))
1304 s->scfunc = do_spell;
Benno Schulenberg5f655da2014-04-27 15:26:25 +00001305#endif
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001306 else if (!strcasecmp(input, "curpos") ||
Benno Schulenberg3aea69d2014-02-28 20:08:59 +00001307 !strcasecmp(input, "cursorpos"))
Chris Allegretta637daa82011-02-07 14:45:56 +00001308 s->scfunc = do_cursorpos_void;
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001309 else if (!strcasecmp(input, "gotoline"))
Chris Allegretta637daa82011-02-07 14:45:56 +00001310 s->scfunc = do_gotolinecolumn_void;
Chris Allegrettac656e9d2008-03-16 12:55:41 +00001311#ifndef DISABLE_JUSTIFY
Chris Allegrettae347efb2008-03-09 02:52:40 +00001312 else if (!strcasecmp(input, "justify"))
Chris Allegretta637daa82011-02-07 14:45:56 +00001313 s->scfunc = do_justify_void;
Benno Schulenberg618051c2014-04-26 20:16:17 +00001314 else if (!strcasecmp(input, "fulljustify"))
1315 s->scfunc = do_full_justify;
Chris Allegrettac656e9d2008-03-16 12:55:41 +00001316 else if (!strcasecmp(input, "beginpara"))
Chris Allegretta637daa82011-02-07 14:45:56 +00001317 s->scfunc = do_para_begin_void;
Chris Allegrettac656e9d2008-03-16 12:55:41 +00001318 else if (!strcasecmp(input, "endpara"))
Chris Allegretta637daa82011-02-07 14:45:56 +00001319 s->scfunc = do_para_end_void;
Chris Allegrettac656e9d2008-03-16 12:55:41 +00001320#endif
1321#ifndef NANO_TINY
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001322 else if (!strcasecmp(input, "indent"))
Chris Allegretta637daa82011-02-07 14:45:56 +00001323 s->scfunc = do_indent_void;
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001324 else if (!strcasecmp(input, "unindent"))
Chris Allegretta637daa82011-02-07 14:45:56 +00001325 s->scfunc = do_unindent;
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001326 else if (!strcasecmp(input, "scrollup"))
Chris Allegretta637daa82011-02-07 14:45:56 +00001327 s->scfunc = do_scroll_up;
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001328 else if (!strcasecmp(input, "scrolldown"))
Chris Allegretta637daa82011-02-07 14:45:56 +00001329 s->scfunc = do_scroll_down;
Chris Allegrettae347efb2008-03-09 02:52:40 +00001330 else if (!strcasecmp(input, "prevword"))
Chris Allegretta637daa82011-02-07 14:45:56 +00001331 s->scfunc = do_prev_word_void;
Benno Schulenberg3064db22014-04-21 12:06:20 +00001332 else if (!strcasecmp(input, "nextword"))
1333 s->scfunc = do_next_word_void;
Chris Allegrettae347efb2008-03-09 02:52:40 +00001334 else if (!strcasecmp(input, "findbracket"))
Chris Allegretta637daa82011-02-07 14:45:56 +00001335 s->scfunc = do_find_bracket;
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001336 else if (!strcasecmp(input, "wordcount"))
Chris Allegretta637daa82011-02-07 14:45:56 +00001337 s->scfunc = do_wordlinechar_count;
Benno Schulenberg3064db22014-04-21 12:06:20 +00001338 else if (!strcasecmp(input, "suspend"))
1339 s->scfunc = do_suspend_void;
Chris Allegretta70859f42008-07-13 01:36:06 +00001340 else if (!strcasecmp(input, "undo"))
Chris Allegretta637daa82011-02-07 14:45:56 +00001341 s->scfunc = do_undo;
Chris Allegretta70859f42008-07-13 01:36:06 +00001342 else if (!strcasecmp(input, "redo"))
Chris Allegretta637daa82011-02-07 14:45:56 +00001343 s->scfunc = do_redo;
Chris Allegrettae347efb2008-03-09 02:52:40 +00001344 else if (!strcasecmp(input, "prevhistory")) {
Chris Allegretta637daa82011-02-07 14:45:56 +00001345 s->scfunc = get_history_older_void;
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001346 s->execute = FALSE;
1347 } else if (!strcasecmp(input, "nexthistory")) {
Chris Allegretta637daa82011-02-07 14:45:56 +00001348 s->scfunc = get_history_newer_void;
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001349 s->execute = FALSE;
Benno Schulenbergeec71e32014-03-19 09:34:37 +00001350 } else if (!strcasecmp(input, "nohelp")) {
Chris Allegretta637daa82011-02-07 14:45:56 +00001351 s->scfunc = do_toggle_void;
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001352 s->execute = FALSE;
1353 s->toggle = NO_HELP;
1354 } else if (!strcasecmp(input, "constupdate")) {
Chris Allegretta637daa82011-02-07 14:45:56 +00001355 s->scfunc = do_toggle_void;
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001356 s->execute = FALSE;
1357 s->toggle = CONST_UPDATE;
1358 } else if (!strcasecmp(input, "morespace")) {
Chris Allegretta637daa82011-02-07 14:45:56 +00001359 s->scfunc = do_toggle_void;
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001360 s->execute = FALSE;
1361 s->toggle = MORE_SPACE;
1362 } else if (!strcasecmp(input, "smoothscroll")) {
Chris Allegretta637daa82011-02-07 14:45:56 +00001363 s->scfunc = do_toggle_void;
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001364 s->execute = FALSE;
1365 s->toggle = SMOOTH_SCROLL;
Benno Schulenberga6804b52014-05-09 20:33:49 +00001366 } else if (!strcasecmp(input, "softwrap")) {
1367 s->scfunc = do_toggle_void;
1368 s->execute = FALSE;
1369 s->toggle = SOFTWRAP;
Chris Allegrettad3659f82008-03-16 23:57:14 +00001370 } else if (!strcasecmp(input, "whitespacedisplay")) {
Chris Allegretta637daa82011-02-07 14:45:56 +00001371 s->scfunc = do_toggle_void;
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001372 s->execute = FALSE;
1373 s->toggle = WHITESPACE_DISPLAY;
Benno Schulenbergd16f9af2014-05-09 12:20:20 +00001374#ifndef DISABLE_COLOR
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001375 } else if (!strcasecmp(input, "nosyntax")) {
Chris Allegretta637daa82011-02-07 14:45:56 +00001376 s->scfunc = do_toggle_void;
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001377 s->execute = FALSE;
1378 s->toggle = NO_COLOR_SYNTAX;
Benno Schulenbergd16f9af2014-05-09 12:20:20 +00001379#endif
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001380 } else if (!strcasecmp(input, "smarthome")) {
Chris Allegretta637daa82011-02-07 14:45:56 +00001381 s->scfunc = do_toggle_void;
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001382 s->execute = FALSE;
1383 s->toggle = SMART_HOME;
1384 } else if (!strcasecmp(input, "autoindent")) {
Chris Allegretta637daa82011-02-07 14:45:56 +00001385 s->scfunc = do_toggle_void;
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001386 s->execute = FALSE;
1387 s->toggle = AUTOINDENT;
1388 } else if (!strcasecmp(input, "cuttoend")) {
Chris Allegretta637daa82011-02-07 14:45:56 +00001389 s->scfunc = do_toggle_void;
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001390 s->execute = FALSE;
1391 s->toggle = CUT_TO_END;
Benno Schulenbergd16f9af2014-05-09 12:20:20 +00001392#ifndef DISABLE_WRAPPING
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001393 } else if (!strcasecmp(input, "nowrap")) {
Chris Allegretta637daa82011-02-07 14:45:56 +00001394 s->scfunc = do_toggle_void;
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001395 s->execute = FALSE;
1396 s->toggle = NO_WRAP;
Benno Schulenbergd16f9af2014-05-09 12:20:20 +00001397#endif
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001398 } else if (!strcasecmp(input, "tabstospaces")) {
Chris Allegretta637daa82011-02-07 14:45:56 +00001399 s->scfunc = do_toggle_void;
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001400 s->execute = FALSE;
1401 s->toggle = TABS_TO_SPACES;
1402 } else if (!strcasecmp(input, "backupfile")) {
Chris Allegretta637daa82011-02-07 14:45:56 +00001403 s->scfunc = do_toggle_void;
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001404 s->execute = FALSE;
1405 s->toggle = BACKUP_FILE;
Benno Schulenbergd16f9af2014-05-09 12:20:20 +00001406#ifndef DISABLE_MULTIBUFFER
Benno Schulenberg92ccf772014-02-28 19:34:11 +00001407 } else if (!strcasecmp(input, "multibuffer")) {
Chris Allegretta637daa82011-02-07 14:45:56 +00001408 s->scfunc = do_toggle_void;
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001409 s->execute = FALSE;
1410 s->toggle = MULTIBUFFER;
Benno Schulenbergd16f9af2014-05-09 12:20:20 +00001411#endif
1412#ifndef DISABLE_MOUSE
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001413 } else if (!strcasecmp(input, "mouse")) {
Chris Allegretta637daa82011-02-07 14:45:56 +00001414 s->scfunc = do_toggle_void;
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001415 s->execute = FALSE;
1416 s->toggle = USE_MOUSE;
Benno Schulenbergd16f9af2014-05-09 12:20:20 +00001417#endif
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001418 } else if (!strcasecmp(input, "noconvert")) {
Chris Allegretta637daa82011-02-07 14:45:56 +00001419 s->scfunc = do_toggle_void;
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001420 s->execute = FALSE;
1421 s->toggle = NO_CONVERT;
Chris Allegretta0018d8e2008-03-13 08:23:52 +00001422 } else if (!strcasecmp(input, "suspendenable")) {
Chris Allegretta637daa82011-02-07 14:45:56 +00001423 s->scfunc = do_toggle_void;
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001424 s->execute = FALSE;
1425 s->toggle = SUSPEND;
Chris Allegrettac656e9d2008-03-16 12:55:41 +00001426 }
Benno Schulenberge4c34c32014-03-17 14:15:57 +00001427#endif /* !NANO_TINY */
Chris Allegrettae347efb2008-03-09 02:52:40 +00001428 else if (!strcasecmp(input, "left") ||
Benno Schulenberg3aea69d2014-02-28 20:08:59 +00001429 !strcasecmp(input, "back"))
Chris Allegretta637daa82011-02-07 14:45:56 +00001430 s->scfunc = do_left;
Benno Schulenberg47be8c22014-04-22 19:07:32 +00001431 else if (!strcasecmp(input, "right") ||
1432 !strcasecmp(input, "forward"))
1433 s->scfunc = do_right;
Chris Allegrettae347efb2008-03-09 02:52:40 +00001434 else if (!strcasecmp(input, "up") ||
Benno Schulenberg3aea69d2014-02-28 20:08:59 +00001435 !strcasecmp(input, "prevline"))
Chris Allegretta637daa82011-02-07 14:45:56 +00001436 s->scfunc = do_up_void;
Chris Allegrettae347efb2008-03-09 02:52:40 +00001437 else if (!strcasecmp(input, "down") ||
Benno Schulenberg3aea69d2014-02-28 20:08:59 +00001438 !strcasecmp(input, "nextline"))
Chris Allegretta637daa82011-02-07 14:45:56 +00001439 s->scfunc = do_down_void;
Chris Allegrettae347efb2008-03-09 02:52:40 +00001440 else if (!strcasecmp(input, "home"))
Chris Allegretta637daa82011-02-07 14:45:56 +00001441 s->scfunc = do_home;
Chris Allegrettae347efb2008-03-09 02:52:40 +00001442 else if (!strcasecmp(input, "end"))
Chris Allegretta637daa82011-02-07 14:45:56 +00001443 s->scfunc = do_end;
Benno Schulenberg618051c2014-04-26 20:16:17 +00001444 else if (!strcasecmp(input, "pageup") ||
1445 !strcasecmp(input, "prevpage"))
1446 s->scfunc = do_page_up;
1447 else if (!strcasecmp(input, "pagedown") ||
1448 !strcasecmp(input, "nextpage"))
1449 s->scfunc = do_page_down;
1450 else if (!strcasecmp(input, "firstline"))
1451 s->scfunc = do_first_line;
1452 else if (!strcasecmp(input, "lastline"))
1453 s->scfunc = do_last_line;
Benno Schulenberg0636d7b2014-04-03 20:23:07 +00001454#ifndef DISABLE_MULTIBUFFER
Chris Allegrettae347efb2008-03-09 02:52:40 +00001455 else if (!strcasecmp(input, "prevbuf"))
Chris Allegretta637daa82011-02-07 14:45:56 +00001456 s->scfunc = switch_to_prev_buffer_void;
Chris Allegrettae347efb2008-03-09 02:52:40 +00001457 else if (!strcasecmp(input, "nextbuf"))
Chris Allegretta637daa82011-02-07 14:45:56 +00001458 s->scfunc = switch_to_next_buffer_void;
Chris Allegrettae347efb2008-03-09 02:52:40 +00001459#endif
1460 else if (!strcasecmp(input, "verbatim"))
Chris Allegretta637daa82011-02-07 14:45:56 +00001461 s->scfunc = do_verbatim_input;
Chris Allegrettae347efb2008-03-09 02:52:40 +00001462 else if (!strcasecmp(input, "tab"))
Chris Allegretta637daa82011-02-07 14:45:56 +00001463 s->scfunc = do_tab;
Chris Allegrettae347efb2008-03-09 02:52:40 +00001464 else if (!strcasecmp(input, "enter"))
Chris Allegretta637daa82011-02-07 14:45:56 +00001465 s->scfunc = do_enter_void;
Chris Allegrettae347efb2008-03-09 02:52:40 +00001466 else if (!strcasecmp(input, "delete"))
Chris Allegretta637daa82011-02-07 14:45:56 +00001467 s->scfunc = do_delete;
Chris Allegrettafa406942008-07-13 16:44:19 +00001468 else if (!strcasecmp(input, "backspace"))
Chris Allegretta637daa82011-02-07 14:45:56 +00001469 s->scfunc = do_backspace;
Chris Allegrettae347efb2008-03-09 02:52:40 +00001470 else if (!strcasecmp(input, "refresh"))
Chris Allegretta637daa82011-02-07 14:45:56 +00001471 s->scfunc = total_refresh;
Chris Allegrettae347efb2008-03-09 02:52:40 +00001472 else if (!strcasecmp(input, "casesens")) {
Chris Allegretta637daa82011-02-07 14:45:56 +00001473 s->scfunc = case_sens_void;
Chris Allegrettae347efb2008-03-09 02:52:40 +00001474 s->execute = FALSE;
1475 } else if (!strcasecmp(input, "regexp") ||
Benno Schulenberg3aea69d2014-02-28 20:08:59 +00001476 !strcasecmp(input, "regex")) {
Chris Allegretta637daa82011-02-07 14:45:56 +00001477 s->scfunc = regexp_void;
Chris Allegrettae347efb2008-03-09 02:52:40 +00001478 s->execute = FALSE;
Benno Schulenbergabaaf2d2014-05-04 20:16:30 +00001479 } else if (!strcasecmp(input, "backwards")) {
Benno Schulenberg08465832014-05-04 12:20:51 +00001480 s->scfunc = backwards_void;
1481 s->execute = FALSE;
Chris Allegrettae347efb2008-03-09 02:52:40 +00001482 } else if (!strcasecmp(input, "dontreplace")) {
Chris Allegretta637daa82011-02-07 14:45:56 +00001483 s->scfunc = no_replace_void;
Chris Allegrettae347efb2008-03-09 02:52:40 +00001484 s->execute = FALSE;
1485 } else if (!strcasecmp(input, "gototext")) {
Chris Allegretta637daa82011-02-07 14:45:56 +00001486 s->scfunc = gototext_void;
Chris Allegrettae347efb2008-03-09 02:52:40 +00001487 s->execute = FALSE;
1488 } else if (!strcasecmp(input, "browser") ||
Benno Schulenberg3aea69d2014-02-28 20:08:59 +00001489 !strcasecmp(input, "tofiles")) {
Chris Allegretta637daa82011-02-07 14:45:56 +00001490 s->scfunc = to_files_void;
Chris Allegrettae347efb2008-03-09 02:52:40 +00001491 s->execute = FALSE;
1492 } else if (!strcasecmp(input, "dosformat")) {
Chris Allegretta637daa82011-02-07 14:45:56 +00001493 s->scfunc = dos_format_void;
Chris Allegrettae347efb2008-03-09 02:52:40 +00001494 s->execute = FALSE;
1495 } else if (!strcasecmp(input, "macformat")) {
Chris Allegretta637daa82011-02-07 14:45:56 +00001496 s->scfunc = mac_format_void;
Chris Allegrettae347efb2008-03-09 02:52:40 +00001497 s->execute = FALSE;
1498 } else if (!strcasecmp(input, "append")) {
Chris Allegretta637daa82011-02-07 14:45:56 +00001499 s->scfunc = append_void;
Chris Allegrettae347efb2008-03-09 02:52:40 +00001500 s->execute = FALSE;
1501 } else if (!strcasecmp(input, "prepend")) {
Chris Allegretta637daa82011-02-07 14:45:56 +00001502 s->scfunc = prepend_void;
Chris Allegrettae347efb2008-03-09 02:52:40 +00001503 s->execute = FALSE;
1504 } else if (!strcasecmp(input, "backup")) {
Chris Allegretta637daa82011-02-07 14:45:56 +00001505 s->scfunc = backup_file_void;
Chris Allegrettae347efb2008-03-09 02:52:40 +00001506 s->execute = FALSE;
Benno Schulenberg0636d7b2014-04-03 20:23:07 +00001507#ifndef DISABLE_MULTIBUFFER
Chris Allegrettae347efb2008-03-09 02:52:40 +00001508 } else if (!strcasecmp(input, "newbuffer")) {
Chris Allegretta637daa82011-02-07 14:45:56 +00001509 s->scfunc = new_buffer_void;
Chris Allegrettae347efb2008-03-09 02:52:40 +00001510 s->execute = FALSE;
1511#endif
Chris Allegretta637daa82011-02-07 14:45:56 +00001512#ifndef DISABLE_BROWSER
Chris Allegrettae347efb2008-03-09 02:52:40 +00001513 } else if (!strcasecmp(input, "firstfile")) {
Chris Allegretta637daa82011-02-07 14:45:56 +00001514 s->scfunc = do_first_file;
Chris Allegrettae347efb2008-03-09 02:52:40 +00001515 s->execute = FALSE;
1516 } else if (!strcasecmp(input, "lastfile")) {
Chris Allegretta637daa82011-02-07 14:45:56 +00001517 s->scfunc = do_last_file;
Chris Allegrettae347efb2008-03-09 02:52:40 +00001518 s->execute = FALSE;
Chris Allegretta637daa82011-02-07 14:45:56 +00001519#endif
David Lawrence Ramsey576bf332004-07-12 03:10:30 +00001520 } else {
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001521 free(s);
1522 return NULL;
David Lawrence Ramsey576bf332004-07-12 03:10:30 +00001523 }
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001524 return s;
David Lawrence Ramsey576bf332004-07-12 03:10:30 +00001525}
1526
Benno Schulenbergeea09082014-04-13 20:50:20 +00001527#ifndef DISABLE_NANORC
Benno Schulenberg7f873932014-02-25 21:27:22 +00001528/* Same thing as above but for the menu. */
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001529int strtomenu(char *input)
David Lawrence Ramsey576bf332004-07-12 03:10:30 +00001530{
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001531 if (!strcasecmp(input, "all"))
Benno Schulenberg4c9573d2014-04-16 09:12:13 +00001532 return (MMOST|MHELP|MYESNO);
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001533 else if (!strcasecmp(input, "main"))
1534 return MMAIN;
1535 else if (!strcasecmp(input, "search"))
1536 return MWHEREIS;
1537 else if (!strcasecmp(input, "replace"))
1538 return MREPLACE;
1539 else if (!strcasecmp(input, "replace2") ||
Benno Schulenbergf803ef52014-04-13 12:16:37 +00001540 !strcasecmp(input, "replacewith"))
Benno Schulenberge167afe2014-04-16 09:26:15 +00001541 return MREPLACEWITH;
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001542 else if (!strcasecmp(input, "gotoline"))
1543 return MGOTOLINE;
1544 else if (!strcasecmp(input, "writeout"))
1545 return MWRITEFILE;
1546 else if (!strcasecmp(input, "insert"))
1547 return MINSERTFILE;
1548 else if (!strcasecmp(input, "externalcmd") ||
Benno Schulenbergf803ef52014-04-13 12:16:37 +00001549 !strcasecmp(input, "extcmd"))
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001550 return MEXTCMD;
1551 else if (!strcasecmp(input, "help"))
1552 return MHELP;
1553 else if (!strcasecmp(input, "spell"))
1554 return MSPELL;
Benno Schulenberg3064db22014-04-21 12:06:20 +00001555 else if (!strcasecmp(input, "linter"))
1556 return MLINTER;
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001557 else if (!strcasecmp(input, "browser"))
1558 return MBROWSER;
1559 else if (!strcasecmp(input, "whereisfile"))
1560 return MWHEREISFILE;
1561 else if (!strcasecmp(input, "gotodir"))
1562 return MGOTODIR;
David Lawrence Ramsey576bf332004-07-12 03:10:30 +00001563
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001564 return -1;
David Lawrence Ramsey576bf332004-07-12 03:10:30 +00001565}
Chris Allegretta79a33bb2008-03-05 07:34:01 +00001566#endif
David Lawrence Ramsey576bf332004-07-12 03:10:30 +00001567
Chris Allegrettae347efb2008-03-09 02:52:40 +00001568
David Lawrence Ramseye6757b92006-04-19 13:36:56 +00001569#ifdef DEBUG
1570/* This function is used to gracefully return all the memory we've used.
1571 * It should be called just before calling exit(). Practically, the
Chris Allegretta6232d662002-05-12 19:52:15 +00001572 * only effect is to cause a segmentation fault if the various data
1573 * structures got bolloxed earlier. Thus, we don't bother having this
Chris Allegretta6df90f52002-07-19 01:08:59 +00001574 * function unless debugging is turned on. */
Chris Allegretta6df90f52002-07-19 01:08:59 +00001575void thanks_for_all_the_fish(void)
Chris Allegrettaf5de33a2002-02-27 04:14:16 +00001576{
David Lawrence Ramsey576bf332004-07-12 03:10:30 +00001577 delwin(topwin);
1578 delwin(edit);
1579 delwin(bottomwin);
1580
Chris Allegretta7662c862003-01-13 01:35:15 +00001581#ifndef DISABLE_JUSTIFY
1582 if (quotestr != NULL)
1583 free(quotestr);
David Lawrence Ramsey819c7f02004-07-30 03:54:34 +00001584#ifdef HAVE_REGEX_H
1585 regfree(&quotereg);
David Lawrence Ramsey31b159c2005-05-26 05:17:13 +00001586 if (quoteerr != NULL)
1587 free(quoteerr);
David Lawrence Ramsey819c7f02004-07-30 03:54:34 +00001588#endif
Chris Allegretta7662c862003-01-13 01:35:15 +00001589#endif
David Lawrence Ramseyebe34252005-11-15 03:17:35 +00001590#ifndef NANO_TINY
David Lawrence Ramsey04e42a62004-02-28 16:24:31 +00001591 if (backup_dir != NULL)
1592 free(backup_dir);
1593#endif
Chris Allegretta2598c662002-03-28 01:59:34 +00001594#ifndef DISABLE_OPERATINGDIR
Chris Allegrettaf5de33a2002-02-27 04:14:16 +00001595 if (operating_dir != NULL)
1596 free(operating_dir);
1597 if (full_operating_dir != NULL)
1598 free(full_operating_dir);
1599#endif
1600 if (last_search != NULL)
1601 free(last_search);
1602 if (last_replace != NULL)
1603 free(last_replace);
Chris Allegrettaf5de33a2002-02-27 04:14:16 +00001604#ifndef DISABLE_SPELLER
1605 if (alt_speller != NULL)
1606 free(alt_speller);
1607#endif
Chris Allegrettaf5de33a2002-02-27 04:14:16 +00001608 if (answer != NULL)
1609 free(answer);
1610 if (cutbuffer != NULL)
Chris Allegretta7662c862003-01-13 01:35:15 +00001611 free_filestruct(cutbuffer);
David Lawrence Ramsey93c84052004-11-23 04:08:28 +00001612#ifndef DISABLE_JUSTIFY
1613 if (jusbuffer != NULL)
1614 free_filestruct(jusbuffer);
1615#endif
David Lawrence Ramsey5d8d0b12005-05-26 05:53:29 +00001616 /* Free the memory associated with each open file buffer. */
David Lawrence Ramsey6ad59cd2005-07-08 20:09:16 +00001617 if (openfile != NULL)
David Lawrence Ramsey64661ac2005-07-08 19:57:25 +00001618 free_openfilestruct(openfile);
Benno Schulenberg00389922014-04-04 11:59:03 +00001619#ifndef DISABLE_COLOR
David Lawrence Ramsey31b159c2005-05-26 05:17:13 +00001620 if (syntaxstr != NULL)
1621 free(syntaxstr);
Chris Allegretta6df90f52002-07-19 01:08:59 +00001622 while (syntaxes != NULL) {
1623 syntaxtype *bill = syntaxes;
1624
1625 free(syntaxes->desc);
1626 while (syntaxes->extensions != NULL) {
Benno Schulenberg1d5134d2014-05-12 14:31:54 +00001627 regexlisttype *bob = syntaxes->extensions;
Chris Allegretta6df90f52002-07-19 01:08:59 +00001628 syntaxes->extensions = bob->next;
David Lawrence Ramsey2385c1a2005-07-29 21:42:08 +00001629 free(bob->ext_regex);
David Lawrence Ramsey7fc0ada2005-08-29 18:52:06 +00001630 if (bob->ext != NULL) {
1631 regfree(bob->ext);
1632 free(bob->ext);
1633 }
Chris Allegretta6df90f52002-07-19 01:08:59 +00001634 free(bob);
1635 }
Benno Schulenberg1d5134d2014-05-12 14:31:54 +00001636 while (syntaxes->headers != NULL) {
1637 regexlisttype *bob = syntaxes->headers;
1638 syntaxes->headers = bob->next;
1639 free(bob->ext_regex);
1640 if (bob->ext != NULL) {
1641 regfree(bob->ext);
1642 free(bob->ext);
1643 }
1644 free(bob);
1645 }
1646 while (syntaxes->magics != NULL) {
1647 regexlisttype *bob = syntaxes->magics;
1648 syntaxes->magics = bob->next;
1649 free(bob->ext_regex);
1650 if (bob->ext != NULL) {
1651 regfree(bob->ext);
1652 free(bob->ext);
1653 }
1654 free(bob);
1655 }
Chris Allegretta6df90f52002-07-19 01:08:59 +00001656 while (syntaxes->color != NULL) {
1657 colortype *bob = syntaxes->color;
1658
1659 syntaxes->color = bob->next;
David Lawrence Ramsey2385c1a2005-07-29 21:42:08 +00001660 free(bob->start_regex);
David Lawrence Ramseydb958022005-07-13 20:18:46 +00001661 if (bob->start != NULL) {
1662 regfree(bob->start);
1663 free(bob->start);
1664 }
David Lawrence Ramseyd2361f02005-07-14 18:33:51 +00001665 if (bob->end_regex != NULL)
1666 free(bob->end_regex);
David Lawrence Ramseydb958022005-07-13 20:18:46 +00001667 if (bob->end != NULL) {
Chris Allegrettace452fb2003-02-03 02:56:44 +00001668 regfree(bob->end);
David Lawrence Ramseydb958022005-07-13 20:18:46 +00001669 free(bob->end);
1670 }
Chris Allegretta6df90f52002-07-19 01:08:59 +00001671 free(bob);
1672 }
1673 syntaxes = syntaxes->next;
1674 free(bill);
1675 }
Benno Schulenberg00389922014-04-04 11:59:03 +00001676#endif /* !DISABLE_COLOR */
David Lawrence Ramseyebe34252005-11-15 03:17:35 +00001677#ifndef NANO_TINY
David Lawrence Ramsey40e4acf2005-05-26 06:09:07 +00001678 /* Free the search and replace history lists. */
David Lawrence Ramsey31b159c2005-05-26 05:17:13 +00001679 if (searchage != NULL)
1680 free_filestruct(searchage);
1681 if (replaceage != NULL)
1682 free_filestruct(replaceage);
Chris Allegretta5beed502003-01-05 20:41:21 +00001683#endif
Benno Schulenbergeea09082014-04-13 20:50:20 +00001684#ifndef DISABLE_NANORC
David Lawrence Ramsey31b159c2005-05-26 05:17:13 +00001685 if (homedir != NULL)
1686 free(homedir);
David Lawrence Ramseya27bd652004-08-17 05:23:38 +00001687#endif
Chris Allegrettaf5de33a2002-02-27 04:14:16 +00001688}
Chris Allegretta637daa82011-02-07 14:45:56 +00001689
Chris Allegretta6232d662002-05-12 19:52:15 +00001690#endif /* DEBUG */