1 /* Line completion stuff for GDB, the GNU debugger.
2 Copyright (C) 2000-2017 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
22 #include "expression.h"
23 #include "filenames.h" /* For DOSish file names. */
25 #include "gdb_signals.h"
27 #include "reggroups.h"
28 #include "user-regs.h"
29 #include "arch-utils.h"
32 #include "cli/cli-decode.h"
34 /* FIXME: This is needed because of lookup_cmd_1 (). We should be
35 calling a hook instead so we eliminate the CLI dependency. */
38 /* Needed for rl_completer_word_break_characters() and for
39 rl_filename_completion_function. */
40 #include "readline/readline.h"
42 /* readline defines this. */
45 #include "completer.h"
47 /* An enumeration of the various things a user might
48 attempt to complete for a location. */
50 enum explicit_location_match_type
52 /* The filename of a source file. */
55 /* The name of a function or method. */
58 /* The name of a label. */
62 /* Prototypes for local functions. */
64 char *line_completion_function (const char *text, int matches,
68 /* readline uses the word breaks for two things:
69 (1) In figuring out where to point the TEXT parameter to the
70 rl_completion_entry_function. Since we don't use TEXT for much,
71 it doesn't matter a lot what the word breaks are for this purpose,
72 but it does affect how much stuff M-? lists.
73 (2) If one of the matches contains a word break character, readline
74 will quote it. That's why we switch between
75 current_language->la_word_break_characters() and
76 gdb_completer_command_word_break_characters. I'm not sure when
77 we need this behavior (perhaps for funky characters in C++
80 /* Variables which are necessary for fancy command line editing. */
82 /* When completing on command names, we remove '-' from the list of
83 word break characters, since we use it in command names. If the
84 readline library sees one in any of the current completion strings,
85 it thinks that the string needs to be quoted and automatically
86 supplies a leading quote. */
87 static const char gdb_completer_command_word_break_characters[] =
88 " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,";
90 /* When completing on file names, we remove from the list of word
91 break characters any characters that are commonly used in file
92 names, such as '-', '+', '~', etc. Otherwise, readline displays
93 incorrect completion candidates. */
94 /* MS-DOS and MS-Windows use colon as part of the drive spec, and most
95 programs support @foo style response files. */
96 static const char gdb_completer_file_name_break_characters[] =
97 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
103 /* Characters that can be used to quote completion strings. Note that
104 we can't include '"' because the gdb C parser treats such quoted
105 sequences as strings. */
106 static const char gdb_completer_quote_characters[] = "'";
108 /* Accessor for some completer data that may interest other files. */
111 get_gdb_completer_quote_characters (void)
113 return gdb_completer_quote_characters;
116 /* Line completion interface function for readline. */
119 readline_line_completion_function (const char *text, int matches)
121 return line_completion_function (text, matches,
122 rl_line_buffer, rl_point);
125 /* This can be used for functions which don't want to complete on
126 symbols but don't want to complete on anything else either. */
128 noop_completer (struct cmd_list_element *ignore,
129 const char *text, const char *prefix)
134 /* Complete on filenames. */
136 filename_completer (struct cmd_list_element *ignore,
137 const char *text, const char *word)
140 VEC (char_ptr) *return_val = NULL;
147 p = rl_filename_completion_function (text, subsequent_name);
150 /* We need to set subsequent_name to a non-zero value before the
151 continue line below, because otherwise, if the first file
152 seen by GDB is a backup file whose name ends in a `~', we
153 will loop indefinitely. */
155 /* Like emacs, don't complete on old versions. Especially
156 useful in the "source" command. */
157 if (p[strlen (p) - 1] == '~')
164 /* Return exactly p. */
166 else if (word > text)
168 /* Return some portion of p. */
169 q = (char *) xmalloc (strlen (p) + 5);
170 strcpy (q, p + (word - text));
175 /* Return some of TEXT plus p. */
176 q = (char *) xmalloc (strlen (p) + (text - word) + 5);
177 strncpy (q, word, text - word);
178 q[text - word] = '\0';
182 VEC_safe_push (char_ptr, return_val, q);
185 /* There is no way to do this just long enough to affect quote
186 inserting without also affecting the next completion. This
187 should be fixed in readline. FIXME. */
188 /* Ensure that readline does the right thing
189 with respect to inserting quotes. */
190 rl_completer_word_break_characters = "";
195 /* Complete on linespecs, which might be of two possible forms:
201 This is intended to be used in commands that set breakpoints
204 static VEC (char_ptr) *
205 linespec_location_completer (struct cmd_list_element *ignore,
206 const char *text, const char *word)
208 int n_syms, n_files, ix;
209 VEC (char_ptr) *fn_list = NULL;
210 VEC (char_ptr) *list = NULL;
213 int quoted = *text == '\'' || *text == '"';
214 int quote_char = '\0';
215 const char *colon = NULL;
216 char *file_to_match = NULL;
217 const char *symbol_start = text;
218 const char *orig_text = text;
221 /* Do we have an unquoted colon, as in "break foo.c:bar"? */
222 for (p = text; *p != '\0'; ++p)
224 if (*p == '\\' && p[1] == '\'')
226 else if (*p == '\'' || *p == '"')
230 while (*p != '\0' && *p != quote_found)
232 if (*p == '\\' && p[1] == quote_found)
237 if (*p == quote_found)
240 break; /* Hit the end of text. */
242 #if HAVE_DOS_BASED_FILE_SYSTEM
243 /* If we have a DOS-style absolute file name at the beginning of
244 TEXT, and the colon after the drive letter is the only colon
245 we found, pretend the colon is not there. */
246 else if (p < text + 3 && *p == ':' && p == text + 1 + quoted)
249 else if (*p == ':' && !colon)
252 symbol_start = p + 1;
254 else if (strchr (current_language->la_word_break_characters(), *p))
255 symbol_start = p + 1;
260 text_len = strlen (text);
262 /* Where is the file name? */
267 file_to_match = (char *) xmalloc (colon - text + 1);
268 strncpy (file_to_match, text, colon - text);
269 file_to_match[colon - text] = '\0';
270 /* Remove trailing colons and quotes from the file name. */
271 for (s = file_to_match + (colon - text);
274 if (*s == ':' || *s == quote_char)
277 /* If the text includes a colon, they want completion only on a
278 symbol name after the colon. Otherwise, we need to complete on
279 symbols as well as on files. */
282 list = make_file_symbol_completion_list (symbol_start, word,
284 xfree (file_to_match);
288 list = make_symbol_completion_list (symbol_start, word);
289 /* If text includes characters which cannot appear in a file
290 name, they cannot be asking for completion on files. */
292 gdb_completer_file_name_break_characters) == text_len)
293 fn_list = make_source_files_completion_list (text, text);
296 n_syms = VEC_length (char_ptr, list);
297 n_files = VEC_length (char_ptr, fn_list);
299 /* Catenate fn_list[] onto the end of list[]. */
302 VEC_free (char_ptr, list); /* Paranoia. */
310 for (ix = 0; VEC_iterate (char_ptr, fn_list, ix, fn); ++ix)
311 VEC_safe_push (char_ptr, list, fn);
312 VEC_free (char_ptr, fn_list);
315 if (n_syms && n_files)
323 /* If we only have file names as possible completion, we should
324 bring them in sync with what rl_complete expects. The
325 problem is that if the user types "break /foo/b TAB", and the
326 possible completions are "/foo/bar" and "/foo/baz"
327 rl_complete expects us to return "bar" and "baz", without the
328 leading directories, as possible completions, because `word'
329 starts at the "b". But we ignore the value of `word' when we
330 call make_source_files_completion_list above (because that
331 would not DTRT when the completion results in both symbols
332 and file names), so make_source_files_completion_list returns
333 the full "/foo/bar" and "/foo/baz" strings. This produces
334 wrong results when, e.g., there's only one possible
335 completion, because rl_complete will prepend "/foo/" to each
336 candidate completion. The loop below removes that leading
338 for (ix = 0; VEC_iterate (char_ptr, list, ix, fn); ++ix)
340 memmove (fn, fn + (word - text),
341 strlen (fn) + 1 - (word - text));
346 /* No completions at all. As the final resort, try completing
347 on the entire text as a symbol. */
348 list = make_symbol_completion_list (orig_text, word);
354 /* A helper function to collect explicit location matches for the given
355 LOCATION, which is attempting to match on WORD. */
357 static VEC (char_ptr) *
358 collect_explicit_location_matches (struct event_location *location,
359 enum explicit_location_match_type what,
362 VEC (char_ptr) *matches = NULL;
363 const struct explicit_location *explicit_loc
364 = get_explicit_location (location);
370 const char *text = (explicit_loc->source_filename == NULL
371 ? "" : explicit_loc->source_filename);
373 matches = make_source_files_completion_list (text, word);
379 const char *text = (explicit_loc->function_name == NULL
380 ? "" : explicit_loc->function_name);
382 if (explicit_loc->source_filename != NULL)
384 const char *filename = explicit_loc->source_filename;
386 matches = make_file_symbol_completion_list (text, word, filename);
389 matches = make_symbol_completion_list (text, word);
398 gdb_assert_not_reached ("unhandled explicit_location_match_type");
404 /* A convenience macro to (safely) back up P to the previous word. */
407 backup_text_ptr (const char *p, const char *text)
409 while (p > text && isspace (*p))
411 for (; p > text && !isspace (p[-1]); --p)
417 /* A completer function for explicit locations. This function
418 completes both options ("-source", "-line", etc) and values. */
420 static VEC (char_ptr) *
421 explicit_location_completer (struct cmd_list_element *ignore,
422 struct event_location *location,
423 const char *text, const char *word)
426 VEC (char_ptr) *matches = NULL;
428 /* Find the beginning of the word. This is necessary because
429 we need to know if we are completing an option name or value. We
430 don't get the leading '-' from the completer. */
431 p = backup_text_ptr (word, text);
435 /* Completing on option name. */
436 static const char *const keywords[] =
445 /* Skip over the '-'. */
448 return complete_on_enum (keywords, p, p);
452 /* Completing on value (or unknown). Get the previous word to see what
453 the user is completing on. */
455 const char *new_word, *end;
456 enum explicit_location_match_type what;
457 struct explicit_location *explicit_loc
458 = get_explicit_location (location);
460 /* Backup P to the previous word, which should be the option
461 the user is attempting to complete. */
464 p = backup_text_ptr (p, text);
467 if (strncmp (p, "-source", len) == 0)
470 new_word = explicit_loc->source_filename + offset;
472 else if (strncmp (p, "-function", len) == 0)
474 what = MATCH_FUNCTION;
475 new_word = explicit_loc->function_name + offset;
477 else if (strncmp (p, "-label", len) == 0)
480 new_word = explicit_loc->label_name + offset;
484 /* The user isn't completing on any valid option name,
485 e.g., "break -source foo.c [tab]". */
489 /* If the user hasn't entered a search expression, e.g.,
490 "break -function <TAB><TAB>", new_word will be NULL, but
491 search routines require non-NULL search words. */
492 if (new_word == NULL)
495 /* Now gather matches */
496 matches = collect_explicit_location_matches (location, what, new_word);
502 /* A completer for locations. */
505 location_completer (struct cmd_list_element *ignore,
506 const char *text, const char *word)
508 VEC (char_ptr) *matches = NULL;
509 const char *copy = text;
511 event_location_up location = string_to_explicit_location (©,
514 if (location != NULL)
515 matches = explicit_location_completer (ignore, location.get (),
519 /* This is an address or linespec location.
520 Right now both of these are handled by the (old) linespec
522 matches = linespec_location_completer (ignore, text, word);
528 /* Helper for expression_completer which recursively adds field and
529 method names from TYPE, a struct or union type, to the array
532 add_struct_fields (struct type *type, VEC (char_ptr) **output,
533 char *fieldname, int namelen)
536 int computed_type_name = 0;
537 const char *type_name = NULL;
539 type = check_typedef (type);
540 for (i = 0; i < TYPE_NFIELDS (type); ++i)
542 if (i < TYPE_N_BASECLASSES (type))
543 add_struct_fields (TYPE_BASECLASS (type, i),
544 output, fieldname, namelen);
545 else if (TYPE_FIELD_NAME (type, i))
547 if (TYPE_FIELD_NAME (type, i)[0] != '\0')
549 if (! strncmp (TYPE_FIELD_NAME (type, i),
551 VEC_safe_push (char_ptr, *output,
552 xstrdup (TYPE_FIELD_NAME (type, i)));
554 else if (TYPE_CODE (TYPE_FIELD_TYPE (type, i)) == TYPE_CODE_UNION)
556 /* Recurse into anonymous unions. */
557 add_struct_fields (TYPE_FIELD_TYPE (type, i),
558 output, fieldname, namelen);
563 for (i = TYPE_NFN_FIELDS (type) - 1; i >= 0; --i)
565 const char *name = TYPE_FN_FIELDLIST_NAME (type, i);
567 if (name && ! strncmp (name, fieldname, namelen))
569 if (!computed_type_name)
571 type_name = type_name_no_tag (type);
572 computed_type_name = 1;
574 /* Omit constructors from the completion list. */
575 if (!type_name || strcmp (type_name, name))
576 VEC_safe_push (char_ptr, *output, xstrdup (name));
581 /* Complete on expressions. Often this means completing on symbol
582 names, but some language parsers also have support for completing
585 expression_completer (struct cmd_list_element *ignore,
586 const char *text, const char *word)
588 struct type *type = NULL;
591 enum type_code code = TYPE_CODE_UNDEF;
593 /* Perform a tentative parse of the expression, to see whether a
594 field completion is required. */
598 type = parse_expression_for_completion (text, &fieldname, &code);
600 CATCH (except, RETURN_MASK_ERROR)
606 if (fieldname && type)
610 type = check_typedef (type);
611 if (TYPE_CODE (type) != TYPE_CODE_PTR && !TYPE_IS_REFERENCE (type))
613 type = TYPE_TARGET_TYPE (type);
616 if (TYPE_CODE (type) == TYPE_CODE_UNION
617 || TYPE_CODE (type) == TYPE_CODE_STRUCT)
619 int flen = strlen (fieldname);
620 VEC (char_ptr) *result = NULL;
622 add_struct_fields (type, &result, fieldname, flen);
627 else if (fieldname && code != TYPE_CODE_UNDEF)
629 VEC (char_ptr) *result;
630 struct cleanup *cleanup = make_cleanup (xfree, fieldname);
632 result = make_symbol_completion_type (fieldname, fieldname, code);
633 do_cleanups (cleanup);
638 /* Commands which complete on locations want to see the entire
641 p > text && p[-1] != ' ' && p[-1] != '\t';
645 /* Not ideal but it is what we used to do before... */
646 return location_completer (ignore, p, word);
649 /* See definition in completer.h. */
652 set_rl_completer_word_break_characters (const char *break_chars)
654 rl_completer_word_break_characters = (char *) break_chars;
657 /* See definition in completer.h. */
660 set_gdb_completion_word_break_characters (completer_ftype *fn)
662 const char *break_chars;
664 /* So far we are only interested in differentiating filename
665 completers from everything else. */
666 if (fn == filename_completer)
667 break_chars = gdb_completer_file_name_break_characters;
669 break_chars = gdb_completer_command_word_break_characters;
671 set_rl_completer_word_break_characters (break_chars);
674 /* Here are some useful test cases for completion. FIXME: These
675 should be put in the test suite. They should be tested with both
678 "show output-" "radix"
679 "show output" "-radix"
680 "p" ambiguous (commands starting with p--path, print, printf, etc.)
681 "p " ambiguous (all symbols)
682 "info t foo" no completions
683 "info t " no completions
684 "info t" ambiguous ("info target", "info terminal", etc.)
685 "info ajksdlfk" no completions
686 "info ajksdlfk " no completions
688 "info " ambiguous (all info commands)
689 "p \"a" no completions (string constant)
690 "p 'a" ambiguous (all symbols starting with a)
691 "p b-a" ambiguous (all symbols starting with a)
692 "p b-" ambiguous (all symbols)
693 "file Make" "file" (word break hard to screw up here)
694 "file ../gdb.stabs/we" "ird" (needs to not break word at slash)
703 complete_line_internal_reason;
706 /* Internal function used to handle completions.
709 TEXT is the caller's idea of the "word" we are looking at.
711 LINE_BUFFER is available to be looked at; it contains the entire
712 text of the line. POINT is the offset in that line of the cursor.
713 You should pretend that the line ends at POINT.
715 REASON is of type complete_line_internal_reason.
717 If REASON is handle_brkchars:
718 Preliminary phase, called by gdb_completion_word_break_characters
719 function, is used to determine the correct set of chars that are
720 word delimiters depending on the current command in line_buffer.
721 No completion list should be generated; the return value should be
722 NULL. This is checked by an assertion in that function.
724 If REASON is handle_completions:
725 Main phase, called by complete_line function, is used to get the list
726 of posible completions.
728 If REASON is handle_help:
729 Special case when completing a 'help' command. In this case,
730 once sub-command completions are exhausted, we simply return NULL.
733 static VEC (char_ptr) *
734 complete_line_internal (const char *text,
735 const char *line_buffer, int point,
736 complete_line_internal_reason reason)
738 VEC (char_ptr) *list = NULL;
741 int ignore_help_classes;
742 /* Pointer within tmp_command which corresponds to text. */
744 struct cmd_list_element *c, *result_list;
746 /* Choose the default set of word break characters to break
747 completions. If we later find out that we are doing completions
748 on command strings (as opposed to strings supplied by the
749 individual command completer functions, which can be any string)
750 then we will switch to the special word break set for command
751 strings, which leaves out the '-' character used in some
753 set_rl_completer_word_break_characters
754 (current_language->la_word_break_characters());
756 /* Decide whether to complete on a list of gdb commands or on
758 tmp_command = (char *) alloca (point + 1);
761 /* The help command should complete help aliases. */
762 ignore_help_classes = reason != handle_help;
764 strncpy (tmp_command, line_buffer, point);
765 tmp_command[point] = '\0';
766 /* Since text always contains some number of characters leading up
767 to point, we can find the equivalent position in tmp_command
768 by subtracting that many characters from the end of tmp_command. */
769 word = tmp_command + point - strlen (text);
773 /* An empty line we want to consider ambiguous; that is, it
774 could be any command. */
775 c = CMD_LIST_AMBIGUOUS;
780 c = lookup_cmd_1 (&p, cmdlist, &result_list, ignore_help_classes);
783 /* Move p up to the next interesting thing. */
784 while (*p == ' ' || *p == '\t')
791 /* It is an unrecognized command. So there are no
792 possible completions. */
795 else if (c == CMD_LIST_AMBIGUOUS)
799 /* lookup_cmd_1 advances p up to the first ambiguous thing, but
800 doesn't advance over that thing itself. Do so now. */
802 while (*q && (isalnum (*q) || *q == '-' || *q == '_'))
804 if (q != tmp_command + point)
806 /* There is something beyond the ambiguous
807 command, so there are no possible completions. For
808 example, "info t " or "info t foo" does not complete
809 to anything, because "info t" can be "info target" or
815 /* We're trying to complete on the command which was ambiguous.
816 This we can deal with. */
819 if (reason != handle_brkchars)
820 list = complete_on_cmdlist (*result_list->prefixlist, p,
821 word, ignore_help_classes);
825 if (reason != handle_brkchars)
826 list = complete_on_cmdlist (cmdlist, p, word,
827 ignore_help_classes);
829 /* Ensure that readline does the right thing with respect to
831 set_rl_completer_word_break_characters
832 (gdb_completer_command_word_break_characters);
837 /* We've recognized a full command. */
839 if (p == tmp_command + point)
841 /* There is no non-whitespace in the line beyond the
844 if (p[-1] == ' ' || p[-1] == '\t')
846 /* The command is followed by whitespace; we need to
847 complete on whatever comes after command. */
850 /* It is a prefix command; what comes after it is
851 a subcommand (e.g. "info "). */
852 if (reason != handle_brkchars)
853 list = complete_on_cmdlist (*c->prefixlist, p, word,
854 ignore_help_classes);
856 /* Ensure that readline does the right thing
857 with respect to inserting quotes. */
858 set_rl_completer_word_break_characters
859 (gdb_completer_command_word_break_characters);
861 else if (reason == handle_help)
865 if (reason != handle_brkchars)
866 list = complete_on_enum (c->enums, p, word);
867 set_rl_completer_word_break_characters
868 (gdb_completer_command_word_break_characters);
872 /* It is a normal command; what comes after it is
873 completed by the command's completer function. */
874 if (c->completer == filename_completer)
876 /* Many commands which want to complete on
877 file names accept several file names, as
878 in "run foo bar >>baz". So we don't want
879 to complete the entire text after the
880 command, just the last word. To this
881 end, we need to find the beginning of the
882 file name by starting at `word' and going
886 && strchr (gdb_completer_file_name_break_characters, p[-1]) == NULL;
889 set_rl_completer_word_break_characters
890 (gdb_completer_file_name_break_characters);
892 if (reason == handle_brkchars
893 && c->completer_handle_brkchars != NULL)
894 (*c->completer_handle_brkchars) (c, p, word);
895 if (reason != handle_brkchars && c->completer != NULL)
896 list = (*c->completer) (c, p, word);
901 /* The command is not followed by whitespace; we need to
902 complete on the command itself, e.g. "p" which is a
903 command itself but also can complete to "print", "ptype"
907 /* Find the command we are completing on. */
909 while (q > tmp_command)
911 if (isalnum (q[-1]) || q[-1] == '-' || q[-1] == '_')
917 if (reason != handle_brkchars)
918 list = complete_on_cmdlist (result_list, q, word,
919 ignore_help_classes);
921 /* Ensure that readline does the right thing
922 with respect to inserting quotes. */
923 set_rl_completer_word_break_characters
924 (gdb_completer_command_word_break_characters);
927 else if (reason == handle_help)
931 /* There is non-whitespace beyond the command. */
933 if (c->prefixlist && !c->allow_unknown)
935 /* It is an unrecognized subcommand of a prefix command,
936 e.g. "info adsfkdj". */
941 if (reason != handle_brkchars)
942 list = complete_on_enum (c->enums, p, word);
946 /* It is a normal command. */
947 if (c->completer == filename_completer)
949 /* See the commentary above about the specifics
950 of file-name completion. */
953 && strchr (gdb_completer_file_name_break_characters,
957 set_rl_completer_word_break_characters
958 (gdb_completer_file_name_break_characters);
960 if (reason == handle_brkchars
961 && c->completer_handle_brkchars != NULL)
962 (*c->completer_handle_brkchars) (c, p, word);
963 if (reason != handle_brkchars && c->completer != NULL)
964 list = (*c->completer) (c, p, word);
972 /* See completer.h. */
974 int max_completions = 200;
976 /* See completer.h. */
979 new_completion_tracker (void)
981 if (max_completions <= 0)
984 return htab_create_alloc (max_completions,
985 htab_hash_string, (htab_eq) streq,
986 NULL, xcalloc, xfree);
989 /* Cleanup routine to free a completion tracker and reset the pointer
993 free_completion_tracker (void *p)
995 completion_tracker_t *tracker_ptr = (completion_tracker_t *) p;
997 htab_delete (*tracker_ptr);
1001 /* See completer.h. */
1004 make_cleanup_free_completion_tracker (completion_tracker_t *tracker_ptr)
1006 if (*tracker_ptr == NULL)
1007 return make_cleanup (null_cleanup, NULL);
1009 return make_cleanup (free_completion_tracker, tracker_ptr);
1012 /* See completer.h. */
1014 enum maybe_add_completion_enum
1015 maybe_add_completion (completion_tracker_t tracker, char *name)
1019 if (max_completions < 0)
1020 return MAYBE_ADD_COMPLETION_OK;
1021 if (max_completions == 0)
1022 return MAYBE_ADD_COMPLETION_MAX_REACHED;
1024 gdb_assert (tracker != NULL);
1026 if (htab_elements (tracker) >= max_completions)
1027 return MAYBE_ADD_COMPLETION_MAX_REACHED;
1029 slot = htab_find_slot (tracker, name, INSERT);
1031 if (*slot != HTAB_EMPTY_ENTRY)
1032 return MAYBE_ADD_COMPLETION_DUPLICATE;
1036 return (htab_elements (tracker) < max_completions
1037 ? MAYBE_ADD_COMPLETION_OK
1038 : MAYBE_ADD_COMPLETION_OK_MAX_REACHED);
1042 throw_max_completions_reached_error (void)
1044 throw_error (MAX_COMPLETIONS_REACHED_ERROR, _("Max completions reached."));
1047 /* Generate completions all at once. Returns a vector of unique strings
1048 allocated with xmalloc. Returns NULL if there are no completions
1049 or if max_completions is 0. If max_completions is non-negative, this will
1050 return at most max_completions strings.
1052 TEXT is the caller's idea of the "word" we are looking at.
1054 LINE_BUFFER is available to be looked at; it contains the entire
1057 POINT is the offset in that line of the cursor. You
1058 should pretend that the line ends at POINT. */
1061 complete_line (const char *text, const char *line_buffer, int point)
1063 VEC (char_ptr) *list;
1064 VEC (char_ptr) *result = NULL;
1065 struct cleanup *cleanups;
1066 completion_tracker_t tracker;
1068 int ix, max_reached;
1070 if (max_completions == 0)
1072 list = complete_line_internal (text, line_buffer, point,
1073 handle_completions);
1074 if (max_completions < 0)
1077 tracker = new_completion_tracker ();
1078 cleanups = make_cleanup_free_completion_tracker (&tracker);
1079 make_cleanup_free_char_ptr_vec (list);
1081 /* Do a final test for too many completions. Individual completers may
1082 do some of this, but are not required to. Duplicates are also removed
1083 here. Otherwise the user is left scratching his/her head: readline and
1084 complete_command will remove duplicates, and if removal of duplicates
1085 there brings the total under max_completions the user may think gdb quit
1086 searching too early. */
1088 for (ix = 0, max_reached = 0;
1089 !max_reached && VEC_iterate (char_ptr, list, ix, candidate);
1092 enum maybe_add_completion_enum add_status;
1094 add_status = maybe_add_completion (tracker, candidate);
1098 case MAYBE_ADD_COMPLETION_OK:
1099 VEC_safe_push (char_ptr, result, xstrdup (candidate));
1101 case MAYBE_ADD_COMPLETION_OK_MAX_REACHED:
1102 VEC_safe_push (char_ptr, result, xstrdup (candidate));
1105 case MAYBE_ADD_COMPLETION_MAX_REACHED:
1106 gdb_assert_not_reached ("more than max completions reached");
1107 case MAYBE_ADD_COMPLETION_DUPLICATE:
1112 do_cleanups (cleanups);
1117 /* Complete on command names. Used by "help". */
1119 command_completer (struct cmd_list_element *ignore,
1120 const char *text, const char *word)
1122 return complete_line_internal (word, text,
1123 strlen (text), handle_help);
1126 /* Complete on signals. */
1129 signal_completer (struct cmd_list_element *ignore,
1130 const char *text, const char *word)
1132 VEC (char_ptr) *return_val = NULL;
1133 size_t len = strlen (word);
1135 const char *signame;
1137 for (signum = GDB_SIGNAL_FIRST; signum != GDB_SIGNAL_LAST; ++signum)
1139 /* Can't handle this, so skip it. */
1140 if (signum == GDB_SIGNAL_0)
1143 signame = gdb_signal_to_name ((enum gdb_signal) signum);
1145 /* Ignore the unknown signal case. */
1146 if (!signame || strcmp (signame, "?") == 0)
1149 if (strncasecmp (signame, word, len) == 0)
1150 VEC_safe_push (char_ptr, return_val, xstrdup (signame));
1156 /* Bit-flags for selecting what the register and/or register-group
1157 completer should complete on. */
1159 enum reg_completer_target
1161 complete_register_names = 0x1,
1162 complete_reggroup_names = 0x2
1164 DEF_ENUM_FLAGS_TYPE (enum reg_completer_target, reg_completer_targets);
1166 /* Complete register names and/or reggroup names based on the value passed
1167 in TARGETS. At least one bit in TARGETS must be set. */
1169 static VEC (char_ptr) *
1170 reg_or_group_completer_1 (struct cmd_list_element *ignore,
1171 const char *text, const char *word,
1172 reg_completer_targets targets)
1174 VEC (char_ptr) *result = NULL;
1175 size_t len = strlen (word);
1176 struct gdbarch *gdbarch;
1179 gdb_assert ((targets & (complete_register_names
1180 | complete_reggroup_names)) != 0);
1181 gdbarch = get_current_arch ();
1183 if ((targets & complete_register_names) != 0)
1188 (name = user_reg_map_regnum_to_name (gdbarch, i)) != NULL;
1191 if (*name != '\0' && strncmp (word, name, len) == 0)
1192 VEC_safe_push (char_ptr, result, xstrdup (name));
1196 if ((targets & complete_reggroup_names) != 0)
1198 struct reggroup *group;
1200 for (group = reggroup_next (gdbarch, NULL);
1202 group = reggroup_next (gdbarch, group))
1204 name = reggroup_name (group);
1205 if (strncmp (word, name, len) == 0)
1206 VEC_safe_push (char_ptr, result, xstrdup (name));
1213 /* Perform completion on register and reggroup names. */
1216 reg_or_group_completer (struct cmd_list_element *ignore,
1217 const char *text, const char *word)
1219 return reg_or_group_completer_1 (ignore, text, word,
1220 (complete_register_names
1221 | complete_reggroup_names));
1224 /* Perform completion on reggroup names. */
1227 reggroup_completer (struct cmd_list_element *ignore,
1228 const char *text, const char *word)
1230 return reg_or_group_completer_1 (ignore, text, word,
1231 complete_reggroup_names);
1234 /* Get the list of chars that are considered as word breaks
1235 for the current command. */
1238 gdb_completion_word_break_characters (void)
1240 VEC (char_ptr) *list;
1242 list = complete_line_internal (rl_line_buffer, rl_line_buffer, rl_point,
1244 gdb_assert (list == NULL);
1245 return rl_completer_word_break_characters;
1248 /* Generate completions one by one for the completer. Each time we
1249 are called return another potential completion to the caller.
1250 line_completion just completes on commands or passes the buck to
1251 the command's completer function, the stuff specific to symbol
1252 completion is in make_symbol_completion_list.
1254 TEXT is the caller's idea of the "word" we are looking at.
1256 MATCHES is the number of matches that have currently been collected
1257 from calling this completion function. When zero, then we need to
1258 initialize, otherwise the initialization has already taken place
1259 and we can just return the next potential completion string.
1261 LINE_BUFFER is available to be looked at; it contains the entire
1262 text of the line. POINT is the offset in that line of the cursor.
1263 You should pretend that the line ends at POINT.
1265 Returns NULL if there are no more completions, else a pointer to a
1266 string which is a possible completion, it is the caller's
1267 responsibility to free the string. */
1270 line_completion_function (const char *text, int matches,
1271 char *line_buffer, int point)
1273 static VEC (char_ptr) *list = NULL; /* Cache of completions. */
1274 static int index; /* Next cached completion. */
1275 char *output = NULL;
1279 /* The caller is beginning to accumulate a new set of
1280 completions, so we need to find all of them now, and cache
1281 them for returning one at a time on future calls. */
1285 /* Free the storage used by LIST, but not by the strings
1286 inside. This is because rl_complete_internal () frees
1287 the strings. As complete_line may abort by calling
1288 `error' clear LIST now. */
1289 VEC_free (char_ptr, list);
1292 list = complete_line (text, line_buffer, point);
1295 /* If we found a list of potential completions during initialization
1296 then dole them out one at a time. After returning the last one,
1297 return NULL (and continue to do so) each time we are called after
1298 that, until a new list is available. */
1302 if (index < VEC_length (char_ptr, list))
1304 output = VEC_index (char_ptr, list, index);
1310 /* Can't do this because readline hasn't yet checked the word breaks
1311 for figuring out whether to insert a quote. */
1313 /* Make sure the word break characters are set back to normal for
1314 the next time that readline tries to complete something. */
1315 rl_completer_word_break_characters =
1316 current_language->la_word_break_characters();
1322 /* Skip over the possibly quoted word STR (as defined by the quote
1323 characters QUOTECHARS and the word break characters BREAKCHARS).
1324 Returns pointer to the location after the "word". If either
1325 QUOTECHARS or BREAKCHARS is NULL, use the same values used by the
1329 skip_quoted_chars (const char *str, const char *quotechars,
1330 const char *breakchars)
1332 char quote_char = '\0';
1335 if (quotechars == NULL)
1336 quotechars = gdb_completer_quote_characters;
1338 if (breakchars == NULL)
1339 breakchars = current_language->la_word_break_characters();
1341 for (scan = str; *scan != '\0'; scan++)
1343 if (quote_char != '\0')
1345 /* Ignore everything until the matching close quote char. */
1346 if (*scan == quote_char)
1348 /* Found matching close quote. */
1353 else if (strchr (quotechars, *scan))
1355 /* Found start of a quoted string. */
1358 else if (strchr (breakchars, *scan))
1367 /* Skip over the possibly quoted word STR (as defined by the quote
1368 characters and word break characters used by the completer).
1369 Returns pointer to the location after the "word". */
1372 skip_quoted (const char *str)
1374 return skip_quoted_chars (str, NULL, NULL);
1377 /* Return a message indicating that the maximum number of completions
1378 has been reached and that there may be more. */
1381 get_max_completions_reached_message (void)
1383 return _("*** List may be truncated, max-completions reached. ***");
1386 /* GDB replacement for rl_display_match_list.
1387 Readline doesn't provide a clean interface for TUI(curses).
1388 A hack previously used was to send readline's rl_outstream through a pipe
1389 and read it from the event loop. Bleah. IWBN if readline abstracted
1390 away all the necessary bits, and this is what this code does. It
1391 replicates the parts of readline we need and then adds an abstraction
1392 layer, currently implemented as struct match_list_displayer, so that both
1393 CLI and TUI can use it. We copy all this readline code to minimize
1394 GDB-specific mods to readline. Once this code performs as desired then
1395 we can submit it to the readline maintainers.
1397 N.B. A lot of the code is the way it is in order to minimize differences
1398 from readline's copy. */
1400 /* Not supported here. */
1401 #undef VISIBLE_STATS
1403 #if defined (HANDLE_MULTIBYTE)
1404 #define MB_INVALIDCH(x) ((x) == (size_t)-1 || (x) == (size_t)-2)
1405 #define MB_NULLWCH(x) ((x) == 0)
1408 #define ELLIPSIS_LEN 3
1410 /* gdb version of readline/complete.c:get_y_or_n.
1411 'y' -> returns 1, and 'n' -> returns 0.
1412 Also supported: space == 'y', RUBOUT == 'n', ctrl-g == start over.
1413 If FOR_PAGER is non-zero, then also supported are:
1414 NEWLINE or RETURN -> returns 2, and 'q' -> returns 0. */
1417 gdb_get_y_or_n (int for_pager, const struct match_list_displayer *displayer)
1423 RL_SETSTATE (RL_STATE_MOREINPUT);
1424 c = displayer->read_key (displayer);
1425 RL_UNSETSTATE (RL_STATE_MOREINPUT);
1427 if (c == 'y' || c == 'Y' || c == ' ')
1429 if (c == 'n' || c == 'N' || c == RUBOUT)
1431 if (c == ABORT_CHAR || c < 0)
1433 /* Readline doesn't erase_entire_line here, but without it the
1434 --More-- prompt isn't erased and neither is the text entered
1435 thus far redisplayed. */
1436 displayer->erase_entire_line (displayer);
1437 /* Note: The arguments to rl_abort are ignored. */
1440 if (for_pager && (c == NEWLINE || c == RETURN))
1442 if (for_pager && (c == 'q' || c == 'Q'))
1444 displayer->beep (displayer);
1448 /* Pager function for tab-completion.
1449 This is based on readline/complete.c:_rl_internal_pager.
1450 LINES is the number of lines of output displayed thus far.
1452 -1 -> user pressed 'n' or equivalent,
1453 0 -> user pressed 'y' or equivalent,
1454 N -> user pressed NEWLINE or equivalent and N is LINES - 1. */
1457 gdb_display_match_list_pager (int lines,
1458 const struct match_list_displayer *displayer)
1462 displayer->puts (displayer, "--More--");
1463 displayer->flush (displayer);
1464 i = gdb_get_y_or_n (1, displayer);
1465 displayer->erase_entire_line (displayer);
1474 /* Return non-zero if FILENAME is a directory.
1475 Based on readline/complete.c:path_isdir. */
1478 gdb_path_isdir (const char *filename)
1482 return (stat (filename, &finfo) == 0 && S_ISDIR (finfo.st_mode));
1485 /* Return the portion of PATHNAME that should be output when listing
1486 possible completions. If we are hacking filename completion, we
1487 are only interested in the basename, the portion following the
1488 final slash. Otherwise, we return what we were passed. Since
1489 printing empty strings is not very informative, if we're doing
1490 filename completion, and the basename is the empty string, we look
1491 for the previous slash and return the portion following that. If
1492 there's no previous slash, we just return what we were passed.
1494 Based on readline/complete.c:printable_part. */
1497 gdb_printable_part (char *pathname)
1501 if (rl_filename_completion_desired == 0) /* don't need to do anything */
1504 temp = strrchr (pathname, '/');
1505 #if defined (__MSDOS__)
1506 if (temp == 0 && ISALPHA ((unsigned char)pathname[0]) && pathname[1] == ':')
1507 temp = pathname + 1;
1510 if (temp == 0 || *temp == '\0')
1512 /* If the basename is NULL, we might have a pathname like '/usr/src/'.
1513 Look for a previous slash and, if one is found, return the portion
1514 following that slash. If there's no previous slash, just return the
1515 pathname we were passed. */
1516 else if (temp[1] == '\0')
1518 for (x = temp - 1; x > pathname; x--)
1521 return ((*x == '/') ? x + 1 : pathname);
1527 /* Compute width of STRING when displayed on screen by print_filename.
1528 Based on readline/complete.c:fnwidth. */
1531 gdb_fnwidth (const char *string)
1534 #if defined (HANDLE_MULTIBYTE)
1540 left = strlen (string) + 1;
1541 memset (&ps, 0, sizeof (mbstate_t));
1547 if (CTRL_CHAR (string[pos]) || string[pos] == RUBOUT)
1554 #if defined (HANDLE_MULTIBYTE)
1555 clen = mbrtowc (&wc, string + pos, left - pos, &ps);
1556 if (MB_INVALIDCH (clen))
1560 memset (&ps, 0, sizeof (mbstate_t));
1562 else if (MB_NULLWCH (clen))
1568 width += (w >= 0) ? w : 1;
1580 /* Print TO_PRINT, one matching completion.
1581 PREFIX_BYTES is number of common prefix bytes.
1582 Based on readline/complete.c:fnprint. */
1585 gdb_fnprint (const char *to_print, int prefix_bytes,
1586 const struct match_list_displayer *displayer)
1590 #if defined (HANDLE_MULTIBYTE)
1597 end = to_print + strlen (to_print) + 1;
1598 memset (&ps, 0, sizeof (mbstate_t));
1603 /* Don't print only the ellipsis if the common prefix is one of the
1604 possible completions */
1605 if (to_print[prefix_bytes] == '\0')
1612 ellipsis = (to_print[prefix_bytes] == '.') ? '_' : '.';
1613 for (w = 0; w < ELLIPSIS_LEN; w++)
1614 displayer->putch (displayer, ellipsis);
1615 printed_len = ELLIPSIS_LEN;
1618 s = to_print + prefix_bytes;
1623 displayer->putch (displayer, '^');
1624 displayer->putch (displayer, UNCTRL (*s));
1627 #if defined (HANDLE_MULTIBYTE)
1628 memset (&ps, 0, sizeof (mbstate_t));
1631 else if (*s == RUBOUT)
1633 displayer->putch (displayer, '^');
1634 displayer->putch (displayer, '?');
1637 #if defined (HANDLE_MULTIBYTE)
1638 memset (&ps, 0, sizeof (mbstate_t));
1643 #if defined (HANDLE_MULTIBYTE)
1644 tlen = mbrtowc (&wc, s, end - s, &ps);
1645 if (MB_INVALIDCH (tlen))
1649 memset (&ps, 0, sizeof (mbstate_t));
1651 else if (MB_NULLWCH (tlen))
1656 width = (w >= 0) ? w : 1;
1658 for (w = 0; w < tlen; ++w)
1659 displayer->putch (displayer, s[w]);
1661 printed_len += width;
1663 displayer->putch (displayer, *s);
1673 /* Output TO_PRINT to rl_outstream. If VISIBLE_STATS is defined and we
1674 are using it, check for and output a single character for `special'
1675 filenames. Return the number of characters we output.
1676 Based on readline/complete.c:print_filename. */
1679 gdb_print_filename (char *to_print, char *full_pathname, int prefix_bytes,
1680 const struct match_list_displayer *displayer)
1682 int printed_len, extension_char, slen, tlen;
1683 char *s, c, *new_full_pathname;
1685 extern int _rl_complete_mark_directories;
1688 printed_len = gdb_fnprint (to_print, prefix_bytes, displayer);
1690 #if defined (VISIBLE_STATS)
1691 if (rl_filename_completion_desired && (rl_visible_stats || _rl_complete_mark_directories))
1693 if (rl_filename_completion_desired && _rl_complete_mark_directories)
1696 /* If to_print != full_pathname, to_print is the basename of the
1697 path passed. In this case, we try to expand the directory
1698 name before checking for the stat character. */
1699 if (to_print != full_pathname)
1701 /* Terminate the directory name. */
1703 to_print[-1] = '\0';
1705 /* If setting the last slash in full_pathname to a NUL results in
1706 full_pathname being the empty string, we are trying to complete
1707 files in the root directory. If we pass a null string to the
1708 bash directory completion hook, for example, it will expand it
1709 to the current directory. We just want the `/'. */
1710 if (full_pathname == 0 || *full_pathname == 0)
1712 else if (full_pathname[0] != '/')
1714 else if (full_pathname[1] == 0)
1715 dn = "//"; /* restore trailing slash to `//' */
1716 else if (full_pathname[1] == '/' && full_pathname[2] == 0)
1717 dn = "/"; /* don't turn /// into // */
1720 s = tilde_expand (dn);
1721 if (rl_directory_completion_hook)
1722 (*rl_directory_completion_hook) (&s);
1725 tlen = strlen (to_print);
1726 new_full_pathname = (char *)xmalloc (slen + tlen + 2);
1727 strcpy (new_full_pathname, s);
1728 if (s[slen - 1] == '/')
1731 new_full_pathname[slen] = '/';
1732 new_full_pathname[slen] = '/';
1733 strcpy (new_full_pathname + slen + 1, to_print);
1735 #if defined (VISIBLE_STATS)
1736 if (rl_visible_stats)
1737 extension_char = stat_char (new_full_pathname);
1740 if (gdb_path_isdir (new_full_pathname))
1741 extension_char = '/';
1743 xfree (new_full_pathname);
1748 s = tilde_expand (full_pathname);
1749 #if defined (VISIBLE_STATS)
1750 if (rl_visible_stats)
1751 extension_char = stat_char (s);
1754 if (gdb_path_isdir (s))
1755 extension_char = '/';
1761 displayer->putch (displayer, extension_char);
1769 /* GDB version of readline/complete.c:complete_get_screenwidth. */
1772 gdb_complete_get_screenwidth (const struct match_list_displayer *displayer)
1774 /* Readline has other stuff here which it's not clear we need. */
1775 return displayer->width;
1778 extern int _rl_completion_prefix_display_length;
1779 extern int _rl_print_completions_horizontally;
1781 EXTERN_C int _rl_qsort_string_compare (const void *, const void *);
1782 typedef int QSFUNC (const void *, const void *);
1784 /* GDB version of readline/complete.c:rl_display_match_list.
1785 See gdb_display_match_list for a description of MATCHES, LEN, MAX.
1786 Returns non-zero if all matches are displayed. */
1789 gdb_display_match_list_1 (char **matches, int len, int max,
1790 const struct match_list_displayer *displayer)
1792 int count, limit, printed_len, lines, cols;
1793 int i, j, k, l, common_length, sind;
1795 int page_completions = displayer->height != INT_MAX && pagination_enabled;
1797 /* Find the length of the prefix common to all items: length as displayed
1798 characters (common_length) and as a byte index into the matches (sind) */
1799 common_length = sind = 0;
1800 if (_rl_completion_prefix_display_length > 0)
1802 t = gdb_printable_part (matches[0]);
1803 temp = strrchr (t, '/');
1804 common_length = temp ? gdb_fnwidth (temp) : gdb_fnwidth (t);
1805 sind = temp ? strlen (temp) : strlen (t);
1807 if (common_length > _rl_completion_prefix_display_length && common_length > ELLIPSIS_LEN)
1808 max -= common_length - ELLIPSIS_LEN;
1810 common_length = sind = 0;
1813 /* How many items of MAX length can we fit in the screen window? */
1814 cols = gdb_complete_get_screenwidth (displayer);
1817 if (limit != 1 && (limit * max == cols))
1820 /* If cols == 0, limit will end up -1 */
1821 if (cols < displayer->width && limit < 0)
1824 /* Avoid a possible floating exception. If max > cols,
1825 limit will be 0 and a divide-by-zero fault will result. */
1829 /* How many iterations of the printing loop? */
1830 count = (len + (limit - 1)) / limit;
1832 /* Watch out for special case. If LEN is less than LIMIT, then
1833 just do the inner printing loop.
1834 0 < len <= limit implies count = 1. */
1836 /* Sort the items if they are not already sorted. */
1837 if (rl_ignore_completion_duplicates == 0 && rl_sort_completion_matches)
1838 qsort (matches + 1, len, sizeof (char *), (QSFUNC *)_rl_qsort_string_compare);
1840 displayer->crlf (displayer);
1843 if (_rl_print_completions_horizontally == 0)
1845 /* Print the sorted items, up-and-down alphabetically, like ls. */
1846 for (i = 1; i <= count; i++)
1848 for (j = 0, l = i; j < limit; j++)
1850 if (l > len || matches[l] == 0)
1854 temp = gdb_printable_part (matches[l]);
1855 printed_len = gdb_print_filename (temp, matches[l], sind,
1859 for (k = 0; k < max - printed_len; k++)
1860 displayer->putch (displayer, ' ');
1864 displayer->crlf (displayer);
1866 if (page_completions && lines >= (displayer->height - 1) && i < count)
1868 lines = gdb_display_match_list_pager (lines, displayer);
1876 /* Print the sorted items, across alphabetically, like ls -x. */
1877 for (i = 1; matches[i]; i++)
1879 temp = gdb_printable_part (matches[i]);
1880 printed_len = gdb_print_filename (temp, matches[i], sind, displayer);
1881 /* Have we reached the end of this line? */
1884 if (i && (limit > 1) && (i % limit) == 0)
1886 displayer->crlf (displayer);
1888 if (page_completions && lines >= displayer->height - 1)
1890 lines = gdb_display_match_list_pager (lines, displayer);
1896 for (k = 0; k < max - printed_len; k++)
1897 displayer->putch (displayer, ' ');
1900 displayer->crlf (displayer);
1906 /* Utility for displaying completion list matches, used by both CLI and TUI.
1908 MATCHES is the list of strings, in argv format, LEN is the number of
1909 strings in MATCHES, and MAX is the length of the longest string in
1913 gdb_display_match_list (char **matches, int len, int max,
1914 const struct match_list_displayer *displayer)
1916 /* Readline will never call this if complete_line returned NULL. */
1917 gdb_assert (max_completions != 0);
1919 /* complete_line will never return more than this. */
1920 if (max_completions > 0)
1921 gdb_assert (len <= max_completions);
1923 if (rl_completion_query_items > 0 && len >= rl_completion_query_items)
1927 /* We can't use *query here because they wait for <RET> which is
1928 wrong here. This follows the readline version as closely as possible
1929 for compatibility's sake. See readline/complete.c. */
1931 displayer->crlf (displayer);
1933 xsnprintf (msg, sizeof (msg),
1934 "Display all %d possibilities? (y or n)", len);
1935 displayer->puts (displayer, msg);
1936 displayer->flush (displayer);
1938 if (gdb_get_y_or_n (0, displayer) == 0)
1940 displayer->crlf (displayer);
1945 if (gdb_display_match_list_1 (matches, len, max, displayer))
1947 /* Note: MAX_COMPLETIONS may be -1 or zero, but LEN is always > 0. */
1948 if (len == max_completions)
1950 /* The maximum number of completions has been reached. Warn the user
1951 that there may be more. */
1952 const char *message = get_max_completions_reached_message ();
1954 displayer->puts (displayer, message);
1955 displayer->crlf (displayer);
1960 extern initialize_file_ftype _initialize_completer; /* -Wmissing-prototypes */
1963 _initialize_completer (void)
1965 add_setshow_zuinteger_unlimited_cmd ("max-completions", no_class,
1966 &max_completions, _("\
1967 Set maximum number of completion candidates."), _("\
1968 Show maximum number of completion candidates."), _("\
1969 Use this to limit the number of candidates considered\n\
1970 during completion. Specifying \"unlimited\" or -1\n\
1971 disables limiting. Note that setting either no limit or\n\
1972 a very large limit can make completion slow."),
1973 NULL, NULL, &setlist, &showlist);