global.c 62.4 KB
Newer Older
Chris Allegretta's avatar
Chris Allegretta committed
1
/**************************************************************************
2
 *   global.c  --  This file is part of GNU nano.                         *
Chris Allegretta's avatar
Chris Allegretta committed
3
 *                                                                        *
4
 *   Copyright (C) 1999-2011, 2013-2018 Free Software Foundation, Inc.    *
5
 *   Copyright (C) 2014-2017 Benno Schulenberg                            *
6
 *                                                                        *
7
8
9
10
 *   GNU nano is free software: you can redistribute it and/or modify     *
 *   it under the terms of the GNU General Public License as published    *
 *   by the Free Software Foundation, either version 3 of the License,    *
 *   or (at your option) any later version.                               *
Chris Allegretta's avatar
Chris Allegretta committed
11
 *                                                                        *
12
13
14
15
 *   GNU nano is distributed in the hope that it will be useful,          *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty          *
 *   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.              *
 *   See the GNU General Public License for more details.                 *
Chris Allegretta's avatar
Chris Allegretta committed
16
17
 *                                                                        *
 *   You should have received a copy of the GNU General Public License    *
18
 *   along with this program.  If not, see http://www.gnu.org/licenses/.  *
Chris Allegretta's avatar
Chris Allegretta committed
19
20
21
 *                                                                        *
 **************************************************************************/

22
23
#include "proto.h"

24
#include <ctype.h>
25
#include <string.h>
26
#include <strings.h>
Chris Allegretta's avatar
Chris Allegretta committed
27

28
29
/* Global variables. */
#ifndef NANO_TINY
30
volatile sig_atomic_t the_window_resized = FALSE;
31
		/* Set to TRUE by the handler whenever a SIGWINCH occurs. */
32
33
#endif

34
#ifdef __linux__
35
bool console;
36
		/* Whether we're running on a Linux VC (TRUE) or under X (FALSE). */
37
38
#endif

39
bool meta_key;
40
		/* Whether the current keystroke is a Meta key. */
41
bool shift_held;
42
		/* Whether Shift was being held together with a movement key. */
43
bool focusing = TRUE;
44
		/* Whether an update of the edit window should center the cursor. */
45

46
bool as_an_at = TRUE;
47
		/* Whether a 0x0A byte should be shown as a ^@ instead of a ^J. */
48

49
int margin = 0;
50
		/* The amount of space reserved at the left for line numbers. */
51
int editwincols = -1;
52
		/* The number of usable columns in the edit window: COLS - margin. */
53

54
bool suppress_cursorpos = FALSE;
55
		/* Should we skip constant position display for current keystroke? */
56

57
message_type lastmessage = HUSH;
58
		/* Messages of type HUSH should not overwrite type MILD nor ALERT. */
59

60
filestruct *pletion_line = NULL;
61
		/* The line where the last completion was found, if any. */
62

63
bool inhelp = FALSE;
64
		/* Whether we are in the help viewer. */
65
char *title = NULL;
66
		/* When not NULL: the title of the current help text. */
67

68
bool more_than_one = FALSE;
69
		/* Whether more than one buffer is or has been open. */
70
bool also_the_last = FALSE;
71
72
		/* Whether indenting/commenting should include the last line of
		 * the marked region. */
73
int didfind = 0;
74
		/* Whether the last search found something. */
75

76
int controlleft, controlright, controlup, controldown, controlhome, controlend;
77
#ifndef NANO_TINY
78
int shiftcontrolleft, shiftcontrolright, shiftcontrolup, shiftcontroldown;
79
int shiftcontrolhome, shiftcontrolend;
80
int altleft, altright, altup, altdown;
81
int shiftaltleft, shiftaltright, shiftaltup, shiftaltdown;
82
83
#endif

84
#ifdef ENABLED_WRAPORJUSTIFY
85
ssize_t fill = 0;
86
		/* The column where we will wrap lines. */
87
ssize_t wrap_at = -CHARS_FROM_EOL;
88
89
90
		/* The position where we will wrap lines.  fill is equal to this
		 * if it's greater than zero, and equal to (COLS + this) if it
		 * isn't. */
91
92
93
#endif

char *last_search = NULL;
94
		/* The last string we searched for. */
95

96
char *present_path = NULL;
97
		/* The current browser directory when trying to do tab completion. */
98

99
unsigned flags[4] = {0, 0, 0, 0};
100
		/* Our flag containing the states of all global options. */
101
WINDOW *topwin = NULL;
102
103
104
		/* The top portion of the window, where we display the version
		 * number of nano, the name of the current file, and whether the
		 * current file has been modified. */
105
WINDOW *edit = NULL;
106
107
		/* The middle portion of the window, i.e. the edit window, where
		 * we display the current file we're editing. */
108
WINDOW *bottomwin = NULL;
109
110
		/* The bottom portion of the window, where we display statusbar
		 * messages, the statusbar prompt, and a list of shortcuts. */
111
int editwinrows = 0;
112
		/* How many rows does the edit window take up? */
113
114

filestruct *cutbuffer = NULL;
115
		/* The buffer where we store cut text. */
116
filestruct *cutbottom = NULL;
117
		/* The last line in the cutbuffer. */
118
partition *filepart = NULL;
119
		/* The "partition" where we store a portion of the current file. */
120
openfilestruct *openfile = NULL;
121
		/* The list of all open file buffers. */
122
openfilestruct *firstfile = NULL;
123
		/* The first open buffer. */
124

125
126
#ifndef NANO_TINY
char *matchbrackets = NULL;
127
128
		/* The opening and closing brackets that can be found by bracket
		 * searches. */
129
char *whitespace = NULL;
130
		/* The characters used when visibly showing tabs and spaces. */
131
int whitespace_len[2];
132
		/* The length in bytes of these characters. */
133
134
#endif

135
#ifdef ENABLE_JUSTIFY
136
char *punct = NULL;
137
		/* The closing punctuation that can end sentences. */
138
char *brackets = NULL;
139
140
		/* The closing brackets that can follow closing punctuation and
		 * can end sentences. */
141
char *quotestr = NULL;
142
		/* The quoting string.  The default value is set in main(). */
143
regex_t quotereg;
144
		/* The compiled regular expression from the quoting string. */
145
int quoterc;
146
		/* Whether it was compiled successfully. */
147
char *quoteerr = NULL;
148
		/* The error message, if it didn't. */
149
#endif
150

151
char *word_chars = NULL;
152
		/* Nonalphanumeric characters that also form words. */
153

154
char *answer = NULL;
155
		/* The answer string used by the statusbar prompt. */
Chris Allegretta's avatar
Chris Allegretta committed
156

157
ssize_t tabsize = -1;
158
		/* The width of a tab in spaces.  The default is set in main(). */
159

160
161
#ifndef NANO_TINY
char *backup_dir = NULL;
162
		/* The directory where we store backup files. */
163

164
const char *locking_prefix = ".";
165
		/* Prefix of how to store the vim-style lock file. */
166
const char *locking_suffix = ".swp";
167
		/* Suffix of the vim-style lock file. */
168
#endif
169
#ifdef ENABLE_OPERATINGDIR
170
char *operating_dir = NULL;
171
		/* The path to our confining "operating" directory, when given. */
172
173
#endif

174
#ifdef ENABLE_SPELLER
175
char *alt_speller = NULL;
176
		/* The command to use for the alternate spell checker. */
177
178
#endif

179
#ifdef ENABLE_COLOR
180
syntaxtype *syntaxes = NULL;
181
		/* The global list of color syntaxes. */
182
char *syntaxstr = NULL;
183
		/* The color syntax name specified on the command line. */
184
bool have_palette = FALSE;
185
		/* Whether the colors for the current syntax have been initialized. */
186
187
#endif

188
bool refresh_needed = FALSE;
189
190
		/* Did a command mangle enough of the buffer that we should
		 * repaint the screen? */
191

192
int currmenu = MMOST;
193
		/* The currently active menu, initialized to a dummy value. */
194
sc *sclist = NULL;
195
		/* The start of the shortcuts list. */
196
subnfunc *allfuncs = NULL;
197
		/* The start of the functions list. */
198
subnfunc *tailfunc;
199
		/* The last function in the list. */
200
subnfunc *exitfunc;
201
		/* A pointer to the special Exit/Close item. */
202
subnfunc *uncutfunc;
203
		/* A pointer to the special Uncut/Unjustify item. */
204

205
filestruct *search_history = NULL;
206
		/* The current item in the list of strings that were searched for. */
207
filestruct *execute_history = NULL;
208
		/* The current item in the list of commands that were run with ^R ^X. */
209
filestruct *replace_history = NULL;
210
		/* The current item in the list of replace strings. */
211
#ifdef ENABLE_HISTORIES
212
filestruct *searchtop = NULL;
213
		/* The oldest item in the list of search strings. */
214
filestruct *searchbot = NULL;
215
		/* The newest item in the list of search strings. */
216

217
filestruct *replacetop = NULL;
218
filestruct *replacebot = NULL;
219

220
221
filestruct *executetop = NULL;
filestruct *executebot = NULL;
222

223
poshiststruct *position_history = NULL;
224
		/* The list of filenames with their last cursor positions. */
225
226
#endif

227
regex_t search_regexp;
228
		/* The compiled regular expression to use in searches. */
229
regmatch_t regmatches[10];
230
231
		/* The match positions for parenthetical subexpressions, 10
		 * maximum, used in regular expression searches. */
232

233
int hilite_attribute = A_REVERSE;
234
		/* The curses attribute we use to highlight something. */
235
#ifdef ENABLE_COLOR
236
237
colortype* color_combo[] = {NULL};
		/* The color combinations for interface elements given in the rcfile. */
238
#endif
239
int interface_color_pair[] = {0};
240
		/* The processed color pairs for the interface elements. */
241

242
char *homedir = NULL;
243
		/* The user's home directory, from $HOME or /etc/passwd. */
244
char *statedir = NULL;
245
		/* The directory for nano's history files. */
246
char *rcfile_with_errors = NULL;
247
		/* The first nanorc file, if any, that produced warnings. */
248

249

250
/* Return the number of entries in the shortcut list for a given menu. */
251
size_t length_of_list(int menu)
252
{
253
254
	subnfunc *f;
	size_t i = 0;
255

256
257
258
	for (f = allfuncs; f != NULL; f = f->next)
		if ((f->menus & menu) && first_sc_for(menu, f->scfunc) != NULL)
			i++;
259

260
	return i;
261
262
}

263
/* To make the functions and shortcuts lists clearer. */
264
#define VIEW  TRUE    /* Is allowed in view mode. */
265
#define NOVIEW  FALSE
266
#define BLANKAFTER  TRUE    /* A blank line after this one. */
267
268
#define TOGETHER  FALSE

269
/* Just throw this here. */
270
271
272
273
274
275
void case_sens_void(void)
{
}
void regexp_void(void)
{
}
276
277
278
void backwards_void(void)
{
}
279
280
281
void flip_replace(void)
{
}
282
void flip_goto(void)
283
284
{
}
285
#ifdef ENABLE_BROWSER
286
287
288
void to_files_void(void)
{
}
289
290
291
292
void goto_dir_void(void)
{
}
#endif
293
#ifndef NANO_TINY
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
void dos_format_void(void)
{
}
void mac_format_void(void)
{
}
void append_void(void)
{
}
void prepend_void(void)
{
}
void backup_file_void(void)
{
}
309
void flip_execute(void)
310
311
{
}
312
#endif
313
#ifdef ENABLE_MULTIBUFFER
314
void flip_newbuffer(void)
315
316
{
}
317
#endif
318
void discard_buffer(void)
319
320
321
{
}

