|
|
1.1 ! root 1: ;; Parse switches controlling how Emacs interfaces with X window system. ! 2: ;; Copyright (C) 1986, 1988 Free Software Foundation, Inc. ! 3: ! 4: ;; This file is part of GNU Emacs. ! 5: ! 6: ;; GNU Emacs is free software; you can redistribute it and/or modify ! 7: ;; it under the terms of the GNU General Public License as published by ! 8: ;; the Free Software Foundation; either version 1, or (at your option) ! 9: ;; any later version. ! 10: ! 11: ;; GNU Emacs is distributed in the hope that it will be useful, ! 12: ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ! 13: ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ! 14: ;; GNU General Public License for more details. ! 15: ! 16: ;; You should have received a copy of the GNU General Public License ! 17: ;; along with GNU Emacs; see the file COPYING. If not, write to ! 18: ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. ! 19: ! 20: (defconst window-system-version window-system-version ! 21: "*Window system version number now in use.") ! 22: ! 23: (defvar x-sigio-bug nil ! 24: "Non-NIL means don't use interrupts for input when using X.") ! 25: ! 26: (defvar x-processed-defaults nil ! 27: "Non-NIL means that user's X defaults have already been processed.") ! 28: ! 29: (defvar x-switches nil ! 30: "Alist of command switches and values for X window system interface. ! 31: You can set this in your init file, if you want some defaults ! 32: for these switches. Example: ! 33: (setq x-switches '((\"-r\" . t) (\"-font\" . \"foo\") (\"-b\" . \"8\"))) ! 34: This feature is currently broken for X11.") ! 35: ! 36: (if (= window-system-version 10) ! 37: (setq command-switch-alist ! 38: (append '(("-r" . x-handle-switch) ! 39: ("-i" . x-handle-switch) ! 40: ("-font" . x-handle-switch) ! 41: ("-w" . x-handle-switch) ! 42: ("-b" . x-handle-switch) ! 43: ("-ib" . x-handle-switch) ! 44: ("-fg" . x-handle-switch) ! 45: ("-bg" . x-handle-switch) ! 46: ("-bd" . x-handle-switch) ! 47: ("-cr" . x-handle-switch) ! 48: ("-ms" . x-handle-switch)) ! 49: command-switch-alist)) ! 50: (setq command-switch-alist ! 51: (append '(("-rn" . x-ignore-arg) ! 52: ("-xrm" . x-ignore-arg) ! 53: ("-r" . ignore) ! 54: ("-i" . ignore) ! 55: ("-rn" . x-ignore-arg) ! 56: ("-font" . x-ignore-arg) ! 57: ("-fn" . x-ignore-arg) ! 58: ("-wn" . x-ignore-arg) ! 59: ("-in" . x-ignore-arg) ! 60: ("-w" . x-ignore-arg) ! 61: ("-geometry" . x-ignore-arg) ! 62: ("-b" . x-ignore-arg) ! 63: ("-ib" . x-ignore-arg) ! 64: ("-fg" . x-ignore-arg) ! 65: ("-bg" . x-ignore-arg) ! 66: ("-bd" . x-ignore-arg) ! 67: ("-cr" . x-ignore-arg) ! 68: ("-ms" . x-ignore-arg)) ! 69: command-switch-alist))) ! 70: ! 71: (defun x-ignore-arg (&rest ignore) ! 72: (setq command-line-args-left (cdr command-line-args-left))) ! 73: ! 74: ;; This is run after the command args are parsed. ! 75: (defun x-handle-switch (switch) ! 76: (if (x-handle-switch-1 switch (car command-line-args-left)) ! 77: (setq command-line-args-left (cdr command-line-args-left)))) ! 78: ! 79: (defun x-handle-switch-1 (switch arg) ! 80: (cond ((string= switch "-r") ! 81: (x-flip-color) ! 82: nil) ! 83: ((string= switch "-i") ! 84: (x-set-icon t) ! 85: nil) ! 86: ((string= switch "-font") ! 87: (x-set-font arg) ! 88: t) ! 89: ((string= switch "-b") ! 90: (x-set-border-width (string-to-int arg)) ! 91: t) ! 92: ((string= switch "-ib") ! 93: (x-set-internal-border-width (string-to-int arg)) ! 94: t) ! 95: ((string= switch "-w") ! 96: (x-create-x-window arg) ! 97: t) ! 98: ((string= switch "-fg") ! 99: (x-set-foreground-color arg) ! 100: t) ! 101: ((string= switch "-bg") ! 102: (x-set-background-color arg) ! 103: t) ! 104: ((string= switch "-bd") ! 105: (x-set-border-color arg) ! 106: t) ! 107: ((string= switch "-cr") ! 108: (x-set-cursor-color arg) ! 109: t) ! 110: ((string= switch "-ms") ! 111: (x-set-mouse-color arg) ! 112: t))) ! 113: ! 114: ;; Convert a string of the form "WWxHH+XO+YO", ! 115: ;; where WW, HH, XO and YO are numerals, ! 116: ;; into a list (WW HH XO YO). ! 117: ;; "xHH" may be omitted; then 0 is used for HH. ! 118: ;; XO and YO may be preceded by - instead of + to make them negative. ! 119: ;; Either YO or both XO and YO may be omitted; zero is used. ! 120: (defun x-parse-edge-spec (arg) ! 121: (let ((cols-by-font 0) ! 122: (rows-by-font 0) ! 123: (xoffset 0) ! 124: (yoffset 0)) ! 125: (if (string-match "^=" arg) ! 126: (setq cols-by-font (x-extract-number)) ! 127: (error "Invalid X window size/position spec")) ! 128: (if (string-match "^x" arg) ;get rows-by-font ! 129: (setq rows-by-font (x-extract-number))) ! 130: (if (string-match "^[-+]" arg) ! 131: (setq xoffset (x-extract-number))) ! 132: (if (string-match "^[-+]" arg) ! 133: (setq yoffset (x-extract-number))) ! 134: (or (equal arg "") ! 135: (error "Invalid X window size/position spec")) ! 136: (list cols-by-font rows-by-font xoffset yoffset))) ! 137: ! 138: ;; Subroutine to extract the next numeral from the front of arg, ! 139: ;; returning it and shortening arg to remove its text. ! 140: ;; If arg is negative, subtract 1 before returning it. ! 141: (defun x-extract-number () ! 142: (if (string-match "^[x=]" arg) ! 143: (setq arg (substring arg 1))) ! 144: (or (string-match "[-+]?[0-9]+" arg) ! 145: (error "Invalid X window size/position spec")) ! 146: (prog1 ! 147: (+ (string-to-int arg) ! 148: (if (string-match "^-" arg) -1 0)) ! 149: (setq arg ! 150: (substring arg ! 151: (or (string-match "[^0-9]" arg 1) ! 152: (length arg)))))) ! 153: ! 154: (defun x-get-default-args () ! 155: (setq x-processed-defaults t) ! 156: (let (value) ! 157: (if (not (string= (setq value (x-get-default "bodyfont")) "")) ! 158: (x-handle-switch-1 "-font" value)) ! 159: (if (string-match "on" (x-get-default "bitmapicon")) ! 160: (x-handle-switch-1 "-i" t)) ! 161: (if (not (string= (setq value (x-get-default "borderwidth")) "")) ! 162: (x-handle-switch-1 "-b" value)) ! 163: (if (not (string= (setq value (x-get-default "internalborder")) "")) ! 164: (x-handle-switch-1 "-ib" value)) ! 165: (if (not (string= (setq value (x-get-default "foreground")) "")) ! 166: (x-handle-switch-1 "-fg" value)) ! 167: (if (not (string= (setq value (x-get-default "background")) "")) ! 168: (x-handle-switch-1 "-bg" value)) ! 169: (if (not (string= (setq value (x-get-default "border")) "")) ! 170: (x-handle-switch-1 "-bd" value)) ! 171: (if (not (string= (setq value (x-get-default "cursor")) "")) ! 172: (x-handle-switch-1 "-cr" value)) ! 173: (if (not (string= (setq value (x-get-default "mouse")) "")) ! 174: (x-handle-switch-1 "-ms" value)) ! 175: (if (string-match "on" (x-get-default "reversevideo")) ! 176: (x-handle-switch-1 "-r" t)))) ! 177: ! 178: ;; So far we have only defined some functions. ! 179: ;; Now we start processing X-related switches ! 180: ;; and redefining commands and variables, ! 181: ;; only if Emacs has been compiled to support direct interface to X. ! 182: ! 183: (if (eq window-system 'x) ! 184: (progn ! 185: (require 'x-mouse) ! 186: (if (= window-system-version 10) ! 187: (progn ! 188: ;; xterm.c depends on using interrupt-driven input. ! 189: (set-input-mode t nil) ! 190: ! 191: (defun x-new-display (display) ! 192: "This function takes one argument, the display where you wish to ! 193: continue your editing session. Your current window will be unmapped and ! 194: the current display will be closed. The new X display will be opened and ! 195: the rubber-band outline of the new window will appear on the new X display." ! 196: (interactive "sDisplay to switch emacs to: ") ! 197: (x-change-display display) ! 198: (x-get-default-args)) ! 199: ! 200: ;; Not defvar! This is not DEFINING this variable, just specifying ! 201: ;; a value for it. ! 202: (setq window-setup-hook 'x-pop-up-window) ! 203: ! 204: ;; Process switch settings made by .emacs file. ! 205: (while x-switches ! 206: (x-handle-switch-1 (car (car x-switches)) (cdr (car x-switches))) ! 207: (setq x-switches (cdr x-switches))))) ! 208: ! 209: ;; On certain systems, turn off use of sigio, because it's broken. ! 210: (if x-sigio-bug ! 211: (set-input-mode nil nil)) ! 212: ! 213: (put 'suspend-emacs 'disabled ! 214: "Suspending a program running in an X window is silly ! 215: and you would not be able to start it again. Just switch windows instead.\n") ! 216: (setq suspend-hook '(lambda () (error "Suspending an emacs running under X makes no sense"))) ! 217: (substitute-key-definition 'suspend-emacs nil global-map) ! 218: (substitute-key-definition 'suspend-emacs nil esc-map) ! 219: (substitute-key-definition 'suspend-emacs nil ctl-x-map) ! 220: ;; Not needed any more -- done in C. ! 221: ;; (if (not x-processed-defaults) (x-get-default-args)) ! 222: ))
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.