global.c 62.3 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-2017 Free Software Foundation, Inc.    *
5
6
 *   Copyright (C) 2014, 2015, 2016 Benno Schulenberg                     *
 *                                                                        *
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
27
#include <strings.h>
#include "assert.h"
Chris Allegretta's avatar
Chris Allegretta committed
28

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

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

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

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

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

55
56
57
58
59
#ifndef DISABLE_COLOR
bool have_palette = FALSE;
	/* Whether the colors for the current syntax have been initialized. */
#endif

60
61
62
bool suppress_cursorpos = FALSE;
	/* Should we skip constant position display for current keystroke? */

63
64
message_type lastmessage = HUSH;
	/* Messages of type HUSH should not overwrite type MILD nor ALERT. */
65

66
67
68
filestruct *pletion_line = NULL;
	/* The line where the last completion was found, if any. */

69
70
71
72
73
bool inhelp = FALSE;
	/* Whether we are in the help viewer. */
char *title = NULL;
	/* When not NULL: the title of the current help text. */

74
75
76
int didfind = 0;
	/* Whether the last search found something. */

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

84
#ifndef DISABLE_WRAPJUSTIFY
85
86
ssize_t fill = 0;
	/* The column where we will wrap lines. */
87
ssize_t wrap_at = -CHARS_FROM_EOL;
88
89
90
91
92
93
94
95
	/* 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. */
#endif

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

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

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
	/* The middle portion of the window, i.e. the edit window, where
107
	 * we display the current file we're editing. */
108
WINDOW *bottomwin = NULL;
109
110
111
112
113
114
115
	/* The bottom portion of the window, where we display statusbar
	 * messages, the statusbar prompt, and a list of shortcuts. */
int editwinrows = 0;
	/* How many rows does the edit window take up? */

filestruct *cutbuffer = NULL;
	/* 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

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

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

149
150
151
char *word_chars = NULL;
	/* Nonalphanumeric characters that also form words. */

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

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

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

162
const char *locking_prefix = ".";
163
	/* Prefix of how to store the vim-style lock file. */
164
const char *locking_suffix = ".swp";
165
	/* Suffix of the vim-style lock file. */
166
#endif
167
#ifndef DISABLE_OPERATINGDIR
168
169
170
171
172
char *operating_dir = NULL;
	/* The relative path to the operating directory, which we can't
	 * move outside of. */
char *full_operating_dir = NULL;
	/* The full path to it. */
173
174
#endif

175
#ifndef DISABLE_SPELLER
176
177
char *alt_speller = NULL;
	/* The command to use for the alternate spell checker. */
178
179
#endif

180
#ifndef DISABLE_COLOR
181
syntaxtype *syntaxes = NULL;
182
	/* The global list of color syntaxes. */
183
char *syntaxstr = NULL;
184
	/* The color syntax name specified on the command line. */
185
186
#endif

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

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

204
#ifndef DISABLE_HISTORIES
205
filestruct *search_history = NULL;
206
	/* The search string history list. */
207
filestruct *searchage = NULL;
208
	/* The top of the search string history list. */
209
filestruct *searchbot = NULL;
210
	/* The bottom of the search string history list. */
211
filestruct *replace_history = NULL;
212
	/* The replace string history list. */
213
filestruct *replaceage = NULL;
214
	/* The top of the replace string history list. */
215
filestruct *replacebot = NULL;
216
	/* The bottom of the replace string history list. */
217
poshiststruct *position_history = NULL;
218
	/* The cursor position history list. */
219
220
#endif

221
222
223
224
225
regex_t search_regexp;
	/* The compiled regular expression to use in searches. */
regmatch_t regmatches[10];
	/* The match positions for parenthetical subexpressions, 10
	 * maximum, used in regular expression searches. */
226

227
int hilite_attribute = A_REVERSE;
228
	/* The curses attribute we use to highlight something. */
229
#ifndef DISABLE_COLOR
230
char* specified_color_combo[] = {NULL};
231
232
	/* The color combinations as specified in the rcfile. */
#endif
233
int interface_color_pair[] = {0};
234
	/* The processed color pairs for the interface elements. */
235

236
char *homedir = NULL;
237
	/* The user's home directory, from $HOME or /etc/passwd. */
238

239

240
/* Return the number of entries in the shortcut list for a given menu. */
241
size_t length_of_list(int menu)
242
{
243
    subnfunc *f;
244
    size_t i = 0;
245

246
    for (f = allfuncs; f != NULL; f = f->next)
247
	if ((f->menus & menu) && first_sc_for(menu, f->scfunc) != NULL)
248
	    i++;
249

250
251
252
    return i;
}

253
254
255
256
257
258
/* To make the functions and shortcuts lists clearer. */
#define VIEW  TRUE		/* Is allowed in view mode. */
#define NOVIEW  FALSE
#define BLANKAFTER  TRUE	/* A blank line after this one. */
#define TOGETHER  FALSE

259
/* Just throw this here. */
260
261
262
263
264
265
void case_sens_void(void)
{
}
void regexp_void(void)
{
}
266
267
268
void backwards_void(void)
{
}
269
270
271
void flip_replace(void)
{
}
272
273
274
void gototext_void(void)
{
}
275
#ifdef ENABLE_BROWSER
276
277
278
void to_files_void(void)
{
}
279
280
281
282
void goto_dir_void(void)
{
}
#endif
283
#ifndef NANO_TINY
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
void dos_format_void(void)
{
}
void mac_format_void(void)
{
}
void append_void(void)
{
}
void prepend_void(void)
{
}
void backup_file_void(void)
{
}
299
void flip_execute(void)
300
301
{
}
302
#endif
303
#ifdef ENABLE_MULTIBUFFER
304
void flip_newbuffer(void)
305
306
{
}
307
#endif
308
void discard_buffer(void)
309
310
311
{
}

312
/* Add a function to the function list. */
313
void add_to_funcs(void (*func)(void), int menus, const char *desc, const char *help,
314
315
    bool blank_after, bool viewok)
{
316
    subnfunc *f = (subnfunc *)nmalloc(sizeof(subnfunc));
317
318
319
320
321
322

    if (allfuncs == NULL)
	allfuncs = f;
    else
	tailfunc->next = f;
    tailfunc = f;
323
324
325
326
327
328

    f->next = NULL;
    f->scfunc = func;
    f->menus = menus;
    f->desc = desc;
    f->viewok = viewok;
329
#ifdef ENABLE_HELP
330
331
332
333
334
    f->help = help;
    f->blank_after = blank_after;
#endif

#ifdef DEBUG
335
    fprintf(stderr, "Added func %ld (%s) for menus %x\n", (long)func, f->desc, menus);
336
#endif
337
338
}

339
/* Add a key combo to the shortcut list. */
340
341
void add_to_sclist(int menus, const char *scstring, const int keycode,
			void (*func)(void), int toggle)
