Revision: miles@gnu.org--gnu-2005/emacs--unicode--0--patch-95
[bpt/emacs.git] / lisp / term / mac-win.el
1 ;;; mac-win.el --- parse switches controlling interface with Mac window system -*-coding: utf-8
2
3 ;; Copyright (C) 1999, 2000, 2002, 2003, 2004,
4 ;; 2005 Free Software Foundation, Inc.
5
6 ;; Author: Andrew Choi <akochoi@mac.com>
7 ;; Keywords: terminals
8
9 ;; This file is part of GNU Emacs.
10
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 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
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
25
26 ;;; Commentary:
27
28 ;; Mac-win.el: this file is loaded from ../lisp/startup.el when it recognizes
29 ;; that Mac windows are to be used. Command line switches are parsed and those
30 ;; pertaining to Mac are processed and removed from the command line. The
31 ;; Mac display is opened and hooks are set for popping up the initial window.
32
33 ;; startup.el will then examine startup files, and eventually call the hooks
34 ;; which create the first window(s).
35
36 ;;; Code:
37 \f
38 ;; These are the standard X switches from the Xt Initialize.c file of
39 ;; Release 4.
40
41 ;; Command line Resource Manager string
42
43 ;; +rv *reverseVideo
44 ;; +synchronous *synchronous
45 ;; -background *background
46 ;; -bd *borderColor
47 ;; -bg *background
48 ;; -bordercolor *borderColor
49 ;; -borderwidth .borderWidth
50 ;; -bw .borderWidth
51 ;; -display .display
52 ;; -fg *foreground
53 ;; -fn *font
54 ;; -font *font
55 ;; -foreground *foreground
56 ;; -geometry .geometry
57 ;; -iconic .iconic
58 ;; -name .name
59 ;; -reverse *reverseVideo
60 ;; -rv *reverseVideo
61 ;; -selectionTimeout .selectionTimeout
62 ;; -synchronous *synchronous
63 ;; -xrm
64
65 ;; An alist of X options and the function which handles them. See
66 ;; ../startup.el.
67
68 (if (not (eq window-system 'mac))
69 (error "%s: Loading mac-win.el but not compiled for Mac" (invocation-name)))
70
71 (require 'frame)
72 (require 'mouse)
73 (require 'scroll-bar)
74 (require 'faces)
75 (require 'select)
76 (require 'menu-bar)
77 (require 'fontset)
78 (require 'dnd)
79
80 (defvar mac-charset-info-alist)
81 (defvar mac-services-selection)
82 (defvar mac-system-script-code)
83 (defvar x-invocation-args)
84
85 (defvar x-command-line-resources nil)
86
87 ;; Handler for switches of the form "-switch value" or "-switch".
88 (defun x-handle-switch (switch)
89 (let ((aelt (assoc switch command-line-x-option-alist)))
90 (if aelt
91 (let ((param (nth 3 aelt))
92 (value (nth 4 aelt)))
93 (if value
94 (setq default-frame-alist
95 (cons (cons param value)
96 default-frame-alist))
97 (setq default-frame-alist
98 (cons (cons param
99 (car x-invocation-args))
100 default-frame-alist)
101 x-invocation-args (cdr x-invocation-args)))))))
102
103 ;; Handler for switches of the form "-switch n"
104 (defun x-handle-numeric-switch (switch)
105 (let ((aelt (assoc switch command-line-x-option-alist)))
106 (if aelt
107 (let ((param (nth 3 aelt)))
108 (setq default-frame-alist
109 (cons (cons param
110 (string-to-number (car x-invocation-args)))
111 default-frame-alist)
112 x-invocation-args
113 (cdr x-invocation-args))))))
114
115 ;; Handle options that apply to initial frame only
116 (defun x-handle-initial-switch (switch)
117 (let ((aelt (assoc switch command-line-x-option-alist)))
118 (if aelt
119 (let ((param (nth 3 aelt))
120 (value (nth 4 aelt)))
121 (if value
122 (setq initial-frame-alist
123 (cons (cons param value)
124 initial-frame-alist))
125 (setq initial-frame-alist
126 (cons (cons param
127 (car x-invocation-args))
128 initial-frame-alist)
129 x-invocation-args (cdr x-invocation-args)))))))
130
131 ;; Make -iconic apply only to the initial frame!
132 (defun x-handle-iconic (switch)
133 (setq initial-frame-alist
134 (cons '(visibility . icon) initial-frame-alist)))
135
136 ;; Handle the -xrm option.
137 (defun x-handle-xrm-switch (switch)
138 (unless (consp x-invocation-args)
139 (error "%s: missing argument to `%s' option" (invocation-name) switch))
140 (setq x-command-line-resources
141 (if (null x-command-line-resources)
142 (car x-invocation-args)
143 (concat x-command-line-resources "\n" (car x-invocation-args))))
144 (setq x-invocation-args (cdr x-invocation-args)))
145
146 ;; Handle the geometry option
147 (defun x-handle-geometry (switch)
148 (let* ((geo (x-parse-geometry (car x-invocation-args)))
149 (left (assq 'left geo))
150 (top (assq 'top geo))
151 (height (assq 'height geo))
152 (width (assq 'width geo)))
153 (if (or height width)
154 (setq default-frame-alist
155 (append default-frame-alist
156 '((user-size . t))
157 (if height (list height))
158 (if width (list width)))
159 initial-frame-alist
160 (append initial-frame-alist
161 '((user-size . t))
162 (if height (list height))
163 (if width (list width)))))
164 (if (or left top)
165 (setq initial-frame-alist
166 (append initial-frame-alist
167 '((user-position . t))
168 (if left (list left))
169 (if top (list top)))))
170 (setq x-invocation-args (cdr x-invocation-args))))
171
172 ;; Handle the -name option. Set the variable x-resource-name
173 ;; to the option's operand; set the name of
174 ;; the initial frame, too.
175 (defun x-handle-name-switch (switch)
176 (or (consp x-invocation-args)
177 (error "%s: missing argument to `%s' option" (invocation-name) switch))
178 (setq x-resource-name (car x-invocation-args)
179 x-invocation-args (cdr x-invocation-args))
180 (setq initial-frame-alist (cons (cons 'name x-resource-name)
181 initial-frame-alist)))
182
183 (defvar x-display-name nil
184 "The display name specifying server and frame.")
185
186 (defun x-handle-display (switch)
187 (setq x-display-name (car x-invocation-args)
188 x-invocation-args (cdr x-invocation-args)))
189
190 (defun x-handle-args (args)
191 "Process the X-related command line options in ARGS.
192 This is done before the user's startup file is loaded. They are copied to
193 `x-invocation-args', from which the X-related things are extracted, first
194 the switch (e.g., \"-fg\") in the following code, and possible values
195 \(e.g., \"black\") in the option handler code (e.g., x-handle-switch).
196 This function returns ARGS minus the arguments that have been processed."
197 ;; We use ARGS to accumulate the args that we don't handle here, to return.
198 (setq x-invocation-args args
199 args nil)
200 (while (and x-invocation-args
201 (not (equal (car x-invocation-args) "--")))
202 (let* ((this-switch (car x-invocation-args))
203 (orig-this-switch this-switch)
204 completion argval aelt handler)
205 (setq x-invocation-args (cdr x-invocation-args))
206 ;; Check for long options with attached arguments
207 ;; and separate out the attached option argument into argval.
208 (if (string-match "^--[^=]*=" this-switch)
209 (setq argval (substring this-switch (match-end 0))
210 this-switch (substring this-switch 0 (1- (match-end 0)))))
211 ;; Complete names of long options.
212 (if (string-match "^--" this-switch)
213 (progn
214 (setq completion (try-completion this-switch command-line-x-option-alist))
215 (if (eq completion t)
216 ;; Exact match for long option.
217 nil
218 (if (stringp completion)
219 (let ((elt (assoc completion command-line-x-option-alist)))
220 ;; Check for abbreviated long option.
221 (or elt
222 (error "Option `%s' is ambiguous" this-switch))
223 (setq this-switch completion))))))
224 (setq aelt (assoc this-switch command-line-x-option-alist))
225 (if aelt (setq handler (nth 2 aelt)))
226 (if handler
227 (if argval
228 (let ((x-invocation-args
229 (cons argval x-invocation-args)))
230 (funcall handler this-switch))
231 (funcall handler this-switch))
232 (setq args (cons orig-this-switch args)))))
233 (nconc (nreverse args) x-invocation-args))
234
235 \f
236 ;;
237 ;; Standard Mac cursor shapes
238 ;;
239
240 (defconst mac-pointer-arrow 0)
241 (defconst mac-pointer-copy-arrow 1)
242 (defconst mac-pointer-alias-arrow 2)
243 (defconst mac-pointer-contextual-menu-arrow 3)
244 (defconst mac-pointer-I-beam 4)
245 (defconst mac-pointer-cross 5)
246 (defconst mac-pointer-plus 6)
247 (defconst mac-pointer-watch 7)
248 (defconst mac-pointer-closed-hand 8)
249 (defconst mac-pointer-open-hand 9)
250 (defconst mac-pointer-pointing-hand 10)
251 (defconst mac-pointer-counting-up-hand 11)
252 (defconst mac-pointer-counting-down-hand 12)
253 (defconst mac-pointer-counting-up-and-down-hand 13)
254 (defconst mac-pointer-spinning 14)
255 (defconst mac-pointer-resize-left 15)
256 (defconst mac-pointer-resize-right 16)
257 (defconst mac-pointer-resize-left-right 17)
258 ;; Mac OS X 10.2 and later
259 (defconst mac-pointer-not-allowed 18)
260 ;; Mac OS X 10.3 and later
261 (defconst mac-pointer-resize-up 19)
262 (defconst mac-pointer-resize-down 20)
263 (defconst mac-pointer-resize-up-down 21)
264 (defconst mac-pointer-poof 22)
265
266 ;;
267 ;; Standard X cursor shapes that have Mac counterparts
268 ;;
269
270 (defconst x-pointer-left-ptr mac-pointer-arrow)
271 (defconst x-pointer-xterm mac-pointer-I-beam)
272 (defconst x-pointer-crosshair mac-pointer-cross)
273 (defconst x-pointer-plus mac-pointer-plus)
274 (defconst x-pointer-watch mac-pointer-watch)
275 (defconst x-pointer-hand2 mac-pointer-pointing-hand)
276 (defconst x-pointer-left-side mac-pointer-resize-left)
277 (defconst x-pointer-right-side mac-pointer-resize-right)
278 (defconst x-pointer-sb-h-double-arrow mac-pointer-resize-left-right)
279 (defconst x-pointer-top-side mac-pointer-resize-up)
280 (defconst x-pointer-bottom-side mac-pointer-resize-down)
281 (defconst x-pointer-sb-v-double-arrow mac-pointer-resize-up-down)
282
283 \f
284 ;;
285 ;; Available colors
286 ;;
287
288 (defvar x-colors '("LightGreen"
289 "light green"
290 "DarkRed"
291 "dark red"
292 "DarkMagenta"
293 "dark magenta"
294 "DarkCyan"
295 "dark cyan"
296 "DarkBlue"
297 "dark blue"
298 "DarkGray"
299 "dark gray"
300 "DarkGrey"
301 "dark grey"
302 "grey100"
303 "gray100"
304 "grey99"
305 "gray99"
306 "grey98"
307 "gray98"
308 "grey97"
309 "gray97"
310 "grey96"
311 "gray96"
312 "grey95"
313 "gray95"
314 "grey94"
315 "gray94"
316 "grey93"
317 "gray93"
318 "grey92"
319 "gray92"
320 "grey91"
321 "gray91"
322 "grey90"
323 "gray90"
324 "grey89"
325 "gray89"
326 "grey88"
327 "gray88"
328 "grey87"
329 "gray87"
330 "grey86"
331 "gray86"
332 "grey85"
333 "gray85"
334 "grey84"
335 "gray84"
336 "grey83"
337 "gray83"
338 "grey82"
339 "gray82"
340 "grey81"
341 "gray81"
342 "grey80"
343 "gray80"
344 "grey79"
345 "gray79"
346 "grey78"
347 "gray78"
348 "grey77"
349 "gray77"
350 "grey76"
351 "gray76"
352 "grey75"
353 "gray75"
354 "grey74"
355 "gray74"
356 "grey73"
357 "gray73"
358 "grey72"
359 "gray72"
360 "grey71"
361 "gray71"
362 "grey70"
363 "gray70"
364 "grey69"
365 "gray69"
366 "grey68"
367 "gray68"
368 "grey67"
369 "gray67"
370 "grey66"
371 "gray66"
372 "grey65"
373 "gray65"
374 "grey64"
375 "gray64"
376 "grey63"
377 "gray63"
378 "grey62"
379 "gray62"
380 "grey61"
381 "gray61"
382 "grey60"
383 "gray60"
384 "grey59"
385 "gray59"
386 "grey58"
387 "gray58"
388 "grey57"
389 "gray57"
390 "grey56"
391 "gray56"
392 "grey55"
393 "gray55"
394 "grey54"
395 "gray54"
396 "grey53"
397 "gray53"
398 "grey52"
399 "gray52"
400 "grey51"
401 "gray51"
402 "grey50"
403 "gray50"
404 "grey49"
405 "gray49"
406 "grey48"
407 "gray48"
408 "grey47"
409 "gray47"
410 "grey46"
411 "gray46"
412 "grey45"
413 "gray45"
414 "grey44"
415 "gray44"
416 "grey43"
417 "gray43"
418 "grey42"
419 "gray42"
420 "grey41"
421 "gray41"
422 "grey40"
423 "gray40"
424 "grey39"
425 "gray39"
426 "grey38"
427 "gray38"
428 "grey37"
429 "gray37"
430 "grey36"
431 "gray36"
432 "grey35"
433 "gray35"
434 "grey34"
435 "gray34"
436 "grey33"
437 "gray33"
438 "grey32"
439 "gray32"
440 "grey31"
441 "gray31"
442 "grey30"
443 "gray30"
444 "grey29"
445 "gray29"
446 "grey28"
447 "gray28"
448 "grey27"
449 "gray27"
450 "grey26"
451 "gray26"
452 "grey25"
453 "gray25"
454 "grey24"
455 "gray24"
456 "grey23"
457 "gray23"
458 "grey22"
459 "gray22"
460 "grey21"
461 "gray21"
462 "grey20"
463 "gray20"
464 "grey19"
465 "gray19"
466 "grey18"
467 "gray18"
468 "grey17"
469 "gray17"
470 "grey16"
471 "gray16"
472 "grey15"
473 "gray15"
474 "grey14"
475 "gray14"
476 "grey13"
477 "gray13"
478 "grey12"
479 "gray12"
480 "grey11"
481 "gray11"
482 "grey10"
483 "gray10"
484 "grey9"
485 "gray9"
486 "grey8"
487 "gray8"
488 "grey7"
489 "gray7"
490 "grey6"
491 "gray6"
492 "grey5"
493 "gray5"
494 "grey4"
495 "gray4"
496 "grey3"
497 "gray3"
498 "grey2"
499 "gray2"
500 "grey1"
501 "gray1"
502 "grey0"
503 "gray0"
504 "thistle4"
505 "thistle3"
506 "thistle2"
507 "thistle1"
508 "MediumPurple4"
509 "MediumPurple3"
510 "MediumPurple2"
511 "MediumPurple1"
512 "purple4"
513 "purple3"
514 "purple2"
515 "purple1"
516 "DarkOrchid4"
517 "DarkOrchid3"
518 "DarkOrchid2"
519 "DarkOrchid1"
520 "MediumOrchid4"
521 "MediumOrchid3"
522 "MediumOrchid2"
523 "MediumOrchid1"
524 "plum4"
525 "plum3"
526 "plum2"
527 "plum1"
528 "orchid4"
529 "orchid3"
530 "orchid2"
531 "orchid1"
532 "magenta4"
533 "magenta3"
534 "magenta2"
535 "magenta1"
536 "VioletRed4"
537 "VioletRed3"
538 "VioletRed2"
539 "VioletRed1"
540 "maroon4"
541 "maroon3"
542 "maroon2"
543 "maroon1"
544 "PaleVioletRed4"
545 "PaleVioletRed3"
546 "PaleVioletRed2"
547 "PaleVioletRed1"
548 "LightPink4"
549 "LightPink3"
550 "LightPink2"
551 "LightPink1"
552 "pink4"
553 "pink3"
554 "pink2"
555 "pink1"
556 "HotPink4"
557 "HotPink3"
558 "HotPink2"
559 "HotPink1"
560 "DeepPink4"
561 "DeepPink3"
562 "DeepPink2"
563 "DeepPink1"
564 "red4"
565 "red3"
566 "red2"
567 "red1"
568 "OrangeRed4"
569 "OrangeRed3"
570 "OrangeRed2"
571 "OrangeRed1"
572 "tomato4"
573 "tomato3"
574 "tomato2"
575 "tomato1"
576 "coral4"
577 "coral3"
578 "coral2"
579 "coral1"
580 "DarkOrange4"
581 "DarkOrange3"
582 "DarkOrange2"
583 "DarkOrange1"
584 "orange4"
585 "orange3"
586 "orange2"
587 "orange1"
588 "LightSalmon4"
589 "LightSalmon3"
590 "LightSalmon2"
591 "LightSalmon1"
592 "salmon4"
593 "salmon3"
594 "salmon2"
595 "salmon1"
596 "brown4"
597 "brown3"
598 "brown2"
599 "brown1"
600 "firebrick4"
601 "firebrick3"
602 "firebrick2"
603 "firebrick1"
604 "chocolate4"
605 "chocolate3"
606 "chocolate2"
607 "chocolate1"
608 "tan4"
609 "tan3"
610 "tan2"
611 "tan1"
612 "wheat4"
613 "wheat3"
614 "wheat2"
615 "wheat1"
616 "burlywood4"
617 "burlywood3"
618 "burlywood2"
619 "burlywood1"
620 "sienna4"
621 "sienna3"
622 "sienna2"
623 "sienna1"
624 "IndianRed4"
625 "IndianRed3"
626 "IndianRed2"
627 "IndianRed1"
628 "RosyBrown4"
629 "RosyBrown3"
630 "RosyBrown2"
631 "RosyBrown1"
632 "DarkGoldenrod4"
633 "DarkGoldenrod3"
634 "DarkGoldenrod2"
635 "DarkGoldenrod1"
636 "goldenrod4"
637 "goldenrod3"
638 "goldenrod2"
639 "goldenrod1"
640 "gold4"
641 "gold3"
642 "gold2"
643 "gold1"
644 "yellow4"
645 "yellow3"
646 "yellow2"
647 "yellow1"
648 "LightYellow4"
649 "LightYellow3"
650 "LightYellow2"
651 "LightYellow1"
652 "LightGoldenrod4"
653 "LightGoldenrod3"
654 "LightGoldenrod2"
655 "LightGoldenrod1"
656 "khaki4"
657 "khaki3"
658 "khaki2"
659 "khaki1"
660 "DarkOliveGreen4"
661 "DarkOliveGreen3"
662 "DarkOliveGreen2"
663 "DarkOliveGreen1"
664 "OliveDrab4"
665 "OliveDrab3"
666 "OliveDrab2"
667 "OliveDrab1"
668 "chartreuse4"
669 "chartreuse3"
670 "chartreuse2"
671 "chartreuse1"
672 "green4"
673 "green3"
674 "green2"
675 "green1"
676 "SpringGreen4"
677 "SpringGreen3"
678 "SpringGreen2"
679 "SpringGreen1"
680 "PaleGreen4"
681 "PaleGreen3"
682 "PaleGreen2"
683 "PaleGreen1"
684 "SeaGreen4"
685 "SeaGreen3"
686 "SeaGreen2"
687 "SeaGreen1"
688 "DarkSeaGreen4"
689 "DarkSeaGreen3"
690 "DarkSeaGreen2"
691 "DarkSeaGreen1"
692 "aquamarine4"
693 "aquamarine3"
694 "aquamarine2"
695 "aquamarine1"
696 "DarkSlateGray4"
697 "DarkSlateGray3"
698 "DarkSlateGray2"
699 "DarkSlateGray1"
700 "cyan4"
701 "cyan3"
702 "cyan2"
703 "cyan1"
704 "turquoise4"
705 "turquoise3"
706 "turquoise2"
707 "turquoise1"
708 "CadetBlue4"
709 "CadetBlue3"
710 "CadetBlue2"
711 "CadetBlue1"
712 "PaleTurquoise4"
713 "PaleTurquoise3"
714 "PaleTurquoise2"
715 "PaleTurquoise1"
716 "LightCyan4"
717 "LightCyan3"
718 "LightCyan2"
719 "LightCyan1"
720 "LightBlue4"
721 "LightBlue3"
722 "LightBlue2"
723 "LightBlue1"
724 "LightSteelBlue4"
725 "LightSteelBlue3"
726 "LightSteelBlue2"
727 "LightSteelBlue1"
728 "SlateGray4"
729 "SlateGray3"
730 "SlateGray2"
731 "SlateGray1"
732 "LightSkyBlue4"
733 "LightSkyBlue3"
734 "LightSkyBlue2"
735 "LightSkyBlue1"
736 "SkyBlue4"
737 "SkyBlue3"
738 "SkyBlue2"
739 "SkyBlue1"
740 "DeepSkyBlue4"
741 "DeepSkyBlue3"
742 "DeepSkyBlue2"
743 "DeepSkyBlue1"
744 "SteelBlue4"
745 "SteelBlue3"
746 "SteelBlue2"
747 "SteelBlue1"
748 "DodgerBlue4"
749 "DodgerBlue3"
750 "DodgerBlue2"
751 "DodgerBlue1"
752 "blue4"
753 "blue3"
754 "blue2"
755 "blue1"
756 "RoyalBlue4"
757 "RoyalBlue3"
758 "RoyalBlue2"
759 "RoyalBlue1"
760 "SlateBlue4"
761 "SlateBlue3"
762 "SlateBlue2"
763 "SlateBlue1"
764 "azure4"
765 "azure3"
766 "azure2"
767 "azure1"
768 "MistyRose4"
769 "MistyRose3"
770 "MistyRose2"
771 "MistyRose1"
772 "LavenderBlush4"
773 "LavenderBlush3"
774 "LavenderBlush2"
775 "LavenderBlush1"
776 "honeydew4"
777 "honeydew3"
778 "honeydew2"
779 "honeydew1"
780 "ivory4"
781 "ivory3"
782 "ivory2"
783 "ivory1"
784 "cornsilk4"
785 "cornsilk3"
786 "cornsilk2"
787 "cornsilk1"
788 "LemonChiffon4"
789 "LemonChiffon3"
790 "LemonChiffon2"
791 "LemonChiffon1"
792 "NavajoWhite4"
793 "NavajoWhite3"
794 "NavajoWhite2"
795 "NavajoWhite1"
796 "PeachPuff4"
797 "PeachPuff3"
798 "PeachPuff2"
799 "PeachPuff1"
800 "bisque4"
801 "bisque3"
802 "bisque2"
803 "bisque1"
804 "AntiqueWhite4"
805 "AntiqueWhite3"
806 "AntiqueWhite2"
807 "AntiqueWhite1"
808 "seashell4"
809 "seashell3"
810 "seashell2"
811 "seashell1"
812 "snow4"
813 "snow3"
814 "snow2"
815 "snow1"
816 "thistle"
817 "MediumPurple"
818 "medium purple"
819 "purple"
820 "BlueViolet"
821 "blue violet"
822 "DarkViolet"
823 "dark violet"
824 "DarkOrchid"
825 "dark orchid"
826 "MediumOrchid"
827 "medium orchid"
828 "orchid"
829 "plum"
830 "violet"
831 "magenta"
832 "VioletRed"
833 "violet red"
834 "MediumVioletRed"
835 "medium violet red"
836 "maroon"
837 "PaleVioletRed"
838 "pale violet red"
839 "LightPink"
840 "light pink"
841 "pink"
842 "DeepPink"
843 "deep pink"
844 "HotPink"
845 "hot pink"
846 "red"
847 "OrangeRed"
848 "orange red"
849 "tomato"
850 "LightCoral"
851 "light coral"
852 "coral"
853 "DarkOrange"
854 "dark orange"
855 "orange"
856 "LightSalmon"
857 "light salmon"
858 "salmon"
859 "DarkSalmon"
860 "dark salmon"
861 "brown"
862 "firebrick"
863 "chocolate"
864 "tan"
865 "SandyBrown"
866 "sandy brown"
867 "wheat"
868 "beige"
869 "burlywood"
870 "peru"
871 "sienna"
872 "SaddleBrown"
873 "saddle brown"
874 "IndianRed"
875 "indian red"
876 "RosyBrown"
877 "rosy brown"
878 "DarkGoldenrod"
879 "dark goldenrod"
880 "goldenrod"
881 "LightGoldenrod"
882 "light goldenrod"
883 "gold"
884 "yellow"
885 "LightYellow"
886 "light yellow"
887 "LightGoldenrodYellow"
888 "light goldenrod yellow"
889 "PaleGoldenrod"
890 "pale goldenrod"
891 "khaki"
892 "DarkKhaki"
893 "dark khaki"
894 "OliveDrab"
895 "olive drab"
896 "ForestGreen"
897 "forest green"
898 "YellowGreen"
899 "yellow green"
900 "LimeGreen"
901 "lime green"
902 "GreenYellow"
903 "green yellow"
904 "MediumSpringGreen"
905 "medium spring green"
906 "chartreuse"
907 "green"
908 "LawnGreen"
909 "lawn green"
910 "SpringGreen"
911 "spring green"
912 "PaleGreen"
913 "pale green"
914 "LightSeaGreen"
915 "light sea green"
916 "MediumSeaGreen"
917 "medium sea green"
918 "SeaGreen"
919 "sea green"
920 "DarkSeaGreen"
921 "dark sea green"
922 "DarkOliveGreen"
923 "dark olive green"
924 "DarkGreen"
925 "dark green"
926 "aquamarine"
927 "MediumAquamarine"
928 "medium aquamarine"
929 "CadetBlue"
930 "cadet blue"
931 "LightCyan"
932 "light cyan"
933 "cyan"
934 "turquoise"
935 "MediumTurquoise"
936 "medium turquoise"
937 "DarkTurquoise"
938 "dark turquoise"
939 "PaleTurquoise"
940 "pale turquoise"
941 "PowderBlue"
942 "powder blue"
943 "LightBlue"
944 "light blue"
945 "LightSteelBlue"
946 "light steel blue"
947 "SteelBlue"
948 "steel blue"
949 "LightSkyBlue"
950 "light sky blue"
951 "SkyBlue"
952 "sky blue"
953 "DeepSkyBlue"
954 "deep sky blue"
955 "DodgerBlue"
956 "dodger blue"
957 "blue"
958 "RoyalBlue"
959 "royal blue"
960 "MediumBlue"
961 "medium blue"
962 "LightSlateBlue"
963 "light slate blue"
964 "MediumSlateBlue"
965 "medium slate blue"
966 "SlateBlue"
967 "slate blue"
968 "DarkSlateBlue"
969 "dark slate blue"
970 "CornflowerBlue"
971 "cornflower blue"
972 "NavyBlue"
973 "navy blue"
974 "navy"
975 "MidnightBlue"
976 "midnight blue"
977 "LightGray"
978 "light gray"
979 "LightGrey"
980 "light grey"
981 "grey"
982 "gray"
983 "LightSlateGrey"
984 "light slate grey"
985 "LightSlateGray"
986 "light slate gray"
987 "SlateGrey"
988 "slate grey"
989 "SlateGray"
990 "slate gray"
991 "DimGrey"
992 "dim grey"
993 "DimGray"
994 "dim gray"
995 "DarkSlateGrey"
996 "dark slate grey"
997 "DarkSlateGray"
998 "dark slate gray"
999 "black"
1000 "white"
1001 "MistyRose"
1002 "misty rose"
1003 "LavenderBlush"
1004 "lavender blush"
1005 "lavender"
1006 "AliceBlue"
1007 "alice blue"
1008 "azure"
1009 "MintCream"
1010 "mint cream"
1011 "honeydew"
1012 "seashell"
1013 "LemonChiffon"
1014 "lemon chiffon"
1015 "ivory"
1016 "cornsilk"
1017 "moccasin"
1018 "NavajoWhite"
1019 "navajo white"
1020 "PeachPuff"
1021 "peach puff"
1022 "bisque"
1023 "BlanchedAlmond"
1024 "blanched almond"
1025 "PapayaWhip"
1026 "papaya whip"
1027 "AntiqueWhite"
1028 "antique white"
1029 "linen"
1030 "OldLace"
1031 "old lace"
1032 "FloralWhite"
1033 "floral white"
1034 "gainsboro"
1035 "WhiteSmoke"
1036 "white smoke"
1037 "GhostWhite"
1038 "ghost white"
1039 "snow")
1040 "The list of X colors from the `rgb.txt' file.
1041 XConsortium: rgb.txt,v 10.41 94/02/20 18:39:36 rws Exp")
1042
1043 (defun xw-defined-colors (&optional frame)
1044 "Internal function called by `defined-colors', which see."
1045 (or frame (setq frame (selected-frame)))
1046 (let ((all-colors x-colors)
1047 (this-color nil)
1048 (defined-colors nil))
1049 (while all-colors
1050 (setq this-color (car all-colors)
1051 all-colors (cdr all-colors))
1052 (and (color-supported-p this-color frame t)
1053 (setq defined-colors (cons this-color defined-colors))))
1054 defined-colors))
1055 \f
1056 ;;;; Function keys
1057
1058 (substitute-key-definition 'suspend-emacs 'iconify-or-deiconify-frame
1059 global-map)
1060
1061 ;; Map certain keypad keys into ASCII characters
1062 ;; that people usually expect.
1063 (define-key function-key-map [backspace] [?\d])
1064 (define-key function-key-map [delete] [?\d])
1065 (define-key function-key-map [tab] [?\t])
1066 (define-key function-key-map [linefeed] [?\n])
1067 (define-key function-key-map [clear] [?\C-l])
1068 (define-key function-key-map [return] [?\C-m])
1069 (define-key function-key-map [escape] [?\e])
1070 (define-key function-key-map [M-backspace] [?\M-\d])
1071 (define-key function-key-map [M-delete] [?\M-\d])
1072 (define-key function-key-map [M-tab] [?\M-\t])
1073 (define-key function-key-map [M-linefeed] [?\M-\n])
1074 (define-key function-key-map [M-clear] [?\M-\C-l])
1075 (define-key function-key-map [M-return] [?\M-\C-m])
1076 (define-key function-key-map [M-escape] [?\M-\e])
1077
1078 ;; These tell read-char how to convert
1079 ;; these special chars to ASCII.
1080 (put 'backspace 'ascii-character ?\d)
1081 (put 'delete 'ascii-character ?\d)
1082 (put 'tab 'ascii-character ?\t)
1083 (put 'linefeed 'ascii-character ?\n)
1084 (put 'clear 'ascii-character ?\C-l)
1085 (put 'return 'ascii-character ?\C-m)
1086 (put 'escape 'ascii-character ?\e)
1087
1088 \f
1089 ;;;; Script codes and coding systems
1090 (defconst mac-script-code-coding-systems
1091 '((0 . mac-roman) ; smRoman
1092 (1 . japanese-shift-jis) ; smJapanese
1093 (2 . chinese-big5) ; smTradChinese
1094 (3 . korean-iso-8bit) ; smKorean
1095 (7 . mac-cyrillic) ; smCyrillic
1096 (25 . chinese-iso-8bit) ; smSimpChinese
1097 (29 . mac-centraleurroman) ; smCentralEuroRoman
1098 )
1099 "Alist of Mac script codes vs Emacs coding systems.")
1100
1101 (defconst mac-system-coding-system
1102 (let ((base (or (cdr (assq mac-system-script-code
1103 mac-script-code-coding-systems))
1104 'mac-roman)))
1105 (if (eq system-type 'darwin)
1106 base
1107 (coding-system-change-eol-conversion base 'mac)))
1108 "Coding system derived from the system script code.")
1109
1110 (defun mac-add-charset-info (xlfd-charset mac-text-encoding)
1111 "Add a character set to display with Mac fonts.
1112 Create an entry in `mac-charset-info-alist'.
1113 XLFD-CHARSET is a string which will appear in the XLFD font name
1114 to identify the character set. MAC-TEXT-ENCODING is the
1115 correspoinding TextEncodingBase value."
1116 (add-to-list 'mac-charset-info-alist
1117 (list xlfd-charset mac-text-encoding
1118 (cdr (assq mac-text-encoding
1119 mac-script-code-coding-systems)))))
1120
1121 (setq mac-charset-info-alist nil)
1122 (mac-add-charset-info "mac-roman" 0)
1123 (mac-add-charset-info "jisx0208.1983-sjis" 1)
1124 (mac-add-charset-info "jisx0201.1976-0" 1)
1125 (mac-add-charset-info "big5-0" 2)
1126 (mac-add-charset-info "ksc5601.1989-0" 3)
1127 (mac-add-charset-info "mac-cyrillic" 7)
1128 (mac-add-charset-info "gb2312.1980-0" 25)
1129 (mac-add-charset-info "mac-centraleurroman" 29)
1130 (mac-add-charset-info "mac-symbol" 33)
1131 (mac-add-charset-info "adobe-fontspecific" 33) ; for X-Symbol
1132 (mac-add-charset-info "mac-dingbats" 34)
1133 (mac-add-charset-info "iso10646-1" 126) ; for ATSUI
1134
1135 \f
1136 ;;;; Keyboard layout/language change events
1137 (defun mac-handle-language-change (event)
1138 (interactive "e")
1139 (let ((coding-system
1140 (cdr (assq (car (cadr event)) mac-script-code-coding-systems))))
1141 (set-keyboard-coding-system (or coding-system 'mac-roman))
1142 ;; MacJapanese maps reverse solidus to ?\x80.
1143 (if (eq coding-system 'japanese-shift-jis)
1144 (define-key key-translation-map [?\x80] "\\"))))
1145
1146 (define-key special-event-map [language-change] 'mac-handle-language-change)
1147 \f
1148 ;;;; Selections and Services menu
1149
1150 ;; Setup to use the Mac clipboard.
1151 (set-selection-coding-system mac-system-coding-system)
1152
1153 ;;; We keep track of the last text selected here, so we can check the
1154 ;;; current selection against it, and avoid passing back our own text
1155 ;;; from x-get-selection-value.
1156 (defvar x-last-selected-text-clipboard nil
1157 "The value of the CLIPBOARD selection last time we selected or
1158 pasted text.")
1159 (defvar x-last-selected-text-primary nil
1160 "The value of the PRIMARY X selection last time we selected or
1161 pasted text.")
1162
1163 (defcustom x-select-enable-clipboard t
1164 "*Non-nil means cutting and pasting uses the clipboard.
1165 This is in addition to the primary selection."
1166 :type 'boolean
1167 :group 'killing)
1168
1169 ;;; Make TEXT, a string, the primary X selection.
1170 (defun x-select-text (text &optional push)
1171 (x-set-selection 'PRIMARY text)
1172 (setq x-last-selected-text-primary text)
1173 (if (not x-select-enable-clipboard)
1174 (setq x-last-selected-text-clipboard nil)
1175 (x-set-selection 'CLIPBOARD text)
1176 (setq x-last-selected-text-clipboard text))
1177 )
1178
1179 (defun x-get-selection (&optional type data-type)
1180 "Return the value of a selection.
1181 The argument TYPE (default `PRIMARY') says which selection,
1182 and the argument DATA-TYPE (default `STRING') says
1183 how to convert the data.
1184
1185 TYPE may be any symbol \(but nil stands for `PRIMARY'). However,
1186 only a few symbols are commonly used. They conventionally have
1187 all upper-case names. The most often used ones, in addition to
1188 `PRIMARY', are `SECONDARY' and `CLIPBOARD'.
1189
1190 DATA-TYPE is usually `STRING', but can also be one of the symbols
1191 in `selection-converter-alist', which see."
1192 (let ((data (x-get-selection-internal (or type 'PRIMARY)
1193 (or data-type 'STRING)))
1194 (coding (or next-selection-coding-system
1195 selection-coding-system)))
1196 (when (and (stringp data)
1197 (setq data-type (get-text-property 0 'foreign-selection data)))
1198 (cond ((eq data-type 'public.utf16-plain-text)
1199 (if (fboundp 'mac-code-convert-string)
1200 (let ((s (mac-code-convert-string data nil coding)))
1201 (if s
1202 (setq data (decode-coding-string s coding))
1203 (setq data
1204 ;; (decode-coding-string data 'utf-16) is
1205 ;; not correct because
1206 ;; public.utf16-plain-text is defined as
1207 ;; native byte order, no BOM.
1208 (decode-coding-string
1209 (mac-code-convert-string data nil 'utf-8)
1210 'utf-8))))
1211 ;; No `mac-code-convert-string' means non-Carbon, which
1212 ;; implies big endian.
1213 (setq data (decode-coding-string data 'utf-16be))))
1214 ((eq data-type 'com.apple.traditional-mac-plain-text)
1215 (setq data (decode-coding-string data coding)))
1216 ((eq data-type 'public.file-url)
1217 (setq data (decode-coding-string data 'utf-8))
1218 ;; Remove a trailing nul character.
1219 (let ((len (length data)))
1220 (if (and (> len 0) (= (aref data (1- len)) ?\0))
1221 (setq data (substring data 0 (1- len)))))))
1222 (put-text-property 0 (length data) 'foreign-selection data-type data))
1223 data))
1224
1225 (defun x-selection-value (type)
1226 (let ((data-types '(public.utf16-plain-text
1227 com.apple.traditional-mac-plain-text
1228 public.file-url))
1229 text tiff-image)
1230 (while (and (null text) data-types)
1231 (setq text (condition-case nil
1232 (x-get-selection type (car data-types))
1233 (error nil)))
1234 (setq data-types (cdr data-types)))
1235 (if text
1236 (remove-text-properties 0 (length text) '(foreign-selection nil) text))
1237 (setq tiff-image (condition-case nil
1238 (x-get-selection type 'public.tiff)
1239 (error nil)))
1240 (when tiff-image
1241 (remove-text-properties 0 (length tiff-image)
1242 '(foreign-selection nil) tiff-image)
1243 (setq tiff-image (create-image tiff-image 'tiff t))
1244 (or text (setq text " "))
1245 (put-text-property 0 (length text) 'display tiff-image text))
1246 text))
1247
1248 ;;; Return the value of the current selection.
1249 ;;; Treat empty strings as if they were unset.
1250 ;;; If this function is called twice and finds the same text,
1251 ;;; it returns nil the second time. This is so that a single
1252 ;;; selection won't be added to the kill ring over and over.
1253 (defun x-get-selection-value ()
1254 (let (clip-text primary-text)
1255 (if (not x-select-enable-clipboard)
1256 (setq x-last-selected-text-clipboard nil)
1257 (setq clip-text (x-selection-value 'CLIPBOARD))
1258 (if (string= clip-text "") (setq clip-text nil))
1259
1260 ;; Check the CLIPBOARD selection for 'newness', is it different
1261 ;; from what we remebered them to be last time we did a
1262 ;; cut/paste operation.
1263 (setq clip-text
1264 (cond;; check clipboard
1265 ((or (not clip-text) (string= clip-text ""))
1266 (setq x-last-selected-text-clipboard nil))
1267 ((eq clip-text x-last-selected-text-clipboard) nil)
1268 ((string= clip-text x-last-selected-text-clipboard)
1269 ;; Record the newer string,
1270 ;; so subsequent calls can use the `eq' test.
1271 (setq x-last-selected-text-clipboard clip-text)
1272 nil)
1273 (t
1274 (setq x-last-selected-text-clipboard clip-text))))
1275 )
1276
1277 (setq primary-text (x-selection-value 'PRIMARY))
1278 ;; Check the PRIMARY selection for 'newness', is it different
1279 ;; from what we remebered them to be last time we did a
1280 ;; cut/paste operation.
1281 (setq primary-text
1282 (cond;; check primary selection
1283 ((or (not primary-text) (string= primary-text ""))
1284 (setq x-last-selected-text-primary nil))
1285 ((eq primary-text x-last-selected-text-primary) nil)
1286 ((string= primary-text x-last-selected-text-primary)
1287 ;; Record the newer string,
1288 ;; so subsequent calls can use the `eq' test.
1289 (setq x-last-selected-text-primary primary-text)
1290 nil)
1291 (t
1292 (setq x-last-selected-text-primary primary-text))))
1293
1294 ;; As we have done one selection, clear this now.
1295 (setq next-selection-coding-system nil)
1296
1297 ;; At this point we have recorded the current values for the
1298 ;; selection from clipboard (if we are supposed to) and primary,
1299 ;; So return the first one that has changed (which is the first
1300 ;; non-null one).
1301 (or clip-text primary-text)
1302 ))
1303
1304 (put 'CLIPBOARD 'mac-scrap-name "com.apple.scrap.clipboard")
1305 (when (eq system-type 'darwin)
1306 (put 'FIND 'mac-scrap-name "com.apple.scrap.find")
1307 (put 'PRIMARY 'mac-scrap-name
1308 (format "org.gnu.Emacs.%d.selection.PRIMARY" (emacs-pid))))
1309 (put 'com.apple.traditional-mac-plain-text 'mac-ostype "TEXT")
1310 (put 'public.utf16-plain-text 'mac-ostype "utxt")
1311 (put 'public.tiff 'mac-ostype "TIFF")
1312 (put 'public.file-url 'mac-ostype "furl")
1313
1314 (defun mac-select-convert-to-string (selection type value)
1315 (let ((str (cdr (xselect-convert-to-string selection nil value)))
1316 coding)
1317 (setq coding (or next-selection-coding-system selection-coding-system))
1318 (if coding
1319 (setq coding (coding-system-base coding))
1320 (setq coding 'raw-text))
1321 (when str
1322 ;; If TYPE is nil, this is a local request, thus return STR as
1323 ;; is. Otherwise, encode STR.
1324 (if (not type)
1325 str
1326 (let ((inhibit-read-only t))
1327 (remove-text-properties 0 (length str) '(composition nil) str)
1328 (cond
1329 ((eq type 'public.utf16-plain-text)
1330 (if (fboundp 'mac-code-convert-string)
1331 (let (s)
1332 (when (memq coding (find-coding-systems-string str))
1333 (setq coding
1334 (coding-system-change-eol-conversion coding 'mac))
1335 (setq s (mac-code-convert-string
1336 (encode-coding-string str coding)
1337 coding nil)))
1338 (setq str (or s
1339 ;; (encode-coding-string str
1340 ;; 'utf-16-mac) is not correct because
1341 ;; public.utf16-plain-text is defined
1342 ;; as native byte order, no BOM.
1343 (mac-code-convert-string
1344 (encode-coding-string str 'utf-8-mac)
1345 'utf-8 nil))))
1346 ;; No `mac-code-convert-string' means non-Carbon, which
1347 ;; implies big endian.
1348 (setq str (encode-coding-string str 'utf-16be-mac))))
1349 ((eq type 'com.apple.traditional-mac-plain-text)
1350 (let ((encodables (find-coding-systems-string str))
1351 (rest mac-script-code-coding-systems))
1352 (unless (memq coding encodables)
1353 (while (and rest (not (memq (cdar rest) encodables)))
1354 (setq rest (cdr rest)))
1355 (if rest
1356 (setq coding (cdar rest)))))
1357 (setq coding (coding-system-change-eol-conversion coding 'mac))
1358 (setq str (encode-coding-string str coding)))
1359 (t
1360 (error "Unknown selection type: %S" type))
1361 )))
1362
1363 (setq next-selection-coding-system nil)
1364 (cons type str))))
1365
1366 (defun mac-select-convert-to-file-url (selection type value)
1367 (let ((filename (xselect-convert-to-filename selection type value))
1368 (coding (or file-name-coding-system default-file-name-coding-system)))
1369 (if (and filename coding)
1370 (setq filename (encode-coding-string filename coding)))
1371 (and filename
1372 (concat "file://localhost"
1373 (mapconcat 'url-hexify-string
1374 (split-string filename "/") "/")))))
1375
1376 (setq selection-converter-alist
1377 (nconc
1378 '((public.utf16-plain-text . mac-select-convert-to-string)
1379 (com.apple.traditional-mac-plain-text . mac-select-convert-to-string)
1380 ;; This is not enabled by default because the `Import Image'
1381 ;; menu makes Emacs crash or hang for unknown reasons.
1382 ;; (public.tiff . nil)
1383 (public.file-url . mac-select-convert-to-file-url)
1384 )
1385 selection-converter-alist))
1386
1387 (defun mac-services-open-file ()
1388 (interactive)
1389 (find-file-existing (x-selection-value mac-services-selection)))
1390
1391 (defun mac-services-open-selection ()
1392 (interactive)
1393 (switch-to-buffer (generate-new-buffer "*untitled*"))
1394 (insert (x-selection-value mac-services-selection))
1395 (sit-for 0)
1396 (save-buffer) ; It pops up the save dialog.
1397 )
1398
1399 (defun mac-services-mail-selection ()
1400 (interactive)
1401 (compose-mail)
1402 (rfc822-goto-eoh)
1403 (forward-line 1)
1404 (insert (x-selection-value mac-services-selection) "\n"))
1405
1406 (defun mac-services-mail-to ()
1407 (interactive)
1408 (compose-mail (x-selection-value mac-services-selection)))
1409
1410 (defun mac-services-insert-text ()
1411 (interactive)
1412 (let ((text (x-selection-value mac-services-selection)))
1413 (if (not buffer-read-only)
1414 (insert text)
1415 (kill-new text)
1416 (message
1417 (substitute-command-keys
1418 "The text from the Services menu can be accessed with \\[yank]")))))
1419
1420 (defvar mac-application-menu-map (make-sparse-keymap))
1421 (define-key mac-application-menu-map [quit] 'save-buffers-kill-emacs)
1422 (define-key mac-application-menu-map [services perform open-file]
1423 'mac-services-open-file)
1424 (define-key mac-application-menu-map [services perform open-selection]
1425 'mac-services-open-selection)
1426 (define-key mac-application-menu-map [services perform mail-selection]
1427 'mac-services-mail-selection)
1428 (define-key mac-application-menu-map [services perform mail-to]
1429 'mac-services-mail-to)
1430 (define-key mac-application-menu-map [services paste]
1431 'mac-services-insert-text)
1432 (define-key mac-application-menu-map [preferences] 'customize)
1433 (define-key mac-application-menu-map [about] 'display-splash-screen)
1434 (global-set-key [menu-bar application] mac-application-menu-map)
1435 \f
1436 ;;; Do the actual Windows setup here; the above code just defines
1437 ;;; functions and variables that we use now.
1438
1439 (setq command-line-args (x-handle-args command-line-args))
1440
1441 ;;; Make sure we have a valid resource name.
1442 (or (stringp x-resource-name)
1443 (let (i)
1444 (setq x-resource-name (invocation-name))
1445
1446 ;; Change any . or * characters in x-resource-name to hyphens,
1447 ;; so as not to choke when we use it in X resource queries.
1448 (while (setq i (string-match "[.*]" x-resource-name))
1449 (aset x-resource-name i ?-))))
1450
1451 (if (x-display-list)
1452 ;; On Mac OS 8/9, Most coding systems used in code conversion for
1453 ;; font names are not ready at the time when the terminal frame is
1454 ;; created. So we reconstruct font name table for the initial
1455 ;; frame.
1456 (mac-clear-font-name-table)
1457 (x-open-connection "Mac"
1458 x-command-line-resources
1459 ;; Exit Emacs with fatal error if this fails.
1460 t))
1461
1462 (setq frame-creation-function 'x-create-frame-with-faces)
1463
1464 (define-charset 'mac-centraleurroman
1465 "Mac Central European Roman"
1466 :short-name "Mac CE"
1467 :ascii-compatible-p t
1468 :code-space [0 255]
1469 :map
1470 (let ((tbl
1471 [?\Ä ?\Ā ?\ā ?\É ?\Ą ?\Ö ?\Ü ?\á ?\ą ?\Č ?\ä ?\č ?\Ć ?\ć ?\é ?\Ź
1472 ?\ź ?\Ď ?\í ?\ď ?\Ē ?\ē ?\Ė ?\ó ?\ė ?\ô ?\ö ?\õ ?\ú ?\Ě ?\ě ?\ü
1473 ?\† ?\° ?\Ę ?\£ ?\§ ?\• ?\¶ ?\ß ?\® ?\© ?\™ ?\ę ?\¨ ?\≠ ?\ģ ?\Į
1474 ?\į ?\Ī ?\≤ ?\≥ ?\ī ?\Ķ ?\∂ ?\∑ ?\ł ?\Ļ ?\ļ ?\Ľ ?\ľ ?\Ĺ ?\ĺ ?\Ņ
1475 ?\ņ ?\Ń ?\¬ ?\√ ?\ń ?\Ň ?\∆ ?\« ?\» ?\… ?\  ?\ň ?\Ő ?\Õ ?\ő ?\Ō
1476 ?\– ?\— ?\“ ?\” ?\‘ ?\’ ?\÷ ?\◊ ?\ō ?\Ŕ ?\ŕ ?\Ř ?\‹ ?\› ?\ř ?\Ŗ
1477 ?\ŗ ?\Š ?\‚ ?\„ ?\š ?\Ś ?\ś ?\Á ?\Ť ?\ť ?\Í ?\Ž ?\ž ?\Ū ?\Ó ?\Ô
1478 ?\ū ?\Ů ?\Ú ?\ů ?\Ű ?\ű ?\Ų ?\ų ?\Ý ?\ý ?\ķ ?\Ż ?\Ł ?\ż ?\Ģ ?\ˇ])
1479 (map (make-vector 512 nil)))
1480 (or (= (length tbl) 128)
1481 (error "Invalid vector length: %d" (length tbl)))
1482 (dotimes (i 128)
1483 (aset map (* i 2) i)
1484 (aset map (1+ (* i 2)) i))
1485 (dotimes (i 128)
1486 (aset map (+ 256 (* i 2)) (+ 128 i))
1487 (aset map (+ 256 (1+ (* i 2))) (aref tbl i)))
1488 map))
1489
1490 (define-coding-system 'mac-centraleurroman
1491 "Mac Central European Roman Encoding (MIME:x-mac-centraleurroman)."
1492 :coding-type 'charset
1493 :mnemonic ?*
1494 :charset-list '(mac-centraleurroman)
1495 :mime-charset 'x-mac-centraleurroman)
1496
1497 (define-charset 'mac-cyrillic
1498 "Mac Cyrillic"
1499 :short-name "Mac CYRILLIC"
1500 :ascii-compatible-p t
1501 :code-space [0 255]
1502 :map
1503 (let ((tbl
1504 [?\А ?\Б ?\В ?\Г ?\Д ?\Е ?\Ж ?\З ?\И ?\Й ?\К ?\Л ?\М ?\Н ?\О ?\П
1505 ?\Р ?\С ?\Т ?\У ?\Ф ?\Х ?\Ц ?\Ч ?\Ш ?\Щ ?\Ъ ?\Ы ?\Ь ?\Э ?\Ю ?\Я
1506 ?\† ?\° ?\Ґ ?\£ ?\§ ?\• ?\¶ ?\І ?\® ?\© ?\™ ?\Ђ ?\ђ ?\≠ ?\Ѓ ?\ѓ
1507 ?\∞ ?\± ?\≤ ?\≥ ?\і ?\µ ?\ґ ?\Ј ?\Є ?\є ?\Ї ?\ї ?\Љ ?\љ ?\Њ ?\њ
1508 ?\ј ?\Ѕ ?\¬ ?\√ ?\ƒ ?\≈ ?\∆ ?\« ?\» ?\… ?\  ?\Ћ ?\ћ ?\Ќ ?\ќ ?\ѕ
1509 ?\– ?\— ?\“ ?\” ?\‘ ?\’ ?\÷ ?\„ ?\Ў ?\ў ?\Џ ?\џ ?\№ ?\Ё ?\ё ?\я
1510 ?\а ?\б ?\в ?\г ?\д ?\е ?\ж ?\з ?\и ?\й ?\к ?\л ?\м ?\н ?\о ?\п
1511 ?\р ?\с ?\т ?\у ?\ф ?\х ?\ц ?\ч ?\ш ?\щ ?\ъ ?\ы ?\ь ?\э ?\ю ?\€])
1512 (map (make-vector 512 nil)))
1513 (or (= (length tbl) 128)
1514 (error "Invalid vector length: %d" (length tbl)))
1515 (dotimes (i 128)
1516 (aset map (* i 2) i)
1517 (aset map (1+ (* i 2)) i))
1518 (dotimes (i 128)
1519 (aset map (+ 256 (* i 2)) (+ 128 i))
1520 (aset map (+ 256 (1+ (* i 2))) (aref tbl i)))
1521 map))
1522
1523 (define-coding-system 'mac-cyrillic
1524 "Mac Cyrillic Encoding (MIME:x-mac-cyrillic)."
1525 :coding-type 'charset
1526 :mnemonic ?*
1527 :charset-list '(mac-cyrillic)
1528 :mime-charset 'x-mac-cyrillic)
1529
1530 (define-charset 'mac-symbol
1531 "Mac Symbol"
1532 :short-name "Mac SYMBOL"
1533 :code-space [32 254]
1534 :map
1535 (let ((tbl-32-126
1536 [?\ ?\! ?\∀ ?\# ?\∃ ?\% ?\& ?\∍ ?\( ?\) ?\∗ ?\+ ?\, ?\− ?\. ?\/
1537 ?\0 ?\1 ?\2 ?\3 ?\4 ?\5 ?\6 ?\7 ?\8 ?\9 ?\: ?\; ?\< ?\= ?\> ?\?
1538 ?\≅ ?\Α ?\Β ?\Χ ?\Δ ?\Ε ?\Φ ?\Γ ?\Η ?\Ι ?\ϑ ?\Κ ?\Λ ?\Μ ?\Ν ?\Ο
1539 ?\Π ?\Θ ?\Ρ ?\Σ ?\Τ ?\Υ ?\ς ?\Ω ?\Ξ ?\Ψ ?\Ζ ?\[ ?\∴ ?\] ?\⊥ ?\_
1540 ?\ ?\α ?\β ?\χ ?\δ ?\ε ?\φ ?\γ ?\η ?\ι ?\ϕ ?\κ ?\λ ?\μ ?\ν ?\ο
1541 ?\π ?\θ ?\ρ ?\σ ?\τ ?\υ ?\ϖ ?\ω ?\ξ ?\ψ ?\ζ ?\{ ?\| ?\} ?\∼])
1542 (map-32-126 (make-vector (* (1+ (- 126 32)) 2) nil))
1543 (tbl-160-254
1544 ;; Mapping of the following characters are changed from the
1545 ;; original one:
1546 ;; 0xE2 0x00AE+0xF87F->0x00AE # REGISTERED SIGN, alternate: sans serif
1547 ;; 0xE3 0x00A9+0xF87F->0x00A9 # COPYRIGHT SIGN, alternate: sans serif
1548 ;; 0xE4 0x2122+0xF87F->0x2122 # TRADE MARK SIGN, alternate: sans serif
1549 [?\€ ?\ϒ ?\′ ?\≤ ?\⁄ ?\∞ ?\ƒ ?\♣ ?\♦ ?\♥ ?\♠ ?\↔ ?\← ?\↑ ?\→ ?\↓
1550 ?\° ?\± ?\″ ?\≥ ?\× ?\∝ ?\∂ ?\• ?\÷ ?\≠ ?\≡ ?\≈ ?\… ?\⏐ ?\⎯ ?\↵
1551 ?\ℵ ?\ℑ ?\ℜ ?\℘ ?\⊗ ?\⊕ ?\∅ ?\∩ ?\∪ ?\⊃ ?\⊇ ?\⊄ ?\⊂ ?\⊆ ?\∈ ?\∉
1552 ?\∠ ?\∇ ?\® ?\© ?\™ ?\∏ ?\√ ?\⋅ ?\¬ ?\∧ ?\∨ ?\⇔ ?\⇐ ?\⇑ ?\⇒ ?\⇓
1553 ?\◊ ?\〈 ?\® ?\© ?\™ ?\∑ ?\⎛ ?\⎜ ?\⎝ ?\⎡ ?\⎢ ?\⎣ ?\⎧ ?\⎨ ?\⎩ ?\⎪
1554 ?\ ?\〉 ?\∫ ?\⌠ ?\⎮ ?\⌡ ?\⎞ ?\⎟ ?\⎠ ?\⎤ ?\⎥ ?\⎦ ?\⎫ ?\⎬ ?\⎭])
1555 (map-160-254 (make-vector (* (1+ (- 254 160)) 2) nil)))
1556 (dotimes (i (1+ (- 126 32)))
1557 (aset map-32-126 (* i 2) (+ 32 i))
1558 (aset map-32-126 (1+ (* i 2)) (aref tbl-32-126 i)))
1559 (dotimes (i (1+ (- 254 160)))
1560 (aset map-160-254 (* i 2) (+ 160 i))
1561 (aset map-160-254 (1+ (* i 2)) (aref tbl-160-254 i)))
1562 (vconcat map-32-126 map-160-254)))
1563
1564 (define-charset 'mac-dingbats
1565 "Mac Dingbats"
1566 :short-name "Mac Dingbats"
1567 :code-space [32 254]
1568 :map
1569 (let ((tbl-32-126
1570 [?\ ?\✁ ?\✂ ?\✃ ?\✄ ?\☎ ?\✆ ?\✇ ?\✈ ?\✉ ?\☛ ?\☞ ?\✌ ?\✍ ?\✎ ?\✏
1571 ?\✐ ?\✑ ?\✒ ?\✓ ?\✔ ?\✕ ?\✖ ?\✗ ?\✘ ?\✙ ?\✚ ?\✛ ?\✜ ?\✝ ?\✞ ?\✟
1572 ?\✠ ?\✡ ?\✢ ?\✣ ?\✤ ?\✥ ?\✦ ?\✧ ?\★ ?\✩ ?\✪ ?\✫ ?\✬ ?\✭ ?\✮ ?\✯
1573 ?\✰ ?\✱ ?\✲ ?\✳ ?\✴ ?\✵ ?\✶ ?\✷ ?\✸ ?\✹ ?\✺ ?\✻ ?\✼ ?\✽ ?\✾ ?\✿
1574 ?\❀ ?\❁ ?\❂ ?\❃ ?\❄ ?\❅ ?\❆ ?\❇ ?\❈ ?\❉ ?\❊ ?\❋ ?\● ?\❍ ?\■ ?\❏
1575 ?\❐ ?\❑ ?\❒ ?\▲ ?\▼ ?\◆ ?\❖ ?\◗ ?\❘ ?\❙ ?\❚ ?\❛ ?\❜ ?\❝ ?\❞])
1576 (map-32-126 (make-vector (* (1+ (- 126 32)) 2) nil))
1577 (tbl-128-141
1578 [?\❨ ?\❩ ?\❪ ?\❫ ?\❬ ?\❭ ?\❮ ?\❯ ?\❰ ?\❱ ?\❲ ?\❳ ?\❴ ?\❵])
1579 (map-128-141 (make-vector (* (1+ (- 141 128)) 2) nil))
1580 (tbl-161-239
1581 [?\❡ ?\❢ ?\❣ ?\❤ ?\❥ ?\❦ ?\❧ ?\♣ ?\♦ ?\♥ ?\♠ ?\① ?\② ?\③ ?\④
1582 ?\⑤ ?\⑥ ?\⑦ ?\⑧ ?\⑨ ?\⑩ ?\❶ ?\❷ ?\❸ ?\❹ ?\❺ ?\❻ ?\❼ ?\❽ ?\❾ ?\❿
1583 ?\➀ ?\➁ ?\➂ ?\➃ ?\➄ ?\➅ ?\➆ ?\➇ ?\➈ ?\➉ ?\➊ ?\➋ ?\➌ ?\➍ ?\➎ ?\➏
1584 ?\➐ ?\➑ ?\➒ ?\➓ ?\➔ ?\→ ?\↔ ?\↕ ?\➘ ?\➙ ?\➚ ?\➛ ?\➜ ?\➝ ?\➞ ?\➟
1585 ?\➠ ?\➡ ?\➢ ?\➣ ?\➤ ?\➥ ?\➦ ?\➧ ?\➨ ?\➩ ?\➪ ?\➫ ?\➬ ?\➭ ?\➮ ?\➯])
1586 (map-161-239 (make-vector (* (1+ (- 239 161)) 2) nil))
1587 (tbl-241-254
1588 [?\➱ ?\➲ ?\➳ ?\➴ ?\➵ ?\➶ ?\➷ ?\➸ ?\➹ ?\➺ ?\➻ ?\➼ ?\➽ ?\➾])
1589 (map-241-254 (make-vector (* (1+ (- 254 241)) 2) nil)))
1590 (dotimes (i (1+ (- 126 32)))
1591 (aset map-32-126 (* i 2) (+ 32 i))
1592 (aset map-32-126 (1+ (* i 2)) (aref tbl-32-126 i)))
1593 (dotimes (i (1+ (- 141 128)))
1594 (aset map-128-141 (* i 2) (+ 128 i))
1595 (aset map-128-141 (1+ (* i 2)) (aref tbl-128-141 i)))
1596 (dotimes (i (1+ (- 239 161)))
1597 (aset map-161-239 (* i 2) (+ 161 i))
1598 (aset map-161-239 (1+ (* i 2)) (aref tbl-161-239 i)))
1599 (dotimes (i (1+ (- 254 241)))
1600 (aset map-241-254 (* i 2) (+ 241 i))
1601 (aset map-241-254 (1+ (* i 2)) (aref tbl-241-254 i)))
1602 (vconcat map-32-126 map-128-141 map-161-239 map-241-254)))
1603
1604 (setq font-encoding-alist
1605 (append
1606 '(("mac-roman" . mac-roman)
1607 ("mac-centraleurroman" . mac-centraleurroman)
1608 ("mac-cyrillic" . mac-cyrillic)
1609 ("mac-symbol" . mac-symbol)
1610 ("mac-dingbats" . mac-dingbats))
1611 font-encoding-alist))
1612
1613 (defun fontset-add-mac-fonts (fontset &optional base-family)
1614 (dolist (elt `((latin . (,(or base-family "Monaco") . "mac-roman"))
1615 (mac-roman . (,base-family . "mac-roman"))
1616 (mac-centraleurroman . (,base-family . "mac-centraleurroman"))
1617 (mac-cyrillic . (,base-family . "mac-cyrillic"))
1618 (mac-symbol . (,base-family . "mac-symbol"))
1619 (mac-dingbats . (,base-family . "mac-dingbats"))))
1620 (set-fontset-font fontset (car elt) (cdr elt))))
1621
1622 (defun create-fontset-from-mac-roman-font (font &optional resolved-font
1623 fontset-name)
1624 "Create a fontset from a Mac roman font FONT.
1625
1626 Optional 1st arg RESOLVED-FONT is a resolved name of FONT. If
1627 omitted, `x-resolve-font-name' is called to get the resolved name. At
1628 this time, if FONT is not available, error is signaled.
1629
1630 Optional 2nd arg FONTSET-NAME is a string to be used in
1631 `<CHARSET_ENCODING>' fields of a new fontset name. If it is omitted,
1632 an appropriate name is generated automatically.
1633
1634 It returns a name of the created fontset."
1635 (or resolved-font
1636 (setq resolved-font (x-resolve-font-name font)))
1637 (let ((base-family (aref (x-decompose-font-name resolved-font)
1638 xlfd-regexp-family-subnum)))
1639 (if (string= base-family "*")
1640 (setq base-family nil))
1641 (new-fontset fontset-name (list (cons 'ascii resolved-font)))
1642 (fontset-add-mac-fonts fontset-name base-family)))
1643
1644 ;; Setup the default fontset.
1645 (setup-default-fontset)
1646
1647 ;; Create a fontset that uses mac-roman font. With this fontset,
1648 ;; characters belonging to mac-roman charset (that contains ASCII and
1649 ;; more Latin characters) are displayed by a mac-roman font.
1650 (create-fontset-from-mac-roman-font
1651 "-*-Monaco-*-*-*-*-12-*-*-*-*-*-mac-roman" nil
1652 "-apple-Monaco-normal-r-*-*-12-*-*-*-*-*-fontset-mac")
1653
1654 ;; Create fontset specified in X resources "Fontset-N" (N is 0, 1, ...).
1655 (create-fontset-from-x-resource)
1656
1657 ;; Apply a geometry resource to the initial frame. Put it at the end
1658 ;; of the alist, so that anything specified on the command line takes
1659 ;; precedence.
1660 (let* ((res-geometry (x-get-resource "geometry" "Geometry"))
1661 parsed)
1662 (if res-geometry
1663 (progn
1664 (setq parsed (x-parse-geometry res-geometry))
1665 ;; If the resource specifies a position,
1666 ;; call the position and size "user-specified".
1667 (if (or (assq 'top parsed) (assq 'left parsed))
1668 (setq parsed (cons '(user-position . t)
1669 (cons '(user-size . t) parsed))))
1670 ;; All geometry parms apply to the initial frame.
1671 (setq initial-frame-alist (append initial-frame-alist parsed))
1672 ;; The size parms apply to all frames.
1673 (if (assq 'height parsed)
1674 (setq default-frame-alist
1675 (cons (cons 'height (cdr (assq 'height parsed)))
1676 default-frame-alist)))
1677 (if (assq 'width parsed)
1678 (setq default-frame-alist
1679 (cons (cons 'width (cdr (assq 'width parsed)))
1680 default-frame-alist))))))
1681
1682 ;; Check the reverseVideo resource.
1683 (let ((case-fold-search t))
1684 (let ((rv (x-get-resource "reverseVideo" "ReverseVideo")))
1685 (if (and rv
1686 (string-match "^\\(true\\|yes\\|on\\)$" rv))
1687 (setq default-frame-alist
1688 (cons '(reverse . t) default-frame-alist)))))
1689
1690 (defun x-win-suspend-error ()
1691 (error "Suspending an Emacs running under Mac makes no sense"))
1692 (add-hook 'suspend-hook 'x-win-suspend-error)
1693
1694 ;;; Arrange for the kill and yank functions to set and check the clipboard.
1695 (setq interprogram-cut-function 'x-select-text)
1696 (setq interprogram-paste-function 'x-get-selection-value)
1697
1698 (defalias 'x-cut-buffer-or-selection-value 'x-get-selection-value)
1699
1700 ;;; Turn off window-splitting optimization; Mac is usually fast enough
1701 ;;; that this is only annoying.
1702 (setq split-window-keep-point t)
1703
1704 ;; Don't show the frame name; that's redundant.
1705 (setq-default mode-line-frame-identification " ")
1706
1707 ;; Turn on support for mouse wheels.
1708 (mouse-wheel-mode 1)
1709
1710
1711 ;; Enable CLIPBOARD copy/paste through menu bar commands.
1712 (menu-bar-enable-clipboard)
1713
1714 (defun mac-drag-n-drop (event)
1715 "Edit the files listed in the drag-n-drop EVENT.
1716 Switch to a buffer editing the last file dropped."
1717 (interactive "e")
1718 ;; Make sure the drop target has positive co-ords
1719 ;; before setting the selected frame - otherwise it
1720 ;; won't work. <skx@tardis.ed.ac.uk>
1721 (let* ((window (posn-window (event-start event)))
1722 (coords (posn-x-y (event-start event)))
1723 (x (car coords))
1724 (y (cdr coords)))
1725 (if (and (> x 0) (> y 0))
1726 (set-frame-selected-window nil window))
1727 (mapcar (lambda (file-name)
1728 (if (listp file-name)
1729 (let ((line (car file-name))
1730 (start (car (cdr file-name)))
1731 (end (car (cdr (cdr file-name)))))
1732 (if (> line 0)
1733 (goto-line line)
1734 (if (and (> start 0) (> end 0))
1735 (progn (set-mark start)
1736 (goto-char end)))))
1737 (dnd-handle-one-url window 'private
1738 (concat "file:" file-name))))
1739 (car (cdr (cdr event)))))
1740 (raise-frame))
1741
1742 (global-set-key [drag-n-drop] 'mac-drag-n-drop)
1743
1744 ;; By checking whether the variable mac-ready-for-drag-n-drop has been
1745 ;; defined, the event loop in macterm.c can be informed that it can
1746 ;; now receive Finder drag and drop events. Files dropped onto the
1747 ;; Emacs application icon can only be processed when the initial frame
1748 ;; has been created: this is where the files should be opened.
1749 (add-hook 'after-init-hook
1750 '(lambda ()
1751 (defvar mac-ready-for-drag-n-drop t)))
1752 \f
1753 ;;;; Non-toolkit Scroll bars
1754
1755 (unless x-toolkit-scroll-bars
1756
1757 ;; for debugging
1758 ;; (defun mac-handle-scroll-bar-event (event) (interactive "e") (princ event))
1759
1760 ;;(global-set-key [vertical-scroll-bar mouse-1] 'mac-handle-scroll-bar-event)
1761
1762 (global-set-key
1763 [vertical-scroll-bar down-mouse-1]
1764 'mac-handle-scroll-bar-event)
1765
1766 (global-unset-key [vertical-scroll-bar drag-mouse-1])
1767 (global-unset-key [vertical-scroll-bar mouse-1])
1768
1769 (defun mac-handle-scroll-bar-event (event)
1770 "Handle scroll bar EVENT to emulate Mac Toolbox style scrolling."
1771 (interactive "e")
1772 (let* ((position (event-start event))
1773 (window (nth 0 position))
1774 (bar-part (nth 4 position)))
1775 (select-window window)
1776 (cond
1777 ((eq bar-part 'up)
1778 (goto-char (window-start window))
1779 (mac-scroll-down-line))
1780 ((eq bar-part 'above-handle)
1781 (mac-scroll-down))
1782 ((eq bar-part 'handle)
1783 (scroll-bar-drag event))
1784 ((eq bar-part 'below-handle)
1785 (mac-scroll-up))
1786 ((eq bar-part 'down)
1787 (goto-char (window-start window))
1788 (mac-scroll-up-line)))))
1789
1790 (defun mac-scroll-ignore-events ()
1791 ;; Ignore confusing non-mouse events
1792 (while (not (memq (car-safe (read-event))
1793 '(mouse-1 double-mouse-1 triple-mouse-1))) nil))
1794
1795 (defun mac-scroll-down ()
1796 (track-mouse
1797 (mac-scroll-ignore-events)
1798 (scroll-down)))
1799
1800 (defun mac-scroll-down-line ()
1801 (track-mouse
1802 (mac-scroll-ignore-events)
1803 (scroll-down 1)))
1804
1805 (defun mac-scroll-up ()
1806 (track-mouse
1807 (mac-scroll-ignore-events)
1808 (scroll-up)))
1809
1810 (defun mac-scroll-up-line ()
1811 (track-mouse
1812 (mac-scroll-ignore-events)
1813 (scroll-up 1)))
1814
1815 )
1816 \f
1817 ;;;; Others
1818
1819 (unless (eq system-type 'darwin)
1820 ;; This variable specifies the Unix program to call (as a process) to
1821 ;; determine the amount of free space on a file system (defaults to
1822 ;; df). If it is not set to nil, ls-lisp will not work correctly
1823 ;; unless an external application df is implemented on the Mac.
1824 (setq directory-free-space-program nil)
1825
1826 ;; Set this so that Emacs calls subprocesses with "sh" as shell to
1827 ;; expand filenames Note no subprocess for the shell is actually
1828 ;; started (see run_mac_command in sysdep.c).
1829 (setq shell-file-name "sh")
1830
1831 ;; Some system variables are encoded with the system script code.
1832 (dolist (v '(system-name
1833 emacs-build-system ; Mac OS 9 version cannot dump
1834 user-login-name user-real-login-name user-full-name))
1835 (set v (decode-coding-string (symbol-value v) mac-system-coding-system))))
1836
1837 ;; If Emacs is started from the Finder, change the default directory
1838 ;; to the user's home directory.
1839 (if (string= default-directory "/")
1840 (cd "~"))
1841
1842 ;; Darwin 6- pty breakage is now controlled from the C code so that
1843 ;; it applies to all builds on darwin. See s/darwin.h PTY_ITERATION.
1844 ;; (setq process-connection-type t)
1845
1846 ;; Assume that fonts are always scalable on the Mac. This sometimes
1847 ;; results in characters with jagged edges. However, without it,
1848 ;; fonts with both truetype and bitmap representations but no italic
1849 ;; or bold bitmap versions will not display these variants correctly.
1850 (setq scalable-fonts-allowed t)
1851
1852 ;; arch-tag: 71dfcd14-cde8-4d66-b05c-85ec94fb23a6
1853 ;;; mac-win.el ends here