global.c 63 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
#include <strings.h>
Chris Allegretta's avatar
Chris Allegretta committed
27

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

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

39
40
bool meta_key;
	/* Whether the current keystroke is a Meta key. */
41
42
bool shift_held;
	/* 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
47
48
bool as_an_at = TRUE;
	/* Whether a 0x0A byte should be shown as a ^@ instead of a ^J. */

49
50
51
52
53
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. */

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

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

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

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

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

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

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
#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
char *operating_dir = NULL;
169
	/* The path to our confining "operating" directory, when given. */
170
171
#endif

172
#ifndef DISABLE_SPELLER
173
174
char *alt_speller = NULL;
	/* The command to use for the alternate spell checker. */
175
176
#endif

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

184
185
186
bool refresh_needed = FALSE;
	/* Did a command mangle enough of the buffer that we should
	 * repaint the screen? */
187

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

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

218
219
220
221
222
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. */
223

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

233
char *homedir = NULL;
234
	/* The user's home directory, from $HOME or /etc/passwd. */
235

236

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

243
    for (f = allfuncs; f != NULL; f = f->next)
244
	if ((f->menus & menu) && first_sc_for(menu, f->scfunc) != NULL)
245
	    i++;
246

247
248
249
    return i;
}

250
251
252
253
254
255
/* 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

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

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

    if (allfuncs == NULL)
	allfuncs = f;
    else
	tailfunc->next = f;
    tailfunc = f;
320
321
322
323
324
325

    f->next = NULL;
    f->scfunc = func;
    f->menus = menus;
    f->desc = desc;
    f->viewok = viewok;
326
#ifdef ENABLE_HELP
327
328
329
330
331
    f->help = help;
    f->blank_after = blank_after;
#endif

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

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

346
347
348
349
350
351
352
353
354
    /* 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. */
355
    s->menus = menus;
356
    s->scfunc = func;
357
#ifndef NANO_TINY
358
    s->toggle = toggle;
359
360
    if (toggle)
	s->ordinal = ++counter;
361
#endif
362
    assign_keyinfo(s, scstring, keycode);
363
364

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

369
/* Assign one function's shortcuts to another function. */
370
371
372
373
void replace_scs_for(void (*oldfunc)(void), void (*newfunc)(void))
{
    sc *s;

374
    for (s = sclist; s != NULL; s = s->next)
375
	if (s->scfunc == oldfunc)
376
377
378
	    s->scfunc = newfunc;
}

379
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))
{
    const sc *s;

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

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

396
397
398
/* 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
399
400
401
{
    const sc *s = first_sc_for(currmenu, func);

402
403
404
405
406
    if (s == NULL)
	return defaultval;

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

409
410
411
412
413
414
415
416
417
418
419
/* 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;
}

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

426
427
    assert(strlen(keystring) > 1 && (!s->meta || strlen(keystring) > 2));

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

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

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

471
    for (s = sclist; s != NULL; s = s->next) {
472
	f = sctofunc(s);
473
	if (f)
474
	    fprintf(stderr, "Shortcut \"%s\", function: %s, menus %x\n", s->keystr, f->desc, f->menus);
475
	else
476
	    fprintf(stderr, "Hmm, didn't find a func for \"%s\"\n", s->keystr);
477
478
479
480
    }
}
#endif

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

490
491
/* Initialize the list of functions and the list of shortcuts. */
void shortcut_init(void)
492
{
493
    const char *read_file_tag = N_("Read File");
494
    const char *whereis_tag = N_("Where Is");
495
496
    const char *replace_tag = N_("Replace");
    const char *gotoline_tag = N_("Go To Line");
497
498
    const char *prev_line_tag = N_("Prev Line");
    const char *next_line_tag = N_("Next Line");
499
500
    const char *prev_page_tag = N_("Prev Page");
    const char *next_page_tag = N_("Next Page");
501
#ifndef DISABLE_JUSTIFY
502
    const char *justify_tag = N_("Justify");
503
    const char *fulljustify_tag = N_("FullJstify");
504
#endif
505
    const char *refresh_tag = N_("Refresh");
506
507
    /* TRANSLATORS: Try to keep this string at most 12 characters. */
    const char *whereis_next_tag = N_("WhereIs Next");
508

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

669
#ifdef ENABLE_HELP
670
#define IFSCHELP(help) help
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
671
#else
672
#define IFSCHELP(help) ""
673
#endif
674

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

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

681
    add_to_funcs(do_cancel, ((MMOST & ~MMAIN & ~MBROWSER) | MYESNO),
682
	N_("Cancel"), IFSCHELP(nano_cancel_msg), BLANKAFTER, VIEW);
683

684
    add_to_funcs(do_exit, MMAIN,
685
	exit_tag, IFSCHELP(nano_exit_msg), TOGETHER, VIEW);
686
687
    /* Remember the entry for Exit, to be able to replace it with Close. */
    exitfunc = tailfunc;
Chris Allegretta's avatar
Chris Allegretta committed
688

689
#ifdef ENABLE_BROWSER
690
    add_to_funcs(do_exit, MBROWSER,
691
	exit_tag, IFSCHELP(nano_exitbrowser_msg), TOGETHER, VIEW);
692
#endif
Chris Allegretta's avatar
Chris Allegretta committed
693

694
    add_to_funcs(do_writeout_void, MMAIN,
695
	N_("Write Out"), IFSCHELP(nano_writeout_msg), TOGETHER, NOVIEW);
696

697
698
699
700
701
702
703
#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
704
705
	add_to_funcs(do_insertfile_void, MMAIN,
		read_file_tag, IFSCHELP(nano_insert_msg), BLANKAFTER,
706
707
		/* We allow inserting files in view mode if multibuffer mode
		 * is switched on, so that we can view multiple files. */
708
#ifdef ENABLE_MULTIBUFFER
709
		VIEW);
710
#else
711
		NOVIEW);
712
#endif
713
714
    } else {
#ifndef DISABLE_JUSTIFY
715
	add_to_funcs(do_justify_void, MMAIN,
716
		justify_tag, IFSCHELP(nano_justify_msg), BLANKAFTER, NOVIEW);
717
718
#endif
    }
