aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEli Zaretskii2013-04-14 20:27:45 +0300
committerEli Zaretskii2013-04-14 20:27:45 +0300
commiteb7a410c147507ffdf0e84d163a014acb82b19a2 (patch)
tree2274bf05e320123c234afbe38dc97932b943c0ea /src
parent64544985029d58bada3486a3eba7f11ce690c526 (diff)
parentddd6b68524ba1f957e2f8ddd76eb23e641429b58 (diff)
downloademacs-eb7a410c147507ffdf0e84d163a014acb82b19a2.tar.gz
emacs-eb7a410c147507ffdf0e84d163a014acb82b19a2.zip
Merge from trunk, resolve conflicts.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog173
-rw-r--r--src/Makefile.in8
-rw-r--r--src/buffer.c25
-rw-r--r--src/coding.c208
-rw-r--r--src/fileio.c31
-rw-r--r--src/fns.c7
-rw-r--r--src/font.c4
-rw-r--r--src/fontset.c9
-rw-r--r--src/fontset.h3
-rw-r--r--src/frame.c51
-rw-r--r--src/frame.h3
-rw-r--r--src/image.c10
-rw-r--r--src/indent.c8
-rw-r--r--src/insdel.c15
-rw-r--r--src/keyboard.c21
-rw-r--r--src/lisp.h5
-rw-r--r--src/menu.c3
-rw-r--r--src/minibuf.c8
-rw-r--r--src/msdos.c7
-rw-r--r--src/nsfns.m145
-rw-r--r--src/nsmenu.m4
-rw-r--r--src/nsselect.m15
-rw-r--r--src/nsterm.h3
-rw-r--r--src/nsterm.m40
-rw-r--r--src/w32fns.c62
-rw-r--r--src/w32font.c2
-rw-r--r--src/w32menu.c4
-rw-r--r--src/w32term.h2
-rw-r--r--src/window.c37
-rw-r--r--src/xfaces.c12
-rw-r--r--src/xfns.c77
-rw-r--r--src/xgselect.c3
-rw-r--r--src/xmenu.c9
-rw-r--r--src/xselect.c8
-rw-r--r--src/xterm.h6
35 files changed, 599 insertions, 429 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index ea4e660ed8d..2d6fda4fec7 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,156 @@
12013-04-14 Eli Zaretskii <eliz@gnu.org>
2
3 * buffer.c (syms_of_buffer) <left-margin-width, right-margin-width>
4 <left-fringe-width, right-fringe-width, fringes-outside-margins>:
5 Mention in the doc string that setting these variables takes
6 effect only after a call to set-window-buffer. (Bug#14200)
7
82013-04-13 Eli Zaretskii <eliz@gnu.org>
9
10 * indent.c (Fvertical_motion): Don't consider display strings on
11 overlay strings as display strings on the buffer position we
12 started from. This prevents vertical cursor motion from jumping
13 more than one line when there's an overlay string with a display
14 property at end of line.
15 Reported by Karl Chen <Karl.Chen@quarl.org> in
16 http://lists.gnu.org/archive/html/emacs-devel/2013-04/msg00362.html.
17
182013-04-12 Stefan Monnier <monnier@iro.umontreal.ca>
19
20 * window.c (select_window): `record_buffer' even if window is
21 already selected (bug#14191).
22
232013-04-11 Eli Zaretskii <eliz@gnu.org>
24
25 * window.c (Fwindow_end): Test more flags, including the buffer's
26 last_overlay_modified flag, to determine whether the window's
27 display is really up-to-date. Prevents the function from
28 returning a stale value. (Bug#14170)
29 (Fwindow_line_height): Fix the test for up-to-date-ness of the
30 current matrix.
31
322013-04-10 Eli Zaretskii <eliz@gnu.org>
33
34 * frame.c (do_switch_frame): Mark the TTY frame we switch to as
35 garbaged only if it is not already the top frame on its TTY.
36 This prevents flickering due to constant redrawing of TTY frames when
37 there are GUI frames open in the same session. (Bug#13864)
38
392013-04-10 Stefan Monnier <monnier@iro.umontreal.ca>
40
41 * keyboard.c (timer_start_idle): Call internal-timer-start-idle instead
42 of marking the idle timers directly.
43
442013-04-09 Stefan Monnier <monnier@iro.umontreal.ca>
45
46 * minibuf.c (Ftest_completion): Ignore non-string/symbol keys in hash
47 tables (bug#14054).
48
492013-04-08 Stefan Monnier <monnier@iro.umontreal.ca>
50
51 * window.c (select_window): Don't record_buffer while the invariant is
52 temporarily broken (bug#14161).
53
54 * fns.c (Fdelq): Don't assume !NILP => CONSP.
55
562013-04-07 Eli Zaretskii <eliz@gnu.org>
57
58 * fileio.c (ACL_NOT_WELL_SUPPORTED): Define macro for WINDOWSNT.
59
602013-04-07 Romain Francoise <romain@orebokech.com>
61
62 Ignore additional platform-specific ACL errors (Bug#13702).
63 * fileio.c (ACL_NOT_WELL_SUPPORTED): New macro copied from gnulib.
64 (Fcopy_file, Fset_file_acl) [HAVE_POSIX_ACL]: Use it.
65
662013-03-31 Jan Djärv <jan.h.d@swipnet.se>
67
68 * nsterm.m (ns_mouse_position): Use NS_FRAME_P instead of checking
69 f->output_data.ns.
70
712013-04-07 Paul Eggert <eggert@cs.ucla.edu>
72
73 Fix --enable-profiling bug introduced by 2013-02-25 change (Bug#13783).
74 This bug was introduced by my 2013-02-25 change that simplified
75 data_start configuration. Without this change, on GNU/Linux
76 an Emacs configured with --enable-profiling fails immediately
77 due to a profiler signal.
78 * Makefile.in: Compile with $(PROFILING_CFLAGS), but do not link
79 with these flags. On platforms where special flags are needed
80 when linking temacs, the flags are now in LD_SWITCH_SYSTEM_TEMACS.
81 (ALL_CFLAGS): Remove $(PROFILING_CFLAGS).
82 (.c.o, .m.o): Compile with $(PROFILING_CFLAGS).
83
842013-04-07 Dmitry Antipov <dmantipov@yandex.ru>
85
86 Get rid of some platform-specific functions examining window
87 system and its capabilities. This is a partial rework of the
88 2013-04-05 change.
89 * lisp.h (have_menus_p): Remove prototype. This function is
90 replaced with platform-independent window_system_available.
91 (check_window_system): Move to...
92 * frame.h (decode_window_system_frame, window_system_available):
93 ...here, add new prototypes.
94 * frame.c (window_system_available, decode_window_system_frame):
95 New functions.
96 (check_window_system): Platform-independent now.
97 * xterm.h (x_in_use): Remove declaration.
98 (check_x_frame):
99 * w32term.h (check_x_frame):
100 * nsterm.h (check_x_frame): Remove prototypes. This function
101 is replaced with platform-independent decode_window_system_frame.
102 * msdos.c (have_menus_p): Remove.
103 * nsfns.m (check_window_system, have_menus_p, check_ns_frame):
104 Remove platform-specific functions. Use check_window_system,
105 decode_window_system_frame and check_ns_display_info where
106 appropriate. Minor style and comment tweaks.
107 * w32fns.c (w32_in_use, check_window_system, have_menus_p)
108 (check_x_frame): Likewise.
109 * xfns.c (x_in_use, check_window_system, have_menus_p, check_x_frame):
110 Likewise.
111 * fileio.c, fns.c, font.c, fontset.c, image.c, menu.c, nsmenu.m:
112 * nsselect.m, nsterm.m, w32font.c, w32menu.c, xfaces.c, xgselect.c:
113 * xmenu.c, xselect.c: All related users changed.
114
1152013-04-03 Kenichi Handa <handa@gnu.org>
116
117 The following changes is to optimize the code for reading UTF-8
118 files.
119
120 * coding.c (check_ascii): Rename from detect_ascii. Return value
121 changed. Check EOL format. Do not call adjust_coding_eol_type
122 here.
123 (check_utf_8): New function.
124 (adjust_coding_eol_type): Do nothing if already adjusted.
125 (detect_coding): Compare the return value of check_ascii with
126 coding->src_bytes. Call adjust_coding_eol_type if necessary.
127 (decode_coding_gap): Optimize for valid UTF-8.
128
1292013-03-21 Kenichi Handa <handa@gnu.org>
130
131 * coding.c (syms_of_coding): Cancel previous change.
132
133 * insdel.c (insert_from_gap): Fix previous change.
134
1352013-04-05 Dmitry Antipov <dmantipov@yandex.ru>
136
137 Consistently use platform-specific function to detect window system.
138 * lisp.h (check_window_system): New prototype. This function is
139 going to replace check_x, check_w32 and check_ns.
140 (have_menus_p): Mention msdos.c in comment.
141 * fontset.c (check_window_system_func): Remove. Adjust all users.
142 * fontset.h (check_window_system_func): Remove prototype.
143 * nsterm.h (check_ns):
144 * xterm.h (check_x):
145 * w32term.h (check_w32): Likewise.
146 * menu.c (Fx_popup_menu): Use check_window_system.
147 * msdos.c (check_window_system): Define for MS-DOS.
148 * nsfns.m (check_window_system): Define for NS. Adjust all users.
149 * w32fns.c (check_window_system): Likewise for MS-Windows.
150 * xfns.c (check_window_system): Likewise for X.
151 * font.c, frame.c, nsmenu.m, nsselect.m, nsterm.m, w32menu.c:
152 * xfaces.c, xmenu.c: Use check_window_system where appropriate.
153
12013-04-02 Paul Eggert <eggert@cs.ucla.edu> 1542013-04-02 Paul Eggert <eggert@cs.ucla.edu>
2 155
3 Prefer < to > in range checks such as 0 <= i && i < N. 156 Prefer < to > in range checks such as 0 <= i && i < N.
@@ -156,8 +309,8 @@
156 309
157 * xdisp.c (with_echo_area_buffer_unwind_data): Save window 310 * xdisp.c (with_echo_area_buffer_unwind_data): Save window
158 start marker... 311 start marker...
159 (unwind_with_echo_area_buffer): ...to restore it here. This 312 (unwind_with_echo_area_buffer): ...to restore it here.
160 is needed to ensure that... 313 This is needed to ensure that...
161 (redisplay_window): ...both window markers are valid here, 314 (redisplay_window): ...both window markers are valid here,
162 which is verified by eassert. 315 which is verified by eassert.
163 * editfns.c (save_excursion_save): Do not assume that 316 * editfns.c (save_excursion_save): Do not assume that
@@ -307,10 +460,10 @@
307 460
308 * w32term.c (w32fullscreen_hook): Use FRAME_NORMAL_WIDTH, 461 * w32term.c (w32fullscreen_hook): Use FRAME_NORMAL_WIDTH,
309 FRAME_NORMAL_HEIGHT, and FRAME_PREV_FSMODE, instead of static 462 FRAME_NORMAL_HEIGHT, and FRAME_PREV_FSMODE, instead of static
310 variables, to save and restore frame dimensions. Use 463 variables, to save and restore frame dimensions.
311 FRAME_NORMAL_LEFT and FRAME_NORMAL_TOP to restore frame position 464 Use FRAME_NORMAL_LEFT and FRAME_NORMAL_TOP to restore frame position
312 after returning from a 'fullscreen' configuration. use 465 after returning from a 'fullscreen' configuration.
313 SendMessage instead of PostMessage to send the SC_RESTORE message, 466 use SendMessage instead of PostMessage to send the SC_RESTORE message,
314 to avoid races between the main thread and the input thread. 467 to avoid races between the main thread and the input thread.
315 468
316 * w32term.h (struct w32_output): New members normal_width, 469 * w32term.h (struct w32_output): New members normal_width,
@@ -395,10 +548,10 @@
395 548
396 * frame.h (struct frame): Drop resx and resy because the same data is 549 * frame.h (struct frame): Drop resx and resy because the same data is
397 available from window system-specific output context. Adjust users. 550 available from window system-specific output context. Adjust users.
398 (default_pixels_per_inch_x, default_pixels_per_inch_y): New 551 (default_pixels_per_inch_x, default_pixels_per_inch_y):
399 functions to provide defaults when no window system available. 552 New functions to provide defaults when no window system available.
400 (FRAME_RES_X, FRAME_RES_Y): New macros. 553 (FRAME_RES_X, FRAME_RES_Y): New macros.
401 (NUMVAL): Moved from xdisp.c. 554 (NUMVAL): Move from xdisp.c.
402 * font.c (font_pixel_size, font_find_for_lface, font_open_for_lface) 555 * font.c (font_pixel_size, font_find_for_lface, font_open_for_lface)
403 (Ffont_face_attributes, Fopen_font): 556 (Ffont_face_attributes, Fopen_font):
404 * image.c (gs_load): 557 * image.c (gs_load):
@@ -465,7 +618,7 @@
465 618
466 * coding.c (decode_coding_gap): Fix typo caught by static checking. 619 * coding.c (decode_coding_gap): Fix typo caught by static checking.
467 620
4682013-03-15 handa <handa@gnu.org> 6212013-03-15 Kenichi Handa <handa@gnu.org>
469 622
470 * insdel.c (insert_from_gap): New arg text_at_gap_tail. 623 * insdel.c (insert_from_gap): New arg text_at_gap_tail.
471 (adjust_after_replace): Make it back to static. Delete the third 624 (adjust_after_replace): Make it back to static. Delete the third
diff --git a/src/Makefile.in b/src/Makefile.in
index 2e56f8f2fe1..ee4e771dc9a 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -265,7 +265,7 @@ EMACSRES = @EMACSRES@
265EMACS_MANIFEST = @EMACS_MANIFEST@ 265EMACS_MANIFEST = @EMACS_MANIFEST@
266## If HAVE_W32, compiler arguments for including 266## If HAVE_W32, compiler arguments for including
267## the resource file in the binary. 267## the resource file in the binary.
268## Cygwin: -Wl,-b -Wl,pe-i386 -Wl,emacs.res 268## Cygwin: -Wl,emacs.res
269## MinGW: emacs.res 269## MinGW: emacs.res
270W32_RES_LINK=@W32_RES_LINK@ 270W32_RES_LINK=@W32_RES_LINK@
271 271
@@ -331,7 +331,7 @@ ALL_CFLAGS=-Demacs $(MYCPPFLAGS) -I. -I$(srcdir) \
331 $(GNUSTEP_CFLAGS) $(CFLAGS_SOUND) $(RSVG_CFLAGS) $(IMAGEMAGICK_CFLAGS) \ 331 $(GNUSTEP_CFLAGS) $(CFLAGS_SOUND) $(RSVG_CFLAGS) $(IMAGEMAGICK_CFLAGS) \
332 $(LIBXML2_CFLAGS) $(DBUS_CFLAGS) \ 332 $(LIBXML2_CFLAGS) $(DBUS_CFLAGS) \
333 $(SETTINGS_CFLAGS) $(FREETYPE_CFLAGS) $(FONTCONFIG_CFLAGS) \ 333 $(SETTINGS_CFLAGS) $(FREETYPE_CFLAGS) $(FONTCONFIG_CFLAGS) \
334 $(LIBOTF_CFLAGS) $(M17N_FLT_CFLAGS) $(DEPFLAGS) $(PROFILING_CFLAGS) \ 334 $(LIBOTF_CFLAGS) $(M17N_FLT_CFLAGS) $(DEPFLAGS) \
335 $(LIBGNUTLS_CFLAGS) \ 335 $(LIBGNUTLS_CFLAGS) \
336 $(WARN_CFLAGS) $(WERROR_CFLAGS) $(CFLAGS) 336 $(WARN_CFLAGS) $(WERROR_CFLAGS) $(CFLAGS)
337ALL_OBJC_CFLAGS=$(ALL_CFLAGS) $(GNU_OBJC_CFLAGS) 337ALL_OBJC_CFLAGS=$(ALL_CFLAGS) $(GNU_OBJC_CFLAGS)
@@ -339,10 +339,10 @@ ALL_OBJC_CFLAGS=$(ALL_CFLAGS) $(GNU_OBJC_CFLAGS)
339.SUFFIXES: .m 339.SUFFIXES: .m
340.c.o: 340.c.o:
341 @$(MKDEPDIR) 341 @$(MKDEPDIR)
342 $(CC) -c $(CPPFLAGS) $(ALL_CFLAGS) $< 342 $(CC) -c $(CPPFLAGS) $(ALL_CFLAGS) $(PROFILING_CFLAGS) $<
343.m.o: 343.m.o:
344 @$(MKDEPDIR) 344 @$(MKDEPDIR)
345 $(CC) -c $(CPPFLAGS) $(ALL_OBJC_CFLAGS) $< 345 $(CC) -c $(CPPFLAGS) $(ALL_OBJC_CFLAGS) $(PROFILING_CFLAGS) $<
346 346
347## lastfile must follow all files whose initialized data areas should 347## lastfile must follow all files whose initialized data areas should
348## be dumped as pure by dump-emacs. 348## be dumped as pure by dump-emacs.
diff --git a/src/buffer.c b/src/buffer.c
index 8728b418812..3810d3db079 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -5883,29 +5883,44 @@ See also the functions `display-table-slot' and `set-display-table-slot'. */);
5883 DEFVAR_PER_BUFFER ("left-margin-width", &BVAR (current_buffer, left_margin_cols), 5883 DEFVAR_PER_BUFFER ("left-margin-width", &BVAR (current_buffer, left_margin_cols),
5884 Qintegerp, 5884 Qintegerp,
5885 doc: /* Width of left marginal area for display of a buffer. 5885 doc: /* Width of left marginal area for display of a buffer.
5886A value of nil means no marginal area. */); 5886A value of nil means no marginal area.
5887
5888Setting this variable does not take effect until a new buffer is displayed
5889in a window. To make the change take effect, call `set-window-buffer'. */);
5887 5890
5888 DEFVAR_PER_BUFFER ("right-margin-width", &BVAR (current_buffer, right_margin_cols), 5891 DEFVAR_PER_BUFFER ("right-margin-width", &BVAR (current_buffer, right_margin_cols),
5889 Qintegerp, 5892 Qintegerp,
5890 doc: /* Width of right marginal area for display of a buffer. 5893 doc: /* Width of right marginal area for display of a buffer.
5891A value of nil means no marginal area. */); 5894A value of nil means no marginal area.
5895
5896Setting this variable does not take effect until a new buffer is displayed
5897in a window. To make the change take effect, call `set-window-buffer'. */);
5892 5898
5893 DEFVAR_PER_BUFFER ("left-fringe-width", &BVAR (current_buffer, left_fringe_width), 5899 DEFVAR_PER_BUFFER ("left-fringe-width", &BVAR (current_buffer, left_fringe_width),
5894 Qintegerp, 5900 Qintegerp,
5895 doc: /* Width of this buffer's left fringe (in pixels). 5901 doc: /* Width of this buffer's left fringe (in pixels).
5896A value of 0 means no left fringe is shown in this buffer's window. 5902A value of 0 means no left fringe is shown in this buffer's window.
5897A value of nil means to use the left fringe width from the window's frame. */); 5903A value of nil means to use the left fringe width from the window's frame.
5904
5905Setting this variable does not take effect until a new buffer is displayed
5906in a window. To make the change take effect, call `set-window-buffer'. */);
5898 5907
5899 DEFVAR_PER_BUFFER ("right-fringe-width", &BVAR (current_buffer, right_fringe_width), 5908 DEFVAR_PER_BUFFER ("right-fringe-width", &BVAR (current_buffer, right_fringe_width),
5900 Qintegerp, 5909 Qintegerp,
5901 doc: /* Width of this buffer's right fringe (in pixels). 5910 doc: /* Width of this buffer's right fringe (in pixels).
5902A value of 0 means no right fringe is shown in this buffer's window. 5911A value of 0 means no right fringe is shown in this buffer's window.
5903A value of nil means to use the right fringe width from the window's frame. */); 5912A value of nil means to use the right fringe width from the window's frame.
5913
5914Setting this variable does not take effect until a new buffer is displayed
5915in a window. To make the change take effect, call `set-window-buffer'. */);
5904 5916
5905 DEFVAR_PER_BUFFER ("fringes-outside-margins", &BVAR (current_buffer, fringes_outside_margins), 5917 DEFVAR_PER_BUFFER ("fringes-outside-margins", &BVAR (current_buffer, fringes_outside_margins),
5906 Qnil, 5918 Qnil,
5907 doc: /* Non-nil means to display fringes outside display margins. 5919 doc: /* Non-nil means to display fringes outside display margins.
5908A value of nil means to display fringes between margins and buffer text. */); 5920A value of nil means to display fringes between margins and buffer text.
5921
5922Setting this variable does not take effect until a new buffer is displayed
5923in a window. To make the change take effect, call `set-window-buffer'. */);
5909 5924
5910 DEFVAR_PER_BUFFER ("scroll-bar-width", &BVAR (current_buffer, scroll_bar_width), 5925 DEFVAR_PER_BUFFER ("scroll-bar-width", &BVAR (current_buffer, scroll_bar_width),
5911 Qintegerp, 5926 Qintegerp,
diff --git a/src/coding.c b/src/coding.c
index cb81375a043..f9799035b3c 100644
--- a/src/coding.c
+++ b/src/coding.c
@@ -6072,17 +6072,18 @@ complement_process_encoding_system (Lisp_Object coding_system)
6072#define EOL_SEEN_CRLF 4 6072#define EOL_SEEN_CRLF 4
6073 6073
6074 6074
6075static Lisp_Object adjust_coding_eol_type (struct coding_system *coding, int eol_seen); 6075static Lisp_Object adjust_coding_eol_type (struct coding_system *coding,
6076 int eol_seen);
6076 6077
6077 6078
6078/* Return true iff all the source bytes are ASCII. 6079/* Return the number of ASCII characters at the head of the source.
6079 By side effects, set coding->head_ascii and coding->eol_seen. The 6080 By side effects, set coding->head_ascii and coding->eol_seen. The
6080 value of coding->eol_seen is "logical or" of EOL_SEEN_LF, 6081 value of coding->eol_seen is "logical or" of EOL_SEEN_LF,
6081 EOL_SEEN_CR, and EOL_SEEN_CRLF, but the value is reliable only when 6082 EOL_SEEN_CR, and EOL_SEEN_CRLF, but the value is reliable only when
6082 all the source bytes are ASCII. */ 6083 all the source bytes are ASCII. */
6083 6084
6084static bool 6085static int
6085detect_ascii (struct coding_system *coding) 6086check_ascii (struct coding_system *coding)
6086{ 6087{
6087 const unsigned char *src, *end; 6088 const unsigned char *src, *end;
6088 Lisp_Object eol_type = CODING_ID_EOL_TYPE (coding->id); 6089 Lisp_Object eol_type = CODING_ID_EOL_TYPE (coding->id);
@@ -6096,21 +6097,20 @@ detect_ascii (struct coding_system *coding)
6096 src = coding->source; 6097 src = coding->source;
6097 end = src + coding->src_bytes; 6098 end = src + coding->src_bytes;
6098 6099
6099 if (inhibit_eol_conversion) 6100 if (inhibit_eol_conversion
6101 || eol_seen != EOL_SEEN_NONE)
6100 { 6102 {
6101 /* We don't have to check EOL format. */ 6103 /* We don't have to check EOL format. */
6102 while (src < end && !( *src & 0x80)) src++; 6104 while (src < end && !( *src & 0x80)) src++;
6103 eol_seen = EOL_SEEN_LF; 6105 if (inhibit_eol_conversion)
6104 adjust_coding_eol_type (coding, eol_seen); 6106 {
6105 } 6107 eol_seen = EOL_SEEN_LF;
6106 else if (eol_seen != EOL_SEEN_NONE) 6108 adjust_coding_eol_type (coding, eol_seen);
6107 { 6109 }
6108 /* We don't have to check EOL format either. */
6109 while (src < end && !(*src & 0x80)) src++;
6110 } 6110 }
6111 else 6111 else
6112 { 6112 {
6113 end--; /* We look ahead one byte. */ 6113 end--; /* We look ahead one byte for "CR LF". */
6114 while (src < end) 6114 while (src < end)
6115 { 6115 {
6116 int c = *src; 6116 int c = *src;
@@ -6118,6 +6118,69 @@ detect_ascii (struct coding_system *coding)
6118 if (c & 0x80) 6118 if (c & 0x80)
6119 break; 6119 break;
6120 src++; 6120 src++;
6121 if (c == '\r')
6122 {
6123 if (*src == '\n')
6124 {
6125 eol_seen |= EOL_SEEN_CRLF;
6126 src++;
6127 }
6128 else
6129 eol_seen |= EOL_SEEN_CR;
6130 }
6131 else if (c == '\n')
6132 eol_seen |= EOL_SEEN_LF;
6133 }
6134 if (src == end)
6135 {
6136 int c = *src;
6137
6138 /* All bytes but the last one C are ASCII. */
6139 if (! (c & 0x80))
6140 {
6141 if (c == '\r')
6142 eol_seen |= EOL_SEEN_CR;
6143 else if (c == '\n')
6144 eol_seen |= EOL_SEEN_LF;
6145 src++;
6146 }
6147 }
6148 }
6149 coding->head_ascii = src - coding->source;
6150 coding->eol_seen = eol_seen;
6151 return (coding->head_ascii);
6152}
6153
6154
6155/* Return the number of characters at the source if all the bytes are
6156 valid UTF-8 (of Unicode range). Otherwise, return -1. By side
6157 effects, update coding->eol_seen. The value of coding->eol_seen is
6158 "logical or" of EOL_SEEN_LF, EOL_SEEN_CR, and EOL_SEEN_CRLF, but
6159 the value is reliable only when all the source bytes are valid
6160 UTF-8. */
6161
6162static int
6163check_utf_8 (struct coding_system *coding)
6164{
6165 const unsigned char *src, *end;
6166 int eol_seen = coding->eol_seen;
6167 int nchars = coding->head_ascii;
6168
6169 if (coding->head_ascii < 0)
6170 check_ascii (coding);
6171 else
6172 coding_set_source (coding);
6173 src = coding->source + coding->head_ascii;
6174 /* We look ahead one byte for CR LF. */
6175 end = coding->source + coding->src_bytes - 1;
6176
6177 while (src < end)
6178 {
6179 int c = *src;
6180
6181 if (UTF_8_1_OCTET_P (*src))
6182 {
6183 src++;
6121 if (c < 0x20) 6184 if (c < 0x20)
6122 { 6185 {
6123 if (c == '\r') 6186 if (c == '\r')
@@ -6126,6 +6189,7 @@ detect_ascii (struct coding_system *coding)
6126 { 6189 {
6127 eol_seen |= EOL_SEEN_CRLF; 6190 eol_seen |= EOL_SEEN_CRLF;
6128 src++; 6191 src++;
6192 nchars++;
6129 } 6193 }
6130 else 6194 else
6131 eol_seen |= EOL_SEEN_CR; 6195 eol_seen |= EOL_SEEN_CR;
@@ -6134,27 +6198,58 @@ detect_ascii (struct coding_system *coding)
6134 eol_seen |= EOL_SEEN_LF; 6198 eol_seen |= EOL_SEEN_LF;
6135 } 6199 }
6136 } 6200 }
6137 if (src > end) 6201 else if (UTF_8_2_OCTET_LEADING_P (c))
6138 /* The last two bytes are CR LF, which means that we have
6139 scanned all bytes. */
6140 end++;
6141 else if (src == end)
6142 { 6202 {
6143 end++; 6203 if (c < 0xC2 /* overlong sequence */
6144 if (! (*src & 0x80)) 6204 || src + 1 >= end
6145 { 6205 || ! UTF_8_EXTRA_OCTET_P (src[1]))
6146 if (*src == '\r') 6206 return -1;
6147 eol_seen |= EOL_SEEN_CR; 6207 src += 2;
6148 else if (*src == '\n')
6149 eol_seen |= EOL_SEEN_LF;
6150 src++;
6151 }
6152 } 6208 }
6153 adjust_coding_eol_type (coding, eol_seen); 6209 else if (UTF_8_3_OCTET_LEADING_P (c))
6210 {
6211 if (src + 2 >= end
6212 || ! (UTF_8_EXTRA_OCTET_P (src[1])
6213 && UTF_8_EXTRA_OCTET_P (src[2])))
6214 return -1;
6215 c = (((c & 0xF) << 12)
6216 | ((src[1] & 0x3F) << 6) | (src[2] & 0x3F));
6217 if (c < 0x800 /* overlong sequence */
6218 || (c >= 0xd800 && c < 0xe000)) /* surrogates (invalid) */
6219 return -1;
6220 src += 3;
6221 }
6222 else if (UTF_8_4_OCTET_LEADING_P (c))
6223 {
6224 if (src + 3 >= end
6225 || ! (UTF_8_EXTRA_OCTET_P (src[1])
6226 && UTF_8_EXTRA_OCTET_P (src[2])
6227 && UTF_8_EXTRA_OCTET_P (src[3])))
6228 return -1;
6229 c = (((c & 0x7) << 18) | ((src[1] & 0x3F) << 12)
6230 | ((src[2] & 0x3F) << 6) | (src[3] & 0x3F));
6231 if (c < 0x10000 /* overlong sequence */
6232 || c >= 0x110000) /* non-Unicode character */
6233 return -1;
6234 src += 4;
6235 }
6236 else
6237 return -1;
6238 nchars++;
6239 }
6240
6241 if (src == end)
6242 {
6243 if (! UTF_8_1_OCTET_P (*src))
6244 return -1;
6245 nchars++;
6246 if (*src == '\r')
6247 eol_seen |= EOL_SEEN_CR;
6248 else if (*src == '\n')
6249 eol_seen |= EOL_SEEN_LF;
6154 } 6250 }
6155 coding->head_ascii = src - coding->source;
6156 coding->eol_seen = eol_seen; 6251 coding->eol_seen = eol_seen;
6157 return (src == end); 6252 return nchars;
6158} 6253}
6159 6254
6160 6255
@@ -6269,6 +6364,9 @@ adjust_coding_eol_type (struct coding_system *coding, int eol_seen)
6269 Lisp_Object eol_type; 6364 Lisp_Object eol_type;
6270 6365
6271 eol_type = CODING_ID_EOL_TYPE (coding->id); 6366 eol_type = CODING_ID_EOL_TYPE (coding->id);
6367 if (! VECTORP (eol_type))
6368 /* Already adjusted. */
6369 return eol_type;
6272 if (eol_seen & EOL_SEEN_LF) 6370 if (eol_seen & EOL_SEEN_LF)
6273 { 6371 {
6274 coding->id = CODING_SYSTEM_ID (AREF (eol_type, 0)); 6372 coding->id = CODING_SYSTEM_ID (AREF (eol_type, 0));
@@ -6360,7 +6458,8 @@ detect_coding (struct coding_system *coding)
6360 { 6458 {
6361 coding->eol_seen |= EOL_SEEN_CRLF; 6459 coding->eol_seen |= EOL_SEEN_CRLF;
6362 src++; 6460 src++;
6363 coding->head_ascii++; 6461 if (! eight_bit_found)
6462 coding->head_ascii++;
6364 } 6463 }
6365 else 6464 else
6366 coding->eol_seen |= EOL_SEEN_CR; 6465 coding->eol_seen |= EOL_SEEN_CR;
@@ -6461,9 +6560,14 @@ detect_coding (struct coding_system *coding)
6461 coding_systems 6560 coding_systems
6462 = AREF (CODING_ID_ATTRS (coding->id), coding_attr_utf_bom); 6561 = AREF (CODING_ID_ATTRS (coding->id), coding_attr_utf_bom);
6463 detect_info.found = detect_info.rejected = 0; 6562 detect_info.found = detect_info.rejected = 0;
6464 if (detect_ascii (coding)) 6563 if (check_ascii (coding) == coding->src_bytes)
6465 { 6564 {
6565 int head_ascii = coding->head_ascii;
6566
6567 if (coding->eol_seen != EOL_SEEN_NONE)
6568 adjust_coding_eol_type (coding, coding->eol_seen);
6466 setup_coding_system (XCDR (coding_systems), coding); 6569 setup_coding_system (XCDR (coding_systems), coding);
6570 coding->head_ascii = head_ascii;
6467 } 6571 }
6468 else 6572 else
6469 { 6573 {
@@ -7620,15 +7724,27 @@ decode_coding_gap (struct coding_system *coding,
7620 if (CODING_REQUIRE_DETECTION (coding)) 7724 if (CODING_REQUIRE_DETECTION (coding))
7621 detect_coding (coding); 7725 detect_coding (coding);
7622 attrs = CODING_ID_ATTRS (coding->id); 7726 attrs = CODING_ID_ATTRS (coding->id);
7623 if (! disable_ascii_optimization) 7727 if (! disable_ascii_optimization
7624 { 7728 && ! coding->src_multibyte
7625 if (! NILP (CODING_ATTR_ASCII_COMPAT (attrs)) 7729 && ! NILP (CODING_ATTR_ASCII_COMPAT (attrs))
7626 && NILP (CODING_ATTR_POST_READ (attrs)) 7730 && NILP (CODING_ATTR_POST_READ (attrs))
7627 && NILP (get_translation_table (attrs, 0, NULL)) 7731 && NILP (get_translation_table (attrs, 0, NULL)))
7628 && (coding->head_ascii >= 0 /* We've already called detect_coding */ 7732 {
7629 ? coding->head_ascii == bytes 7733 chars = coding->head_ascii;
7630 : detect_ascii (coding))) 7734 if (chars < 0)
7735 chars = check_ascii (coding);
7736 if (chars != bytes)
7737 {
7738 if (EQ (CODING_ATTR_TYPE (attrs), Qutf_8))
7739 chars = check_utf_8 (coding);
7740 else
7741 chars = -1;
7742 }
7743 if (chars >= 0)
7631 { 7744 {
7745 if (coding->eol_seen != EOL_SEEN_NONE)
7746 adjust_coding_eol_type (coding, coding->eol_seen);
7747
7632 if (coding->eol_seen == EOL_SEEN_CR) 7748 if (coding->eol_seen == EOL_SEEN_CR)
7633 { 7749 {
7634 unsigned char *src_end = GAP_END_ADDR; 7750 unsigned char *src_end = GAP_END_ADDR;
@@ -7645,6 +7761,7 @@ decode_coding_gap (struct coding_system *coding,
7645 unsigned char *src = GAP_END_ADDR; 7761 unsigned char *src = GAP_END_ADDR;
7646 unsigned char *src_beg = src - coding->src_bytes; 7762 unsigned char *src_beg = src - coding->src_bytes;
7647 unsigned char *dst = src; 7763 unsigned char *dst = src;
7764 ptrdiff_t diff;
7648 7765
7649 while (src_beg < src) 7766 while (src_beg < src)
7650 { 7767 {
@@ -7652,10 +7769,13 @@ decode_coding_gap (struct coding_system *coding,
7652 if (*src == '\n') 7769 if (*src == '\n')
7653 src--; 7770 src--;
7654 } 7771 }
7655 bytes -= dst - src; 7772 diff = dst - src;
7773 bytes -= diff;
7774 chars -= diff;
7656 } 7775 }
7657 coding->produced_char = coding->produced = bytes; 7776 coding->produced = bytes;
7658 insert_from_gap (bytes, bytes, 1); 7777 coding->produced_char = chars;
7778 insert_from_gap (chars, bytes, 1);
7659 return; 7779 return;
7660 } 7780 }
7661 } 7781 }
@@ -10877,7 +10997,7 @@ decode text as usual. */);
10877 DEFVAR_BOOL ("disable-ascii-optimization", disable_ascii_optimization, 10997 DEFVAR_BOOL ("disable-ascii-optimization", disable_ascii_optimization,
10878 doc: /* If non-nil, Emacs does not optimize code decoder for ASCII files. 10998 doc: /* If non-nil, Emacs does not optimize code decoder for ASCII files.
10879Internal use only. Removed after the experimental optimizer gets stable. */); 10999Internal use only. Removed after the experimental optimizer gets stable. */);
10880 disable_ascii_optimization = 1; 11000 disable_ascii_optimization = 0;
10881 11001
10882 DEFVAR_LISP ("translation-table-for-input", Vtranslation_table_for_input, 11002 DEFVAR_LISP ("translation-table-for-input", Vtranslation_table_for_input,
10883 doc: /* Char table for translating self-inserting characters. 11003 doc: /* Char table for translating self-inserting characters.
diff --git a/src/fileio.c b/src/fileio.c
index 2047338f03e..1049522e5a9 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -81,6 +81,25 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
81#define DRIVE_LETTER(x) c_tolower (x) 81#define DRIVE_LETTER(x) c_tolower (x)
82#endif 82#endif
83 83
84#ifdef HAVE_POSIX_ACL
85/* FIXME: this macro was copied from gnulib's private acl-internal.h
86 header file. */
87/* Recognize some common errors such as from an NFS mount that does
88 not support ACLs, even when local drives do. */
89#if defined __APPLE__ && defined __MACH__ /* Mac OS X */
90#define ACL_NOT_WELL_SUPPORTED(Err) \
91 ((Err) == ENOTSUP || (Err) == ENOSYS || (Err) == EINVAL || (Err) == EBUSY || (Err) == ENOENT)
92#elif defined EOPNOTSUPP /* Tru64 NFS */
93#define ACL_NOT_WELL_SUPPORTED(Err) \
94 ((Err) == ENOTSUP || (Err) == ENOSYS || (Err) == EINVAL || (Err) == EBUSY || (Err) == EOPNOTSUPP)
95#elif defined WINDOWSNT
96#define ACL_NOT_WELL_SUPPORTED(Err) ((Err) == ENOTSUP)
97#else
98#define ACL_NOT_WELL_SUPPORTED(Err) \
99 ((Err) == ENOTSUP || (Err) == ENOSYS || (Err) == EINVAL || (Err) == EBUSY)
100#endif
101#endif /* HAVE_POSIX_ACL */
102
84#include "systime.h" 103#include "systime.h"
85#include <allocator.h> 104#include <allocator.h>
86#include <careadlinkat.h> 105#include <careadlinkat.h>
@@ -2011,7 +2030,7 @@ entries (depending on how Emacs was built). */)
2011 { 2030 {
2012#ifdef HAVE_POSIX_ACL 2031#ifdef HAVE_POSIX_ACL
2013 acl = acl_get_file (SDATA (encoded_file), ACL_TYPE_ACCESS); 2032 acl = acl_get_file (SDATA (encoded_file), ACL_TYPE_ACCESS);
2014 if (acl == NULL && errno != ENOTSUP) 2033 if (acl == NULL && !ACL_NOT_WELL_SUPPORTED (errno))
2015 report_file_error ("Getting ACL", Fcons (file, Qnil)); 2034 report_file_error ("Getting ACL", Fcons (file, Qnil));
2016#endif 2035#endif
2017 } 2036 }
@@ -2055,7 +2074,7 @@ entries (depending on how Emacs was built). */)
2055 { 2074 {
2056 bool fail = 2075 bool fail =
2057 acl_set_file (SDATA (encoded_newname), ACL_TYPE_ACCESS, acl) != 0; 2076 acl_set_file (SDATA (encoded_newname), ACL_TYPE_ACCESS, acl) != 0;
2058 if (fail && errno != ENOTSUP) 2077 if (fail && !ACL_NOT_WELL_SUPPORTED (errno))
2059 report_file_error ("Setting ACL", Fcons (newname, Qnil)); 2078 report_file_error ("Setting ACL", Fcons (newname, Qnil));
2060 2079
2061 acl_free (acl); 2080 acl_free (acl);
@@ -2087,7 +2106,7 @@ entries (depending on how Emacs was built). */)
2087 2106
2088#ifdef HAVE_POSIX_ACL 2107#ifdef HAVE_POSIX_ACL
2089 acl = acl_get_fd (ifd); 2108 acl = acl_get_fd (ifd);
2090 if (acl == NULL && errno != ENOTSUP) 2109 if (acl == NULL && !ACL_NOT_WELL_SUPPORTED (errno))
2091 report_file_error ("Getting ACL", Fcons (file, Qnil)); 2110 report_file_error ("Getting ACL", Fcons (file, Qnil));
2092#endif 2111#endif
2093 } 2112 }
@@ -2176,7 +2195,7 @@ entries (depending on how Emacs was built). */)
2176 if (acl != NULL) 2195 if (acl != NULL)
2177 { 2196 {
2178 bool fail = acl_set_fd (ofd, acl) != 0; 2197 bool fail = acl_set_fd (ofd, acl) != 0;
2179 if (fail && errno != ENOTSUP) 2198 if (fail && !ACL_NOT_WELL_SUPPORTED (errno))
2180 report_file_error ("Setting ACL", Fcons (newname, Qnil)); 2199 report_file_error ("Setting ACL", Fcons (newname, Qnil));
2181 2200
2182 acl_free (acl); 2201 acl_free (acl);
@@ -3174,7 +3193,7 @@ support. */)
3174 fail = (acl_set_file (SSDATA (encoded_absname), ACL_TYPE_ACCESS, 3193 fail = (acl_set_file (SSDATA (encoded_absname), ACL_TYPE_ACCESS,
3175 acl) 3194 acl)
3176 != 0); 3195 != 0);
3177 if (fail && errno != ENOTSUP) 3196 if (fail && !ACL_NOT_WELL_SUPPORTED (errno))
3178 report_file_error ("Setting ACL", Fcons (absname, Qnil)); 3197 report_file_error ("Setting ACL", Fcons (absname, Qnil));
3179 3198
3180 acl_free (acl); 3199 acl_free (acl);
@@ -5816,7 +5835,7 @@ before any other event (mouse or keypress) is handled. */)
5816 if ((NILP (last_nonmenu_event) || CONSP (last_nonmenu_event)) 5835 if ((NILP (last_nonmenu_event) || CONSP (last_nonmenu_event))
5817 && use_dialog_box 5836 && use_dialog_box
5818 && use_file_dialog 5837 && use_file_dialog
5819 && have_menus_p ()) 5838 && window_system_available (SELECTED_FRAME ()))
5820 return Qt; 5839 return Qt;
5821#endif 5840#endif
5822 return Qnil; 5841 return Qnil;
diff --git a/src/fns.c b/src/fns.c
index b3a1dc2317a..08c6f055f38 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -1551,7 +1551,7 @@ the value of a list `foo'. */)
1551 1551
1552 tail = list; 1552 tail = list;
1553 prev = Qnil; 1553 prev = Qnil;
1554 while (!NILP (tail)) 1554 while (CONSP (tail))
1555 { 1555 {
1556 CHECK_LIST_CONS (tail, list); 1556 CHECK_LIST_CONS (tail, list);
1557 tem = XCAR (tail); 1557 tem = XCAR (tail);
@@ -2443,10 +2443,9 @@ is nil, and `use-dialog-box' is non-nil. */)
2443 CHECK_STRING (prompt); 2443 CHECK_STRING (prompt);
2444 2444
2445#ifdef HAVE_MENUS 2445#ifdef HAVE_MENUS
2446 if (FRAME_WINDOW_P (SELECTED_FRAME ()) 2446 if ((NILP (last_nonmenu_event) || CONSP (last_nonmenu_event))
2447 && (NILP (last_nonmenu_event) || CONSP (last_nonmenu_event))
2448 && use_dialog_box 2447 && use_dialog_box
2449 && have_menus_p ()) 2448 && window_system_available (SELECTED_FRAME ()))
2450 { 2449 {
2451 Lisp_Object pane, menu, obj; 2450 Lisp_Object pane, menu, obj;
2452 redisplay_preserve_echo_area (4); 2451 redisplay_preserve_echo_area (4);
diff --git a/src/font.c b/src/font.c
index 0b0144f3197..6247eeca948 100644
--- a/src/font.c
+++ b/src/font.c
@@ -4844,11 +4844,9 @@ If the named font is not yet loaded, return nil. */)
4844 Lisp_Object info; 4844 Lisp_Object info;
4845 Lisp_Object font_object; 4845 Lisp_Object font_object;
4846 4846
4847 (*check_window_system_func) ();
4848
4849 if (! FONTP (name)) 4847 if (! FONTP (name))
4850 CHECK_STRING (name); 4848 CHECK_STRING (name);
4851 f = decode_live_frame (frame); 4849 f = decode_window_system_frame (frame);
4852 4850
4853 if (STRINGP (name)) 4851 if (STRINGP (name))
4854 { 4852 {
diff --git a/src/fontset.c b/src/fontset.c
index 3578bc9403d..2f6313c4214 100644
--- a/src/fontset.c
+++ b/src/fontset.c
@@ -179,10 +179,6 @@ static int next_fontset_id;
179 font for each character. */ 179 font for each character. */
180static Lisp_Object Vdefault_fontset; 180static Lisp_Object Vdefault_fontset;
181 181
182/* Check if any window system is used now. */
183void (*check_window_system_func) (void);
184
185
186/* Prototype declarations for static functions. */ 182/* Prototype declarations for static functions. */
187static Lisp_Object make_fontset (Lisp_Object, Lisp_Object, Lisp_Object); 183static Lisp_Object make_fontset (Lisp_Object, Lisp_Object, Lisp_Object);
188 184
@@ -1213,7 +1209,7 @@ If REGEXPP is non-nil, PATTERN is a regular expression. */)
1213 Lisp_Object fontset; 1209 Lisp_Object fontset;
1214 int id; 1210 int id;
1215 1211
1216 (*check_window_system_func) (); 1212 check_window_system (NULL);
1217 1213
1218 CHECK_STRING (pattern); 1214 CHECK_STRING (pattern);
1219 1215
@@ -1919,8 +1915,7 @@ format is the same as above. */)
1919 Lisp_Object val, elt; 1915 Lisp_Object val, elt;
1920 int c, i, j, k; 1916 int c, i, j, k;
1921 1917
1922 (*check_window_system_func) (); 1918 check_window_system (NULL);
1923
1924 fontset = check_fontset_name (fontset, &frame); 1919 fontset = check_fontset_name (fontset, &frame);
1925 1920
1926 /* Recode fontsets realized on FRAME from the base fontset FONTSET 1921 /* Recode fontsets realized on FRAME from the base fontset FONTSET
diff --git a/src/fontset.h b/src/fontset.h
index 07ee5d65c25..926520c8001 100644
--- a/src/fontset.h
+++ b/src/fontset.h
@@ -26,9 +26,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
26#ifndef EMACS_FONTSET_H 26#ifndef EMACS_FONTSET_H
27#define EMACS_FONTSET_H 27#define EMACS_FONTSET_H
28 28
29/* Check if any window system is used now. */
30extern void (*check_window_system_func) (void);
31
32struct face; 29struct face;
33 30
34extern void free_face_fontset (FRAME_PTR, struct face *); 31extern void free_face_fontset (FRAME_PTR, struct face *);
diff --git a/src/frame.c b/src/frame.c
index 0aeaf4cf417..ccd50122f50 100644
--- a/src/frame.c
+++ b/src/frame.c
@@ -149,6 +149,37 @@ decode_any_frame (register Lisp_Object frame)
149 return XFRAME (frame); 149 return XFRAME (frame);
150} 150}
151 151
152bool
153window_system_available (struct frame *f)
154{
155 if (f)
156 return FRAME_WINDOW_P (f) || FRAME_MSDOS_P (f);
157 else
158#ifdef HAVE_WINDOW_SYSTEM
159 return x_display_list != NULL;
160#else
161 return 0;
162#endif
163}
164
165struct frame *
166decode_window_system_frame (Lisp_Object frame)
167{
168 struct frame *f = decode_live_frame (frame);
169
170 if (!window_system_available (f))
171 error ("Window system frame should be used");
172 return f;
173}
174
175void
176check_window_system (struct frame *f)
177{
178 if (!window_system_available (f))
179 error (f ? "Window system frame should be used"
180 : "Window system is not in use or not initialized");
181}
182
152static void 183static void
153set_menu_bar_lines_1 (Lisp_Object window, int n) 184set_menu_bar_lines_1 (Lisp_Object window, int n)
154{ 185{
@@ -803,10 +834,18 @@ do_switch_frame (Lisp_Object frame, int track, int for_deletion, Lisp_Object nor
803 834
804 if (FRAME_TERMCAP_P (XFRAME (frame)) || FRAME_MSDOS_P (XFRAME (frame))) 835 if (FRAME_TERMCAP_P (XFRAME (frame)) || FRAME_MSDOS_P (XFRAME (frame)))
805 { 836 {
806 if (FRAMEP (FRAME_TTY (XFRAME (frame))->top_frame)) 837 Lisp_Object top_frame = FRAME_TTY (XFRAME (frame))->top_frame;
807 /* Mark previously displayed frame as now obscured. */ 838
808 SET_FRAME_VISIBLE (XFRAME (FRAME_TTY (XFRAME (frame))->top_frame), 2); 839 /* Don't mark the frame garbaged and/or obscured if we are
809 SET_FRAME_VISIBLE (XFRAME (frame), 1); 840 switching to the frame that is already the top frame of that
841 TTY. */
842 if (!EQ (frame, top_frame))
843 {
844 if (FRAMEP (top_frame))
845 /* Mark previously displayed frame as now obscured. */
846 SET_FRAME_VISIBLE (XFRAME (top_frame), 2);
847 SET_FRAME_VISIBLE (XFRAME (frame), 1);
848 }
810 FRAME_TTY (XFRAME (frame))->top_frame = frame; 849 FRAME_TTY (XFRAME (frame))->top_frame = frame;
811 } 850 }
812 851
@@ -3493,9 +3532,7 @@ and the class is `Emacs.CLASS.SUBCLASS'. */)
3493 (Lisp_Object attribute, Lisp_Object class, Lisp_Object component, 3532 (Lisp_Object attribute, Lisp_Object class, Lisp_Object component,
3494 Lisp_Object subclass) 3533 Lisp_Object subclass)
3495{ 3534{
3496#ifdef HAVE_X_WINDOWS 3535 check_window_system (NULL);
3497 check_x ();
3498#endif
3499 3536
3500 return xrdb_get_resource (check_x_display_info (Qnil)->xrdb, 3537 return xrdb_get_resource (check_x_display_info (Qnil)->xrdb,
3501 attribute, class, component, subclass); 3538 attribute, class, component, subclass);
diff --git a/src/frame.h b/src/frame.h
index 46e18dd8ddb..b69f19b7ef8 100644
--- a/src/frame.h
+++ b/src/frame.h
@@ -958,6 +958,7 @@ extern Lisp_Object Qnoelisp;
958extern struct frame *last_nonminibuf_frame; 958extern struct frame *last_nonminibuf_frame;
959 959
960extern void set_menu_bar_lines (struct frame *, Lisp_Object, Lisp_Object); 960extern void set_menu_bar_lines (struct frame *, Lisp_Object, Lisp_Object);
961extern struct frame *decode_window_system_frame (Lisp_Object);
961extern struct frame *decode_live_frame (Lisp_Object); 962extern struct frame *decode_live_frame (Lisp_Object);
962extern struct frame *decode_any_frame (Lisp_Object); 963extern struct frame *decode_any_frame (Lisp_Object);
963extern struct frame *make_initial_frame (void); 964extern struct frame *make_initial_frame (void);
@@ -968,6 +969,8 @@ extern struct frame *make_frame_without_minibuffer (Lisp_Object,
968 struct kboard *, 969 struct kboard *,
969 Lisp_Object); 970 Lisp_Object);
970#endif /* HAVE_WINDOW_SYSTEM */ 971#endif /* HAVE_WINDOW_SYSTEM */
972extern bool window_system_available (struct frame *);
973extern void check_window_system (struct frame *);
971extern void frame_make_pointer_invisible (void); 974extern void frame_make_pointer_invisible (void);
972extern void frame_make_pointer_visible (void); 975extern void frame_make_pointer_visible (void);
973extern Lisp_Object delete_frame (Lisp_Object, Lisp_Object); 976extern Lisp_Object delete_frame (Lisp_Object, Lisp_Object);
diff --git a/src/image.c b/src/image.c
index cac23b7fa87..2dae63a294f 100644
--- a/src/image.c
+++ b/src/image.c
@@ -889,7 +889,7 @@ or omitted means use the selected frame. */)
889 size = Qnil; 889 size = Qnil;
890 if (valid_image_p (spec)) 890 if (valid_image_p (spec))
891 { 891 {
892 struct frame *f = check_x_frame (frame); 892 struct frame *f = decode_window_system_frame (frame);
893 ptrdiff_t id = lookup_image (f, spec); 893 ptrdiff_t id = lookup_image (f, spec);
894 struct image *img = IMAGE_FROM_ID (f, id); 894 struct image *img = IMAGE_FROM_ID (f, id);
895 int width = img->width + 2 * img->hmargin; 895 int width = img->width + 2 * img->hmargin;
@@ -919,7 +919,7 @@ or omitted means use the selected frame. */)
919 mask = Qnil; 919 mask = Qnil;
920 if (valid_image_p (spec)) 920 if (valid_image_p (spec))
921 { 921 {
922 struct frame *f = check_x_frame (frame); 922 struct frame *f = decode_window_system_frame (frame);
923 ptrdiff_t id = lookup_image (f, spec); 923 ptrdiff_t id = lookup_image (f, spec);
924 struct image *img = IMAGE_FROM_ID (f, id); 924 struct image *img = IMAGE_FROM_ID (f, id);
925 if (img->mask) 925 if (img->mask)
@@ -942,7 +942,7 @@ or omitted means use the selected frame. */)
942 ext = Qnil; 942 ext = Qnil;
943 if (valid_image_p (spec)) 943 if (valid_image_p (spec))
944 { 944 {
945 struct frame *f = check_x_frame (frame); 945 struct frame *f = decode_window_system_frame (frame);
946 ptrdiff_t id = lookup_image (f, spec); 946 ptrdiff_t id = lookup_image (f, spec);
947 struct image *img = IMAGE_FROM_ID (f, id); 947 struct image *img = IMAGE_FROM_ID (f, id);
948 ext = img->lisp_data; 948 ext = img->lisp_data;
@@ -1550,7 +1550,7 @@ which is then usually a filename. */)
1550 if (!(EQ (filter, Qnil) || FRAMEP (filter))) 1550 if (!(EQ (filter, Qnil) || FRAMEP (filter)))
1551 clear_image_caches (filter); 1551 clear_image_caches (filter);
1552 else 1552 else
1553 clear_image_cache (check_x_frame (filter), Qt); 1553 clear_image_cache (decode_window_system_frame (filter), Qt);
1554 1554
1555 return Qnil; 1555 return Qnil;
1556} 1556}
@@ -1581,7 +1581,7 @@ FRAME t means refresh the image on all frames. */)
1581 } 1581 }
1582 } 1582 }
1583 else 1583 else
1584 uncache_image (check_x_frame (frame), spec); 1584 uncache_image (decode_window_system_frame (frame), spec);
1585 1585
1586 return Qnil; 1586 return Qnil;
1587} 1587}
diff --git a/src/indent.c b/src/indent.c
index 67796ab8a8f..47358e17db8 100644
--- a/src/indent.c
+++ b/src/indent.c
@@ -2006,11 +2006,15 @@ whether or not it is currently displayed in some window. */)
2006 const char *s = SSDATA (it.string); 2006 const char *s = SSDATA (it.string);
2007 const char *e = s + SBYTES (it.string); 2007 const char *e = s + SBYTES (it.string);
2008 2008
2009 disp_string_at_start_p =
2009 /* If it.area is anything but TEXT_AREA, we need not bother 2010 /* If it.area is anything but TEXT_AREA, we need not bother
2010 about the display string, as it doesn't affect cursor 2011 about the display string, as it doesn't affect cursor
2011 positioning. */ 2012 positioning. */
2012 disp_string_at_start_p = 2013 it.area == TEXT_AREA
2013 it.string_from_display_prop_p && it.area == TEXT_AREA; 2014 && it.string_from_display_prop_p
2015 /* A display string on anything but buffer text (e.g., on
2016 an overlay string) doesn't affect cursor positioning. */
2017 && (it.sp > 0 && it.stack[it.sp - 1].method == GET_FROM_BUFFER);
2014 while (s < e) 2018 while (s < e)
2015 { 2019 {
2016 if (*s++ == '\n') 2020 if (*s++ == '\n')
diff --git a/src/insdel.c b/src/insdel.c
index 246ba80f290..8029291cd68 100644
--- a/src/insdel.c
+++ b/src/insdel.c
@@ -983,6 +983,9 @@ insert_from_string_1 (Lisp_Object string, ptrdiff_t pos, ptrdiff_t pos_byte,
983void 983void
984insert_from_gap (ptrdiff_t nchars, ptrdiff_t nbytes, bool text_at_gap_tail) 984insert_from_gap (ptrdiff_t nchars, ptrdiff_t nbytes, bool text_at_gap_tail)
985{ 985{
986 int ins_charpos = GPT;
987 int ins_bytepos = GPT_BYTE;
988
986 if (NILP (BVAR (current_buffer, enable_multibyte_characters))) 989 if (NILP (BVAR (current_buffer, enable_multibyte_characters)))
987 nchars = nbytes; 990 nchars = nbytes;
988 991
@@ -1003,18 +1006,18 @@ insert_from_gap (ptrdiff_t nchars, ptrdiff_t nbytes, bool text_at_gap_tail)
1003 1006
1004 eassert (GPT <= GPT_BYTE); 1007 eassert (GPT <= GPT_BYTE);
1005 1008
1006 adjust_overlays_for_insert (GPT - nchars, nchars); 1009 adjust_overlays_for_insert (ins_charpos, nchars);
1007 adjust_markers_for_insert (GPT - nchars, GPT_BYTE - nbytes, 1010 adjust_markers_for_insert (ins_charpos, ins_bytepos,
1008 GPT, GPT_BYTE, 0); 1011 ins_charpos + nchars, ins_bytepos + nbytes, 0);
1009 1012
1010 if (buffer_intervals (current_buffer)) 1013 if (buffer_intervals (current_buffer))
1011 { 1014 {
1012 offset_intervals (current_buffer, GPT - nchars, nchars); 1015 offset_intervals (current_buffer, ins_charpos, nchars);
1013 graft_intervals_into_buffer (NULL, GPT - nchars, nchars, 1016 graft_intervals_into_buffer (NULL, ins_charpos, nchars,
1014 current_buffer, 0); 1017 current_buffer, 0);
1015 } 1018 }
1016 1019
1017 if (! text_at_gap_tail && GPT - nchars < PT) 1020 if (ins_charpos < PT)
1018 adjust_point (nchars, nbytes); 1021 adjust_point (nchars, nbytes);
1019 1022
1020 check_markers (); 1023 check_markers ();
diff --git a/src/keyboard.c b/src/keyboard.c
index beba3025887..12407bd536c 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -72,7 +72,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
72#include TERM_HEADER 72#include TERM_HEADER
73#endif /* HAVE_WINDOW_SYSTEM */ 73#endif /* HAVE_WINDOW_SYSTEM */
74 74
75/* Variables for blockinput.h: */ 75/* Variables for blockinput.h: */
76 76
77/* Positive if interrupt input is blocked right now. */ 77/* Positive if interrupt input is blocked right now. */
78volatile int interrupt_input_blocked; 78volatile int interrupt_input_blocked;
@@ -4198,16 +4198,7 @@ timer_start_idle (void)
4198 timer_last_idleness_start_time = timer_idleness_start_time; 4198 timer_last_idleness_start_time = timer_idleness_start_time;
4199 4199
4200 /* Mark all idle-time timers as once again candidates for running. */ 4200 /* Mark all idle-time timers as once again candidates for running. */
4201 for (timers = Vtimer_idle_list; CONSP (timers); timers = XCDR (timers)) 4201 call0 (intern ("internal-timer-start-idle"));
4202 {
4203 Lisp_Object timer;
4204
4205 timer = XCAR (timers);
4206
4207 if (!VECTORP (timer) || ASIZE (timer) != 9)
4208 continue;
4209 ASET (timer, 0, Qnil);
4210 }
4211} 4202}
4212 4203
4213/* Record that Emacs is no longer idle, so stop running idle-time timers. */ 4204/* Record that Emacs is no longer idle, so stop running idle-time timers. */
@@ -4337,10 +4328,10 @@ timer_check_2 (Lisp_Object timers, Lisp_Object idle_timers)
4337 } 4328 }
4338 4329
4339 idle_timer_ripe = EMACS_TIME_LE (idle_timer_time, idleness_now); 4330 idle_timer_ripe = EMACS_TIME_LE (idle_timer_time, idleness_now);
4340 idle_timer_difference = 4331 idle_timer_difference
4341 (idle_timer_ripe 4332 = (idle_timer_ripe
4342 ? sub_emacs_time (idleness_now, idle_timer_time) 4333 ? sub_emacs_time (idleness_now, idle_timer_time)
4343 : sub_emacs_time (idle_timer_time, idleness_now)); 4334 : sub_emacs_time (idle_timer_time, idleness_now));
4344 } 4335 }
4345 4336
4346 /* Decide which timer is the next timer, 4337 /* Decide which timer is the next timer,
diff --git a/src/lisp.h b/src/lisp.h
index 82cf0cb2678..bcb866b4cc4 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -3771,11 +3771,6 @@ extern void syms_of_xml (void);
3771extern void xml_cleanup_parser (void); 3771extern void xml_cleanup_parser (void);
3772#endif 3772#endif
3773 3773
3774#ifdef HAVE_MENUS
3775/* Defined in (x|w32)fns.c, nsfns.m... */
3776extern int have_menus_p (void);
3777#endif
3778
3779#ifdef HAVE_DBUS 3774#ifdef HAVE_DBUS
3780/* Defined in dbusbind.c. */ 3775/* Defined in dbusbind.c. */
3781void syms_of_dbusbind (void); 3776void syms_of_dbusbind (void);
diff --git a/src/menu.c b/src/menu.c
index ffb5c3bc936..58558d5aedd 100644
--- a/src/menu.c
+++ b/src/menu.c
@@ -1085,7 +1085,8 @@ no quit occurs and `x-popup-menu' returns nil. */)
1085#ifdef HAVE_MENUS 1085#ifdef HAVE_MENUS
1086 { 1086 {
1087 bool get_current_pos_p = 0; 1087 bool get_current_pos_p = 0;
1088 /* FIXME!! check_w32 (); or check_x (); or check_ns (); */ 1088
1089 check_window_system (SELECTED_FRAME ());
1089 1090
1090 /* Decode the first argument: find the window and the coordinates. */ 1091 /* Decode the first argument: find the window and the coordinates. */
1091 if (EQ (position, Qt) 1092 if (EQ (position, Qt)
diff --git a/src/minibuf.c b/src/minibuf.c
index 68c39310f01..4cc1f8d435a 100644
--- a/src/minibuf.c
+++ b/src/minibuf.c
@@ -1800,17 +1800,21 @@ the values STRING, PREDICATE and `lambda'. */)
1800 { 1800 {
1801 struct Lisp_Hash_Table *h = XHASH_TABLE (collection); 1801 struct Lisp_Hash_Table *h = XHASH_TABLE (collection);
1802 i = hash_lookup (h, string, NULL); 1802 i = hash_lookup (h, string, NULL);
1803 Lisp_Object key = Qnil;
1803 if (i >= 0) 1804 if (i >= 0)
1804 tem = HASH_KEY (h, i); 1805 tem = HASH_KEY (h, i);
1805 else 1806 else
1806 for (i = 0; i < HASH_TABLE_SIZE (h); ++i) 1807 for (i = 0; i < HASH_TABLE_SIZE (h); ++i)
1807 if (!NILP (HASH_HASH (h, i)) 1808 if (!NILP (HASH_HASH (h, i))
1809 && (key = HASH_KEY (h, i),
1810 SYMBOLP (key) ? key = Fsymbol_name (key) : key,
1811 STRINGP (key))
1808 && EQ (Fcompare_strings (string, make_number (0), Qnil, 1812 && EQ (Fcompare_strings (string, make_number (0), Qnil,
1809 HASH_KEY (h, i), make_number (0) , Qnil, 1813 key, make_number (0) , Qnil,
1810 completion_ignore_case ? Qt : Qnil), 1814 completion_ignore_case ? Qt : Qnil),
1811 Qt)) 1815 Qt))
1812 { 1816 {
1813 tem = HASH_KEY (h, i); 1817 tem = key;
1814 break; 1818 break;
1815 } 1819 }
1816 if (!STRINGP (tem)) 1820 if (!STRINGP (tem))
diff --git a/src/msdos.c b/src/msdos.c
index 695cca60728..a2bcc06ac17 100644
--- a/src/msdos.c
+++ b/src/msdos.c
@@ -1920,7 +1920,7 @@ dos_get_saved_screen (char **screen, int *rows, int *cols)
1920 1920
1921/* We are not X, but we can emulate it well enough for our needs... */ 1921/* We are not X, but we can emulate it well enough for our needs... */
1922void 1922void
1923check_x (void) 1923check_window_system (void)
1924{ 1924{
1925 if (! FRAME_MSDOS_P (SELECTED_FRAME ())) 1925 if (! FRAME_MSDOS_P (SELECTED_FRAME ()))
1926 error ("Not running under a window system"); 1926 error ("Not running under a window system");
@@ -2983,11 +2983,6 @@ IT_menu_display (XMenu *menu, int y, int x, int pn, int *faces, int disp_help)
2983 2983
2984/* --------------------------- X Menu emulation ---------------------- */ 2984/* --------------------------- X Menu emulation ---------------------- */
2985 2985
2986/* Report availability of menus. */
2987
2988int
2989have_menus_p (void) { return 1; }
2990
2991/* Create a brand new menu structure. */ 2986/* Create a brand new menu structure. */
2992 2987
2993XMenu * 2988XMenu *
diff --git a/src/nsfns.m b/src/nsfns.m
index 17f27910ca2..a483f847dec 100644
--- a/src/nsfns.m
+++ b/src/nsfns.m
@@ -107,43 +107,6 @@ static ptrdiff_t image_cache_refcount;
107 107
108 ========================================================================== */ 108 ========================================================================== */
109 109
110
111void
112check_ns (void)
113{
114 if (NSApp == nil)
115 error ("OpenStep is not in use or not initialized");
116}
117
118
119/* Nonzero if we can use mouse menus. */
120int
121have_menus_p (void)
122{
123 return NSApp != nil;
124}
125
126
127/* Extract a frame as a FRAME_PTR, defaulting to the selected frame
128 and checking validity for NS. */
129static FRAME_PTR
130check_ns_frame (Lisp_Object frame)
131{
132 FRAME_PTR f;
133
134 if (NILP (frame))
135 f = SELECTED_FRAME ();
136 else
137 {
138 CHECK_LIVE_FRAME (frame);
139 f = XFRAME (frame);
140 }
141 if (! FRAME_NS_P (f))
142 error ("non-Nextstep frame used");
143 return f;
144}
145
146
147/* Let the user specify an Nextstep display with a frame. 110/* Let the user specify an Nextstep display with a frame.
148 nil stands for the selected frame--or, if that is not an Nextstep frame, 111 nil stands for the selected frame--or, if that is not an Nextstep frame,
149 the first Nextstep display on the list. */ 112 the first Nextstep display on the list. */
@@ -1145,8 +1108,6 @@ This function is an internal primitive--use `make-frame' instead. */)
1145 Lisp_Object tfont, tfontsize; 1108 Lisp_Object tfont, tfontsize;
1146 static int desc_ctr = 1; 1109 static int desc_ctr = 1;
1147 1110
1148 check_ns ();
1149
1150 /* x_get_arg modifies parms. */ 1111 /* x_get_arg modifies parms. */
1151 parms = Fcopy_alist (parms); 1112 parms = Fcopy_alist (parms);
1152 1113
@@ -1418,7 +1379,7 @@ DEFUN ("x-focus-frame", Fx_focus_frame, Sx_focus_frame, 1, 1, 0,
1418FRAME nil means use the selected frame. */) 1379FRAME nil means use the selected frame. */)
1419 (Lisp_Object frame) 1380 (Lisp_Object frame)
1420{ 1381{
1421 struct frame *f = check_ns_frame (frame); 1382 struct frame *f = decode_window_system_frame (frame);
1422 struct ns_display_info *dpyinfo = FRAME_NS_DISPLAY_INFO (f); 1383 struct ns_display_info *dpyinfo = FRAME_NS_DISPLAY_INFO (f);
1423 1384
1424 if (dpyinfo->x_focus_frame != f) 1385 if (dpyinfo->x_focus_frame != f)
@@ -1439,18 +1400,8 @@ DEFUN ("ns-popup-font-panel", Fns_popup_font_panel, Sns_popup_font_panel,
1439 doc: /* Pop up the font panel. */) 1400 doc: /* Pop up the font panel. */)
1440 (Lisp_Object frame) 1401 (Lisp_Object frame)
1441{ 1402{
1442 id fm; 1403 struct frame *f = decode_window_system_frame (frame);
1443 struct frame *f; 1404 id fm = [NSFontManager sharedFontManager];
1444
1445 check_ns ();
1446 fm = [NSFontManager sharedFontManager];
1447 if (NILP (frame))
1448 f = SELECTED_FRAME ();
1449 else
1450 {
1451 CHECK_FRAME (frame);
1452 f = XFRAME (frame);
1453 }
1454 1405
1455 [fm setSelectedFont: ((struct nsfont_info *)f->output_data.ns->font)->nsfont 1406 [fm setSelectedFont: ((struct nsfont_info *)f->output_data.ns->font)->nsfont
1456 isMultiple: NO]; 1407 isMultiple: NO];
@@ -1464,17 +1415,7 @@ DEFUN ("ns-popup-color-panel", Fns_popup_color_panel, Sns_popup_color_panel,
1464 doc: /* Pop up the color panel. */) 1415 doc: /* Pop up the color panel. */)
1465 (Lisp_Object frame) 1416 (Lisp_Object frame)
1466{ 1417{
1467 struct frame *f; 1418 check_window_system (NULL);
1468
1469 check_ns ();
1470 if (NILP (frame))
1471 f = SELECTED_FRAME ();
1472 else
1473 {
1474 CHECK_FRAME (frame);
1475 f = XFRAME (frame);
1476 }
1477
1478 [NSApp orderFrontColorPanel: NSApp]; 1419 [NSApp orderFrontColorPanel: NSApp];
1479 return Qnil; 1420 return Qnil;
1480} 1421}
@@ -1503,7 +1444,7 @@ Optional arg DIR_ONLY_P, if non-nil, means choose only directories. */)
1503 NSString *initS = NILP (init) || !STRINGP (init) ? nil : 1444 NSString *initS = NILP (init) || !STRINGP (init) ? nil :
1504 [NSString stringWithUTF8String: SSDATA (init)]; 1445 [NSString stringWithUTF8String: SSDATA (init)];
1505 1446
1506 check_ns (); 1447 check_window_system (NULL);
1507 1448
1508 if (fileDelegate == nil) 1449 if (fileDelegate == nil)
1509 fileDelegate = [EmacsFileDelegate new]; 1450 fileDelegate = [EmacsFileDelegate new];
@@ -1594,11 +1535,10 @@ If OWNER is nil, Emacs is assumed. */)
1594{ 1535{
1595 const char *value; 1536 const char *value;
1596 1537
1597 check_ns (); 1538 check_window_system (NULL);
1598 if (NILP (owner)) 1539 if (NILP (owner))
1599 owner = build_string([ns_app_name UTF8String]); 1540 owner = build_string([ns_app_name UTF8String]);
1600 CHECK_STRING (name); 1541 CHECK_STRING (name);
1601/*fprintf (stderr, "ns-get-resource checking resource '%s'\n", SSDATA (name)); */
1602 1542
1603 value = ns_get_defaults_value (SSDATA (name)); 1543 value = ns_get_defaults_value (SSDATA (name));
1604 1544
@@ -1614,7 +1554,7 @@ If OWNER is nil, Emacs is assumed.
1614If VALUE is nil, the default is removed. */) 1554If VALUE is nil, the default is removed. */)
1615 (Lisp_Object owner, Lisp_Object name, Lisp_Object value) 1555 (Lisp_Object owner, Lisp_Object name, Lisp_Object value)
1616{ 1556{
1617 check_ns (); 1557 check_window_system (NULL);
1618 if (NILP (owner)) 1558 if (NILP (owner))
1619 owner = build_string ([ns_app_name UTF8String]); 1559 owner = build_string ([ns_app_name UTF8String]);
1620 CHECK_STRING (name); 1560 CHECK_STRING (name);
@@ -1642,7 +1582,7 @@ DEFUN ("x-server-max-request-size", Fx_server_max_request_size,
1642 doc: /* This function is a no-op. It is only present for completeness. */) 1582 doc: /* This function is a no-op. It is only present for completeness. */)
1643 (Lisp_Object display) 1583 (Lisp_Object display)
1644{ 1584{
1645 check_ns (); 1585 check_ns_display_info (display);
1646 /* This function has no real equivalent under NeXTstep. Return nil to 1586 /* This function has no real equivalent under NeXTstep. Return nil to
1647 indicate this. */ 1587 indicate this. */
1648 return Qnil; 1588 return Qnil;
@@ -1692,7 +1632,7 @@ If omitted or nil, the selected frame's display is used. */)
1692{ 1632{
1693 int num; 1633 int num;
1694 1634
1695 check_ns (); 1635 check_ns_display_info (display);
1696 num = [[NSScreen screens] count]; 1636 num = [[NSScreen screens] count];
1697 1637
1698 return (num != 0) ? make_number (num) : Qnil; 1638 return (num != 0) ? make_number (num) : Qnil;
@@ -1706,7 +1646,7 @@ DISPLAY should be a frame, the display name as a string, or a terminal ID.
1706If omitted or nil, the selected frame's display is used. */) 1646If omitted or nil, the selected frame's display is used. */)
1707 (Lisp_Object display) 1647 (Lisp_Object display)
1708{ 1648{
1709 check_ns (); 1649 check_ns_display_info (display);
1710 return make_number ((int) 1650 return make_number ((int)
1711 ([ns_get_screen (display) frame].size.height/(92.0/25.4))); 1651 ([ns_get_screen (display) frame].size.height/(92.0/25.4)));
1712} 1652}
@@ -1719,7 +1659,7 @@ DISPLAY should be a frame, the display name as a string, or a terminal ID.
1719If omitted or nil, the selected frame's display is used. */) 1659If omitted or nil, the selected frame's display is used. */)
1720 (Lisp_Object display) 1660 (Lisp_Object display)
1721{ 1661{
1722 check_ns (); 1662 check_ns_display_info (display);
1723 return make_number ((int) 1663 return make_number ((int)
1724 ([ns_get_screen (display) frame].size.width/(92.0/25.4))); 1664 ([ns_get_screen (display) frame].size.width/(92.0/25.4)));
1725} 1665}
@@ -1733,7 +1673,7 @@ DISPLAY should be a frame, the display name as a string, or a terminal ID.
1733If omitted or nil, the selected frame's display is used. */) 1673If omitted or nil, the selected frame's display is used. */)
1734 (Lisp_Object display) 1674 (Lisp_Object display)
1735{ 1675{
1736 check_ns (); 1676 check_ns_display_info (display);
1737 switch ([ns_get_window (display) backingType]) 1677 switch ([ns_get_window (display) backingType])
1738 { 1678 {
1739 case NSBackingStoreBuffered: 1679 case NSBackingStoreBuffered:
@@ -1759,7 +1699,8 @@ If omitted or nil, the selected frame's display is used. */)
1759 (Lisp_Object display) 1699 (Lisp_Object display)
1760{ 1700{
1761 NSWindowDepth depth; 1701 NSWindowDepth depth;
1762 check_ns (); 1702
1703 check_ns_display_info (display);
1763 depth = [ns_get_screen (display) depth]; 1704 depth = [ns_get_screen (display) depth];
1764 1705
1765 if ( depth == NSBestDepth (NSCalibratedWhiteColorSpace, 2, 2, YES, NULL)) 1706 if ( depth == NSBestDepth (NSCalibratedWhiteColorSpace, 2, 2, YES, NULL))
@@ -1786,7 +1727,7 @@ DISPLAY should be a frame, the display name as a string, or a terminal ID.
1786If omitted or nil, the selected frame's display is used. */) 1727If omitted or nil, the selected frame's display is used. */)
1787 (Lisp_Object display) 1728 (Lisp_Object display)
1788{ 1729{
1789 check_ns (); 1730 check_ns_display_info (display);
1790 switch ([ns_get_window (display) backingType]) 1731 switch ([ns_get_window (display) backingType])
1791 { 1732 {
1792 case NSBackingStoreBuffered: 1733 case NSBackingStoreBuffered:
@@ -1836,11 +1777,10 @@ terminate Emacs if we can't open the connection.
1836DEFUN ("x-close-connection", Fx_close_connection, Sx_close_connection, 1777DEFUN ("x-close-connection", Fx_close_connection, Sx_close_connection,
1837 1, 1, 0, 1778 1, 1, 0,
1838 doc: /* Close the connection to the current Nextstep display server. 1779 doc: /* Close the connection to the current Nextstep display server.
1839The argument DISPLAY is currently ignored. */) 1780DISPLAY should be a frame, the display name as a string, or a terminal ID. */)
1840 (Lisp_Object display) 1781 (Lisp_Object display)
1841{ 1782{
1842 check_ns (); 1783 check_ns_display_info (display);
1843 /*ns_delete_terminal (dpyinfo->terminal); */
1844 [NSApp terminate: NSApp]; 1784 [NSApp terminate: NSApp];
1845 return Qnil; 1785 return Qnil;
1846} 1786}
@@ -1865,7 +1805,7 @@ DEFUN ("ns-hide-others", Fns_hide_others, Sns_hide_others,
1865 doc: /* Hides all applications other than Emacs. */) 1805 doc: /* Hides all applications other than Emacs. */)
1866 (void) 1806 (void)
1867{ 1807{
1868 check_ns (); 1808 check_window_system (NULL);
1869 [NSApp hideOtherApplications: NSApp]; 1809 [NSApp hideOtherApplications: NSApp];
1870 return Qnil; 1810 return Qnil;
1871} 1811}
@@ -1878,7 +1818,7 @@ If ON is equal to `activate', Emacs is unhidden and becomes
1878the active application. */) 1818the active application. */)
1879 (Lisp_Object on) 1819 (Lisp_Object on)
1880{ 1820{
1881 check_ns (); 1821 check_window_system (NULL);
1882 if (EQ (on, intern ("activate"))) 1822 if (EQ (on, intern ("activate")))
1883 { 1823 {
1884 [NSApp unhide: NSApp]; 1824 [NSApp unhide: NSApp];
@@ -1897,7 +1837,7 @@ DEFUN ("ns-emacs-info-panel", Fns_emacs_info_panel, Sns_emacs_info_panel,
1897 doc: /* Shows the 'Info' or 'About' panel for Emacs. */) 1837 doc: /* Shows the 'Info' or 'About' panel for Emacs. */)
1898 (void) 1838 (void)
1899{ 1839{
1900 check_ns (); 1840 check_window_system (NULL);
1901 [NSApp orderFrontStandardAboutPanel: nil]; 1841 [NSApp orderFrontStandardAboutPanel: nil];
1902 return Qnil; 1842 return Qnil;
1903} 1843}
@@ -1975,7 +1915,7 @@ DEFUN ("ns-list-services", Fns_list_services, Sns_list_services, 0, 0, 0,
1975 NSMenu *svcs; 1915 NSMenu *svcs;
1976 id delegate; 1916 id delegate;
1977 1917
1978 check_ns (); 1918 check_window_system (NULL);
1979 svcs = [[NSMenu alloc] initWithTitle: @"Services"]; 1919 svcs = [[NSMenu alloc] initWithTitle: @"Services"];
1980 [NSApp setServicesMenu: svcs]; 1920 [NSApp setServicesMenu: svcs];
1981 [NSApp registerServicesMenuSendTypes: ns_send_types 1921 [NSApp registerServicesMenuSendTypes: ns_send_types
@@ -2028,7 +1968,7 @@ there was no result. */)
2028 char *utfStr; 1968 char *utfStr;
2029 1969
2030 CHECK_STRING (service); 1970 CHECK_STRING (service);
2031 check_ns (); 1971 check_window_system (NULL);
2032 1972
2033 utfStr = SSDATA (service); 1973 utfStr = SSDATA (service);
2034 svcName = [NSString stringWithUTF8String: utfStr]; 1974 svcName = [NSString stringWithUTF8String: utfStr];
@@ -2152,7 +2092,7 @@ In case the execution fails, an error is signaled. */)
2152 NSEvent *nxev; 2092 NSEvent *nxev;
2153 2093
2154 CHECK_STRING (script); 2094 CHECK_STRING (script);
2155 check_ns (); 2095 check_window_system (NULL);
2156 2096
2157 block_input (); 2097 block_input ();
2158 2098
@@ -2201,15 +2141,6 @@ In case the execution fails, an error is signaled. */)
2201 2141
2202 ========================================================================== */ 2142 ========================================================================== */
2203 2143
2204
2205/* called from image.c */
2206FRAME_PTR
2207check_x_frame (Lisp_Object frame)
2208{
2209 return check_ns_frame (frame);
2210}
2211
2212
2213/* called from frame.c */ 2144/* called from frame.c */
2214struct ns_display_info * 2145struct ns_display_info *
2215check_x_display_info (Lisp_Object frame) 2146check_x_display_info (Lisp_Object frame)
@@ -2235,7 +2166,7 @@ x_get_string_resource (XrmDatabase rdb, char *name, char *class)
2235 /* remove appname prefix; TODO: allow for !="Emacs" */ 2166 /* remove appname prefix; TODO: allow for !="Emacs" */
2236 char *toCheck = class + (!strncmp (class, "Emacs.", 6) ? 6 : 0); 2167 char *toCheck = class + (!strncmp (class, "Emacs.", 6) ? 6 : 0);
2237 const char *res; 2168 const char *res;
2238 check_ns (); 2169 check_window_system (NULL);
2239 2170
2240 if (inhibit_x_resources) 2171 if (inhibit_x_resources)
2241 /* --quick was passed, so this is a no-op. */ 2172 /* --quick was passed, so this is a no-op. */
@@ -2305,7 +2236,7 @@ DEFUN ("xw-color-defined-p", Fxw_color_defined_p, Sxw_color_defined_p, 1, 2, 0,
2305 (Lisp_Object color, Lisp_Object frame) 2236 (Lisp_Object color, Lisp_Object frame)
2306{ 2237{
2307 NSColor * col; 2238 NSColor * col;
2308 check_ns (); 2239 check_window_system (NULL);
2309 return ns_lisp_to_color (color, &col) ? Qnil : Qt; 2240 return ns_lisp_to_color (color, &col) ? Qnil : Qt;
2310} 2241}
2311 2242
@@ -2317,7 +2248,7 @@ DEFUN ("xw-color-values", Fxw_color_values, Sxw_color_values, 1, 2, 0,
2317 NSColor * col; 2248 NSColor * col;
2318 CGFloat red, green, blue, alpha; 2249 CGFloat red, green, blue, alpha;
2319 2250
2320 check_ns (); 2251 check_window_system (NULL);
2321 CHECK_STRING (color); 2252 CHECK_STRING (color);
2322 2253
2323 if (ns_lisp_to_color (color, &col)) 2254 if (ns_lisp_to_color (color, &col))
@@ -2336,7 +2267,8 @@ DEFUN ("xw-display-color-p", Fxw_display_color_p, Sxw_display_color_p, 0, 1, 0,
2336{ 2267{
2337 NSWindowDepth depth; 2268 NSWindowDepth depth;
2338 NSString *colorSpace; 2269 NSString *colorSpace;
2339 check_ns (); 2270
2271 check_ns_display_info (display);
2340 depth = [ns_get_screen (display) depth]; 2272 depth = [ns_get_screen (display) depth];
2341 colorSpace = NSColorSpaceFromDepth (depth); 2273 colorSpace = NSColorSpaceFromDepth (depth);
2342 2274
@@ -2356,7 +2288,8 @@ If omitted or nil, that stands for the selected frame's display. */)
2356 (Lisp_Object display) 2288 (Lisp_Object display)
2357{ 2289{
2358 NSWindowDepth depth; 2290 NSWindowDepth depth;
2359 check_ns (); 2291
2292 check_ns_display_info (display);
2360 depth = [ns_get_screen (display) depth]; 2293 depth = [ns_get_screen (display) depth];
2361 2294
2362 return NSBitsPerPixelFromDepth (depth) > 1 ? Qt : Qnil; 2295 return NSBitsPerPixelFromDepth (depth) > 1 ? Qt : Qnil;
@@ -2371,7 +2304,7 @@ DISPLAY should be either a frame, a display name (a string), or terminal ID.
2371If omitted or nil, that stands for the selected frame's display. */) 2304If omitted or nil, that stands for the selected frame's display. */)
2372 (Lisp_Object display) 2305 (Lisp_Object display)
2373{ 2306{
2374 check_ns (); 2307 check_ns_display_info (display);
2375 return make_number ((int) [ns_get_screen (display) frame].size.width); 2308 return make_number ((int) [ns_get_screen (display) frame].size.width);
2376} 2309}
2377 2310
@@ -2384,7 +2317,7 @@ DISPLAY should be either a frame, a display name (a string), or terminal ID.
2384If omitted or nil, that stands for the selected frame's display. */) 2317If omitted or nil, that stands for the selected frame's display. */)
2385 (Lisp_Object display) 2318 (Lisp_Object display)
2386{ 2319{
2387 check_ns (); 2320 check_ns_display_info (display);
2388 return make_number ((int) [ns_get_screen (display) frame].size.height); 2321 return make_number ((int) [ns_get_screen (display) frame].size.height);
2389} 2322}
2390 2323
@@ -2404,7 +2337,7 @@ that stands for the selected frame's display. */)
2404 NSScreen *screen; 2337 NSScreen *screen;
2405 NSRect vScreen; 2338 NSRect vScreen;
2406 2339
2407 check_ns (); 2340 check_ns_display_info (display);
2408 screen = ns_get_screen (display); 2341 screen = ns_get_screen (display);
2409 if (!screen) 2342 if (!screen)
2410 return Qnil; 2343 return Qnil;
@@ -2428,7 +2361,7 @@ DISPLAY should be either a frame, a display name (a string), or terminal ID.
2428If omitted or nil, that stands for the selected frame's display. */) 2361If omitted or nil, that stands for the selected frame's display. */)
2429 (Lisp_Object display) 2362 (Lisp_Object display)
2430{ 2363{
2431 check_ns (); 2364 check_ns_display_info (display);
2432 return make_number 2365 return make_number
2433 (NSBitsPerPixelFromDepth ([ns_get_screen (display) depth])); 2366 (NSBitsPerPixelFromDepth ([ns_get_screen (display) depth]));
2434} 2367}
@@ -2442,10 +2375,7 @@ DISPLAY should be either a frame, a display name (a string), or terminal ID.
2442If omitted or nil, that stands for the selected frame's display. */) 2375If omitted or nil, that stands for the selected frame's display. */)
2443 (Lisp_Object display) 2376 (Lisp_Object display)
2444{ 2377{
2445 struct ns_display_info *dpyinfo; 2378 struct ns_display_info *dpyinfo = check_ns_display_info (display);
2446 check_ns ();
2447
2448 dpyinfo = check_ns_display_info (display);
2449 /* We force 24+ bit depths to 24-bit to prevent an overflow. */ 2379 /* We force 24+ bit depths to 24-bit to prevent an overflow. */
2450 return make_number (1 << min (dpyinfo->n_planes, 24)); 2380 return make_number (1 << min (dpyinfo->n_planes, 24));
2451} 2381}
@@ -2558,7 +2488,7 @@ Text larger than the specified size is clipped. */)
2558 2488
2559 CHECK_STRING (string); 2489 CHECK_STRING (string);
2560 str = SSDATA (string); 2490 str = SSDATA (string);
2561 f = check_x_frame (frame); 2491 f = decode_window_system_frame (frame);
2562 if (NILP (timeout)) 2492 if (NILP (timeout))
2563 timeout = make_number (5); 2493 timeout = make_number (5);
2564 else 2494 else
@@ -2787,9 +2717,6 @@ be used as the image of the icon representing the frame. */);
2787 defsubr (&Sx_show_tip); 2717 defsubr (&Sx_show_tip);
2788 defsubr (&Sx_hide_tip); 2718 defsubr (&Sx_hide_tip);
2789 2719
2790 /* used only in fontset.c */
2791 check_window_system_func = check_ns;
2792
2793 as_status = 0; 2720 as_status = 0;
2794 as_script = Qnil; 2721 as_script = Qnil;
2795 as_result = 0; 2722 as_result = 0;
diff --git a/src/nsmenu.m b/src/nsmenu.m
index 15878dc74d7..648b568d180 100644
--- a/src/nsmenu.m
+++ b/src/nsmenu.m
@@ -1409,8 +1409,6 @@ ns_popup_dialog (Lisp_Object position, Lisp_Object contents, Lisp_Object header)
1409 1409
1410 NSTRACE (x-popup-dialog); 1410 NSTRACE (x-popup-dialog);
1411 1411
1412 check_ns ();
1413
1414 isQ = NILP (header); 1412 isQ = NILP (header);
1415 1413
1416 if (EQ (position, Qt) 1414 if (EQ (position, Qt)
@@ -1448,6 +1446,8 @@ ns_popup_dialog (Lisp_Object position, Lisp_Object contents, Lisp_Object header)
1448 else 1446 else
1449 CHECK_WINDOW (window); 1447 CHECK_WINDOW (window);
1450 1448
1449 check_window_system (f);
1450
1451 p.x = (int)f->left_pos + ((int)FRAME_COLUMN_WIDTH (f) * f->text_cols)/2; 1451 p.x = (int)f->left_pos + ((int)FRAME_COLUMN_WIDTH (f) * f->text_cols)/2;
1452 p.y = (int)f->top_pos + (FRAME_LINE_HEIGHT (f) * f->text_lines)/2; 1452 p.y = (int)f->top_pos + (FRAME_LINE_HEIGHT (f) * f->text_lines)/2;
1453 1453
diff --git a/src/nsselect.m b/src/nsselect.m
index 49380f87945..bb9eacd23cd 100644
--- a/src/nsselect.m
+++ b/src/nsselect.m
@@ -354,8 +354,7 @@ On Nextstep, FRAME is unused. */)
354 Lisp_Object successful_p = Qnil, rest; 354 Lisp_Object successful_p = Qnil, rest;
355 Lisp_Object target_symbol, data; 355 Lisp_Object target_symbol, data;
356 356
357 357 check_window_system (NULL);
358 check_ns ();
359 CHECK_SYMBOL (selection); 358 CHECK_SYMBOL (selection);
360 if (NILP (value)) 359 if (NILP (value))
361 error ("selection value may not be nil."); 360 error ("selection value may not be nil.");
@@ -409,7 +408,7 @@ On MS-DOS, all this does is return non-nil if we own the selection. */)
409 (Lisp_Object selection, Lisp_Object time_object, Lisp_Object terminal) 408 (Lisp_Object selection, Lisp_Object time_object, Lisp_Object terminal)
410{ 409{
411 id pb; 410 id pb;
412 check_ns (); 411 check_window_system (NULL);
413 CHECK_SYMBOL (selection); 412 CHECK_SYMBOL (selection);
414 if (NILP (assq_no_quit (selection, Vselection_alist))) return Qnil; 413 if (NILP (assq_no_quit (selection, Vselection_alist))) return Qnil;
415 414
@@ -436,7 +435,7 @@ On Nextstep, TERMINAL is unused. */)
436 id pb; 435 id pb;
437 NSArray *types; 436 NSArray *types;
438 437
439 check_ns (); 438 check_window_system (NULL);
440 CHECK_SYMBOL (selection); 439 CHECK_SYMBOL (selection);
441 if (EQ (selection, Qnil)) selection = QPRIMARY; 440 if (EQ (selection, Qnil)) selection = QPRIMARY;
442 if (EQ (selection, Qt)) selection = QSECONDARY; 441 if (EQ (selection, Qt)) selection = QSECONDARY;
@@ -464,7 +463,7 @@ frame's display, or the first available X display.
464On Nextstep, TERMINAL is unused. */) 463On Nextstep, TERMINAL is unused. */)
465 (Lisp_Object selection, Lisp_Object terminal) 464 (Lisp_Object selection, Lisp_Object terminal)
466{ 465{
467 check_ns (); 466 check_window_system (NULL);
468 CHECK_SYMBOL (selection); 467 CHECK_SYMBOL (selection);
469 if (EQ (selection, Qnil)) selection = QPRIMARY; 468 if (EQ (selection, Qnil)) selection = QPRIMARY;
470 if (EQ (selection, Qt)) selection = QSECONDARY; 469 if (EQ (selection, Qt)) selection = QSECONDARY;
@@ -492,7 +491,7 @@ On Nextstep, TIME-STAMP and TERMINAL are unused. */)
492{ 491{
493 Lisp_Object val; 492 Lisp_Object val;
494 493
495 check_ns (); 494 check_window_system (NULL);
496 CHECK_SYMBOL (selection_name); 495 CHECK_SYMBOL (selection_name);
497 CHECK_SYMBOL (target_type); 496 CHECK_SYMBOL (target_type);
498 val = ns_get_local_selection (selection_name, target_type); 497 val = ns_get_local_selection (selection_name, target_type);
@@ -516,7 +515,7 @@ SELECTION is a symbol, typically `PRIMARY', `SECONDARY', or `CLIPBOARD'. */)
516 (Lisp_Object selection) 515 (Lisp_Object selection)
517{ 516{
518 id pb; 517 id pb;
519 check_ns (); 518 check_window_system (NULL);
520 pb = ns_symbol_to_pb (selection); 519 pb = ns_symbol_to_pb (selection);
521 return pb != nil ? ns_string_from_pasteboard (pb) : Qnil; 520 return pb != nil ? ns_string_from_pasteboard (pb) : Qnil;
522} 521}
@@ -529,7 +528,7 @@ SELECTION is a symbol, typically `PRIMARY', `SECONDARY', or `CLIPBOARD'. */)
529 (Lisp_Object selection, Lisp_Object string) 528 (Lisp_Object selection, Lisp_Object string)
530{ 529{
531 id pb; 530 id pb;
532 check_ns (); 531 check_window_system (NULL);
533 pb = ns_symbol_to_pb (selection); 532 pb = ns_symbol_to_pb (selection);
534 if (pb != nil) ns_string_to_pasteboard (pb, string); 533 if (pb != nil) ns_string_to_pasteboard (pb, string);
535 return Qnil; 534 return Qnil;
diff --git a/src/nsterm.h b/src/nsterm.h
index a43a90428d0..07cfc2e022e 100644
--- a/src/nsterm.h
+++ b/src/nsterm.h
@@ -577,8 +577,6 @@ extern Lisp_Object ns_display_name_list;
577extern struct ns_display_info *ns_display_info_for_name (Lisp_Object name); 577extern struct ns_display_info *ns_display_info_for_name (Lisp_Object name);
578 578
579struct ns_display_info *check_x_display_info (Lisp_Object frame); 579struct ns_display_info *check_x_display_info (Lisp_Object frame);
580FRAME_PTR check_x_frame (Lisp_Object frame);
581
582 580
583struct ns_output 581struct ns_output
584{ 582{
@@ -764,7 +762,6 @@ extern void ns_clear_frame (struct frame *f);
764 762
765extern const char *ns_xlfd_to_fontname (const char *xlfd); 763extern const char *ns_xlfd_to_fontname (const char *xlfd);
766 764
767extern void check_ns (void);
768extern Lisp_Object ns_map_event_to_object (void); 765extern Lisp_Object ns_map_event_to_object (void);
769#ifdef __OBJC__ 766#ifdef __OBJC__
770extern Lisp_Object ns_string_from_pasteboard (id pb); 767extern Lisp_Object ns_string_from_pasteboard (id pb);
diff --git a/src/nsterm.m b/src/nsterm.m
index 9baa95a506b..f5b48ee4b11 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -1012,8 +1012,9 @@ ns_raise_frame (struct frame *f)
1012 Bring window to foreground and make it active 1012 Bring window to foreground and make it active
1013 -------------------------------------------------------------------------- */ 1013 -------------------------------------------------------------------------- */
1014{ 1014{
1015 NSView *view = FRAME_NS_VIEW (f); 1015 NSView *view;
1016 check_ns (); 1016 check_window_system (f);
1017 view = FRAME_NS_VIEW (f);
1017 block_input (); 1018 block_input ();
1018 if (FRAME_VISIBLE_P (f)) 1019 if (FRAME_VISIBLE_P (f))
1019 [[view window] makeKeyAndOrderFront: NSApp]; 1020 [[view window] makeKeyAndOrderFront: NSApp];
@@ -1027,8 +1028,9 @@ ns_lower_frame (struct frame *f)
1027 Send window to back 1028 Send window to back
1028 -------------------------------------------------------------------------- */ 1029 -------------------------------------------------------------------------- */
1029{ 1030{
1030 NSView *view = FRAME_NS_VIEW (f); 1031 NSView *view;
1031 check_ns (); 1032 check_window_system (f);
1033 view = FRAME_NS_VIEW (f);
1032 block_input (); 1034 block_input ();
1033 [[view window] orderBack: NSApp]; 1035 [[view window] orderBack: NSApp];
1034 unblock_input (); 1036 unblock_input ();
@@ -1131,9 +1133,10 @@ x_make_frame_invisible (struct frame *f)
1131 External: Hide the window (X11 semantics) 1133 External: Hide the window (X11 semantics)
1132 -------------------------------------------------------------------------- */ 1134 -------------------------------------------------------------------------- */
1133{ 1135{
1134 NSView * view = FRAME_NS_VIEW (f); 1136 NSView *view;
1135 NSTRACE (x_make_frame_invisible); 1137 NSTRACE (x_make_frame_invisible);
1136 check_ns (); 1138 check_window_system (f);
1139 view = FRAME_NS_VIEW (f);
1137 [[view window] orderOut: NSApp]; 1140 [[view window] orderOut: NSApp];
1138 SET_FRAME_VISIBLE (f, 0); 1141 SET_FRAME_VISIBLE (f, 0);
1139 SET_FRAME_ICONIFIED (f, 0); 1142 SET_FRAME_ICONIFIED (f, 0);
@@ -1146,10 +1149,13 @@ x_iconify_frame (struct frame *f)
1146 External: Iconify window 1149 External: Iconify window
1147 -------------------------------------------------------------------------- */ 1150 -------------------------------------------------------------------------- */
1148{ 1151{
1149 NSView * view = FRAME_NS_VIEW (f); 1152 NSView *view;
1150 struct ns_display_info *dpyinfo = FRAME_NS_DISPLAY_INFO (f); 1153 struct ns_display_info *dpyinfo;
1154
1151 NSTRACE (x_iconify_frame); 1155 NSTRACE (x_iconify_frame);
1152 check_ns (); 1156 check_window_system (f);
1157 view = FRAME_NS_VIEW (f);
1158 dpyinfo = FRAME_NS_DISPLAY_INFO (f);
1153 1159
1154 if (dpyinfo->x_highlight_frame == f) 1160 if (dpyinfo->x_highlight_frame == f)
1155 dpyinfo->x_highlight_frame = 0; 1161 dpyinfo->x_highlight_frame = 0;
@@ -1174,11 +1180,15 @@ x_iconify_frame (struct frame *f)
1174void 1180void
1175x_free_frame_resources (struct frame *f) 1181x_free_frame_resources (struct frame *f)
1176{ 1182{
1177 NSView *view = FRAME_NS_VIEW (f); 1183 NSView *view;
1178 struct ns_display_info *dpyinfo = FRAME_NS_DISPLAY_INFO (f); 1184 struct ns_display_info *dpyinfo;
1179 Mouse_HLInfo *hlinfo = MOUSE_HL_INFO (f); 1185 Mouse_HLInfo *hlinfo;
1186
1180 NSTRACE (x_free_frame_resources); 1187 NSTRACE (x_free_frame_resources);
1181 check_ns (); 1188 check_window_system (f);
1189 view = FRAME_NS_VIEW (f);
1190 dpyinfo = FRAME_NS_DISPLAY_INFO (f);
1191 hlinfo = MOUSE_HL_INFO (f);
1182 1192
1183 [(EmacsView *)view setWindowClosing: YES]; /* may not have been informed */ 1193 [(EmacsView *)view setWindowClosing: YES]; /* may not have been informed */
1184 1194
@@ -1219,7 +1229,7 @@ x_destroy_window (struct frame *f)
1219 -------------------------------------------------------------------------- */ 1229 -------------------------------------------------------------------------- */
1220{ 1230{
1221 NSTRACE (x_destroy_window); 1231 NSTRACE (x_destroy_window);
1222 check_ns (); 1232 check_window_system (f);
1223 x_free_frame_resources (f); 1233 x_free_frame_resources (f);
1224 ns_window_num--; 1234 ns_window_num--;
1225} 1235}
@@ -1873,7 +1883,7 @@ ns_mouse_position (struct frame **fp, int insist, Lisp_Object *bar_window,
1873 f = dpyinfo->x_focus_frame ? dpyinfo->x_focus_frame 1883 f = dpyinfo->x_focus_frame ? dpyinfo->x_focus_frame
1874 : SELECTED_FRAME (); 1884 : SELECTED_FRAME ();
1875 1885
1876 if (f && f->output_data.ns) /* TODO: 2nd check no longer needed? */ 1886 if (f && FRAME_NS_P (f))
1877 { 1887 {
1878 view = FRAME_NS_VIEW (*fp); 1888 view = FRAME_NS_VIEW (*fp);
1879 1889
diff --git a/src/w32fns.c b/src/w32fns.c
index bd54e990efc..5d3a78f8b95 100644
--- a/src/w32fns.c
+++ b/src/w32fns.c
@@ -95,10 +95,6 @@ static HWND hourglass_hwnd = NULL;
95#define IDC_HAND MAKEINTRESOURCE(32649) 95#define IDC_HAND MAKEINTRESOURCE(32649)
96#endif 96#endif
97 97
98/* Nonzero if using Windows. */
99
100static int w32_in_use;
101
102Lisp_Object Qsuppress_icon; 98Lisp_Object Qsuppress_icon;
103Lisp_Object Qundefined_color; 99Lisp_Object Qundefined_color;
104Lisp_Object Qcancel_timer; 100Lisp_Object Qcancel_timer;
@@ -239,37 +235,6 @@ HINSTANCE hinst = NULL;
239static unsigned int sound_type = 0xFFFFFFFF; 235static unsigned int sound_type = 0xFFFFFFFF;
240#define MB_EMACS_SILENT (0xFFFFFFFF - 1) 236#define MB_EMACS_SILENT (0xFFFFFFFF - 1)
241 237
242
243/* Error if we are not connected to MS-Windows. */
244void
245check_w32 (void)
246{
247 if (! w32_in_use)
248 error ("MS-Windows not in use or not initialized");
249}
250
251/* Nonzero if we can use mouse menus.
252 You should not call this unless HAVE_MENUS is defined. */
253
254int
255have_menus_p (void)
256{
257 return w32_in_use;
258}
259
260/* Extract a frame as a FRAME_PTR, defaulting to the selected frame
261 and checking validity for W32. */
262
263FRAME_PTR
264check_x_frame (Lisp_Object frame)
265{
266 struct frame *f = decode_live_frame (frame);
267
268 if (! FRAME_W32_P (f))
269 error ("Non-W32 frame used");
270 return f;
271}
272
273/* Let the user specify a display with a frame. 238/* Let the user specify a display with a frame.
274 nil stands for the selected frame--or, if that is not a w32 frame, 239 nil stands for the selected frame--or, if that is not a w32 frame,
275 the first display on the list. */ 240 the first display on the list. */
@@ -4567,7 +4532,7 @@ DEFUN ("x-focus-frame", Fx_focus_frame, Sx_focus_frame, 1, 1, 0,
4567 doc: /* Give FRAME input focus, raising to foreground if necessary. */) 4532 doc: /* Give FRAME input focus, raising to foreground if necessary. */)
4568 (Lisp_Object frame) 4533 (Lisp_Object frame)
4569{ 4534{
4570 x_focus_on_frame (check_x_frame (frame)); 4535 x_focus_on_frame (decode_window_system_frame (frame));
4571 return Qnil; 4536 return Qnil;
4572} 4537}
4573 4538
@@ -4578,7 +4543,7 @@ DEFUN ("xw-color-defined-p", Fxw_color_defined_p, Sxw_color_defined_p, 1, 2, 0,
4578 (Lisp_Object color, Lisp_Object frame) 4543 (Lisp_Object color, Lisp_Object frame)
4579{ 4544{
4580 XColor foo; 4545 XColor foo;
4581 FRAME_PTR f = check_x_frame (frame); 4546 FRAME_PTR f = decode_window_system_frame (frame);
4582 4547
4583 CHECK_STRING (color); 4548 CHECK_STRING (color);
4584 4549
@@ -4593,7 +4558,7 @@ DEFUN ("xw-color-values", Fxw_color_values, Sxw_color_values, 1, 2, 0,
4593 (Lisp_Object color, Lisp_Object frame) 4558 (Lisp_Object color, Lisp_Object frame)
4594{ 4559{
4595 XColor foo; 4560 XColor foo;
4596 FRAME_PTR f = check_x_frame (frame); 4561 FRAME_PTR f = decode_window_system_frame (frame);
4597 4562
4598 CHECK_STRING (color); 4563 CHECK_STRING (color);
4599 4564
@@ -4911,7 +4876,6 @@ x_display_info_for_name (Lisp_Object name)
4911 if (dpyinfo == 0) 4876 if (dpyinfo == 0)
4912 error ("Cannot connect to server %s", SDATA (name)); 4877 error ("Cannot connect to server %s", SDATA (name));
4913 4878
4914 w32_in_use = 1;
4915 XSETFASTINT (Vwindow_system_version, w32_major_version); 4879 XSETFASTINT (Vwindow_system_version, w32_major_version);
4916 4880
4917 return dpyinfo; 4881 return dpyinfo;
@@ -4941,7 +4905,7 @@ terminate Emacs if we can't open the connection.
4941 4905
4942 /* If initialization has already been done, return now to avoid 4906 /* If initialization has already been done, return now to avoid
4943 overwriting critical parts of one_w32_display_info. */ 4907 overwriting critical parts of one_w32_display_info. */
4944 if (w32_in_use) 4908 if (window_system_available (NULL))
4945 return Qnil; 4909 return Qnil;
4946 4910
4947 if (! NILP (xrm_string)) 4911 if (! NILP (xrm_string))
@@ -5010,8 +4974,6 @@ terminate Emacs if we can't open the connection.
5010 error ("Cannot connect to server %s", SDATA (display)); 4974 error ("Cannot connect to server %s", SDATA (display));
5011 } 4975 }
5012 4976
5013 w32_in_use = 1;
5014
5015 XSETFASTINT (Vwindow_system_version, w32_major_version); 4977 XSETFASTINT (Vwindow_system_version, w32_major_version);
5016 return Qnil; 4978 return Qnil;
5017} 4979}
@@ -5095,7 +5057,7 @@ FRAME. Default is to change on the edit X window. */)
5095 (Lisp_Object prop, Lisp_Object value, Lisp_Object frame, 5057 (Lisp_Object prop, Lisp_Object value, Lisp_Object frame,
5096 Lisp_Object type, Lisp_Object format, Lisp_Object outer_p) 5058 Lisp_Object type, Lisp_Object format, Lisp_Object outer_p)
5097{ 5059{
5098 struct frame *f = check_x_frame (frame); 5060 struct frame *f = decode_window_system_frame (frame);
5099 Atom prop_atom; 5061 Atom prop_atom;
5100 5062
5101 CHECK_STRING (prop); 5063 CHECK_STRING (prop);
@@ -5121,7 +5083,7 @@ DEFUN ("x-delete-window-property", Fx_delete_window_property,
5121FRAME nil or omitted means use the selected frame. Value is PROP. */) 5083FRAME nil or omitted means use the selected frame. Value is PROP. */)
5122 (Lisp_Object prop, Lisp_Object frame) 5084 (Lisp_Object prop, Lisp_Object frame)
5123{ 5085{
5124 struct frame *f = check_x_frame (frame); 5086 struct frame *f = decode_window_system_frame (frame);
5125 Atom prop_atom; 5087 Atom prop_atom;
5126 5088
5127 CHECK_STRING (prop); 5089 CHECK_STRING (prop);
@@ -5157,7 +5119,7 @@ no value of TYPE (always string in the MS Windows case). */)
5157 (Lisp_Object prop, Lisp_Object frame, Lisp_Object type, 5119 (Lisp_Object prop, Lisp_Object frame, Lisp_Object type,
5158 Lisp_Object source, Lisp_Object delete_p, Lisp_Object vector_ret_p) 5120 Lisp_Object source, Lisp_Object delete_p, Lisp_Object vector_ret_p)
5159{ 5121{
5160 struct frame *f = check_x_frame (frame); 5122 struct frame *f = decode_window_system_frame (frame);
5161 Atom prop_atom; 5123 Atom prop_atom;
5162 int rc; 5124 int rc;
5163 Lisp_Object prop_value = Qnil; 5125 Lisp_Object prop_value = Qnil;
@@ -5358,8 +5320,6 @@ x_create_tip_frame (struct w32_display_info *dpyinfo,
5358 Lisp_Object buffer; 5320 Lisp_Object buffer;
5359 struct buffer *old_buffer; 5321 struct buffer *old_buffer;
5360 5322
5361 check_w32 ();
5362
5363 /* Use this general default value to start with until we know if 5323 /* Use this general default value to start with until we know if
5364 this frame has a specified name. */ 5324 this frame has a specified name. */
5365 Vx_resource_name = Vinvocation_name; 5325 Vx_resource_name = Vinvocation_name;
@@ -5703,7 +5663,7 @@ Text larger than the specified size is clipped. */)
5703 GCPRO4 (string, parms, frame, timeout); 5663 GCPRO4 (string, parms, frame, timeout);
5704 5664
5705 CHECK_STRING (string); 5665 CHECK_STRING (string);
5706 f = check_x_frame (frame); 5666 f = decode_window_system_frame (frame);
5707 if (NILP (timeout)) 5667 if (NILP (timeout))
5708 timeout = make_number (5); 5668 timeout = make_number (5);
5709 else 5669 else
@@ -6354,7 +6314,7 @@ screen saver if defined.
6354If optional parameter FRAME is not specified, use selected frame. */) 6314If optional parameter FRAME is not specified, use selected frame. */)
6355 (Lisp_Object command, Lisp_Object frame) 6315 (Lisp_Object command, Lisp_Object frame)
6356{ 6316{
6357 FRAME_PTR f = check_x_frame (frame); 6317 FRAME_PTR f = decode_window_system_frame (frame);
6358 6318
6359 CHECK_NUMBER (command); 6319 CHECK_NUMBER (command);
6360 6320
@@ -7312,8 +7272,6 @@ void
7312syms_of_w32fns (void) 7272syms_of_w32fns (void)
7313{ 7273{
7314 globals_of_w32fns (); 7274 globals_of_w32fns ();
7315 /* This is zero if not using MS-Windows. */
7316 w32_in_use = 0;
7317 track_mouse_window = NULL; 7275 track_mouse_window = NULL;
7318 7276
7319 w32_visible_system_caret_hwnd = NULL; 7277 w32_visible_system_caret_hwnd = NULL;
@@ -7635,8 +7593,6 @@ only be necessary if the default setting causes problems. */);
7635 defsubr (&Sdefault_printer_name); 7593 defsubr (&Sdefault_printer_name);
7636 defsubr (&Sset_message_beep); 7594 defsubr (&Sset_message_beep);
7637 7595
7638 check_window_system_func = check_w32;
7639
7640 hourglass_hwnd = NULL; 7596 hourglass_hwnd = NULL;
7641 7597
7642 defsubr (&Sx_show_tip); 7598 defsubr (&Sx_show_tip);
diff --git a/src/w32font.c b/src/w32font.c
index fb52376b9e1..105daa06365 100644
--- a/src/w32font.c
+++ b/src/w32font.c
@@ -2467,7 +2467,7 @@ If EXCLUDE-PROPORTIONAL is non-nil, exclude proportional fonts
2467in the font selection dialog. */) 2467in the font selection dialog. */)
2468 (Lisp_Object frame, Lisp_Object exclude_proportional) 2468 (Lisp_Object frame, Lisp_Object exclude_proportional)
2469{ 2469{
2470 FRAME_PTR f = check_x_frame (frame); 2470 FRAME_PTR f = decode_window_system_frame (frame);
2471 CHOOSEFONT cf; 2471 CHOOSEFONT cf;
2472 LOGFONT lf; 2472 LOGFONT lf;
2473 TEXTMETRIC tm; 2473 TEXTMETRIC tm;
diff --git a/src/w32menu.c b/src/w32menu.c
index 60ef6d2cfb5..346402b7c6b 100644
--- a/src/w32menu.c
+++ b/src/w32menu.c
@@ -140,8 +140,6 @@ otherwise it is "Question". */)
140 FRAME_PTR f = NULL; 140 FRAME_PTR f = NULL;
141 Lisp_Object window; 141 Lisp_Object window;
142 142
143 check_w32 ();
144
145 /* Decode the first argument: find the window or frame to use. */ 143 /* Decode the first argument: find the window or frame to use. */
146 if (EQ (position, Qt) 144 if (EQ (position, Qt)
147 || (CONSP (position) && (EQ (XCAR (position), Qmenu_bar) 145 || (CONSP (position) && (EQ (XCAR (position), Qmenu_bar)
@@ -194,6 +192,8 @@ otherwise it is "Question". */)
194 but I don't want to make one now. */ 192 but I don't want to make one now. */
195 CHECK_WINDOW (window); 193 CHECK_WINDOW (window);
196 194
195 check_window_system (f);
196
197#ifndef HAVE_DIALOGS 197#ifndef HAVE_DIALOGS
198 198
199 { 199 {
diff --git a/src/w32term.h b/src/w32term.h
index b319f0ca592..9bb37b31ef5 100644
--- a/src/w32term.h
+++ b/src/w32term.h
@@ -203,7 +203,6 @@ extern void x_focus_on_frame (struct frame *f);
203 203
204extern struct w32_display_info *w32_term_init (Lisp_Object, 204extern struct w32_display_info *w32_term_init (Lisp_Object,
205 char *, char *); 205 char *, char *);
206extern void check_w32 (void);
207extern int w32_defined_color (FRAME_PTR f, const char *color, 206extern int w32_defined_color (FRAME_PTR f, const char *color,
208 XColor *color_def, int alloc); 207 XColor *color_def, int alloc);
209extern void x_set_window_size (struct frame *f, int change_grav, 208extern void x_set_window_size (struct frame *f, int change_grav,
@@ -740,7 +739,6 @@ struct image;
740struct face; 739struct face;
741 740
742XGCValues *XCreateGC (void *, Window, unsigned long, XGCValues *); 741XGCValues *XCreateGC (void *, Window, unsigned long, XGCValues *);
743struct frame * check_x_frame (Lisp_Object);
744 742
745typedef DWORD (WINAPI * ClipboardSequence_Proc) (void); 743typedef DWORD (WINAPI * ClipboardSequence_Proc) (void);
746typedef BOOL (WINAPI * AppendMenuW_Proc) ( 744typedef BOOL (WINAPI * AppendMenuW_Proc) (
diff --git a/src/window.c b/src/window.c
index feb5f7b5cc7..7cf35a480f7 100644
--- a/src/window.c
+++ b/src/window.c
@@ -485,17 +485,14 @@ select_window (Lisp_Object window, Lisp_Object norecord, int inhibit_point_swap)
485 w = XWINDOW (window); 485 w = XWINDOW (window);
486 w->frozen_window_start_p = 0; 486 w->frozen_window_start_p = 0;
487 487
488 if (NILP (norecord))
489 {
490 w->use_time = ++window_select_count;
491 record_buffer (w->contents);
492 }
493
494 /* Make the selected window's buffer current. */ 488 /* Make the selected window's buffer current. */
495 Fset_buffer (w->contents); 489 Fset_buffer (w->contents);
496 490
497 if (EQ (window, selected_window) && !inhibit_point_swap) 491 if (EQ (window, selected_window) && !inhibit_point_swap)
498 return window; 492 /* `switch-to-buffer' uses (select-window (selected-window)) as a "clever"
493 way to call record_buffer from Elisp, so it's important that we call
494 record_buffer before returning here. */
495 goto record_and_return;
499 496
500 sf = SELECTED_FRAME (); 497 sf = SELECTED_FRAME ();
501 if (XFRAME (WINDOW_FRAME (w)) != sf) 498 if (XFRAME (WINDOW_FRAME (w)) != sf)
@@ -514,9 +511,19 @@ select_window (Lisp_Object window, Lisp_Object norecord, int inhibit_point_swap)
514 fset_selected_window (sf, window); 511 fset_selected_window (sf, window);
515 512
516 select_window_1 (window, inhibit_point_swap); 513 select_window_1 (window, inhibit_point_swap);
517
518 bset_last_selected_window (XBUFFER (w->contents), window); 514 bset_last_selected_window (XBUFFER (w->contents), window);
519 windows_or_buffers_changed++; 515 windows_or_buffers_changed++;
516
517 record_and_return:
518 /* record_buffer can run QUIT, so make sure it is run only after we have
519 re-established the invariant between selected_window and selected_frame,
520 otherwise the temporary broken invariant might "escape" (bug#14161). */
521 if (NILP (norecord))
522 {
523 w->use_time = ++window_select_count;
524 record_buffer (w->contents);
525 }
526
520 return window; 527 return window;
521} 528}
522 529
@@ -1490,7 +1497,12 @@ if it isn't already recorded. */)
1490 b = XBUFFER (buf); 1497 b = XBUFFER (buf);
1491 1498
1492 if (! NILP (update) 1499 if (! NILP (update)
1493 && (windows_or_buffers_changed || !w->window_end_valid) 1500 && (windows_or_buffers_changed
1501 || !w->window_end_valid
1502 || b->clip_changed
1503 || b->prevent_redisplay_optimizations_p
1504 || w->last_modified < BUF_MODIFF (b)
1505 || w->last_overlay_modified < BUF_OVERLAY_MODIFF (b))
1494 && !noninteractive) 1506 && !noninteractive)
1495 { 1507 {
1496 struct text_pos startp; 1508 struct text_pos startp;
@@ -1699,8 +1711,9 @@ Return nil if window display is not up-to-date. In that case, use
1699 1711
1700 /* Fail if current matrix is not up-to-date. */ 1712 /* Fail if current matrix is not up-to-date. */
1701 if (!w->window_end_valid 1713 if (!w->window_end_valid
1702 || current_buffer->clip_changed 1714 || windows_or_buffers_changed
1703 || current_buffer->prevent_redisplay_optimizations_p 1715 || b->clip_changed
1716 || b->prevent_redisplay_optimizations_p
1704 || w->last_modified < BUF_MODIFF (b) 1717 || w->last_modified < BUF_MODIFF (b)
1705 || w->last_overlay_modified < BUF_OVERLAY_MODIFF (b)) 1718 || w->last_overlay_modified < BUF_OVERLAY_MODIFF (b))
1706 return Qnil; 1719 return Qnil;
@@ -2929,7 +2942,7 @@ window-start value is reasonable when this function is called. */)
2929 2942
2930 replace_window (root, window, 1); 2943 replace_window (root, window, 1);
2931 2944
2932 /* This must become SWINDOW anyway ....... */ 2945 /* This must become SWINDOW anyway ....... */
2933 if (BUFFERP (w->contents) && !resize_failed) 2946 if (BUFFERP (w->contents) && !resize_failed)
2934 { 2947 {
2935 /* Try to minimize scrolling, by setting the window start to the 2948 /* Try to minimize scrolling, by setting the window start to the
diff --git a/src/xfaces.c b/src/xfaces.c
index b988295e9b6..b2ace1be14e 100644
--- a/src/xfaces.c
+++ b/src/xfaces.c
@@ -231,7 +231,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
231#undef FRAME_X_DISPLAY_INFO 231#undef FRAME_X_DISPLAY_INFO
232#define FRAME_X_DISPLAY_INFO FRAME_W32_DISPLAY_INFO 232#define FRAME_X_DISPLAY_INFO FRAME_W32_DISPLAY_INFO
233#define x_display_info w32_display_info 233#define x_display_info w32_display_info
234#define check_x check_w32
235#define GCGraphicsExposures 0 234#define GCGraphicsExposures 0
236#endif /* HAVE_NTGUI */ 235#endif /* HAVE_NTGUI */
237 236
@@ -239,7 +238,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
239#undef FRAME_X_DISPLAY_INFO 238#undef FRAME_X_DISPLAY_INFO
240#define FRAME_X_DISPLAY_INFO FRAME_NS_DISPLAY_INFO 239#define FRAME_X_DISPLAY_INFO FRAME_NS_DISPLAY_INFO
241#define x_display_info ns_display_info 240#define x_display_info ns_display_info
242#define check_x check_ns
243#define GCGraphicsExposures 0 241#define GCGraphicsExposures 0
244#endif /* HAVE_NS */ 242#endif /* HAVE_NS */
245#endif /* HAVE_WINDOW_SYSTEM */ 243#endif /* HAVE_WINDOW_SYSTEM */
@@ -1636,7 +1634,7 @@ the WIDTH times as wide as FACE on FRAME. */)
1636 struct frame *f; 1634 struct frame *f;
1637 int size, avgwidth IF_LINT (= 0); 1635 int size, avgwidth IF_LINT (= 0);
1638 1636
1639 check_x (); 1637 check_window_system (NULL);
1640 CHECK_STRING (pattern); 1638 CHECK_STRING (pattern);
1641 1639
1642 if (! NILP (maximum)) 1640 if (! NILP (maximum))
@@ -1645,8 +1643,8 @@ the WIDTH times as wide as FACE on FRAME. */)
1645 if (!NILP (width)) 1643 if (!NILP (width))
1646 CHECK_NUMBER (width); 1644 CHECK_NUMBER (width);
1647 1645
1648 /* We can't simply call check_x_frame because this function may be 1646 /* We can't simply call decode_window_system_frame because
1649 called before any frame is created. */ 1647 this function may be called before any frame is created. */
1650 f = decode_live_frame (frame); 1648 f = decode_live_frame (frame);
1651 if (! FRAME_WINDOW_P (f)) 1649 if (! FRAME_WINDOW_P (f))
1652 { 1650 {
@@ -3925,8 +3923,8 @@ If FRAME is omitted or nil, use the selected frame. */)
3925 struct frame *f; 3923 struct frame *f;
3926 Lisp_Object lface1, lface2; 3924 Lisp_Object lface1, lface2;
3927 3925
3928 /* Don't use check_x_frame here because this function is called 3926 /* Don't use decode_window_system_frame here because this function
3929 before X frames exist. At that time, if FRAME is nil, 3927 is called before X frames exist. At that time, if FRAME is nil,
3930 selected_frame will be used which is the frame dumped with 3928 selected_frame will be used which is the frame dumped with
3931 Emacs. That frame is not an X frame. */ 3929 Emacs. That frame is not an X frame. */
3932 f = EQ (frame, Qt) ? NULL : decode_live_frame (frame); 3930 f = EQ (frame, Qt) ? NULL : decode_live_frame (frame);
diff --git a/src/xfns.c b/src/xfns.c
index b39b78004a4..f4c24cb09a0 100644
--- a/src/xfns.c
+++ b/src/xfns.c
@@ -123,10 +123,6 @@ extern LWLIB_ID widget_id_tick;
123 123
124#define MAXREQUEST(dpy) (XMaxRequestSize (dpy)) 124#define MAXREQUEST(dpy) (XMaxRequestSize (dpy))
125 125
126/* Nonzero if using X. */
127
128int x_in_use;
129
130static Lisp_Object Qsuppress_icon; 126static Lisp_Object Qsuppress_icon;
131static Lisp_Object Qundefined_color; 127static Lisp_Object Qundefined_color;
132static Lisp_Object Qcompound_text, Qcancel_timer; 128static Lisp_Object Qcompound_text, Qcancel_timer;
@@ -139,38 +135,6 @@ static int dpyinfo_refcount;
139 135
140static struct x_display_info *x_display_info_for_name (Lisp_Object); 136static struct x_display_info *x_display_info_for_name (Lisp_Object);
141 137
142
143/* Error if we are not connected to X. */
144
145void
146check_x (void)
147{
148 if (! x_in_use)
149 error ("X windows are not in use or not initialized");
150}
151
152/* Nonzero if we can use mouse menus.
153 You should not call this unless HAVE_MENUS is defined. */
154
155int
156have_menus_p (void)
157{
158 return x_in_use;
159}
160
161/* Extract a frame as a FRAME_PTR, defaulting to the selected frame
162 and checking validity for X. */
163
164FRAME_PTR
165check_x_frame (Lisp_Object frame)
166{
167 struct frame *f = decode_live_frame (frame);
168
169 if (! FRAME_X_P (f))
170 error ("Non-X frame used");
171 return f;
172}
173
174/* Let the user specify an X display with a Lisp object. 138/* Let the user specify an X display with a Lisp object.
175 OBJECT may be nil, a frame or a terminal object. 139 OBJECT may be nil, a frame or a terminal object.
176 nil stands for the selected frame--or, if that is not an X frame, 140 nil stands for the selected frame--or, if that is not an X frame,
@@ -205,7 +169,7 @@ check_x_display_info (Lisp_Object object)
205 dpyinfo = x_display_info_for_name (object); 169 dpyinfo = x_display_info_for_name (object);
206 else 170 else
207 { 171 {
208 FRAME_PTR f = check_x_frame (object); 172 FRAME_PTR f = decode_window_system_frame (object);
209 dpyinfo = FRAME_X_DISPLAY_INFO (f); 173 dpyinfo = FRAME_X_DISPLAY_INFO (f);
210 } 174 }
211 175
@@ -2992,7 +2956,7 @@ If FRAME is omitted or nil, use the selected frame.
2992Signal error if FRAME is not an X frame. */) 2956Signal error if FRAME is not an X frame. */)
2993 (Lisp_Object frame) 2957 (Lisp_Object frame)
2994{ 2958{
2995 struct frame *f = check_x_frame (frame); 2959 struct frame *f = decode_window_system_frame (frame);
2996 2960
2997 block_input (); 2961 block_input ();
2998 x_wm_set_size_hint (f, 0, 0); 2962 x_wm_set_size_hint (f, 0, 0);
@@ -3483,7 +3447,7 @@ DEFUN ("x-focus-frame", Fx_focus_frame, Sx_focus_frame, 1, 1, 0,
3483FRAME nil means use the selected frame. */) 3447FRAME nil means use the selected frame. */)
3484 (Lisp_Object frame) 3448 (Lisp_Object frame)
3485{ 3449{
3486 struct frame *f = check_x_frame (frame); 3450 struct frame *f = decode_window_system_frame (frame);
3487 Display *dpy = FRAME_X_DISPLAY (f); 3451 Display *dpy = FRAME_X_DISPLAY (f);
3488 3452
3489 block_input (); 3453 block_input ();
@@ -3516,7 +3480,7 @@ DEFUN ("xw-color-defined-p", Fxw_color_defined_p, Sxw_color_defined_p, 1, 2, 0,
3516 (Lisp_Object color, Lisp_Object frame) 3480 (Lisp_Object color, Lisp_Object frame)
3517{ 3481{
3518 XColor foo; 3482 XColor foo;
3519 FRAME_PTR f = check_x_frame (frame); 3483 FRAME_PTR f = decode_window_system_frame (frame);
3520 3484
3521 CHECK_STRING (color); 3485 CHECK_STRING (color);
3522 3486
@@ -3531,7 +3495,7 @@ DEFUN ("xw-color-values", Fxw_color_values, Sxw_color_values, 1, 2, 0,
3531 (Lisp_Object color, Lisp_Object frame) 3495 (Lisp_Object color, Lisp_Object frame)
3532{ 3496{
3533 XColor foo; 3497 XColor foo;
3534 FRAME_PTR f = check_x_frame (frame); 3498 FRAME_PTR f = decode_window_system_frame (frame);
3535 3499
3536 CHECK_STRING (color); 3500 CHECK_STRING (color);
3537 3501
@@ -3996,7 +3960,6 @@ x_display_info_for_name (Lisp_Object name)
3996 if (dpyinfo == 0) 3960 if (dpyinfo == 0)
3997 error ("Cannot connect to X server %s", SDATA (name)); 3961 error ("Cannot connect to X server %s", SDATA (name));
3998 3962
3999 x_in_use = 1;
4000 XSETFASTINT (Vwindow_system_version, 11); 3963 XSETFASTINT (Vwindow_system_version, 11);
4001 3964
4002 return dpyinfo; 3965 return dpyinfo;
@@ -4050,8 +4013,6 @@ An insecure way to solve the problem may be to use `xhost'.\n",
4050 error ("Cannot connect to X server %s", SDATA (display)); 4013 error ("Cannot connect to X server %s", SDATA (display));
4051 } 4014 }
4052 4015
4053 x_in_use = 1;
4054
4055 XSETFASTINT (Vwindow_system_version, 11); 4016 XSETFASTINT (Vwindow_system_version, 11);
4056 return Qnil; 4017 return Qnil;
4057} 4018}
@@ -4143,7 +4104,7 @@ FRAME. Default is to change on the edit X window. */)
4143 (Lisp_Object prop, Lisp_Object value, Lisp_Object frame, 4104 (Lisp_Object prop, Lisp_Object value, Lisp_Object frame,
4144 Lisp_Object type, Lisp_Object format, Lisp_Object outer_p) 4105 Lisp_Object type, Lisp_Object format, Lisp_Object outer_p)
4145{ 4106{
4146 struct frame *f = check_x_frame (frame); 4107 struct frame *f = decode_window_system_frame (frame);
4147 Atom prop_atom; 4108 Atom prop_atom;
4148 Atom target_type = XA_STRING; 4109 Atom target_type = XA_STRING;
4149 int element_format = 8; 4110 int element_format = 8;
@@ -4221,7 +4182,7 @@ DEFUN ("x-delete-window-property", Fx_delete_window_property,
4221FRAME nil or omitted means use the selected frame. Value is PROP. */) 4182FRAME nil or omitted means use the selected frame. Value is PROP. */)
4222 (Lisp_Object prop, Lisp_Object frame) 4183 (Lisp_Object prop, Lisp_Object frame)
4223{ 4184{
4224 struct frame *f = check_x_frame (frame); 4185 struct frame *f = decode_window_system_frame (frame);
4225 Atom prop_atom; 4186 Atom prop_atom;
4226 4187
4227 CHECK_STRING (prop); 4188 CHECK_STRING (prop);
@@ -4257,7 +4218,7 @@ no value of TYPE (always string in the MS Windows case). */)
4257 (Lisp_Object prop, Lisp_Object frame, Lisp_Object type, 4218 (Lisp_Object prop, Lisp_Object frame, Lisp_Object type,
4258 Lisp_Object source, Lisp_Object delete_p, Lisp_Object vector_ret_p) 4219 Lisp_Object source, Lisp_Object delete_p, Lisp_Object vector_ret_p)
4259{ 4220{
4260 struct frame *f = check_x_frame (frame); 4221 struct frame *f = decode_window_system_frame (frame);
4261 Atom prop_atom; 4222 Atom prop_atom;
4262 int rc; 4223 int rc;
4263 Lisp_Object prop_value = Qnil; 4224 Lisp_Object prop_value = Qnil;
@@ -4525,8 +4486,6 @@ x_create_tip_frame (struct x_display_info *dpyinfo,
4525 Lisp_Object buffer; 4486 Lisp_Object buffer;
4526 struct buffer *old_buffer; 4487 struct buffer *old_buffer;
4527 4488
4528 check_x ();
4529
4530 if (!dpyinfo->terminal->name) 4489 if (!dpyinfo->terminal->name)
4531 error ("Terminal is not live, can't create new frames on it"); 4490 error ("Terminal is not live, can't create new frames on it");
4532 4491
@@ -4923,7 +4882,7 @@ Text larger than the specified size is clipped. */)
4923 if (SCHARS (string) == 0) 4882 if (SCHARS (string) == 0)
4924 string = make_unibyte_string (" ", 1); 4883 string = make_unibyte_string (" ", 1);
4925 4884
4926 f = check_x_frame (frame); 4885 f = decode_window_system_frame (frame);
4927 if (NILP (timeout)) 4886 if (NILP (timeout))
4928 timeout = make_number (5); 4887 timeout = make_number (5);
4929 else 4888 else
@@ -5246,7 +5205,7 @@ DEFUN ("x-uses-old-gtk-dialog", Fx_uses_old_gtk_dialog,
5246#ifdef USE_GTK 5205#ifdef USE_GTK
5247 if (use_dialog_box 5206 if (use_dialog_box
5248 && use_file_dialog 5207 && use_file_dialog
5249 && have_menus_p () 5208 && window_system_available (SELECTED_FRAME ())
5250 && xg_uses_old_file_dialog ()) 5209 && xg_uses_old_file_dialog ())
5251 return Qt; 5210 return Qt;
5252#endif 5211#endif
@@ -5316,7 +5275,7 @@ Otherwise, if ONLY-DIR-P is non-nil, the user can only select directories. */)
5316 ptrdiff_t count = SPECPDL_INDEX (); 5275 ptrdiff_t count = SPECPDL_INDEX ();
5317 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5, gcpro6; 5276 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5, gcpro6;
5318 5277
5319 check_x (); 5278 check_window_system (f);
5320 5279
5321 GCPRO6 (prompt, dir, default_filename, mustmatch, only_dir_p, file); 5280 GCPRO6 (prompt, dir, default_filename, mustmatch, only_dir_p, file);
5322 5281
@@ -5486,7 +5445,7 @@ Otherwise, if ONLY-DIR-P is non-nil, the user can only select directories. */)
5486 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5, gcpro6; 5445 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5, gcpro6;
5487 char *cdef_file; 5446 char *cdef_file;
5488 5447
5489 check_x (); 5448 check_window_system (f);
5490 5449
5491 GCPRO6 (prompt, dir, default_filename, mustmatch, only_dir_p, file); 5450 GCPRO6 (prompt, dir, default_filename, mustmatch, only_dir_p, file);
5492 5451
@@ -5541,15 +5500,13 @@ FRAME is the frame on which to pop up the font chooser. If omitted or
5541nil, it defaults to the selected frame. */) 5500nil, it defaults to the selected frame. */)
5542 (Lisp_Object frame, Lisp_Object ignored) 5501 (Lisp_Object frame, Lisp_Object ignored)
5543{ 5502{
5544 FRAME_PTR f = check_x_frame (frame); 5503 FRAME_PTR f = decode_window_system_frame (frame);
5545 Lisp_Object font; 5504 Lisp_Object font;
5546 Lisp_Object font_param; 5505 Lisp_Object font_param;
5547 char *default_name = NULL; 5506 char *default_name = NULL;
5548 struct gcpro gcpro1, gcpro2; 5507 struct gcpro gcpro1, gcpro2;
5549 ptrdiff_t count = SPECPDL_INDEX (); 5508 ptrdiff_t count = SPECPDL_INDEX ();
5550 5509
5551 check_x ();
5552
5553 if (popup_activated ()) 5510 if (popup_activated ())
5554 error ("Trying to use a menu from within a menu-entry"); 5511 error ("Trying to use a menu from within a menu-entry");
5555 5512
@@ -5609,7 +5566,7 @@ present and mapped to the usual X keysyms. */)
5609 return Qlambda; 5566 return Qlambda;
5610#else 5567#else
5611 XkbDescPtr kb; 5568 XkbDescPtr kb;
5612 struct frame *f = check_x_frame (frame); 5569 struct frame *f = decode_window_system_frame (frame);
5613 Display *dpy = FRAME_X_DISPLAY (f); 5570 Display *dpy = FRAME_X_DISPLAY (f);
5614 Lisp_Object have_keys; 5571 Lisp_Object have_keys;
5615 int major, minor, op, event, error_code; 5572 int major, minor, op, event, error_code;
@@ -5737,9 +5694,6 @@ frame_parm_handler x_frame_parm_handlers[] =
5737void 5694void
5738syms_of_xfns (void) 5695syms_of_xfns (void)
5739{ 5696{
5740 /* This is zero if not using X windows. */
5741 x_in_use = 0;
5742
5743 /* The section below is built by the lisp expression at the top of the file, 5697 /* The section below is built by the lisp expression at the top of the file,
5744 just above where these variables are declared. */ 5698 just above where these variables are declared. */
5745 /*&&& init symbols here &&&*/ 5699 /*&&& init symbols here &&&*/
@@ -5919,9 +5873,6 @@ When using Gtk+ tooltips, the tooltip face is not used. */);
5919 defsubr (&Sx_focus_frame); 5873 defsubr (&Sx_focus_frame);
5920 defsubr (&Sx_backspace_delete_keys_p); 5874 defsubr (&Sx_backspace_delete_keys_p);
5921 5875
5922 /* Setting callback functions for fontset handler. */
5923 check_window_system_func = check_x;
5924
5925 defsubr (&Sx_show_tip); 5876 defsubr (&Sx_show_tip);
5926 defsubr (&Sx_hide_tip); 5877 defsubr (&Sx_hide_tip);
5927 tip_timer = Qnil; 5878 tip_timer = Qnil;
diff --git a/src/xgselect.c b/src/xgselect.c
index 2c8e9671abb..0b5ad6ae70d 100644
--- a/src/xgselect.c
+++ b/src/xgselect.c
@@ -26,6 +26,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
26#include <glib.h> 26#include <glib.h>
27#include <errno.h> 27#include <errno.h>
28#include "xterm.h" 28#include "xterm.h"
29#include "frame.h"
29 30
30int 31int
31xg_select (int fds_lim, SELECT_TYPE *rfds, SELECT_TYPE *wfds, SELECT_TYPE *efds, 32xg_select (int fds_lim, SELECT_TYPE *rfds, SELECT_TYPE *wfds, SELECT_TYPE *efds,
@@ -43,7 +44,7 @@ xg_select (int fds_lim, SELECT_TYPE *rfds, SELECT_TYPE *wfds, SELECT_TYPE *efds,
43 int i, nfds, tmo_in_millisec; 44 int i, nfds, tmo_in_millisec;
44 USE_SAFE_ALLOCA; 45 USE_SAFE_ALLOCA;
45 46
46 if (! (x_in_use 47 if (! (window_system_available (NULL)
47 && g_main_context_pending (context = g_main_context_default ()))) 48 && g_main_context_pending (context = g_main_context_default ())))
48 return pselect (fds_lim, rfds, wfds, efds, timeout, sigmask); 49 return pselect (fds_lim, rfds, wfds, efds, timeout, sigmask);
49 50
diff --git a/src/xmenu.c b/src/xmenu.c
index 2042699f48c..9993bd87d5b 100644
--- a/src/xmenu.c
+++ b/src/xmenu.c
@@ -223,8 +223,6 @@ for instance using the window manager, then this produces a quit and
223 FRAME_PTR f = NULL; 223 FRAME_PTR f = NULL;
224 Lisp_Object window; 224 Lisp_Object window;
225 225
226 check_x ();
227
228 /* Decode the first argument: find the window or frame to use. */ 226 /* Decode the first argument: find the window or frame to use. */
229 if (EQ (position, Qt) 227 if (EQ (position, Qt)
230 || (CONSP (position) && (EQ (XCAR (position), Qmenu_bar) 228 || (CONSP (position) && (EQ (XCAR (position), Qmenu_bar)
@@ -277,8 +275,7 @@ for instance using the window manager, then this produces a quit and
277 but I don't want to make one now. */ 275 but I don't want to make one now. */
278 CHECK_WINDOW (window); 276 CHECK_WINDOW (window);
279 277
280 if (! FRAME_X_P (f) && ! FRAME_MSDOS_P (f)) 278 check_window_system (f);
281 error ("Can not put X dialog on this terminal");
282 279
283 /* Force a redisplay before showing the dialog. If a frame is created 280 /* Force a redisplay before showing the dialog. If a frame is created
284 just before showing the dialog, its contents may not have been fully 281 just before showing the dialog, its contents may not have been fully
@@ -485,7 +482,7 @@ If FRAME is nil or not given, use the selected frame. */)
485 (Lisp_Object frame) 482 (Lisp_Object frame)
486{ 483{
487 XEvent ev; 484 XEvent ev;
488 FRAME_PTR f = check_x_frame (frame); 485 FRAME_PTR f = decode_window_system_frame (frame);
489 Widget menubar; 486 Widget menubar;
490 block_input (); 487 block_input ();
491 488
@@ -569,7 +566,7 @@ If FRAME is nil or not given, use the selected frame. */)
569 block_input (). */ 566 block_input (). */
570 567
571 block_input (); 568 block_input ();
572 f = check_x_frame (frame); 569 f = decode_window_system_frame (frame);
573 570
574 if (FRAME_EXTERNAL_MENU_BAR (f)) 571 if (FRAME_EXTERNAL_MENU_BAR (f))
575 set_frame_menubar (f, 0, 1); 572 set_frame_menubar (f, 0, 1);
diff --git a/src/xselect.c b/src/xselect.c
index cca1a47212b..b422a22d68b 100644
--- a/src/xselect.c
+++ b/src/xselect.c
@@ -2450,7 +2450,7 @@ Use the display for FRAME or the current frame if FRAME is not given or nil.
2450If the value is 0 or the atom is not known, return the empty string. */) 2450If the value is 0 or the atom is not known, return the empty string. */)
2451 (Lisp_Object value, Lisp_Object frame) 2451 (Lisp_Object value, Lisp_Object frame)
2452{ 2452{
2453 struct frame *f = check_x_frame (frame); 2453 struct frame *f = decode_window_system_frame (frame);
2454 char *name = 0; 2454 char *name = 0;
2455 char empty[] = ""; 2455 char empty[] = "";
2456 Lisp_Object ret = Qnil; 2456 Lisp_Object ret = Qnil;
@@ -2485,7 +2485,7 @@ FRAME is on. If FRAME is nil, the selected frame is used. */)
2485 (Lisp_Object atom, Lisp_Object frame) 2485 (Lisp_Object atom, Lisp_Object frame)
2486{ 2486{
2487 Atom x_atom; 2487 Atom x_atom;
2488 struct frame *f = check_x_frame (frame); 2488 struct frame *f = decode_window_system_frame (frame);
2489 ptrdiff_t i; 2489 ptrdiff_t i;
2490 struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f); 2490 struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
2491 2491
@@ -2618,7 +2618,7 @@ x_send_client_event (Lisp_Object display, Lisp_Object dest, Lisp_Object from,
2618 struct x_display_info *dpyinfo = check_x_display_info (display); 2618 struct x_display_info *dpyinfo = check_x_display_info (display);
2619 Window wdest; 2619 Window wdest;
2620 XEvent event; 2620 XEvent event;
2621 struct frame *f = check_x_frame (from); 2621 struct frame *f = decode_window_system_frame (from);
2622 int to_root; 2622 int to_root;
2623 2623
2624 CHECK_NUMBER (format); 2624 CHECK_NUMBER (format);
@@ -2635,7 +2635,7 @@ x_send_client_event (Lisp_Object display, Lisp_Object dest, Lisp_Object from,
2635 2635
2636 if (FRAMEP (dest) || NILP (dest)) 2636 if (FRAMEP (dest) || NILP (dest))
2637 { 2637 {
2638 struct frame *fdest = check_x_frame (dest); 2638 struct frame *fdest = decode_window_system_frame (dest);
2639 wdest = FRAME_OUTER_WINDOW (fdest); 2639 wdest = FRAME_OUTER_WINDOW (fdest);
2640 } 2640 }
2641 else if (STRINGP (dest)) 2641 else if (STRINGP (dest))
diff --git a/src/xterm.h b/src/xterm.h
index b241ff23559..16effc5c9ea 100644
--- a/src/xterm.h
+++ b/src/xterm.h
@@ -366,10 +366,6 @@ struct x_display_info
366extern int use_xim; 366extern int use_xim;
367#endif 367#endif
368 368
369/* This checks to make sure we have a display. */
370
371extern void check_x (void);
372
373extern struct frame *x_window_to_frame (struct x_display_info *, int); 369extern struct frame *x_window_to_frame (struct x_display_info *, int);
374extern struct frame *x_any_window_to_frame (struct x_display_info *, int); 370extern struct frame *x_any_window_to_frame (struct x_display_info *, int);
375extern struct frame *x_menubar_window_to_frame (struct x_display_info *, 371extern struct frame *x_menubar_window_to_frame (struct x_display_info *,
@@ -927,7 +923,6 @@ void x_handle_property_notify (XPropertyEvent *);
927 923
928/* From xfns.c. */ 924/* From xfns.c. */
929 925
930struct frame *check_x_frame (Lisp_Object);
931extern void x_free_gcs (struct frame *); 926extern void x_free_gcs (struct frame *);
932 927
933/* From xrdb.c. */ 928/* From xrdb.c. */
@@ -1012,7 +1007,6 @@ extern void x_clipboard_manager_save_all (void);
1012 1007
1013extern struct x_display_info * check_x_display_info (Lisp_Object); 1008extern struct x_display_info * check_x_display_info (Lisp_Object);
1014extern Lisp_Object x_get_focus_frame (struct frame *); 1009extern Lisp_Object x_get_focus_frame (struct frame *);
1015extern int x_in_use;
1016 1010
1017#ifdef USE_GTK 1011#ifdef USE_GTK
1018extern int xg_set_icon (struct frame *, Lisp_Object); 1012extern int xg_set_icon (struct frame *, Lisp_Object);