Chris Allegretta's avatar
Chris Allegretta committed
342
{
343
    static sc *tailsc;
344
#ifndef NANO_TINY
345
    static int counter = 0;
346
#endif
347
    sc *s = (sc *)nmalloc(sizeof(sc));
348

349
350
351
352
353
354
355
356
357
    /* Start the list, or tack on the next item. */
    if (sclist == NULL)
	sclist = s;
    else
	tailsc->next = s;
    tailsc = s;
    s->next = NULL;

    /* Fill in the data. */
358
    s->menus = menus;
359
    s->scfunc = func;
360
#ifndef NANO_TINY
361
    s->toggle = toggle;
362
363
    if (toggle)
	s->ordinal = ++counter;
364
#endif
365
    assign_keyinfo(s, scstring, keycode);
366
367

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

372
/* Assign one function's shortcuts to another function. */
373
374
375
376
void replace_scs_for(void (*oldfunc)(void), void (*newfunc)(void))
{
    sc *s;

377
    for (s = sclist; s != NULL; s = s->next)
378
	if (s->scfunc == oldfunc)
379
380
381
	    s->scfunc = newfunc;
}

382
383
384
385
386
387
388
/* 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))
{
    const sc *s;

    for (s = sclist; s != NULL; s = s->next)
389
	if ((s->menus & menu) && s->scfunc == func)
390
391
392
393
394
395
396
397
398
	    return s;

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

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
404
{
    const sc *s = first_sc_for(currmenu, func);

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

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

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

    if (s)
	return s->scfunc;
    else
	return NULL;
}

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
    s->keystr = keystring;
427
    s->meta = (keystring[0] == 'M');
428

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

431
432
433
    if (keycode)
	s->keycode = keycode;
    else if (keystring[0] == '^') {
434
435
	if (strcasecmp(keystring, "^Space") == 0)
	    s->keycode = 0;
436
437
	else
	    s->keycode = keystring[1] - 64;
438
439
440
    } else if (s->meta) {
	if (strcasecmp(keystring, "M-Space") == 0)
	    s->keycode = (int)' ';
441
	else
442
	    s->keycode = tolower((unsigned char)keystring[2]);
443
    } else if (keystring[0] == 'F')
444
445
	s->keycode = KEY_F0 + atoi(&keystring[1]);
    else if (!strcasecmp(keystring, "Ins"))
446
	s->keycode = KEY_IC;
447
    else if (!strcasecmp(keystring, "Del"))
448
	s->keycode = KEY_DC;
449
450
451
452
453
454
455
456
}

#ifdef DEBUG
void print_sclist(void)
{
    sc *s;
    const subnfunc *f;

457
    for (s = sclist; s != NULL; s = s->next) {
458
	f = sctofunc(s);
459
	if (f)
460
	    fprintf(stderr, "Shortcut \"%s\", function: %s, menus %x\n", s->keystr, f->desc, f->menus);
461
	else
462
	    fprintf(stderr, "Hmm, didn't find a func for \"%s\"\n", s->keystr);
463
464
465
466
    }
}
#endif

467
468
/* These four tags are used elsewhere too, so they are global. */
/* TRANSLATORS: Try to keep the next fifteen strings at most 10 characters. */
469
470
const char *exit_tag = N_("Exit");
const char *close_tag = N_("Close");
471
const char *uncut_tag = N_("Uncut Text");
472
#ifndef DISABLE_JUSTIFY
473
474
const char *unjust_tag = N_("Unjustify");
#endif
475

476
477
/* Initialize the list of functions and the list of shortcuts. */
void shortcut_init(void)
478
{
479
    const char *read_file_tag = N_("Read File");
480
    const char *whereis_tag = N_("Where Is");
481
482
    const char *replace_tag = N_("Replace");
    const char *gotoline_tag = N_("Go To Line");
483
484
    const char *prev_line_tag = N_("Prev Line");
    const char *next_line_tag = N_("Next Line");
485
486
    const char *prev_page_tag = N_("Prev Page");
    const char *next_page_tag = N_("Next Page");
487
#ifndef DISABLE_JUSTIFY
488
    const char *justify_tag = N_("Justify");
489
    const char *fulljustify_tag = N_("FullJstify");
490
#endif
491
    const char *refresh_tag = N_("Refresh");
492
493
    /* TRANSLATORS: Try to keep this string at most 12 characters. */
    const char *whereis_next_tag = N_("WhereIs Next");
494

495
#ifdef ENABLE_HELP
496
497
    /* TRANSLATORS: The next long series of strings are shortcut descriptions;
     * they are best kept shorter than 56 characters, but may be longer. */
498
    const char *nano_cancel_msg = N_("Cancel the current function");
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
499
    const char *nano_help_msg = N_("Display this help text");
500
    const char *nano_exit_msg =
501
#ifdef ENABLE_MULTIBUFFER
502
	N_("Close the current file buffer / Exit from nano")
503
#else
504
	N_("Exit from nano")
505
506
#endif
	;
507
508
    const char *nano_writeout_msg =
	N_("Write the current file to disk");
509
510
    const char *nano_insert_msg =
	N_("Insert another file into the current one");
511
    const char *nano_whereis_msg =
512
	N_("Search for a string or a regular expression");
513
#ifdef ENABLE_BROWSER
514
515
    const char *nano_browser_whereis_msg = N_("Search for a string");
    const char *nano_browser_refresh_msg = N_("Refresh the file list");
516
#ifndef NANO_TINY
517
518
    const char *nano_browser_lefthand_msg = N_("Go to lefthand column");
    const char *nano_browser_righthand_msg = N_("Go to righthand column");
519
520
    const char *nano_browser_toprow_msg = N_("Go to first row in this column");
    const char *nano_browser_bottomrow_msg = N_("Go to last row in this column");
521
#endif
522
#endif
523
524
    const char *nano_prevpage_msg = N_("Go one screenful up");
    const char *nano_nextpage_msg = N_("Go one screenful down");
525
526
527
528
    const char *nano_cut_msg =
	N_("Cut the current line and store it in the cutbuffer");
    const char *nano_uncut_msg =
	N_("Uncut from the cutbuffer into the current line");
529
    const char *nano_cursorpos_msg = N_("Display the position of the cursor");
530
#ifndef DISABLE_SPELLER
531
    const char *nano_spell_msg = N_("Invoke the spell checker, if available");
532
#endif
533
    const char *nano_replace_msg = N_("Replace a string or a regular expression");
Benno Schulenberg's avatar
Benno Schulenberg committed
534
    const char *nano_gotoline_msg = N_("Go to line and column number");
535
    const char *nano_whereis_next_msg = N_("Repeat the last search");
536
#ifndef NANO_TINY
537
    const char *nano_mark_msg = N_("Mark text starting from the cursor position");
538
539
    const char *nano_copy_msg =
	N_("Copy the current line and store it in the cutbuffer");
540
541
    const char *nano_indent_msg = N_("Indent the current line");
    const char *nano_unindent_msg = N_("Unindent the current line");
542
543
    const char *nano_undo_msg = N_("Undo the last operation");
    const char *nano_redo_msg = N_("Redo the last undone operation");
544
#endif
545
    const char *nano_back_msg = N_("Go back one character");
546
    const char *nano_forward_msg = N_("Go forward one character");
547
    const char *nano_prevword_msg = N_("Go back one word");
548
    const char *nano_nextword_msg = N_("Go forward one word");
549
550
551
552
    const char *nano_prevline_msg = N_("Go to previous line");
    const char *nano_nextline_msg = N_("Go to next line");
    const char *nano_home_msg = N_("Go to beginning of current line");
    const char *nano_end_msg = N_("Go to end of current line");
553
554
    const char *nano_prevblock_msg = N_("Go to previous block of text");
    const char *nano_nextblock_msg = N_("Go to next block of text");
555
556
#ifndef DISABLE_JUSTIFY
    const char *nano_parabegin_msg =
557
	N_("Go to beginning of paragraph; then of previous paragraph");
558
    const char *nano_paraend_msg =
559
	N_("Go just beyond end of paragraph; then of next paragraph");
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
560
#endif
561
562
    const char *nano_firstline_msg = N_("Go to the first line of the file");
    const char *nano_lastline_msg = N_("Go to the last line of the file");
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
563
#ifndef NANO_TINY
564
    const char *nano_bracket_msg = N_("Go to the matching bracket");
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
565
566
567
568
    const char *nano_scrollup_msg =
	N_("Scroll up one line without scrolling the cursor");
    const char *nano_scrolldown_msg =
	N_("Scroll down one line without scrolling the cursor");
569
#endif
570
#ifdef ENABLE_MULTIBUFFER
571
572
573
574
575
576
577
    const char *nano_prevfile_msg = N_("Switch to the previous file buffer");
    const char *nano_nextfile_msg = N_("Switch to the next file buffer");
#endif
    const char *nano_verbatim_msg = N_("Insert the next keystroke verbatim");
    const char *nano_tab_msg = N_("Insert a tab at the cursor position");
    const char *nano_enter_msg = N_("Insert a newline at the cursor position");
    const char *nano_delete_msg = N_("Delete the character under the cursor");
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
578
579
    const char *nano_backspace_msg =
	N_("Delete the character to the left of the cursor");
580
#ifndef NANO_TINY
581
582
583
584
    const char *nano_cut_word_left_msg =
	N_("Cut backward from cursor to word start");
    const char *nano_cut_word_right_msg =
	N_("Cut forward from cursor to next word start");
585
    const char *nano_cut_till_eof_msg =
586
587
	N_("Cut from the cursor position to the end of the file");
#endif
588
#ifndef DISABLE_JUSTIFY
589
    const char *nano_justify_msg = N_("Justify the current paragraph");
590
    const char *nano_fulljustify_msg = N_("Justify the entire file");
591
#endif
592
#ifndef NANO_TINY
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
593
594
    const char *nano_wordcount_msg =
	N_("Count the number of words, lines, and characters");
595
#endif
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
596
597
    const char *nano_refresh_msg =
	N_("Refresh (redraw) the current screen");
598
    const char *nano_suspend_msg =
599
	N_("Suspend the editor (if suspension is enabled)");
600
601
602
#ifdef ENABLE_WORDCOMPLETION
    const char *nano_completion_msg = N_("Try and complete the current word");
#endif
603
604
605
606
#ifdef ENABLE_COMMENT
    const char *nano_comment_msg =
	N_("Comment/uncomment the current line or marked lines");
#endif
607
#ifndef NANO_TINY
608
    const char *nano_savefile_msg = N_("Save file without prompting");
609
610
    const char *nano_findprev_msg = N_("Search next occurrence backward");
    const char *nano_findnext_msg = N_("Search next occurrence forward");
611
#endif
612
    const char *nano_case_msg =
613
	N_("Toggle the case sensitivity of the search");
614
    const char *nano_reverse_msg =
615
616
617
	N_("Reverse the direction of the search");
    const char *nano_regexp_msg =
	N_("Toggle the use of regular expressions");
618
#ifndef DISABLE_HISTORIES
619
    const char *nano_prev_history_msg =
620
	N_("Recall the previous search/replace string");
621
    const char *nano_next_history_msg =
622
	N_("Recall the next search/replace string");
623
#endif
624
#ifndef NANO_TINY
625
626
627
628
    const char *nano_dos_msg = N_("Toggle the use of DOS format");
    const char *nano_mac_msg = N_("Toggle the use of Mac format");
    const char *nano_append_msg = N_("Toggle appending");
    const char *nano_prepend_msg = N_("Toggle prepending");
629
    const char *nano_backup_msg = N_("Toggle backing up of the original file");
630
    const char *nano_execute_msg = N_("Execute external command");
631
#endif
632
#ifdef ENABLE_MULTIBUFFER
633
634
635
    const char *nano_newbuffer_msg = N_("Toggle the use of a new buffer");
#endif
    const char *nano_discard_buffer_msg = N_("Close buffer without saving it");
636
#ifdef ENABLE_BROWSER
637
    const char *nano_tofiles_msg = N_("Go to file browser");
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
638
    const char *nano_exitbrowser_msg = N_("Exit from the file browser");
639
640
    const char *nano_firstfile_msg = N_("Go to the first file in the list");
    const char *nano_lastfile_msg = N_("Go to the last file in the list");
641
    const char *nano_backfile_msg = N_("Go to the previous file in the list");
642
    const char *nano_forwardfile_msg = N_("Go to the next file in the list");
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
643
    const char *nano_gotodir_msg = N_("Go to directory");
Chris Allegretta's avatar
Chris Allegretta committed
644
#endif
645
#ifndef DISABLE_COLOR
646
    const char *nano_lint_msg = N_("Invoke the linter, if available");
647
648
    const char *nano_prevlint_msg = N_("Go to previous linter msg");
    const char *nano_nextlint_msg = N_("Go to next linter msg");
649
#ifndef DISABLE_SPELLER
650
    const char *nano_formatter_msg = N_("Invoke formatter, if available");
651
#endif
652
#endif
653
#endif /* ENABLE_HELP */
Chris Allegretta's avatar
Chris Allegretta committed
654

655
#ifdef ENABLE_HELP
656
#define IFSCHELP(help) help
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
657
#else
658
#define IFSCHELP(help) ""
659
#endif
660

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

663
    add_to_funcs(do_help_void, MMOST,
664
	/* TRANSLATORS: Try to keep the following strings at most 10 characters. */
665
	N_("Get Help"), IFSCHELP(nano_help_msg), TOGETHER, VIEW);
Chris Allegretta's avatar
Chris Allegretta committed
666

667
    add_to_funcs(do_cancel, ((MMOST & ~MMAIN & ~MBROWSER) | MYESNO),
668
	N_("Cancel"), IFSCHELP(nano_cancel_msg), BLANKAFTER, VIEW);
669

670
    add_to_funcs(do_exit, MMAIN,
671
	exit_tag, IFSCHELP(nano_exit_msg), TOGETHER, VIEW);
672
673
    /* Remember the entry for Exit, to be able to replace it with Close. */
    exitfunc = tailfunc;
Chris Allegretta's avatar
Chris Allegretta committed
674

675
#ifdef ENABLE_BROWSER
676
    add_to_funcs(do_exit, MBROWSER,
677
	exit_tag, IFSCHELP(nano_exitbrowser_msg), TOGETHER, VIEW);
678
#endif
Chris Allegretta's avatar
Chris Allegretta committed
679

680
    add_to_funcs(do_writeout_void, MMAIN,
681
	N_("Write Out"), IFSCHELP(nano_writeout_msg), TOGETHER, NOVIEW);
682

683
684
685
686
687
688
689
#ifndef DISABLE_JUSTIFY
    if (!ISSET(RESTRICTED)) {
#else
    /* 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
690
691
	add_to_funcs(do_insertfile_void, MMAIN,
		read_file_tag, IFSCHELP(nano_insert_msg), BLANKAFTER,
692
693
		/* We allow inserting files in view mode if multibuffer mode
		 * is switched on, so that we can view multiple files. */
694
#ifdef ENABLE_MULTIBUFFER
695
		VIEW);
696
#else
697
		NOVIEW);
698
#endif
699
700
    } else {
#ifndef DISABLE_JUSTIFY
701
	add_to_funcs(do_justify_void, MMAIN,
702
		justify_tag, IFSCHELP(nano_justify_msg), BLANKAFTER, NOVIEW);
703
704
#endif
    }