322
/* Add a function to the function list. */
323
void add_to_funcs(void (*func)(void), int menus, const char *desc, const char *help,
324
	bool blank_after, bool viewok)
325
{
326
327
328
329
330
331
332
333
334
335
336
337
338
	subnfunc *f = nmalloc(sizeof(subnfunc));

	if (allfuncs == NULL)
		allfuncs = f;
	else
		tailfunc->next = f;
	tailfunc = f;

	f->next = NULL;
	f->scfunc = func;
	f->menus = menus;
	f->desc = desc;
	f->viewok = viewok;
339
#ifdef ENABLE_HELP
340
341
	f->help = help;
	f->blank_after = blank_after;
342
343
344
#endif

#ifdef DEBUG
345
	fprintf(stderr, "Added func %ld (%s) for menus %x\n", (long)func, f->desc, menus);
346
#endif
347
348
}

349
/* Add a key combo to the shortcut list. */
350
void add_to_sclist(int menus, const char *scstring, const int keycode,
351
						void (*func)(void), int toggle)
Chris Allegretta's avatar
Chris Allegretta committed
352
{
353
	static sc *tailsc;
354
#ifndef NANO_TINY
355
	static int counter = 0;
356
#endif
357
	sc *s = nmalloc(sizeof(sc));
358

359
360
361
362
363
364
365
	/* Start the list, or tack on the next item. */
	if (sclist == NULL)
		sclist = s;
	else
		tailsc->next = s;
	tailsc = s;
	s->next = NULL;
366

367
368
369
	/* Fill in the data. */
	s->menus = menus;
	s->scfunc = func;
370
#ifndef NANO_TINY
371
372
373
	s->toggle = toggle;
	if (toggle)
		s->ordinal = ++counter;
374
#endif
375
	assign_keyinfo(s, scstring, keycode);
376
377

#ifdef DEBUG
378
	fprintf(stderr, "Setting keycode to %d for shortcut \"%s\" in menus %x\n", s->keycode, scstring, s->menus);
379
#endif
Chris Allegretta's avatar
Chris Allegretta committed
380
381
}

382
383
384
385
/* Return the first shortcut in the list of shortcuts that
 * matches the given func in the given menu. */
const sc *first_sc_for(int menu, void (*func)(void))
{
386
	const sc *s;
387

388
389
390
	for (s = sclist; s != NULL; s = s->next)
		if ((s->menus & menu) && s->scfunc == func)
			return s;
391
392

#ifdef DEBUG
393
	fprintf(stderr, "Whoops, returning null given func %ld in menu %x\n", (long)func, menu);
394
#endif
395
396
	/* Otherwise... */
	return NULL;
397
398
}

399
400
401
/* Return the first keycode that is bound to the given function in the
 * current menu, if any; otherwise, return the given default value. */
int the_code_for(void (*func)(void), int defaultval)
Chris Allegretta's avatar
Chris Allegretta committed
402
{
403
	const sc *s = first_sc_for(currmenu, func);
Chris Allegretta's avatar
Chris Allegretta committed
404

405
406
	if (s == NULL)
		return defaultval;
407

408
409
	meta_key = s->meta;
	return s->keycode;
Chris Allegretta's avatar
Chris Allegretta committed
410
411
}

412
413
414
/* Return a pointer to the function that is bound to the given key. */
functionptrtype func_from_key(int *kbinput)
{
415
	const sc *s = get_shortcut(kbinput);
416

417
418
419
420
	if (s)
		return s->scfunc;
	else
		return NULL;
421
422
}

423
/* Set the string and its corresponding keycode for the given shortcut s. */
424
void assign_keyinfo(sc *s, const char *keystring, const int keycode)
425
{
426
427
	s->keystr = keystring;
	s->meta = (keystring[0] == 'M' && keystring[2] != '\xE2');
428

429
	assert(strlen(keystring) > 1 && (!s->meta || strlen(keystring) > 2));
430

431
432
433
434
	if (keycode)
		s->keycode = keycode;
	else
		s->keycode = keycode_from_string(keystring);
435
436
437
438
439
440
}

/* Parse the given keystring and return the corresponding keycode,
 * or return -1 when the string is invalid. */
int keycode_from_string(const char *keystring)
{
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
	if (keystring[0] == '^') {
		if (strcasecmp(keystring, "^Space") == 0)
			return 0;
		if (strlen(keystring) == 2)
			return keystring[1] - 64;
		else
			return -1;
	} else if (keystring[0] == 'M') {
		if (strcasecmp(keystring, "M-Space") == 0)
			return (int)' ';
		if (keystring[1] == '-')
			return tolower((unsigned char)keystring[2]);
		else
			return -1;
	} else if (keystring[0] == 'F') {
		int fn = atoi(&keystring[1]);
		if (fn < 0 || fn > 63)
			return -1;
		return KEY_F0 + fn;
	} else if (!strcasecmp(keystring, "Ins"))
		return KEY_IC;
	else if (!strcasecmp(keystring, "Del"))
		return KEY_DC;
464
	else
465
		return -1;
466
467
468
469
470
}

#ifdef DEBUG
void print_sclist(void)
{
471
472
473
474
475
476
477
478
479
480
	sc *s;
	const subnfunc *f;

	for (s = sclist; s != NULL; s = s->next) {
		f = sctofunc(s);
		if (f)
			fprintf(stderr, "Shortcut \"%s\", function: %s, menus %x\n", s->keystr, f->desc, f->menus);
		else
			fprintf(stderr, "Hmm, didn't find a func for \"%s\"\n", s->keystr);
	}
481
482
483
}
#endif

484
485
/* These four tags are used elsewhere too, so they are global. */
/* TRANSLATORS: Try to keep the next fifteen strings at most 10 characters. */
486
487
const char *exit_tag = N_("Exit");
const char *close_tag = N_("Close");
488
const char *uncut_tag = N_("Uncut Text");
489
#ifdef ENABLE_JUSTIFY
490
491
const char *unjust_tag = N_("Unjustify");
#endif
492

