Commit | Line | Data |
---|---|---|
092af6d8 | 1 | ;;; pc-win.el --- setup support for `PC windows' (whatever that is). |
ef88bd2d | 2 | |
e2f35ede | 3 | ;; Copyright (C) 1994, 1996, 1997 Free Software Foundation, Inc. |
ef88bd2d MW |
4 | |
5 | ;; Author: Morten Welinder <terra@diku.dk> | |
9596811a | 6 | ;; Maintainer: FSF |
ef88bd2d MW |
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 | |
2fe590dc EN |
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 | ;;; Code: | |
26 | ||
ef88bd2d MW |
27 | (load "term/internal" nil t) |
28 | ||
ec46c6e8 RS |
29 | ;; Color translation -- doesn't really need to be fast. |
30 | ;; Colors listed here do not include the "light-", | |
31 | ;; "medium-" and "dark-" prefixes that are accounted for | |
32 | ;; by `msdos-color-translate', which see below). | |
ef88bd2d MW |
33 | |
34 | (defvar msdos-color-aliases | |
ec46c6e8 RS |
35 | '(("snow" . "white") |
36 | ("ghost white" . "white") | |
37 | ("ghostwhite" . "white") | |
38 | ("white smoke" . "white") | |
39 | ("whitesmoke" . "white") | |
40 | ("gainsboro" . "white") | |
41 | ("floral white" . "white") | |
42 | ("floralwhite" . "white") | |
43 | ("old lace" . "white") | |
44 | ("oldlace" . "white") | |
45 | ("linen" . "white") | |
46 | ("antique white" . "white") | |
47 | ("antiquewhite" . "white") | |
48 | ("papaya whip" . "white") | |
49 | ("papayawhip" . "white") | |
50 | ("blanched almond" . "white") | |
51 | ("blanchedalmond" . "white") | |
52 | ("bisque" . "white") | |
53 | ("peach puff" . "lightred") | |
54 | ("peachpuff" . "lightred") | |
55 | ("navajo white" . "lightred") | |
56 | ("navajowhite" . "lightred") | |
57 | ("moccasin" . "lightred") | |
58 | ("cornsilk" . "white") | |
59 | ("ivory" . "white") | |
60 | ("lemon chiffon" . "yellow") | |
61 | ("lemonchiffon" . "yellow") | |
62 | ("seashell" . "white") | |
63 | ("honeydew" . "white") | |
64 | ("mint cream" . "white") | |
65 | ("mintcream" . "white") | |
66 | ("azure" . "lightcyan") | |
67 | ("alice blue" . "lightcyan") | |
68 | ("aliceblue" . "lightcyan") | |
69 | ("lavender" . "lightcyan") | |
70 | ("lavender blush" . "lightcyan") | |
71 | ("lavenderblush" . "lightcyan") | |
72 | ("misty rose" . "lightred") | |
73 | ("mistyrose" . "lightred") | |
74 | ("aquamarine" . "blue") | |
75 | ("cadet blue" . "blue") | |
76 | ("cadetblue" . "blue") | |
77 | ("cornflower blue" . "lightblue") | |
78 | ("cornflowerblue" . "lightblue") | |
79 | ("midnight blue" . "blue") | |
80 | ("midnightblue" . "blue") | |
81 | ("navy blue" . "cyan") | |
82 | ("navyblue" . "cyan") | |
83 | ("navy" . "cyan") | |
9de91fc5 EZ |
84 | ("royalblue" . "blue") |
85 | ("royal blue" . "blue") | |
ec46c6e8 RS |
86 | ("sky blue" . "lightblue") |
87 | ("skyblue" . "lightblue") | |
88 | ("dodger blue" . "blue") | |
89 | ("dodgerblue" . "blue") | |
90 | ("powder blue" . "lightblue") | |
91 | ("powderblue" . "lightblue") | |
92 | ("slate blue" . "cyan") | |
93 | ("slateblue" . "cyan") | |
94 | ("steel blue" . "blue") | |
95 | ("steelblue" . "blue") | |
96 | ("coral" . "lightred") | |
9de91fc5 | 97 | ("tomato" . "lightred") |
ec46c6e8 RS |
98 | ("firebrick" . "red") |
99 | ("gold" . "yellow") | |
100 | ("goldenrod" . "yellow") | |
9de91fc5 EZ |
101 | ("goldenrod yellow" . "yellow") |
102 | ("goldenrodyellow" . "yellow") | |
ec46c6e8 RS |
103 | ("pale goldenrod" . "yellow") |
104 | ("palegoldenrod" . "yellow") | |
105 | ("olive green" . "lightgreen") | |
106 | ("olivegreen" . "lightgreen") | |
107 | ("olive drab" . "green") | |
108 | ("olivedrab" . "green") | |
109 | ("forest green" . "green") | |
110 | ("forestgreen" . "green") | |
111 | ("lime green" . "lightgreen") | |
112 | ("limegreen" . "lightgreen") | |
113 | ("sea green" . "lightcyan") | |
114 | ("seagreen" . "lightcyan") | |
115 | ("spring green" . "green") | |
116 | ("springgreen" . "green") | |
ec46c6e8 RS |
117 | ("lawn green" . "lightgreen") |
118 | ("lawngreen" . "lightgreen") | |
119 | ("chartreuse" . "yellow") | |
120 | ("yellow green" . "lightgreen") | |
121 | ("yellowgreen" . "lightgreen") | |
122 | ("green yellow" . "lightgreen") | |
123 | ("greenyellow" . "lightgreen") | |
124 | ("slate grey" . "lightgray") | |
125 | ("slategrey" . "lightgray") | |
126 | ("slate gray" . "lightgray") | |
127 | ("slategray" . "lightgray") | |
128 | ("dim grey" . "darkgray") | |
129 | ("dimgrey" . "darkgray") | |
130 | ("dim gray" . "darkgray") | |
131 | ("dimgray" . "darkgray") | |
132 | ("light grey" . "lightgray") | |
133 | ("lightgrey" . "lightgray") | |
134 | ("light gray" . "lightgray") | |
135 | ("gray" . "darkgray") | |
136 | ("grey" . "darkgray") | |
ec46c6e8 RS |
137 | ("khaki" . "green") |
138 | ("maroon" . "red") | |
139 | ("orange" . "brown") | |
140 | ("orchid" . "brown") | |
141 | ("saddle brown" . "red") | |
142 | ("saddlebrown" . "red") | |
ec46c6e8 | 143 | ("peru" . "red") |
9de91fc5 EZ |
144 | ("burlywood" . "brown") |
145 | ("sandy brown" . "brown") | |
146 | ("sandybrown" . "brown") | |
ec46c6e8 | 147 | ("pink" . "lightred") |
9de91fc5 EZ |
148 | ("hotpink" . "lightred") |
149 | ("hot pink" ."lightred") | |
ec46c6e8 RS |
150 | ("plum" . "magenta") |
151 | ("indian red" . "red") | |
152 | ("indianred" . "red") | |
153 | ("violet red" . "magenta") | |
154 | ("violetred" . "magenta") | |
155 | ("orange red" . "red") | |
156 | ("orangered" . "red") | |
157 | ("salmon" . "lightred") | |
158 | ("sienna" . "lightred") | |
159 | ("tan" . "lightred") | |
9de91fc5 | 160 | ("chocolate" . "brown") |
ec46c6e8 RS |
161 | ("thistle" . "magenta") |
162 | ("turquoise" . "lightgreen") | |
163 | ("pale turquoise" . "cyan") | |
164 | ("paleturquoise" . "cyan") | |
165 | ("violet" . "magenta") | |
166 | ("blue violet" . "lightmagenta") | |
167 | ("blueviolet" . "lightmagenta") | |
168 | ("wheat" . "white") | |
169 | ("green yellow" . "yellow") | |
170 | ("greenyellow" . "yellow") | |
171 | ("purple" . "magenta") | |
ec46c6e8 RS |
172 | ("rosybrown" . "brown") |
173 | ("rosy brown" . "brown") | |
174 | ("beige" . "brown")) | |
ef88bd2d MW |
175 | "List of alternate names for colors.") |
176 | ||
177 | (defun msdos-color-translate (name) | |
178 | (setq name (downcase name)) | |
179 | (let* ((len (length name)) | |
bb3a4574 RS |
180 | (val (- (length x-colors) |
181 | (length (member name x-colors)))) | |
ef88bd2d | 182 | (try)) |
bb3a4574 | 183 | (if (or (< val 0) (>= val (length x-colors))) (setq val nil)) |
ef88bd2d MW |
184 | (or val |
185 | (and (setq try (cdr (assoc name msdos-color-aliases))) | |
186 | (msdos-color-translate try)) | |
187 | (and (> len 5) | |
ec46c6e8 | 188 | (string= "light" (substring name 0 5)) |
ef88bd2d MW |
189 | (setq try (msdos-color-translate (substring name 5))) |
190 | (logior try 8)) | |
191 | (and (> len 6) | |
ec46c6e8 | 192 | (string= "light " (substring name 0 6)) |
ef88bd2d MW |
193 | (setq try (msdos-color-translate (substring name 6))) |
194 | (logior try 8)) | |
9de91fc5 EZ |
195 | (and (> len 4) |
196 | (string= "pale" (substring name 0 4)) | |
197 | (setq try (msdos-color-translate (substring name 4))) | |
198 | (logior try 8)) | |
199 | (and (> len 5) | |
200 | (string= "pale " (substring name 0 5)) | |
201 | (setq try (msdos-color-translate (substring name 5))) | |
202 | (logior try 8)) | |
ec46c6e8 RS |
203 | (and (> len 6) |
204 | (string= "medium" (substring name 0 6)) | |
205 | (msdos-color-translate (substring name 6))) | |
206 | (and (> len 7) | |
207 | (string= "medium " (substring name 0 7)) | |
208 | (msdos-color-translate (substring name 7))) | |
ef88bd2d | 209 | (and (> len 4) |
9de91fc5 EZ |
210 | (or (string= "dark" (substring name 0 4)) |
211 | (string= "deep" (substring name 0 4))) | |
ef88bd2d MW |
212 | (msdos-color-translate (substring name 4))) |
213 | (and (> len 5) | |
9de91fc5 EZ |
214 | (or (string= "dark " (substring name 0 5)) |
215 | (string= "deep " (substring name 0 5))) | |
c13c88d7 RS |
216 | (msdos-color-translate (substring name 5))) |
217 | (and (> len 4) ;; gray shades: gray0 to gray100 | |
218 | (save-match-data | |
219 | (and | |
220 | (string-match "gr[ae]y[0-9]" name) | |
221 | (string-match "[0-9]+\\'" name) | |
222 | (let ((num (string-to-int | |
223 | (substring name (match-beginning 0))))) | |
224 | (msdos-color-translate | |
225 | (cond | |
226 | ((> num 90) "white") | |
227 | ((> num 50) "lightgray") | |
228 | ((> num 10) "darkgray") | |
229 | (t "black"))))))) | |
230 | (and (> len 1) ;; purple1 to purple4 and the like | |
231 | (save-match-data | |
232 | (and | |
233 | (string-match "[1-4]\\'" name) | |
234 | (msdos-color-translate | |
235 | (substring name 0 (match-beginning 0))))))))) | |
ef88bd2d MW |
236 | ;; --------------------------------------------------------------------------- |
237 | ;; We want to delay setting frame parameters until the faces are setup | |
238 | (defvar default-frame-alist nil) | |
9000684d | 239 | (modify-frame-parameters terminal-frame default-frame-alist) |
ef88bd2d | 240 | |
e2f35ede RS |
241 | (defun msdos-bg-mode (&optional frame) |
242 | (let* ((frame (or frame (selected-frame))) | |
243 | (params (frame-parameters frame)) | |
244 | (bg (cdr (assq 'background-color params)))) | |
245 | (if (member bg '("black" "blue" "darkgray" "green")) | |
246 | 'dark | |
247 | 'light))) | |
248 | ||
ef88bd2d | 249 | (defun msdos-face-setup () |
9000684d | 250 | (modify-frame-parameters terminal-frame default-frame-alist) |
ef88bd2d | 251 | |
c13c88d7 RS |
252 | (modify-frame-parameters terminal-frame |
253 | (list (cons 'background-mode | |
254 | (msdos-bg-mode terminal-frame)) | |
255 | (cons 'display-type 'color))) | |
256 | (face-set-after-frame-default terminal-frame) | |
257 | ||
9000684d RS |
258 | (set-face-foreground 'bold "yellow" terminal-frame) |
259 | (set-face-foreground 'italic "red" terminal-frame) | |
260 | (set-face-foreground 'bold-italic "lightred" terminal-frame) | |
261 | (set-face-foreground 'underline "white" terminal-frame) | |
ef88bd2d MW |
262 | |
263 | (make-face 'msdos-menu-active-face) | |
264 | (make-face 'msdos-menu-passive-face) | |
265 | (make-face 'msdos-menu-select-face) | |
9000684d RS |
266 | (set-face-foreground 'msdos-menu-active-face "white" terminal-frame) |
267 | (set-face-foreground 'msdos-menu-passive-face "lightgray" terminal-frame) | |
268 | (set-face-background 'msdos-menu-active-face "blue" terminal-frame) | |
269 | (set-face-background 'msdos-menu-passive-face "blue" terminal-frame) | |
c13c88d7 | 270 | (set-face-background 'msdos-menu-select-face "red" terminal-frame)) |
ef88bd2d MW |
271 | |
272 | ;; We have only one font, so... | |
273 | (add-hook 'before-init-hook 'msdos-face-setup) | |
9000684d RS |
274 | |
275 | ;; We create frames as if we were a terminal, but with a twist. | |
276 | (defun make-msdos-frame (&optional parameters) | |
e2f35ede RS |
277 | (let* ((parms |
278 | (append initial-frame-alist default-frame-alist parameters nil)) | |
279 | (frame (make-terminal-frame parms))) | |
280 | (modify-frame-parameters frame | |
281 | (list (cons 'background-mode | |
282 | (msdos-bg-mode frame)) | |
283 | (cons 'display-type 'color))) | |
284 | frame)) | |
9000684d RS |
285 | |
286 | (setq frame-creation-function 'make-msdos-frame) | |
287 | ||
ef88bd2d | 288 | ;; --------------------------------------------------------------------------- |
a7acbbe4 | 289 | ;; More or less useful imitations of certain X-functions. A lot of the |
ef88bd2d MW |
290 | ;; values returned are questionable, but usually only the form of the |
291 | ;; returned value matters. Also, by the way, recall that `ignore' is | |
292 | ;; a useful function for returning 'nil regardless of argument. | |
293 | ||
294 | ;; From src/xfns.c | |
beb4ba68 | 295 | (defun x-display-color-p (&optional display) 't) |
cee30b8f RS |
296 | (defun x-list-fonts (pattern &optional face frame maximum width) |
297 | (if (and (numberp width) (= width 1)) | |
298 | (list "default") | |
299 | (list "no-such-font"))) | |
ef88bd2d | 300 | (defun x-color-defined-p (color) (numberp (msdos-color-translate color))) |
a259d337 RS |
301 | (defun x-display-pixel-width (&optional frame) (frame-width frame)) |
302 | (defun x-display-pixel-height (&optional frame) (frame-height frame)) | |
ef88bd2d MW |
303 | (defun x-display-planes (&optional frame) 4) ; 3 for background, actually |
304 | (defun x-display-color-cells (&optional frame) 16) ; ??? | |
305 | (defun x-server-max-request-size (&optional frame) 1000000) ; ??? | |
306 | (defun x-server-vendor (&optional frame) t "GNU") | |
307 | (defun x-server-version (&optional frame) '(1 0 0)) | |
308 | (defun x-display-screens (&optional frame) 1) | |
309 | (defun x-display-mm-height (&optional frame) 200) ; Guess the size of my | |
310 | (defun x-display-mm-width (&optional frame) 253) ; monitor, MW... | |
311 | (defun x-display-backing-store (&optional frame) 'not-useful) | |
312 | (defun x-display-visual-class (&optional frame) 'static-color) | |
313 | (fset 'x-display-save-under 'ignore) | |
314 | (fset 'x-get-resource 'ignore) | |
315 | ||
316 | ;; From lisp/term/x-win.el | |
317 | (setq x-display-name "pc") | |
318 | (setq split-window-keep-point t) | |
bb3a4574 RS |
319 | (defvar x-colors '("black" |
320 | "blue" | |
321 | "green" | |
322 | "cyan" | |
323 | "red" | |
324 | "magenta" | |
325 | "brown" | |
326 | "lightgray" | |
327 | "darkgray" | |
328 | "lightblue" | |
329 | "lightgreen" | |
330 | "lightcyan" | |
331 | "lightred" | |
332 | "lightmagenta" | |
333 | "yellow" | |
334 | "white") | |
335 | "The list of colors available on a PC display under MS-DOS.") | |
336 | (defun x-defined-colors (&optional frame) | |
337 | "Return a list of colors supported for a particular frame. | |
338 | The argument FRAME specifies which frame to try. | |
339 | The value may be different for frames on different X displays." | |
340 | x-colors) | |
c432c362 EZ |
341 | |
342 | ;; From lisp/term/win32-win.el | |
343 | ; | |
344 | ;;;; Selections and cut buffers | |
bb3a4574 | 345 | ; |
c432c362 EZ |
346 | ;;; We keep track of the last text selected here, so we can check the |
347 | ;;; current selection against it, and avoid passing back our own text | |
348 | ;;; from x-cut-buffer-or-selection-value. | |
349 | (defvar x-last-selected-text nil) | |
350 | ||
351 | (defvar x-select-enable-clipboard t | |
352 | "Non-nil means cutting and pasting uses the clipboard. | |
353 | This is in addition to the primary selection.") | |
354 | ||
355 | (defun x-select-text (text &optional push) | |
356 | (if x-select-enable-clipboard | |
357 | (win16-set-clipboard-data text)) | |
358 | (setq x-last-selected-text text)) | |
359 | ||
360 | ;;; Return the value of the current selection. | |
361 | ;;; Consult the selection, then the cut buffer. Treat empty strings | |
362 | ;;; as if they were unset. | |
363 | (defun x-get-selection-value () | |
364 | (if x-select-enable-clipboard | |
365 | (let (text) | |
366 | ;; Don't die if x-get-selection signals an error. | |
367 | (condition-case c | |
368 | (setq text (win16-get-clipboard-data)) | |
369 | (error (message "win16-get-clipboard-data:%s" c))) | |
370 | (if (string= text "") (setq text nil)) | |
371 | (cond | |
372 | ((not text) nil) | |
373 | ((eq text x-last-selected-text) nil) | |
374 | ((string= text x-last-selected-text) | |
375 | ;; Record the newer string, so subsequent calls can use the 'eq' test. | |
376 | (setq x-last-selected-text text) | |
377 | nil) | |
378 | (t | |
379 | (setq x-last-selected-text text)))))) | |
380 | ||
381 | ;;; Arrange for the kill and yank functions to set and check the clipboard. | |
382 | (setq interprogram-cut-function 'x-select-text) | |
383 | (setq interprogram-paste-function 'x-get-selection-value) | |
ef88bd2d | 384 | |
ea6401d7 RS |
385 | ;; From lisp/faces.el: we only have one font, so always return |
386 | ;; it, no matter which variety they've asked for. | |
387 | (defun x-frob-font-slant (font which) | |
388 | font) | |
389 | ||
cee30b8f RS |
390 | ;; From src/fontset.c: |
391 | (fset 'query-fontset 'ignore) | |
392 | ||
e1ddc4b4 RS |
393 | ;; From lisp/term/x-win.el: make iconify-or-deiconify-frame a no-op. |
394 | (fset 'iconify-or-deiconify-frame 'ignore) | |
395 | ||
ef88bd2d MW |
396 | ;; From lisp/frame.el |
397 | (fset 'set-default-font 'ignore) | |
398 | (fset 'set-mouse-color 'ignore) ; We cannot, I think. | |
399 | (fset 'set-cursor-color 'ignore) ; Hardware determined by char under. | |
400 | (fset 'set-border-color 'ignore) ; Not useful. | |
c8a6e3b9 EZ |
401 | |
402 | ;; From lisp/term/x-win.el: | |
403 | (defconst x-long-option-alist | |
404 | '(("--name" . "-name") | |
405 | ("--title" . "-T") | |
406 | ("--reverse-video" . "-reverse") | |
407 | ("--foreground-color" . "-fg") | |
408 | ("--background-color" . "-bg"))) | |
ef88bd2d | 409 | ;; --------------------------------------------------------------------------- |
c8a6e3b9 | 410 | ;; Handle the X-like command line parameters "-fg", "-bg", "-name", etc. |
ef88bd2d MW |
411 | (defun msdos-handle-args (args) |
412 | (let ((rest nil)) | |
c8a6e3b9 | 413 | (message "%s" args) |
ef88bd2d | 414 | (while args |
c8a6e3b9 EZ |
415 | (let* ((this (car args)) |
416 | (orig-this this) | |
417 | completion argval) | |
ef88bd2d | 418 | (setq args (cdr args)) |
c8a6e3b9 EZ |
419 | ;; Check for long options with attached arguments |
420 | ;; and separate out the attached option argument into argval. | |
421 | (if (string-match "^--[^=]*=" this) | |
422 | (setq argval (substring this (match-end 0)) | |
423 | this (substring this 0 (1- (match-end 0))))) | |
424 | (setq completion (try-completion this x-long-option-alist)) | |
425 | (if (eq completion t) | |
426 | ;; Exact match for long option. | |
427 | (setq this (cdr (assoc this x-long-option-alist))) | |
428 | (if (stringp completion) | |
429 | (let ((elt (assoc completion x-long-option-alist))) | |
430 | ;; Check for abbreviated long option. | |
431 | (or elt | |
432 | (error "Option `%s' is ambiguous" this)) | |
433 | (setq this (cdr elt))) | |
434 | ;; Check for a short option. | |
435 | (setq argval nil this orig-this))) | |
ef88bd2d | 436 | (cond ((or (string= this "-fg") (string= this "-foreground")) |
c8a6e3b9 EZ |
437 | (or argval (setq argval (car args) args (cdr args))) |
438 | (setq default-frame-alist | |
439 | (cons (cons 'foreground-color argval) | |
440 | default-frame-alist))) | |
ef88bd2d | 441 | ((or (string= this "-bg") (string= this "-background")) |
c8a6e3b9 EZ |
442 | (or argval (setq argval (car args) args (cdr args))) |
443 | (setq default-frame-alist | |
444 | (cons (cons 'background-color argval) | |
445 | default-frame-alist))) | |
446 | ((or (string= this "-T") (string= this "-name")) | |
447 | (or argval (setq argval (car args) args (cdr args))) | |
448 | (setq default-frame-alist | |
449 | (cons | |
450 | (cons 'title | |
451 | (if (stringp argval) | |
452 | argval | |
453 | (let ((case-fold-search t) | |
454 | i) | |
455 | (setq argval (invocation-name)) | |
456 | ||
457 | ;; Change any . or * characters in name to | |
458 | ;; hyphens, so as to emulate behavior on X. | |
459 | (while | |
460 | (setq i (string-match "[.*]" argval)) | |
461 | (aset argval i ?-)) | |
462 | argval))) | |
463 | default-frame-alist))) | |
464 | ((or (string= this "-r") | |
465 | (string= this "-rv") | |
466 | (string= this "-reverse")) | |
467 | (setq default-frame-alist | |
468 | (cons '(reverse . t) | |
469 | default-frame-alist))) | |
ef88bd2d | 470 | (t (setq rest (cons this rest)))))) |
c8a6e3b9 | 471 | (nreverse rest))) |
ef88bd2d MW |
472 | |
473 | (setq command-line-args (msdos-handle-args command-line-args)) | |
474 | ;; --------------------------------------------------------------------------- | |
092af6d8 RS |
475 | |
476 | ;;; pc-win.el ends here |