1 /* Line completion stuff for GDB, the GNU debugger.
2 Copyright (C) 2000-2016 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 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 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
95 /* MS-DOS and MS-Windows use colon as part of the drive spec, and most
96 programs support @foo style response files. */
97 static char *gdb_completer_file_name_break_characters = " \t\n*|\"';?><@";
99 static char *gdb_completer_file_name_break_characters = " \t\n*|\"';:?><";
102 /* Characters that can be used to quote completion strings. Note that
103 we can't include '"' because the gdb C parser treats such quoted
104 sequences as strings. */
105 static char *gdb_completer_quote_characters = "'";
107 /* Accessor for some completer data that may interest other files. */
110 get_gdb_completer_quote_characters (void)
112 return gdb_completer_quote_characters;
115 /* Line completion interface function for readline. */
118 readline_line_completion_function (const char *text, int matches)
120 return line_completion_function (text, matches,
121 rl_line_buffer, rl_point);
124 /* This can be used for functions which don't want to complete on
125 symbols but don't want to complete on anything else either. */
127 noop_completer (struct cmd_list_element *ignore,
128 const char *text, const char *prefix)
133 /* Complete on filenames. */
135 filename_completer (struct cmd_list_element *ignore,
136 const char *text, const char *word)
139 VEC (char_ptr) *return_val = NULL;
146 p = rl_filename_completion_function (text, subsequent_name);
149 /* We need to set subsequent_name to a non-zero value before the
150 continue line below, because otherwise, if the first file
151 seen by GDB is a backup file whose name ends in a `~', we
152 will loop indefinitely. */
154 /* Like emacs, don't complete on old versions. Especially
155 useful in the "source" command. */
156 if (p[strlen (p) - 1] == '~')
163 /* Return exactly p. */
165 else if (word > text)
167 /* Return some portion of p. */
168 q = (char *) xmalloc (strlen (p) + 5);
169 strcpy (q, p + (word - text));
174 /* Return some of TEXT plus p. */
175 q = (char *) xmalloc (strlen (p) + (text - word) + 5);
176 strncpy (q, word, text - word);
177 q[text - word] = '\0';
181 VEC_safe_push (char_ptr, return_val, q);
184 /* There is no way to do this just long enough to affect quote
185 inserting without also affecting the next completion. This
186 should be fixed in readline. FIXME. */
187 /* Ensure that readline does the right thing
188 with respect to inserting quotes. */
189 rl_completer_word_break_characters = "";
194 /* Complete on linespecs, which might be of two possible forms:
200 This is intended to be used in commands that set breakpoints
203 static VEC (char_ptr) *
204 linespec_location_completer (struct cmd_list_element *ignore,
205 const char *text, const char *word)
207 int n_syms, n_files, ix;
208 VEC (char_ptr) *fn_list = NULL;
209 VEC (char_ptr) *list = NULL;
212 int quoted = *text == '\'' || *text == '"';
213 int quote_char = '\0';
214 const char *colon = NULL;
215 char *file_to_match = NULL;
216 const char *symbol_start = text;
217 const char *orig_text = text;
220 /* Do we have an unquoted colon, as in "break foo.c:bar"? */
221 for (p = text; *p != '\0'; ++p)
223 if (*p == '\\' && p[1] == '\'')
225 else if (*p == '\'' || *p == '"')
229 while (*p != '\0' && *p != quote_found)
231 if (*p == '\\' && p[1] == quote_found)
236 if (*p == quote_found)
239 break; /* Hit the end of text. */
241 #if HAVE_DOS_BASED_FILE_SYSTEM
242 /* If we have a DOS-style absolute file name at the beginning of
243 TEXT, and the colon after the drive letter is the only colon
244 we found, pretend the colon is not there. */
245 else if (p < text + 3 && *p == ':' && p == text + 1 + quoted)
248 else if (*p == ':' && !colon)
251 symbol_start = p + 1;
253 else if (strchr (current_language->la_word_break_characters(), *p))
254 symbol_start = p + 1;
259 text_len = strlen (text);
261 /* Where is the file name? */
266 file_to_match = (char *) xmalloc (colon - text + 1);
267 strncpy (file_to_match, text, colon - text + 1);
268 /* Remove trailing colons and quotes from the file name. */
269 for (s = file_to_match + (colon - text);
272 if (*s == ':' || *s == quote_char)
275 /* If the text includes a colon, they want completion only on a
276 symbol name after the colon. Otherwise, we need to complete on
277 symbols as well as on files. */
280 list = make_file_symbol_completion_list (symbol_start, word,
282 xfree (file_to_match);
286 list = make_symbol_completion_list (symbol_start, word);
287 /* If text includes characters which cannot appear in a file
288 name, they cannot be asking for completion on files. */
290 gdb_completer_file_name_break_characters) == text_len)
291 fn_list = make_source_files_completion_list (text, text);
294 n_syms = VEC_length (char_ptr, list);
295 n_files = VEC_length (char_ptr, fn_list);
297 /* Catenate fn_list[] onto the end of list[]. */
300 VEC_free (char_ptr, list); /* Paranoia. */
308 for (ix = 0; VEC_iterate (char_ptr, fn_list, ix, fn); ++ix)
309 VEC_safe_push (char_ptr, list, fn);
310 VEC_free (char_ptr, fn_list);
313 if (n_syms && n_files)
321 /* If we only have file names as possible completion, we should
322 bring them in sync with what rl_complete expects. The
323 problem is that if the user types "break /foo/b TAB", and the
324 possible completions are "/foo/bar" and "/foo/baz"
325 rl_complete expects us to return "bar" and "baz", without the
326 leading directories, as possible completions, because `word'
327 starts at the "b". But we ignore the value of `word' when we
328 call make_source_files_completion_list above (because that
329 would not DTRT when the completion results in both symbols
330 and file names), so make_source_files_completion_list returns
331 the full "/foo/bar" and "/foo/baz" strings. This produces
332 wrong results when, e.g., there's only one possible
333 completion, because rl_complete will prepend "/foo/" to each
334 candidate completion. The loop below removes that leading
336 for (ix = 0; VEC_iterate (char_ptr, list, ix, fn); ++ix)
338 memmove (fn, fn + (word - text),
339 strlen (fn) + 1 - (word - text));
344 /* No completions at all. As the final resort, try completing
345 on the entire text as a symbol. */
346 list = make_symbol_completion_list (orig_text, word);
352 /* A helper function to collect explicit location matches for the given
353 LOCATION, which is attempting to match on WORD. */
355 static VEC (char_ptr) *
356 collect_explicit_location_matches (struct event_location *location,
357 enum explicit_location_match_type what,
360 VEC (char_ptr) *matches = NULL;
361 const struct explicit_location *explicit_loc
362 = get_explicit_location (location);
368 const char *text = (explicit_loc->source_filename == NULL
369 ? "" : explicit_loc->source_filename);
371 matches = make_source_files_completion_list (text, word);
377 const char *text = (explicit_loc->function_name == NULL
378 ? "" : explicit_loc->function_name);
380 if (explicit_loc->source_filename != NULL)
382 const char *filename = explicit_loc->source_filename;
384 matches = make_file_symbol_completion_list (text, word, filename);
387 matches = make_symbol_completion_list (text, word);
396 gdb_assert_not_reached ("unhandled explicit_location_match_type");
402 /* A convenience macro to (safely) back up P to the previous word. */
405 backup_text_ptr (const char *p, const char *text)
407 while (p > text && isspace (*p))
409 for (; p > text && !isspace (p[-1]); --p)
415 /* A completer function for explicit locations. This function
416 completes both options ("-source", "-line", etc) and values. */
418 static VEC (char_ptr) *
419 explicit_location_completer (struct cmd_list_element *ignore,
420 struct event_location *location,
421 const char *text, const char *word)
424 VEC (char_ptr) *matches = NULL;
426 /* Find the beginning of the word. This is necessary because
427 we need to know if we are completing an option name or value. We
428 don't get the leading '-' from the completer. */
429 p = backup_text_ptr (word, text);
433 /* Completing on option name. */
434 static const char *const keywords[] =
443 /* Skip over the '-'. */
446 return complete_on_enum (keywords, p, p);
450 /* Completing on value (or unknown). Get the previous word to see what
451 the user is completing on. */
453 const char *new_word, *end;
454 enum explicit_location_match_type what;
455 struct explicit_location *explicit_loc
456 = get_explicit_location (location);
458 /* Backup P to the previous word, which should be the option
459 the user is attempting to complete. */
462 p = backup_text_ptr (p, text);
465 if (strncmp (p, "-source", len) == 0)
468 new_word = explicit_loc->source_filename + offset;
470 else if (strncmp (p, "-function", len) == 0)
472 what = MATCH_FUNCTION;
473 new_word = explicit_loc->function_name + offset;
475 else if (strncmp (p, "-label", len) == 0)
478 new_word = explicit_loc->label_name + offset;
482 /* The user isn't completing on any valid option name,
483 e.g., "break -source foo.c [tab]". */
487 /* If the user hasn't entered a search expression, e.g.,
488 "break -function <TAB><TAB>", new_word will be NULL, but
489 search routines require non-NULL search words. */
490 if (new_word == NULL)
493 /* Now gather matches */
494 matches = collect_explicit_location_matches (location, what, new_word);
500 /* A completer for locations. */
503 location_completer (struct cmd_list_element *ignore,
504 const char *text, const char *word)
506 VEC (char_ptr) *matches = NULL;
507 const char *copy = text;
508 struct event_location *location;
510 location = string_to_explicit_location (©, current_language, 1);
511 if (location != NULL)
513 struct cleanup *cleanup;
515 cleanup = make_cleanup_delete_event_location (location);
516 matches = explicit_location_completer (ignore, location, text, word);
517 do_cleanups (cleanup);
521 /* This is an address or linespec location.
522 Right now both of these are handled by the (old) linespec
524 matches = linespec_location_completer (ignore, text, word);
530 /* Helper for expression_completer which recursively adds field and
531 method names from TYPE, a struct or union type, to the array
534 add_struct_fields (struct type *type, VEC (char_ptr) **output,
535 char *fieldname, int namelen)
538 int computed_type_name = 0;
539 const char *type_name = NULL;
541 type = check_typedef (type);
542 for (i = 0; i < TYPE_NFIELDS (type); ++i)
544 if (i < TYPE_N_BASECLASSES (type))
545 add_struct_fields (TYPE_BASECLASS (type, i),
546 output, fieldname, namelen);
547 else if (TYPE_FIELD_NAME (type, i))
549 if (TYPE_FIELD_NAME (type, i)[0] != '\0')
551 if (! strncmp (TYPE_FIELD_NAME (type, i),
553 VEC_safe_push (char_ptr, *output,
554 xstrdup (TYPE_FIELD_NAME (type, i)));
556 else if (TYPE_CODE (TYPE_FIELD_TYPE (type, i)) == TYPE_CODE_UNION)
558 /* Recurse into anonymous unions. */
559 add_struct_fields (TYPE_FIELD_TYPE (type, i),
560 output, fieldname, namelen);
565 for (i = TYPE_NFN_FIELDS (type) - 1; i >= 0; --i)
567 const char *name = TYPE_FN_FIELDLIST_NAME (type, i);
569 if (name && ! strncmp (name, fieldname, namelen))
571 if (!computed_type_name)
573 type_name = type_name_no_tag (type);
574 computed_type_name = 1;
576 /* Omit constructors from the completion list. */
577 if (!type_name || strcmp (type_name, name))
578 VEC_safe_push (char_ptr, *output, xstrdup (name));
583 /* Complete on expressions. Often this means completing on symbol
584 names, but some language parsers also have support for completing
587 expression_completer (struct cmd_list_element *ignore,
588 const char *text, const char *word)
590 struct type *type = NULL;
593 enum type_code code = TYPE_CODE_UNDEF;
595 /* Perform a tentative parse of the expression, to see whether a
596 field completion is required. */
600 type = parse_expression_for_completion (text, &fieldname, &code);
602 CATCH (except, RETURN_MASK_ERROR)
608 if (fieldname && type)
612 type = check_typedef (type);
613 if (TYPE_CODE (type) != TYPE_CODE_PTR
614 && TYPE_CODE (type) != TYPE_CODE_REF)
616 type = TYPE_TARGET_TYPE (type);
619 if (TYPE_CODE (type) == TYPE_CODE_UNION
620 || TYPE_CODE (type) == TYPE_CODE_STRUCT)
622 int flen = strlen (fieldname);
623 VEC (char_ptr) *result = NULL;
625 add_struct_fields (type, &result, fieldname, flen);
630 else if (fieldname && code != TYPE_CODE_UNDEF)
632 VEC (char_ptr) *result;
633 struct cleanup *cleanup = make_cleanup (xfree, fieldname);
635 result = make_symbol_completion_type (fieldname, fieldname, code);
636 do_cleanups (cleanup);
641 /* Commands which complete on locations want to see the entire
644 p > text && p[-1] != ' ' && p[-1] != '\t';
648 /* Not ideal but it is what we used to do before... */
649 return location_completer (ignore, p, word);
652 /* See definition in completer.h. */
655 set_gdb_completion_word_break_characters (completer_ftype *fn)
657 /* So far we are only interested in differentiating filename
658 completers from everything else. */
659 if (fn == filename_completer)
660 rl_completer_word_break_characters
661 = gdb_completer_file_name_break_characters;
663 rl_completer_word_break_characters
664 = gdb_completer_command_word_break_characters;
667 /* Here are some useful test cases for completion. FIXME: These
668 should be put in the test suite. They should be tested with both
671 "show output-" "radix"
672 "show output" "-radix"
673 "p" ambiguous (commands starting with p--path, print, printf, etc.)
674 "p " ambiguous (all symbols)
675 "info t foo" no completions
676 "info t " no completions
677 "info t" ambiguous ("info target", "info terminal", etc.)
678 "info ajksdlfk" no completions
679 "info ajksdlfk " no completions
681 "info " ambiguous (all info commands)
682 "p \"a" no completions (string constant)
683 "p 'a" ambiguous (all symbols starting with a)
684 "p b-a" ambiguous (all symbols starting with a)
685 "p b-" ambiguous (all symbols)
686 "file Make" "file" (word break hard to screw up here)
687 "file ../gdb.stabs/we" "ird" (needs to not break word at slash)
696 complete_line_internal_reason;
699 /* Internal function used to handle completions.
702 TEXT is the caller's idea of the "word" we are looking at.
704 LINE_BUFFER is available to be looked at; it contains the entire
705 text of the line. POINT is the offset in that line of the cursor.
706 You should pretend that the line ends at POINT.
708 REASON is of type complete_line_internal_reason.
710 If REASON is handle_brkchars:
711 Preliminary phase, called by gdb_completion_word_break_characters
712 function, is used to determine the correct set of chars that are
713 word delimiters depending on the current command in line_buffer.
714 No completion list should be generated; the return value should be
715 NULL. This is checked by an assertion in that function.
717 If REASON is handle_completions:
718 Main phase, called by complete_line function, is used to get the list
719 of posible completions.
721 If REASON is handle_help:
722 Special case when completing a 'help' command. In this case,
723 once sub-command completions are exhausted, we simply return NULL.
726 static VEC (char_ptr) *
727 complete_line_internal (const char *text,
728 const char *line_buffer, int point,
729 complete_line_internal_reason reason)
731 VEC (char_ptr) *list = NULL;
734 int ignore_help_classes;
735 /* Pointer within tmp_command which corresponds to text. */
737 struct cmd_list_element *c, *result_list;
739 /* Choose the default set of word break characters to break
740 completions. If we later find out that we are doing completions
741 on command strings (as opposed to strings supplied by the
742 individual command completer functions, which can be any string)
743 then we will switch to the special word break set for command
744 strings, which leaves out the '-' character used in some
746 rl_completer_word_break_characters =
747 current_language->la_word_break_characters();
749 /* Decide whether to complete on a list of gdb commands or on
751 tmp_command = (char *) alloca (point + 1);
754 /* The help command should complete help aliases. */
755 ignore_help_classes = reason != handle_help;
757 strncpy (tmp_command, line_buffer, point);
758 tmp_command[point] = '\0';
759 /* Since text always contains some number of characters leading up
760 to point, we can find the equivalent position in tmp_command
761 by subtracting that many characters from the end of tmp_command. */
762 word = tmp_command + point - strlen (text);
766 /* An empty line we want to consider ambiguous; that is, it
767 could be any command. */
768 c = CMD_LIST_AMBIGUOUS;
773 c = lookup_cmd_1 (&p, cmdlist, &result_list, ignore_help_classes);
776 /* Move p up to the next interesting thing. */
777 while (*p == ' ' || *p == '\t')
784 /* It is an unrecognized command. So there are no
785 possible completions. */
788 else if (c == CMD_LIST_AMBIGUOUS)
792 /* lookup_cmd_1 advances p up to the first ambiguous thing, but
793 doesn't advance over that thing itself. Do so now. */
795 while (*q && (isalnum (*q) || *q == '-' || *q == '_'))
797 if (q != tmp_command + point)
799 /* There is something beyond the ambiguous
800 command, so there are no possible completions. For
801 example, "info t " or "info t foo" does not complete
802 to anything, because "info t" can be "info target" or
808 /* We're trying to complete on the command which was ambiguous.
809 This we can deal with. */
812 if (reason != handle_brkchars)
813 list = complete_on_cmdlist (*result_list->prefixlist, p,
814 word, ignore_help_classes);
818 if (reason != handle_brkchars)
819 list = complete_on_cmdlist (cmdlist, p, word,
820 ignore_help_classes);
822 /* Ensure that readline does the right thing with respect to
824 rl_completer_word_break_characters =
825 gdb_completer_command_word_break_characters;
830 /* We've recognized a full command. */
832 if (p == tmp_command + point)
834 /* There is no non-whitespace in the line beyond the
837 if (p[-1] == ' ' || p[-1] == '\t')
839 /* The command is followed by whitespace; we need to
840 complete on whatever comes after command. */
843 /* It is a prefix command; what comes after it is
844 a subcommand (e.g. "info "). */
845 if (reason != handle_brkchars)
846 list = complete_on_cmdlist (*c->prefixlist, p, word,
847 ignore_help_classes);
849 /* Ensure that readline does the right thing
850 with respect to inserting quotes. */
851 rl_completer_word_break_characters =
852 gdb_completer_command_word_break_characters;
854 else if (reason == handle_help)
858 if (reason != handle_brkchars)
859 list = complete_on_enum (c->enums, p, word);
860 rl_completer_word_break_characters =
861 gdb_completer_command_word_break_characters;
865 /* It is a normal command; what comes after it is
866 completed by the command's completer function. */
867 if (c->completer == filename_completer)
869 /* Many commands which want to complete on
870 file names accept several file names, as
871 in "run foo bar >>baz". So we don't want
872 to complete the entire text after the
873 command, just the last word. To this
874 end, we need to find the beginning of the
875 file name by starting at `word' and going
879 && strchr (gdb_completer_file_name_break_characters, p[-1]) == NULL;
882 rl_completer_word_break_characters =
883 gdb_completer_file_name_break_characters;
885 if (reason == handle_brkchars
886 && c->completer_handle_brkchars != NULL)
887 (*c->completer_handle_brkchars) (c, p, word);
888 if (reason != handle_brkchars && c->completer != NULL)
889 list = (*c->completer) (c, p, word);
894 /* The command is not followed by whitespace; we need to
895 complete on the command itself, e.g. "p" which is a
896 command itself but also can complete to "print", "ptype"
900 /* Find the command we are completing on. */
902 while (q > tmp_command)
904 if (isalnum (q[-1]) || q[-1] == '-' || q[-1] == '_')
910 if (reason != handle_brkchars)
911 list = complete_on_cmdlist (result_list, q, word,
912 ignore_help_classes);
914 /* Ensure that readline does the right thing
915 with respect to inserting quotes. */
916 rl_completer_word_break_characters =
917 gdb_completer_command_word_break_characters;
920 else if (reason == handle_help)
924 /* There is non-whitespace beyond the command. */
926 if (c->prefixlist && !c->allow_unknown)
928 /* It is an unrecognized subcommand of a prefix command,
929 e.g. "info adsfkdj". */
934 if (reason != handle_brkchars)
935 list = complete_on_enum (c->enums, p, word);
939 /* It is a normal command. */
940 if (c->completer == filename_completer)
942 /* See the commentary above about the specifics
943 of file-name completion. */
946 && strchr (gdb_completer_file_name_break_characters,
950 rl_completer_word_break_characters =
951 gdb_completer_file_name_break_characters;
953 if (reason == handle_brkchars
954 && c->completer_handle_brkchars != NULL)
955 (*c->completer_handle_brkchars) (c, p, word);
956 if (reason != handle_brkchars && c->completer != NULL)
957 list = (*c->completer) (c, p, word);
965 /* See completer.h. */
967 int max_completions = 200;
969 /* See completer.h. */
972 new_completion_tracker (void)
974 if (max_completions <= 0)
977 return htab_create_alloc (max_completions,
978 htab_hash_string, (htab_eq) streq,
979 NULL, xcalloc, xfree);
982 /* Cleanup routine to free a completion tracker and reset the pointer
986 free_completion_tracker (void *p)
988 completion_tracker_t *tracker_ptr = (completion_tracker_t *) p;
990 htab_delete (*tracker_ptr);
994 /* See completer.h. */
997 make_cleanup_free_completion_tracker (completion_tracker_t *tracker_ptr)
999 if (*tracker_ptr == NULL)
1000 return make_cleanup (null_cleanup, NULL);
1002 return make_cleanup (free_completion_tracker, tracker_ptr);
1005 /* See completer.h. */
1007 enum maybe_add_completion_enum
1008 maybe_add_completion (completion_tracker_t tracker, char *name)
1012 if (max_completions < 0)
1013 return MAYBE_ADD_COMPLETION_OK;
1014 if (max_completions == 0)
1015 return MAYBE_ADD_COMPLETION_MAX_REACHED;
1017 gdb_assert (tracker != NULL);
1019 if (htab_elements (tracker) >= max_completions)
1020 return MAYBE_ADD_COMPLETION_MAX_REACHED;
1022 slot = htab_find_slot (tracker, name, INSERT);
1024 if (*slot != HTAB_EMPTY_ENTRY)
1025 return MAYBE_ADD_COMPLETION_DUPLICATE;
1029 return (htab_elements (tracker) < max_completions
1030 ? MAYBE_ADD_COMPLETION_OK
1031 : MAYBE_ADD_COMPLETION_OK_MAX_REACHED);
1035 throw_max_completions_reached_error (void)
1037 throw_error (MAX_COMPLETIONS_REACHED_ERROR, _("Max completions reached."));
1040 /* Generate completions all at once. Returns a vector of unique strings
1041 allocated with xmalloc. Returns NULL if there are no completions
1042 or if max_completions is 0. If max_completions is non-negative, this will
1043 return at most max_completions strings.
1045 TEXT is the caller's idea of the "word" we are looking at.
1047 LINE_BUFFER is available to be looked at; it contains the entire
1050 POINT is the offset in that line of the cursor. You
1051 should pretend that the line ends at POINT. */
1054 complete_line (const char *text, const char *line_buffer, int point)
1056 VEC (char_ptr) *list;
1057 VEC (char_ptr) *result = NULL;
1058 struct cleanup *cleanups;
1059 completion_tracker_t tracker;
1061 int ix, max_reached;
1063 if (max_completions == 0)
1065 list = complete_line_internal (text, line_buffer, point,
1066 handle_completions);
1067 if (max_completions < 0)
1070 tracker = new_completion_tracker ();
1071 cleanups = make_cleanup_free_completion_tracker (&tracker);
1072 make_cleanup_free_char_ptr_vec (list);
1074 /* Do a final test for too many completions. Individual completers may
1075 do some of this, but are not required to. Duplicates are also removed
1076 here. Otherwise the user is left scratching his/her head: readline and
1077 complete_command will remove duplicates, and if removal of duplicates
1078 there brings the total under max_completions the user may think gdb quit
1079 searching too early. */
1081 for (ix = 0, max_reached = 0;
1082 !max_reached && VEC_iterate (char_ptr, list, ix, candidate);
1085 enum maybe_add_completion_enum add_status;
1087 add_status = maybe_add_completion (tracker, candidate);
1091 case MAYBE_ADD_COMPLETION_OK:
1092 VEC_safe_push (char_ptr, result, xstrdup (candidate));
1094 case MAYBE_ADD_COMPLETION_OK_MAX_REACHED:
1095 VEC_safe_push (char_ptr, result, xstrdup (candidate));
1098 case MAYBE_ADD_COMPLETION_MAX_REACHED:
1099 gdb_assert_not_reached ("more than max completions reached");
1100 case MAYBE_ADD_COMPLETION_DUPLICATE:
1105 do_cleanups (cleanups);
1110 /* Complete on command names. Used by "help". */
1112 command_completer (struct cmd_list_element *ignore,
1113 const char *text, const char *word)
1115 return complete_line_internal (word, text,
1116 strlen (text), handle_help);
1119 /* Complete on signals. */
1122 signal_completer (struct cmd_list_element *ignore,
1123 const char *text, const char *word)
1125 VEC (char_ptr) *return_val = NULL;
1126 size_t len = strlen (word);
1128 const char *signame;
1130 for (signum = GDB_SIGNAL_FIRST; signum != GDB_SIGNAL_LAST; ++signum)
1132 /* Can't handle this, so skip it. */
1133 if (signum == GDB_SIGNAL_0)
1136 signame = gdb_signal_to_name ((enum gdb_signal) signum);
1138 /* Ignore the unknown signal case. */
1139 if (!signame || strcmp (signame, "?") == 0)
1142 if (strncasecmp (signame, word, len) == 0)
1143 VEC_safe_push (char_ptr, return_val, xstrdup (signame));
1149 /* Bit-flags for selecting what the register and/or register-group
1150 completer should complete on. */
1152 enum reg_completer_target
1154 complete_register_names = 0x1,
1155 complete_reggroup_names = 0x2
1157 DEF_ENUM_FLAGS_TYPE (enum reg_completer_target, reg_completer_targets);
1159 /* Complete register names and/or reggroup names based on the value passed
1160 in TARGETS. At least one bit in TARGETS must be set. */
1162 static VEC (char_ptr) *
1163 reg_or_group_completer_1 (struct cmd_list_element *ignore,
1164 const char *text, const char *word,
1165 reg_completer_targets targets)
1167 VEC (char_ptr) *result = NULL;
1168 size_t len = strlen (word);
1169 struct gdbarch *gdbarch;
1172 gdb_assert ((targets & (complete_register_names
1173 | complete_reggroup_names)) != 0);
1174 gdbarch = get_current_arch ();
1176 if ((targets & complete_register_names) != 0)
1181 (name = user_reg_map_regnum_to_name (gdbarch, i)) != NULL;
1184 if (*name != '\0' && strncmp (word, name, len) == 0)
1185 VEC_safe_push (char_ptr, result, xstrdup (name));
1189 if ((targets & complete_reggroup_names) != 0)
1191 struct reggroup *group;
1193 for (group = reggroup_next (gdbarch, NULL);
1195 group = reggroup_next (gdbarch, group))
1197 name = reggroup_name (group);
1198 if (strncmp (word, name, len) == 0)
1199 VEC_safe_push (char_ptr, result, xstrdup (name));
1206 /* Perform completion on register and reggroup names. */
1209 reg_or_group_completer (struct cmd_list_element *ignore,
1210 const char *text, const char *word)
1212 return reg_or_group_completer_1 (ignore, text, word,
1213 (complete_register_names
1214 | complete_reggroup_names));
1217 /* Perform completion on reggroup names. */
1220 reggroup_completer (struct cmd_list_element *ignore,
1221 const char *text, const char *word)
1223 return reg_or_group_completer_1 (ignore, text, word,
1224 complete_reggroup_names);
1227 /* Get the list of chars that are considered as word breaks
1228 for the current command. */
1231 gdb_completion_word_break_characters (void)
1233 VEC (char_ptr) *list;
1235 list = complete_line_internal (rl_line_buffer, rl_line_buffer, rl_point,
1237 gdb_assert (list == NULL);
1238 return rl_completer_word_break_characters;
1241 /* Generate completions one by one for the completer. Each time we
1242 are called return another potential completion to the caller.
1243 line_completion just completes on commands or passes the buck to
1244 the command's completer function, the stuff specific to symbol
1245 completion is in make_symbol_completion_list.
1247 TEXT is the caller's idea of the "word" we are looking at.
1249 MATCHES is the number of matches that have currently been collected
1250 from calling this completion function. When zero, then we need to
1251 initialize, otherwise the initialization has already taken place
1252 and we can just return the next potential completion string.
1254 LINE_BUFFER is available to be looked at; it contains the entire
1255 text of the line. POINT is the offset in that line of the cursor.
1256 You should pretend that the line ends at POINT.
1258 Returns NULL if there are no more completions, else a pointer to a
1259 string which is a possible completion, it is the caller's
1260 responsibility to free the string. */
1263 line_completion_function (const char *text, int matches,
1264 char *line_buffer, int point)
1266 static VEC (char_ptr) *list = NULL; /* Cache of completions. */
1267 static int index; /* Next cached completion. */
1268 char *output = NULL;
1272 /* The caller is beginning to accumulate a new set of
1273 completions, so we need to find all of them now, and cache
1274 them for returning one at a time on future calls. */
1278 /* Free the storage used by LIST, but not by the strings
1279 inside. This is because rl_complete_internal () frees
1280 the strings. As complete_line may abort by calling
1281 `error' clear LIST now. */
1282 VEC_free (char_ptr, list);
1285 list = complete_line (text, line_buffer, point);
1288 /* If we found a list of potential completions during initialization
1289 then dole them out one at a time. After returning the last one,
1290 return NULL (and continue to do so) each time we are called after
1291 that, until a new list is available. */
1295 if (index < VEC_length (char_ptr, list))
1297 output = VEC_index (char_ptr, list, index);
1303 /* Can't do this because readline hasn't yet checked the word breaks
1304 for figuring out whether to insert a quote. */
1306 /* Make sure the word break characters are set back to normal for
1307 the next time that readline tries to complete something. */
1308 rl_completer_word_break_characters =
1309 current_language->la_word_break_characters();
1315 /* Skip over the possibly quoted word STR (as defined by the quote
1316 characters QUOTECHARS and the word break characters BREAKCHARS).
1317 Returns pointer to the location after the "word". If either
1318 QUOTECHARS or BREAKCHARS is NULL, use the same values used by the
1322 skip_quoted_chars (const char *str, const char *quotechars,
1323 const char *breakchars)
1325 char quote_char = '\0';
1328 if (quotechars == NULL)
1329 quotechars = gdb_completer_quote_characters;
1331 if (breakchars == NULL)
1332 breakchars = current_language->la_word_break_characters();
1334 for (scan = str; *scan != '\0'; scan++)
1336 if (quote_char != '\0')
1338 /* Ignore everything until the matching close quote char. */
1339 if (*scan == quote_char)
1341 /* Found matching close quote. */
1346 else if (strchr (quotechars, *scan))
1348 /* Found start of a quoted string. */
1351 else if (strchr (breakchars, *scan))
1360 /* Skip over the possibly quoted word STR (as defined by the quote
1361 characters and word break characters used by the completer).
1362 Returns pointer to the location after the "word". */
1365 skip_quoted (const char *str)
1367 return skip_quoted_chars (str, NULL, NULL);
1370 /* Return a message indicating that the maximum number of completions
1371 has been reached and that there may be more. */
1374 get_max_completions_reached_message (void)
1376 return _("*** List may be truncated, max-completions reached. ***");
1379 /* GDB replacement for rl_display_match_list.
1380 Readline doesn't provide a clean interface for TUI(curses).
1381 A hack previously used was to send readline's rl_outstream through a pipe
1382 and read it from the event loop. Bleah. IWBN if readline abstracted
1383 away all the necessary bits, and this is what this code does. It
1384 replicates the parts of readline we need and then adds an abstraction
1385 layer, currently implemented as struct match_list_displayer, so that both
1386 CLI and TUI can use it. We copy all this readline code to minimize
1387 GDB-specific mods to readline. Once this code performs as desired then
1388 we can submit it to the readline maintainers.
1390 N.B. A lot of the code is the way it is in order to minimize differences
1391 from readline's copy. */
1393 /* Not supported here. */
1394 #undef VISIBLE_STATS
1396 #if defined (HANDLE_MULTIBYTE)
1397 #define MB_INVALIDCH(x) ((x) == (size_t)-1 || (x) == (size_t)-2)
1398 #define MB_NULLWCH(x) ((x) == 0)
1401 #define ELLIPSIS_LEN 3
1403 /* gdb version of readline/complete.c:get_y_or_n.
1404 'y' -> returns 1, and 'n' -> returns 0.
1405 Also supported: space == 'y', RUBOUT == 'n', ctrl-g == start over.
1406 If FOR_PAGER is non-zero, then also supported are:
1407 NEWLINE or RETURN -> returns 2, and 'q' -> returns 0. */
1410 gdb_get_y_or_n (int for_pager, const struct match_list_displayer *displayer)
1416 RL_SETSTATE (RL_STATE_MOREINPUT);
1417 c = displayer->read_key (displayer);
1418 RL_UNSETSTATE (RL_STATE_MOREINPUT);
1420 if (c == 'y' || c == 'Y' || c == ' ')
1422 if (c == 'n' || c == 'N' || c == RUBOUT)
1424 if (c == ABORT_CHAR || c < 0)
1426 /* Readline doesn't erase_entire_line here, but without it the
1427 --More-- prompt isn't erased and neither is the text entered
1428 thus far redisplayed. */
1429 displayer->erase_entire_line (displayer);
1430 /* Note: The arguments to rl_abort are ignored. */
1433 if (for_pager && (c == NEWLINE || c == RETURN))
1435 if (for_pager && (c == 'q' || c == 'Q'))
1437 displayer->beep (displayer);
1441 /* Pager function for tab-completion.
1442 This is based on readline/complete.c:_rl_internal_pager.
1443 LINES is the number of lines of output displayed thus far.
1445 -1 -> user pressed 'n' or equivalent,
1446 0 -> user pressed 'y' or equivalent,
1447 N -> user pressed NEWLINE or equivalent and N is LINES - 1. */
1450 gdb_display_match_list_pager (int lines,
1451 const struct match_list_displayer *displayer)
1455 displayer->puts (displayer, "--More--");
1456 displayer->flush (displayer);
1457 i = gdb_get_y_or_n (1, displayer);
1458 displayer->erase_entire_line (displayer);
1467 /* Return non-zero if FILENAME is a directory.
1468 Based on readline/complete.c:path_isdir. */
1471 gdb_path_isdir (const char *filename)
1475 return (stat (filename, &finfo) == 0 && S_ISDIR (finfo.st_mode));
1478 /* Return the portion of PATHNAME that should be output when listing
1479 possible completions. If we are hacking filename completion, we
1480 are only interested in the basename, the portion following the
1481 final slash. Otherwise, we return what we were passed. Since
1482 printing empty strings is not very informative, if we're doing
1483 filename completion, and the basename is the empty string, we look
1484 for the previous slash and return the portion following that. If
1485 there's no previous slash, we just return what we were passed.
1487 Based on readline/complete.c:printable_part. */
1490 gdb_printable_part (char *pathname)
1494 if (rl_filename_completion_desired == 0) /* don't need to do anything */
1497 temp = strrchr (pathname, '/');
1498 #if defined (__MSDOS__)
1499 if (temp == 0 && ISALPHA ((unsigned char)pathname[0]) && pathname[1] == ':')
1500 temp = pathname + 1;
1503 if (temp == 0 || *temp == '\0')
1505 /* If the basename is NULL, we might have a pathname like '/usr/src/'.
1506 Look for a previous slash and, if one is found, return the portion
1507 following that slash. If there's no previous slash, just return the
1508 pathname we were passed. */
1509 else if (temp[1] == '\0')
1511 for (x = temp - 1; x > pathname; x--)
1514 return ((*x == '/') ? x + 1 : pathname);
1520 /* Compute width of STRING when displayed on screen by print_filename.
1521 Based on readline/complete.c:fnwidth. */
1524 gdb_fnwidth (const char *string)
1527 #if defined (HANDLE_MULTIBYTE)
1533 left = strlen (string) + 1;
1534 memset (&ps, 0, sizeof (mbstate_t));
1540 if (CTRL_CHAR (string[pos]) || string[pos] == RUBOUT)
1547 #if defined (HANDLE_MULTIBYTE)
1548 clen = mbrtowc (&wc, string + pos, left - pos, &ps);
1549 if (MB_INVALIDCH (clen))
1553 memset (&ps, 0, sizeof (mbstate_t));
1555 else if (MB_NULLWCH (clen))
1561 width += (w >= 0) ? w : 1;
1573 /* Print TO_PRINT, one matching completion.
1574 PREFIX_BYTES is number of common prefix bytes.
1575 Based on readline/complete.c:fnprint. */
1578 gdb_fnprint (const char *to_print, int prefix_bytes,
1579 const struct match_list_displayer *displayer)
1583 #if defined (HANDLE_MULTIBYTE)
1590 end = to_print + strlen (to_print) + 1;
1591 memset (&ps, 0, sizeof (mbstate_t));
1596 /* Don't print only the ellipsis if the common prefix is one of the
1597 possible completions */
1598 if (to_print[prefix_bytes] == '\0')
1605 ellipsis = (to_print[prefix_bytes] == '.') ? '_' : '.';
1606 for (w = 0; w < ELLIPSIS_LEN; w++)
1607 displayer->putch (displayer, ellipsis);
1608 printed_len = ELLIPSIS_LEN;
1611 s = to_print + prefix_bytes;
1616 displayer->putch (displayer, '^');
1617 displayer->putch (displayer, UNCTRL (*s));
1620 #if defined (HANDLE_MULTIBYTE)
1621 memset (&ps, 0, sizeof (mbstate_t));
1624 else if (*s == RUBOUT)
1626 displayer->putch (displayer, '^');
1627 displayer->putch (displayer, '?');
1630 #if defined (HANDLE_MULTIBYTE)
1631 memset (&ps, 0, sizeof (mbstate_t));
1636 #if defined (HANDLE_MULTIBYTE)
1637 tlen = mbrtowc (&wc, s, end - s, &ps);
1638 if (MB_INVALIDCH (tlen))
1642 memset (&ps, 0, sizeof (mbstate_t));
1644 else if (MB_NULLWCH (tlen))
1649 width = (w >= 0) ? w : 1;
1651 for (w = 0; w < tlen; ++w)
1652 displayer->putch (displayer, s[w]);
1654 printed_len += width;
1656 displayer->putch (displayer, *s);
1666 /* Output TO_PRINT to rl_outstream. If VISIBLE_STATS is defined and we
1667 are using it, check for and output a single character for `special'
1668 filenames. Return the number of characters we output.
1669 Based on readline/complete.c:print_filename. */
1672 gdb_print_filename (char *to_print, char *full_pathname, int prefix_bytes,
1673 const struct match_list_displayer *displayer)
1675 int printed_len, extension_char, slen, tlen;
1676 char *s, c, *new_full_pathname, *dn;
1677 extern int _rl_complete_mark_directories;
1680 printed_len = gdb_fnprint (to_print, prefix_bytes, displayer);
1682 #if defined (VISIBLE_STATS)
1683 if (rl_filename_completion_desired && (rl_visible_stats || _rl_complete_mark_directories))
1685 if (rl_filename_completion_desired && _rl_complete_mark_directories)
1688 /* If to_print != full_pathname, to_print is the basename of the
1689 path passed. In this case, we try to expand the directory
1690 name before checking for the stat character. */
1691 if (to_print != full_pathname)
1693 /* Terminate the directory name. */
1695 to_print[-1] = '\0';
1697 /* If setting the last slash in full_pathname to a NUL results in
1698 full_pathname being the empty string, we are trying to complete
1699 files in the root directory. If we pass a null string to the
1700 bash directory completion hook, for example, it will expand it
1701 to the current directory. We just want the `/'. */
1702 if (full_pathname == 0 || *full_pathname == 0)
1704 else if (full_pathname[0] != '/')
1706 else if (full_pathname[1] == 0)
1707 dn = "//"; /* restore trailing slash to `//' */
1708 else if (full_pathname[1] == '/' && full_pathname[2] == 0)
1709 dn = "/"; /* don't turn /// into // */
1712 s = tilde_expand (dn);
1713 if (rl_directory_completion_hook)
1714 (*rl_directory_completion_hook) (&s);
1717 tlen = strlen (to_print);
1718 new_full_pathname = (char *)xmalloc (slen + tlen + 2);
1719 strcpy (new_full_pathname, s);
1720 if (s[slen - 1] == '/')
1723 new_full_pathname[slen] = '/';
1724 new_full_pathname[slen] = '/';
1725 strcpy (new_full_pathname + slen + 1, to_print);
1727 #if defined (VISIBLE_STATS)
1728 if (rl_visible_stats)
1729 extension_char = stat_char (new_full_pathname);
1732 if (gdb_path_isdir (new_full_pathname))
1733 extension_char = '/';
1735 xfree (new_full_pathname);
1740 s = tilde_expand (full_pathname);
1741 #if defined (VISIBLE_STATS)
1742 if (rl_visible_stats)
1743 extension_char = stat_char (s);
1746 if (gdb_path_isdir (s))
1747 extension_char = '/';
1753 displayer->putch (displayer, extension_char);
1761 /* GDB version of readline/complete.c:complete_get_screenwidth. */
1764 gdb_complete_get_screenwidth (const struct match_list_displayer *displayer)
1766 /* Readline has other stuff here which it's not clear we need. */
1767 return displayer->width;
1770 extern int _rl_completion_prefix_display_length;
1771 extern int _rl_print_completions_horizontally;
1773 EXTERN_C int _rl_qsort_string_compare (const void *, const void *);
1774 typedef int QSFUNC (const void *, const void *);
1776 /* GDB version of readline/complete.c:rl_display_match_list.
1777 See gdb_display_match_list for a description of MATCHES, LEN, MAX.
1778 Returns non-zero if all matches are displayed. */
1781 gdb_display_match_list_1 (char **matches, int len, int max,
1782 const struct match_list_displayer *displayer)
1784 int count, limit, printed_len, lines, cols;
1785 int i, j, k, l, common_length, sind;
1787 int page_completions = displayer->height != INT_MAX && pagination_enabled;
1789 /* Find the length of the prefix common to all items: length as displayed
1790 characters (common_length) and as a byte index into the matches (sind) */
1791 common_length = sind = 0;
1792 if (_rl_completion_prefix_display_length > 0)
1794 t = gdb_printable_part (matches[0]);
1795 temp = strrchr (t, '/');
1796 common_length = temp ? gdb_fnwidth (temp) : gdb_fnwidth (t);
1797 sind = temp ? strlen (temp) : strlen (t);
1799 if (common_length > _rl_completion_prefix_display_length && common_length > ELLIPSIS_LEN)
1800 max -= common_length - ELLIPSIS_LEN;
1802 common_length = sind = 0;
1805 /* How many items of MAX length can we fit in the screen window? */
1806 cols = gdb_complete_get_screenwidth (displayer);
1809 if (limit != 1 && (limit * max == cols))
1812 /* If cols == 0, limit will end up -1 */
1813 if (cols < displayer->width && limit < 0)
1816 /* Avoid a possible floating exception. If max > cols,
1817 limit will be 0 and a divide-by-zero fault will result. */
1821 /* How many iterations of the printing loop? */
1822 count = (len + (limit - 1)) / limit;
1824 /* Watch out for special case. If LEN is less than LIMIT, then
1825 just do the inner printing loop.
1826 0 < len <= limit implies count = 1. */
1828 /* Sort the items if they are not already sorted. */
1829 if (rl_ignore_completion_duplicates == 0 && rl_sort_completion_matches)
1830 qsort (matches + 1, len, sizeof (char *), (QSFUNC *)_rl_qsort_string_compare);
1832 displayer->crlf (displayer);
1835 if (_rl_print_completions_horizontally == 0)
1837 /* Print the sorted items, up-and-down alphabetically, like ls. */
1838 for (i = 1; i <= count; i++)
1840 for (j = 0, l = i; j < limit; j++)
1842 if (l > len || matches[l] == 0)
1846 temp = gdb_printable_part (matches[l]);
1847 printed_len = gdb_print_filename (temp, matches[l], sind,
1851 for (k = 0; k < max - printed_len; k++)
1852 displayer->putch (displayer, ' ');
1856 displayer->crlf (displayer);
1858 if (page_completions && lines >= (displayer->height - 1) && i < count)
1860 lines = gdb_display_match_list_pager (lines, displayer);
1868 /* Print the sorted items, across alphabetically, like ls -x. */
1869 for (i = 1; matches[i]; i++)
1871 temp = gdb_printable_part (matches[i]);
1872 printed_len = gdb_print_filename (temp, matches[i], sind, displayer);
1873 /* Have we reached the end of this line? */
1876 if (i && (limit > 1) && (i % limit) == 0)
1878 displayer->crlf (displayer);
1880 if (page_completions && lines >= displayer->height - 1)
1882 lines = gdb_display_match_list_pager (lines, displayer);
1888 for (k = 0; k < max - printed_len; k++)
1889 displayer->putch (displayer, ' ');
1892 displayer->crlf (displayer);
1898 /* Utility for displaying completion list matches, used by both CLI and TUI.
1900 MATCHES is the list of strings, in argv format, LEN is the number of
1901 strings in MATCHES, and MAX is the length of the longest string in
1905 gdb_display_match_list (char **matches, int len, int max,
1906 const struct match_list_displayer *displayer)
1908 /* Readline will never call this if complete_line returned NULL. */
1909 gdb_assert (max_completions != 0);
1911 /* complete_line will never return more than this. */
1912 if (max_completions > 0)
1913 gdb_assert (len <= max_completions);
1915 if (rl_completion_query_items > 0 && len >= rl_completion_query_items)
1919 /* We can't use *query here because they wait for <RET> which is
1920 wrong here. This follows the readline version as closely as possible
1921 for compatibility's sake. See readline/complete.c. */
1923 displayer->crlf (displayer);
1925 xsnprintf (msg, sizeof (msg),
1926 "Display all %d possibilities? (y or n)", len);
1927 displayer->puts (displayer, msg);
1928 displayer->flush (displayer);
1930 if (gdb_get_y_or_n (0, displayer) == 0)
1932 displayer->crlf (displayer);
1937 if (gdb_display_match_list_1 (matches, len, max, displayer))
1939 /* Note: MAX_COMPLETIONS may be -1 or zero, but LEN is always > 0. */
1940 if (len == max_completions)
1942 /* The maximum number of completions has been reached. Warn the user
1943 that there may be more. */
1944 const char *message = get_max_completions_reached_message ();
1946 displayer->puts (displayer, message);
1947 displayer->crlf (displayer);
1952 extern initialize_file_ftype _initialize_completer; /* -Wmissing-prototypes */
1955 _initialize_completer (void)
1957 add_setshow_zuinteger_unlimited_cmd ("max-completions", no_class,
1958 &max_completions, _("\
1959 Set maximum number of completion candidates."), _("\
1960 Show maximum number of completion candidates."), _("\
1961 Use this to limit the number of candidates considered\n\
1962 during completion. Specifying \"unlimited\" or -1\n\
1963 disables limiting. Note that setting either no limit or\n\
1964 a very large limit can make completion slow."),
1965 NULL, NULL, &setlist, &showlist);