Chris Allegretta's avatar
Chris Allegretta committed
719

720
    add_to_funcs(do_search, MMAIN,
721
	whereis_tag, IFSCHELP(nano_whereis_msg), TOGETHER, VIEW);
Chris Allegretta's avatar
Chris Allegretta committed
722

723
    add_to_funcs(do_replace, MMAIN,
724
	replace_tag, IFSCHELP(nano_replace_msg), TOGETHER, NOVIEW);
725

726
#ifdef ENABLE_BROWSER
727
    add_to_funcs(do_search, MBROWSER,
728
	whereis_tag, IFSCHELP(nano_browser_whereis_msg), TOGETHER, VIEW);
729

730
    add_to_funcs(goto_dir_void, MBROWSER,
731
	N_("Go To Dir"), IFSCHELP(nano_gotodir_msg), BLANKAFTER, VIEW);
732
733
#endif

734
#ifdef ENABLE_HELP
735
736
    /* The description ("x") and blank_after (0) are irrelevant,
     * because the help viewer does not have a help text. */
737
    add_to_funcs(total_refresh, MHELP, refresh_tag, "x", 0, VIEW);
738
    add_to_funcs(do_exit, MHELP, close_tag, "x", 0, VIEW);
739

740
741
    add_to_funcs(do_search, MHELP, whereis_tag, "x", 0, VIEW);
    add_to_funcs(do_research, MHELP, whereis_next_tag, "x", 0, VIEW);
742
743
#endif

744
    add_to_funcs(do_cut_text_void, MMAIN,
745
	N_("Cut Text"), IFSCHELP(nano_cut_msg), TOGETHER, NOVIEW);
Chris Allegretta's avatar
Chris Allegretta committed
746

747
    add_to_funcs(do_uncut_text, MMAIN,
748
	uncut_tag, IFSCHELP(nano_uncut_msg), BLANKAFTER, NOVIEW);
749
    /* Remember the entry for Uncut, to be able to replace it with Unjustify. */
750
    uncutfunc = tailfunc;
Chris Allegretta's avatar
Chris Allegretta committed
751

752
    if (!ISSET(RESTRICTED)) {
753
#ifndef DISABLE_JUSTIFY
754
	add_to_funcs(do_justify_void, MMAIN,
755
		justify_tag, IFSCHELP(nano_justify_msg), TOGETHER, NOVIEW);
Chris Allegretta's avatar
Chris Allegretta committed
756
#endif
Chris Allegretta's avatar
Chris Allegretta committed
757

758
#ifndef DISABLE_SPELLER
759
760
	add_to_funcs(do_spell, MMAIN,
		N_("To Spell"), IFSCHELP(nano_spell_msg), TOGETHER, NOVIEW);
761
#endif
762
#ifndef DISABLE_COLOR
763
764
	add_to_funcs(do_linter, MMAIN,
		N_("To Linter"), IFSCHELP(nano_lint_msg), TOGETHER, NOVIEW);
765
#ifndef DISABLE_SPELLER
766
767
	add_to_funcs(do_formatter, MMAIN,
		N_("Formatter"), IFSCHELP(nano_formatter_msg), BLANKAFTER, NOVIEW);
768
#endif
769
#endif
770
    }