Chris Allegretta's avatar
Chris Allegretta committed
705

706
    add_to_funcs(do_search, MMAIN,
707
	whereis_tag, IFSCHELP(nano_whereis_msg), TOGETHER, VIEW);
Chris Allegretta's avatar
Chris Allegretta committed
708

709
    add_to_funcs(do_replace, MMAIN,
710
	replace_tag, IFSCHELP(nano_replace_msg), TOGETHER, NOVIEW);
711

712
#ifdef ENABLE_BROWSER
713
    add_to_funcs(do_search, MBROWSER,
714
	whereis_tag, IFSCHELP(nano_browser_whereis_msg), TOGETHER, VIEW);
715

716
    add_to_funcs(goto_dir_void, MBROWSER,
717
	N_("Go To Dir"), IFSCHELP(nano_gotodir_msg), BLANKAFTER, VIEW);
718
719
#endif

720
#ifdef ENABLE_HELP
721
722
    /* The description ("x") and blank_after (0) are irrelevant,
     * because the help viewer does not have a help text. */
723
    add_to_funcs(do_exit, MHELP, close_tag, "x", 0, VIEW);
724
    add_to_funcs(total_refresh, MHELP, refresh_tag, "x", 0, VIEW);
725

726
727
    add_to_funcs(do_search, MHELP, whereis_tag, "x", 0, VIEW);
    add_to_funcs(do_research, MHELP, whereis_next_tag, "x", 0, VIEW);
728
729
#endif

730
    add_to_funcs(do_cut_text_void, MMAIN,
731
	N_("Cut Text"), IFSCHELP(nano_cut_msg), TOGETHER, NOVIEW);
Chris Allegretta's avatar
Chris Allegretta committed
732

733
    add_to_funcs(do_uncut_text, MMAIN,
734
	uncut_tag, IFSCHELP(nano_uncut_msg), BLANKAFTER, NOVIEW);
735
    /* Remember the entry for Uncut, to be able to replace it with Unjustify. */
736
    uncutfunc = tailfunc;
Chris Allegretta's avatar
Chris Allegretta committed
737

738
    if (!ISSET(RESTRICTED)) {
739
#ifndef DISABLE_JUSTIFY
740
	add_to_funcs(do_justify_void, MMAIN,
741
		justify_tag, IFSCHELP(nano_justify_msg), TOGETHER, NOVIEW);
Chris Allegretta's avatar
Chris Allegretta committed
742
#endif
Chris Allegretta's avatar
Chris Allegretta committed
743

744
#ifndef DISABLE_SPELLER
745
746
	add_to_funcs(do_spell, MMAIN,
		N_("To Spell"), IFSCHELP(nano_spell_msg), TOGETHER, NOVIEW);
747
#endif
748
#ifndef DISABLE_COLOR
749
750
	add_to_funcs(do_linter, MMAIN,
		N_("To Linter"), IFSCHELP(nano_lint_msg), TOGETHER, NOVIEW);
751
#ifndef DISABLE_SPELLER
752
753
	add_to_funcs(do_formatter, MMAIN,
		N_("Formatter"), IFSCHELP(nano_formatter_msg), BLANKAFTER, NOVIEW);
754
#endif
755
#endif
756
    }
757

758
759
760
761
762
763
764
765
766
767
768
    add_to_funcs(do_cursorpos_void, MMAIN,
	N_("Cur Pos"), IFSCHELP(nano_cursorpos_msg), TOGETHER, VIEW);

#if (!defined(DISABLE_JUSTIFY) && (!defined(DISABLE_SPELLER) || !defined(DISABLE_COLOR)) || \
	defined(DISABLE_JUSTIFY) && defined(DISABLE_SPELLER) && defined(DISABLE_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, IFSCHELP(nano_gotoline_msg), BLANKAFTER, VIEW);
#endif

769
770
771
772
773
774
775
776
777
778
779
780
#ifndef NANO_TINY
    add_to_funcs(do_undo, MMAIN,
	N_("Undo"), IFSCHELP(nano_undo_msg), TOGETHER, NOVIEW);
    add_to_funcs(do_redo, MMAIN,
	N_("Redo"), IFSCHELP(nano_redo_msg), BLANKAFTER, NOVIEW);

    add_to_funcs(do_mark, MMAIN,
	N_("Mark Text"), IFSCHELP(nano_mark_msg), TOGETHER, VIEW);
    add_to_funcs(do_copy_text, MMAIN,
	N_("Copy Text"), IFSCHELP(nano_copy_msg), BLANKAFTER, NOVIEW);
#endif

781
    add_to_funcs(case_sens_void, MWHEREIS|MREPLACE,
782
	N_("Case Sens"), IFSCHELP(nano_case_msg), TOGETHER, VIEW);
783
    add_to_funcs(regexp_void, MWHEREIS|MREPLACE,
784
	N_("Regexp"), IFSCHELP(nano_regexp_msg), TOGETHER, VIEW);
785
    add_to_funcs(backwards_void, MWHEREIS|MREPLACE,
786
	N_("Backwards"), IFSCHELP(nano_reverse_msg), TOGETHER, VIEW);
787

788
    add_to_funcs(flip_replace, MWHEREIS,
789
	replace_tag, IFSCHELP(nano_replace_msg), BLANKAFTER, VIEW);
790

791
    add_to_funcs(flip_replace, MREPLACE,
792
	N_("No Replace"), IFSCHELP(nano_whereis_msg), BLANKAFTER, VIEW);
793
794

#ifndef DISABLE_JUSTIFY
795
    add_to_funcs(do_full_justify, MWHEREIS,
796
	fulljustify_tag, IFSCHELP(nano_fulljustify_msg), TOGETHER, NOVIEW);
797

798
    add_to_funcs(do_gotolinecolumn_void, MWHEREIS,
799
	gotoline_tag, IFSCHELP(nano_gotoline_msg), BLANKAFTER, VIEW);
800
#endif
801

802
#ifndef NANO_TINY
803
804
805
    add_to_funcs(do_find_bracket, MMAIN,
	N_("To Bracket"), IFSCHELP(nano_bracket_msg), BLANKAFTER, VIEW);

806
    add_to_funcs(do_research, MMAIN,
807
	whereis_next_tag, IFSCHELP(nano_whereis_next_msg), TOGETHER, VIEW);
808

809
810
811
812
    add_to_funcs(do_findprevious, MMAIN,
	N_("Previous"), IFSCHELP(nano_findprev_msg), TOGETHER, VIEW);
    add_to_funcs(do_findnext, MMAIN,
	N_("Next"), IFSCHELP(nano_findnext_msg), BLANKAFTER, VIEW);
813
#endif /* !NANO_TINY */
814

815
    add_to_funcs(do_left, MMAIN,
816
	N_("Back"), IFSCHELP(nano_back_msg), TOGETHER, VIEW);
817
    add_to_funcs(do_right, MMAIN,
818
	N_("Forward"), IFSCHELP(nano_forward_msg), TOGETHER, VIEW);
819
#ifdef ENABLE_BROWSER
820
    add_to_funcs(do_left, MBROWSER,
821
	N_("Back"), IFSCHELP(nano_backfile_msg), TOGETHER, VIEW);
822
    add_to_funcs(do_right, MBROWSER,
823
	N_("Forward"), IFSCHELP(nano_forwardfile_msg), TOGETHER, VIEW);
824
825
#endif

826
    add_to_funcs(do_prev_word_void, MMAIN,
827
	N_("Prev Word"), IFSCHELP(nano_prevword_msg), TOGETHER, VIEW);
828
    add_to_funcs(do_next_word_void, MMAIN,
829
	N_("Next Word"), IFSCHELP(nano_nextword_msg), TOGETHER, VIEW);
830

831
    add_to_funcs(do_home_void, MMAIN,
832
	N_("Home"), IFSCHELP(nano_home_msg), TOGETHER, VIEW);
833
    add_to_funcs(do_end_void, MMAIN,
834
	N_("End"), IFSCHELP(nano_end_msg), BLANKAFTER, VIEW);
835

836
    add_to_funcs(do_up_void, MMAIN|MHELP|MBROWSER,
837
	prev_line_tag, IFSCHELP(nano_prevline_msg), TOGETHER, VIEW);
838
    add_to_funcs(do_down_void, MMAIN|MHELP|MBROWSER,
839
840
841
842
843
844
845
	next_line_tag, IFSCHELP(nano_nextline_msg), TOGETHER, VIEW);