493
494
/* Initialize the list of functions and the list of shortcuts. */
void shortcut_init(void)
495
{
496
497
498
499
500
501
502
503
	const char *readfile_tag = N_("Read File");
	const char *whereis_tag = N_("Where Is");
	const char *replace_tag = N_("Replace");
	const char *gotoline_tag = N_("Go To Line");
	const char *prevline_tag = N_("Prev Line");
	const char *nextline_tag = N_("Next Line");
	const char *prevpage_tag = N_("Prev Page");
	const char *nextpage_tag = N_("Next Page");
504
#ifdef ENABLE_JUSTIFY
505
506
	const char *justify_tag = N_("Justify");
	const char *fulljustify_tag = N_("FullJstify");
507
#endif
508
509
510
	const char *refresh_tag = N_("Refresh");
	/* TRANSLATORS: Try to keep this string at most 12 characters. */
	const char *whereisnext_tag = N_("WhereIs Next");
511

512
#ifdef ENABLE_HELP
513
514
515
516
517
	/* TRANSLATORS: The next long series of strings are shortcut descriptions;
	 * they are best kept shorter than 56 characters, but may be longer. */
	const char *cancel_gist = N_("Cancel the current function");
	const char *help_gist = N_("Display this help text");
	const char *exit_gist =
518
#ifdef ENABLE_MULTIBUFFER
519
		N_("Close the current file buffer / Exit from nano")
520
#else
521
522
523
524
525
526
527
528
529
530
531
		N_("Exit from nano")
#endif
		;
	const char *writeout_gist =
		N_("Write the current file to disk");
	const char *readfile_gist =
		N_("Insert another file into the current one");
	const char *whereis_gist =
		N_("Search forward for a string or a regular expression");
	const char *wherewas_gist =
		N_("Search backward for a string or a regular expression");
532
#ifdef ENABLE_BROWSER
533
534
	const char *browserwhereis_gist = N_("Search for a string");
	const char *browserrefresh_gist = N_("Refresh the file list");
535
#ifndef NANO_TINY
536
537
538
539
540
541
542
543
544
545
546
547
548
	const char *browserlefthand_gist = N_("Go to lefthand column");
	const char *browserrighthand_gist = N_("Go to righthand column");
	const char *browsertoprow_gist = N_("Go to first row in this column");
	const char *browserbottomrow_gist = N_("Go to last row in this column");
#endif
#endif
	const char *prevpage_gist = N_("Go one screenful up");
	const char *nextpage_gist = N_("Go one screenful down");
	const char *cut_gist =
		N_("Cut the current line and store it in the cutbuffer");
	const char *uncut_gist =
		N_("Uncut from the cutbuffer into the current line");
	const char *cursorpos_gist = N_("Display the position of the cursor");
549
#ifdef ENABLE_SPELLER
550
	const char *spell_gist = N_("Invoke the spell checker, if available");
551
#endif
552
553
554
	const char *replace_gist = N_("Replace a string or a regular expression");
	const char *gotoline_gist = N_("Go to line and column number");
	const char *whereisnext_gist = N_("Repeat the last search");
555
#ifndef NANO_TINY
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
	const char *mark_gist = N_("Mark text starting from the cursor position");
	const char *copy_gist =
		N_("Copy the current line and store it in the cutbuffer");
	const char *indent_gist = N_("Indent the current line (or marked lines)");
	const char *unindent_gist = N_("Unindent the current line (or marked lines)");
	const char *undo_gist = N_("Undo the last operation");
	const char *redo_gist = N_("Redo the last undone operation");
#endif
	const char *back_gist = N_("Go back one character");
	const char *forward_gist = N_("Go forward one character");
	const char *prevword_gist = N_("Go back one word");
	const char *nextword_gist = N_("Go forward one word");
	const char *prevline_gist = N_("Go to previous line");
	const char *nextline_gist = N_("Go to next line");
	const char *home_gist = N_("Go to beginning of current line");
	const char *end_gist = N_("Go to end of current line");
	const char *prevblock_gist = N_("Go to previous block of text");
	const char *nextblock_gist = N_("Go to next block of text");
574
#ifdef ENABLE_JUSTIFY
575
576
577
578
	const char *parabegin_gist =
		N_("Go to beginning of paragraph; then of previous paragraph");
	const char *paraend_gist =
		N_("Go just beyond end of paragraph; then of next paragraph");
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
579
#endif
580
581
	const char *firstline_gist = N_("Go to the first line of the file");
	const char *lastline_gist = N_("Go to the last line of the file");
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
582
#ifndef NANO_TINY
583
584
585
586
587
	const char *bracket_gist = N_("Go to the matching bracket");
	const char *scrollup_gist =
		N_("Scroll up one line without scrolling the cursor");
	const char *scrolldown_gist =
		N_("Scroll down one line without scrolling the cursor");
588
#endif
589
#ifdef ENABLE_MULTIBUFFER
590
591
592
593
594
595
596
597
598
	const char *prevfile_gist = N_("Switch to the previous file buffer");
	const char *nextfile_gist = N_("Switch to the next file buffer");
#endif
	const char *verbatim_gist = N_("Insert the next keystroke verbatim");
	const char *tab_gist = N_("Insert a tab at the cursor position");
	const char *enter_gist = N_("Insert a newline at the cursor position");
	const char *delete_gist = N_("Delete the character under the cursor");
	const char *backspace_gist =
		N_("Delete the character to the left of the cursor");
599
#ifndef NANO_TINY
600
601
602
603
604
605
	const char *cutwordleft_gist =
		N_("Cut backward from cursor to word start");
	const char *cutwordright_gist =
		N_("Cut forward from cursor to next word start");
	const char *cuttilleof_gist =
		N_("Cut from the cursor position to the end of the file");
606
#endif
607
#ifdef ENABLE_JUSTIFY
608
609
	const char *justify_gist = N_("Justify the current paragraph");
	const char *fulljustify_gist = N_("Justify the entire file");
610
#endif
611
#ifndef NANO_TINY
612
613
	const char *wordcount_gist =
		N_("Count the number of words, lines, and characters");
614
#endif
615
616
617
618
	const char *refresh_gist =
		N_("Refresh (redraw) the current screen");
	const char *suspend_gist =
		N_("Suspend the editor (if suspension is enabled)");
619
#ifdef ENABLE_WORDCOMPLETION
620
	const char *completion_gist = N_("Try and complete the current word");
621
#endif
622
#ifdef ENABLE_COMMENT
623
624
	const char *comment_gist =
		N_("Comment/uncomment the current line (or marked lines)");
625
#endif
626
	const char *savefile_gist = N_("Save file without prompting");
627
#ifndef NANO_TINY
628
629
630
631
632
633
634
635
636
637
638
	const char *findprev_gist = N_("Search next occurrence backward");
	const char *findnext_gist = N_("Search next occurrence forward");
	const char *recordmacro_gist = N_("Start/stop recording a macro");
	const char *runmacro_gist = N_("Run the last recorded macro");
#endif
	const char *case_gist =
		N_("Toggle the case sensitivity of the search");
	const char *reverse_gist =
		N_("Reverse the direction of the search");
	const char *regexp_gist =
		N_("Toggle the use of regular expressions");
639
#ifdef ENABLE_HISTORIES
640
641
642
643
	const char *prevhistory_gist =
		N_("Recall the previous search/replace string");
	const char *nexthistory_gist =
		N_("Recall the next search/replace string");
644
#endif
645
#ifndef NANO_TINY
646
647
648
649
650
651
	const char *dos_gist = N_("Toggle the use of DOS format");
	const char *mac_gist = N_("Toggle the use of Mac format");
	const char *append_gist = N_("Toggle appending");
	const char *prepend_gist = N_("Toggle prepending");
	const char *backup_gist = N_("Toggle backing up of the original file");
	const char *execute_gist = N_("Execute external command");
652
#endif
653
#ifdef ENABLE_MULTIBUFFER
654
	const char *newbuffer_gist = N_("Toggle the use of a new buffer");
655
#endif
656
	const char *discardbuffer_gist = N_("Close buffer without saving it");
657
#ifdef ENABLE_BROWSER
658
659
660
661
662
663
664
	const char *tofiles_gist = N_("Go to file browser");
	const char *exitbrowser_gist = N_("Exit from the file browser");
	const char *firstfile_gist = N_("Go to the first file in the list");
	const char *lastfile_gist = N_("Go to the last file in the list");
	const char *backfile_gist = N_("Go to the previous file in the list");
	const char *forwardfile_gist = N_("Go to the next file in the list");
	const char *gotodir_gist = N_("Go to directory");
Chris Allegretta's avatar
Chris Allegretta committed
665
#endif
666
#ifdef ENABLE_COLOR
667
668
669
	const char *lint_gist = N_("Invoke the linter, if available");
	const char *prevlint_gist = N_("Go to previous linter msg");
	const char *nextlint_gist = N_("Go to next linter msg");
670
#ifdef ENABLE_SPELLER
671
	const char *formatter_gist = N_("Invoke formatter, if available");
672
#endif
673
#endif
674
#endif /* ENABLE_HELP */
Chris Allegretta's avatar
Chris Allegretta committed
675

676
#ifdef ENABLE_HELP
677
#define WITHORSANS(help) help
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
678
#else
679
#define WITHORSANS(help) ""
680
#endif
681

682
	/* Start populating the different menus with functions. */
Benno Schulenberg's avatar
Benno Schulenberg committed
683

684
685
686
	add_to_funcs(do_help_void, MMOST & ~MFINDINHELP,
		/* TRANSLATORS: Try to keep the following strings at most 10 characters. */
		N_("Get Help"), WITHORSANS(help_gist), TOGETHER, VIEW);
Chris Allegretta's avatar
Chris Allegretta committed
687

688
689
	add_to_funcs(do_cancel, ((MMOST & ~MMAIN & ~MBROWSER) | MYESNO),
		N_("Cancel"), WITHORSANS(cancel_gist), BLANKAFTER, VIEW);
690

691
692
693
694
	add_to_funcs(do_exit, MMAIN,
		exit_tag, WITHORSANS(exit_gist), TOGETHER, VIEW);
	/* Remember the entry for Exit, to be able to replace it with Close. */
	exitfunc = tailfunc;
Chris Allegretta's avatar
Chris Allegretta committed
695

696
#ifdef ENABLE_BROWSER
697
698
	add_to_funcs(do_exit, MBROWSER,
		exit_tag, WITHORSANS(exitbrowser_gist), TOGETHER, VIEW);
699
#endif
Chris Allegretta's avatar
Chris Allegretta committed
700

701
702
	add_to_funcs(do_writeout_void, MMAIN,
		N_("Write Out"), WITHORSANS(writeout_gist), TOGETHER, NOVIEW);
703

704
#ifdef ENABLE_JUSTIFY
705
	if (!ISSET(RESTRICTED)) {
706
#else
707
708
709
710
711
712
713
714
	/* If we can't replace Insert with Justify, show Insert anyway, to
	 * keep the help items nicely paired also in restricted mode.  */
	if (TRUE) {
#endif
		add_to_funcs(do_insertfile_void, MMAIN,
				readfile_tag, WITHORSANS(readfile_gist), BLANKAFTER,
				/* We allow inserting files in view mode if multibuffer mode
				 * is switched on, so that we can view multiple files. */
715
#ifdef ENABLE_MULTIBUFFER
716
				VIEW);
717
#else
718
				NOVIEW);
719
#endif
720
	} else {
721
#ifdef ENABLE_JUSTIFY
722
723
		add_to_funcs(do_justify_void, MMAIN,
				justify_tag, WITHORSANS(justify_gist), BLANKAFTER, NOVIEW);
724
#endif
725
	}
Chris Allegretta's avatar
Chris Allegretta committed
726

727
728
	add_to_funcs(do_search_forward, MMAIN,
		whereis_tag, WITHORSANS(whereis_gist), TOGETHER, VIEW);
Chris Allegretta's avatar
Chris Allegretta committed
729

730
731
	add_to_funcs(do_replace, MMAIN,
		replace_tag, WITHORSANS(replace_gist), TOGETHER, NOVIEW);
732

733
#ifdef ENABLE_BROWSER
734
735
	add_to_funcs(do_search_forward, MBROWSER,
		whereis_tag, WITHORSANS(browserwhereis_gist), TOGETHER, VIEW);
736

737
738
	add_to_funcs(do_research, MBROWSER,
		whereisnext_tag, WITHORSANS(whereisnext_gist), BLANKAFTER, VIEW);
739

740
741
	add_to_funcs(goto_dir_void, MBROWSER,
		N_("Go To Dir"), WITHORSANS(gotodir_gist), TOGETHER, VIEW);
742

743
744
	add_to_funcs(total_refresh, MBROWSER,
		refresh_tag, WITHORSANS(browserrefresh_gist), BLANKAFTER, VIEW);
745
746
#endif

747
#ifdef ENABLE_HELP
748
749
750
751
	/* The description ("x") and blank_after (0) are irrelevant,
	 * because the help viewer does not have a help text. */
	add_to_funcs(total_refresh, MHELP, refresh_tag, "x", 0, VIEW);
	add_to_funcs(do_exit, MHELP, close_tag, "x", 0, VIEW);
752

753
754
	add_to_funcs(do_search_forward, MHELP, whereis_tag, "x", 0, VIEW);
	add_to_funcs(do_research, MHELP, whereisnext_tag, "x", 0, VIEW);
755
756
#endif

757
758
	add_to_funcs(do_cut_text_void, MMAIN,
		N_("Cut Text"), WITHORSANS(cut_gist), TOGETHER, NOVIEW);
Chris Allegretta's avatar
Chris Allegretta committed
759

760
761
762
763
	add_to_funcs(do_uncut_text, MMAIN,
		uncut_tag, WITHORSANS(uncut_gist), BLANKAFTER, NOVIEW);
	/* Remember the entry for Uncut, to be able to replace it with Unjustify. */
	uncutfunc = tailfunc;
Chris Allegretta's avatar
Chris Allegretta committed
764

765
	if (!ISSET(RESTRICTED)) {
766
#ifdef ENABLE_JUSTIFY
767
768
		add_to_funcs(do_justify_void, MMAIN,
				justify_tag, WITHORSANS(justify_gist), TOGETHER, NOVIEW);
Chris Allegretta's avatar
Chris Allegretta committed
769
#endif
Chris Allegretta's avatar
Chris Allegretta committed
770

771
#ifdef ENABLE_SPELLER
772
773
		add_to_funcs(do_spell, MMAIN,
				N_("To Spell"), WITHORSANS(spell_gist), TOGETHER, NOVIEW);
774
#endif
775
#ifdef ENABLE_COLOR
776
777
		add_to_funcs(do_linter, MMAIN,
				N_("To Linter"), WITHORSANS(lint_gist), TOGETHER, NOVIEW);
778
#ifdef ENABLE_SPELLER
779
780
		add_to_funcs(do_formatter, MMAIN,
				N_("Formatter"), WITHORSANS(formatter_gist), BLANKAFTER, NOVIEW);
781
#endif
782
#endif
783
	}
784

785
786
	add_to_funcs(do_cursorpos_void, MMAIN,
		N_("Cur Pos"), WITHORSANS(cursorpos_gist), TOGETHER, VIEW);
787

788
#if (defined(ENABLE_JUSTIFY) && (defined(ENABLE_SPELLER) || defined(ENABLE_COLOR)) || \
789
790
791
792
793
		!defined(ENABLE_JUSTIFY) && !defined(ENABLE_SPELLER) && !defined(ENABLE_COLOR))
	/* Conditionally placing this one here or further on, to keep the
	 * help items nicely paired in most conditions. */
	add_to_funcs(do_gotolinecolumn_void, MMAIN,
		gotoline_tag, WITHORSANS(gotoline_gist), BLANKAFTER, VIEW);
794
795
#endif

796
#ifndef NANO_TINY
797
798
799
800
	add_to_funcs(do_undo, MMAIN,
		N_("Undo"), WITHORSANS(undo_gist), TOGETHER, NOVIEW);
	add_to_funcs(do_redo, MMAIN,
		N_("Redo"), WITHORSANS(redo_gist), BLANKAFTER, NOVIEW);
801

802
803
804
805
	add_to_funcs(do_mark, MMAIN,
		N_("Mark Text"), WITHORSANS(mark_gist), TOGETHER, VIEW);
	add_to_funcs(do_copy_text, MMAIN,
		N_("Copy Text"), WITHORSANS(copy_gist), BLANKAFTER, NOVIEW);
806
807
#endif

808
809
810
811
812
813
	add_to_funcs(case_sens_void, MWHEREIS|MREPLACE,
		N_("Case Sens"), WITHORSANS(case_gist), TOGETHER, VIEW);
	add_to_funcs(regexp_void, MWHEREIS|MREPLACE,
		N_("Regexp"), WITHORSANS(regexp_gist), TOGETHER, VIEW);
	add_to_funcs(backwards_void, MWHEREIS|MREPLACE,
		N_("Backwards"), WITHORSANS(reverse_gist), TOGETHER, VIEW);
814

815
816
	add_to_funcs(flip_replace, MWHEREIS,
		replace_tag, WITHORSANS(replace_gist), BLANKAFTER, VIEW);
817

818
819
	add_to_funcs(flip_replace, MREPLACE,
		N_("No Replace"), WITHORSANS(whereis_gist), BLANKAFTER, VIEW);