771

772
773
774
775
776
777
778
779
780
781
782
    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

783
784
785
786
787
788
789
790
791
792
793
794
#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

795
    add_to_funcs(case_sens_void, MWHEREIS|MREPLACE,
796
	N_("Case Sens"), IFSCHELP(nano_case_msg), TOGETHER, VIEW);
797
    add_to_funcs(regexp_void, MWHEREIS|MREPLACE,
798
	N_("Regexp"), IFSCHELP(nano_regexp_msg), TOGETHER, VIEW);
799
    add_to_funcs(backwards_void, MWHEREIS|MREPLACE,
800
	N_("Backwards"), IFSCHELP(nano_reverse_msg), TOGETHER, VIEW);
801

802
    add_to_funcs(flip_replace, MWHEREIS,
803
	replace_tag, IFSCHELP(nano_replace_msg), BLANKAFTER, VIEW);
804

805
    add_to_funcs(flip_replace, MREPLACE,
806
	N_("No Replace"), IFSCHELP(nano_whereis_msg), BLANKAFTER, VIEW);
807
808

#ifndef DISABLE_JUSTIFY
809
    add_to_funcs(do_full_justify, MWHEREIS,
810
	fulljustify_tag, IFSCHELP(nano_fulljustify_msg), TOGETHER, NOVIEW);
811

812
    add_to_funcs(do_gotolinecolumn_void, MWHEREIS,
813
	gotoline_tag, IFSCHELP(nano_gotoline_msg), BLANKAFTER, VIEW);
814
#endif
815

816
#ifndef NANO_TINY
817
818
819
    add_to_funcs(do_find_bracket, MMAIN,
	N_("To Bracket"), IFSCHELP(nano_bracket_msg), BLANKAFTER, VIEW);

820
    add_to_funcs(do_research, MMAIN,
821
	whereis_next_tag, IFSCHELP(nano_whereis_next_msg), TOGETHER, VIEW);
822

823
824
825
826
    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);
827
#endif /* !NANO_TINY */
828

829
    add_to_funcs(do_left, MMAIN,
830
	N_("Back"), IFSCHELP(nano_back_msg), TOGETHER, VIEW);
831
    add_to_funcs(do_right, MMAIN,
832
	N_("Forward"), IFSCHELP(nano_forward_msg), TOGETHER, VIEW);
833
#ifdef ENABLE_BROWSER
834
    add_to_funcs(do_left, MBROWSER,
835
	N_("Back"), IFSCHELP(nano_backfile_msg), TOGETHER, VIEW);
836
    add_to_funcs(do_right, MBROWSER,
837
	N_("Forward"), IFSCHELP(nano_forwardfile_msg), TOGETHER, VIEW);
838
839
#endif

840
    add_to_funcs(do_prev_word_void, MMAIN,
841
	N_("Prev Word"), IFSCHELP(nano_prevword_msg), TOGETHER, VIEW);
842
    add_to_funcs(do_next_word_void, MMAIN,
843
	N_("Next Word"), IFSCHELP(nano_nextword_msg), TOGETHER, VIEW);
844

845
    add_to_funcs(do_home_void, MMAIN,
846
	N_("Home"), IFSCHELP(nano_home_msg), TOGETHER, VIEW);
847
    add_to_funcs(do_end_void, MMAIN,
848
	N_("End"), IFSCHELP(nano_end_msg), BLANKAFTER, VIEW);
849

850
    add_to_funcs(do_up_void, MMAIN|MHELP|MBROWSER,
851
	prev_line_tag, IFSCHELP(nano_prevline_msg), TOGETHER, VIEW);
852
    add_to_funcs(do_down_void, MMAIN|MHELP|MBROWSER,
853
854
855
856
857
858
859
	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
860

861
862
863
864
    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);
865
#ifndef DISABLE_JUSTIFY
866
    add_to_funcs(do_para_begin_void, MMAIN|MWHEREIS,
867
	N_("Beg of Par"), IFSCHELP(nano_parabegin_msg), TOGETHER, VIEW);
868
    add_to_funcs(do_para_end_void, MMAIN|MWHEREIS,
869
	N_("End of Par"), IFSCHELP(nano_paraend_msg), BLANKAFTER, VIEW);
