Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Andrew Burgess <aburgess@redhat.com>
To: gdb-patches@sourceware.org
Cc: Andrew Burgess <aburgess@redhat.com>
Subject: [PATCHv2 7/7] gdb: move more completion setup into completer.c
Date: Wed,  6 Mar 2024 10:23:39 +0000	[thread overview]
Message-ID: <c34672f3bdbd609a0d29ff76f7b2037eb5ece356.1709720449.git.aburgess@redhat.com> (raw)
In-Reply-To: <cover.1709720449.git.aburgess@redhat.com>

Move more setup of the readline global state relating to tab
completion into completer.c out of top.c.

Lots of the readline setup is done in init_main (top.c).  This commit
moves those bits of initialisation that relate to completion, and
which are only set the one time, into completer.c.  This does mean
that readline initialisation is now done in multiple locations, some
in init_main (top.c) and some in completer.c, but I think this is OK.
The work done in init_main is the general readline setup.

I think making static what can be made static, and having it all in
one file, makes things easier to reason about.  So I'm OK with having
this split initialisation.

The only completion related thing which is still setup in top.c is
rl_completion_display_matches_hook.  I've left this where it is for
now as rl_completion_display_matches_hook is also updated in the tui
code, and the display hook functions are not in completer.c anyway, so
moving this initialisation to completer.c would not allow anything
else to be made static.

There should be no user visible changes after this commit.
---
 gdb/completer.c | 24 +++++++++++++++++++-----
 gdb/completer.h | 11 -----------
 gdb/top.c       |  3 ---
 3 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/gdb/completer.c b/gdb/completer.c
index 2fee90503db..8e34e30f46b 100644
--- a/gdb/completer.c
+++ b/gdb/completer.c
@@ -51,6 +51,8 @@ static const char *completion_find_completion_word (completion_tracker &tracker,
 						    const char *text,
 						    int *quote_char);
 
+static void set_rl_completer_word_break_characters (const char *break_chars);
+
 /* See completer.h.  */
 
 class completion_tracker::completion_hash_entry
@@ -1113,9 +1115,12 @@ expression_completer (struct cmd_list_element *ignore,
   complete_expression (tracker, text, word);
 }
 
-/* See definition in completer.h.  */
+/* Set the word break characters array to BREAK_CHARS.  This function is
+   useful as const-correct alternative to direct assignment to
+   rl_completer_word_break_characters, which is "char *", not "const
+   char *".  */
 
-void
+static void
 set_rl_completer_word_break_characters (const char *break_chars)
 {
   rl_completer_word_break_characters = (char *) break_chars;
@@ -1940,8 +1945,12 @@ gdb_completion_word_break_characters_throw ()
   return (char *) rl_completer_word_break_characters;
 }
 
