aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMiles Bader2005-05-05 00:04:55 +0000
committerMiles Bader2005-05-05 00:04:55 +0000
commitcca4e3b099ec4c3f4a36fd0cb865c618a5589069 (patch)
tree711e73e53dbe1ab3a59b53fb56a10836e777b43e /src
parentd469f5c370dbb6fac0e8d6687b47ccfcf96a13a5 (diff)
parentd68a5392cafedbe0ee6c3eca0444fce4a58b6cdf (diff)
downloademacs-cca4e3b099ec4c3f4a36fd0cb865c618a5589069.tar.gz
emacs-cca4e3b099ec4c3f4a36fd0cb865c618a5589069.zip
Revision: miles@gnu.org--gnu-2005/emacs--unicode--0--patch-44
Merge from emacs--cvs-trunk--0 Patches applied: * emacs--cvs-trunk--0 (patch 272-288) - src/xdisp.c (dump_glyph_row): Don't display overlay_arrow_p field. - Update from CVS - Merge from gnus--rel--5.10 * gnus--rel--5.10 (patch 67) - Update from CVS
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog244
-rw-r--r--src/ChangeLog.unicode5
-rw-r--r--src/Makefile.in7
-rw-r--r--src/buffer.c6
-rw-r--r--src/buffer.h5
-rw-r--r--src/character.c20
-rw-r--r--src/commands.h4
-rw-r--r--src/data.c1
-rw-r--r--src/dispnew.c2
-rw-r--r--src/emacs.c15
-rw-r--r--src/eval.c9
-rw-r--r--src/fileio.c52
-rw-r--r--src/fns.c28
-rw-r--r--src/frame.c4
-rw-r--r--src/keyboard.c48
-rw-r--r--src/lisp.h2
-rw-r--r--src/m/macppc.h13
-rw-r--r--src/mac.c412
-rw-r--r--src/macfns.c7
-rw-r--r--src/macgui.h4
-rw-r--r--src/macros.c52
-rw-r--r--src/macros.h8
-rw-r--r--src/macselect.c1121
-rw-r--r--src/macterm.c345
-rw-r--r--src/macterm.h4
-rw-r--r--src/sysdep.c10
-rw-r--r--src/sysselect.h2
-rw-r--r--src/window.c35
-rw-r--r--src/xdisp.c67
-rw-r--r--src/xfaces.c48
-rw-r--r--src/xmenu.c16
31 files changed, 2084 insertions, 512 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 7ace79442e9..6d9c1da92d5 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,245 @@
12005-05-03 Jan Dj,Ad(Brv <jan.h.d@swipnet.se>
2
3 * mac.c: #undef init_process so not to conflict with system headers.
4
52005-05-02 Richard M. Stallman <rms@gnu.org>
6
7 * buffer.c (syms_of_buffer): Define cursor-in-non-selected-windows.
8
9 * buffer.h (struct buffer): Add cursor_in_non_selected_windows slot.
10
11 * xdisp.c (Vcursor_in_non_selected_windows)
12 (Qcursor_in_non_selected_windows): Vars deleted.
13 (syms_of_xdisp): Don't initialize them.
14 (get_window_cursor_type): Use cursor_in_non_selected_windows
15 buffer slot.
16
172005-05-02 Kim F. Storm <storm@cua.dk>
18
19 * macros.c (executing_kbd_macro_index): Rename from
20 executing_macro_index. All uses changed.
21 (executing_kbd_macro_iterations): Rename from
22 executing_macro_iterations. All uses changed.
23 (executing_kbd_macro): Rename from executing_macro.
24 All uses changed.
25 (syms_of_macros): Rename Lisp var executing-macro-index to
26 executing-kbd-macro-index.
27
28 * xdisp.c (move_it_in_display_line_to): Fix last change.
29
302005-05-01 Luc Teirlinck <teirllm@auburn.edu>
31
32 * xmenu.c (Fx_popup_menu): Doc fix.
33
34 * charset.c (syms_of_charset): Delete defsubr for Schars_in_region.
35
362005-05-02 Jason Rumney <jasonr@gnu.org>
37
38 * emacs.c (USAGE3, USAGE4): Keep strings below 2048 bytes.
39
402005-05-02 Nozomu Ando <nand@mac.com>
41
42 * sysselect.h: Fix typo.
43
442005-05-02 Nick Roberts <nickrob@snap.net.nz>
45
46 * charset.c (Fchars_in_region): Remove as obsolete.
47
482005-05-01 Kim F. Storm <storm@cua.dk>
49
50 * xdisp.c (move_it_in_display_line_to): Stop if we move beyond
51 TO_CHARPOS. This may happen if last glyphs was an image or stretch
52 glyph.
53
542005-05-01 Luc Teirlinck <teirllm@auburn.edu>
55
56 * dispnew.c (sit_for): Vexecuting_macro -> Vexecuting_kbd_macro.
57
582005-05-01 Richard M. Stallman <rms@gnu.org>
59
60 * xmenu.c [not HAVE_X_TOOLKIT] (xmenu_show):
61 If user cancels the menu, quit unless FOR_CLICK.
62
63 * macros.c (Vexecuting_kbd_macro): Renamed from Vexecuting_macro.
64 All uses changed.
65 (syms_of_macros): Define only executing-kbd-macro, not executing-macro.
66 * keyboard.c: Change Vexecuting_macro to Vexecuting_kbd_macro.
67 * macros.h (Vexecuting_kbd_macro): Declare instead of Vexecuting_macro.
68 * commands.h (Vexecuting_kbd_macro): Likewise.
69
702005-05-01 Thien-Thi Nguyen <ttn@gnu.org>
71
72 * sysdep.c (get_frame_size) [VMS]: Use a fresh i/o channel.
73
742005-04-30 Richard M. Stallman <rms@gnu.org>
75
76 * fileio.c (Ffind_file_name_handler): Handle the `operations'
77 property of the file name handler.
78 (Qoperations): New variable.
79 (syms_of_fileio): Initialize and staticpro it.
80
81 * xdisp.c (set_message_1): Delete xassert.
82
832005-04-29 YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
84
85 * mac.c: Don't include time.h. Include sysselect.h after
86 systime.h.
87
88 * macfns.c (Fx_server_version): Add BLOCK_INPUT around Gestalt.
89
90 * macgui.h [HAVE_CARBON && MAC_OSX]: Don't undefine/define mktime
91 before/after including Carbon.h if there is a working mktime.
92
932005-04-28 Kim F. Storm <storm@cua.dk>
94
95 * xfaces.c (resolve_face_name): Add arg SIGNAL_P. Calls changed.
96 Fix cyclic alias check. If alias loop is detected, signal
97 circular-list error if SIGNAL_P, and return Qdefault if !SIGNAL_P.
98
992005-04-28 Lute Kamstra <lute@gnu.org>
100
101 * eval.c (do_autoload): Record only autoloads in the autoload
102 property of symbols.
103
1042005-04-28 Nick Roberts <nickrob@snap.net.nz>
105
106 * emacs.c (USAGE1): Add --basic-display and --quick options.
107
1082005-04-27 Kim F. Storm <storm@cua.dk>
109
110 * data.c (syms_of_data) Staticpro Qcyclic_variable_indirection.
111
1122005-04-26 Richard M. Stallman <rms@gnu.org>
113
114 * window.c (Fsame_window_p, Fspecial_display_p): Doc fixes.
115 (syms_of_window): Doc fixes.
116
117 * indent.c (Fvertical_motion): Undo previous change.
118
1192005-04-26 Kenichi Handa <handa@m17n.org>
120
121 * fns.c (char_table_range): New function.
122 (Fchar_table_range): Signal an error if characters in the range
123 have inconsistent values. Don't check the parent.
124
1252005-04-25 Kenichi Handa <handa@m17n.org>
126
127 * fontset.c (fontset_set): Fix previous change.
128
1292005-04-24 Richard M. Stallman <rms@gnu.org>
130
131 * indent.c (Fvertical_motion): Bind fontification-functions to nil.
132
1332005-04-24 Eli Zaretskii <eliz@gnu.org>
134
135 * regex.c (re_search_2, re_match_2_internal): Convert second arg
136 of RE_TRANSLATE to int, to shut up GCC warnings.
137
138 * fileio.c (Fcopy_file): Doc fix.
139 [MSDOS]: Fix call to emacs_open: buffer_file_type not defined and
140 not needed.
141
1422005-04-24 YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
143
144 * Makefile.in [HAVE_CARBON] (MAC_OBJ): Add macselect.o.
145 (SOME_MACHINE_OBJECTS): Likewise.
146 (mac.o): Depend on ccl.h.
147 (macselect.o): New target.
148
149 * emacs.c (main) [MAC_OS8 || MAC_OSX && HAVE_CARBON]: Call
150 syms_of_macselect.
151
152 * frame.c (Fdelete_frame) [MAC_OS]: Call x_clear_frame_selections.
153
154 * mac.c [!TARGET_API_MAC_CARBON]: Don't include charset.h or
155 coding.h.
156 (QCLIPBOARD): Remove variable.
157 (syms_of_mac): Don't initialize it.
158 (Fmac_paste_function, Fmac_cut_function, Fx_selection_exists_p):
159 Remove functions.
160 (syms_of_mac): Don't defsubr them.
161 [TARGET_API_MAC_CARBON] (Qmime_charset, QNFD, QNFKD, QNFC, QNFKC)
162 (QHFS_plus_D, QHFS_plus_C): New variables.
163 (syms_of_mac) [TARGET_API_MAC_CARBON]: Initialize them.
164 [TARGET_API_MAC_CARBON] (get_cfstring_encoding_from_lisp)
165 (cfstring_create_normalized): New functions.
166 [TARGET_API_MAC_CARBON] (Fmac_code_convert_string): Likewise.
167 (syms_of_mac) [TARGET_API_MAC_CARBON]: Defsubr it.
168
169 * macterm.c (handling_window_update, terminate_flag): Remove
170 variables.
171 (do_window_update, do_ae_quit_application, XTread_socket): Don't
172 use them.
173 (WNE_SLEEP_AT_SUSPEND, WNE_SLEEP_AT_RESUME): Don't define.
174 [USE_CARBON_EVENTS && MAC_OSX] (mac_handle_service_event)
175 (init_service_handler): Move to macselect.c. Remove declarations.
176 [USE_CARBON_EVENTS && MAC_OSX] (init_service_handler): Add extern.
177 (Qapplication, Qabout): New variables.
178 (syms_of_mac): Initialize them.
179 [USE_CARBON_EVENTS && MAC_OSX] (Qpreferences, Qservices, Qpaste)
180 (Qperform): New variables.
181 (syms_of_mac) [USE_CARBON_EVENTS && MAC_OSX]: Initialize them.
182 (do_get_menus) [TARGET_API_MAC_CARBON]: Don't call AppendResMenu.
183 (do_menu_choice): Unhighlight menu bar also when menu_id is 0.
184 (mac_store_application_menu_event, init_menu_bar): New functions.
185 [USE_CARBON_EVENTS] (mac_handle_command_event)
186 (init_command_handler): New functions.
187 (mac_handle_window_event): Return noErr on window update event.
188 (do_ae_quit_application): Call mac_store_application_menu_event.
189 (mac_initialize) [USE_CARBON_EVENTS]: Call init_command_handler
190 and init_menu_bar.
191
192 * macterm.h (x_clear_frame_selections): Add extern.
193
194 * macselect.c: New file for selection processing on Mac OS.
195
1962005-04-23 Richard M. Stallman <rms@gnu.org>
197
198 * fileio.c (Fcopy_file): New arg MUSTBENEW.
199 (Frename_file): Pass new arg to Fcopy_file.
200
201 * window.c (window_size_fixed): Variable deleted.
202 (syms_of_window): Initialize window-size-fixed to nil.
203 But don't DEFVAR window_size_fixed.
204
2052005-04-23 Andreas Schwab <schwab@suse.de>
206
207 * m/macppc.h (LD_SWITCH_MACHINE) [LINUX]: Don't define.
208 (START_FILES, LIB_STANDARD) [LINUX && _ARCH_PPC64]: Override to
209 use lib64 instead of lib.
210 (_LP64) [_ARCH_PPC64]: Define if not defined.
211
2122005-04-23 David Hunter <hunterd42@comcast.net> (tiny change)
213
214 * s/ms-w32.h (HAVE_PWD_H): Define.
215
2162005-04-22 Kenichi Handa <handa@m17n.org>
217
218 * fns.c (copy_sub_char_table): Explicitly copy the default value
219 of the sub-chartable.
220
221 * fontset.c (fontset_set): When a sub-chartable is created,
222 explicitly sets the defalt value.
223
2242005-04-22 Kim F. Storm <storm@cua.dk>
225
226 * fns.c (Fplist_get): Replace by Fsafe_plist_get.
227 (Fsafe_plist_get): Rename to Fplist_get.
228 (Fsafe_get): Remove, as Fget now uses safe Fplist_get.
229 (defsubr): Remove defsubr for Fsafe_plist_get and Fsafe_get.
230
231 * lisp.h (Fsafe_plist_get, Fsafe_get): Remove EXFUN.
232
233 * xdisp.c (store_mode_line_string, produce_stretch_glyph)
234 (note_mode_line_or_margin_highlight, note_mouse_highlight):
235 Use Fplist_get instead of Fsafe_plist_get.
236
237 * xfaces.c (resolve_face_name): Use Fget instead of Fsafe_get.
238
2392005-04-21 Miles Bader <miles@gnu.org>
240
241 * xdisp.c (dump_glyph_row): Don't display overlay_arrow_p field.
242
12005-04-20 Thien-Thi Nguyen <ttn@gnu.org> 2432005-04-20 Thien-Thi Nguyen <ttn@gnu.org>
2 244
3 * sysdep.c: Remove reference to defunct vms-pwd.h. 245 * sysdep.c: Remove reference to defunct vms-pwd.h.
@@ -2763,7 +3005,7 @@
2763 3005
2764 * doc.c: New variable Vbuild_files. 3006 * doc.c: New variable Vbuild_files.
2765 (Fsnarf_documentation): If Vbuild_files is nil, populate it with 3007 (Fsnarf_documentation): If Vbuild_files is nil, populate it with
2766 file names from buildobh.lst. Only attach docstrings from files 3008 file names from buildobj.lst. Only attach docstrings from files
2767 that are in Vbuild_files. 3009 that are in Vbuild_files.
2768 (syms_of_doc): Defvar Vbuild_files. 3010 (syms_of_doc): Defvar Vbuild_files.
2769 3011
diff --git a/src/ChangeLog.unicode b/src/ChangeLog.unicode
index bc19b41e6d0..8ca882f9a07 100644
--- a/src/ChangeLog.unicode
+++ b/src/ChangeLog.unicode
@@ -1,3 +1,8 @@
12005-05-04 Miles Bader <miles@gnu.org>
2
3 * character.c (chars-in-region): Obsolete function removed.
4 (syms_of_character): Remove its initialization.
5
12005-04-28 Benjamin Riefenstahl <b.riefenstahl@turtle-trading.net> 62005-04-28 Benjamin Riefenstahl <b.riefenstahl@turtle-trading.net>
2 7
3 * w32select.c (validate_coding_system) 8 * w32select.c (validate_coding_system)
diff --git a/src/Makefile.in b/src/Makefile.in
index 2afdbb4771e..64047763a8f 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -570,7 +570,7 @@ CYGWIN_OBJ = sheap.o
570 570
571#ifdef HAVE_CARBON 571#ifdef HAVE_CARBON
572mac = $(dot)$(dot)/mac/ 572mac = $(dot)$(dot)/mac/
573MAC_OBJ = mac.o macterm.o macfns.o macmenu.o fontset.o fringe.o image.o 573MAC_OBJ = mac.o macterm.o macfns.o macmenu.o macselect.o fontset.o fringe.o image.o
574emacsapp = $(PWD)/$(mac)Emacs.app/ 574emacsapp = $(PWD)/$(mac)Emacs.app/
575emacsappsrc = ${srcdir}/../mac/Emacs.app/ 575emacsappsrc = ${srcdir}/../mac/Emacs.app/
576#endif 576#endif
@@ -597,7 +597,7 @@ obj= dispnew.o frame.o scroll.o xdisp.o $(XMENU_OBJ) window.o \
597 in case they are needed there. */ 597 in case they are needed there. */
598SOME_MACHINE_OBJECTS = sunfns.o dosfns.o msdos.o \ 598SOME_MACHINE_OBJECTS = sunfns.o dosfns.o msdos.o \
599 xterm.o xfns.o xmenu.o xselect.o xrdb.o xsmfns.o fringe.o image.o \ 599 xterm.o xfns.o xmenu.o xselect.o xrdb.o xsmfns.o fringe.o image.o \
600 mac.o macterm.o macfns.o macmenu.o fontset.o \ 600 mac.o macterm.o macfns.o macmenu.o macselect.o fontset.o \
601 w32.o w32bdf.o w32console.o w32fns.o w32heap.o w32inevt.o \ 601 w32.o w32bdf.o w32console.o w32fns.o w32heap.o w32inevt.o \
602 w32menu.o w32proc.o w32reg.o w32select.o w32term.o w32xfns.o 602 w32menu.o w32proc.o w32reg.o w32select.o w32term.o w32xfns.o
603 603
@@ -1230,7 +1230,7 @@ abbrev.o buffer.o callint.o cmds.o dispnew.o editfns.o fileio.o frame.o \
1230 scroll.o sysdep.o term.o widget.o window.o xdisp.o xfaces.o xfns.o xmenu.o \ 1230 scroll.o sysdep.o term.o widget.o window.o xdisp.o xfaces.o xfns.o xmenu.o \
1231 xterm.o xselect.o sound.o: macgui.h 1231 xterm.o xselect.o sound.o: macgui.h
1232mac.o: mac.c process.h sysselect.h blockinput.h atimer.h systime.h charset.h \ 1232mac.o: mac.c process.h sysselect.h blockinput.h atimer.h systime.h charset.h \
1233 coding.h $(config_h) 1233 coding.h ccl.h $(config_h)
1234macfns.o: macfns.c charset.h macterm.h macgui.h frame.h window.h buffer.h \ 1234macfns.o: macfns.c charset.h macterm.h macgui.h frame.h window.h buffer.h \
1235 dispextern.h macgui.h fontset.h $(INTERVAL_SRC) keyboard.h blockinput.h \ 1235 dispextern.h macgui.h fontset.h $(INTERVAL_SRC) keyboard.h blockinput.h \
1236 atimer.h systime.h epaths.h termhooks.h coding.h systime.h $(config_h) 1236 atimer.h systime.h epaths.h termhooks.h coding.h systime.h $(config_h)
@@ -1240,6 +1240,7 @@ macterm.o: blockinput.h atimer.h systime.h syssignal.h macterm.h macgui.h \
1240 frame.h charset.h ccl.h dispextern.h fontset.h termhooks.h termopts.h \ 1240 frame.h charset.h ccl.h dispextern.h fontset.h termhooks.h termopts.h \
1241 termchar.h gnu.h disptab.h buffer.h window.h keyboard.h $(INTERVAL_SRC) \ 1241 termchar.h gnu.h disptab.h buffer.h window.h keyboard.h $(INTERVAL_SRC) \
1242 process.h coding.h $(config_h) 1242 process.h coding.h $(config_h)
1243macselect.o: blockinput.h macterm.h macgui.h frame.h $(config_h)
1243 1244
1244${emacsapp}Contents/Resources/English.lproj: 1245${emacsapp}Contents/Resources/English.lproj:
1245 mkdir -p $@ 1246 mkdir -p $@
diff --git a/src/buffer.c b/src/buffer.c
index d24deb0a9a1..6733cbf0815 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -5084,6 +5084,7 @@ init_buffer_once ()
5084 XSETFASTINT (buffer_local_flags.header_line_format, idx); ++idx; 5084 XSETFASTINT (buffer_local_flags.header_line_format, idx); ++idx;
5085 XSETFASTINT (buffer_local_flags.cursor_type, idx); ++idx; 5085 XSETFASTINT (buffer_local_flags.cursor_type, idx); ++idx;
5086 XSETFASTINT (buffer_local_flags.extra_line_spacing, idx); ++idx; 5086 XSETFASTINT (buffer_local_flags.extra_line_spacing, idx); ++idx;
5087 XSETFASTINT (buffer_local_flags.cursor_in_non_selected_windows, idx); ++idx;
5087 5088
5088 /* Need more room? */ 5089 /* Need more room? */
5089 if (idx >= MAX_PER_BUFFER_VARS) 5090 if (idx >= MAX_PER_BUFFER_VARS)
@@ -5954,6 +5955,11 @@ The space is measured in pixels, and put below lines on window systems.
5954If value is a floating point number, it specifies the spacing relative 5955If value is a floating point number, it specifies the spacing relative
5955to the default frame line height. */); 5956to the default frame line height. */);
5956 5957
5958 DEFVAR_PER_BUFFER ("cursor-in-non-selected-windows",
5959 &current_buffer->cursor_in_non_selected_windows, Qt,
5960 doc: /* *Cursor type to display in non-selected windows.
5961t means to use hollow box cursor. See `cursor-type' for other values. */);
5962
5957 DEFVAR_LISP ("kill-buffer-query-functions", &Vkill_buffer_query_functions, 5963 DEFVAR_LISP ("kill-buffer-query-functions", &Vkill_buffer_query_functions,
5958 doc: /* List of functions called with no args to query before killing a buffer. */); 5964 doc: /* List of functions called with no args to query before killing a buffer. */);
5959 Vkill_buffer_query_functions = Qnil; 5965 Vkill_buffer_query_functions = Qnil;
diff --git a/src/buffer.h b/src/buffer.h
index 838ace7b18b..0da6b5c4953 100644
--- a/src/buffer.h
+++ b/src/buffer.h
@@ -765,6 +765,11 @@ struct buffer
765 /* An integer > 0 means put that number of pixels below text lines 765 /* An integer > 0 means put that number of pixels below text lines
766 in the display of this buffer. */ 766 in the display of this buffer. */
767 Lisp_Object extra_line_spacing; 767 Lisp_Object extra_line_spacing;
768
769 /* *Cursor type to display in non-selected windows.
770 t means to use hollow box cursor.
771 See `cursor-type' for other values. */
772 Lisp_Object cursor_in_non_selected_windows;
768}; 773};
769 774
770 775
diff --git a/src/character.c b/src/character.c
index e4a2ed4a253..91b889c3836 100644
--- a/src/character.c
+++ b/src/character.c
@@ -1,7 +1,7 @@
1/* Basic character support. 1/* Basic character support.
2 Copyright (C) 1995, 1997, 1998, 2001 Electrotechnical Laboratory, JAPAN. 2 Copyright (C) 1995, 1997, 1998, 2001 Electrotechnical Laboratory, JAPAN.
3 Licensed to the Free Software Foundation. 3 Licensed to the Free Software Foundation.
4 Copyright (C) 2001 Free Software Foundation, Inc. 4 Copyright (C) 2001, 2005 Free Software Foundation, Inc.
5 Copyright (C) 2003 5 Copyright (C) 2003
6 National Institute of Advanced Industrial Science and Technology (AIST) 6 National Institute of Advanced Industrial Science and Technology (AIST)
7 Registration Number H13PRO009 7 Registration Number H13PRO009
@@ -532,23 +532,6 @@ The returned value is 0 for left-to-right and 1 for right-to-left. */)
532 return CHAR_TABLE_REF (Vchar_direction_table, c); 532 return CHAR_TABLE_REF (Vchar_direction_table, c);
533} 533}
534 534
535DEFUN ("chars-in-region", Fchars_in_region, Schars_in_region, 2, 2, 0,
536 doc: /* Return number of characters between BEG and END.
537This is now an obsolete function. We keep it just for backward compatibility. */)
538 (beg, end)
539 Lisp_Object beg, end;
540{
541 int from, to;
542
543 CHECK_NUMBER_COERCE_MARKER (beg);
544 CHECK_NUMBER_COERCE_MARKER (end);
545
546 from = min (XFASTINT (beg), XFASTINT (end));
547 to = max (XFASTINT (beg), XFASTINT (end));
548
549 return make_number (to - from);
550}
551
552/* Return the number of characters in the NBYTES bytes at PTR. 535/* Return the number of characters in the NBYTES bytes at PTR.
553 This works by looking at the contents and checking for multibyte 536 This works by looking at the contents and checking for multibyte
554 sequences while assuming that there's no invalid sequence. 537 sequences while assuming that there's no invalid sequence.
@@ -943,7 +926,6 @@ syms_of_character ()
943 defsubr (&Schar_width); 926 defsubr (&Schar_width);
944 defsubr (&Sstring_width); 927 defsubr (&Sstring_width);
945 defsubr (&Schar_direction); 928 defsubr (&Schar_direction);
946 defsubr (&Schars_in_region);
947 defsubr (&Sstring); 929 defsubr (&Sstring);
948 930
949 DEFVAR_LISP ("translation-table-vector", &Vtranslation_table_vector, 931 DEFVAR_LISP ("translation-table-vector", &Vtranslation_table_vector,
diff --git a/src/commands.h b/src/commands.h
index f7831bc36a9..b9b1ad41933 100644
--- a/src/commands.h
+++ b/src/commands.h
@@ -76,11 +76,11 @@ extern Lisp_Object last_point_position_buffer;
76/* Nonzero means ^G can quit instantly */ 76/* Nonzero means ^G can quit instantly */
77extern int immediate_quit; 77extern int immediate_quit;
78 78
79extern Lisp_Object Vexecuting_macro; 79extern Lisp_Object Vexecuting_kbd_macro;
80 80
81/* Nonzero if input is coming from the keyboard */ 81/* Nonzero if input is coming from the keyboard */
82 82
83#define INTERACTIVE (NILP (Vexecuting_macro) && !noninteractive) 83#define INTERACTIVE (NILP (Vexecuting_kbd_macro) && !noninteractive)
84 84
85/* Set this nonzero to force reconsideration of mode line. */ 85/* Set this nonzero to force reconsideration of mode line. */
86 86
diff --git a/src/data.c b/src/data.c
index a78ff68c7e4..cb7f1649c00 100644
--- a/src/data.c
+++ b/src/data.c
@@ -3057,6 +3057,7 @@ syms_of_data ()
3057 staticpro (&Qargs_out_of_range); 3057 staticpro (&Qargs_out_of_range);
3058 staticpro (&Qvoid_function); 3058 staticpro (&Qvoid_function);
3059 staticpro (&Qcyclic_function_indirection); 3059 staticpro (&Qcyclic_function_indirection);
3060 staticpro (&Qcyclic_variable_indirection);
3060 staticpro (&Qvoid_variable); 3061 staticpro (&Qvoid_variable);
3061 staticpro (&Qsetting_constant); 3062 staticpro (&Qsetting_constant);
3062 staticpro (&Qinvalid_read_syntax); 3063 staticpro (&Qinvalid_read_syntax);
diff --git a/src/dispnew.c b/src/dispnew.c
index 70186e279b1..fd35ad338b2 100644
--- a/src/dispnew.c
+++ b/src/dispnew.c
@@ -6343,7 +6343,7 @@ sit_for (sec, usec, reading, display, initial_display)
6343{ 6343{
6344 swallow_events (display); 6344 swallow_events (display);
6345 6345
6346 if (detect_input_pending_run_timers (display) || !NILP (Vexecuting_macro)) 6346 if (detect_input_pending_run_timers (display) || !NILP (Vexecuting_kbd_macro))
6347 return Qnil; 6347 return Qnil;
6348 6348
6349 if (initial_display) 6349 if (initial_display)
diff --git a/src/emacs.c b/src/emacs.c
index 79c0654d379..597a86d2eec 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -264,7 +264,8 @@ Initialization options:\n\
264--no-shared-memory, -nl do not use shared memory\n\ 264--no-shared-memory, -nl do not use shared memory\n\
265--no-site-file do not load site-start.el\n\ 265--no-site-file do not load site-start.el\n\
266--no-splash do not display a splash screen on startup\n\ 266--no-splash do not display a splash screen on startup\n\
267--no-window-system, -nw don't communicate with X, ignoring $DISPLAY\n\ 267--no-window-system, -nw do not communicate with X, ignoring $DISPLAY\n\
268--quick, -Q equivalent to -q --no-site-file\n\
268--script FILE run FILE as an Emacs Lisp script\n\ 269--script FILE run FILE as an Emacs Lisp script\n\
269--terminal, -t DEVICE use DEVICE for terminal I/O\n\ 270--terminal, -t DEVICE use DEVICE for terminal I/O\n\
270--unibyte, --no-multibyte run Emacs in unibyte mode\n\ 271--unibyte, --no-multibyte run Emacs in unibyte mode\n\
@@ -294,6 +295,8 @@ FILE visit FILE using find-file\n\
294Display options:\n\ 295Display options:\n\
295\n\ 296\n\
296--background-color, -bg COLOR window background color\n\ 297--background-color, -bg COLOR window background color\n\
298--basic-display, -D disable many display features;\n\
299 used for debugging Emacs\n\
297--border-color, -bd COLOR main border color\n\ 300--border-color, -bd COLOR main border color\n\
298--border-width, -bw WIDTH width of main border\n\ 301--border-width, -bw WIDTH width of main border\n\
299--color, --color=MODE color mode for character terminals;\n\ 302--color, --color=MODE color mode for character terminals;\n\
@@ -320,16 +323,16 @@ Display options:\n\
320--xrm XRESOURCES set additional X resources\n\ 323--xrm XRESOURCES set additional X resources\n\
321--help display this help and exit\n\ 324--help display this help and exit\n\
322--version output version information and exit\n\ 325--version output version information and exit\n\
323\n\ 326\n"
327
328#define USAGE4 "\
324You can generally also specify long option names with a single -; for\n\ 329You can generally also specify long option names with a single -; for\n\
325example, -batch as well as --batch. You can use any unambiguous\n\ 330example, -batch as well as --batch. You can use any unambiguous\n\
326abbreviation for a --option.\n\ 331abbreviation for a --option.\n\
327\n\ 332\n\
328Various environment variables and window system resources also affect\n\ 333Various environment variables and window system resources also affect\n\
329Emacs' operation. See the main documentation.\n\ 334Emacs' operation. See the main documentation.\n\
330\n" 335\n\
331
332#define USAGE4 "\
333Report bugs to %s. First, please see the Bugs\n\ 336Report bugs to %s. First, please see the Bugs\n\
334section of the Emacs manual or the file BUGS.\n" 337section of the Emacs manual or the file BUGS.\n"
335 338
@@ -1318,6 +1321,7 @@ main (argc, argv
1318 syms_of_fontset (); 1321 syms_of_fontset ();
1319 syms_of_macterm (); 1322 syms_of_macterm ();
1320 syms_of_macmenu (); 1323 syms_of_macmenu ();
1324 syms_of_macselect ();
1321 syms_of_data (); 1325 syms_of_data ();
1322 syms_of_search (); 1326 syms_of_search ();
1323 syms_of_frame (); 1327 syms_of_frame ();
@@ -1637,6 +1641,7 @@ main (argc, argv
1637 syms_of_macterm (); 1641 syms_of_macterm ();
1638 syms_of_macfns (); 1642 syms_of_macfns ();
1639 syms_of_macmenu (); 1643 syms_of_macmenu ();
1644 syms_of_macselect ();
1640 syms_of_fontset (); 1645 syms_of_fontset ();
1641#endif /* MAC_OSX && HAVE_CARBON */ 1646#endif /* MAC_OSX && HAVE_CARBON */
1642 1647
diff --git a/src/eval.c b/src/eval.c
index 8700ca222ce..6832f3197ad 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -1,6 +1,6 @@
1/* Evaluator for GNU Emacs Lisp interpreter. 1/* Evaluator for GNU Emacs Lisp interpreter.
2 Copyright (C) 1985, 86, 87, 93, 94, 95, 99, 2000, 2001, 02, 2004 2 Copyright (C) 1985, 1986, 1987, 1993, 1994, 1995, 1999, 2000, 2001,
3 Free Software Foundation, Inc. 3 2002, 2004, 2005 Free Software Foundation, Inc.
4 4
5This file is part of GNU Emacs. 5This file is part of GNU Emacs.
6 6
@@ -1982,10 +1982,7 @@ do_autoload (fundef, funname)
1982 second = Fcdr (first); 1982 second = Fcdr (first);
1983 first = Fcar (first); 1983 first = Fcar (first);
1984 1984
1985 /* Note: This test is subtle. The cdr of an autoload-queue entry 1985 if (CONSP (second) && EQ (XCAR (second), Qautoload))
1986 may be an atom if the autoload entry was generated by a defalias
1987 or fset. */
1988 if (CONSP (second))
1989 Fput (first, Qautoload, (XCDR (second))); 1986 Fput (first, Qautoload, (XCDR (second)));
1990 1987
1991 queue = XCDR (queue); 1988 queue = XCDR (queue);
diff --git a/src/fileio.c b/src/fileio.c
index 2a2703ba7a1..9ee4d10b081 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -175,6 +175,10 @@ Lisp_Object Vdefault_file_name_coding_system;
175 whose I/O is done with a special handler. */ 175 whose I/O is done with a special handler. */
176Lisp_Object Vfile_name_handler_alist; 176Lisp_Object Vfile_name_handler_alist;
177 177
178/* Property name of a file name handler,
179 which gives a list of operations it handles.. */
180Lisp_Object Qoperations;
181
178/* Lisp functions for translating file formats */ 182/* Lisp functions for translating file formats */
179Lisp_Object Qformat_decode, Qformat_annotate_function; 183Lisp_Object Qformat_decode, Qformat_annotate_function;
180 184
@@ -370,13 +374,16 @@ use the standard functions without calling themselves recursively. */)
370 elt = XCAR (chain); 374 elt = XCAR (chain);
371 if (CONSP (elt)) 375 if (CONSP (elt))
372 { 376 {
373 Lisp_Object string; 377 Lisp_Object string = XCAR (elt);
374 int match_pos; 378 int match_pos;
375 string = XCAR (elt); 379 Lisp_Object handler = XCDR (elt);
380 Lisp_Object operations = Fget (handler, Qoperations);
381
376 if (STRINGP (string) 382 if (STRINGP (string)
377 && (match_pos = fast_string_match (string, filename)) > pos) 383 && (match_pos = fast_string_match (string, filename)) > pos
384 && (NILP (operations) || ! NILP (Fmemq (operation, operations))))
378 { 385 {
379 Lisp_Object handler, tem; 386 Lisp_Object tem;
380 387
381 handler = XCDR (elt); 388 handler = XCDR (elt);
382 tem = Fmemq (handler, inhibited_handlers); 389 tem = Fmemq (handler, inhibited_handlers);
@@ -2393,7 +2400,7 @@ barf_or_query_if_file_exists (absname, querystring, interactive, statptr, quick)
2393 return; 2400 return;
2394} 2401}
2395 2402
2396DEFUN ("copy-file", Fcopy_file, Scopy_file, 2, 4, 2403DEFUN ("copy-file", Fcopy_file, Scopy_file, 2, 5,
2397 "fCopy file: \nGCopy %s to file: \np\nP", 2404 "fCopy file: \nGCopy %s to file: \np\nP",
2398 doc: /* Copy FILE to NEWNAME. Both args must be strings. 2405 doc: /* Copy FILE to NEWNAME. Both args must be strings.
2399If NEWNAME names a directory, copy FILE there. 2406If NEWNAME names a directory, copy FILE there.
@@ -2402,11 +2409,20 @@ unless a third argument OK-IF-ALREADY-EXISTS is supplied and non-nil.
2402A number as third arg means request confirmation if NEWNAME already exists. 2409A number as third arg means request confirmation if NEWNAME already exists.
2403This is what happens in interactive use with M-x. 2410This is what happens in interactive use with M-x.
2404Always sets the file modes of the output file to match the input file. 2411Always sets the file modes of the output file to match the input file.
2412
2405Fourth arg KEEP-TIME non-nil means give the output file the same 2413Fourth arg KEEP-TIME non-nil means give the output file the same
2406last-modified time as the old one. (This works on only some systems.) 2414last-modified time as the old one. (This works on only some systems.)
2407A prefix arg makes KEEP-TIME non-nil. */) 2415
2408 (file, newname, ok_if_already_exists, keep_time) 2416A prefix arg makes KEEP-TIME non-nil.
2409 Lisp_Object file, newname, ok_if_already_exists, keep_time; 2417
2418The optional fifth arg MUSTBENEW, if non-nil, insists on a check
2419for an existing file with the same name. If MUSTBENEW is `excl',
2420that means to get an error if the file already exists; never overwrite.
2421If MUSTBENEW is neither nil nor `excl', that means ask for
2422confirmation before overwriting, but do go ahead and overwrite the file
2423if the user confirms. */)
2424 (file, newname, ok_if_already_exists, keep_time, mustbenew)
2425 Lisp_Object file, newname, ok_if_already_exists, keep_time, mustbenew;
2410{ 2426{
2411 int ifd, ofd, n; 2427 int ifd, ofd, n;
2412 char buf[16 * 1024]; 2428 char buf[16 * 1024];
@@ -2422,6 +2438,9 @@ A prefix arg makes KEEP-TIME non-nil. */)
2422 CHECK_STRING (file); 2438 CHECK_STRING (file);
2423 CHECK_STRING (newname); 2439 CHECK_STRING (newname);
2424 2440
2441 if (!NILP (mustbenew) && !EQ (mustbenew, Qexcl))
2442 barf_or_query_if_file_exists (newname, "overwrite", 1, 0, 1);
2443
2425 if (!NILP (Ffile_directory_p (newname))) 2444 if (!NILP (Ffile_directory_p (newname)))
2426 newname = Fexpand_file_name (Ffile_name_nondirectory (file), newname); 2445 newname = Fexpand_file_name (Ffile_name_nondirectory (file), newname);
2427 else 2446 else
@@ -2522,9 +2541,15 @@ A prefix arg makes KEEP-TIME non-nil. */)
2522#else 2541#else
2523#ifdef MSDOS 2542#ifdef MSDOS
2524 /* System's default file type was set to binary by _fmode in emacs.c. */ 2543 /* System's default file type was set to binary by _fmode in emacs.c. */
2525 ofd = creat (SDATA (encoded_newname), S_IREAD | S_IWRITE); 2544 ofd = emacs_open (SDATA (encoded_newname),
2526#else /* not MSDOS */ 2545 O_WRONLY | O_TRUNC | O_CREAT
2527 ofd = creat (SDATA (encoded_newname), 0666); 2546 | (EQ (mustbenew, Qexcl) ? O_EXCL : 0),
2547 S_IREAD | S_IWRITE);
2548#else /* not MSDOS */
2549 ofd = emacs_open (SDATA (encoded_newname),
2550 O_WRONLY | O_TRUNC | O_CREAT
2551 | (EQ (mustbenew, Qexcl) ? O_EXCL : 0),
2552 0666);
2528#endif /* not MSDOS */ 2553#endif /* not MSDOS */
2529#endif /* VMS */ 2554#endif /* VMS */
2530 if (ofd < 0) 2555 if (ofd < 0)
@@ -2754,7 +2779,8 @@ This is what happens in interactive use with M-x. */)
2754 Fcopy_file (file, newname, 2779 Fcopy_file (file, newname,
2755 /* We have already prompted if it was an integer, 2780 /* We have already prompted if it was an integer,
2756 so don't have copy-file prompt again. */ 2781 so don't have copy-file prompt again. */
2757 NILP (ok_if_already_exists) ? Qnil : Qt, Qt); 2782 NILP (ok_if_already_exists) ? Qnil : Qt,
2783 Qt, Qnil);
2758 Fdelete_file (file); 2784 Fdelete_file (file);
2759 } 2785 }
2760 else 2786 else
@@ -6334,6 +6360,7 @@ init_fileio_once ()
6334void 6360void
6335syms_of_fileio () 6361syms_of_fileio ()
6336{ 6362{
6363 Qoperations = intern ("operations");
6337 Qexpand_file_name = intern ("expand-file-name"); 6364 Qexpand_file_name = intern ("expand-file-name");
6338 Qsubstitute_in_file_name = intern ("substitute-in-file-name"); 6365 Qsubstitute_in_file_name = intern ("substitute-in-file-name");
6339 Qdirectory_file_name = intern ("directory-file-name"); 6366 Qdirectory_file_name = intern ("directory-file-name");
@@ -6368,6 +6395,7 @@ syms_of_fileio ()
6368 Qset_visited_file_modtime = intern ("set-visited-file-modtime"); 6395 Qset_visited_file_modtime = intern ("set-visited-file-modtime");
6369 Qauto_save_coding = intern ("auto-save-coding"); 6396 Qauto_save_coding = intern ("auto-save-coding");
6370 6397
6398 staticpro (&Qoperations);
6371 staticpro (&Qexpand_file_name); 6399 staticpro (&Qexpand_file_name);
6372 staticpro (&Qsubstitute_in_file_name); 6400 staticpro (&Qsubstitute_in_file_name);
6373 staticpro (&Qdirectory_file_name); 6401 staticpro (&Qdirectory_file_name);
diff --git a/src/fns.c b/src/fns.c
index f1788bd88e1..4562eaff02e 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -184,8 +184,7 @@ To get the number of bytes, use `string-bytes'. */)
184 return val; 184 return val;
185} 185}
186 186
187/* This does not check for quits. That is safe 187/* This does not check for quits. That is safe since it must terminate. */
188 since it must terminate. */
189 188
190DEFUN ("safe-length", Fsafe_length, Ssafe_length, 1, 1, 0, 189DEFUN ("safe-length", Fsafe_length, Ssafe_length, 1, 1, 0,
191 doc: /* Return the length of a list, but avoid error or infinite loop. 190 doc: /* Return the length of a list, but avoid error or infinite loop.
@@ -1901,6 +1900,7 @@ merge (org_l1, org_l2, pred)
1901} 1900}
1902 1901
1903 1902
1903#if 0 /* Unsafe version. */
1904DEFUN ("plist-get", Fplist_get, Splist_get, 2, 2, 0, 1904DEFUN ("plist-get", Fplist_get, Splist_get, 2, 2, 0,
1905 doc: /* Extract a value from a property list. 1905 doc: /* Extract a value from a property list.
1906PLIST is a property list, which is a list of the form 1906PLIST is a property list, which is a list of the form
@@ -1931,14 +1931,16 @@ one of the properties on the list. */)
1931 1931
1932 return Qnil; 1932 return Qnil;
1933} 1933}
1934#endif
1935
1936/* This does not check for quits. That is safe since it must terminate. */
1934 1937
1935DEFUN ("safe-plist-get", Fsafe_plist_get, Ssafe_plist_get, 2, 2, 0, 1938DEFUN ("plist-get", Fplist_get, Splist_get, 2, 2, 0,
1936 doc: /* Extract a value from a property list. 1939 doc: /* Extract a value from a property list.
1937PLIST is a property list, which is a list of the form 1940PLIST is a property list, which is a list of the form
1938\(PROP1 VALUE1 PROP2 VALUE2...). This function returns the value 1941\(PROP1 VALUE1 PROP2 VALUE2...). This function returns the value
1939corresponding to the given PROP, or nil if PROP is not 1942corresponding to the given PROP, or nil if PROP is not one of the
1940one of the properties on the list. 1943properties on the list. This function never signals an error. */)
1941This function never signals an error. */)
1942 (plist, prop) 1944 (plist, prop)
1943 Lisp_Object plist; 1945 Lisp_Object plist;
1944 Lisp_Object prop; 1946 Lisp_Object prop;
@@ -1971,18 +1973,6 @@ This is the last value stored with `(put SYMBOL PROPNAME VALUE)'. */)
1971 return Fplist_get (XSYMBOL (symbol)->plist, propname); 1973 return Fplist_get (XSYMBOL (symbol)->plist, propname);
1972} 1974}
1973 1975
1974DEFUN ("safe-get", Fsafe_get, Ssafe_get, 2, 2, 0,
1975 doc: /* Return the value of SYMBOL's PROPNAME property.
1976This is the last value stored with `(put SYMBOL PROPNAME VALUE)'.
1977This function never signals an error. */)
1978 (symbol, propname)
1979 Lisp_Object symbol, propname;
1980{
1981 if (!SYMBOLP (symbol))
1982 return Qnil;
1983 return Fsafe_plist_get (XSYMBOL (symbol)->plist, propname);
1984}
1985
1986DEFUN ("plist-put", Fplist_put, Splist_put, 3, 3, 0, 1976DEFUN ("plist-put", Fplist_put, Splist_put, 3, 3, 0,
1987 doc: /* Change value in PLIST of PROP to VAL. 1977 doc: /* Change value in PLIST of PROP to VAL.
1988PLIST is a property list, which is a list of the form 1978PLIST is a property list, which is a list of the form
@@ -5263,9 +5253,7 @@ used if both `use-dialog-box' and this variable are non-nil. */);
5263 defsubr (&Sreverse); 5253 defsubr (&Sreverse);
5264 defsubr (&Ssort); 5254 defsubr (&Ssort);
5265 defsubr (&Splist_get); 5255 defsubr (&Splist_get);
5266 defsubr (&Ssafe_plist_get);
5267 defsubr (&Sget); 5256 defsubr (&Sget);
5268 defsubr (&Ssafe_get);
5269 defsubr (&Splist_put); 5257 defsubr (&Splist_put);
5270 defsubr (&Sput); 5258 defsubr (&Sput);
5271 defsubr (&Slax_plist_get); 5259 defsubr (&Slax_plist_get);
diff --git a/src/frame.c b/src/frame.c
index f2799206d4c..1a84072b40b 100644
--- a/src/frame.c
+++ b/src/frame.c
@@ -1260,6 +1260,10 @@ The functions are run with one arg, the frame to be deleted. */)
1260 if (FRAME_X_P (f)) 1260 if (FRAME_X_P (f))
1261 x_clear_frame_selections (f); 1261 x_clear_frame_selections (f);
1262#endif 1262#endif
1263#ifdef MAC_OS
1264 if (FRAME_MAC_P (f))
1265 x_clear_frame_selections (f);
1266#endif
1263 1267
1264 /* Free glyphs. 1268 /* Free glyphs.
1265 This function must be called before the window tree of the 1269 This function must be called before the window tree of the
diff --git a/src/keyboard.c b/src/keyboard.c
index ab8c8907c00..dd4767585b7 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -1173,21 +1173,21 @@ cmd_error (data)
1173 cancel_hourglass (); 1173 cancel_hourglass ();
1174#endif 1174#endif
1175 1175
1176 if (!NILP (executing_macro)) 1176 if (!NILP (executing_kbd_macro))
1177 { 1177 {
1178 if (executing_macro_iterations == 1) 1178 if (executing_kbd_macro_iterations == 1)
1179 sprintf (macroerror, "After 1 kbd macro iteration: "); 1179 sprintf (macroerror, "After 1 kbd macro iteration: ");
1180 else 1180 else
1181 sprintf (macroerror, "After %d kbd macro iterations: ", 1181 sprintf (macroerror, "After %d kbd macro iterations: ",
1182 executing_macro_iterations); 1182 executing_kbd_macro_iterations);
1183 } 1183 }
1184 else 1184 else
1185 *macroerror = 0; 1185 *macroerror = 0;
1186 1186
1187 Vstandard_output = Qt; 1187 Vstandard_output = Qt;
1188 Vstandard_input = Qt; 1188 Vstandard_input = Qt;
1189 Vexecuting_macro = Qnil; 1189 Vexecuting_kbd_macro = Qnil;
1190 executing_macro = Qnil; 1190 executing_kbd_macro = Qnil;
1191 current_kboard->Vprefix_arg = Qnil; 1191 current_kboard->Vprefix_arg = Qnil;
1192 current_kboard->Vlast_prefix_arg = Qnil; 1192 current_kboard->Vlast_prefix_arg = Qnil;
1193 cancel_echoing (); 1193 cancel_echoing ();
@@ -1288,7 +1288,7 @@ command_loop ()
1288 { 1288 {
1289 Lisp_Object val; 1289 Lisp_Object val;
1290 val = internal_catch (Qexit, command_loop_2, Qnil); 1290 val = internal_catch (Qexit, command_loop_2, Qnil);
1291 executing_macro = Qnil; 1291 executing_kbd_macro = Qnil;
1292 return val; 1292 return val;
1293 } 1293 }
1294 else 1294 else
@@ -1300,7 +1300,7 @@ command_loop ()
1300 other reason. */ 1300 other reason. */
1301 any_kboard_state (); 1301 any_kboard_state ();
1302 internal_catch (Qtop_level, command_loop_2, Qnil); 1302 internal_catch (Qtop_level, command_loop_2, Qnil);
1303 executing_macro = Qnil; 1303 executing_kbd_macro = Qnil;
1304 1304
1305 /* End of file in -batch run causes exit here. */ 1305 /* End of file in -batch run causes exit here. */
1306 if (noninteractive) 1306 if (noninteractive)
@@ -1453,7 +1453,7 @@ command_loop_1 ()
1453 if (NILP (Vunread_command_events) 1453 if (NILP (Vunread_command_events)
1454 && NILP (Vunread_input_method_events) 1454 && NILP (Vunread_input_method_events)
1455 && NILP (Vunread_post_input_method_events) 1455 && NILP (Vunread_post_input_method_events)
1456 && NILP (Vexecuting_macro) 1456 && NILP (Vexecuting_kbd_macro)
1457 && !NILP (sit_for (0, post_command_idle_delay, 0, 1, 1))) 1457 && !NILP (sit_for (0, post_command_idle_delay, 0, 1, 1)))
1458 safe_run_hooks (Qpost_command_idle_hook); 1458 safe_run_hooks (Qpost_command_idle_hook);
1459 } 1459 }
@@ -1582,11 +1582,11 @@ command_loop_1 ()
1582 } 1582 }
1583 1583
1584 cmd = read_key_sequence_cmd; 1584 cmd = read_key_sequence_cmd;
1585 if (!NILP (Vexecuting_macro)) 1585 if (!NILP (Vexecuting_kbd_macro))
1586 { 1586 {
1587 if (!NILP (Vquit_flag)) 1587 if (!NILP (Vquit_flag))
1588 { 1588 {
1589 Vexecuting_macro = Qt; 1589 Vexecuting_kbd_macro = Qt;
1590 QUIT; /* Make some noise. */ 1590 QUIT; /* Make some noise. */
1591 /* Will return since macro now empty. */ 1591 /* Will return since macro now empty. */
1592 } 1592 }
@@ -1685,7 +1685,7 @@ command_loop_1 ()
1685 && EQ (current_buffer->selective_display, Qnil) 1685 && EQ (current_buffer->selective_display, Qnil)
1686 && !detect_input_pending () 1686 && !detect_input_pending ()
1687 && NILP (XWINDOW (selected_window)->column_number_displayed) 1687 && NILP (XWINDOW (selected_window)->column_number_displayed)
1688 && NILP (Vexecuting_macro)) 1688 && NILP (Vexecuting_kbd_macro))
1689 direct_output_forward_char (1); 1689 direct_output_forward_char (1);
1690 goto directly_done; 1690 goto directly_done;
1691 } 1691 }
@@ -1720,7 +1720,7 @@ command_loop_1 ()
1720 && EQ (current_buffer->selective_display, Qnil) 1720 && EQ (current_buffer->selective_display, Qnil)
1721 && !detect_input_pending () 1721 && !detect_input_pending ()
1722 && NILP (XWINDOW (selected_window)->column_number_displayed) 1722 && NILP (XWINDOW (selected_window)->column_number_displayed)
1723 && NILP (Vexecuting_macro)) 1723 && NILP (Vexecuting_kbd_macro))
1724 direct_output_forward_char (-1); 1724 direct_output_forward_char (-1);
1725 goto directly_done; 1725 goto directly_done;
1726 } 1726 }
@@ -1733,7 +1733,7 @@ command_loop_1 ()
1733 = translate_char (Vtranslation_table_for_input, 1733 = translate_char (Vtranslation_table_for_input,
1734 XFASTINT (last_command_char)); 1734 XFASTINT (last_command_char));
1735 int value; 1735 int value;
1736 if (NILP (Vexecuting_macro) 1736 if (NILP (Vexecuting_kbd_macro)
1737 && !EQ (minibuf_window, selected_window)) 1737 && !EQ (minibuf_window, selected_window))
1738 { 1738 {
1739 if (!nonundocount || nonundocount >= 20) 1739 if (!nonundocount || nonundocount >= 20)
@@ -1755,7 +1755,7 @@ command_loop_1 ()
1755 || !EQ (current_buffer->selective_display, Qnil) 1755 || !EQ (current_buffer->selective_display, Qnil)
1756 || detect_input_pending () 1756 || detect_input_pending ()
1757 || !NILP (XWINDOW (selected_window)->column_number_displayed) 1757 || !NILP (XWINDOW (selected_window)->column_number_displayed)
1758 || !NILP (Vexecuting_macro)); 1758 || !NILP (Vexecuting_kbd_macro));
1759 1759
1760 value = internal_self_insert (c, 0); 1760 value = internal_self_insert (c, 0);
1761 1761
@@ -1783,7 +1783,7 @@ command_loop_1 ()
1783 int scount = SPECPDL_INDEX (); 1783 int scount = SPECPDL_INDEX ();
1784 1784
1785 if (display_hourglass_p 1785 if (display_hourglass_p
1786 && NILP (Vexecuting_macro)) 1786 && NILP (Vexecuting_kbd_macro))
1787 { 1787 {
1788 record_unwind_protect (cancel_hourglass_unwind, Qnil); 1788 record_unwind_protect (cancel_hourglass_unwind, Qnil);
1789 start_hourglass (); 1789 start_hourglass ();
@@ -1801,7 +1801,7 @@ command_loop_1 ()
1801 hourglass cursor anyway. 1801 hourglass cursor anyway.
1802 But don't cancel the hourglass within a macro 1802 But don't cancel the hourglass within a macro
1803 just because a command in the macro finishes. */ 1803 just because a command in the macro finishes. */
1804 if (NILP (Vexecuting_macro)) 1804 if (NILP (Vexecuting_kbd_macro))
1805 unbind_to (scount, Qnil); 1805 unbind_to (scount, Qnil);
1806#endif 1806#endif
1807 } 1807 }
@@ -1827,7 +1827,7 @@ command_loop_1 ()
1827 if (NILP (Vunread_command_events) 1827 if (NILP (Vunread_command_events)
1828 && NILP (Vunread_input_method_events) 1828 && NILP (Vunread_input_method_events)
1829 && NILP (Vunread_post_input_method_events) 1829 && NILP (Vunread_post_input_method_events)
1830 && NILP (Vexecuting_macro) 1830 && NILP (Vexecuting_kbd_macro)
1831 && !NILP (sit_for (0, post_command_idle_delay, 0, 1, 1))) 1831 && !NILP (sit_for (0, post_command_idle_delay, 0, 1, 1)))
1832 safe_run_hooks (Qpost_command_idle_hook); 1832 safe_run_hooks (Qpost_command_idle_hook);
1833 } 1833 }
@@ -2499,7 +2499,7 @@ read_char (commandflag, nmaps, maps, prev_event, used_mouse_menu)
2499 2499
2500 this_command_key_count_reset = 0; 2500 this_command_key_count_reset = 0;
2501 2501
2502 if (!NILP (Vexecuting_macro)) 2502 if (!NILP (Vexecuting_kbd_macro))
2503 { 2503 {
2504 /* We set this to Qmacro; since that's not a frame, nobody will 2504 /* We set this to Qmacro; since that's not a frame, nobody will
2505 try to switch frames on us, and the selected window will 2505 try to switch frames on us, and the selected window will
@@ -2516,19 +2516,19 @@ read_char (commandflag, nmaps, maps, prev_event, used_mouse_menu)
2516 /* Exit the macro if we are at the end. 2516 /* Exit the macro if we are at the end.
2517 Also, some things replace the macro with t 2517 Also, some things replace the macro with t
2518 to force an early exit. */ 2518 to force an early exit. */
2519 if (EQ (Vexecuting_macro, Qt) 2519 if (EQ (Vexecuting_kbd_macro, Qt)
2520 || executing_macro_index >= XFASTINT (Flength (Vexecuting_macro))) 2520 || executing_kbd_macro_index >= XFASTINT (Flength (Vexecuting_kbd_macro)))
2521 { 2521 {
2522 XSETINT (c, -1); 2522 XSETINT (c, -1);
2523 goto exit; 2523 goto exit;
2524 } 2524 }
2525 2525
2526 c = Faref (Vexecuting_macro, make_number (executing_macro_index)); 2526 c = Faref (Vexecuting_kbd_macro, make_number (executing_kbd_macro_index));
2527 if (STRINGP (Vexecuting_macro) 2527 if (STRINGP (Vexecuting_kbd_macro)
2528 && (XINT (c) & 0x80) && (XUINT (c) <= 0xff)) 2528 && (XINT (c) & 0x80) && (XUINT (c) <= 0xff))
2529 XSETFASTINT (c, CHAR_META | (XINT (c) & ~0x80)); 2529 XSETFASTINT (c, CHAR_META | (XINT (c) & ~0x80));
2530 2530
2531 executing_macro_index++; 2531 executing_kbd_macro_index++;
2532 2532
2533 goto from_macro; 2533 goto from_macro;
2534 } 2534 }
@@ -9815,7 +9815,7 @@ DEFUN ("execute-extended-command", Fexecute_extended_command, Sexecute_extended_
9815 9815
9816 /* If enabled, show which key runs this command. */ 9816 /* If enabled, show which key runs this command. */
9817 if (!NILP (Vsuggest_key_bindings) 9817 if (!NILP (Vsuggest_key_bindings)
9818 && NILP (Vexecuting_macro) 9818 && NILP (Vexecuting_kbd_macro)
9819 && SYMBOLP (function)) 9819 && SYMBOLP (function))
9820 bindings = Fwhere_is_internal (function, Voverriding_local_map, 9820 bindings = Fwhere_is_internal (function, Voverriding_local_map,
9821 Qt, Qnil, Qnil); 9821 Qt, Qnil, Qnil);
diff --git a/src/lisp.h b/src/lisp.h
index 766af053b60..20270bc357e 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -2349,7 +2349,6 @@ EXFUN (Fsort, 2);
2349EXFUN (Freverse, 1); 2349EXFUN (Freverse, 1);
2350EXFUN (Fnreverse, 1); 2350EXFUN (Fnreverse, 1);
2351EXFUN (Fget, 2); 2351EXFUN (Fget, 2);
2352EXFUN (Fsafe_get, 2);
2353EXFUN (Fput, 3); 2352EXFUN (Fput, 3);
2354EXFUN (Fequal, 2); 2353EXFUN (Fequal, 2);
2355EXFUN (Ffillarray, 2); 2354EXFUN (Ffillarray, 2);
@@ -2372,7 +2371,6 @@ extern Lisp_Object string_to_multibyte P_ ((Lisp_Object));
2372extern Lisp_Object string_make_unibyte P_ ((Lisp_Object)); 2371extern Lisp_Object string_make_unibyte P_ ((Lisp_Object));
2373EXFUN (Fcopy_alist, 1); 2372EXFUN (Fcopy_alist, 1);
2374EXFUN (Fplist_get, 2); 2373EXFUN (Fplist_get, 2);
2375EXFUN (Fsafe_plist_get, 2);
2376EXFUN (Fplist_put, 3); 2374EXFUN (Fplist_put, 3);
2377EXFUN (Fplist_member, 2); 2375EXFUN (Fplist_member, 2);
2378EXFUN (Frassoc, 2); 2376EXFUN (Frassoc, 2);
diff --git a/src/m/macppc.h b/src/m/macppc.h
index 21ba90ad101..c068fca32a9 100644
--- a/src/m/macppc.h
+++ b/src/m/macppc.h
@@ -86,11 +86,16 @@ Boston, MA 02111-1307, USA. */
86 86
87#ifdef LINUX 87#ifdef LINUX
88#define LINKER $(CC) -nostdlib 88#define LINKER $(CC) -nostdlib
89#define LD_SWITCH_MACHINE -Xlinker -m -Xlinker elf32ppc
90/* s/gnu-linux.h defines this to `-z nocombreloc' which does not work here 89/* s/gnu-linux.h defines this to `-z nocombreloc' which does not work here
91 because prefix-args is not used. */ 90 because prefix-args is not used. */
92#undef LD_SWITCH_SYSTEM_TEMACS 91#undef LD_SWITCH_SYSTEM_TEMACS
93#define LD_SWITCH_MACHINE_TEMACS -Xlinker -znocombreloc 92#define LD_SWITCH_MACHINE_TEMACS -Xlinker -znocombreloc
93#ifdef _ARCH_PPC64
94#undef START_FILES
95#define START_FILES pre-crt0.o /usr/lib64/crt1.o /usr/lib64/crti.o
96#undef LIB_STANDARD
97#define LIB_STANDARD -lgcc -lc -lgcc /usr/lib64/crtn.o
98#endif
94#endif 99#endif
95 100
96#if 0 /* This breaks things on PPC GNU/Linux ecept for Yellowdog, 101#if 0 /* This breaks things on PPC GNU/Linux ecept for Yellowdog,
@@ -105,5 +110,11 @@ Boston, MA 02111-1307, USA. */
105#endif 110#endif
106#endif /* 0 */ 111#endif /* 0 */
107 112
113#ifdef _ARCH_PPC64
114#ifndef _LP64
115#define _LP64
116#endif
117#endif
118
108/* arch-tag: 41913e4e-e7d1-4023-aadb-210cc31712ed 119/* arch-tag: 41913e4e-e7d1-4023-aadb-210cc31712ed
109 (do not change this comment) */ 120 (do not change this comment) */
diff --git a/src/mac.c b/src/mac.c
index 68e3bdfa065..14257fdee94 100644
--- a/src/mac.c
+++ b/src/mac.c
@@ -24,19 +24,20 @@ Boston, MA 02111-1307, USA. */
24 24
25#include <stdio.h> 25#include <stdio.h>
26#include <errno.h> 26#include <errno.h>
27#include <time.h>
28 27
29#include "lisp.h" 28#include "lisp.h"
30#include "process.h" 29#include "process.h"
31#include "sysselect.h" 30#undef init_process
32#include "systime.h" 31#include "systime.h"
32#include "sysselect.h"
33#include "blockinput.h" 33#include "blockinput.h"
34#include "charset.h"
35#include "coding.h"
36 34
37#include "macterm.h" 35#include "macterm.h"
38 36
39#ifndef HAVE_CARBON 37#if TARGET_API_MAC_CARBON
38#include "charset.h"
39#include "coding.h"
40#else /* not TARGET_API_MAC_CARBON */
40#include <Files.h> 41#include <Files.h>
41#include <MacTypes.h> 42#include <MacTypes.h>
42#include <TextUtils.h> 43#include <TextUtils.h>
@@ -52,7 +53,7 @@ Boston, MA 02111-1307, USA. */
52#include <Processes.h> 53#include <Processes.h>
53#include <EPPC.h> 54#include <EPPC.h>
54#include <MacLocales.h> 55#include <MacLocales.h>
55#endif /* not HAVE_CARBON */ 56#endif /* not TARGET_API_MAC_CARBON */
56 57
57#include <utime.h> 58#include <utime.h>
58#include <dirent.h> 59#include <dirent.h>
@@ -68,8 +69,6 @@ Boston, MA 02111-1307, USA. */
68#include <unistd.h> 69#include <unistd.h>
69#endif 70#endif
70 71
71Lisp_Object QCLIPBOARD;
72
73/* The system script code. */ 72/* The system script code. */
74static int mac_system_script_code; 73static int mac_system_script_code;
75 74
@@ -331,7 +330,7 @@ cfdata_to_lisp (data)
331{ 330{
332 CFIndex len = CFDataGetLength (data); 331 CFIndex len = CFDataGetLength (data);
333 Lisp_Object result = make_uninit_string (len); 332 Lisp_Object result = make_uninit_string (len);
334 333
335 CFDataGetBytes (data, CFRangeMake (0, len), SDATA (result)); 334 CFDataGetBytes (data, CFRangeMake (0, len), SDATA (result));
336 335
337 return result; 336 return result;
@@ -894,7 +893,7 @@ xrm_q_put_resource (database, quarks, value)
894 if (i < 0) 893 if (i < 0)
895 { 894 {
896 max_nid++; 895 max_nid++;
897 XSETINT (node_id, max_nid); 896 XSETINT (node_id, max_nid);
898 hash_put (h, key, node_id, hash_code); 897 hash_put (h, key, node_id, hash_code);
899 } 898 }
900 else 899 else
@@ -3515,169 +3514,9 @@ DEFUN ("posix-file-name-to-mac", Fposix_file_name_to_mac,
3515} 3514}
3516 3515
3517 3516
3518/* set interprogram-paste-function to mac-paste-function in mac-win.el
3519 to enable Emacs to obtain the contents of the Mac clipboard. */
3520DEFUN ("mac-paste-function", Fmac_paste_function, Smac_paste_function, 0, 0, 0,
3521 doc: /* Return the contents of the Mac clipboard as a string. */)
3522 ()
3523{
3524#if TARGET_API_MAC_CARBON
3525 OSStatus err;
3526 ScrapRef scrap;
3527 ScrapFlavorFlags sff;
3528 Size s;
3529 int i;
3530 char *data;
3531
3532 BLOCK_INPUT;
3533 err = GetCurrentScrap (&scrap);
3534 if (err == noErr)
3535 err = GetScrapFlavorFlags (scrap, kScrapFlavorTypeText, &sff);
3536 if (err == noErr)
3537 err = GetScrapFlavorSize (scrap, kScrapFlavorTypeText, &s);
3538 if (err == noErr && (data = (char*) alloca (s)))
3539 err = GetScrapFlavorData (scrap, kScrapFlavorTypeText, &s, data);
3540 UNBLOCK_INPUT;
3541 if (err != noErr || s == 0)
3542 return Qnil;
3543
3544 /* Emacs expects clipboard contents have Unix-style eol's */
3545 for (i = 0; i < s; i++)
3546 if (data[i] == '\r')
3547 data[i] = '\n';
3548
3549 return make_string (data, s);
3550#else /* not TARGET_API_MAC_CARBON */
3551 Lisp_Object value;
3552 Handle my_handle;
3553 long scrap_offset, rc, i;
3554
3555 my_handle = NewHandle (0); /* allocate 0-length data area */
3556
3557 rc = GetScrap (my_handle, 'TEXT', &scrap_offset);
3558 if (rc < 0)
3559 return Qnil;
3560
3561 HLock (my_handle);
3562
3563 /* Emacs expects clipboard contents have Unix-style eol's */
3564 for (i = 0; i < rc; i++)
3565 if ((*my_handle)[i] == '\r')
3566 (*my_handle)[i] = '\n';
3567
3568 value = make_string (*my_handle, rc);
3569
3570 HUnlock (my_handle);
3571
3572 DisposeHandle (my_handle);
3573
3574 return value;
3575#endif /* not TARGET_API_MAC_CARBON */
3576}
3577
3578
3579/* set interprogram-cut-function to mac-cut-function in mac-win.el
3580 to enable Emacs to write the top of the kill-ring to the Mac clipboard. */
3581DEFUN ("mac-cut-function", Fmac_cut_function, Smac_cut_function, 1, 2, 0,
3582 doc: /* Put the value of the string parameter to the Mac clipboard. */)
3583 (value, push)
3584 Lisp_Object value, push;
3585{
3586 char *buf;
3587 int len, i;
3588
3589 /* fixme: ignore the push flag for now */
3590
3591 CHECK_STRING (value);
3592
3593 len = SCHARS (value);
3594 buf = (char *) alloca (len+1);
3595 bcopy (SDATA (value), buf, len);
3596 buf[len] = '\0';
3597
3598 /* convert to Mac-style eol's before sending to clipboard */
3599 for (i = 0; i < len; i++)
3600 if (buf[i] == '\n')
3601 buf[i] = '\r';
3602
3603#if TARGET_API_MAC_CARBON
3604 {
3605 ScrapRef scrap;
3606
3607 BLOCK_INPUT;
3608 ClearCurrentScrap ();
3609 if (GetCurrentScrap (&scrap) != noErr)
3610 {
3611 UNBLOCK_INPUT;
3612 error ("cannot get current scrap");
3613 }
3614
3615 if (PutScrapFlavor (scrap, kScrapFlavorTypeText, kScrapFlavorMaskNone, len,
3616 buf) != noErr)
3617 {
3618 UNBLOCK_INPUT;
3619 error ("cannot put to scrap");
3620 }
3621 UNBLOCK_INPUT;
3622 }
3623#else /* not TARGET_API_MAC_CARBON */
3624 ZeroScrap ();
3625 PutScrap (len, 'TEXT', buf);
3626#endif /* not TARGET_API_MAC_CARBON */
3627
3628 return Qnil;
3629}
3630
3631
3632DEFUN ("x-selection-exists-p", Fx_selection_exists_p, Sx_selection_exists_p,
3633 0, 1, 0,
3634 doc: /* Whether there is an owner for the given X Selection.
3635The arg should be the name of the selection in question, typically one of
3636the symbols `PRIMARY', `SECONDARY', or `CLIPBOARD'.
3637\(Those are literal upper-case symbol names, since that's what X expects.)
3638For convenience, the symbol nil is the same as `PRIMARY',
3639and t is the same as `SECONDARY'. */)
3640 (selection)
3641 Lisp_Object selection;
3642{
3643 CHECK_SYMBOL (selection);
3644
3645 /* Return nil for PRIMARY and SECONDARY selections; for CLIPBOARD, check
3646 if the clipboard currently has valid text format contents. */
3647
3648 if (EQ (selection, QCLIPBOARD))
3649 {
3650 Lisp_Object val = Qnil;
3651
3652#if TARGET_API_MAC_CARBON 3517#if TARGET_API_MAC_CARBON
3653 ScrapRef scrap; 3518static Lisp_Object Qxml, Qmime_charset;
3654 ScrapFlavorFlags sff; 3519static Lisp_Object QNFD, QNFKD, QNFC, QNFKC, QHFS_plus_D, QHFS_plus_C;
3655
3656 BLOCK_INPUT;
3657 if (GetCurrentScrap (&scrap) == noErr)
3658 if (GetScrapFlavorFlags (scrap, kScrapFlavorTypeText, &sff) == noErr)
3659 val = Qt;
3660 UNBLOCK_INPUT;
3661#else /* not TARGET_API_MAC_CARBON */
3662 Handle my_handle;
3663 long rc, scrap_offset;
3664
3665 my_handle = NewHandle (0);
3666
3667 rc = GetScrap (my_handle, 'TEXT', &scrap_offset);
3668 if (rc >= 0)
3669 val = Qt;
3670
3671 DisposeHandle (my_handle);
3672#endif /* not TARGET_API_MAC_CARBON */
3673
3674 return val;
3675 }
3676 return Qnil;
3677}
3678
3679#if TARGET_API_MAC_CARBON
3680static Lisp_Object Qxml;
3681 3520
3682DEFUN ("mac-get-preference", Fmac_get_preference, Smac_get_preference, 1, 4, 0, 3521DEFUN ("mac-get-preference", Fmac_get_preference, Smac_get_preference, 1, 4, 0,
3683 doc: /* Return the application preference value for KEY. 3522 doc: /* Return the application preference value for KEY.
@@ -3792,6 +3631,218 @@ otherwise. */)
3792 3631
3793 return result; 3632 return result;
3794} 3633}
3634
3635
3636static CFStringEncoding
3637get_cfstring_encoding_from_lisp (obj)
3638 Lisp_Object obj;
3639{
3640 CFStringRef iana_name;
3641 CFStringEncoding encoding = kCFStringEncodingInvalidId;
3642
3643 if (INTEGERP (obj))
3644 return XINT (obj);
3645
3646 if (SYMBOLP (obj) && !NILP (obj) && !NILP (Fcoding_system_p (obj)))
3647 {
3648 Lisp_Object coding_spec, plist;
3649
3650 coding_spec = Fget (obj, Qcoding_system);
3651 plist = XVECTOR (coding_spec)->contents[3];
3652 obj = Fplist_get (XVECTOR (coding_spec)->contents[3], Qmime_charset);
3653 }
3654
3655 if (SYMBOLP (obj))
3656 obj = SYMBOL_NAME (obj);
3657
3658 if (STRINGP (obj))
3659 {
3660 iana_name = cfstring_create_with_string (obj);
3661 if (iana_name)
3662 {
3663 encoding = CFStringConvertIANACharSetNameToEncoding (iana_name);
3664 CFRelease (iana_name);
3665 }
3666 }
3667
3668 return encoding;
3669}
3670
3671#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020
3672static CFStringRef
3673cfstring_create_normalized (str, symbol)
3674 CFStringRef str;
3675 Lisp_Object symbol;
3676{
3677 int form = -1;
3678 TextEncodingVariant variant;
3679 float initial_mag = 0.0;
3680 CFStringRef result = NULL;
3681
3682 if (EQ (symbol, QNFD))
3683 form = kCFStringNormalizationFormD;
3684 else if (EQ (symbol, QNFKD))
3685 form = kCFStringNormalizationFormKD;
3686 else if (EQ (symbol, QNFC))
3687 form = kCFStringNormalizationFormC;
3688 else if (EQ (symbol, QNFKC))
3689 form = kCFStringNormalizationFormKC;
3690 else if (EQ (symbol, QHFS_plus_D))
3691 {
3692 variant = kUnicodeHFSPlusDecompVariant;
3693 initial_mag = 1.5;
3694 }
3695 else if (EQ (symbol, QHFS_plus_C))
3696 {
3697 variant = kUnicodeHFSPlusCompVariant;
3698 initial_mag = 1.0;
3699 }
3700
3701 if (form >= 0)
3702 {
3703 CFMutableStringRef mut_str = CFStringCreateMutableCopy (NULL, 0, str);
3704
3705 if (mut_str)
3706 {
3707 CFStringNormalize (mut_str, form);
3708 result = mut_str;
3709 }
3710 }
3711 else if (initial_mag > 0.0)
3712 {
3713 UnicodeToTextInfo uni = NULL;
3714 UnicodeMapping map;
3715 CFIndex length;
3716 UniChar *in_text, *buffer = NULL, *out_buf = NULL;
3717 OSErr err = noErr;
3718 ByteCount out_read, out_size, out_len;
3719
3720 map.unicodeEncoding = CreateTextEncoding (kTextEncodingUnicodeDefault,
3721 kUnicodeNoSubset,
3722 kTextEncodingDefaultFormat);
3723 map.otherEncoding = CreateTextEncoding (kTextEncodingUnicodeDefault,
3724 variant,
3725 kTextEncodingDefaultFormat);
3726 map.mappingVersion = kUnicodeUseLatestMapping;
3727
3728 length = CFStringGetLength (str);
3729 out_size = (int)((float)length * initial_mag) * sizeof (UniChar);
3730 if (out_size < 32)
3731 out_size = 32;
3732
3733 in_text = (UniChar *)CFStringGetCharactersPtr (str);
3734 if (in_text == NULL)
3735 {
3736 buffer = xmalloc (sizeof (UniChar) * length);
3737 if (buffer)
3738 {
3739 CFStringGetCharacters (str, CFRangeMake (0, length), buffer);
3740 in_text = buffer;
3741 }
3742 }
3743
3744 if (in_text)
3745 err = CreateUnicodeToTextInfo(&map, &uni);
3746 while (err == noErr)
3747 {
3748 out_buf = xmalloc (out_size);
3749 if (out_buf == NULL)
3750 err = mFulErr;
3751 else
3752 err = ConvertFromUnicodeToText (uni, length * sizeof (UniChar),
3753 in_text,
3754 kUnicodeDefaultDirectionMask,
3755 0, NULL, NULL, NULL,
3756 out_size, &out_read, &out_len,
3757 out_buf);
3758 if (err == noErr && out_read < length * sizeof (UniChar))
3759 {
3760 xfree (out_buf);
3761 out_size += length;
3762 }
3763 else
3764 break;
3765 }
3766 if (err == noErr)
3767 result = CFStringCreateWithCharacters (NULL, out_buf,
3768 out_len / sizeof (UniChar));
3769 if (uni)
3770 DisposeUnicodeToTextInfo (&uni);
3771 if (out_buf)
3772 xfree (out_buf);
3773 if (buffer)
3774 xfree (buffer);
3775 }
3776 else
3777 {
3778 result = str;
3779 CFRetain (result);
3780 }
3781
3782 return result;
3783}
3784#endif
3785
3786DEFUN ("mac-code-convert-string", Fmac_code_convert_string, Smac_code_convert_string, 3, 4, 0,
3787 doc: /* Convert STRING from SOURCE encoding to TARGET encoding.
3788The conversion is performed using the converter provided by the system.
3789Each encoding is specified by either a coding system symbol, a mime
3790charset string, or an integer as a CFStringEncoding value.
3791On Mac OS X 10.2 and later, you can do Unicode Normalization by
3792specifying the optional argument NORMALIZATION-FORM with a symbol NFD,
3793NFKD, NFC, NFKC, HFS+D, or HFS+C.
3794On successful conversion, returns the result string, else returns
3795nil. */)
3796 (string, source, target, normalization_form)
3797 Lisp_Object string, source, target, normalization_form;
3798{
3799 Lisp_Object result = Qnil;
3800 CFStringEncoding src_encoding, tgt_encoding;
3801 CFStringRef str = NULL;
3802 CFDataRef data = NULL;
3803
3804 CHECK_STRING (string);
3805 if (!INTEGERP (source) && !STRINGP (source))
3806 CHECK_SYMBOL (source);
3807 if (!INTEGERP (target) && !STRINGP (target))
3808 CHECK_SYMBOL (target);
3809 CHECK_SYMBOL (normalization_form);
3810
3811 BLOCK_INPUT;
3812
3813 src_encoding = get_cfstring_encoding_from_lisp (source);
3814 tgt_encoding = get_cfstring_encoding_from_lisp (target);
3815
3816 string = string_make_unibyte (string);
3817 if (src_encoding != kCFStringEncodingInvalidId
3818 && tgt_encoding != kCFStringEncodingInvalidId)
3819 str = CFStringCreateWithBytes (NULL, SDATA (string), SBYTES (string),
3820 src_encoding, true);
3821#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020
3822 if (str)
3823 {
3824 CFStringRef saved_str = str;
3825
3826 str = cfstring_create_normalized (saved_str, normalization_form);
3827 CFRelease (saved_str);
3828 }
3829#endif
3830 if (str)
3831 {
3832 data = CFStringCreateExternalRepresentation (NULL, str,
3833 tgt_encoding, '\0');
3834 CFRelease (str);
3835 }
3836 if (data)
3837 {
3838 result = cfdata_to_lisp (data);
3839 CFRelease (data);
3840 }
3841
3842 UNBLOCK_INPUT;
3843
3844 return result;
3845}
3795#endif /* TARGET_API_MAC_CARBON */ 3846#endif /* TARGET_API_MAC_CARBON */
3796 3847
3797 3848
@@ -4232,9 +4283,6 @@ mac_get_system_locale ()
4232void 4283void
4233syms_of_mac () 4284syms_of_mac ()
4234{ 4285{
4235 QCLIPBOARD = intern ("CLIPBOARD");
4236 staticpro (&QCLIPBOARD);
4237
4238#if TARGET_API_MAC_CARBON 4286#if TARGET_API_MAC_CARBON
4239 Qstring = intern ("string"); staticpro (&Qstring); 4287 Qstring = intern ("string"); staticpro (&Qstring);
4240 Qnumber = intern ("number"); staticpro (&Qnumber); 4288 Qnumber = intern ("number"); staticpro (&Qnumber);
@@ -4246,13 +4294,21 @@ syms_of_mac ()
4246 4294
4247 Qxml = intern ("xml"); 4295 Qxml = intern ("xml");
4248 staticpro (&Qxml); 4296 staticpro (&Qxml);
4297
4298 Qmime_charset = intern ("mime-charset");
4299 staticpro (&Qmime_charset);
4300
4301 QNFD = intern ("NFD"); staticpro (&QNFD);
4302 QNFKD = intern ("NFKD"); staticpro (&QNFKD);
4303 QNFC = intern ("NFC"); staticpro (&QNFC);
4304 QNFKC = intern ("NFKC"); staticpro (&QNFKC);
4305 QHFS_plus_D = intern ("HFS+D"); staticpro (&QHFS_plus_D);
4306 QHFS_plus_C = intern ("HFS+C"); staticpro (&QHFS_plus_C);
4249#endif 4307#endif
4250 4308
4251 defsubr (&Smac_paste_function);
4252 defsubr (&Smac_cut_function);
4253 defsubr (&Sx_selection_exists_p);
4254#if TARGET_API_MAC_CARBON 4309#if TARGET_API_MAC_CARBON
4255 defsubr (&Smac_get_preference); 4310 defsubr (&Smac_get_preference);
4311 defsubr (&Smac_code_convert_string);
4256#endif 4312#endif
4257 defsubr (&Smac_clear_font_name_table); 4313 defsubr (&Smac_clear_font_name_table);
4258 4314
diff --git a/src/macfns.c b/src/macfns.c
index 4247888fb18..75cd7e76576 100644
--- a/src/macfns.c
+++ b/src/macfns.c
@@ -2969,8 +2969,13 @@ If omitted or nil, that stands for the selected frame's display. */)
2969{ 2969{
2970 int mac_major_version; 2970 int mac_major_version;
2971 SInt32 response; 2971 SInt32 response;
2972 OSErr err;
2972 2973
2973 if (Gestalt (gestaltSystemVersion, &response) != noErr) 2974 BLOCK_INPUT;
2975 err = Gestalt (gestaltSystemVersion, &response);
2976 UNBLOCK_INPUT;
2977
2978 if (err != noErr)
2974 error ("Cannot get Mac OS version"); 2979 error ("Cannot get Mac OS version");
2975 2980
2976 mac_major_version = (response >> 8) & 0xff; 2981 mac_major_version = (response >> 8) & 0xff;
diff --git a/src/macgui.h b/src/macgui.h
index 5d4f1894e2e..939496aaeef 100644
--- a/src/macgui.h
+++ b/src/macgui.h
@@ -32,7 +32,9 @@ typedef unsigned long Time;
32#ifdef HAVE_CARBON 32#ifdef HAVE_CARBON
33#undef Z 33#undef Z
34#ifdef MAC_OSX 34#ifdef MAC_OSX
35#if ! HAVE_MKTIME || BROKEN_MKTIME
35#undef mktime 36#undef mktime
37#endif
36#undef DEBUG 38#undef DEBUG
37#undef free 39#undef free
38#undef malloc 40#undef malloc
@@ -43,8 +45,10 @@ typedef unsigned long Time;
43#undef min 45#undef min
44#undef init_process 46#undef init_process
45#include <Carbon/Carbon.h> 47#include <Carbon/Carbon.h>
48#if ! HAVE_MKTIME || BROKEN_MKTIME
46#undef mktime 49#undef mktime
47#define mktime emacs_mktime 50#define mktime emacs_mktime
51#endif
48#undef free 52#undef free
49#define free unexec_free 53#define free unexec_free
50#undef malloc 54#undef malloc
diff --git a/src/macros.c b/src/macros.c
index 09ae87b0a59..8b17c9fb261 100644
--- a/src/macros.c
+++ b/src/macros.c
@@ -31,25 +31,25 @@ Lisp_Object Qexecute_kbd_macro, Qkbd_macro_termination_hook;
31 31
32/* Kbd macro currently being executed (a string or vector). */ 32/* Kbd macro currently being executed (a string or vector). */
33 33
34Lisp_Object Vexecuting_macro; 34Lisp_Object Vexecuting_kbd_macro;
35 35
36/* Index of next character to fetch from that macro. */ 36/* Index of next character to fetch from that macro. */
37 37
38EMACS_INT executing_macro_index; 38EMACS_INT executing_kbd_macro_index;
39 39
40/* Number of successful iterations so far 40/* Number of successful iterations so far
41 for innermost keyboard macro. 41 for innermost keyboard macro.
42 This is not bound at each level, 42 This is not bound at each level,
43 so after an error, it describes the innermost interrupted macro. */ 43 so after an error, it describes the innermost interrupted macro. */
44 44
45int executing_macro_iterations; 45int executing_kbd_macro_iterations;
46 46
47/* This is the macro that was executing. 47/* This is the macro that was executing.
48 This is not bound at each level, 48 This is not bound at each level,
49 so after an error, it describes the innermost interrupted macro. 49 so after an error, it describes the innermost interrupted macro.
50 We use it only as a kind of flag, so no need to protect it. */ 50 We use it only as a kind of flag, so no need to protect it. */
51 51
52Lisp_Object executing_macro; 52Lisp_Object executing_kbd_macro;
53 53
54extern Lisp_Object real_this_command; 54extern Lisp_Object real_this_command;
55 55
@@ -114,7 +114,7 @@ macro before appending to it. */)
114 } 114 }
115 115
116 /* Must convert meta modifier when copying string to vector. */ 116 /* Must convert meta modifier when copying string to vector. */
117 cvt = STRINGP (current_kboard->Vlast_kbd_macro); 117 cvt = STRINGP (current_kboard->Vlast_kbd_macro);
118 for (i = 0; i < len; i++) 118 for (i = 0; i < len; i++)
119 { 119 {
120 Lisp_Object c; 120 Lisp_Object c;
@@ -285,17 +285,17 @@ each iteration of the macro. Iteration stops if LOOPFUNC returns nil. */)
285 return Qnil; 285 return Qnil;
286} 286}
287 287
288/* Restore Vexecuting_macro and executing_macro_index - called when 288/* Restore Vexecuting_kbd_macro and executing_kbd_macro_index.
289 the unwind-protect in Fexecute_kbd_macro gets invoked. */ 289 Called when the unwind-protect in Fexecute_kbd_macro gets invoked. */
290 290
291static Lisp_Object 291static Lisp_Object
292pop_kbd_macro (info) 292pop_kbd_macro (info)
293 Lisp_Object info; 293 Lisp_Object info;
294{ 294{
295 Lisp_Object tem; 295 Lisp_Object tem;
296 Vexecuting_macro = XCAR (info); 296 Vexecuting_kbd_macro = XCAR (info);
297 tem = XCDR (info); 297 tem = XCDR (info);
298 executing_macro_index = XINT (XCAR (tem)); 298 executing_kbd_macro_index = XINT (XCAR (tem));
299 real_this_command = XCDR (tem); 299 real_this_command = XCDR (tem);
300 Frun_hooks (1, &Qkbd_macro_termination_hook); 300 Frun_hooks (1, &Qkbd_macro_termination_hook);
301 return Qnil; 301 return Qnil;
@@ -318,7 +318,7 @@ each iteration of the macro. Iteration stops if LOOPFUNC returns nil. */)
318 struct gcpro gcpro1, gcpro2; 318 struct gcpro gcpro1, gcpro2;
319 int success_count = 0; 319 int success_count = 0;
320 320
321 executing_macro_iterations = 0; 321 executing_kbd_macro_iterations = 0;
322 322
323 if (!NILP (count)) 323 if (!NILP (count))
324 { 324 {
@@ -330,17 +330,17 @@ each iteration of the macro. Iteration stops if LOOPFUNC returns nil. */)
330 if (!STRINGP (final) && !VECTORP (final)) 330 if (!STRINGP (final) && !VECTORP (final))
331 error ("Keyboard macros must be strings or vectors"); 331 error ("Keyboard macros must be strings or vectors");
332 332
333 tem = Fcons (Vexecuting_macro, 333 tem = Fcons (Vexecuting_kbd_macro,
334 Fcons (make_number (executing_macro_index), 334 Fcons (make_number (executing_kbd_macro_index),
335 real_this_command)); 335 real_this_command));
336 record_unwind_protect (pop_kbd_macro, tem); 336 record_unwind_protect (pop_kbd_macro, tem);
337 337
338 GCPRO2 (final, loopfunc); 338 GCPRO2 (final, loopfunc);
339 do 339 do
340 { 340 {
341 Vexecuting_macro = final; 341 Vexecuting_kbd_macro = final;
342 executing_macro = final; 342 executing_kbd_macro = final;
343 executing_macro_index = 0; 343 executing_kbd_macro_index = 0;
344 344
345 current_kboard->Vprefix_arg = Qnil; 345 current_kboard->Vprefix_arg = Qnil;
346 346
@@ -354,16 +354,16 @@ each iteration of the macro. Iteration stops if LOOPFUNC returns nil. */)
354 354
355 command_loop_1 (); 355 command_loop_1 ();
356 356
357 executing_macro_iterations = ++success_count; 357 executing_kbd_macro_iterations = ++success_count;
358 358
359 QUIT; 359 QUIT;
360 } 360 }
361 while (--repeat 361 while (--repeat
362 && (STRINGP (Vexecuting_macro) || VECTORP (Vexecuting_macro))); 362 && (STRINGP (Vexecuting_kbd_macro) || VECTORP (Vexecuting_kbd_macro)));
363 363
364 executing_macro = Qnil; 364 executing_kbd_macro = Qnil;
365 365
366 real_this_command = Vexecuting_macro; 366 real_this_command = Vexecuting_kbd_macro;
367 367
368 UNGCPRO; 368 UNGCPRO;
369 return unbind_to (pdlcount, Qnil); 369 return unbind_to (pdlcount, Qnil);
@@ -372,8 +372,8 @@ each iteration of the macro. Iteration stops if LOOPFUNC returns nil. */)
372void 372void
373init_macros () 373init_macros ()
374{ 374{
375 Vexecuting_macro = Qnil; 375 Vexecuting_kbd_macro = Qnil;
376 executing_macro = Qnil; 376 executing_kbd_macro = Qnil;
377} 377}
378 378
379void 379void
@@ -396,15 +396,13 @@ syms_of_macros ()
396The value is the symbol `append' while appending to the definition of 396The value is the symbol `append' while appending to the definition of
397an existing macro. */); 397an existing macro. */);
398 398
399 DEFVAR_LISP ("executing-macro", &Vexecuting_macro, 399 DEFVAR_LISP ("executing-kbd-macro", &Vexecuting_kbd_macro,
400 doc: /* Currently executing keyboard macro (string or vector); nil if none executing. */); 400 doc: /* Currently executing keyboard macro (string or vector).
401This is nil when not executing a keyboard macro. */);
401 402
402 DEFVAR_INT ("executing-macro-index", &executing_macro_index, 403 DEFVAR_INT ("executing-kbd-macro-index", &executing_kbd_macro_index,
403 doc: /* Index in currently executing keyboard macro; undefined if none executing. */); 404 doc: /* Index in currently executing keyboard macro; undefined if none executing. */);
404 405
405 DEFVAR_LISP_NOPRO ("executing-kbd-macro", &Vexecuting_macro,
406 doc: /* Currently executing keyboard macro (string or vector); nil if none executing. */);
407
408 DEFVAR_KBOARD ("last-kbd-macro", Vlast_kbd_macro, 406 DEFVAR_KBOARD ("last-kbd-macro", Vlast_kbd_macro,
409 doc: /* Last kbd macro defined, as a string or vector; nil if none defined. */); 407 doc: /* Last kbd macro defined, as a string or vector; nil if none defined. */);
410} 408}
diff --git a/src/macros.h b/src/macros.h
index 41a32efe2e0..bf33ea8325b 100644
--- a/src/macros.h
+++ b/src/macros.h
@@ -21,24 +21,24 @@ Boston, MA 02111-1307, USA. */
21 21
22/* Kbd macro currently being executed (a string or vector). */ 22/* Kbd macro currently being executed (a string or vector). */
23 23
24extern Lisp_Object Vexecuting_macro; 24extern Lisp_Object Vexecuting_kbd_macro;
25 25
26/* Index of next character to fetch from that macro. */ 26/* Index of next character to fetch from that macro. */
27 27
28extern EMACS_INT executing_macro_index; 28extern EMACS_INT executing_kbd_macro_index;
29 29
30/* Number of successful iterations so far 30/* Number of successful iterations so far
31 for innermost keyboard macro. 31 for innermost keyboard macro.
32 This is not bound at each level, 32 This is not bound at each level,
33 so after an error, it describes the innermost interrupted macro. */ 33 so after an error, it describes the innermost interrupted macro. */
34 34
35extern int executing_macro_iterations; 35extern int executing_kbd_macro_iterations;
36 36
37/* This is the macro that was executing. 37/* This is the macro that was executing.
38 This is not bound at each level, 38 This is not bound at each level,
39 so after an error, it describes the innermost interrupted macro. */ 39 so after an error, it describes the innermost interrupted macro. */
40 40
41extern Lisp_Object executing_macro; 41extern Lisp_Object executing_kbd_macro;
42 42
43/* Finish defining the current keyboard macro. */ 43/* Finish defining the current keyboard macro. */
44 44
diff --git a/src/macselect.c b/src/macselect.c
new file mode 100644
index 00000000000..49246f7eddc
--- /dev/null
+++ b/src/macselect.c
@@ -0,0 +1,1121 @@
1/* Selection processing for Emacs on Mac OS.
2 Copyright (C) 2005 Free Software Foundation, Inc.
3
4This file is part of GNU Emacs.
5
6GNU Emacs is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)
9any later version.
10
11GNU Emacs is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Emacs; see the file COPYING. If not, write to
18the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19Boston, MA 02111-1307, USA. */
20
21#include <config.h>
22
23#include "lisp.h"
24#include "macterm.h"
25#include "blockinput.h"
26
27#if !TARGET_API_MAC_CARBON
28#include <Endian.h>
29typedef int ScrapRef;
30typedef ResType ScrapFlavorType;
31#endif /* !TARGET_API_MAC_CARBON */
32
33static OSErr get_scrap_from_symbol P_ ((Lisp_Object, int, ScrapRef *));
34static ScrapFlavorType get_flavor_type_from_symbol P_ ((Lisp_Object));
35static int valid_scrap_target_type_p P_ ((Lisp_Object));
36static OSErr clear_scrap P_ ((ScrapRef *));
37static OSErr put_scrap_string P_ ((ScrapRef, Lisp_Object, Lisp_Object));
38static OSErr put_scrap_private_timestamp P_ ((ScrapRef, unsigned long));
39static ScrapFlavorType scrap_has_target_type P_ ((ScrapRef, Lisp_Object));
40static Lisp_Object get_scrap_string P_ ((ScrapRef, Lisp_Object));
41static OSErr get_scrap_private_timestamp P_ ((ScrapRef, unsigned long *));
42static Lisp_Object get_scrap_target_type_list P_ ((ScrapRef));
43static void x_own_selection P_ ((Lisp_Object, Lisp_Object));
44static Lisp_Object x_get_local_selection P_ ((Lisp_Object, Lisp_Object, int));
45static Lisp_Object x_get_foreign_selection P_ ((Lisp_Object,
46 Lisp_Object,
47 Lisp_Object));
48EXFUN (Fx_selection_owner_p, 1);
49#ifdef MAC_OSX
50static OSStatus mac_handle_service_event P_ ((EventHandlerCallRef,
51 EventRef, void *));
52void init_service_handler P_ ((void));
53#endif
54
55Lisp_Object QPRIMARY, QSECONDARY, QTIMESTAMP, QTARGETS;
56
57static Lisp_Object Vx_lost_selection_functions;
58/* Coding system for communicating with other programs via scrap. */
59static Lisp_Object Vselection_coding_system;
60
61/* Coding system for the next communicating with other programs. */
62static Lisp_Object Vnext_selection_coding_system;
63
64static Lisp_Object Qforeign_selection;
65
66/* The timestamp of the last input event Emacs received from the
67 window server. */
68/* Defined in keyboard.c. */
69extern unsigned long last_event_timestamp;
70
71/* This is an association list whose elements are of the form
72 ( SELECTION-NAME SELECTION-VALUE SELECTION-TIMESTAMP FRAME)
73 SELECTION-NAME is a lisp symbol.
74 SELECTION-VALUE is the value that emacs owns for that selection.
75 It may be any kind of Lisp object.
76 SELECTION-TIMESTAMP is the time at which emacs began owning this selection,
77 as a cons of two 16-bit numbers (making a 32 bit time.)
78 FRAME is the frame for which we made the selection.
79 If there is an entry in this alist, and the data for the flavor
80 type SCRAP_FLAVOR_TYPE_EMACS_TIMESTAMP in the corresponding scrap
81 (if exists) coincides with SELECTION-TIMESTAMP, then it can be
82 assumed that Emacs owns that selection.
83 The only (eq) parts of this list that are visible from Lisp are the
84 selection-values. */
85static Lisp_Object Vselection_alist;
86
87#define SCRAP_FLAVOR_TYPE_EMACS_TIMESTAMP 'Etsp'
88
89/* This is an alist whose CARs are selection-types and whose CDRs are
90 the names of Lisp functions to call to convert the given Emacs
91 selection value to a string representing the given selection type.
92 This is for Lisp-level extension of the emacs selection
93 handling. */
94static Lisp_Object Vselection_converter_alist;
95
96/* A selection name (represented as a Lisp symbol) can be associated
97 with a named scrap via `mac-scrap-name' property. Likewise for a
98 selection type with a scrap flavor type via `mac-ostype'. */
99static Lisp_Object Qmac_scrap_name, Qmac_ostype;
100
101/* Selection name for communication via Services menu. */
102static Lisp_Object Vmac_services_selection;
103
104/* Get a reference to the scrap corresponding to the symbol SYM. The
105 reference is set to *SCRAP, and it becomes NULL if there's no
106 corresponding scrap. Clear the scrap if CLEAR_P is non-zero. */
107
108static OSErr
109get_scrap_from_symbol (sym, clear_p, scrap)
110 Lisp_Object sym;
111 int clear_p;
112 ScrapRef *scrap;
113{
114 OSErr err = noErr;
115 Lisp_Object str = Fget (sym, Qmac_scrap_name);
116
117 if (!STRINGP (str))
118 *scrap = NULL;
119 else
120 {
121#if TARGET_API_MAC_CARBON
122#ifdef MAC_OSX
123 CFStringRef scrap_name = cfstring_create_with_string (str);
124 OptionBits options = (clear_p ? kScrapClearNamedScrap
125 : kScrapGetNamedScrap);
126
127 err = GetScrapByName (scrap_name, options, scrap);
128 CFRelease (scrap_name);
129#else /* !MAC_OSX */
130 if (clear_p)
131 err = ClearCurrentScrap ();
132 if (err == noErr)
133 err = GetCurrentScrap (scrap);
134#endif /* !MAC_OSX */
135#else /* !TARGET_API_MAC_CARBON */
136 if (clear_p)
137 err = ZeroScrap ();
138 if (err == noErr)
139 *scrap = 1;
140#endif /* !TARGET_API_MAC_CARBON */
141 }
142
143 return err;
144}
145
146/* Get a scrap flavor type from the symbol SYM. Return 0 if no
147 corresponding flavor type. */
148
149static ScrapFlavorType
150get_flavor_type_from_symbol (sym)
151 Lisp_Object sym;
152{
153 ScrapFlavorType val;
154 Lisp_Object str = Fget (sym, Qmac_ostype);
155
156 if (STRINGP (str) && SBYTES (str) == 4)
157 return EndianU32_BtoN (*((UInt32 *) SDATA (str)));
158
159 return 0;
160}
161
162/* Check if the symbol SYM has a corresponding scrap flavor type. */
163
164static int
165valid_scrap_target_type_p (sym)
166 Lisp_Object sym;
167{
168 return get_flavor_type_from_symbol (sym) != 0;
169}
170
171/* Clear the scrap whose reference is *SCRAP. */
172
173static INLINE OSErr
174clear_scrap (scrap)
175 ScrapRef *scrap;
176{
177#if TARGET_API_MAC_CARBON
178#ifdef MAC_OSX
179 return ClearScrap (scrap);
180#else
181 return ClearCurrentScrap ();
182#endif
183#else /* !TARGET_API_MAC_CARBON */
184 return ZeroScrap ();
185#endif /* !TARGET_API_MAC_CARBON */
186}
187
188/* Put Lisp String STR to the scrap SCRAP. The target type is
189 specified by TYPE. */
190
191static OSErr
192put_scrap_string (scrap, type, str)
193 ScrapRef scrap;
194 Lisp_Object type, str;
195{
196 ScrapFlavorType flavor_type = get_flavor_type_from_symbol (type);
197
198 if (flavor_type == 0)
199 return noTypeErr;
200
201#if TARGET_API_MAC_CARBON
202 return PutScrapFlavor (scrap, flavor_type, kScrapFlavorMaskNone,
203 SBYTES (str), SDATA (str));
204#else /* !TARGET_API_MAC_CARBON */
205 return PutScrap (SBYTES (str), flavor_type, SDATA (str));
206#endif /* !TARGET_API_MAC_CARBON */
207}
208
209/* Put TIMESTAMP to the scrap SCRAP. The timestamp is used for
210 checking if the scrap is owned by the process. */
211
212static INLINE OSErr
213put_scrap_private_timestamp (scrap, timestamp)
214 ScrapRef scrap;
215 unsigned long timestamp;
216{
217#if TARGET_API_MAC_CARBON
218 return PutScrapFlavor (scrap, SCRAP_FLAVOR_TYPE_EMACS_TIMESTAMP,
219 kScrapFlavorMaskSenderOnly,
220 sizeof (timestamp), &timestamp);
221#else /* !TARGET_API_MAC_CARBON */
222 return PutScrap (sizeof (timestamp), SCRAP_FLAVOR_TYPE_EMACS_TIMESTAMP,
223 &timestamp);
224#endif /* !TARGET_API_MAC_CARBON */
225}
226
227/* Check if data for the target type TYPE is available in SCRAP. */
228
229static ScrapFlavorType
230scrap_has_target_type (scrap, type)
231 ScrapRef scrap;
232 Lisp_Object type;
233{
234 OSErr err;
235 ScrapFlavorType flavor_type = get_flavor_type_from_symbol (type);
236
237 if (flavor_type)
238 {
239#if TARGET_API_MAC_CARBON
240 ScrapFlavorFlags flags;
241
242 err = GetScrapFlavorFlags (scrap, flavor_type, &flags);
243 if (err != noErr)
244 flavor_type = 0;
245#else /* !TARGET_API_MAC_CARBON */
246 SInt32 size, offset;
247
248 size = GetScrap (NULL, flavor_type, &offset);
249 if (size < 0)
250 flavor_type = 0;
251#endif /* !TARGET_API_MAC_CARBON */
252 }
253
254 return flavor_type;
255}
256
257/* Get data for the target type TYPE from SCRAP and create a Lisp
258 string. Return nil if failed to get data. */
259
260static Lisp_Object
261get_scrap_string (scrap, type)
262 ScrapRef scrap;
263 Lisp_Object type;
264{
265 OSErr err;
266 Lisp_Object result = Qnil;
267 ScrapFlavorType flavor_type = get_flavor_type_from_symbol (type);
268#if TARGET_API_MAC_CARBON
269 Size size;
270
271 if (flavor_type)
272 {
273 err = GetScrapFlavorSize (scrap, flavor_type, &size);
274 if (err == noErr)
275 {
276 do
277 {
278 result = make_uninit_string (size);
279 err = GetScrapFlavorData (scrap, flavor_type,
280 &size, SDATA (result));
281 if (err != noErr)
282 result = Qnil;
283 else if (size < SBYTES (result))
284 result = make_unibyte_string (SDATA (result), size);
285 }
286 while (STRINGP (result) && size > SBYTES (result));
287 }
288 }
289#else
290 Handle handle;
291 SInt32 size, offset;
292
293 if (flavor_type)
294 size = GetScrap (NULL, flavor_type, &offset);
295 if (size >= 0)
296 {
297 handle = NewHandle (size);
298 HLock (handle);
299 size = GetScrap (handle, flavor_type, &offset);
300 if (size >= 0)
301 result = make_unibyte_string (*handle, size);
302 DisposeHandle (handle);
303 }
304#endif
305
306 return result;
307}
308
309/* Get timestamp from the scrap SCRAP and set to *TIMPSTAMP. */
310
311static OSErr
312get_scrap_private_timestamp (scrap, timestamp)
313 ScrapRef scrap;
314 unsigned long *timestamp;
315{
316 OSErr err = noErr;
317#if TARGET_API_MAC_CARBON
318 ScrapFlavorFlags flags;
319
320 err = GetScrapFlavorFlags (scrap, SCRAP_FLAVOR_TYPE_EMACS_TIMESTAMP, &flags);
321 if (err == noErr)
322 if (!(flags & kScrapFlavorMaskSenderOnly))
323 err = noTypeErr;
324 else
325 {
326 Size size = sizeof (*timestamp);
327
328 err = GetScrapFlavorData (scrap, SCRAP_FLAVOR_TYPE_EMACS_TIMESTAMP,
329 &size, timestamp);
330 if (err == noErr && size != sizeof (*timestamp))
331 err = noTypeErr;
332 }
333#else /* !TARGET_API_MAC_CARBON */
334 Handle handle;
335 SInt32 size, offset;
336
337 size = GetScrap (NULL, SCRAP_FLAVOR_TYPE_EMACS_TIMESTAMP, &offset);
338 if (size == sizeof (*timestamp))
339 {
340 handle = NewHandle (size);
341 HLock (handle);
342 size = GetScrap (handle, SCRAP_FLAVOR_TYPE_EMACS_TIMESTAMP, &offset);
343 if (size == sizeof (*timestamp))
344 *timestamp = *((unsigned long *) *handle);
345 DisposeHandle (handle);
346 }
347 if (size != sizeof (*timestamp))
348 err = noTypeErr;
349#endif /* !TARGET_API_MAC_CARBON */
350
351 return err;
352}
353
354/* Get the list of target types in SCRAP. The return value is a list
355 of target type symbols possibly followed by scrap flavor type
356 strings. */
357
358static Lisp_Object
359get_scrap_target_type_list (scrap)
360 ScrapRef scrap;
361{
362 Lisp_Object result = Qnil, rest, target_type;
363#if TARGET_API_MAC_CARBON
364 OSErr err;
365 UInt32 count, i, type;
366 ScrapFlavorInfo *flavor_info = NULL;
367 Lisp_Object strings = Qnil;
368
369 err = GetScrapFlavorCount (scrap, &count);
370 if (err == noErr)
371 flavor_info = xmalloc (sizeof (ScrapFlavorInfo) * count);
372 if (err == noErr && flavor_info)
373 {
374 err = GetScrapFlavorInfoList (scrap, &count, flavor_info);
375 if (err != noErr)
376 {
377 xfree (flavor_info);
378 flavor_info = NULL;
379 }
380 }
381#endif
382 for (rest = Vselection_converter_alist; CONSP (rest); rest = XCDR (rest))
383 {
384 ScrapFlavorType flavor_type = 0;
385
386 if (CONSP (XCAR (rest)) && SYMBOLP (target_type = XCAR (XCAR (rest)))
387 && (flavor_type = scrap_has_target_type (scrap, target_type)))
388 {
389 result = Fcons (target_type, result);
390#if TARGET_API_MAC_CARBON
391 for (i = 0; i < count; i++)
392 if (flavor_info[i].flavorType == flavor_type)
393 {
394 flavor_info[i].flavorType = 0;
395 break;
396 }
397#endif
398 }
399 }
400#if TARGET_API_MAC_CARBON
401 if (flavor_info)
402 {
403 for (i = 0; i < count; i++)
404 if (flavor_info[i].flavorType)
405 {
406 type = EndianU32_NtoB (flavor_info[i].flavorType);
407 strings = Fcons (make_unibyte_string ((char *) &type, 4), strings);
408 }
409 result = nconc2 (result, strings);
410 xfree (flavor_info);
411 }
412#endif
413
414 return result;
415}
416
417/* Do protocol to assert ourself as a selection owner.
418 Update the Vselection_alist so that we can reply to later requests for
419 our selection. */
420
421static void
422x_own_selection (selection_name, selection_value)
423 Lisp_Object selection_name, selection_value;
424{
425 OSErr err;
426 ScrapRef scrap;
427 struct gcpro gcpro1, gcpro2;
428 Lisp_Object rest, handler_fn, value, type;
429 int count;
430
431 CHECK_SYMBOL (selection_name);
432
433 GCPRO2 (selection_name, selection_value);
434
435 BLOCK_INPUT;
436
437 err = get_scrap_from_symbol (selection_name, 1, &scrap);
438 if (err == noErr && scrap)
439 {
440 /* Don't allow a quit within the converter.
441 When the user types C-g, he would be surprised
442 if by luck it came during a converter. */
443 count = SPECPDL_INDEX ();
444 specbind (Qinhibit_quit, Qt);
445
446 for (rest = Vselection_converter_alist; CONSP (rest); rest = XCDR (rest))
447 {
448 if (!(CONSP (XCAR (rest))
449 && SYMBOLP (type = XCAR (XCAR (rest)))
450 && valid_scrap_target_type_p (type)
451 && SYMBOLP (handler_fn = XCDR (XCAR (rest)))))
452 continue;
453
454 if (!NILP (handler_fn))
455 value = call3 (handler_fn, selection_name,
456 type, selection_value);
457
458 if (CONSP (value)
459 && EQ (XCAR (value), type)
460 && STRINGP (XCDR (value)))
461 err = put_scrap_string (scrap, type, XCDR (value));
462 }
463
464 unbind_to (count, Qnil);
465
466 if (err == noErr)
467 err = put_scrap_private_timestamp (scrap, last_event_timestamp);
468 }
469
470 UNBLOCK_INPUT;
471
472 UNGCPRO;
473
474 if (scrap && err != noErr)
475 error ("Can't set selection");
476
477 /* Now update the local cache */
478 {
479 Lisp_Object selection_time;
480 Lisp_Object selection_data;
481 Lisp_Object prev_value;
482
483 selection_time = long_to_cons (last_event_timestamp);
484 selection_data = Fcons (selection_name,
485 Fcons (selection_value,
486 Fcons (selection_time,
487 Fcons (selected_frame, Qnil))));
488 prev_value = assq_no_quit (selection_name, Vselection_alist);
489
490 Vselection_alist = Fcons (selection_data, Vselection_alist);
491
492 /* If we already owned the selection, remove the old selection data.
493 Perhaps we should destructively modify it instead.
494 Don't use Fdelq as that may QUIT. */
495 if (!NILP (prev_value))
496 {
497 Lisp_Object rest; /* we know it's not the CAR, so it's easy. */
498 for (rest = Vselection_alist; !NILP (rest); rest = Fcdr (rest))
499 if (EQ (prev_value, Fcar (XCDR (rest))))
500 {
501 XSETCDR (rest, Fcdr (XCDR (rest)));
502 break;
503 }
504 }
505 }
506}
507
508/* Given a selection-name and desired type, look up our local copy of
509 the selection value and convert it to the type.
510 The value is nil or a string.
511 This function is used both for remote requests (LOCAL_REQUEST is zero)
512 and for local x-get-selection-internal (LOCAL_REQUEST is nonzero).
513
514 This calls random Lisp code, and may signal or gc. */
515
516static Lisp_Object
517x_get_local_selection (selection_symbol, target_type, local_request)
518 Lisp_Object selection_symbol, target_type;
519 int local_request;
520{
521 Lisp_Object local_value;
522 Lisp_Object handler_fn, value, type, check;
523 int count;
524
525 if (NILP (Fx_selection_owner_p (selection_symbol)))
526 return Qnil;
527
528 local_value = assq_no_quit (selection_symbol, Vselection_alist);
529
530 /* TIMESTAMP is a special case 'cause that's easiest. */
531 if (EQ (target_type, QTIMESTAMP))
532 {
533 handler_fn = Qnil;
534 value = XCAR (XCDR (XCDR (local_value)));
535 }
536#if 0
537 else if (EQ (target_type, QDELETE))
538 {
539 handler_fn = Qnil;
540 Fx_disown_selection_internal
541 (selection_symbol,
542 XCAR (XCDR (XCDR (local_value))));
543 value = QNULL;
544 }
545#endif
546 else
547 {
548 /* Don't allow a quit within the converter.
549 When the user types C-g, he would be surprised
550 if by luck it came during a converter. */
551 count = SPECPDL_INDEX ();
552 specbind (Qinhibit_quit, Qt);
553
554 CHECK_SYMBOL (target_type);
555 handler_fn = Fcdr (Fassq (target_type, Vselection_converter_alist));
556 /* gcpro is not needed here since nothing but HANDLER_FN
557 is live, and that ought to be a symbol. */
558
559 if (!NILP (handler_fn))
560 value = call3 (handler_fn,
561 selection_symbol, (local_request ? Qnil : target_type),
562 XCAR (XCDR (local_value)));
563 else
564 value = Qnil;
565 unbind_to (count, Qnil);
566 }
567
568 /* Make sure this value is of a type that we could transmit
569 to another X client. */
570
571 check = value;
572 if (CONSP (value)
573 && SYMBOLP (XCAR (value)))
574 type = XCAR (value),
575 check = XCDR (value);
576
577 if (STRINGP (check)
578 || VECTORP (check)
579 || SYMBOLP (check)
580 || INTEGERP (check)
581 || NILP (value))
582 return value;
583 /* Check for a value that cons_to_long could handle. */
584 else if (CONSP (check)
585 && INTEGERP (XCAR (check))
586 && (INTEGERP (XCDR (check))
587 ||
588 (CONSP (XCDR (check))
589 && INTEGERP (XCAR (XCDR (check)))
590 && NILP (XCDR (XCDR (check))))))
591 return value;
592 else
593 return
594 Fsignal (Qerror,
595 Fcons (build_string ("invalid data returned by selection-conversion function"),
596 Fcons (handler_fn, Fcons (value, Qnil))));
597}
598
599
600/* Clear all selections that were made from frame F.
601 We do this when about to delete a frame. */
602
603void
604x_clear_frame_selections (f)
605 FRAME_PTR f;
606{
607 Lisp_Object frame;
608 Lisp_Object rest;
609
610 XSETFRAME (frame, f);
611
612 /* Otherwise, we're really honest and truly being told to drop it.
613 Don't use Fdelq as that may QUIT;. */
614
615 /* Delete elements from the beginning of Vselection_alist. */
616 while (!NILP (Vselection_alist)
617 && EQ (frame, Fcar (Fcdr (Fcdr (Fcdr (Fcar (Vselection_alist)))))))
618 {
619 /* Let random Lisp code notice that the selection has been stolen. */
620 Lisp_Object hooks, selection_symbol;
621
622 hooks = Vx_lost_selection_functions;
623 selection_symbol = Fcar (Fcar (Vselection_alist));
624
625 if (!EQ (hooks, Qunbound))
626 {
627 for (; CONSP (hooks); hooks = Fcdr (hooks))
628 call1 (Fcar (hooks), selection_symbol);
629#if 0 /* This can crash when deleting a frame
630 from x_connection_closed. Anyway, it seems unnecessary;
631 something else should cause a redisplay. */
632 redisplay_preserve_echo_area (21);
633#endif
634 }
635
636 Vselection_alist = Fcdr (Vselection_alist);
637 }
638
639 /* Delete elements after the beginning of Vselection_alist. */
640 for (rest = Vselection_alist; !NILP (rest); rest = Fcdr (rest))
641 if (EQ (frame, Fcar (Fcdr (Fcdr (Fcdr (Fcar (XCDR (rest))))))))
642 {
643 /* Let random Lisp code notice that the selection has been stolen. */
644 Lisp_Object hooks, selection_symbol;
645
646 hooks = Vx_lost_selection_functions;
647 selection_symbol = Fcar (Fcar (XCDR (rest)));
648
649 if (!EQ (hooks, Qunbound))
650 {
651 for (; CONSP (hooks); hooks = Fcdr (hooks))
652 call1 (Fcar (hooks), selection_symbol);
653#if 0 /* See above */
654 redisplay_preserve_echo_area (22);
655#endif
656 }
657 XSETCDR (rest, Fcdr (XCDR (rest)));
658 break;
659 }
660}
661
662/* Do protocol to read selection-data from the server.
663 Converts this to Lisp data and returns it. */
664
665static Lisp_Object
666x_get_foreign_selection (selection_symbol, target_type, time_stamp)
667 Lisp_Object selection_symbol, target_type, time_stamp;
668{
669 OSErr err;
670 ScrapRef scrap;
671 Lisp_Object result = Qnil;
672
673 BLOCK_INPUT;
674
675 err = get_scrap_from_symbol (selection_symbol, 0, &scrap);
676 if (err == noErr && scrap)
677 if (EQ (target_type, QTARGETS))
678 {
679 result = get_scrap_target_type_list (scrap);
680 result = Fvconcat (1, &result);
681 }
682 else
683 {
684 result = get_scrap_string (scrap, target_type);
685 if (STRINGP (result))
686 Fput_text_property (make_number (0), make_number (SBYTES (result)),
687 Qforeign_selection, target_type, result);
688 }
689
690 UNBLOCK_INPUT;
691
692 return result;
693}
694
695
696DEFUN ("x-own-selection-internal", Fx_own_selection_internal,
697 Sx_own_selection_internal, 2, 2, 0,
698 doc: /* Assert a selection of the given TYPE with the given VALUE.
699TYPE is a symbol, typically `PRIMARY', `SECONDARY', or `CLIPBOARD'.
700VALUE is typically a string, or a cons of two markers, but may be
701anything that the functions on `selection-converter-alist' know about. */)
702 (selection_name, selection_value)
703 Lisp_Object selection_name, selection_value;
704{
705 check_mac ();
706 CHECK_SYMBOL (selection_name);
707 if (NILP (selection_value)) error ("selection-value may not be nil");
708 x_own_selection (selection_name, selection_value);
709 return selection_value;
710}
711
712
713/* Request the selection value from the owner. If we are the owner,
714 simply return our selection value. If we are not the owner, this
715 will block until all of the data has arrived. */
716
717DEFUN ("x-get-selection-internal", Fx_get_selection_internal,
718 Sx_get_selection_internal, 2, 3, 0,
719 doc: /* Return text selected from some Mac window.
720SELECTION is a symbol, typically `PRIMARY', `SECONDARY', or `CLIPBOARD'.
721TYPE is the type of data desired, typically `STRING'.
722TIME_STAMP is ignored on Mac. */)
723 (selection_symbol, target_type, time_stamp)
724 Lisp_Object selection_symbol, target_type, time_stamp;
725{
726 Lisp_Object val = Qnil;
727 struct gcpro gcpro1, gcpro2;
728 GCPRO2 (target_type, val); /* we store newly consed data into these */
729 check_mac ();
730 CHECK_SYMBOL (selection_symbol);
731 CHECK_SYMBOL (target_type);
732
733 val = x_get_local_selection (selection_symbol, target_type, 1);
734
735 if (NILP (val))
736 {
737 val = x_get_foreign_selection (selection_symbol, target_type, time_stamp);
738 goto DONE;
739 }
740
741 if (CONSP (val)
742 && SYMBOLP (XCAR (val)))
743 {
744 val = XCDR (val);
745 if (CONSP (val) && NILP (XCDR (val)))
746 val = XCAR (val);
747 }
748 DONE:
749 UNGCPRO;
750 return val;
751}
752
753DEFUN ("x-disown-selection-internal", Fx_disown_selection_internal,
754 Sx_disown_selection_internal, 1, 2, 0,
755 doc: /* If we own the selection SELECTION, disown it.
756Disowning it means there is no such selection. */)
757 (selection, time)
758 Lisp_Object selection;
759 Lisp_Object time;
760{
761 OSErr err;
762 ScrapRef scrap;
763 Lisp_Object local_selection_data;
764
765 check_mac ();
766 CHECK_SYMBOL (selection);
767
768 if (NILP (Fx_selection_owner_p (selection)))
769 return Qnil; /* Don't disown the selection when we're not the owner. */
770
771 local_selection_data = assq_no_quit (selection, Vselection_alist);
772
773 /* Don't use Fdelq as that may QUIT;. */
774
775 if (EQ (local_selection_data, Fcar (Vselection_alist)))
776 Vselection_alist = Fcdr (Vselection_alist);
777 else
778 {
779 Lisp_Object rest;
780 for (rest = Vselection_alist; !NILP (rest); rest = Fcdr (rest))
781 if (EQ (local_selection_data, Fcar (XCDR (rest))))
782 {
783 XSETCDR (rest, Fcdr (XCDR (rest)));
784 break;
785 }
786 }
787
788 /* Let random lisp code notice that the selection has been stolen. */
789
790 {
791 Lisp_Object rest;
792 rest = Vx_lost_selection_functions;
793 if (!EQ (rest, Qunbound))
794 {
795 for (; CONSP (rest); rest = Fcdr (rest))
796 call1 (Fcar (rest), selection);
797 prepare_menu_bars ();
798 redisplay_preserve_echo_area (20);
799 }
800 }
801
802 BLOCK_INPUT;
803
804 err = get_scrap_from_symbol (selection, 0, &scrap);
805 if (err == noErr && scrap)
806 clear_scrap (&scrap);
807
808 UNBLOCK_INPUT;
809
810 return Qt;
811}
812
813
814DEFUN ("x-selection-owner-p", Fx_selection_owner_p, Sx_selection_owner_p,
815 0, 1, 0,
816 doc: /* Whether the current Emacs process owns the given Selection.
817The arg should be the name of the selection in question, typically one of
818the symbols `PRIMARY', `SECONDARY', or `CLIPBOARD'.
819For convenience, the symbol nil is the same as `PRIMARY',
820and t is the same as `SECONDARY'. */)
821 (selection)
822 Lisp_Object selection;
823{
824 OSErr err;
825 ScrapRef scrap;
826 Lisp_Object result = Qnil, local_selection_data;
827
828 check_mac ();
829 CHECK_SYMBOL (selection);
830 if (EQ (selection, Qnil)) selection = QPRIMARY;
831 if (EQ (selection, Qt)) selection = QSECONDARY;
832
833 local_selection_data = assq_no_quit (selection, Vselection_alist);
834
835 if (NILP (local_selection_data))
836 return Qnil;
837
838 BLOCK_INPUT;
839
840 err = get_scrap_from_symbol (selection, 0, &scrap);
841 if (err == noErr && scrap)
842 {
843 unsigned long timestamp;
844
845 err = get_scrap_private_timestamp (scrap, &timestamp);
846 if (err == noErr
847 && (timestamp
848 == cons_to_long (XCAR (XCDR (XCDR (local_selection_data))))))
849 result = Qt;
850 }
851 else
852 result = Qt;
853
854 UNBLOCK_INPUT;
855
856 return result;
857}
858
859DEFUN ("x-selection-exists-p", Fx_selection_exists_p, Sx_selection_exists_p,
860 0, 1, 0,
861 doc: /* Whether there is an owner for the given Selection.
862The arg should be the name of the selection in question, typically one of
863the symbols `PRIMARY', `SECONDARY', or `CLIPBOARD'.
864For convenience, the symbol nil is the same as `PRIMARY',
865and t is the same as `SECONDARY'. */)
866 (selection)
867 Lisp_Object selection;
868{
869 OSErr err;
870 ScrapRef scrap;
871 Lisp_Object result = Qnil, rest;
872
873 /* It should be safe to call this before we have an Mac frame. */
874 if (! FRAME_MAC_P (SELECTED_FRAME ()))
875 return Qnil;
876
877 CHECK_SYMBOL (selection);
878 if (!NILP (Fx_selection_owner_p (selection)))
879 return Qt;
880 if (EQ (selection, Qnil)) selection = QPRIMARY;
881 if (EQ (selection, Qt)) selection = QSECONDARY;
882
883 BLOCK_INPUT;
884
885 err = get_scrap_from_symbol (selection, 0, &scrap);
886 if (err == noErr && scrap)
887 for (rest = Vselection_converter_alist; CONSP (rest); rest = XCDR (rest))
888 {
889 if (CONSP (XCAR (rest)) && SYMBOLP (XCAR (XCAR (rest)))
890 && scrap_has_target_type (scrap, XCAR (XCAR (rest))))
891 {
892 result = Qt;
893 break;
894 }
895 }
896
897 UNBLOCK_INPUT;
898
899 return result;
900}
901
902
903#ifdef MAC_OSX
904void
905init_service_handler ()
906{
907 EventTypeSpec specs[] = {{kEventClassService, kEventServiceGetTypes},
908 {kEventClassService, kEventServiceCopy},
909 {kEventClassService, kEventServicePaste},
910 {kEventClassService, kEventServicePerform}};
911 InstallApplicationEventHandler (NewEventHandlerUPP (mac_handle_service_event),
912 GetEventTypeCount (specs), specs, NULL, NULL);
913}
914
915extern void mac_store_services_event P_ ((EventRef));
916
917static OSStatus
918mac_handle_service_event (call_ref, event, data)
919 EventHandlerCallRef call_ref;
920 EventRef event;
921 void *data;
922{
923 OSStatus err = noErr;
924 ScrapRef cur_scrap;
925
926 /* Check if Vmac_services_selection is a valid selection that has a
927 corresponding scrap. */
928 if (!SYMBOLP (Vmac_services_selection))
929 err = eventNotHandledErr;
930 else
931 err = get_scrap_from_symbol (Vmac_services_selection, 0, &cur_scrap);
932 if (!(err == noErr && cur_scrap))
933 return eventNotHandledErr;
934
935 switch (GetEventKind (event))
936 {
937 case kEventServiceGetTypes:
938 {
939 CFMutableArrayRef copy_types, paste_types;
940 CFStringRef type;
941 Lisp_Object rest;
942 ScrapFlavorType flavor_type;
943
944 /* Set paste types. */
945 err = GetEventParameter (event, kEventParamServicePasteTypes,
946 typeCFMutableArrayRef, NULL,
947 sizeof (CFMutableArrayRef), NULL,
948 &paste_types);
949 if (err == noErr)
950 for (rest = Vselection_converter_alist; CONSP (rest);
951 rest = XCDR (rest))
952 if (CONSP (XCAR (rest)) && SYMBOLP (XCAR (XCAR (rest)))
953 && (flavor_type =
954 get_flavor_type_from_symbol (XCAR (XCAR (rest)))))
955 {
956 type = CreateTypeStringWithOSType (flavor_type);
957 if (type)
958 {
959 CFArrayAppendValue (paste_types, type);
960 CFRelease (type);
961 }
962 }
963
964 /* Set copy types. */
965 err = GetEventParameter (event, kEventParamServiceCopyTypes,
966 typeCFMutableArrayRef, NULL,
967 sizeof (CFMutableArrayRef), NULL,
968 &copy_types);
969 if (err == noErr
970 && !NILP (Fx_selection_owner_p (Vmac_services_selection)))
971 for (rest = get_scrap_target_type_list (cur_scrap);
972 CONSP (rest) && SYMBOLP (XCAR (rest)); rest = XCDR (rest))
973 {
974 flavor_type = get_flavor_type_from_symbol (XCAR (rest));
975 if (flavor_type)
976 {
977 type = CreateTypeStringWithOSType (flavor_type);
978 if (type)
979 {
980 CFArrayAppendValue (copy_types, type);
981 CFRelease (type);
982 }
983 }
984 }
985 }
986 break;
987
988 case kEventServiceCopy:
989 {
990 ScrapRef specific_scrap;
991 Lisp_Object rest, data;
992
993 err = GetEventParameter (event, kEventParamScrapRef,
994 typeScrapRef, NULL,
995 sizeof (ScrapRef), NULL, &specific_scrap);
996 if (err == noErr
997 && !NILP (Fx_selection_owner_p (Vmac_services_selection)))
998 for (rest = get_scrap_target_type_list (cur_scrap);
999 CONSP (rest) && SYMBOLP (XCAR (rest)); rest = XCDR (rest))
1000 {
1001 data = get_scrap_string (cur_scrap, XCAR (rest));
1002 if (STRINGP (data))
1003 err = put_scrap_string (specific_scrap, XCAR (rest), data);
1004 }
1005 else
1006 err = eventNotHandledErr;
1007 }
1008 break;
1009
1010 case kEventServicePaste:
1011 case kEventServicePerform:
1012 {
1013 ScrapRef specific_scrap;
1014 Lisp_Object rest, data;
1015 int data_exists_p = 0;
1016
1017 err = GetEventParameter (event, kEventParamScrapRef, typeScrapRef,
1018 NULL, sizeof (ScrapRef), NULL,
1019 &specific_scrap);
1020 if (err == noErr)
1021 err = clear_scrap (&cur_scrap);
1022 if (err == noErr)
1023 for (rest = Vselection_converter_alist; CONSP (rest);
1024 rest = XCDR (rest))
1025 {
1026 if (! (CONSP (XCAR (rest)) && SYMBOLP (XCAR (XCAR (rest)))))
1027 continue;
1028 data = get_scrap_string (specific_scrap, XCAR (XCAR (rest)));
1029 if (STRINGP (data))
1030 {
1031 err = put_scrap_string (cur_scrap, XCAR (XCAR (rest)),
1032 data);
1033 if (err != noErr)
1034 break;
1035 data_exists_p = 1;
1036 }
1037 }
1038 if (err == noErr)
1039 if (data_exists_p)
1040 mac_store_application_menu_event (event);
1041 else
1042 err = eventNotHandledErr;
1043 }
1044 break;
1045 }
1046
1047 return err;
1048}
1049#endif
1050
1051
1052void
1053syms_of_macselect ()
1054{
1055 defsubr (&Sx_get_selection_internal);
1056 defsubr (&Sx_own_selection_internal);
1057 defsubr (&Sx_disown_selection_internal);
1058 defsubr (&Sx_selection_owner_p);
1059 defsubr (&Sx_selection_exists_p);
1060
1061 Vselection_alist = Qnil;
1062 staticpro (&Vselection_alist);
1063
1064 DEFVAR_LISP ("selection-converter-alist", &Vselection_converter_alist,
1065 doc: /* An alist associating selection-types with functions.
1066These functions are called to convert the selection, with three args:
1067the name of the selection (typically `PRIMARY', `SECONDARY', or `CLIPBOARD');
1068a desired type to which the selection should be converted;
1069and the local selection value (whatever was given to `x-own-selection').
1070
1071The function should return the value to send to the Scrap Manager
1072\(a string). A return value of nil
1073means that the conversion could not be done.
1074A return value which is the symbol `NULL'
1075means that a side-effect was executed,
1076and there is no meaningful selection value. */);
1077 Vselection_converter_alist = Qnil;
1078
1079 DEFVAR_LISP ("x-lost-selection-functions", &Vx_lost_selection_functions,
1080 doc: /* A list of functions to be called when Emacs loses a selection.
1081\(This happens when a Lisp program explicitly clears the selection.)
1082The functions are called with one argument, the selection type
1083\(a symbol, typically `PRIMARY', `SECONDARY', or `CLIPBOARD'). */);
1084 Vx_lost_selection_functions = Qnil;
1085
1086 DEFVAR_LISP ("selection-coding-system", &Vselection_coding_system,
1087 doc: /* Coding system for communicating with other programs.
1088When sending or receiving text via cut_buffer, selection, and clipboard,
1089the text is encoded or decoded by this coding system.
1090The default value is determined by the system script code. */);
1091 Vselection_coding_system = Qnil;
1092
1093 DEFVAR_LISP ("next-selection-coding-system", &Vnext_selection_coding_system,
1094 doc: /* Coding system for the next communication with other programs.
1095Usually, `selection-coding-system' is used for communicating with
1096other programs. But, if this variable is set, it is used for the
1097next communication only. After the communication, this variable is
1098set to nil. */);
1099 Vnext_selection_coding_system = Qnil;
1100
1101 DEFVAR_LISP ("mac-services-selection", &Vmac_services_selection,
1102 doc: /* Selection name for communication via Services menu. */);
1103 Vmac_services_selection = intern ("CLIPBOARD");
1104
1105 QPRIMARY = intern ("PRIMARY"); staticpro (&QPRIMARY);
1106 QSECONDARY = intern ("SECONDARY"); staticpro (&QSECONDARY);
1107 QTIMESTAMP = intern ("TIMESTAMP"); staticpro (&QTIMESTAMP);
1108 QTARGETS = intern ("TARGETS"); staticpro (&QTARGETS);
1109
1110 Qforeign_selection = intern ("foreign-selection");
1111 staticpro (&Qforeign_selection);
1112
1113 Qmac_scrap_name = intern ("mac-scrap-name");
1114 staticpro (&Qmac_scrap_name);
1115
1116 Qmac_ostype = intern ("mac-ostype");
1117 staticpro (&Qmac_ostype);
1118}
1119
1120/* arch-tag: f3c91ad8-99e0-4bd6-9eef-251b2f848732
1121 (do not change this comment) */
diff --git a/src/macterm.c b/src/macterm.c
index d98b6d2b784..114102f7648 100644
--- a/src/macterm.c
+++ b/src/macterm.c
@@ -7106,14 +7106,11 @@ x_find_ccl_program (fontp)
7106#define MIN_DOC_SIZE 64 7106#define MIN_DOC_SIZE 64
7107#define MAX_DOC_SIZE 32767 7107#define MAX_DOC_SIZE 32767
7108 7108
7109#if 0
7109/* sleep time for WaitNextEvent */ 7110/* sleep time for WaitNextEvent */
7110#define WNE_SLEEP_AT_SUSPEND 10 7111#define WNE_SLEEP_AT_SUSPEND 10
7111#define WNE_SLEEP_AT_RESUME 1 7112#define WNE_SLEEP_AT_RESUME 1
7112 7113
7113/* true when cannot handle any Mac OS events */
7114static int handling_window_update = 0;
7115
7116#if 0
7117/* the flag appl_is_suspended is used both for determining the sleep 7114/* the flag appl_is_suspended is used both for determining the sleep
7118 time to be passed to WaitNextEvent and whether the cursor should be 7115 time to be passed to WaitNextEvent and whether the cursor should be
7119 drawn when updating the display. The cursor is turned off when 7116 drawn when updating the display. The cursor is turned off when
@@ -7131,8 +7128,6 @@ static long app_sleep_time = WNE_SLEEP_AT_RESUME;
7131#define ABOUT_ALERT_ID 128 7128#define ABOUT_ALERT_ID 128
7132#define RAM_TOO_LARGE_ALERT_ID 129 7129#define RAM_TOO_LARGE_ALERT_ID 129
7133 7130
7134Boolean terminate_flag = false;
7135
7136/* Contains the string "reverse", which is a constant for mouse button emu.*/ 7131/* Contains the string "reverse", which is a constant for mouse button emu.*/
7137Lisp_Object Qreverse; 7132Lisp_Object Qreverse;
7138 7133
@@ -7188,11 +7183,11 @@ static DragTrackingHandlerUPP mac_do_track_dragUPP = NULL;
7188static DragReceiveHandlerUPP mac_do_receive_dragUPP = NULL; 7183static DragReceiveHandlerUPP mac_do_receive_dragUPP = NULL;
7189#endif 7184#endif
7190 7185
7186static Lisp_Object Qapplication, Qabout;
7191#if USE_CARBON_EVENTS 7187#if USE_CARBON_EVENTS
7192#ifdef MAC_OSX 7188#ifdef MAC_OSX
7193/* Preliminary Support for the OSX Services Menu */ 7189extern void init_service_handler ();
7194static OSStatus mac_handle_service_event (EventHandlerCallRef,EventRef,void*); 7190static Lisp_Object Qpreferences, Qservices, Qpaste, Qperform;
7195static void init_service_handler ();
7196#endif 7191#endif
7197/* Window Event Handler */ 7192/* Window Event Handler */
7198static pascal OSStatus mac_handle_window_event (EventHandlerCallRef, 7193static pascal OSStatus mac_handle_window_event (EventHandlerCallRef,
@@ -7350,11 +7345,13 @@ do_get_menus (void)
7350 SetMenuBar (menubar_handle); 7345 SetMenuBar (menubar_handle);
7351 DrawMenuBar (); 7346 DrawMenuBar ();
7352 7347
7348#if !TARGET_API_MAC_CARBON
7353 menu_handle = GetMenuHandle (M_APPLE); 7349 menu_handle = GetMenuHandle (M_APPLE);
7354 if(menu_handle != NULL) 7350 if(menu_handle != NULL)
7355 AppendResMenu (menu_handle,'DRVR'); 7351 AppendResMenu (menu_handle,'DRVR');
7356 else 7352 else
7357 abort (); 7353 abort ();
7354#endif
7358} 7355}
7359 7356
7360 7357
@@ -7426,8 +7423,6 @@ do_window_update (WindowPtr win)
7426 { 7423 {
7427 Rect r; 7424 Rect r;
7428 7425
7429 handling_window_update = 1;
7430
7431#if TARGET_API_MAC_CARBON 7426#if TARGET_API_MAC_CARBON
7432 { 7427 {
7433 RgnHandle region = NewRgn (); 7428 RgnHandle region = NewRgn ();
@@ -7443,8 +7438,6 @@ do_window_update (WindowPtr win)
7443 expose_frame (f, r.left, r.top, r.right - r.left, r.bottom - r.top); 7438 expose_frame (f, r.left, r.top, r.right - r.left, r.bottom - r.top);
7444 UpdateControls (win, win->visRgn); 7439 UpdateControls (win, win->visRgn);
7445#endif 7440#endif
7446
7447 handling_window_update = 0;
7448 } 7441 }
7449 } 7442 }
7450 7443
@@ -7513,11 +7506,11 @@ do_menu_choice (SInt32 menu_choice)
7513 menu_id = HiWord (menu_choice); 7506 menu_id = HiWord (menu_choice);
7514 menu_item = LoWord (menu_choice); 7507 menu_item = LoWord (menu_choice);
7515 7508
7516 if (menu_id == 0)
7517 return;
7518
7519 switch (menu_id) 7509 switch (menu_id)
7520 { 7510 {
7511 case 0:
7512 break;
7513
7521 case M_APPLE: 7514 case M_APPLE:
7522 do_apple_menu (menu_item); 7515 do_apple_menu (menu_item);
7523 break; 7516 break;
@@ -7767,105 +7760,157 @@ init_required_apple_events ()
7767 abort (); 7760 abort ();
7768} 7761}
7769 7762
7770#if USE_CARBON_EVENTS
7771#ifdef MAC_OSX
7772void 7763void
7773init_service_handler () 7764mac_store_application_menu_event (event)
7765#if USE_CARBON_EVENTS
7766 EventRef event;
7767#else
7768 UInt32 event;
7769#endif
7774{ 7770{
7775 EventTypeSpec specs[] = {{kEventClassService, kEventServiceGetTypes}, 7771 struct input_event buf;
7776 {kEventClassService, kEventServiceCopy}, 7772 Lisp_Object frame, entry;
7777 {kEventClassService, kEventServicePaste}};
7778 InstallApplicationEventHandler (NewEventHandlerUPP (mac_handle_service_event),
7779 3, specs, NULL, NULL);
7780}
7781 7773
7782/* 7774 EVENT_INIT (buf);
7783 MAC_TODO: Check to see if this is called by AEProcessDesc...
7784 */
7785OSStatus
7786mac_handle_service_event (EventHandlerCallRef callRef,
7787 EventRef event, void *data)
7788{
7789 OSStatus err = noErr;
7790 switch (GetEventKind (event))
7791 {
7792 case kEventServiceGetTypes:
7793 {
7794 CFMutableArrayRef copyTypes, pasteTypes;
7795 CFStringRef type;
7796 Boolean selection = true;
7797 /*
7798 GetEventParameter(event, kEventParamServicePasteTypes,
7799 typeCFMutableArrayRef, NULL,
7800 sizeof (CFMutableArrayRef), NULL, &pasteTypes);
7801 */
7802 GetEventParameter(event, kEventParamServiceCopyTypes,
7803 typeCFMutableArrayRef, NULL,
7804 sizeof (CFMutableArrayRef), NULL, &copyTypes);
7805 type = CreateTypeStringWithOSType (kScrapFlavorTypeText);
7806 if (type) {
7807 CFArrayAppendValue (copyTypes, type);
7808 //CFArrayAppendValue (pasteTypes, type);
7809 CFRelease (type);
7810 }
7811 }
7812 case kEventServiceCopy:
7813 {
7814 ScrapRef currentScrap, specificScrap;
7815 char * buf = "";
7816 Size byteCount = 0;
7817 7775
7818 GetCurrentScrap (&currentScrap); 7776 XSETFRAME (frame, mac_focus_frame (&one_mac_display_info));
7777 buf.kind = MENU_BAR_EVENT;
7778 buf.frame_or_window = frame;
7779 buf.arg = frame;
7780 kbd_buffer_store_event (&buf);
7819 7781
7820 err = GetScrapFlavorSize (currentScrap, kScrapFlavorTypeText, &byteCount); 7782 buf.arg = Qapplication;
7821 if (err == noErr) 7783 kbd_buffer_store_event (&buf);
7784
7785#if USE_CARBON_EVENTS
7786 switch (GetEventClass (event))
7787 {
7788#ifdef MAC_OSX
7789 case kEventClassService:
7790 buf.arg = Qservices;
7791 kbd_buffer_store_event (&buf);
7792 switch (GetEventKind (event))
7793 {
7794 case kEventServicePaste:
7795 entry = Qpaste;
7796 break;
7797
7798 case kEventServicePerform:
7822 { 7799 {
7823 void *buffer = xmalloc (byteCount); 7800 OSErr err;
7824 if (buffer != NULL) 7801 CFStringRef message;
7825 { 7802
7826 GetEventParameter (event, kEventParamScrapRef, typeScrapRef, NULL, 7803 err = GetEventParameter (event, kEventParamServiceMessageName,
7827 sizeof (ScrapRef), NULL, &specificScrap); 7804 typeCFStringRef, NULL,
7828 7805 sizeof (CFStringRef), NULL, &message);
7829 err = GetScrapFlavorData (currentScrap, kScrapFlavorTypeText, 7806 buf.arg = Qperform;
7830 &byteCount, buffer); 7807 kbd_buffer_store_event (&buf);
7831 if (err == noErr) 7808 if (err == noErr && message)
7832 PutScrapFlavor (specificScrap, kScrapFlavorTypeText, 7809 entry = intern (SDATA (cfstring_to_lisp (message)));
7833 kScrapFlavorMaskNone, byteCount, buffer); 7810 else
7834 xfree (buffer); 7811 entry = Qnil;
7835 }
7836 } 7812 }
7837 err = noErr; 7813 break;
7838 } 7814
7839 case kEventServicePaste: 7815 default:
7816 abort ();
7817 }
7818 break;
7819#endif /* MAC_OSX */
7820 case kEventClassCommand:
7840 { 7821 {
7841 /* 7822 HICommand command;
7842 // Get the current location 7823
7843 Size byteCount; 7824 GetEventParameter(event, kEventParamDirectObject, typeHICommand,
7844 ScrapRef specificScrap; 7825 NULL, sizeof (HICommand), NULL, &command);
7845 GetEventParameter(event, kEventParamScrapRef, typeScrapRef, NULL, 7826 switch (command.commandID)
7846 sizeof(ScrapRef), NULL, &specificScrap); 7827 {
7847 err = GetScrapFlavorSize(specificScrap, kScrapFlavorTypeText, &byteCount); 7828 case kHICommandAbout:
7848 if (err == noErr) { 7829 entry = Qabout;
7849 void * buffer = xmalloc(byteCount); 7830 break;
7850 if (buffer != NULL ) { 7831#ifdef MAC_OSX
7851 err = GetScrapFlavorData(specificScrap, kScrapFlavorTypeText, 7832 case kHICommandPreferences:
7852 &byteCount, buffer); 7833 entry = Qpreferences;
7853 if (err == noErr) { 7834 break;
7854 // Actually place in the buffer 7835#endif /* MAC_OSX */
7855 BLOCK_INPUT; 7836 case kHICommandQuit:
7856 // Get the current "selection" string here 7837 entry = Qquit;
7857 UNBLOCK_INPUT; 7838 break;
7858 } 7839 default:
7840 abort ();
7859 } 7841 }
7860 xfree(buffer);
7861 }
7862 */
7863 } 7842 }
7843 break;
7844
7845 default:
7846 abort ();
7847 }
7848#else /* USE_CARBON_EVENTS */
7849 switch (event)
7850 {
7851 case kHICommandAbout:
7852 entry = Qabout;
7853 break;
7854 case kHICommandQuit:
7855 entry = Qquit;
7856 break;
7857 default:
7858 abort ();
7864 } 7859 }
7865 return err;
7866}
7867#endif 7860#endif
7868 7861
7862 buf.arg = entry;
7863 kbd_buffer_store_event (&buf);
7864}
7865
7866#if USE_CARBON_EVENTS
7867static pascal OSStatus
7868mac_handle_command_event (next_handler, event, data)
7869 EventHandlerCallRef next_handler;
7870 EventRef event;
7871 void *data;
7872{
7873 HICommand command;
7874 OSErr result;
7875
7876 GetEventParameter(event, kEventParamDirectObject, typeHICommand, NULL,
7877 sizeof (HICommand), NULL, &command);
7878
7879 switch (command.commandID)
7880 {
7881 case kHICommandAbout:
7882#ifdef MAC_OSX
7883 case kHICommandPreferences:
7884#endif /* MAC_OSX */
7885 result = CallNextEventHandler (next_handler, event);
7886 if (result != eventNotHandledErr)
7887 return result;
7888
7889 mac_store_application_menu_event (event);
7890 return noErr;
7891
7892 default:
7893 break;
7894 }
7895
7896 return eventNotHandledErr;
7897}
7898
7899static OSErr
7900init_command_handler (window)
7901 WindowPtr window;
7902{
7903 OSErr err = noErr;
7904 EventTypeSpec specs[] = {{kEventClassCommand, kEventCommandProcess}};
7905 static EventHandlerUPP handle_command_eventUPP = NULL;
7906
7907 if (handle_command_eventUPP == NULL)
7908 handle_command_eventUPP = NewEventHandlerUPP (mac_handle_command_event);
7909 return InstallApplicationEventHandler (handle_command_eventUPP,
7910 GetEventTypeCount (specs), specs,
7911 NULL, NULL);
7912}
7913
7869static pascal OSStatus 7914static pascal OSStatus
7870mac_handle_window_event (next_handler, event, data) 7915mac_handle_window_event (next_handler, event, data)
7871 EventHandlerCallRef next_handler; 7916 EventHandlerCallRef next_handler;
@@ -7888,7 +7933,7 @@ mac_handle_window_event (next_handler, event, data)
7888 return result; 7933 return result;
7889 7934
7890 do_window_update (wp); 7935 do_window_update (wp);
7891 break; 7936 return noErr;
7892 7937
7893 case kEventWindowBoundsChanging: 7938 case kEventWindowBoundsChanging:
7894 result = CallNextEventHandler (next_handler, event); 7939 result = CallNextEventHandler (next_handler, event);
@@ -8267,14 +8312,30 @@ do_ae_print_documents (const AppleEvent *pAE, AppleEvent *reply, long refcon)
8267static pascal OSErr 8312static pascal OSErr
8268do_ae_quit_application (AppleEvent* message, AppleEvent *reply, long refcon) 8313do_ae_quit_application (AppleEvent* message, AppleEvent *reply, long refcon)
8269{ 8314{
8270 /* FixMe: Do we need an unwind-protect or something here? And what 8315#if USE_CARBON_EVENTS
8271 do we do about unsaved files. Currently just forces quit rather 8316 OSErr err;
8272 than doing recursive callback to get user input. */ 8317 EventRef event = NULL;
8318 static const HICommand quit_command = {kEventAttributeNone, kHICommandQuit};
8273 8319
8274 terminate_flag = true; 8320 err = CreateEvent (NULL, kEventClassCommand, kEventCommandProcess, 0,
8321 kEventAttributeUserEvent, &event);
8322 if (err == noErr)
8323 err = SetEventParameter (event, kEventParamDirectObject, typeHICommand,
8324 sizeof (HICommand), &quit_command);
8325 if (err == noErr)
8326 mac_store_application_menu_event (event);
8327 if (event)
8328 ReleaseEvent (event);
8329
8330 if (err == noErr)
8331 return noErr;
8332 else
8333 return errAEEventNotHandled;
8334#else
8335 mac_store_application_menu_event (kHICommandQuit);
8275 8336
8276 /* Fkill_emacs doesn't return. We have to return. (TI) */
8277 return noErr; 8337 return noErr;
8338#endif
8278} 8339}
8279 8340
8280 8341
@@ -8474,20 +8535,6 @@ XTread_socket (sd, expected, hold_quit)
8474 /* So people can tell when we have read the available input. */ 8535 /* So people can tell when we have read the available input. */
8475 input_signal_count++; 8536 input_signal_count++;
8476 8537
8477 /* Don't poll for events to process (specifically updateEvt) if
8478 window update currently already in progress. A call to redisplay
8479 (in do_window_update) can be preempted by another call to
8480 redisplay, causing blank regions to be left on the screen and the
8481 cursor to be left at strange places. */
8482 if (handling_window_update)
8483 {
8484 UNBLOCK_INPUT;
8485 return 0;
8486 }
8487
8488 if (terminate_flag)
8489 Fkill_emacs (make_number (1));
8490
8491#if USE_CARBON_EVENTS 8538#if USE_CARBON_EVENTS
8492 toolbox_dispatcher = GetEventDispatcherTarget (); 8539 toolbox_dispatcher = GetEventDispatcherTarget ();
8493 8540
@@ -9580,9 +9627,41 @@ mac_check_for_quit_char ()
9580 kbd_buffer_store_event (&e); 9627 kbd_buffer_store_event (&e);
9581 } 9628 }
9582} 9629}
9583
9584#endif /* MAC_OSX */ 9630#endif /* MAC_OSX */
9585 9631
9632static void
9633init_menu_bar ()
9634{
9635#ifdef MAC_OSX
9636 OSErr err;
9637 MenuRef menu;
9638 MenuItemIndex menu_index;
9639
9640 err = GetIndMenuItemWithCommandID (NULL, kHICommandQuit, 1,
9641 &menu, &menu_index);
9642 if (err == noErr)
9643 SetMenuItemCommandKey (menu, menu_index, false, 0);
9644#if USE_CARBON_EVENTS
9645 EnableMenuCommand (NULL, kHICommandPreferences);
9646 err = GetIndMenuItemWithCommandID (NULL, kHICommandPreferences, 1,
9647 &menu, &menu_index);
9648 if (err == noErr)
9649 {
9650 SetMenuItemCommandKey (menu, menu_index, false, 0);
9651 InsertMenuItemTextWithCFString (menu, NULL,
9652 0, kMenuItemAttrSeparator, 0);
9653 InsertMenuItemTextWithCFString (menu, CFSTR ("About Emacs"),
9654 0, 0, kHICommandAbout);
9655 }
9656#endif /* USE_CARBON_EVENTS */
9657#else /* !MAC_OSX */
9658#if USE_CARBON_EVENTS
9659 SetMenuItemCommandID (GetMenuHandle (M_APPLE), I_ABOUT, kHICommandAbout);
9660#endif
9661#endif
9662}
9663
9664
9586/* Set up use of X before we make the first connection. */ 9665/* Set up use of X before we make the first connection. */
9587 9666
9588extern frame_parm_handler mac_frame_parm_handlers[]; 9667extern frame_parm_handler mac_frame_parm_handlers[];
@@ -9699,13 +9778,17 @@ mac_initialize ()
9699#if TARGET_API_MAC_CARBON 9778#if TARGET_API_MAC_CARBON
9700 init_required_apple_events (); 9779 init_required_apple_events ();
9701 9780
9702#if USE_CARBON_EVENTS && defined (MAC_OSX) 9781#if USE_CARBON_EVENTS
9782#ifdef MAC_OSX
9703 init_service_handler (); 9783 init_service_handler ();
9704 9784
9705 init_quit_char_handler (); 9785 init_quit_char_handler ();
9706#endif 9786#endif /* MAC_OSX */
9707 9787
9708 DisableMenuCommand (NULL, kHICommandQuit); 9788 init_command_handler ();
9789
9790 init_menu_bar ();
9791#endif /* USE_CARBON_EVENTS */
9709 9792
9710#ifdef MAC_OSX 9793#ifdef MAC_OSX
9711 if (!inhibit_window_system) 9794 if (!inhibit_window_system)
@@ -9732,6 +9815,16 @@ syms_of_macterm ()
9732 Qsuper = intern ("super"); 9815 Qsuper = intern ("super");
9733 Fput (Qsuper, Qmodifier_value, make_number (super_modifier)); 9816 Fput (Qsuper, Qmodifier_value, make_number (super_modifier));
9734 9817
9818 Qapplication = intern ("application"); staticpro (&Qapplication);
9819 Qabout = intern ("about"); staticpro (&Qabout);
9820
9821#if USE_CARBON_EVENTS && defined (MAC_OSX)
9822 Qpreferences = intern ("preferences"); staticpro (&Qpreferences);
9823 Qservices = intern ("services"); staticpro (&Qservices);
9824 Qpaste = intern ("paste"); staticpro (&Qpaste);
9825 Qperform = intern ("perform"); staticpro (&Qperform);
9826#endif
9827
9735#ifdef MAC_OSX 9828#ifdef MAC_OSX
9736 Fprovide (intern ("mac-carbon"), Qnil); 9829 Fprovide (intern ("mac-carbon"), Qnil);
9737#endif 9830#endif
diff --git a/src/macterm.h b/src/macterm.h
index 48e028f9064..127c00b077b 100644
--- a/src/macterm.h
+++ b/src/macterm.h
@@ -620,6 +620,10 @@ extern void remove_window_handler P_ ((WindowPtr));
620#define FONT_TYPE_FOR_UNIBYTE(font, ch) 0 620#define FONT_TYPE_FOR_UNIBYTE(font, ch) 0
621#define FONT_TYPE_FOR_MULTIBYTE(font, ch) 0 621#define FONT_TYPE_FOR_MULTIBYTE(font, ch) 0
622 622
623/* Defined in macselect.c */
624
625extern void x_clear_frame_selections P_ ((struct frame *));
626
623/* Defined in mac.c. */ 627/* Defined in mac.c. */
624 628
625extern OSErr posix_pathname_to_fsspec P_ ((const char *, FSSpec *)); 629extern OSErr posix_pathname_to_fsspec P_ ((const char *, FSSpec *));
diff --git a/src/sysdep.c b/src/sysdep.c
index e7494a2755d..42179d97e82 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -1718,10 +1718,16 @@ get_frame_size (widthp, heightp)
1718#else 1718#else
1719#ifdef VMS 1719#ifdef VMS
1720 1720
1721 /* Use a fresh channel since the current one may have stale info
1722 (for example, from prior to a suspend); and to avoid a dependency
1723 in the init sequence. */
1724 int chan;
1721 struct sensemode tty; 1725 struct sensemode tty;
1722 1726
1723 SYS$QIOW (0, input_fd, IO$_SENSEMODE, &tty, 0, 0, 1727 SYS$ASSIGN (&input_dsc, &chan, 0, 0);
1724 &tty.class, 12, 0, 0, 0, 0); 1728 SYS$QIOW (0, chan, IO$_SENSEMODE, &tty, 0, 0,
1729 &tty.class, 12, 0, 0, 0, 0);
1730 SYS$DASSGN (chan);
1725 *widthp = tty.scr_wid; 1731 *widthp = tty.scr_wid;
1726 *heightp = tty.scr_len; 1732 *heightp = tty.scr_len;
1727 1733
diff --git a/src/sysselect.h b/src/sysselect.h
index 5aa9eb4aee7..4c52bba677a 100644
--- a/src/sysselect.h
+++ b/src/sysselect.h
@@ -18,7 +18,7 @@ along with GNU Emacs; see the file COPYING. If not, write to
18the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19Boston, MA 02111-1307, USA. */ 19Boston, MA 02111-1307, USA. */
20 20
21#ifdef HAVE_SYS_SELECT 21#ifdef HAVE_SYS_SELECT_H
22#include <sys/select.h> 22#include <sys/select.h>
23#endif 23#endif
24 24
diff --git a/src/window.c b/src/window.c
index 0cfd4162fd7..454d712726c 100644
--- a/src/window.c
+++ b/src/window.c
@@ -79,10 +79,6 @@ static int foreach_window_1 P_ ((struct window *,
79 void *)); 79 void *));
80static Lisp_Object window_list_1 P_ ((Lisp_Object, Lisp_Object, Lisp_Object)); 80static Lisp_Object window_list_1 P_ ((Lisp_Object, Lisp_Object, Lisp_Object));
81 81
82/* The value of `window-size-fixed'. */
83
84int window_size_fixed;
85
86/* This is the window in which the terminal's cursor should 82/* This is the window in which the terminal's cursor should
87 be left when nothing is being done with it. This must 83 be left when nothing is being done with it. This must
88 always be a leaf window, and its buffer is selected by 84 always be a leaf window, and its buffer is selected by
@@ -3267,9 +3263,10 @@ display_buffer_1 (window)
3267 3263
3268DEFUN ("special-display-p", Fspecial_display_p, Sspecial_display_p, 1, 1, 0, 3264DEFUN ("special-display-p", Fspecial_display_p, Sspecial_display_p, 1, 1, 0,
3269 doc: /* Returns non-nil if a buffer named BUFFER-NAME gets a special frame. 3265 doc: /* Returns non-nil if a buffer named BUFFER-NAME gets a special frame.
3270If the value is t, a frame would be created for that buffer 3266If the value is t, `display-buffer' or `pop-to-buffer' would create a
3271using the default frame parameters. If the value is a list, 3267special frame for that buffer using the default frame parameters.
3272it is a list of frame parameters that would be used 3268
3269If the value is a list, it is a list of frame parameters that would be used
3273to make a frame for that buffer. 3270to make a frame for that buffer.
3274The variables `special-display-buffer-names' 3271The variables `special-display-buffer-names'
3275and `special-display-regexps' control this. */) 3272and `special-display-regexps' control this. */)
@@ -3303,7 +3300,9 @@ and `special-display-regexps' control this. */)
3303} 3300}
3304 3301
3305DEFUN ("same-window-p", Fsame_window_p, Ssame_window_p, 1, 1, 0, 3302DEFUN ("same-window-p", Fsame_window_p, Ssame_window_p, 1, 1, 0,
3306 doc: /* Returns non-nil if a new buffer named BUFFER-NAME would use the same window. 3303 doc: /* Returns non-nil if a buffer named BUFFER-NAME would use the same window.
3304More precisely, if `display-buffer' or `pop-to-buffer' would display
3305that buffer in the selected window rather than (as usual) in some other window.
3307See `same-window-buffer-names' and `same-window-regexps'. */) 3306See `same-window-buffer-names' and `same-window-regexps'. */)
3308 (buffer_name) 3307 (buffer_name)
3309 Lisp_Object buffer_name; 3308 Lisp_Object buffer_name;
@@ -6669,6 +6668,7 @@ syms_of_window ()
6669{ 6668{
6670 Qwindow_size_fixed = intern ("window-size-fixed"); 6669 Qwindow_size_fixed = intern ("window-size-fixed");
6671 staticpro (&Qwindow_size_fixed); 6670 staticpro (&Qwindow_size_fixed);
6671 Fset (Qwindow_size_fixed, Qnil);
6672 6672
6673 staticpro (&Qwindow_configuration_change_hook); 6673 staticpro (&Qwindow_configuration_change_hook);
6674 Qwindow_configuration_change_hook 6674 Qwindow_configuration_change_hook
@@ -6751,7 +6751,8 @@ where `pop-up-frame-alist' would hold the default frame parameters. */);
6751 6751
6752 DEFVAR_LISP ("special-display-buffer-names", &Vspecial_display_buffer_names, 6752 DEFVAR_LISP ("special-display-buffer-names", &Vspecial_display_buffer_names,
6753 doc: /* *List of buffer names that should have their own special frames. 6753 doc: /* *List of buffer names that should have their own special frames.
6754Displaying a buffer whose name is in this list makes a special frame for it 6754Displaying a buffer with `display-buffer' or `pop-to-buffer',
6755if its name is in this list, makes a special frame for it
6755using `special-display-function'. See also `special-display-regexps'. 6756using `special-display-function'. See also `special-display-regexps'.
6756 6757
6757An element of the list can be a list instead of just a string. 6758An element of the list can be a list instead of just a string.
@@ -6776,9 +6777,9 @@ Those variables take precedence over this one. */);
6776 6777
6777 DEFVAR_LISP ("special-display-regexps", &Vspecial_display_regexps, 6778 DEFVAR_LISP ("special-display-regexps", &Vspecial_display_regexps,
6778 doc: /* *List of regexps saying which buffers should have their own special frames. 6779 doc: /* *List of regexps saying which buffers should have their own special frames.
6779If a buffer name matches one of these regexps, it gets its own frame. 6780When displaying a buffer with `display-buffer' or `pop-to-buffer',
6780Displaying a buffer whose name is in this list makes a special frame for it 6781if any regexp in this list matches the buffer name, it makes a
6781using `special-display-function'. 6782special frame for the buffer by calling `special-display-function'.
6782 6783
6783An element of the list can be a list instead of just a string. 6784An element of the list can be a list instead of just a string.
6784There are two ways to use a list as an element: 6785There are two ways to use a list as an element:
@@ -6877,16 +6878,6 @@ scroll as specified. */);
6877The selected frame is the one whose configuration has changed. */); 6878The selected frame is the one whose configuration has changed. */);
6878 Vwindow_configuration_change_hook = Qnil; 6879 Vwindow_configuration_change_hook = Qnil;
6879 6880
6880 DEFVAR_BOOL ("window-size-fixed", &window_size_fixed,
6881 doc: /* Non-nil in a buffer means windows displaying the buffer are fixed-size.
6882If the value is`height', then only the window's height is fixed.
6883If the value is `width', then only the window's width is fixed.
6884Any other non-nil value fixes both the width and the height.
6885Emacs won't change the size of any window displaying that buffer,
6886unless you explicitly change the size, or Emacs has no other choice. */);
6887 Fmake_variable_buffer_local (Qwindow_size_fixed);
6888 window_size_fixed = 0;
6889
6890 defsubr (&Sselected_window); 6881 defsubr (&Sselected_window);
6891 defsubr (&Sminibuffer_window); 6882 defsubr (&Sminibuffer_window);
6892 defsubr (&Swindow_minibuffer_p); 6883 defsubr (&Swindow_minibuffer_p);
diff --git a/src/xdisp.c b/src/xdisp.c
index c1bd7acb2a0..23898e78774 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -622,12 +622,6 @@ Lisp_Object Qmessage_truncate_lines;
622 622
623static int message_cleared_p; 623static int message_cleared_p;
624 624
625/* Non-zero means we want a hollow cursor in windows that are not
626 selected. Zero means there's no cursor in such windows. */
627
628Lisp_Object Vcursor_in_non_selected_windows;
629Lisp_Object Qcursor_in_non_selected_windows;
630
631/* How to blink the default frame cursor off. */ 625/* How to blink the default frame cursor off. */
632Lisp_Object Vblink_cursor_alist; 626Lisp_Object Vblink_cursor_alist;
633 627
@@ -5977,6 +5971,16 @@ move_it_in_display_line_to (it, to_charpos, to_x, op)
5977 { 5971 {
5978 int x, i, ascent = 0, descent = 0; 5972 int x, i, ascent = 0, descent = 0;
5979 5973
5974 /* Stop if we move beyond TO_CHARPOS (after an image or stretch glyph). */
5975 if ((op & MOVE_TO_POS) != 0
5976 && BUFFERP (it->object)
5977 && it->method == GET_FROM_BUFFER
5978 && IT_CHARPOS (*it) > to_charpos)
5979 {
5980 result = MOVE_POS_MATCH_OR_ZV;
5981 break;
5982 }
5983
5980 /* Stop when ZV reached. 5984 /* Stop when ZV reached.
5981 We used to stop here when TO_CHARPOS reached as well, but that is 5985 We used to stop here when TO_CHARPOS reached as well, but that is
5982 too soon if this glyph does not fit on this line. So we handle it 5986 too soon if this glyph does not fit on this line. So we handle it
@@ -8010,8 +8014,6 @@ set_message_1 (a1, a2, nbytes, multibyte_p)
8010 const char *s = (const char *) a1; 8014 const char *s = (const char *) a1;
8011 Lisp_Object string = a2; 8015 Lisp_Object string = a2;
8012 8016
8013 xassert (BEG == Z);
8014
8015 /* Change multibyteness of the echo buffer appropriately. */ 8017 /* Change multibyteness of the echo buffer appropriately. */
8016 if (message_enable_multibyte 8018 if (message_enable_multibyte
8017 != !NILP (current_buffer->enable_multibyte_characters)) 8019 != !NILP (current_buffer->enable_multibyte_characters))
@@ -14256,10 +14258,10 @@ dump_glyph_row (row, vpos, glyphs)
14256{ 14258{
14257 if (glyphs != 1) 14259 if (glyphs != 1)
14258 { 14260 {
14259 fprintf (stderr, "Row Start End Used oEI><O\\CTZFesm X Y W H V A P\n"); 14261 fprintf (stderr, "Row Start End Used oEI><\\CTZFesm X Y W H V A P\n");
14260 fprintf (stderr, "=======================================================================\n"); 14262 fprintf (stderr, "======================================================================\n");
14261 14263
14262 fprintf (stderr, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d%1.1d\ 14264 fprintf (stderr, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d\
14263%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n", 14265%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
14264 vpos, 14266 vpos,
14265 MATRIX_ROW_START_CHARPOS (row), 14267 MATRIX_ROW_START_CHARPOS (row),
@@ -14269,7 +14271,6 @@ dump_glyph_row (row, vpos, glyphs)
14269 row->enabled_p, 14271 row->enabled_p,
14270 row->truncated_on_left_p, 14272 row->truncated_on_left_p,
14271 row->truncated_on_right_p, 14273 row->truncated_on_right_p,
14272 row->overlay_arrow_p,
14273 row->continued_p, 14274 row->continued_p,
14274 MATRIX_ROW_CONTINUATION_LINE_P (row), 14275 MATRIX_ROW_CONTINUATION_LINE_P (row),
14275 row->displays_text_p, 14276 row->displays_text_p,
@@ -16189,7 +16190,7 @@ store_mode_line_string (string, lisp_string, copy_string, field_width, precision
16189 props = mode_line_string_face_prop; 16190 props = mode_line_string_face_prop;
16190 else if (!NILP (mode_line_string_face)) 16191 else if (!NILP (mode_line_string_face))
16191 { 16192 {
16192 Lisp_Object face = Fsafe_plist_get (props, Qface); 16193 Lisp_Object face = Fplist_get (props, Qface);
16193 props = Fcopy_sequence (props); 16194 props = Fcopy_sequence (props);
16194 if (NILP (face)) 16195 if (NILP (face))
16195 face = mode_line_string_face; 16196 face = mode_line_string_face;
@@ -16214,7 +16215,7 @@ store_mode_line_string (string, lisp_string, copy_string, field_width, precision
16214 Lisp_Object face; 16215 Lisp_Object face;
16215 if (NILP (props)) 16216 if (NILP (props))
16216 props = Ftext_properties_at (make_number (0), lisp_string); 16217 props = Ftext_properties_at (make_number (0), lisp_string);
16217 face = Fsafe_plist_get (props, Qface); 16218 face = Fplist_get (props, Qface);
16218 if (NILP (face)) 16219 if (NILP (face))
16219 face = mode_line_string_face; 16220 face = mode_line_string_face;
16220 else 16221 else
@@ -19023,14 +19024,14 @@ produce_stretch_glyph (it)
19023 plist = XCDR (it->object); 19024 plist = XCDR (it->object);
19024 19025
19025 /* Compute the width of the stretch. */ 19026 /* Compute the width of the stretch. */
19026 if ((prop = Fsafe_plist_get (plist, QCwidth), !NILP (prop)) 19027 if ((prop = Fplist_get (plist, QCwidth), !NILP (prop))
19027 && calc_pixel_width_or_height (&tem, it, prop, font, 1, 0)) 19028 && calc_pixel_width_or_height (&tem, it, prop, font, 1, 0))
19028 { 19029 {
19029 /* Absolute width `:width WIDTH' specified and valid. */ 19030 /* Absolute width `:width WIDTH' specified and valid. */
19030 zero_width_ok_p = 1; 19031 zero_width_ok_p = 1;
19031 width = (int)tem; 19032 width = (int)tem;
19032 } 19033 }
19033 else if (prop = Fsafe_plist_get (plist, QCrelative_width), 19034 else if (prop = Fplist_get (plist, QCrelative_width),
19034 NUMVAL (prop) > 0) 19035 NUMVAL (prop) > 0)
19035 { 19036 {
19036 /* Relative width `:relative-width FACTOR' specified and valid. 19037 /* Relative width `:relative-width FACTOR' specified and valid.
@@ -19054,7 +19055,7 @@ produce_stretch_glyph (it)
19054 x_produce_glyphs (&it2); 19055 x_produce_glyphs (&it2);
19055 width = NUMVAL (prop) * it2.pixel_width; 19056 width = NUMVAL (prop) * it2.pixel_width;
19056 } 19057 }
19057 else if ((prop = Fsafe_plist_get (plist, QCalign_to), !NILP (prop)) 19058 else if ((prop = Fplist_get (plist, QCalign_to), !NILP (prop))
19058 && calc_pixel_width_or_height (&tem, it, prop, font, 1, &align_to)) 19059 && calc_pixel_width_or_height (&tem, it, prop, font, 1, &align_to))
19059 { 19060 {
19060 if (it->glyph_row == NULL || !it->glyph_row->mode_line_p) 19061 if (it->glyph_row == NULL || !it->glyph_row->mode_line_p)
@@ -19074,13 +19075,13 @@ produce_stretch_glyph (it)
19074 width = 1; 19075 width = 1;
19075 19076
19076 /* Compute height. */ 19077 /* Compute height. */
19077 if ((prop = Fsafe_plist_get (plist, QCheight), !NILP (prop)) 19078 if ((prop = Fplist_get (plist, QCheight), !NILP (prop))
19078 && calc_pixel_width_or_height (&tem, it, prop, font, 0, 0)) 19079 && calc_pixel_width_or_height (&tem, it, prop, font, 0, 0))
19079 { 19080 {
19080 height = (int)tem; 19081 height = (int)tem;
19081 zero_height_ok_p = 1; 19082 zero_height_ok_p = 1;
19082 } 19083 }
19083 else if (prop = Fsafe_plist_get (plist, QCrelative_height), 19084 else if (prop = Fplist_get (plist, QCrelative_height),
19084 NUMVAL (prop) > 0) 19085 NUMVAL (prop) > 0)
19085 height = FONT_HEIGHT (font) * NUMVAL (prop); 19086 height = FONT_HEIGHT (font) * NUMVAL (prop);
19086 else 19087 else
@@ -19092,7 +19093,7 @@ produce_stretch_glyph (it)
19092 /* Compute percentage of height used for ascent. If 19093 /* Compute percentage of height used for ascent. If
19093 `:ascent ASCENT' is present and valid, use that. Otherwise, 19094 `:ascent ASCENT' is present and valid, use that. Otherwise,
19094 derive the ascent from the font in use. */ 19095 derive the ascent from the font in use. */
19095 if (prop = Fsafe_plist_get (plist, QCascent), 19096 if (prop = Fplist_get (plist, QCascent),
19096 NUMVAL (prop) > 0 && NUMVAL (prop) <= 100) 19097 NUMVAL (prop) > 0 && NUMVAL (prop) <= 100)
19097 ascent = height * NUMVAL (prop) / 100.0; 19098 ascent = height * NUMVAL (prop) / 100.0;
19098 else if (!NILP (prop) 19099 else if (!NILP (prop)
@@ -20273,7 +20274,7 @@ get_window_cursor_type (w, glyph, width, active_cursor)
20273 /* Use cursor-in-non-selected-windows for non-selected window or frame. */ 20274 /* Use cursor-in-non-selected-windows for non-selected window or frame. */
20274 if (non_selected) 20275 if (non_selected)
20275 { 20276 {
20276 alt_cursor = Fbuffer_local_value (Qcursor_in_non_selected_windows, w->buffer); 20277 alt_cursor = XBUFFER (w->buffer)->cursor_in_non_selected_windows;
20277 return get_specified_cursor_type (alt_cursor, width); 20278 return get_specified_cursor_type (alt_cursor, width);
20278 } 20279 }
20279 20280
@@ -21390,7 +21391,7 @@ note_mode_line_or_margin_highlight (w, x, y, area)
21390 if (IMAGEP (object)) 21391 if (IMAGEP (object))
21391 { 21392 {
21392 Lisp_Object image_map, hotspot; 21393 Lisp_Object image_map, hotspot;
21393 if ((image_map = Fsafe_plist_get (XCDR (object), QCmap), 21394 if ((image_map = Fplist_get (XCDR (object), QCmap),
21394 !NILP (image_map)) 21395 !NILP (image_map))
21395 && (hotspot = find_hot_spot (image_map, dx, dy), 21396 && (hotspot = find_hot_spot (image_map, dx, dy),
21396 CONSP (hotspot)) 21397 CONSP (hotspot))
@@ -21406,10 +21407,10 @@ note_mode_line_or_margin_highlight (w, x, y, area)
21406 if (CONSP (hotspot) 21407 if (CONSP (hotspot)
21407 && (plist = XCAR (hotspot), CONSP (plist))) 21408 && (plist = XCAR (hotspot), CONSP (plist)))
21408 { 21409 {
21409 pointer = Fsafe_plist_get (plist, Qpointer); 21410 pointer = Fplist_get (plist, Qpointer);
21410 if (NILP (pointer)) 21411 if (NILP (pointer))
21411 pointer = Qhand; 21412 pointer = Qhand;
21412 help = Fsafe_plist_get (plist, Qhelp_echo); 21413 help = Fplist_get (plist, Qhelp_echo);
21413 if (!NILP (help)) 21414 if (!NILP (help))
21414 { 21415 {
21415 help_echo_string = help; 21416 help_echo_string = help;
@@ -21421,7 +21422,7 @@ note_mode_line_or_margin_highlight (w, x, y, area)
21421 } 21422 }
21422 } 21423 }
21423 if (NILP (pointer)) 21424 if (NILP (pointer))
21424 pointer = Fsafe_plist_get (XCDR (object), QCpointer); 21425 pointer = Fplist_get (XCDR (object), QCpointer);
21425 } 21426 }
21426 21427
21427 if (STRINGP (string)) 21428 if (STRINGP (string))
@@ -21574,7 +21575,7 @@ note_mouse_highlight (f, x, y)
21574 if (img != NULL && IMAGEP (img->spec)) 21575 if (img != NULL && IMAGEP (img->spec))
21575 { 21576 {
21576 Lisp_Object image_map, hotspot; 21577 Lisp_Object image_map, hotspot;
21577 if ((image_map = Fsafe_plist_get (XCDR (img->spec), QCmap), 21578 if ((image_map = Fplist_get (XCDR (img->spec), QCmap),
21578 !NILP (image_map)) 21579 !NILP (image_map))
21579 && (hotspot = find_hot_spot (image_map, 21580 && (hotspot = find_hot_spot (image_map,
21580 glyph->slice.x + dx, 21581 glyph->slice.x + dx,
@@ -21592,10 +21593,10 @@ note_mouse_highlight (f, x, y)
21592 if (CONSP (hotspot) 21593 if (CONSP (hotspot)
21593 && (plist = XCAR (hotspot), CONSP (plist))) 21594 && (plist = XCAR (hotspot), CONSP (plist)))
21594 { 21595 {
21595 pointer = Fsafe_plist_get (plist, Qpointer); 21596 pointer = Fplist_get (plist, Qpointer);
21596 if (NILP (pointer)) 21597 if (NILP (pointer))
21597 pointer = Qhand; 21598 pointer = Qhand;
21598 help_echo_string = Fsafe_plist_get (plist, Qhelp_echo); 21599 help_echo_string = Fplist_get (plist, Qhelp_echo);
21599 if (!NILP (help_echo_string)) 21600 if (!NILP (help_echo_string))
21600 { 21601 {
21601 help_echo_window = window; 21602 help_echo_window = window;
@@ -21605,7 +21606,7 @@ note_mouse_highlight (f, x, y)
21605 } 21606 }
21606 } 21607 }
21607 if (NILP (pointer)) 21608 if (NILP (pointer))
21608 pointer = Fsafe_plist_get (XCDR (img->spec), QCpointer); 21609 pointer = Fplist_get (XCDR (img->spec), QCpointer);
21609 } 21610 }
21610 } 21611 }
21611 21612
@@ -22637,8 +22638,6 @@ syms_of_xdisp ()
22637 staticpro (&Qpoly); 22638 staticpro (&Qpoly);
22638 Qmessage_truncate_lines = intern ("message-truncate-lines"); 22639 Qmessage_truncate_lines = intern ("message-truncate-lines");
22639 staticpro (&Qmessage_truncate_lines); 22640 staticpro (&Qmessage_truncate_lines);
22640 Qcursor_in_non_selected_windows = intern ("cursor-in-non-selected-windows");
22641 staticpro (&Qcursor_in_non_selected_windows);
22642 Qgrow_only = intern ("grow-only"); 22641 Qgrow_only = intern ("grow-only");
22643 staticpro (&Qgrow_only); 22642 staticpro (&Qgrow_only);
22644 Qinhibit_menubar_update = intern ("inhibit-menubar-update"); 22643 Qinhibit_menubar_update = intern ("inhibit-menubar-update");
@@ -22932,12 +22931,6 @@ only, until their display becomes empty, at which point the windows
22932go back to their normal size. */); 22931go back to their normal size. */);
22933 Vresize_mini_windows = Qgrow_only; 22932 Vresize_mini_windows = Qgrow_only;
22934 22933
22935 DEFVAR_LISP ("cursor-in-non-selected-windows",
22936 &Vcursor_in_non_selected_windows,
22937 doc: /* *Cursor type to display in non-selected windows.
22938t means to use hollow box cursor. See `cursor-type' for other values. */);
22939 Vcursor_in_non_selected_windows = Qt;
22940
22941 DEFVAR_LISP ("blink-cursor-alist", &Vblink_cursor_alist, 22934 DEFVAR_LISP ("blink-cursor-alist", &Vblink_cursor_alist,
22942 doc: /* Alist specifying how to blink the cursor off. 22935 doc: /* Alist specifying how to blink the cursor off.
22943Each element has the form (ON-STATE . OFF-STATE). Whenever the 22936Each element has the form (ON-STATE . OFF-STATE). Whenever the
diff --git a/src/xfaces.c b/src/xfaces.c
index 4709d1cb285..edff936b08d 100644
--- a/src/xfaces.c
+++ b/src/xfaces.c
@@ -337,6 +337,8 @@ extern Lisp_Object Qmode_line;
337 337
338Lisp_Object Qface_alias; 338Lisp_Object Qface_alias;
339 339
340extern Lisp_Object Qcircular_list;
341
340/* Default stipple pattern used on monochrome displays. This stipple 342/* Default stipple pattern used on monochrome displays. This stipple
341 pattern is used on monochrome displays instead of shades of gray 343 pattern is used on monochrome displays instead of shades of gray
342 for a face background color. See `set-face-stipple' for possible 344 for a face background color. See `set-face-stipple' for possible
@@ -472,7 +474,7 @@ struct named_merge_point;
472 474
473static void map_tty_color P_ ((struct frame *, struct face *, 475static void map_tty_color P_ ((struct frame *, struct face *,
474 enum lface_attribute_index, int *)); 476 enum lface_attribute_index, int *));
475static Lisp_Object resolve_face_name P_ ((Lisp_Object)); 477static Lisp_Object resolve_face_name P_ ((Lisp_Object, int));
476static int may_use_scalable_font_p P_ ((const char *)); 478static int may_use_scalable_font_p P_ ((const char *));
477static void set_font_frame_param P_ ((Lisp_Object, Lisp_Object)); 479static void set_font_frame_param P_ ((Lisp_Object, Lisp_Object));
478static int better_font_p P_ ((int *, struct font_name *, struct font_name *, 480static int better_font_p P_ ((int *, struct font_name *, struct font_name *,
@@ -3266,27 +3268,47 @@ push_named_merge_point (struct named_merge_point *new_named_merge_point,
3266 3268
3267 3269
3268/* Resolve face name FACE_NAME. If FACE_NAME is a string, intern it 3270/* Resolve face name FACE_NAME. If FACE_NAME is a string, intern it
3269 to make it a symvol. If FACE_NAME is an alias for another face, 3271 to make it a symbol. If FACE_NAME is an alias for another face,
3270 return that face's name. */ 3272 return that face's name.
3273
3274 Return default face in case of errors. */
3271 3275
3272static Lisp_Object 3276static Lisp_Object
3273resolve_face_name (face_name) 3277resolve_face_name (face_name, signal_p)
3274 Lisp_Object face_name; 3278 Lisp_Object face_name;
3279 int signal_p;
3275{ 3280{
3276 Lisp_Object aliased; 3281 Lisp_Object orig_face;
3277 int alias_loop_max = 10; 3282 Lisp_Object tortoise, hare;
3278 3283
3279 if (STRINGP (face_name)) 3284 if (STRINGP (face_name))
3280 face_name = intern (SDATA (face_name)); 3285 face_name = intern (SDATA (face_name));
3281 3286
3282 while (SYMBOLP (face_name)) 3287 if (NILP (face_name) || !SYMBOLP (face_name))
3288 return face_name;
3289
3290 orig_face = face_name;
3291 tortoise = hare = face_name;
3292
3293 while (1)
3283 { 3294 {
3284 aliased = Fsafe_get (face_name, Qface_alias); 3295 face_name = hare;
3285 if (NILP (aliased)) 3296 hare = Fget (hare, Qface_alias);
3297 if (NILP (hare) || !SYMBOLP (hare))
3286 break; 3298 break;
3287 if (--alias_loop_max == 0) 3299
3300 face_name = hare;
3301 hare = Fget (hare, Qface_alias);
3302 if (NILP (hare) || !SYMBOLP (hare))
3288 break; 3303 break;
3289 face_name = aliased; 3304
3305 tortoise = Fget (tortoise, Qface_alias);
3306 if (EQ (hare, tortoise))
3307 {
3308 if (signal_p)
3309 Fsignal (Qcircular_list, Fcons (orig_face, Qnil));
3310 return Qdefault;
3311 }
3290 } 3312 }
3291 3313
3292 return face_name; 3314 return face_name;
@@ -3310,7 +3332,7 @@ lface_from_face_name (f, face_name, signal_p)
3310{ 3332{
3311 Lisp_Object lface; 3333 Lisp_Object lface;
3312 3334
3313 face_name = resolve_face_name (face_name); 3335 face_name = resolve_face_name (face_name, signal_p);
3314 3336
3315 if (f) 3337 if (f)
3316 lface = assq_no_quit (face_name, f->face_alist); 3338 lface = assq_no_quit (face_name, f->face_alist);
@@ -4061,7 +4083,7 @@ FRAME 0 means change the face on all frames, and change the default
4061 CHECK_SYMBOL (face); 4083 CHECK_SYMBOL (face);
4062 CHECK_SYMBOL (attr); 4084 CHECK_SYMBOL (attr);
4063 4085
4064 face = resolve_face_name (face); 4086 face = resolve_face_name (face, 1);
4065 4087
4066 /* If FRAME is 0, change face on all frames, and change the 4088 /* If FRAME is 0, change face on all frames, and change the
4067 default for new frames. */ 4089 default for new frames. */
diff --git a/src/xmenu.c b/src/xmenu.c
index 7d34c627692..85beb56d861 100644
--- a/src/xmenu.c
+++ b/src/xmenu.c
@@ -737,7 +737,7 @@ DEFUN ("x-popup-menu", Fx_popup_menu, Sx_popup_menu, 2, 2, 0,
737POSITION is a position specification. This is either a mouse button event 737POSITION is a position specification. This is either a mouse button event
738or a list ((XOFFSET YOFFSET) WINDOW) 738or a list ((XOFFSET YOFFSET) WINDOW)
739where XOFFSET and YOFFSET are positions in pixels from the top left 739where XOFFSET and YOFFSET are positions in pixels from the top left
740corner of WINDOW's frame. (WINDOW may be a frame object instead of a window.) 740corner of WINDOW. (WINDOW may be a window or a frame object.)
741This controls the position of the top left of the menu as a whole. 741This controls the position of the top left of the menu as a whole.
742If POSITION is t, it means to use the current mouse position. 742If POSITION is t, it means to use the current mouse position.
743 743
@@ -752,8 +752,11 @@ Otherwise, REAL-DEFINITION should be a valid key binding definition.
752 752
753You can also use a list of keymaps as MENU. 753You can also use a list of keymaps as MENU.
754 Then each keymap makes a separate pane. 754 Then each keymap makes a separate pane.
755When MENU is a keymap or a list of keymaps, the return value 755
756is a list of events. 756When MENU is a keymap or a list of keymaps, the return value is the
757list of events corresponding to the user's choice. Note that
758`x-popup-menu' does not actually execute the command bound to that
759sequence of events.
757 760
758Alternatively, you can specify a menu of multiple panes 761Alternatively, you can specify a menu of multiple panes
759 with a list of the form (TITLE PANE1 PANE2...), 762 with a list of the form (TITLE PANE1 PANE2...),
@@ -2889,6 +2892,9 @@ xmenu_show (f, x, y, for_click, keymaps, title, error)
2889 } 2892 }
2890 } 2893 }
2891 } 2894 }
2895 else if (!for_click)
2896 /* Make "Cancel" equivalent to C-g. */
2897 Fsignal (Qquit, Qnil);
2892 2898
2893 return Qnil; 2899 return Qnil;
2894} 2900}
@@ -3519,8 +3525,8 @@ xmenu_show (f, x, y, for_click, keymaps, title, error)
3519 entry = Qnil; 3525 entry = Qnil;
3520 break; 3526 break;
3521 case XM_NO_SELECT: 3527 case XM_NO_SELECT:
3522 /* Make "Cancel" equivalent to C-g unless this menu was popped up by 3528 /* Make "Cancel" equivalent to C-g unless FOR_CLICK (which means
3523 a mouse press. */ 3529 the menu was invoked with a mouse event as POSITION). */
3524 if (! for_click) 3530 if (! for_click)
3525 Fsignal (Qquit, Qnil); 3531 Fsignal (Qquit, Qnil);
3526 entry = Qnil; 3532 entry = Qnil;