870
#endif
871

872
873
874
875
876
877
878
879
880
    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);
881

882
#ifdef ENABLE_MULTIBUFFER
883
    add_to_funcs(switch_to_prev_buffer_void, MMAIN,
884
	N_("Prev File"), IFSCHELP(nano_prevfile_msg), TOGETHER, VIEW);
885
    add_to_funcs(switch_to_next_buffer_void, MMAIN,
886
	N_("Next File"), IFSCHELP(nano_nextfile_msg), BLANKAFTER, VIEW);
887
888
#endif

889
890
#if (defined(DISABLE_JUSTIFY) && (!defined(DISABLE_SPELLER) || !defined(DISABLE_COLOR)) || \
	!defined(DISABLE_JUSTIFY) && defined(DISABLE_SPELLER) && defined(DISABLE_COLOR))
891
    add_to_funcs(do_gotolinecolumn_void, MMAIN,
892
	gotoline_tag, IFSCHELP(nano_gotoline_msg), BLANKAFTER, VIEW);
893
894
#endif

895
896
897
898
899
900
#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

901
    add_to_funcs(do_tab, MMAIN,
902
	N_("Tab"), IFSCHELP(nano_tab_msg), TOGETHER, NOVIEW);
903
    add_to_funcs(do_enter, MMAIN,
904
905
	N_("Enter"), IFSCHELP(nano_enter_msg), BLANKAFTER, NOVIEW);

906
    add_to_funcs(do_delete, MMAIN,
907
	N_("Delete"), IFSCHELP(nano_delete_msg), TOGETHER, NOVIEW);
908
909
    add_to_funcs(do_backspace, MMAIN,
	N_("Backspace"), IFSCHELP(nano_backspace_msg),
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
910
#ifndef NANO_TINY
911
	TOGETHER,
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
912
#else
913
	BLANKAFTER,
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
914
#endif
915
916
	NOVIEW);

917
#ifndef NANO_TINY
918
    add_to_funcs(do_cut_prev_word, MMAIN,
919
	/* TRANSLATORS: The next two strings refer to cutting words. */
920
921
922
	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);
923
    add_to_funcs(do_cut_till_eof, MMAIN,
924
	N_("CutTillEnd"), IFSCHELP(nano_cut_till_eof_msg), BLANKAFTER, NOVIEW);
925
#endif
Chris Allegretta's avatar
Chris Allegretta committed
926

927
#ifndef DISABLE_JUSTIFY
928
    add_to_funcs(do_full_justify, MMAIN,
929
	fulljustify_tag, IFSCHELP(nano_fulljustify_msg), TOGETHER, NOVIEW);
930
931
#endif

932
#ifndef NANO_TINY
933
    add_to_funcs(do_wordlinechar_count, MMAIN,
934
	N_("Word Count"), IFSCHELP(nano_wordcount_msg), TOGETHER, VIEW);
935
#endif
936

937
938
939
    add_to_funcs(do_verbatim_input, MMAIN,
	N_("Verbatim"), IFSCHELP(nano_verbatim_msg), BLANKAFTER, NOVIEW);

940
    add_to_funcs(total_refresh, MMAIN,
941
	refresh_tag, IFSCHELP(nano_refresh_msg), TOGETHER, VIEW);
942

943
    add_to_funcs(do_suspend_void, MMAIN,
944
	N_("Suspend"), IFSCHELP(nano_suspend_msg), BLANKAFTER, VIEW);
Chris Allegretta's avatar
Chris Allegretta committed
945

946
#ifndef NANO_TINY
947
    add_to_funcs(do_indent, MMAIN,
948
	N_("Indent Text"), IFSCHELP(nano_indent_msg), TOGETHER, NOVIEW);
949
    add_to_funcs(do_unindent, MMAIN,
950
951
	N_("Unindent Text"), IFSCHELP(nano_unindent_msg), BLANKAFTER, NOVIEW);
#endif
952
953
954
955
#ifdef ENABLE_WORDCOMPLETION
    add_to_funcs(complete_a_word, MMAIN,
	N_("Complete"), IFSCHELP(nano_completion_msg), TOGETHER, NOVIEW);
#endif
956
957
958
959
#ifdef ENABLE_COMMENT
    add_to_funcs(do_comment, MMAIN,
	N_("Comment Lines"), IFSCHELP(nano_comment_msg), BLANKAFTER, NOVIEW);
#endif
960
961
962
963
964
#ifndef NANO_TINY
    add_to_funcs(do_savefile, MMAIN,
	N_("Save"), IFSCHELP(nano_savefile_msg), BLANKAFTER, NOVIEW);
