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