(url-retrieve-internal): Bind url-proxy-object to nil.
[emacs.git] / lisp / term / mac-win.el
blob3f67c2c66135aac19f95f2622cd9aff4f9f16529
1 ;;; mac-win.el --- parse switches controlling interface with Mac window system -*-coding: iso-2022-7bit;-*-
3 ;; Copyright (C) 1999, 2000, 2002, 2003, 2004,
4 ;; 2005, 2006 Free Software Foundation, Inc.
6 ;; Author: Andrew Choi <akochoi@mac.com>
7 ;; Keywords: terminals
9 ;; This file is part of GNU Emacs.
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.
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.
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.
26 ;;; Commentary:
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.
33 ;; startup.el will then examine startup files, and eventually call the hooks
34 ;; which create the first window(s).
36 ;;; Code:
38 ;; These are the standard X switches from the Xt Initialize.c file of
39 ;; Release 4.
41 ;; Command line Resource Manager string
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
65 ;; An alist of X options and the function which handles them. See
66 ;; ../startup.el.
68 (if (not (eq window-system 'mac))
69 (error "%s: Loading mac-win.el but not compiled for Mac" (invocation-name)))
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 (eval-when-compile (require 'url))
81 (defvar mac-charset-info-alist)
82 (defvar mac-service-selection)
83 (defvar mac-system-script-code)
84 (defvar mac-apple-event-map)
85 (defvar mac-atsu-font-table)
86 (defvar mac-font-panel-mode)
87 (defvar mac-ts-active-input-overlay)
88 (defvar x-invocation-args)
90 (defvar x-command-line-resources nil)
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)))))))
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
115 (string-to-number (car x-invocation-args)))
116 default-frame-alist)
117 x-invocation-args
118 (cdr x-invocation-args))))))
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)))))))
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)))
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)))
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))))
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)))
188 (defvar x-display-name nil
189 "The display name specifying server and frame.")
191 (defun x-handle-display (switch)
192 (setq x-display-name (car x-invocation-args)
193 x-invocation-args (cdr x-invocation-args)))
195 (defun x-handle-args (args)
196 "Process the X-related command line options in ARGS.
197 This 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
199 the 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).
201 This 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.
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))
242 ;; Standard Mac cursor shapes
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)
272 ;; Standard X cursor shapes that have Mac counterparts
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)
290 ;; Available colors
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")
1045 "The list of X colors from the `rgb.txt' file.
1046 XConsortium: rgb.txt,v 10.41 94/02/20 18:39:36 rws Exp")
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))
1061 ;;;; Function keys
1063 (substitute-key-definition 'suspend-emacs 'iconify-or-deiconify-frame
1064 global-map)
1066 ;; Map certain keypad keys into ASCII characters
1067 ;; that people usually expect.
1068 (define-key function-key-map [backspace] [?\d])
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])
1074 (define-key function-key-map [escape] [?\e])
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])
1081 (define-key function-key-map [M-escape] [?\M-\e])
1083 ;; These tell read-char how to convert
1084 ;; these special chars to ASCII.
1085 (put 'backspace 'ascii-character ?\d)
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)
1091 (put 'escape 'ascii-character ?\e)
1093 ;; Modifier name `ctrl' is an alias of `control'.
1094 (put 'ctrl 'modifier-value (get 'control 'modifier-value))
1097 ;;;; Script codes and coding systems
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
1107 "Alist of Mac script codes vs Emacs coding systems.")
1109 (defun mac-add-charset-info (xlfd-charset mac-text-encoding)
1110 "Add a character set to display with Mac fonts.
1111 Create an entry in `mac-charset-info-alist'.
1112 XLFD-CHARSET is a string which will appear in the XLFD font name
1113 to identify the character set. MAC-TEXT-ENCODING is the
1114 correspoinding 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)))))
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)
1132 (mac-add-charset-info "iso10646-1" 126) ; for ATSUI
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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\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)
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$,1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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$,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symbol-decoder translation-table)
1189 (define-translation-table 'mac-symbol-encoder
1190 (char-table-extra-slot translation-table 0)))
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 ?\\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?\\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)))
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.")
1233 (set-selection-coding-system mac-system-coding-system)
1236 ;;;; Keyboard layout/language change events
1237 (defun mac-handle-language-change (event)
1238 "Set keyboard coding system to what is specified in EVENT."
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] "\\"))))
1247 (define-key special-event-map [language-change] 'mac-handle-language-change)
1250 ;;;; Conversion between common flavors and Lisp string.
1252 (defconst mac-text-encoding-ascii #x600
1253 "ASCII text encoding.")
1255 (defconst mac-text-encoding-mac-japanese-basic-variant #x20001
1256 "MacJapanese text encoding without Apple double-byte extensions.")
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))
1269 (if (eq encoding mac-text-encoding-mac-japanese-basic-variant)
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)
1274 ;; ASCII-only?
1275 (unless (mac-code-convert-string data nil mac-text-encoding-ascii)
1276 (subst-char-in-string ?\x5c ?\\e(J\\e(B str t)
1277 (subst-char-in-string ?\x80 ?\\ str t)))))
1278 (or str
1279 (decode-coding-string data
1280 (if (eq (byteorder) ?B) 'utf-16be 'utf-16le)))))
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 (let ((str string))
1291 (when (and (eq system-type 'darwin)
1292 (eq coding-system 'japanese-shift-jis-mac))
1293 (setq encoding mac-text-encoding-mac-japanese-basic-variant)
1294 (setq str (subst-char-in-string ?\\ ?\x80 str))
1295 (subst-char-in-string ?\\e(J\\e(B ?\x5c str t)
1296 ;; ASCII-only?
1297 (if (string-match "\\`[\x00-\x7f]*\\'" str)
1298 (setq str nil)))
1299 (and str
1300 (setq data (mac-code-convert-string
1301 (encode-coding-string str coding-system)
1302 (or encoding coding-system) nil)))))
1303 (or data (encode-coding-string string (if (eq (byteorder) ?B)
1304 'utf-16be-mac
1305 'utf-16le-mac)))))
1307 (defun mac-TEXT-to-string (data &optional coding-system)
1308 (or coding-system (setq coding-system mac-system-coding-system))
1309 (prog1 (setq data (decode-coding-string data coding-system))
1310 (when (eq (coding-system-base coding-system) 'japanese-shift-jis)
1311 ;; (subst-char-in-string ?\x5c ?\\e(J\\e(B data t)
1312 (subst-char-in-string ?\x80 ?\\ data t))))
1314 (defun mac-string-to-TEXT (string &optional coding-system)
1315 (or coding-system (setq coding-system mac-system-coding-system))
1316 (let ((encodables (find-coding-systems-string string))
1317 (rest mac-script-code-coding-systems))
1318 (unless (memq (coding-system-base coding-system) encodables)
1319 (while (and rest (not (memq (cdar rest) encodables)))
1320 (setq rest (cdr rest)))
1321 (if rest
1322 (setq coding-system (cdar rest)))))
1323 (setq coding-system
1324 (coding-system-change-eol-conversion coding-system 'mac))
1325 (when (eq coding-system 'japanese-shift-jis-mac)
1326 ;; (setq string (subst-char-in-string ?\\ ?\x80 string))
1327 (setq string (subst-char-in-string ?\\e(J\\e(B ?\x5c string)))
1328 (encode-coding-string string coding-system))
1330 (defun mac-furl-to-string (data)
1331 ;; Remove a trailing nul character.
1332 (let ((len (length data)))
1333 (if (and (> len 0) (= (aref data (1- len)) ?\0))
1334 (substring data 0 (1- len))
1335 data)))
1337 (defun mac-TIFF-to-string (data &optional text)
1338 (prog1 (or text (setq text (copy-sequence " ")))
1339 (put-text-property 0 (length text) 'display (create-image data 'tiff t)
1340 text)))
1342 ;;;; Selections
1344 ;;; We keep track of the last text selected here, so we can check the
1345 ;;; current selection against it, and avoid passing back our own text
1346 ;;; from x-get-selection-value.
1347 (defvar x-last-selected-text-clipboard nil
1348 "The value of the CLIPBOARD selection last time we selected or
1349 pasted text.")
1350 (defvar x-last-selected-text-primary nil
1351 "The value of the PRIMARY X selection last time we selected or
1352 pasted text.")
1354 (defcustom x-select-enable-clipboard t
1355 "*Non-nil means cutting and pasting uses the clipboard.
1356 This is in addition to the primary selection."
1357 :type 'boolean
1358 :group 'killing)
1360 ;;; Make TEXT, a string, the primary X selection.
1361 (defun x-select-text (text &optional push)
1362 (x-set-selection 'PRIMARY text)
1363 (setq x-last-selected-text-primary text)
1364 (if (not x-select-enable-clipboard)
1365 (setq x-last-selected-text-clipboard nil)
1366 (x-set-selection 'CLIPBOARD text)
1367 (setq x-last-selected-text-clipboard text))
1370 (defun x-get-selection (&optional type data-type)
1371 "Return the value of a selection.
1372 The argument TYPE (default `PRIMARY') says which selection,
1373 and the argument DATA-TYPE (default `STRING') says
1374 how to convert the data.
1376 TYPE may be any symbol \(but nil stands for `PRIMARY'). However,
1377 only a few symbols are commonly used. They conventionally have
1378 all upper-case names. The most often used ones, in addition to
1379 `PRIMARY', are `SECONDARY' and `CLIPBOARD'.
1381 DATA-TYPE is usually `STRING', but can also be one of the symbols
1382 in `selection-converter-alist', which see."
1383 (let ((data (x-get-selection-internal (or type 'PRIMARY)
1384 (or data-type 'STRING)))
1385 (coding (or next-selection-coding-system
1386 selection-coding-system)))
1387 (when (and (stringp data)
1388 (setq data-type (get-text-property 0 'foreign-selection data)))
1389 (cond ((eq data-type 'public.utf16-plain-text)
1390 (setq data (mac-utxt-to-string data coding)))
1391 ((eq data-type 'com.apple.traditional-mac-plain-text)
1392 (setq data (mac-TEXT-to-string data coding)))
1393 ((eq data-type 'public.file-url)
1394 (setq data (mac-furl-to-string data))))
1395 (put-text-property 0 (length data) 'foreign-selection data-type data))
1396 data))
1398 (defun x-selection-value (type)
1399 (let ((data-types '(public.utf16-plain-text
1400 com.apple.traditional-mac-plain-text
1401 public.file-url))
1402 text tiff-image)
1403 (while (and (null text) data-types)
1404 (setq text (condition-case nil
1405 (x-get-selection type (car data-types))
1406 (error nil)))
1407 (setq data-types (cdr data-types)))
1408 (if text
1409 (remove-text-properties 0 (length text) '(foreign-selection nil) text))
1410 (setq tiff-image (condition-case nil
1411 (x-get-selection type 'public.tiff)
1412 (error nil)))
1413 (when tiff-image
1414 (remove-text-properties 0 (length tiff-image)
1415 '(foreign-selection nil) tiff-image)
1416 (setq text (mac-TIFF-to-string tiff-image text)))
1417 text))
1419 ;;; Return the value of the current selection.
1420 ;;; Treat empty strings as if they were unset.
1421 ;;; If this function is called twice and finds the same text,
1422 ;;; it returns nil the second time. This is so that a single
1423 ;;; selection won't be added to the kill ring over and over.
1424 (defun x-get-selection-value ()
1425 (let (clip-text primary-text)
1426 (if (not x-select-enable-clipboard)
1427 (setq x-last-selected-text-clipboard nil)
1428 (setq clip-text (x-selection-value 'CLIPBOARD))
1429 (if (string= clip-text "") (setq clip-text nil))
1431 ;; Check the CLIPBOARD selection for 'newness', is it different
1432 ;; from what we remebered them to be last time we did a
1433 ;; cut/paste operation.
1434 (setq clip-text
1435 (cond;; check clipboard
1436 ((or (not clip-text) (string= clip-text ""))
1437 (setq x-last-selected-text-clipboard nil))
1438 ((eq clip-text x-last-selected-text-clipboard) nil)
1439 ((string= clip-text x-last-selected-text-clipboard)
1440 ;; Record the newer string,
1441 ;; so subsequent calls can use the `eq' test.
1442 (setq x-last-selected-text-clipboard clip-text)
1443 nil)
1445 (setq x-last-selected-text-clipboard clip-text))))
1448 (setq primary-text (x-selection-value 'PRIMARY))
1449 ;; Check the PRIMARY selection for 'newness', is it different
1450 ;; from what we remebered them to be last time we did a
1451 ;; cut/paste operation.
1452 (setq primary-text
1453 (cond;; check primary selection
1454 ((or (not primary-text) (string= primary-text ""))
1455 (setq x-last-selected-text-primary nil))
1456 ((eq primary-text x-last-selected-text-primary) nil)
1457 ((string= primary-text x-last-selected-text-primary)
1458 ;; Record the newer string,
1459 ;; so subsequent calls can use the `eq' test.
1460 (setq x-last-selected-text-primary primary-text)
1461 nil)
1463 (setq x-last-selected-text-primary primary-text))))
1465 ;; As we have done one selection, clear this now.
1466 (setq next-selection-coding-system nil)
1468 ;; At this point we have recorded the current values for the
1469 ;; selection from clipboard (if we are supposed to) and primary,
1470 ;; So return the first one that has changed (which is the first
1471 ;; non-null one).
1472 (or clip-text primary-text)
1475 (put 'CLIPBOARD 'mac-scrap-name "com.apple.scrap.clipboard")
1476 (when (eq system-type 'darwin)
1477 (put 'FIND 'mac-scrap-name "com.apple.scrap.find")
1478 (put 'PRIMARY 'mac-scrap-name
1479 (format "org.gnu.Emacs.%d.selection.PRIMARY" (emacs-pid))))
1480 (put 'com.apple.traditional-mac-plain-text 'mac-ostype "TEXT")
1481 (put 'public.utf16-plain-text 'mac-ostype "utxt")
1482 (put 'public.tiff 'mac-ostype "TIFF")
1483 (put 'public.file-url 'mac-ostype "furl")
1485 (defun mac-select-convert-to-string (selection type value)
1486 (let ((str (cdr (xselect-convert-to-string selection nil value)))
1487 (coding (or next-selection-coding-system selection-coding-system)))
1488 (when str
1489 ;; If TYPE is nil, this is a local request, thus return STR as
1490 ;; is. Otherwise, encode STR.
1491 (if (not type)
1493 (let ((inhibit-read-only t))
1494 (remove-text-properties 0 (length str) '(composition nil) str)
1495 (cond
1496 ((eq type 'public.utf16-plain-text)
1497 (setq str (mac-string-to-utxt str coding)))
1498 ((eq type 'com.apple.traditional-mac-plain-text)
1499 (setq str (mac-string-to-TEXT str coding)))
1501 (error "Unknown selection type: %S" type))
1504 (setq next-selection-coding-system nil)
1505 (cons type str))))
1507 (defun mac-select-convert-to-file-url (selection type value)
1508 (let ((filename (xselect-convert-to-filename selection type value))
1509 (coding (or file-name-coding-system default-file-name-coding-system)))
1510 (if (and filename coding)
1511 (setq filename (encode-coding-string filename coding)))
1512 (and filename
1513 (concat "file://localhost"
1514 (mapconcat 'url-hexify-string
1515 (split-string filename "/") "/")))))
1517 (setq selection-converter-alist
1518 (nconc
1519 '((public.utf16-plain-text . mac-select-convert-to-string)
1520 (com.apple.traditional-mac-plain-text . mac-select-convert-to-string)
1521 ;; This is not enabled by default because the `Import Image'
1522 ;; menu makes Emacs crash or hang for unknown reasons.
1523 ;; (public.tiff . nil)
1524 (public.file-url . mac-select-convert-to-file-url)
1526 selection-converter-alist))
1528 ;;;; Apple events, HICommand events, and Services menu
1530 ;;; Event classes
1531 (put 'core-event 'mac-apple-event-class "aevt") ; kCoreEventClass
1532 (put 'internet-event 'mac-apple-event-class "GURL") ; kAEInternetEventClass
1534 ;;; Event IDs
1535 ;; kCoreEventClass
1536 (put 'open-application 'mac-apple-event-id "oapp") ; kAEOpenApplication
1537 (put 'reopen-application 'mac-apple-event-id "rapp") ; kAEReopenApplication
1538 (put 'open-documents 'mac-apple-event-id "odoc") ; kAEOpenDocuments
1539 (put 'print-documents 'mac-apple-event-id "pdoc") ; kAEPrintDocuments
1540 (put 'open-contents 'mac-apple-event-id "ocon") ; kAEOpenContents
1541 (put 'quit-application 'mac-apple-event-id "quit") ; kAEQuitApplication
1542 (put 'application-died 'mac-apple-event-id "obit") ; kAEApplicationDied
1543 (put 'show-preferences 'mac-apple-event-id "pref") ; kAEShowPreferences
1544 (put 'autosave-now 'mac-apple-event-id "asav") ; kAEAutosaveNow
1545 ;; kAEInternetEventClass
1546 (put 'get-url 'mac-apple-event-id "GURL") ; kAEGetURL
1547 ;; Converted HI command events
1548 (put 'about 'mac-apple-event-id "abou") ; kHICommandAbout
1549 (put 'show-hide-font-panel 'mac-apple-event-id "shfp") ; kHICommandShowHideFontPanel
1551 (defmacro mac-event-spec (event)
1552 `(nth 1 ,event))
1554 (defmacro mac-event-ae (event)
1555 `(nth 2 ,event))
1557 (defun mac-ae-parameter (ae &optional keyword type)
1558 (or keyword (setq keyword "----")) ;; Direct object.
1559 (if (not (and (consp ae) (equal (car ae) "aevt")))
1560 (error "Not an Apple event: %S" ae)
1561 (let ((type-data (cdr (assoc keyword (cdr ae))))
1562 data)
1563 (when (and type type-data (not (equal type (car type-data))))
1564 (setq data (mac-coerce-ae-data (car type-data) (cdr type-data) type))
1565 (setq type-data (if data (cons type data) nil)))
1566 type-data)))
1568 (defun mac-ae-list (ae &optional keyword type)
1569 (or keyword (setq keyword "----")) ;; Direct object.
1570 (let ((desc (mac-ae-parameter ae keyword "list")))
1571 (cond ((null desc)
1572 nil)
1573 ((not (equal (car desc) "list"))
1574 (error "Parameter for \"%s\" is not a list" keyword))
1576 (if (null type)
1577 (cdr desc)
1578 (mapcar
1579 (lambda (type-data)
1580 (mac-coerce-ae-data (car type-data) (cdr type-data) type))
1581 (cdr desc)))))))
1583 (defun mac-ae-number (ae keyword)
1584 (let ((type-data (mac-ae-parameter ae keyword))
1585 str)
1586 (if (and type-data
1587 (setq str (mac-coerce-ae-data (car type-data)
1588 (cdr type-data) "TEXT")))
1589 (string-to-number str)
1590 nil)))
1592 (defun mac-bytes-to-integer (bytes &optional from to)
1593 (or from (setq from 0))
1594 (or to (setq to (length bytes)))
1595 (let* ((len (- to from))
1596 (extended-sign-len (- (1+ (ceiling (log most-positive-fixnum 2)))
1597 (* 8 len)))
1598 (result 0))
1599 (dotimes (i len)
1600 (setq result (logior (lsh result 8)
1601 (aref bytes (+ from (if (eq (byteorder) ?B) i
1602 (- len i 1)))))))
1603 (if (> extended-sign-len 0)
1604 (ash (lsh result extended-sign-len) (- extended-sign-len))
1605 result)))
1607 (defun mac-ae-selection-range (ae)
1608 ;; #pragma options align=mac68k
1609 ;; typedef struct SelectionRange {
1610 ;; short unused1; // 0 (not used)
1611 ;; short lineNum; // line to select (<0 to specify range)
1612 ;; long startRange; // start of selection range (if line < 0)
1613 ;; long endRange; // end of selection range (if line < 0)
1614 ;; long unused2; // 0 (not used)
1615 ;; long theDate; // modification date/time
1616 ;; } SelectionRange;
1617 ;; #pragma options align=reset
1618 (let ((range-bytes (cdr (mac-ae-parameter ae "kpos" "TEXT"))))
1619 (and range-bytes
1620 (list (mac-bytes-to-integer range-bytes 2 4)
1621 (mac-bytes-to-integer range-bytes 4 8)
1622 (mac-bytes-to-integer range-bytes 8 12)
1623 (mac-bytes-to-integer range-bytes 16 20)))))
1625 ;; On Mac OS X 10.4 and later, the `open-document' event contains an
1626 ;; optional parameter keyAESearchText from the Spotlight search.
1627 (defun mac-ae-text-for-search (ae)
1628 (let ((utf8-text (cdr (mac-ae-parameter ae "stxt" "utf8"))))
1629 (and utf8-text
1630 (decode-coding-string utf8-text 'utf-8))))
1632 (defun mac-ae-text (ae)
1633 (or (cdr (mac-ae-parameter ae nil "TEXT"))
1634 (error "No text in Apple event.")))
1636 (defun mac-ae-frame (ae &optional keyword type)
1637 (let ((bytes (cdr (mac-ae-parameter ae keyword type))))
1638 (if (or (null bytes) (/= (length bytes) 4))
1639 (error "No window reference in Apple event.")
1640 (let ((window-id (mac-coerce-ae-data "long" bytes "TEXT"))
1641 (rest (frame-list))
1642 frame)
1643 (while (and (null frame) rest)
1644 (if (string= (frame-parameter (car rest) 'window-id) window-id)
1645 (setq frame (car rest)))
1646 (setq rest (cdr rest)))
1647 frame))))
1649 (defun mac-ae-script-language (ae keyword)
1650 ;; struct WritingCode {
1651 ;; ScriptCode theScriptCode;
1652 ;; LangCode theLangCode;
1653 ;; };
1654 (let ((bytes (cdr (mac-ae-parameter ae keyword "intl"))))
1655 (and bytes
1656 (cons (mac-bytes-to-integer bytes 0 2)
1657 (mac-bytes-to-integer bytes 2 4)))))
1659 (defun mac-bytes-to-text-range (bytes &optional from to)
1660 ;; struct TextRange {
1661 ;; long fStart;
1662 ;; long fEnd;
1663 ;; short fHiliteStyle;
1664 ;; };
1665 (or from (setq from 0))
1666 (or to (setq to (length bytes)))
1667 (and (= (- to from) (+ 4 4 2))
1668 (list (mac-bytes-to-integer bytes from (+ from 4))
1669 (mac-bytes-to-integer bytes (+ from 4) (+ from 8))
1670 (mac-bytes-to-integer bytes (+ from 8) to))))
1672 (defun mac-ae-text-range-array (ae keyword)
1673 ;; struct TextRangeArray {
1674 ;; short fNumOfRanges;
1675 ;; TextRange fRange[1];
1676 ;; };
1677 (let* ((bytes (cdr (mac-ae-parameter ae keyword "tray")))
1678 (len (length bytes))
1679 nranges result)
1680 (when (and bytes (>= len 2)
1681 (progn
1682 (setq nranges (mac-bytes-to-integer bytes 0 2))
1683 (= len (+ 2 (* nranges 10)))))
1684 (setq result (make-vector nranges nil))
1685 (dotimes (i nranges)
1686 (aset result i
1687 (mac-bytes-to-text-range bytes (+ (* i 10) 2)
1688 (+ (* i 10) 12)))))
1689 result))
1691 (defun mac-ae-open-documents (event)
1692 "Open the documents specified by the Apple event EVENT."
1693 (interactive "e")
1694 (let ((ae (mac-event-ae event)))
1695 (dolist (file-name (mac-ae-list ae nil 'undecoded-file-name))
1696 (if file-name
1697 (dnd-open-local-file
1698 (concat "file://"
1699 (mapconcat 'url-hexify-string
1700 (split-string file-name "/") "/")) nil)))
1701 (let ((selection-range (mac-ae-selection-range ae))
1702 (search-text (mac-ae-text-for-search ae)))
1703 (cond (selection-range
1704 (let ((line (car selection-range))
1705 (start (cadr selection-range))
1706 (end (nth 2 selection-range)))
1707 (if (> line 0)
1708 (goto-line line)
1709 (if (and (> start 0) (> end 0))
1710 (progn (set-mark start)
1711 (goto-char end))))))
1712 ((stringp search-text)
1713 (re-search-forward
1714 (mapconcat 'regexp-quote (split-string search-text) "\\|")
1715 nil t)))))
1716 (select-frame-set-input-focus (selected-frame)))
1718 (defun mac-ae-get-url (event)
1719 "Open the URL specified by the Apple event EVENT.
1720 Currently the `mailto' scheme is supported."
1721 (interactive "e")
1722 (let* ((ae (mac-event-ae event))
1723 (parsed-url (url-generic-parse-url (mac-ae-text ae))))
1724 (if (string= (url-type parsed-url) "mailto")
1725 (url-mailto parsed-url)
1726 (mac-resume-apple-event ae t))))
1728 (setq mac-apple-event-map (make-sparse-keymap))
1730 ;; Received when Emacs is launched without associated documents.
1731 ;; Accept it as an Apple event, but no Emacs event is generated so as
1732 ;; not to erase the splash screen.
1733 (define-key mac-apple-event-map [core-event open-application] 0)
1735 ;; Received when a dock or application icon is clicked and Emacs is
1736 ;; already running. Simply ignored. Another idea is to make a new
1737 ;; frame if all frames are invisible.
1738 (define-key mac-apple-event-map [core-event reopen-application] 'ignore)
1740 (define-key mac-apple-event-map [core-event open-documents]
1741 'mac-ae-open-documents)
1742 (define-key mac-apple-event-map [core-event show-preferences] 'customize)
1743 (define-key mac-apple-event-map [core-event quit-application]
1744 'save-buffers-kill-emacs)
1746 (define-key mac-apple-event-map [internet-event get-url] 'mac-ae-get-url)
1748 (define-key mac-apple-event-map [hi-command about] 'display-splash-screen)
1750 ;;; Converted Carbon Events
1751 (defun mac-handle-toolbar-switch-mode (event)
1752 "Toggle visibility of tool-bars in response to EVENT.
1753 With no keyboard modifiers, it toggles the visibility of the
1754 frame where the tool-bar toggle button was pressed. With some
1755 modifiers, it changes global tool-bar visibility setting."
1756 (interactive "e")
1757 (let* ((ae (mac-event-ae event))
1758 (modifiers (cdr (mac-ae-parameter ae "kmod"))))
1759 (if (and modifiers (not (string= modifiers "\000\000\000\000")))
1760 ;; Globally toggle tool-bar-mode if some modifier key is pressed.
1761 (tool-bar-mode)
1762 (let ((frame (mac-ae-frame ae)))
1763 (set-frame-parameter frame 'tool-bar-lines
1764 (if (= (frame-parameter frame 'tool-bar-lines) 0)
1765 1 0))))))
1767 ;; kEventClassWindow/kEventWindowToolbarSwitchMode
1768 (define-key mac-apple-event-map [window toolbar-switch-mode]
1769 'mac-handle-toolbar-switch-mode)
1771 ;;; Font panel
1772 (when (fboundp 'mac-set-font-panel-visibility)
1774 (define-minor-mode mac-font-panel-mode
1775 "Toggle use of the font panel.
1776 With numeric ARG, display the font panel if and only if ARG is positive."
1777 :init-value nil
1778 :global t
1779 :group 'mac
1780 (mac-set-font-panel-visibility mac-font-panel-mode))
1782 (defun mac-handle-font-panel-closed (event)
1783 "Update internal status in response to font panel closed EVENT."
1784 (interactive "e")
1785 ;; Synchronize with the minor mode variable.
1786 (mac-font-panel-mode 0))
1788 (defun mac-handle-font-selection (event)
1789 "Change default face attributes according to font selection EVENT."
1790 (interactive "e")
1791 (let* ((ae (mac-event-ae event))
1792 (fm-font-size (mac-ae-number ae "fmsz"))
1793 (atsu-font-id (mac-ae-number ae "auid"))
1794 (attribute-values (gethash atsu-font-id mac-atsu-font-table)))
1795 (if fm-font-size
1796 (setq attribute-values
1797 `(:height ,(* 10 fm-font-size) ,@attribute-values)))
1798 (apply 'set-face-attribute 'default (selected-frame) attribute-values)))
1800 ;; kEventClassFont/kEventFontPanelClosed
1801 (define-key mac-apple-event-map [font panel-closed]
1802 'mac-handle-font-panel-closed)
1803 ;; kEventClassFont/kEventFontSelection
1804 (define-key mac-apple-event-map [font selection] 'mac-handle-font-selection)
1805 (define-key mac-apple-event-map [hi-command show-hide-font-panel]
1806 'mac-font-panel-mode)
1808 (define-key-after menu-bar-showhide-menu [mac-font-panel-mode]
1809 (menu-bar-make-mm-toggle mac-font-panel-mode
1810 "Font Panel"
1811 "Show the font panel as a floating dialog")
1812 'showhide-speedbar)
1814 ) ;; (fboundp 'mac-set-font-panel-visibility)
1816 ;;; Text Services
1817 (defvar mac-ts-active-input-buf ""
1818 "Byte sequence of the current Mac TSM active input area.")
1819 (defvar mac-ts-update-active-input-area-seqno 0
1820 "Number of processed update-active-input-area events.")
1821 (setq mac-ts-active-input-overlay (make-overlay 0 0))
1823 (defface mac-ts-caret-position
1824 '((t :inverse-video t))
1825 "Face for caret position in Mac TSM active input area.
1826 This is used when the active input area is displayed either in
1827 the echo area or in a buffer where the cursor is not displayed."
1828 :group 'mac)
1830 (defface mac-ts-raw-text
1831 '((t :underline t))
1832 "Face for raw text in Mac TSM active input area."
1833 :group 'mac)
1835 (defface mac-ts-selected-raw-text
1836 '((t :underline t))
1837 "Face for selected raw text in Mac TSM active input area."
1838 :group 'mac)
1840 (defface mac-ts-converted-text
1841 '((((background dark)) :underline "gray20")
1842 (t :underline "gray80"))
1843 "Face for converted text in Mac TSM active input area."
1844 :group 'mac)
1846 (defface mac-ts-selected-converted-text
1847 '((t :underline t))
1848 "Face for selected converted text in Mac TSM active input area."
1849 :group 'mac)
1851 (defface mac-ts-block-fill-text
1852 '((t :underline t))
1853 "Face for block fill text in Mac TSM active input area."
1854 :group 'mac)
1856 (defface mac-ts-outline-text
1857 '((t :underline t))
1858 "Face for outline text in Mac TSM active input area."
1859 :group 'mac)
1861 (defface mac-ts-selected-text
1862 '((t :underline t))
1863 "Face for selected text in Mac TSM active input area."
1864 :group 'mac)
1866 (defface mac-ts-no-hilite
1867 '((t :inherit default))
1868 "Face for no hilite in Mac TSM active input area."
1869 :group 'mac)
1871 (defconst mac-ts-hilite-style-faces
1872 '((2 . mac-ts-raw-text) ; kTSMHiliteRawText
1873 (3 . mac-ts-selected-raw-text) ; kTSMHiliteSelectedRawText
1874 (4 . mac-ts-converted-text) ; kTSMHiliteConvertedText
1875 (5 . mac-ts-selected-converted-text) ; kTSMHiliteSelectedConvertedText
1876 (6 . mac-ts-block-fill-text) ; kTSMHiliteBlockFillText
1877 (7 . mac-ts-outline-text) ; kTSMHiliteOutlineText
1878 (8 . mac-ts-selected-text) ; kTSMHiliteSelectedText
1879 (9 . mac-ts-no-hilite)) ; kTSMHiliteNoHilite
1880 "Alist of Mac TSM hilite style vs Emacs face.")
1882 (defun mac-ts-update-active-input-buf (text fix-len hilite-rng update-rng)
1883 (let ((buf-len (length mac-ts-active-input-buf))
1884 confirmed)
1885 (if (or (null update-rng)
1886 (/= (% (length update-rng) 2) 0))
1887 ;; The parameter is missing (or in a bad format). The
1888 ;; existing inline input session is completely replaced with
1889 ;; the new text.
1890 (setq mac-ts-active-input-buf text)
1891 ;; Otherwise, the current subtext specified by the (2*j)-th
1892 ;; range is replaced with the new subtext specified by the
1893 ;; (2*j+1)-th range.
1894 (let ((tail buf-len)
1895 (i (length update-rng))
1896 segments rng)
1897 (while (> i 0)
1898 (setq i (- i 2))
1899 (setq rng (aref update-rng i))
1900 (if (and (<= 0 (cadr rng)) (< (cadr rng) tail)
1901 (<= tail buf-len))
1902 (setq segments
1903 (cons (substring mac-ts-active-input-buf (cadr rng) tail)
1904 segments)))
1905 (setq tail (car rng))
1906 (setq rng (aref update-rng (1+ i)))
1907 (if (and (<= 0 (car rng)) (< (car rng) (cadr rng))
1908 (<= (cadr rng) (length text)))
1909 (setq segments
1910 (cons (substring text (car rng) (cadr rng))
1911 segments))))
1912 (if (and (< 0 tail) (<= tail buf-len))
1913 (setq segments
1914 (cons (substring mac-ts-active-input-buf 0 tail)
1915 segments)))
1916 (setq mac-ts-active-input-buf (apply 'concat segments))))
1917 (setq buf-len (length mac-ts-active-input-buf))
1918 ;; Confirm (a part of) inline input session.
1919 (cond ((< fix-len 0)
1920 ;; Entire inline session is being confirmed.
1921 (setq confirmed mac-ts-active-input-buf)
1922 (setq mac-ts-active-input-buf ""))
1923 ((= fix-len 0)
1924 ;; None of the text is being confirmed (yet).
1925 (setq confirmed ""))
1927 (if (> fix-len buf-len)
1928 (setq fix-len buf-len))
1929 (setq confirmed (substring mac-ts-active-input-buf 0 fix-len))
1930 (setq mac-ts-active-input-buf
1931 (substring mac-ts-active-input-buf fix-len))))
1932 (setq buf-len (length mac-ts-active-input-buf))
1933 ;; Update highlighting and the caret position in the new inline
1934 ;; input session.
1935 (remove-text-properties 0 buf-len '(cursor nil) mac-ts-active-input-buf)
1936 (mapc (lambda (rng)
1937 (cond ((and (= (nth 2 rng) 1) ; kTSMHiliteCaretPosition
1938 (<= 0 (car rng)) (< (car rng) buf-len))
1939 (put-text-property (car rng) buf-len
1940 'cursor t mac-ts-active-input-buf))
1941 ((and (<= 0 (car rng)) (< (car rng) (cadr rng))
1942 (<= (cadr rng) buf-len))
1943 (put-text-property (car rng) (cadr rng) 'face
1944 (cdr (assq (nth 2 rng)
1945 mac-ts-hilite-style-faces))
1946 mac-ts-active-input-buf))))
1947 hilite-rng)
1948 confirmed))
1950 (defun mac-split-string-by-property-change (string)
1951 (let ((tail (length string))
1952 head result)
1953 (unless (= tail 0)
1954 (while (setq head (previous-property-change tail string)
1955 result (cons (substring string (or head 0) tail) result)
1956 tail head)))
1957 result))
1959 (defun mac-replace-untranslated-utf-8-chars (string &optional to-string)
1960 (or to-string (setq to-string "\e$,3u=\e(B"))
1961 (mapconcat
1962 (lambda (str)
1963 (if (get-text-property 0 'untranslated-utf-8 str) to-string str))
1964 (mac-split-string-by-property-change string)
1965 ""))
1967 (defun mac-ts-update-active-input-area (event)
1968 "Update Mac TSM active input area according to EVENT.
1969 The confirmed text is converted to Emacs input events and pushed
1970 into `unread-command-events'. The unconfirmed text is displayed
1971 either in the current buffer or in the echo area."
1972 (interactive "e")
1973 (let* ((ae (mac-event-ae event))
1974 (type-text (mac-ae-parameter ae "tstx"))
1975 (text (or (cdr type-text) ""))
1976 (decode-fun (if (equal (car type-text) "TEXT")
1977 'mac-TEXT-to-string 'mac-utxt-to-string))
1978 (script-language (mac-ae-script-language ae "tssl"))
1979 (coding (or (cdr (assq (car script-language)
1980 mac-script-code-coding-systems))
1981 'mac-roman))
1982 (fix-len (mac-ae-number ae "tsfx"))
1983 ;; Optional parameters
1984 (hilite-rng (mac-ae-text-range-array ae "tshi"))
1985 (update-rng (mac-ae-text-range-array ae "tsup"))
1986 ;;(pin-rng (mac-bytes-to-text-range (cdr (mac-ae-parameter ae "tspn" "txrn"))))
1987 ;;(clause-offsets (cdr (mac-ae-parameter ae "tscl" "ofay")))
1988 (seqno (mac-ae-number ae "tsSn"))
1989 confirmed)
1990 (unless (= seqno mac-ts-update-active-input-area-seqno)
1991 ;; Reset internal states if sequence number is out of sync.
1992 (setq mac-ts-active-input-buf ""))
1993 (setq confirmed
1994 (mac-ts-update-active-input-buf text fix-len hilite-rng update-rng))
1995 (let ((use-echo-area
1996 (or isearch-mode
1997 (and cursor-in-echo-area (current-message))
1998 ;; Overlay strings are not shown in some cases.
1999 (get-char-property (point) 'invisible)
2000 (and (not (bobp))
2001 (or (and (get-char-property (point) 'display)
2002 (eq (get-char-property (1- (point)) 'display)
2003 (get-char-property (point) 'display)))
2004 (and (get-char-property (point) 'composition)
2005 (eq (get-char-property (1- (point)) 'composition)
2006 (get-char-property (point) 'composition)))))))
2007 active-input-string caret-seen)
2008 ;; Decode the active input area text with inheriting faces and
2009 ;; the caret position.
2010 (setq active-input-string
2011 (mapconcat
2012 (lambda (str)
2013 (let ((decoded (funcall decode-fun str coding)))
2014 (put-text-property 0 (length decoded) 'face
2015 (get-text-property 0 'face str) decoded)
2016 (when (and (not caret-seen)
2017 (get-text-property 0 'cursor str))
2018 (setq caret-seen t)
2019 (if (or use-echo-area (null cursor-type))
2020 (put-text-property 0 1 'face 'mac-ts-caret-position
2021 decoded)
2022 (put-text-property 0 1 'cursor t decoded)))
2023 decoded))
2024 (mac-split-string-by-property-change mac-ts-active-input-buf)
2025 ""))
2026 (put-text-property 0 (length active-input-string)
2027 'mac-ts-active-input-string t active-input-string)
2028 (if use-echo-area
2029 (let ((msg (current-message))
2030 message-log-max)
2031 (if (and msg
2032 ;; Don't get confused by previously displayed
2033 ;; `active-input-string'.
2034 (null (get-text-property 0 'mac-ts-active-input-string
2035 msg)))
2036 (setq msg (propertize msg 'display
2037 (concat msg active-input-string)))
2038 (setq msg active-input-string))
2039 (message "%s" msg)
2040 (overlay-put mac-ts-active-input-overlay 'before-string nil))
2041 (move-overlay mac-ts-active-input-overlay
2042 (point) (point) (current-buffer))
2043 (overlay-put mac-ts-active-input-overlay 'before-string
2044 active-input-string))
2045 ;; Unread confirmed characters and insert them in a keyboard
2046 ;; macro being defined.
2047 (apply 'isearch-unread
2048 (append (mac-replace-untranslated-utf-8-chars
2049 (funcall decode-fun confirmed coding)) '())))
2050 ;; The event is successfully processed. Sync the sequence number.
2051 (setq mac-ts-update-active-input-area-seqno (1+ seqno))))
2053 (defun mac-ts-unicode-for-key-event (event)
2054 "Convert Unicode key EVENT to Emacs key events and unread them."
2055 (interactive "e")
2056 (let* ((ae (mac-event-ae event))
2057 (text (cdr (mac-ae-parameter ae "tstx" "utxt")))
2058 (script-language (mac-ae-script-language ae "tssl"))
2059 (coding (or (cdr (assq (car script-language)
2060 mac-script-code-coding-systems))
2061 'mac-roman)))
2062 ;; Unread characters and insert them in a keyboard macro being
2063 ;; defined.
2064 (apply 'isearch-unread
2065 (append (mac-replace-untranslated-utf-8-chars
2066 (mac-utxt-to-string text coding)) '()))))
2068 ;; kEventClassTextInput/kEventTextInputUpdateActiveInputArea
2069 (define-key mac-apple-event-map [text-input update-active-input-area]
2070 'mac-ts-update-active-input-area)
2071 ;; kEventClassTextInput/kEventTextInputUnicodeForKeyEvent
2072 (define-key mac-apple-event-map [text-input unicode-for-key-event]
2073 'mac-ts-unicode-for-key-event)
2075 ;;; Services
2076 (defun mac-service-open-file ()
2077 "Open the file specified by the selection value for Services."
2078 (interactive)
2079 (find-file-existing (x-selection-value mac-service-selection)))
2081 (defun mac-service-open-selection ()
2082 "Create a new buffer containing the selection value for Services."
2083 (interactive)
2084 (switch-to-buffer (generate-new-buffer "*untitled*"))
2085 (insert (x-selection-value mac-service-selection))
2086 (sit-for 0)
2087 (save-buffer) ; It pops up the save dialog.
2090 (defun mac-service-mail-selection ()
2091 "Prepare a mail buffer containing the selection value for Services."
2092 (interactive)
2093 (compose-mail)
2094 (rfc822-goto-eoh)
2095 (forward-line 1)
2096 (insert (x-selection-value mac-service-selection) "\n"))
2098 (defun mac-service-mail-to ()
2099 "Prepare a mail buffer to be sent to the selection value for Services."
2100 (interactive)
2101 (compose-mail (x-selection-value mac-service-selection)))
2103 (defun mac-service-insert-text ()
2104 "Insert the selection value for Services."
2105 (interactive)
2106 (let ((text (x-selection-value mac-service-selection)))
2107 (if (not buffer-read-only)
2108 (insert text)
2109 (kill-new text)
2110 (message
2111 (substitute-command-keys
2112 "The text from the Services menu can be accessed with \\[yank]")))))
2114 ;; kEventClassService/kEventServicePaste
2115 (define-key mac-apple-event-map [service paste] 'mac-service-insert-text)
2116 ;; kEventClassService/kEventServicePerform
2117 (define-key mac-apple-event-map [service perform open-file]
2118 'mac-service-open-file)
2119 (define-key mac-apple-event-map [service perform open-selection]
2120 'mac-service-open-selection)
2121 (define-key mac-apple-event-map [service perform mail-selection]
2122 'mac-service-mail-selection)
2123 (define-key mac-apple-event-map [service perform mail-to]
2124 'mac-service-mail-to)
2126 (defun mac-dispatch-apple-event (event)
2127 "Dispatch EVENT according to the keymap `mac-apple-event-map'."
2128 (interactive "e")
2129 (let* ((binding (lookup-key mac-apple-event-map (mac-event-spec event)))
2130 (ae (mac-event-ae event))
2131 (service-message (and (keymapp binding)
2132 (cdr (mac-ae-parameter ae "svmg")))))
2133 (when service-message
2134 (setq service-message
2135 (intern (decode-coding-string service-message 'utf-8)))
2136 (setq binding (lookup-key binding (vector service-message))))
2137 ;; Replace (cadr event) with a dummy position so that event-start
2138 ;; returns it.
2139 (setcar (cdr event) (list (selected-window) (point) '(0 . 0) 0))
2140 (if (null (mac-ae-parameter ae 'emacs-suspension-id))
2141 (command-execute binding nil (vector event) t)
2142 (condition-case err
2143 (progn
2144 (command-execute binding nil (vector event) t)
2145 (mac-resume-apple-event ae))
2146 (error
2147 (mac-ae-set-reply-parameter ae "errs"
2148 (cons "TEXT" (error-message-string err)))
2149 (mac-resume-apple-event ae -10000)))))) ; errAEEventFailed
2151 (define-key special-event-map [mac-apple-event] 'mac-dispatch-apple-event)
2153 ;; Processing of Apple events are deferred at the startup time. For
2154 ;; example, files dropped onto the Emacs application icon can only be
2155 ;; processed when the initial frame has been created: this is where
2156 ;; the files should be opened.
2157 (add-hook 'after-init-hook 'mac-process-deferred-apple-events)
2159 (run-with-idle-timer 5 t 'mac-cleanup-expired-apple-events)
2162 ;;;; Drag and drop
2164 (defcustom mac-dnd-types-alist
2165 '(("furl" . mac-dnd-handle-furl)
2166 ("hfs " . mac-dnd-handle-hfs)
2167 ("utxt" . mac-dnd-insert-utxt)
2168 ("TEXT" . mac-dnd-insert-TEXT)
2169 ("TIFF" . mac-dnd-insert-TIFF))
2170 "Which function to call to handle a drop of that type.
2171 The function takes three arguments, WINDOW, ACTION and DATA.
2172 WINDOW is where the drop occured, ACTION is always `private' on
2173 Mac. DATA is the drop data. Unlike the x-dnd counterpart, the
2174 return value of the function is not significant.
2176 See also `mac-dnd-known-types'."
2177 :version "22.1"
2178 :type 'alist
2179 :group 'mac)
2181 (defun mac-dnd-handle-furl (window action data)
2182 (dnd-handle-one-url window action (mac-furl-to-string data)))
2184 (defun mac-dnd-handle-hfs (window action data)
2185 ;; struct HFSFlavor {
2186 ;; OSType fileType;
2187 ;; OSType fileCreator;
2188 ;; UInt16 fdFlags;
2189 ;; FSSpec fileSpec;
2190 ;; };
2191 (let* ((file-name (mac-coerce-ae-data "fss " (substring data 10)
2192 'undecoded-file-name))
2193 (url (concat "file://"
2194 (mapconcat 'url-hexify-string
2195 (split-string file-name "/") "/"))))
2196 (dnd-handle-one-url window action url)))
2198 (defun mac-dnd-insert-utxt (window action data)
2199 (dnd-insert-text window action (mac-utxt-to-string data)))
2201 (defun mac-dnd-insert-TEXT (window action data)
2202 (dnd-insert-text window action (mac-TEXT-to-string data)))
2204 (defun mac-dnd-insert-TIFF (window action data)
2205 (dnd-insert-text window action (mac-TIFF-to-string data)))
2207 (defun mac-dnd-drop-data (event frame window data type)
2208 (let* ((type-info (assoc type mac-dnd-types-alist))
2209 (handler (cdr type-info))
2210 (action 'private)
2211 (w (posn-window (event-start event))))
2212 (when handler
2213 (if (and (windowp w) (window-live-p w)
2214 (not (window-minibuffer-p w))
2215 (not (window-dedicated-p w)))
2216 ;; If dropping in an ordinary window which we could use,
2217 ;; let dnd-open-file-other-window specify what to do.
2218 (progn
2219 (when (not mouse-yank-at-point)
2220 (goto-char (posn-point (event-start event))))
2221 (funcall handler window action data))
2222 ;; If we can't display the file here,
2223 ;; make a new window for it.
2224 (let ((dnd-open-file-other-window t))
2225 (select-frame frame)
2226 (funcall handler window action data))))))
2228 (defun mac-dnd-handle-drag-n-drop-event (event)
2229 "Receive drag and drop events."
2230 (interactive "e")
2231 (let ((window (posn-window (event-start event))))
2232 (when (windowp window) (select-window window))
2233 (dolist (item (mac-ae-list (mac-event-ae event)))
2234 (if (not (equal (car item) "null"))
2235 (mac-dnd-drop-data event (selected-frame) window
2236 (cdr item) (car item)))))
2237 (select-frame-set-input-focus (selected-frame)))
2239 ;;; Do the actual Windows setup here; the above code just defines
2240 ;;; functions and variables that we use now.
2242 (setq command-line-args (x-handle-args command-line-args))
2244 ;;; Make sure we have a valid resource name.
2245 (or (stringp x-resource-name)
2246 (let (i)
2247 (setq x-resource-name (invocation-name))
2249 ;; Change any . or * characters in x-resource-name to hyphens,
2250 ;; so as not to choke when we use it in X resource queries.
2251 (while (setq i (string-match "[.*]" x-resource-name))
2252 (aset x-resource-name i ?-))))
2254 (if (x-display-list)
2255 ;; On Mac OS 8/9, Most coding systems used in code conversion for
2256 ;; font names are not ready at the time when the terminal frame is
2257 ;; created. So we reconstruct font name table for the initial
2258 ;; frame.
2259 (mac-clear-font-name-table)
2260 (x-open-connection "Mac"
2261 x-command-line-resources
2262 ;; Exit Emacs with fatal error if this fails.
2265 (setq frame-creation-function 'x-create-frame-with-faces)
2267 (defvar mac-font-encoder-list
2268 '(("mac-roman" mac-roman-encoder
2269 ccl-encode-mac-roman-font "%s")
2270 ("mac-centraleurroman" encode-mac-centraleurroman
2271 ccl-encode-mac-centraleurroman-font "%s ce")
2272 ("mac-cyrillic" encode-mac-cyrillic
2273 ccl-encode-mac-cyrillic-font "%s cy")
2274 ("mac-symbol" mac-symbol-encoder
2275 ccl-encode-mac-symbol-font "symbol")
2276 ("mac-dingbats" mac-dingbats-encoder
2277 ccl-encode-mac-dingbats-font "zapf dingbats")))
2279 (let ((encoder-list
2280 (mapcar (lambda (lst) (nth 1 lst)) mac-font-encoder-list))
2281 (charset-list
2282 '(latin-iso8859-2
2283 latin-iso8859-3 latin-iso8859-4
2284 cyrillic-iso8859-5 greek-iso8859-7 hebrew-iso8859-8
2285 latin-iso8859-9 latin-iso8859-14 latin-iso8859-15)))
2286 (dolist (encoder encoder-list)
2287 (let ((table (get encoder 'translation-table)))
2288 (dolist (charset charset-list)
2289 (dotimes (i 96)
2290 (let* ((c (make-char charset (+ i 32)))
2291 (mu (aref ucs-mule-to-mule-unicode c))
2292 (mac-encoded (and mu (aref table mu))))
2293 (if mac-encoded
2294 (aset table c mac-encoded))))))))
2296 ;; We assume none of official dim2 charsets (0x90..0x99) are encoded
2297 ;; to these fonts.
2299 (define-ccl-program ccl-encode-mac-roman-font
2301 (if (r0 <= ?\xef)
2302 (translate-character mac-roman-encoder r0 r1)
2303 ((r1 <<= 7)
2304 (r1 |= r2)
2305 (translate-character mac-roman-encoder r0 r1))))
2306 "CCL program for Mac Roman font")
2308 (define-ccl-program ccl-encode-mac-centraleurroman-font
2310 (if (r0 <= ?\xef)
2311 (translate-character encode-mac-centraleurroman r0 r1)
2312 ((r1 <<= 7)
2313 (r1 |= r2)
2314 (translate-character encode-mac-centraleurroman r0 r1))))
2315 "CCL program for Mac Central European Roman font")
2317 (define-ccl-program ccl-encode-mac-cyrillic-font
2319 (if (r0 <= ?\xef)
2320 (translate-character encode-mac-cyrillic r0 r1)
2321 ((r1 <<= 7)
2322 (r1 |= r2)
2323 (translate-character encode-mac-cyrillic r0 r1))))
2324 "CCL program for Mac Cyrillic font")
2326 (define-ccl-program ccl-encode-mac-symbol-font
2328 (if (r0 <= ?\xef)
2329 (translate-character mac-symbol-encoder r0 r1)
2330 ((r1 <<= 7)
2331 (r1 |= r2)
2332 (translate-character mac-symbol-encoder r0 r1))))
2333 "CCL program for Mac Symbol font")
2335 (define-ccl-program ccl-encode-mac-dingbats-font
2337 (if (r0 <= ?\xef)
2338 (translate-character mac-dingbats-encoder r0 r1)
2339 ((r1 <<= 7)
2340 (r1 |= r2)
2341 (translate-character mac-dingbats-encoder r0 r1))))
2342 "CCL program for Mac Dingbats font")
2345 (setq font-ccl-encoder-alist
2346 (nconc
2347 (mapcar (lambda (lst) (cons (nth 0 lst) (nth 2 lst)))
2348 mac-font-encoder-list)
2349 font-ccl-encoder-alist))
2351 (defconst mac-char-fontspec-list
2352 ;; Directly operate on a char-table instead of a fontset so that it
2353 ;; may not create a dummy fontset.
2354 (let ((template (make-char-table 'fontset)))
2355 (dolist
2356 (font-encoder
2357 (nreverse
2358 (mapcar (lambda (lst)
2359 (cons (cons (nth 3 lst) (nth 0 lst)) (nth 1 lst)))
2360 mac-font-encoder-list)))
2361 (let ((font (car font-encoder))
2362 (encoder (cdr font-encoder)))
2363 (map-char-table
2364 (lambda (key val)
2365 (or (null val)
2366 (generic-char-p key)
2367 (memq (char-charset key)
2368 '(ascii eight-bit-control eight-bit-graphic))
2369 (aset template key font)))
2370 (get encoder 'translation-table))))
2372 ;; Like fontset-info, but extend a range only if its "to" part is
2373 ;; the predecessor of the current char.
2374 (let* ((last '((0 nil)))
2375 (accumulator last)
2376 last-char-or-range last-char last-elt)
2377 (map-char-table
2378 (lambda (char elt)
2379 (when elt
2380 (setq last-char-or-range (car (car last))
2381 last-char (if (consp last-char-or-range)
2382 (cdr last-char-or-range)
2383 last-char-or-range)
2384 last-elt (cdr (car last)))
2385 (if (and (eq elt last-elt)
2386 (= char (1+ last-char))
2387 (eq (char-charset char) (char-charset last-char)))
2388 (if (consp last-char-or-range)
2389 (setcdr last-char-or-range char)
2390 (setcar (car last) (cons last-char char)))
2391 (setcdr last (list (cons char elt)))
2392 (setq last (cdr last)))))
2393 template)
2394 (cdr accumulator))))
2396 (defun fontset-add-mac-fonts (fontset &optional base-family)
2397 "Add font-specs for Mac fonts to FONTSET.
2398 The added font-specs are determined by BASE-FAMILY and the value
2399 of `mac-char-fontspec-list', which is a list
2400 of (CHARACTER-OR-RANGE . (FAMILY-FORMAT . REGISTRY)). If
2401 BASE-FAMILY is nil, the font family in the added font-specs is
2402 also nil. If BASE-FAMILY is a string, `%s' in FAMILY-FORMAT is
2403 replaced with the string. Otherwise, `%s' in FAMILY-FORMAT is
2404 replaced with the ASCII font family name in FONTSET."
2405 (if base-family
2406 (if (stringp base-family)
2407 (setq base-family (downcase base-family))
2408 (let ((ascii-font (fontset-font fontset (charset-id 'ascii))))
2409 (if ascii-font
2410 (setq base-family
2411 (aref (x-decompose-font-name
2412 (downcase (x-resolve-font-name ascii-font)))
2413 xlfd-regexp-family-subnum))))))
2414 (let (fontspec-cache fontspec)
2415 (dolist (char-fontspec mac-char-fontspec-list)
2416 (setq fontspec (cdr (assq (cdr char-fontspec) fontspec-cache)))
2417 (when (null fontspec)
2418 (setq fontspec
2419 (cons (and base-family
2420 (format (car (cdr char-fontspec)) base-family))
2421 (cdr (cdr char-fontspec))))
2422 (setq fontspec-cache (cons (cons (cdr char-fontspec) fontspec)
2423 fontspec-cache)))
2424 (set-fontset-font fontset (car char-fontspec) fontspec))))
2426 (defun create-fontset-from-mac-roman-font (font &optional resolved-font
2427 fontset-name)
2428 "Create a fontset from a Mac roman font FONT.
2430 Optional 1st arg RESOLVED-FONT is a resolved name of FONT. If
2431 omitted, `x-resolve-font-name' is called to get the resolved name. At
2432 this time, if FONT is not available, error is signaled.
2434 Optional 2nd arg FONTSET-NAME is a string to be used in
2435 `<CHARSET_ENCODING>' fields of a new fontset name. If it is omitted,
2436 an appropriate name is generated automatically.
2438 It returns a name of the created fontset."
2439 (let ((fontset
2440 (create-fontset-from-ascii-font font resolved-font fontset-name)))
2441 (fontset-add-mac-fonts fontset t)
2442 fontset))
2444 ;; Adjust Courier font specifications in x-fixed-font-alist.
2445 (let ((courier-fonts (assoc "Courier" x-fixed-font-alist)))
2446 (if courier-fonts
2447 (dolist (label-fonts (cdr courier-fonts))
2448 (setcdr label-fonts
2449 (mapcar
2450 (lambda (font)
2451 (if (string-match "\\`-adobe-courier-\\([^-]*\\)-\\(.\\)-\\(.*\\)-iso8859-1\\'" font)
2452 (replace-match
2453 (if (string= (match-string 2 font) "o")
2454 "-*-courier-\\1-i-\\3-*-*"
2455 "-*-courier-\\1-\\2-\\3-*-*")
2456 t nil font)
2457 font))
2458 (cdr label-fonts))))))
2460 ;; Setup the default fontset.
2461 (setup-default-fontset)
2462 (cond ((x-list-fonts "*-iso10646-1")
2463 ;; Use ATSUI (if available) for the following charsets.
2464 (dolist
2465 (charset '(latin-iso8859-1
2466 latin-iso8859-2 latin-iso8859-3 latin-iso8859-4
2467 thai-tis620 greek-iso8859-7 arabic-iso8859-6
2468 hebrew-iso8859-8 cyrillic-iso8859-5
2469 latin-iso8859-9 latin-iso8859-15 latin-iso8859-14
2470 japanese-jisx0212 chinese-sisheng ipa
2471 vietnamese-viscii-lower vietnamese-viscii-upper
2472 lao ethiopic tibetan))
2473 (set-fontset-font nil charset '(nil . "iso10646-1"))))
2474 ((null (x-list-fonts "*-iso8859-1"))
2475 ;; Add Mac-encoding fonts unless ETL fonts are installed.
2476 (fontset-add-mac-fonts "fontset-default")))
2478 ;; Create a fontset that uses mac-roman font. With this fontset,
2479 ;; characters decoded from mac-roman encoding (ascii, latin-iso8859-1,
2480 ;; and mule-unicode-xxxx-yyyy) are displayed by a mac-roman font.
2481 (create-fontset-from-fontset-spec
2482 "-etl-fixed-medium-r-normal-*-16-*-*-*-*-*-fontset-standard,
2483 ascii:-*-Monaco-*-*-*-*-12-*-*-*-*-*-mac-roman")
2484 (fontset-add-mac-fonts "fontset-standard" t)
2486 ;; Create fontset specified in X resources "Fontset-N" (N is 0, 1, ...).
2487 (create-fontset-from-x-resource)
2489 ;; Try to create a fontset from a font specification which comes
2490 ;; from initial-frame-alist, default-frame-alist, or X resource.
2491 ;; A font specification in command line argument (i.e. -fn XXXX)
2492 ;; should be already in default-frame-alist as a `font'
2493 ;; parameter. However, any font specifications in site-start
2494 ;; library, user's init file (.emacs), and default.el are not
2495 ;; yet handled here.
2497 (let ((font (or (cdr (assq 'font initial-frame-alist))
2498 (cdr (assq 'font default-frame-alist))
2499 (x-get-resource "font" "Font")))
2500 xlfd-fields resolved-name)
2501 (if (and font
2502 (not (query-fontset font))
2503 (setq resolved-name (x-resolve-font-name font))
2504 (setq xlfd-fields (x-decompose-font-name font)))
2505 (if (string= "fontset" (aref xlfd-fields xlfd-regexp-registry-subnum))
2506 (new-fontset font (x-complement-fontset-spec xlfd-fields nil))
2507 ;; Create a fontset from FONT. The fontset name is
2508 ;; generated from FONT.
2509 (if (and (string= "mac" (aref xlfd-fields xlfd-regexp-registry-subnum))
2510 (string= "roman" (aref xlfd-fields xlfd-regexp-encoding-subnum)))
2511 (create-fontset-from-mac-roman-font font resolved-name "startup")
2512 (create-fontset-from-ascii-font font resolved-name "startup")))))
2514 ;; Apply a geometry resource to the initial frame. Put it at the end
2515 ;; of the alist, so that anything specified on the command line takes
2516 ;; precedence.
2517 (let* ((res-geometry (x-get-resource "geometry" "Geometry"))
2518 parsed)
2519 (if res-geometry
2520 (progn
2521 (setq parsed (x-parse-geometry res-geometry))
2522 ;; If the resource specifies a position,
2523 ;; call the position and size "user-specified".
2524 (if (or (assq 'top parsed) (assq 'left parsed))
2525 (setq parsed (cons '(user-position . t)
2526 (cons '(user-size . t) parsed))))
2527 ;; All geometry parms apply to the initial frame.
2528 (setq initial-frame-alist (append initial-frame-alist parsed))
2529 ;; The size parms apply to all frames. Don't set it if there are
2530 ;; sizes there already (from command line).
2531 (if (and (assq 'height parsed)
2532 (not (assq 'height default-frame-alist)))
2533 (setq default-frame-alist
2534 (cons (cons 'height (cdr (assq 'height parsed)))
2535 default-frame-alist)))
2536 (if (and (assq 'width parsed)
2537 (not (assq 'width default-frame-alist)))
2538 (setq default-frame-alist
2539 (cons (cons 'width (cdr (assq 'width parsed)))
2540 default-frame-alist))))))
2542 ;; Check the reverseVideo resource.
2543 (let ((case-fold-search t))
2544 (let ((rv (x-get-resource "reverseVideo" "ReverseVideo")))
2545 (if (and rv
2546 (string-match "^\\(true\\|yes\\|on\\)$" rv))
2547 (setq default-frame-alist
2548 (cons '(reverse . t) default-frame-alist)))))
2550 (defun x-win-suspend-error ()
2551 (error "Suspending an Emacs running under Mac makes no sense"))
2552 (add-hook 'suspend-hook 'x-win-suspend-error)
2554 ;;; Arrange for the kill and yank functions to set and check the clipboard.
2555 (setq interprogram-cut-function 'x-select-text)
2556 (setq interprogram-paste-function 'x-get-selection-value)
2558 (defalias 'x-cut-buffer-or-selection-value 'x-get-selection-value)
2560 ;;; Turn off window-splitting optimization; Mac is usually fast enough
2561 ;;; that this is only annoying.
2562 (setq split-window-keep-point t)
2564 ;; Don't show the frame name; that's redundant.
2565 (setq-default mode-line-frame-identification " ")
2567 ;; Turn on support for mouse wheels.
2568 (mouse-wheel-mode 1)
2571 ;; Enable CLIPBOARD copy/paste through menu bar commands.
2572 (menu-bar-enable-clipboard)
2574 ;; Initiate drag and drop
2576 (define-key special-event-map [drag-n-drop] 'mac-dnd-handle-drag-n-drop-event)
2577 (define-key special-event-map [M-drag-n-drop] 'mac-dnd-handle-drag-n-drop-event)
2580 ;;;; Non-toolkit Scroll bars
2582 (unless x-toolkit-scroll-bars
2584 ;; for debugging
2585 ;; (defun mac-handle-scroll-bar-event (event) (interactive "e") (princ event))
2587 ;;(global-set-key [vertical-scroll-bar mouse-1] 'mac-handle-scroll-bar-event)
2589 (global-set-key
2590 [vertical-scroll-bar down-mouse-1]
2591 'mac-handle-scroll-bar-event)
2593 (global-unset-key [vertical-scroll-bar drag-mouse-1])
2594 (global-unset-key [vertical-scroll-bar mouse-1])
2596 (defun mac-handle-scroll-bar-event (event)
2597 "Handle scroll bar EVENT to emulate Mac Toolbox style scrolling."
2598 (interactive "e")
2599 (let* ((position (event-start event))
2600 (window (nth 0 position))
2601 (bar-part (nth 4 position)))
2602 (select-window window)
2603 (cond
2604 ((eq bar-part 'up)
2605 (goto-char (window-start window))
2606 (mac-scroll-down-line))
2607 ((eq bar-part 'above-handle)
2608 (mac-scroll-down))
2609 ((eq bar-part 'handle)
2610 (scroll-bar-drag event))
2611 ((eq bar-part 'below-handle)
2612 (mac-scroll-up))
2613 ((eq bar-part 'down)
2614 (goto-char (window-start window))
2615 (mac-scroll-up-line)))))
2617 (defun mac-scroll-ignore-events ()
2618 ;; Ignore confusing non-mouse events
2619 (while (not (memq (car-safe (read-event))
2620 '(mouse-1 double-mouse-1 triple-mouse-1))) nil))
2622 (defun mac-scroll-down ()
2623 (track-mouse
2624 (mac-scroll-ignore-events)
2625 (scroll-down)))
2627 (defun mac-scroll-down-line ()
2628 (track-mouse
2629 (mac-scroll-ignore-events)
2630 (scroll-down 1)))
2632 (defun mac-scroll-up ()
2633 (track-mouse
2634 (mac-scroll-ignore-events)
2635 (scroll-up)))
2637 (defun mac-scroll-up-line ()
2638 (track-mouse
2639 (mac-scroll-ignore-events)
2640 (scroll-up 1)))
2645 ;;;; Others
2647 (unless (eq system-type 'darwin)
2648 ;; This variable specifies the Unix program to call (as a process) to
2649 ;; determine the amount of free space on a file system (defaults to
2650 ;; df). If it is not set to nil, ls-lisp will not work correctly
2651 ;; unless an external application df is implemented on the Mac.
2652 (setq directory-free-space-program nil)
2654 ;; Set this so that Emacs calls subprocesses with "sh" as shell to
2655 ;; expand filenames Note no subprocess for the shell is actually
2656 ;; started (see run_mac_command in sysdep.c).
2657 (setq shell-file-name "sh")
2659 ;; Some system variables are encoded with the system script code.
2660 (dolist (v '(system-name
2661 emacs-build-system ; Mac OS 9 version cannot dump
2662 user-login-name user-real-login-name user-full-name))
2663 (set v (decode-coding-string (symbol-value v) mac-system-coding-system))))
2665 ;; Now the default directory is changed to the user's home directory
2666 ;; in emacs.c if invoked from the WindowServer (with -psn_* option).
2667 ;; (if (string= default-directory "/")
2668 ;; (cd "~"))
2670 ;; Darwin 6- pty breakage is now controlled from the C code so that
2671 ;; it applies to all builds on darwin. See s/darwin.h PTY_ITERATION.
2672 ;; (setq process-connection-type t)
2674 ;; Assume that fonts are always scalable on the Mac. This sometimes
2675 ;; results in characters with jagged edges. However, without it,
2676 ;; fonts with both truetype and bitmap representations but no italic
2677 ;; or bold bitmap versions will not display these variants correctly.
2678 (setq scalable-fonts-allowed t)
2680 ;; arch-tag: 71dfcd14-cde8-4d66-b05c-85ec94fb23a6
2681 ;;; mac-win.el ends here