(calcDigit-key): Use minibuffer-prompt-end instead of point-min.
[bpt/emacs.git] / lisp / term / x-win.el
1 ;;; x-win.el --- parse switches controlling interface with X window system
2
3 ;; Copyright (C) 1993, 1994, 2001 Free Software Foundation, Inc.
4
5 ;; Author: FSF
6 ;; Keywords: terminals
7
8 ;; This file is part of GNU Emacs.
9
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
14
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
24
25 ;;; Commentary:
26
27 ;; X-win.el: this file is loaded from ../lisp/startup.el when it recognizes
28 ;; that X windows are to be used. Command line switches are parsed and those
29 ;; pertaining to X are processed and removed from the command line. The
30 ;; X display is opened and hooks are set for popping up the initial window.
31
32 ;; startup.el will then examine startup files, and eventually call the hooks
33 ;; which create the first window (s).
34
35 ;;; Code:
36 \f
37 ;; These are the standard X switches from the Xt Initialize.c file of
38 ;; Release 4.
39
40 ;; Command line Resource Manager string
41
42 ;; +rv *reverseVideo
43 ;; +synchronous *synchronous
44 ;; -background *background
45 ;; -bd *borderColor
46 ;; -bg *background
47 ;; -bordercolor *borderColor
48 ;; -borderwidth .borderWidth
49 ;; -bw .borderWidth
50 ;; -display .display
51 ;; -fg *foreground
52 ;; -fn *font
53 ;; -font *font
54 ;; -foreground *foreground
55 ;; -geometry .geometry
56 ;; -i .iconType
57 ;; -itype .iconType
58 ;; -iconic .iconic
59 ;; -name .name
60 ;; -reverse *reverseVideo
61 ;; -rv *reverseVideo
62 ;; -selectionTimeout .selectionTimeout
63 ;; -synchronous *synchronous
64 ;; -xrm
65
66 ;; An alist of X options and the function which handles them. See
67 ;; ../startup.el.
68
69 (if (not (eq window-system 'x))
70 (error "%s: Loading x-win.el but not compiled for X" (invocation-name)))
71
72 (require 'frame)
73 (require 'mouse)
74 (require 'scroll-bar)
75 (require 'faces)
76 (require 'select)
77 (require 'menu-bar)
78 (if (fboundp 'new-fontset)
79 (require 'fontset))
80
81 (defvar x-invocation-args)
82
83 (defvar x-command-line-resources nil)
84
85 ;; Handler for switches of the form "-switch value" or "-switch".
86 (defun x-handle-switch (switch)
87 (let ((aelt (assoc switch command-line-x-option-alist)))
88 (if aelt
89 (let ((param (nth 3 aelt))
90 (value (nth 4 aelt)))
91 (if value
92 (setq default-frame-alist
93 (cons (cons param value)
94 default-frame-alist))
95 (setq default-frame-alist
96 (cons (cons param
97 (car x-invocation-args))
98 default-frame-alist)
99 x-invocation-args (cdr x-invocation-args)))))))
100
101 ;; Handler for switches of the form "-switch n"
102 (defun x-handle-numeric-switch (switch)
103 (let ((aelt (assoc switch command-line-x-option-alist)))
104 (if aelt
105 (let ((param (nth 3 aelt)))
106 (setq default-frame-alist
107 (cons (cons param
108 (string-to-int (car x-invocation-args)))
109 default-frame-alist)
110 x-invocation-args
111 (cdr x-invocation-args))))))
112
113 ;; Handle options that apply to initial frame only
114 (defun x-handle-initial-switch (switch)
115 (let ((aelt (assoc switch command-line-x-option-alist)))
116 (if aelt
117 (let ((param (nth 3 aelt))
118 (value (nth 4 aelt)))
119 (if value
120 (setq initial-frame-alist
121 (cons (cons param value)
122 initial-frame-alist))
123 (setq initial-frame-alist
124 (cons (cons param
125 (car x-invocation-args))
126 initial-frame-alist)
127 x-invocation-args (cdr x-invocation-args)))))))
128
129 ;; Make -iconic apply only to the initial frame!
130 (defun x-handle-iconic (switch)
131 (setq initial-frame-alist
132 (cons '(visibility . icon) initial-frame-alist)))
133
134 ;; Handle the -xrm option.
135 (defun x-handle-xrm-switch (switch)
136 (unless (consp x-invocation-args)
137 (error "%s: missing argument to `%s' option" (invocation-name) switch))
138 (setq x-command-line-resources
139 (if (null x-command-line-resources)
140 (car x-invocation-args)
141 (concat x-command-line-resources "\n" (car x-invocation-args))))
142 (setq x-invocation-args (cdr x-invocation-args)))
143
144 ;; Handle the geometry option
145 (defun x-handle-geometry (switch)
146 (let* ((geo (x-parse-geometry (car x-invocation-args)))
147 (left (assq 'left geo))
148 (top (assq 'top geo))
149 (height (assq 'height geo))
150 (width (assq 'width geo)))
151 (if (or height width)
152 (setq default-frame-alist
153 (append default-frame-alist
154 '((user-size . t))
155 (if height (list height))
156 (if width (list width)))
157 initial-frame-alist
158 (append initial-frame-alist
159 '((user-size . t))
160 (if height (list height))
161 (if width (list width)))))
162 (if (or left top)
163 (setq initial-frame-alist
164 (append initial-frame-alist
165 '((user-position . t))
166 (if left (list left))
167 (if top (list top)))))
168 (setq x-invocation-args (cdr x-invocation-args))))
169
170 ;; Handle the -name option. Set the variable x-resource-name
171 ;; to the option's operand; set the name of
172 ;; the initial frame, too.
173 (defun x-handle-name-switch (switch)
174 (or (consp x-invocation-args)
175 (error "%s: missing argument to `%s' option" (invocation-name) switch))
176 (setq x-resource-name (car x-invocation-args)
177 x-invocation-args (cdr x-invocation-args))
178 (setq initial-frame-alist (cons (cons 'name x-resource-name)
179 initial-frame-alist)))
180
181 (defvar x-display-name nil
182 "The X display name specifying server and X frame.")
183
184 (defun x-handle-display (switch)
185 (setq x-display-name (car x-invocation-args)
186 x-invocation-args (cdr x-invocation-args))
187 ;; Make subshell programs see the same DISPLAY value Emacs really uses.
188 ;; Note that this isn't completely correct, since Emacs can use
189 ;; multiple displays. However, there is no way to tell an already
190 ;; running subshell which display the user is currently typing on.
191 (setenv "DISPLAY" x-display-name))
192
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))
237 \f
238 ;;
239 ;; Standard X cursor shapes, courtesy of Mr. Fox, who wanted ALL of them.
240 ;;
241
242 (defconst x-pointer-X-cursor 0)
243 (defconst x-pointer-arrow 2)
244 (defconst x-pointer-based-arrow-down 4)
245 (defconst x-pointer-based-arrow-up 6)
246 (defconst x-pointer-boat 8)
247 (defconst x-pointer-bogosity 10)
248 (defconst x-pointer-bottom-left-corner 12)
249 (defconst x-pointer-bottom-right-corner 14)
250 (defconst x-pointer-bottom-side 16)
251 (defconst x-pointer-bottom-tee 18)
252 (defconst x-pointer-box-spiral 20)
253 (defconst x-pointer-center-ptr 22)
254 (defconst x-pointer-circle 24)
255 (defconst x-pointer-clock 26)
256 (defconst x-pointer-coffee-mug 28)
257 (defconst x-pointer-cross 30)
258 (defconst x-pointer-cross-reverse 32)
259 (defconst x-pointer-crosshair 34)
260 (defconst x-pointer-diamond-cross 36)
261 (defconst x-pointer-dot 38)
262 (defconst x-pointer-dotbox 40)
263 (defconst x-pointer-double-arrow 42)
264 (defconst x-pointer-draft-large 44)
265 (defconst x-pointer-draft-small 46)
266 (defconst x-pointer-draped-box 48)
267 (defconst x-pointer-exchange 50)
268 (defconst x-pointer-fleur 52)
269 (defconst x-pointer-gobbler 54)
270 (defconst x-pointer-gumby 56)
271 (defconst x-pointer-hand1 58)
272 (defconst x-pointer-hand2 60)
273 (defconst x-pointer-heart 62)
274 (defconst x-pointer-icon 64)
275 (defconst x-pointer-iron-cross 66)
276 (defconst x-pointer-left-ptr 68)
277 (defconst x-pointer-left-side 70)
278 (defconst x-pointer-left-tee 72)
279 (defconst x-pointer-leftbutton 74)
280 (defconst x-pointer-ll-angle 76)
281 (defconst x-pointer-lr-angle 78)
282 (defconst x-pointer-man 80)
283 (defconst x-pointer-middlebutton 82)
284 (defconst x-pointer-mouse 84)
285 (defconst x-pointer-pencil 86)
286 (defconst x-pointer-pirate 88)
287 (defconst x-pointer-plus 90)
288 (defconst x-pointer-question-arrow 92)
289 (defconst x-pointer-right-ptr 94)
290 (defconst x-pointer-right-side 96)
291 (defconst x-pointer-right-tee 98)
292 (defconst x-pointer-rightbutton 100)
293 (defconst x-pointer-rtl-logo 102)
294 (defconst x-pointer-sailboat 104)
295 (defconst x-pointer-sb-down-arrow 106)
296 (defconst x-pointer-sb-h-double-arrow 108)
297 (defconst x-pointer-sb-left-arrow 110)
298 (defconst x-pointer-sb-right-arrow 112)
299 (defconst x-pointer-sb-up-arrow 114)
300 (defconst x-pointer-sb-v-double-arrow 116)
301 (defconst x-pointer-shuttle 118)
302 (defconst x-pointer-sizing 120)
303 (defconst x-pointer-spider 122)
304 (defconst x-pointer-spraycan 124)
305 (defconst x-pointer-star 126)
306 (defconst x-pointer-target 128)
307 (defconst x-pointer-tcross 130)
308 (defconst x-pointer-top-left-arrow 132)
309 (defconst x-pointer-top-left-corner 134)
310 (defconst x-pointer-top-right-corner 136)
311 (defconst x-pointer-top-side 138)
312 (defconst x-pointer-top-tee 140)
313 (defconst x-pointer-trek 142)
314 (defconst x-pointer-ul-angle 144)
315 (defconst x-pointer-umbrella 146)
316 (defconst x-pointer-ur-angle 148)
317 (defconst x-pointer-watch 150)
318 (defconst x-pointer-xterm 152)
319 \f
320 ;;
321 ;; Available colors
322 ;;
323
324 (defvar x-colors '("LightGreen"
325 "light green"
326 "DarkRed"
327 "dark red"
328 "DarkMagenta"
329 "dark magenta"
330 "DarkCyan"
331 "dark cyan"
332 "DarkBlue"
333 "dark blue"
334 "DarkGray"
335 "dark gray"
336 "DarkGrey"
337 "dark grey"
338 "grey100"
339 "gray100"
340 "grey99"
341 "gray99"
342 "grey98"
343 "gray98"
344 "grey97"
345 "gray97"
346 "grey96"
347 "gray96"
348 "grey95"
349 "gray95"
350 "grey94"
351 "gray94"
352 "grey93"
353 "gray93"
354 "grey92"
355 "gray92"
356 "grey91"
357 "gray91"
358 "grey90"
359 "gray90"
360 "grey89"
361 "gray89"
362 "grey88"
363 "gray88"
364 "grey87"
365 "gray87"
366 "grey86"
367 "gray86"
368 "grey85"
369 "gray85"
370 "grey84"
371 "gray84"
372 "grey83"
373 "gray83"
374 "grey82"
375 "gray82"
376 "grey81"
377 "gray81"
378 "grey80"
379 "gray80"
380 "grey79"
381 "gray79"
382 "grey78"
383 "gray78"
384 "grey77"
385 "gray77"
386 "grey76"
387 "gray76"
388 "grey75"
389 "gray75"
390 "grey74"
391 "gray74"
392 "grey73"
393 "gray73"
394 "grey72"
395 "gray72"
396 "grey71"
397 "gray71"
398 "grey70"
399 "gray70"
400 "grey69"
401 "gray69"
402 "grey68"
403 "gray68"
404 "grey67"
405 "gray67"
406 "grey66"
407 "gray66"
408 "grey65"
409 "gray65"
410 "grey64"
411 "gray64"
412 "grey63"
413 "gray63"
414 "grey62"
415 "gray62"
416 "grey61"
417 "gray61"
418 "grey60"
419 "gray60"
420 "grey59"
421 "gray59"
422 "grey58"
423 "gray58"
424 "grey57"
425 "gray57"
426 "grey56"
427 "gray56"
428 "grey55"
429 "gray55"
430 "grey54"
431 "gray54"
432 "grey53"
433 "gray53"
434 "grey52"
435 "gray52"
436 "grey51"
437 "gray51"
438 "grey50"
439 "gray50"
440 "grey49"
441 "gray49"
442 "grey48"
443 "gray48"
444 "grey47"
445 "gray47"
446 "grey46"
447 "gray46"
448 "grey45"
449 "gray45"
450 "grey44"
451 "gray44"
452 "grey43"
453 "gray43"
454 "grey42"
455 "gray42"
456 "grey41"
457 "gray41"
458 "grey40"
459 "gray40"
460 "grey39"
461 "gray39"
462 "grey38"
463 "gray38"
464 "grey37"
465 "gray37"
466 "grey36"
467 "gray36"
468 "grey35"
469 "gray35"
470 "grey34"
471 "gray34"
472 "grey33"
473 "gray33"
474 "grey32"
475 "gray32"
476 "grey31"
477 "gray31"
478 "grey30"
479 "gray30"
480 "grey29"
481 "gray29"
482 "grey28"
483 "gray28"
484 "grey27"
485 "gray27"
486 "grey26"
487 "gray26"
488 "grey25"
489 "gray25"
490 "grey24"
491 "gray24"
492 "grey23"
493 "gray23"
494 "grey22"
495 "gray22"
496 "grey21"
497 "gray21"
498 "grey20"
499 "gray20"
500 "grey19"
501 "gray19"
502 "grey18"
503 "gray18"
504 "grey17"
505 "gray17"
506 "grey16"
507 "gray16"
508 "grey15"
509 "gray15"
510 "grey14"
511 "gray14"
512 "grey13"
513 "gray13"
514 "grey12"
515 "gray12"
516 "grey11"
517 "gray11"
518 "grey10"
519 "gray10"
520 "grey9"
521 "gray9"
522 "grey8"
523 "gray8"
524 "grey7"
525 "gray7"
526 "grey6"
527 "gray6"
528 "grey5"
529 "gray5"
530 "grey4"
531 "gray4"
532 "grey3"
533 "gray3"
534 "grey2"
535 "gray2"
536 "grey1"
537 "gray1"
538 "grey0"
539 "gray0"
540 "thistle4"
541 "thistle3"
542 "thistle2"
543 "thistle1"
544 "MediumPurple4"
545 "MediumPurple3"
546 "MediumPurple2"
547 "MediumPurple1"
548 "purple4"
549 "purple3"
550 "purple2"
551 "purple1"
552 "DarkOrchid4"
553 "DarkOrchid3"
554 "DarkOrchid2"
555 "DarkOrchid1"
556 "MediumOrchid4"
557 "MediumOrchid3"
558 "MediumOrchid2"
559 "MediumOrchid1"
560 "plum4"
561 "plum3"
562 "plum2"
563 "plum1"
564 "orchid4"
565 "orchid3"
566 "orchid2"
567 "orchid1"
568 "magenta4"
569 "magenta3"
570 "magenta2"
571 "magenta1"
572 "VioletRed4"
573 "VioletRed3"
574 "VioletRed2"
575 "VioletRed1"
576 "maroon4"
577 "maroon3"
578 "maroon2"
579 "maroon1"
580 "PaleVioletRed4"
581 "PaleVioletRed3"
582 "PaleVioletRed2"
583 "PaleVioletRed1"
584 "LightPink4"
585 "LightPink3"
586 "LightPink2"
587 "LightPink1"
588 "pink4"
589 "pink3"
590 "pink2"
591 "pink1"
592 "HotPink4"
593 "HotPink3"
594 "HotPink2"
595 "HotPink1"
596 "DeepPink4"
597 "DeepPink3"
598 "DeepPink2"
599 "DeepPink1"
600 "red4"
601 "red3"
602 "red2"
603 "red1"
604 "OrangeRed4"
605 "OrangeRed3"
606 "OrangeRed2"
607 "OrangeRed1"
608 "tomato4"
609 "tomato3"
610 "tomato2"
611 "tomato1"
612 "coral4"
613 "coral3"
614 "coral2"
615 "coral1"
616 "DarkOrange4"
617 "DarkOrange3"
618 "DarkOrange2"
619 "DarkOrange1"
620 "orange4"
621 "orange3"
622 "orange2"
623 "orange1"
624 "LightSalmon4"
625 "LightSalmon3"
626 "LightSalmon2"
627 "LightSalmon1"
628 "salmon4"
629 "salmon3"
630 "salmon2"
631 "salmon1"
632 "brown4"
633 "brown3"
634 "brown2"
635 "brown1"
636 "firebrick4"
637 "firebrick3"
638 "firebrick2"
639 "firebrick1"
640 "chocolate4"
641 "chocolate3"
642 "chocolate2"
643 "chocolate1"
644 "tan4"
645 "tan3"
646 "tan2"
647 "tan1"
648 "wheat4"
649 "wheat3"
650 "wheat2"
651 "wheat1"
652 "burlywood4"
653 "burlywood3"
654 "burlywood2"
655 "burlywood1"
656 "sienna4"
657 "sienna3"
658 "sienna2"
659 "sienna1"
660 "IndianRed4"
661 "IndianRed3"
662 "IndianRed2"
663 "IndianRed1"
664 "RosyBrown4"
665 "RosyBrown3"
666 "RosyBrown2"
667 "RosyBrown1"
668 "DarkGoldenrod4"
669 "DarkGoldenrod3"
670 "DarkGoldenrod2"
671 "DarkGoldenrod1"
672 "goldenrod4"
673 "goldenrod3"
674 "goldenrod2"
675 "goldenrod1"
676 "gold4"
677 "gold3"
678 "gold2"
679 "gold1"
680 "yellow4"
681 "yellow3"
682 "yellow2"
683 "yellow1"
684 "LightYellow4"
685 "LightYellow3"
686 "LightYellow2"
687 "LightYellow1"
688 "LightGoldenrod4"
689 "LightGoldenrod3"
690 "LightGoldenrod2"
691 "LightGoldenrod1"
692 "khaki4"
693 "khaki3"
694 "khaki2"
695 "khaki1"
696 "DarkOliveGreen4"
697 "DarkOliveGreen3"
698 "DarkOliveGreen2"
699 "DarkOliveGreen1"
700 "OliveDrab4"
701 "OliveDrab3"
702 "OliveDrab2"
703 "OliveDrab1"
704 "chartreuse4"
705 "chartreuse3"
706 "chartreuse2"
707 "chartreuse1"
708 "green4"
709 "green3"
710 "green2"
711 "green1"
712 "SpringGreen4"
713 "SpringGreen3"
714 "SpringGreen2"
715 "SpringGreen1"
716 "PaleGreen4"
717 "PaleGreen3"
718 "PaleGreen2"
719 "PaleGreen1"
720 "SeaGreen4"
721 "SeaGreen3"
722 "SeaGreen2"
723 "SeaGreen1"
724 "DarkSeaGreen4"
725 "DarkSeaGreen3"
726 "DarkSeaGreen2"
727 "DarkSeaGreen1"
728 "aquamarine4"
729 "aquamarine3"
730 "aquamarine2"
731 "aquamarine1"
732 "DarkSlateGray4"
733 "DarkSlateGray3"
734 "DarkSlateGray2"
735 "DarkSlateGray1"
736 "cyan4"
737 "cyan3"
738 "cyan2"
739 "cyan1"
740 "turquoise4"
741 "turquoise3"
742 "turquoise2"
743 "turquoise1"
744 "CadetBlue4"
745 "CadetBlue3"
746 "CadetBlue2"
747 "CadetBlue1"
748 "PaleTurquoise4"
749 "PaleTurquoise3"
750 "PaleTurquoise2"
751 "PaleTurquoise1"
752 "LightCyan4"
753 "LightCyan3"
754 "LightCyan2"
755 "LightCyan1"
756 "LightBlue4"
757 "LightBlue3"
758 "LightBlue2"
759 "LightBlue1"
760 "LightSteelBlue4"
761 "LightSteelBlue3"
762 "LightSteelBlue2"
763 "LightSteelBlue1"
764 "SlateGray4"
765 "SlateGray3"
766 "SlateGray2"
767 "SlateGray1"
768 "LightSkyBlue4"
769 "LightSkyBlue3"
770 "LightSkyBlue2"
771 "LightSkyBlue1"
772 "SkyBlue4"
773 "SkyBlue3"
774 "SkyBlue2"
775 "SkyBlue1"
776 "DeepSkyBlue4"
777 "DeepSkyBlue3"
778 "DeepSkyBlue2"
779 "DeepSkyBlue1"
780 "SteelBlue4"
781 "SteelBlue3"
782 "SteelBlue2"
783 "SteelBlue1"
784 "DodgerBlue4"
785 "DodgerBlue3"
786 "DodgerBlue2"
787 "DodgerBlue1"
788 "blue4"
789 "blue3"
790 "blue2"
791 "blue1"
792 "RoyalBlue4"
793 "RoyalBlue3"
794 "RoyalBlue2"
795 "RoyalBlue1"
796 "SlateBlue4"
797 "SlateBlue3"
798 "SlateBlue2"
799 "SlateBlue1"
800 "azure4"
801 "azure3"
802 "azure2"
803 "azure1"
804 "MistyRose4"
805 "MistyRose3"
806 "MistyRose2"
807 "MistyRose1"
808 "LavenderBlush4"
809 "LavenderBlush3"
810 "LavenderBlush2"
811 "LavenderBlush1"
812 "honeydew4"
813 "honeydew3"
814 "honeydew2"
815 "honeydew1"
816 "ivory4"
817 "ivory3"
818 "ivory2"
819 "ivory1"
820 "cornsilk4"
821 "cornsilk3"
822 "cornsilk2"
823 "cornsilk1"
824 "LemonChiffon4"
825 "LemonChiffon3"
826 "LemonChiffon2"
827 "LemonChiffon1"
828 "NavajoWhite4"
829 "NavajoWhite3"
830 "NavajoWhite2"
831 "NavajoWhite1"
832 "PeachPuff4"
833 "PeachPuff3"
834 "PeachPuff2"
835 "PeachPuff1"
836 "bisque4"
837 "bisque3"
838 "bisque2"
839 "bisque1"
840 "AntiqueWhite4"
841 "AntiqueWhite3"
842 "AntiqueWhite2"
843 "AntiqueWhite1"
844 "seashell4"
845 "seashell3"
846 "seashell2"
847 "seashell1"
848 "snow4"
849 "snow3"
850 "snow2"
851 "snow1"
852 "thistle"
853 "MediumPurple"
854 "medium purple"
855 "purple"
856 "BlueViolet"
857 "blue violet"
858 "DarkViolet"
859 "dark violet"
860 "DarkOrchid"
861 "dark orchid"
862 "MediumOrchid"
863 "medium orchid"
864 "orchid"
865 "plum"
866 "violet"
867 "magenta"
868 "VioletRed"
869 "violet red"
870 "MediumVioletRed"
871 "medium violet red"
872 "maroon"
873 "PaleVioletRed"
874 "pale violet red"
875 "LightPink"
876 "light pink"
877 "pink"
878 "DeepPink"
879 "deep pink"
880 "HotPink"
881 "hot pink"
882 "red"
883 "OrangeRed"
884 "orange red"
885 "tomato"
886 "LightCoral"
887 "light coral"
888 "coral"
889 "DarkOrange"
890 "dark orange"
891 "orange"
892 "LightSalmon"
893 "light salmon"
894 "salmon"
895 "DarkSalmon"
896 "dark salmon"
897 "brown"
898 "firebrick"
899 "chocolate"
900 "tan"
901 "SandyBrown"
902 "sandy brown"
903 "wheat"
904 "beige"
905 "burlywood"
906 "peru"
907 "sienna"
908 "SaddleBrown"
909 "saddle brown"
910 "IndianRed"
911 "indian red"
912 "RosyBrown"
913 "rosy brown"
914 "DarkGoldenrod"
915 "dark goldenrod"
916 "goldenrod"
917 "LightGoldenrod"
918 "light goldenrod"
919 "gold"
920 "yellow"
921 "LightYellow"
922 "light yellow"
923 "LightGoldenrodYellow"
924 "light goldenrod yellow"
925 "PaleGoldenrod"
926 "pale goldenrod"
927 "khaki"
928 "DarkKhaki"
929 "dark khaki"
930 "OliveDrab"
931 "olive drab"
932 "ForestGreen"
933 "forest green"
934 "YellowGreen"
935 "yellow green"
936 "LimeGreen"
937 "lime green"
938 "GreenYellow"
939 "green yellow"
940 "MediumSpringGreen"
941 "medium spring green"
942 "chartreuse"
943 "green"
944 "LawnGreen"
945 "lawn green"
946 "SpringGreen"
947 "spring green"
948 "PaleGreen"
949 "pale green"
950 "LightSeaGreen"
951 "light sea green"
952 "MediumSeaGreen"
953 "medium sea green"
954 "SeaGreen"
955 "sea green"
956 "DarkSeaGreen"
957 "dark sea green"
958 "DarkOliveGreen"
959 "dark olive green"
960 "DarkGreen"
961 "dark green"
962 "aquamarine"
963 "MediumAquamarine"
964 "medium aquamarine"
965 "CadetBlue"
966 "cadet blue"
967 "LightCyan"
968 "light cyan"
969 "cyan"
970 "turquoise"
971 "MediumTurquoise"
972 "medium turquoise"
973 "DarkTurquoise"
974 "dark turquoise"
975 "PaleTurquoise"
976 "pale turquoise"
977 "PowderBlue"
978 "powder blue"
979 "LightBlue"
980 "light blue"
981 "LightSteelBlue"
982 "light steel blue"
983 "SteelBlue"
984 "steel blue"
985 "LightSkyBlue"
986 "light sky blue"
987 "SkyBlue"
988 "sky blue"
989 "DeepSkyBlue"
990 "deep sky blue"
991 "DodgerBlue"
992 "dodger blue"
993 "blue"
994 "RoyalBlue"
995 "royal blue"
996 "MediumBlue"
997 "medium blue"
998 "LightSlateBlue"
999 "light slate blue"
1000 "MediumSlateBlue"
1001 "medium slate blue"
1002 "SlateBlue"
1003 "slate blue"
1004 "DarkSlateBlue"
1005 "dark slate blue"
1006 "CornflowerBlue"
1007 "cornflower blue"
1008 "NavyBlue"
1009 "navy blue"
1010 "navy"
1011 "MidnightBlue"
1012 "midnight blue"
1013 "LightGray"
1014 "light gray"
1015 "LightGrey"
1016 "light grey"
1017 "grey"
1018 "gray"
1019 "LightSlateGrey"
1020 "light slate grey"
1021 "LightSlateGray"
1022 "light slate gray"
1023 "SlateGrey"
1024 "slate grey"
1025 "SlateGray"
1026 "slate gray"
1027 "DimGrey"
1028 "dim grey"
1029 "DimGray"
1030 "dim gray"
1031 "DarkSlateGrey"
1032 "dark slate grey"
1033 "DarkSlateGray"
1034 "dark slate gray"
1035 "black"
1036 "white"
1037 "MistyRose"
1038 "misty rose"
1039 "LavenderBlush"
1040 "lavender blush"
1041 "lavender"
1042 "AliceBlue"
1043 "alice blue"
1044 "azure"
1045 "MintCream"
1046 "mint cream"
1047 "honeydew"
1048 "seashell"
1049 "LemonChiffon"
1050 "lemon chiffon"
1051 "ivory"
1052 "cornsilk"
1053 "moccasin"
1054 "NavajoWhite"
1055 "navajo white"
1056 "PeachPuff"
1057 "peach puff"
1058 "bisque"
1059 "BlanchedAlmond"
1060 "blanched almond"
1061 "PapayaWhip"
1062 "papaya whip"
1063 "AntiqueWhite"
1064 "antique white"
1065 "linen"
1066 "OldLace"
1067 "old lace"
1068 "FloralWhite"
1069 "floral white"
1070 "gainsboro"
1071 "WhiteSmoke"
1072 "white smoke"
1073 "GhostWhite"
1074 "ghost white"
1075 "snow")
1076 "The list of X colors from the `rgb.txt' file.
1077 XConsortium: rgb.txt,v 10.41 94/02/20 18:39:36 rws Exp")
1078
1079 (defun xw-defined-colors (&optional frame)
1080 "Internal function called by `defined-colors', which see."
1081 (or frame (setq frame (selected-frame)))
1082 (let ((all-colors x-colors)
1083 (this-color nil)
1084 (defined-colors nil))
1085 (while all-colors
1086 (setq this-color (car all-colors)
1087 all-colors (cdr all-colors))
1088 (and (color-supported-p this-color frame t)
1089 (setq defined-colors (cons this-color defined-colors))))
1090 defined-colors))
1091 \f
1092 ;;;; Function keys
1093
1094 (defun iconify-or-deiconify-frame ()
1095 "Iconify the selected frame, or deiconify if it's currently an icon."
1096 (interactive)
1097 (if (eq (cdr (assq 'visibility (frame-parameters))) t)
1098 (iconify-frame)
1099 (make-frame-visible)))
1100
1101 (substitute-key-definition 'suspend-emacs 'iconify-or-deiconify-frame
1102 global-map)
1103
1104 ;; Map certain keypad keys into ASCII characters
1105 ;; that people usually expect.
1106 (define-key function-key-map [backspace] [127])
1107 (define-key function-key-map [delete] [127])
1108 (define-key function-key-map [tab] [?\t])
1109 (define-key function-key-map [linefeed] [?\n])
1110 (define-key function-key-map [clear] [?\C-l])
1111 (define-key function-key-map [return] [?\C-m])
1112 (define-key function-key-map [escape] [?\e])
1113 (define-key function-key-map [M-backspace] [?\M-\d])
1114 (define-key function-key-map [M-delete] [?\M-\d])
1115 (define-key function-key-map [M-tab] [?\M-\t])
1116 (define-key function-key-map [M-linefeed] [?\M-\n])
1117 (define-key function-key-map [M-clear] [?\M-\C-l])
1118 (define-key function-key-map [M-return] [?\M-\C-m])
1119 (define-key function-key-map [M-escape] [?\M-\e])
1120 (define-key function-key-map [iso-lefttab] [backtab])
1121
1122 ;; These tell read-char how to convert
1123 ;; these special chars to ASCII.
1124 (put 'backspace 'ascii-character 127)
1125 (put 'delete 'ascii-character 127)
1126 (put 'tab 'ascii-character ?\t)
1127 (put 'linefeed 'ascii-character ?\n)
1128 (put 'clear 'ascii-character 12)
1129 (put 'return 'ascii-character 13)
1130 (put 'escape 'ascii-character ?\e)
1131
1132 (defun vendor-specific-keysyms (vendor)
1133 "Return the appropriate value of system-key-alist for VENDOR.
1134 VENDOR is a string containing the name of the X Server's vendor,
1135 as returned by (x-server-vendor)."
1136 (cond ((string-equal vendor "Apollo Computer Inc.")
1137 '((65280 . linedel)
1138 (65281 . chardel)
1139 (65282 . copy)
1140 (65283 . cut)
1141 (65284 . paste)
1142 (65285 . move)
1143 (65286 . grow)
1144 (65287 . cmd)
1145 (65288 . shell)
1146 (65289 . leftbar)
1147 (65290 . rightbar)
1148 (65291 . leftbox)
1149 (65292 . rightbox)
1150 (65293 . upbox)
1151 (65294 . downbox)
1152 (65295 . pop)
1153 (65296 . read)
1154 (65297 . edit)
1155 (65298 . save)
1156 (65299 . exit)
1157 (65300 . repeat)))
1158 ((or (string-equal vendor "Hewlett-Packard Incorporated")
1159 (string-equal vendor "Hewlett-Packard Company"))
1160 '(( 168 . mute-acute)
1161 ( 169 . mute-grave)
1162 ( 170 . mute-asciicircum)
1163 ( 171 . mute-diaeresis)
1164 ( 172 . mute-asciitilde)
1165 ( 175 . lira)
1166 ( 190 . guilder)
1167 ( 252 . block)
1168 ( 256 . longminus)
1169 (65388 . reset)
1170 (65389 . system)
1171 (65390 . user)
1172 (65391 . clearline)
1173 (65392 . insertline)
1174 (65393 . deleteline)
1175 (65394 . insertchar)
1176 (65395 . deletechar)
1177 (65396 . backtab)
1178 (65397 . kp-backtab)))
1179 ((or (string-equal vendor "X11/NeWS - Sun Microsystems Inc.")
1180 (string-equal vendor "X Consortium"))
1181 '((392976 . f36)
1182 (392977 . f37)
1183 (393056 . req)
1184 ;; These are for Sun under X11R6
1185 (393072 . props)
1186 (393073 . front)
1187 (393074 . copy)
1188 (393075 . open)
1189 (393076 . paste)
1190 (393077 . cut)))
1191 (t
1192 ;; This is used by DEC's X server.
1193 '((65280 . remove)))))
1194
1195 \f
1196 ;;;; Selections and cut buffers
1197
1198 ;;; We keep track of the last text selected here, so we can check the
1199 ;;; current selection against it, and avoid passing back our own text
1200 ;;; from x-cut-buffer-or-selection-value.
1201 (defvar x-last-selected-text nil)
1202
1203 ;;; It is said that overlarge strings are slow to put into the cut buffer.
1204 ;;; Note this value is overridden below.
1205 (defvar x-cut-buffer-max 20000
1206 "Max number of characters to put in the cut buffer.")
1207
1208 (defcustom x-select-enable-clipboard nil
1209 "Non-nil means cutting and pasting uses the clipboard.
1210 This is in addition to, but in preference to, the primary selection."
1211 :type 'boolean
1212 :group 'killing)
1213
1214 ;;; Make TEXT, a string, the primary X selection.
1215 ;;; Also, set the value of X cut buffer 0, for backward compatibility
1216 ;;; with older X applications.
1217 ;;; gildea@stop.mail-abuse.org says it's not desirable to put kills
1218 ;;; in the clipboard.
1219 (defun x-select-text (text &optional push)
1220 ;; Don't send the cut buffer too much text.
1221 ;; It becomes slow, and if really big it causes errors.
1222 (if (< (length text) x-cut-buffer-max)
1223 (x-set-cut-buffer text push)
1224 (x-set-cut-buffer "" push))
1225 (x-set-selection 'PRIMARY text)
1226 (if x-select-enable-clipboard
1227 (x-set-selection 'CLIPBOARD text))
1228 (setq x-last-selected-text text))
1229
1230 ;;; Return the value of the current X selection.
1231 ;;; Consult the selection, then the cut buffer. Treat empty strings
1232 ;;; as if they were unset.
1233 ;;; If this function is called twice and finds the same text,
1234 ;;; it returns nil the second time. This is so that a single
1235 ;;; selection won't be added to the kill ring over and over.
1236 (defun x-cut-buffer-or-selection-value ()
1237 (let (text)
1238 (when x-select-enable-clipboard
1239 (if (null text)
1240 (condition-case c
1241 (setq text (x-get-selection 'CLIPBOARD 'COMPOUND_TEXT))
1242 (error nil)))
1243 (if (null text)
1244 (condition-case c
1245 (setq text (x-get-selection 'CLIPBOARD 'STRING))
1246 (error nil)))
1247 (if (string= text "") (setq text nil)))
1248
1249 ;; Don't die if x-get-selection signals an error.
1250 (if (null text)
1251 (condition-case c
1252 (setq text (x-get-selection 'PRIMARY 'COMPOUND_TEXT))
1253 (error nil)))
1254 (if (null text)
1255 (condition-case c
1256 (setq text (x-get-selection 'PRIMARY 'STRING))
1257 (error nil)))
1258 (if (string= text "") (setq text nil))
1259
1260 (or text (setq text (x-get-cut-buffer 0)))
1261 (if (string= text "") (setq text nil))
1262
1263 (cond
1264 ((not text) nil)
1265 ((eq text x-last-selected-text) nil)
1266 ((string= text x-last-selected-text)
1267 ;; Record the newer string, so subsequent calls can use the `eq' test.
1268 (setq x-last-selected-text text)
1269 nil)
1270 (t
1271 (setq x-last-selected-text text)))))
1272
1273 \f
1274 ;;; Do the actual X Windows setup here; the above code just defines
1275 ;;; functions and variables that we use now.
1276
1277 (setq command-line-args (x-handle-args command-line-args))
1278
1279 ;;; Make sure we have a valid resource name.
1280 (or (stringp x-resource-name)
1281 (let (i)
1282 (setq x-resource-name (invocation-name))
1283
1284 ;; Change any . or * characters in x-resource-name to hyphens,
1285 ;; so as not to choke when we use it in X resource queries.
1286 (while (setq i (string-match "[.*]" x-resource-name))
1287 (aset x-resource-name i ?-))))
1288
1289 ;; For the benefit of older Emacses (19.27 and earlier) that are sharing
1290 ;; the same lisp directory, don't pass the third argument unless we seem
1291 ;; to have the multi-display support.
1292 (if (fboundp 'x-close-connection)
1293 (x-open-connection (or x-display-name
1294 (setq x-display-name (getenv "DISPLAY")))
1295 x-command-line-resources
1296 ;; Exit Emacs with fatal error if this fails.
1297 t)
1298 (x-open-connection (or x-display-name
1299 (setq x-display-name (getenv "DISPLAY")))
1300 x-command-line-resources))
1301
1302 (setq frame-creation-function 'x-create-frame-with-faces)
1303
1304 (setq x-cut-buffer-max (min (- (/ (x-server-max-request-size) 2) 100)
1305 x-cut-buffer-max))
1306
1307 (if (fboundp 'new-fontset)
1308 (progn
1309 ;; Create the standard fontset.
1310 (create-fontset-from-fontset-spec standard-fontset-spec t)
1311
1312 ;; Create fontset specified in X resources "Fontset-N" (N is 0, 1, ...).
1313 (create-fontset-from-x-resource)
1314
1315 ;; Try to create a fontset from a font specification which comes
1316 ;; from initial-frame-alist, default-frame-alist, or X resource.
1317 ;; A font specification in command line argument (i.e. -fn XXXX)
1318 ;; should be already in default-frame-alist as a `font'
1319 ;; parameter. However, any font specifications in site-start
1320 ;; library, user's init file (.emacs), and default.el are not
1321 ;; yet handled here.
1322
1323 (let ((font (or (cdr (assq 'font initial-frame-alist))
1324 (cdr (assq 'font default-frame-alist))
1325 (x-get-resource "font" "Font")))
1326 xlfd-fields resolved-name)
1327 (if (and font
1328 (not (query-fontset font))
1329 (setq resolved-name (x-resolve-font-name font))
1330 (setq xlfd-fields (x-decompose-font-name font)))
1331 (if (string= "fontset"
1332 (aref xlfd-fields xlfd-regexp-registry-subnum))
1333 (new-fontset font (x-complement-fontset-spec xlfd-fields nil))
1334 ;; Create a fontset from FONT. The fontset name is
1335 ;; generated from FONT.
1336 (create-fontset-from-ascii-font font
1337 resolved-name "startup"))))))
1338
1339 ;; Sun expects the menu bar cut and paste commands to use the clipboard.
1340 ;; This has ,? to match both on Sunos and on Solaris.
1341 (if (string-match "Sun Microsystems,? Inc\\."
1342 (x-server-vendor))
1343 (menu-bar-enable-clipboard))
1344
1345 ;; Apply a geometry resource to the initial frame. Put it at the end
1346 ;; of the alist, so that anything specified on the command line takes
1347 ;; precedence.
1348 (let* ((res-geometry (x-get-resource "geometry" "Geometry"))
1349 parsed)
1350 (if res-geometry
1351 (progn
1352 (setq parsed (x-parse-geometry res-geometry))
1353 ;; If the resource specifies a position,
1354 ;; call the position and size "user-specified".
1355 (if (or (assq 'top parsed) (assq 'left parsed))
1356 (setq parsed (cons '(user-position . t)
1357 (cons '(user-size . t) parsed))))
1358 ;; All geometry parms apply to the initial frame.
1359 (setq initial-frame-alist (append initial-frame-alist parsed))
1360 ;; The size parms apply to all frames.
1361 (if (assq 'height parsed)
1362 (setq default-frame-alist
1363 (cons (cons 'height (cdr (assq 'height parsed)))
1364 default-frame-alist)))
1365 (if (assq 'width parsed)
1366 (setq default-frame-alist
1367 (cons (cons 'width (cdr (assq 'width parsed)))
1368 default-frame-alist))))))
1369
1370 ;; Check the reverseVideo resource.
1371 (let ((case-fold-search t))
1372 (let ((rv (x-get-resource "reverseVideo" "ReverseVideo")))
1373 (if (and rv
1374 (string-match "^\\(true\\|yes\\|on\\)$" rv))
1375 (setq default-frame-alist
1376 (cons '(reverse . t) default-frame-alist)))))
1377
1378 ;; Set x-selection-timeout, measured in milliseconds.
1379 (let ((res-selection-timeout
1380 (x-get-resource "selectionTimeout" "SelectionTimeout")))
1381 (setq x-selection-timeout 20000)
1382 (if res-selection-timeout
1383 (setq x-selection-timeout (string-to-number res-selection-timeout))))
1384
1385 (defun x-win-suspend-error ()
1386 (error "Suspending an emacs running under X makes no sense"))
1387 (add-hook 'suspend-hook 'x-win-suspend-error)
1388
1389 ;;; Arrange for the kill and yank functions to set and check the clipboard.
1390 (setq interprogram-cut-function 'x-select-text)
1391 (setq interprogram-paste-function 'x-cut-buffer-or-selection-value)
1392
1393 ;;; Turn off window-splitting optimization; X is usually fast enough
1394 ;;; that this is only annoying.
1395 (setq split-window-keep-point t)
1396
1397 ;; Don't show the frame name; that's redundant with X.
1398 (setq-default mode-line-frame-identification " ")
1399
1400 ;;; Motif direct handling of f10 wasn't working right,
1401 ;;; So temporarily we've turned it off in lwlib-Xm.c
1402 ;;; and turned the Emacs f10 back on.
1403 ;;; ;; Motif normally handles f10 itself, so don't try to handle it a second time.
1404 ;;; (if (featurep 'motif)
1405 ;;; (global-set-key [f10] 'ignore))
1406
1407 ;;; x-win.el ends here