820

821
#ifdef ENABLE_JUSTIFY
822
823
	add_to_funcs(do_full_justify, MWHEREIS,
		fulljustify_tag, WITHORSANS(fulljustify_gist), TOGETHER, NOVIEW);
824

825
	add_to_funcs(flip_goto, MWHEREIS,
826
		gotoline_tag, WITHORSANS(gotoline_gist), BLANKAFTER, VIEW);
827
#endif
828

829
#ifndef NANO_TINY
830
831
	add_to_funcs(do_find_bracket, MMAIN,
		N_("To Bracket"), WITHORSANS(bracket_gist), BLANKAFTER, VIEW);
832

833
834
	add_to_funcs(do_research, MMAIN,
		whereisnext_tag, WITHORSANS(whereisnext_gist), TOGETHER, VIEW);
835

836
837
838
839
	add_to_funcs(do_findprevious, MMAIN,
		N_("Previous"), WITHORSANS(findprev_gist), TOGETHER, VIEW);
	add_to_funcs(do_findnext, MMAIN,
		N_("Next"), WITHORSANS(findnext_gist), BLANKAFTER, VIEW);
840
#endif /* !NANO_TINY */
841

842
843
844
845
	add_to_funcs(do_left, MMAIN,
		N_("Back"), WITHORSANS(back_gist), TOGETHER, VIEW);
	add_to_funcs(do_right, MMAIN,
		N_("Forward"), WITHORSANS(forward_gist), TOGETHER, VIEW);
846
#ifdef ENABLE_BROWSER
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
	add_to_funcs(do_left, MBROWSER,
		N_("Back"), WITHORSANS(backfile_gist), TOGETHER, VIEW);
	add_to_funcs(do_right, MBROWSER,
		N_("Forward"), WITHORSANS(forwardfile_gist), TOGETHER, VIEW);
#endif

	add_to_funcs(do_prev_word_void, MMAIN,
		N_("Prev Word"), WITHORSANS(prevword_gist), TOGETHER, VIEW);
	add_to_funcs(do_next_word_void, MMAIN,
		N_("Next Word"), WITHORSANS(nextword_gist), TOGETHER, VIEW);

	add_to_funcs(do_home, MMAIN,
		N_("Home"), WITHORSANS(home_gist), TOGETHER, VIEW);
	add_to_funcs(do_end, MMAIN,
		N_("End"), WITHORSANS(end_gist), BLANKAFTER, VIEW);

	add_to_funcs(do_up_void, MMAIN|MHELP|MBROWSER,
		prevline_tag, WITHORSANS(prevline_gist), TOGETHER, VIEW);
	add_to_funcs(do_down_void, MMAIN|MHELP|MBROWSER,
		nextline_tag, WITHORSANS(nextline_gist), TOGETHER, VIEW);
867
#ifndef NANO_TINY
868
869
870
871
	add_to_funcs(do_scroll_up, MMAIN,
		N_("Scroll Up"), WITHORSANS(scrollup_gist), TOGETHER, VIEW);
	add_to_funcs(do_scroll_down, MMAIN,
		N_("Scroll Down"), WITHORSANS(scrolldown_gist), BLANKAFTER, VIEW);
872
#endif
873

874
875
876
877
	add_to_funcs(do_prev_block, MMAIN,
		N_("Prev Block"), WITHORSANS(prevblock_gist), TOGETHER, VIEW);
	add_to_funcs(do_next_block, MMAIN,
		N_("Next Block"), WITHORSANS(nextblock_gist), TOGETHER, VIEW);
878
#ifdef ENABLE_JUSTIFY
879
880
881
882
	add_to_funcs(do_para_begin_void, MMAIN|MWHEREIS,
		N_("Beg of Par"), WITHORSANS(parabegin_gist), TOGETHER, VIEW);
	add_to_funcs(do_para_end_void, MMAIN|MWHEREIS,
		N_("End of Par"), WITHORSANS(paraend_gist), BLANKAFTER, VIEW);
883
#endif
884

885
886
887
888
	add_to_funcs(do_page_up, MMAIN|MHELP,
		prevpage_tag, WITHORSANS(prevpage_gist), TOGETHER, VIEW);
	add_to_funcs(do_page_down, MMAIN|MHELP,
		nextpage_tag, WITHORSANS(nextpage_gist), TOGETHER, VIEW);
889

890
891
892
893
	add_to_funcs(to_first_line, MMAIN|MHELP|MWHEREIS|MREPLACE|MREPLACEWITH|MGOTOLINE,
		N_("First Line"), WITHORSANS(firstline_gist), TOGETHER, VIEW);
	add_to_funcs(to_last_line, MMAIN|MHELP|MWHEREIS|MREPLACE|MREPLACEWITH|MGOTOLINE,
		N_("Last Line"), WITHORSANS(lastline_gist), BLANKAFTER, VIEW);
894

895
#ifdef ENABLE_MULTIBUFFER
896
897
898
899
	add_to_funcs(switch_to_prev_buffer, MMAIN,
		N_("Prev File"), WITHORSANS(prevfile_gist), TOGETHER, VIEW);
	add_to_funcs(switch_to_next_buffer, MMAIN,
		N_("Next File"), WITHORSANS(nextfile_gist), BLANKAFTER, VIEW);
900
901
#endif

902
#if (!defined(ENABLE_JUSTIFY) && (defined(ENABLE_SPELLER) || defined(ENABLE_COLOR)) || \
903
904
905
		defined(ENABLE_JUSTIFY) && !defined(ENABLE_SPELLER) && !defined(ENABLE_COLOR))
	add_to_funcs(do_gotolinecolumn_void, MMAIN,
		gotoline_tag, WITHORSANS(gotoline_gist), BLANKAFTER, VIEW);
906
907
#endif

908
#ifdef NANO_TINY
909
910
911
	/* Place this one here only in the tiny version; otherwise further up. */
	add_to_funcs(do_research, MMAIN,
		whereisnext_tag, WITHORSANS(whereisnext_gist), TOGETHER, VIEW);
912
913
#endif

914
915
916
917
	add_to_funcs(do_tab, MMAIN,
		N_("Tab"), WITHORSANS(tab_gist), TOGETHER, NOVIEW);
	add_to_funcs(do_enter, MMAIN,
		N_("Enter"), WITHORSANS(enter_gist), BLANKAFTER, NOVIEW);
918

919
920
921
922
	add_to_funcs(do_delete, MMAIN,
		N_("Delete"), WITHORSANS(delete_gist), TOGETHER, NOVIEW);
	add_to_funcs(do_backspace, MMAIN,
		N_("Backspace"), WITHORSANS(backspace_gist),
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
923
#ifndef NANO_TINY
924
		TOGETHER,
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
925
#else
926
		BLANKAFTER,
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
927
#endif
928
		NOVIEW);
929

930
#ifndef NANO_TINY
931
932
933
934
935
936
937
	add_to_funcs(do_cut_prev_word, MMAIN,
		/* TRANSLATORS: The next two strings refer to cutting words. */
		N_("Cut Left"), WITHORSANS(cutwordleft_gist), TOGETHER, NOVIEW);
	add_to_funcs(do_cut_next_word, MMAIN,
		N_("Cut Right"), WITHORSANS(cutwordright_gist), TOGETHER, NOVIEW);
	add_to_funcs(do_cut_till_eof, MMAIN,
		N_("CutTillEnd"), WITHORSANS(cuttilleof_gist), BLANKAFTER, NOVIEW);
938
#endif
Chris Allegretta's avatar
Chris Allegretta committed
939

940
#ifdef ENABLE_JUSTIFY
941
942
	add_to_funcs(do_full_justify, MMAIN,
		fulljustify_tag, WITHORSANS(fulljustify_gist), TOGETHER, NOVIEW);
943
944
#endif

945
#ifndef NANO_TINY
946
947
	add_to_funcs(do_wordlinechar_count, MMAIN,
		N_("Word Count"), WITHORSANS(wordcount_gist), TOGETHER, VIEW);
948
#endif
949

950
951
	add_to_funcs(do_verbatim_input, MMAIN,
		N_("Verbatim"), WITHORSANS(verbatim_gist), BLANKAFTER, NOVIEW);
952

953
954
	add_to_funcs(total_refresh, MMAIN,
		refresh_tag, WITHORSANS(refresh_gist), TOGETHER, VIEW);
955

956
957
	add_to_funcs(do_suspend_void, MMAIN,
		N_("Suspend"), WITHORSANS(suspend_gist), BLANKAFTER, VIEW);
Chris Allegretta's avatar
Chris Allegretta committed
958

959
#ifndef NANO_TINY
960
961
962
963
	add_to_funcs(do_indent, MMAIN,
		N_("Indent Text"), WITHORSANS(indent_gist), TOGETHER, NOVIEW);
	add_to_funcs(do_unindent, MMAIN,
		N_("Unindent Text"), WITHORSANS(unindent_gist), BLANKAFTER, NOVIEW);
964
#endif
965
#ifdef ENABLE_COMMENT
966
967
	add_to_funcs(do_comment, MMAIN,
		N_("Comment Lines"), WITHORSANS(comment_gist), TOGETHER, NOVIEW);
968
969
#endif
#ifdef ENABLE_WORDCOMPLETION
970
971
	add_to_funcs(complete_a_word, MMAIN,
		N_("Complete"), WITHORSANS(completion_gist), BLANKAFTER, NOVIEW);
972
#endif
973
#ifndef NANO_TINY
974
975
976
977
	add_to_funcs(record_macro, MMAIN,
		N_("Record"), WITHORSANS(recordmacro_gist), TOGETHER, VIEW);
	add_to_funcs(run_macro, MMAIN,
		N_("Run Macro"), WITHORSANS(runmacro_gist), BLANKAFTER, VIEW);
978
#endif
979
980
981
	add_to_funcs(do_search_backward, MMAIN,
		/* TRANSLATORS: This starts a backward search. */
		N_("Where Was"), WITHORSANS(wherewas_gist), BLANKAFTER, VIEW);
982

983
984
	add_to_funcs(do_savefile, MMAIN,
		N_("Save"), WITHORSANS(savefile_gist), BLANKAFTER, NOVIEW);
985

986
#ifdef ENABLE_HISTORIES
987
988
989
990
	add_to_funcs(get_history_older_void, MWHEREIS|MREPLACE|MREPLACEWITH|MWHEREISFILE,
		N_("PrevHstory"), WITHORSANS(prevhistory_gist), TOGETHER, VIEW);
	add_to_funcs(get_history_newer_void, MWHEREIS|MREPLACE|MREPLACEWITH|MWHEREISFILE,
		N_("NextHstory"), WITHORSANS(nexthistory_gist), BLANKAFTER, VIEW);
991
992
#endif

993
#ifndef ENABLE_JUSTIFY
994
	add_to_funcs(flip_goto, MWHEREIS,
995
		gotoline_tag, WITHORSANS(gotoline_gist), BLANKAFTER, VIEW);
996
#endif
997

998
	add_to_funcs(flip_goto, MGOTOLINE,
999
		N_("Go To Text"), WITHORSANS(whereis_gist), BLANKAFTER, VIEW);
1000

