aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTom Tromey2013-03-17 05:17:24 -0600
committerTom Tromey2013-03-17 05:17:24 -0600
commit6bd488cd8d05aa3983ca55f70ee384732d8c0085 (patch)
tree5645fc7b882638d6c0eb3f61fd55bde1a63fc190 /src
parent71f91792e3013b397996905224f387da5cc539a9 (diff)
parent9c44569ea2a18099307e0571d523d8637000a153 (diff)
downloademacs-6bd488cd8d05aa3983ca55f70ee384732d8c0085.tar.gz
emacs-6bd488cd8d05aa3983ca55f70ee384732d8c0085.zip
merge from trunk
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog240
-rw-r--r--src/Makefile.in3
-rw-r--r--src/alloc.c4
-rw-r--r--src/bytecode.c12
-rw-r--r--src/coding.c200
-rw-r--r--src/coding.h9
-rw-r--r--src/conf_post.h13
-rw-r--r--src/dispnew.c9
-rw-r--r--src/emacs.c4
-rw-r--r--src/eval.c1
-rw-r--r--src/fileio.c21
-rw-r--r--src/filelock.c8
-rw-r--r--src/insdel.c14
-rw-r--r--src/keyboard.c152
-rw-r--r--src/keyboard.h12
-rw-r--r--src/keymap.c4
-rw-r--r--src/lisp.h4
-rw-r--r--src/lread.c74
-rw-r--r--src/nsfns.m66
-rw-r--r--src/nsterm.h4
-rw-r--r--src/nsterm.m19
-rw-r--r--src/region-cache.c68
-rw-r--r--src/scroll.c17
-rw-r--r--src/search.c64
-rw-r--r--src/sysdep.c12
-rw-r--r--src/term.c6
-rw-r--r--src/termhooks.h28
-rw-r--r--src/terminal.c2
-rw-r--r--src/textprop.c2
-rw-r--r--src/thread.h4
-rw-r--r--src/w32fns.c89
-rw-r--r--src/w32term.c44
-rw-r--r--src/w32term.h17
-rw-r--r--src/window.c2
-rw-r--r--src/xdisp.c66
-rw-r--r--src/xfns.c6
-rw-r--r--src/xsmfns.c2
37 files changed, 884 insertions, 418 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index fe084b160c4..3a2a36c0cf7 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,231 @@
12013-03-16 Jan Djärv <jan.h.d@swipnet.se>
2
3 * nsterm.m (updateFrameSize:): Change resize increments if needed.
4 (ns_select): Don't return with result uninitialized.
5
6 * nsterm.h (EmacsSavePanel, EmacsOpenPanel): Add getFilename
7 and getDirectory.
8
9 * nsfns.m (ns_filename_from_panel, ns_directory_from_panel): New
10 functions.
11 (Fns_read_file_name): ret is BOOL. If ! dir_only_p, don't choose
12 directories. If filename is nil, get directory name (Bug#13932).
13 Use getFilename and getDirectory.
14 (getFilename, getDirectory): New methods for EmacsSavePanel and
15 EmacsOpenPanel.
16 (ok:): In EmacsOpenPanel, if we can't choose directories, just return.
17
182013-03-15 Paul Eggert <eggert@cs.ucla.edu>
19
20 * coding.c (decode_coding_gap): Fix typo caught by static checking.
21
222013-03-15 handa <handa@gnu.org>
23
24 * insdel.c (insert_from_gap): New arg text_at_gap_tail.
25 (adjust_after_replace): Make it back to static. Delete the third
26 arg text_at_gap_tail. Cancel the code for handling it.
27
28 * coding.h (struct coding_system): New member eol_seen.
29
30 * coding.c (detect_ascii): New function.
31 (detect_coding): Set coding->head_ascii and coding->eol_seen only
32 when the source bytes are actually scanned. On detecting for
33 coding_category_utf_8_auto, call detect_ascii instead of scanning
34 source bytes directly.
35 (produce_chars): Call insert_from_gap with the new arg 0.
36 (encode_coding): Likewise.
37 (decode_coding_gap): Control ASCII optimization by the variable
38 disable_ascii_optimization instead of #ifndef .. #endif.
39 Deccode EOL format according to coding->eol_seen.
40 (syms_of_coding): Declare disable-ascii-optimization as a Lisp
41 variable.
42
43 * global.h (struct emacs_globals): New member
44 f_disable_ascii_optimization.
45 (disable_ascii_optimization): New macro.
46
47 * lisp.h (adjust_after_replace): Cancel externing it.
48 (insert_from_gap): Adjust prototype.
49
502013-03-15 Eli Zaretskii <eliz@gnu.org>
51
52 * w32term.c (w32fullscreen_hook): Swap FULLSCREEN_BOTH and
53 FULLSCREEN_MAXIMIZED. (Bug#13935)
54
552013-03-15 Dmitry Antipov <dmantipov@yandex.ru>
56
57 * region-cache.c (find_cache_boundary, move_cache_gap)
58 (insert_cache_boundary, delete_cache_boundaries, set_cache_region):
59 Simplify debugging check and convert to eassert. Adjust comment.
60 (pp_cache): Put under ENABLE_CHECKING.
61
622013-03-14 Eli Zaretskii <eliz@gnu.org>
63
64 * w32term.c (w32_read_socket) <WM_WINDOWPOSCHANGED>: Remove old
65 and incorrect code. Treat WM_WINDOWPOSCHANGED like WM_ACTIVATE
66 and WM_ACTIVATEAPP.
67 (w32fullscreen_hook): If the frame is visible, reset
68 f->want_fullscreen flag after changing the frame size. If the
69 frame is not visible, set f->want_fullscreen to FULLSCREEN_WAIT.
70 (Bug#13953)
71
722013-03-13 Daniel Colascione <dancol@dancol.org>
73
74 * emacs.c (main): Call syms_of_cygw32 on CYGWIN non-NTGUI builds
75 too so that these builds can use Cygwin's file conversion
76 functions. (We've been building and linking cygw32.o all along
77 and just not using it.)
78
792013-03-13 Paul Eggert <eggert@cs.ucla.edu>
80
81 File synchronization fixes (Bug#13944).
82 * Makefile.in (LIB_FDATASYNC): New macro.
83 (LIBES): Use it.
84 * conf_post.h (BSD_SYSTEM, BSD_SYSTEM_AHB): Remove; no longer needed.
85 * fileio.c (Fwrite_region, write_region_inhibit_fsync):
86 Don't worry about HAVE_FSYNC, since a substitute fsync is
87 available if the system lacks one.
88 (Fwrite_regin): Retry fsync if interrupted.
89
902013-03-13 Eli Zaretskii <eliz@gnu.org>
91
92 * w32term.c (w32_read_socket): If the Emacs frame is being
93 activated, call w32fullscreen_hook, to make sure the new frame
94 dimensions are in effect. (Bug#13937)
95
962013-03-13 Dmitry Antipov <dmantipov@yandex.ru>
97
98 * xdisp.c (init_iterator): Simplify because both character and byte
99 positions are either specified or -1. Add eassert. Adjust comment.
100 * window.c (Fscroll_other_window): Use SET_PT_BOTH because both
101 character and byte positions can be obtained from marker.
102
1032013-03-13 Paul Eggert <eggert@cs.ucla.edu>
104
105 Static checking by Sun C 5.12.
106 * alloc.c (buffer_memory_full) [REL_ALLOC]:
107 * bytecode.c (exec_byte_code):
108 * dispnew.c (init_display):
109 * eval.c (error):
110 * fileio.c (Fsubstitute_in_file_name):
111 * keyboard.c (Fevent_convert_list):
112 * keymap.c (Fsingle_key_description):
113 * term.c (maybe_fatal, fatal):
114 * xfns.c (Fx_display_backing_store, Fx_display_visual_class):
115 * xsmfns.c (Fhandle_save_session):
116 Omit unreachable code.
117 * keymap.c (map_keymap_char_table_item): Cast void * to
118 a function pointer type; the C Standard requires this.
119
120 * sysdep.c: Remove a use of BSD_SYSTEM, which I'm trying to phase out.
121 Include <sys/param.h> unconditionally, as that works elsewhere and
122 is simpler here. Include <sys/sysctl.h> if DARWIN_OS ||
123 __FreeBSD__, not if BSD_SYSTEM, since it's needed only for Darwin
124 and FreeBSD now.
125
1262013-03-11 Paul Eggert <eggert@cs.ucla.edu>
127
128 * insdel.c (adjust_after_replace): Use bool for boolean.
129
1302013-03-11 Stefan Monnier <monnier@iro.umontreal.ca>
131
132 * keyboard.c: Move keyboard decoding to read_key_sequence.
133 (decode_keyboard_code): Remove.
134 (tty_read_avail_input): Don't try to decode input.
135 (read_decoded_char): New function.
136 (read_key_sequence): Use it.
137
1382013-03-10 Daniel Colascione <dancol@dancol.org>
139
140 * w32term.h (GUISTR, GUI_ENCODE_FILE, GUI_ENCODE_SYSTEM, GUI_FN)
141 (GUI_SDATA, guichar_t): Macros to abstract out differences between
142 NTGUI_UNICODE and !NTGUI_UNICODE builds, some moved out of
143 w32fns.c.
144
145 * w32term.c (construct_drag_n_drop): Use the above macros to make
146 drag-and-drop work for non-ASCII filenames in cygw32 builds.
147
148 * w32fns.c (x_set_name, x_set_title): Use the above macros to
149 properly display non-ASCII frame titles in cygw32 builds.
150
151 * w32fns.c (Fw32_shell_execute): Use the above macros to properly
152 call ShellExecute in cygw32 builds.
153
154 * w32fn.c (Fx_file_dialog): Use the above macros to simplify the
155 common file dialog code.
156
157 * w32fns.c (Ffile_system_info): Remove from cygw32 builds, which
158 can just use du like other systems.
159
160 * coding.c (from_unicode_buffer): Declare.
161 * coding.c (from_unicode_buffer): Implement.
162
1632013-03-10 Stefan Monnier <monnier@iro.umontreal.ca>
164
165 * lread.c: Minor cleanup.
166 (FROM_FILE_P): New macro.
167 (skip_dyn_bytes, unreadchar, read1): Use it.
168 (read_list): Consolidate duplicated code.
169
170 * bytecode.c (struct byte_stack): Remove `constants' when unused.
171
1722013-03-10 Eli Zaretskii <eliz@gnu.org>
173
174 * xdisp.c (display_tool_bar_line, redisplay_tool_bar)
175 (redisplay_internal, set_cursor_from_row, try_window)
176 (try_window_id, dump_glyph_row, extend_face_to_end_of_line)
177 (display_line, notice_overwritten_cursor)
178 (mouse_face_from_buffer_pos, note_mouse_highlight):
179 Use MATRIX_ROW_DISPLAYS_TEXT_P.
180 (note_mouse_highlight): Use MATRIX_ROW_GLYPH_START.
181 (mouse_face_from_string_pos, fast_find_string_pos):
182 Use MATRIX_ROW_VPOS.
183
184 * xfns.c (Fx_show_tip): Use MATRIX_ROW_DISPLAYS_TEXT_P.
185
186 * w32fns.c (Fx_show_tip): Use MATRIX_ROW_DISPLAYS_TEXT_P.
187
188 * xdisp.c (try_cursor_movement): Use MATRIX_ROW and
189 MATRIX_MODE_LINE_ROW.
190
191 * dispnew.c (update_window): Use MATRIX_ROW and MATRIX_MODE_LINE_ROW.
192
1932013-03-10 handa <handa@gnu.org>
194
195 * lisp.h (adjust_after_replace): Extern it.
196
197 * coding.c (detect_coding): Cound the heading ASCII bytes in the
198 case of detection for coding_category_utf_8_auto.
199 (decode_coding_gap) [not CODING_DISABLE_ASCII_OPTIMIZATION]:
200 Skip decoding if all bytes are ASCII.
201
202 * insdel.c (adjust_after_replace): Make it public. New arg
203 text_at_gap_tail.
204 (adjust_after_insert): Call adjust_after_replace with the new arg
205 value 0.
206
2072013-03-09 Stefan Monnier <monnier@iro.umontreal.ca>
208
209 * keyboard.h (EVENT_START, EVENT_END, POSN_WINDOW, POSN_POSN)
210 (POSN_WINDOW_POSN, POSN_TIMESTAMP): Be careful since events may come
211 from Elisp via unread-command-events.
212
213 * keyboard.c (access_keymap_keyremap): Accept nil return value from
214 functions to mean "no change".
215
2162013-03-08 Paul Eggert <eggert@cs.ucla.edu>
217
218 region-cache.c, scroll.c, search.c: Use bool for booleans.
219 * lisp.h (compile_pattern):
220 * scroll.c (do_scrolling, do_direct_scrolling):
221 * search.c (struct regexp_cache, compile_pattern_1)
222 (compile_pattern, string_match_1, search_command)
223 (trivial_regexp_p, search_buffer, Freplace_match, match_limit)
224 (search_regs_saved, Fregexp_quote):
225 Use bool for boolean.
226 * region-cache.c (region_cache_forward, region_cache_backward):
227 Fix comments to match code: these functions return int, not boolean.
228
12013-03-08 Dmitry Antipov <dmantipov@yandex.ru> 2292013-03-08 Dmitry Antipov <dmantipov@yandex.ru>
2 230
3 * search.c (find_newline): Accept start and end byte positions 231 * search.c (find_newline): Accept start and end byte positions
@@ -6,8 +234,8 @@
6 * lisp.h (find_newline, find_newline_no_quit): Adjust prototype. 234 * lisp.h (find_newline, find_newline_no_quit): Adjust prototype.
7 * bidi.c (bidi_find_paragraph_start): Pass byte position to 235 * bidi.c (bidi_find_paragraph_start): Pass byte position to
8 find_newline_no_quit, thus eliminating CHAR_TO_BYTE. 236 find_newline_no_quit, thus eliminating CHAR_TO_BYTE.
9 * editfns.c (Fconstrain_to_field): Break long line. Adjust 237 * editfns.c (Fconstrain_to_field): Break long line.
10 call to find_newline. 238 Adjust call to find_newline.
11 * indent.c (vmotion): Adjust calls to find_newline_no_quit. 239 * indent.c (vmotion): Adjust calls to find_newline_no_quit.
12 Use DEC_BOTH to start next search from the previous buffer 240 Use DEC_BOTH to start next search from the previous buffer
13 position, where appropriate. 241 position, where appropriate.
@@ -257,8 +485,8 @@
257 485
2582013-03-02 Eli Zaretskii <eliz@gnu.org> 4862013-03-02 Eli Zaretskii <eliz@gnu.org>
259 487
260 * textprop.c (Fadd_text_properties, Fremove_text_properties): If 488 * textprop.c (Fadd_text_properties, Fremove_text_properties):
261 the interval tree changes as a side effect of calling 489 If the interval tree changes as a side effect of calling
262 modify_region, re-do processing starting from the call to 490 modify_region, re-do processing starting from the call to
263 validate_interval_range. (Bug#13743) 491 validate_interval_range. (Bug#13743)
264 492
@@ -334,8 +562,8 @@
334 * textprop.c (Fadd_text_properties, Fremove_text_properties) 562 * textprop.c (Fadd_text_properties, Fremove_text_properties)
335 (Fremove_list_of_text_properties): Skip all of the intervals in 563 (Fremove_list_of_text_properties): Skip all of the intervals in
336 the region between START and END that already have resp. don't 564 the region between START and END that already have resp. don't
337 have the requested properties, not just the first one. Add 565 have the requested properties, not just the first one.
338 assertions that the loop afterwards always modifies the 566 Add assertions that the loop afterwards always modifies the
339 properties. (Bug#13743) 567 properties. (Bug#13743)
340 568
3412013-02-25 Stefan Monnier <monnier@iro.umontreal.ca> 5692013-02-25 Stefan Monnier <monnier@iro.umontreal.ca>
diff --git a/src/Makefile.in b/src/Makefile.in
index b42fc7faf02..eeb2b88bf32 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -139,6 +139,7 @@ M17N_FLT_LIBS = @M17N_FLT_LIBS@
139 139
140LIB_CLOCK_GETTIME=@LIB_CLOCK_GETTIME@ 140LIB_CLOCK_GETTIME=@LIB_CLOCK_GETTIME@
141LIB_EACCESS=@LIB_EACCESS@ 141LIB_EACCESS=@LIB_EACCESS@
142LIB_FDATASYNC=@LIB_FDATASYNC@
142LIB_TIMER_TIME=@LIB_TIMER_TIME@ 143LIB_TIMER_TIME=@LIB_TIMER_TIME@
143 144
144DBUS_CFLAGS = @DBUS_CFLAGS@ 145DBUS_CFLAGS = @DBUS_CFLAGS@
@@ -392,7 +393,7 @@ ALLOBJS = $(VMLIMIT_OBJ) $(obj) $(otherobj)
392LIBES = $(LIBS) $(W32_LIBS) $(LIBS_GNUSTEP) $(LIBX_BASE) $(LIBIMAGE) \ 393LIBES = $(LIBS) $(W32_LIBS) $(LIBS_GNUSTEP) $(LIBX_BASE) $(LIBIMAGE) \
393 $(LIBX_OTHER) $(LIBSOUND) \ 394 $(LIBX_OTHER) $(LIBSOUND) \
394 $(RSVG_LIBS) $(IMAGEMAGICK_LIBS) $(LIB_CLOCK_GETTIME) \ 395 $(RSVG_LIBS) $(IMAGEMAGICK_LIBS) $(LIB_CLOCK_GETTIME) \
395 $(LIB_EACCESS) $(LIB_TIMER_TIME) $(DBUS_LIBS) \ 396 $(LIB_EACCESS) $(LIB_FDATASYNC) $(LIB_TIMER_TIME) $(DBUS_LIBS) \
396 $(LIB_EXECINFO) \ 397 $(LIB_EXECINFO) \
397 $(LIBXML2_LIBS) $(LIBGPM) $(LIBRESOLV) $(LIBS_SYSTEM) \ 398 $(LIBXML2_LIBS) $(LIBGPM) $(LIBRESOLV) $(LIBS_SYSTEM) \
398 $(LIBS_TERMCAP) $(GETLOADAVG_LIBS) $(SETTINGS_LIBS) $(LIBSELINUX_LIBS) \ 399 $(LIBS_TERMCAP) $(GETLOADAVG_LIBS) $(SETTINGS_LIBS) $(LIBSELINUX_LIBS) \
diff --git a/src/alloc.c b/src/alloc.c
index 63fd973ffce..6da0ac428ab 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -413,11 +413,11 @@ buffer_memory_full (ptrdiff_t nbytes)
413 413
414#ifndef REL_ALLOC 414#ifndef REL_ALLOC
415 memory_full (nbytes); 415 memory_full (nbytes);
416#endif 416#else
417
418 /* This used to call error, but if we've run out of memory, we could 417 /* This used to call error, but if we've run out of memory, we could
419 get infinite recursion trying to build the string. */ 418 get infinite recursion trying to build the string. */
420 xsignal (Qnil, Vmemory_signal_data); 419 xsignal (Qnil, Vmemory_signal_data);
420#endif
421} 421}
422 422
423/* A common multiple of the positive integers A and B. Ideally this 423/* A common multiple of the positive integers A and B. Ideally this
diff --git a/src/bytecode.c b/src/bytecode.c
index 010477904be..45fe5d49154 100644
--- a/src/bytecode.c
+++ b/src/bytecode.c
@@ -313,9 +313,11 @@ struct byte_stack
313 Lisp_Object byte_string; 313 Lisp_Object byte_string;
314 const unsigned char *byte_string_start; 314 const unsigned char *byte_string_start;
315 315
316#if BYTE_MARK_STACK
316 /* The vector of constants used during byte-code execution. Storing 317 /* The vector of constants used during byte-code execution. Storing
317 this here protects it from GC because mark_byte_stack marks it. */ 318 this here protects it from GC because mark_byte_stack marks it. */
318 Lisp_Object constants; 319 Lisp_Object constants;
320#endif
319 321
320 /* Next entry in byte_stack_list. */ 322 /* Next entry in byte_stack_list. */
321 struct byte_stack *next; 323 struct byte_stack *next;
@@ -376,12 +378,12 @@ unmark_byte_stack (struct byte_stack *stack)
376} 378}
377 379
378 380
379/* Fetch the next byte from the bytecode stream */ 381/* Fetch the next byte from the bytecode stream. */
380 382
381#define FETCH *stack.pc++ 383#define FETCH *stack.pc++
382 384
383/* Fetch two bytes from the bytecode stream and make a 16-bit number 385/* Fetch two bytes from the bytecode stream and make a 16-bit number
384 out of them */ 386 out of them. */
385 387
386#define FETCH2 (op = FETCH, op + (FETCH << 8)) 388#define FETCH2 (op = FETCH, op + (FETCH << 8))
387 389
@@ -401,7 +403,7 @@ unmark_byte_stack (struct byte_stack *stack)
401#define DISCARD(n) (top -= (n)) 403#define DISCARD(n) (top -= (n))
402 404
403/* Get the value which is at the top of the execution stack, but don't 405/* Get the value which is at the top of the execution stack, but don't
404 pop it. */ 406 pop it. */
405 407
406#define TOP (*top) 408#define TOP (*top)
407 409
@@ -532,7 +534,9 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
532 534
533 stack.byte_string = bytestr; 535 stack.byte_string = bytestr;
534 stack.pc = stack.byte_string_start = SDATA (bytestr); 536 stack.pc = stack.byte_string_start = SDATA (bytestr);
537#if BYTE_MARK_STACK
535 stack.constants = vector; 538 stack.constants = vector;
539#endif
536 if (MAX_ALLOCA / word_size <= XFASTINT (maxdepth)) 540 if (MAX_ALLOCA / word_size <= XFASTINT (maxdepth))
537 memory_full (SIZE_MAX); 541 memory_full (SIZE_MAX);
538 top = alloca ((XFASTINT (maxdepth) + 1) * sizeof *top); 542 top = alloca ((XFASTINT (maxdepth) + 1) * sizeof *top);
@@ -748,7 +752,6 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
748 { 752 {
749 BEFORE_POTENTIAL_GC (); 753 BEFORE_POTENTIAL_GC ();
750 wrong_type_argument (Qlistp, v1); 754 wrong_type_argument (Qlistp, v1);
751 AFTER_POTENTIAL_GC ();
752 } 755 }
753 NEXT; 756 NEXT;
754 } 757 }
@@ -783,7 +786,6 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
783 { 786 {
784 BEFORE_POTENTIAL_GC (); 787 BEFORE_POTENTIAL_GC ();
785 wrong_type_argument (Qlistp, v1); 788 wrong_type_argument (Qlistp, v1);
786 AFTER_POTENTIAL_GC ();
787 } 789 }
788 NEXT; 790 NEXT;
789 } 791 }
diff --git a/src/coding.c b/src/coding.c
index 32da72ab626..6cfcec905a1 100644
--- a/src/coding.c
+++ b/src/coding.c
@@ -286,6 +286,10 @@ encode_coding_XXX (struct coding_system *coding)
286#include <config.h> 286#include <config.h>
287#include <stdio.h> 287#include <stdio.h>
288 288
289#ifdef HAVE_WCHAR_H
290#include <wchar.h>
291#endif /* HAVE_WCHAR_H */
292
289#include "lisp.h" 293#include "lisp.h"
290#include "character.h" 294#include "character.h"
291#include "buffer.h" 295#include "buffer.h"
@@ -6067,6 +6071,93 @@ complement_process_encoding_system (Lisp_Object coding_system)
6067#define EOL_SEEN_CR 2 6071#define EOL_SEEN_CR 2
6068#define EOL_SEEN_CRLF 4 6072#define EOL_SEEN_CRLF 4
6069 6073
6074
6075static Lisp_Object adjust_coding_eol_type (struct coding_system *coding, int eol_seen);
6076
6077
6078/* Return 1 if all the source bytes are ASCII, and return 0 otherwize.
6079 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 EOL_SEEN_CR, and EOL_SEEN_CRLF, but the value is reliable only when
6082 all the source bytes are ASCII. */
6083
6084static bool
6085detect_ascii (struct coding_system *coding)
6086{
6087 const unsigned char *src, *end;
6088 Lisp_Object eol_type = CODING_ID_EOL_TYPE (coding->id);
6089 int eol_seen;
6090
6091 eol_seen = (VECTORP (eol_type) ? EOL_SEEN_NONE
6092 : EQ (eol_type, Qunix) ? EOL_SEEN_LF
6093 : EQ (eol_type, Qdos) ? EOL_SEEN_CRLF
6094 : EOL_SEEN_CR);
6095 coding_set_source (coding);
6096 src = coding->source;
6097 end = src + coding->src_bytes;
6098
6099 if (inhibit_eol_conversion)
6100 {
6101 /* We don't have to check EOL format. */
6102 while (src < end && !( *src & 0x80)) src++;
6103 eol_seen = EOL_SEEN_LF;
6104 adjust_coding_eol_type (coding, eol_seen);
6105 }
6106 else if (eol_seen != EOL_SEEN_NONE)
6107 {
6108 /* We don't have to check EOL format either. */
6109 while (src < end && !(*src & 0x80)) src++;
6110 }
6111 else
6112 {
6113 end--; /* We look ahead one byte. */
6114 while (src < end)
6115 {
6116 int c = *src;
6117
6118 if (c & 0x80)
6119 break;
6120 src++;
6121 if (c < 0x20)
6122 {
6123 if (c == '\r')
6124 {
6125 if (*src == '\n')
6126 {
6127 eol_seen |= EOL_SEEN_CRLF;
6128 src++;
6129 }
6130 else
6131 eol_seen |= EOL_SEEN_CR;
6132 }
6133 else if (c == '\n')
6134 eol_seen |= EOL_SEEN_LF;
6135 }
6136 }
6137 if (src > end)
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 {
6143 end++;
6144 if (! (*src & 0x80))
6145 {
6146 if (*src == '\r')
6147 eol_seen |= EOL_SEEN_CR;
6148 else if (*src == '\n')
6149 eol_seen |= EOL_SEEN_LF;
6150 src++;
6151 }
6152 }
6153 adjust_coding_eol_type (coding, eol_seen);
6154 }
6155 coding->head_ascii = src - coding->source;
6156 coding->eol_seen = eol_seen;
6157 return (src == end);
6158}
6159
6160
6070/* Detect how end-of-line of a text of length SRC_BYTES pointed by 6161/* Detect how end-of-line of a text of length SRC_BYTES pointed by
6071 SOURCE is encoded. If CATEGORY is one of 6162 SOURCE is encoded. If CATEGORY is one of
6072 coding_category_utf_16_XXXX, assume that CR and LF are encoded by 6163 coding_category_utf_16_XXXX, assume that CR and LF are encoded by
@@ -6211,7 +6302,6 @@ detect_coding (struct coding_system *coding)
6211 coding_set_source (coding); 6302 coding_set_source (coding);
6212 6303
6213 src_end = coding->source + coding->src_bytes; 6304 src_end = coding->source + coding->src_bytes;
6214 coding->head_ascii = 0;
6215 6305
6216 /* If we have not yet decided the text encoding type, detect it 6306 /* If we have not yet decided the text encoding type, detect it
6217 now. */ 6307 now. */
@@ -6221,6 +6311,8 @@ detect_coding (struct coding_system *coding)
6221 struct coding_detection_info detect_info; 6311 struct coding_detection_info detect_info;
6222 bool null_byte_found = 0, eight_bit_found = 0; 6312 bool null_byte_found = 0, eight_bit_found = 0;
6223 6313
6314 coding->head_ascii = 0;
6315 coding->eol_seen = EOL_SEEN_NONE;
6224 detect_info.checked = detect_info.found = detect_info.rejected = 0; 6316 detect_info.checked = detect_info.found = detect_info.rejected = 0;
6225 for (src = coding->source; src < src_end; src++) 6317 for (src = coding->source; src < src_end; src++)
6226 { 6318 {
@@ -6259,6 +6351,26 @@ detect_coding (struct coding_system *coding)
6259 if (eight_bit_found) 6351 if (eight_bit_found)
6260 break; 6352 break;
6261 } 6353 }
6354 else if (! disable_ascii_optimization
6355 && ! inhibit_eol_conversion)
6356 {
6357 if (c == '\r')
6358 {
6359 if (src < src_end && src[1] == '\n')
6360 {
6361 coding->eol_seen |= EOL_SEEN_CRLF;
6362 src++;
6363 coding->head_ascii++;
6364 }
6365 else
6366 coding->eol_seen |= EOL_SEEN_CR;
6367 }
6368 else if (c == '\n')
6369 {
6370 coding->eol_seen |= EOL_SEEN_LF;
6371 }
6372 }
6373
6262 if (! eight_bit_found) 6374 if (! eight_bit_found)
6263 coding->head_ascii++; 6375 coding->head_ascii++;
6264 } 6376 }
@@ -6349,14 +6461,20 @@ detect_coding (struct coding_system *coding)
6349 coding_systems 6461 coding_systems
6350 = AREF (CODING_ID_ATTRS (coding->id), coding_attr_utf_bom); 6462 = AREF (CODING_ID_ATTRS (coding->id), coding_attr_utf_bom);
6351 detect_info.found = detect_info.rejected = 0; 6463 detect_info.found = detect_info.rejected = 0;
6352 coding->head_ascii = 0; 6464 if (detect_ascii (coding))
6353 if (CONSP (coding_systems)
6354 && detect_coding_utf_8 (coding, &detect_info))
6355 { 6465 {
6356 if (detect_info.found & CATEGORY_MASK_UTF_8_SIG) 6466 setup_coding_system (XCDR (coding_systems), coding);
6357 setup_coding_system (XCAR (coding_systems), coding); 6467 }
6358 else 6468 else
6359 setup_coding_system (XCDR (coding_systems), coding); 6469 {
6470 if (CONSP (coding_systems)
6471 && detect_coding_utf_8 (coding, &detect_info))
6472 {
6473 if (detect_info.found & CATEGORY_MASK_UTF_8_SIG)
6474 setup_coding_system (XCAR (coding_systems), coding);
6475 else
6476 setup_coding_system (XCDR (coding_systems), coding);
6477 }
6360 } 6478 }
6361 } 6479 }
6362 else if (XINT (CODING_ATTR_CATEGORY (CODING_ID_ATTRS (coding->id))) 6480 else if (XINT (CODING_ATTR_CATEGORY (CODING_ID_ATTRS (coding->id)))
@@ -6369,6 +6487,7 @@ detect_coding (struct coding_system *coding)
6369 = AREF (CODING_ID_ATTRS (coding->id), coding_attr_utf_bom); 6487 = AREF (CODING_ID_ATTRS (coding->id), coding_attr_utf_bom);
6370 detect_info.found = detect_info.rejected = 0; 6488 detect_info.found = detect_info.rejected = 0;
6371 coding->head_ascii = 0; 6489 coding->head_ascii = 0;
6490 coding->eol_seen = EOL_SEEN_NONE;
6372 if (CONSP (coding_systems) 6491 if (CONSP (coding_systems)
6373 && detect_coding_utf_16 (coding, &detect_info)) 6492 && detect_coding_utf_16 (coding, &detect_info))
6374 { 6493 {
@@ -6806,7 +6925,7 @@ produce_chars (struct coding_system *coding, Lisp_Object translation_table,
6806 6925
6807 produced = dst - (coding->destination + coding->produced); 6926 produced = dst - (coding->destination + coding->produced);
6808 if (BUFFERP (coding->dst_object) && produced_chars > 0) 6927 if (BUFFERP (coding->dst_object) && produced_chars > 0)
6809 insert_from_gap (produced_chars, produced); 6928 insert_from_gap (produced_chars, produced, 0);
6810 coding->produced += produced; 6929 coding->produced += produced;
6811 coding->produced_char += produced_chars; 6930 coding->produced_char += produced_chars;
6812 return carryover; 6931 return carryover;
@@ -7391,7 +7510,7 @@ encode_coding (struct coding_system *coding)
7391 } while (coding->consumed_char < coding->src_chars); 7510 } while (coding->consumed_char < coding->src_chars);
7392 7511
7393 if (BUFFERP (coding->dst_object) && coding->produced_char > 0) 7512 if (BUFFERP (coding->dst_object) && coding->produced_char > 0)
7394 insert_from_gap (coding->produced_char, coding->produced); 7513 insert_from_gap (coding->produced_char, coding->produced, 0);
7395 7514
7396 SAFE_FREE (); 7515 SAFE_FREE ();
7397} 7516}
@@ -7487,8 +7606,6 @@ decode_coding_gap (struct coding_system *coding,
7487 ptrdiff_t count = SPECPDL_INDEX (); 7606 ptrdiff_t count = SPECPDL_INDEX ();
7488 Lisp_Object attrs; 7607 Lisp_Object attrs;
7489 7608
7490 code_conversion_save (0, 0);
7491
7492 coding->src_object = Fcurrent_buffer (); 7609 coding->src_object = Fcurrent_buffer ();
7493 coding->src_chars = chars; 7610 coding->src_chars = chars;
7494 coding->src_bytes = bytes; 7611 coding->src_bytes = bytes;
@@ -7502,13 +7619,53 @@ decode_coding_gap (struct coding_system *coding,
7502 7619
7503 if (CODING_REQUIRE_DETECTION (coding)) 7620 if (CODING_REQUIRE_DETECTION (coding))
7504 detect_coding (coding); 7621 detect_coding (coding);
7622 attrs = CODING_ID_ATTRS (coding->id);
7623 if (! disable_ascii_optimization)
7624 {
7625 if (! NILP (CODING_ATTR_ASCII_COMPAT (attrs))
7626 && NILP (CODING_ATTR_POST_READ (attrs))
7627 && NILP (get_translation_table (attrs, 0, NULL))
7628 && (coding->head_ascii >= 0 /* We've already called detect_coding */
7629 ? coding->head_ascii == bytes
7630 : detect_ascii (coding)))
7631 {
7632 if (coding->eol_seen == EOL_SEEN_CR)
7633 {
7634 unsigned char *src_end = GAP_END_ADDR;
7635 unsigned char *src = src_end - coding->src_bytes;
7636
7637 while (src < src_end)
7638 {
7639 if (*src++ == '\r')
7640 src[-1] = '\n';
7641 }
7642 }
7643 else if (coding->eol_seen == EOL_SEEN_CRLF)
7644 {
7645 unsigned char *src = GAP_END_ADDR;
7646 unsigned char *src_beg = src - coding->src_bytes;
7647 unsigned char *dst = src;
7648
7649 while (src_beg < src)
7650 {
7651 *--dst = *--src;
7652 if (*src == '\n')
7653 src--;
7654 }
7655 bytes -= dst - src;
7656 }
7657 coding->produced_char = coding->produced = bytes;
7658 insert_from_gap (bytes, bytes, 1);
7659 return;
7660 }
7661 }
7662 code_conversion_save (0, 0);
7505 7663
7506 coding->mode |= CODING_MODE_LAST_BLOCK; 7664 coding->mode |= CODING_MODE_LAST_BLOCK;
7507 current_buffer->text->inhibit_shrinking = 1; 7665 current_buffer->text->inhibit_shrinking = 1;
7508 decode_coding (coding); 7666 decode_coding (coding);
7509 current_buffer->text->inhibit_shrinking = 0; 7667 current_buffer->text->inhibit_shrinking = 0;
7510 7668
7511 attrs = CODING_ID_ATTRS (coding->id);
7512 if (! NILP (CODING_ATTR_POST_READ (attrs))) 7669 if (! NILP (CODING_ATTR_POST_READ (attrs)))
7513 { 7670 {
7514 ptrdiff_t prev_Z = Z, prev_Z_BYTE = Z_BYTE; 7671 ptrdiff_t prev_Z = Z, prev_Z_BYTE = Z_BYTE;
@@ -7966,11 +8123,21 @@ from_unicode (Lisp_Object str)
7966 return code_convert_string_norecord (str, Qutf_16le, 0); 8123 return code_convert_string_norecord (str, Qutf_16le, 0);
7967} 8124}
7968 8125
8126Lisp_Object
8127from_unicode_buffer (const wchar_t* wstr)
8128{
8129 return from_unicode (
8130 make_unibyte_string (
8131 (char*) wstr,
8132 /* we get one of the two final 0 bytes for free. */
8133 1 + sizeof (wchar_t) * wcslen (wstr)));
8134}
8135
7969wchar_t * 8136wchar_t *
7970to_unicode (Lisp_Object str, Lisp_Object *buf) 8137to_unicode (Lisp_Object str, Lisp_Object *buf)
7971{ 8138{
7972 *buf = code_convert_string_norecord (str, Qutf_16le, 1); 8139 *buf = code_convert_string_norecord (str, Qutf_16le, 1);
7973 /* We need to make a another copy (in addition to the one made by 8140 /* We need to make another copy (in addition to the one made by
7974 code_convert_string_norecord) to ensure that the final string is 8141 code_convert_string_norecord) to ensure that the final string is
7975 _doubly_ zero terminated --- that is, that the string is 8142 _doubly_ zero terminated --- that is, that the string is
7976 terminated by two zero bytes and one utf-16le null character. 8143 terminated by two zero bytes and one utf-16le null character.
@@ -10707,6 +10874,11 @@ from GNU Find and GNU Grep. Emacs will then ignore the null bytes and
10707decode text as usual. */); 10874decode text as usual. */);
10708 inhibit_null_byte_detection = 0; 10875 inhibit_null_byte_detection = 0;
10709 10876
10877 DEFVAR_BOOL ("disable-ascii-optimization", disable_ascii_optimization,
10878 doc: /* If non-nil, Emacs does not optimize code decoder for ASCII files.
10879Internal use only. Removed after the experimental optimizer gets stable. */);
10880 disable_ascii_optimization = 0;
10881
10710 DEFVAR_LISP ("translation-table-for-input", Vtranslation_table_for_input, 10882 DEFVAR_LISP ("translation-table-for-input", Vtranslation_table_for_input,
10711 doc: /* Char table for translating self-inserting characters. 10883 doc: /* Char table for translating self-inserting characters.
10712This is applied to the result of input methods, not their input. 10884This is applied to the result of input methods, not their input.
diff --git a/src/coding.h b/src/coding.h
index 28a7d776b63..d40209be68f 100644
--- a/src/coding.h
+++ b/src/coding.h
@@ -440,9 +440,13 @@ struct coding_system
440 /* How may heading bytes we can skip for decoding. This is set to 440 /* How may heading bytes we can skip for decoding. This is set to
441 -1 in setup_coding_system, and updated by detect_coding. So, 441 -1 in setup_coding_system, and updated by detect_coding. So,
442 when this is equal to the byte length of the text being 442 when this is equal to the byte length of the text being
443 converted, we can skip the actual conversion process. */ 443 converted, we can skip the actual conversion process except for
444 the eol format. */
444 ptrdiff_t head_ascii; 445 ptrdiff_t head_ascii;
445 446
447 /* Used internally in coding.c. See the comment of detect_ascii. */
448 int eol_seen;
449
446 /* The following members are set by encoding/decoding routine. */ 450 /* The following members are set by encoding/decoding routine. */
447 ptrdiff_t produced, produced_char, consumed, consumed_char; 451 ptrdiff_t produced, produced_char, consumed, consumed_char;
448 452
@@ -715,6 +719,9 @@ extern wchar_t *to_unicode (Lisp_Object str, Lisp_Object *buf);
715 failure modes. STR itself is not modified. */ 719 failure modes. STR itself is not modified. */
716extern Lisp_Object from_unicode (Lisp_Object str); 720extern Lisp_Object from_unicode (Lisp_Object str);
717 721
722/* Convert WSTR to an Emacs string. */
723extern Lisp_Object from_unicode_buffer (const wchar_t* wstr);
724
718#endif /* WINDOWSNT || CYGWIN */ 725#endif /* WINDOWSNT || CYGWIN */
719 726
720/* Macros for backward compatibility. */ 727/* Macros for backward compatibility. */
diff --git a/src/conf_post.h b/src/conf_post.h
index 6c9747a436c..5cb385d9029 100644
--- a/src/conf_post.h
+++ b/src/conf_post.h
@@ -44,19 +44,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
44# define __has_attribute(a) 0 /* non-clang */ 44# define __has_attribute(a) 0 /* non-clang */
45#endif 45#endif
46 46
47/* This silences a few compilation warnings on FreeBSD. */
48#ifdef BSD_SYSTEM_AHB
49#undef BSD_SYSTEM_AHB
50#undef BSD_SYSTEM
51#if __FreeBSD__ == 1
52#define BSD_SYSTEM 199103
53#elif __FreeBSD__ == 2
54#define BSD_SYSTEM 199306
55#elif __FreeBSD__ >= 3
56#define BSD_SYSTEM 199506
57#endif
58#endif
59
60#ifdef DARWIN_OS 47#ifdef DARWIN_OS
61#ifdef emacs 48#ifdef emacs
62#define malloc unexec_malloc 49#define malloc unexec_malloc
diff --git a/src/dispnew.c b/src/dispnew.c
index f9fed7de406..47adab6b8f7 100644
--- a/src/dispnew.c
+++ b/src/dispnew.c
@@ -3392,8 +3392,8 @@ update_window (struct window *w, bool force_p)
3392 3392
3393 rif->update_window_begin_hook (w); 3393 rif->update_window_begin_hook (w);
3394 yb = window_text_bottom_y (w); 3394 yb = window_text_bottom_y (w);
3395 row = desired_matrix->rows; 3395 row = MATRIX_ROW (desired_matrix, 0);
3396 end = row + desired_matrix->nrows - 1; 3396 end = MATRIX_MODE_LINE_ROW (desired_matrix);
3397 3397
3398 /* Take note of the header line, if there is one. We will 3398 /* Take note of the header line, if there is one. We will
3399 update it below, after updating all of the window's lines. */ 3399 update it below, after updating all of the window's lines. */
@@ -6100,10 +6100,7 @@ init_display (void)
6100 6100
6101 /* If no window system has been specified, try to use the terminal. */ 6101 /* If no window system has been specified, try to use the terminal. */
6102 if (! isatty (0)) 6102 if (! isatty (0))
6103 { 6103 fatal ("standard input is not a tty");
6104 fatal ("standard input is not a tty");
6105 exit (1);
6106 }
6107 6104
6108#ifdef WINDOWSNT 6105#ifdef WINDOWSNT
6109 terminal_type = "w32console"; 6106 terminal_type = "w32console";
diff --git a/src/emacs.c b/src/emacs.c
index 7b6f147619b..148bb836927 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -44,7 +44,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
44#include "w32common.h" 44#include "w32common.h"
45#endif 45#endif
46 46
47#if defined HAVE_NTGUI && defined CYGWIN 47#if defined CYGWIN
48#include "cygw32.h" 48#include "cygw32.h"
49#endif 49#endif
50 50
@@ -1339,7 +1339,7 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem
1339#ifdef WINDOWSNT 1339#ifdef WINDOWSNT
1340 syms_of_ntproc (); 1340 syms_of_ntproc ();
1341#endif /* WINDOWSNT */ 1341#endif /* WINDOWSNT */
1342#if defined CYGWIN && defined HAVE_NTGUI 1342#if defined CYGWIN
1343 syms_of_cygw32 (); 1343 syms_of_cygw32 ();
1344#endif 1344#endif
1345 syms_of_window (); 1345 syms_of_window ();
diff --git a/src/eval.c b/src/eval.c
index 6d34cd80802..a58a1508aaf 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -1709,7 +1709,6 @@ error (const char *m, ...)
1709 va_list ap; 1709 va_list ap;
1710 va_start (ap, m); 1710 va_start (ap, m);
1711 verror (m, ap); 1711 verror (m, ap);
1712 va_end (ap);
1713} 1712}
1714 1713
1715DEFUN ("commandp", Fcommandp, Scommandp, 1, 2, 0, 1714DEFUN ("commandp", Fcommandp, Scommandp, 1, 2, 0,
diff --git a/src/fileio.c b/src/fileio.c
index d7363077b35..724250c8aaa 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -1850,9 +1850,6 @@ those `/' is discarded. */)
1850 error ("Missing \"}\" in environment-variable substitution"); 1850 error ("Missing \"}\" in environment-variable substitution");
1851 badvar: 1851 badvar:
1852 error ("Substituting nonexistent environment variable \"%s\"", target); 1852 error ("Substituting nonexistent environment variable \"%s\"", target);
1853
1854 /* NOTREACHED */
1855 return Qnil;
1856} 1853}
1857 1854
1858/* A slightly faster and more convenient way to get 1855/* A slightly faster and more convenient way to get
@@ -3305,7 +3302,6 @@ Use the current time if TIMESTAMP is nil. TIMESTAMP is in the format of
3305 return Qnil; 3302 return Qnil;
3306#endif 3303#endif
3307 report_file_error ("Setting file times", Fcons (absname, Qnil)); 3304 report_file_error ("Setting file times", Fcons (absname, Qnil));
3308 return Qnil;
3309 } 3305 }
3310 } 3306 }
3311 3307
@@ -4963,20 +4959,23 @@ This calls `write-region-annotate-functions' at the start, and
4963 4959
4964 immediate_quit = 0; 4960 immediate_quit = 0;
4965 4961
4966#ifdef HAVE_FSYNC
4967 /* fsync appears to change the modtime on BSD4.2. 4962 /* fsync appears to change the modtime on BSD4.2.
4968 Disk full in NFS may be reported here. */ 4963 Disk full in NFS may be reported here. */
4969 /* mib says that closing the file will try to write as fast as NFS can do 4964 /* mib says that closing the file will try to write as fast as NFS can do
4970 it, and that means the fsync here is not crucial for autosave files. */ 4965 it, and that means the fsync here is not crucial for autosave files. */
4971 if (!auto_saving && !write_region_inhibit_fsync && fsync (desc) < 0) 4966 if (!auto_saving && !write_region_inhibit_fsync)
4972 { 4967 {
4973 /* If fsync fails with EINTR, don't treat that as serious. Also 4968 /* Transfer data and metadata to disk, retrying if interrupted. Also,
4974 ignore EINVAL which happens when fsync is not supported on this 4969 ignore EINVAL which happens when fsync is not supported on this
4975 file. */ 4970 file. */
4976 if (errno != EINTR && errno != EINVAL) 4971 while (fsync (desc) != 0)
4977 ok = 0, save_errno = errno; 4972 if (errno != EINTR)
4973 {
4974 if (errno != EINVAL)
4975 ok = 0, save_errno = errno;
4976 break;
4977 }
4978 } 4978 }
4979#endif
4980 4979
4981 modtime = invalid_emacs_time (); 4980 modtime = invalid_emacs_time ();
4982 if (visiting) 4981 if (visiting)
@@ -6050,13 +6049,11 @@ in the buffer; this is the default behavior, because the auto-save
6050file is usually more useful if it contains the deleted text. */); 6049file is usually more useful if it contains the deleted text. */);
6051 Vauto_save_include_big_deletions = Qnil; 6050 Vauto_save_include_big_deletions = Qnil;
6052 6051
6053#ifdef HAVE_FSYNC
6054 DEFVAR_BOOL ("write-region-inhibit-fsync", write_region_inhibit_fsync, 6052 DEFVAR_BOOL ("write-region-inhibit-fsync", write_region_inhibit_fsync,
6055 doc: /* Non-nil means don't call fsync in `write-region'. 6053 doc: /* Non-nil means don't call fsync in `write-region'.
6056This variable affects calls to `write-region' as well as save commands. 6054This variable affects calls to `write-region' as well as save commands.
6057A non-nil value may result in data loss! */); 6055A non-nil value may result in data loss! */);
6058 write_region_inhibit_fsync = 0; 6056 write_region_inhibit_fsync = 0;
6059#endif
6060 6057
6061 DEFVAR_BOOL ("delete-by-moving-to-trash", delete_by_moving_to_trash, 6058 DEFVAR_BOOL ("delete-by-moving-to-trash", delete_by_moving_to_trash,
6062 doc: /* Specifies whether to use the system's trash can. 6059 doc: /* Specifies whether to use the system's trash can.
diff --git a/src/filelock.c b/src/filelock.c
index 32992896c2b..f17d3182eab 100644
--- a/src/filelock.c
+++ b/src/filelock.c
@@ -437,6 +437,14 @@ create_lock_file (char *lfname, char *lock_info_str, bool force)
437 if (emacs_write (fd, lock_info_str, lock_info_len) != lock_info_len 437 if (emacs_write (fd, lock_info_str, lock_info_len) != lock_info_len
438 || (need_fchmod && fchmod (fd, world_readable) != 0)) 438 || (need_fchmod && fchmod (fd, world_readable) != 0))
439 err = errno; 439 err = errno;
440 else
441 while (fsync (fd) != 0)
442 if (errno != EINTR)
443 {
444 if (errno != EINVAL)
445 err = errno;
446 break;
447 }
440 if (emacs_close (fd) != 0) 448 if (emacs_close (fd) != 0)
441 err = errno; 449 err = errno;
442 if (!err && rename_lock_file (nonce, lfname, force) != 0) 450 if (!err && rename_lock_file (nonce, lfname, force) != 0)
diff --git a/src/insdel.c b/src/insdel.c
index fc5a4576dc2..a60fed0c32e 100644
--- a/src/insdel.c
+++ b/src/insdel.c
@@ -977,10 +977,11 @@ insert_from_string_1 (Lisp_Object string, ptrdiff_t pos, ptrdiff_t pos_byte,
977} 977}
978 978
979/* Insert a sequence of NCHARS chars which occupy NBYTES bytes 979/* Insert a sequence of NCHARS chars which occupy NBYTES bytes
980 starting at GPT_ADDR. */ 980 starting at GAP_END_ADDR - NBYTES (if text_at_gap_tail) and at
981 GPT_ADDR (if not text_at_gap_tail). */
981 982
982void 983void
983insert_from_gap (ptrdiff_t nchars, ptrdiff_t nbytes) 984insert_from_gap (ptrdiff_t nchars, ptrdiff_t nbytes, bool text_at_gap_tail)
984{ 985{
985 if (NILP (BVAR (current_buffer, enable_multibyte_characters))) 986 if (NILP (BVAR (current_buffer, enable_multibyte_characters)))
986 nchars = nbytes; 987 nchars = nbytes;
@@ -989,10 +990,13 @@ insert_from_gap (ptrdiff_t nchars, ptrdiff_t nbytes)
989 MODIFF++; 990 MODIFF++;
990 991
991 GAP_SIZE -= nbytes; 992 GAP_SIZE -= nbytes;
992 GPT += nchars; 993 if (! text_at_gap_tail)
994 {
995 GPT += nchars;
996 GPT_BYTE += nbytes;
997 }
993 ZV += nchars; 998 ZV += nchars;
994 Z += nchars; 999 Z += nchars;
995 GPT_BYTE += nbytes;
996 ZV_BYTE += nbytes; 1000 ZV_BYTE += nbytes;
997 Z_BYTE += nbytes; 1001 Z_BYTE += nbytes;
998 if (GAP_SIZE > 0) *(GPT_ADDR) = 0; /* Put an anchor. */ 1002 if (GAP_SIZE > 0) *(GPT_ADDR) = 0; /* Put an anchor. */
@@ -1010,7 +1014,7 @@ insert_from_gap (ptrdiff_t nchars, ptrdiff_t nbytes)
1010 current_buffer, 0); 1014 current_buffer, 0);
1011 } 1015 }
1012 1016
1013 if (GPT - nchars < PT) 1017 if (! text_at_gap_tail && GPT - nchars < PT)
1014 adjust_point (nchars, nbytes); 1018 adjust_point (nchars, nbytes);
1015 1019
1016 check_markers (); 1020 check_markers ();
diff --git a/src/keyboard.c b/src/keyboard.c
index 914378947ed..e43b7a73172 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -6552,10 +6552,7 @@ has the same base event type and all the specified modifiers. */)
6552 else if (SYMBOLP (base)) 6552 else if (SYMBOLP (base))
6553 return apply_modifiers (modifiers, base); 6553 return apply_modifiers (modifiers, base);
6554 else 6554 else
6555 { 6555 error ("Invalid base event");
6556 error ("Invalid base event");
6557 return Qnil;
6558 }
6559} 6556}
6560 6557
6561/* Try to recognize SYMBOL as a modifier name. 6558/* Try to recognize SYMBOL as a modifier name.
@@ -6815,48 +6812,6 @@ gobble_input (void)
6815 return nread; 6812 return nread;
6816} 6813}
6817 6814
6818static void
6819decode_keyboard_code (struct tty_display_info *tty,
6820 struct coding_system *coding,
6821 unsigned char *buf, int nbytes)
6822{
6823 unsigned char *src = buf;
6824 const unsigned char *p;
6825 int i;
6826
6827 if (nbytes == 0)
6828 return;
6829 if (tty->meta_key != 2)
6830 for (i = 0; i < nbytes; i++)
6831 buf[i] &= ~0x80;
6832 if (coding->carryover_bytes > 0)
6833 {
6834 src = alloca (coding->carryover_bytes + nbytes);
6835 memcpy (src, coding->carryover, coding->carryover_bytes);
6836 memcpy (src + coding->carryover_bytes, buf, nbytes);
6837 nbytes += coding->carryover_bytes;
6838 }
6839 coding->destination = alloca (nbytes * 4);
6840 coding->dst_bytes = nbytes * 4;
6841 decode_coding_c_string (coding, src, nbytes, Qnil);
6842 if (coding->produced_char == 0)
6843 return;
6844 for (i = 0, p = coding->destination; i < coding->produced_char; i++)
6845 {
6846 struct input_event event_buf;
6847
6848 EVENT_INIT (event_buf);
6849 event_buf.code = STRING_CHAR_ADVANCE (p);
6850 event_buf.kind =
6851 (ASCII_CHAR_P (event_buf.code)
6852 ? ASCII_KEYSTROKE_EVENT : MULTIBYTE_CHAR_KEYSTROKE_EVENT);
6853 /* See the comment in tty_read_avail_input. */
6854 event_buf.frame_or_window = tty->top_frame;
6855 event_buf.arg = Qnil;
6856 kbd_buffer_store_event (&event_buf);
6857 }
6858}
6859
6860/* This is the tty way of reading available input. 6815/* This is the tty way of reading available input.
6861 6816
6862 Note that each terminal device has its own `struct terminal' object, 6817 Note that each terminal device has its own `struct terminal' object,
@@ -7014,36 +6969,6 @@ tty_read_avail_input (struct terminal *terminal,
7014#endif /* not MSDOS */ 6969#endif /* not MSDOS */
7015#endif /* not WINDOWSNT */ 6970#endif /* not WINDOWSNT */
7016 6971
7017 if (TERMINAL_KEYBOARD_CODING (terminal)->common_flags
7018 & CODING_REQUIRE_DECODING_MASK)
7019 {
7020 struct coding_system *coding = TERMINAL_KEYBOARD_CODING (terminal);
7021 int from;
7022
7023 /* Decode the key sequence except for those with meta
7024 modifiers. */
7025 for (i = from = 0; ; i++)
7026 if (i == nread || (tty->meta_key == 1 && (cbuf[i] & 0x80)))
7027 {
7028 struct input_event buf;
7029
7030 decode_keyboard_code (tty, coding, cbuf + from, i - from);
7031 if (i == nread)
7032 break;
7033
7034 EVENT_INIT (buf);
7035 buf.kind = ASCII_KEYSTROKE_EVENT;
7036 buf.modifiers = meta_modifier;
7037 buf.code = cbuf[i] & ~0x80;
7038 /* See the comment below. */
7039 buf.frame_or_window = tty->top_frame;
7040 buf.arg = Qnil;
7041 kbd_buffer_store_event (&buf);
7042 from = i + 1;
7043 }
7044 return nread;
7045 }
7046
7047 for (i = 0; i < nread; i++) 6972 for (i = 0; i < nread; i++)
7048 { 6973 {
7049 struct input_event buf; 6974 struct input_event buf;
@@ -8699,7 +8624,7 @@ access_keymap_keyremap (Lisp_Object map, Lisp_Object key, Lisp_Object prompt,
8699 barf--don't ignore it. 8624 barf--don't ignore it.
8700 (To ignore it safely, we would need to gcpro a bunch of 8625 (To ignore it safely, we would need to gcpro a bunch of
8701 other variables.) */ 8626 other variables.) */
8702 if (! (VECTORP (next) || STRINGP (next))) 8627 if (! (NILP (next) || VECTORP (next) || STRINGP (next)))
8703 error ("Function %s returns invalid key sequence", 8628 error ("Function %s returns invalid key sequence",
8704 SSDATA (SYMBOL_NAME (tem))); 8629 SSDATA (SYMBOL_NAME (tem)));
8705 } 8630 }
@@ -8783,6 +8708,71 @@ test_undefined (Lisp_Object binding)
8783 && EQ (Fcommand_remapping (binding, Qnil, Qnil), Qundefined))); 8708 && EQ (Fcommand_remapping (binding, Qnil, Qnil), Qundefined)));
8784} 8709}
8785 8710
8711/* Like `read_char' but applies keyboard-coding-system to tty input. */
8712static Lisp_Object
8713read_decoded_char (int commandflag, Lisp_Object map,
8714 Lisp_Object prev_event, bool *used_mouse_menu)
8715{
8716#define MAX_ENCODED_BYTES 16
8717 Lisp_Object events[MAX_ENCODED_BYTES];
8718 int n = 0;
8719 while (true)
8720 {
8721 Lisp_Object nextevt
8722 = read_char (commandflag, map, prev_event, used_mouse_menu, NULL);
8723 struct frame *frame = XFRAME (selected_frame);
8724 struct terminal *terminal = frame->terminal;
8725 if (!((FRAME_TERMCAP_P (frame) || FRAME_MSDOS_P (frame))
8726 && (TERMINAL_KEYBOARD_CODING (terminal)->common_flags
8727 & CODING_REQUIRE_DECODING_MASK)))
8728 return nextevt; /* No decoding needed. */
8729 else
8730 {
8731 int meta_key = terminal->display_info.tty->meta_key;
8732 eassert (n < MAX_ENCODED_BYTES);
8733 events[n++] = nextevt;
8734 if (NATNUMP (nextevt)
8735 && XINT (nextevt) < (meta_key == 1 ? 0x80 : 0x100))
8736 { /* An encoded byte sequence, let's try to decode it. */
8737 struct coding_system *coding
8738 = TERMINAL_KEYBOARD_CODING (terminal);
8739 unsigned char *src = alloca (n);
8740 int i;
8741 for (i = 0; i < n; i++)
8742 src[i] = XINT (events[i]);
8743 if (meta_key != 2)
8744 for (i = 0; i < n; i++)
8745 src[i] &= ~0x80;
8746 coding->destination = alloca (n * 4);
8747 coding->dst_bytes = n * 4;
8748 decode_coding_c_string (coding, src, n, Qnil);
8749 eassert (coding->produced_char <= n);
8750 if (coding->produced_char == 0)
8751 { /* The encoded sequence is incomplete. */
8752 if (n < MAX_ENCODED_BYTES) /* Avoid buffer overflow. */
8753 continue; /* Read on! */
8754 }
8755 else
8756 {
8757 const unsigned char *p = coding->destination;
8758 eassert (coding->carryover_bytes == 0);
8759 n = 0;
8760 while (n < coding->produced_char)
8761 events[n++] = make_number (STRING_CHAR_ADVANCE (p));
8762 }
8763 }
8764 /* Now `events' should hold decoded events.
8765 Normally, n should be equal to 1, but better not rely on it.
8766 We can only return one event here, so return the first we
8767 had and keep the others (if any) for later. */
8768 while (n > 1)
8769 Vunread_command_events
8770 = Fcons (events[--n], Vunread_command_events);
8771 return events[0];
8772 }
8773 }
8774}
8775
8786/* Read a sequence of keys that ends with a non prefix character, 8776/* Read a sequence of keys that ends with a non prefix character,
8787 storing it in KEYBUF, a buffer of size BUFSIZE. 8777 storing it in KEYBUF, a buffer of size BUFSIZE.
8788 Prompt with PROMPT. 8778 Prompt with PROMPT.
@@ -9060,9 +9050,9 @@ read_key_sequence (Lisp_Object *keybuf, int bufsize, Lisp_Object prompt,
9060 { 9050 {
9061 KBOARD *interrupted_kboard = current_kboard; 9051 KBOARD *interrupted_kboard = current_kboard;
9062 struct frame *interrupted_frame = SELECTED_FRAME (); 9052 struct frame *interrupted_frame = SELECTED_FRAME ();
9063 key = read_char (NILP (prompt), 9053 key = read_decoded_char (NILP (prompt),
9064 current_binding, last_nonmenu_event, 9054 current_binding, last_nonmenu_event,
9065 &used_mouse_menu, NULL); 9055 &used_mouse_menu);
9066 if ((INTEGERP (key) && XINT (key) == -2) /* wrong_kboard_jmpbuf */ 9056 if ((INTEGERP (key) && XINT (key) == -2) /* wrong_kboard_jmpbuf */
9067 /* When switching to a new tty (with a new keyboard), 9057 /* When switching to a new tty (with a new keyboard),
9068 read_char returns the new buffer, rather than -2 9058 read_char returns the new buffer, rather than -2
@@ -10553,7 +10543,7 @@ See also `current-input-mode'. */)
10553 if (tty->flow_control != !NILP (flow)) 10543 if (tty->flow_control != !NILP (flow))
10554 { 10544 {
10555#ifndef DOS_NT 10545#ifndef DOS_NT
10556 /* this causes startup screen to be restored and messes with the mouse */ 10546 /* This causes startup screen to be restored and messes with the mouse. */
10557 reset_sys_modes (tty); 10547 reset_sys_modes (tty);
10558#endif 10548#endif
10559 10549
diff --git a/src/keyboard.h b/src/keyboard.h
index c6ade35dd52..8bb1c409efc 100644
--- a/src/keyboard.h
+++ b/src/keyboard.h
@@ -421,18 +421,18 @@ typedef struct _widget_value
421 (EVENT_HAS_PARAMETERS (event) ? XCAR (event) : (event)) 421 (EVENT_HAS_PARAMETERS (event) ? XCAR (event) : (event))
422 422
423/* Extract the starting and ending positions from a composite event. */ 423/* Extract the starting and ending positions from a composite event. */
424#define EVENT_START(event) (XCAR (XCDR (event))) 424#define EVENT_START(event) (CAR_SAFE (CDR_SAFE (event)))
425#define EVENT_END(event) (XCAR (XCDR (XCDR (event)))) 425#define EVENT_END(event) (CAR_SAFE (CDR_SAFE (CDR_SAFE (event))))
426 426
427/* Extract the click count from a multi-click event. */ 427/* Extract the click count from a multi-click event. */
428#define EVENT_CLICK_COUNT(event) (Fnth (make_number (2), (event))) 428#define EVENT_CLICK_COUNT(event) (Fnth (make_number (2), (event)))
429 429
430/* Extract the fields of a position. */ 430/* Extract the fields of a position. */
431#define POSN_WINDOW(posn) (XCAR (posn)) 431#define POSN_WINDOW(posn) (CAR_SAFE (posn))
432#define POSN_POSN(posn) (XCAR (XCDR (posn))) 432#define POSN_POSN(posn) (CAR_SAFE (CDR_SAFE (posn)))
433#define POSN_SET_POSN(posn,x) (XSETCAR (XCDR (posn), (x))) 433#define POSN_SET_POSN(posn,x) (XSETCAR (XCDR (posn), (x)))
434#define POSN_WINDOW_POSN(posn) (XCAR (XCDR (XCDR (posn)))) 434#define POSN_WINDOW_POSN(posn) (CAR_SAFE (CDR_SAFE (CDR_SAFE (posn))))
435#define POSN_TIMESTAMP(posn) (XCAR (XCDR (XCDR (XCDR (posn))))) 435#define POSN_TIMESTAMP(posn) (CAR_SAFE (CDR_SAFE (CDR_SAFE (CDR_SAFE (posn)))))
436#define POSN_SCROLLBAR_PART(posn) (Fnth (make_number (4), (posn))) 436#define POSN_SCROLLBAR_PART(posn) (Fnth (make_number (4), (posn)))
437 437
438/* A cons (STRING . STRING-CHARPOS), or nil in mouse-click events. 438/* A cons (STRING . STRING-CHARPOS), or nil in mouse-click events.
diff --git a/src/keymap.c b/src/keymap.c
index 922c1703edf..00eefb375ef 100644
--- a/src/keymap.c
+++ b/src/keymap.c
@@ -565,7 +565,8 @@ map_keymap_char_table_item (Lisp_Object args, Lisp_Object key, Lisp_Object val)
565{ 565{
566 if (!NILP (val)) 566 if (!NILP (val))
567 { 567 {
568 map_keymap_function_t fun = XSAVE_POINTER (args, 0); 568 map_keymap_function_t fun
569 = (map_keymap_function_t) XSAVE_POINTER (args, 0);
569 /* If the key is a range, make a copy since map_char_table modifies 570 /* If the key is a range, make a copy since map_char_table modifies
570 it in place. */ 571 it in place. */
571 if (CONSP (key)) 572 if (CONSP (key))
@@ -2310,7 +2311,6 @@ around function keys and event symbols. */)
2310 return Fcopy_sequence (key); 2311 return Fcopy_sequence (key);
2311 else 2312 else
2312 error ("KEY must be an integer, cons, symbol, or string"); 2313 error ("KEY must be an integer, cons, symbol, or string");
2313 return Qnil;
2314} 2314}
2315 2315
2316static char * 2316static char *
diff --git a/src/lisp.h b/src/lisp.h
index 735cf8097dd..44dde1860cc 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -2894,7 +2894,7 @@ extern void insert (const char *, ptrdiff_t);
2894extern void insert_and_inherit (const char *, ptrdiff_t); 2894extern void insert_and_inherit (const char *, ptrdiff_t);
2895extern void insert_1_both (const char *, ptrdiff_t, ptrdiff_t, 2895extern void insert_1_both (const char *, ptrdiff_t, ptrdiff_t,
2896 bool, bool, bool); 2896 bool, bool, bool);
2897extern void insert_from_gap (ptrdiff_t, ptrdiff_t); 2897extern void insert_from_gap (ptrdiff_t, ptrdiff_t, bool text_at_gap_tail);
2898extern void insert_from_string (Lisp_Object, ptrdiff_t, ptrdiff_t, 2898extern void insert_from_string (Lisp_Object, ptrdiff_t, ptrdiff_t,
2899 ptrdiff_t, ptrdiff_t, bool); 2899 ptrdiff_t, ptrdiff_t, bool);
2900extern void insert_from_buffer (struct buffer *, ptrdiff_t, ptrdiff_t, bool); 2900extern void insert_from_buffer (struct buffer *, ptrdiff_t, ptrdiff_t, bool);
@@ -3377,7 +3377,7 @@ extern void record_unwind_save_match_data (void);
3377struct re_registers; 3377struct re_registers;
3378extern struct re_pattern_buffer *compile_pattern (Lisp_Object, 3378extern struct re_pattern_buffer *compile_pattern (Lisp_Object,
3379 struct re_registers *, 3379 struct re_registers *,
3380 Lisp_Object, int, bool); 3380 Lisp_Object, bool, bool);
3381extern ptrdiff_t fast_string_match (Lisp_Object, Lisp_Object); 3381extern ptrdiff_t fast_string_match (Lisp_Object, Lisp_Object);
3382extern ptrdiff_t fast_c_string_match_ignore_case (Lisp_Object, const char *, 3382extern ptrdiff_t fast_c_string_match_ignore_case (Lisp_Object, const char *,
3383 ptrdiff_t); 3383 ptrdiff_t);
diff --git a/src/lread.c b/src/lread.c
index e7af86aa664..f8ab03af218 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -348,11 +348,14 @@ readchar (Lisp_Object readcharfun, bool *multibyte)
348 return STRING_CHAR (buf); 348 return STRING_CHAR (buf);
349} 349}
350 350
351#define FROM_FILE_P(readcharfun) \
352 (EQ (readcharfun, Qget_file_char) \
353 || EQ (readcharfun, Qget_emacs_mule_file_char))
354
351static void 355static void
352skip_dyn_bytes (Lisp_Object readcharfun, ptrdiff_t n) 356skip_dyn_bytes (Lisp_Object readcharfun, ptrdiff_t n)
353{ 357{
354 if (EQ (readcharfun, Qget_file_char) 358 if (FROM_FILE_P (readcharfun))
355 || EQ (readcharfun, Qget_emacs_mule_file_char))
356 { 359 {
357 block_input (); /* FIXME: Not sure if it's needed. */ 360 block_input (); /* FIXME: Not sure if it's needed. */
358 fseek (instream, n, SEEK_CUR); 361 fseek (instream, n, SEEK_CUR);
@@ -423,8 +426,7 @@ unreadchar (Lisp_Object readcharfun, int c)
423 { 426 {
424 unread_char = c; 427 unread_char = c;
425 } 428 }
426 else if (EQ (readcharfun, Qget_file_char) 429 else if (FROM_FILE_P (readcharfun))
427 || EQ (readcharfun, Qget_emacs_mule_file_char))
428 { 430 {
429 unread_char = c; 431 unread_char = c;
430 } 432 }
@@ -2636,8 +2638,7 @@ read1 (Lisp_Object readcharfun, int *pch, bool first_in_list)
2636 UNREAD (c); 2638 UNREAD (c);
2637 2639
2638 if (load_force_doc_strings 2640 if (load_force_doc_strings
2639 && (EQ (readcharfun, Qget_file_char) 2641 && (FROM_FILE_P (readcharfun)))
2640 || EQ (readcharfun, Qget_emacs_mule_file_char)))
2641 { 2642 {
2642 /* If we are supposed to force doc strings into core right now, 2643 /* If we are supposed to force doc strings into core right now,
2643 record the last string that we skipped, 2644 record the last string that we skipped,
@@ -3573,8 +3574,10 @@ read_list (bool flag, Lisp_Object readcharfun)
3573 { 3574 {
3574 if (doc_reference == 1) 3575 if (doc_reference == 1)
3575 return make_number (0); 3576 return make_number (0);
3576 if (doc_reference == 2) 3577 if (doc_reference == 2 && INTEGERP (XCDR (val)))
3577 { 3578 {
3579 char *saved = NULL;
3580 file_offset saved_position;
3578 /* Get a doc string from the file we are loading. 3581 /* Get a doc string from the file we are loading.
3579 If it's in saved_doc_string, get it from there. 3582 If it's in saved_doc_string, get it from there.
3580 3583
@@ -3591,65 +3594,42 @@ read_list (bool flag, Lisp_Object readcharfun)
3591 && pos < (saved_doc_string_position 3594 && pos < (saved_doc_string_position
3592 + saved_doc_string_length)) 3595 + saved_doc_string_length))
3593 { 3596 {
3594 ptrdiff_t start = pos - saved_doc_string_position; 3597 saved = saved_doc_string;
3595 ptrdiff_t from, to; 3598 saved_position = saved_doc_string_position;
3596
3597 /* Process quoting with ^A,
3598 and find the end of the string,
3599 which is marked with ^_ (037). */
3600 for (from = start, to = start;
3601 saved_doc_string[from] != 037;)
3602 {
3603 int c = saved_doc_string[from++];
3604 if (c == 1)
3605 {
3606 c = saved_doc_string[from++];
3607 if (c == 1)
3608 saved_doc_string[to++] = c;
3609 else if (c == '0')
3610 saved_doc_string[to++] = 0;
3611 else if (c == '_')
3612 saved_doc_string[to++] = 037;
3613 }
3614 else
3615 saved_doc_string[to++] = c;
3616 }
3617
3618 return make_unibyte_string (saved_doc_string + start,
3619 to - start);
3620 } 3599 }
3621 /* Look in prev_saved_doc_string the same way. */ 3600 /* Look in prev_saved_doc_string the same way. */
3622 else if (pos >= prev_saved_doc_string_position 3601 else if (pos >= prev_saved_doc_string_position
3623 && pos < (prev_saved_doc_string_position 3602 && pos < (prev_saved_doc_string_position
3624 + prev_saved_doc_string_length)) 3603 + prev_saved_doc_string_length))
3625 { 3604 {
3626 ptrdiff_t start = 3605 saved = prev_saved_doc_string;
3627 pos - prev_saved_doc_string_position; 3606 saved_position = prev_saved_doc_string_position;
3607 }
3608 if (saved)
3609 {
3610 ptrdiff_t start = pos - saved_position;
3628 ptrdiff_t from, to; 3611 ptrdiff_t from, to;
3629 3612
3630 /* Process quoting with ^A, 3613 /* Process quoting with ^A,
3631 and find the end of the string, 3614 and find the end of the string,
3632 which is marked with ^_ (037). */ 3615 which is marked with ^_ (037). */
3633 for (from = start, to = start; 3616 for (from = start, to = start;
3634 prev_saved_doc_string[from] != 037;) 3617 saved[from] != 037;)
3635 { 3618 {
3636 int c = prev_saved_doc_string[from++]; 3619 int c = saved[from++];
3637 if (c == 1) 3620 if (c == 1)
3638 { 3621 {
3639 c = prev_saved_doc_string[from++]; 3622 c = saved[from++];
3640 if (c == 1) 3623 saved[to++] = (c == 1 ? c
3641 prev_saved_doc_string[to++] = c; 3624 : c == '0' ? 0
3642 else if (c == '0') 3625 : c == '_' ? 037
3643 prev_saved_doc_string[to++] = 0; 3626 : c);
3644 else if (c == '_')
3645 prev_saved_doc_string[to++] = 037;
3646 } 3627 }
3647 else 3628 else
3648 prev_saved_doc_string[to++] = c; 3629 saved[to++] = c;
3649 } 3630 }
3650 3631
3651 return make_unibyte_string (prev_saved_doc_string 3632 return make_unibyte_string (saved + start,
3652 + start,
3653 to - start); 3633 to - start);
3654 } 3634 }
3655 else 3635 else
diff --git a/src/nsfns.m b/src/nsfns.m
index e4dde5fb894..ef18acaa045 100644
--- a/src/nsfns.m
+++ b/src/nsfns.m
@@ -261,6 +261,29 @@ ns_display_info_for_name (Lisp_Object name)
261 return dpyinfo; 261 return dpyinfo;
262} 262}
263 263
264static NSString *
265ns_filename_from_panel (NSSavePanel *panel)
266{
267#if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
268 NSURL *url = [panel URL];
269 NSString *str = [url path];
270 return str;
271#else
272 return [panel filename];
273#endif
274}
275
276static NSString *
277ns_directory_from_panel (NSSavePanel *panel)
278{
279#if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
280 NSURL *url = [panel directoryURL];
281 NSString *str = [url path];
282 return str;
283#else
284 return [panel directory];
285#endif
286}
264 287
265static Lisp_Object 288static Lisp_Object
266interpret_services_menu (NSMenu *menu, Lisp_Object prefix, Lisp_Object old) 289interpret_services_menu (NSMenu *menu, Lisp_Object prefix, Lisp_Object old)
@@ -1471,7 +1494,7 @@ Optional arg DIR_ONLY_P, if non-nil, means choose only directories. */)
1471 Lisp_Object init, Lisp_Object dir_only_p) 1494 Lisp_Object init, Lisp_Object dir_only_p)
1472{ 1495{
1473 static id fileDelegate = nil; 1496 static id fileDelegate = nil;
1474 int ret; 1497 BOOL ret;
1475 id panel; 1498 id panel;
1476 Lisp_Object fname; 1499 Lisp_Object fname;
1477 1500
@@ -1508,6 +1531,13 @@ Optional arg DIR_ONLY_P, if non-nil, means choose only directories. */)
1508 [panel setCanChooseDirectories: YES]; 1531 [panel setCanChooseDirectories: YES];
1509 [panel setCanChooseFiles: NO]; 1532 [panel setCanChooseFiles: NO];
1510 } 1533 }
1534 else
1535 {
1536 /* This is not quite what the documentation says, but it is compatible
1537 with the Gtk+ code. Also, the menu entry says "Open File...". */
1538 [panel setCanChooseDirectories: NO];
1539 [panel setCanChooseFiles: YES];
1540 }
1511 1541
1512 block_input (); 1542 block_input ();
1513#if defined (NS_IMPL_COCOA) && \ 1543#if defined (NS_IMPL_COCOA) && \
@@ -1528,15 +1558,19 @@ Optional arg DIR_ONLY_P, if non-nil, means choose only directories. */)
1528 } 1558 }
1529 else 1559 else
1530 { 1560 {
1531 [panel setCanChooseDirectories: YES];
1532 ret = [panel runModalForDirectory: dirS file: initS types: nil]; 1561 ret = [panel runModalForDirectory: dirS file: initS types: nil];
1533 } 1562 }
1534#endif 1563#endif
1535 1564
1536 ret = (ret == NSOKButton) || panelOK; 1565 ret = (ret == NSOKButton) || panelOK;
1537 1566
1538 if (ret) 1567 if (ret)
1539 fname = build_string ([[panel filename] UTF8String]); 1568 {
1569 NSString *str = [panel getFilename];
1570 if (! str) str = [panel getDirectory];
1571 if (! str) ret = NO;
1572 else fname = build_string ([str UTF8String]);
1573 }
1540 1574
1541 [[FRAME_NS_VIEW (SELECTED_FRAME ()) window] makeKeyWindow]; 1575 [[FRAME_NS_VIEW (SELECTED_FRAME ()) window] makeKeyWindow];
1542 unblock_input (); 1576 unblock_input ();
@@ -2603,6 +2637,14 @@ Value is t if tooltip was open, nil otherwise. */)
2603 [NSApp stop: self]; 2637 [NSApp stop: self];
2604} 2638}
2605#endif 2639#endif
2640- (NSString *) getFilename
2641{
2642 return ns_filename_from_panel (self);
2643}
2644- (NSString *) getDirectory
2645{
2646 return ns_directory_from_panel (self);
2647}
2606@end 2648@end
2607 2649
2608 2650
@@ -2616,6 +2658,12 @@ Value is t if tooltip was open, nil otherwise. */)
2616- (void) ok: (id)sender 2658- (void) ok: (id)sender
2617{ 2659{
2618 [super ok: sender]; 2660 [super ok: sender];
2661
2662 // If not choosing directories, and Open is pressed on a directory, return.
2663 if (! [self canChooseDirectories] && [self getDirectory] &&
2664 ! [self getFilename])
2665 return;
2666
2619 panelOK = 1; 2667 panelOK = 1;
2620 [NSApp stop: self]; 2668 [NSApp stop: self];
2621} 2669}
@@ -2624,7 +2672,17 @@ Value is t if tooltip was open, nil otherwise. */)
2624 [super cancel: sender]; 2672 [super cancel: sender];
2625 [NSApp stop: self]; 2673 [NSApp stop: self];
2626} 2674}
2675
2627#endif 2676#endif
2677- (NSString *) getFilename
2678{
2679 return ns_filename_from_panel (self);
2680}
2681- (NSString *) getDirectory
2682{
2683 return ns_directory_from_panel (self);
2684}
2685
2628@end 2686@end
2629 2687
2630 2688
diff --git a/src/nsterm.h b/src/nsterm.h
index 41dbaf3c0f7..6bd04b96684 100644
--- a/src/nsterm.h
+++ b/src/nsterm.h
@@ -267,10 +267,14 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
267@interface EmacsSavePanel : NSSavePanel 267@interface EmacsSavePanel : NSSavePanel
268{ 268{
269} 269}
270- (NSString *) getFilename;
271- (NSString *) getDirectory;
270@end 272@end
271@interface EmacsOpenPanel : NSOpenPanel 273@interface EmacsOpenPanel : NSOpenPanel
272{ 274{
273} 275}
276- (NSString *) getFilename;
277- (NSString *) getDirectory;
274@end 278@end
275 279
276@interface EmacsFileDelegate : NSObject 280@interface EmacsFileDelegate : NSObject
diff --git a/src/nsterm.m b/src/nsterm.m
index 1f09e031592..40e506eab27 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -3601,6 +3601,11 @@ ns_select (int nfds, fd_set *readfds, fd_set *writefds,
3601 result = t; 3601 result = t;
3602 } 3602 }
3603 } 3603 }
3604 else
3605 {
3606 errno = EINTR;
3607 result = -1;
3608 }
3604 3609
3605 return result; 3610 return result;
3606} 3611}
@@ -5448,12 +5453,26 @@ not_in_argv (NSString *arg)
5448 5453
5449 if (oldr != rows || oldc != cols || neww != oldw || newh != oldh) 5454 if (oldr != rows || oldc != cols || neww != oldw || newh != oldh)
5450 { 5455 {
5456 struct frame *f = emacsframe;
5451 NSView *view = FRAME_NS_VIEW (emacsframe); 5457 NSView *view = FRAME_NS_VIEW (emacsframe);
5458 NSWindow *win = [view window];
5459 NSSize sz = [win resizeIncrements];
5460
5452 FRAME_PIXEL_WIDTH (emacsframe) = neww; 5461 FRAME_PIXEL_WIDTH (emacsframe) = neww;
5453 FRAME_PIXEL_HEIGHT (emacsframe) = newh; 5462 FRAME_PIXEL_HEIGHT (emacsframe) = newh;
5454 change_frame_size (emacsframe, rows, cols, 0, delay, 0); 5463 change_frame_size (emacsframe, rows, cols, 0, delay, 0);
5455 SET_FRAME_GARBAGED (emacsframe); 5464 SET_FRAME_GARBAGED (emacsframe);
5456 cancel_mouse_face (emacsframe); 5465 cancel_mouse_face (emacsframe);
5466
5467 // Did resize increments change because of a font change?
5468 if (sz.width != FRAME_COLUMN_WIDTH (emacsframe) ||
5469 sz.height != FRAME_LINE_HEIGHT (emacsframe))
5470 {
5471 sz.width = FRAME_COLUMN_WIDTH (emacsframe);
5472 sz.height = FRAME_LINE_HEIGHT (emacsframe);
5473 [win setResizeIncrements: sz];
5474 }
5475
5457 [view setFrame: NSMakeRect (0, 0, neww, newh)]; 5476 [view setFrame: NSMakeRect (0, 0, neww, newh)];
5458 [self windowDidMove:nil]; // Update top/left. 5477 [self windowDidMove:nil]; // Update top/left.
5459 } 5478 }
diff --git a/src/region-cache.c b/src/region-cache.c
index 14e6982cd9a..be7d50a50e4 100644
--- a/src/region-cache.c
+++ b/src/region-cache.c
@@ -190,10 +190,9 @@ find_cache_boundary (struct region_cache *c, ptrdiff_t pos)
190 } 190 }
191 191
192 /* Some testing. */ 192 /* Some testing. */
193 if (BOUNDARY_POS (c, low) > pos 193 eassert (!(BOUNDARY_POS (c, low) > pos
194 || (low + 1 < c->cache_len 194 || (low + 1 < c->cache_len
195 && BOUNDARY_POS (c, low + 1) <= pos)) 195 && BOUNDARY_POS (c, low + 1) <= pos)));
196 emacs_abort ();
197 196
198 return low; 197 return low;
199} 198}
@@ -214,14 +213,9 @@ move_cache_gap (struct region_cache *c, ptrdiff_t pos, ptrdiff_t min_size)
214 ptrdiff_t buffer_beg = c->buffer_beg; 213 ptrdiff_t buffer_beg = c->buffer_beg;
215 ptrdiff_t buffer_end = c->buffer_end; 214 ptrdiff_t buffer_end = c->buffer_end;
216 215
217 if (pos < 0
218 || pos > c->cache_len)
219 emacs_abort ();
220
221 /* We mustn't ever try to put the gap before the dummy start 216 /* We mustn't ever try to put the gap before the dummy start
222 boundary. That must always be start-relative. */ 217 boundary. That must always be start-relative. */
223 if (pos == 0) 218 eassert (0 < pos && pos <= c->cache_len);
224 emacs_abort ();
225 219
226 /* Need we move the gap right? */ 220 /* Need we move the gap right? */
227 while (gap_start < pos) 221 while (gap_start < pos)
@@ -288,26 +282,19 @@ static void
288insert_cache_boundary (struct region_cache *c, ptrdiff_t i, ptrdiff_t pos, 282insert_cache_boundary (struct region_cache *c, ptrdiff_t i, ptrdiff_t pos,
289 int value) 283 int value)
290{ 284{
291 /* i must be a valid cache index. */ 285 /* I must be a valid cache index, and we must never want
292 if (i < 0 || i > c->cache_len) 286 to insert something before the dummy first boundary. */
293 emacs_abort (); 287 eassert (0 < i && i <= c->cache_len);
294
295 /* We must never want to insert something before the dummy first
296 boundary. */
297 if (i == 0)
298 emacs_abort ();
299 288
300 /* We must only be inserting things in order. */ 289 /* We must only be inserting things in order. */
301 if (! (BOUNDARY_POS (c, i - 1) < pos 290 eassert ((BOUNDARY_POS (c, i - 1) < pos
302 && (i == c->cache_len 291 && (i == c->cache_len
303 || pos < BOUNDARY_POS (c, i)))) 292 || pos < BOUNDARY_POS (c, i))));
304 emacs_abort ();
305 293
306 /* The value must be different from the ones around it. However, we 294 /* The value must be different from the ones around it. However, we
307 temporarily create boundaries that establish the same value as 295 temporarily create boundaries that establish the same value as
308 the subsequent boundary, so we're not going to flag that case. */ 296 the subsequent boundary, so we're not going to flag that case. */
309 if (BOUNDARY_VALUE (c, i - 1) == value) 297 eassert (BOUNDARY_VALUE (c, i - 1) != value);
310 emacs_abort ();
311 298
312 move_cache_gap (c, i, 1); 299 move_cache_gap (c, i, 1);
313 300
@@ -328,18 +315,13 @@ delete_cache_boundaries (struct region_cache *c,
328 ptrdiff_t len = end - start; 315 ptrdiff_t len = end - start;
329 316
330 /* Gotta be in range. */ 317 /* Gotta be in range. */
331 if (start < 0 318 eassert (0 <= start && end <= c->cache_len);
332 || end > c->cache_len)
333 emacs_abort ();
334 319
335 /* Gotta be in order. */ 320 /* Gotta be in order. */
336 if (start > end) 321 eassert (start <= end);
337 emacs_abort ();
338 322
339 /* Can't delete the dummy entry. */ 323 /* Can't delete the dummy entry. */
340 if (start == 0 324 eassert (!(start == 0 && end >= 1));
341 && end >= 1)
342 emacs_abort ();
343 325
344 /* Minimize gap motion. If we're deleting nothing, do nothing. */ 326 /* Minimize gap motion. If we're deleting nothing, do nothing. */
345 if (len == 0) 327 if (len == 0)
@@ -378,11 +360,8 @@ static void
378set_cache_region (struct region_cache *c, 360set_cache_region (struct region_cache *c,
379 ptrdiff_t start, ptrdiff_t end, int value) 361 ptrdiff_t start, ptrdiff_t end, int value)
380{ 362{
381 if (start > end) 363 eassert (start <= end);
382 emacs_abort (); 364 eassert (c->buffer_beg <= start && end <= c->buffer_end);
383 if (start < c->buffer_beg
384 || end > c->buffer_end)
385 emacs_abort ();
386 365
387 /* Eliminate this case; then we can assume that start and end-1 are 366 /* Eliminate this case; then we can assume that start and end-1 are
388 both the locations of real characters in the buffer. */ 367 both the locations of real characters in the buffer. */
@@ -695,8 +674,9 @@ know_region_cache (struct buffer *buf, struct region_cache *c,
695 674
696/* Interface: using the cache. */ 675/* Interface: using the cache. */
697 676
698/* Return true if the text immediately after POS in BUF is known, for 677/* Return the value for the text immediately after POS in BUF if the value
699 the purposes of CACHE. If NEXT is non-zero, set *NEXT to the nearest 678 is known, for the purposes of CACHE, and return zero otherwise.
679 If NEXT is non-zero, set *NEXT to the nearest
700 position after POS where the knowledge changes. */ 680 position after POS where the knowledge changes. */
701int 681int
702region_cache_forward (struct buffer *buf, struct region_cache *c, 682region_cache_forward (struct buffer *buf, struct region_cache *c,
@@ -732,8 +712,9 @@ region_cache_forward (struct buffer *buf, struct region_cache *c,
732 } 712 }
733} 713}
734 714
735/* Return true if the text immediately before POS in BUF is known, for 715/* Return the value for the text immediately before POS in BUF if the
736 the purposes of CACHE. If NEXT is non-zero, set *NEXT to the nearest 716 value is known, for the purposes of CACHE, and return zero
717 otherwise. If NEXT is non-zero, set *NEXT to the nearest
737 position before POS where the knowledge changes. */ 718 position before POS where the knowledge changes. */
738int region_cache_backward (struct buffer *buf, struct region_cache *c, 719int region_cache_backward (struct buffer *buf, struct region_cache *c,
739 ptrdiff_t pos, ptrdiff_t *next) 720 ptrdiff_t pos, ptrdiff_t *next)
@@ -770,7 +751,8 @@ int region_cache_backward (struct buffer *buf, struct region_cache *c,
770 } 751 }
771} 752}
772 753
773 754#ifdef ENABLE_CHECKING
755
774/* Debugging: pretty-print a cache to the standard error output. */ 756/* Debugging: pretty-print a cache to the standard error output. */
775 757
776void pp_cache (struct region_cache *) EXTERNALLY_VISIBLE; 758void pp_cache (struct region_cache *) EXTERNALLY_VISIBLE;
@@ -801,3 +783,5 @@ pp_cache (struct region_cache *c)
801 fprintf (stderr, "%"pD"d : %d\n", pos, BOUNDARY_VALUE (c, i)); 783 fprintf (stderr, "%"pD"d : %d\n", pos, BOUNDARY_VALUE (c, i));
802 } 784 }
803} 785}
786
787#endif /* ENABLE_CHECKING */
diff --git a/src/scroll.c b/src/scroll.c
index 9e11feb64d4..037e338c696 100644
--- a/src/scroll.c
+++ b/src/scroll.c
@@ -246,9 +246,8 @@ do_scrolling (struct frame *frame, struct glyph_matrix *current_matrix,
246 struct matrix_elt *p; 246 struct matrix_elt *p;
247 int i, j, k; 247 int i, j, k;
248 248
249 /* Set to 1 if we have set a terminal window with 249 /* True if we have set a terminal window with set_terminal_window. */
250 set_terminal_window. It's unsigned to work around GCC bug 48228. */ 250 bool terminal_window_p = 0;
251 unsigned int terminal_window_p = 0;
252 251
253 /* A queue for line insertions to be done. */ 252 /* A queue for line insertions to be done. */
254 struct queue { int count, pos; }; 253 struct queue { int count, pos; };
@@ -657,18 +656,16 @@ do_direct_scrolling (struct frame *frame, struct glyph_matrix *current_matrix,
657 alloca (window_size * sizeof *queue_start); 656 alloca (window_size * sizeof *queue_start);
658 struct alt_queue *queue = queue_start; 657 struct alt_queue *queue = queue_start;
659 658
660 /* Set to 1 if a terminal window has been set with 659 /* True if a terminal window has been set with set_terminal_window. */
661 set_terminal_window: */ 660 bool terminal_window_p = 0;
662 int terminal_window_p = 0;
663 661
664 /* A nonzero value of write_follows indicates that a write has been 662 /* If true, a write has been selected, allowing either an insert or a
665 selected, allowing either an insert or a delete to be selected 663 delete to be selected next. If false, a delete cannot be selected
666 next. When write_follows is zero, a delete cannot be selected
667 unless j < i, and an insert cannot be selected unless i < j. 664 unless j < i, and an insert cannot be selected unless i < j.
668 This corresponds to a similar restriction (with the ordering 665 This corresponds to a similar restriction (with the ordering
669 reversed) in calculate_direct_scrolling, which is intended to 666 reversed) in calculate_direct_scrolling, which is intended to
670 ensure that lines marked as inserted will be blank. */ 667 ensure that lines marked as inserted will be blank. */
671 int write_follows_p = 1; 668 bool write_follows_p = 1;
672 669
673 /* For each row in the new matrix what row of the old matrix it is. */ 670 /* For each row in the new matrix what row of the old matrix it is. */
674 int *copy_from = alloca (window_size * sizeof *copy_from); 671 int *copy_from = alloca (window_size * sizeof *copy_from);
diff --git a/src/search.c b/src/search.c
index 32ad6927442..4dd3260b735 100644
--- a/src/search.c
+++ b/src/search.c
@@ -49,8 +49,8 @@ struct regexp_cache
49 Lisp_Object syntax_table; 49 Lisp_Object syntax_table;
50 struct re_pattern_buffer buf; 50 struct re_pattern_buffer buf;
51 char fastmap[0400]; 51 char fastmap[0400];
52 /* Nonzero means regexp was compiled to do full POSIX backtracking. */ 52 /* True means regexp was compiled to do full POSIX backtracking. */
53 char posix; 53 bool posix;
54}; 54};
55 55
56/* The instances of that struct. */ 56/* The instances of that struct. */
@@ -100,7 +100,7 @@ static EMACS_INT boyer_moore (EMACS_INT, unsigned char *, ptrdiff_t,
100 ptrdiff_t, int); 100 ptrdiff_t, int);
101static EMACS_INT search_buffer (Lisp_Object, ptrdiff_t, ptrdiff_t, 101static EMACS_INT search_buffer (Lisp_Object, ptrdiff_t, ptrdiff_t,
102 ptrdiff_t, ptrdiff_t, EMACS_INT, int, 102 ptrdiff_t, ptrdiff_t, EMACS_INT, int,
103 Lisp_Object, Lisp_Object, int); 103 Lisp_Object, Lisp_Object, bool);
104 104
105static _Noreturn void 105static _Noreturn void
106matcher_overflow (void) 106matcher_overflow (void)
@@ -112,13 +112,14 @@ matcher_overflow (void)
112 PATTERN is the pattern to compile. 112 PATTERN is the pattern to compile.
113 CP is the place to put the result. 113 CP is the place to put the result.
114 TRANSLATE is a translation table for ignoring case, or nil for none. 114 TRANSLATE is a translation table for ignoring case, or nil for none.
115 POSIX is nonzero if we want full backtracking (POSIX style) 115 POSIX is true if we want full backtracking (POSIX style) for this pattern.
116 for this pattern. 0 means backtrack only enough to get a valid match. 116 False means backtrack only enough to get a valid match.
117 117
118 The behavior also depends on Vsearch_spaces_regexp. */ 118 The behavior also depends on Vsearch_spaces_regexp. */
119 119
120static void 120static void
121compile_pattern_1 (struct regexp_cache *cp, Lisp_Object pattern, Lisp_Object translate, int posix) 121compile_pattern_1 (struct regexp_cache *cp, Lisp_Object pattern,
122 Lisp_Object translate, bool posix)
122{ 123{
123 char *val; 124 char *val;
124 reg_syntax_t old; 125 reg_syntax_t old;
@@ -205,12 +206,12 @@ clear_regexp_cache (void)
205 values that will result from matching this pattern. 206 values that will result from matching this pattern.
206 If it is 0, we should compile the pattern not to record any 207 If it is 0, we should compile the pattern not to record any
207 subexpression bounds. 208 subexpression bounds.
208 POSIX is nonzero if we want full backtracking (POSIX style) 209 POSIX is true if we want full backtracking (POSIX style) for this pattern.
209 for this pattern. 0 means backtrack only enough to get a valid match. */ 210 False means backtrack only enough to get a valid match. */
210 211
211struct re_pattern_buffer * 212struct re_pattern_buffer *
212compile_pattern (Lisp_Object pattern, struct re_registers *regp, 213compile_pattern (Lisp_Object pattern, struct re_registers *regp,
213 Lisp_Object translate, int posix, bool multibyte) 214 Lisp_Object translate, bool posix, bool multibyte)
214{ 215{
215 struct regexp_cache *cp, **cpp; 216 struct regexp_cache *cp, **cpp;
216 217
@@ -267,7 +268,7 @@ compile_pattern (Lisp_Object pattern, struct re_registers *regp,
267 268
268 269
269static Lisp_Object 270static Lisp_Object
270looking_at_1 (Lisp_Object string, int posix) 271looking_at_1 (Lisp_Object string, bool posix)
271{ 272{
272 Lisp_Object val; 273 Lisp_Object val;
273 unsigned char *p1, *p2; 274 unsigned char *p1, *p2;
@@ -365,7 +366,8 @@ data if you want to preserve them. */)
365} 366}
366 367
367static Lisp_Object 368static Lisp_Object
368string_match_1 (Lisp_Object regexp, Lisp_Object string, Lisp_Object start, int posix) 369string_match_1 (Lisp_Object regexp, Lisp_Object string, Lisp_Object start,
370 bool posix)
369{ 371{
370 ptrdiff_t val; 372 ptrdiff_t val;
371 struct re_pattern_buffer *bufp; 373 struct re_pattern_buffer *bufp;
@@ -975,9 +977,9 @@ find_before_next_newline (ptrdiff_t from, ptrdiff_t to,
975 977
976static Lisp_Object 978static Lisp_Object
977search_command (Lisp_Object string, Lisp_Object bound, Lisp_Object noerror, 979search_command (Lisp_Object string, Lisp_Object bound, Lisp_Object noerror,
978 Lisp_Object count, int direction, int RE, int posix) 980 Lisp_Object count, int direction, int RE, bool posix)
979{ 981{
980 register EMACS_INT np; 982 EMACS_INT np;
981 EMACS_INT lim; 983 EMACS_INT lim;
982 ptrdiff_t lim_byte; 984 ptrdiff_t lim_byte;
983 EMACS_INT n = direction; 985 EMACS_INT n = direction;
@@ -1047,9 +1049,9 @@ search_command (Lisp_Object string, Lisp_Object bound, Lisp_Object noerror,
1047 return make_number (np); 1049 return make_number (np);
1048} 1050}
1049 1051
1050/* Return 1 if REGEXP it matches just one constant string. */ 1052/* Return true if REGEXP it matches just one constant string. */
1051 1053
1052static int 1054static bool
1053trivial_regexp_p (Lisp_Object regexp) 1055trivial_regexp_p (Lisp_Object regexp)
1054{ 1056{
1055 ptrdiff_t len = SBYTES (regexp); 1057 ptrdiff_t len = SBYTES (regexp);
@@ -1118,7 +1120,7 @@ static struct re_registers search_regs_1;
1118static EMACS_INT 1120static EMACS_INT
1119search_buffer (Lisp_Object string, ptrdiff_t pos, ptrdiff_t pos_byte, 1121search_buffer (Lisp_Object string, ptrdiff_t pos, ptrdiff_t pos_byte,
1120 ptrdiff_t lim, ptrdiff_t lim_byte, EMACS_INT n, 1122 ptrdiff_t lim, ptrdiff_t lim_byte, EMACS_INT n,
1121 int RE, Lisp_Object trt, Lisp_Object inverse_trt, int posix) 1123 int RE, Lisp_Object trt, Lisp_Object inverse_trt, bool posix)
1122{ 1124{
1123 ptrdiff_t len = SCHARS (string); 1125 ptrdiff_t len = SCHARS (string);
1124 ptrdiff_t len_byte = SBYTES (string); 1126 ptrdiff_t len_byte = SBYTES (string);
@@ -1273,7 +1275,7 @@ search_buffer (Lisp_Object string, ptrdiff_t pos, ptrdiff_t pos_byte,
1273 /* Set to positive if we find a non-ASCII char that need 1275 /* Set to positive if we find a non-ASCII char that need
1274 translation. Otherwise set to zero later. */ 1276 translation. Otherwise set to zero later. */
1275 int char_base = -1; 1277 int char_base = -1;
1276 int boyer_moore_ok = 1; 1278 bool boyer_moore_ok = 1;
1277 1279
1278 /* MULTIBYTE says whether the text to be searched is multibyte. 1280 /* MULTIBYTE says whether the text to be searched is multibyte.
1279 We must convert PATTERN to match that, or we will not really 1281 We must convert PATTERN to match that, or we will not really
@@ -2282,12 +2284,12 @@ since only regular expressions have distinguished subexpressions. */)
2282 (Lisp_Object newtext, Lisp_Object fixedcase, Lisp_Object literal, Lisp_Object string, Lisp_Object subexp) 2284 (Lisp_Object newtext, Lisp_Object fixedcase, Lisp_Object literal, Lisp_Object string, Lisp_Object subexp)
2283{ 2285{
2284 enum { nochange, all_caps, cap_initial } case_action; 2286 enum { nochange, all_caps, cap_initial } case_action;
2285 register ptrdiff_t pos, pos_byte; 2287 ptrdiff_t pos, pos_byte;
2286 int some_multiletter_word; 2288 bool some_multiletter_word;
2287 int some_lowercase; 2289 bool some_lowercase;
2288 int some_uppercase; 2290 bool some_uppercase;
2289 int some_nonuppercase_initial; 2291 bool some_nonuppercase_initial;
2290 register int c, prevc; 2292 int c, prevc;
2291 ptrdiff_t sub; 2293 ptrdiff_t sub;
2292 ptrdiff_t opoint, newpoint; 2294 ptrdiff_t opoint, newpoint;
2293 2295
@@ -2432,7 +2434,7 @@ since only regular expressions have distinguished subexpressions. */)
2432 { 2434 {
2433 ptrdiff_t substart = -1; 2435 ptrdiff_t substart = -1;
2434 ptrdiff_t subend = 0; 2436 ptrdiff_t subend = 0;
2435 int delbackslash = 0; 2437 bool delbackslash = 0;
2436 2438
2437 FETCH_STRING_CHAR_ADVANCE (c, newtext, pos, pos_byte); 2439 FETCH_STRING_CHAR_ADVANCE (c, newtext, pos, pos_byte);
2438 2440
@@ -2529,7 +2531,7 @@ since only regular expressions have distinguished subexpressions. */)
2529 ptrdiff_t substed_alloc_size, substed_len; 2531 ptrdiff_t substed_alloc_size, substed_len;
2530 bool buf_multibyte = !NILP (BVAR (current_buffer, enable_multibyte_characters)); 2532 bool buf_multibyte = !NILP (BVAR (current_buffer, enable_multibyte_characters));
2531 bool str_multibyte = STRING_MULTIBYTE (newtext); 2533 bool str_multibyte = STRING_MULTIBYTE (newtext);
2532 int really_changed = 0; 2534 bool really_changed = 0;
2533 2535
2534 substed_alloc_size = ((STRING_BYTES_BOUND - 100) / 2 < length 2536 substed_alloc_size = ((STRING_BYTES_BOUND - 100) / 2 < length
2535 ? STRING_BYTES_BOUND 2537 ? STRING_BYTES_BOUND
@@ -2695,7 +2697,7 @@ since only regular expressions have distinguished subexpressions. */)
2695} 2697}
2696 2698
2697static Lisp_Object 2699static Lisp_Object
2698match_limit (Lisp_Object num, int beginningp) 2700match_limit (Lisp_Object num, bool beginningp)
2699{ 2701{
2700 EMACS_INT n; 2702 EMACS_INT n;
2701 2703
@@ -2968,9 +2970,9 @@ If optional arg RESEAT is non-nil, make markers on LIST point nowhere. */)
2968 return Qnil; 2970 return Qnil;
2969} 2971}
2970 2972
2971/* If non-zero the match data have been saved in saved_search_regs 2973/* If true the match data have been saved in saved_search_regs
2972 during the execution of a sentinel or filter. */ 2974 during the execution of a sentinel or filter. */
2973/* static int search_regs_saved; */ 2975/* static bool search_regs_saved; */
2974/* static struct re_registers saved_search_regs; */ 2976/* static struct re_registers saved_search_regs; */
2975/* static Lisp_Object saved_last_thing_searched; */ 2977/* static Lisp_Object saved_last_thing_searched; */
2976 2978
@@ -3035,9 +3037,9 @@ DEFUN ("regexp-quote", Fregexp_quote, Sregexp_quote, 1, 1, 0,
3035 doc: /* Return a regexp string which matches exactly STRING and nothing else. */) 3037 doc: /* Return a regexp string which matches exactly STRING and nothing else. */)
3036 (Lisp_Object string) 3038 (Lisp_Object string)
3037{ 3039{
3038 register char *in, *out, *end; 3040 char *in, *out, *end;
3039 register char *temp; 3041 char *temp;
3040 int backslashes_added = 0; 3042 ptrdiff_t backslashes_added = 0;
3041 3043
3042 CHECK_STRING (string); 3044 CHECK_STRING (string);
3043 3045
diff --git a/src/sysdep.c b/src/sysdep.c
index fe6371623a9..bff11fc9f75 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -38,9 +38,8 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
38#include "sysselect.h" 38#include "sysselect.h"
39#include "blockinput.h" 39#include "blockinput.h"
40 40
41#ifdef BSD_SYSTEM 41#if defined DARWIN_OS || defined __FreeBSD__
42#include <sys/param.h> 42# include <sys/sysctl.h>
43#include <sys/sysctl.h>
44#endif 43#endif
45 44
46#ifdef __FreeBSD__ 45#ifdef __FreeBSD__
@@ -69,9 +68,9 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
69 68
70#ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida, MW Aug 1993 */ 69#ifdef MSDOS /* Demacs 1.1.2 91/10/20 Manabu Higashida, MW Aug 1993 */
71#include "msdos.h" 70#include "msdos.h"
72#include <sys/param.h>
73#endif 71#endif
74 72
73#include <sys/param.h>
75#include <sys/file.h> 74#include <sys/file.h>
76#include <fcntl.h> 75#include <fcntl.h>
77 76
@@ -1290,10 +1289,9 @@ reset_sys_modes (struct tty_display_info *tty_out)
1290 if (tty_out->terminal->reset_terminal_modes_hook) 1289 if (tty_out->terminal->reset_terminal_modes_hook)
1291 tty_out->terminal->reset_terminal_modes_hook (tty_out->terminal); 1290 tty_out->terminal->reset_terminal_modes_hook (tty_out->terminal);
1292 1291
1293#ifdef BSD_SYSTEM
1294 /* Avoid possible loss of output when changing terminal modes. */ 1292 /* Avoid possible loss of output when changing terminal modes. */
1295 fsync (fileno (tty_out->output)); 1293 while (fdatasync (fileno (tty_out->output)) != 0 && errno == EINTR)
1296#endif 1294 continue;
1297 1295
1298#ifndef DOS_NT 1296#ifndef DOS_NT
1299#ifdef F_SETOWN 1297#ifdef F_SETOWN
diff --git a/src/term.c b/src/term.c
index a31fd51084e..38706602a02 100644
--- a/src/term.c
+++ b/src/term.c
@@ -1321,7 +1321,7 @@ term_get_fkeys_1 (void)
1321 if (!KEYMAPP (KVAR (kboard, Vinput_decode_map))) 1321 if (!KEYMAPP (KVAR (kboard, Vinput_decode_map)))
1322 kset_input_decode_map (kboard, Fmake_sparse_keymap (Qnil)); 1322 kset_input_decode_map (kboard, Fmake_sparse_keymap (Qnil));
1323 1323
1324 for (i = 0; i < (sizeof (keys)/sizeof (keys[0])); i++) 1324 for (i = 0; i < (sizeof (keys) / sizeof (keys[0])); i++)
1325 { 1325 {
1326 char *sequence = tgetstr (keys[i].cap, address); 1326 char *sequence = tgetstr (keys[i].cap, address);
1327 if (sequence) 1327 if (sequence)
@@ -3426,9 +3426,6 @@ maybe_fatal (int must_succeed, struct terminal *terminal,
3426 vfatal (str2, ap); 3426 vfatal (str2, ap);
3427 else 3427 else
3428 verror (str1, ap); 3428 verror (str1, ap);
3429
3430 va_end (ap);
3431 emacs_abort ();
3432} 3429}
3433 3430
3434void 3431void
@@ -3437,7 +3434,6 @@ fatal (const char *str, ...)
3437 va_list ap; 3434 va_list ap;
3438 va_start (ap, str); 3435 va_start (ap, str);
3439 vfatal (str, ap); 3436 vfatal (str, ap);
3440 va_end (ap);
3441} 3437}
3442 3438
3443 3439
diff --git a/src/termhooks.h b/src/termhooks.h
index 7385298d3d4..252dbabb6f9 100644
--- a/src/termhooks.h
+++ b/src/termhooks.h
@@ -382,7 +382,7 @@ struct terminal
382 struct image_cache *image_cache; 382 struct image_cache *image_cache;
383#endif /* HAVE_WINDOW_SYSTEM */ 383#endif /* HAVE_WINDOW_SYSTEM */
384 384
385 /* Device-type dependent data shared amongst all frames on this terminal. */ 385 /* Device-type dependent data shared amongst all frames on this terminal. */
386 union display_info 386 union display_info
387 { 387 {
388 struct tty_display_info *tty; /* termchar.h */ 388 struct tty_display_info *tty; /* termchar.h */
@@ -403,22 +403,22 @@ struct terminal
403 the function `set-keyboard-coding-system'. */ 403 the function `set-keyboard-coding-system'. */
404 struct coding_system *keyboard_coding; 404 struct coding_system *keyboard_coding;
405 405
406 /* Terminal characteristics. */ 406 /* Terminal characteristics. */
407 /* XXX Are these really used on non-termcap displays? */ 407 /* XXX Are these really used on non-termcap displays? */
408 408
409 int must_write_spaces; /* Nonzero means spaces in the text must 409 int must_write_spaces; /* Nonzero means spaces in the text must
410 actually be output; can't just skip over 410 actually be output; can't just skip over
411 some columns to leave them blank. */ 411 some columns to leave them blank. */
412 int fast_clear_end_of_line; /* Nonzero means terminal has a `ce' string */ 412 int fast_clear_end_of_line; /* Nonzero means terminal has a `ce' string. */
413 413
414 int line_ins_del_ok; /* Terminal can insert and delete lines */ 414 int line_ins_del_ok; /* Terminal can insert and delete lines. */
415 int char_ins_del_ok; /* Terminal can insert and delete chars */ 415 int char_ins_del_ok; /* Terminal can insert and delete chars. */
416 int scroll_region_ok; /* Terminal supports setting the scroll 416 int scroll_region_ok; /* Terminal supports setting the scroll
417 window */ 417 window. */
418 int scroll_region_cost; /* Cost of setting the scroll window, 418 int scroll_region_cost; /* Cost of setting the scroll window,
419 measured in characters. */ 419 measured in characters. */
420 int memory_below_frame; /* Terminal remembers lines scrolled 420 int memory_below_frame; /* Terminal remembers lines scrolled
421 off bottom */ 421 off bottom. */
422 422
423 /* Window-based redisplay interface for this device (0 for tty 423 /* Window-based redisplay interface for this device (0 for tty
424 devices). */ 424 devices). */
@@ -617,7 +617,7 @@ tset_selection_alist (struct terminal *t, Lisp_Object val)
617 t->Vselection_alist = val; 617 t->Vselection_alist = val;
618} 618}
619 619
620/* Chain of all terminal devices currently in use. */ 620/* Chain of all terminal devices currently in use. */
621extern struct terminal *terminal_list; 621extern struct terminal *terminal_list;
622 622
623#define FRAME_MUST_WRITE_SPACES(f) ((f)->terminal->must_write_spaces) 623#define FRAME_MUST_WRITE_SPACES(f) ((f)->terminal->must_write_spaces)
@@ -638,14 +638,16 @@ extern struct terminal *terminal_list;
638 638
639#define FRAME_TERMINAL(f) ((f)->terminal) 639#define FRAME_TERMINAL(f) ((f)->terminal)
640 640
641/* Return true if the terminal device is not suspended. */ 641/* Return true if the terminal device is not suspended. */
642#define TERMINAL_ACTIVE_P(d) (((d)->type != output_termcap && (d)->type !=output_msdos_raw) || (d)->display_info.tty->input) 642#define TERMINAL_ACTIVE_P(d) \
643 (((d)->type != output_termcap && (d)->type != output_msdos_raw) \
644 || (d)->display_info.tty->input)
643 645
644extern struct terminal *get_terminal (Lisp_Object terminal, int); 646extern struct terminal *get_terminal (Lisp_Object terminal, int);
645extern struct terminal *create_terminal (void); 647extern struct terminal *create_terminal (void);
646extern void delete_terminal (struct terminal *); 648extern void delete_terminal (struct terminal *);
647 649
648/* The initial terminal device, created by initial_term_init. */ 650/* The initial terminal device, created by initial_term_init. */
649extern struct terminal *initial_terminal; 651extern struct terminal *initial_terminal;
650 652
651extern unsigned char *encode_terminal_code (struct glyph *, int, 653extern unsigned char *encode_terminal_code (struct glyph *, int,
diff --git a/src/terminal.c b/src/terminal.c
index 5e1f1ff77f7..c99c39c64ae 100644
--- a/src/terminal.c
+++ b/src/terminal.c
@@ -280,7 +280,7 @@ delete_terminal (struct terminal *terminal)
280 xfree (terminal->name); 280 xfree (terminal->name);
281 terminal->name = NULL; 281 terminal->name = NULL;
282 282
283 /* Check for live frames that are still on this terminal. */ 283 /* Check for live frames that are still on this terminal. */
284 FOR_EACH_FRAME (tail, frame) 284 FOR_EACH_FRAME (tail, frame)
285 { 285 {
286 struct frame *f = XFRAME (frame); 286 struct frame *f = XFRAME (frame);
diff --git a/src/textprop.c b/src/textprop.c
index 18e893b3ef2..2b454485370 100644
--- a/src/textprop.c
+++ b/src/textprop.c
@@ -60,7 +60,7 @@ Lisp_Object Qinvisible, Qintangible, Qmouse_face;
60static Lisp_Object Qread_only; 60static Lisp_Object Qread_only;
61Lisp_Object Qminibuffer_prompt; 61Lisp_Object Qminibuffer_prompt;
62 62
63/* Sticky properties */ 63/* Sticky properties. */
64Lisp_Object Qfront_sticky, Qrear_nonsticky; 64Lisp_Object Qfront_sticky, Qrear_nonsticky;
65 65
66/* If o1 is a cons whose cdr is a cons, return non-zero and set o2 to 66/* If o1 is a cons whose cdr is a cons, return non-zero and set o2 to
diff --git a/src/thread.h b/src/thread.h
index 989acec6afb..97bdb2c805c 100644
--- a/src/thread.h
+++ b/src/thread.h
@@ -1,5 +1,5 @@
1/* Thread definitions 1/* Thread definitions
2 Copyright (C) 2012 Free Software Foundation, Inc. 2 Copyright (C) 2012, 2013 Free Software Foundation, Inc.
3 3
4This file is part of GNU Emacs. 4This file is part of GNU Emacs.
5 5
@@ -138,7 +138,7 @@ struct thread_state
138 138
139 /* If non-zero the match data have been saved in saved_search_regs 139 /* If non-zero the match data have been saved in saved_search_regs
140 during the execution of a sentinel or filter. */ 140 during the execution of a sentinel or filter. */
141 int m_search_regs_saved; 141 bool m_search_regs_saved;
142#define search_regs_saved (current_thread->m_search_regs_saved) 142#define search_regs_saved (current_thread->m_search_regs_saved)
143 143
144 struct re_registers m_saved_search_regs; 144 struct re_registers m_saved_search_regs;
diff --git a/src/w32fns.c b/src/w32fns.c
index 6fd980c6b70..cef2009d7a1 100644
--- a/src/w32fns.c
+++ b/src/w32fns.c
@@ -1721,11 +1721,9 @@ x_set_name (struct frame *f, Lisp_Object name, int explicit)
1721 1721
1722 if (FRAME_W32_WINDOW (f)) 1722 if (FRAME_W32_WINDOW (f))
1723 { 1723 {
1724 if (STRING_MULTIBYTE (name))
1725 name = ENCODE_SYSTEM (name);
1726
1727 block_input (); 1724 block_input ();
1728 SetWindowText (FRAME_W32_WINDOW (f), SDATA (name)); 1725 GUI_FN (SetWindowText) (FRAME_W32_WINDOW (f),
1726 GUI_SDATA (GUI_ENCODE_SYSTEM (name)));
1729 unblock_input (); 1727 unblock_input ();
1730 } 1728 }
1731} 1729}
@@ -1767,11 +1765,9 @@ x_set_title (struct frame *f, Lisp_Object name, Lisp_Object old_name)
1767 1765
1768 if (FRAME_W32_WINDOW (f)) 1766 if (FRAME_W32_WINDOW (f))
1769 { 1767 {
1770 if (STRING_MULTIBYTE (name))
1771 name = ENCODE_SYSTEM (name);
1772
1773 block_input (); 1768 block_input ();
1774 SetWindowText (FRAME_W32_WINDOW (f), SDATA (name)); 1769 GUI_FN (SetWindowText) (FRAME_W32_WINDOW (f),
1770 GUI_SDATA (GUI_ENCODE_SYSTEM (name)));
1775 unblock_input (); 1771 unblock_input ();
1776 } 1772 }
1777} 1773}
@@ -5824,7 +5820,7 @@ Text larger than the specified size is clipped. */)
5824 int row_width; 5820 int row_width;
5825 5821
5826 /* Stop at the first empty row at the end. */ 5822 /* Stop at the first empty row at the end. */
5827 if (!row->enabled_p || !row->displays_text_p) 5823 if (!row->enabled_p || !MATRIX_ROW_DISPLAYS_TEXT_P (row))
5828 break; 5824 break;
5829 5825
5830 /* Let the row go over the full width of the frame. */ 5826 /* Let the row go over the full width of the frame. */
@@ -5885,7 +5881,7 @@ Text larger than the specified size is clipped. */)
5885 struct glyph *last; 5881 struct glyph *last;
5886 int row_width; 5882 int row_width;
5887 5883
5888 if (!row->enabled_p || !row->displays_text_p) 5884 if (!row->enabled_p || !MATRIX_ROW_DISPLAYS_TEXT_P (row))
5889 break; 5885 break;
5890 row->full_width_p = 1; 5886 row->full_width_p = 1;
5891 row_width = row->pixel_width; 5887 row_width = row->pixel_width;
@@ -6006,14 +6002,6 @@ Value is t if tooltip was open, nil otherwise. */)
6006#define FILE_NAME_COMBO_BOX cmb13 6002#define FILE_NAME_COMBO_BOX cmb13
6007#define FILE_NAME_LIST lst1 6003#define FILE_NAME_LIST lst1
6008 6004
6009#ifdef NTGUI_UNICODE
6010#define GUISTR(x) (L ## x)
6011typedef wchar_t guichar_t;
6012#else /* !NTGUI_UNICODE */
6013#define GUISTR(x) x
6014typedef char guichar_t;
6015#endif /* NTGUI_UNICODE */
6016
6017/* Callback for altering the behavior of the Open File dialog. 6005/* Callback for altering the behavior of the Open File dialog.
6018 Makes the Filename text field contain "Current Directory" and be 6006 Makes the Filename text field contain "Current Directory" and be
6019 read-only when "Directories" is selected in the filter. This 6007 read-only when "Directories" is selected in the filter. This
@@ -6230,11 +6218,7 @@ Otherwise, if ONLY-DIR-P is non-nil, the user can only select directories. */)
6230 block_input (); 6218 block_input ();
6231 file_details->lpfnHook = file_dialog_callback; 6219 file_details->lpfnHook = file_dialog_callback;
6232 6220
6233#ifdef NTGUI_UNICODE 6221 file_opened = GUI_FN (GetOpenFileName) (file_details);
6234 file_opened = GetOpenFileNameW (file_details);
6235#else /* !NTGUI_UNICODE */
6236 file_opened = GetOpenFileNameA (file_details);
6237#endif /* NTGUI_UNICODE */
6238 unblock_input (); 6222 unblock_input ();
6239 unbind_to (count, Qnil); 6223 unbind_to (count, Qnil);
6240 } 6224 }
@@ -6243,11 +6227,7 @@ Otherwise, if ONLY-DIR-P is non-nil, the user can only select directories. */)
6243 { 6227 {
6244 /* Get an Emacs string from the value Windows gave us. */ 6228 /* Get an Emacs string from the value Windows gave us. */
6245#ifdef NTGUI_UNICODE 6229#ifdef NTGUI_UNICODE
6246 filename = from_unicode ( 6230 filename = from_unicode_buffer (filename_buf);
6247 make_unibyte_string (
6248 (char*) filename_buf,
6249 /* we get one of the two final 0 bytes for free. */
6250 1 + sizeof (wchar_t) * wcslen (filename_buf)));
6251#else /* !NTGUI_UNICODE */ 6231#else /* !NTGUI_UNICODE */
6252 dostounix_filename (filename_buf, 0); 6232 dostounix_filename (filename_buf, 0);
6253 filename = DECODE_FILE (build_string (filename_buf)); 6233 filename = DECODE_FILE (build_string (filename_buf));
@@ -6421,20 +6401,29 @@ an integer representing a ShowWindow flag:
6421 CHECK_STRING (document); 6401 CHECK_STRING (document);
6422 6402
6423 /* Encode filename, current directory and parameters. */ 6403 /* Encode filename, current directory and parameters. */
6424 current_dir = ENCODE_FILE (BVAR (current_buffer, directory)); 6404 current_dir = BVAR (current_buffer, directory);
6425 document = ENCODE_FILE (document); 6405
6406#ifdef CYGWIN
6407 current_dir = Fcygwin_convert_file_name_to_windows (current_dir, Qt);
6408 if (STRINGP (document))
6409 document = Fcygwin_convert_file_name_to_windows (document, Qt);
6410#endif /* CYGWIN */
6411
6412 current_dir = GUI_ENCODE_FILE (current_dir);
6413 if (STRINGP (document))
6414 document = GUI_ENCODE_FILE (document);
6426 if (STRINGP (parameters)) 6415 if (STRINGP (parameters))
6427 parameters = ENCODE_SYSTEM (parameters); 6416 parameters = GUI_ENCODE_SYSTEM (parameters);
6428 6417
6429 if ((int) ShellExecute (NULL, 6418 if ((int) GUI_FN (ShellExecute) (NULL,
6430 (STRINGP (operation) ? 6419 (STRINGP (operation) ?
6431 SDATA (operation) : NULL), 6420 GUI_SDATA (operation) : NULL),
6432 SDATA (document), 6421 GUI_SDATA (document),
6433 (STRINGP (parameters) ? 6422 (STRINGP (parameters) ?
6434 SDATA (parameters) : NULL), 6423 GUI_SDATA (parameters) : NULL),
6435 SDATA (current_dir), 6424 GUI_SDATA (current_dir),
6436 (INTEGERP (show_flag) ? 6425 (INTEGERP (show_flag) ?
6437 XINT (show_flag) : SW_SHOWDEFAULT)) 6426 XINT (show_flag) : SW_SHOWDEFAULT))
6438 > 32) 6427 > 32)
6439 return Qt; 6428 return Qt;
6440 errstr = w32_strerror (0); 6429 errstr = w32_strerror (0);
@@ -6803,6 +6792,7 @@ The following %-sequences are provided:
6803} 6792}
6804 6793
6805 6794
6795#ifdef WINDOWSNT
6806DEFUN ("file-system-info", Ffile_system_info, Sfile_system_info, 1, 1, 0, 6796DEFUN ("file-system-info", Ffile_system_info, Sfile_system_info, 1, 1, 0,
6807 doc: /* Return storage information about the file system FILENAME is on. 6797 doc: /* Return storage information about the file system FILENAME is on.
6808Value is a list of floats (TOTAL FREE AVAIL), where TOTAL is the total 6798Value is a list of floats (TOTAL FREE AVAIL), where TOTAL is the total
@@ -6898,6 +6888,8 @@ If the underlying system call fails, value is nil. */)
6898 6888
6899 return value; 6889 return value;
6900} 6890}
6891#endif /* WINDOWSNT */
6892
6901 6893
6902DEFUN ("default-printer-name", Fdefault_printer_name, Sdefault_printer_name, 6894DEFUN ("default-printer-name", Fdefault_printer_name, Sdefault_printer_name,
6903 0, 0, 0, doc: /* Return the name of Windows default printer device. */) 6895 0, 0, 0, doc: /* Return the name of Windows default printer device. */)
@@ -7624,7 +7616,10 @@ only be necessary if the default setting causes problems. */);
7624 defsubr (&Sw32_window_exists_p); 7616 defsubr (&Sw32_window_exists_p);
7625 defsubr (&Sw32_battery_status); 7617 defsubr (&Sw32_battery_status);
7626 7618
7619#ifdef WINDOWSNT
7627 defsubr (&Sfile_system_info); 7620 defsubr (&Sfile_system_info);
7621#endif
7622
7628 defsubr (&Sdefault_printer_name); 7623 defsubr (&Sdefault_printer_name);
7629 defsubr (&Sset_message_beep); 7624 defsubr (&Sset_message_beep);
7630 7625
@@ -7805,3 +7800,15 @@ emacs_abort (void)
7805 } 7800 }
7806 } 7801 }
7807} 7802}
7803
7804#ifdef NTGUI_UNICODE
7805
7806Lisp_Object
7807ntgui_encode_system (Lisp_Object str)
7808{
7809 Lisp_Object encoded;
7810 to_unicode (str, &encoded);
7811 return encoded;
7812}
7813
7814#endif /* NTGUI_UNICODE */
diff --git a/src/w32term.c b/src/w32term.c
index 170f33ecd67..989ceb0f847 100644
--- a/src/w32term.c
+++ b/src/w32term.c
@@ -236,6 +236,7 @@ static void my_set_focus (struct frame *, HWND);
236#endif 236#endif
237static void my_set_foreground_window (HWND); 237static void my_set_foreground_window (HWND);
238static void my_destroy_window (struct frame *, HWND); 238static void my_destroy_window (struct frame *, HWND);
239static void w32fullscreen_hook (FRAME_PTR);
239 240
240#ifdef GLYPH_DEBUG 241#ifdef GLYPH_DEBUG
241static void x_check_font (struct frame *, struct font *); 242static void x_check_font (struct frame *, struct font *);
@@ -3161,7 +3162,7 @@ construct_drag_n_drop (struct input_event *result, W32Msg *msg, struct frame *f)
3161 HDROP hdrop; 3162 HDROP hdrop;
3162 POINT p; 3163 POINT p;
3163 WORD num_files; 3164 WORD num_files;
3164 char *name; 3165 guichar_t *name;
3165 int i, len; 3166 int i, len;
3166 3167
3167 result->kind = DRAG_N_DROP_EVENT; 3168 result->kind = DRAG_N_DROP_EVENT;
@@ -3186,12 +3187,17 @@ construct_drag_n_drop (struct input_event *result, W32Msg *msg, struct frame *f)
3186 3187
3187 for (i = 0; i < num_files; i++) 3188 for (i = 0; i < num_files; i++)
3188 { 3189 {
3189 len = DragQueryFile (hdrop, i, NULL, 0); 3190 len = GUI_FN (DragQueryFile) (hdrop, i, NULL, 0);
3190 if (len <= 0) 3191 if (len <= 0)
3191 continue; 3192 continue;
3192 name = alloca (len + 1); 3193
3193 DragQueryFile (hdrop, i, name, len + 1); 3194 name = alloca ((len + 1) * sizeof (*name));
3195 GUI_FN (DragQueryFile) (hdrop, i, name, len + 1);
3196#ifdef NTGUI_UNICODE
3197 files = Fcons (from_unicode_buffer (name), files);
3198#else
3194 files = Fcons (DECODE_FILE (build_string (name)), files); 3199 files = Fcons (DECODE_FILE (build_string (name)), files);
3200#endif /* NTGUI_UNICODE */
3195 } 3201 }
3196 3202
3197 DragFinish (hdrop); 3203 DragFinish (hdrop);
@@ -4699,20 +4705,23 @@ w32_read_socket (struct terminal *terminal,
4699 } 4705 }
4700 4706
4701 case WM_WINDOWPOSCHANGED: 4707 case WM_WINDOWPOSCHANGED:
4702 f = x_window_to_frame (dpyinfo, msg.msg.hwnd);
4703 if (f)
4704 {
4705 if (f->want_fullscreen & FULLSCREEN_WAIT)
4706 f->want_fullscreen &= ~(FULLSCREEN_WAIT|FULLSCREEN_BOTH);
4707 }
4708 check_visibility = 1;
4709 break;
4710
4711 case WM_ACTIVATE: 4708 case WM_ACTIVATE:
4712 case WM_ACTIVATEAPP: 4709 case WM_ACTIVATEAPP:
4713 f = x_window_to_frame (dpyinfo, msg.msg.hwnd); 4710 f = x_window_to_frame (dpyinfo, msg.msg.hwnd);
4714 if (f) 4711 if (f)
4715 x_check_fullscreen (f); 4712 {
4713 /* Run the full-screen hook function also when we are
4714 being activated, to actually install the required
4715 size in effect, if the WAIT flag is set. This is
4716 because when the hook is run from x_set_fullscreen,
4717 the frame might not yet be visible, if that call is a
4718 result of make-frame, and in that case the hook just
4719 sets the WAIT flag. */
4720 if ((msg.msg.message == WM_WINDOWPOSCHANGED || msg.msg.wParam)
4721 && (f->want_fullscreen & FULLSCREEN_WAIT))
4722 w32fullscreen_hook (f);
4723 x_check_fullscreen (f);
4724 }
4716 check_visibility = 1; 4725 check_visibility = 1;
4717 break; 4726 break;
4718 4727
@@ -5673,10 +5682,10 @@ w32fullscreen_hook (FRAME_PTR f)
5673 5682
5674 switch (f->want_fullscreen) 5683 switch (f->want_fullscreen)
5675 { 5684 {
5676 case FULLSCREEN_MAXIMIZED: 5685 case FULLSCREEN_BOTH:
5677 PostMessage (FRAME_W32_WINDOW (f), WM_SYSCOMMAND, SC_MAXIMIZE, 0); 5686 PostMessage (FRAME_W32_WINDOW (f), WM_SYSCOMMAND, SC_MAXIMIZE, 0);
5678 break; 5687 break;
5679 case FULLSCREEN_BOTH: 5688 case FULLSCREEN_MAXIMIZED:
5680 height = 5689 height =
5681 FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, pixel_height) 5690 FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, pixel_height)
5682 - XINT (Ftool_bar_lines_needed (selected_frame)) 5691 - XINT (Ftool_bar_lines_needed (selected_frame))
@@ -5724,8 +5733,11 @@ w32fullscreen_hook (FRAME_PTR f)
5724 x_set_window_size (f, 1, width, height); 5733 x_set_window_size (f, 1, width, height);
5725 do_pending_window_change (0); 5734 do_pending_window_change (0);
5726 } 5735 }
5736 f->want_fullscreen = FULLSCREEN_NONE;
5727 unblock_input (); 5737 unblock_input ();
5728 } 5738 }
5739 else
5740 f->want_fullscreen |= FULLSCREEN_WAIT;
5729} 5741}
5730 5742
5731/* Call this to change the size of frame F's x-window. 5743/* Call this to change the size of frame F's x-window.
diff --git a/src/w32term.h b/src/w32term.h
index 7154d549f21..a31c5de193d 100644
--- a/src/w32term.h
+++ b/src/w32term.h
@@ -761,6 +761,23 @@ extern const char*
761w32_name_of_message (UINT msg); 761w32_name_of_message (UINT msg);
762#endif /* EMACSDEBUG */ 762#endif /* EMACSDEBUG */
763 763
764#ifdef NTGUI_UNICODE
765extern Lisp_Object ntgui_encode_system (Lisp_Object str);
766#define GUISTR(x) (L ## x)
767#define GUI_ENCODE_FILE GUI_ENCODE_SYSTEM
768#define GUI_ENCODE_SYSTEM(x) ntgui_encode_system (x)
769#define GUI_FN(fn) fn ## W
770typedef wchar_t guichar_t;
771#else /* !NTGUI_UNICODE */
772#define GUISTR(x) x
773#define GUI_ENCODE_FILE ENCODE_FILE
774#define GUI_ENCODE_SYSTEM ENCODE_SYSTEM
775#define GUI_FN(fn) fn
776typedef char guichar_t;
777#endif /* NTGUI_UNICODE */
778
779#define GUI_SDATA(x) ((guichar_t*) SDATA (x))
780
764extern void syms_of_w32term (void); 781extern void syms_of_w32term (void);
765extern void syms_of_w32menu (void); 782extern void syms_of_w32menu (void);
766extern void syms_of_w32fns (void); 783extern void syms_of_w32fns (void);
diff --git a/src/window.c b/src/window.c
index 4b30a9d55da..4109b752d8e 100644
--- a/src/window.c
+++ b/src/window.c
@@ -5021,7 +5021,7 @@ specifies the window to scroll. This takes precedence over
5021 ++windows_or_buffers_changed; 5021 ++windows_or_buffers_changed;
5022 5022
5023 Fset_buffer (w->buffer); 5023 Fset_buffer (w->buffer);
5024 SET_PT (marker_position (w->pointm)); 5024 SET_PT_BOTH (marker_position (w->pointm), marker_byte_position (w->pointm));
5025 5025
5026 if (NILP (arg)) 5026 if (NILP (arg))
5027 window_scroll (window, 1, 1, 1); 5027 window_scroll (window, 1, 1, 1);
diff --git a/src/xdisp.c b/src/xdisp.c
index c6e204702ce..a5bba1a81cd 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -2550,7 +2550,7 @@ markpos_of_region (void)
2550 at character position CHARPOS. CHARPOS < 0 means that no buffer 2550 at character position CHARPOS. CHARPOS < 0 means that no buffer
2551 position is specified which is useful when the iterator is assigned 2551 position is specified which is useful when the iterator is assigned
2552 a position later. BYTEPOS is the byte position corresponding to 2552 a position later. BYTEPOS is the byte position corresponding to
2553 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS. 2553 CHARPOS.
2554 2554
2555 If ROW is not null, calls to produce_glyphs with IT as parameter 2555 If ROW is not null, calls to produce_glyphs with IT as parameter
2556 will produce glyphs in that row. 2556 will produce glyphs in that row.
@@ -2828,18 +2828,14 @@ init_iterator (struct it *it, struct window *w,
2828 if (charpos >= BUF_BEG (current_buffer)) 2828 if (charpos >= BUF_BEG (current_buffer))
2829 { 2829 {
2830 it->end_charpos = ZV; 2830 it->end_charpos = ZV;
2831 eassert (charpos == BYTE_TO_CHAR (bytepos));
2831 IT_CHARPOS (*it) = charpos; 2832 IT_CHARPOS (*it) = charpos;
2833 IT_BYTEPOS (*it) = bytepos;
2832 2834
2833 /* We will rely on `reseat' to set this up properly, via 2835 /* We will rely on `reseat' to set this up properly, via
2834 handle_face_prop. */ 2836 handle_face_prop. */
2835 it->face_id = it->base_face_id; 2837 it->face_id = it->base_face_id;
2836 2838
2837 /* Compute byte position if not specified. */
2838 if (bytepos < charpos)
2839 IT_BYTEPOS (*it) = CHAR_TO_BYTE (charpos);
2840 else
2841 IT_BYTEPOS (*it) = bytepos;
2842
2843 it->start = it->current; 2839 it->start = it->current;
2844 /* Do we need to reorder bidirectional text? Not if this is a 2840 /* Do we need to reorder bidirectional text? Not if this is a
2845 unibyte buffer: by definition, none of the single-byte 2841 unibyte buffer: by definition, none of the single-byte
@@ -11711,7 +11707,8 @@ display_tool_bar_line (struct it *it, int height)
11711 no additional border below the possibly empty tool-bar lines. 11707 no additional border below the possibly empty tool-bar lines.
11712 So to make the extra empty lines look "normal", we have to 11708 So to make the extra empty lines look "normal", we have to
11713 use the tool-bar face for the border too. */ 11709 use the tool-bar face for the border too. */
11714 if (!row->displays_text_p && !EQ (Vauto_resize_tool_bars, Qgrow_only)) 11710 if (!MATRIX_ROW_DISPLAYS_TEXT_P (row)
11711 && !EQ (Vauto_resize_tool_bars, Qgrow_only))
11715 it->face_id = DEFAULT_FACE_ID; 11712 it->face_id = DEFAULT_FACE_ID;
11716 11713
11717 extend_face_to_end_of_line (it); 11714 extend_face_to_end_of_line (it);
@@ -11732,7 +11729,7 @@ display_tool_bar_line (struct it *it, int height)
11732 compute_line_metrics (it); 11729 compute_line_metrics (it);
11733 11730
11734 /* If line is empty, make it occupy the rest of the tool-bar. */ 11731 /* If line is empty, make it occupy the rest of the tool-bar. */
11735 if (!row->displays_text_p) 11732 if (!MATRIX_ROW_DISPLAYS_TEXT_P (row))
11736 { 11733 {
11737 row->height = row->phys_height = it->last_visible_y - row->y; 11734 row->height = row->phys_height = it->last_visible_y - row->y;
11738 row->visible_height = row->height; 11735 row->visible_height = row->height;
@@ -11947,13 +11944,13 @@ redisplay_tool_bar (struct frame *f)
11947 /* If there are blank lines at the end, except for a partially 11944 /* If there are blank lines at the end, except for a partially
11948 visible blank line at the end that is smaller than 11945 visible blank line at the end that is smaller than
11949 FRAME_LINE_HEIGHT, change the tool-bar's height. */ 11946 FRAME_LINE_HEIGHT, change the tool-bar's height. */
11950 if (!row->displays_text_p 11947 if (!MATRIX_ROW_DISPLAYS_TEXT_P (row)
11951 && row->height >= FRAME_LINE_HEIGHT (f)) 11948 && row->height >= FRAME_LINE_HEIGHT (f))
11952 change_height_p = 1; 11949 change_height_p = 1;
11953 11950
11954 /* If row displays tool-bar items, but is partially visible, 11951 /* If row displays tool-bar items, but is partially visible,
11955 change the tool-bar's height. */ 11952 change the tool-bar's height. */
11956 if (row->displays_text_p 11953 if (MATRIX_ROW_DISPLAYS_TEXT_P (row)
11957 && MATRIX_ROW_BOTTOM_Y (row) > it.last_visible_y 11954 && MATRIX_ROW_BOTTOM_Y (row) > it.last_visible_y
11958 && MATRIX_ROW_BOTTOM_Y (row) < max_tool_bar_height) 11955 && MATRIX_ROW_BOTTOM_Y (row) < max_tool_bar_height)
11959 change_height_p = 1; 11956 change_height_p = 1;
@@ -13144,7 +13141,7 @@ redisplay_internal (void)
13144 /* If this row displays text now but previously didn't, 13141 /* If this row displays text now but previously didn't,
13145 or vice versa, w->window_end_vpos may have to be 13142 or vice versa, w->window_end_vpos may have to be
13146 adjusted. */ 13143 adjusted. */
13147 if ((it.glyph_row - 1)->displays_text_p) 13144 if (MATRIX_ROW_DISPLAYS_TEXT_P (it.glyph_row - 1))
13148 { 13145 {
13149 if (XFASTINT (w->window_end_vpos) < this_line_vpos) 13146 if (XFASTINT (w->window_end_vpos) < this_line_vpos)
13150 wset_window_end_vpos (w, make_number (this_line_vpos)); 13147 wset_window_end_vpos (w, make_number (this_line_vpos));
@@ -13754,7 +13751,7 @@ set_cursor_from_row (struct window *w, struct glyph_row *row,
13754 /* Skip over glyphs not having an object at the start and the end of 13751 /* Skip over glyphs not having an object at the start and the end of
13755 the row. These are special glyphs like truncation marks on 13752 the row. These are special glyphs like truncation marks on
13756 terminal frames. */ 13753 terminal frames. */
13757 if (row->displays_text_p) 13754 if (MATRIX_ROW_DISPLAYS_TEXT_P (row))
13758 { 13755 {
13759 if (!row->reversed_p) 13756 if (!row->reversed_p)
13760 { 13757 {
@@ -14931,8 +14928,7 @@ try_cursor_movement (Lisp_Object window, struct text_pos startp, int *scroll_ste
14931 we would rather display cursor in the next line. */ 14928 we would rather display cursor in the next line. */
14932 while (MATRIX_ROW_BOTTOM_Y (row) < last_y 14929 while (MATRIX_ROW_BOTTOM_Y (row) < last_y
14933 && MATRIX_ROW_END_CHARPOS (row) == PT 14930 && MATRIX_ROW_END_CHARPOS (row) == PT
14934 && row < w->current_matrix->rows 14931 && row < MATRIX_MODE_LINE_ROW (w->current_matrix)
14935 + w->current_matrix->nrows - 1
14936 && MATRIX_ROW_START_CHARPOS (row+1) == PT 14932 && MATRIX_ROW_START_CHARPOS (row+1) == PT
14937 && !cursor_row_p (row)) 14933 && !cursor_row_p (row))
14938 ++row; 14934 ++row;
@@ -16171,8 +16167,8 @@ try_window (Lisp_Object window, struct text_pos pos, int flags)
16171 wset_window_end_vpos 16167 wset_window_end_vpos
16172 (w, make_number (MATRIX_ROW_VPOS (last_text_row, w->desired_matrix))); 16168 (w, make_number (MATRIX_ROW_VPOS (last_text_row, w->desired_matrix)));
16173 eassert 16169 eassert
16174 (MATRIX_ROW (w->desired_matrix, 16170 (MATRIX_ROW_DISPLAYS_TEXT_P (MATRIX_ROW (w->desired_matrix,
16175 XFASTINT (w->window_end_vpos))->displays_text_p); 16171 XFASTINT (w->window_end_vpos))));
16176 } 16172 }
16177 else 16173 else
16178 { 16174 {
@@ -17581,7 +17577,7 @@ try_window_id (struct window *w)
17581 struct glyph_row *last_row = MATRIX_ROW (current_matrix, last_vpos); 17577 struct glyph_row *last_row = MATRIX_ROW (current_matrix, last_vpos);
17582 17578
17583 /* If last_row is the window end line, it should display text. */ 17579 /* If last_row is the window end line, it should display text. */
17584 eassert (last_row->displays_text_p); 17580 eassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_row));
17585 17581
17586 /* If window end line was partially visible before, begin 17582 /* If window end line was partially visible before, begin
17587 displaying at that line. Otherwise begin displaying with the 17583 displaying at that line. Otherwise begin displaying with the
@@ -17628,7 +17624,7 @@ try_window_id (struct window *w)
17628 matrix. Set row to the last row displaying text in current 17624 matrix. Set row to the last row displaying text in current
17629 matrix starting at first_unchanged_at_end_row, after 17625 matrix starting at first_unchanged_at_end_row, after
17630 scrolling. */ 17626 scrolling. */
17631 eassert (first_unchanged_at_end_row->displays_text_p); 17627 eassert (MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row));
17632 row = find_last_row_displaying_text (w->current_matrix, &it, 17628 row = find_last_row_displaying_text (w->current_matrix, &it,
17633 first_unchanged_at_end_row); 17629 first_unchanged_at_end_row);
17634 eassert (row && MATRIX_ROW_DISPLAYS_TEXT_P (row)); 17630 eassert (row && MATRIX_ROW_DISPLAYS_TEXT_P (row));
@@ -17682,10 +17678,10 @@ try_window_id (struct window *w)
17682 { 17678 {
17683 if (desired_row->enabled_p) 17679 if (desired_row->enabled_p)
17684 { 17680 {
17685 if (desired_row->displays_text_p) 17681 if (MATRIX_ROW_DISPLAYS_TEXT_P (desired_row))
17686 row = desired_row; 17682 row = desired_row;
17687 } 17683 }
17688 else if (current_row->displays_text_p) 17684 else if (MATRIX_ROW_DISPLAYS_TEXT_P (current_row))
17689 row = current_row; 17685 row = current_row;
17690 } 17686 }
17691 17687
@@ -17865,7 +17861,7 @@ dump_glyph_row (struct glyph_row *row, int vpos, int glyphs)
17865 row->truncated_on_right_p, 17861 row->truncated_on_right_p,
17866 row->continued_p, 17862 row->continued_p,
17867 MATRIX_ROW_CONTINUATION_LINE_P (row), 17863 MATRIX_ROW_CONTINUATION_LINE_P (row),
17868 row->displays_text_p, 17864 MATRIX_ROW_DISPLAYS_TEXT_P (row),
17869 row->ends_at_zv_p, 17865 row->ends_at_zv_p,
17870 row->fill_line_p, 17866 row->fill_line_p,
17871 row->ends_in_middle_of_char_p, 17867 row->ends_in_middle_of_char_p,
@@ -18501,7 +18497,7 @@ extend_face_to_end_of_line (struct it *it)
18501 face = FACE_FROM_ID (f, it->face_id); 18497 face = FACE_FROM_ID (f, it->face_id);
18502 18498
18503 if (FRAME_WINDOW_P (f) 18499 if (FRAME_WINDOW_P (f)
18504 && it->glyph_row->displays_text_p 18500 && MATRIX_ROW_DISPLAYS_TEXT_P (it->glyph_row)
18505 && face->box == FACE_NO_BOX 18501 && face->box == FACE_NO_BOX
18506 && face->background == FRAME_BACKGROUND_PIXEL (f) 18502 && face->background == FRAME_BACKGROUND_PIXEL (f)
18507 && !face->stipple 18503 && !face->stipple
@@ -19761,7 +19757,7 @@ display_line (struct it *it)
19761 mark this glyph row as the one containing the overlay arrow. 19757 mark this glyph row as the one containing the overlay arrow.
19762 This is clearly a mess with variable size fonts. It would be 19758 This is clearly a mess with variable size fonts. It would be
19763 better to let it be displayed like cursors under X. */ 19759 better to let it be displayed like cursors under X. */
19764 if ((row->displays_text_p || !overlay_arrow_seen) 19760 if ((MATRIX_ROW_DISPLAYS_TEXT_P (row) || !overlay_arrow_seen)
19765 && (overlay_arrow_string = overlay_arrow_at_row (it, row), 19761 && (overlay_arrow_string = overlay_arrow_at_row (it, row),
19766 !NILP (overlay_arrow_string))) 19762 !NILP (overlay_arrow_string)))
19767 { 19763 {
@@ -19861,7 +19857,7 @@ display_line (struct it *it)
19861 if (it->glyph_row < MATRIX_BOTTOM_TEXT_ROW (it->w->desired_matrix, it->w)) 19857 if (it->glyph_row < MATRIX_BOTTOM_TEXT_ROW (it->w->desired_matrix, it->w))
19862 it->glyph_row->reversed_p = row->reversed_p; 19858 it->glyph_row->reversed_p = row->reversed_p;
19863 it->start = row->end; 19859 it->start = row->end;
19864 return row->displays_text_p; 19860 return MATRIX_ROW_DISPLAYS_TEXT_P (row);
19865 19861
19866#undef RECORD_MAX_MIN_POS 19862#undef RECORD_MAX_MIN_POS
19867} 19863}
@@ -25660,7 +25656,7 @@ notice_overwritten_cursor (struct window *w, enum glyph_row_area area,
25660 if (w->phys_cursor.vpos < 0 25656 if (w->phys_cursor.vpos < 0
25661 || w->phys_cursor.vpos >= w->current_matrix->nrows 25657 || w->phys_cursor.vpos >= w->current_matrix->nrows
25662 || (row = w->current_matrix->rows + w->phys_cursor.vpos, 25658 || (row = w->current_matrix->rows + w->phys_cursor.vpos,
25663 !(row->enabled_p && row->displays_text_p))) 25659 !(row->enabled_p && MATRIX_ROW_DISPLAYS_TEXT_P (row))))
25664 return; 25660 return;
25665 25661
25666 if (row->cursor_in_fringe_p) 25662 if (row->cursor_in_fringe_p)
@@ -26595,7 +26591,7 @@ mouse_face_from_buffer_pos (Lisp_Object window,
26595 x = r1->x; 26591 x = r1->x;
26596 26592
26597 /* Skip truncation glyphs at the start of the glyph row. */ 26593 /* Skip truncation glyphs at the start of the glyph row. */
26598 if (r1->displays_text_p) 26594 if (MATRIX_ROW_DISPLAYS_TEXT_P (r1))
26599 for (; glyph < end 26595 for (; glyph < end
26600 && INTEGERP (glyph->object) 26596 && INTEGERP (glyph->object)
26601 && glyph->charpos < 0; 26597 && glyph->charpos < 0;
@@ -26646,7 +26642,7 @@ mouse_face_from_buffer_pos (Lisp_Object window,
26646 glyph = end + r1->used[TEXT_AREA]; 26642 glyph = end + r1->used[TEXT_AREA];
26647 26643
26648 /* Skip truncation glyphs at the start of the glyph row. */ 26644 /* Skip truncation glyphs at the start of the glyph row. */
26649 if (r1->displays_text_p) 26645 if (MATRIX_ROW_DISPLAYS_TEXT_P (r1))
26650 for (; glyph > end 26646 for (; glyph > end
26651 && INTEGERP (glyph->object) 26647 && INTEGERP (glyph->object)
26652 && glyph->charpos < 0; 26648 && glyph->charpos < 0;
@@ -26897,7 +26893,7 @@ fast_find_string_pos (struct window *w, ptrdiff_t pos, Lisp_Object object,
26897 } 26893 }
26898 26894
26899 *y = best_row->y; 26895 *y = best_row->y;
26900 *vpos = best_row - w->current_matrix->rows; 26896 *vpos = MATRIX_ROW_VPOS (best_row, w->current_matrix);
26901 } 26897 }
26902 26898
26903 return best_glyph != NULL; 26899 return best_glyph != NULL;
@@ -26935,7 +26931,8 @@ mouse_face_from_string_pos (struct window *w, Mouse_HLInfo *hlinfo,
26935 if (EQ (g->object, object) 26931 if (EQ (g->object, object)
26936 && startpos <= g->charpos && g->charpos <= endpos) 26932 && startpos <= g->charpos && g->charpos <= endpos)
26937 { 26933 {
26938 hlinfo->mouse_face_beg_row = r - w->current_matrix->rows; 26934 hlinfo->mouse_face_beg_row
26935 = MATRIX_ROW_VPOS (r, w->current_matrix);
26939 hlinfo->mouse_face_beg_y = r->y; 26936 hlinfo->mouse_face_beg_y = r->y;
26940 hlinfo->mouse_face_beg_col = g - r->glyphs[TEXT_AREA]; 26937 hlinfo->mouse_face_beg_col = g - r->glyphs[TEXT_AREA];
26941 hlinfo->mouse_face_beg_x = gx; 26938 hlinfo->mouse_face_beg_x = gx;
@@ -26953,7 +26950,8 @@ mouse_face_from_string_pos (struct window *w, Mouse_HLInfo *hlinfo,
26953 if (EQ ((g-1)->object, object) 26950 if (EQ ((g-1)->object, object)
26954 && startpos <= (g-1)->charpos && (g-1)->charpos <= endpos) 26951 && startpos <= (g-1)->charpos && (g-1)->charpos <= endpos)
26955 { 26952 {
26956 hlinfo->mouse_face_beg_row = r - w->current_matrix->rows; 26953 hlinfo->mouse_face_beg_row
26954 = MATRIX_ROW_VPOS (r, w->current_matrix);
26957 hlinfo->mouse_face_beg_y = r->y; 26955 hlinfo->mouse_face_beg_y = r->y;
26958 hlinfo->mouse_face_beg_col = g - r->glyphs[TEXT_AREA]; 26956 hlinfo->mouse_face_beg_col = g - r->glyphs[TEXT_AREA];
26959 for (gx = r->x, g1 = r->glyphs[TEXT_AREA]; g1 < g; ++g1) 26957 for (gx = r->x, g1 = r->glyphs[TEXT_AREA]; g1 < g; ++g1)
@@ -26992,7 +26990,7 @@ mouse_face_from_string_pos (struct window *w, Mouse_HLInfo *hlinfo,
26992 r--; 26990 r--;
26993 26991
26994 /* Set the end row and its vertical pixel coordinate. */ 26992 /* Set the end row and its vertical pixel coordinate. */
26995 hlinfo->mouse_face_end_row = r - w->current_matrix->rows; 26993 hlinfo->mouse_face_end_row = MATRIX_ROW_VPOS (r, w->current_matrix);
26996 hlinfo->mouse_face_end_y = r->y; 26994 hlinfo->mouse_face_end_y = r->y;
26997 26995
26998 /* Compute and set the end column and the end column's horizontal 26996 /* Compute and set the end column and the end column's horizontal
@@ -27676,7 +27674,7 @@ note_mouse_highlight (struct frame *f, int x, int y)
27676 /* Clear mouse face if X/Y not over text. */ 27674 /* Clear mouse face if X/Y not over text. */
27677 if (glyph == NULL 27675 if (glyph == NULL
27678 || area != TEXT_AREA 27676 || area != TEXT_AREA
27679 || !MATRIX_ROW (w->current_matrix, vpos)->displays_text_p 27677 || !MATRIX_ROW_DISPLAYS_TEXT_P (MATRIX_ROW (w->current_matrix, vpos))
27680 /* Glyph's OBJECT is an integer for glyphs inserted by the 27678 /* Glyph's OBJECT is an integer for glyphs inserted by the
27681 display engine for its internal purposes, like truncation 27679 display engine for its internal purposes, like truncation
27682 and continuation glyphs and blanks beyond the end of 27680 and continuation glyphs and blanks beyond the end of
@@ -27688,7 +27686,7 @@ note_mouse_highlight (struct frame *f, int x, int y)
27688 all beyond the end of text. Treat such stretch glyphs 27686 all beyond the end of text. Treat such stretch glyphs
27689 like we do with NULL glyphs in L2R rows. */ 27687 like we do with NULL glyphs in L2R rows. */
27690 || (MATRIX_ROW (w->current_matrix, vpos)->reversed_p 27688 || (MATRIX_ROW (w->current_matrix, vpos)->reversed_p
27691 && glyph == MATRIX_ROW (w->current_matrix, vpos)->glyphs[TEXT_AREA] 27689 && glyph == MATRIX_ROW_GLYPH_START (w->current_matrix, vpos)
27692 && glyph->type == STRETCH_GLYPH 27690 && glyph->type == STRETCH_GLYPH
27693 && glyph->avoid_cursor_p)) 27691 && glyph->avoid_cursor_p))
27694 { 27692 {
diff --git a/src/xfns.c b/src/xfns.c
index 5c93b8ef4da..100fd81a155 100644
--- a/src/xfns.c
+++ b/src/xfns.c
@@ -3769,7 +3769,6 @@ If omitted or nil, that stands for the selected frame's display. */)
3769 3769
3770 default: 3770 default:
3771 error ("Strange value for BackingStore parameter of screen"); 3771 error ("Strange value for BackingStore parameter of screen");
3772 result = Qnil;
3773 } 3772 }
3774 3773
3775 return result; 3774 return result;
@@ -3811,7 +3810,6 @@ If omitted or nil, that stands for the selected frame's display. */)
3811 break; 3810 break;
3812 default: 3811 default:
3813 error ("Display has an unknown visual class"); 3812 error ("Display has an unknown visual class");
3814 result = Qnil;
3815 } 3813 }
3816 3814
3817 return result; 3815 return result;
@@ -5067,7 +5065,7 @@ Text larger than the specified size is clipped. */)
5067 int row_width; 5065 int row_width;
5068 5066
5069 /* Stop at the first empty row at the end. */ 5067 /* Stop at the first empty row at the end. */
5070 if (!row->enabled_p || !row->displays_text_p) 5068 if (!row->enabled_p || !MATRIX_ROW_DISPLAYS_TEXT_P (row))
5071 break; 5069 break;
5072 5070
5073 /* Let the row go over the full width of the frame. */ 5071 /* Let the row go over the full width of the frame. */
@@ -5126,7 +5124,7 @@ Text larger than the specified size is clipped. */)
5126 struct glyph *last; 5124 struct glyph *last;
5127 int row_width; 5125 int row_width;
5128 5126
5129 if (!row->enabled_p || !row->displays_text_p) 5127 if (!row->enabled_p || !MATRIX_ROW_DISPLAYS_TEXT_P (row))
5130 break; 5128 break;
5131 row->full_width_p = 1; 5129 row->full_width_p = 1;
5132 row_width = row->pixel_width; 5130 row_width = row->pixel_width;
diff --git a/src/xsmfns.c b/src/xsmfns.c
index fe2dfbaf83e..cb7122202df 100644
--- a/src/xsmfns.c
+++ b/src/xsmfns.c
@@ -514,9 +514,11 @@ Do not call this function yourself. */)
514 prevent. Fix this in next version. */ 514 prevent. Fix this in next version. */
515 Fkill_emacs (Qnil); 515 Fkill_emacs (Qnil);
516 516
517#if 0
517 /* This will not be reached, but we want kill-emacs-hook to be run. */ 518 /* This will not be reached, but we want kill-emacs-hook to be run. */
518 SmcCloseConnection (smc_conn, 0, 0); 519 SmcCloseConnection (smc_conn, 0, 0);
519 ice_connection_closed (); 520 ice_connection_closed ();
521#endif
520 } 522 }
521 523
522 return Qnil; 524 return Qnil;