#ifndef NANO_TINY
    add_to_funcs(do_scroll_up, MMAIN,
	N_("Scroll Up"), IFSCHELP(nano_scrollup_msg), TOGETHER, VIEW);
    add_to_funcs(do_scroll_down, MMAIN,
	N_("Scroll Down"), IFSCHELP(nano_scrolldown_msg), BLANKAFTER, VIEW);
#endif
846

847
848
849
850
    add_to_funcs(do_prev_block, MMAIN,
	N_("Prev Block"), IFSCHELP(nano_prevblock_msg), TOGETHER, VIEW);
    add_to_funcs(do_next_block, MMAIN,
	N_("Next Block"), IFSCHELP(nano_nextblock_msg), TOGETHER, VIEW);
851
#ifndef DISABLE_JUSTIFY
852
    add_to_funcs(do_para_begin_void, MMAIN|MWHEREIS,
853
	N_("Beg of Par"), IFSCHELP(nano_parabegin_msg), TOGETHER, VIEW);
854
    add_to_funcs(do_para_end_void, MMAIN|MWHEREIS,
855
	N_("End of Par"), IFSCHELP(nano_paraend_msg), BLANKAFTER, VIEW);
856
#endif
857

858
859
860
861
862
863
864
865
866
    add_to_funcs(do_page_up, MMAIN|MHELP,
	prev_page_tag, IFSCHELP(nano_prevpage_msg), TOGETHER, VIEW);
    add_to_funcs(do_page_down, MMAIN|MHELP,
	next_page_tag, IFSCHELP(nano_nextpage_msg), TOGETHER, VIEW);

    add_to_funcs(do_first_line, MMAIN|MHELP|MWHEREIS|MREPLACE|MREPLACEWITH|MGOTOLINE,
	N_("First Line"), IFSCHELP(nano_firstline_msg), TOGETHER, VIEW);
    add_to_funcs(do_last_line, MMAIN|MHELP|MWHEREIS|MREPLACE|MREPLACEWITH|MGOTOLINE,
	N_("Last Line"), IFSCHELP(nano_lastline_msg), BLANKAFTER, VIEW);
867

868
#ifdef ENABLE_MULTIBUFFER
869
    add_to_funcs(switch_to_prev_buffer_void, MMAIN,
870
	N_("Prev File"), IFSCHELP(nano_prevfile_msg), TOGETHER, VIEW);
871
    add_to_funcs(switch_to_next_buffer_void, MMAIN,
872
	N_("Next File"), IFSCHELP(nano_nextfile_msg), BLANKAFTER, VIEW);
873
874
#endif

875
876
#if (defined(DISABLE_JUSTIFY) && (!defined(DISABLE_SPELLER) || !defined(DISABLE_COLOR)) || \
	!defined(DISABLE_JUSTIFY) && defined(DISABLE_SPELLER) && defined(DISABLE_COLOR))
877
    add_to_funcs(do_gotolinecolumn_void, MMAIN,
878
	gotoline_tag, IFSCHELP(nano_gotoline_msg), BLANKAFTER, VIEW);
879
880
#endif

881
882
883
884
885
886
#ifdef NANO_TINY
    /* Place this one here only in the tiny version; otherwise further up. */
    add_to_funcs(do_research, MMAIN,
	whereis_next_tag, IFSCHELP(nano_whereis_next_msg), TOGETHER, VIEW);
#endif

887
    add_to_funcs(do_tab, MMAIN,
888
	N_("Tab"), IFSCHELP(nano_tab_msg), TOGETHER, NOVIEW);
889
    add_to_funcs(do_enter, MMAIN,
890
891
	N_("Enter"), IFSCHELP(nano_enter_msg), BLANKAFTER, NOVIEW);

892
    add_to_funcs(do_delete, MMAIN,
893
	N_("Delete"), IFSCHELP(nano_delete_msg), TOGETHER, NOVIEW);
894
895
    add_to_funcs(do_backspace, MMAIN,
	N_("Backspace"), IFSCHELP(nano_backspace_msg),
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
896
#ifndef NANO_TINY
897
	TOGETHER,
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
898
#else
899
	BLANKAFTER,
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
900
#endif
901
902
	NOVIEW);

903
#ifndef NANO_TINY
904
    add_to_funcs(do_cut_prev_word, MMAIN,
905
	/* TRANSLATORS: The next two strings refer to cutting words. */
906
907
908
	N_("Cut Left"), IFSCHELP(nano_cut_word_left_msg), TOGETHER, NOVIEW);
    add_to_funcs(do_cut_next_word, MMAIN,
	N_("Cut Right"), IFSCHELP(nano_cut_word_right_msg), TOGETHER, NOVIEW);
909
    add_to_funcs(do_cut_till_eof, MMAIN,
910
	N_("CutTillEnd"), IFSCHELP(nano_cut_till_eof_msg), BLANKAFTER, NOVIEW);
911
#endif
Chris Allegretta's avatar
Chris Allegretta committed
912

913
#ifndef DISABLE_JUSTIFY
914
    add_to_funcs(do_full_justify, MMAIN,
915
	fulljustify_tag, IFSCHELP(nano_fulljustify_msg), TOGETHER, NOVIEW);
916
917
#endif

918
#ifndef NANO_TINY
919
    add_to_funcs(do_wordlinechar_count, MMAIN,
920
	N_("Word Count"), IFSCHELP(nano_wordcount_msg), TOGETHER, VIEW);
921
#endif
922

923
924
925
    add_to_funcs(do_verbatim_input, MMAIN,
	N_("Verbatim"), IFSCHELP(nano_verbatim_msg), BLANKAFTER, NOVIEW);

926
    add_to_funcs(total_refresh, MMAIN,
927
	refresh_tag, IFSCHELP(nano_refresh_msg), TOGETHER, VIEW);
928

929
    add_to_funcs(do_suspend_void, MMAIN,
930
	N_("Suspend"), IFSCHELP(nano_suspend_msg), BLANKAFTER, VIEW);
Chris Allegretta's avatar
Chris Allegretta committed
931

932
#ifndef NANO_TINY
933
    add_to_funcs(do_indent, MMAIN,
934
	N_("Indent Text"), IFSCHELP(nano_indent_msg), TOGETHER, NOVIEW);
935
    add_to_funcs(do_unindent, MMAIN,
936
937
	N_("Unindent Text"), IFSCHELP(nano_unindent_msg), BLANKAFTER, NOVIEW);
#endif
938
939
940
941
#ifdef ENABLE_WORDCOMPLETION
    add_to_funcs(complete_a_word, MMAIN,
	N_("Complete"), IFSCHELP(nano_completion_msg), TOGETHER, NOVIEW);
#endif
942
943
944
945
#ifdef ENABLE_COMMENT
    add_to_funcs(do_comment, MMAIN,
	N_("Comment Lines"), IFSCHELP(nano_comment_msg), BLANKAFTER, NOVIEW);
#endif
946
947
948
949
950
#ifndef NANO_TINY
    add_to_funcs(do_savefile, MMAIN,
	N_("Save"), IFSCHELP(nano_savefile_msg), BLANKAFTER, NOVIEW);
#endif

951
#ifndef DISABLE_HISTORIES
952
    add_to_funcs(get_history_older_void,
953
	(MWHEREIS|MREPLACE|MREPLACEWITH|MWHEREISFILE),
954
	N_("PrevHstory"), IFSCHELP(nano_prev_history_msg), TOGETHER, VIEW);
955
    add_to_funcs(get_history_newer_void,
956
	(MWHEREIS|MREPLACE|MREPLACEWITH|MWHEREISFILE),
957
958
959
	N_("NextHstory"), IFSCHELP(nano_next_history_msg), BLANKAFTER, VIEW);
#endif

960
#ifdef DISABLE_JUSTIFY
961
962
    add_to_funcs(do_gotolinecolumn_void, MWHEREIS,
	gotoline_tag, IFSCHELP(nano_gotoline_msg), BLANKAFTER, VIEW);
963
#endif
964

965
    add_to_funcs(gototext_void, MGOTOLINE,
966
	N_("Go To Text"), IFSCHELP(nano_whereis_msg), BLANKAFTER, VIEW);
967

968
#ifndef NANO_TINY
969
    add_to_funcs(dos_format_void, MWRITEFILE,
970
	N_("DOS Format"), IFSCHELP(nano_dos_msg), TOGETHER, NOVIEW);
971
    add_to_funcs(mac_format_void, MWRITEFILE,
972
973
974
975
976
977
	N_("Mac Format"), IFSCHELP(nano_mac_msg), 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. */
978
    if (!ISSET(RESTRICTED)) {
979
980
981
982
	add_to_funcs(append_void, MWRITEFILE,
	    N_("Append"), IFSCHELP(nano_append_msg), TOGETHER, NOVIEW);
	add_to_funcs(prepend_void, MWRITEFILE,
	    N_("Prepend"), IFSCHELP(nano_prepend_msg), TOGETHER, NOVIEW);
983

984
	add_to_funcs(backup_file_void, MWRITEFILE,
985
	    N_("Backup File"), IFSCHELP(nano_backup_msg), BLANKAFTER, NOVIEW);
986
    }
987

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

994
	add_to_funcs(flip_execute, MEXTCMD,
995
	    read_file_tag, IFSCHELP(nano_insert_msg), TOGETHER, NOVIEW);
996
997
    }
#endif /* !NANO_TINY */
998
#ifdef ENABLE_MULTIBUFFER
999
    if (!ISSET(RESTRICTED))
1000
	add_to_funcs(flip_newbuffer, MINSERTFILE|MEXTCMD,
1001
	    N_("New Buffer"), IFSCHELP(nano_newbuffer_msg), TOGETHER, NOVIEW);
1002
#endif
1003

1004
#ifdef ENABLE_BROWSER
1005
1006
    if (!ISSET(RESTRICTED))
	add_to_funcs(to_files_void, MWRITEFILE|MINSERTFILE,
1007
	    N_("To Files"), IFSCHELP(nano_tofiles_msg), TOGETHER, VIEW);
1008