1001
#ifndef NANO_TINY
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
	add_to_funcs(dos_format_void, MWRITEFILE,
		N_("DOS Format"), WITHORSANS(dos_gist), TOGETHER, NOVIEW);
	add_to_funcs(mac_format_void, MWRITEFILE,
		N_("Mac Format"), WITHORSANS(mac_gist), TOGETHER, NOVIEW);

	/* If we're using restricted mode, the Append, Prepend, and Backup toggles
	 * are disabled.  The first and second are not useful as they only allow
	 * reduplicating the current file, and the third is not allowed as it
	 * would write to a file not specified on the command line. */
	if (!ISSET(RESTRICTED)) {
		add_to_funcs(append_void, MWRITEFILE,
			N_("Append"), WITHORSANS(append_gist), TOGETHER, NOVIEW);
		add_to_funcs(prepend_void, MWRITEFILE,
			N_("Prepend"), WITHORSANS(prepend_gist), TOGETHER, NOVIEW);

		add_to_funcs(backup_file_void, MWRITEFILE,
			N_("Backup File"), WITHORSANS(backup_gist), BLANKAFTER, NOVIEW);
	}

	/* If we're using restricted mode, file insertion is disabled, and
	 * thus command execution and the multibuffer toggle have no place. */
	if (!ISSET(RESTRICTED)) {
		add_to_funcs(flip_execute, MINSERTFILE,
			N_("Execute Command"), WITHORSANS(execute_gist), TOGETHER, NOVIEW);

		add_to_funcs(flip_execute, MEXTCMD,
			readfile_tag, WITHORSANS(readfile_gist), TOGETHER, NOVIEW);
	}
1030
#endif /* !NANO_TINY */
1031
#ifdef ENABLE_MULTIBUFFER
1032
1033
1034
	if (!ISSET(RESTRICTED))
		add_to_funcs(flip_newbuffer, MINSERTFILE|MEXTCMD,
			N_("New Buffer"), WITHORSANS(newbuffer_gist), TOGETHER, NOVIEW);
1035
#endif
1036

1037
#ifdef ENABLE_BROWSER
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
	if (!ISSET(RESTRICTED))
		add_to_funcs(to_files_void, MWRITEFILE|MINSERTFILE,
			N_("To Files"), WITHORSANS(tofiles_gist), TOGETHER, VIEW);

	add_to_funcs(do_page_up, MBROWSER,
		prevpage_tag, WITHORSANS(prevpage_gist), TOGETHER, VIEW);
	add_to_funcs(do_page_down, MBROWSER,
		nextpage_tag, WITHORSANS(nextpage_gist), TOGETHER, VIEW);

	add_to_funcs(to_first_file, MBROWSER|MWHEREISFILE,
		N_("First File"), WITHORSANS(firstfile_gist), TOGETHER, VIEW);
	add_to_funcs(to_last_file, MBROWSER|MWHEREISFILE,
		N_("Last File"), WITHORSANS(lastfile_gist), BLANKAFTER, VIEW);
1051
#ifndef NANO_TINY
1052
1053
1054
1055
1056
1057
1058
1059
	add_to_funcs(do_prev_word_void, MBROWSER,
		N_("Left Column"), WITHORSANS(browserlefthand_gist), TOGETHER, VIEW);
	add_to_funcs(do_next_word_void, MBROWSER,
		N_("Right Column"), WITHORSANS(browserrighthand_gist), TOGETHER, VIEW);
	add_to_funcs(do_prev_block, MBROWSER,
		N_("Top Row"), WITHORSANS(browsertoprow_gist), TOGETHER, VIEW);
	add_to_funcs(do_next_block, MBROWSER,
		N_("Bottom Row"), WITHORSANS(browserbottomrow_gist), BLANKAFTER, VIEW);
1060
#endif
1061
1062
#endif /* ENABLE_BROWSER */

1063
1064
	add_to_funcs(discard_buffer, MWRITEFILE,
		N_("Discard buffer"), WITHORSANS(discardbuffer_gist), BLANKAFTER, NOVIEW);
1065

1066
#ifdef ENABLE_COLOR
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
	add_to_funcs(do_page_up, MLINTER,
		/* TRANSLATORS: Try to keep the next two strings at most 20 characters. */
		N_("Prev Lint Msg"), WITHORSANS(prevlint_gist), TOGETHER, VIEW);
	add_to_funcs(do_page_down, MLINTER,
		N_("Next Lint Msg"), WITHORSANS(nextlint_gist), TOGETHER, VIEW);
#endif

	/* Link key combos to functions in certain menus. */
	add_to_sclist(MMOST, "^M", 0, do_enter, 0);
	add_to_sclist(MMOST, "Enter", KEY_ENTER, do_enter, 0);
	add_to_sclist(MMOST, "^H", 0, do_backspace, 0);
	add_to_sclist(MMOST, "Bsp", KEY_BACKSPACE, do_backspace, 0);
	add_to_sclist(MMOST, "^D", 0, do_delete, 0);
	add_to_sclist(MMOST, "Del", 0, do_delete, 0);
	add_to_sclist(MMOST, "^I", 0, do_tab, 0);
	add_to_sclist(MMOST, "Tab", TAB_CODE, do_tab, 0);
	add_to_sclist(MMOST & ~MFINDINHELP, "^G", 0, do_help_void, 0);
	add_to_sclist(MMOST & ~MFINDINHELP, "F1", 0, do_help_void, 0);
	add_to_sclist(MMAIN|MHELP|MBROWSER, "^X", 0, do_exit, 0);
	add_to_sclist(MMAIN|MHELP|MBROWSER, "F2", 0, do_exit, 0);
	add_to_sclist(MMAIN, "^S", 0, do_savefile, 0);
	add_to_sclist(MMAIN, "^O", 0, do_writeout_void, 0);
	add_to_sclist(MMAIN, "F3", 0, do_writeout_void, 0);
	add_to_sclist(MMAIN, "^R", 0, do_insertfile_void, 0);
	add_to_sclist(MMAIN, "F5", 0, do_insertfile_void, 0);
	add_to_sclist(MMAIN, "Ins", 0, do_insertfile_void, 0);
	add_to_sclist(MMAIN, "^Q", 0, do_search_backward, 0);
	add_to_sclist(MMAIN|MHELP|MBROWSER, "^W", 0, do_search_forward, 0);
	add_to_sclist(MMAIN|MHELP|MBROWSER, "F6", 0, do_search_forward, 0);
	add_to_sclist(MMAIN, "^\\", 0, do_replace, 0);
	add_to_sclist(MMAIN, "M-R", 0, do_replace, 0);
	add_to_sclist(MMAIN, "F14", 0, do_replace, 0);
	add_to_sclist(MMOST, "^K", 0, do_cut_text_void, 0);
	add_to_sclist(MMOST, "F9", 0, do_cut_text_void, 0);
	add_to_sclist(MMOST, "^U", 0, do_uncut_text, 0);
	add_to_sclist(MMOST, "F10", 0, do_uncut_text, 0);
1103
#ifdef ENABLE_JUSTIFY
1104
1105
	add_to_sclist(MMAIN, "^J", 0, do_justify_void, 0);
	add_to_sclist(MMAIN, "F4", 0, do_justify_void, 0);
1106
#endif
1107
#ifdef ENABLE_SPELLER
1108
1109
	add_to_sclist(MMAIN, "^T", 0, do_spell, 0);
	add_to_sclist(MMAIN, "F12", 0, do_spell, 0);
1110
#else
1111
#ifdef ENABLE_COLOR
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
	add_to_sclist(MMAIN, "^T", 0, do_linter, 0);
	add_to_sclist(MMAIN, "F12", 0, do_linter, 0);
#endif
#endif
	add_to_sclist(MMAIN, "^C", 0, do_cursorpos_void, 0);
	add_to_sclist(MMAIN, "F11", 0, do_cursorpos_void, 0);
	add_to_sclist(MMAIN, "^_", 0, do_gotolinecolumn_void, 0);
	add_to_sclist(MMAIN, "M-G", 0, do_gotolinecolumn_void, 0);
	add_to_sclist(MMAIN, "F13", 0, do_gotolinecolumn_void, 0);
	add_to_sclist(MMAIN|MHELP|MBROWSER|MLINTER, "^Y", 0, do_page_up, 0);
	add_to_sclist(MMAIN|MHELP|MBROWSER|MLINTER, "F7", 0, do_page_up, 0);
	add_to_sclist(MMAIN|MHELP|MBROWSER|MLINTER, "PgUp", KEY_PPAGE, do_page_up, 0);
	add_to_sclist(MHELP|MBROWSER, "Bsp", KEY_BACKSPACE, do_page_up, 0);
	add_to_sclist(MMAIN|MHELP|MBROWSER|MLINTER, "^V", 0, do_page_down, 0);
	add_to_sclist(MMAIN|MHELP|MBROWSER|MLINTER, "F8", 0, do_page_down, 0);
	add_to_sclist(MMAIN|MHELP|MBROWSER|MLINTER, "PgDn", KEY_NPAGE, do_page_down, 0);
	add_to_sclist(MMAIN|MHELP, "M-\\", 0, to_first_line, 0);
	add_to_sclist(MMAIN|MHELP, "^Home", CONTROL_HOME, to_first_line, 0);
	add_to_sclist(MMAIN|MHELP, "M-|", 0, to_first_line, 0);
	add_to_sclist(MMAIN|MHELP, "M-/", 0, to_last_line, 0);
	add_to_sclist(MMAIN|MHELP, "^End", CONTROL_END, to_last_line, 0);
	add_to_sclist(MMAIN|MHELP, "M-?", 0, to_last_line, 0);
	add_to_sclist(MMAIN|MHELP|MBROWSER, "M-W", 0, do_research, 0);
	add_to_sclist(MMAIN|MHELP|MBROWSER, "F16", 0, do_research, 0);
1136
#ifndef NANO_TINY
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
	add_to_sclist(MMAIN, "M-]", 0, do_find_bracket, 0);
	add_to_sclist(MMAIN, "M-A", 0, do_mark, 0);
	add_to_sclist(MMAIN, "^6", 0, do_mark, 0);
	add_to_sclist(MMAIN, "^^", 0, do_mark, 0);
	add_to_sclist(MMAIN, "F15", 0, do_mark, 0);
	add_to_sclist(MMAIN, "M-6", 0, do_copy_text, 0);
	add_to_sclist(MMAIN, "M-^", 0, do_copy_text, 0);
	add_to_sclist(MMAIN, "M-}", 0, do_indent, 0);
	add_to_sclist(MMAIN, "Tab", TAB_CODE, do_indent, 0);
	add_to_sclist(MMAIN, "M-{", 0, do_unindent, 0);
	add_to_sclist(MMAIN, "Sh-Tab", SHIFT_TAB, do_unindent, 0);
	add_to_sclist(MMAIN, "M-:", 0, record_macro, 0);
	add_to_sclist(MMAIN, "M-;", 0, run_macro, 0);
	add_to_sclist(MMAIN, "M-U", 0, do_undo, 0);
	add_to_sclist(MMAIN, "M-E", 0, do_redo, 0);
1152
1153
#endif
#ifdef ENABLE_WORDCOMPLETION
1154
	add_to_sclist(MMAIN, "^]", 0, complete_a_word, 0);
1155
1156
#endif
#ifdef ENABLE_COMMENT
1157
	add_to_sclist(MMAIN, "M-3", 0, do_comment, 0);
1158
#endif
1159
1160
	add_to_sclist(MMOST, "^B", 0, do_left, 0);
	add_to_sclist(MMOST, "^F", 0, do_right, 0);