-char *
-gdb_completion_word_break_characters ()
+/* Get the list of chars that are considered as word breaks for the current
+   command.  This function does not throw any exceptions and is called from
+   readline.  See gdb_completion_word_break_characters_throw for details.  */
+
+static char *
+gdb_completion_word_break_characters () noexcept
 {
   /* New completion starting.  */
   current_completion.aborted = false;
@@ -2336,7 +2345,7 @@ gdb_rl_attempted_completion_function_throw (const char *text, int start, int end
    hook.  Wrapper around gdb_rl_attempted_completion_function_throw
    that catches C++ exceptions, which can't cross readline.  */
 
-char **
+static char **
 gdb_rl_attempted_completion_function (const char *text, int start, int end)
 {
   /* Restore globals that might have been tweaked in
@@ -3004,6 +3013,11 @@ void _initialize_completer ();
 void
 _initialize_completer ()
 {
+  /* Setup some readline completion globals.  */
+  rl_completion_word_break_hook = gdb_completion_word_break_characters;
+  rl_attempted_completion_function = gdb_rl_attempted_completion_function;
+  set_rl_completer_word_break_characters (default_word_break_characters ());
+
   add_setshow_zuinteger_unlimited_cmd ("max-completions", no_class,
 				       &max_completions, _("\
 Set maximum number of completion candidates."), _("\
diff --git a/gdb/completer.h b/gdb/completer.h
index 9011ba778a7..98a12f3907c 100644
--- a/gdb/completer.h
+++ b/gdb/completer.h
@@ -569,9 +569,6 @@ const char *advance_to_expression_complete_word_point
 extern const char *advance_to_filename_complete_word_point
   (completion_tracker &tracker, const char *text);
 
-extern char **gdb_rl_attempted_completion_function (const char *text,
-						    int start, int end);
-
 extern void noop_completer (struct cmd_list_element *,
 			    completion_tracker &tracker,
 			    const char *, const char *);
@@ -608,14 +605,6 @@ extern void reggroup_completer (struct cmd_list_element *,
 				completion_tracker &tracker,
 				const char *, const char *);
 
-extern char *gdb_completion_word_break_characters (void);
-
-/* Set the word break characters array to BREAK_CHARS.  This function
-   is useful as const-correct alternative to direct assignment to
-   rl_completer_word_break_characters, which is "char *",
-   not "const char *".  */
-extern void set_rl_completer_word_break_characters (const char *break_chars);
-
 /* Get the matching completer_handle_brkchars_ftype function for FN.
    FN is one of the core completer functions above (filename,
    location, symbol, etc.).  This function is useful for cases when
diff --git a/gdb/top.c b/gdb/top.c
index 8df684ec8b4..0aeeb987832 100644
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -2139,9 +2139,6 @@ init_main (void)
   write_history_p = 0;
 
   /* Setup important stuff for command line editing.  */
-  rl_completion_word_break_hook = gdb_completion_word_break_characters;
-  rl_attempted_completion_function = gdb_rl_attempted_completion_function;
-  set_rl_completer_word_break_characters (default_word_break_characters ());
   rl_completion_display_matches_hook = cli_display_match_list;
   rl_readline_name = "gdb";
   rl_terminal_name = getenv ("TERM");
-- 
2.25.4


  parent reply	other threads:[~2024-03-06 10:25 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-16 21:23 [PATCH 0/5] Cleanup and changes for file name completion Andrew Burgess
2024-01-16 21:23 ` [PATCH 1/5] gdb: remove skip_quoted and skip_quoted_chars Andrew Burgess
2024-01-16 21:23 ` [PATCH 2/5] gdb: fix bug where quote characters would become nullptr Andrew Burgess
2024-01-16 21:24 ` [PATCH 3/5] gdb: allow double quotes for quoting filenames Andrew Burgess
2024-01-16 21:24 ` [PATCH 4/5] gdb: remove some dead code from completer.c Andrew Burgess
2024-01-16 21:24 ` [PATCH 5/5] gdb: remove special case completion word handling for filenames Andrew Burgess
2024-01-17 12:09   ` Eli Zaretskii
2024-01-17 16:29     ` Hannes Domani
2024-01-17 16:52       ` Eli Zaretskii
2024-01-18  9:33       ` Andrew Burgess
2024-03-06 10:23 ` [PATCHv2 0/7] Cleanup and changes for file name completion Andrew Burgess
2024-03-06 10:23   ` [PATCHv2 1/7] gdb: remove skip_quoted and skip_quoted_chars Andrew Burgess
2024-03-06 10:23   ` [PATCHv2 2/7] gdb: fix bug where quote characters would become nullptr Andrew Burgess
2024-03-06 10:23   ` [PATCHv2 3/7] gdb: allow double quotes for quoting filenames Andrew Burgess
2024-03-06 10:23   ` [PATCHv2 4/7] gdb: remove some dead code from completer.c Andrew Burgess
2024-03-06 10:23   ` [PATCHv2 5/7] gdb: remove special case completion word handling for filenames Andrew Burgess
2024-03-06 10:23   ` [PATCHv2 6/7] gdb/completion: make completion_find_completion_word static Andrew Burgess
2024-03-06 10:23   ` Andrew Burgess [this message]
2024-03-25 18:30   ` [PATCHv2 0/7] Cleanup and changes for file name completion Andrew Burgess

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c34672f3bdbd609a0d29ff76f7b2037eb5ece356.1709720449.git.aburgess@redhat.com \
    --to=aburgess@redhat.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox