aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndrea Corallo2021-02-17 22:26:28 +0100
committerAndrea Corallo2021-02-17 22:26:28 +0100
commitf92bb788a073c6b3ca7f188e0edea714598193fd (patch)
tree9bea27955098bfc33d0daaa345cfa3dca5b695fd /src
parent1fe5994bcb8b58012dbba0a5f7d03138c293286f (diff)
parent6735bb3d22dc64f3fe42e4a7f439ea9d62f75b5a (diff)
downloademacs-f92bb788a073c6b3ca7f188e0edea714598193fd.tar.gz
emacs-f92bb788a073c6b3ca7f188e0edea714598193fd.zip
Merge remote-tracking branch 'savannah/master' into native-comp
Diffstat (limited to 'src')
-rw-r--r--src/buffer.c14
-rw-r--r--src/buffer.h3
-rw-r--r--src/callint.c9
-rw-r--r--src/data.c87
-rw-r--r--src/emacs-module.c8
-rw-r--r--src/eval.c41
-rw-r--r--src/frame.c4
-rw-r--r--src/image.c13
-rw-r--r--src/json.c77
-rw-r--r--src/lisp.h4
-rw-r--r--src/minibuf.c115
-rw-r--r--src/nsterm.h1
-rw-r--r--src/nsterm.m58
-rw-r--r--src/pdumper.c3
-rw-r--r--src/window.h4
-rw-r--r--src/xdisp.c9
-rw-r--r--src/xfns.c7
17 files changed, 349 insertions, 108 deletions
diff --git a/src/buffer.c b/src/buffer.c
index 80c799e719b..5bd9b37702f 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -292,6 +292,11 @@ bset_major_mode (struct buffer *b, Lisp_Object val)
292 b->major_mode_ = val; 292 b->major_mode_ = val;
293} 293}
294static void 294static void
295bset_local_minor_modes (struct buffer *b, Lisp_Object val)
296{
297 b->local_minor_modes_ = val;
298}
299static void
295bset_mark (struct buffer *b, Lisp_Object val) 300bset_mark (struct buffer *b, Lisp_Object val)
296{ 301{
297 b->mark_ = val; 302 b->mark_ = val;
@@ -893,6 +898,7 @@ CLONE nil means the indirect buffer's state is reset to default values. */)
893 bset_file_truename (b, Qnil); 898 bset_file_truename (b, Qnil);
894 bset_display_count (b, make_fixnum (0)); 899 bset_display_count (b, make_fixnum (0));
895 bset_backed_up (b, Qnil); 900 bset_backed_up (b, Qnil);
901 bset_local_minor_modes (b, Qnil);
896 bset_auto_save_file_name (b, Qnil); 902 bset_auto_save_file_name (b, Qnil);
897 set_buffer_internal_1 (b); 903 set_buffer_internal_1 (b);
898 Fset (intern ("buffer-save-without-query"), Qnil); 904 Fset (intern ("buffer-save-without-query"), Qnil);
@@ -967,6 +973,7 @@ reset_buffer (register struct buffer *b)
967 b->clip_changed = 0; 973 b->clip_changed = 0;
968 b->prevent_redisplay_optimizations_p = 1; 974 b->prevent_redisplay_optimizations_p = 1;
969 bset_backed_up (b, Qnil); 975 bset_backed_up (b, Qnil);
976 bset_local_minor_modes (b, Qnil);
970 BUF_AUTOSAVE_MODIFF (b) = 0; 977 BUF_AUTOSAVE_MODIFF (b) = 0;
971 b->auto_save_failure_time = 0; 978 b->auto_save_failure_time = 0;
972 bset_auto_save_file_name (b, Qnil); 979 bset_auto_save_file_name (b, Qnil);
@@ -5151,6 +5158,7 @@ init_buffer_once (void)
5151 bset_auto_save_file_name (&buffer_local_flags, make_fixnum (-1)); 5158 bset_auto_save_file_name (&buffer_local_flags, make_fixnum (-1));
5152 bset_read_only (&buffer_local_flags, make_fixnum (-1)); 5159 bset_read_only (&buffer_local_flags, make_fixnum (-1));
5153 bset_major_mode (&buffer_local_flags, make_fixnum (-1)); 5160 bset_major_mode (&buffer_local_flags, make_fixnum (-1));
5161 bset_local_minor_modes (&buffer_local_flags, make_fixnum (-1));
5154 bset_mode_name (&buffer_local_flags, make_fixnum (-1)); 5162 bset_mode_name (&buffer_local_flags, make_fixnum (-1));
5155 bset_undo_list (&buffer_local_flags, make_fixnum (-1)); 5163 bset_undo_list (&buffer_local_flags, make_fixnum (-1));
5156 bset_mark_active (&buffer_local_flags, make_fixnum (-1)); 5164 bset_mark_active (&buffer_local_flags, make_fixnum (-1));
@@ -5617,6 +5625,12 @@ The default value (normally `fundamental-mode') affects new buffers.
5617A value of nil means to use the current buffer's major mode, provided 5625A value of nil means to use the current buffer's major mode, provided
5618it is not marked as "special". */); 5626it is not marked as "special". */);
5619 5627
5628 DEFVAR_PER_BUFFER ("local-minor-modes",
5629 &BVAR (current_buffer, local_minor_modes),
5630 Qnil,
5631 doc: /* Minor modes currently active in the current buffer.
5632This is a list of symbols, or nil if there are no minor modes active. */);
5633
5620 DEFVAR_PER_BUFFER ("mode-name", &BVAR (current_buffer, mode_name), 5634 DEFVAR_PER_BUFFER ("mode-name", &BVAR (current_buffer, mode_name),
5621 Qnil, 5635 Qnil,
5622 doc: /* Pretty name of current buffer's major mode. 5636 doc: /* Pretty name of current buffer's major mode.
diff --git a/src/buffer.h b/src/buffer.h
index 790291f1185..24e9c3fcbc8 100644
--- a/src/buffer.h
+++ b/src/buffer.h
@@ -338,6 +338,9 @@ struct buffer
338 /* Symbol naming major mode (e.g., lisp-mode). */ 338 /* Symbol naming major mode (e.g., lisp-mode). */
339 Lisp_Object major_mode_; 339 Lisp_Object major_mode_;
340 340
341 /* Symbol listing all currently enabled minor modes. */
342 Lisp_Object local_minor_modes_;
343
341 /* Pretty name of major mode (e.g., "Lisp"). */ 344 /* Pretty name of major mode (e.g., "Lisp"). */
342 Lisp_Object mode_name_; 345 Lisp_Object mode_name_;
343 346
diff --git a/src/callint.c b/src/callint.c
index d3f49bc35d1..18624637843 100644
--- a/src/callint.c
+++ b/src/callint.c
@@ -104,7 +104,14 @@ If the string begins with `^' and `shift-select-mode' is non-nil,
104 Emacs first calls the function `handle-shift-selection'. 104 Emacs first calls the function `handle-shift-selection'.
105You may use `@', `*', and `^' together. They are processed in the 105You may use `@', `*', and `^' together. They are processed in the
106 order that they appear, before reading any arguments. 106 order that they appear, before reading any arguments.
107usage: (interactive &optional ARG-DESCRIPTOR) */ 107
108If MODES is present, it should be a list of mode names (symbols) that
109this command is applicable for. The main effect of this is that
110`M-x TAB' (by default) won't list this command if the current buffer's
111mode doesn't match the list. That is, if either the major mode isn't
112derived from them, or (when it's a minor mode) the mode isn't in effect.
113
114usage: (interactive &optional ARG-DESCRIPTOR &rest MODES) */
108 attributes: const) 115 attributes: const)
109 (Lisp_Object args) 116 (Lisp_Object args)
110{ 117{
diff --git a/src/data.c b/src/data.c
index 2fa92fecc4f..5177a7cc649 100644
--- a/src/data.c
+++ b/src/data.c
@@ -978,7 +978,17 @@ Value, if non-nil, is a list (interactive SPEC). */)
978 else if (COMPILEDP (fun)) 978 else if (COMPILEDP (fun))
979 { 979 {
980 if (PVSIZE (fun) > COMPILED_INTERACTIVE) 980 if (PVSIZE (fun) > COMPILED_INTERACTIVE)
981 return list2 (Qinteractive, AREF (fun, COMPILED_INTERACTIVE)); 981 {
982 Lisp_Object form = AREF (fun, COMPILED_INTERACTIVE);
983 if (VECTORP (form))
984 /* The vector form is the new form, where the first
985 element is the interactive spec, and the second is the
986 command modes. */
987 return list2 (Qinteractive, AREF (form, 0));
988 else
989 /* Old form -- just the interactive spec. */
990 return list2 (Qinteractive, form);
991 }
982 } 992 }
983#ifdef HAVE_MODULES 993#ifdef HAVE_MODULES
984 else if (MODULE_FUNCTIONP (fun)) 994 else if (MODULE_FUNCTIONP (fun))
@@ -994,10 +1004,75 @@ Value, if non-nil, is a list (interactive SPEC). */)
994 else if (CONSP (fun)) 1004 else if (CONSP (fun))
995 { 1005 {
996 Lisp_Object funcar = XCAR (fun); 1006 Lisp_Object funcar = XCAR (fun);
997 if (EQ (funcar, Qclosure)) 1007 if (EQ (funcar, Qclosure)
998 return Fassq (Qinteractive, Fcdr (Fcdr (XCDR (fun)))); 1008 || EQ (funcar, Qlambda))
999 else if (EQ (funcar, Qlambda)) 1009 {
1000 return Fassq (Qinteractive, Fcdr (XCDR (fun))); 1010 Lisp_Object form = Fcdr (XCDR (fun));
1011 if (EQ (funcar, Qclosure))
1012 form = Fcdr (form);
1013 Lisp_Object spec = Fassq (Qinteractive, form);
1014 if (NILP (Fcdr (Fcdr (spec))))
1015 return spec;
1016 else
1017 return list2 (Qinteractive, Fcar (Fcdr (spec)));
1018 }
1019 }
1020 return Qnil;
1021}
1022
1023DEFUN ("command-modes", Fcommand_modes, Scommand_modes, 1, 1, 0,
1024 doc: /* Return the modes COMMAND is defined for.
1025If COMMAND is not a command, the return value is nil.
1026The value, if non-nil, is a list of mode name symbols. */)
1027 (Lisp_Object command)
1028{
1029 Lisp_Object fun = indirect_function (command); /* Check cycles. */
1030
1031 if (NILP (fun))
1032 return Qnil;
1033
1034 fun = command;
1035 while (SYMBOLP (fun))
1036 fun = Fsymbol_function (fun);
1037
1038 if (COMPILEDP (fun))
1039 {
1040 Lisp_Object form = AREF (fun, COMPILED_INTERACTIVE);
1041 if (VECTORP (form))
1042 /* New form -- the second element is the command modes. */
1043 return AREF (form, 1);
1044 else
1045 /* Old .elc file -- no command modes. */
1046 return Qnil;
1047 }
1048#ifdef HAVE_MODULES
1049 else if (MODULE_FUNCTIONP (fun))
1050 {
1051 Lisp_Object form
1052 = module_function_command_modes (XMODULE_FUNCTION (fun));
1053 if (! NILP (form))
1054 return form;
1055 }
1056#endif
1057 else if (AUTOLOADP (fun))
1058 {
1059 Lisp_Object modes = Fnth (make_int (3), fun);
1060 if (CONSP (modes))
1061 return modes;
1062 else
1063 return Qnil;
1064 }
1065 else if (CONSP (fun))
1066 {
1067 Lisp_Object funcar = XCAR (fun);
1068 if (EQ (funcar, Qclosure)
1069 || EQ (funcar, Qlambda))
1070 {
1071 Lisp_Object form = Fcdr (XCDR (fun));
1072 if (EQ (funcar, Qclosure))
1073 form = Fcdr (form);
1074 return Fcdr (Fcdr (Fassq (Qinteractive, form)));
1075 }
1001 } 1076 }
1002 return Qnil; 1077 return Qnil;
1003} 1078}
@@ -3983,6 +4058,7 @@ syms_of_data (void)
3983 4058
3984 defsubr (&Sindirect_variable); 4059 defsubr (&Sindirect_variable);
3985 defsubr (&Sinteractive_form); 4060 defsubr (&Sinteractive_form);
4061 defsubr (&Scommand_modes);
3986 defsubr (&Seq); 4062 defsubr (&Seq);
3987 defsubr (&Snull); 4063 defsubr (&Snull);
3988 defsubr (&Stype_of); 4064 defsubr (&Stype_of);
@@ -4113,6 +4189,7 @@ This variable cannot be set; trying to do so will signal an error. */);
4113 DEFSYM (Qunlet, "unlet"); 4189 DEFSYM (Qunlet, "unlet");
4114 DEFSYM (Qset, "set"); 4190 DEFSYM (Qset, "set");
4115 DEFSYM (Qset_default, "set-default"); 4191 DEFSYM (Qset_default, "set-default");
4192 DEFSYM (Qcommand_modes, "command-modes");
4116 defsubr (&Sadd_variable_watcher); 4193 defsubr (&Sadd_variable_watcher);
4117 defsubr (&Sremove_variable_watcher); 4194 defsubr (&Sremove_variable_watcher);
4118 defsubr (&Sget_variable_watchers); 4195 defsubr (&Sget_variable_watchers);
diff --git a/src/emacs-module.c b/src/emacs-module.c
index 894dffcf21e..f8fb54c0728 100644
--- a/src/emacs-module.c
+++ b/src/emacs-module.c
@@ -549,7 +549,7 @@ struct Lisp_Module_Function
549 union vectorlike_header header; 549 union vectorlike_header header;
550 550
551 /* Fields traced by GC; these must come first. */ 551 /* Fields traced by GC; these must come first. */
552 Lisp_Object documentation, interactive_form; 552 Lisp_Object documentation, interactive_form, command_modes;
553 553
554 /* Fields ignored by GC. */ 554 /* Fields ignored by GC. */
555 ptrdiff_t min_arity, max_arity; 555 ptrdiff_t min_arity, max_arity;
@@ -646,6 +646,12 @@ module_function_interactive_form (const struct Lisp_Module_Function *fun)
646 return fun->interactive_form; 646 return fun->interactive_form;
647} 647}
648 648
649Lisp_Object
650module_function_command_modes (const struct Lisp_Module_Function *fun)
651{
652 return fun->command_modes;
653}
654
649static emacs_value 655static emacs_value
650module_funcall (emacs_env *env, emacs_value func, ptrdiff_t nargs, 656module_funcall (emacs_env *env, emacs_value func, ptrdiff_t nargs,
651 emacs_value *args) 657 emacs_value *args)
diff --git a/src/eval.c b/src/eval.c
index bf5f6995d87..10e53cf9aed 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -1174,21 +1174,23 @@ usage: (catch TAG BODY...) */)
1174 FUNC should return a Lisp_Object. 1174 FUNC should return a Lisp_Object.
1175 This is how catches are done from within C code. */ 1175 This is how catches are done from within C code. */
1176 1176
1177/* MINIBUFFER_QUIT_LEVEL is to handle quitting from nested minibuffers by
1178 throwing t to tag `exit'.
1179 0 means there is no (throw 'exit t) in progress, or it wasn't from
1180 a minibuffer which isn't the most nested;
1181 N > 0 means the `throw' was done from the minibuffer at level N which
1182 wasn't the most nested. */
1183EMACS_INT minibuffer_quit_level = 0;
1184
1177Lisp_Object 1185Lisp_Object
1178internal_catch (Lisp_Object tag, 1186internal_catch (Lisp_Object tag,
1179 Lisp_Object (*func) (Lisp_Object), Lisp_Object arg) 1187 Lisp_Object (*func) (Lisp_Object), Lisp_Object arg)
1180{ 1188{
1181 /* MINIBUFFER_QUIT_LEVEL is to handle quitting from nested minibuffers by
1182 throwing t to tag `exit'.
1183 Value -1 means there is no (throw 'exit t) in progress;
1184 0 means the `throw' wasn't done from an active minibuffer;
1185 N > 0 means the `throw' was done from the minibuffer at level N. */
1186 static EMACS_INT minibuffer_quit_level = -1;
1187 /* This structure is made part of the chain `catchlist'. */ 1189 /* This structure is made part of the chain `catchlist'. */
1188 struct handler *c = push_handler (tag, CATCHER); 1190 struct handler *c = push_handler (tag, CATCHER);
1189 1191
1190 if (EQ (tag, Qexit)) 1192 if (EQ (tag, Qexit))
1191 minibuffer_quit_level = -1; 1193 minibuffer_quit_level = 0;
1192 1194
1193 /* Call FUNC. */ 1195 /* Call FUNC. */
1194 if (! sys_setjmp (c->jmp)) 1196 if (! sys_setjmp (c->jmp))
@@ -1203,22 +1205,16 @@ internal_catch (Lisp_Object tag,
1203 Lisp_Object val = handlerlist->val; 1205 Lisp_Object val = handlerlist->val;
1204 clobbered_eassert (handlerlist == c); 1206 clobbered_eassert (handlerlist == c);
1205 handlerlist = handlerlist->next; 1207 handlerlist = handlerlist->next;
1206 if (EQ (tag, Qexit) && EQ (val, Qt)) 1208 if (EQ (tag, Qexit) && EQ (val, Qt) && minibuffer_quit_level > 0)
1207 /* If we've thrown t to tag `exit' from within a minibuffer, we 1209 /* If we've thrown t to tag `exit' from within a minibuffer, we
1208 exit all minibuffers more deeply nested than the current 1210 exit all minibuffers more deeply nested than the current
1209 one. */ 1211 one. */
1210 { 1212 {
1211 EMACS_INT mini_depth = this_minibuffer_depth (Qnil); 1213 if (minibuf_level > minibuffer_quit_level
1212 if (mini_depth && mini_depth != minibuffer_quit_level) 1214 && !NILP (Fminibuffer_innermost_command_loop_p (Qnil)))
1213 { 1215 Fthrow (Qexit, Qt);
1214 if (minibuffer_quit_level == -1)
1215 minibuffer_quit_level = mini_depth;
1216 if (minibuffer_quit_level
1217 && (minibuf_level > minibuffer_quit_level))
1218 Fthrow (Qexit, Qt);
1219 }
1220 else 1216 else
1221 minibuffer_quit_level = -1; 1217 minibuffer_quit_level = 0;
1222 } 1218 }
1223 return val; 1219 return val;
1224 } 1220 }
@@ -2177,14 +2173,21 @@ then strings and vectors are not accepted. */)
2177DEFUN ("autoload", Fautoload, Sautoload, 2, 5, 0, 2173DEFUN ("autoload", Fautoload, Sautoload, 2, 5, 0,
2178 doc: /* Define FUNCTION to autoload from FILE. 2174 doc: /* Define FUNCTION to autoload from FILE.
2179FUNCTION is a symbol; FILE is a file name string to pass to `load'. 2175FUNCTION is a symbol; FILE is a file name string to pass to `load'.
2176
2180Third arg DOCSTRING is documentation for the function. 2177Third arg DOCSTRING is documentation for the function.
2181Fourth arg INTERACTIVE if non-nil says function can be called interactively. 2178
2179Fourth arg INTERACTIVE if non-nil says function can be called
2180interactively. If INTERACTIVE is a list, it is interpreted as a list
2181of modes the function is applicable for.
2182
2182Fifth arg TYPE indicates the type of the object: 2183Fifth arg TYPE indicates the type of the object:
2183 nil or omitted says FUNCTION is a function, 2184 nil or omitted says FUNCTION is a function,
2184 `keymap' says FUNCTION is really a keymap, and 2185 `keymap' says FUNCTION is really a keymap, and
2185 `macro' or t says FUNCTION is really a macro. 2186 `macro' or t says FUNCTION is really a macro.
2187
2186Third through fifth args give info about the real definition. 2188Third through fifth args give info about the real definition.
2187They default to nil. 2189They default to nil.
2190
2188If FUNCTION is already defined other than as an autoload, 2191If FUNCTION is already defined other than as an autoload,
2189this does nothing and returns nil. */) 2192this does nothing and returns nil. */)
2190 (Lisp_Object function, Lisp_Object file, Lisp_Object docstring, Lisp_Object interactive, Lisp_Object type) 2193 (Lisp_Object function, Lisp_Object file, Lisp_Object docstring, Lisp_Object interactive, Lisp_Object type)
diff --git a/src/frame.c b/src/frame.c
index 635fc945604..a62347c1fb2 100644
--- a/src/frame.c
+++ b/src/frame.c
@@ -3890,7 +3890,7 @@ frame_float (struct frame *f, Lisp_Object val, enum frame_float_type what,
3890 Lisp_Object frame; 3890 Lisp_Object frame;
3891 3891
3892 XSETFRAME (frame, f); 3892 XSETFRAME (frame, f);
3893 monitor_attributes = Fcar (call1 (Qdisplay_monitor_attributes_list, frame)); 3893 monitor_attributes = call1 (Qframe_monitor_attributes, frame);
3894 if (NILP (monitor_attributes)) 3894 if (NILP (monitor_attributes))
3895 { 3895 {
3896 /* No monitor attributes available. */ 3896 /* No monitor attributes available. */
@@ -5890,7 +5890,7 @@ syms_of_frame (void)
5890 DEFSYM (Qframep, "framep"); 5890 DEFSYM (Qframep, "framep");
5891 DEFSYM (Qframe_live_p, "frame-live-p"); 5891 DEFSYM (Qframe_live_p, "frame-live-p");
5892 DEFSYM (Qframe_windows_min_size, "frame-windows-min-size"); 5892 DEFSYM (Qframe_windows_min_size, "frame-windows-min-size");
5893 DEFSYM (Qdisplay_monitor_attributes_list, "display-monitor-attributes-list"); 5893 DEFSYM (Qframe_monitor_attributes, "frame-monitor-attributes");
5894 DEFSYM (Qwindow__pixel_to_total, "window--pixel-to-total"); 5894 DEFSYM (Qwindow__pixel_to_total, "window--pixel-to-total");
5895 DEFSYM (Qexplicit_name, "explicit-name"); 5895 DEFSYM (Qexplicit_name, "explicit-name");
5896 DEFSYM (Qheight, "height"); 5896 DEFSYM (Qheight, "height");
diff --git a/src/image.c b/src/image.c
index a124cf91ba0..8137dbea8d7 100644
--- a/src/image.c
+++ b/src/image.c
@@ -135,6 +135,12 @@ typedef struct ns_bitmap_record Bitmap_Record;
135# define COLOR_TABLE_SUPPORT 1 135# define COLOR_TABLE_SUPPORT 1
136#endif 136#endif
137 137
138#if defined HAVE_NS
139# define FRAME_SCALE_FACTOR(f) ns_frame_scale_factor (f)
140#else
141# define FRAME_SCALE_FACTOR(f) 1;
142#endif
143
138static void image_disable_image (struct frame *, struct image *); 144static void image_disable_image (struct frame *, struct image *);
139static void image_edge_detection (struct frame *, struct image *, Lisp_Object, 145static void image_edge_detection (struct frame *, struct image *, Lisp_Object,
140 Lisp_Object); 146 Lisp_Object);
@@ -2207,8 +2213,8 @@ image_set_transform (struct frame *f, struct image *img)
2207 /* SVGs are pre-scaled to the correct size. */ 2213 /* SVGs are pre-scaled to the correct size. */
2208 if (EQ (image_spec_value (img->spec, QCtype, NULL), Qsvg)) 2214 if (EQ (image_spec_value (img->spec, QCtype, NULL), Qsvg))
2209 { 2215 {
2210 width = img->width; 2216 width = img->width / FRAME_SCALE_FACTOR (f);
2211 height = img->height; 2217 height = img->height / FRAME_SCALE_FACTOR (f);
2212 } 2218 }
2213 else 2219 else
2214#endif 2220#endif
@@ -10008,6 +10014,9 @@ svg_load_image (struct frame *f, struct image *img, char *contents,
10008 compute_image_size (viewbox_width, viewbox_height, img->spec, 10014 compute_image_size (viewbox_width, viewbox_height, img->spec,
10009 &width, &height); 10015 &width, &height);
10010 10016
10017 width *= FRAME_SCALE_FACTOR (f);
10018 height *= FRAME_SCALE_FACTOR (f);
10019
10011 if (! check_image_size (f, width, height)) 10020 if (! check_image_size (f, width, height))
10012 { 10021 {
10013 image_size_error (); 10022 image_size_error ();
diff --git a/src/json.c b/src/json.c
index 2901a20811a..3f1d27ad7fb 100644
--- a/src/json.c
+++ b/src/json.c
@@ -327,13 +327,14 @@ struct json_configuration {
327 Lisp_Object false_object; 327 Lisp_Object false_object;
328}; 328};
329 329
330static json_t *lisp_to_json (Lisp_Object, struct json_configuration *conf); 330static json_t *lisp_to_json (Lisp_Object,
331 const struct json_configuration *conf);
331 332
332/* Convert a Lisp object to a toplevel JSON object (array or object). */ 333/* Convert a Lisp object to a nonscalar JSON object (array or object). */
333 334
334static json_t * 335static json_t *
335lisp_to_json_toplevel_1 (Lisp_Object lisp, 336lisp_to_json_nonscalar_1 (Lisp_Object lisp,
336 struct json_configuration *conf) 337 const struct json_configuration *conf)
337{ 338{
338 json_t *json; 339 json_t *json;
339 ptrdiff_t count; 340 ptrdiff_t count;
@@ -448,16 +449,17 @@ lisp_to_json_toplevel_1 (Lisp_Object lisp,
448 return json; 449 return json;
449} 450}
450 451
451/* Convert LISP to a toplevel JSON object (array or object). Signal 452/* Convert LISP to a nonscalar JSON object (array or object). Signal
452 an error of type `wrong-type-argument' if LISP is not a vector, 453 an error of type `wrong-type-argument' if LISP is not a vector,
453 hashtable, alist, or plist. */ 454 hashtable, alist, or plist. */
454 455
455static json_t * 456static json_t *
456lisp_to_json_toplevel (Lisp_Object lisp, struct json_configuration *conf) 457lisp_to_json_nonscalar (Lisp_Object lisp,
458 const struct json_configuration *conf)
457{ 459{
458 if (++lisp_eval_depth > max_lisp_eval_depth) 460 if (++lisp_eval_depth > max_lisp_eval_depth)
459 xsignal0 (Qjson_object_too_deep); 461 xsignal0 (Qjson_object_too_deep);
460 json_t *json = lisp_to_json_toplevel_1 (lisp, conf); 462 json_t *json = lisp_to_json_nonscalar_1 (lisp, conf);
461 --lisp_eval_depth; 463 --lisp_eval_depth;
462 return json; 464 return json;
463} 465}
@@ -467,7 +469,7 @@ lisp_to_json_toplevel (Lisp_Object lisp, struct json_configuration *conf)
467 JSON object. */ 469 JSON object. */
468 470
469static json_t * 471static json_t *
470lisp_to_json (Lisp_Object lisp, struct json_configuration *conf) 472lisp_to_json (Lisp_Object lisp, const struct json_configuration *conf)
471{ 473{
472 if (EQ (lisp, conf->null_object)) 474 if (EQ (lisp, conf->null_object))
473 return json_check (json_null ()); 475 return json_check (json_null ());
@@ -499,7 +501,7 @@ lisp_to_json (Lisp_Object lisp, struct json_configuration *conf)
499 } 501 }
500 502
501 /* LISP now must be a vector, hashtable, alist, or plist. */ 503 /* LISP now must be a vector, hashtable, alist, or plist. */
502 return lisp_to_json_toplevel (lisp, conf); 504 return lisp_to_json_nonscalar (lisp, conf);
503} 505}
504 506
505static void 507static void
@@ -557,15 +559,15 @@ DEFUN ("json-serialize", Fjson_serialize, Sjson_serialize, 1, MANY,
557 NULL, 559 NULL,
558 doc: /* Return the JSON representation of OBJECT as a string. 560 doc: /* Return the JSON representation of OBJECT as a string.
559 561
560OBJECT must be a vector, hashtable, alist, or plist and its elements 562OBJECT must be t, a number, string, vector, hashtable, alist, plist,
561can recursively contain the Lisp equivalents to the JSON null and 563or the Lisp equivalents to the JSON null and false values, and its
562false values, t, numbers, strings, or other vectors hashtables, alists 564elements must recursively consist of the same kinds of values. t will
563or plists. t will be converted to the JSON true value. Vectors will 565be converted to the JSON true value. Vectors will be converted to
564be converted to JSON arrays, whereas hashtables, alists and plists are 566JSON arrays, whereas hashtables, alists and plists are converted to
565converted to JSON objects. Hashtable keys must be strings without 567JSON objects. Hashtable keys must be strings without embedded null
566embedded null characters and must be unique within each object. Alist 568characters and must be unique within each object. Alist and plist
567and plist keys must be symbols; if a key is duplicate, the first 569keys must be symbols; if a key is duplicate, the first instance is
568instance is used. 570used.
569 571
570The Lisp equivalents to the JSON null and false values are 572The Lisp equivalents to the JSON null and false values are
571configurable in the arguments ARGS, a list of keyword/argument pairs: 573configurable in the arguments ARGS, a list of keyword/argument pairs:
@@ -603,12 +605,10 @@ usage: (json-serialize OBJECT &rest ARGS) */)
603 {json_object_hashtable, json_array_array, QCnull, QCfalse}; 605 {json_object_hashtable, json_array_array, QCnull, QCfalse};
604 json_parse_args (nargs - 1, args + 1, &conf, false); 606 json_parse_args (nargs - 1, args + 1, &conf, false);
605 607
606 json_t *json = lisp_to_json_toplevel (args[0], &conf); 608 json_t *json = lisp_to_json (args[0], &conf);
607 record_unwind_protect_ptr (json_release_object, json); 609 record_unwind_protect_ptr (json_release_object, json);
608 610
609 /* If desired, we might want to add the following flags: 611 char *string = json_dumps (json, JSON_COMPACT | JSON_ENCODE_ANY);
610 JSON_DECODE_ANY, JSON_ALLOW_NUL. */
611 char *string = json_dumps (json, JSON_COMPACT);
612 if (string == NULL) 612 if (string == NULL)
613 json_out_of_memory (); 613 json_out_of_memory ();
614 record_unwind_protect_ptr (json_free, string); 614 record_unwind_protect_ptr (json_free, string);
@@ -723,12 +723,10 @@ usage: (json-insert OBJECT &rest ARGS) */)
723 move_gap_both (PT, PT_BYTE); 723 move_gap_both (PT, PT_BYTE);
724 struct json_insert_data data; 724 struct json_insert_data data;
725 data.inserted_bytes = 0; 725 data.inserted_bytes = 0;
726 /* If desired, we might want to add the following flags: 726 /* Could have used json_dumpb, but that became available only in
727 JSON_DECODE_ANY, JSON_ALLOW_NUL. */ 727 Jansson 2.10, whereas we want to support 2.7 and upward. */
728 int status 728 int status = json_dump_callback (json, json_insert_callback, &data,
729 /* Could have used json_dumpb, but that became available only in 729 JSON_COMPACT | JSON_ENCODE_ANY);
730 Jansson 2.10, whereas we want to support 2.7 and upward. */
731 = json_dump_callback (json, json_insert_callback, &data, JSON_COMPACT);
732 if (status == -1) 730 if (status == -1)
733 { 731 {
734 if (CONSP (data.error)) 732 if (CONSP (data.error))
@@ -791,7 +789,7 @@ usage: (json-insert OBJECT &rest ARGS) */)
791/* Convert a JSON object to a Lisp object. */ 789/* Convert a JSON object to a Lisp object. */
792 790
793static Lisp_Object ARG_NONNULL ((1)) 791static Lisp_Object ARG_NONNULL ((1))
794json_to_lisp (json_t *json, struct json_configuration *conf) 792json_to_lisp (json_t *json, const struct json_configuration *conf)
795{ 793{
796 switch (json_typeof (json)) 794 switch (json_typeof (json))
797 { 795 {
@@ -932,12 +930,12 @@ DEFUN ("json-parse-string", Fjson_parse_string, Sjson_parse_string, 1, MANY,
932 NULL, 930 NULL,
933 doc: /* Parse the JSON STRING into a Lisp object. 931 doc: /* Parse the JSON STRING into a Lisp object.
934This is essentially the reverse operation of `json-serialize', which 932This is essentially the reverse operation of `json-serialize', which
935see. The returned object will be a vector, list, hashtable, alist, or 933see. The returned object will be the JSON null value, the JSON false
936plist. Its elements will be the JSON null value, the JSON false 934value, t, a number, a string, a vector, a list, a hashtable, an alist,
937value, t, numbers, strings, or further vectors, hashtables, alists, or 935or a plist. Its elements will be further objects of these types. If
938plists. If there are duplicate keys in an object, all but the last 936there are duplicate keys in an object, all but the last one are
939one are ignored. If STRING doesn't contain a valid JSON object, this 937ignored. If STRING doesn't contain a valid JSON object, this function
940function signals an error of type `json-parse-error'. 938signals an error of type `json-parse-error'.
941 939
942The arguments ARGS are a list of keyword/argument pairs: 940The arguments ARGS are a list of keyword/argument pairs:
943 941
@@ -982,7 +980,8 @@ usage: (json-parse-string STRING &rest ARGS) */)
982 json_parse_args (nargs - 1, args + 1, &conf, true); 980 json_parse_args (nargs - 1, args + 1, &conf, true);
983 981
984 json_error_t error; 982 json_error_t error;
985 json_t *object = json_loads (SSDATA (encoded), 0, &error); 983 json_t *object
984 = json_loads (SSDATA (encoded), JSON_DECODE_ANY, &error);
986 if (object == NULL) 985 if (object == NULL)
987 json_parse_error (&error); 986 json_parse_error (&error);
988 987
@@ -1078,8 +1077,10 @@ usage: (json-parse-buffer &rest args) */)
1078 ptrdiff_t point = PT_BYTE; 1077 ptrdiff_t point = PT_BYTE;
1079 struct json_read_buffer_data data = {.point = point}; 1078 struct json_read_buffer_data data = {.point = point};
1080 json_error_t error; 1079 json_error_t error;
1081 json_t *object = json_load_callback (json_read_buffer_callback, &data, 1080 json_t *object
1082 JSON_DISABLE_EOF_CHECK, &error); 1081 = json_load_callback (json_read_buffer_callback, &data,
1082 JSON_DECODE_ANY | JSON_DISABLE_EOF_CHECK,
1083 &error);
1083 1084
1084 if (object == NULL) 1085 if (object == NULL)
1085 json_parse_error (&error); 1086 json_parse_error (&error);
diff --git a/src/lisp.h b/src/lisp.h
index 1d4f16bd581..fcdf8e27181 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -4110,6 +4110,7 @@ intern_c_string (const char *str)
4110} 4110}
4111 4111
4112/* Defined in eval.c. */ 4112/* Defined in eval.c. */
4113extern EMACS_INT minibuffer_quit_level;
4113extern Lisp_Object Vautoload_queue; 4114extern Lisp_Object Vautoload_queue;
4114extern Lisp_Object Vrun_hooks; 4115extern Lisp_Object Vrun_hooks;
4115extern Lisp_Object Vsignaling_function; 4116extern Lisp_Object Vsignaling_function;
@@ -4242,6 +4243,8 @@ extern Lisp_Object module_function_documentation
4242 (struct Lisp_Module_Function const *); 4243 (struct Lisp_Module_Function const *);
4243extern Lisp_Object module_function_interactive_form 4244extern Lisp_Object module_function_interactive_form
4244 (const struct Lisp_Module_Function *); 4245 (const struct Lisp_Module_Function *);
4246extern Lisp_Object module_function_command_modes
4247 (const struct Lisp_Module_Function *);
4245extern module_funcptr module_function_address 4248extern module_funcptr module_function_address
4246 (struct Lisp_Module_Function const *); 4249 (struct Lisp_Module_Function const *);
4247extern void *module_function_data (const struct Lisp_Module_Function *); 4250extern void *module_function_data (const struct Lisp_Module_Function *);
@@ -4391,6 +4394,7 @@ extern void syms_of_casetab (void);
4391 4394
4392/* Defined in keyboard.c. */ 4395/* Defined in keyboard.c. */
4393 4396
4397extern EMACS_INT command_loop_level;
4394extern Lisp_Object echo_message_buffer; 4398extern Lisp_Object echo_message_buffer;
4395extern struct kboard *echo_kboard; 4399extern struct kboard *echo_kboard;
4396extern void cancel_echoing (void); 4400extern void cancel_echoing (void);
diff --git a/src/minibuf.c b/src/minibuf.c
index 949c3d989d5..4b1f4b1ff72 100644
--- a/src/minibuf.c
+++ b/src/minibuf.c
@@ -41,6 +41,7 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
41 minibuffer recursions are encountered. */ 41 minibuffer recursions are encountered. */
42 42
43Lisp_Object Vminibuffer_list; 43Lisp_Object Vminibuffer_list;
44Lisp_Object Vcommand_loop_level_list;
44 45
45/* Data to remember during recursive minibuffer invocations. */ 46/* Data to remember during recursive minibuffer invocations. */
46 47
@@ -64,6 +65,8 @@ static Lisp_Object minibuf_prompt;
64static ptrdiff_t minibuf_prompt_width; 65static ptrdiff_t minibuf_prompt_width;
65 66
66static Lisp_Object nth_minibuffer (EMACS_INT depth); 67static Lisp_Object nth_minibuffer (EMACS_INT depth);
68static EMACS_INT minibuf_c_loop_level (EMACS_INT depth);
69static void set_minibuffer_mode (Lisp_Object buf, EMACS_INT depth);
67 70
68 71
69/* Return TRUE when a frame switch causes a minibuffer on the old 72/* Return TRUE when a frame switch causes a minibuffer on the old
@@ -181,7 +184,12 @@ void move_minibuffer_onto_frame (void)
181 set_window_buffer (sf->minibuffer_window, nth_minibuffer (i), 0, 0); 184 set_window_buffer (sf->minibuffer_window, nth_minibuffer (i), 0, 0);
182 minibuf_window = sf->minibuffer_window; 185 minibuf_window = sf->minibuffer_window;
183 if (of != sf) 186 if (of != sf)
184 set_window_buffer (of->minibuffer_window, get_minibuffer (0), 0, 0); 187 {
188 Lisp_Object temp = get_minibuffer (0);
189
190 set_window_buffer (of->minibuffer_window, temp, 0, 0);
191 set_minibuffer_mode (temp, 0);
192 }
185 } 193 }
186} 194}
187 195
@@ -389,6 +397,21 @@ No argument or nil as argument means use the current buffer as BUFFER. */)
389 : Qnil; 397 : Qnil;
390} 398}
391 399
400DEFUN ("minibuffer-innermost-command-loop-p", Fminibuffer_innermost_command_loop_p,
401 Sminibuffer_innermost_command_loop_p, 0, 1, 0,
402 doc: /* Return t if BUFFER is a minibuffer at the current command loop level.
403No argument or nil as argument means use the current buffer as BUFFER. */)
404 (Lisp_Object buffer)
405{
406 EMACS_INT depth;
407 if (NILP (buffer))
408 buffer = Fcurrent_buffer ();
409 depth = this_minibuffer_depth (buffer);
410 return depth && minibuf_c_loop_level (depth) == command_loop_level
411 ? Qt
412 : Qnil;
413}
414
392/* Return the nesting depth of the active minibuffer BUFFER, or 0 if 415/* Return the nesting depth of the active minibuffer BUFFER, or 0 if
393 BUFFER isn't such a thing. If BUFFER is nil, this means use the current 416 BUFFER isn't such a thing. If BUFFER is nil, this means use the current
394 buffer. */ 417 buffer. */
@@ -420,12 +443,17 @@ confirm the aborting of the current minibuffer and all contained ones. */)
420 443
421 if (!minibuf_depth) 444 if (!minibuf_depth)
422 error ("Not in a minibuffer"); 445 error ("Not in a minibuffer");
446 if (NILP (Fminibuffer_innermost_command_loop_p (Qnil)))
447 error ("Not in most nested command loop");
423 if (minibuf_depth < minibuf_level) 448 if (minibuf_depth < minibuf_level)
424 { 449 {
425 array[0] = fmt; 450 array[0] = fmt;
426 array[1] = make_fixnum (minibuf_level - minibuf_depth + 1); 451 array[1] = make_fixnum (minibuf_level - minibuf_depth + 1);
427 if (!NILP (Fyes_or_no_p (Fformat (2, array)))) 452 if (!NILP (Fyes_or_no_p (Fformat (2, array))))
428 Fthrow (Qexit, Qt); 453 {
454 minibuffer_quit_level = minibuf_depth;
455 Fthrow (Qexit, Qt);
456 }
429 } 457 }
430 else 458 else
431 Fthrow (Qexit, Qt); 459 Fthrow (Qexit, Qt);
@@ -508,6 +536,7 @@ read_minibuf (Lisp_Object map, Lisp_Object initial, Lisp_Object prompt,
508 ptrdiff_t count = SPECPDL_INDEX (); 536 ptrdiff_t count = SPECPDL_INDEX ();
509 Lisp_Object mini_frame, ambient_dir, minibuffer, input_method; 537 Lisp_Object mini_frame, ambient_dir, minibuffer, input_method;
510 Lisp_Object calling_frame = selected_frame; 538 Lisp_Object calling_frame = selected_frame;
539 Lisp_Object calling_window = selected_window;
511 Lisp_Object enable_multibyte; 540 Lisp_Object enable_multibyte;
512 EMACS_INT pos = 0; 541 EMACS_INT pos = 0;
513 /* String to add to the history. */ 542 /* String to add to the history. */
@@ -598,7 +627,8 @@ read_minibuf (Lisp_Object map, Lisp_Object initial, Lisp_Object prompt,
598 627
599 if (minibuf_level > 1 628 if (minibuf_level > 1
600 && minibuf_moves_frame_when_opened () 629 && minibuf_moves_frame_when_opened ()
601 && !minibuf_follows_frame ()) 630 && (!minibuf_follows_frame ()
631 || (!EQ (mini_frame, selected_frame))))
602 { 632 {
603 EMACS_INT i; 633 EMACS_INT i;
604 634
@@ -607,8 +637,6 @@ read_minibuf (Lisp_Object map, Lisp_Object initial, Lisp_Object prompt,
607 set_window_buffer (minibuf_window, nth_minibuffer (i), 0, 0); 637 set_window_buffer (minibuf_window, nth_minibuffer (i), 0, 0);
608 } 638 }
609 639
610 record_unwind_protect_void (choose_minibuf_frame);
611
612 record_unwind_protect (restore_window_configuration, 640 record_unwind_protect (restore_window_configuration,
613 Fcons (Qt, Fcurrent_window_configuration (Qnil))); 641 Fcons (Qt, Fcurrent_window_configuration (Qnil)));
614 642
@@ -640,7 +668,9 @@ read_minibuf (Lisp_Object map, Lisp_Object initial, Lisp_Object prompt,
640 minibuf_save_list 668 minibuf_save_list
641 = Fcons (Voverriding_local_map, 669 = Fcons (Voverriding_local_map,
642 Fcons (minibuf_window, 670 Fcons (minibuf_window,
643 minibuf_save_list)); 671 Fcons (calling_frame,
672 Fcons (calling_window,
673 minibuf_save_list))));
644 minibuf_save_list 674 minibuf_save_list
645 = Fcons (minibuf_prompt, 675 = Fcons (minibuf_prompt,
646 Fcons (make_fixnum (minibuf_prompt_width), 676 Fcons (make_fixnum (minibuf_prompt_width),
@@ -694,6 +724,7 @@ read_minibuf (Lisp_Object map, Lisp_Object initial, Lisp_Object prompt,
694 /* Switch to the minibuffer. */ 724 /* Switch to the minibuffer. */
695 725
696 minibuffer = get_minibuffer (minibuf_level); 726 minibuffer = get_minibuffer (minibuf_level);
727 set_minibuffer_mode (minibuffer, minibuf_level);
697 Fset_buffer (minibuffer); 728 Fset_buffer (minibuffer);
698 729
699 /* Defeat (setq-default truncate-lines t), since truncated lines do 730 /* Defeat (setq-default truncate-lines t), since truncated lines do
@@ -738,6 +769,7 @@ read_minibuf (Lisp_Object map, Lisp_Object initial, Lisp_Object prompt,
738 where there is an active minibuffer. 769 where there is an active minibuffer.
739 Set them to point to ` *Minibuf-0*', which is always empty. */ 770 Set them to point to ` *Minibuf-0*', which is always empty. */
740 empty_minibuf = get_minibuffer (0); 771 empty_minibuf = get_minibuffer (0);
772 set_minibuffer_mode (empty_minibuf, 0);
741 773
742 FOR_EACH_FRAME (dummy, frame) 774 FOR_EACH_FRAME (dummy, frame)
743 { 775 {
@@ -837,20 +869,6 @@ read_minibuf (Lisp_Object map, Lisp_Object initial, Lisp_Object prompt,
837 869
838 recursive_edit_1 (); 870 recursive_edit_1 ();
839 871
840 /* We've exited the recursive edit without an error, so switch the
841 current window away from the expired minibuffer window. */
842 {
843 Lisp_Object prev = Fprevious_window (minibuf_window, Qnil, Qnil);
844 /* PREV can be on a different frame when we have a minibuffer only
845 frame, the other frame's minibuffer window is MINIBUF_WINDOW,
846 and its "focus window" is also MINIBUF_WINDOW. */
847 while (!EQ (prev, minibuf_window)
848 && !EQ (selected_frame, WINDOW_FRAME (XWINDOW (prev))))
849 prev = Fprevious_window (prev, Qnil, Qnil);
850 if (!EQ (prev, minibuf_window))
851 Fset_frame_selected_window (selected_frame, prev, Qnil);
852 }
853
854 /* If cursor is on the minibuffer line, 872 /* If cursor is on the minibuffer line,
855 show the user we have exited by putting it in column 0. */ 873 show the user we have exited by putting it in column 0. */
856 if (XWINDOW (minibuf_window)->cursor.vpos >= 0 874 if (XWINDOW (minibuf_window)->cursor.vpos >= 0
@@ -959,11 +977,16 @@ Lisp_Object
959get_minibuffer (EMACS_INT depth) 977get_minibuffer (EMACS_INT depth)
960{ 978{
961 Lisp_Object tail = Fnthcdr (make_fixnum (depth), Vminibuffer_list); 979 Lisp_Object tail = Fnthcdr (make_fixnum (depth), Vminibuffer_list);
980 Lisp_Object cll_tail = Fnthcdr (make_fixnum (depth),
981 Vcommand_loop_level_list);
962 if (NILP (tail)) 982 if (NILP (tail))
963 { 983 {
964 tail = list1 (Qnil); 984 tail = list1 (Qnil);
965 Vminibuffer_list = nconc2 (Vminibuffer_list, tail); 985 Vminibuffer_list = nconc2 (Vminibuffer_list, tail);
986 cll_tail = list1 (Qnil);
987 Vcommand_loop_level_list = nconc2 (Vcommand_loop_level_list, cll_tail);
966 } 988 }
989 XSETCAR (cll_tail, make_fixnum (depth ? command_loop_level : 0));
967 Lisp_Object buf = Fcar (tail); 990 Lisp_Object buf = Fcar (tail);
968 if (NILP (buf) || !BUFFER_LIVE_P (XBUFFER (buf))) 991 if (NILP (buf) || !BUFFER_LIVE_P (XBUFFER (buf)))
969 { 992 {
@@ -973,7 +996,6 @@ get_minibuffer (EMACS_INT depth)
973 buf = Fget_buffer_create (lname, Qnil); 996 buf = Fget_buffer_create (lname, Qnil);
974 /* Do this before set_minibuffer_mode. */ 997 /* Do this before set_minibuffer_mode. */
975 XSETCAR (tail, buf); 998 XSETCAR (tail, buf);
976 set_minibuffer_mode (buf, depth);
977 /* Although the buffer's name starts with a space, undo should be 999 /* Although the buffer's name starts with a space, undo should be
978 enabled in it. */ 1000 enabled in it. */
979 Fbuffer_enable_undo (buf); 1001 Fbuffer_enable_undo (buf);
@@ -985,12 +1007,19 @@ get_minibuffer (EMACS_INT depth)
985 while the buffer doesn't know about them any more. */ 1007 while the buffer doesn't know about them any more. */
986 delete_all_overlays (XBUFFER (buf)); 1008 delete_all_overlays (XBUFFER (buf));
987 reset_buffer (XBUFFER (buf)); 1009 reset_buffer (XBUFFER (buf));
988 set_minibuffer_mode (buf, depth);
989 } 1010 }
990 1011
991 return buf; 1012 return buf;
992} 1013}
993 1014
1015static EMACS_INT minibuf_c_loop_level (EMACS_INT depth)
1016{
1017 Lisp_Object cll = Fnth (make_fixnum (depth), Vcommand_loop_level_list);
1018 if (FIXNUMP (cll))
1019 return XFIXNUM (cll);
1020 return 0;
1021}
1022
994static void 1023static void
995run_exit_minibuf_hook (void) 1024run_exit_minibuf_hook (void)
996{ 1025{
@@ -1004,17 +1033,16 @@ static void
1004read_minibuf_unwind (void) 1033read_minibuf_unwind (void)
1005{ 1034{
1006 Lisp_Object old_deactivate_mark; 1035 Lisp_Object old_deactivate_mark;
1007 Lisp_Object window; 1036 Lisp_Object calling_frame;
1037 Lisp_Object calling_window;
1008 Lisp_Object future_mini_window; 1038 Lisp_Object future_mini_window;
1009 1039
1010 /* If this was a recursive minibuffer,
1011 tie the minibuffer window back to the outer level minibuffer buffer. */
1012 minibuf_level--;
1013
1014 window = minibuf_window;
1015 /* To keep things predictable, in case it matters, let's be in the 1040 /* To keep things predictable, in case it matters, let's be in the
1016 minibuffer when we reset the relevant variables. */ 1041 minibuffer when we reset the relevant variables. Don't depend on
1017 Fset_buffer (XWINDOW (window)->contents); 1042 `minibuf_window' here. This could by now be the mini-window of any
1043 frame. */
1044 Fset_buffer (nth_minibuffer (minibuf_level));
1045 minibuf_level--;
1018 1046
1019 /* Restore prompt, etc, from outer minibuffer level. */ 1047 /* Restore prompt, etc, from outer minibuffer level. */
1020 Lisp_Object key_vec = Fcar (minibuf_save_list); 1048 Lisp_Object key_vec = Fcar (minibuf_save_list);
@@ -1042,6 +1070,10 @@ read_minibuf_unwind (void)
1042#endif 1070#endif
1043 future_mini_window = Fcar (minibuf_save_list); 1071 future_mini_window = Fcar (minibuf_save_list);
1044 minibuf_save_list = Fcdr (minibuf_save_list); 1072 minibuf_save_list = Fcdr (minibuf_save_list);
1073 calling_frame = Fcar (minibuf_save_list);
1074 minibuf_save_list = Fcdr (minibuf_save_list);
1075 calling_window = Fcar (minibuf_save_list);
1076 minibuf_save_list = Fcdr (minibuf_save_list);
1045 1077
1046 /* Erase the minibuffer we were using at this level. */ 1078 /* Erase the minibuffer we were using at this level. */
1047 { 1079 {
@@ -1059,7 +1091,7 @@ read_minibuf_unwind (void)
1059 mini-window back to its normal size. */ 1091 mini-window back to its normal size. */
1060 if (minibuf_level == 0 1092 if (minibuf_level == 0
1061 || !EQ (selected_frame, WINDOW_FRAME (XWINDOW (future_mini_window)))) 1093 || !EQ (selected_frame, WINDOW_FRAME (XWINDOW (future_mini_window))))
1062 resize_mini_window (XWINDOW (window), 0); 1094 resize_mini_window (XWINDOW (minibuf_window), 0);
1063 1095
1064 /* Deal with frames that should be removed when exiting the 1096 /* Deal with frames that should be removed when exiting the
1065 minibuffer. */ 1097 minibuffer. */
@@ -1090,6 +1122,24 @@ read_minibuf_unwind (void)
1090 to make sure we don't leave around bindings and stuff which only 1122 to make sure we don't leave around bindings and stuff which only
1091 made sense during the read_minibuf invocation. */ 1123 made sense during the read_minibuf invocation. */
1092 call0 (intern ("minibuffer-inactive-mode")); 1124 call0 (intern ("minibuffer-inactive-mode"));
1125
1126 /* We've exited the recursive edit, so switch the current windows
1127 away from the expired minibuffer window, both in the current
1128 minibuffer's frame and the original calling frame. */
1129 choose_minibuf_frame ();
1130 if (!EQ (WINDOW_FRAME (XWINDOW (minibuf_window)), calling_frame))
1131 {
1132 Lisp_Object prev = Fprevious_window (minibuf_window, Qnil, Qnil);
1133 /* PREV can be on a different frame when we have a minibuffer only
1134 frame, the other frame's minibuffer window is MINIBUF_WINDOW,
1135 and its "focus window" is also MINIBUF_WINDOW. */
1136 if (!EQ (prev, minibuf_window)
1137 && EQ (WINDOW_FRAME (XWINDOW (prev)),
1138 WINDOW_FRAME (XWINDOW (minibuf_window))))
1139 Fset_frame_selected_window (selected_frame, prev, Qnil);
1140 }
1141 else
1142 Fset_frame_selected_window (calling_frame, calling_window, Qnil);
1093} 1143}
1094 1144
1095 1145
@@ -2137,6 +2187,7 @@ void
2137init_minibuf_once (void) 2187init_minibuf_once (void)
2138{ 2188{
2139 staticpro (&Vminibuffer_list); 2189 staticpro (&Vminibuffer_list);
2190 staticpro (&Vcommand_loop_level_list);
2140 pdumper_do_now_and_after_load (init_minibuf_once_for_pdumper); 2191 pdumper_do_now_and_after_load (init_minibuf_once_for_pdumper);
2141} 2192}
2142 2193
@@ -2150,6 +2201,7 @@ init_minibuf_once_for_pdumper (void)
2150 restore from a dump file. pdumper doesn't try to preserve 2201 restore from a dump file. pdumper doesn't try to preserve
2151 frames, windows, and so on, so reset everything related here. */ 2202 frames, windows, and so on, so reset everything related here. */
2152 Vminibuffer_list = Qnil; 2203 Vminibuffer_list = Qnil;
2204 Vcommand_loop_level_list = Qnil;
2153 minibuf_level = 0; 2205 minibuf_level = 0;
2154 minibuf_prompt = Qnil; 2206 minibuf_prompt = Qnil;
2155 minibuf_save_list = Qnil; 2207 minibuf_save_list = Qnil;
@@ -2380,6 +2432,7 @@ instead. */);
2380 2432
2381 defsubr (&Sminibufferp); 2433 defsubr (&Sminibufferp);
2382 defsubr (&Sinnermost_minibuffer_p); 2434 defsubr (&Sinnermost_minibuffer_p);
2435 defsubr (&Sminibuffer_innermost_command_loop_p);
2383 defsubr (&Sabort_minibuffers); 2436 defsubr (&Sabort_minibuffers);
2384 defsubr (&Sminibuffer_prompt_end); 2437 defsubr (&Sminibuffer_prompt_end);
2385 defsubr (&Sminibuffer_contents); 2438 defsubr (&Sminibuffer_contents);
diff --git a/src/nsterm.h b/src/nsterm.h
index eae1d0725ea..017c2394ef1 100644
--- a/src/nsterm.h
+++ b/src/nsterm.h
@@ -1252,6 +1252,7 @@ struct input_event;
1252extern void ns_init_events (struct input_event *); 1252extern void ns_init_events (struct input_event *);
1253extern void ns_finish_events (void); 1253extern void ns_finish_events (void);
1254 1254
1255extern double ns_frame_scale_factor (struct frame *);
1255 1256
1256#ifdef NS_IMPL_GNUSTEP 1257#ifdef NS_IMPL_GNUSTEP
1257extern char gnustep_base_version[]; /* version tracking */ 1258extern char gnustep_base_version[]; /* version tracking */
diff --git a/src/nsterm.m b/src/nsterm.m
index 1b2328628ee..b0cf5952fd5 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -857,6 +857,17 @@ ns_row_rect (struct window *w, struct glyph_row *row,
857} 857}
858 858
859 859
860double
861ns_frame_scale_factor (struct frame *f)
862{
863#if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED > 1060
864 return [[FRAME_NS_VIEW (f) window] backingScaleFactor];
865#else
866 return [[FRAME_NS_VIEW (f) window] userSpaceScaleFactor];
867#endif
868}
869
870
860/* ========================================================================== 871/* ==========================================================================
861 872
862 Focus (clipping) and screen update 873 Focus (clipping) and screen update
@@ -7339,6 +7350,8 @@ not_in_argv (NSString *arg)
7339 7350
7340 [surface release]; 7351 [surface release];
7341 surface = nil; 7352 surface = nil;
7353
7354 [self setNeedsDisplay:YES];
7342 } 7355 }
7343#endif 7356#endif
7344 7357
@@ -7510,6 +7523,16 @@ not_in_argv (NSString *arg)
7510 [self initWithFrame: r]; 7523 [self initWithFrame: r];
7511 [self setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable]; 7524 [self setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable];
7512 7525
7526#ifdef NS_DRAW_TO_BUFFER
7527 /* These settings mean AppKit will retain the contents of the frame
7528 on resize. Unfortunately it also means the frame will not be
7529 automatically marked for display, but we can do that ourselves in
7530 viewDidResize. */
7531 [self setLayerContentsRedrawPolicy:
7532 NSViewLayerContentsRedrawOnSetNeedsDisplay];
7533 [self setLayerContentsPlacement:NSViewLayerContentsPlacementTopLeft];
7534#endif
7535
7513 FRAME_NS_VIEW (f) = self; 7536 FRAME_NS_VIEW (f) = self;
7514 emacsframe = f; 7537 emacsframe = f;
7515#ifdef NS_IMPL_COCOA 7538#ifdef NS_IMPL_COCOA
@@ -8452,6 +8475,34 @@ not_in_argv (NSString *arg)
8452} 8475}
8453 8476
8454 8477
8478#ifdef NS_IMPL_COCOA
8479/* If the frame has been garbaged but the toolkit wants to draw, for
8480 example when resizing the frame, we end up with a blank screen.
8481 Sometimes this results in an unpleasant flicker, so try to
8482 redisplay before drawing. */
8483- (void)viewWillDraw
8484{
8485 if (FRAME_GARBAGED_P (emacsframe)
8486 && !redisplaying_p)
8487 {
8488 /* If there is IO going on when redisplay is run here Emacs
8489 crashes. I think it's because this code will always be run
8490 within the run loop and for whatever reason processing input
8491 is dangerous. This technique was stolen wholesale from
8492 nsmenu.m and seems to work. */
8493 bool owfi = waiting_for_input;
8494 waiting_for_input = 0;
8495 block_input ();
8496
8497 redisplay ();
8498
8499 unblock_input ();
8500 waiting_for_input = owfi;
8501 }
8502}
8503#endif
8504
8505
8455#ifdef NS_DRAW_TO_BUFFER 8506#ifdef NS_DRAW_TO_BUFFER
8456- (BOOL)wantsUpdateLayer 8507- (BOOL)wantsUpdateLayer
8457{ 8508{
@@ -8469,6 +8520,13 @@ not_in_argv (NSString *arg)
8469{ 8520{
8470 NSTRACE ("[EmacsView updateLayer]"); 8521 NSTRACE ("[EmacsView updateLayer]");
8471 8522
8523 /* We run redisplay on frames that are garbaged, but marked for
8524 display, before updateLayer is called so if the frame is still
8525 garbaged that means the last redisplay must have refused to
8526 update the frame. */
8527 if (FRAME_GARBAGED_P (emacsframe))
8528 return;
8529
8472 /* This can fail to update the screen if the same surface is 8530 /* This can fail to update the screen if the same surface is
8473 provided twice in a row, even if its contents have changed. 8531 provided twice in a row, even if its contents have changed.
8474 There's a private method, -[CALayer setContentsChanged], that we 8532 There's a private method, -[CALayer setContentsChanged], that we
diff --git a/src/pdumper.c b/src/pdumper.c
index 1f1f6e05df4..f053143a9f7 100644
--- a/src/pdumper.c
+++ b/src/pdumper.c
@@ -2712,7 +2712,7 @@ dump_hash_table (struct dump_context *ctx,
2712static dump_off 2712static dump_off
2713dump_buffer (struct dump_context *ctx, const struct buffer *in_buffer) 2713dump_buffer (struct dump_context *ctx, const struct buffer *in_buffer)
2714{ 2714{
2715#if CHECK_STRUCTS && !defined HASH_buffer_99D642C1CB 2715#if CHECK_STRUCTS && !defined HASH_buffer_F8FE65D42F
2716# error "buffer changed. See CHECK_STRUCTS comment in config.h." 2716# error "buffer changed. See CHECK_STRUCTS comment in config.h."
2717#endif 2717#endif
2718 struct buffer munged_buffer = *in_buffer; 2718 struct buffer munged_buffer = *in_buffer;
@@ -2723,6 +2723,7 @@ dump_buffer (struct dump_context *ctx, const struct buffer *in_buffer)
2723 buffer->window_count = 0; 2723 buffer->window_count = 0;
2724 else 2724 else
2725 eassert (buffer->window_count == -1); 2725 eassert (buffer->window_count == -1);
2726 buffer->local_minor_modes_ = Qnil;
2726 buffer->last_selected_window_ = Qnil; 2727 buffer->last_selected_window_ = Qnil;
2727 buffer->display_count_ = make_fixnum (0); 2728 buffer->display_count_ = make_fixnum (0);
2728 buffer->clip_changed = 0; 2729 buffer->clip_changed = 0;
diff --git a/src/window.h b/src/window.h
index 79eb44e7a38..b6f88e8f55f 100644
--- a/src/window.h
+++ b/src/window.h
@@ -1120,10 +1120,6 @@ void set_window_buffer (Lisp_Object window, Lisp_Object buffer,
1120 1120
1121extern Lisp_Object echo_area_window; 1121extern Lisp_Object echo_area_window;
1122 1122
1123/* Depth in recursive edits. */
1124
1125extern EMACS_INT command_loop_level;
1126
1127/* Non-zero if we should redraw the mode lines on the next redisplay. 1123/* Non-zero if we should redraw the mode lines on the next redisplay.
1128 Usually set to a unique small integer so we can track the main causes of 1124 Usually set to a unique small integer so we can track the main causes of
1129 full redisplays in `redisplay--mode-lines-cause'. */ 1125 full redisplays in `redisplay--mode-lines-cause'. */
diff --git a/src/xdisp.c b/src/xdisp.c
index fb8eaf4b967..f86d3527b3d 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -9227,10 +9227,10 @@ move_it_in_display_line_to (struct it *it,
9227 || prev_method == GET_FROM_STRING) 9227 || prev_method == GET_FROM_STRING)
9228 /* Passed TO_CHARPOS from left to right. */ 9228 /* Passed TO_CHARPOS from left to right. */
9229 && ((prev_pos < to_charpos 9229 && ((prev_pos < to_charpos
9230 && IT_CHARPOS (*it) > to_charpos) 9230 && IT_CHARPOS (*it) >= to_charpos)
9231 /* Passed TO_CHARPOS from right to left. */ 9231 /* Passed TO_CHARPOS from right to left. */
9232 || (prev_pos > to_charpos 9232 || (prev_pos > to_charpos
9233 && IT_CHARPOS (*it) < to_charpos))))) 9233 && IT_CHARPOS (*it) <= to_charpos)))))
9234 { 9234 {
9235 if (it->line_wrap != WORD_WRAP || wrap_it.sp < 0) 9235 if (it->line_wrap != WORD_WRAP || wrap_it.sp < 0)
9236 { 9236 {
@@ -10049,7 +10049,10 @@ move_it_to (struct it *it, ptrdiff_t to_charpos, int to_x, int to_y, int to_vpos
10049 it->continuation_lines_width = 0; 10049 it->continuation_lines_width = 0;
10050 reseat_at_next_visible_line_start (it, false); 10050 reseat_at_next_visible_line_start (it, false);
10051 if ((op & MOVE_TO_POS) != 0 10051 if ((op & MOVE_TO_POS) != 0
10052 && IT_CHARPOS (*it) > to_charpos) 10052 && (IT_CHARPOS (*it) > to_charpos
10053 || (IT_CHARPOS (*it) == to_charpos
10054 && to_charpos == ZV
10055 && FETCH_BYTE (ZV_BYTE - 1) != '\n')))
10053 { 10056 {
10054 reached = 9; 10057 reached = 9;
10055 goto out; 10058 goto out;
diff --git a/src/xfns.c b/src/xfns.c
index 481ee0e2255..d90644819b6 100644
--- a/src/xfns.c
+++ b/src/xfns.c
@@ -4599,7 +4599,7 @@ On MS Windows, this just returns nil. */)
4599 return Qnil; 4599 return Qnil;
4600} 4600}
4601 4601
4602#if !defined USE_GTK || !defined HAVE_GTK3 4602#if !(defined USE_GTK && defined HAVE_GTK3)
4603 4603
4604/* Store the geometry of the workarea on display DPYINFO into *RECT. 4604/* Store the geometry of the workarea on display DPYINFO into *RECT.
4605 Return false if and only if the workarea information cannot be 4605 Return false if and only if the workarea information cannot be
@@ -4662,6 +4662,9 @@ x_get_net_workarea (struct x_display_info *dpyinfo, XRectangle *rect)
4662 4662
4663 return result; 4663 return result;
4664} 4664}
4665#endif /* !(USE_GTK && HAVE_GTK3) */
4666
4667#ifndef USE_GTK
4665 4668
4666/* Return monitor number where F is "most" or closest to. */ 4669/* Return monitor number where F is "most" or closest to. */
4667static int 4670static int
@@ -4877,6 +4880,8 @@ x_get_monitor_attributes_xrandr (struct x_display_info *dpyinfo)
4877 pxid = XRRGetOutputPrimary (dpy, dpyinfo->root_window); 4880 pxid = XRRGetOutputPrimary (dpy, dpyinfo->root_window);
4878#endif 4881#endif
4879 4882
4883#undef RANDR13_LIBRARY
4884
4880 for (i = 0; i < n_monitors; ++i) 4885 for (i = 0; i < n_monitors; ++i)
4881 { 4886 {
4882 XRROutputInfo *info = XRRGetOutputInfo (dpy, resources, 4887 XRROutputInfo *info = XRRGetOutputInfo (dpy, resources,