; Typo fixes, mostly repeated words
[emacs.git] / lisp / term / common-win.el
blob2cf1e84768e3f162eed42185c6c7a6320cbef8df
1 ;;; common-win.el --- common part of handling window systems
3 ;; Copyright (C) 1993-1994, 2001-2017 Free Software Foundation, Inc.
5 ;; Maintainer: emacs-devel@gnu.org
6 ;; Keywords: terminals
8 ;; This file is part of GNU Emacs.
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 3 of the License, or
13 ;; (at your option) any later version.
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.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
23 ;;; Commentary:
25 ;;; Code:
27 ;;;; Function keys
29 (defvar x-alternatives-map
30 (let ((map (make-sparse-keymap)))
31 ;; Map certain keypad keys into ASCII characters that people usually expect.
32 (define-key map [M-backspace] [?\M-\d])
33 (define-key map [M-delete] [?\M-\d])
34 (define-key map [M-tab] [?\M-\t])
35 (define-key map [M-linefeed] [?\M-\n])
36 (define-key map [M-clear] [?\M-\C-l])
37 (define-key map [M-return] [?\M-\C-m])
38 (define-key map [M-escape] [?\M-\e])
39 (unless (featurep 'ns)
40 (define-key map [iso-lefttab] [backtab])
41 (define-key map [S-iso-lefttab] [backtab]))
42 (and (or (eq system-type 'windows-nt)
43 (featurep 'ns))
44 (define-key map [S-tab] [backtab]))
45 map)
46 "Keymap of possible alternative meanings for some keys.")
48 (defun x-setup-function-keys (frame)
49 "Set up `function-key-map' on the graphical frame FRAME."
50 ;; Don't do this twice on the same display, or it would break
51 ;; normal-erase-is-backspace-mode.
52 (unless (terminal-parameter frame 'x-setup-function-keys)
53 ;; Map certain keypad keys into ASCII characters that people usually expect.
54 (with-selected-frame frame
55 (let ((map (copy-keymap x-alternatives-map)))
56 (set-keymap-parent map (keymap-parent local-function-key-map))
57 (set-keymap-parent local-function-key-map map))
58 (when (featurep 'ns)
59 (setq system-key-alist
60 (list
61 ;; These are special "keys" used to pass events from C to lisp.
62 (cons (logior (lsh 0 16) 1) 'ns-power-off)
63 (cons (logior (lsh 0 16) 2) 'ns-open-file)
64 (cons (logior (lsh 0 16) 3) 'ns-open-temp-file)
65 (cons (logior (lsh 0 16) 4) 'ns-drag-file)
66 (cons (logior (lsh 0 16) 5) 'ns-drag-color)
67 (cons (logior (lsh 0 16) 6) 'ns-drag-text)
68 (cons (logior (lsh 0 16) 7) 'ns-change-font)
69 (cons (logior (lsh 0 16) 8) 'ns-open-file-line)
70 ;;; (cons (logior (lsh 0 16) 9) 'ns-insert-working-text)
71 ;;; (cons (logior (lsh 0 16) 10) 'ns-delete-working-text)
72 (cons (logior (lsh 0 16) 11) 'ns-spi-service-call)
73 (cons (logior (lsh 0 16) 12) 'ns-new-frame)
74 (cons (logior (lsh 0 16) 13) 'ns-toggle-toolbar)
75 (cons (logior (lsh 0 16) 14) 'ns-show-prefs)
76 ))))
77 (set-terminal-parameter frame 'x-setup-function-keys t)))
79 (defvar x-invocation-args)
81 (defvar x-command-line-resources nil)
83 ;; Handler for switches of the form "-switch value" or "-switch".
84 (defun x-handle-switch (switch &optional numeric)
85 (let ((aelt (assoc switch command-line-x-option-alist)))
86 (if aelt
87 (setq default-frame-alist
88 (cons (cons (nth 3 aelt)
89 (if numeric
90 (string-to-number (pop x-invocation-args))
91 (or (nth 4 aelt) (pop x-invocation-args))))
92 default-frame-alist)))))
94 ;; Handler for switches of the form "-switch n"
95 (defun x-handle-numeric-switch (switch)
96 (x-handle-switch switch t))
98 ;; Handle options that apply to initial frame only
99 (defun x-handle-initial-switch (switch)
100 (let ((aelt (assoc switch command-line-x-option-alist)))
101 (if aelt
102 (setq initial-frame-alist
103 (cons (cons (nth 3 aelt)
104 (or (nth 4 aelt) (pop x-invocation-args)))
105 initial-frame-alist)))))
107 ;; Make -iconic apply only to the initial frame!
108 (defun x-handle-iconic (_switch)
109 (setq initial-frame-alist
110 (cons '(visibility . icon) initial-frame-alist)))
112 ;; Handle the -xrm option.
113 (defun x-handle-xrm-switch (switch)
114 (unless (consp x-invocation-args)
115 (error "%s: missing argument to `%s' option" (invocation-name) switch))
116 (setq x-command-line-resources
117 (if (null x-command-line-resources)
118 (pop x-invocation-args)
119 (concat x-command-line-resources "\n" (pop x-invocation-args)))))
121 (declare-function x-parse-geometry "frame.c" (string))
123 ;; Handle the geometry option
124 (defun x-handle-geometry (_switch)
125 (let* ((geo (x-parse-geometry (pop x-invocation-args)))
126 (left (assq 'left geo))
127 (top (assq 'top geo))
128 (height (assq 'height geo))
129 (width (assq 'width geo)))
130 (if (or height width)
131 (setq default-frame-alist
132 (append default-frame-alist
133 '((user-size . t))
134 (if height (list height))
135 (if width (list width)))
136 initial-frame-alist
137 (append initial-frame-alist
138 '((user-size . t))
139 (if height (list height))
140 (if width (list width)))))
141 (if (or left top)
142 (setq initial-frame-alist
143 (append initial-frame-alist
144 '((user-position . t))
145 (if left (list left))
146 (if top (list top)))))))
148 (defvar x-resource-name)
150 ;; Handle the -name option. Set the variable x-resource-name
151 ;; to the option's operand; set the name of
152 ;; the initial frame, too.
153 (defun x-handle-name-switch (switch)
154 (or (consp x-invocation-args)
155 (error "%s: missing argument to `%s' option" (invocation-name) switch))
156 (setq x-resource-name (pop x-invocation-args)
157 initial-frame-alist (cons (cons 'name x-resource-name)
158 initial-frame-alist)))
160 (defvar x-display-name nil
161 "The name of the window display on which Emacs was started.
162 On X, the display name of individual X frames is recorded in the
163 `display' frame parameter.")
165 (defun x-handle-display (_switch)
166 "Handle -display DISPLAY option."
167 (setq x-display-name (pop x-invocation-args))
168 ;; Make subshell programs see the same DISPLAY value Emacs really uses.
169 ;; Note that this isn't completely correct, since Emacs can use
170 ;; multiple displays. However, there is no way to tell an already
171 ;; running subshell which display the user is currently typing on.
172 (setenv "DISPLAY" x-display-name))
174 (defun x-handle-args (args)
175 "Process the X (or Nextstep) related command line options in ARGS.
176 This is done before the user's startup file is loaded.
177 Copies the options in ARGS to `x-invocation-args'. It then extracts
178 the X (or Nextstep) options according to the handlers defined in
179 `command-line-x-option-alist' (or `command-line-ns-option-alist').
180 For example, `x-handle-switch' handles a switch like \"-fg\" and its
181 value \"black\". This function returns ARGS minus the arguments that
182 have been processed."
183 ;; We use ARGS to accumulate the args that we don't handle here, to return.
184 (setq x-invocation-args args ; FIXME let-bind?
185 args nil)
186 (while (and x-invocation-args
187 (not (equal (car x-invocation-args) "--")))
188 (let* ((this-switch (pop x-invocation-args))
189 (orig-this-switch this-switch)
190 (option-alist (if (featurep 'ns)
191 command-line-ns-option-alist
192 command-line-x-option-alist))
193 completion argval aelt handler)
194 ;; Check for long options with attached arguments
195 ;; and separate out the attached option argument into argval.
196 (if (string-match "^--[^=]*=" this-switch)
197 (setq argval (substring this-switch (match-end 0))
198 this-switch (substring this-switch 0 (1- (match-end 0)))))
199 ;; Complete names of long options.
200 (if (string-match "^--" this-switch)
201 (progn
202 (setq completion (try-completion this-switch option-alist))
203 (if (eq completion t)
204 ;; Exact match for long option.
206 (if (stringp completion)
207 (let ((elt (assoc completion option-alist)))
208 ;; Check for abbreviated long option.
209 (or elt
210 (error "Option `%s' is ambiguous" this-switch))
211 (setq this-switch completion))))))
212 (setq aelt (assoc this-switch option-alist))
213 (if aelt (setq handler (nth 2 aelt)))
214 (if handler
215 (if argval
216 (let ((x-invocation-args
217 (cons argval x-invocation-args)))
218 (funcall handler this-switch))
219 (funcall handler this-switch))
220 (setq args (cons orig-this-switch args)))))
221 (nconc (nreverse args) x-invocation-args))
225 ;; Available colors
227 ;; The ordering of the colors is chosen for the user's convenience in
228 ;; `list-colors-display', which displays the reverse of this list.
229 ;; Roughly speaking, `list-colors-display' orders by (i) named shades
230 ;; of gray with hue 0.0, sorted by value (ii) named colors with
231 ;; saturation 1.0, sorted by hue, (iii) named non-white colors with
232 ;; saturation less than 1.0, sorted by hue, (iv) other named shades of
233 ;; white, (v) numbered colors sorted by hue, and (vi) numbered shades
234 ;; of gray.
236 (declare-function ns-list-colors "nsfns.m" (&optional frame))
238 (defvar x-colors
239 (if (featurep 'ns) (ns-list-colors)
240 (purecopy
241 '("gray100" "grey100" "gray99" "grey99" "gray98" "grey98" "gray97"
242 "grey97" "gray96" "grey96" "gray95" "grey95" "gray94" "grey94"
243 "gray93" "grey93" "gray92" "grey92" "gray91" "grey91" "gray90"
244 "grey90" "gray89" "grey89" "gray88" "grey88" "gray87" "grey87"
245 "gray86" "grey86" "gray85" "grey85" "gray84" "grey84" "gray83"
246 "grey83" "gray82" "grey82" "gray81" "grey81" "gray80" "grey80"
247 "gray79" "grey79" "gray78" "grey78" "gray77" "grey77" "gray76"
248 "grey76" "gray75" "grey75" "gray74" "grey74" "gray73" "grey73"
249 "gray72" "grey72" "gray71" "grey71" "gray70" "grey70" "gray69"
250 "grey69" "gray68" "grey68" "gray67" "grey67" "gray66" "grey66"
251 "gray65" "grey65" "gray64" "grey64" "gray63" "grey63" "gray62"
252 "grey62" "gray61" "grey61" "gray60" "grey60" "gray59" "grey59"
253 "gray58" "grey58" "gray57" "grey57" "gray56" "grey56" "gray55"
254 "grey55" "gray54" "grey54" "gray53" "grey53" "gray52" "grey52"
255 "gray51" "grey51" "gray50" "grey50" "gray49" "grey49" "gray48"
256 "grey48" "gray47" "grey47" "gray46" "grey46" "gray45" "grey45"
257 "gray44" "grey44" "gray43" "grey43" "gray42" "grey42" "gray41"
258 "grey41" "gray40" "grey40" "gray39" "grey39" "gray38" "grey38"
259 "gray37" "grey37" "gray36" "grey36" "gray35" "grey35" "gray34"
260 "grey34" "gray33" "grey33" "gray32" "grey32" "gray31" "grey31"
261 "gray30" "grey30" "gray29" "grey29" "gray28" "grey28" "gray27"
262 "grey27" "gray26" "grey26" "gray25" "grey25" "gray24" "grey24"
263 "gray23" "grey23" "gray22" "grey22" "gray21" "grey21" "gray20"
264 "grey20" "gray19" "grey19" "gray18" "grey18" "gray17" "grey17"
265 "gray16" "grey16" "gray15" "grey15" "gray14" "grey14" "gray13"
266 "grey13" "gray12" "grey12" "gray11" "grey11" "gray10" "grey10"
267 "gray9" "grey9" "gray8" "grey8" "gray7" "grey7" "gray6" "grey6"
268 "gray5" "grey5" "gray4" "grey4" "gray3" "grey3" "gray2" "grey2"
269 "gray1" "grey1" "gray0" "grey0"
270 "LightPink1" "LightPink2" "LightPink3" "LightPink4"
271 "pink1" "pink2" "pink3" "pink4"
272 "PaleVioletRed1" "PaleVioletRed2" "PaleVioletRed3" "PaleVioletRed4"
273 "LavenderBlush1" "LavenderBlush2" "LavenderBlush3" "LavenderBlush4"
274 "VioletRed1" "VioletRed2" "VioletRed3" "VioletRed4"
275 "HotPink1" "HotPink2" "HotPink3" "HotPink4"
276 "DeepPink1" "DeepPink2" "DeepPink3" "DeepPink4"
277 "maroon1" "maroon2" "maroon3" "maroon4"
278 "orchid1" "orchid2" "orchid3" "orchid4"
279 "plum1" "plum2" "plum3" "plum4"
280 "thistle1" "thistle2" "thistle3" "thistle4"
281 "MediumOrchid1" "MediumOrchid2" "MediumOrchid3" "MediumOrchid4"
282 "DarkOrchid1" "DarkOrchid2" "DarkOrchid3" "DarkOrchid4"
283 "purple1" "purple2" "purple3" "purple4"
284 "MediumPurple1" "MediumPurple2" "MediumPurple3" "MediumPurple4"
285 "SlateBlue1" "SlateBlue2" "SlateBlue3" "SlateBlue4"
286 "RoyalBlue1" "RoyalBlue2" "RoyalBlue3" "RoyalBlue4"
287 "LightSteelBlue1" "LightSteelBlue2" "LightSteelBlue3" "LightSteelBlue4"
288 "SlateGray1" "SlateGray2" "SlateGray3" "SlateGray4"
289 "DodgerBlue1" "DodgerBlue2" "DodgerBlue3" "DodgerBlue4"
290 "SteelBlue1" "SteelBlue2" "SteelBlue3" "SteelBlue4"
291 "SkyBlue1" "SkyBlue2" "SkyBlue3" "SkyBlue4"
292 "LightSkyBlue1" "LightSkyBlue2" "LightSkyBlue3" "LightSkyBlue4"
293 "LightBlue1" "LightBlue2" "LightBlue3" "LightBlue4"
294 "CadetBlue1" "CadetBlue2" "CadetBlue3" "CadetBlue4"
295 "azure1" "azure2" "azure3" "azure4"
296 "LightCyan1" "LightCyan2" "LightCyan3" "LightCyan4"
297 "PaleTurquoise1" "PaleTurquoise2" "PaleTurquoise3" "PaleTurquoise4"
298 "DarkSlateGray1" "DarkSlateGray2" "DarkSlateGray3" "DarkSlateGray4"
299 "aquamarine1" "aquamarine2" "aquamarine3" "aquamarine4"
300 "SeaGreen1" "SeaGreen2" "SeaGreen3" "SeaGreen4"
301 "honeydew1" "honeydew2" "honeydew3" "honeydew4"
302 "DarkSeaGreen1" "DarkSeaGreen2" "DarkSeaGreen3" "DarkSeaGreen4"
303 "PaleGreen1" "PaleGreen2" "PaleGreen3" "PaleGreen4"
304 "DarkOliveGreen1" "DarkOliveGreen2" "DarkOliveGreen3" "DarkOliveGreen4"
305 "OliveDrab1" "OliveDrab2" "OliveDrab3" "OliveDrab4"
306 "ivory1" "ivory2" "ivory3" "ivory4"
307 "LightYellow1" "LightYellow2" "LightYellow3" "LightYellow4"
308 "khaki1" "khaki2" "khaki3" "khaki4"
309 "LemonChiffon1" "LemonChiffon2" "LemonChiffon3" "LemonChiffon4"
310 "LightGoldenrod1" "LightGoldenrod2" "LightGoldenrod3" "LightGoldenrod4"
311 "cornsilk1" "cornsilk2" "cornsilk3" "cornsilk4"
312 "goldenrod1" "goldenrod2" "goldenrod3" "goldenrod4"
313 "DarkGoldenrod1" "DarkGoldenrod2" "DarkGoldenrod3" "DarkGoldenrod4"
314 "wheat1" "wheat2" "wheat3" "wheat4"
315 "NavajoWhite1" "NavajoWhite2" "NavajoWhite3" "NavajoWhite4"
316 "burlywood1" "burlywood2" "burlywood3" "burlywood4"
317 "AntiqueWhite1" "AntiqueWhite2" "AntiqueWhite3" "AntiqueWhite4"
318 "bisque1" "bisque2" "bisque3" "bisque4"
319 "tan1" "tan2" "tan3" "tan4"
320 "PeachPuff1" "PeachPuff2" "PeachPuff3" "PeachPuff4"
321 "seashell1" "seashell2" "seashell3" "seashell4"
322 "chocolate1" "chocolate2" "chocolate3" "chocolate4"
323 "sienna1" "sienna2" "sienna3" "sienna4"
324 "LightSalmon1" "LightSalmon2" "LightSalmon3" "LightSalmon4"
325 "salmon1" "salmon2" "salmon3" "salmon4"
326 "coral1" "coral2" "coral3" "coral4"
327 "tomato1" "tomato2" "tomato3" "tomato4"
328 "MistyRose1" "MistyRose2" "MistyRose3" "MistyRose4"
329 "snow1" "snow2" "snow3" "snow4"
330 "RosyBrown1" "RosyBrown2" "RosyBrown3" "RosyBrown4"
331 "IndianRed1" "IndianRed2" "IndianRed3" "IndianRed4"
332 "firebrick1" "firebrick2" "firebrick3" "firebrick4"
333 "brown1" "brown2" "brown3" "brown4"
334 "magenta1" "magenta2" "magenta3" "magenta4"
335 "blue1" "blue2" "blue3" "blue4"
336 "DeepSkyBlue1" "DeepSkyBlue2" "DeepSkyBlue3" "DeepSkyBlue4"
337 "turquoise1" "turquoise2" "turquoise3" "turquoise4"
338 "cyan1" "cyan2" "cyan3" "cyan4"
339 "SpringGreen1" "SpringGreen2" "SpringGreen3" "SpringGreen4"
340 "green1" "green2" "green3" "green4"
341 "chartreuse1" "chartreuse2" "chartreuse3" "chartreuse4"
342 "yellow1" "yellow2" "yellow3" "yellow4"
343 "gold1" "gold2" "gold3" "gold4"
344 "orange1" "orange2" "orange3" "orange4"
345 "DarkOrange1" "DarkOrange2" "DarkOrange3" "DarkOrange4"
346 "OrangeRed1" "OrangeRed2" "OrangeRed3" "OrangeRed4"
347 "red1" "red2" "red3" "red4"
348 "lavender blush" "LavenderBlush" "ghost white" "GhostWhite"
349 "lavender" "alice blue" "AliceBlue" "azure" "light cyan"
350 "LightCyan" "mint cream" "MintCream" "honeydew" "ivory"
351 "light goldenrod yellow" "LightGoldenrodYellow" "light yellow"
352 "LightYellow" "beige" "floral white" "FloralWhite" "old lace"
353 "OldLace" "blanched almond" "BlanchedAlmond" "moccasin"
354 "papaya whip" "PapayaWhip" "bisque" "antique white"
355 "AntiqueWhite" "linen" "peach puff" "PeachPuff" "seashell"
356 "misty rose" "MistyRose" "snow" "light pink" "LightPink" "pink"
357 "hot pink" "HotPink" "deep pink" "DeepPink" "maroon"
358 "pale violet red" "PaleVioletRed" "violet red" "VioletRed"
359 "medium violet red" "MediumVioletRed" "violet" "plum" "thistle"
360 "orchid" "medium orchid" "MediumOrchid" "dark orchid"
361 "DarkOrchid" "purple" "blue violet" "BlueViolet" "medium purple"
362 "MediumPurple" "light slate blue" "LightSlateBlue"
363 "medium slate blue" "MediumSlateBlue" "slate blue" "SlateBlue"
364 "dark slate blue" "DarkSlateBlue" "midnight blue" "MidnightBlue"
365 "navy" "navy blue" "NavyBlue" "dark blue" "DarkBlue"
366 "light steel blue" "LightSteelBlue" "cornflower blue"
367 "CornflowerBlue" "dodger blue" "DodgerBlue" "royal blue"
368 "RoyalBlue" "light slate gray" "light slate grey"
369 "LightSlateGray" "LightSlateGrey" "slate gray" "slate grey"
370 "SlateGray" "SlateGrey" "dark slate gray" "dark slate grey"
371 "DarkSlateGray" "DarkSlateGrey" "steel blue" "SteelBlue"
372 "cadet blue" "CadetBlue" "light sky blue" "LightSkyBlue"
373 "sky blue" "SkyBlue" "light blue" "LightBlue" "powder blue"
374 "PowderBlue" "pale turquoise" "PaleTurquoise" "turquoise"
375 "medium turquoise" "MediumTurquoise" "dark turquoise"
376 "DarkTurquoise" "dark cyan" "DarkCyan" "aquamarine"
377 "medium aquamarine" "MediumAquamarine" "light sea green"
378 "LightSeaGreen" "medium sea green" "MediumSeaGreen" "sea green"
379 "SeaGreen" "dark sea green" "DarkSeaGreen" "pale green"
380 "PaleGreen" "lime green" "LimeGreen" "dark green" "DarkGreen"
381 "forest green" "ForestGreen" "light green" "LightGreen"
382 "green yellow" "GreenYellow" "yellow green" "YellowGreen"
383 "olive drab" "OliveDrab" "dark olive green" "DarkOliveGreen"
384 "lemon chiffon" "LemonChiffon" "khaki" "dark khaki" "DarkKhaki"
385 "cornsilk" "pale goldenrod" "PaleGoldenrod" "light goldenrod"
386 "LightGoldenrod" "goldenrod" "dark goldenrod" "DarkGoldenrod"
387 "wheat" "navajo white" "NavajoWhite" "tan" "burlywood"
388 "sandy brown" "SandyBrown" "peru" "chocolate" "saddle brown"
389 "SaddleBrown" "sienna" "rosy brown" "RosyBrown" "dark salmon"
390 "DarkSalmon" "coral" "tomato" "light salmon" "LightSalmon"
391 "salmon" "light coral" "LightCoral" "indian red" "IndianRed"
392 "firebrick" "brown" "dark red" "DarkRed" "magenta"
393 "dark magenta" "DarkMagenta" "dark violet" "DarkViolet"
394 "medium blue" "MediumBlue" "blue" "deep sky blue" "DeepSkyBlue"
395 "cyan" "medium spring green" "MediumSpringGreen" "spring green"
396 "SpringGreen" "green" "lawn green" "LawnGreen" "chartreuse"
397 "yellow" "gold" "orange" "dark orange" "DarkOrange" "orange red"
398 "OrangeRed" "red" "white" "white smoke" "WhiteSmoke" "gainsboro"
399 "light gray" "light grey" "LightGray" "LightGrey" "gray" "grey"
400 "dark gray" "dark grey" "DarkGray" "DarkGrey" "dim gray"
401 "dim grey" "DimGray" "DimGrey" "black")))
402 "List of basic colors available on color displays.
403 For X, the list comes from the `rgb.txt' file,v 10.41 94/02/20.
404 For Nextstep, this is a list of non-PANTONE colors returned by
405 the operating system.")
407 (defvar w32-color-map)
409 (defun xw-defined-colors (&optional frame)
410 "Internal function called by `defined-colors', which see."
411 (if (featurep 'ns)
412 x-colors
413 (or frame (setq frame (selected-frame)))
414 (let (defined-colors)
415 (dolist (this-color (if (eq system-type 'windows-nt)
416 (or (mapcar 'car w32-color-map) x-colors)
417 x-colors))
418 (and (color-supported-p this-color frame t)
419 (setq defined-colors (cons this-color defined-colors))))
420 defined-colors)))
422 (provide 'term/common-win)
424 ;;; common-win.el ends here