* erc-stamp.el (erc-echo-timestamp):
[bpt/emacs.git] / lisp / term / mac-win.el
1 ;;; mac-win.el --- parse switches controlling interface with Mac window system -*-coding: iso-2022-7bit;-*-
2
3 ;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007 Free Software Foundation, Inc.
5
6 ;; Author: Andrew Choi <akochoi@mac.com>
7 ;; Keywords: terminals
8
9 ;; This file is part of GNU Emacs.
10
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 3, or (at your option)
14 ;; any later version.
15
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
25
26 ;;; Commentary:
27
28 ;; Mac-win.el: this file is loaded from ../lisp/startup.el when it recognizes
29 ;; that Mac windows are to be used. Command line switches are parsed and those
30 ;; pertaining to Mac are processed and removed from the command line. The
31 ;; Mac display is opened and hooks are set for popping up the initial window.
32
33 ;; startup.el will then examine startup files, and eventually call the hooks
34 ;; which create the first window(s).
35
36 ;;; Code:
37 \f
38 ;; These are the standard X switches from the Xt Initialize.c file of
39 ;; Release 4.
40
41 ;; Command line Resource Manager string
42
43 ;; +rv *reverseVideo
44 ;; +synchronous *synchronous
45 ;; -background *background
46 ;; -bd *borderColor
47 ;; -bg *background
48 ;; -bordercolor *borderColor
49 ;; -borderwidth .borderWidth
50 ;; -bw .borderWidth
51 ;; -display .display
52 ;; -fg *foreground
53 ;; -fn *font
54 ;; -font *font
55 ;; -foreground *foreground
56 ;; -geometry .geometry
57 ;; -iconic .iconic
58 ;; -name .name
59 ;; -reverse *reverseVideo
60 ;; -rv *reverseVideo
61 ;; -selectionTimeout .selectionTimeout
62 ;; -synchronous *synchronous
63 ;; -xrm
64
65 ;; An alist of X options and the function which handles them. See
66 ;; ../startup.el.
67
68 ;; (if (not (eq window-system 'mac))
69 ;; (error "%s: Loading mac-win.el but not compiled for Mac" (invocation-name)))
70
71 (require 'frame)
72 (require 'mouse)
73 (require 'scroll-bar)
74 (require 'faces)
75 (require 'select)
76 (require 'menu-bar)
77 (require 'fontset)
78 (require 'dnd)
79
80 (defvar mac-charset-info-alist)
81 (defvar mac-service-selection)
82 (defvar mac-system-script-code)
83 (defvar mac-apple-event-map)
84 (defvar mac-font-panel-mode)
85 (defvar mac-ts-active-input-overlay)
86 (defvar x-invocation-args)
87 (declare-function mac-code-convert-string "mac.c")
88 (declare-function mac-coerce-ae-data "mac.c")
89 (declare-function mac-resume-apple-event "macselect.c")
90 ;; Suppress warning when compiling on non-Mac.
91 (declare-function mac-font-panel-mode "mac-win.el")
92 (declare-function mac-atsu-font-face-attributes "macfns.c")
93 (declare-function mac-ae-set-reply-parameter "macselect.c")
94 (declare-function mac-clear-font-name-table "macfns.c")
95
96 (defvar x-command-line-resources nil)
97
98 ;; Handler for switches of the form "-switch value" or "-switch".
99 (defun x-handle-switch (switch)
100 (let ((aelt (assoc switch command-line-x-option-alist)))
101 (if aelt
102 (let ((param (nth 3 aelt))
103 (value (nth 4 aelt)))
104 (if value
105 (setq default-frame-alist
106 (cons (cons param value)
107 default-frame-alist))
108 (setq default-frame-alist
109 (cons (cons param
110 (car x-invocation-args))
111 default-frame-alist)
112 x-invocation-args (cdr x-invocation-args)))))))
113
114 ;; Handler for switches of the form "-switch n"
115 (defun x-handle-numeric-switch (switch)
116 (let ((aelt (assoc switch command-line-x-option-alist)))
117 (if aelt
118 (let ((param (nth 3 aelt)))
119 (setq default-frame-alist
120 (cons (cons param
121 (string-to-number (car x-invocation-args)))
122 default-frame-alist)
123 x-invocation-args
124 (cdr x-invocation-args))))))
125
126 ;; Handle options that apply to initial frame only
127 (defun x-handle-initial-switch (switch)
128 (let ((aelt (assoc switch command-line-x-option-alist)))
129 (if aelt
130 (let ((param (nth 3 aelt))
131 (value (nth 4 aelt)))
132 (if value
133 (setq initial-frame-alist
134 (cons (cons param value)
135 initial-frame-alist))
136 (setq initial-frame-alist
137 (cons (cons param
138 (car x-invocation-args))
139 initial-frame-alist)
140 x-invocation-args (cdr x-invocation-args)))))))
141
142 ;; Make -iconic apply only to the initial frame!
143 (defun x-handle-iconic (switch)
144 (setq initial-frame-alist
145 (cons '(visibility . icon) initial-frame-alist)))
146
147 ;; Handle the -xrm option.
148 (defun x-handle-xrm-switch (switch)
149 (unless (consp x-invocation-args)
150 (error "%s: missing argument to `%s' option" (invocation-name) switch))
151 (setq x-command-line-resources
152 (if (null x-command-line-resources)
153 (car x-invocation-args)
154 (concat x-command-line-resources "\n" (car x-invocation-args))))
155 (setq x-invocation-args (cdr x-invocation-args)))
156
157 ;; Handle the geometry option
158 (defun x-handle-geometry (switch)
159 (let* ((geo (x-parse-geometry (car x-invocation-args)))
160 (left (assq 'left geo))
161 (top (assq 'top geo))
162 (height (assq 'height geo))
163 (width (assq 'width geo)))
164 (if (or height width)
165 (setq default-frame-alist
166 (append default-frame-alist
167 '((user-size . t))
168 (if height (list height))
169 (if width (list width)))
170 initial-frame-alist
171 (append initial-frame-alist
172 '((user-size . t))
173 (if height (list height))
174 (if width (list width)))))
175 (if (or left top)
176 (setq initial-frame-alist
177 (append initial-frame-alist
178 '((user-position . t))
179 (if left (list left))
180 (if top (list top)))))
181 (setq x-invocation-args (cdr x-invocation-args))))
182
183 ;; Handle the -name option. Set the variable x-resource-name
184 ;; to the option's operand; set the name of
185 ;; the initial frame, too.
186 (defun x-handle-name-switch (switch)
187 (or (consp x-invocation-args)
188 (error "%s: missing argument to `%s' option" (invocation-name) switch))
189 (setq x-resource-name (car x-invocation-args)
190 x-invocation-args (cdr x-invocation-args))
191 (setq initial-frame-alist (cons (cons 'name x-resource-name)
192 initial-frame-alist)))
193
194 (defvar x-display-name nil
195 "The display name specifying server and frame.")
196
197 (defun x-handle-display (switch)
198 (setq x-display-name (car x-invocation-args)
199 x-invocation-args (cdr x-invocation-args)))
200
201 (defun x-handle-args (args)
202 "Process the X-related command line options in ARGS.
203 This is done before the user's startup file is loaded. They are copied to
204 `x-invocation-args', from which the X-related things are extracted, first
205 the switch (e.g., \"-fg\") in the following code, and possible values
206 \(e.g., \"black\") in the option handler code (e.g., x-handle-switch).
207 This function returns ARGS minus the arguments that have been processed."
208 ;; We use ARGS to accumulate the args that we don't handle here, to return.
209 (setq x-invocation-args args
210 args nil)
211 (while (and x-invocation-args
212 (not (equal (car x-invocation-args) "--")))
213 (let* ((this-switch (car x-invocation-args))
214 (orig-this-switch this-switch)
215 completion argval aelt handler)
216 (setq x-invocation-args (cdr x-invocation-args))
217 ;; Check for long options with attached arguments
218 ;; and separate out the attached option argument into argval.
219 (if (string-match "^--[^=]*=" this-switch)
220 (setq argval (substring this-switch (match-end 0))
221 this-switch (substring this-switch 0 (1- (match-end 0)))))
222 ;; Complete names of long options.
223 (if (string-match "^--" this-switch)
224 (progn
225 (setq completion (try-completion this-switch command-line-x-option-alist))
226 (if (eq completion t)
227 ;; Exact match for long option.
228 nil
229 (if (stringp completion)
230 (let ((elt (assoc completion command-line-x-option-alist)))
231 ;; Check for abbreviated long option.
232 (or elt
233 (error "Option `%s' is ambiguous" this-switch))
234 (setq this-switch completion))))))
235 (setq aelt (assoc this-switch command-line-x-option-alist))
236 (if aelt (setq handler (nth 2 aelt)))
237 (if handler
238 (if argval
239 (let ((x-invocation-args
240 (cons argval x-invocation-args)))
241 (funcall handler this-switch))
242 (funcall handler this-switch))
243 (setq args (cons orig-this-switch args)))))
244 (nconc (nreverse args) x-invocation-args))
245
246 \f
247 ;;
248 ;; Standard Mac cursor shapes
249 ;;
250
251 (defconst mac-pointer-arrow 0)
252 (defconst mac-pointer-copy-arrow 1)
253 (defconst mac-pointer-alias-arrow 2)
254 (defconst mac-pointer-contextual-menu-arrow 3)
255 (defconst mac-pointer-I-beam 4)
256 (defconst mac-pointer-cross 5)
257 (defconst mac-pointer-plus 6)
258 (defconst mac-pointer-watch 7)
259 (defconst mac-pointer-closed-hand 8)
260 (defconst mac-pointer-open-hand 9)
261 (defconst mac-pointer-pointing-hand 10)
262 (defconst mac-pointer-counting-up-hand 11)
263 (defconst mac-pointer-counting-down-hand 12)
264 (defconst mac-pointer-counting-up-and-down-hand 13)
265 (defconst mac-pointer-spinning 14)
266 (defconst mac-pointer-resize-left 15)
267 (defconst mac-pointer-resize-right 16)
268 (defconst mac-pointer-resize-left-right 17)
269 ;; Mac OS X 10.2 and later
270 (defconst mac-pointer-not-allowed 18)
271 ;; Mac OS X 10.3 and later
272 (defconst mac-pointer-resize-up 19)
273 (defconst mac-pointer-resize-down 20)
274 (defconst mac-pointer-resize-up-down 21)
275 (defconst mac-pointer-poof 22)
276
277 ;;
278 ;; Standard X cursor shapes that have Mac counterparts
279 ;;
280
281 (defconst x-pointer-left-ptr mac-pointer-arrow)
282 (defconst x-pointer-xterm mac-pointer-I-beam)
283 (defconst x-pointer-crosshair mac-pointer-cross)
284 (defconst x-pointer-plus mac-pointer-plus)
285 (defconst x-pointer-watch mac-pointer-watch)
286 (defconst x-pointer-hand2 mac-pointer-pointing-hand)
287 (defconst x-pointer-left-side mac-pointer-resize-left)
288 (defconst x-pointer-right-side mac-pointer-resize-right)
289 (defconst x-pointer-sb-h-double-arrow mac-pointer-resize-left-right)
290 (defconst x-pointer-top-side mac-pointer-resize-up)
291 (defconst x-pointer-bottom-side mac-pointer-resize-down)
292 (defconst x-pointer-sb-v-double-arrow mac-pointer-resize-up-down)
293
294 \f
295 ;;
296 ;; Available colors
297 ;;
298
299 (defvar x-colors '("LightGreen"
300 "light green"
301 "DarkRed"
302 "dark red"
303 "DarkMagenta"
304 "dark magenta"
305 "DarkCyan"
306 "dark cyan"
307 "DarkBlue"
308 "dark blue"
309 "DarkGray"
310 "dark gray"
311 "DarkGrey"
312 "dark grey"
313 "grey100"
314 "gray100"
315 "grey99"
316 "gray99"
317 "grey98"
318 "gray98"
319 "grey97"
320 "gray97"
321 "grey96"
322 "gray96"
323 "grey95"
324 "gray95"
325 "grey94"
326 "gray94"
327 "grey93"
328 "gray93"
329 "grey92"
330 "gray92"
331 "grey91"
332 "gray91"
333 "grey90"
334 "gray90"
335 "grey89"
336 "gray89"
337 "grey88"
338 "gray88"
339 "grey87"
340 "gray87"
341 "grey86"
342 "gray86"
343 "grey85"
344 "gray85"
345 "grey84"
346 "gray84"
347 "grey83"
348 "gray83"
349 "grey82"
350 "gray82"
351 "grey81"
352 "gray81"
353 "grey80"
354 "gray80"
355 "grey79"
356 "gray79"
357 "grey78"
358 "gray78"
359 "grey77"
360 "gray77"
361 "grey76"
362 "gray76"
363 "grey75"
364 "gray75"
365 "grey74"
366 "gray74"
367 "grey73"
368 "gray73"
369 "grey72"
370 "gray72"
371 "grey71"
372 "gray71"
373 "grey70"
374 "gray70"
375 "grey69"
376 "gray69"
377 "grey68"
378 "gray68"
379 "grey67"
380 "gray67"
381 "grey66"
382 "gray66"
383 "grey65"
384 "gray65"
385 "grey64"
386 "gray64"
387 "grey63"
388 "gray63"
389 "grey62"
390 "gray62"
391 "grey61"
392 "gray61"
393 "grey60"
394 "gray60"
395 "grey59"
396 "gray59"
397 "grey58"
398 "gray58"
399 "grey57"
400 "gray57"
401 "grey56"
402 "gray56"
403 "grey55"
404 "gray55"
405 "grey54"
406 "gray54"
407 "grey53"
408 "gray53"
409 "grey52"
410 "gray52"
411 "grey51"
412 "gray51"
413 "grey50"
414 "gray50"
415 "grey49"
416 "gray49"
417 "grey48"
418 "gray48"
419 "grey47"
420 "gray47"
421 "grey46"
422 "gray46"
423 "grey45"
424 "gray45"
425 "grey44"
426 "gray44"
427 "grey43"
428 "gray43"
429 "grey42"
430 "gray42"
431 "grey41"
432 "gray41"
433 "grey40"
434 "gray40"
435 "grey39"
436 "gray39"
437 "grey38"
438 "gray38"
439 "grey37"
440 "gray37"
441 "grey36"
442 "gray36"
443 "grey35"
444 "gray35"
445 "grey34"
446 "gray34"
447 "grey33"
448 "gray33"
449 "grey32"
450 "gray32"
451 "grey31"
452 "gray31"
453 "grey30"
454 "gray30"
455 "grey29"
456 "gray29"
457 "grey28"
458 "gray28"
459 "grey27"
460 "gray27"
461 "grey26"
462 "gray26"
463 "grey25"
464 "gray25"
465 "grey24"
466 "gray24"
467 "grey23"
468 "gray23"
469 "grey22"
470 "gray22"
471 "grey21"
472 "gray21"
473 "grey20"
474 "gray20"
475 "grey19"
476 "gray19"
477 "grey18"
478 "gray18"
479 "grey17"
480 "gray17"
481 "grey16"
482 "gray16"
483 "grey15"
484 "gray15"
485 "grey14"
486 "gray14"
487 "grey13"
488 "gray13"
489 "grey12"
490 "gray12"
491 "grey11"
492 "gray11"
493 "grey10"
494 "gray10"
495 "grey9"
496 "gray9"
497 "grey8"
498 "gray8"
499 "grey7"
500 "gray7"
501 "grey6"
502 "gray6"
503 "grey5"
504 "gray5"
505 "grey4"
506 "gray4"
507 "grey3"
508 "gray3"
509 "grey2"
510 "gray2"
511 "grey1"
512 "gray1"
513 "grey0"
514 "gray0"
515 "thistle4"
516 "thistle3"
517 "thistle2"
518 "thistle1"
519 "MediumPurple4"
520 "MediumPurple3"
521 "MediumPurple2"
522 "MediumPurple1"
523 "purple4"
524 "purple3"
525 "purple2"
526 "purple1"
527 "DarkOrchid4"
528 "DarkOrchid3"
529 "DarkOrchid2"
530 "DarkOrchid1"
531 "MediumOrchid4"
532 "MediumOrchid3"
533 "MediumOrchid2"
534 "MediumOrchid1"
535 "plum4"
536 "plum3"
537 "plum2"
538 "plum1"
539 "orchid4"
540 "orchid3"
541 "orchid2"
542 "orchid1"
543 "magenta4"
544 "magenta3"
545 "magenta2"
546 "magenta1"
547 "VioletRed4"
548 "VioletRed3"
549 "VioletRed2"
550 "VioletRed1"
551 "maroon4"
552 "maroon3"
553 "maroon2"
554 "maroon1"
555 "PaleVioletRed4"
556 "PaleVioletRed3"
557 "PaleVioletRed2"
558 "PaleVioletRed1"
559 "LightPink4"
560 "LightPink3"
561 "LightPink2"
562 "LightPink1"
563 "pink4"
564 "pink3"
565 "pink2"
566 "pink1"
567 "HotPink4"
568 "HotPink3"
569 "HotPink2"
570 "HotPink1"
571 "DeepPink4"
572 "DeepPink3"
573 "DeepPink2"
574 "DeepPink1"
575 "red4"
576 "red3"
577 "red2"
578 "red1"
579 "OrangeRed4"
580 "OrangeRed3"
581 "OrangeRed2"
582 "OrangeRed1"
583 "tomato4"
584 "tomato3"
585 "tomato2"
586 "tomato1"
587 "coral4"
588 "coral3"
589 "coral2"
590 "coral1"
591 "DarkOrange4"
592 "DarkOrange3"
593 "DarkOrange2"
594 "DarkOrange1"
595 "orange4"
596 "orange3"
597 "orange2"
598 "orange1"
599 "LightSalmon4"
600 "LightSalmon3"
601 "LightSalmon2"
602 "LightSalmon1"
603 "salmon4"
604 "salmon3"
605 "salmon2"
606 "salmon1"
607 "brown4"
608 "brown3"
609 "brown2"
610 "brown1"
611 "firebrick4"
612 "firebrick3"
613 "firebrick2"
614 "firebrick1"
615 "chocolate4"
616 "chocolate3"
617 "chocolate2"
618 "chocolate1"
619 "tan4"
620 "tan3"
621 "tan2"
622 "tan1"
623 "wheat4"
624 "wheat3"
625 "wheat2"
626 "wheat1"
627 "burlywood4"
628 "burlywood3"
629 "burlywood2"
630 "burlywood1"
631 "sienna4"
632 "sienna3"
633 "sienna2"
634 "sienna1"
635 "IndianRed4"
636 "IndianRed3"
637 "IndianRed2"
638 "IndianRed1"
639 "RosyBrown4"
640 "RosyBrown3"
641 "RosyBrown2"
642 "RosyBrown1"
643 "DarkGoldenrod4"
644 "DarkGoldenrod3"
645 "DarkGoldenrod2"
646 "DarkGoldenrod1"
647 "goldenrod4"
648 "goldenrod3"
649 "goldenrod2"
650 "goldenrod1"
651 "gold4"
652 "gold3"
653 "gold2"
654 "gold1"
655 "yellow4"
656 "yellow3"
657 "yellow2"
658 "yellow1"
659 "LightYellow4"
660 "LightYellow3"
661 "LightYellow2"
662 "LightYellow1"
663 "LightGoldenrod4"
664 "LightGoldenrod3"
665 "LightGoldenrod2"
666 "LightGoldenrod1"
667 "khaki4"
668 "khaki3"
669 "khaki2"
670 "khaki1"
671 "DarkOliveGreen4"
672 "DarkOliveGreen3"
673 "DarkOliveGreen2"
674 "DarkOliveGreen1"
675 "OliveDrab4"
676 "OliveDrab3"
677 "OliveDrab2"
678 "OliveDrab1"
679 "chartreuse4"
680 "chartreuse3"
681 "chartreuse2"
682 "chartreuse1"
683 "green4"
684 "green3"
685 "green2"
686 "green1"
687 "SpringGreen4"
688 "SpringGreen3"
689 "SpringGreen2"
690 "SpringGreen1"
691 "PaleGreen4"
692 "PaleGreen3"
693 "PaleGreen2"
694 "PaleGreen1"
695 "SeaGreen4"
696 "SeaGreen3"
697 "SeaGreen2"
698 "SeaGreen1"
699 "DarkSeaGreen4"
700 "DarkSeaGreen3"
701 "DarkSeaGreen2"
702 "DarkSeaGreen1"
703 "aquamarine4"
704 "aquamarine3"
705 "aquamarine2"
706 "aquamarine1"
707 "DarkSlateGray4"
708 "DarkSlateGray3"
709 "DarkSlateGray2"
710 "DarkSlateGray1"
711 "cyan4"
712 "cyan3"
713 "cyan2"
714 "cyan1"
715 "turquoise4"
716 "turquoise3"
717 "turquoise2"
718 "turquoise1"
719 "CadetBlue4"
720 "CadetBlue3"
721 "CadetBlue2"
722 "CadetBlue1"
723 "PaleTurquoise4"
724 "PaleTurquoise3"
725 "PaleTurquoise2"
726 "PaleTurquoise1"
727 "LightCyan4"
728 "LightCyan3"
729 "LightCyan2"
730 "LightCyan1"
731 "LightBlue4"
732 "LightBlue3"
733 "LightBlue2"
734 "LightBlue1"
735 "LightSteelBlue4"
736 "LightSteelBlue3"
737 "LightSteelBlue2"
738 "LightSteelBlue1"
739 "SlateGray4"
740 "SlateGray3"
741 "SlateGray2"
742 "SlateGray1"
743 "LightSkyBlue4"
744 "LightSkyBlue3"
745 "LightSkyBlue2"
746 "LightSkyBlue1"
747 "SkyBlue4"
748 "SkyBlue3"
749 "SkyBlue2"
750 "SkyBlue1"
751 "DeepSkyBlue4"
752 "DeepSkyBlue3"
753 "DeepSkyBlue2"
754 "DeepSkyBlue1"
755 "SteelBlue4"
756 "SteelBlue3"
757 "SteelBlue2"
758 "SteelBlue1"
759 "DodgerBlue4"
760 "DodgerBlue3"
761 "DodgerBlue2"
762 "DodgerBlue1"
763 "blue4"
764 "blue3"
765 "blue2"
766 "blue1"
767 "RoyalBlue4"
768 "RoyalBlue3"
769 "RoyalBlue2"
770 "RoyalBlue1"
771 "SlateBlue4"
772 "SlateBlue3"
773 "SlateBlue2"
774 "SlateBlue1"
775 "azure4"
776 "azure3"
777 "azure2"
778 "azure1"
779 "MistyRose4"
780 "MistyRose3"
781 "MistyRose2"
782 "MistyRose1"
783 "LavenderBlush4"
784 "LavenderBlush3"
785 "LavenderBlush2"
786 "LavenderBlush1"
787 "honeydew4"
788 "honeydew3"
789 "honeydew2"
790 "honeydew1"
791 "ivory4"
792 "ivory3"
793 "ivory2"
794 "ivory1"
795 "cornsilk4"
796 "cornsilk3"
797 "cornsilk2"
798 "cornsilk1"
799 "LemonChiffon4"
800 "LemonChiffon3"
801 "LemonChiffon2"
802 "LemonChiffon1"
803 "NavajoWhite4"
804 "NavajoWhite3"
805 "NavajoWhite2"
806 "NavajoWhite1"
807 "PeachPuff4"
808 "PeachPuff3"
809 "PeachPuff2"
810 "PeachPuff1"
811 "bisque4"
812 "bisque3"
813 "bisque2"
814 "bisque1"
815 "AntiqueWhite4"
816 "AntiqueWhite3"
817 "AntiqueWhite2"
818 "AntiqueWhite1"
819 "seashell4"
820 "seashell3"
821 "seashell2"
822 "seashell1"
823 "snow4"
824 "snow3"
825 "snow2"
826 "snow1"
827 "thistle"
828 "MediumPurple"
829 "medium purple"
830 "purple"
831 "BlueViolet"
832 "blue violet"
833 "DarkViolet"
834 "dark violet"
835 "DarkOrchid"
836 "dark orchid"
837 "MediumOrchid"
838 "medium orchid"
839 "orchid"
840 "plum"
841 "violet"
842 "magenta"
843 "VioletRed"
844 "violet red"
845 "MediumVioletRed"
846 "medium violet red"
847 "maroon"
848 "PaleVioletRed"
849 "pale violet red"
850 "LightPink"
851 "light pink"
852 "pink"
853 "DeepPink"
854 "deep pink"
855 "HotPink"
856 "hot pink"
857 "red"
858 "OrangeRed"
859 "orange red"
860 "tomato"
861 "LightCoral"
862 "light coral"
863 "coral"
864 "DarkOrange"
865 "dark orange"
866 "orange"
867 "LightSalmon"
868 "light salmon"
869 "salmon"
870 "DarkSalmon"
871 "dark salmon"
872 "brown"
873 "firebrick"
874 "chocolate"
875 "tan"
876 "SandyBrown"
877 "sandy brown"
878 "wheat"
879 "beige"
880 "burlywood"
881 "peru"
882 "sienna"
883 "SaddleBrown"
884 "saddle brown"
885 "IndianRed"
886 "indian red"
887 "RosyBrown"
888 "rosy brown"
889 "DarkGoldenrod"
890 "dark goldenrod"
891 "goldenrod"
892 "LightGoldenrod"
893 "light goldenrod"
894 "gold"
895 "yellow"
896 "LightYellow"
897 "light yellow"
898 "LightGoldenrodYellow"
899 "light goldenrod yellow"
900 "PaleGoldenrod"
901 "pale goldenrod"
902 "khaki"
903 "DarkKhaki"
904 "dark khaki"
905 "OliveDrab"
906 "olive drab"
907 "ForestGreen"
908 "forest green"
909 "YellowGreen"
910 "yellow green"
911 "LimeGreen"
912 "lime green"
913 "GreenYellow"
914 "green yellow"
915 "MediumSpringGreen"
916 "medium spring green"
917 "chartreuse"
918 "green"
919 "LawnGreen"
920 "lawn green"
921 "SpringGreen"
922 "spring green"
923 "PaleGreen"
924 "pale green"
925 "LightSeaGreen"
926 "light sea green"
927 "MediumSeaGreen"
928 "medium sea green"
929 "SeaGreen"
930 "sea green"
931 "DarkSeaGreen"
932 "dark sea green"
933 "DarkOliveGreen"
934 "dark olive green"
935 "DarkGreen"
936 "dark green"
937 "aquamarine"
938 "MediumAquamarine"
939 "medium aquamarine"
940 "CadetBlue"
941 "cadet blue"
942 "LightCyan"
943 "light cyan"
944 "cyan"
945 "turquoise"
946 "MediumTurquoise"
947 "medium turquoise"
948 "DarkTurquoise"
949 "dark turquoise"
950 "PaleTurquoise"
951 "pale turquoise"
952 "PowderBlue"
953 "powder blue"
954 "LightBlue"
955 "light blue"
956 "LightSteelBlue"
957 "light steel blue"
958 "SteelBlue"
959 "steel blue"
960 "LightSkyBlue"
961 "light sky blue"
962 "SkyBlue"
963 "sky blue"
964 "DeepSkyBlue"
965 "deep sky blue"
966 "DodgerBlue"
967 "dodger blue"
968 "blue"
969 "RoyalBlue"
970 "royal blue"
971 "MediumBlue"
972 "medium blue"
973 "LightSlateBlue"
974 "light slate blue"
975 "MediumSlateBlue"
976 "medium slate blue"
977 "SlateBlue"
978 "slate blue"
979 "DarkSlateBlue"
980 "dark slate blue"
981 "CornflowerBlue"
982 "cornflower blue"
983 "NavyBlue"
984 "navy blue"
985 "navy"
986 "MidnightBlue"
987 "midnight blue"
988 "LightGray"
989 "light gray"
990 "LightGrey"
991 "light grey"
992 "grey"
993 "gray"
994 "LightSlateGrey"
995 "light slate grey"
996 "LightSlateGray"
997 "light slate gray"
998 "SlateGrey"
999 "slate grey"
1000 "SlateGray"
1001 "slate gray"
1002 "DimGrey"
1003 "dim grey"
1004 "DimGray"
1005 "dim gray"
1006 "DarkSlateGrey"
1007 "dark slate grey"
1008 "DarkSlateGray"
1009 "dark slate gray"
1010 "black"
1011 "white"
1012 "MistyRose"
1013 "misty rose"
1014 "LavenderBlush"
1015 "lavender blush"
1016 "lavender"
1017 "AliceBlue"
1018 "alice blue"
1019 "azure"
1020 "MintCream"
1021 "mint cream"
1022 "honeydew"
1023 "seashell"
1024 "LemonChiffon"
1025 "lemon chiffon"
1026 "ivory"
1027 "cornsilk"
1028 "moccasin"
1029 "NavajoWhite"
1030 "navajo white"
1031 "PeachPuff"
1032 "peach puff"
1033 "bisque"
1034 "BlanchedAlmond"
1035 "blanched almond"
1036 "PapayaWhip"
1037 "papaya whip"
1038 "AntiqueWhite"
1039 "antique white"
1040 "linen"
1041 "OldLace"
1042 "old lace"
1043 "FloralWhite"
1044 "floral white"
1045 "gainsboro"
1046 "WhiteSmoke"
1047 "white smoke"
1048 "GhostWhite"
1049 "ghost white"
1050 "snow")
1051 "The list of X colors from the `rgb.txt' file.
1052 XConsortium: rgb.txt,v 10.41 94/02/20 18:39:36 rws Exp")
1053
1054 (defun xw-defined-colors (&optional frame)
1055 "Internal function called by `defined-colors', which see."
1056 (or frame (setq frame (selected-frame)))
1057 (let ((all-colors x-colors)
1058 (this-color nil)
1059 (defined-colors nil))
1060 (while all-colors
1061 (setq this-color (car all-colors)
1062 all-colors (cdr all-colors))
1063 (and (color-supported-p this-color frame t)
1064 (setq defined-colors (cons this-color defined-colors))))
1065 defined-colors))
1066 \f
1067 ;;;; Function keys
1068
1069 (defun x-setup-function-keys (frame)
1070 "Setup Function Keys for mac."
1071 ;; Don't do this twice on the same display, or it would break
1072 ;; normal-erase-is-backspace-mode.
1073 (unless (terminal-parameter frame 'x-setup-function-keys)
1074 (with-selected-frame frame
1075 ;; Map certain keypad keys into ASCII characters
1076 ;; that people usually expect.
1077 (define-key local-function-key-map [backspace] [?\d])
1078 (define-key local-function-key-map [delete] [?\d])
1079 (define-key local-function-key-map [tab] [?\t])
1080 (define-key local-function-key-map [linefeed] [?\n])
1081 (define-key local-function-key-map [clear] [?\C-l])
1082 (define-key local-function-key-map [return] [?\C-m])
1083 (define-key local-function-key-map [escape] [?\e])
1084 (define-key local-function-key-map [M-backspace] [?\M-\d])
1085 (define-key local-function-key-map [M-delete] [?\M-\d])
1086 (define-key local-function-key-map [M-tab] [?\M-\t])
1087 (define-key local-function-key-map [M-linefeed] [?\M-\n])
1088 (define-key local-function-key-map [M-clear] [?\M-\C-l])
1089 (define-key local-function-key-map [M-return] [?\M-\C-m])
1090 (define-key local-function-key-map [M-escape] [?\M-\e])
1091 (substitute-key-definition 'suspend-emacs 'iconify-or-deiconify-frame
1092 local-function-key-map global-map))
1093 (set-terminal-parameter frame 'x-setup-function-keys t)))
1094
1095 ;; These tell read-char how to convert
1096 ;; these special chars to ASCII.
1097 (put 'backspace 'ascii-character ?\d)
1098 (put 'delete 'ascii-character ?\d)
1099 (put 'tab 'ascii-character ?\t)
1100 (put 'linefeed 'ascii-character ?\n)
1101 (put 'clear 'ascii-character ?\C-l)
1102 (put 'return 'ascii-character ?\C-m)
1103 (put 'escape 'ascii-character ?\e)
1104
1105 ;; Modifier name `ctrl' is an alias of `control'.
1106 (put 'ctrl 'modifier-value (get 'control 'modifier-value))
1107
1108 \f
1109 ;;;; Script codes and coding systems
1110 (defconst mac-script-code-coding-systems
1111 '((0 . mac-roman) ; smRoman
1112 (1 . japanese-shift-jis) ; smJapanese
1113 (2 . chinese-big5) ; smTradChinese
1114 (3 . korean-iso-8bit) ; smKorean
1115 (7 . mac-cyrillic) ; smCyrillic
1116 (25 . chinese-iso-8bit) ; smSimpChinese
1117 (29 . mac-centraleurroman) ; smCentralEuroRoman
1118 )
1119 "Alist of Mac script codes vs Emacs coding systems.")
1120
1121 (defun mac-add-charset-info (xlfd-charset mac-text-encoding)
1122 "Add a character set to display with Mac fonts.
1123 Create an entry in `mac-charset-info-alist'.
1124 XLFD-CHARSET is a string which will appear in the XLFD font name
1125 to identify the character set. MAC-TEXT-ENCODING is the
1126 correspoinding TextEncodingBase value."
1127 (add-to-list 'mac-charset-info-alist
1128 (list xlfd-charset mac-text-encoding
1129 (cdr (assq mac-text-encoding
1130 mac-script-code-coding-systems)))))
1131
1132 (setq mac-charset-info-alist nil)
1133 (mac-add-charset-info "mac-roman" 0)
1134 (mac-add-charset-info "jisx0208.1983-sjis" 1)
1135 (mac-add-charset-info "jisx0201.1976-0" 1)
1136 (mac-add-charset-info "big5-0" 2)
1137 (mac-add-charset-info "ksc5601.1989-0" 3)
1138 (mac-add-charset-info "mac-cyrillic" 7)
1139 (mac-add-charset-info "gb2312.1980-0" 25)
1140 (mac-add-charset-info "mac-centraleurroman" 29)
1141 (mac-add-charset-info "mac-symbol" 33)
1142 (mac-add-charset-info "adobe-fontspecific" 33) ; for X-Symbol
1143 (mac-add-charset-info "mac-dingbats" 34)
1144 (mac-add-charset-info "iso10646-1" 126) ; for ATSUI
1145
1146 (cp-make-coding-system
1147 mac-centraleurroman
1148 [?\\e,AD\e(B ?\\e$,1 \e(B ?\\e$,1 !\e(B ?\\e,AI\e(B ?\\e$,1 $\e(B ?\\e,AV\e(B ?\\e,A\\e(B ?\\e,Aa\e(B ?\\e$,1 %\e(B ?\\e$,1 ,\e(B ?\\e,Ad\e(B ?\\e$,1 -\e(B ?\\e$,1 &\e(B ?\\e$,1 '\e(B ?\\e,Ai\e(B ?\\e$,1!9\e(B
1149 ?\\e$,1!:\e(B ?\\e$,1 .\e(B ?\\e,Am\e(B ?\\e$,1 /\e(B ?\\e$,1 2\e(B ?\\e$,1 3\e(B ?\\e$,1 6\e(B ?\\e,As\e(B ?\\e$,1 7\e(B ?\\e,At\e(B ?\\e,Av\e(B ?\\e,Au\e(B ?\\e,Az\e(B ?\\e$,1 :\e(B ?\\e$,1 ;\e(B ?\\e,A|\e(B
1150 ?\\e$,1s \e(B ?\\e,A0\e(B ?\\e$,1 8\e(B ?\\e,A#\e(B ?\\e,A'\e(B ?\\e$,1s"\e(B ?\\e,A6\e(B ?\\e,A_\e(B ?\\e,A.\e(B ?\\e,A)\e(B ?\\e$,1ub\e(B ?\\e$,1 9\e(B ?\\e,A(\e(B ?\\e$,1y \e(B ?\\e$,1 C\e(B ?\\e$,1 N\e(B
1151 ?\\e$,1 O\e(B ?\\e$,1 J\e(B ?\\e$,1y$\e(B ?\\e$,1y%\e(B ?\\e$,1 K\e(B ?\\e$,1 V\e(B ?\\e$,1x"\e(B ?\\e$,1x1\e(B ?\\e$,1 b\e(B ?\\e$,1 [\e(B ?\\e$,1 \\e(B ?\\e$,1 ]\e(B ?\\e$,1 ^\e(B ?\\e$,1 Y\e(B ?\\e$,1 Z\e(B ?\\e$,1 e\e(B
1152 ?\\e$,1 f\e(B ?\\e$,1 c\e(B ?\\e,A,\e(B ?\\e$,1x:\e(B ?\\e$,1 d\e(B ?\\e$,1 g\e(B ?\\e$,1x&\e(B ?\\e,A+\e(B ?\\e,A;\e(B ?\\e$,1s&\e(B ?\\e,A \e(B ?\\e$,1 h\e(B ?\\e$,1 p\e(B ?\\e,AU\e(B ?\\e$,1 q\e(B ?\\e$,1 l\e(B
1153 ?\\e$,1rs\e(B ?\\e$,1rt\e(B ?\\e$,1r|\e(B ?\\e$,1r}\e(B ?\\e$,1rx\e(B ?\\e$,1ry\e(B ?\\e,Aw\e(B ?\\e$,2"*\e(B ?\\e$,1 m\e(B ?\\e$,1 t\e(B ?\\e$,1 u\e(B ?\\e$,1 x\e(B ?\\e$,1s9\e(B ?\\e$,1s:\e(B ?\\e$,1 y\e(B ?\\e$,1 v\e(B
1154 ?\\e$,1 w\e(B ?\\e$,1! \e(B ?\\e$,1rz\e(B ?\\e$,1r~\e(B ?\\e$,1!!\e(B ?\\e$,1 z\e(B ?\\e$,1 {\e(B ?\\e,AA\e(B ?\\e$,1!$\e(B ?\\e$,1!%\e(B ?\\e,AM\e(B ?\\e$,1!=\e(B ?\\e$,1!>\e(B ?\\e$,1!*\e(B ?\\e,AS\e(B ?\\e,AT\e(B
1155 ?\\e$,1!+\e(B ?\\e$,1!.\e(B ?\\e,AZ\e(B ?\\e$,1!/\e(B ?\\e$,1!0\e(B ?\\e$,1!1\e(B ?\\e$,1!2\e(B ?\\e$,1!3\e(B ?\\e,A]\e(B ?\\e,A}\e(B ?\\e$,1 W\e(B ?\\e$,1!;\e(B ?\\e$,1 a\e(B ?\\e$,1!<\e(B ?\\e$,1 B\e(B ?\\e$,1$g\e(B]
1156 "Mac Central European Roman Encoding (MIME:x-mac-centraleurroman).")
1157 (coding-system-put 'mac-centraleurroman 'mime-charset 'x-mac-centraleurroman)
1158
1159 (cp-make-coding-system
1160 mac-cyrillic
1161 [?\\e$,1(0\e(B ?\\e$,1(1\e(B ?\\e$,1(2\e(B ?\\e$,1(3\e(B ?\\e$,1(4\e(B ?\\e$,1(5\e(B ?\\e$,1(6\e(B ?\\e$,1(7\e(B ?\\e$,1(8\e(B ?\\e$,1(9\e(B ?\\e$,1(:\e(B ?\\e$,1(;\e(B ?\\e$,1(<\e(B ?\\e$,1(=\e(B ?\\e$,1(>\e(B ?\\e$,1(?\e(B
1162 ?\\e$,1(@\e(B ?\\e$,1(A\e(B ?\\e$,1(B\e(B ?\\e$,1(C\e(B ?\\e$,1(D\e(B ?\\e$,1(E\e(B ?\\e$,1(F\e(B ?\\e$,1(G\e(B ?\\e$,1(H\e(B ?\\e$,1(I\e(B ?\\e$,1(J\e(B ?\\e$,1(K\e(B ?\\e$,1(L\e(B ?\\e$,1(M\e(B ?\\e$,1(N\e(B ?\\e$,1(O\e(B
1163 ?\\e$,1s \e(B ?\\e,A0\e(B ?\\e$,1)P\e(B ?\\e,A#\e(B ?\\e,A'\e(B ?\\e$,1s"\e(B ?\\e,A6\e(B ?\\e$,1(&\e(B ?\\e,A.\e(B ?\\e,A)\e(B ?\\e$,1ub\e(B ?\\e$,1("\e(B ?\\e$,1(r\e(B ?\\e$,1y \e(B ?\\e$,1(#\e(B ?\\e$,1(s\e(B
1164 ?\\e$,1x>\e(B ?\\e,A1\e(B ?\\e$,1y$\e(B ?\\e$,1y%\e(B ?\\e$,1(v\e(B ?\\e,A5\e(B ?\\e$,1)Q\e(B ?\\e$,1((\e(B ?\\e$,1($\e(B ?\\e$,1(t\e(B ?\\e$,1('\e(B ?\\e$,1(w\e(B ?\\e$,1()\e(B ?\\e$,1(y\e(B ?\\e$,1(*\e(B ?\\e$,1(z\e(B
1165 ?\\e$,1(x\e(B ?\\e$,1(%\e(B ?\\e,A,\e(B ?\\e$,1x:\e(B ?\\e$,1!R\e(B ?\\e$,1xh\e(B ?\\e$,1x&\e(B ?\\e,A+\e(B ?\\e,A;\e(B ?\\e$,1s&\e(B ?\\e,A \e(B ?\\e$,1(+\e(B ?\\e$,1({\e(B ?\\e$,1(,\e(B ?\\e$,1(|\e(B ?\\e$,1(u\e(B
1166 ?\\e$,1rs\e(B ?\\e$,1rt\e(B ?\\e$,1r|\e(B ?\\e$,1r}\e(B ?\\e$,1rx\e(B ?\\e$,1ry\e(B ?\\e,Aw\e(B ?\\e$,1r~\e(B ?\\e$,1(.\e(B ?\\e$,1(~\e(B ?\\e$,1(/\e(B ?\\e$,1(\7f\e(B ?\\e$,1uV\e(B ?\\e$,1(!\e(B ?\\e$,1(q\e(B ?\\e$,1(o\e(B
1167 ?\\e$,1(P\e(B ?\\e$,1(Q\e(B ?\\e$,1(R\e(B ?\\e$,1(S\e(B ?\\e$,1(T\e(B ?\\e$,1(U\e(B ?\\e$,1(V\e(B ?\\e$,1(W\e(B ?\\e$,1(X\e(B ?\\e$,1(Y\e(B ?\\e$,1(Z\e(B ?\\e$,1([\e(B ?\\e$,1(\\e(B ?\\e$,1(]\e(B ?\\e$,1(^\e(B ?\\e$,1(_\e(B
1168 ?\\e$,1(`\e(B ?\\e$,1(a\e(B ?\\e$,1(b\e(B ?\\e$,1(c\e(B ?\\e$,1(d\e(B ?\\e$,1(e\e(B ?\\e$,1(f\e(B ?\\e$,1(g\e(B ?\\e$,1(h\e(B ?\\e$,1(i\e(B ?\\e$,1(j\e(B ?\\e$,1(k\e(B ?\\e$,1(l\e(B ?\\e$,1(m\e(B ?\\e$,1(n\e(B ?\\e$,1tL\e(B]
1169 "Mac Cyrillic Encoding (MIME:x-mac-cyrillic).")
1170 (coding-system-put 'mac-cyrillic 'mime-charset 'x-mac-cyrillic)
1171
1172 (let
1173 ((encoding-vector
1174 (vconcat
1175 (make-vector 32 nil)
1176 ;; mac-symbol (32..126) -> emacs-mule mapping
1177 [?\ ?\! ?\\e$,1x \e(B ?\# ?\\e$,1x#\e(B ?\% ?\& ?\\e$,1x-\e(B ?\( ?\) ?\\e$,1x7\e(B ?\+ ?\, ?\\e$,1x2\e(B ?\. ?\/
1178 ?\0 ?\1 ?\2 ?\3 ?\4 ?\5 ?\6 ?\7 ?\8 ?\9 ?\: ?\; ?\< ?\= ?\> ?\?
1179 ?\\e$,1xe\e(B ?\\e$,1&q\e(B ?\\e$,1&r\e(B ?\\e$,1''\e(B ?\\e$,1&t\e(B ?\\e$,1&u\e(B ?\\e$,1'&\e(B ?\\e$,1&s\e(B ?\\e$,1&w\e(B ?\\e$,1&y\e(B ?\\e$,1'Q\e(B ?\\e$,1&z\e(B ?\\e$,1&{\e(B ?\\e$,1&|\e(B ?\\e$,1&}\e(B ?\\e$,1&\7f\e(B
1180 ?\\e$,1' \e(B ?\\e$,1&x\e(B ?\\e$,1'!\e(B ?\\e$,1'#\e(B ?\\e$,1'$\e(B ?\\e$,1'%\e(B ?\\e$,1'B\e(B ?\\e$,1')\e(B ?\\e$,1&~\e(B ?\\e$,1'(\e(B ?\\e$,1&v\e(B ?\[ ?\\e$,1xT\e(B ?\] ?\\e$,1ye\e(B ?\_
1181 ?\\e$,3bE\e(B ?\\e$,1'1\e(B ?\\e$,1'2\e(B ?\\e$,1'G\e(B ?\\e$,1'4\e(B ?\\e$,1'5\e(B ?\\e$,1'F\e(B ?\\e$,1'3\e(B ?\\e$,1'7\e(B ?\\e$,1'9\e(B ?\\e$,1'U\e(B ?\\e$,1':\e(B ?\\e$,1';\e(B ?\\e$,1'<\e(B ?\\e$,1'=\e(B ?\\e$,1'?\e(B
1182 ?\\e$,1'@\e(B ?\\e$,1'8\e(B ?\\e$,1'A\e(B ?\\e$,1'C\e(B ?\\e$,1'D\e(B ?\\e$,1'E\e(B ?\\e$,1'V\e(B ?\\e$,1'I\e(B ?\\e$,1'>\e(B ?\\e$,1'H\e(B ?\\e$,1'6\e(B ?\{ ?\| ?\} ?\\e$,1x\\e(B]
1183 (make-vector (- 160 127) nil)
1184 ;; mac-symbol (160..254) -> emacs-mule mapping
1185 ;; Mapping of the following characters are changed from the
1186 ;; original one:
1187 ;; 0xE2 0x00AE+0xF87F -> 0x00AE # REGISTERED SIGN, alternate: sans serif
1188 ;; 0xE3 0x00A9+0xF87F -> 0x00A9 # COPYRIGHT SIGN, alternate: sans serif
1189 ;; 0xE4 0x2122+0xF87F -> 0x2122 # TRADE MARK SIGN, alternate: sans serif
1190 [?\\e$,1tL\e(B ?\\e$,1'R\e(B ?\\e$,1s2\e(B ?\\e$,1y$\e(B ?\\e$,1sD\e(B ?\\e$,1x>\e(B ?\\e$,1!R\e(B ?\\e$,2#c\e(B ?\\e$,2#f\e(B ?\\e$,2#e\e(B ?\\e$,2#`\e(B ?\\e$,1vt\e(B ?\\e$,1vp\e(B ?\\e$,1vq\e(B ?\\e$,1vr\e(B ?\\e$,1vs\e(B
1191 ?\\e,A0\e(B ?\\e,A1\e(B ?\\e$,1s3\e(B ?\\e$,1y%\e(B ?\\e,AW\e(B ?\\e$,1x=\e(B ?\\e$,1x"\e(B ?\\e$,1s"\e(B ?\\e,Aw\e(B ?\\e$,1y \e(B ?\\e$,1y!\e(B ?\\e$,1xh\e(B ?\\e$,1s&\e(B ?\\e$,1|p\e(B ?\\e$,1|O\e(B ?\\e$,1w5\e(B
1192 ?\\e$,1uu\e(B ?\\e$,1uQ\e(B ?\\e$,1u\\e(B ?\\e$,1uX\e(B ?\\e$,1yW\e(B ?\\e$,1yU\e(B ?\\e$,1x%\e(B ?\\e$,1xI\e(B ?\\e$,1xJ\e(B ?\\e$,1yC\e(B ?\\e$,1yG\e(B ?\\e$,1yD\e(B ?\\e$,1yB\e(B ?\\e$,1yF\e(B ?\\e$,1x(\e(B ?\\e$,1x)\e(B
1193 ?\\e$,1x@\e(B ?\\e$,1x'\e(B ?\\e,A.\e(B ?\\e,A)\e(B ?\\e$,1ub\e(B ?\\e$,1x/\e(B ?\\e$,1x:\e(B ?\\e$,1z%\e(B ?\\e,A,\e(B ?\\e$,1xG\e(B ?\\e$,1xH\e(B ?\\e$,1wT\e(B ?\\e$,1wP\e(B ?\\e$,1wQ\e(B ?\\e$,1wR\e(B ?\\e$,1wS\e(B
1194 ?\\e$,2"*\e(B ?\\e$,2=H\e(B ?\\e,A.\e(B ?\\e,A)\e(B ?\\e$,1ub\e(B ?\\e$,1x1\e(B ?\\e$,1|;\e(B ?\\e$,1|<\e(B ?\\e$,1|=\e(B ?\\e$,1|A\e(B ?\\e$,1|B\e(B ?\\e$,1|C\e(B ?\\e$,1|G\e(B ?\\e$,1|H\e(B ?\\e$,1|I\e(B ?\\e$,1|J\e(B
1195 ?\\e$,3b_\e(B ?\\e$,2=I\e(B ?\\e$,1xK\e(B ?\\e$,1{ \e(B ?\\e$,1|N\e(B ?\\e$,1{!\e(B ?\\e$,1|>\e(B ?\\e$,1|?\e(B ?\\e$,1|@\e(B ?\\e$,1|D\e(B ?\\e$,1|E\e(B ?\\e$,1|F\e(B ?\\e$,1|K\e(B ?\\e$,1|L\e(B ?\\e$,1|M\e(B
1196 nil]))
1197 translation-table)
1198 (setq translation-table
1199 (make-translation-table-from-vector encoding-vector))
1200 ;; (define-translation-table 'mac-symbol-decoder translation-table)
1201 (define-translation-table 'mac-symbol-encoder
1202 (char-table-extra-slot translation-table 0)))
1203
1204 (let
1205 ((encoding-vector
1206 (vconcat
1207 (make-vector 32 nil)
1208 ;; mac-dingbats (32..126) -> emacs-mule mapping
1209 [?\ ?\\e$,2%A\e(B ?\\e$,2%B\e(B ?\\e$,2%C\e(B ?\\e$,2%D\e(B ?\\e$,2"n\e(B ?\\e$,2%F\e(B ?\\e$,2%G\e(B ?\\e$,2%H\e(B ?\\e$,2%I\e(B ?\\e$,2"{\e(B ?\\e$,2"~\e(B ?\\e$,2%L\e(B ?\\e$,2%M\e(B ?\\e$,2%N\e(B ?\\e$,2%O\e(B
1210 ?\\e$,2%P\e(B ?\\e$,2%Q\e(B ?\\e$,2%R\e(B ?\\e$,2%S\e(B ?\\e$,2%T\e(B ?\\e$,2%U\e(B ?\\e$,2%V\e(B ?\\e$,2%W\e(B ?\\e$,2%X\e(B ?\\e$,2%Y\e(B ?\\e$,2%Z\e(B ?\\e$,2%[\e(B ?\\e$,2%\\e(B ?\\e$,2%]\e(B ?\\e$,2%^\e(B ?\\e$,2%_\e(B
1211 ?\\e$,2%`\e(B ?\\e$,2%a\e(B ?\\e$,2%b\e(B ?\\e$,2%c\e(B ?\\e$,2%d\e(B ?\\e$,2%e\e(B ?\\e$,2%f\e(B ?\\e$,2%g\e(B ?\\e$,2"e\e(B ?\\e$,2%i\e(B ?\\e$,2%j\e(B ?\\e$,2%k\e(B ?\\e$,2%l\e(B ?\\e$,2%m\e(B ?\\e$,2%n\e(B ?\\e$,2%o\e(B
1212 ?\\e$,2%p\e(B ?\\e$,2%q\e(B ?\\e$,2%r\e(B ?\\e$,2%s\e(B ?\\e$,2%t\e(B ?\\e$,2%u\e(B ?\\e$,2%v\e(B ?\\e$,2%w\e(B ?\\e$,2%x\e(B ?\\e$,2%y\e(B ?\\e$,2%z\e(B ?\\e$,2%{\e(B ?\\e$,2%|\e(B ?\\e$,2%}\e(B ?\\e$,2%~\e(B ?\\e$,2%\7f\e(B
1213 ?\\e$,2& \e(B ?\\e$,2&!\e(B ?\\e$,2&"\e(B ?\\e$,2&#\e(B ?\\e$,2&$\e(B ?\\e$,2&%\e(B ?\\e$,2&&\e(B ?\\e$,2&'\e(B ?\\e$,2&(\e(B ?\\e$,2&)\e(B ?\\e$,2&*\e(B ?\\e$,2&+\e(B ?\\e$,2"/\e(B ?\\e$,2&-\e(B ?\\e$,2!`\e(B ?\\e$,2&/\e(B
1214 ?\\e$,2&0\e(B ?\\e$,2&1\e(B ?\\e$,2&2\e(B ?\\e$,2!r\e(B ?\\e$,2!|\e(B ?\\e$,2"&\e(B ?\\e$,2&6\e(B ?\\e$,2"7\e(B ?\\e$,2&8\e(B ?\\e$,2&9\e(B ?\\e$,2&:\e(B ?\\e$,2&;\e(B ?\\e$,2&<\e(B ?\\e$,2&=\e(B ?\\e$,2&>\e(B
1215 nil
1216 ;; mac-dingbats (128..141) -> emacs-mule mapping
1217 ?\\e$,2&H\e(B ?\\e$,2&I\e(B ?\\e$,2&J\e(B ?\\e$,2&K\e(B ?\\e$,2&L\e(B ?\\e$,2&M\e(B ?\\e$,2&N\e(B ?\\e$,2&O\e(B ?\\e$,2&P\e(B ?\\e$,2&Q\e(B ?\\e$,2&R\e(B ?\\e$,2&S\e(B ?\\e$,2&T\e(B ?\\e$,2&U\e(B]
1218 (make-vector (- 161 142) nil)
1219 ;; mac-dingbats (161..239) -> emacs-mule mapping
1220 [?\\e$,2&A\e(B ?\\e$,2&B\e(B ?\\e$,2&C\e(B ?\\e$,2&D\e(B ?\\e$,2&E\e(B ?\\e$,2&F\e(B ?\\e$,2&G\e(B ?\\e$,2#c\e(B ?\\e$,2#f\e(B ?\\e$,2#e\e(B ?\\e$,2#`\e(B ?\\e$,1~@\e(B ?\\e$,1~A\e(B ?\\e$,1~B\e(B ?\\e$,1~C\e(B
1221 ?\\e$,1~D\e(B ?\\e$,1~E\e(B ?\\e$,1~F\e(B ?\\e$,1~G\e(B ?\\e$,1~H\e(B ?\\e$,1~I\e(B ?\\e$,2&V\e(B ?\\e$,2&W\e(B ?\\e$,2&X\e(B ?\\e$,2&Y\e(B ?\\e$,2&Z\e(B ?\\e$,2&[\e(B ?\\e$,2&\\e(B ?\\e$,2&]\e(B ?\\e$,2&^\e(B ?\\e$,2&_\e(B
1222 ?\\e$,2&`\e(B ?\\e$,2&a\e(B ?\\e$,2&b\e(B ?\\e$,2&c\e(B ?\\e$,2&d\e(B ?\\e$,2&e\e(B ?\\e$,2&f\e(B ?\\e$,2&g\e(B ?\\e$,2&h\e(B ?\\e$,2&i\e(B ?\\e$,2&j\e(B ?\\e$,2&k\e(B ?\\e$,2&l\e(B ?\\e$,2&m\e(B ?\\e$,2&n\e(B ?\\e$,2&o\e(B
1223 ?\\e$,2&p\e(B ?\\e$,2&q\e(B ?\\e$,2&r\e(B ?\\e$,2&s\e(B ?\\e$,2&t\e(B ?\\e$,1vr\e(B ?\\e$,1vt\e(B ?\\e$,1vu\e(B ?\\e$,2&x\e(B ?\\e$,2&y\e(B ?\\e$,2&z\e(B ?\\e$,2&{\e(B ?\\e$,2&|\e(B ?\\e$,2&}\e(B ?\\e$,2&~\e(B ?\\e$,2&\7f\e(B
1224 ?\\e$,2' \e(B ?\\e$,2'!\e(B ?\\e$,2'"\e(B ?\\e$,2'#\e(B ?\\e$,2'$\e(B ?\\e$,2'%\e(B ?\\e$,2'&\e(B ?\\e$,2''\e(B ?\\e$,2'(\e(B ?\\e$,2')\e(B ?\\e$,2'*\e(B ?\\e$,2'+\e(B ?\\e$,2',\e(B ?\\e$,2'-\e(B ?\\e$,2'.\e(B ?\\e$,2'/\e(B
1225 nil
1226 ;; mac-dingbats (241..254) -> emacs-mule mapping
1227 ?\\e$,2'1\e(B ?\\e$,2'2\e(B ?\\e$,2'3\e(B ?\\e$,2'4\e(B ?\\e$,2'5\e(B ?\\e$,2'6\e(B ?\\e$,2'7\e(B ?\\e$,2'8\e(B ?\\e$,2'9\e(B ?\\e$,2':\e(B ?\\e$,2';\e(B ?\\e$,2'<\e(B ?\\e$,2'=\e(B ?\\e$,2'>\e(B
1228 nil]))
1229 translation-table)
1230 (setq translation-table
1231 (make-translation-table-from-vector encoding-vector))
1232 ;; (define-translation-table 'mac-dingbats-decoder translation-table)
1233 (define-translation-table 'mac-dingbats-encoder
1234 (char-table-extra-slot translation-table 0)))
1235
1236 (defconst mac-system-coding-system
1237 (let ((base (or (cdr (assq mac-system-script-code
1238 mac-script-code-coding-systems))
1239 'mac-roman)))
1240 (if (eq system-type 'darwin)
1241 base
1242 (coding-system-change-eol-conversion base 'mac)))
1243 "Coding system derived from the system script code.")
1244
1245 (set-selection-coding-system mac-system-coding-system)
1246
1247 \f
1248 ;;;; Keyboard layout/language change events
1249 (defun mac-handle-language-change (event)
1250 "Set keyboard coding system to what is specified in EVENT."
1251 (interactive "e")
1252 (let ((coding-system
1253 (cdr (assq (car (cadr event)) mac-script-code-coding-systems))))
1254 (set-keyboard-coding-system (or coding-system 'mac-roman))
1255 ;; MacJapanese maps reverse solidus to ?\x80.
1256 (if (eq coding-system 'japanese-shift-jis)
1257 (define-key key-translation-map [?\x80] "\\"))))
1258
1259 (define-key special-event-map [language-change] 'mac-handle-language-change)
1260
1261 \f
1262 ;;;; Conversion between common flavors and Lisp string.
1263
1264 (defconst mac-text-encoding-ascii #x600
1265 "ASCII text encoding.")
1266
1267 (defconst mac-text-encoding-mac-japanese-basic-variant #x20001
1268 "MacJapanese text encoding without Apple double-byte extensions.")
1269
1270 (defun mac-utxt-to-string (data &optional coding-system)
1271 (or coding-system (setq coding-system mac-system-coding-system))
1272 (let* ((encoding
1273 (and (eq system-type 'darwin)
1274 (eq (coding-system-base coding-system) 'japanese-shift-jis)
1275 mac-text-encoding-mac-japanese-basic-variant))
1276 (str (and (fboundp 'mac-code-convert-string)
1277 (mac-code-convert-string data nil
1278 (or encoding coding-system)))))
1279 (when str
1280 (setq str (decode-coding-string str coding-system))
1281 (if (eq encoding mac-text-encoding-mac-japanese-basic-variant)
1282 ;; Does it contain Apple one-byte extensions other than
1283 ;; reverse solidus?
1284 (if (string-match "[\xa0\xfd-\xff]" str)
1285 (setq str nil)
1286 ;; ASCII-only?
1287 (unless (mac-code-convert-string data nil mac-text-encoding-ascii)
1288 (subst-char-in-string ?\x5c ?\\e(J\\e(B str t)
1289 (subst-char-in-string ?\x80 ?\\ str t)))))
1290 (or str
1291 (decode-coding-string data
1292 (if (eq (byteorder) ?B) 'utf-16be 'utf-16le)))))
1293
1294 (defun mac-string-to-utxt (string &optional coding-system)
1295 (or coding-system (setq coding-system mac-system-coding-system))
1296 (let (data encoding)
1297 (when (and (fboundp 'mac-code-convert-string)
1298 (memq (coding-system-base coding-system)
1299 (find-coding-systems-string string)))
1300 (setq coding-system
1301 (coding-system-change-eol-conversion coding-system 'mac))
1302 (let ((str string))
1303 (when (and (eq system-type 'darwin)
1304 (eq coding-system 'japanese-shift-jis-mac))
1305 (setq encoding mac-text-encoding-mac-japanese-basic-variant)
1306 (setq str (subst-char-in-string ?\\ ?\x80 str))
1307 (subst-char-in-string ?\\e(J\\e(B ?\x5c str t)
1308 ;; ASCII-only?
1309 (if (string-match "\\`[\x00-\x7f]*\\'" str)
1310 (setq str nil)))
1311 (and str
1312 (setq data (mac-code-convert-string
1313 (encode-coding-string str coding-system)
1314 (or encoding coding-system) nil)))))
1315 (or data (encode-coding-string string (if (eq (byteorder) ?B)
1316 'utf-16be-mac
1317 'utf-16le-mac)))))
1318
1319 (defun mac-TEXT-to-string (data &optional coding-system)
1320 (or coding-system (setq coding-system mac-system-coding-system))
1321 (prog1 (setq data (decode-coding-string data coding-system))
1322 (when (eq (coding-system-base coding-system) 'japanese-shift-jis)
1323 ;; (subst-char-in-string ?\x5c ?\\e(J\\e(B data t)
1324 (subst-char-in-string ?\x80 ?\\ data t))))
1325
1326 (defun mac-string-to-TEXT (string &optional coding-system)
1327 (or coding-system (setq coding-system mac-system-coding-system))
1328 (let ((encodables (find-coding-systems-string string))
1329 (rest mac-script-code-coding-systems))
1330 (unless (memq (coding-system-base coding-system) encodables)
1331 (while (and rest (not (memq (cdar rest) encodables)))
1332 (setq rest (cdr rest)))
1333 (if rest
1334 (setq coding-system (cdar rest)))))
1335 (setq coding-system
1336 (coding-system-change-eol-conversion coding-system 'mac))
1337 (when (eq coding-system 'japanese-shift-jis-mac)
1338 ;; (setq string (subst-char-in-string ?\\ ?\x80 string))
1339 (setq string (subst-char-in-string ?\\e(J\\e(B ?\x5c string)))
1340 (encode-coding-string string coding-system))
1341
1342 (defun mac-furl-to-string (data)
1343 ;; Remove a trailing nul character.
1344 (let ((len (length data)))
1345 (if (and (> len 0) (= (aref data (1- len)) ?\0))
1346 (substring data 0 (1- len))
1347 data)))
1348
1349 (defun mac-TIFF-to-string (data &optional text)
1350 (prog1 (or text (setq text (copy-sequence " ")))
1351 (put-text-property 0 (length text) 'display (create-image data 'tiff t)
1352 text)))
1353 \f
1354 ;;;; Selections
1355
1356 ;;; We keep track of the last text selected here, so we can check the
1357 ;;; current selection against it, and avoid passing back our own text
1358 ;;; from x-get-selection-value.
1359 (defvar x-last-selected-text-clipboard nil
1360 "The value of the CLIPBOARD selection last time we selected or
1361 pasted text.")
1362 (defvar x-last-selected-text-primary nil
1363 "The value of the PRIMARY X selection last time we selected or
1364 pasted text.")
1365
1366 (defcustom x-select-enable-clipboard t
1367 "*Non-nil means cutting and pasting uses the clipboard.
1368 This is in addition to the primary selection."
1369 :type 'boolean
1370 :group 'killing)
1371
1372 ;;; Make TEXT, a string, the primary X selection.
1373 (defun x-select-text (text &optional push)
1374 (x-set-selection 'PRIMARY text)
1375 (setq x-last-selected-text-primary text)
1376 (if (not x-select-enable-clipboard)
1377 (setq x-last-selected-text-clipboard nil)
1378 (x-set-selection 'CLIPBOARD text)
1379 (setq x-last-selected-text-clipboard text))
1380 )
1381
1382 (defun x-get-selection (&optional type data-type)
1383 "Return the value of a selection.
1384 The argument TYPE (default `PRIMARY') says which selection,
1385 and the argument DATA-TYPE (default `STRING') says
1386 how to convert the data.
1387
1388 TYPE may be any symbol \(but nil stands for `PRIMARY'). However,
1389 only a few symbols are commonly used. They conventionally have
1390 all upper-case names. The most often used ones, in addition to
1391 `PRIMARY', are `SECONDARY' and `CLIPBOARD'.
1392
1393 DATA-TYPE is usually `STRING', but can also be one of the symbols
1394 in `selection-converter-alist', which see."
1395 (let ((data (x-get-selection-internal (or type 'PRIMARY)
1396 (or data-type 'STRING)))
1397 (coding (or next-selection-coding-system
1398 selection-coding-system)))
1399 (when (and (stringp data)
1400 (setq data-type (get-text-property 0 'foreign-selection data)))
1401 (cond ((eq data-type 'public.utf16-plain-text)
1402 (setq data (mac-utxt-to-string data coding)))
1403 ((eq data-type 'com.apple.traditional-mac-plain-text)
1404 (setq data (mac-TEXT-to-string data coding)))
1405 ((eq data-type 'public.file-url)
1406 (setq data (mac-furl-to-string data))))
1407 (put-text-property 0 (length data) 'foreign-selection data-type data))
1408 data))
1409
1410 (defun x-selection-value (type)
1411 (let ((data-types '(public.utf16-plain-text
1412 com.apple.traditional-mac-plain-text
1413 public.file-url))
1414 text tiff-image)
1415 (while (and (null text) data-types)
1416 (setq text (condition-case nil
1417 (x-get-selection type (car data-types))
1418 (error nil)))
1419 (setq data-types (cdr data-types)))
1420 (if text
1421 (remove-text-properties 0 (length text) '(foreign-selection nil) text))
1422 (setq tiff-image (condition-case nil
1423 (x-get-selection type 'public.tiff)
1424 (error nil)))
1425 (when tiff-image
1426 (remove-text-properties 0 (length tiff-image)
1427 '(foreign-selection nil) tiff-image)
1428 (setq text (mac-TIFF-to-string tiff-image text)))
1429 text))
1430
1431 ;;; Return the value of the current selection.
1432 ;;; Treat empty strings as if they were unset.
1433 ;;; If this function is called twice and finds the same text,
1434 ;;; it returns nil the second time. This is so that a single
1435 ;;; selection won't be added to the kill ring over and over.
1436 (defun x-get-selection-value ()
1437 (let (clip-text primary-text)
1438 (if (not x-select-enable-clipboard)
1439 (setq x-last-selected-text-clipboard nil)
1440 (setq clip-text (x-selection-value 'CLIPBOARD))
1441 (if (string= clip-text "") (setq clip-text nil))
1442
1443 ;; Check the CLIPBOARD selection for 'newness', is it different
1444 ;; from what we remebered them to be last time we did a
1445 ;; cut/paste operation.
1446 (setq clip-text
1447 (cond;; check clipboard
1448 ((or (not clip-text) (string= clip-text ""))
1449 (setq x-last-selected-text-clipboard nil))
1450 ((eq clip-text x-last-selected-text-clipboard) nil)
1451 ((string= clip-text x-last-selected-text-clipboard)
1452 ;; Record the newer string,
1453 ;; so subsequent calls can use the `eq' test.
1454 (setq x-last-selected-text-clipboard clip-text)
1455 nil)
1456 (t
1457 (setq x-last-selected-text-clipboard clip-text))))
1458 )
1459
1460 (setq primary-text (x-selection-value 'PRIMARY))
1461 ;; Check the PRIMARY selection for 'newness', is it different
1462 ;; from what we remebered them to be last time we did a
1463 ;; cut/paste operation.
1464 (setq primary-text
1465 (cond;; check primary selection
1466 ((or (not primary-text) (string= primary-text ""))
1467 (setq x-last-selected-text-primary nil))
1468 ((eq primary-text x-last-selected-text-primary) nil)
1469 ((string= primary-text x-last-selected-text-primary)
1470 ;; Record the newer string,
1471 ;; so subsequent calls can use the `eq' test.
1472 (setq x-last-selected-text-primary primary-text)
1473 nil)
1474 (t
1475 (setq x-last-selected-text-primary primary-text))))
1476
1477 ;; As we have done one selection, clear this now.
1478 (setq next-selection-coding-system nil)
1479
1480 ;; At this point we have recorded the current values for the
1481 ;; selection from clipboard (if we are supposed to) and primary,
1482 ;; So return the first one that has changed (which is the first
1483 ;; non-null one).
1484 (or clip-text primary-text)
1485 ))
1486
1487 (put 'CLIPBOARD 'mac-scrap-name "com.apple.scrap.clipboard")
1488 (when (eq system-type 'darwin)
1489 (put 'FIND 'mac-scrap-name "com.apple.scrap.find")
1490 (put 'PRIMARY 'mac-scrap-name
1491 (format "org.gnu.Emacs.%d.selection.PRIMARY" (emacs-pid))))
1492 (put 'com.apple.traditional-mac-plain-text 'mac-ostype "TEXT")
1493 (put 'public.utf16-plain-text 'mac-ostype "utxt")
1494 (put 'public.tiff 'mac-ostype "TIFF")
1495 (put 'public.file-url 'mac-ostype "furl")
1496
1497 (defun mac-select-convert-to-string (selection type value)
1498 (let ((str (cdr (xselect-convert-to-string selection nil value)))
1499 (coding (or next-selection-coding-system selection-coding-system)))
1500 (when str
1501 ;; If TYPE is nil, this is a local request, thus return STR as
1502 ;; is. Otherwise, encode STR.
1503 (if (not type)
1504 str
1505 (let ((inhibit-read-only t))
1506 (remove-text-properties 0 (length str) '(composition nil) str)
1507 (cond
1508 ((eq type 'public.utf16-plain-text)
1509 (setq str (mac-string-to-utxt str coding)))
1510 ((eq type 'com.apple.traditional-mac-plain-text)
1511 (setq str (mac-string-to-TEXT str coding)))
1512 (t
1513 (error "Unknown selection type: %S" type))
1514 )))
1515
1516 (setq next-selection-coding-system nil)
1517 (cons type str))))
1518
1519 (defun mac-select-convert-to-file-url (selection type value)
1520 (let ((filename (xselect-convert-to-filename selection type value))
1521 (coding (or file-name-coding-system default-file-name-coding-system)))
1522 (if (and filename coding)
1523 (setq filename (encode-coding-string filename coding)))
1524 (and filename
1525 (concat "file://localhost"
1526 (mapconcat 'url-hexify-string
1527 (split-string filename "/") "/")))))
1528
1529 (setq selection-converter-alist
1530 (nconc
1531 '((public.utf16-plain-text . mac-select-convert-to-string)
1532 (com.apple.traditional-mac-plain-text . mac-select-convert-to-string)
1533 ;; This is not enabled by default because the `Import Image'
1534 ;; menu makes Emacs crash or hang for unknown reasons.
1535 ;; (public.tiff . nil)
1536 (public.file-url . mac-select-convert-to-file-url)
1537 )
1538 selection-converter-alist))
1539 \f
1540 ;;;; Apple events, HICommand events, and Services menu
1541
1542 ;;; Event classes
1543 (put 'core-event 'mac-apple-event-class "aevt") ; kCoreEventClass
1544 (put 'internet-event 'mac-apple-event-class "GURL") ; kAEInternetEventClass
1545
1546 ;;; Event IDs
1547 ;; kCoreEventClass
1548 (put 'open-application 'mac-apple-event-id "oapp") ; kAEOpenApplication
1549 (put 'reopen-application 'mac-apple-event-id "rapp") ; kAEReopenApplication
1550 (put 'open-documents 'mac-apple-event-id "odoc") ; kAEOpenDocuments
1551 (put 'print-documents 'mac-apple-event-id "pdoc") ; kAEPrintDocuments
1552 (put 'open-contents 'mac-apple-event-id "ocon") ; kAEOpenContents
1553 (put 'quit-application 'mac-apple-event-id "quit") ; kAEQuitApplication
1554 (put 'application-died 'mac-apple-event-id "obit") ; kAEApplicationDied
1555 (put 'show-preferences 'mac-apple-event-id "pref") ; kAEShowPreferences
1556 (put 'autosave-now 'mac-apple-event-id "asav") ; kAEAutosaveNow
1557 ;; kAEInternetEventClass
1558 (put 'get-url 'mac-apple-event-id "GURL") ; kAEGetURL
1559 ;; Converted HI command events
1560 (put 'about 'mac-apple-event-id "abou") ; kHICommandAbout
1561 (put 'show-hide-font-panel 'mac-apple-event-id "shfp") ; kHICommandShowHideFontPanel
1562
1563 (defmacro mac-event-spec (event)
1564 `(nth 1 ,event))
1565
1566 (defmacro mac-event-ae (event)
1567 `(nth 2 ,event))
1568
1569 (defun mac-ae-parameter (ae &optional keyword type)
1570 (or keyword (setq keyword "----")) ;; Direct object.
1571 (if (not (and (consp ae) (equal (car ae) "aevt")))
1572 (error "Not an Apple event: %S" ae)
1573 (let ((type-data (cdr (assoc keyword (cdr ae))))
1574 data)
1575 (when (and type type-data (not (equal type (car type-data))))
1576 (setq data (mac-coerce-ae-data (car type-data) (cdr type-data) type))
1577 (setq type-data (if data (cons type data) nil)))
1578 type-data)))
1579
1580 (defun mac-ae-list (ae &optional keyword type)
1581 (or keyword (setq keyword "----")) ;; Direct object.
1582 (let ((desc (mac-ae-parameter ae keyword "list")))
1583 (cond ((null desc)
1584 nil)
1585 ((not (equal (car desc) "list"))
1586 (error "Parameter for \"%s\" is not a list" keyword))
1587 (t
1588 (if (null type)
1589 (cdr desc)
1590 (mapcar
1591 (lambda (type-data)
1592 (mac-coerce-ae-data (car type-data) (cdr type-data) type))
1593 (cdr desc)))))))
1594
1595 (defun mac-ae-number (ae keyword)
1596 (let ((type-data (mac-ae-parameter ae keyword))
1597 str)
1598 (if (and type-data
1599 (setq str (mac-coerce-ae-data (car type-data)
1600 (cdr type-data) "TEXT")))
1601 (let ((num (string-to-number str)))
1602 ;; Mac OS Classic may return "0e+0" as the coerced value for
1603 ;; the type "magn" and the data "\000\000\000\000".
1604 (if (= num 0.0) 0 num))
1605 nil)))
1606
1607 (defun mac-bytes-to-integer (bytes &optional from to)
1608 (or from (setq from 0))
1609 (or to (setq to (length bytes)))
1610 (let* ((len (- to from))
1611 (extended-sign-len (- (1+ (ceiling (log most-positive-fixnum 2)))
1612 (* 8 len)))
1613 (result 0))
1614 (dotimes (i len)
1615 (setq result (logior (lsh result 8)
1616 (aref bytes (+ from (if (eq (byteorder) ?B) i
1617 (- len i 1)))))))
1618 (if (> extended-sign-len 0)
1619 (ash (lsh result extended-sign-len) (- extended-sign-len))
1620 result)))
1621
1622 (defun mac-ae-selection-range (ae)
1623 ;; #pragma options align=mac68k
1624 ;; typedef struct SelectionRange {
1625 ;; short unused1; // 0 (not used)
1626 ;; short lineNum; // line to select (<0 to specify range)
1627 ;; long startRange; // start of selection range (if line < 0)
1628 ;; long endRange; // end of selection range (if line < 0)
1629 ;; long unused2; // 0 (not used)
1630 ;; long theDate; // modification date/time
1631 ;; } SelectionRange;
1632 ;; #pragma options align=reset
1633 (let ((range-bytes (cdr (mac-ae-parameter ae "kpos" "TEXT"))))
1634 (and range-bytes
1635 (list (mac-bytes-to-integer range-bytes 2 4)
1636 (mac-bytes-to-integer range-bytes 4 8)
1637 (mac-bytes-to-integer range-bytes 8 12)
1638 (mac-bytes-to-integer range-bytes 16 20)))))
1639
1640 ;; On Mac OS X 10.4 and later, the `open-document' event contains an
1641 ;; optional parameter keyAESearchText from the Spotlight search.
1642 (defun mac-ae-text-for-search (ae)
1643 (let ((utf8-text (cdr (mac-ae-parameter ae "stxt" "utf8"))))
1644 (and utf8-text
1645 (decode-coding-string utf8-text 'utf-8))))
1646
1647 (defun mac-ae-text (ae)
1648 (or (cdr (mac-ae-parameter ae nil "TEXT"))
1649 (error "No text in Apple event.")))
1650
1651 (defun mac-ae-frame (ae &optional keyword type)
1652 (let ((bytes (cdr (mac-ae-parameter ae keyword type))))
1653 (if (or (null bytes) (/= (length bytes) 4))
1654 (error "No window reference in Apple event.")
1655 (let ((window-id (mac-coerce-ae-data "long" bytes "TEXT"))
1656 (rest (frame-list))
1657 frame)
1658 (while (and (null frame) rest)
1659 (if (string= (frame-parameter (car rest) 'window-id) window-id)
1660 (setq frame (car rest)))
1661 (setq rest (cdr rest)))
1662 frame))))
1663
1664 (defun mac-ae-script-language (ae keyword)
1665 ;; struct WritingCode {
1666 ;; ScriptCode theScriptCode;
1667 ;; LangCode theLangCode;
1668 ;; };
1669 (let ((bytes (cdr (mac-ae-parameter ae keyword "intl"))))
1670 (and bytes
1671 (cons (mac-bytes-to-integer bytes 0 2)
1672 (mac-bytes-to-integer bytes 2 4)))))
1673
1674 (defun mac-bytes-to-text-range (bytes &optional from to)
1675 ;; struct TextRange {
1676 ;; long fStart;
1677 ;; long fEnd;
1678 ;; short fHiliteStyle;
1679 ;; };
1680 (or from (setq from 0))
1681 (or to (setq to (length bytes)))
1682 (and (= (- to from) (+ 4 4 2))
1683 (list (mac-bytes-to-integer bytes from (+ from 4))
1684 (mac-bytes-to-integer bytes (+ from 4) (+ from 8))
1685 (mac-bytes-to-integer bytes (+ from 8) to))))
1686
1687 (defun mac-ae-text-range-array (ae keyword)
1688 ;; struct TextRangeArray {
1689 ;; short fNumOfRanges;
1690 ;; TextRange fRange[1];
1691 ;; };
1692 (let* ((bytes (cdr (mac-ae-parameter ae keyword "tray")))
1693 (len (length bytes))
1694 nranges result)
1695 (when (and bytes (>= len 2)
1696 (progn
1697 (setq nranges (mac-bytes-to-integer bytes 0 2))
1698 (= len (+ 2 (* nranges 10)))))
1699 (setq result (make-vector nranges nil))
1700 (dotimes (i nranges)
1701 (aset result i
1702 (mac-bytes-to-text-range bytes (+ (* i 10) 2)
1703 (+ (* i 10) 12)))))
1704 result))
1705
1706 (defconst mac-keyboard-modifier-mask-alist
1707 (mapcar
1708 (lambda (modifier-bit)
1709 (cons (car modifier-bit) (lsh 1 (cdr modifier-bit))))
1710 '((command . 8) ; cmdKeyBit
1711 (shift . 9) ; shiftKeyBit
1712 (option . 11) ; optionKeyBit
1713 (control . 12) ; controlKeyBit
1714 (function . 17))) ; kEventKeyModifierFnBit
1715 "Alist of Mac keyboard modifier symbols vs masks.")
1716
1717 (defun mac-ae-keyboard-modifiers (ae)
1718 (let ((modifiers-value (mac-ae-number ae "kmod"))
1719 modifiers)
1720 (if modifiers-value
1721 (dolist (modifier-mask mac-keyboard-modifier-mask-alist)
1722 (if (/= (logand modifiers-value (cdr modifier-mask)) 0)
1723 (setq modifiers (cons (car modifier-mask) modifiers)))))
1724 modifiers))
1725
1726 (defun mac-ae-reopen-application (event)
1727 "Show some frame in response to the Apple event EVENT.
1728 The frame to be shown is chosen from visible or iconified frames
1729 if possible. If there's no such frame, a new frame is created."
1730 (interactive "e")
1731 (unless (frame-visible-p (selected-frame))
1732 (let ((frame (or (car (visible-frame-list))
1733 (car (filtered-frame-list 'frame-visible-p)))))
1734 (if frame
1735 (select-frame frame)
1736 (switch-to-buffer-other-frame "*scratch*"))))
1737 (select-frame-set-input-focus (selected-frame)))
1738
1739 (defun mac-ae-open-documents (event)
1740 "Open the documents specified by the Apple event EVENT."
1741 (interactive "e")
1742 (let ((ae (mac-event-ae event)))
1743 (dolist (file-name (mac-ae-list ae nil 'undecoded-file-name))
1744 (if file-name
1745 (dnd-open-local-file
1746 (concat "file://"
1747 (mapconcat 'url-hexify-string
1748 (split-string file-name "/") "/")) nil)))
1749 (let ((selection-range (mac-ae-selection-range ae))
1750 (search-text (mac-ae-text-for-search ae)))
1751 (cond (selection-range
1752 (let ((line (car selection-range))
1753 (start (cadr selection-range))
1754 (end (nth 2 selection-range)))
1755 (if (> line 0)
1756 (goto-line line)
1757 (if (and (> start 0) (> end 0))
1758 (progn (set-mark start)
1759 (goto-char end))))))
1760 ((stringp search-text)
1761 (re-search-forward
1762 (mapconcat 'regexp-quote (split-string search-text) "\\|")
1763 nil t)))))
1764 (select-frame-set-input-focus (selected-frame)))
1765
1766 (defun mac-ae-quit-application (event)
1767 "Quit the application Emacs with the Apple event EVENT."
1768 (interactive "e")
1769 (let ((ae (mac-event-ae event)))
1770 (unwind-protect
1771 (save-buffers-kill-emacs)
1772 ;; Reaches here if the user has canceled the quit.
1773 (mac-resume-apple-event ae -128)))) ; userCanceledErr
1774
1775 ;; url-generic-parse-url is autoloaded from url-parse.
1776 (declare-function url-type "url-parse" t t) ; defstruct
1777
1778 (defun mac-ae-get-url (event)
1779 "Open the URL specified by the Apple event EVENT.
1780 Currently the `mailto' scheme is supported."
1781 (interactive "e")
1782 (let* ((ae (mac-event-ae event))
1783 (parsed-url (url-generic-parse-url (mac-ae-text ae))))
1784 (if (string= (url-type parsed-url) "mailto")
1785 (progn
1786 (url-mailto parsed-url)
1787 (select-frame-set-input-focus (selected-frame)))
1788 (mac-resume-apple-event ae t))))
1789
1790 (setq mac-apple-event-map (make-sparse-keymap))
1791
1792 ;; Received when Emacs is launched without associated documents.
1793 ;; Accept it as an Apple event, but no Emacs event is generated so as
1794 ;; not to erase the splash screen.
1795 (define-key mac-apple-event-map [core-event open-application] 0)
1796
1797 ;; Received when a dock or application icon is clicked and Emacs is
1798 ;; already running.
1799 (define-key mac-apple-event-map [core-event reopen-application]
1800 'mac-ae-reopen-application)
1801
1802 (define-key mac-apple-event-map [core-event open-documents]
1803 'mac-ae-open-documents)
1804 (define-key mac-apple-event-map [core-event show-preferences] 'customize)
1805 (define-key mac-apple-event-map [core-event quit-application]
1806 'mac-ae-quit-application)
1807
1808 (define-key mac-apple-event-map [internet-event get-url] 'mac-ae-get-url)
1809
1810 (define-key mac-apple-event-map [hi-command about] 'about-emacs)
1811
1812 ;;; Converted Carbon Events
1813 (defun mac-handle-toolbar-switch-mode (event)
1814 "Toggle visibility of tool-bars in response to EVENT.
1815 With no keyboard modifiers, it toggles the visibility of the
1816 frame where the tool-bar toggle button was pressed. With some
1817 modifiers, it changes the global tool-bar visibility setting."
1818 (interactive "e")
1819 (let ((ae (mac-event-ae event)))
1820 (if (mac-ae-keyboard-modifiers ae)
1821 ;; Globally toggle tool-bar-mode if some modifier key is pressed.
1822 (tool-bar-mode 'toggle)
1823 (let ((frame (mac-ae-frame ae)))
1824 (set-frame-parameter frame 'tool-bar-lines
1825 (if (= (frame-parameter frame 'tool-bar-lines) 0)
1826 1 0))))))
1827
1828 ;; kEventClassWindow/kEventWindowToolbarSwitchMode
1829 (define-key mac-apple-event-map [window toolbar-switch-mode]
1830 'mac-handle-toolbar-switch-mode)
1831
1832 ;;; Font panel
1833 (when (fboundp 'mac-set-font-panel-visible-p)
1834
1835 (define-minor-mode mac-font-panel-mode
1836 "Toggle use of the font panel.
1837 With numeric ARG, display the font panel if and only if ARG is positive."
1838 :init-value nil
1839 :global t
1840 :group 'mac
1841 (mac-set-font-panel-visible-p mac-font-panel-mode))
1842
1843 (defun mac-handle-font-panel-closed (event)
1844 "Update internal status in response to font panel closed EVENT."
1845 (interactive "e")
1846 ;; Synchronize with the minor mode variable.
1847 (mac-font-panel-mode 0))
1848
1849 (defun mac-handle-font-selection (event)
1850 "Change default face attributes according to font selection EVENT."
1851 (interactive "e")
1852 (let* ((ae (mac-event-ae event))
1853 (fm-font-size (mac-ae-number ae "fmsz"))
1854 (atsu-font-id (mac-ae-number ae "auid"))
1855 (attribute-values (and atsu-font-id
1856 (mac-atsu-font-face-attributes atsu-font-id))))
1857 (if fm-font-size
1858 (setq attribute-values
1859 `(:height ,(* 10 fm-font-size) ,@attribute-values)))
1860 (apply 'set-face-attribute 'default (selected-frame) attribute-values)))
1861
1862 ;; kEventClassFont/kEventFontPanelClosed
1863 (define-key mac-apple-event-map [font panel-closed]
1864 'mac-handle-font-panel-closed)
1865 ;; kEventClassFont/kEventFontSelection
1866 (define-key mac-apple-event-map [font selection] 'mac-handle-font-selection)
1867 (define-key mac-apple-event-map [hi-command show-hide-font-panel]
1868 'mac-font-panel-mode)
1869
1870 (define-key-after menu-bar-showhide-menu [mac-font-panel-mode]
1871 (menu-bar-make-mm-toggle mac-font-panel-mode
1872 "Font Panel"
1873 "Show the font panel as a floating dialog")
1874 'showhide-speedbar)
1875
1876 ) ;; (fboundp 'mac-set-font-panel-visible-p)
1877
1878 ;;; Text Services
1879 (defvar mac-ts-active-input-buf ""
1880 "Byte sequence of the current Mac TSM active input area.")
1881 (defvar mac-ts-update-active-input-area-seqno 0
1882 "Number of processed update-active-input-area events.")
1883 (setq mac-ts-active-input-overlay (make-overlay 0 0))
1884
1885 (defface mac-ts-caret-position
1886 '((t :inverse-video t))
1887 "Face for caret position in Mac TSM active input area.
1888 This is used when the active input area is displayed either in
1889 the echo area or in a buffer where the cursor is not displayed."
1890 :group 'mac)
1891
1892 (defface mac-ts-raw-text
1893 '((t :underline t))
1894 "Face for raw text in Mac TSM active input area."
1895 :group 'mac)
1896
1897 (defface mac-ts-selected-raw-text
1898 '((t :underline t))
1899 "Face for selected raw text in Mac TSM active input area."
1900 :group 'mac)
1901
1902 (defface mac-ts-converted-text
1903 '((((background dark)) :underline "gray20")
1904 (t :underline "gray80"))
1905 "Face for converted text in Mac TSM active input area."
1906 :group 'mac)
1907
1908 (defface mac-ts-selected-converted-text
1909 '((t :underline t))
1910 "Face for selected converted text in Mac TSM active input area."
1911 :group 'mac)
1912
1913 (defface mac-ts-block-fill-text
1914 '((t :underline t))
1915 "Face for block fill text in Mac TSM active input area."
1916 :group 'mac)
1917
1918 (defface mac-ts-outline-text
1919 '((t :underline t))
1920 "Face for outline text in Mac TSM active input area."
1921 :group 'mac)
1922
1923 (defface mac-ts-selected-text
1924 '((t :underline t))
1925 "Face for selected text in Mac TSM active input area."
1926 :group 'mac)
1927
1928 (defface mac-ts-no-hilite
1929 '((t :inherit default))
1930 "Face for no hilite in Mac TSM active input area."
1931 :group 'mac)
1932
1933 (defconst mac-ts-hilite-style-faces
1934 '((2 . mac-ts-raw-text) ; kTSMHiliteRawText
1935 (3 . mac-ts-selected-raw-text) ; kTSMHiliteSelectedRawText
1936 (4 . mac-ts-converted-text) ; kTSMHiliteConvertedText
1937 (5 . mac-ts-selected-converted-text) ; kTSMHiliteSelectedConvertedText
1938 (6 . mac-ts-block-fill-text) ; kTSMHiliteBlockFillText
1939 (7 . mac-ts-outline-text) ; kTSMHiliteOutlineText
1940 (8 . mac-ts-selected-text) ; kTSMHiliteSelectedText
1941 (9 . mac-ts-no-hilite)) ; kTSMHiliteNoHilite
1942 "Alist of Mac TSM hilite style vs Emacs face.")
1943
1944 (defun mac-ts-update-active-input-buf (text fix-len hilite-rng update-rng)
1945 (let ((buf-len (length mac-ts-active-input-buf))
1946 confirmed)
1947 (if (or (null update-rng)
1948 (/= (% (length update-rng) 2) 0))
1949 ;; The parameter is missing (or in a bad format). The
1950 ;; existing inline input session is completely replaced with
1951 ;; the new text.
1952 (setq mac-ts-active-input-buf text)
1953 ;; Otherwise, the current subtext specified by the (2*j)-th
1954 ;; range is replaced with the new subtext specified by the
1955 ;; (2*j+1)-th range.
1956 (let ((tail buf-len)
1957 (i (length update-rng))
1958 segments rng)
1959 (while (> i 0)
1960 (setq i (- i 2))
1961 (setq rng (aref update-rng i))
1962 (if (and (<= 0 (cadr rng)) (< (cadr rng) tail)
1963 (<= tail buf-len))
1964 (setq segments
1965 (cons (substring mac-ts-active-input-buf (cadr rng) tail)
1966 segments)))
1967 (setq tail (car rng))
1968 (setq rng (aref update-rng (1+ i)))
1969 (if (and (<= 0 (car rng)) (< (car rng) (cadr rng))
1970 (<= (cadr rng) (length text)))
1971 (setq segments
1972 (cons (substring text (car rng) (cadr rng))
1973 segments))))
1974 (if (and (< 0 tail) (<= tail buf-len))
1975 (setq segments
1976 (cons (substring mac-ts-active-input-buf 0 tail)
1977 segments)))
1978 (setq mac-ts-active-input-buf (apply 'concat segments))))
1979 (setq buf-len (length mac-ts-active-input-buf))
1980 ;; Confirm (a part of) inline input session.
1981 (cond ((< fix-len 0)
1982 ;; Entire inline session is being confirmed.
1983 (setq confirmed mac-ts-active-input-buf)
1984 (setq mac-ts-active-input-buf ""))
1985 ((= fix-len 0)
1986 ;; None of the text is being confirmed (yet).
1987 (setq confirmed ""))
1988 (t
1989 (if (> fix-len buf-len)
1990 (setq fix-len buf-len))
1991 (setq confirmed (substring mac-ts-active-input-buf 0 fix-len))
1992 (setq mac-ts-active-input-buf
1993 (substring mac-ts-active-input-buf fix-len))))
1994 (setq buf-len (length mac-ts-active-input-buf))
1995 ;; Update highlighting and the caret position in the new inline
1996 ;; input session.
1997 (remove-text-properties 0 buf-len '(cursor nil) mac-ts-active-input-buf)
1998 (mapc (lambda (rng)
1999 (cond ((and (= (nth 2 rng) 1) ; kTSMHiliteCaretPosition
2000 (<= 0 (car rng)) (< (car rng) buf-len))
2001 (put-text-property (car rng) buf-len
2002 'cursor t mac-ts-active-input-buf))
2003 ((and (<= 0 (car rng)) (< (car rng) (cadr rng))
2004 (<= (cadr rng) buf-len))
2005 (put-text-property (car rng) (cadr rng) 'face
2006 (cdr (assq (nth 2 rng)
2007 mac-ts-hilite-style-faces))
2008 mac-ts-active-input-buf))))
2009 hilite-rng)
2010 confirmed))
2011
2012 (defun mac-split-string-by-property-change (string)
2013 (let ((tail (length string))
2014 head result)
2015 (unless (= tail 0)
2016 (while (setq head (previous-property-change tail string)
2017 result (cons (substring string (or head 0) tail) result)
2018 tail head)))
2019 result))
2020
2021 (defun mac-replace-untranslated-utf-8-chars (string &optional to-string)
2022 (or to-string (setq to-string "\e$,3u=\e(B"))
2023 (mapconcat
2024 (lambda (str)
2025 (if (get-text-property 0 'untranslated-utf-8 str) to-string str))
2026 (mac-split-string-by-property-change string)
2027 ""))
2028
2029 (defun mac-keyboard-translate-char (ch)
2030 (if (and (char-valid-p ch)
2031 (or (char-table-p keyboard-translate-table)
2032 (and (or (stringp keyboard-translate-table)
2033 (vectorp keyboard-translate-table))
2034 (> (length keyboard-translate-table) ch))))
2035 (or (aref keyboard-translate-table ch) ch)
2036 ch))
2037
2038 (defun mac-unread-string (string)
2039 ;; Unread characters and insert them in a keyboard macro being
2040 ;; defined.
2041 (apply 'isearch-unread
2042 (mapcar 'mac-keyboard-translate-char
2043 (mac-replace-untranslated-utf-8-chars string))))
2044
2045 (defun mac-ts-update-active-input-area (event)
2046 "Update Mac TSM active input area according to EVENT.
2047 The confirmed text is converted to Emacs input events and pushed
2048 into `unread-command-events'. The unconfirmed text is displayed
2049 either in the current buffer or in the echo area."
2050 (interactive "e")
2051 (let* ((ae (mac-event-ae event))
2052 (type-text (mac-ae-parameter ae "tstx"))
2053 (text (or (cdr type-text) ""))
2054 (decode-fun (if (equal (car type-text) "TEXT")
2055 'mac-TEXT-to-string 'mac-utxt-to-string))
2056 (script-language (mac-ae-script-language ae "tssl"))
2057 (coding (or (cdr (assq (car script-language)
2058 mac-script-code-coding-systems))
2059 'mac-roman))
2060 (fix-len (mac-ae-number ae "tsfx"))
2061 ;; Optional parameters
2062 (hilite-rng (mac-ae-text-range-array ae "tshi"))
2063 (update-rng (mac-ae-text-range-array ae "tsup"))
2064 ;;(pin-rng (mac-bytes-to-text-range (cdr (mac-ae-parameter ae "tspn" "txrn"))))
2065 ;;(clause-offsets (cdr (mac-ae-parameter ae "tscl" "ofay")))
2066 (seqno (mac-ae-number ae "tsSn"))
2067 confirmed)
2068 (unless (= seqno mac-ts-update-active-input-area-seqno)
2069 ;; Reset internal states if sequence number is out of sync.
2070 (setq mac-ts-active-input-buf ""))
2071 (setq confirmed
2072 (mac-ts-update-active-input-buf text fix-len hilite-rng update-rng))
2073 (let ((use-echo-area
2074 (or isearch-mode
2075 (and cursor-in-echo-area (current-message))
2076 ;; Overlay strings are not shown in some cases.
2077 (get-char-property (point) 'invisible)
2078 (and (not (bobp))
2079 (or (and (get-char-property (point) 'display)
2080 (eq (get-char-property (1- (point)) 'display)
2081 (get-char-property (point) 'display)))
2082 (and (get-char-property (point) 'composition)
2083 (eq (get-char-property (1- (point)) 'composition)
2084 (get-char-property (point) 'composition)))))))
2085 active-input-string caret-seen)
2086 ;; Decode the active input area text with inheriting faces and
2087 ;; the caret position.
2088 (setq active-input-string
2089 (mapconcat
2090 (lambda (str)
2091 (let ((decoded (funcall decode-fun str coding)))
2092 (put-text-property 0 (length decoded) 'face
2093 (get-text-property 0 'face str) decoded)
2094 (when (and (not caret-seen)
2095 (get-text-property 0 'cursor str))
2096 (setq caret-seen t)
2097 (if (or use-echo-area (null cursor-type))
2098 (put-text-property 0 1 'face 'mac-ts-caret-position
2099 decoded)
2100 (put-text-property 0 1 'cursor t decoded)))
2101 decoded))
2102 (mac-split-string-by-property-change mac-ts-active-input-buf)
2103 ""))
2104 (put-text-property 0 (length active-input-string)
2105 'mac-ts-active-input-string t active-input-string)
2106 (if use-echo-area
2107 (let ((msg (current-message))
2108 message-log-max)
2109 (if (and msg
2110 ;; Don't get confused by previously displayed
2111 ;; `active-input-string'.
2112 (null (get-text-property 0 'mac-ts-active-input-string
2113 msg)))
2114 (setq msg (propertize msg 'display
2115 (concat msg active-input-string)))
2116 (setq msg active-input-string))
2117 (message "%s" msg)
2118 (overlay-put mac-ts-active-input-overlay 'before-string nil))
2119 (move-overlay mac-ts-active-input-overlay
2120 (point) (point) (current-buffer))
2121 (overlay-put mac-ts-active-input-overlay 'before-string
2122 active-input-string))
2123 (mac-unread-string (funcall decode-fun confirmed coding)))
2124 ;; The event is successfully processed. Sync the sequence number.
2125 (setq mac-ts-update-active-input-area-seqno (1+ seqno))))
2126
2127 (defun mac-ts-unicode-for-key-event (event)
2128 "Convert Unicode key EVENT to Emacs key events and unread them."
2129 (interactive "e")
2130 (let* ((ae (mac-event-ae event))
2131 (text (cdr (mac-ae-parameter ae "tstx" "utxt")))
2132 (script-language (mac-ae-script-language ae "tssl"))
2133 (coding (or (cdr (assq (car script-language)
2134 mac-script-code-coding-systems))
2135 'mac-roman)))
2136 (if text
2137 (mac-unread-string (mac-utxt-to-string text coding)))))
2138
2139 ;; kEventClassTextInput/kEventTextInputUpdateActiveInputArea
2140 (define-key mac-apple-event-map [text-input update-active-input-area]
2141 'mac-ts-update-active-input-area)
2142 ;; kEventClassTextInput/kEventTextInputUnicodeForKeyEvent
2143 (define-key mac-apple-event-map [text-input unicode-for-key-event]
2144 'mac-ts-unicode-for-key-event)
2145
2146 ;;; Services
2147 (defun mac-service-open-file ()
2148 "Open the file specified by the selection value for Services."
2149 (interactive)
2150 (find-file-existing (x-selection-value mac-service-selection)))
2151
2152 (defun mac-service-open-selection ()
2153 "Create a new buffer containing the selection value for Services."
2154 (interactive)
2155 (switch-to-buffer (generate-new-buffer "*untitled*"))
2156 (insert (x-selection-value mac-service-selection))
2157 (sit-for 0)
2158 (save-buffer) ; It pops up the save dialog.
2159 )
2160
2161 (defun mac-service-mail-selection ()
2162 "Prepare a mail buffer containing the selection value for Services."
2163 (interactive)
2164 (compose-mail)
2165 (rfc822-goto-eoh)
2166 (forward-line 1)
2167 (insert (x-selection-value mac-service-selection) "\n"))
2168
2169 (defun mac-service-mail-to ()
2170 "Prepare a mail buffer to be sent to the selection value for Services."
2171 (interactive)
2172 (compose-mail (x-selection-value mac-service-selection)))
2173
2174 (defun mac-service-insert-text ()
2175 "Insert the selection value for Services."
2176 (interactive)
2177 (let ((text (x-selection-value mac-service-selection)))
2178 (if (not buffer-read-only)
2179 (insert text)
2180 (kill-new text)
2181 (message "%s"
2182 (substitute-command-keys
2183 "The text from the Services menu can be accessed with \\[yank]")))))
2184
2185 ;; kEventClassService/kEventServicePaste
2186 (define-key mac-apple-event-map [service paste] 'mac-service-insert-text)
2187 ;; kEventClassService/kEventServicePerform
2188 (define-key mac-apple-event-map [service perform open-file]
2189 'mac-service-open-file)
2190 (define-key mac-apple-event-map [service perform open-selection]
2191 'mac-service-open-selection)
2192 (define-key mac-apple-event-map [service perform mail-selection]
2193 'mac-service-mail-selection)
2194 (define-key mac-apple-event-map [service perform mail-to]
2195 'mac-service-mail-to)
2196
2197 (defun mac-dispatch-apple-event (event)
2198 "Dispatch EVENT according to the keymap `mac-apple-event-map'."
2199 (interactive "e")
2200 (let* ((binding (lookup-key mac-apple-event-map (mac-event-spec event)))
2201 (ae (mac-event-ae event))
2202 (service-message (and (keymapp binding)
2203 (cdr (mac-ae-parameter ae "svmg")))))
2204 (when service-message
2205 (setq service-message
2206 (intern (decode-coding-string service-message 'utf-8)))
2207 (setq binding (lookup-key binding (vector service-message))))
2208 ;; Replace (cadr event) with a dummy position so that event-start
2209 ;; returns it.
2210 (setcar (cdr event) (list (selected-window) (point) '(0 . 0) 0))
2211 (if (null (mac-ae-parameter ae 'emacs-suspension-id))
2212 (command-execute binding nil (vector event) t)
2213 (condition-case err
2214 (progn
2215 (command-execute binding nil (vector event) t)
2216 (mac-resume-apple-event ae))
2217 (error
2218 (mac-ae-set-reply-parameter ae "errs"
2219 (cons "TEXT" (error-message-string err)))
2220 (mac-resume-apple-event ae -10000)))))) ; errAEEventFailed
2221
2222 (define-key special-event-map [mac-apple-event] 'mac-dispatch-apple-event)
2223
2224 ;; Processing of Apple events are deferred at the startup time. For
2225 ;; example, files dropped onto the Emacs application icon can only be
2226 ;; processed when the initial frame has been created: this is where
2227 ;; the files should be opened.
2228 (add-hook 'after-init-hook 'mac-process-deferred-apple-events)
2229
2230 (run-with-idle-timer 5 t 'mac-cleanup-expired-apple-events)
2231
2232 \f
2233 ;;;; Drag and drop
2234
2235 (defcustom mac-dnd-types-alist
2236 '(("furl" . mac-dnd-handle-furl)
2237 ("hfs " . mac-dnd-handle-hfs)
2238 ("utxt" . mac-dnd-insert-utxt)
2239 ("TEXT" . mac-dnd-insert-TEXT)
2240 ("TIFF" . mac-dnd-insert-TIFF))
2241 "Which function to call to handle a drop of that type.
2242 The function takes three arguments, WINDOW, ACTION and DATA.
2243 WINDOW is where the drop occurred, ACTION is always `private' on
2244 Mac. DATA is the drop data. Unlike the x-dnd counterpart, the
2245 return value of the function is not significant.
2246
2247 See also `mac-dnd-known-types'."
2248 :version "22.1"
2249 :type 'alist
2250 :group 'mac)
2251
2252 (defun mac-dnd-handle-furl (window action data)
2253 (dnd-handle-one-url window action (mac-furl-to-string data)))
2254
2255 (defun mac-dnd-handle-hfs (window action data)
2256 ;; struct HFSFlavor {
2257 ;; OSType fileType;
2258 ;; OSType fileCreator;
2259 ;; UInt16 fdFlags;
2260 ;; FSSpec fileSpec;
2261 ;; };
2262 (let* ((file-name (mac-coerce-ae-data "fss " (substring data 10)
2263 'undecoded-file-name))
2264 (url (concat "file://"
2265 (mapconcat 'url-hexify-string
2266 (split-string file-name "/") "/"))))
2267 (dnd-handle-one-url window action url)))
2268
2269 (defun mac-dnd-insert-utxt (window action data)
2270 (dnd-insert-text window action (mac-utxt-to-string data)))
2271
2272 (defun mac-dnd-insert-TEXT (window action data)
2273 (dnd-insert-text window action (mac-TEXT-to-string data)))
2274
2275 (defun mac-dnd-insert-TIFF (window action data)
2276 (dnd-insert-text window action (mac-TIFF-to-string data)))
2277
2278 (defun mac-dnd-drop-data (event frame window data type &optional action)
2279 (or action (setq action 'private))
2280 (let* ((type-info (assoc type mac-dnd-types-alist))
2281 (handler (cdr type-info))
2282 (w (posn-window (event-start event))))
2283 (when handler
2284 (if (and (window-live-p w)
2285 (not (window-minibuffer-p w))
2286 (not (window-dedicated-p w)))
2287 ;; If dropping in an ordinary window which we could use,
2288 ;; let dnd-open-file-other-window specify what to do.
2289 (progn
2290 (when (not mouse-yank-at-point)
2291 (goto-char (posn-point (event-start event))))
2292 (funcall handler window action data))
2293 ;; If we can't display the file here,
2294 ;; make a new window for it.
2295 (let ((dnd-open-file-other-window t))
2296 (select-frame frame)
2297 (funcall handler window action data))))))
2298
2299 (defun mac-dnd-handle-drag-n-drop-event (event)
2300 "Receive drag and drop events."
2301 (interactive "e")
2302 (let ((window (posn-window (event-start event)))
2303 (ae (mac-event-ae event))
2304 action)
2305 (when (windowp window) (select-window window))
2306 (if (memq 'option (mac-ae-keyboard-modifiers ae))
2307 (setq action 'copy))
2308 (dolist (item (mac-ae-list ae))
2309 (if (not (equal (car item) "null"))
2310 (mac-dnd-drop-data event (selected-frame) window
2311 (cdr item) (car item) action)))))
2312 \f
2313 (defvar mac-font-encoder-list
2314 '(("mac-roman" mac-roman-encoder
2315 ccl-encode-mac-roman-font "%s")
2316 ("mac-centraleurroman" encode-mac-centraleurroman
2317 ccl-encode-mac-centraleurroman-font "%s ce")
2318 ("mac-cyrillic" encode-mac-cyrillic
2319 ccl-encode-mac-cyrillic-font "%s cy")
2320 ("mac-symbol" mac-symbol-encoder
2321 ccl-encode-mac-symbol-font "symbol")
2322 ("mac-dingbats" mac-dingbats-encoder
2323 ccl-encode-mac-dingbats-font "zapf dingbats")))
2324
2325 (let ((encoder-list
2326 (mapcar (lambda (lst) (nth 1 lst)) mac-font-encoder-list))
2327 (charset-list
2328 '(latin-iso8859-2
2329 latin-iso8859-3 latin-iso8859-4
2330 cyrillic-iso8859-5 greek-iso8859-7 hebrew-iso8859-8
2331 latin-iso8859-9 latin-iso8859-14 latin-iso8859-15)))
2332 (dolist (encoder encoder-list)
2333 (let ((table (get encoder 'translation-table)))
2334 (dolist (charset charset-list)
2335 (dotimes (i 96)
2336 (let* ((c (make-char charset (+ i 32)))
2337 (mu (aref ucs-mule-to-mule-unicode c))
2338 (mac-encoded (and mu (aref table mu))))
2339 (if mac-encoded
2340 (aset table c mac-encoded))))))))
2341
2342 ;; We assume none of official dim2 charsets (0x90..0x99) are encoded
2343 ;; to these fonts.
2344
2345 (define-ccl-program ccl-encode-mac-roman-font
2346 `(0
2347 (if (r0 <= ?\xef)
2348 (translate-character mac-roman-encoder r0 r1)
2349 ((r1 <<= 7)
2350 (r1 |= r2)
2351 (translate-character mac-roman-encoder r0 r1))))
2352 "CCL program for Mac Roman font")
2353
2354 (define-ccl-program ccl-encode-mac-centraleurroman-font
2355 `(0
2356 (if (r0 <= ?\xef)
2357 (translate-character encode-mac-centraleurroman r0 r1)
2358 ((r1 <<= 7)
2359 (r1 |= r2)
2360 (translate-character encode-mac-centraleurroman r0 r1))))
2361 "CCL program for Mac Central European Roman font")
2362
2363 (define-ccl-program ccl-encode-mac-cyrillic-font
2364 `(0
2365 (if (r0 <= ?\xef)
2366 (translate-character encode-mac-cyrillic r0 r1)
2367 ((r1 <<= 7)
2368 (r1 |= r2)
2369 (translate-character encode-mac-cyrillic r0 r1))))
2370 "CCL program for Mac Cyrillic font")
2371
2372 (define-ccl-program ccl-encode-mac-symbol-font
2373 `(0
2374 (if (r0 <= ?\xef)
2375 (translate-character mac-symbol-encoder r0 r1)
2376 ((r1 <<= 7)
2377 (r1 |= r2)
2378 (translate-character mac-symbol-encoder r0 r1))))
2379 "CCL program for Mac Symbol font")
2380
2381 (define-ccl-program ccl-encode-mac-dingbats-font
2382 `(0
2383 (if (r0 <= ?\xef)
2384 (translate-character mac-dingbats-encoder r0 r1)
2385 ((r1 <<= 7)
2386 (r1 |= r2)
2387 (translate-character mac-dingbats-encoder r0 r1))))
2388 "CCL program for Mac Dingbats font")
2389
2390
2391 (setq font-ccl-encoder-alist
2392 (nconc
2393 (mapcar (lambda (lst) (cons (nth 0 lst) (nth 2 lst)))
2394 mac-font-encoder-list)
2395 font-ccl-encoder-alist))
2396
2397 (defconst mac-char-fontspec-list
2398 ;; Directly operate on a char-table instead of a fontset so that it
2399 ;; may not create a dummy fontset.
2400 (let ((template (make-char-table 'fontset)))
2401 (dolist
2402 (font-encoder
2403 (nreverse
2404 (mapcar (lambda (lst)
2405 (cons (cons (nth 3 lst) (nth 0 lst)) (nth 1 lst)))
2406 mac-font-encoder-list)))
2407 (let ((font (car font-encoder))
2408 (encoder (cdr font-encoder)))
2409 (map-char-table
2410 (lambda (key val)
2411 (or (null val)
2412 (generic-char-p key)
2413 (memq (char-charset key)
2414 '(ascii eight-bit-control eight-bit-graphic))
2415 (aset template key font)))
2416 (get encoder 'translation-table))))
2417
2418 ;; Like fontset-info, but extend a range only if its "to" part is
2419 ;; the predecessor of the current char.
2420 (let* ((last '((0 nil)))
2421 (accumulator last)
2422 last-char-or-range last-char last-elt)
2423 (map-char-table
2424 (lambda (char elt)
2425 (when elt
2426 (setq last-char-or-range (car (car last))
2427 last-char (if (consp last-char-or-range)
2428 (cdr last-char-or-range)
2429 last-char-or-range)
2430 last-elt (cdr (car last)))
2431 (if (and (eq elt last-elt)
2432 (= char (1+ last-char))
2433 (eq (char-charset char) (char-charset last-char)))
2434 (if (consp last-char-or-range)
2435 (setcdr last-char-or-range char)
2436 (setcar (car last) (cons last-char char)))
2437 (setcdr last (list (cons char elt)))
2438 (setq last (cdr last)))))
2439 template)
2440 (cdr accumulator))))
2441
2442 (defun fontset-add-mac-fonts (fontset &optional base-family)
2443 "Add font-specs for Mac fonts to FONTSET.
2444 The added font-specs are determined by BASE-FAMILY and the value
2445 of `mac-char-fontspec-list', which is a list
2446 of (CHARACTER-OR-RANGE . (FAMILY-FORMAT . REGISTRY)). If
2447 BASE-FAMILY is nil, the font family in the added font-specs is
2448 also nil. If BASE-FAMILY is a string, `%s' in FAMILY-FORMAT is
2449 replaced with the string. Otherwise, `%s' in FAMILY-FORMAT is
2450 replaced with the ASCII font family name in FONTSET."
2451 (if base-family
2452 (if (stringp base-family)
2453 (setq base-family (downcase base-family))
2454 (let ((ascii-font (fontset-font fontset (charset-id 'ascii))))
2455 (if ascii-font
2456 (setq base-family
2457 (aref (x-decompose-font-name
2458 (downcase (x-resolve-font-name ascii-font)))
2459 xlfd-regexp-family-subnum))))))
2460 (let (fontspec-cache fontspec)
2461 (dolist (char-fontspec mac-char-fontspec-list)
2462 (setq fontspec (cdr (assq (cdr char-fontspec) fontspec-cache)))
2463 (when (null fontspec)
2464 (setq fontspec
2465 (cons (and base-family
2466 (format (car (cdr char-fontspec)) base-family))
2467 (cdr (cdr char-fontspec))))
2468 (setq fontspec-cache (cons (cons (cdr char-fontspec) fontspec)
2469 fontspec-cache)))
2470 (set-fontset-font fontset (car char-fontspec) fontspec))))
2471
2472 (defun create-fontset-from-mac-roman-font (font &optional resolved-font
2473 fontset-name)
2474 "Create a fontset from a Mac roman font FONT.
2475
2476 Optional 1st arg RESOLVED-FONT is a resolved name of FONT. If
2477 omitted, `x-resolve-font-name' is called to get the resolved name. At
2478 this time, if FONT is not available, error is signaled.
2479
2480 Optional 2nd arg FONTSET-NAME is a string to be used in
2481 `<CHARSET_ENCODING>' fields of a new fontset name. If it is omitted,
2482 an appropriate name is generated automatically.
2483
2484 It returns a name of the created fontset."
2485 (let ((fontset
2486 (create-fontset-from-ascii-font font resolved-font fontset-name)))
2487 (fontset-add-mac-fonts fontset t)
2488 fontset))
2489
2490 (defun x-win-suspend-error ()
2491 (error "Suspending an Emacs running under Mac makes no sense"))
2492
2493 (defalias 'x-cut-buffer-or-selection-value 'x-get-selection-value)
2494
2495 (defvar mac-initialized nil
2496 "Non-nil if the w32 window system has been initialized.")
2497
2498 (defun mac-initialize-window-system ()
2499 "Initialize Emacs for Mac GUI frames."
2500
2501 ;;; Do the actual Windows setup here; the above code just defines
2502 ;;; functions and variables that we use now.
2503
2504 (setq command-line-args (x-handle-args command-line-args))
2505
2506 ;;; Make sure we have a valid resource name.
2507 (or (stringp x-resource-name)
2508 (let (i)
2509 (setq x-resource-name (invocation-name))
2510
2511 ;; Change any . or * characters in x-resource-name to hyphens,
2512 ;; so as not to choke when we use it in X resource queries.
2513 (while (setq i (string-match "[.*]" x-resource-name))
2514 (aset x-resource-name i ?-))))
2515
2516 (if (x-display-list)
2517 ;; On Mac OS 8/9, Most coding systems used in code conversion for
2518 ;; font names are not ready at the time when the terminal frame is
2519 ;; created. So we reconstruct font name table for the initial
2520 ;; frame.
2521 (mac-clear-font-name-table)
2522 (x-open-connection "Mac"
2523 x-command-line-resources
2524 ;; Exit Emacs with fatal error if this fails.
2525 t))
2526
2527 (add-hook 'suspend-hook 'x-win-suspend-error)
2528
2529 ;;; Arrange for the kill and yank functions to set and check the clipboard.
2530 (setq interprogram-cut-function 'x-select-text)
2531 (setq interprogram-paste-function 'x-get-selection-value)
2532
2533
2534
2535
2536 ;;; Turn off window-splitting optimization; Mac is usually fast enough
2537 ;;; that this is only annoying.
2538 (setq split-window-keep-point t)
2539
2540 ;; Don't show the frame name; that's redundant.
2541 (setq-default mode-line-frame-identification " ")
2542
2543 ;; Turn on support for mouse wheels.
2544 (mouse-wheel-mode 1)
2545
2546
2547 ;; Enable CLIPBOARD copy/paste through menu bar commands.
2548 (menu-bar-enable-clipboard)
2549
2550
2551 ;; Initiate drag and drop
2552
2553 (define-key special-event-map [drag-n-drop] 'mac-dnd-handle-drag-n-drop-event)
2554
2555 \f
2556 ;;;; Non-toolkit Scroll bars
2557
2558 (unless x-toolkit-scroll-bars
2559
2560 ;; for debugging
2561 ;; (defun mac-handle-scroll-bar-event (event) (interactive "e") (princ event))
2562
2563 ;;(global-set-key [vertical-scroll-bar mouse-1] 'mac-handle-scroll-bar-event)
2564
2565 (global-set-key
2566 [vertical-scroll-bar down-mouse-1]
2567 'mac-handle-scroll-bar-event)
2568
2569 (global-unset-key [vertical-scroll-bar drag-mouse-1])
2570 (global-unset-key [vertical-scroll-bar mouse-1])
2571
2572 ;; Adjust Courier font specifications in x-fixed-font-alist.
2573 (let ((courier-fonts (assoc "Courier" x-fixed-font-alist)))
2574 (if courier-fonts
2575 (dolist (label-fonts (cdr courier-fonts))
2576 (setcdr label-fonts
2577 (mapcar
2578 (lambda (font)
2579 (if (string-match "\\`-adobe-courier-\\([^-]*\\)-\\(.\\)-\\(.*\\)-iso8859-1\\'" font)
2580 (replace-match
2581 (if (string= (match-string 2 font) "o")
2582 "-*-courier-\\1-i-\\3-*-*"
2583 "-*-courier-\\1-\\2-\\3-*-*")
2584 t nil font)
2585 font))
2586 (cdr label-fonts))))))
2587
2588 ;; Setup the default fontset.
2589 (setup-default-fontset)
2590 (cond ((x-list-fonts "*-iso10646-1" nil nil 1)
2591 ;; Use ATSUI (if available) for the following charsets.
2592 (dolist
2593 (charset '(latin-iso8859-1
2594 latin-iso8859-2 latin-iso8859-3 latin-iso8859-4
2595 thai-tis620 greek-iso8859-7 arabic-iso8859-6
2596 hebrew-iso8859-8 cyrillic-iso8859-5
2597 latin-iso8859-9 latin-iso8859-15 latin-iso8859-14
2598 japanese-jisx0212 chinese-sisheng ipa
2599 vietnamese-viscii-lower vietnamese-viscii-upper
2600 lao ethiopic tibetan))
2601 (set-fontset-font nil charset '(nil . "iso10646-1"))))
2602 ((null (x-list-fonts "*-iso8859-1" nil nil 1))
2603 ;; Add Mac-encoding fonts unless ETL fonts are installed.
2604 (fontset-add-mac-fonts "fontset-default")))
2605
2606 ;; Create a fontset that uses mac-roman font. With this fontset,
2607 ;; characters decoded from mac-roman encoding (ascii, latin-iso8859-1,
2608 ;; and mule-unicode-xxxx-yyyy) are displayed by a mac-roman font.
2609 (create-fontset-from-fontset-spec
2610 "-etl-fixed-medium-r-normal-*-16-*-*-*-*-*-fontset-standard,
2611 ascii:-*-Monaco-*-*-*-*-12-*-*-*-*-*-mac-roman")
2612 (fontset-add-mac-fonts "fontset-standard" t)
2613
2614 ;; Create fontset specified in X resources "Fontset-N" (N is 0, 1, ...).
2615 (create-fontset-from-x-resource)
2616
2617 ;; Try to create a fontset from a font specification which comes
2618 ;; from initial-frame-alist, default-frame-alist, or X resource.
2619 ;; A font specification in command line argument (i.e. -fn XXXX)
2620 ;; should be already in default-frame-alist as a `font'
2621 ;; parameter. However, any font specifications in site-start
2622 ;; library, user's init file (.emacs), and default.el are not
2623 ;; yet handled here.
2624
2625 (let ((font (or (cdr (assq 'font initial-frame-alist))
2626 (cdr (assq 'font default-frame-alist))
2627 (x-get-resource "font" "Font")))
2628 xlfd-fields resolved-name)
2629 (if (and font
2630 (not (query-fontset font))
2631 (setq resolved-name (x-resolve-font-name font))
2632 (setq xlfd-fields (x-decompose-font-name font)))
2633 (if (string= "fontset" (aref xlfd-fields xlfd-regexp-registry-subnum))
2634 (new-fontset font (x-complement-fontset-spec xlfd-fields nil))
2635 ;; Create a fontset from FONT. The fontset name is
2636 ;; generated from FONT.
2637 (if (and (string= "mac" (aref xlfd-fields xlfd-regexp-registry-subnum))
2638 (string= "roman" (aref xlfd-fields xlfd-regexp-encoding-subnum)))
2639 (create-fontset-from-mac-roman-font font resolved-name "startup")
2640 (create-fontset-from-ascii-font font resolved-name "startup")))))
2641
2642 ;; Apply a geometry resource to the initial frame. Put it at the end
2643 ;; of the alist, so that anything specified on the command line takes
2644 ;; precedence.
2645 (let* ((res-geometry (x-get-resource "geometry" "Geometry"))
2646 parsed)
2647 (if res-geometry
2648 (progn
2649 (setq parsed (x-parse-geometry res-geometry))
2650 ;; If the resource specifies a position,
2651 ;; call the position and size "user-specified".
2652 (if (or (assq 'top parsed) (assq 'left parsed))
2653 (setq parsed (cons '(user-position . t)
2654 (cons '(user-size . t) parsed))))
2655 ;; All geometry parms apply to the initial frame.
2656 (setq initial-frame-alist (append initial-frame-alist parsed))
2657 ;; The size parms apply to all frames. Don't set it if there are
2658 ;; sizes there already (from command line).
2659 (if (and (assq 'height parsed)
2660 (not (assq 'height default-frame-alist)))
2661 (setq default-frame-alist
2662 (cons (cons 'height (cdr (assq 'height parsed)))
2663 default-frame-alist)))
2664 (if (and (assq 'width parsed)
2665 (not (assq 'width default-frame-alist)))
2666 (setq default-frame-alist
2667 (cons (cons 'width (cdr (assq 'width parsed)))
2668 default-frame-alist))))))
2669
2670 ;; Check the reverseVideo resource.
2671 (let ((case-fold-search t))
2672 (let ((rv (x-get-resource "reverseVideo" "ReverseVideo")))
2673 (if (and rv
2674 (string-match "^\\(true\\|yes\\|on\\)$" rv))
2675 (setq default-frame-alist
2676 (cons '(reverse . t) default-frame-alist)))))
2677
2678 (setq mac-initialized t)))
2679
2680 (defun mac-handle-scroll-bar-event (event)
2681 "Handle scroll bar EVENT to emulate Mac Toolbox style scrolling."
2682 (interactive "e")
2683 (let* ((position (event-start event))
2684 (window (nth 0 position))
2685 (bar-part (nth 4 position)))
2686 (select-window window)
2687 (cond
2688 ((eq bar-part 'up)
2689 (goto-char (window-start window))
2690 (mac-scroll-down-line))
2691 ((eq bar-part 'above-handle)
2692 (mac-scroll-down))
2693 ((eq bar-part 'handle)
2694 (scroll-bar-drag event))
2695 ((eq bar-part 'below-handle)
2696 (mac-scroll-up))
2697 ((eq bar-part 'down)
2698 (goto-char (window-start window))
2699 (mac-scroll-up-line)))))
2700
2701 (defun mac-scroll-ignore-events ()
2702 ;; Ignore confusing non-mouse events
2703 (while (not (memq (car-safe (read-event))
2704 '(mouse-1 double-mouse-1 triple-mouse-1))) nil))
2705
2706 (defun mac-scroll-down ()
2707 (track-mouse
2708 (mac-scroll-ignore-events)
2709 (scroll-down)))
2710
2711 (defun mac-scroll-down-line ()
2712 (track-mouse
2713 (mac-scroll-ignore-events)
2714 (scroll-down 1)))
2715
2716 (defun mac-scroll-up ()
2717 (track-mouse
2718 (mac-scroll-ignore-events)
2719 (scroll-up)))
2720
2721 (defun mac-scroll-up-line ()
2722 (track-mouse
2723 (mac-scroll-ignore-events)
2724 (scroll-up 1)))
2725
2726
2727 \f
2728 ;;;; Others
2729
2730 (unless (eq system-type 'darwin)
2731 ;; This variable specifies the Unix program to call (as a process) to
2732 ;; determine the amount of free space on a file system (defaults to
2733 ;; df). If it is not set to nil, ls-lisp will not work correctly
2734 ;; unless an external application df is implemented on the Mac.
2735 (setq directory-free-space-program nil)
2736
2737 ;; Set this so that Emacs calls subprocesses with "sh" as shell to
2738 ;; expand filenames Note no subprocess for the shell is actually
2739 ;; started (see run_mac_command in sysdep.c).
2740 (setq shell-file-name "sh")
2741
2742 ;; Some system variables are encoded with the system script code.
2743 (dolist (v '(system-name
2744 emacs-build-system ; Mac OS 9 version cannot dump
2745 user-login-name user-real-login-name user-full-name))
2746 (set v (decode-coding-string (symbol-value v) mac-system-coding-system))))
2747
2748 ;; Now the default directory is changed to the user's home directory
2749 ;; in emacs.c if invoked from the WindowServer (with -psn_* option).
2750 ;; (if (string= default-directory "/")
2751 ;; (cd "~"))
2752
2753 ;; Darwin 6- pty breakage is now controlled from the C code so that
2754 ;; it applies to all builds on darwin. See s/darwin.h PTY_ITERATION.
2755 ;; (setq process-connection-type t)
2756
2757 ;; Assume that fonts are always scalable on the Mac. This sometimes
2758 ;; results in characters with jagged edges. However, without it,
2759 ;; fonts with both truetype and bitmap representations but no italic
2760 ;; or bold bitmap versions will not display these variants correctly.
2761 (setq scalable-fonts-allowed t)
2762
2763 (add-to-list 'handle-args-function-alist '(mac . x-handle-args))
2764 (add-to-list 'frame-creation-function-alist '(mac . x-create-frame-with-faces))
2765 (add-to-list 'window-system-initialization-alist '(mac . mac-initialize-window-system))
2766
2767 (provide 'mac-win)
2768
2769 ;; arch-tag: 71dfcd14-cde8-4d66-b05c-85ec94fb23a6
2770 ;;; mac-win.el ends here