1161
#ifdef ENABLE_UTF8
1162
1163
1164
1165
1166
	if (using_utf8()) {
		add_to_sclist(MMOST, "\xE2\x97\x80", KEY_LEFT, do_left, 0);
		add_to_sclist(MMOST, "\xE2\x96\xb6", KEY_RIGHT, do_right, 0);
		add_to_sclist(MSOME, "^\xE2\x97\x80", CONTROL_LEFT, do_prev_word_void, 0);
		add_to_sclist(MSOME, "^\xE2\x96\xb6", CONTROL_RIGHT, do_next_word_void, 0);
1167
#ifdef ENABLE_MULTIBUFFER
1168
1169
		add_to_sclist(MMAIN, "M-\xE2\x97\x80", ALT_LEFT, switch_to_prev_buffer, 0);
		add_to_sclist(MMAIN, "M-\xE2\x96\xb6", ALT_RIGHT, switch_to_next_buffer, 0);
1170
#endif
1171
#ifndef NANO_TINY
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
		add_to_sclist(MMAIN|MHELP|MBROWSER, "M-\xE2\x96\xb2", ALT_UP, do_findprevious, 0);
		add_to_sclist(MMAIN|MHELP|MBROWSER, "M-\xE2\x96\xbc", ALT_DOWN, do_findnext, 0);
#endif
	} else
#endif
	{
		add_to_sclist(MMOST, "Left", KEY_LEFT, do_left, 0);
		add_to_sclist(MMOST, "Right", KEY_RIGHT, do_right, 0);
		add_to_sclist(MSOME, "^Left", CONTROL_LEFT, do_prev_word_void, 0);
		add_to_sclist(MSOME, "^Right", CONTROL_RIGHT, do_next_word_void, 0);
	}
	add_to_sclist(MMOST, "M-Space", 0, do_prev_word_void, 0);
	add_to_sclist(MMOST, "^Space", 0, do_next_word_void, 0);
	add_to_sclist((MMOST & ~MBROWSER), "^A", 0, do_home, 0);
	add_to_sclist((MMOST & ~MBROWSER), "Home", KEY_HOME, do_home, 0);
	add_to_sclist((MMOST & ~MBROWSER), "^E", 0, do_end, 0);
	add_to_sclist((MMOST & ~MBROWSER), "End", KEY_END, do_end, 0);
	add_to_sclist(MMAIN|MHELP|MBROWSER, "^P", 0, do_up_void, 0);
	add_to_sclist(MMAIN|MHELP|MBROWSER, "^N", 0, do_down_void, 0);
1191
#ifdef ENABLE_UTF8
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
	if (using_utf8()) {
		add_to_sclist(MMAIN|MHELP|MBROWSER, "\xE2\x96\xb2", KEY_UP, do_up_void, 0);
		add_to_sclist(MMAIN|MHELP|MBROWSER, "\xE2\x96\xbc", KEY_DOWN, do_down_void, 0);
		add_to_sclist(MMAIN|MBROWSER, "^\xE2\x96\xb2", CONTROL_UP, do_prev_block, 0);
		add_to_sclist(MMAIN|MBROWSER, "^\xE2\x96\xbc", CONTROL_DOWN, do_next_block, 0);
	} else
#endif
	{
		add_to_sclist(MMAIN|MHELP|MBROWSER, "Up", KEY_UP, do_up_void, 0);
		add_to_sclist(MMAIN|MHELP|MBROWSER, "Down", KEY_DOWN, do_down_void, 0);
		add_to_sclist(MMAIN|MBROWSER, "^Up", CONTROL_UP, do_prev_block, 0);
		add_to_sclist(MMAIN|MBROWSER, "^Down", CONTROL_DOWN, do_next_block, 0);
	}
	add_to_sclist(MMAIN, "M-7", 0, do_prev_block, 0);
	add_to_sclist(MMAIN, "M-8", 0, do_next_block, 0);
1207
#ifdef ENABLE_JUSTIFY
1208
1209
1210
1211
	add_to_sclist(MMAIN, "M-(", 0, do_para_begin_void, 0);
	add_to_sclist(MMAIN, "M-9", 0, do_para_begin_void, 0);
	add_to_sclist(MMAIN, "M-)", 0, do_para_end_void, 0);
	add_to_sclist(MMAIN, "M-0", 0, do_para_end_void, 0);
Benno Schulenberg's avatar
Benno Schulenberg committed
1212
#endif
1213
#ifndef NANO_TINY
1214
1215
1216
1217
	add_to_sclist(MMAIN, "M--", 0, do_scroll_up, 0);
	add_to_sclist(MMAIN, "M-_", 0, do_scroll_up, 0);
	add_to_sclist(MMAIN, "M-+", 0, do_scroll_down, 0);
	add_to_sclist(MMAIN, "M-=", 0, do_scroll_down, 0);
1218
#endif
1219
#ifdef ENABLE_MULTIBUFFER
1220
1221
1222
1223
	add_to_sclist(MMAIN, "M-<", 0, switch_to_prev_buffer, 0);
	add_to_sclist(MMAIN, "M-,", 0, switch_to_prev_buffer, 0);
	add_to_sclist(MMAIN, "M->", 0, switch_to_next_buffer, 0);
	add_to_sclist(MMAIN, "M-.", 0, switch_to_next_buffer, 0);
1224
#endif
1225
	add_to_sclist(MMOST, "M-V", 0, do_verbatim_input, 0);
1226
#ifndef NANO_TINY
1227
1228
	add_to_sclist(MMAIN, "M-T", 0, do_cut_till_eof, 0);
	add_to_sclist(MMAIN, "M-D", 0, do_wordlinechar_count, 0);
1229
#endif
1230
#ifdef ENABLE_JUSTIFY
1231
	add_to_sclist(MMAIN|MWHEREIS, "M-J", 0, do_full_justify, 0);
1232
#endif
1233
1234
	add_to_sclist(MMAIN|MHELP|MBROWSER, "^L", 0, total_refresh, 0);
	add_to_sclist(MMAIN, "^Z", 0, do_suspend_void, 0);
1235

1236
#ifndef NANO_TINY
1237
1238
1239
1240
1241
1242
	/* Group of "Appearance" toggles. */
	add_to_sclist(MMAIN, "M-X", 0, do_toggle_void, NO_HELP);
	add_to_sclist(MMAIN, "M-C", 0, do_toggle_void, CONSTANT_SHOW);
	add_to_sclist(MMAIN, "M-O", 0, do_toggle_void, MORE_SPACE);
	add_to_sclist(MMAIN, "M-S", 0, do_toggle_void, SMOOTH_SCROLL);
	add_to_sclist(MMAIN, "M-$", 0, do_toggle_void, SOFTWRAP);
1243
#ifdef ENABLE_LINENUMBERS
1244
	add_to_sclist(MMAIN, "M-#", 0, do_toggle_void, LINE_NUMBERS);
1245
#endif
1246
	add_to_sclist(MMAIN, "M-P", 0, do_toggle_void, WHITESPACE_DISPLAY);
1247
#ifdef ENABLE_COLOR
1248
	add_to_sclist(MMAIN, "M-Y", 0, do_toggle_void, NO_COLOR_SYNTAX);
1249
#endif
1250

1251
1252
1253
1254
	/* Group of "Editing-behavior" toggles. */
	add_to_sclist(MMAIN, "M-H", 0, do_toggle_void, SMART_HOME);
	add_to_sclist(MMAIN, "M-I", 0, do_toggle_void, AUTOINDENT);
	add_to_sclist(MMAIN, "M-K", 0, do_toggle_void, CUT_FROM_CURSOR);
1255
#ifdef ENABLE_WRAPPING
1256
	add_to_sclist(MMAIN, "M-L", 0, do_toggle_void, NO_WRAP);
1257
#endif
1258
	add_to_sclist(MMAIN, "M-Q", 0, do_toggle_void, TABS_TO_SPACES);
1259

1260
1261
	/* Group of "Peripheral-feature" toggles. */
	add_to_sclist(MMAIN, "M-B", 0, do_toggle_void, BACKUP_FILE);
1262
#ifdef ENABLE_MULTIBUFFER
1263
	add_to_sclist(MMAIN, "M-F", 0, do_toggle_void, MULTIBUFFER);
1264
#endif
1265
#ifdef ENABLE_MOUSE
1266
	add_to_sclist(MMAIN, "M-M", 0, do_toggle_void, USE_MOUSE);
1267
#endif
1268
1269
	add_to_sclist(MMAIN, "M-N", 0, do_toggle_void, NO_CONVERT);
	add_to_sclist(MMAIN, "M-Z", 0, do_toggle_void, SUSPEND);
1270
#endif /* !NANO_TINY */
Benno Schulenberg's avatar
Benno Schulenberg committed
1271

1272
	add_to_sclist(((MMOST & ~MMAIN & ~MBROWSER) | MYESNO), "^C", 0, do_cancel, 0);
1273

1274
1275
1276
1277
1278
1279
	add_to_sclist(MWHEREIS|MREPLACE, "M-C", 0, case_sens_void, 0);
	add_to_sclist(MWHEREIS|MREPLACE, "M-R", 0, regexp_void, 0);
	add_to_sclist(MWHEREIS|MREPLACE, "M-B", 0, backwards_void, 0);
	add_to_sclist(MWHEREIS|MREPLACE, "^R", 0, flip_replace, 0);
	add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH|MGOTOLINE|MFINDINHELP, "^Y", 0, to_first_line, 0);
	add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH|MGOTOLINE|MFINDINHELP, "^V", 0, to_last_line, 0);
1280
#ifdef ENABLE_JUSTIFY
1281
1282
	add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH, "^W", 0, do_para_begin_void, 0);
	add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH, "^O", 0, do_para_end_void, 0);
1283
#endif
1284
	add_to_sclist(MWHEREIS|MGOTOLINE, "^T", 0, flip_goto, 0);
1285
#ifdef ENABLE_HISTORIES
1286
1287
	add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH|MWHEREISFILE|MFINDINHELP|MEXTCMD, "^P", 0, get_history_older_void, 0);
	add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH|MWHEREISFILE|MFINDINHELP|MEXTCMD, "^N", 0, get_history_newer_void, 0);
1288
#ifdef ENABLE_UTF8
1289
1290
1291
1292
	if (using_utf8()) {
		add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH|MWHEREISFILE|MFINDINHELP|MEXTCMD, "\xE2\x96\xb2", KEY_UP, get_history_older_void, 0);
		add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH|MWHEREISFILE|MFINDINHELP|MEXTCMD, "\xE2\x96\xbc", KEY_DOWN, get_history_newer_void, 0);
	} else
1293
#endif
1294
1295
1296
1297
	{
		add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH|MWHEREISFILE|MFINDINHELP|MEXTCMD, "Up", KEY_UP, get_history_older_void, 0);
		add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH|MWHEREISFILE|MFINDINHELP|MEXTCMD, "Down", KEY_DOWN, get_history_newer_void, 0);
	}
1298
#endif
1299
#ifdef ENABLE_BROWSER
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
	add_to_sclist(MWHEREISFILE, "^Y", 0, to_first_file, 0);
	add_to_sclist(MWHEREISFILE, "^V", 0, to_last_file, 0);
	add_to_sclist(MBROWSER|MWHEREISFILE, "M-\\", 0, to_first_file, 0);
	add_to_sclist(MBROWSER|MWHEREISFILE, "M-/", 0, to_last_file, 0);
	add_to_sclist(MBROWSER, "Home", KEY_HOME, to_first_file, 0);
	add_to_sclist(MBROWSER, "End", KEY_END, to_last_file, 0);
	add_to_sclist(MBROWSER|MWHEREISFILE, "M-|", 0, to_first_file, 0);
	add_to_sclist(MBROWSER|MWHEREISFILE, "M-?", 0, to_last_file, 0);
	add_to_sclist(MBROWSER, "^Home", CONTROL_HOME, to_first_file, 0);
	add_to_sclist(MBROWSER, "^End", CONTROL_END, to_last_file, 0);
	add_to_sclist(MBROWSER, "^_", 0, goto_dir_void, 0);
	add_to_sclist(MBROWSER, "M-G", 0, goto_dir_void, 0);
	add_to_sclist(MBROWSER, "F13", 0, goto_dir_void, 0);
