(get_bss_info_from_map_file): New function.
[bpt/emacs.git] / lisp / term / w32-win.el
CommitLineData
ee78dc32
GV
1;;; win32-win.el --- parse switches controlling interface with win32
2;; Copyright (C) 1993, 1994 Free Software Foundation, Inc.
3
4;; Author: Kevin Gallo
5;; Keywords: terminals
6
7;;; This file is part of GNU Emacs.
8;;;
9;;; GNU Emacs is free software; you can redistribute it and/or modify
10;;; it under the terms of the GNU General Public License as published by
11;;; the Free Software Foundation; either version 2, or (at your option)
12;;; any later version.
13;;;
14;;; GNU Emacs is distributed in the hope that it will be useful,
15;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17;;; GNU General Public License for more details.
18;;;
19;;; You should have received a copy of the GNU General Public License
20;;; along with GNU Emacs; see the file COPYING. If not, write to
21;;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
22
23;;; Commentary:
24
25;; win32-win.el: this file is loaded from ../lisp/startup.el when it recognizes
26;; that win32 windows are to be used. Command line switches are parsed and those
27;; pertaining to win32 are processed and removed from the command line. The
28;; win32 display is opened and hooks are set for popping up the initial window.
29
30;; startup.el will then examine startup files, and eventually call the hooks
31;; which create the first window (s).
32
33;;; Code:
34\f
35
36;; These are the standard X switches from the Xt Initialize.c file of
37;; Release 4.
38
39;; Command line Resource Manager string
40
41;; +rv *reverseVideo
42;; +synchronous *synchronous
43;; -background *background
44;; -bd *borderColor
45;; -bg *background
46;; -bordercolor *borderColor
47;; -borderwidth .borderWidth
48;; -bw .borderWidth
49;; -display .display
50;; -fg *foreground
51;; -fn *font
52;; -font *font
53;; -foreground *foreground
54;; -geometry .geometry
55;; -i .iconType
56;; -itype .iconType
57;; -iconic .iconic
58;; -name .name
59;; -reverse *reverseVideo
60;; -rv *reverseVideo
61;; -selectionTimeout .selectionTimeout
62;; -synchronous *synchronous
63;; -xrm
64
65;; An alist of X options and the function which handles them. See
66;; ../startup.el.
67
68(if (not (eq window-system 'win32))
69 (error "%s: Loading win32-win.el but not compiled for win32" (invocation-name)))
70
71(require 'frame)
72(require 'mouse)
73(require 'scroll-bar)
74(require 'faces)
75(require 'select)
76(require 'menu-bar)
77
78(defvar x-invocation-args)
79
80(defvar x-command-line-resources nil)
81
82(defconst x-option-alist
83 '(("-bw" . x-handle-numeric-switch)
84 ("-d" . x-handle-display)
85 ("-display" . x-handle-display)
86 ("-name" . x-handle-name-rn-switch)
87 ("-rn" . x-handle-name-rn-switch)
88 ("-T" . x-handle-switch)
89 ("-r" . x-handle-switch)
90 ("-rv" . x-handle-switch)
91 ("-reverse" . x-handle-switch)
92 ("-fn" . x-handle-switch)
93 ("-font" . x-handle-switch)
94 ("-ib" . x-handle-numeric-switch)
95 ("-g" . x-handle-geometry)
96 ("-geometry" . x-handle-geometry)
97 ("-fg" . x-handle-switch)
98 ("-foreground". x-handle-switch)
99 ("-bg" . x-handle-switch)
100 ("-background". x-handle-switch)
101 ("-ms" . x-handle-switch)
102 ("-itype" . x-handle-switch)
103 ("-i" . x-handle-switch)
104 ("-iconic" . x-handle-iconic)
105 ("-xrm" . x-handle-xrm-switch)
106 ("-cr" . x-handle-switch)
107 ("-vb" . x-handle-switch)
108 ("-hb" . x-handle-switch)
109 ("-bd" . x-handle-switch)))
110
111(defconst x-long-option-alist
112 '(("--border-width" . "-bw")
113 ("--display" . "-d")
114 ("--name" . "-name")
115 ("--title" . "-T")
116 ("--reverse-video" . "-reverse")
117 ("--font" . "-font")
118 ("--internal-border" . "-ib")
119 ("--geometry" . "-geometry")
120 ("--foreground-color" . "-fg")
121 ("--background-color" . "-bg")
122 ("--mouse-color" . "-ms")
123 ("--icon-type" . "-itype")
124 ("--iconic" . "-iconic")
125 ("--xrm" . "-xrm")
126 ("--cursor-color" . "-cr")
127 ("--vertical-scroll-bars" . "-vb")
128 ("--border-color" . "-bd")))
129
130(defconst x-switch-definitions
131 '(("-name" name)
132 ("-T" name)
133 ("-r" reverse t)
134 ("-rv" reverse t)
135 ("-reverse" reverse t)
136 ("-fn" font)
137 ("-font" font)
138 ("-ib" internal-border-width)
139 ("-fg" foreground-color)
140 ("-foreground" foreground-color)
141 ("-bg" background-color)
142 ("-background" background-color)
143 ("-ms" mouse-color)
144 ("-cr" cursor-color)
145 ("-itype" icon-type t)
146 ("-i" icon-type t)
147 ("-vb" vertical-scroll-bars t)
148 ("-hb" horizontal-scroll-bars t)
149 ("-bd" border-color)
150 ("-bw" border-width)))
151
152;; Handler for switches of the form "-switch value" or "-switch".
153(defun x-handle-switch (switch)
154 (let ((aelt (assoc switch x-switch-definitions)))
155 (if aelt
156 (if (nth 2 aelt)
157 (setq default-frame-alist
158 (cons (cons (nth 1 aelt) (nth 2 aelt))
159 default-frame-alist))
160 (setq default-frame-alist
161 (cons (cons (nth 1 aelt)
162 (car x-invocation-args))
163 default-frame-alist)
164 x-invocation-args (cdr x-invocation-args))))))
165
166;; Make -iconic apply only to the initial frame!
167(defun x-handle-iconic (switch)
168 (setq initial-frame-alist
169 (cons '(visibility . icon) initial-frame-alist)))
170
171;; Handler for switches of the form "-switch n"
172(defun x-handle-numeric-switch (switch)
173 (let ((aelt (assoc switch x-switch-definitions)))
174 (if aelt
175 (setq default-frame-alist
176 (cons (cons (nth 1 aelt)
177 (string-to-int (car x-invocation-args)))
178 default-frame-alist)
179 x-invocation-args
180 (cdr x-invocation-args)))))
181
182;; Handle the -xrm option.
183(defun x-handle-xrm-switch (switch)
184 (or (consp x-invocation-args)
185 (error "%s: missing argument to `%s' option" (invocation-name) switch))
186 (setq x-command-line-resources (car x-invocation-args))
187 (setq x-invocation-args (cdr x-invocation-args)))
188
189;; Handle the geometry option
190(defun x-handle-geometry (switch)
191 (let ((geo (x-parse-geometry (car x-invocation-args))))
192 (setq initial-frame-alist
193 (append initial-frame-alist
194 (if (or (assq 'left geo) (assq 'top geo))
195 '((user-position . t)))
196 (if (or (assq 'height geo) (assq 'width geo))
197 '((user-size . t)))
198 geo)
199 x-invocation-args (cdr x-invocation-args))))
200
201;; Handle the -name and -rn options. Set the variable x-resource-name
202;; to the option's operand; if the switch was `-name', set the name of
203;; the initial frame, too.
204(defun x-handle-name-rn-switch (switch)
205 (or (consp x-invocation-args)
206 (error "%s: missing argument to `%s' option" (invocation-name) switch))
207 (setq x-resource-name (car x-invocation-args)
208 x-invocation-args (cdr x-invocation-args))
209 (if (string= switch "-name")
210 (setq initial-frame-alist (cons (cons 'name x-resource-name)
211 initial-frame-alist))))
212
213(defvar x-display-name nil
214 "The display name specifying server and frame.")
215
216(defun x-handle-display (switch)
217 (setq x-display-name (car x-invocation-args)
218 x-invocation-args (cdr x-invocation-args)))
219
220(defvar x-invocation-args nil)
221
222(defun x-handle-args (args)
223 "Process the X-related command line options in ARGS.
224This is done before the user's startup file is loaded. They are copied to
225x-invocation args from which the X-related things are extracted, first
226the switch (e.g., \"-fg\") in the following code, and possible values
227\(e.g., \"black\") in the option handler code (e.g., x-handle-switch).
228This returns ARGS with the arguments that have been processed removed."
229 (message "%s" args)
230 (setq x-invocation-args args
231 args nil)
232 (while x-invocation-args
233 (let* ((this-switch (car x-invocation-args))
234 (orig-this-switch this-switch)
235 completion argval aelt)
236 (setq x-invocation-args (cdr x-invocation-args))
237 ;; Check for long options with attached arguments
238 ;; and separate out the attached option argument into argval.
239 (if (string-match "^--[^=]*=" this-switch)
240 (setq argval (substring this-switch (match-end 0))
241 this-switch (substring this-switch 0 (1- (match-end 0)))))
242 (setq completion (try-completion this-switch x-long-option-alist))
243 (if (eq completion t)
244 ;; Exact match for long option.
245 (setq this-switch (cdr (assoc this-switch x-long-option-alist)))
246 (if (stringp completion)
247 (let ((elt (assoc completion x-long-option-alist)))
248 ;; Check for abbreviated long option.
249 (or elt
250 (error "Option `%s' is ambiguous" this-switch))
251 (setq this-switch (cdr elt)))
252 ;; Check for a short option.
253 (setq argval nil this-switch orig-this-switch)))
254 (setq aelt (assoc this-switch x-option-alist))
255 (if aelt
256 (if argval
257 (let ((x-invocation-args
258 (cons argval x-invocation-args)))
259 (funcall (cdr aelt) this-switch))
260 (funcall (cdr aelt) this-switch))
261 (setq args (cons this-switch args)))))
262 (setq args (nreverse args)))
263
264
265\f
266;;
267;; Available colors
268;;
269
270(defvar x-colors '("aquamarine"
271 "Aquamarine"
272 "medium aquamarine"
273 "MediumAquamarine"
274 "black"
275 "Black"
276 "blue"
277 "Blue"
278 "cadet blue"
279 "CadetBlue"
280 "cornflower blue"
281 "CornflowerBlue"
282 "dark slate blue"
283 "DarkSlateBlue"
284 "light blue"
285 "LightBlue"
286 "light steel blue"
287 "LightSteelBlue"
288 "medium blue"
289 "MediumBlue"
290 "medium slate blue"
291 "MediumSlateBlue"
292 "midnight blue"
293 "MidnightBlue"
294 "navy blue"
295 "NavyBlue"
296 "navy"
297 "Navy"
298 "sky blue"
299 "SkyBlue"
300 "slate blue"
301 "SlateBlue"
302 "steel blue"
303 "SteelBlue"
304 "coral"
305 "Coral"
306 "cyan"
307 "Cyan"
308 "firebrick"
309 "Firebrick"
310 "brown"
311 "Brown"
312 "gold"
313 "Gold"
314 "goldenrod"
315 "Goldenrod"
316 "green"
317 "Green"
318 "dark green"
319 "DarkGreen"
320 "dark olive green"
321 "DarkOliveGreen"
322 "forest green"
323 "ForestGreen"
324 "lime green"
325 "LimeGreen"
326 "medium sea green"
327 "MediumSeaGreen"
328 "medium spring green"
329 "MediumSpringGreen"
330 "pale green"
331 "PaleGreen"
332 "sea green"
333 "SeaGreen"
334 "spring green"
335 "SpringGreen"
336 "yellow green"
337 "YellowGreen"
338 "dark slate grey"
339 "DarkSlateGrey"
340 "dark slate gray"
341 "DarkSlateGray"
342 "dim grey"
343 "DimGrey"
344 "dim gray"
345 "DimGray"
346 "light grey"
347 "LightGrey"
348 "light gray"
349 "LightGray"
350 "gray"
351 "grey"
352 "Gray"
353 "Grey"
354 "khaki"
355 "Khaki"
356 "magenta"
357 "Magenta"
358 "maroon"
359 "Maroon"
360 "orange"
361 "Orange"
362 "orchid"
363 "Orchid"
364 "dark orchid"
365 "DarkOrchid"
366 "medium orchid"
367 "MediumOrchid"
368 "pink"
369 "Pink"
370 "plum"
371 "Plum"
372 "red"
373 "Red"
374 "indian red"
375 "IndianRed"
376 "medium violet red"
377 "MediumVioletRed"
378 "orange red"
379 "OrangeRed"
380 "violet red"
381 "VioletRed"
382 "salmon"
383 "Salmon"
384 "sienna"
385 "Sienna"
386 "tan"
387 "Tan"
388 "thistle"
389 "Thistle"
390 "turquoise"
391 "Turquoise"
392 "dark turquoise"
393 "DarkTurquoise"
394 "medium turquoise"
395 "MediumTurquoise"
396 "violet"
397 "Violet"
398 "blue violet"
399 "BlueViolet"
400 "wheat"
401 "Wheat"
402 "white"
403 "White"
404 "yellow"
405 "Yellow"
406 "green yellow"
407 "GreenYellow")
408 "The full list of X colors from the `rgb.text' file.")
409
410(defun x-defined-colors (&optional frame)
411 "Return a list of colors supported for a particular frame.
412The argument FRAME specifies which frame to try.
413The value may be different for frames on different X displays."
414 (or frame (setq frame (selected-frame)))
415 (let ((all-colors x-colors)
416 (this-color nil)
417 (defined-colors nil))
418 (while all-colors
419 (setq this-color (car all-colors)
420 all-colors (cdr all-colors))
421 (and (face-color-supported-p frame this-color t)
422 (setq defined-colors (cons this-color defined-colors))))
423 defined-colors))
424\f
425;;;; Function keys
426
427(defun iconify-or-deiconify-frame ()
428 "Iconify the selected frame, or deiconify if it's currently an icon."
429 (interactive)
430 (if (eq (cdr (assq 'visibility (frame-parameters))) t)
431 (iconify-frame)
432 (make-frame-visible)))
433
434(substitute-key-definition 'suspend-emacs 'iconify-or-deiconify-frame
435 global-map)
436
437;; Map certain keypad keys into ASCII characters
438;; that people usually expect.
439(define-key function-key-map [backspace] [127])
440(define-key function-key-map [delete] [127])
441(define-key function-key-map [tab] [?\t])
442(define-key function-key-map [linefeed] [?\n])
443(define-key function-key-map [clear] [11])
444(define-key function-key-map [return] [13])
445(define-key function-key-map [escape] [?\e])
446(define-key function-key-map [M-backspace] [?\M-\d])
447(define-key function-key-map [M-delete] [?\M-\d])
448(define-key function-key-map [M-tab] [?\M-\t])
449(define-key function-key-map [M-linefeed] [?\M-\n])
450(define-key function-key-map [M-clear] [?\M-\013])
451(define-key function-key-map [M-return] [?\M-\015])
452(define-key function-key-map [M-escape] [?\M-\e])
453
454;; These tell read-char how to convert
455;; these special chars to ASCII.
456(put 'backspace 'ascii-character 127)
457(put 'delete 'ascii-character 127)
458(put 'tab 'ascii-character ?\t)
459(put 'linefeed 'ascii-character ?\n)
460(put 'clear 'ascii-character 12)
461(put 'return 'ascii-character 13)
462(put 'escape 'ascii-character ?\e)
463
464\f
465;;;; Selections and cut buffers
466
467;;; We keep track of the last text selected here, so we can check the
468;;; current selection against it, and avoid passing back our own text
469;;; from x-cut-buffer-or-selection-value.
470(defvar x-last-selected-text nil)
471
472;;; It is said that overlarge strings are slow to put into the cut buffer.
473;;; Note this value is overridden below.
474(defvar x-cut-buffer-max 20000
475 "Max number of characters to put in the cut buffer.")
476
477(defvar x-select-enable-clipboard t
478 "Non-nil means cutting and pasting uses the clipboard.
479This is in addition to the primary selection.")
480
481(defun x-select-text (text &optional push)
482 (if x-select-enable-clipboard
483 (win32-set-clipboard-data text)))
484
485;;; Return the value of the current selection.
486;;; Consult the selection, then the cut buffer. Treat empty strings
487;;; as if they were unset.
488(defun x-get-selection-value ()
489 (if x-select-enable-clipboard
490 (let (text)
491 ;; Don't die if x-get-selection signals an error.
492 (condition-case c
493 (setq text (win32-get-clipboard-data))
494 (error (message "win32-get-clipboard-data:%s" c)))
495 (if (string= text "") (setq text nil))
496 text)))
497\f
498;;; Do the actual Windows setup here; the above code just defines
499;;; functions and variables that we use now.
500
501(setq command-line-args (x-handle-args command-line-args))
502
503;;; Make sure we have a valid resource name.
504(or (stringp x-resource-name)
505 (let (i)
506 (setq x-resource-name (invocation-name))
507
508 ;; Change any . or * characters in x-resource-name to hyphens,
509 ;; so as not to choke when we use it in X resource queries.
510 (while (setq i (string-match "[.*]" x-resource-name))
511 (aset x-resource-name i ?-))))
512
513;; For the benefit of older Emacses (19.27 and earlier) that are sharing
514;; the same lisp directory, don't pass the third argument unless we seem
515;; to have the multi-display support.
516(if (fboundp 'x-close-connection)
517 (x-open-connection ""
518 x-command-line-resources
519 ;; Exit Emacs with fatal error if this fails.
520 t)
521 (x-open-connection ""
522 x-command-line-resources))
523
524(setq frame-creation-function 'x-create-frame-with-faces)
525
526(setq x-cut-buffer-max (min (- (/ (x-server-max-request-size) 2) 100)
527 x-cut-buffer-max))
528
529;; Win32 expects the menu bar cut and paste commands to use the clipboard.
530;; This has ,? to match both on Sunos and on Solaris.
531(menu-bar-enable-clipboard)
532
533;; Apply a geometry resource to the initial frame. Put it at the end
534;; of the alist, so that anything specified on the command line takes
535;; precedence.
536(let* ((res-geometry (x-get-resource "geometry" "Geometry"))
537 parsed)
538 (if res-geometry
539 (progn
540 (setq parsed (x-parse-geometry res-geometry))
541 ;; If the resource specifies a position,
542 ;; call the position and size "user-specified".
543 (if (or (assq 'top parsed) (assq 'left parsed))
544 (setq parsed (cons '(user-position . t)
545 (cons '(user-size . t) parsed))))
546 ;; All geometry parms apply to the initial frame.
547 (setq initial-frame-alist (append initial-frame-alist parsed))
548 ;; The size parms apply to all frames.
549 (if (assq 'height parsed)
550 (setq default-frame-alist
551 (cons (cons 'height (cdr (assq 'height parsed)))
552 default-frame-alist)))
553 (if (assq 'width parsed)
554 (setq default-frame-alist
555 (cons (cons 'width (cdr (assq 'width parsed)))
556 default-frame-alist))))))
557
558;; Check the reverseVideo resource.
559(let ((case-fold-search t))
560 (let ((rv (x-get-resource "reverseVideo" "ReverseVideo")))
561 (if (and rv
562 (string-match "^\\(true\\|yes\\|on\\)$" rv))
563 (setq default-frame-alist
564 (cons '(reverse . t) default-frame-alist)))))
565
566;; Set x-selection-timeout, measured in milliseconds.
567(let ((res-selection-timeout
568 (x-get-resource "selectionTimeout" "SelectionTimeout")))
569 (setq x-selection-timeout 20000)
570 (if res-selection-timeout
571 (setq x-selection-timeout (string-to-number res-selection-timeout))))
572
573(defun x-win-suspend-error ()
574 (error "Suspending an emacs running under Win32 makes no sense"))
575(add-hook 'suspend-hook 'x-win-suspend-error)
576
577;;; Arrange for the kill and yank functions to set and check the clipboard.
578(setq interprogram-cut-function 'x-select-text)
579(setq interprogram-paste-function 'x-get-selection-value)
580
581;;; Turn off window-splitting optimization; win32 is usually fast enough
582;;; that this is only annoying.
583(setq split-window-keep-point t)
584
585;; Don't show the frame name; that's redundant.
586(setq-default mode-line-buffer-identification '("Emacs: %12b"))
587
588;;; Set to a system sound if you want a fancy bell.
589(set-message-beep 'ok)
590
591;; Remap some functions to call win32 common dialogs
592
593(defun internal-face-interactive (what &optional bool)
594 (let* ((fn (intern (concat "face-" what)))
595 (prompt (concat "Set " what " of face"))
596 (face (read-face-name (concat prompt ": ")))
597 (default (if (fboundp fn)
598 (or (funcall fn face (selected-frame))
599 (funcall fn 'default (selected-frame)))))
600 (fn-win (intern (concat (symbol-name window-system) "-select-" what)))
601 (value
602 (if (fboundp fn-win)
603 (funcall fn-win)
604 (if bool
605 (y-or-n-p (concat "Should face " (symbol-name face)
606 " be " bool "? "))
607 (read-string (concat prompt " " (symbol-name face) " to: ")
608 default)))))
609 (list face (if (equal value "") nil value))))
610
611;; Redefine the font selection to use the Win32 dialog
612
613(defun mouse-set-font (&rest fonts)
614 (interactive)
615 (set-default-font (win32-select-font)))
616
617;;; win32-win.el ends here