From: Philippe Waroquiers <philippe.waroquiers@skynet.be>
To: gdb-patches@sourceware.org
Cc: Philippe Waroquiers <philippe.waroquiers@skynet.be>
Subject: [RFA 2/4] Improve usability and/or readibility of help and apropos output.
Date: Fri, 31 May 2019 13:19:00 -0000 [thread overview]
Message-ID: <20190531131903.21203-3-philippe.waroquiers@skynet.be> (raw)
In-Reply-To: <20190531131903.21203-1-philippe.waroquiers@skynet.be>
The "help" command can output long list of command names or classes.
Use the title style to style the command names or classes to make
the output more readable.
Similarly, change "apropos" command to also style the command names.
It is sometimes unclear why "apropos REGEXP" lists some commands,
and then the user has to manually do 'help command' for all commands
listed by "apropos" to see more details about the matching commands.
=> Add an optional flag -v so that "apropos -v REGEXP":
* outputs the full documentation of matching commands.
* highlights the documentation parts matching REGEXP.
---
gdb/ChangeLog | 11 +++++++++
gdb/cli/cli-cmds.c | 22 ++++++++++++------
gdb/cli/cli-decode.c | 55 +++++++++++++++++++++++++++++++++-----------
gdb/cli/cli-decode.h | 1 +
4 files changed, 69 insertions(+), 20 deletions(-)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 318275b34c..7018c3347a 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -7089,3 +7089,14 @@ End:
Update all callers according to the changes in cli/cli-style.h.
* utils.h (fputs_highlighted): New function.
* utils.c (fputs_highlighted): Likewise.
+
+2019-05-31 Philippe Waroquiers <philippe.waroquiers@skynet.be>
+
+ * cli/cli-decode.h (apropos_cmd): Add verbose argument.
+ * cli/cli-decode.c (apropos_cmd): Likewise. Use print_doc_of_command
+ instead of print_help_for_command.
+ (print_doc_of_command): New function.
+ (help_list): Add 'apropos -v word' suggestion.
+ (print_help_for_command): Style the command name using title style.
+ * cli/cli-cmds.c (apropos_command): Parse optional -v flag.
+ (_initialize_cli_cmds): Describe -v in apropos_command help.
diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c
index daf409a558..5f36814467 100644
--- a/gdb/cli/cli-cmds.c
+++ b/gdb/cli/cli-cmds.c
@@ -1289,16 +1289,21 @@ show_user (const char *args, int from_tty)
/* Search through names of commands and documentations for a certain
regular expression. */
-static void
-apropos_command (const char *searchstr, int from_tty)
+static void
+apropos_command (const char *arg, int from_tty)
{
- if (searchstr == NULL)
+ bool verbose = arg && check_for_argument (&arg, "-v", 2);
+
+ if (verbose)
+ arg = skip_spaces (arg);
+
+ if (arg == NULL || *arg == '\0')
error (_("REGEXP string is empty"));
- compiled_regex pattern (searchstr, REG_ICASE,
+ compiled_regex pattern (arg, REG_ICASE,
_("Error in regular expression"));
- apropos_cmd (gdb_stdout, cmdlist, pattern, "");
+ apropos_cmd (gdb_stdout, cmdlist, verbose, pattern, "");
}
/* Subroutine of alias_command to simplify it.
@@ -1877,8 +1882,11 @@ Run the ``make'' program using the rest of the line as arguments."));
Show definitions of non-python/scheme user defined commands.\n\
Argument is the name of the user defined command.\n\
With no argument, show definitions of all user defined commands."), &showlist);
- add_com ("apropos", class_support, apropos_command,
- _("Search for commands matching a REGEXP"));
+ add_com ("apropos", class_support, apropos_command, _("\
+Search for commands matching a REGEXP\n\
+Usage: apropos [-v] REGEXP\n\
+Flag -v indicates to produce a verbose output, showing full documentation\n\
+of the matching commands."));
add_setshow_uinteger_cmd ("max-user-call-depth", no_class,
&max_user_call_depth, _("\
diff --git a/gdb/cli/cli-decode.c b/gdb/cli/cli-decode.c
index 72e2a97009..07e36b3132 100644
--- a/gdb/cli/cli-decode.c
+++ b/gdb/cli/cli-decode.c
@@ -23,6 +23,7 @@
#include "ui-out.h"
#include "cli/cli-cmds.h"
#include "cli/cli-decode.h"
+#include "cli/cli-style.h"
#include "common/gdb_optional.h"
/* Prototypes for local functions. */
@@ -937,13 +938,42 @@ add_com_suppress_notification (const char *name, enum command_class theclass,
&cmdlist, suppress_notification);
}
+/* If VERBOSE, print the full help for command C and highlight the
+ documentation parts matching HIGHLIGHT,
+ otherwise print only one-line help for command C. */
+
+static void
+print_doc_of_command (struct cmd_list_element *c, const char *prefix,
+ bool verbose, compiled_regex &highlight,
+ struct ui_file *stream)
+{
+ /* When printing the full documentation, add a line to separate
+ this documentation from the previous command help, in the likely
+ case that apropos finds several commands. */
+ if (verbose)
+ fputs_filtered ("\n", stream);
+
+ fprintf_styled (stream, title_style.style (),
+ "%s%s", prefix, c->name);
+ fputs_filtered (" -- ", stream);
+ if (verbose)
+ fputs_highlighted (c->doc, highlight, stream);
+ else
+ print_doc_line (stream, c->doc);
+ fputs_filtered ("\n", stream);
+}
+
/* Recursively walk the commandlist structures, and print out the
documentation of commands that match our regex in either their
name, or their documentation.
+ If VERBOSE, prints the complete documentation and highlight the
+ documentation parts matching REGEX, otherwise prints only
+ the first line.
*/
-void
-apropos_cmd (struct ui_file *stream,
+void
+apropos_cmd (struct ui_file *stream,
struct cmd_list_element *commandlist,
+ bool verbose,
compiled_regex ®ex, const char *prefix)
{
struct cmd_list_element *c;
@@ -960,10 +990,7 @@ apropos_cmd (struct ui_file *stream,
/* Try to match against the name. */
returnvalue = regex.search (c->name, name_len, 0, name_len, NULL);
if (returnvalue >= 0)
- {
- print_help_for_command (c, prefix,
- 0 /* don't recurse */, stream);
- }
+ print_doc_of_command (c, prefix, verbose, regex, stream);
}
if (c->doc != NULL && returnvalue < 0)
{
@@ -971,10 +998,7 @@ apropos_cmd (struct ui_file *stream,
/* Try to match against documentation. */
if (regex.search (c->doc, doc_len, 0, doc_len, NULL) >= 0)
- {
- print_help_for_command (c, prefix,
- 0 /* don't recurse */, stream);
- }
+ print_doc_of_command (c, prefix, verbose, regex, stream);
}
/* Check if this command has subcommands and is not an
abbreviation. We skip listing subcommands of abbreviations
@@ -983,7 +1007,7 @@ apropos_cmd (struct ui_file *stream,
{
/* Recursively call ourselves on the subcommand list,
passing the right prefix in. */
- apropos_cmd (stream,*c->prefixlist,regex,c->prefixname);
+ apropos_cmd (stream, *c->prefixlist, verbose, regex, c->prefixname);
}
}
}
@@ -1126,6 +1150,9 @@ Type \"help all\" for the list of all commands.");
fputs_filtered ("documentation.\n", stream);
fputs_filtered ("Type \"apropos word\" to search "
"for commands related to \"word\".\n", stream);
+ fputs_filtered ("Type \"apropos -v word\" for full documentation", stream);
+ wrap_here ("");
+ fputs_filtered (" of commands related to \"word\".\n", stream);
fputs_filtered ("Command name abbreviations are allowed if unambiguous.\n",
stream);
}
@@ -1212,10 +1239,12 @@ static void
print_help_for_command (struct cmd_list_element *c, const char *prefix,
int recurse, struct ui_file *stream)
{
- fprintf_filtered (stream, "%s%s -- ", prefix, c->name);
+ fprintf_styled (stream, title_style.style (),
+ "%s%s", prefix, c->name);
+ fputs_filtered (" -- ", stream);
print_doc_line (stream, c->doc);
fputs_filtered ("\n", stream);
-
+
if (recurse
&& c->prefixlist != 0
&& c->abbrev_flag == 0)
diff --git a/gdb/cli/cli-decode.h b/gdb/cli/cli-decode.h
index c53683d95c..f68b4c120f 100644
--- a/gdb/cli/cli-decode.h
+++ b/gdb/cli/cli-decode.h
@@ -249,6 +249,7 @@ extern void help_cmd_list (struct cmd_list_element *, enum command_class,
extern void help_cmd (const char *, struct ui_file *);
extern void apropos_cmd (struct ui_file *, struct cmd_list_element *,
+ bool verbose,
compiled_regex &, const char *);
/* Used to mark commands that don't do anything. If we just leave the
--
2.20.1
next prev parent reply other threads:[~2019-05-31 13:19 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-31 13:19 [RFA 0/4] Improve "show style", use style in "help" and "apropos" Philippe Waroquiers
2019-05-31 13:19 ` [RFA 4/4] Document in NEWS and gdb.texinfo the "help", "apropos" and "show style" changes Philippe Waroquiers
2019-05-31 13:46 ` Eli Zaretskii
2019-05-31 13:19 ` Philippe Waroquiers [this message]
2019-05-31 20:22 ` [RFA 2/4] Improve usability and/or readibility of help and apropos output Tom Tromey
2019-05-31 13:19 ` [RFA 3/4] Update tests following changes to "help" and "apropos" Philippe Waroquiers
2019-05-31 20:34 ` Tom Tromey
2019-05-31 13:19 ` [RFA 1/4] Add highlight style, title style, fputs_highlighted. Improve 'show style' Philippe Waroquiers
2019-05-31 20:10 ` Tom Tromey
2019-06-01 8:47 ` Philippe Waroquiers
2019-06-03 14:21 ` Tom Tromey
2019-05-31 20:35 ` [RFA 0/4] Improve "show style", use style in "help" and "apropos" Tom Tromey
2019-06-18 13:09 ` Pedro Alves
2019-06-18 16:04 ` Tom Tromey
2019-06-18 20:11 ` Philippe Waroquiers
2019-06-18 20:46 ` Tom Tromey
2019-06-18 20:53 ` Philippe Waroquiers
2019-06-18 20:58 ` Philippe Waroquiers
2019-06-18 22:40 ` Pedro Alves
2019-06-19 0:25 ` Philippe Waroquiers
2019-06-19 19:44 ` Tom Tromey
2019-06-19 19:26 ` Tom Tromey
2019-06-19 22:56 ` Pedro Alves
2019-06-20 14:21 ` Tom Tromey
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=20190531131903.21203-3-philippe.waroquiers@skynet.be \
--to=philippe.waroquiers@skynet.be \
--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