#endif
	if (ISSET(TEMP_FILE))
		add_to_sclist(MWRITEFILE, "^Q", 0, discard_buffer, 0);
1316
#ifndef NANO_TINY
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
	add_to_sclist(MWRITEFILE, "M-D", 0, dos_format_void, 0);
	add_to_sclist(MWRITEFILE, "M-M", 0, mac_format_void, 0);
	/* In restricted mode, don't allow Appending, Prepending, nor making
	 * backups, nor executing a command, nor opening a new buffer. */
	if (!ISSET(RESTRICTED)) {
		add_to_sclist(MWRITEFILE, "M-A", 0, append_void, 0);
		add_to_sclist(MWRITEFILE, "M-P", 0, prepend_void, 0);
		add_to_sclist(MWRITEFILE, "M-B", 0, backup_file_void, 0);
		add_to_sclist(MINSERTFILE|MEXTCMD, "^X", 0, flip_execute, 0);
	}
1327
#endif
1328
#ifdef ENABLE_MULTIBUFFER
1329
1330
	if (!ISSET(RESTRICTED))
		add_to_sclist(MINSERTFILE|MEXTCMD, "M-F", 0, flip_newbuffer, 0);
1331
#endif
1332
#ifdef ENABLE_BROWSER
1333
1334
1335
	/* In restricted mode, don't allow entering the file browser. */
	if (!ISSET(RESTRICTED))
		add_to_sclist(MWRITEFILE|MINSERTFILE, "^T", 0, to_files_void, 0);
1336
#endif
1337
1338
1339
	add_to_sclist(MHELP|MBROWSER, "^C", 0, do_exit, 0);
	/* Allow exiting from the file browser and the help viewer with
	 * the same key as they were entered. */
1340
#ifdef ENABLE_BROWSER
1341
	add_to_sclist(MBROWSER, "^T", 0, do_exit, 0);
1342
#endif
1343
#ifdef ENABLE_HELP
1344
1345
1346
1347
	add_to_sclist(MHELP, "^G", 0, do_exit, 0);
	add_to_sclist(MHELP, "F1", 0, do_exit, 0);
	add_to_sclist(MHELP, "Home", KEY_HOME, to_first_line, 0);
	add_to_sclist(MHELP, "End", KEY_END, to_last_line, 0);
1348
#endif
Chris Allegretta's avatar
Chris Allegretta committed
1349

1350
#ifdef DEBUG
1351
	print_sclist();
Chris Allegretta's avatar
Chris Allegretta committed
1352
#endif
1353
}
1354

1355
1356
1357
1358
1359
1360
1361
1362
1363
#if defined(ENABLE_COLOR) && defined(ENABLE_SPELLER)
/* Assign one function's shortcuts to another function. */
void replace_scs_for(void (*oldfunc)(void), void (*newfunc)(void))
{
	for (sc *s = sclist; s != NULL; s = s->next)
		if (s->scfunc == oldfunc)
			s->scfunc = newfunc;
}

1364
void set_lint_or_format_shortcuts(void)
1365
{
1366
1367
1368
1369
1370
1371
1372
	if (openfile->syntax->formatter) {
		replace_scs_for(do_spell, do_formatter);
		replace_scs_for(do_linter, do_formatter);
	} else {
		replace_scs_for(do_spell, do_linter);
		replace_scs_for(do_formatter, do_linter);
	}
1373
1374
1375
1376
}

void set_spell_shortcuts(void)
{
1377
1378
		replace_scs_for(do_formatter, do_spell);
		replace_scs_for(do_linter, do_spell);
1379
}
1380
#endif /* ENABLE_COLOR && ENABLE_SPELLER */
1381

1382
const subnfunc *sctofunc(const sc *s)
1383
{
1384
	subnfunc *f = allfuncs;
1385

1386
1387
	while (f != NULL && f->scfunc != s->scfunc)
		f = f->next;
1388

1389
	return f;
1390
1391
}

1392
#ifndef NANO_TINY
1393
1394
/* Now let's come up with a single (hopefully) function to get a string
 * for each flag. */
1395
const char *flagtostr(int flag)
1396
{
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
	switch (flag) {
		case NO_HELP:
			/* TRANSLATORS: The next eighteen strings are toggle descriptions;
			 * they are best kept shorter than 40 characters, but may be longer. */
			return N_("Help mode");
		case CONSTANT_SHOW:
			return N_("Constant cursor position display");
		case MORE_SPACE:
			return N_("Use of one more line for editing");
		case SMOOTH_SCROLL:
			return N_("Smooth scrolling");
		case SOFTWRAP:
			return N_("Soft wrapping of overlong lines");
		case WHITESPACE_DISPLAY:
			return N_("Whitespace display");
		case NO_COLOR_SYNTAX:
			return N_("Color syntax highlighting");
		case SMART_HOME:
			return N_("Smart home key");
		case AUTOINDENT:
			return N_("Auto indent");
		case CUT_FROM_CURSOR:
			return N_("Cut to end");
		case NO_WRAP:
			return N_("Hard wrapping of overlong lines");
		case TABS_TO_SPACES:
			return N_("Conversion of typed tabs to spaces");
		case BACKUP_FILE:
			return N_("Backup files");
		case MULTIBUFFER:
			return N_("Reading file into separate buffer");
		case USE_MOUSE:
			return N_("Mouse support");
		case NO_CONVERT:
			return N_("No conversion from DOS/Mac format");
		case SUSPEND:
			return N_("Suspension");
		case LINE_NUMBERS:
			return N_("Line numbering");
		default:
			return "Bad toggle -- please report a bug";
	}
1439
}
1440
#endif /* !NANO_TINY */
1441

1442
#ifdef ENABLE_NANORC
1443
/* Interpret a function string given in the rc file, and return a
1444
 * shortcut struct with the corresponding function filled in. */
