Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Andrew Burgess <andrew.burgess@embecosm.com>
To: gdb-patches@sourceware.org
Cc: Keith Seitz <keiths@redhat.com>
Subject: Re: [PATCH 2/4] gdb: Add completer for layout command.
Date: Thu, 21 May 2015 07:10:00 -0000	[thread overview]
Message-ID: <20150521071027.GG2880@embecosm.com> (raw)
In-Reply-To: <555D25EA.5000007@redhat.com>

* Keith Seitz <keiths@redhat.com> [2015-05-20 17:25:14 -0700]:

> One quick observation (having seen my fair share of completion functions
> recently)... Most completer functions are using complete_on_enum to do
> this sort of thing. Will that work here?

Indeed it will, I never knew this even existed :)

New simpler version of the patch below.

Thanks,
Andrew

--

gdb: Add completer for layout command.

Add layout name completion for the layout command.

gdb/ChangeLog:

	* tui/tui-layout.c (layout_completer): New function.
	(_initialize_tui_layout): Set completer on layout command.

gdb/testsuite/ChangeLog:

	* gdb.base/completion.exp: Add test for completion of layout
	names.

--

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 40c70e7..51d2bfc 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,10 @@
 2015-05-20  Andrew Burgess  <andrew.burgess@embecosm.com>
 
+	* tui/tui-layout.c (layout_completer): New function.
+	(_initialize_tui_layout): Set completer on layout command.
+
+2015-05-20  Andrew Burgess  <andrew.burgess@embecosm.com>
+
 	* tui/tui-layout.c (tui_set_layout): Remove
 	tui_register_display_type parameter.  Remove all checking of this
 	parameter, and reindent function.  Update header comment.
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 3a947eb..15dae61 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,5 +1,10 @@
 2015-05-20  Andrew Burgess  <andrew.burgess@embecosm.com>
 
+	* gdb.base/completion.exp: Add test for completion of layout
+	names.
+
+2015-05-20  Andrew Burgess  <andrew.burgess@embecosm.com>
+
 	* lib/gdb.exp (skip_tui_tests): New proc.
 	* gdb.base/tui-layout.exp: Check skip_tui_tests.
 
diff --git a/gdb/testsuite/gdb.base/completion.exp b/gdb/testsuite/gdb.base/completion.exp
index f77bfe2..4c31bfc 100644
--- a/gdb/testsuite/gdb.base/completion.exp
+++ b/gdb/testsuite/gdb.base/completion.exp
@@ -859,3 +859,22 @@ gdb_test_multiple "" "$test" {
 	pass "$test"
     }
 }
+
+gdb_test_no_output "set max-completions unlimited"
+
+if {![skip_tui_tests]} {
+    set test "test completion of layout names"
+    send_gdb "layout\t\t\t"
+    gdb_test_multiple "" "$test" {
+	-re "asm *next *prev *regs *split *src *\r\n$gdb_prompt layout $" {
+	    pass "$test"
+	}
+    }
+    send_gdb "\003"
+    set test "quit command input after testing layout completion"
+    gdb_test_multiple "" "$test" {
+	-re "$gdb_prompt $" {
+	    pass "$test"
+	}
+    }
+}
diff --git a/gdb/tui/tui-layout.c b/gdb/tui/tui-layout.c
index 44aca5d..600f0de 100644
--- a/gdb/tui/tui-layout.c
+++ b/gdb/tui/tui-layout.c
@@ -350,6 +350,19 @@ tui_default_win_viewport_height (enum tui_win_type type,
   return h;
 }
 
+/* Complete possible layout names.  TEXT is the complete text entered so
+   far, WORD is the word currently being completed.  */
+
+static VEC (char_ptr) *
+layout_completer (struct cmd_list_element *ignore,
+		  const char *text, const char *word)
+{
+  static const char *layout_names [] =
+    { "src", "asm", "split", "regs", "next", "prev", NULL };
+
+  return complete_on_enum (layout_names, text, word);
+}
+
 /* Function to initialize gdb commands, for tui window layout
    manipulation.  */
 
@@ -359,7 +372,9 @@ extern initialize_file_ftype _initialize_tui_layout;
 void
 _initialize_tui_layout (void)
 {
-  add_com ("layout", class_tui, tui_layout_command, _("\
+  struct cmd_list_element *cmd;
+
+  cmd = add_com ("layout", class_tui, tui_layout_command, _("\
 Change the layout of windows.\n\
 Usage: layout prev | next | <layout_name> \n\
 Layout names are:\n\
@@ -372,6 +387,7 @@ Layout names are:\n\
            source/assembly/command (split) is displayed, \n\
            the register window is displayed with \n\
            the window that has current logical focus.\n"));
+  set_cmd_completer (cmd, layout_completer);
 }
 
 


  reply	other threads:[~2015-05-21  7:10 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-20 23:17 [PATCH 0/4] layout command changes Andrew Burgess
2015-05-20 23:18 ` [PATCH 4/4] gdb: Add cleanup to avoid memory leak on error Andrew Burgess
2015-05-20 23:18 ` [PATCH 3/4] gdb: Don't call tui_enable too early Andrew Burgess
2015-05-20 23:18 ` [PATCH 2/4] gdb: Add completer for layout command Andrew Burgess
2015-05-21  0:25   ` Keith Seitz
2015-05-21  7:10     ` Andrew Burgess [this message]
2015-05-20 23:18 ` [PATCH 1/4] gdb: Remove register class specific layout names Andrew Burgess
2015-05-21  8:42   ` Pedro Alves
2015-05-21 11:33     ` Andrew Burgess
2015-05-21 11:34       ` Pedro Alves
2015-05-21 12:25   ` Andrew Burgess
2015-05-21 13:17     ` Pedro Alves
2015-05-21  8:12 ` [PATCH 0/4] layout command changes Pedro Alves
2015-05-21  8:35   ` Pedro Alves

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=20150521071027.GG2880@embecosm.com \
    --to=andrew.burgess@embecosm.com \
    --cc=gdb-patches@sourceware.org \
    --cc=keiths@redhat.com \
    /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