1009
1010
1011
1012
1013
    add_to_funcs(do_page_up, MBROWSER,
	prev_page_tag, IFSCHELP(nano_prevpage_msg), TOGETHER, VIEW);
    add_to_funcs(do_page_down, MBROWSER,
	next_page_tag, IFSCHELP(nano_nextpage_msg), TOGETHER, VIEW);

Benno Schulenberg's avatar
Benno Schulenberg committed
1014
    add_to_funcs(do_first_file, (MBROWSER|MWHEREISFILE),
1015
	N_("First File"), IFSCHELP(nano_firstfile_msg), TOGETHER, VIEW);
Benno Schulenberg's avatar
Benno Schulenberg committed
1016
    add_to_funcs(do_last_file, (MBROWSER|MWHEREISFILE),
1017
	N_("Last File"), IFSCHELP(nano_lastfile_msg), BLANKAFTER, VIEW);
1018
#endif
Chris Allegretta's avatar
Chris Allegretta committed
1019

1020
1021
1022
    add_to_funcs(discard_buffer, MWRITEFILE,
	N_("Discard buffer"), IFSCHELP(nano_discard_buffer_msg), BLANKAFTER, NOVIEW);

1023
#ifdef ENABLE_BROWSER
1024
    add_to_funcs(do_research, MBROWSER,
1025
	whereis_next_tag, IFSCHELP(nano_whereis_next_msg), TOGETHER, VIEW);
1026
1027
    add_to_funcs(total_refresh, MBROWSER,
	refresh_tag, IFSCHELP(nano_browser_refresh_msg), BLANKAFTER, VIEW);
1028
#ifndef NANO_TINY
1029
1030
1031
    add_to_funcs(do_prev_word_void, MBROWSER,
	N_("Left Column"), IFSCHELP(nano_browser_lefthand_msg), TOGETHER, VIEW);
    add_to_funcs(do_next_word_void, MBROWSER,
1032
1033
1034
1035
1036
	N_("Right Column"), IFSCHELP(nano_browser_righthand_msg), TOGETHER, VIEW);
    add_to_funcs(do_prev_block, MBROWSER,
	N_("Top Row"), IFSCHELP(nano_browser_toprow_msg), TOGETHER, VIEW);
    add_to_funcs(do_next_block, MBROWSER,
	N_("Bottom Row"), IFSCHELP(nano_browser_bottomrow_msg), BLANKAFTER, VIEW);
1037
#endif
1038
#endif
1039
1040
1041

#ifndef DISABLE_COLOR
    add_to_funcs(do_page_up, MLINTER,
1042
	/* TRANSLATORS: Try to keep the next two strings at most 20 characters. */
1043
	N_("Prev Lint Msg"), IFSCHELP(nano_prevlint_msg), TOGETHER, VIEW);
1044
    add_to_funcs(do_page_down, MLINTER,
1045
	N_("Next Lint Msg"), IFSCHELP(nano_nextlint_msg), TOGETHER, VIEW);
1046
1047
#endif

Benno Schulenberg's avatar
Benno Schulenberg committed
1048
1049
    /* Start associating key combos with functions in specific menus. */

1050
1051
    add_to_sclist(MMOST & ~MFINDINHELP, "^G", 0, do_help_void, 0);
    add_to_sclist(MMOST & ~MFINDINHELP, "F1", 0, do_help_void, 0);
1052
1053
1054
1055
1056
1057
1058
    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, "^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);
1059
1060
    add_to_sclist(MMAIN|MHELP|MBROWSER, "^W", 0, do_search, 0);
    add_to_sclist(MMAIN|MHELP|MBROWSER, "F6", 0, do_search, 0);
1061
1062
1063
1064
1065
1066
1067
    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(MMAIN, "^U", 0, do_uncut_text, 0);
    add_to_sclist(MMAIN, "F10", 0, do_uncut_text, 0);
1068
#ifndef DISABLE_JUSTIFY
1069
1070
    add_to_sclist(MMAIN, "^J", 0, do_justify_void, 0);
    add_to_sclist(MMAIN, "F4", 0, do_justify_void, 0);
1071
#endif
1072
#ifndef DISABLE_SPELLER
1073
1074
    add_to_sclist(MMAIN, "^T", 0, do_spell, 0);
    add_to_sclist(MMAIN, "F12", 0, do_spell, 0);
1075
1076
#else
#ifndef DISABLE_COLOR
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
    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);
1089
    add_to_sclist(MHELP|MBROWSER, "Bsp", KEY_BACKSPACE, do_page_up, 0);
1090
1091
1092
1093
    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, do_first_line, 0);
1094
    add_to_sclist(MMAIN|MHELP, "^Home", CONTROL_HOME, do_first_line, 0);
1095
1096
    add_to_sclist(MMAIN|MHELP, "M-|", 0, do_first_line, 0);
    add_to_sclist(MMAIN|MHELP, "M-/", 0, do_last_line, 0);
1097
    add_to_sclist(MMAIN|MHELP, "^End", CONTROL_END, do_last_line, 0);
1098
    add_to_sclist(MMAIN|MHELP, "M-?", 0, do_last_line, 0);
1099
1100
    add_to_sclist(MMAIN|MHELP|MBROWSER, "M-W", 0, do_research, 0);
    add_to_sclist(MMAIN|MHELP|MBROWSER, "F16", 0, do_research, 0);
1101
#ifndef NANO_TINY
1102
1103
    add_to_sclist(MMAIN, "M-]", 0, do_find_bracket, 0);
    add_to_sclist(MMAIN, "M-A", 0, do_mark, 0);
1104
    add_to_sclist(MMAIN, "^6", 0, do_mark, 0);
1105
    add_to_sclist(MMAIN, "^^", 0, do_mark, 0);
1106
    add_to_sclist(MMAIN, "F15", 0, do_mark, 0);
1107
    add_to_sclist(MMAIN, "M-6", 0, do_copy_text, 0);
1108
    add_to_sclist(MMAIN, "M-^", 0, do_copy_text, 0);
1109
1110
    add_to_sclist(MMAIN, "M-}", 0, do_indent, 0);
    add_to_sclist(MMAIN, "M-{", 0, do_unindent, 0);
1111
1112
    add_to_sclist(MMAIN, "M-U", 0, do_undo, 0);
    add_to_sclist(MMAIN, "M-E", 0, do_redo, 0);
1113
1114
#endif
#ifdef ENABLE_WORDCOMPLETION
1115
    add_to_sclist(MMAIN, "^]", 0, complete_a_word, 0);
1116
1117
#endif
#ifdef ENABLE_COMMENT
1118
    add_to_sclist(MMAIN, "M-3", 0, do_comment, 0);
1119
#endif
1120
1121
    add_to_sclist(MMOST, "^B", 0, do_left, 0);
    add_to_sclist(MMOST, "^F", 0, do_right, 0);
1122
#ifdef ENABLE_UTF8
1123
    if (using_utf8()) {
1124
1125
	add_to_sclist(MMOST, "\xE2\x86\x90", KEY_LEFT, do_left, 0);
	add_to_sclist(MMOST, "\xE2\x86\x92", KEY_RIGHT, do_right, 0);
1126
1127
	add_to_sclist(MSOME, "^\xE2\x86\x90", CONTROL_LEFT, do_prev_word_void, 0);
	add_to_sclist(MSOME, "^\xE2\x86\x92", CONTROL_RIGHT, do_next_word_void, 0);
1128
1129
1130
    } else
#endif
    {
1131
1132
	add_to_sclist(MMOST, "Left", KEY_LEFT, do_left, 0);
	add_to_sclist(MMOST, "Right", KEY_RIGHT, do_right, 0);
1133
1134
	add_to_sclist(MSOME, "^Left", CONTROL_LEFT, do_prev_word_void, 0);
	add_to_sclist(MSOME, "^Right", CONTROL_RIGHT, do_next_word_void, 0);
1135
    }
1136
1137
    add_to_sclist(MMOST, "M-Space", 0, do_prev_word_void, 0);
    add_to_sclist(MMOST, "^Space", 0, do_next_word_void, 0);
1138
1139
1140
1141
    add_to_sclist((MMOST & ~MBROWSER), "^A", 0, do_home_void, 0);
    add_to_sclist((MMOST & ~MBROWSER), "Home", KEY_HOME, do_home_void, 0);
    add_to_sclist((MMOST & ~MBROWSER), "^E", 0, do_end_void, 0);
    add_to_sclist((MMOST & ~MBROWSER), "End", KEY_END, do_end_void, 0);
1142
1143
    add_to_sclist(MMAIN|MHELP|MBROWSER, "^P", 0, do_up_void, 0);
    add_to_sclist(MMAIN|MHELP|MBROWSER, "^N", 0, do_down_void, 0);
1144
#ifdef ENABLE_UTF8
1145
    if (using_utf8()) {
1146
1147
	add_to_sclist(MMAIN|MHELP|MBROWSER, "\xE2\x86\x91", KEY_UP, do_up_void, 0);
	add_to_sclist(MMAIN|MHELP|MBROWSER, "\xE2\x86\x93", KEY_DOWN, do_down_void, 0);
1148
1149
	add_to_sclist(MMAIN|MBROWSER, "^\xE2\x86\x91", CONTROL_UP, do_prev_block, 0);
	add_to_sclist(MMAIN|MBROWSER, "^\xE2\x86\x93", CONTROL_DOWN, do_next_block, 0);
1150
1151
1152
    } else
#endif
    {
1153
1154
	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);
1155
1156
	add_to_sclist(MMAIN|MBROWSER, "^Up", CONTROL_UP, do_prev_block, 0);
	add_to_sclist(MMAIN|MBROWSER, "^Down", CONTROL_DOWN, do_next_block, 0);
1157
    }
1158
1159
    add_to_sclist(MMAIN, "M-7", 0, do_prev_block, 0);
    add_to_sclist(MMAIN, "M-8", 0, do_next_block, 0);
1160
#ifndef DISABLE_JUSTIFY
1161
1162
1163
1164
    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
1165
#endif
1166
#ifndef NANO_TINY
1167
1168
1169
1170
    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);
