x-win.el 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. ;; Parse switches controlling how Emacs interfaces with X window system.
  2. ;; Copyright (C) 1986 Free Software Foundation, Inc.
  3. ;; This file is part of GNU Emacs.
  4. ;; GNU Emacs is distributed in the hope that it will be useful,
  5. ;; but WITHOUT ANY WARRANTY. No author or distributor
  6. ;; accepts responsibility to anyone for the consequences of using it
  7. ;; or for whether it serves any particular purpose or works at all,
  8. ;; unless he says so in writing. Refer to the GNU Emacs General Public
  9. ;; License for full details.
  10. ;; Everyone is granted permission to copy, modify and redistribute
  11. ;; GNU Emacs, but only under the conditions described in the
  12. ;; GNU Emacs General Public License. A copy of this license is
  13. ;; supposed to have been given to you along with GNU Emacs so you
  14. ;; can know your rights and responsibilities. It should be in a
  15. ;; file named COPYING. Among other things, the copyright notice
  16. ;; and this notice must be preserved on all copies.
  17. (defvar x-processed-defaults nil
  18. "Non-NIL means that user's X defaults have already been processed.")
  19. (defvar x-switches nil
  20. "Alist of command switches and values for X window system interface.
  21. You can set this in your init file, if you want some defaults
  22. for these switches. Example:
  23. (setq x-switches '((\"-r\" . t) (\"-font\" . \"foo\") (\"-b\" . \"8\")))")
  24. (setq command-switch-alist
  25. (append '(("-r" . x-handle-switch)
  26. ("-i" . x-handle-switch)
  27. ("-font" . x-handle-switch)
  28. ("-w" . x-handle-switch)
  29. ("-b" . x-handle-switch)
  30. ("-ib" . x-handle-switch)
  31. ("-fg" . x-handle-switch)
  32. ("-bg" . x-handle-switch)
  33. ("-bd" . x-handle-switch)
  34. ("-cr" . x-handle-switch)
  35. ("-ms" . x-handle-switch))
  36. command-switch-alist))
  37. ;; This is run after the command args are parsed.
  38. (defun x-handle-switch (switch)
  39. (if (x-handle-switch-1 switch (car command-line-args-left))
  40. (setq command-line-args-left (cdr command-line-args-left))))
  41. (defun x-handle-switch-1 (switch arg)
  42. (cond ((string= switch "-r")
  43. (x-flip-color)
  44. nil)
  45. ((string= switch "-i")
  46. (x-set-icon t)
  47. nil)
  48. ((string= switch "-font")
  49. (x-set-font arg)
  50. t)
  51. ((string= switch "-b")
  52. (x-set-border-width (string-to-int arg))
  53. t)
  54. ((string= switch "-ib")
  55. (x-set-internal-border-width (string-to-int arg))
  56. t)
  57. ((string= switch "-w")
  58. (x-create-x-window arg)
  59. t)
  60. ((string= switch "-fg")
  61. (x-set-foreground-color arg)
  62. t)
  63. ((string= switch "-bg")
  64. (x-set-background-color arg)
  65. t)
  66. ((string= switch "-bd")
  67. (x-set-border-color arg)
  68. t)
  69. ((string= switch "-cr")
  70. (x-set-cursor-color arg)
  71. t)
  72. ((string= switch "-ms")
  73. (x-set-mouse-color arg)
  74. t)))
  75. ;; Convert a string of the form "WWxHH+XO+YO",
  76. ;; where WW, HH, XO and YO are numerals,
  77. ;; into a list (WW HH XO YO).
  78. ;; "xHH" may be omitted; then 0 is used for HH.
  79. ;; XO and YO may be preceded by - instead of + to make them negative.
  80. ;; Either YO or both XO and YO may be omitted; zero is used.
  81. (defun x-parse-edge-spec (arg)
  82. (let ((cols-by-font 0)
  83. (rows-by-font 0)
  84. (xoffset 0)
  85. (yoffset 0))
  86. (if (string-match "^=" arg)
  87. (setq cols-by-font (x-extract-number))
  88. (error "Invalid X window size/position spec"))
  89. (if (string-match "^x" arg) ;get rows-by-font
  90. (setq rows-by-font (x-extract-number)))
  91. (if (string-match "^[-+]" arg)
  92. (setq xoffset (x-extract-number)))
  93. (if (string-match "^[-+]" arg)
  94. (setq yoffset (x-extract-number)))
  95. (or (equal arg "")
  96. (error "Invalid X window size/position spec"))
  97. (list cols-by-font rows-by-font xoffset yoffset)))
  98. ;; Subroutine to extract the next numeral from the front of arg,
  99. ;; returning it and shortening arg to remove its text.
  100. ;; If arg is negative, subtract 1 before returning it.
  101. (defun x-extract-number ()
  102. (if (string-match "^[x=]" arg)
  103. (setq arg (substring arg 1)))
  104. (or (string-match "[-+]?[0-9]+" arg)
  105. (error "Invalid X window size/position spec"))
  106. (prog1
  107. (+ (string-to-int arg)
  108. (if (string-match "^-" arg) -1 0))
  109. (setq arg
  110. (substring arg
  111. (or (string-match "[^0-9]" arg 1)
  112. (length arg))))))
  113. (defun x-get-default-args ()
  114. (setq x-processed-defaults t)
  115. (let (value)
  116. (if (not (string= (setq value (x-get-default "bodyfont")) ""))
  117. (x-handle-switch-1 "-font" value))
  118. (if (string-match "on" (x-get-default "bitmapicon"))
  119. (x-handle-switch-1 "-i" t))
  120. (if (not (string= (setq value (x-get-default "borderwidth")) ""))
  121. (x-handle-switch-1 "-b" value))
  122. (if (not (string= (setq value (x-get-default "internalborder")) ""))
  123. (x-handle-switch-1 "-ib" value))
  124. (if (not (string= (setq value (x-get-default "foreground")) ""))
  125. (x-handle-switch-1 "-fg" value))
  126. (if (not (string= (setq value (x-get-default "background")) ""))
  127. (x-handle-switch-1 "-bg" value))
  128. (if (not (string= (setq value (x-get-default "border")) ""))
  129. (x-handle-switch-1 "-bd" value))
  130. (if (not (string= (setq value (x-get-default "cursor")) ""))
  131. (x-handle-switch-1 "-cr" value))
  132. (if (not (string= (setq value (x-get-default "mouse")) ""))
  133. (x-handle-switch-1 "-ms" value))
  134. (if (string-match "on" (x-get-default "reversevideo"))
  135. (x-handle-switch-1 "-r" t))))
  136. (defun x-new-display (display)
  137. "This function takes one argument, the display where you wish to
  138. continue your editing session. Your current window will be unmapped and
  139. the current display will be closed. The new X display will be opened and
  140. the rubber-band outline of the new window will appear on the new X display."
  141. (interactive "sDisplay to switch emacs to: ")
  142. (x-change-display display)
  143. (x-get-default-args))
  144. ;; So far we have only defined some functions.
  145. ;; Now we start processing X-related switches
  146. ;; and redefining commands and variables,
  147. ;; only if Emacs has been compiled to support direct interface to X.
  148. (if (fboundp 'x-change-display)
  149. (progn
  150. ;; xterm.c depends on using interrupt-driven input.
  151. (set-input-mode t nil)
  152. ;; Not defvar! This is not DEFINING this variable, just specifying
  153. ;; a value for it.
  154. (setq term-setup-hook 'x-pop-up-window)
  155. (require 'x-mouse)
  156. (put 'suspend-emacs 'disabled
  157. "Suspending a program running in an X window is silly
  158. and you would not be able to start it again. Just switch windows instead.\n")
  159. (setq suspend-hook '(lambda () (error "Suspending an emacs running under X makes no sense")))
  160. (substitute-key-definition 'suspend-emacs nil global-map)
  161. (substitute-key-definition 'suspend-emacs nil esc-map)
  162. (substitute-key-definition 'suspend-emacs nil ctl-x-map)
  163. ;; Not needed any more -- done in C.
  164. ;; (if (not x-processed-defaults) (x-get-default-args))
  165. ;; Process switch settings made by .emacs file.
  166. (while x-switches
  167. (x-handle-switch-1 (car (car x-switches)) (cdr (car x-switches)))
  168. (setq x-switches (cdr x-switches)))))