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