1171
#endif
1172
#ifdef ENABLE_MULTIBUFFER
1173
1174
1175
1176
    add_to_sclist(MMAIN, "M-<", 0, switch_to_prev_buffer_void, 0);
    add_to_sclist(MMAIN, "M-,", 0, switch_to_prev_buffer_void, 0);
    add_to_sclist(MMAIN, "M->", 0, switch_to_next_buffer_void, 0);
    add_to_sclist(MMAIN, "M-.", 0, switch_to_next_buffer_void, 0);
1177
#endif
1178
    add_to_sclist(MMOST, "M-V", 0, do_verbatim_input, 0);
1179
#ifndef NANO_TINY
1180
1181
    add_to_sclist(MMAIN, "M-T", 0, do_cut_till_eof, 0);
    add_to_sclist(MMAIN, "M-D", 0, do_wordlinechar_count, 0);
1182
#endif
1183
#ifndef DISABLE_JUSTIFY
1184
    add_to_sclist(MMAIN|MWHEREIS, "M-J", 0, do_full_justify, 0);
1185
#endif
1186
1187
    add_to_sclist(MMAIN|MHELP, "^L", 0, total_refresh, 0);
    add_to_sclist(MMAIN, "^Z", 0, do_suspend_void, 0);
1188

1189
#ifndef NANO_TINY
1190
    /* Group of "Appearance" toggles. */
1191
    add_to_sclist(MMAIN, "M-X", 0, do_toggle_void, NO_HELP);
1192
    add_to_sclist(MMAIN, "M-C", 0, do_toggle_void, CONSTANT_SHOW);
1193
1194
1195
    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);
1196
1197
1198
#ifdef ENABLE_LINENUMBERS
    add_to_sclist(MMAIN, "M-#", 0, do_toggle_void, LINE_NUMBERS);
#endif
1199
    add_to_sclist(MMAIN, "M-P", 0, do_toggle_void, WHITESPACE_DISPLAY);
1200
#ifndef DISABLE_COLOR
1201
    add_to_sclist(MMAIN, "M-Y", 0, do_toggle_void, NO_COLOR_SYNTAX);
1202
#endif
1203

1204
    /* Group of "Editing-behavior" toggles. */
1205
1206
1207
    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_TO_END);
1208
#ifndef DISABLE_WRAPPING
1209
    add_to_sclist(MMAIN, "M-L", 0, do_toggle_void, NO_WRAP);
1210
#endif
1211
    add_to_sclist(MMAIN, "M-Q", 0, do_toggle_void, TABS_TO_SPACES);
1212

1213
    /* Group of "Peripheral-feature" toggles. */
1214
    add_to_sclist(MMAIN, "M-B", 0, do_toggle_void, BACKUP_FILE);
1215
#ifdef ENABLE_MULTIBUFFER
1216
    add_to_sclist(MMAIN, "M-F", 0, do_toggle_void, MULTIBUFFER);
1217
#endif
1218
#ifdef ENABLE_MOUSE
1219
    add_to_sclist(MMAIN, "M-M", 0, do_toggle_void, USE_MOUSE);
1220
#endif
1221
1222
    add_to_sclist(MMAIN, "M-N", 0, do_toggle_void, NO_CONVERT);
    add_to_sclist(MMAIN, "M-Z", 0, do_toggle_void, SUSPEND);
1223
#endif /* !NANO_TINY */
Benno Schulenberg's avatar
Benno Schulenberg committed
1224

1225
1226
    add_to_sclist(MMAIN, "^Q", 0, xon_complaint, 0);
    add_to_sclist(MMAIN, "^S", 0, xoff_complaint, 0);
1227

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

1230
1231
1232
    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);
1233
    add_to_sclist(MWHEREIS|MREPLACE, "^R", 0, flip_replace, 0);
1234
1235
    add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH|MGOTOLINE, "^Y", 0, do_first_line, 0);
    add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH|MGOTOLINE, "^V", 0, do_last_line, 0);
1236
#ifndef DISABLE_JUSTIFY
1237
1238
    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);
1239
#endif
1240
1241
    add_to_sclist(MWHEREIS, "^T", 0, do_gotolinecolumn_void, 0);
    add_to_sclist(MGOTOLINE, "^T", 0, gototext_void, 0);
1242
#ifndef DISABLE_HISTORIES
1243
1244
    add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH|MWHEREISFILE|MFINDINHELP, "^P", 0, get_history_older_void, 0);
    add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH|MWHEREISFILE|MFINDINHELP, "^N", 0, get_history_newer_void, 0);
1245
1246
#ifdef ENABLE_UTF8
    if (using_utf8()) {
1247
1248
	add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH|MWHEREISFILE|MFINDINHELP, "\xE2\x86\x91", KEY_UP, get_history_older_void, 0);
	add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH|MWHEREISFILE|MFINDINHELP, "\xE2\x86\x93", KEY_DOWN, get_history_newer_void, 0);
1249
1250
1251
    } else
#endif
    {
1252
1253
	add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH|MWHEREISFILE|MFINDINHELP, "Up", KEY_UP, get_history_older_void, 0);
	add_to_sclist(MWHEREIS|MREPLACE|MREPLACEWITH|MWHEREISFILE|MFINDINHELP, "Down", KEY_DOWN, get_history_newer_void, 0);
1254
    }
1255
#endif
1256
#ifdef ENABLE_BROWSER
1257
1258
1259
1260
1261
1262
    add_to_sclist(MWHEREISFILE, "^Y", 0, do_first_file, 0);
    add_to_sclist(MWHEREISFILE, "^V", 0, do_last_file, 0);
    add_to_sclist(MBROWSER|MWHEREISFILE, "M-\\", 0, do_first_file, 0);
    add_to_sclist(MBROWSER|MWHEREISFILE, "M-/", 0, do_last_file, 0);
    add_to_sclist(MBROWSER, "Home", KEY_HOME, do_first_file, 0);
    add_to_sclist(MBROWSER, "End", KEY_END, do_last_file, 0);
1263
1264
    add_to_sclist(MBROWSER|MWHEREISFILE, "M-|", 0, do_first_file, 0);
    add_to_sclist(MBROWSER|MWHEREISFILE, "M-?", 0, do_last_file, 0);
1265
    add_to_sclist(MBROWSER, "^Home", CONTROL_HOME, do_first_file, 0);
1266
    add_to_sclist(MBROWSER, "^End", CONTROL_END, do_last_file, 0);
1267
1268
1269
1270
    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);
    add_to_sclist(MBROWSER, "^L", 0, total_refresh, 0);
1271
#endif
1272
    if (ISSET(TEMP_FILE))
1273
	add_to_sclist(MWRITEFILE, "^Q", 0, discard_buffer, 0);
1274
#ifndef NANO_TINY
1275
1276
    add_to_sclist(MWRITEFILE, "M-D", 0, dos_format_void, 0);
    add_to_sclist(MWRITEFILE, "M-M", 0, mac_format_void, 0);
1277
1278
    /* In restricted mode, don't allow Appending, Prepending, nor making
     * backups, nor executing a command, nor opening a new buffer. */
1279
    if (!ISSET(RESTRICTED)) {
1280
1281
1282
	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);
1283
	add_to_sclist(MINSERTFILE|MEXTCMD, "^X", 0, flip_execute, 0);
1284
    }
1285
#endif
1286
1287
#ifdef ENABLE_MULTIBUFFER
    if (!ISSET(RESTRICTED))
1288
	add_to_sclist(MINSERTFILE|MEXTCMD, "M-F", 0, flip_newbuffer, 0);
1289
#endif
1290
#ifdef ENABLE_BROWSER
1291
1292
1293
1294
    /* In restricted mode, don't allow entering the file browser. */
    if (!ISSET(RESTRICTED))
	add_to_sclist(MWRITEFILE|MINSERTFILE, "^T", 0, to_files_void, 0);
#endif
1295
    add_to_sclist(MHELP|MBROWSER, "^C", 0, do_exit, 0);
1296
1297
    /* Allow exiting from the file browser and the help viewer with
     * the same key as they were entered. */
1298
#ifdef ENABLE_BROWSER
1299
    add_to_sclist(MBROWSER, "^T", 0, do_exit, 0);
1300
#endif
1301
#ifdef ENABLE_HELP
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
    add_to_sclist(MHELP, "^G", 0, do_exit, 0);
    add_to_sclist(MHELP, "Home", KEY_HOME, do_first_line, 0);
    add_to_sclist(MHELP, "End", KEY_END, do_last_line, 0);
#endif
    add_to_sclist(MMOST, "^I", 0, do_tab, 0);
    add_to_sclist(MMOST, "Tab", TAB_CODE, do_tab, 0);
    add_to_sclist(MMOST, "^M", 0, do_enter, 0);
    add_to_sclist(MMOST, "Enter", KEY_ENTER, do_enter, 0);
    add_to_sclist(MMOST, "^D", 0, do_delete, 0);
    add_to_sclist(MMOST, "Del", 0, do_delete, 0);
    add_to_sclist(MMOST, "^H", 0, do_backspace, 0);
    add_to_sclist(MMOST, "Bsp", KEY_BACKSPACE, do_backspace, 0);
Chris Allegretta's avatar
Chris Allegretta committed
1314

1315
1316
#ifdef DEBUG
    print_sclist();
Chris Allegretta's avatar
Chris Allegretta committed
1317
#endif
1318
}
1319

1320
#ifndef DISABLE_COLOR
1321
void set_lint_or_format_shortcuts(void)
1322
1323
{
#ifndef DISABLE_SPELLER
1324
1325
1326
1327
1328
1329
1330
    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);
    }
1331
1332
1333
1334
1335
1336
#endif
}

void set_spell_shortcuts(void)
{
#ifndef DISABLE_SPELLER
1337
1338
	replace_scs_for(do_formatter, do_spell);
	replace_scs_for(do_linter, do_spell);
1339
1340
#endif
}
1341
#endif /* !DISABLE_COLOR */
1342

1343
const subnfunc *sctofunc(const sc *s)
1344
{
1345
    subnfunc *f = allfuncs;
1346

1347
1348
    while (f != NULL && f->scfunc != s->scfunc)
	f = f->next;
1349

1350
    return f;
1351
1352
}

1353
#ifndef NANO_TINY
1354
1355
/* Now let's come up with a single (hopefully) function to get a string
 * for each flag. */
