startup.el 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. ;; Process Emacs shell arguments
  2. ;; Copyright (C) 1985, 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. ; These are processed only at the beginning of the argument list.
  18. ; -batch execute noninteractively (messages go to stdout,
  19. ; variable noninteractive set to t)
  20. ; This option must be the first in the arglist.
  21. ; Processed by `main' in emacs.c -- never seen by lisp
  22. ; -t file Specify to use file rather than stdin/stdout
  23. ; as the terminal.
  24. ; This option must be the first in the arglist.
  25. ; Processed by `main' in emacs.c -- never seen by lisp
  26. ; -nw Inhibit the use of any window-system-specific display
  27. ; code; use the current virtual terminal.
  28. ; This option must be the first in the arglist.
  29. ; Processed by `main' in emacs.c -- never seen by lisp
  30. ; -q load no init file
  31. ; -no-init-file same
  32. ; -u user load user's init file
  33. ; -user user same
  34. ; These are processed in the order encountered.
  35. ; -f function execute function
  36. ; -funcall function same
  37. ; -l file load file
  38. ; -load file same
  39. ; -i file insert file into buffer
  40. ; -insert file same
  41. ; file visit file
  42. ; -kill kill (exit) emacs
  43. (setq top-level '(normal-top-level))
  44. (defvar command-line-processed nil "t once command line has been processed")
  45. (defconst inhibit-startup-message nil
  46. "*Non-nil inhibits the initial startup messages.
  47. This is for use in your personal init file, once you are familiar
  48. with the contents of the startup message.")
  49. (defconst inhibit-default-init nil
  50. "*Non-nil inhibits loading the `default' library.")
  51. (defconst command-switch-alist nil
  52. "Alist of command-line switches.
  53. Elements look like (SWITCH-STRING . HANDLER-FUNCTION).
  54. HANDLER-FUNCTION receives switch name as sole arg;
  55. remaining command-line args are in the variable `args'.")
  56. (defvar term-setup-hook nil)
  57. (defconst initial-major-mode 'lisp-interaction-mode
  58. "Major mode command symbol to use for the initial *scratch* buffer.")
  59. (defun normal-top-level ()
  60. (if command-line-processed
  61. (message "Back to top level.")
  62. (setq command-line-processed t)
  63. (unwind-protect
  64. (command-line)
  65. (and term-setup-hook
  66. (funcall term-setup-hook)))))
  67. (defun command-line ()
  68. (let ((args (cdr command-line-args))
  69. (user (if noninteractive
  70. nil
  71. (or (getenv "USER")
  72. (getenv "LOGNAME")))) ;USG bletcherousness.
  73. done)
  74. (while (and (not done) args)
  75. (let ((argi (car args)))
  76. (if (or (string-equal argi "-q")
  77. (string-equal argi "-no-init-file"))
  78. (setq user nil
  79. args (cdr args))
  80. (if (or (string-equal argi "-u")
  81. (string-equal argi "-user"))
  82. (setq args (cdr args)
  83. user (car args)
  84. args (cdr args))
  85. (setq done t)))))
  86. ;; Load user's init file, or load default one.
  87. (condition-case error
  88. (if user
  89. (progn (load (if (eq system-type 'vax-vms)
  90. "sys$login:.emacs"
  91. (concat "~" user "/.emacs"))
  92. t t t)
  93. (or inhibit-default-init
  94. (let (inhibit-startup-message)
  95. ;; Users are supposed to be told their rights.
  96. ;; (Plus how to get help and how to undo.)
  97. ;; Don't you dare turn this off for anyone
  98. ;; except yourself.
  99. (load "default" t t)))))
  100. (error (message "Error in init file")))
  101. (if (get-buffer "*scratch*")
  102. (save-excursion
  103. (set-buffer "*scratch*")
  104. (funcall initial-major-mode)))
  105. ;; Load library for our terminal type.
  106. ;; User init file can set term-file-prefix to nil to prevent this.
  107. (and term-file-prefix (not noninteractive)
  108. (load (if window-system
  109. (concat term-file-prefix
  110. (symbol-name window-system)
  111. "-win")
  112. (concat term-file-prefix
  113. (substring (getenv "TERM") 0
  114. (string-match "-" (getenv "TERM")))))
  115. t t))
  116. (command-line-1 args)
  117. (if noninteractive (kill-emacs t))))
  118. (defun command-line-1 (command-line-args-left)
  119. (if (null command-line-args-left)
  120. (cond ((and (not inhibit-startup-message) (not noninteractive)
  121. (not (input-pending-p)))
  122. ;; If there are no switches to procss, we might as well
  123. ;; run this hook now, and there may be some need to do it
  124. ;; before doing any output.
  125. (and term-setup-hook
  126. (funcall term-setup-hook))
  127. ;; Don't let the hook be run twice.
  128. (setq term-setup-hook nil)
  129. (unwind-protect
  130. (progn
  131. (insert (emacs-version)
  132. "
  133. Copyright (C) 1987 Free Software Foundation, Inc.\n")
  134. ;; If keys have their default meanings,
  135. ;; use precomputed string to save lots of time.
  136. (if (and (eq (key-binding "\C-h") 'help-command)
  137. (eq (key-binding "\C-xu") 'advertised-undo)
  138. (eq (key-binding "\C-h\C-c") 'describe-copying)
  139. (eq (key-binding "\C-h\C-d") 'describe-distribution)
  140. (eq (key-binding "\C-h\C-w") 'describe-no-warranty)
  141. (eq (key-binding "\C-ht") 'help-with-tutorial))
  142. (insert
  143. "Type C-h for help; C-x u to undo changes. (`C-' means use CTRL key.)
  144. GNU Emacs comes with ABSOLUTELY NO WARRANTY; type C-h C-w for full details.
  145. You may give out copies of Emacs; type C-h C-c to see the conditions.
  146. Type C-h C-d for information on getting the latest version.
  147. Type C-h t for a tutorial on using Emacs.")
  148. (insert (substitute-command-keys
  149. "Type \\[help-command] for help; \\[advertised-undo] to undo changes. (`C-' means use CTRL key.)
  150. GNU Emacs comes with ABSOLUTELY NO WARRANTY; type \\[describe-no-warranty] for full details.
  151. You may give out copies of Emacs; type \\[describe-copying] to see the conditions.
  152. Type \\[describe-distribution] for information on getting the latest version.
  153. Type \\[help-with-tutorial] for a tutorial on using Emacs.")))
  154. (set-buffer-modified-p nil)
  155. (sit-for 120))
  156. (erase-buffer)
  157. (set-buffer-modified-p nil))))
  158. (let ((dir default-directory)
  159. (line 0))
  160. (while command-line-args-left
  161. (let ((argi (car command-line-args-left))
  162. tem)
  163. (setq command-line-args-left (cdr command-line-args-left))
  164. (cond ((setq tem (assoc argi command-switch-alist))
  165. (funcall (cdr tem) argi))
  166. ((or (string-equal argi "-f") ;what the manual claims
  167. (string-equal argi "-funcall")
  168. (string-equal argi "-e")) ; what the source used to say
  169. (setq tem (intern (car command-line-args-left)))
  170. (setq command-line-args-left (cdr command-line-args-left))
  171. (funcall tem))
  172. ((or (string-equal argi "-l")
  173. (string-equal argi "-load"))
  174. (let ((load-path (cons default-directory load-path)))
  175. (load (car command-line-args-left) nil t))
  176. (setq command-line-args-left (cdr command-line-args-left)))
  177. ((or (string-equal argi "-i")
  178. (string-equal argi "-insert"))
  179. (insert-file-contents (car command-line-args-left))
  180. (setq command-line-args-left (cdr command-line-args-left)))
  181. ((string-equal argi "-kill")
  182. (kill-emacs t))
  183. ((string-match "^\\+[0-9]+\\'" argi)
  184. (setq line (string-to-int argi)))
  185. (t
  186. (find-file (expand-file-name argi dir))
  187. (goto-line line)
  188. (setq line 0))))))))