As a simple version like this is pretty easy to implement, it seems very
likely I am not the first person to suggest or even send in a patch
about this.

However, I've wanted this feature myself.  Sometimes I space out and am
unsure which macro I've just typed, and it would be nice to be able to
print a message afterwards.

If this is controversial I'll hold off on this patch until after 1.10.0,
but if no one has an objection I'd like to sneak it in.  So please drop
an email by Friday if you think this is a bad idea.

Thanks!

-- 
Kevin J. McCarthy
GPG Fingerprint: 8975 A9B3 3AA3 7910 385C  5308 ADEF 7684 8031 6BDA
From bd14a2c25337d1bb95301f6f74c1f984291a419d Mon Sep 17 00:00:00 2001
From: Kevin McCarthy <ke...@8t8.us>
Date: Sun, 29 Apr 2018 15:10:21 -0700
Subject: [PATCH] Add echo command.

Prints messages using mutt_message().  Sets OPTFORCEREFRESH to allow
updates in the middle of a macro.

Calls mutt_sleep(0) to pause for $sleep_time seconds after displaying
the message.
---
 doc/manual.xml.head | 39 +++++++++++++++++++++++++++++++++++++++
 init.c              | 16 ++++++++++++++++
 init.h              |  2 ++
 3 files changed, 57 insertions(+)

diff --git a/doc/manual.xml.head b/doc/manual.xml.head
index 01888032..168a84b1 100644
--- a/doc/manual.xml.head
+++ b/doc/manual.xml.head
@@ -6482,6 +6482,36 @@ macro pager \cb |urlview\n
 
 </sect1>
 
+<sect1 id="echo">
+<title>Echoing Text</title>
+
+<para>
+Usage:
+</para>
+
+<cmdsynopsis>
+<command>echo</command>
+<arg choice="plain">
+<replaceable class="parameter">message</replaceable>
+</arg>
+</cmdsynopsis>
+
+<para>
+You can print messages to the message window using the "echo" command.
+This might be useful after a macro finishes executing.  After printing
+the message, echo will pause for the number of seconds specified by
+<link linkend="sleep-time">$sleep_time</link>.
+</para>
+
+<screen>
+echo "Sourcing muttrc file"
+
+unset confirmappend
+macro index ,a "&lt;save-message&gt;=archive&lt;enter&gt;&lt;enter-command&gt;echo 'Saved to archive'&lt;enter&gt;"
+</screen>
+
+</sect1>
+
 <sect1 id="misc-topics">
 <title>Miscellany</title>
 
@@ -9633,6 +9663,15 @@ The following are the commands understood by Mutt:
 </cmdsynopsis>
 </listitem>
 
+<listitem>
+<cmdsynopsis>
+<command><link linkend="echo">echo</link></command>
+<arg choice="plain">
+<replaceable class="parameter">message</replaceable>
+</arg>
+</cmdsynopsis>
+</listitem>
+
 <listitem>
 <cmdsynopsis>
 <command><link linkend="exec">exec</link></command>
diff --git a/init.c b/init.c
index f5a89bff..f8a54e6d 100644
--- a/init.c
+++ b/init.c
@@ -692,6 +692,22 @@ static int parse_list (BUFFER *buf, BUFFER *s, unsigned long data, BUFFER *err)
   return 0;
 }
 
+static int parse_echo (BUFFER *buf, BUFFER *s, unsigned long data, BUFFER *err)
+{
+  if (!MoreArgs (s))
+  {
+    strfcpy (err->data, _("not enough arguments"), err->dsize);
+    return -1;
+  }
+  mutt_extract_token (buf, s, 0);
+  set_option (OPTFORCEREFRESH);
+  mutt_message ("%s", buf->data);
+  unset_option (OPTFORCEREFRESH);
+  mutt_sleep (0);
+
+  return 0;
+}
+
 static void _alternates_clean (void)
 {
   int i;
diff --git a/init.h b/init.h
index f5837be3..6c443945 100644
--- a/init.h
+++ b/init.h
@@ -4101,6 +4101,7 @@ static int parse_lists (BUFFER *, BUFFER *, unsigned long, BUFFER *);
 static int parse_unlists (BUFFER *, BUFFER *, unsigned long, BUFFER *);
 static int parse_alias (BUFFER *, BUFFER *, unsigned long, BUFFER *);
 static int parse_unalias (BUFFER *, BUFFER *, unsigned long, BUFFER *);
+static int parse_echo (BUFFER *, BUFFER *, unsigned long, BUFFER *);
 static int parse_ignore (BUFFER *, BUFFER *, unsigned long, BUFFER *);
 static int parse_unignore (BUFFER *, BUFFER *, unsigned long, BUFFER *);
 static int parse_source (BUFFER *, BUFFER *, unsigned long, BUFFER *);
@@ -4149,6 +4150,7 @@ const struct command_t Commands[] = {
   { "color",		mutt_parse_color,	0 },
   { "uncolor",		mutt_parse_uncolor,	0 },
 #endif
+  { "echo",		parse_echo,		0 },
   { "exec",		mutt_parse_exec,	0 },
   { "fcc-hook",		mutt_parse_hook,	MUTT_FCCHOOK },
   { "fcc-save-hook",	mutt_parse_hook,	MUTT_FCCHOOK | MUTT_SAVEHOOK },
-- 
2.17.0

Attachment: signature.asc
Description: PGP signature

Reply via email to