1356
const char *flagtostr(int flag)
1357
{
1358
    switch (flag) {
1359
1360
1361
1362
	case NO_HELP:
	    /* TRANSLATORS: The next seventeen strings are toggle descriptions;
	     * they are best kept shorter than 40 characters, but may be longer. */
	    return N_("Help mode");
1363
	case CONSTANT_SHOW:
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
	    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_TO_END:
	    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:
1388
	    return N_("Reading file into separate buffer");
1389
1390
1391
1392
1393
1394
	case USE_MOUSE:
	    return N_("Mouse support");
	case NO_CONVERT:
	    return N_("No conversion from DOS/Mac format");
	case SUSPEND:
	    return N_("Suspension");
1395
1396
	case LINE_NUMBERS:
	    return N_("Line numbering");
1397
1398
	default:
	    return "?????";
1399
1400
    }
}
1401
#endif /* !NANO_TINY */
1402

1403
#ifdef ENABLE_NANORC
1404
/* Interpret a function string given in the rc file, and return a
1405
 * shortcut struct with the corresponding function filled in. */
1406
sc *strtosc(const char *input)
1407
{
1408
    sc *s = nmalloc(sizeof(sc));
1409

1410
#ifndef NANO_TINY
1411
    s->toggle = 0;
1412
#endif
1413

1414
#ifdef ENABLE_HELP
1415
    if (!strcasecmp(input, "help"))
1416
1417
	s->scfunc = do_help_void;
    else
Chris Allegretta's avatar
Chris Allegretta committed
1418
#endif
1419
    if (!strcasecmp(input, "cancel"))
1420
	s->scfunc = do_cancel;
1421
    else if (!strcasecmp(input, "exit"))
1422
	s->scfunc = do_exit;
1423
1424
    else if (!strcasecmp(input, "discardbuffer"))
	s->scfunc = discard_buffer;
1425
    else if (!strcasecmp(input, "writeout"))
1426
	s->scfunc = do_writeout_void;
1427
1428
1429
1430
#ifndef NANO_TINY
    else if (!strcasecmp(input, "savefile"))
	s->scfunc = do_savefile;
#endif
1431
    else if (!strcasecmp(input, "insert"))
1432
	s->scfunc = do_insertfile_void;
1433
    else if (!strcasecmp(input, "whereis"))
1434
	s->scfunc = do_search;
1435
    else if (!strcasecmp(input, "searchagain") ||
1436
	     !strcasecmp(input, "research"))  /* Deprecated.  Remove in 2018. */
1437
	s->scfunc = do_research;
1438
#ifndef NANO_TINY
1439
1440
1441
1442
    else if (!strcasecmp(input, "findprevious"))
	s->scfunc = do_findprevious;
    else if (!strcasecmp(input, "findnext"))
	s->scfunc = do_findnext;
1443
#endif
1444
1445
    else if (!strcasecmp(input, "replace"))
	s->scfunc = do_replace;
1446
    else if (!strcasecmp(input, "cut"))
1447
	s->scfunc = do_cut_text_void;
1448
    else if (!strcasecmp(input, "uncut"))
1449
	s->scfunc = do_uncut_text;
1450
#ifndef NANO_TINY
1451
    else if (!strcasecmp(input, "cutrestoffile"))
1452
	s->scfunc = do_cut_till_eof;
1453
1454
    else if (!strcasecmp(input, "copytext"))
	s->scfunc = do_copy_text;
1455
1456
    else if (!strcasecmp(input, "mark"))
	s->scfunc = do_mark;
1457
1458
#endif
#ifndef DISABLE_SPELLER
1459
1460
1461
    else if (!strcasecmp(input, "tospell") ||
	     !strcasecmp(input, "speller"))
	s->scfunc = do_spell;
1462
#endif
1463
#ifndef DISABLE_COLOR
1464
1465
    else if (!strcasecmp(input, "linter"))
	s->scfunc = do_linter;
1466
#endif
1467
    else if (!strcasecmp(input, "curpos") ||
1468
	     !strcasecmp(input, "cursorpos"))  /* Deprecated.  Remove in 2018. */
1469
	s->scfunc = do_cursorpos_void;
1470
    else if (!strcasecmp(input, "gotoline"))
1471
	s->scfunc = do_gotolinecolumn_void;
1472
#ifndef DISABLE_JUSTIFY
Chris Allegretta's avatar
Chris Allegretta committed
1473
    else if (!strcasecmp(input, "justify"))
1474
	s->scfunc = do_justify_void;
1475
1476
    else if (!strcasecmp(input, "fulljustify"))
	s->scfunc = do_full_justify;
1477
    else if (!strcasecmp(input, "beginpara"))
1478
	s->scfunc = do_para_begin_void;
1479
    else if (!strcasecmp(input, "endpara"))
1480
	s->scfunc = do_para_end_void;
1481
#endif
1482
1483
1484
1485
#ifdef ENABLE_COMMENT
    else if (!strcasecmp(input, "comment"))
	s->scfunc = do_comment;
#endif
1486
1487
1488
1489
#ifdef ENABLE_WORDCOMPLETION
    else if (!strcasecmp(input, "complete"))
	s->scfunc = complete_a_word;
#endif
1490
#ifndef NANO_TINY
1491
    else if (!strcasecmp(input, "indent"))
1492
	s->scfunc = do_indent;
1493
    else if (!strcasecmp(input, "unindent"))
1494
	s->scfunc = do_unindent;
Chris Allegretta's avatar
Chris Allegretta committed
1495
    else if (!strcasecmp(input, "scrollup"))
1496
	s->scfunc = do_scroll_up;
Chris Allegretta's avatar
Chris Allegretta committed
1497
    else if (!strcasecmp(input, "scrolldown"))
1498
	s->scfunc = do_scroll_down;
1499
1500
1501
1502
    else if (!strcasecmp(input, "cutwordleft"))
	s->scfunc = do_cut_prev_word;
    else if (!strcasecmp(input, "cutwordright"))
	s->scfunc = do_cut_next_word;
1503
    else if (!strcasecmp(input, "findbracket"))
1504
	s->scfunc = do_find_bracket;
1505
    else if (!strcasecmp(input, "wordcount"))
1506
	s->scfunc = do_wordlinechar_count;
1507
    else if (!strcasecmp(input, "undo"))
1508
	s->scfunc = do_undo;
1509
    else if (!strcasecmp(input, "redo"))
1510
	s->scfunc = do_redo;
1511
#endif
Chris Allegretta's avatar
Chris Allegretta committed
1512
    else if (!strcasecmp(input, "left") ||
1513
	     !strcasecmp(input, "back"))
1514
	s->scfunc = do_left;
1515
1516
1517
    else if (!strcasecmp(input, "right") ||
	     !strcasecmp(input, "forward"))
	s->scfunc = do_right;
Chris Allegretta's avatar
Chris Allegretta committed
1518
    else if (!strcasecmp(input, "up") ||
1519
	     !strcasecmp(input, "prevline"))
1520
	s->scfunc = do_up_void;
Chris Allegretta's avatar
Chris Allegretta committed
1521
    else if (!strcasecmp(input, "down") ||
1522
	     !strcasecmp(input, "nextline"))
1523
	s->scfunc = do_down_void;
1524
1525
1526
1527
    else if (!strcasecmp(input, "prevword"))
	s->scfunc = do_prev_word_void;
    else if (!strcasecmp(input, "nextword"))
	s->scfunc = do_next_word_void;
Chris Allegretta's avatar
Chris Allegretta committed
1528
    else if (!strcasecmp(input, "home"))
1529
	s->scfunc = do_home_void;
Chris Allegretta's avatar
Chris Allegretta committed
1530
    else if (!strcasecmp(input, "end"))
1531
	s->scfunc = do_end_void;
1532
1533
1534
1535
    else if (!strcasecmp(input, "prevblock"))
	s->scfunc = do_prev_block;
    else if (!strcasecmp(input, "nextblock"))
	s->scfunc = do_next_block;
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
    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 = do_first_line;
    else if (!strcasecmp(input, "lastline"))
	s->scfunc = do_last_line;
1546
#ifdef ENABLE_MULTIBUFFER
Chris Allegretta's avatar
Chris Allegretta committed
1547
    else if (!strcasecmp(input, "prevbuf"))
1548
	s->scfunc = switch_to_prev_buffer_void;
Chris Allegretta's avatar
Chris Allegretta committed
1549
    else if (!strcasecmp(input, "nextbuf"))
1550
	s->scfunc = switch_to_next_buffer_void;
Chris Allegretta's avatar
Chris Allegretta committed
1551
1552
#endif
    else if (!strcasecmp(input, "verbatim"))
1553
	s->scfunc = do_verbatim_input;
Chris Allegretta's avatar
Chris Allegretta committed
1554
    else if (!strcasecmp(input, "tab"))
1555
	s->scfunc = do_tab;
Chris Allegretta's avatar
Chris Allegretta committed
1556
    else if (!strcasecmp(input, "enter"))
1557
	s->scfunc = do_enter;
Chris Allegretta's avatar
Chris Allegretta committed
1558
    else if (!strcasecmp(input, "delete"))
1559
	s->scfunc = do_delete;
1560
    else if (!strcasecmp(input, "backspace"))
1561
	s->scfunc = do_backspace;
Chris Allegretta's avatar
Chris Allegretta committed
1562
    else if (!strcasecmp(input, "refresh"))
1563
	s->scfunc = total_refresh;
1564
1565
    else if (!strcasecmp(input, "suspend"))
	s->scfunc = do_suspend_void;
1566
    else if (!strcasecmp(input, "casesens"))
1567
	s->scfunc = case_sens_void;
1568
    else if (!strcasecmp(input, "regexp") ||
1569
	     !strcasecmp(input, "regex"))  /* Deprecated.  Remove in 2018. */
1570
	s->scfunc = regexp_void;
1571
    else if (!strcasecmp(input, "backwards"))
1572
	s->scfunc = backwards_void;
1573
    else if (!strcasecmp(input, "flipreplace") ||
1574
	     !strcasecmp(input, "dontreplace"))  /* Deprecated.  Remove in 2018. */
1575
	s->scfunc = flip_replace;
1576
    else if (!strcasecmp(input, "gototext"))
1577
	s->scfunc = gototext_void;
1578
1579
1580
1581
1582
1583
#ifndef DISABLE_HISTORIES
    else if (!strcasecmp(input, "prevhistory"))
	s->scfunc = get_history_older_void;
    else if (!strcasecmp(input, "nexthistory"))
	s->scfunc = get_history_newer_void;
#endif
1584
#ifndef NANO_TINY
1585
    else if (!strcasecmp(input, "dosformat"))
1586
	s->scfunc = dos_format_void;
1587
    else if (!strcasecmp(input, "macformat"))
1588
	s->scfunc = mac_format_void;
1589
    else if (!strcasecmp(input, "append"))
1590
	s->scfunc = append_void;
1591
    else if (!strcasecmp(input, "prepend"))
1592
	s->scfunc = prepend_void;
1593
    else if (!strcasecmp(input, "backup"))
1594
	s->scfunc = backup_file_void;
1595
    else if (!strcasecmp(input, "flipexecute"))
1596
	s->scfunc = flip_execute;
1597
#endif
1598
#ifdef ENABLE_MULTIBUFFER
1599
    else if (!strcasecmp(input, "flipnewbuffer") ||
1600
	     !strcasecmp(input, "newbuffer"))  /* Deprecated.  Remove in 2018. */
1601
	s->scfunc = flip_newbuffer;
Chris Allegretta's avatar
Chris Allegretta committed
1602
#endif
1603
#ifdef ENABLE_BROWSER
1604
1605
    else if (!strcasecmp(input, "tofiles") ||
	     !strcasecmp(input, "browser"))
1606
	s->scfunc = to_files_void;
1607
    else if (!strcasecmp(input, "gotodir"))
1608
	s->scfunc = goto_dir_void;
1609
    else if (!strcasecmp(input, "firstfile"))
1610
	s->scfunc = do_first_file;
1611
    else if (!strcasecmp(input, "lastfile"))
1612
1613
	s->scfunc = do_last_file;
#endif
1614
    else {
1615
#ifndef NANO_TINY
1616
	s->scfunc = do_toggle_void;
1617
	if (!strcasecmp(input, "nohelp"))
1618
	    s->toggle = NO_HELP;
1619
	else if (!strcasecmp(input, "constupdate"))
1620
	    s->toggle = CONSTANT_SHOW;
1621
	else if (!strcasecmp(input, "morespace"))
1622
	    s->toggle = MORE_SPACE;
1623
	else if (!strcasecmp(input, "smoothscroll"))
1624
	    s->toggle = SMOOTH_SCROLL;
1625
	else if (!strcasecmp(input, "softwrap"))
1626
	    s->toggle = SOFTWRAP;
1627
	else if (!strcasecmp(input, "whitespacedisplay"))
1628
	    s->toggle = WHITESPACE_DISPLAY;
1629
#ifndef DISABLE_COLOR
1630
	else if (!strcasecmp(input, "nosyntax"))
1631
1632
	    s->toggle = NO_COLOR_SYNTAX;
#endif
1633
	else if (!strcasecmp(input, "smarthome"))
1634
	    s->toggle = SMART_HOME;
1635
	else if (!strcasecmp(input, "autoindent"))
1636
	    s->toggle = AUTOINDENT;
1637
	else if (!strcasecmp(input, "cuttoend"))
1638
	    s->toggle = CUT_TO_END;
1639
#ifndef DISABLE_WRAPPING
1640
	else if (!strcasecmp(input, "nowrap"))
1641
	    s->toggle = NO_WRAP;
1642
#endif
1643
	else if (!strcasecmp(input, "tabstospaces"))
1644
	    s->toggle = TABS_TO_SPACES;
1645
	else if (!strcasecmp(input, "backupfile"))
1646
	    s->toggle = BACKUP_FILE;
1647
#ifdef ENABLE_MULTIBUFFER
1648
	else if (!strcasecmp(input, "multibuffer"))
1649
	    s->toggle = MULTIBUFFER;
1650
#endif
1651
#ifdef ENABLE_MOUSE
1652
	else if (!strcasecmp(input, "mouse"))
1653
	    s->toggle = USE_MOUSE;
1654
#endif
1655
	else if (!strcasecmp(input, "noconvert"))
1656
	    s->toggle = NO_CONVERT;
1657
	else if (!strcasecmp(input, "suspendenable"))
1658
	    s->toggle = SUSPEND;
1659
	else
1660
#endif /* !NANO_TINY */
1661
	{
1662
1663
1664
	    free(s);
	    return NULL;
	}
1665
1666
1667
    }
    return s;
}
1668