#endif

965
#ifndef DISABLE_HISTORIES
966
    add_to_funcs(get_history_older_void,
967
	(MWHEREIS|MREPLACE|MREPLACEWITH|MWHEREISFILE),
968
	N_("PrevHstory"), IFSCHELP(nano_prev_history_msg), TOGETHER, VIEW);
969
    add_to_funcs(get_history_newer_void,
970
	(MWHEREIS|MREPLACE|MREPLACEWITH|MWHEREISFILE),
971
972
973
	N_("NextHstory"), IFSCHELP(nano_next_history_msg), BLANKAFTER, VIEW);
#endif

974
#ifdef DISABLE_JUSTIFY
975
976
    add_to_funcs(do_gotolinecolumn_void, MWHEREIS,
	gotoline_tag, IFSCHELP(nano_gotoline_msg), BLANKAFTER, VIEW);
977
#endif
978

979
    add_to_funcs(gototext_void, MGOTOLINE,
980
	N_("Go To Text"), IFSCHELP(nano_whereis_msg), BLANKAFTER, VIEW);
981

982
#ifndef NANO_TINY
983
    add_to_funcs(dos_format_void, MWRITEFILE,
984
	N_("DOS Format"), IFSCHELP(nano_dos_msg), TOGETHER, NOVIEW);
985
    add_to_funcs(mac_format_void, MWRITEFILE,
986
987
988
989
990
991
	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. */
992
    if (!ISSET(RESTRICTED)) {
993
994
995
996
	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);
997

998
	add_to_funcs(backup_file_void, MWRITEFILE,
999
	    N_("Backup File"), IFSCHELP(nano_backup_msg), BLANKAFTER, NOVIEW);
1000
    }
1001

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

1008
	add_to_funcs(flip_execute, MEXTCMD,
1009
	    read_file_tag, IFSCHELP(nano_insert_msg), TOGETHER, NOVIEW);
1010
1011
    }
#endif /* !NANO_TINY */
1012
#ifdef ENABLE_MULTIBUFFER
1013
    if (!ISSET(RESTRICTED))
1014
	add_to_funcs(flip_newbuffer, MINSERTFILE|MEXTCMD,
1015
	    N_("New Buffer"), IFSCHELP(nano_newbuffer_msg), TOGETHER, NOVIEW);
1016
#endif
1017

1018
#ifdef ENABLE_BROWSER
1019
1020
    if (!ISSET(RESTRICTED))
	add_to_funcs(to_files_void, MWRITEFILE|MINSERTFILE,
1021
	    N_("To Files"), IFSCHELP(nano_tofiles_msg), TOGETHER, VIEW);
1022

1023
1024
1025
1026
1027
    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
1028
    add_to_funcs(do_first_file, (MBROWSER|MWHEREISFILE),
1029
	N_("First File"), IFSCHELP(nano_firstfile_msg), TOGETHER, VIEW);
Benno Schulenberg's avatar
Benno Schulenberg committed
1030
    add_to_funcs(do_last_file, (MBROWSER|MWHEREISFILE),
1031
	N_("Last File"), IFSCHELP(nano_lastfile_msg), BLANKAFTER, VIEW);
1032
#endif
Chris Allegretta's avatar
Chris Allegretta committed
1033

1034
1035
1036
    add_to_funcs(discard_buffer, MWRITEFILE,
	N_("Discard buffer"), IFSCHELP(nano_discard_buffer_msg), BLANKAFTER, NOVIEW);

1037
#ifdef ENABLE_BROWSER
1038
    add_to_funcs(do_research, MBROWSER,
1039
	whereis_next_tag, IFSCHELP(nano_whereis_next_msg), TOGETHER, VIEW);
1040
1041
    add_to_funcs(total_refresh, MBROWSER,
	refresh_tag, IFSCHELP(nano_browser_refresh_msg), BLANKAFTER, VIEW);
1042
#ifndef NANO_TINY
1043
1044
1045
    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,
1046
1047
1048
1049
1050
	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);
1051
#endif
1052
#endif
1053
1054
1055

#ifndef DISABLE_COLOR
    add_to_funcs(do_page_up, MLINTER,
1056
	/* TRANSLATORS: Try to keep the next two strings at most 20 characters. */
1057
	N_("Prev Lint Msg"), IFSCHELP(nano_prevlint_msg), TOGETHER, VIEW);
