aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLars Ingebrigtsen2021-10-24 22:20:19 +0200
committerLars Ingebrigtsen2021-10-24 22:21:19 +0200
commitc2055d41b4b145aa940ce940adc1a3fabfe87a6b (patch)
tree1f48428b7a9ff967f5943413e4024602a6ef7ca2 /src
parent374f14fb9936d2b8fb30a123457ff4b12160f5f3 (diff)
downloademacs-c2055d41b4b145aa940ce940adc1a3fabfe87a6b.tar.gz
emacs-c2055d41b4b145aa940ce940adc1a3fabfe87a6b.zip
Add new macro `with-delayed-message'
* doc/lispref/display.texi (Progress): Document it. * lisp/subr.el (with-delayed-message): New macro. * src/eval.c (with_delayed_message_display) (with_delayed_message_cancel): Helper functions. (Ffuncall_with_delayed_message): New function (bug#19776).
Diffstat (limited to 'src')
-rw-r--r--src/eval.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/eval.c b/src/eval.c
index 0f792b487ed..cd451ecff06 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -29,6 +29,7 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
29#include "dispextern.h" 29#include "dispextern.h"
30#include "buffer.h" 30#include "buffer.h"
31#include "pdumper.h" 31#include "pdumper.h"
32#include "atimer.h"
32 33
33/* CACHEABLE is ordinarily nothing, except it is 'volatile' if 34/* CACHEABLE is ordinarily nothing, except it is 'volatile' if
34 necessary to cajole GCC into not warning incorrectly that a 35 necessary to cajole GCC into not warning incorrectly that a
@@ -1078,6 +1079,49 @@ usage: (while TEST BODY...) */)
1078 return Qnil; 1079 return Qnil;
1079} 1080}
1080 1081
1082static void
1083with_delayed_message_display (struct atimer *timer)
1084{
1085 printf("Here: %s\n", SDATA (timer->client_data));
1086 message3 (timer->client_data);
1087}
1088
1089static void
1090with_delayed_message_cancel (void *timer)
1091{
1092 cancel_atimer (timer);
1093}
1094
1095DEFUN ("funcall-with-delayed-message",
1096 Ffuncall_with_delayed_message, Sfuncall_with_delayed_message,
1097 3, 3, 0,
1098 doc: /* Like `funcall', but display MESSAGE if FUNCTION takes longer than TIMEOUT.
1099TIMEOUT is a number of seconds, and can be an integer or a floating
1100point number.
1101
1102If FUNCTION takes less time to execute than TIMEOUT seconds, MESSAGE
1103is not displayed. */)
1104 (Lisp_Object timeout, Lisp_Object message, Lisp_Object function)
1105{
1106 ptrdiff_t count = SPECPDL_INDEX ();
1107
1108 CHECK_NUMBER (timeout);
1109 CHECK_STRING (message);
1110
1111 /* Set up the atimer. */
1112 struct timespec interval = dtotimespec (XFLOATINT (timeout));
1113 struct atimer *timer = start_atimer (ATIMER_RELATIVE, interval,
1114 with_delayed_message_display,
1115 message);
1116 record_unwind_protect_ptr (with_delayed_message_cancel, timer);
1117
1118 Lisp_Object result = CALLN (Ffuncall, function);
1119
1120 cancel_atimer (timer);
1121
1122 return unbind_to (count, result);
1123}
1124
1081DEFUN ("macroexpand", Fmacroexpand, Smacroexpand, 1, 2, 0, 1125DEFUN ("macroexpand", Fmacroexpand, Smacroexpand, 1, 2, 0,
1082 doc: /* Return result of expanding macros at top level of FORM. 1126 doc: /* Return result of expanding macros at top level of FORM.
1083If FORM is not a macro call, it is returned unchanged. 1127If FORM is not a macro call, it is returned unchanged.
@@ -4511,6 +4555,7 @@ alist of active lexical bindings. */);
4511 defsubr (&Slet); 4555 defsubr (&Slet);
4512 defsubr (&SletX); 4556 defsubr (&SletX);
4513 defsubr (&Swhile); 4557 defsubr (&Swhile);
4558 defsubr (&Sfuncall_with_delayed_message);
4514 defsubr (&Smacroexpand); 4559 defsubr (&Smacroexpand);
4515 defsubr (&Scatch); 4560 defsubr (&Scatch);
4516 defsubr (&Sthrow); 4561 defsubr (&Sthrow);