1445
sc *strtosc(const char *input)
1446
{
1447
	sc *s = nmalloc(sizeof(sc));
1448

1449
#ifndef NANO_TINY
1450
	s->toggle = 0;
1451
#endif
1452

1453
#ifdef ENABLE_HELP
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
	if (!strcasecmp(input, "help"))
		s->scfunc = do_help_void;
	else
#endif
	if (!strcasecmp(input, "cancel"))
		s->scfunc = do_cancel;
	else if (!strcasecmp(input, "exit"))
		s->scfunc = do_exit;
	else if (!strcasecmp(input, "discardbuffer"))
		s->scfunc = discard_buffer;
	else if (!strcasecmp(input, "writeout"))
		s->scfunc = do_writeout_void;
	else if (!strcasecmp(input, "savefile"))
		s->scfunc = do_savefile;
	else if (!strcasecmp(input, "insert"))
		s->scfunc = do_insertfile_void;
	else if (!strcasecmp(input, "whereis"))
		s->scfunc = do_search_forward;
	else if (!strcasecmp(input, "wherewas"))
		s->scfunc = do_search_backward;
	else if (!strcasecmp(input, "searchagain") ||
			 !strcasecmp(input, "research"))  /* Deprecated.  Remove in 2018. */
		s->scfunc = do_research;
1477
#ifndef NANO_TINY
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
	else if (!strcasecmp(input, "findprevious"))
		s->scfunc = do_findprevious;
	else if (!strcasecmp(input, "findnext"))
		s->scfunc = do_findnext;
#endif
	else if (!strcasecmp(input, "replace"))
		s->scfunc = do_replace;
	else if (!strcasecmp(input, "cut"))
		s->scfunc = do_cut_text_void;
	else if (!strcasecmp(input, "uncut"))
		s->scfunc = do_uncut_text;
1489
#ifndef NANO_TINY
1490
1491
1492
1493
1494
1495
	else if (!strcasecmp(input, "cutrestoffile"))
		s->scfunc = do_cut_till_eof;
	else if (!strcasecmp(input, "copytext"))
		s->scfunc = do_copy_text;
	else if (!strcasecmp(input, "mark"))
		s->scfunc = do_mark;
1496
#endif
1497
#ifdef ENABLE_SPELLER
1498
1499
1500
	else if (!strcasecmp(input, "tospell") ||
			 !strcasecmp(input, "speller"))
		s->scfunc = do_spell;
1501
#endif
1502
#ifdef ENABLE_COLOR
1503
1504
1505
1506
1507
1508
1509
1510
	else if (!strcasecmp(input, "linter"))
		s->scfunc = do_linter;
#endif
	else if (!strcasecmp(input, "curpos") ||
			 !strcasecmp(input, "cursorpos"))  /* Deprecated.  Remove in 2018. */
		s->scfunc = do_cursorpos_void;
	else if (!strcasecmp(input, "gotoline"))
		s->scfunc = do_gotolinecolumn_void;
1511
#ifdef ENABLE_JUSTIFY
1512
1513
1514
1515
1516
1517
1518
1519
	else if (!strcasecmp(input, "justify"))
		s->scfunc = do_justify_void;
	else if (!strcasecmp(input, "fulljustify"))
		s->scfunc = do_full_justify;
	else if (!strcasecmp(input, "beginpara"))
		s->scfunc = do_para_begin_void;
	else if (!strcasecmp(input, "endpara"))
		s->scfunc = do_para_end_void;
1520
#endif
1521
#ifdef ENABLE_COMMENT
1522
1523
	else if (!strcasecmp(input, "comment"))
		s->scfunc = do_comment;
1524
#endif
1525
#ifdef ENABLE_WORDCOMPLETION
1526
1527
	else if (!strcasecmp(input, "complete"))
		s->scfunc = complete_a_word;
1528
#endif
1529
#ifndef NANO_TINY
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
	else if (!strcasecmp(input, "indent"))
		s->scfunc = do_indent;
	else if (!strcasecmp(input, "unindent"))
		s->scfunc = do_unindent;
	else if (!strcasecmp(input, "scrollup"))
		s->scfunc = do_scroll_up;
	else if (!strcasecmp(input, "scrolldown"))
		s->scfunc = do_scroll_down;
	else if (!strcasecmp(input, "cutwordleft"))
		s->scfunc = do_cut_prev_word;
	else if (!strcasecmp(input, "cutwordright"))
		s->scfunc = do_cut_next_word;
	else if (!strcasecmp(input, "findbracket"))
		s->scfunc = do_find_bracket;
	else if (!strcasecmp(input, "wordcount"))
		s->scfunc = do_wordlinechar_count;
	else if (!strcasecmp(input, "recordmacro"))
		s->scfunc = record_macro;
	else if (!strcasecmp(input, "runmacro"))
		s->scfunc = run_macro;
	else if (!strcasecmp(input, "undo"))
		s->scfunc = do_undo;
	else if (!strcasecmp(input, "redo"))
		s->scfunc = do_redo;
#endif
	else if (!strcasecmp(input, "left") ||
			 !strcasecmp(input, "back"))
		s->scfunc = do_left;
	else if (!strcasecmp(input, "right") ||
			 !strcasecmp(input, "forward"))
		s->scfunc = do_right;
	else if (!strcasecmp(input, "up") ||
			 !strcasecmp(input, "prevline"))
		s->scfunc = do_up_void;
	else if (!strcasecmp(input, "down") ||
			 !strcasecmp(input, "nextline"))
		s->scfunc = do_down_void;
	else if (!strcasecmp(input, "prevword"))
		s->scfunc = do_prev_word_void;
	else if (!strcasecmp(input, "nextword"))
		s->scfunc = do_next_word_void;
	else if (!strcasecmp(input, "home"))
		s->scfunc = do_home;
	else if (!strcasecmp(input, "end"))
		s->scfunc = do_end;
	else if (!strcasecmp(input, "prevblock"))
		s->scfunc = do_prev_block;
	else if (!strcasecmp(input, "nextblock"))
		s->scfunc = do_next_block;
	else if (!strcasecmp(input, "pageup") ||
			 !strcasecmp(input, "prevpage"))
		s->scfunc = do_page_up;
	else if (!strcasecmp(input, "pagedown") ||
			 !strcasecmp(input, "nextpage"))
		s->scfunc = do_page_down;
	else if (!strcasecmp(input, "firstline"))
		s->scfunc = to_first_line;
	else if (!strcasecmp(input, "lastline"))
		s->scfunc = to_last_line;
1589
#ifdef ENABLE_MULTIBUFFER
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
	else if (!strcasecmp(input, "prevbuf"))
		s->scfunc = switch_to_prev_buffer;
	else if (!strcasecmp(input, "nextbuf"))
		s->scfunc = switch_to_next_buffer;
#endif
	else if (!strcasecmp(input, "verbatim"))
		s->scfunc = do_verbatim_input;
	else if (!strcasecmp(input, "tab"))
		s->scfunc = do_tab;
	else if (!strcasecmp(input, "enter"))
		s->scfunc = do_enter;
	else if (!strcasecmp(input, "delete"))
		s->scfunc = do_delete;
	else if (!strcasecmp(input, "backspace"))
		s->scfunc = do_backspace;
	else if (!strcasecmp(input, "refresh"))
		s->scfunc = total_refresh;
	else if (!strcasecmp(input, "suspend"))
		s->scfunc = do_suspend_void;
	else if (!strcasecmp(input, "casesens"))
		s->scfunc = case_sens_void;
	else if (!strcasecmp(input, "regexp") ||
			 !strcasecmp(input, "regex"))  /* Deprecated.  Remove in 2018. */
		s->scfunc = regexp_void;
	else if (!strcasecmp(input, "backwards"))
		s->scfunc = backwards_void;
	else if (!strcasecmp(input, "flipreplace") ||
			 !strcasecmp(input, "dontreplace"))  /* Deprecated.  Remove in 2018. */
		s->scfunc = flip_replace;
1619
1620
1621
	else if (!strcasecmp(input, "flipgoto") ||
			 !strcasecmp(input, "gototext"))  /* Deprecated.  Remove end of 2018. */
		s->scfunc = flip_goto;
1622
#ifdef ENABLE_HISTORIES
1623
1624
1625
1626
	else if (!strcasecmp(input, "prevhistory"))
		s->scfunc = get_history_older_void;
	else if (!strcasecmp(input, "nexthistory"))
		s->scfunc = get_history_newer_void;
1627
#endif
1628
#ifndef NANO_TINY
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
	else if (!strcasecmp(input, "dosformat"))
		s->scfunc = dos_format_void;
	else if (!strcasecmp(input, "macformat"))
		s->scfunc = mac_format_void;
	else if (!strcasecmp(input, "append"))
		s->scfunc = append_void;
	else if (!strcasecmp(input, "prepend"))
		s->scfunc = prepend_void;
	else if (!strcasecmp(input, "backup"))
		s->scfunc = backup_file_void;
	else if (!strcasecmp(input, "flipexecute"))
		s->scfunc = flip_execute;
1641
#endif
1642
#ifdef ENABLE_MULTIBUFFER
1643
1644
1645
	else if (!strcasecmp(input, "flipnewbuffer") ||
			 !strcasecmp(input, "newbuffer"))  /* Deprecated.  Remove in 2018. */
		s->scfunc = flip_newbuffer;
Chris Allegretta's avatar
Chris Allegretta committed
1646
#endif
1647
#ifdef ENABLE_BROWSER
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
	else if (!strcasecmp(input, "tofiles") ||
			 !strcasecmp(input, "browser"))
		s->scfunc = to_files_void;
	else if (!strcasecmp(input, "gotodir"))
		s->scfunc = goto_dir_void;
	else if (!strcasecmp(input, "firstfile"))
		s->scfunc = to_first_file;
	else if (!strcasecmp(input, "lastfile"))
		s->scfunc = to_last_file;
#endif
	else {
1659
#ifndef NANO_TINY
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
		s->scfunc = do_toggle_void;
		if (!strcasecmp(input, "nohelp"))
			s->toggle = NO_HELP;
		else if (!strcasecmp(input, "constupdate"))
			s->toggle = CONSTANT_SHOW;
		else if (!strcasecmp(input, "morespace"))
			s->toggle = MORE_SPACE;
		else if (!strcasecmp(input, "smoothscroll"))
			s->toggle = SMOOTH_SCROLL;
		else if (!strcasecmp(input, "softwrap"))
			s->toggle = SOFTWRAP;
		else if (!strcasecmp(input, "whitespacedisplay"))
			s->toggle = WHITESPACE_DISPLAY;
1673
#ifdef ENABLE_COLOR
1674
1675
1676
1677
1678
1679
1680
1681
1682
		else if (!strcasecmp(input, "nosyntax"))
			s->toggle = NO_COLOR_SYNTAX;
#endif
		else if (!strcasecmp(input, "smarthome"))
			s->toggle = SMART_HOME;
		else if (!strcasecmp(input, "autoindent"))
			s->toggle = AUTOINDENT;
		else if (!strcasecmp(input, "cuttoend"))
			s->toggle = CUT_FROM_CURSOR;
1683
#ifdef ENABLE_WRAPPING
1684
1685
		else if (!strcasecmp(input, "nowrap"))
			s->toggle = NO_WRAP;
1686
#endif
1687
1688
1689
1690
		else if (!strcasecmp(input, "tabstospaces"))
			s->toggle = TABS_TO_SPACES;
		else if (!strcasecmp(input, "backupfile"))
			s->toggle = BACKUP_FILE;
1691
#ifdef ENABLE_MULTIBUFFER
1692
1693
		else if (!strcasecmp(input, "multibuffer"))
			s->toggle = MULTIBUFFER;
1694
#endif
1695
#ifdef ENABLE_MOUSE
1696
1697
1698
1699
1700
1701
1702
1703
		else if (!strcasecmp(input, "mouse"))
			s->toggle = USE_MOUSE;
#endif
		else if (!strcasecmp(input, "noconvert"))
			s->toggle = NO_CONVERT;
		else if (!strcasecmp(input, "suspendenable"))
			s->toggle = SUSPEND;
		else
1704
#endif /* !NANO_TINY */
1705
1706
1707
1708
		{
			free(s);
			return NULL;
		}
1709
	}
1710
	return s;
1711
}
1712

1713
/* Interpret a menu name and return the corresponding menu flag. */
1714
int strtomenu(const char *input)
1715
{
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
	if (!strcasecmp(input, "all"))
		return (MMOST|MHELP|MYESNO);
	else if (!strcasecmp(input, "main"))
		return MMAIN;
	else if (!strcasecmp(input, "search"))
		return MWHEREIS;
	else if (!strcasecmp(input, "replace"))
		return MREPLACE;
	else if (!strcasecmp(input, "replace2") ||  /* Deprecated.  Remove in 2018. */
			 !strcasecmp(input, "replacewith"))
		return MREPLACEWITH;
	else if (!strcasecmp(input, "gotoline"))
		return MGOTOLINE;
	else if (!strcasecmp(input, "writeout"))
		return MWRITEFILE;
	else if (!strcasecmp(input, "insert"))
		return MINSERTFILE;
	else if (!strcasecmp(input, "externalcmd") ||
			 !strcasecmp(input, "extcmd"))
		return MEXTCMD;
1736
#ifdef ENABLE_HELP
1737
1738
	else if (!strcasecmp(input, "help"))
		return MHELP;
1739
#endif
1740
#ifdef ENABLE_SPELLER
1741
1742
	else if (!strcasecmp(input, "spell"))
		return MSPELL;
1743
#endif
1744
1745
	else if (!strcasecmp(input, "linter"))
		return MLINTER;
1746
#ifdef ENABLE_BROWSER
1747
1748
1749
1750
1751
1752
1753
1754
	else if (!strcasecmp(input, "browser"))
		return MBROWSER;
	else if (!strcasecmp(input, "whereisfile"))
		return MWHEREISFILE;
	else if (!strcasecmp(input, "gotodir"))
		return MGOTODIR;
#endif
	return -1;
1755
}
1756
#endif /* ENABLE_NANORC */
1757

Chris Allegretta's avatar
Chris Allegretta committed
1758

1759
1760
1761
#ifdef DEBUG
/* This function is used to gracefully return all the memory we've used.
 * It should be called just before calling exit().  Practically, the
1762
1763
 * only effect is to cause a segmentation fault if the various data
 * structures got bolloxed earlier.  Thus, we don't bother having this
Chris Allegretta's avatar
Chris Allegretta committed
1764
1765
 * function unless debugging is turned on. */
void thanks_for_all_the_fish(void)
1766
{
1767
1768
1769
1770
	if (topwin != NULL)
		delwin(topwin);
	delwin(edit);
	delwin(bottomwin);
1771

1772
	free(word_chars);
1773
#ifdef ENABLE_JUSTIFY
1774
1775
1776
	free(quotestr);
	regfree(&quotereg);
	free(quoteerr);
1777
#endif
1778
#ifndef NANO_TINY
1779
	free(backup_dir);
1780
#endif
1781
#ifdef ENABLE_OPERATINGDIR
1782
	free(operating_dir);
1783
#endif
1784
1785
1786
	free(answer);
	free(last_search);
	free(present_path);
1787
#ifdef ENABLE_SPELLER
1788
1789
1790
1791
1792
1793
1794
	free(alt_speller);
#endif
	free_filestruct(cutbuffer);
	/* Free the memory associated with each open file buffer. */
	while (openfile != openfile->next) {
		openfile = openfile->next;
		delete_opennode(openfile->prev);
1795
	}
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
	delete_opennode(openfile);
#ifdef ENABLE_COLOR
	free(syntaxstr);
	while (syntaxes != NULL) {
		syntaxtype *sint = syntaxes;
		syntaxes = syntaxes->next;

		free(sint->name);
		free(sint->linter);
		free(sint->formatter);

		while (sint->extensions != NULL) {
			regexlisttype *item = sint->extensions;
			sint->extensions = sint->extensions->next;
			free(item->full_regex);
			free(item);
		}
		while (sint->headers != NULL) {
			regexlisttype *item = sint->headers;
			sint->headers = sint->headers->next;
			free(item->full_regex);
			free(item);
		}
		while (sint->magics != NULL) {
			regexlisttype *item = sint->magics;
			sint->magics = sint->magics->next;
			free(item->full_regex);
			free(item);
		}

		while (sint->color != NULL) {
			colortype *ink = sint->color;
			sint->color = sint->color->next;
			free(ink->start_regex);
			if (ink->start != NULL) {
				regfree(ink->start);
				free(ink->start);
			}
			free(ink->end_regex);
			if (ink->end != NULL) {
				regfree(ink->end);
				free(ink->end);
			}
			free(ink);
		}

		free(sint);
Chris Allegretta's avatar
Chris Allegretta committed
1843
	}
1844
#endif /* ENABLE_COLOR */
1845
#ifdef ENABLE_HISTORIES
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
	/* Free the search, replace, and execute history lists. */
	free_filestruct(searchtop);
	free_filestruct(replacetop);
	free_filestruct(executetop);
#endif
	/* Free the list of functions. */
	while (allfuncs != NULL) {
		subnfunc *f = allfuncs;
		allfuncs = allfuncs->next;
		free(f);
	}
	/* Free the list of shortcuts. */
	while (sclist != NULL) {
		sc *s = sclist;
		sclist = sclist->next;
		free(s);
	}
	free(homedir);
1864
}
1865
#endif /* DEBUG */