1669
/* Interpret a menu name and return the corresponding menu flag. */
1670
int strtomenu(const char *input)
1671
1672
{
    if (!strcasecmp(input, "all"))
1673
	return (MMOST|MHELP|MYESNO);
1674
1675
1676
1677
1678
1679
    else if (!strcasecmp(input, "main"))
	return MMAIN;
    else if (!strcasecmp(input, "search"))
	return MWHEREIS;
    else if (!strcasecmp(input, "replace"))
	return MREPLACE;
1680
    else if (!strcasecmp(input, "replace2") ||  /* Deprecated.  Remove in 2018. */
Benno Schulenberg's avatar
Benno Schulenberg committed
1681
	     !strcasecmp(input, "replacewith"))
1682
	return MREPLACEWITH;
1683
1684
1685
1686
1687
1688
1689
    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") ||
Benno Schulenberg's avatar
Benno Schulenberg committed
1690
	     !strcasecmp(input, "extcmd"))
1691
	return MEXTCMD;
1692
#ifdef ENABLE_HELP
1693
1694
    else if (!strcasecmp(input, "help"))
	return MHELP;
1695
1696
#endif
#ifndef DISABLE_SPELLER
1697
    else if (!strcasecmp(input, "spell"))
1698
	return MSPELL;
1699
#endif
1700
1701
    else if (!strcasecmp(input, "linter"))
	return MLINTER;
1702
#ifdef ENABLE_BROWSER
1703
1704
1705
1706
1707
1708
    else if (!strcasecmp(input, "browser"))
	return MBROWSER;
    else if (!strcasecmp(input, "whereisfile"))
	return MWHEREISFILE;
    else if (!strcasecmp(input, "gotodir"))
	return MGOTODIR;
1709
#endif
1710
1711
    return -1;
}
1712
#endif /* ENABLE_NANORC */
1713

Chris Allegretta's avatar
Chris Allegretta committed
1714

1715
1716
1717
#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
1718
1719
 * 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
1720
1721
 * function unless debugging is turned on. */
void thanks_for_all_the_fish(void)
1722
{
1723
1724
    if (topwin != NULL)
	delwin(topwin);
1725
1726
1727
    delwin(edit);
    delwin(bottomwin);

1728
    free(word_chars);
Chris Allegretta's avatar
Chris Allegretta committed
1729
#ifndef DISABLE_JUSTIFY
1730
    free(quotestr);
1731
    regfree(&quotereg);
1732
    free(quoteerr);
1733
#endif
1734
#ifndef NANO_TINY
1735
    free(backup_dir);
1736
#endif
Chris Allegretta's avatar
Chris Allegretta committed
1737
#ifndef DISABLE_OPERATINGDIR
1738
1739
    free(operating_dir);
    free(full_operating_dir);
1740
#endif
1741
    free(answer);
1742
    free(last_search);
1743
    free(present_path);
1744
#ifndef DISABLE_SPELLER
1745
    free(alt_speller);
1746
#endif
1747
    free_filestruct(cutbuffer);
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
1748
    /* Free the memory associated with each open file buffer. */
1749
1750
1751
1752
1753
    while (openfile != openfile->next) {
	openfile = openfile->next;
	delete_opennode(openfile->prev);
    }
    delete_opennode(openfile);
1754
#ifndef DISABLE_COLOR
1755
    free(syntaxstr);
Chris Allegretta's avatar
Chris Allegretta committed
1756
    while (syntaxes != NULL) {
1757
1758
	syntaxtype *sint = syntaxes;
	syntaxes = syntaxes->next;
Chris Allegretta's avatar
Chris Allegretta committed
1759

1760
1761
1762
	free(sint->name);
	free(sint->linter);
	free(sint->formatter);
1763

1764
1765
1766
1767
1768
	while (sint->extensions != NULL) {
	    regexlisttype *item = sint->extensions;
	    sint->extensions = sint->extensions->next;
	    free(item->full_regex);
	    free(item);
Chris Allegretta's avatar
Chris Allegretta committed
1769
	}
1770
1771
1772
1773
1774
	while (sint->headers != NULL) {
	    regexlisttype *item = sint->headers;
	    sint->headers = sint->headers->next;
	    free(item->full_regex);
	    free(item);
1775
	}
1776
1777
1778
1779
1780
	while (sint->magics != NULL) {
	    regexlisttype *item = sint->magics;
	    sint->magics = sint->magics->next;
	    free(item->full_regex);
	    free(item);
1781
	}
1782

1783
1784
1785
1786
1787
1788
1789
	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);
1790
	    }
1791
1792
1793
1794
	    free(ink->end_regex);
	    if (ink->end != NULL) {
		regfree(ink->end);
		free(ink->end);
1795
	    }
1796
	    free(ink);
Chris Allegretta's avatar
Chris Allegretta committed
1797
	}
1798
1799

	free(sint);
Chris Allegretta's avatar
Chris Allegretta committed
1800
    }
1801
#endif /* !DISABLE_COLOR */
1802
#ifndef DISABLE_HISTORIES
1803
    /* Free the search and replace history lists. */
1804
1805
    free_filestruct(searchage);
    free_filestruct(replaceage);
1806
#endif
1807
    /* Free the list of functions. */
1808
    while (allfuncs != NULL) {
1809
1810
1811
	subnfunc *f = allfuncs;
	allfuncs = allfuncs->next;
	free(f);
1812
    }
1813
    /* Free the list of shortcuts. */
1814
    while (sclist != NULL) {
1815
1816
1817
	sc *s = sclist;
	sclist = sclist->next;
	free(s);
1818
    }
1819
#ifdef ENABLE_NANORC
1820
    free(homedir);
1821
#endif
1822
}
1823
#endif /* DEBUG */