1058
    add_to_funcs(do_page_down, MLINTER,
1059
	N_("Next Lint Msg"), IFSCHELP(nano_nextlint_msg), TOGETHER, VIEW);
1060
1061
#endif

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

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

1211
#ifndef NANO_TINY
1212
    /* Group of "Appearance" toggles. */
1213
    add_to_sclist(MMAIN, "M-X", 0, do_toggle_void, NO_HELP);
1214
    add_to_sclist(MMAIN, "M-C", 0, do_toggle_void, CONSTANT_SHOW);
1215
1216
1217
    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);
1218
1219
1220
#ifdef ENABLE_LINENUMBERS
    add_to_sclist(MMAIN, "M-#", 0, do_toggle_void, LINE_NUMBERS);
#endif
1221
    add_to_sclist(MMAIN, "M-P", 0, do_toggle_void, WHITESPACE_DISPLAY);
1222
#ifndef DISABLE_COLOR
1223
    add_to_sclist(MMAIN, "M-Y", 0, do_toggle_void, NO_COLOR_SYNTAX);
1224
#endif
1225

1226
    /* Group of "Editing-behavior" toggles. */
1227
1228
    add_to_sclist(MMAIN, "M-H", 0, do_toggle_void, SMART_HOME);
    add_to_sclist(MMAIN, "M-I", 0, do_toggle_void, AUTOINDENT);
1229
    add_to_sclist(MMAIN, "M-K", 0, do_toggle_void, CUT_FROM_CURSOR);
1230
#ifndef DISABLE_WRAPPING
1231
    add_to_sclist(MMAIN, "M-L", 0, do_toggle_void, NO_WRAP);
1232
#endif
1233
    add_to_sclist(MMAIN, "M-Q", 0, do_toggle_void, TABS_TO_SPACES);
1234

1235
    /* Group of "Peripheral-feature" toggles. */
1236
    add_to_sclist(MMAIN, "M-B", 0, do_toggle_void, BACKUP_FILE);
1237
#ifdef ENABLE_MULTIBUFFER
1238
    add_to_sclist(MMAIN, "M-F", 0, do_toggle_void, MULTIBUFFER);
1239
#endif
1240
#ifdef ENABLE_MOUSE
1241
    add_to_sclist(MMAIN, "M-M", 0, do_toggle_void, USE_MOUSE);
1242
#endif
1243
1244
    add_to_sclist(MMAIN, "M-N", 0, do_toggle_void, NO_CONVERT);
    add_to_sclist(MMAIN, "M-Z", 0, do_toggle_void, SUSPEND);
1245
#endif /* !NANO_TINY */
Benno Schulenberg's avatar
Benno Schulenberg committed
1246

1247
1248
    add_to_sclist(MMAIN, "^Q", 0, xon_complaint, 0);
    add_to_sclist(MMAIN, "^S", 0, xoff_complaint, 0);
1249

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

1252
1253
1254
    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);
1255
    add_to_sclist(MWHEREIS|MREPLACE, "^R", 0, flip_replace, 0);
1256
1257
    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);
1258
#ifndef DISABLE_JUSTIFY
1259
1260
    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);
1261
#endif
1262
1263
    add_to_sclist(MWHEREIS, "^T", 0, do_gotolinecolumn_void, 0);
    add_to_sclist(MGOTOLINE, "^T", 0, gototext_void, 0);
1264
#ifndef DISABLE_HISTORIES
1265
1266
    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);
1267
1268
#ifdef ENABLE_UTF8
    if (using_utf8()) {
1269
1270
	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);
1271
1272
1273
    } else
#endif
    {
1274
1275
	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);
1276
    }
1277
#endif
1278
#ifdef ENABLE_BROWSER
1279
1280
1281
1282
1283
1284
    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);
1285
1286
    add_to_sclist(MBROWSER|MWHEREISFILE, "M-|", 0, do_first_file, 0);
    add_to_sclist(MBROWSER|MWHEREISFILE, "M-?", 0, do_last_file, 0);
1287
    add_to_sclist(MBROWSER, "^Home", CONTROL_HOME, do_first_file, 0);
1288
    add_to_sclist(MBROWSER, "^End", CONTROL_END, do_last_file, 0);
1289
1290
1291
1292
    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);
1293
#endif
1294
    if (ISSET(TEMP_FILE))
1295
	add_to_sclist(MWRITEFILE, "^Q", 0, discard_buffer, 0);
1296
#ifndef NANO_TINY
1297
1298
    add_to_sclist(MWRITEFILE, "M-D", 0, dos_format_void, 0);
    add_to_sclist(MWRITEFILE, "M-M", 0, mac_format_void, 0);
