diff options
| author | Lars Ingebrigtsen | 2021-01-12 15:12:28 +0100 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2021-01-12 15:12:38 +0100 |
| commit | ca024b0575c4ea754c4c6e6dbf21ed610e0d1fb8 (patch) | |
| tree | 4b87356a3d9a269d88a7d0a05b04afcba9b7074d /src | |
| parent | d191f1589b6d06221a58c8c4e6a6441b0a2a2e49 (diff) | |
| download | emacs-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.c | 3 | ||||
| -rw-r--r-- | src/lisp.h | 1 | ||||
| -rw-r--r-- | src/lread.c | 23 | ||||
| -rw-r--r-- | src/minibuf.c | 29 |
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; | |||
| 4351 | extern Lisp_Object get_minibuffer (EMACS_INT); | 4351 | extern Lisp_Object get_minibuffer (EMACS_INT); |
| 4352 | extern void init_minibuf_once (void); | 4352 | extern void init_minibuf_once (void); |
| 4353 | extern void syms_of_minibuf (void); | 4353 | extern void syms_of_minibuf (void); |
| 4354 | extern 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. | |||
| 767 | If the optional argument SECONDS is non-nil, it should be a number | 767 | If the optional argument SECONDS is non-nil, it should be a number |
| 768 | specifying the maximum number of seconds to wait for input. If no | 768 | specifying the maximum number of seconds to wait for input. If no |
| 769 | input arrives in that time, return nil. SECONDS may be a | 769 | input arrives in that time, return nil. SECONDS may be a |
| 770 | floating-point value. */) | 770 | floating-point value. |
| 771 | |||
| 772 | If `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. | |||
| 793 | If the optional argument SECONDS is non-nil, it should be a number | 798 | If the optional argument SECONDS is non-nil, it should be a number |
| 794 | specifying the maximum number of seconds to wait for input. If no | 799 | specifying the maximum number of seconds to wait for input. If no |
| 795 | input arrives in that time, return nil. SECONDS may be a | 800 | input arrives in that time, return nil. SECONDS may be a |
| 796 | floating-point value. */) | 801 | floating-point value. |
| 802 | |||
| 803 | If `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. | |||
| 822 | If the optional argument SECONDS is non-nil, it should be a number | 832 | If the optional argument SECONDS is non-nil, it should be a number |
| 823 | specifying the maximum number of seconds to wait for input. If no | 833 | specifying the maximum number of seconds to wait for input. If no |
| 824 | input arrives in that time, return nil. SECONDS may be a | 834 | input arrives in that time, return nil. SECONDS may be a |
| 825 | floating-point value. */) | 835 | floating-point value. |
| 826 | (Lisp_Object prompt, Lisp_Object inherit_input_method, Lisp_Object seconds) | 836 | |
| 837 | If `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 | ||
| 1078 | void | ||
| 1079 | barf_if_interaction_inhibited (void) | ||
| 1080 | { | ||
| 1081 | if (inhibit_interaction) | ||
| 1082 | xsignal0 (Qinhibited_interaction); | ||
| 1083 | } | ||
| 1084 | |||
| 1078 | DEFUN ("read-from-minibuffer", Fread_from_minibuffer, | 1085 | DEFUN ("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 | ||
| 1129 | If `inhibit-interaction' is non-nil, this function will signal an | ||
| 1130 | `inhibited-interaction' error. | ||
| 1131 | |||
| 1122 | The remainder of this documentation string describes the | 1132 | The remainder of this documentation string describes the |
| 1123 | INITIAL-CONTENTS argument in more detail. It is only relevant when | 1133 | INITIAL-CONTENTS argument in more detail. It is only relevant when |
| 1124 | studying existing code, or when HIST is a cons. If non-nil, | 1134 | studying 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. |
| 1208 | Such values are treated as in `read-from-minibuffer', but are normally | 1220 | Such values are treated as in `read-from-minibuffer', but are normally |
| 1209 | not useful in this function.) | 1221 | not useful in this function.) |
| 1222 | |||
| 1210 | Third arg INHERIT-INPUT-METHOD, if non-nil, means the minibuffer inherits | 1223 | Third arg INHERIT-INPUT-METHOD, if non-nil, means the minibuffer inherits |
| 1211 | the current input method and the setting of`enable-multibyte-characters'. */) | 1224 | the current input method and the setting of`enable-multibyte-characters'. |
| 1225 | |||
| 1226 | If `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' | |||
| 2321 | uses to hide passwords. */); | 2339 | uses 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. | ||
| 2345 | This variable can be bound when user interaction can't be performed, | ||
| 2346 | for instance when running a headless Emacs server. Functions like | ||
| 2347 | `read-from-minibuffer' (and the like) will signal `inhibited-interaction' | ||
| 2348 | instead. */); | ||
| 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); |