aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLars Ingebrigtsen2021-01-12 15:12:28 +0100
committerLars Ingebrigtsen2021-01-12 15:12:38 +0100
commitca024b0575c4ea754c4c6e6dbf21ed610e0d1fb8 (patch)
tree4b87356a3d9a269d88a7d0a05b04afcba9b7074d /src
parentd191f1589b6d06221a58c8c4e6a6441b0a2a2e49 (diff)
downloademacs-ca024b0575c4ea754c4c6e6dbf21ed610e0d1fb8.tar.gz
emacs-ca024b0575c4ea754c4c6e6dbf21ed610e0d1fb8.zip
Add a new variable `inhibit-interaction'
* doc/lispref/elisp.texi (Top): Add a link. * doc/lispref/errors.texi (Standard Errors): Mention the new error. * doc/lispref/minibuf.texi (Minibuffers): Add a link. (Inhibiting Interaction): New node. * src/data.c (syms_of_data): Define the `inhibited-interaction' error. * src/lisp.h: Export the barfing function. * src/lread.c (Fread_char, Fread_event, Fread_char_exclusive): Barf if inhibited. * src/minibuf.c (barf_if_interaction_inhibited): New function. (Fread_from_minibuffer, Fread_no_blanks_input): Barf if inhibited. (syms_of_minibuf): Define the `inhibit-interaction' variable.
Diffstat (limited to 'src')
-rw-r--r--src/data.c3
-rw-r--r--src/lisp.h1
-rw-r--r--src/lread.c23
-rw-r--r--src/minibuf.c29
4 files changed, 51 insertions, 5 deletions
diff --git a/src/data.c b/src/data.c
index d420bf5fc58..35a6890b9bd 100644
--- a/src/data.c
+++ b/src/data.c
@@ -3760,6 +3760,7 @@ syms_of_data (void)
3760 DEFSYM (Qbuffer_read_only, "buffer-read-only"); 3760 DEFSYM (Qbuffer_read_only, "buffer-read-only");
3761 DEFSYM (Qtext_read_only, "text-read-only"); 3761 DEFSYM (Qtext_read_only, "text-read-only");
3762 DEFSYM (Qmark_inactive, "mark-inactive"); 3762 DEFSYM (Qmark_inactive, "mark-inactive");
3763 DEFSYM (Qinhibited_interaction, "inhibited-interaction");
3763 3764
3764 DEFSYM (Qlistp, "listp"); 3765 DEFSYM (Qlistp, "listp");
3765 DEFSYM (Qconsp, "consp"); 3766 DEFSYM (Qconsp, "consp");
@@ -3844,6 +3845,8 @@ syms_of_data (void)
3844 PUT_ERROR (Qbuffer_read_only, error_tail, "Buffer is read-only"); 3845 PUT_ERROR (Qbuffer_read_only, error_tail, "Buffer is read-only");
3845 PUT_ERROR (Qtext_read_only, pure_cons (Qbuffer_read_only, error_tail), 3846 PUT_ERROR (Qtext_read_only, pure_cons (Qbuffer_read_only, error_tail),
3846 "Text is read-only"); 3847 "Text is read-only");
3848 PUT_ERROR (Qinhibited_interaction, error_tail,
3849 "User interaction while inhibited");
3847 3850
3848 DEFSYM (Qrange_error, "range-error"); 3851 DEFSYM (Qrange_error, "range-error");
3849 DEFSYM (Qdomain_error, "domain-error"); 3852 DEFSYM (Qdomain_error, "domain-error");
diff --git a/src/lisp.h b/src/lisp.h
index 9d8dbbd629f..f6588685443 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -4351,6 +4351,7 @@ extern EMACS_INT minibuf_level;
4351extern Lisp_Object get_minibuffer (EMACS_INT); 4351extern Lisp_Object get_minibuffer (EMACS_INT);
4352extern void init_minibuf_once (void); 4352extern void init_minibuf_once (void);
4353extern void syms_of_minibuf (void); 4353extern void syms_of_minibuf (void);
4354extern void barf_if_interaction_inhibited (void);
4354 4355
4355/* Defined in callint.c. */ 4356/* Defined in callint.c. */
4356 4357
diff --git a/src/lread.c b/src/lread.c
index 1ff0828e85e..4b168fb84bd 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -767,11 +767,16 @@ is used for reading a character.
767If the optional argument SECONDS is non-nil, it should be a number 767If the optional argument SECONDS is non-nil, it should be a number
768specifying the maximum number of seconds to wait for input. If no 768specifying the maximum number of seconds to wait for input. If no
769input arrives in that time, return nil. SECONDS may be a 769input arrives in that time, return nil. SECONDS may be a
770floating-point value. */) 770floating-point value.
771
772If `inhibit-interaction' is non-nil, this function will signal an
773`inhibited-interaction' error. */)
771 (Lisp_Object prompt, Lisp_Object inherit_input_method, Lisp_Object seconds) 774 (Lisp_Object prompt, Lisp_Object inherit_input_method, Lisp_Object seconds)
772{ 775{
773 Lisp_Object val; 776 Lisp_Object val;
774 777
778 barf_if_interaction_inhibited ();
779
775 if (! NILP (prompt)) 780 if (! NILP (prompt))
776 message_with_string ("%s", prompt, 0); 781 message_with_string ("%s", prompt, 0);
777 val = read_filtered_event (1, 1, 1, ! NILP (inherit_input_method), seconds); 782 val = read_filtered_event (1, 1, 1, ! NILP (inherit_input_method), seconds);
@@ -793,9 +798,14 @@ is used for reading a character.
793If the optional argument SECONDS is non-nil, it should be a number 798If the optional argument SECONDS is non-nil, it should be a number
794specifying the maximum number of seconds to wait for input. If no 799specifying the maximum number of seconds to wait for input. If no
795input arrives in that time, return nil. SECONDS may be a 800input arrives in that time, return nil. SECONDS may be a
796floating-point value. */) 801floating-point value.
802
803If `inhibit-interaction' is non-nil, this function will signal an
804`inhibited-interaction' error. */)
797 (Lisp_Object prompt, Lisp_Object inherit_input_method, Lisp_Object seconds) 805 (Lisp_Object prompt, Lisp_Object inherit_input_method, Lisp_Object seconds)
798{ 806{
807 barf_if_interaction_inhibited ();
808
799 if (! NILP (prompt)) 809 if (! NILP (prompt))
800 message_with_string ("%s", prompt, 0); 810 message_with_string ("%s", prompt, 0);
801 return read_filtered_event (0, 0, 0, ! NILP (inherit_input_method), seconds); 811 return read_filtered_event (0, 0, 0, ! NILP (inherit_input_method), seconds);
@@ -822,11 +832,16 @@ is used for reading a character.
822If the optional argument SECONDS is non-nil, it should be a number 832If the optional argument SECONDS is non-nil, it should be a number
823specifying the maximum number of seconds to wait for input. If no 833specifying the maximum number of seconds to wait for input. If no
824input arrives in that time, return nil. SECONDS may be a 834input arrives in that time, return nil. SECONDS may be a
825floating-point value. */) 835floating-point value.
826 (Lisp_Object prompt, Lisp_Object inherit_input_method, Lisp_Object seconds) 836
837If `inhibit-interaction' is non-nil, this function will signal an
838`inhibited-interaction' error. */)
839(Lisp_Object prompt, Lisp_Object inherit_input_method, Lisp_Object seconds)
827{ 840{
828 Lisp_Object val; 841 Lisp_Object val;
829 842
843 barf_if_interaction_inhibited ();
844
830 if (! NILP (prompt)) 845 if (! NILP (prompt))
831 message_with_string ("%s", prompt, 0); 846 message_with_string ("%s", prompt, 0);
832 847
diff --git a/src/minibuf.c b/src/minibuf.c
index 868e481f843..5df10453739 100644
--- a/src/minibuf.c
+++ b/src/minibuf.c
@@ -1075,6 +1075,13 @@ read_minibuf_unwind (void)
1075} 1075}
1076 1076
1077 1077
1078void
1079barf_if_interaction_inhibited (void)
1080{
1081 if (inhibit_interaction)
1082 xsignal0 (Qinhibited_interaction);
1083}
1084
1078DEFUN ("read-from-minibuffer", Fread_from_minibuffer, 1085DEFUN ("read-from-minibuffer", Fread_from_minibuffer,
1079 Sread_from_minibuffer, 1, 7, 0, 1086 Sread_from_minibuffer, 1, 7, 0,
1080 doc: /* Read a string from the minibuffer, prompting with string PROMPT. 1087 doc: /* Read a string from the minibuffer, prompting with string PROMPT.
@@ -1119,6 +1126,9 @@ If the variable `minibuffer-allow-text-properties' is non-nil,
1119 then the string which is returned includes whatever text properties 1126 then the string which is returned includes whatever text properties
1120 were present in the minibuffer. Otherwise the value has no text properties. 1127 were present in the minibuffer. Otherwise the value has no text properties.
1121 1128
1129If `inhibit-interaction' is non-nil, this function will signal an
1130 `inhibited-interaction' error.
1131
1122The remainder of this documentation string describes the 1132The remainder of this documentation string describes the
1123INITIAL-CONTENTS argument in more detail. It is only relevant when 1133INITIAL-CONTENTS argument in more detail. It is only relevant when
1124studying existing code, or when HIST is a cons. If non-nil, 1134studying existing code, or when HIST is a cons. If non-nil,
@@ -1134,6 +1144,8 @@ and some related functions, which use zero-indexing for POSITION. */)
1134{ 1144{
1135 Lisp_Object histvar, histpos, val; 1145 Lisp_Object histvar, histpos, val;
1136 1146
1147 barf_if_interaction_inhibited ();
1148
1137 CHECK_STRING (prompt); 1149 CHECK_STRING (prompt);
1138 if (NILP (keymap)) 1150 if (NILP (keymap))
1139 keymap = Vminibuffer_local_map; 1151 keymap = Vminibuffer_local_map;
@@ -1207,11 +1219,17 @@ point positioned at the end, so that SPACE will accept the input.
1207\(Actually, INITIAL can also be a cons of a string and an integer. 1219\(Actually, INITIAL can also be a cons of a string and an integer.
1208Such values are treated as in `read-from-minibuffer', but are normally 1220Such values are treated as in `read-from-minibuffer', but are normally
1209not useful in this function.) 1221not useful in this function.)
1222
1210Third arg INHERIT-INPUT-METHOD, if non-nil, means the minibuffer inherits 1223Third arg INHERIT-INPUT-METHOD, if non-nil, means the minibuffer inherits
1211the current input method and the setting of`enable-multibyte-characters'. */) 1224the current input method and the setting of`enable-multibyte-characters'.
1225
1226If `inhibit-interaction' is non-nil, this function will signal an
1227`inhibited-interaction' error. */)
1212 (Lisp_Object prompt, Lisp_Object initial, Lisp_Object inherit_input_method) 1228 (Lisp_Object prompt, Lisp_Object initial, Lisp_Object inherit_input_method)
1213{ 1229{
1214 CHECK_STRING (prompt); 1230 CHECK_STRING (prompt);
1231 barf_if_interaction_inhibited ();
1232
1215 return read_minibuf (Vminibuffer_local_ns_map, initial, prompt, 1233 return read_minibuf (Vminibuffer_local_ns_map, initial, prompt,
1216 0, Qminibuffer_history, make_fixnum (0), Qnil, 0, 1234 0, Qminibuffer_history, make_fixnum (0), Qnil, 0,
1217 !NILP (inherit_input_method)); 1235 !NILP (inherit_input_method));
@@ -2321,6 +2339,15 @@ This variable also overrides the default character that `read-passwd'
2321uses to hide passwords. */); 2339uses to hide passwords. */);
2322 Vread_hide_char = Qnil; 2340 Vread_hide_char = Qnil;
2323 2341
2342 DEFVAR_BOOL ("inhibit-interaction",
2343 inhibit_interaction,
2344 doc: /* Non-nil means any user interaction will signal an error.
2345This variable can be bound when user interaction can't be performed,
2346for instance when running a headless Emacs server. Functions like
2347`read-from-minibuffer' (and the like) will signal `inhibited-interaction'
2348instead. */);
2349 inhibit_interaction = 0;
2350
2324 defsubr (&Sactive_minibuffer_window); 2351 defsubr (&Sactive_minibuffer_window);
2325 defsubr (&Sset_minibuffer_window); 2352 defsubr (&Sset_minibuffer_window);
2326 defsubr (&Sread_from_minibuffer); 2353 defsubr (&Sread_from_minibuffer);