1299
1300
    /* In restricted mode, don't allow Appending, Prepending, nor making
     * backups, nor executing a command, nor opening a new buffer. */
1301
    if (!ISSET(RESTRICTED)) {
1302
1303
1304
	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);
1305
	add_to_sclist(MINSERTFILE|MEXTCMD, "^X", 0, flip_execute, 0);
1306
    }
1307
#endif
1308
1309
#ifdef ENABLE_MULTIBUFFER
    if (!ISSET(RESTRICTED))
1310
	add_to_sclist(MINSERTFILE|MEXTCMD, "M-F", 0, flip_newbuffer, 0);
1311
#endif
1312
#ifdef ENABLE_BROWSER
1313
1314
1315
1316
    /* 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
1317
    add_to_sclist(MHELP|MBROWSER, "^C", 0, do_exit, 0);
1318
1319
    /* Allow exiting from the file browser and the help viewer with
     * the same key as they were entered. */
1320
#ifdef ENABLE_BROWSER
1321
    add_to_sclist(MBROWSER, "^T", 0, do_exit, 0);
1322
#endif
1323
#ifdef ENABLE_HELP
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
    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
1336

1337
1338
#ifdef DEBUG
    print_sclist();
Chris Allegretta's avatar
Chris Allegretta committed
1339
#endif
1340
}
1341

1342
#ifndef DISABLE_COLOR
1343
void set_lint_or_format_shortcuts(void)
1344
1345
{
#ifndef DISABLE_SPELLER
1346
1347
1348
1349
1350
1351
1352
    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);
    }
1353
1354
1355
1356
1357
1358
#endif
}

void set_spell_shortcuts(void)
{
#ifndef DISABLE_SPELLER
1359
1360
	replace_scs_for(do_formatter, do_spell);
	replace_scs_for(do_linter, do_spell);
1361
1362
#endif
}
1363
#endif /* !DISABLE_COLOR */
1364

1365
const subnfunc *sctofunc(const sc *s)
1366
{
1367
    subnfunc *f = allfuncs;
1368

1369
1370
    while (f != NULL && f->scfunc != s->scfunc)
	f = f->next;
1371

1372
    return f;
1373
1374
}

1375
#ifndef NANO_TINY
1376
1377
/* Now let's come up with a single (hopefully) function to get a string
 * for each flag. */
1378
const char *flagtostr(int flag)
1379
{
1380
    switch (flag) {
1381
1382
1383
1384
	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");
1385
	case CONSTANT_SHOW:
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
	    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");
1401
	case CUT_FROM_CURSOR:
1402
1403
1404
1405
1406
1407
1408
1409
	    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:
1410
	    return N_("Reading file into separate buffer");
1411
1412
1413
1414
1415
1416
	case USE_MOUSE:
	    return N_("Mouse support");
	case NO_CONVERT:
	    return N_("No conversion from DOS/Mac format");
	case SUSPEND:
	    return N_("Suspension");
1417
1418
	case LINE_NUMBERS:
	    return N_("Line numbering");
1419
1420
	default:
	    return "?????";
1421
1422
    }
}
1423
#endif /* !NANO_TINY */
1424

1425
#ifdef ENABLE_NANORC
1426
/* Interpret a function string given in the rc file, and return a
1427
 * shortcut struct with the corresponding function filled in. */
1428
sc *strtosc(const char *input)
1429
{
1430
    sc *s = nmalloc(sizeof(sc));
1431

1432
#ifndef NANO_TINY
1433
    s->toggle = 0;
1434
#endif
1435

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

1691
/* Interpret a menu name and return the corresponding menu flag. */
1692
int strtomenu(const char *input)
1693
1694
{
    if (!strcasecmp(input, "all"))
1695
	return (MMOST|MHELP|MYESNO);
1696
1697
1698
1699
1700
1701
    else if (!strcasecmp(input, "main"))
	return MMAIN;
    else if (!strcasecmp(input, "search"))
	return MWHEREIS;
    else if (!strcasecmp(input, "replace"))
	return MREPLACE;
1702
    else if (!strcasecmp(input, "replace2") ||  /* Deprecated.  Remove in 2018. */
Benno Schulenberg's avatar
Benno Schulenberg committed
1703
	     !strcasecmp(input, "replacewith"))
1704
	return MREPLACEWITH;
1705
1706
1707
1708
1709
1710
1711
    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
1712
	     !strcasecmp(input, "extcmd"))
1713
	return MEXTCMD;
1714
#ifdef ENABLE_HELP
1715
1716
    else if (!strcasecmp(input, "help"))
	return MHELP;
1717
1718
#endif
#ifndef DISABLE_SPELLER
1719
    else if (!strcasecmp(input, "spell"))
1720
	return MSPELL;
1721
#endif
1722
1723
    else if (!strcasecmp(input, "linter"))
	return MLINTER;
1724
#ifdef ENABLE_BROWSER
1725
1726
1727
1728
1729
1730
    else if (!strcasecmp(input, "browser"))
	return MBROWSER;
    else if (!strcasecmp(input, "whereisfile"))
	return MWHEREISFILE;
    else if (!strcasecmp(input, "gotodir"))
	return MGOTODIR;
1731
#endif
1732
1733
    return -1;
}
1734
#endif /* ENABLE_NANORC */
1735

Chris Allegretta's avatar
Chris Allegretta committed
1736

1737
1738
1739
#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
1740
1741
 * 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
1742
1743
 * function unless debugging is turned on. */
void thanks_for_all_the_fish(void)
1744
{
1745
1746
    if (topwin != NULL)
	delwin(topwin);
1747
1748
1749
    delwin(edit);
    delwin(bottomwin);

1750
    free(word_chars);
Chris Allegretta's avatar
Chris Allegretta committed
1751
#ifndef DISABLE_JUSTIFY
1752
    free(quotestr);
1753
    regfree(&quotereg);
1754
    free(quoteerr);
1755
#endif
1756
#ifndef NANO_TINY
1757
    free(backup_dir);
1758
#endif
Chris Allegretta's avatar
Chris Allegretta committed
1759
#ifndef DISABLE_OPERATINGDIR
1760
    free(operating_dir);
1761
#endif
1762
    free(answer);
1763
    free(last_search);
1764
    free(present_path);
1765
#ifndef DISABLE_SPELLER
1766
    free(alt_speller);
1767
#endif
1768
    free_filestruct(cutbuffer);
David Lawrence Ramsey's avatar
David Lawrence Ramsey committed
1769
    /* Free the memory associated with each open file buffer. */
1770
1771
1772
1773
1774
    while (openfile != openfile->next) {
	openfile = openfile->next;
	delete_opennode(openfile->prev);
    }
    delete_opennode(openfile);
1775
#ifndef DISABLE_COLOR
1776
    free(syntaxstr);
Chris Allegretta's avatar
Chris Allegretta committed
1777
    while (syntaxes != NULL) {
1778
1779
	syntaxtype *sint = syntaxes;
	syntaxes = syntaxes->next;
Chris Allegretta's avatar
Chris Allegretta committed
1780

1781
1782
1783
	free(sint->name);
	free(sint->linter);
	free(sint->formatter);
1784

1785
1786
1787
1788
1789
	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
1790
	}
1791
1792
1793
1794
1795
	while (sint->headers != NULL) {
	    regexlisttype *item = sint->headers;
	    sint->headers = sint->headers->next;
	    free(item->full_regex);
	    free(item);
1796
	}
1797
1798
1799
1800
1801
	while (sint->magics != NULL) {
	    regexlisttype *item = sint->magics;
	    sint->magics = sint->magics->next;
	    free(item->full_regex);
	    free(item);
1802
	}
1803

1804
1805
1806
1807
1808
1809
1810
	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);
1811
	    }
1812
1813
1814
1815
	    free(ink->end_regex);
	    if (ink->end != NULL) {
		regfree(ink->end);
		free(ink->end);
1816
	    }
1817
	    free(ink);
Chris Allegretta's avatar
Chris Allegretta committed
1818
	}
1819
1820

	free(sint);
Chris Allegretta's avatar
Chris Allegretta committed
1821
    }
1822
#endif /* !DISABLE_COLOR */
1823
#ifndef DISABLE_HISTORIES
1824
    /* Free the search and replace history lists. */
1825
1826
    free_filestruct(searchage);
    free_filestruct(replaceage);
1827
#endif
1828
    /* Free the list of functions. */
1829
    while (allfuncs != NULL) {
1830
1831
1832
	subnfunc *f = allfuncs;
	allfuncs = allfuncs->next;
	free(f);
1833
    }
1834
    /* Free the list of shortcuts. */
1835
    while (sclist != NULL) {
1836
1837
1838
	sc *s = sclist;
	sclist = sclist->next;
	free(s);
1839
    }
1840
#ifdef ENABLE_NANORC
1841
    free(homedir);
1842
#endif
1843
}
1844
#endif /* DEBUG */