1 ;;; startup.el --- process Emacs shell arguments
3 ;; Copyright (C) 1985, 1986, 1992, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
4 ;; 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
28 ;; This file parses the command line and gets Emacs running. Options
29 ;; on the command line are handled in precedence order. For priorities
30 ;; see the structure standard_args in the emacs.c file.
34 (setq top-level
'(normal-top-level))
36 (defvar command-line-processed nil
37 "Non-nil once command line has been processed.")
39 (defvar window-system initial-window-system
40 "Name of window system the selected frame is displaying through.
41 The value is a symbol--for instance, `x' for X windows.
42 The value is nil if the selected frame is on a text-only-terminal.")
44 (make-variable-frame-local 'window-system
)
46 (defgroup initialization nil
47 "Emacs start-up procedure."
50 (defcustom inhibit-splash-screen nil
51 "Non-nil inhibits the startup screen.
52 It also inhibits display of the initial message in the *scratch* buffer.
54 This is for use in your personal init file, once you are familiar
55 with the contents of the startup screen."
57 :group
'initialization
)
59 (defvaralias 'inhibit-startup-message
'inhibit-splash-screen
)
61 (defcustom inhibit-startup-echo-area-message nil
62 "*Non-nil inhibits the initial startup echo area message.
63 Setting this variable takes effect
64 only if you do it with the customization buffer
65 or if your `.emacs' file contains a line of this form:
66 (setq inhibit-startup-echo-area-message \"YOUR-USER-NAME\")
67 If your `.emacs' file is byte-compiled, use the following form instead:
68 (eval '(setq inhibit-startup-echo-area-message \"YOUR-USER-NAME\"))
69 Thus, someone else using a copy of your `.emacs' file will see
70 the startup message unless he personally acts to inhibit it."
71 :type
'(choice (const :tag
"Don't inhibit")
72 (string :tag
"Enter your user name, to inhibit"))
73 :group
'initialization
)
75 (defcustom inhibit-default-init nil
76 "*Non-nil inhibits loading the `default' library."
78 :group
'initialization
)
80 (defcustom inhibit-startup-buffer-menu nil
81 "*Non-nil inhibits display of buffer list when more than 2 files are loaded."
83 :group
'initialization
)
85 (defvar command-switch-alist nil
86 "Alist of command-line switches.
87 Elements look like (SWITCH-STRING . HANDLER-FUNCTION).
88 HANDLER-FUNCTION receives the switch string as its sole argument;
89 the remaining command-line args are in the variable `command-line-args-left'.")
91 (defvar command-line-args-left nil
92 "List of command-line args not yet processed.")
94 (defvar command-line-functions nil
;; lrs 7/31/89
95 "List of functions to process unrecognized command-line arguments.
96 Each function should access the dynamically bound variables
97 `argi' (the current argument) and `command-line-args-left' (the remaining
98 arguments). The function should return non-nil only if it recognizes and
99 processes `argi'. If it does so, it may consume successive arguments by
100 altering `command-line-args-left' to remove them.")
102 (defvar command-line-default-directory nil
103 "Default directory to use for command line arguments.
104 This is normally copied from `default-directory' when Emacs starts.")
106 ;;; This is here, rather than in x-win.el, so that we can ignore these
107 ;;; options when we are not using X.
108 (defconst command-line-x-option-alist
109 '(("-bw" 1 x-handle-numeric-switch border-width
)
110 ("-d" 1 x-handle-display
)
111 ("-display" 1 x-handle-display
)
112 ("-name" 1 x-handle-name-switch
)
113 ("-title" 1 x-handle-switch title
)
114 ("-T" 1 x-handle-switch title
)
115 ("-r" 0 x-handle-switch reverse t
)
116 ("-rv" 0 x-handle-switch reverse t
)
117 ("-reverse" 0 x-handle-switch reverse t
)
118 ("-reverse-video" 0 x-handle-switch reverse t
)
119 ("-fn" 1 x-handle-switch font
)
120 ("-font" 1 x-handle-switch font
)
121 ("-fs" 0 x-handle-initial-switch fullscreen fullboth
)
122 ("-fw" 0 x-handle-initial-switch fullscreen fullwidth
)
123 ("-fh" 0 x-handle-initial-switch fullscreen fullheight
)
124 ("-ib" 1 x-handle-numeric-switch internal-border-width
)
125 ("-g" 1 x-handle-geometry
)
126 ("-lsp" 1 x-handle-numeric-switch line-spacing
)
127 ("-geometry" 1 x-handle-geometry
)
128 ("-fg" 1 x-handle-switch foreground-color
)
129 ("-foreground" 1 x-handle-switch foreground-color
)
130 ("-bg" 1 x-handle-switch background-color
)
131 ("-background" 1 x-handle-switch background-color
)
132 ("-ms" 1 x-handle-switch mouse-color
)
133 ("-nbi" 0 x-handle-switch icon-type nil
)
134 ("-iconic" 0 x-handle-iconic
)
135 ("-xrm" 1 x-handle-xrm-switch
)
136 ("-cr" 1 x-handle-switch cursor-color
)
137 ("-vb" 0 x-handle-switch vertical-scroll-bars t
)
138 ("-hb" 0 x-handle-switch horizontal-scroll-bars t
)
139 ("-bd" 1 x-handle-switch
)
140 ("--border-width" 1 x-handle-numeric-switch border-width
)
141 ("--display" 1 x-handle-display
)
142 ("--name" 1 x-handle-name-switch
)
143 ("--title" 1 x-handle-switch title
)
144 ("--reverse-video" 0 x-handle-switch reverse t
)
145 ("--font" 1 x-handle-switch font
)
146 ("--fullscreen" 0 x-handle-initial-switch fullscreen fullboth
)
147 ("--fullwidth" 0 x-handle-initial-switch fullscreen fullwidth
)
148 ("--fullheight" 0 x-handle-initial-switch fullscreen fullheight
)
149 ("--internal-border" 1 x-handle-numeric-switch internal-border-width
)
150 ("--geometry" 1 x-handle-geometry
)
151 ("--foreground-color" 1 x-handle-switch foreground-color
)
152 ("--background-color" 1 x-handle-switch background-color
)
153 ("--mouse-color" 1 x-handle-switch mouse-color
)
154 ("--no-bitmap-icon" 0 x-handle-switch icon-type nil
)
155 ("--iconic" 0 x-handle-iconic
)
156 ("--xrm" 1 x-handle-xrm-switch
)
157 ("--cursor-color" 1 x-handle-switch cursor-color
)
158 ("--vertical-scroll-bars" 0 x-handle-switch vertical-scroll-bars t
)
159 ("--line-spacing" 1 x-handle-numeric-switch line-spacing
)
160 ("--border-color" 1 x-handle-switch border-color
)
161 ("--smid" 1 x-handle-smid
))
162 "Alist of X Windows options.
163 Each element has the form
164 (NAME NUMARGS HANDLER FRAME-PARAM VALUE)
165 where NAME is the option name string, NUMARGS is the number of arguments
166 that the option accepts, HANDLER is a function to call to handle the option.
167 FRAME-PARAM (optional) is the frame parameter this option specifies,
168 and VALUE is the value which is given to that frame parameter
169 \(most options use the argument for this, so VALUE is not present).")
171 (defvar before-init-hook nil
172 "Normal hook run after handling urgent options but before loading init files.")
174 (defvar after-init-hook nil
175 "Normal hook run after loading the init files, `~/.emacs' and `default.el'.
176 There is no `condition-case' around the running of these functions;
177 therefore, if you set `debug-on-error' non-nil in `.emacs',
178 an error in one of these functions will invoke the debugger.")
180 (defvar emacs-startup-hook nil
181 "Normal hook run after loading init files and handling the command line.")
183 (defvar term-setup-hook nil
184 "Normal hook run after loading terminal-specific Lisp code.
185 It also follows `emacs-startup-hook'. This hook exists for users to set,
186 so as to override the definitions made by the terminal-specific file.
187 Emacs never sets this variable itself.")
189 (defvar inhibit-startup-hooks nil
190 "Non-nil means don't run `term-setup-hook' and `emacs-startup-hook'.
191 This is because we already did so.")
193 (defvar keyboard-type nil
194 "The brand of keyboard you are using.
195 This variable is used to define the proper function and keypad
196 keys for use under X. It is used in a fashion analogous to the
197 environment variable TERM.")
199 (defvar window-setup-hook nil
200 "Normal hook run to initialize window system display.
201 Emacs runs this hook after processing the command line arguments and loading
202 the user's init file.")
204 (defcustom initial-major-mode
'lisp-interaction-mode
205 "Major mode command symbol to use for the initial *scratch* buffer."
207 :group
'initialization
)
209 (defvar init-file-user nil
210 "Identity of user whose `.emacs' file is or was read.
211 The value is nil if `-q' or `--no-init-file' was specified,
212 meaning do not load any init file.
214 Otherwise, the value may be an empty string, meaning
215 use the init file for the user who originally logged in,
216 or it may be a string containing a user's name meaning
217 use that person's init file.
219 In either of the latter cases, `(concat \"~\" init-file-user \"/\")'
220 evaluates to the name of the directory where the `.emacs' file was
223 Setting `init-file-user' does not prevent Emacs from loading
224 `site-start.el'. The only way to do that is to use `--no-site-file'.")
226 (defcustom site-run-file
"site-start"
227 "File containing site-wide run-time initializations.
228 This file is loaded at run-time before `~/.emacs'. It contains inits
229 that need to be in place for the entire site, but which, due to their
230 higher incidence of change, don't make sense to load into Emacs's
231 dumped image. Thus, the run-time load order is: 1. file described in
232 this variable, if non-nil; 2. `~/.emacs'; 3. `default.el'.
234 Don't use the `site-start.el' file for things some users may not like.
235 Put them in `default.el' instead, so that users can more easily
236 override them. Users can prevent loading `default.el' with the `-q'
237 option or by setting `inhibit-default-init' in their own init files,
238 but inhibiting `site-start.el' requires `--no-site-file', which
241 This variable is defined for customization so as to make
242 it visible in the relevant context. However, actually customizing it
243 is not allowed, since it would not work anyway. The only way to set
244 this variable usefully is to set it while building and dumping Emacs."
245 :type
'(choice (const :tag
"none" nil
) string
)
246 :group
'initialization
247 :initialize
'custom-initialize-default
248 :set
'(lambda (variable value
)
249 (error "Customizing `site-run-file' does not work")))
251 (defcustom mail-host-address nil
252 "*Name of this machine, for purposes of naming users."
253 :type
'(choice (const nil
) string
)
256 (defcustom user-mail-address
(if command-line-processed
258 (concat (user-login-name) "@"
259 (or mail-host-address
261 ;; Empty string means "not set yet".
263 "*Full mailing address of this user.
264 This is initialized with environment variable `EMAIL' or, as a
265 fallback, using `mail-host-address'. This is done after your
266 init file is read, in case it sets `mail-host-address'."
270 (defcustom auto-save-list-file-prefix
271 (cond ((eq system-type
'ms-dos
)
272 ;; MS-DOS cannot have initial dot, and allows only 8.3 names
273 "~/_emacs.d/auto-save.list/_s")
275 "~/.emacs.d/auto-save-list/.saves-"))
276 "Prefix for generating `auto-save-list-file-name'.
277 This is used after reading your `.emacs' file to initialize
278 `auto-save-list-file-name', by appending Emacs's pid and the system name,
279 if you have not already set `auto-save-list-file-name' yourself.
280 Directories in the prefix will be created if necessary.
281 Set this to nil if you want to prevent `auto-save-list-file-name'
282 from being initialized."
283 :type
'(choice (const :tag
"Don't record a session's auto save list" nil
)
287 (defvar emacs-quick-startup nil
)
289 (defvar emacs-basic-display nil
)
291 (defvar init-file-debug nil
)
293 (defvar init-file-had-error nil
)
295 (defvar normal-top-level-add-subdirs-inode-list nil
)
297 (defvar no-blinking-cursor nil
)
299 (defvar default-frame-background-mode
)
301 (defvar pure-space-overflow nil
302 "Non-nil if building Emacs overflowed pure space.")
304 (defun normal-top-level-add-subdirs-to-load-path ()
305 "Add all subdirectories of current directory to `load-path'.
306 More precisely, this uses only the subdirectories whose names
307 start with letters or digits; it excludes any subdirectory named `RCS'
308 or `CVS', and any subdirectory that contains a file named `.nosearch'."
311 (pending (list default-directory
)))
312 ;; This loop does a breadth-first tree walk on DIR's subtree,
313 ;; putting each subdir into DIRS as its contents are examined.
315 (push (pop pending
) dirs
)
316 (let* ((this-dir (car dirs
))
317 (contents (directory-files this-dir
))
318 (default-directory this-dir
)
319 (canonicalized (if (fboundp 'untranslated-canonical-name
)
320 (untranslated-canonical-name this-dir
))))
321 ;; The Windows version doesn't report meaningful inode
322 ;; numbers, so use the canonicalized absolute file name of the
323 ;; directory instead.
324 (setq attrs
(or canonicalized
325 (nthcdr 10 (file-attributes this-dir
))))
326 (unless (member attrs normal-top-level-add-subdirs-inode-list
)
327 (push attrs normal-top-level-add-subdirs-inode-list
)
328 (dolist (file contents
)
329 ;; The lower-case variants of RCS and CVS are for DOS/Windows.
330 (unless (member file
'("." ".." "RCS" "CVS" "rcs" "cvs"))
331 (when (and (string-match "\\`[[:alnum:]]" file
)
332 ;; Avoid doing a `stat' when it isn't necessary
333 ;; because that can cause trouble when an NFS server
335 (not (string-match "\\.elc?\\'" file
))
336 (file-directory-p file
))
337 (let ((expanded (expand-file-name file
)))
338 (unless (file-exists-p (expand-file-name ".nosearch"
340 (setq pending
(nconc pending
(list expanded
)))))))))))
341 (normal-top-level-add-to-load-path (cdr (nreverse dirs
)))))
343 ;; This function is called from a subdirs.el file.
344 ;; It assumes that default-directory is the directory
345 ;; in which the subdirs.el file exists,
346 ;; and it adds to load-path the subdirs of that directory
347 ;; as specified in DIRS. Normally the elements of DIRS are relative.
348 (defun normal-top-level-add-to-load-path (dirs)
349 (let ((tail load-path
)
350 (thisdir (directory-file-name default-directory
)))
352 ;;Don't go all the way to the nil terminator.
354 (not (equal thisdir
(car tail
)))
355 (not (and (memq system-type
'(ms-dos windows-nt
))
356 (equal (downcase thisdir
) (downcase (car tail
))))))
357 (setq tail
(cdr tail
)))
358 ;;Splice the new section in.
360 (setcdr tail
(append (mapcar 'expand-file-name dirs
) (cdr tail
))))))
362 (defun normal-top-level ()
363 (if command-line-processed
364 (message "Back to top level.")
365 (setq command-line-processed t
)
366 ;; Give *Messages* the same default-directory as *scratch*,
367 ;; just to keep things predictable.
368 (let ((dir default-directory
))
369 (with-current-buffer "*Messages*"
370 (setq default-directory dir
)))
371 ;; `user-full-name' is now known; reset its standard-value here.
372 (put 'user-full-name
'standard-value
373 (list (default-value 'user-full-name
)))
374 ;; For root, preserve owner and group when editing files.
375 (if (equal (user-uid) 0)
376 (setq backup-by-copying-when-mismatch t
))
377 ;; Look in each dir in load-path for a subdirs.el file.
378 ;; If we find one, load it, which will add the appropriate subdirs
379 ;; of that dir into load-path,
380 ;; Look for a leim-list.el file too. Loading it will register
381 ;; available input methods.
382 (let ((tail load-path
) dir
)
384 (setq dir
(car tail
))
385 (let ((default-directory dir
))
386 (load (expand-file-name "subdirs.el") t t t
))
387 (let ((default-directory dir
))
388 (load (expand-file-name "leim-list.el") t t t
))
389 ;; We don't use a dolist loop and we put this "setq-cdr" command at
390 ;; the end, because the subdirs.el files may add elements to the end
391 ;; of load-path and we want to take it into account.
392 (setq tail
(cdr tail
))))
393 (unless (eq system-type
'vax-vms
)
394 ;; If the PWD environment variable isn't accurate, delete it.
395 (let ((pwd (getenv "PWD")))
397 ;; Use FOO/., so that if FOO is a symlink, file-attributes
398 ;; describes the directory linked to, not FOO itself.
399 (or (equal (file-attributes
400 (concat (file-name-as-directory pwd
) "."))
402 (concat (file-name-as-directory default-directory
)
404 (setq process-environment
405 (delete (concat "PWD=" pwd
)
406 process-environment
))))))
407 (setq default-directory
(abbreviate-file-name default-directory
))
408 (let ((menubar-bindings-done nil
))
411 ;; Do this again, in case .emacs defined more abbreviations.
412 (setq default-directory
(abbreviate-file-name default-directory
))
413 ;; Specify the file for recording all the auto save files of this session.
414 ;; This is used by recover-session.
415 (or auto-save-list-file-name
416 (and auto-save-list-file-prefix
417 (setq auto-save-list-file-name
418 ;; Under MS-DOS our PID is almost always reused between
419 ;; Emacs invocations. We need something more unique.
420 (cond ((eq system-type
'ms-dos
)
421 ;; We are going to access the auto-save
422 ;; directory, so make sure it exists.
424 (file-name-directory auto-save-list-file-prefix
)
429 auto-save-list-file-prefix
))
434 auto-save-list-file-prefix
437 (unless inhibit-startup-hooks
438 (run-hooks 'emacs-startup-hook
)
440 (run-hooks 'term-setup-hook
)))
442 ;; Don't do this if we failed to create the initial frame,
443 ;; for instance due to a dense colormap.
444 (when (or frame-initial-frame
445 ;; If frame-initial-frame has no meaning, do this anyway.
446 (not (and initial-window-system
448 (not (eq initial-window-system
'pc
)))))
449 ;; Modify the initial frame based on what .emacs puts into
451 (if (fboundp 'frame-notice-user-settings
)
452 (frame-notice-user-settings))
453 ;; Set the faces for the initial background mode even if
454 ;; frame-notice-user-settings didn't (such as on a tty).
455 ;; frame-set-background-mode is idempotent, so it won't
456 ;; cause any harm if it's already been done.
457 (if (fboundp 'frame-set-background-mode
)
458 (frame-set-background-mode (selected-frame))))
460 ;; Now we know the user's default font, so add it to the menu.
461 (if (fboundp 'font-menu-add-default
)
462 (font-menu-add-default))
463 (and window-setup-hook
464 (run-hooks 'window-setup-hook
))
465 (or menubar-bindings-done
466 (if (display-popup-menus-p)
467 (precompute-menubar-bindings)))))))
469 ;; Precompute the keyboard equivalents in the menu bar items.
470 (defun precompute-menubar-bindings ()
471 (let ((submap (lookup-key global-map
[menu-bar
])))
473 (and (consp (car submap
))
474 (symbolp (car (car submap
)))
475 (stringp (car-safe (cdr (car submap
))))
476 (keymapp (cdr (cdr (car submap
))))
478 (x-popup-menu nil
(cdr (cdr (car submap
))))
481 (setq submap
(cdr submap
))))
482 (setq define-key-rebound-commands t
))
484 ;; Command-line options supported by tty's:
485 (defconst tty-long-option-alist
486 '(("--name" .
"-name")
488 ("--reverse-video" .
"-reverse")
489 ("--foreground-color" .
"-fg")
490 ("--background-color" .
"-bg")
491 ("--color" .
"-color")))
493 (defconst tool-bar-images-pixel-height
24
494 "Height in pixels of images in the tool bar.")
496 (defvar tool-bar-originally-present nil
497 "Non-nil if tool-bars are present before user and site init files are read.")
499 (defvar handle-args-function-alist
'((nil . tty-handle-args
))
500 "Functions for processing window-system dependent command-line arguments.
501 Window system startup files should add their own function to this
502 alist, which should parse the command line arguments. Those
503 pertaining to the window system should be processed and removed
504 from the returned command line.")
506 (defvar window-system-initialization-alist
'((nil . ignore
))
507 "Alist of window-system initialization functions.
508 Window-system startup files should add their own initialization
509 function to this list. The function should take no arguments,
510 and initialize the window system environment to prepare for
511 opening the first frame (e.g. open a connection to an X server).")
513 ;; Handle the X-like command-line arguments "-fg", "-bg", "-name", etc.
514 (defun tty-handle-args (args)
518 (not (equal (car args
) "--")))
519 (let* ((argi (pop args
))
522 ;; Check for long options with attached arguments
523 ;; and separate out the attached option argument into argval.
524 (when (string-match "^\\(--[^=]*\\)=" argi
)
525 (setq argval
(substring argi
(match-end 0))
526 argi
(match-string 1 argi
)))
527 (when (string-match "^--" argi
)
528 (setq completion
(try-completion argi tty-long-option-alist
))
529 (if (eq completion t
)
530 ;; Exact match for long option.
531 (setq argi
(cdr (assoc argi tty-long-option-alist
)))
532 (if (stringp completion
)
533 (let ((elt (assoc completion tty-long-option-alist
)))
534 ;; Check for abbreviated long option.
536 (error "Option `%s' is ambiguous" argi
))
537 (setq argi
(cdr elt
)))
538 ;; Check for a short option.
541 (cond ((member argi
'("-fg" "-foreground"))
542 (push (cons 'foreground-color
(or argval
(pop args
)))
543 default-frame-alist
))
544 ((member argi
'("-bg" "-background"))
545 (push (cons 'background-color
(or argval
(pop args
)))
546 default-frame-alist
))
547 ((member argi
'("-T" "-name"))
548 (unless argval
(setq argval
(pop args
)))
552 (let ((case-fold-search t
)
554 (setq argval
(invocation-name))
556 ;; Change any . or * characters in name to
557 ;; hyphens, so as to emulate behavior on X.
559 (setq i
(string-match "[.*]" argval
))
562 default-frame-alist
))
563 ((member argi
'("-r" "-rv" "-reverse"))
565 default-frame-alist
))
566 ((equal argi
"-color")
567 (unless argval
(setq argval
8)) ; default --color means 8 ANSI colors
568 (push (cons 'tty-color-mode
570 ((numberp argval
) argval
)
571 ((string-match "-?[0-9]+" argval
)
572 (string-to-number argval
))
573 (t (intern argval
))))
574 default-frame-alist
))
579 (defun command-line ()
580 (setq command-line-default-directory default-directory
)
582 ;; Choose a reasonable location for temporary files.
583 (custom-reevaluate-setting 'temporary-file-directory
)
584 (custom-reevaluate-setting 'small-temporary-file-directory
)
585 (custom-reevaluate-setting 'auto-save-file-name-transforms
)
587 ;; See if we should import version-control from the environment variable.
588 (let ((vc (getenv "VERSION_CONTROL")))
589 (cond ((eq vc nil
)) ;don't do anything if not set
590 ((member vc
'("t" "numbered"))
591 (setq version-control t
))
592 ((member vc
'("nil" "existing"))
593 (setq version-control nil
))
594 ((member vc
'("never" "simple"))
595 (setq version-control
'never
))))
597 ;;! This has been commented out; I currently find the behavior when
598 ;;! split-window-keep-point is nil disturbing, but if I can get used
599 ;;! to it, then it would be better to eliminate the option.
600 ;;! ;; Choose a good default value for split-window-keep-point.
601 ;;! (setq split-window-keep-point (> baud-rate 2400))
603 ;; Set the default strings to display in mode line for
604 ;; end-of-line formats that aren't native to this platform.
606 ((memq system-type
'(ms-dos windows-nt emx
))
607 (setq eol-mnemonic-unix
"(Unix)"
608 eol-mnemonic-mac
"(Mac)"))
609 ;; Both Mac and Unix EOLs are now "native" on Mac OS so keep the
610 ;; abbreviated strings `/' and `:' set in coding.c for them.
611 ((eq system-type
'macos
)
612 (setq eol-mnemonic-dos
"(DOS)"))
613 (t ; this is for Unix/GNU/Linux systems
614 (setq eol-mnemonic-dos
"(DOS)"
615 eol-mnemonic-mac
"(Mac)")))
617 ;; Make sure window system's init file was loaded in loadup.el if using a window system.
618 (condition-case error
619 (unless noninteractive
620 (if (and initial-window-system
622 (intern (concat (symbol-name initial-window-system
) "-win")))))
623 (error "Unsupported window system `%s'" initial-window-system
))
624 ;; Process window-system specific command line parameters.
625 (setq command-line-args
626 (funcall (or (cdr (assq initial-window-system handle-args-function-alist
))
627 (error "Unsupported window system `%s'" initial-window-system
))
629 ;; Initialize the window system. (Open connection, etc.)
630 (funcall (or (cdr (assq initial-window-system window-system-initialization-alist
))
631 (error "Unsupported window system `%s'" initial-window-system
))))
632 ;; If there was an error, print the error message and exit.
635 (if (eq (car error
) 'error
)
636 (apply 'concat
(cdr error
))
637 (if (memq 'file-error
(get (car error
) 'error-conditions
))
640 (mapconcat (lambda (obj) (prin1-to-string obj t
))
641 (cdr (cdr error
)) ", "))
643 (get (car error
) 'error-message
)
644 (mapconcat (lambda (obj) (prin1-to-string obj t
))
646 'external-debugging-output
)
647 (terpri 'external-debugging-output
)
648 (setq initial-window-system nil
)
651 (set-locale-environment nil
)
653 ;; Convert preloaded file names to absolute.
657 (locate-file "simple" load-path
658 (get-load-suffixes))))))
661 (mapcar (lambda (elt)
662 (if (and (stringp (car elt
))
663 (not (file-name-absolute-p (car elt
))))
664 (cons (concat lisp-dir
670 ;; Convert the arguments to Emacs internal representation.
671 (let ((args (cdr command-line-args
)))
674 (decode-coding-string (car args
) locale-coding-system t
))
678 (args (cdr command-line-args
)))
680 ;; Figure out which user's init file to load,
681 ;; either from the environment or from the options.
682 (setq init-file-user
(if noninteractive nil
(user-login-name)))
683 ;; If user has not done su, use current $HOME to find .emacs.
685 (equal init-file-user
(user-real-login-name))
686 (setq init-file-user
""))
688 ;; Process the command-line args, and delete the arguments
689 ;; processed. This is consistent with the way main in emacs.c
691 (while (and (not done
) args
)
692 (let* ((longopts '(("--no-init-file") ("--no-site-file") ("--debug-init")
693 ("--user") ("--iconic") ("--icon-type") ("--quick")
694 ("--no-blinking-cursor") ("--basic-display")))
698 ;; Handle --OPTION=VALUE format.
699 (when (string-match "^\\(--[^=]*\\)=" argi
)
700 (setq argval
(substring argi
(match-end 0))
701 argi
(match-string 1 argi
)))
702 (unless (equal argi
"--")
703 (let ((completion (try-completion argi longopts
)))
704 (if (eq completion t
)
705 (setq argi
(substring argi
1))
706 (if (stringp completion
)
707 (let ((elt (assoc completion longopts
)))
709 (error "Option `%s' is ambiguous" argi
))
710 (setq argi
(substring (car elt
) 1)))
714 ((member argi
'("-Q" "-quick"))
715 (setq init-file-user nil
717 emacs-quick-startup t
))
718 ((member argi
'("-D" "-basic-display"))
719 (setq no-blinking-cursor t
720 emacs-basic-display t
)
721 (push '(vertical-scroll-bars . nil
) initial-frame-alist
))
722 ((member argi
'("-q" "-no-init-file"))
723 (setq init-file-user nil
))
724 ((member argi
'("-u" "-user"))
725 (setq init-file-user
(or argval
(pop args
))
727 ((equal argi
"-no-site-file")
728 (setq site-run-file nil
))
729 ((equal argi
"-debug-init")
730 (setq init-file-debug t
))
731 ((equal argi
"-iconic")
732 (push '(visibility . icon
) initial-frame-alist
))
733 ((member argi
'("-icon-type" "-i" "-itype"))
734 (push '(icon-type . t
) default-frame-alist
))
735 ((member argi
'("-nbc" "-no-blinking-cursor"))
736 (setq no-blinking-cursor t
))
737 ;; Push the popped arg back on the list of arguments.
741 ;; Was argval set but not used?
743 (error "Option `%s' doesn't allow an argument" argi
))))
745 ;; Re-attach the program name to the front of the arg list.
746 (and command-line-args
747 (setcdr command-line-args args
)))
749 (run-hooks 'before-init-hook
)
751 ;; Under X Window, this creates the X frame and deletes the terminal frame.
752 (when (fboundp 'frame-initialize
)
755 ;; Turn off blinking cursor if so specified in X resources. This is here
756 ;; only because all other settings of no-blinking-cursor are here.
757 (unless (or noninteractive
759 (and (memq window-system
'(x w32 mac
))
760 (not (member (x-get-resource "cursorBlink" "CursorBlink")
762 (setq no-blinking-cursor t
))
764 ;; If frame was created with a menu bar, set menu-bar-mode on.
765 (unless (or noninteractive
767 (and (memq initial-window-system
'(x w32
))
768 (<= (frame-parameter nil
'menu-bar-lines
) 0)))
771 ;; If frame was created with a tool bar, switch tool-bar-mode on.
772 (unless (or noninteractive
774 (not (display-graphic-p))
775 (<= (frame-parameter nil
'tool-bar-lines
) 0))
778 ;; Can't do this init in defcustom because the relevant variables
780 (custom-reevaluate-setting 'blink-cursor-mode
)
781 (custom-reevaluate-setting 'tooltip-mode
)
782 (custom-reevaluate-setting 'global-font-lock-mode
)
783 (custom-reevaluate-setting 'mouse-wheel-down-event
)
784 (custom-reevaluate-setting 'mouse-wheel-up-event
)
785 (custom-reevaluate-setting 'file-name-shadow-mode
)
786 (custom-reevaluate-setting 'send-mail-function
)
787 (custom-reevaluate-setting 'focus-follows-mouse
)
789 (normal-erase-is-backspace-setup-frame)
791 ;; Register default TTY colors for the case the terminal hasn't a
792 ;; terminal init file. We do this regardles of whether the terminal
793 ;; supports colors or not and regardless the current display type,
794 ;; since users can connect to color-capable terminals and also
795 ;; switch color support on or off in mid-session by setting the
796 ;; tty-color-mode frame parameter.
797 (tty-register-default-colors)
799 ;; Record whether the tool-bar is present before the user and site
800 ;; init files are processed. frame-notice-user-settings uses this
801 ;; to determine if the tool-bar has been disabled by the init files,
802 ;; and the frame needs to be resized.
803 (when (fboundp 'frame-notice-user-settings
)
804 (let ((tool-bar-lines (or (assq 'tool-bar-lines initial-frame-alist
)
805 (assq 'tool-bar-lines default-frame-alist
))))
806 (setq tool-bar-originally-present
809 (not (eq 0 (cdr tool-bar-lines
)))))))
811 (let ((old-scalable-fonts-allowed scalable-fonts-allowed
)
812 (old-font-list-limit font-list-limit
)
813 (old-face-ignored-fonts face-ignored-fonts
))
815 ;; Run the site-start library if it exists. The point of this file is
816 ;; that it is run before .emacs. There is no point in doing this after
817 ;; .emacs; that is useless.
819 (load site-run-file t t
))
821 ;; Sites should not disable this. Only individuals should disable
822 ;; the startup message.
823 (setq inhibit-startup-message nil
)
825 ;; Warn for invalid user name.
827 (if (string-match "[~/:\n]" init-file-user
)
828 (display-warning 'initialization
829 (format "Invalid user name %s"
832 (if (file-directory-p (expand-file-name
833 ;; We don't support ~USER on MS-Windows except
834 ;; for the current user, and always load .emacs
835 ;; from the current user's home directory (see
836 ;; below). So always check "~", even if invoked
837 ;; with "-u USER", or if $USER or $LOGNAME are
838 ;; set to something different.
839 (if (eq system-type
'windows-nt
)
841 (concat "~" init-file-user
))))
843 (display-warning 'initialization
844 (format "User %s has no home directory"
848 ;; Load that user's init file, or the default one, or none.
849 (let (debug-on-error-from-init-file
850 debug-on-error-should-be-set
851 (debug-on-error-initial
852 (if (eq init-file-debug t
) 'startup init-file-debug
))
853 (orig-enable-multibyte default-enable-multibyte-characters
))
854 (let ((debug-on-error debug-on-error-initial
)
855 ;; This function actually reads the init files.
860 (let ((user-init-file-1
862 ((eq system-type
'ms-dos
)
863 (concat "~" init-file-user
"/_emacs"))
864 ((eq system-type
'windows-nt
)
865 ;; Prefer .emacs on Windows.
866 (if (directory-files "~" nil
"^\\.emacs\\(\\.elc?\\)?$")
868 ;; Also support _emacs for compatibility.
869 (if (directory-files "~" nil
"^_emacs\\(\\.elc?\\)?$")
871 ;; But default to .emacs if _emacs does not exist.
873 ((eq system-type
'vax-vms
)
876 (concat "~" init-file-user
"/.emacs")))))
877 ;; This tells `load' to store the file name found
878 ;; into user-init-file.
879 (setq user-init-file t
)
880 (load user-init-file-1 t t
)
882 (when (eq user-init-file t
)
883 ;; If we did not find ~/.emacs, try
884 ;; ~/.emacs.d/init.el.
888 (file-name-as-directory
889 (concat "~" init-file-user
"/.emacs.d")))))
892 ;; If we did not find the user's init file,
893 ;; set user-init-file conclusively.
894 ;; Don't let it be set from default.el.
895 (when (eq user-init-file t
)
896 (setq user-init-file user-init-file-1
))))
898 ;; If we loaded a compiled file, set
899 ;; `user-init-file' to the source version if that
901 (when (and user-init-file
902 (equal (file-name-extension user-init-file
)
904 (let* ((source (file-name-sans-extension user-init-file
))
905 (alt (concat source
".el")))
906 (setq source
(cond ((file-exists-p alt
) alt
)
907 ((file-exists-p source
) source
)
910 (when (file-newer-than-file-p source user-init-file
)
911 (message "Warning: %s is newer than %s"
912 source user-init-file
)
914 (setq user-init-file source
))))
916 (unless inhibit-default-init
917 (let ((inhibit-startup-message nil
))
918 ;; Users are supposed to be told their rights.
919 ;; (Plus how to get help and how to undo.)
920 ;; Don't you dare turn this off for anyone
922 (load "default" t t
)))))))))
924 ;; Do this without a condition-case if the user wants to debug.
926 (condition-case error
929 (setq init-file-had-error nil
))
931 (let ((message-log-max nil
))
933 (set-buffer (get-buffer-create "*Messages*"))
935 (format "An error has occurred while loading `%s':\n\n"
938 (get (car error
) 'error-message
)
939 (if (cdr error
) ": " "")
940 (mapconcat (lambda (s) (prin1-to-string s t
)) (cdr error
) ", "))
942 "To ensure normal operation, you should investigate and remove the\n"
943 "cause of the error in your initialization file. Start Emacs with\n"
944 "the `--debug-init' option to view a complete error backtrace.\n\n"))
945 (message "Error in init file: %s%s%s"
946 (get (car error
) 'error-message
)
947 (if (cdr error
) ": " "")
948 (mapconcat 'prin1-to-string
(cdr error
) ", "))
949 (let ((pop-up-windows nil
))
950 (pop-to-buffer "*Messages*"))
951 (setq init-file-had-error t
)))))
953 (if (and deactivate-mark transient-mark-mode
)
954 (with-current-buffer (window-buffer)
957 ;; If the user has a file of abbrevs, read it.
958 (if (file-exists-p abbrev-file-name
)
959 (quietly-read-abbrev-file abbrev-file-name
))
961 ;; If the abbrevs came entirely from the init file or the
962 ;; abbrevs file, they do not need saving.
963 (setq abbrevs-changed nil
)
965 ;; If we can tell that the init file altered debug-on-error,
966 ;; arrange to preserve the value that it set up.
967 (or (eq debug-on-error debug-on-error-initial
)
968 (setq debug-on-error-should-be-set t
969 debug-on-error-from-init-file debug-on-error
)))
970 (if debug-on-error-should-be-set
971 (setq debug-on-error debug-on-error-from-init-file
))
972 (unless (or default-enable-multibyte-characters
973 (eq orig-enable-multibyte default-enable-multibyte-characters
))
974 ;; Init file changed to unibyte. Reset existing multibyte
975 ;; buffers (probably *scratch*, *Messages*, *Minibuff-0*).
976 ;; Arguably this should only be done if they're free of
977 ;; multibyte characters.
978 (mapcar (lambda (buffer)
979 (with-current-buffer buffer
980 (if enable-multibyte-characters
981 (set-buffer-multibyte nil
))))
983 ;; Also re-set the language environment in case it was
984 ;; originally done before unibyte was set and is sensitive to
985 ;; unibyte (display table, terminal coding system &c).
986 (set-language-environment current-language-environment
)))
988 ;; Do this here in case the init file sets mail-host-address.
989 (if (equal user-mail-address
"")
990 (setq user-mail-address
(or (getenv "EMAIL")
991 (concat (user-login-name) "@"
992 (or mail-host-address
995 ;; Originally face attributes were specified via
996 ;; `font-lock-face-attributes'. Users then changed the default
997 ;; face attributes by setting that variable. However, we try and
998 ;; be back-compatible and respect its value if set except for
999 ;; faces where M-x customize has been used to save changes for the
1001 (when (boundp 'font-lock-face-attributes
)
1002 (let ((face-attributes font-lock-face-attributes
))
1003 (while face-attributes
1004 (let* ((face-attribute (pop face-attributes
))
1005 (face (car face-attribute
)))
1006 ;; Rustle up a `defface' SPEC from a
1007 ;; `font-lock-face-attributes' entry.
1008 (unless (get face
'saved-face
)
1009 (let ((foreground (nth 1 face-attribute
))
1010 (background (nth 2 face-attribute
))
1011 (bold-p (nth 3 face-attribute
))
1012 (italic-p (nth 4 face-attribute
))
1013 (underline-p (nth 5 face-attribute
))
1016 (setq face-spec
(cons ':foreground
(cons foreground face-spec
))))
1018 (setq face-spec
(cons ':background
(cons background face-spec
))))
1020 (setq face-spec
(append '(:weight bold
) face-spec
)))
1022 (setq face-spec
(append '(:slant italic
) face-spec
)))
1024 (setq face-spec
(append '(:underline t
) face-spec
)))
1025 (face-spec-set face
(list (list t face-spec
)) nil
)))))))
1027 ;; If parameter have been changed in the init file which influence
1028 ;; face realization, clear the face cache so that new faces will
1030 (unless (and (eq scalable-fonts-allowed old-scalable-fonts-allowed
)
1031 (eq font-list-limit old-font-list-limit
)
1032 (eq face-ignored-fonts old-face-ignored-fonts
))
1033 (clear-face-cache)))
1035 (run-hooks 'after-init-hook
)
1037 ;; Decode all default-directory.
1038 (if (and default-enable-multibyte-characters locale-coding-system
)
1040 (dolist (elt (buffer-list))
1042 (if default-directory
1043 (setq default-directory
1044 (decode-coding-string default-directory
1045 locale-coding-system t
))))
1046 (setq command-line-default-directory
1047 (decode-coding-string command-line-default-directory
1048 locale-coding-system t
))))
1050 ;; If *scratch* exists and init file didn't change its mode, initialize it.
1051 (if (get-buffer "*scratch*")
1052 (with-current-buffer "*scratch*"
1053 (if (eq major-mode
'fundamental-mode
)
1054 (funcall initial-major-mode
))))
1056 ;; Load library for our terminal type.
1057 ;; User init file can set term-file-prefix to nil to prevent this.
1058 (unless (or noninteractive
1059 initial-window-system
)
1060 (tty-run-terminal-initialization (selected-frame)))
1062 ;; Update the out-of-memory error message based on user's key bindings
1063 ;; for save-some-buffers.
1064 (setq memory-signal-data
1066 (substitute-command-keys "Memory exhausted--use \\[save-some-buffers] then exit and restart Emacs")))
1068 ;; Process the remaining args.
1069 (command-line-1 (cdr command-line-args
))
1071 ;; If -batch, terminate after processing the command options.
1072 (if noninteractive
(kill-emacs t
))
1074 ;; Run emacs-session-restore (session management) if started by
1075 ;; the session manager and we have a session manager connection.
1076 (if (and (boundp 'x-session-previous-id
)
1077 (stringp x-session-previous-id
))
1079 (emacs-session-restore x-session-previous-id
))))
1081 (defcustom initial-scratch-message
(purecopy "\
1082 ;; This buffer is for notes you don't want to save, and for Lisp evaluation.
1083 ;; If you want to create a file, visit that file with C-x C-f,
1084 ;; then enter the text in that file's own buffer.
1087 "Initial message displayed in *scratch* buffer at startup.
1088 If this is nil, no message will be displayed.
1089 If `inhibit-splash-screen' is non-nil, then no message is displayed,
1090 regardless of the value of this variable."
1091 :type
'(choice (text :tag
"Message")
1092 (const :tag
"none" nil
))
1093 :group
'initialization
)
1096 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1097 ;;; Fancy splash screen
1098 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1100 (defvar fancy-splash-text
1101 '((:face
(variable-pitch :weight bold
)
1102 "Important Help menu items:\n"
1103 :face variable-pitch
1105 (let* ((en "TUTORIAL")
1106 (tut (or (get-language-info current-language-environment
1109 (title (with-temp-buffer
1110 (insert-file-contents
1111 (expand-file-name tut data-directory
)
1113 (search-forward ".")
1114 (buffer-substring (point-min) (1- (point))))))
1115 ;; If there is a specific tutorial for the current language
1116 ;; environment and it is not English, append its title.
1118 "Emacs Tutorial\tLearn how to use Emacs efficiently"
1119 (if (string= en tut
)
1121 (concat " (" title
")"))
1123 :face variable-pitch
"\
1124 Emacs FAQ\tFrequently asked questions and answers
1125 View Emacs Manual\tView the Emacs manual using Info
1126 Absence of Warranty\tGNU Emacs comes with "
1127 :face
(variable-pitch :slant oblique
)
1128 "ABSOLUTELY NO WARRANTY\n"
1129 :face variable-pitch
1131 Copying Conditions\tConditions for redistributing and changing Emacs
1132 Getting New Versions\tHow to obtain the latest version of Emacs
1133 More Manuals / Ordering Manuals Buying printed manuals from the FSF\n")
1134 (:face
(variable-pitch :weight bold
)
1135 "Useful File menu items:\n"
1136 :face variable-pitch
"\
1137 Exit Emacs\t\t(Or type Control-x followed by Control-c)
1138 Recover Crashed Session\tRecover files you were editing before a crash
1146 "A list of texts to show in the middle part of splash screens.
1147 Each element in the list should be a list of strings or pairs
1148 `:face FACE', like `fancy-splash-insert' accepts them.")
1151 (defgroup fancy-splash-screen
()
1152 "Fancy splash screen when Emacs starts."
1154 :group
'initialization
)
1157 (defcustom fancy-splash-delay
7
1158 "*Delay in seconds between splash screens."
1159 :group
'fancy-splash-screen
1163 (defcustom fancy-splash-max-time
30
1164 "*Show splash screens for at most this number of seconds.
1165 Values less than twice `fancy-splash-delay' are ignored."
1166 :group
'fancy-splash-screen
1170 (defcustom fancy-splash-image nil
1171 "*The image to show in the splash screens, or nil for defaults."
1172 :group
'fancy-splash-screen
1173 :type
'(choice (const :tag
"Default" nil
)
1174 (file :tag
"File")))
1177 ;; These are temporary storage areas for the splash screen display.
1179 (defvar fancy-current-text nil
)
1180 (defvar fancy-splash-help-echo nil
)
1181 (defvar fancy-splash-stop-time nil
)
1182 (defvar fancy-splash-outer-buffer nil
)
1184 (defun fancy-splash-insert (&rest args
)
1185 "Insert text into the current buffer, with faces.
1186 Arguments from ARGS should be either strings, functions called
1187 with no args that return a string, or pairs `:face FACE',
1188 where FACE is a valid face specification, as it can be used with
1189 `put-text-property'."
1190 (let ((current-face nil
))
1192 (if (eq (car args
) :face
)
1193 (setq args
(cdr args
) current-face
(car args
))
1194 (insert (propertize (let ((it (car args
)))
1199 'help-echo fancy-splash-help-echo
)))
1200 (setq args
(cdr args
)))))
1203 (defun fancy-splash-head ()
1204 "Insert the head part of the splash screen into the current buffer."
1205 (let* ((image-file (cond ((stringp fancy-splash-image
)
1207 ((and (display-color-p)
1208 (image-type-available-p 'xpm
))
1209 (if (and (fboundp 'x-display-planes
)
1210 (= (funcall 'x-display-planes
) 8))
1214 (img (create-image image-file
))
1215 (image-width (and img
(car (image-size img
))))
1216 (window-width (window-width (selected-window))))
1218 (when (> window-width image-width
)
1219 ;; Center the image in the window.
1220 (insert (propertize " " 'display
1221 `(space :align-to
(+ center
(-0.5 .
,img
)))))
1223 ;; Change the color of the XPM version of the splash image
1224 ;; so that it is visible with a dark frame background.
1225 (when (and (memq 'xpm img
)
1226 (eq (frame-parameter nil
'background-mode
) 'dark
))
1227 (setq img
(append img
'(:color-symbols
(("#000000" .
"gray30"))))))
1229 ;; Insert the image with a help-echo and a keymap.
1230 (let ((map (make-sparse-keymap))
1231 (help-echo "mouse-2: browse http://www.gnu.org/"))
1232 (define-key map
[mouse-2
]
1235 (browse-url "http://www.gnu.org/")
1237 (define-key map
[down-mouse-2
] 'ignore
)
1238 (define-key map
[up-mouse-2
] 'ignore
)
1239 (insert-image img
(propertize "xxx" 'help-echo help-echo
1242 (fancy-splash-insert
1243 :face
'(variable-pitch :foreground
"red")
1244 (if (eq system-type
'gnu
/linux
)
1245 "GNU Emacs is one component of the GNU/Linux operating system."
1246 "GNU Emacs is one component of the GNU operating system."))
1248 (fancy-splash-insert
1249 :face
'variable-pitch
1250 "You can do basic editing with the menu bar and scroll bar \
1251 using the mouse.\n\n")
1252 (if fancy-splash-outer-buffer
1253 (fancy-splash-insert
1254 :face
'variable-pitch
1255 (substitute-command-keys
1257 "Type \\[recenter] to begin editing"
1258 (if (equal (buffer-name fancy-splash-outer-buffer
)
1261 " your file.\n"))))))
1263 (defun fancy-splash-tail ()
1264 "Insert the tail part of the splash screen into the current buffer."
1265 (let ((fg (if (eq (frame-parameter nil
'background-mode
) 'dark
)
1266 "cyan" "darkblue")))
1267 (fancy-splash-insert :face
`(variable-pitch :foreground
,fg
)
1271 :face
'(variable-pitch :height
0.5)
1272 "Copyright (C) 2006 Free Software Foundation, Inc.")
1273 (and auto-save-list-file-prefix
1274 ;; Don't signal an error if the
1275 ;; directory for auto-save-list files
1276 ;; does not yet exist.
1277 (file-directory-p (file-name-directory
1278 auto-save-list-file-prefix
))
1280 (file-name-directory auto-save-list-file-prefix
)
1283 (regexp-quote (file-name-nondirectory
1284 auto-save-list-file-prefix
)))
1286 (fancy-splash-insert :face
'(variable-pitch :foreground
"red")
1287 "\n\nIf an Emacs session crashed recently, "
1288 "type Meta-x recover-session RET\nto recover"
1289 " the files you were editing."))))
1291 (defun fancy-splash-screens-1 (buffer)
1292 "Timer function displaying a splash screen."
1293 (when (> (float-time) fancy-splash-stop-time
)
1294 (throw 'stop-splashing nil
))
1295 (unless fancy-current-text
1296 (setq fancy-current-text fancy-splash-text
))
1297 (let ((text (car fancy-current-text
)))
1300 (if pure-space-overflow
1302 Warning Warning!!! Pure space overflow !!!Warning Warning
1303 \(See the node Pure Storage in the Lisp manual for details.)\n"))
1305 (apply #'fancy-splash-insert text
)
1307 (unless (current-message)
1308 (message fancy-splash-help-echo
))
1309 (set-buffer-modified-p nil
)
1310 (goto-char (point-min))
1311 (force-mode-line-update)
1312 (setq fancy-current-text
(cdr fancy-current-text
))))
1314 (defun fancy-splash-default-action ()
1315 "Stop displaying the splash screen buffer.
1316 This is an internal function used to turn off the splash screen after
1317 the user caused an input event by hitting a key or clicking with the
1320 (if (and (memq 'down
(event-modifiers last-command-event
))
1321 (eq (posn-window (event-start last-command-event
))
1323 ;; This is a mouse-down event in the splash screen window.
1324 ;; Ignore it and consume the corresponding mouse-up event.
1326 (push last-command-event unread-command-events
))
1329 (defun fancy-splash-exit ()
1330 "Exit the splash screen."
1331 (if (get-buffer "GNU Emacs")
1332 (throw 'stop-splashing nil
)))
1334 (defun fancy-splash-delete-frame (frame)
1335 "Exit the splash screen after the frame is deleted."
1336 ;; We can not throw from `delete-frame-events', so we set up a timer
1337 ;; to exit the recursive edit as soon as Emacs is idle again.
1338 (if (frame-live-p frame
)
1339 (run-at-time 0 nil
'fancy-splash-exit
)))
1341 (defun fancy-splash-screens (&optional hide-on-input
)
1342 "Display fancy splash screens when Emacs starts."
1344 (let ((old-hourglass display-hourglass
)
1345 (fancy-splash-outer-buffer (current-buffer))
1347 (old-minor-mode-map-alist minor-mode-map-alist
)
1348 (old-emulation-mode-map-alists emulation-mode-map-alists
)
1349 (frame (fancy-splash-frame))
1351 (save-selected-window
1352 (select-frame frame
)
1353 (switch-to-buffer "GNU Emacs")
1354 (setq splash-buffer
(current-buffer))
1355 (catch 'stop-splashing
1357 (let* ((map (make-sparse-keymap))
1359 (overriding-local-map map
)
1360 ;; Catch if our frame is deleted; the delete-frame
1361 ;; event is unreliable and is handled by
1362 ;; `special-event-map' anyway.
1363 (delete-frame-functions (cons 'fancy-splash-delete-frame
1364 delete-frame-functions
)))
1365 (define-key map
[t] 'fancy-splash-default-action)
1366 (define-key map [mouse-movement] 'ignore)
1367 (define-key map [mode-line t] 'ignore)
1368 (define-key map [select-window] 'ignore)
1369 (setq display-hourglass nil
1370 minor-mode-map-alist nil
1371 emulation-mode-map-alists nil
1373 mode-line-format (propertize "---- %b %-"
1374 'face 'mode-line-buffer-id)
1375 fancy-splash-stop-time (+ (float-time)
1376 fancy-splash-max-time)
1377 timer (run-with-timer 0 fancy-splash-delay
1378 #'fancy-splash-screens-1
1380 (message "%s" (startup-echo-area-message))
1382 (cancel-timer timer)
1383 (setq display-hourglass old-hourglass
1384 minor-mode-map-alist old-minor-mode-map-alist
1385 emulation-mode-map-alists old-emulation-mode-map-alists)
1386 (kill-buffer splash-buffer)
1387 (when (frame-live-p frame)
1388 (select-frame frame)
1389 (switch-to-buffer fancy-splash-outer-buffer))))))
1390 ;; If hide-on-input is nil, don't hide the buffer on input.
1391 (if (or (window-minibuffer-p)
1392 (window-dedicated-p (selected-window)))
1393 (pop-to-buffer (current-buffer))
1394 (switch-to-buffer "*About GNU Emacs*"))
1395 (setq buffer-read-only nil)
1397 (if pure-space-overflow
1399 Warning Warning!!! Pure space overflow !!!Warning Warning
1400 \(See the node Pure Storage in the Lisp manual for details.)\n"))
1401 (let (fancy-splash-outer-buffer)
1403 (dolist (text fancy-splash-text)
1404 (apply #'fancy-splash-insert text)
1406 (skip-chars-backward "\n")
1407 (delete-region (point) (point-max))
1410 (set-buffer-modified-p nil)
1411 (setq buffer-read-only t)
1412 (if (and view-read-only (not view-mode))
1413 (view-mode-enter nil 'kill-buffer))
1414 (goto-char (point-min)))))
1417 (defun fancy-splash-frame ()
1418 "Return the frame to use for the fancy splash screen.
1419 Returning non-nil does not mean we should necessarily
1420 use the fancy splash screen, but if we do use it,
1421 we put it on this frame."
1423 (dolist (frame (append (frame-list) (list (selected-frame))))
1424 (if (and (frame-visible-p frame)
1425 (not (window-minibuffer-p (frame-selected-window frame))))
1426 (setq chosen-frame frame)))
1429 (defun use-fancy-splash-screens-p ()
1430 "Return t if fancy splash screens should be used."
1431 (when (and (display-graphic-p)
1432 (or (and (display-color-p)
1433 (image-type-available-p 'xpm))
1434 (image-type-available-p 'pbm)))
1435 (let ((frame (fancy-splash-frame)))
1437 (let* ((img (create-image (or fancy-splash-image
1438 (if (and (display-color-p)
1439 (image-type-available-p 'xpm))
1440 "splash.xpm" "splash.pbm"))))
1441 (image-height (and img (cdr (image-size img))))
1442 (window-height (1- (window-height (frame-selected-window frame)))))
1443 (> window-height (+ image-height 19)))))))
1446 (defun normal-splash-screen (&optional hide-on-input)
1447 "Display splash screen when Emacs starts."
1448 (let ((prev-buffer (current-buffer)))
1450 (with-current-buffer (get-buffer-create "GNU Emacs")
1451 (setq buffer-read-only nil)
1453 (set (make-local-variable 'tab-width) 8)
1455 (set (make-local-variable 'mode-line-format)
1456 (propertize "---- %b %-" 'face 'mode-line-buffer-id)))
1458 (if pure-space-overflow
1460 Warning Warning!!! Pure space overflow !!!Warning Warning
1461 \(See the node Pure Storage in the Lisp manual for details.)\n"))
1463 ;; The convention for this piece of code is that
1464 ;; each piece of output starts with one or two newlines
1465 ;; and does not end with any newlines.
1466 (insert "Welcome to GNU Emacs")
1468 (if (eq system-type 'gnu/linux)
1469 ", one component of the GNU/Linux operating system.\n"
1470 ", a part of the GNU operating system.\n"))
1473 (insert (substitute-command-keys
1475 "\nType \\[recenter] to begin editing"
1476 (if (equal (buffer-name prev-buffer) "*scratch*")
1478 " your file.\n")))))
1480 (if (display-mouse-p)
1481 ;; The user can use the mouse to activate menus
1482 ;; so give help in terms of menu items.
1485 You can do basic editing with the menu bar and scroll bar using the mouse.
1487 Useful File menu items:
1488 Exit Emacs (or type Control-x followed by Control-c)
1489 Recover Crashed Session Recover files you were editing before a crash
1491 Important Help menu items:
1492 Emacs Tutorial Learn how to use Emacs efficiently
1493 Emacs FAQ Frequently asked questions and answers
1494 Read the Emacs Manual View the Emacs manual using Info
1495 \(Non)Warranty GNU Emacs comes with ABSOLUTELY NO WARRANTY
1496 Copying Conditions Conditions for redistributing and changing Emacs
1497 Getting New Versions How to obtain the latest version of Emacs
1498 More Manuals / Ordering Manuals How to order printed manuals from the FSF
1500 (insert "\n\n" (emacs-version)
1502 Copyright (C) 2006 Free Software Foundation, Inc."))
1504 ;; No mouse menus, so give help using kbd commands.
1506 ;; If keys have their default meanings,
1507 ;; use precomputed string to save lots of time.
1508 (if (and (eq (key-binding "\C-h") 'help-command)
1509 (eq (key-binding "\C-xu") 'advertised-undo)
1510 (eq (key-binding "\C-x\C-c") 'save-buffers-kill-terminal)
1511 (eq (key-binding "\C-ht") 'help-with-tutorial)
1512 (eq (key-binding "\C-hi") 'info)
1513 (eq (key-binding "\C-hr") 'info-emacs-manual)
1514 (eq (key-binding "\C-h\C-n") 'view-emacs-news))
1516 Get help C-h (Hold down CTRL and press h)
1518 Emacs tutorial C-h t Undo changes C-x u
1519 Buy manuals C-h C-m Exit Emacs C-x C-c
1520 Browse manuals C-h i")
1522 (insert (substitute-command-keys
1525 Emacs manual \\[info-emacs-manual]
1526 Emacs tutorial \\[help-with-tutorial]\tUndo changes\t\\[advertised-undo]
1527 Buy manuals \\[view-order-manuals]\tExit Emacs\t\\[save-buffers-kill-terminal]
1528 Browse manuals \\[info]"
1529 (let ((where (where-is-internal
1530 'help-command nil t)))
1532 (key-description where)
1535 ;; Say how to use the menu bar with the keyboard.
1536 (if (and (eq (key-binding "\M-`") 'tmm-menubar)
1537 (eq (key-binding [f10]) 'tmm-menubar))
1539 Activate menubar F10 or ESC ` or M-`")
1540 (insert (substitute-command-keys "
1541 Activate menubar \\[tmm-menubar]")))
1543 ;; Many users seem to have problems with these.
1545 \(`C-' means use the CTRL key. `M-' means use the Meta (or Alt) key.
1546 If you have no Meta key, you may instead type ESC followed by the character.)")
1548 (insert "\n\n" (emacs-version)
1550 Copyright (C) 2006 Free Software Foundation, Inc.")
1552 (if (and (eq (key-binding "\C-h\C-c") 'describe-copying)
1553 (eq (key-binding "\C-h\C-d") 'describe-distribution)
1554 (eq (key-binding "\C-h\C-w") 'describe-no-warranty))
1557 GNU Emacs comes with ABSOLUTELY NO WARRANTY; type C-h C-w for full details.
1558 Emacs is Free Software--Free as in Freedom--so you can redistribute copies
1559 of Emacs and modify it; type C-h C-c to see the conditions.
1560 Type C-h C-d for information on getting the latest version.")
1561 (insert (substitute-command-keys
1563 GNU Emacs comes with ABSOLUTELY NO WARRANTY; type \\[describe-no-warranty] for full details.
1564 Emacs is Free Software--Free as in Freedom--so you can redistribute copies
1565 of Emacs and modify it; type \\[describe-copying] to see the conditions.
1566 Type \\[describe-distribution] for information on getting the latest version."))))
1568 ;; The rest of the startup screen is the same on all
1569 ;; kinds of terminals.
1571 ;; Give information on recovering, if there was a crash.
1572 (and auto-save-list-file-prefix
1573 ;; Don't signal an error if the
1574 ;; directory for auto-save-list files
1575 ;; does not yet exist.
1576 (file-directory-p (file-name-directory
1577 auto-save-list-file-prefix))
1579 (file-name-directory auto-save-list-file-prefix)
1582 (regexp-quote (file-name-nondirectory
1583 auto-save-list-file-prefix)))
1585 (insert "\n\nIf an Emacs session crashed recently, "
1586 "type Meta-x recover-session RET\nto recover"
1587 " the files you were editing."))
1589 ;; Display the input that we set up in the buffer.
1590 (set-buffer-modified-p nil)
1591 (setq buffer-read-only t)
1592 (if (and view-read-only (not view-mode))
1593 (view-mode-enter nil 'kill-buffer))
1594 (goto-char (point-min))
1596 (if (or (window-minibuffer-p)
1597 (window-dedicated-p (selected-window)))
1598 ;; If hide-on-input is nil, creating a new frame will
1599 ;; generate enough events that the subsequent `sit-for'
1600 ;; will immediately return anyway.
1601 nil ;; (pop-to-buffer (current-buffer))
1602 (save-window-excursion
1603 (switch-to-buffer (current-buffer))
1606 (switch-to-buffer (current-buffer))))))
1607 ;; Unwind ... ensure splash buffer is killed
1609 (kill-buffer "GNU Emacs")
1610 (switch-to-buffer "GNU Emacs")
1611 (rename-buffer "*About GNU Emacs*" t)))))
1614 (defun startup-echo-area-message ()
1615 (if (eq (key-binding "\C-h\C-p") 'describe-project)
1616 "For information about the GNU Project and its goals, type C-h C-p."
1617 (substitute-command-keys
1618 "For information about the GNU Project and its goals, type \
1619 \\[describe-project].")))
1622 (defun display-startup-echo-area-message ()
1623 (let ((resize-mini-windows t))
1624 (or noninteractive ;(input-pending-p) init-file-had-error
1625 ;; t if the init file says to inhibit the echo area startup message.
1626 (and inhibit-startup-echo-area-message
1628 (or (and (get 'inhibit-startup-echo-area-message 'saved-value)
1629 (equal inhibit-startup-echo-area-message
1630 (if (equal init-file-user "")
1633 ;; Wasn't set with custom; see if .emacs has a setq.
1634 (let ((buffer (get-buffer-create " *temp*")))
1639 (insert-file-contents user-init-file)
1642 "([ \t\n]*setq[ \t\n]+"
1643 "inhibit-startup-echo-area-message[ \t\n]+"
1646 (if (equal init-file-user "")
1652 (kill-buffer buffer)))))
1653 ;; display-splash-screen at the end of command-line-1 calls
1654 ;; use-fancy-splash-screens-p. This can cause image.el to be
1655 ;; loaded, putting "Loading image... done" in the echo area.
1656 ;; This hides startup-echo-area-message. So
1657 ;; use-fancy-splash-screens-p is called here simply to get the
1658 ;; loading of image.el (if needed) out of the way before
1659 ;; display-startup-echo-area-message runs.
1661 (use-fancy-splash-screens-p)
1662 (message "%s" (startup-echo-area-message))))))
1665 (defun display-splash-screen (&optional hide-on-input)
1666 "Display splash screen according to display.
1667 Fancy splash screens are used on graphic displays,
1669 With a prefix argument, any user input hides the splash screen."
1671 ;; Prevent recursive calls from server-process-filter.
1672 (if (not (get-buffer "GNU Emacs"))
1673 (if (use-fancy-splash-screens-p)
1674 (fancy-splash-screens hide-on-input)
1675 (normal-splash-screen hide-on-input))))
1677 (defun command-line-1 (command-line-args-left)
1678 (display-startup-echo-area-message)
1680 ;; Delay 2 seconds after an init file error message
1681 ;; was displayed, so user can read it.
1682 (when init-file-had-error
1685 (when (and pure-space-overflow
1686 (not noninteractive))
1689 "Building Emacs overflowed pure space. (See the node Pure Storage in the Lisp manual for details.)"
1692 (when command-line-args-left
1693 ;; We have command args; process them.
1694 (let ((dir command-line-default-directory)
1698 ;; This approach loses for "-batch -L DIR --eval "(require foo)",
1699 ;; if foo is intended to be found in DIR.
1701 ;; ;; The directories listed in --directory/-L options will *appear*
1702 ;; ;; at the front of `load-path' in the order they appear on the
1703 ;; ;; command-line. We cannot do this by *placing* them at the front
1704 ;; ;; in the order they appear, so we need this variable to hold them,
1708 ;; To DTRT we keep track of the splice point and modify `load-path'
1709 ;; straight away upon any --directory/-L option.
1711 just-files ;; t if this follows the magic -- option.
1712 ;; This includes our standard options' long versions
1713 ;; and long versions of what's on command-switch-alist.
1715 (append '(("--funcall") ("--load") ("--insert") ("--kill")
1716 ("--directory") ("--eval") ("--execute") ("--no-splash")
1717 ("--find-file") ("--visit") ("--file") ("--no-desktop"))
1718 (mapcar (lambda (elt)
1719 (list (concat "-" (car elt))))
1720 command-switch-alist)))
1724 ;; Add the long X options to longopts.
1725 (dolist (tem command-line-x-option-alist)
1726 (if (string-match "^--" (car tem))
1727 (push (list (car tem)) longopts)))
1729 ;; Loop, processing options.
1730 (while command-line-args-left
1731 (let* ((argi (car command-line-args-left))
1734 (setq command-line-args-left (cdr command-line-args-left))
1736 ;; Do preliminary decoding of the option.
1738 ;; After --, don't look for options; treat all args as files.
1740 ;; Convert long options to ordinary options
1741 ;; and separate out an attached option argument into argval.
1742 (when (string-match "^\\(--[^=]*\\)=" argi)
1743 (setq argval (substring argi (match-end 0))
1744 argi (match-string 1 argi)))
1745 (if (equal argi "--")
1746 (setq completion nil)
1747 (setq completion (try-completion argi longopts)))
1748 (if (eq completion t)
1749 (setq argi (substring argi 1))
1750 (if (stringp completion)
1751 (let ((elt (assoc completion longopts)))
1753 (error "Option `%s' is ambiguous" argi))
1754 (setq argi (substring (car elt) 1)))
1758 ;; Execute the option.
1759 (cond ((setq tem (assoc argi command-switch-alist))
1761 (let ((command-line-args-left
1762 (cons argval command-line-args-left)))
1763 (funcall (cdr tem) argi))
1764 (funcall (cdr tem) argi)))
1766 ((equal argi "-no-splash")
1767 (setq inhibit-startup-message t))
1769 ((member argi '("-f" ; what the manual claims
1771 "-e")) ; what the source used to say
1772 (setq tem (intern (or argval (pop command-line-args-left))))
1774 (command-execute tem)
1777 ((member argi '("-eval" "-execute"))
1778 (eval (read (or argval (pop command-line-args-left)))))
1780 ((member argi '("-L" "-directory"))
1781 (setq tem (expand-file-name
1782 (command-line-normalize-file-name
1783 (or argval (pop command-line-args-left)))))
1784 (cond (splice (setcdr splice (cons tem (cdr splice)))
1785 (setq splice (cdr splice)))
1786 (t (setq load-path (cons tem load-path)
1787 splice load-path))))
1789 ((member argi '("-l" "-load"))
1790 (let* ((file (command-line-normalize-file-name
1791 (or argval (pop command-line-args-left))))
1792 ;; Take file from default dir if it exists there;
1793 ;; otherwise let `load' search for it.
1794 (file-ex (expand-file-name file)))
1795 (when (file-exists-p file-ex)
1796 (setq file file-ex))
1799 ;; This is used to handle -script. It's not clear
1800 ;; we need to document it.
1801 ((member argi '("-scriptload"))
1802 (let* ((file (command-line-normalize-file-name
1803 (or argval (pop command-line-args-left))))
1804 ;; Take file from default dir.
1805 (file-ex (expand-file-name file)))
1806 (load file-ex nil t t)))
1808 ((equal argi "-insert")
1809 (setq tem (or argval (pop command-line-args-left)))
1811 (error "File name omitted from `-insert' option"))
1812 (insert-file-contents (command-line-normalize-file-name tem)))
1814 ((equal argi "-kill")
1817 ;; This is for when they use --no-desktop with -q, or
1818 ;; don't load Desktop in their .emacs. If desktop.el
1819 ;; _is_ loaded, it will handle this switch, and we
1820 ;; won't see it by the time we get here.
1821 ((equal argi "-no-desktop")
1822 (message "\"--no-desktop\" ignored because the Desktop package is not loaded"))
1824 ((string-match "^\\+[0-9]+\\'" argi)
1825 (setq line (string-to-number argi)))
1827 ((string-match "^\\+\\([0-9]+\\):\\([0-9]+\\)\\'" argi)
1828 (setq line (string-to-number (match-string 1 argi))
1829 column (string-to-number (match-string 2 argi))))
1831 ((setq tem (assoc argi command-line-x-option-alist))
1832 ;; Ignore X-windows options and their args if not using X.
1833 (setq command-line-args-left
1834 (nthcdr (nth 1 tem) command-line-args-left)))
1836 ((member argi '("-find-file" "-file" "-visit"))
1837 ;; An explicit option to specify visiting a file.
1838 (setq tem (or argval (pop command-line-args-left)))
1839 (unless (stringp tem)
1840 (error "File name omitted from `%s' option" argi))
1841 (setq file-count (1+ file-count))
1842 (let ((file (expand-file-name
1843 (command-line-normalize-file-name tem) dir)))
1844 (if (= file-count 1)
1845 (setq first-file-buffer (find-file file))
1846 (find-file-other-window file)))
1850 (unless (< column 1)
1851 (move-to-column (1- column)))
1855 (setq just-files t))
1857 ;; We have almost exhausted our options. See if the
1858 ;; user has made any other command-line options available
1859 (let ((hooks command-line-functions) ;; lrs 7/31/89
1862 (not (setq did-hook (funcall (car hooks)))))
1863 (setq hooks (cdr hooks)))
1865 ;; Presume that the argument is a file name.
1867 (if (string-match "\\`-" argi)
1868 (error "Unknown option `%s'" argi))
1869 (setq file-count (1+ file-count))
1872 (command-line-normalize-file-name orig-argi)
1874 (if (= file-count 1)
1875 (setq first-file-buffer (find-file file))
1876 (find-file-other-window file)))
1880 (unless (< column 1)
1881 (move-to-column (1- column)))
1882 (setq column 0))))))))
1884 ;; If 3 or more files visited, and not all visible,
1885 ;; show user what they all are. But leave the last one current.
1886 (and (> file-count 2)
1887 (not noninteractive)
1888 (not inhibit-startup-buffer-menu)
1889 (or (get-buffer-window first-file-buffer)
1892 ;; Maybe display a startup screen.
1893 (unless (or inhibit-startup-message
1895 emacs-quick-startup)
1896 ;; Display a startup screen, after some preparations.
1898 ;; If there are no switches to process, we might as well
1899 ;; run this hook now, and there may be some need to do it
1900 ;; before doing any output.
1901 (run-hooks 'emacs-startup-hook)
1902 (and term-setup-hook
1903 (run-hooks 'term-setup-hook))
1904 (setq inhibit-startup-hooks t)
1906 ;; It's important to notice the user settings before we
1907 ;; display the startup message; otherwise, the settings
1908 ;; won't take effect until the user gives the first
1909 ;; keystroke, and that's distracting.
1910 (when (fboundp 'frame-notice-user-settings)
1911 (frame-notice-user-settings))
1913 ;; If there are no switches to process, we might as well
1914 ;; run this hook now, and there may be some need to do it
1915 ;; before doing any output.
1916 (when window-setup-hook
1917 (run-hooks 'window-setup-hook)
1918 ;; Don't let the hook be run twice.
1919 (setq window-setup-hook nil))
1921 ;; Do this now to avoid an annoying delay if the user
1922 ;; clicks the menu bar during the sit-for.
1923 (when (display-popup-menus-p)
1924 (precompute-menubar-bindings))
1926 (setq menubar-bindings-done t))
1928 ;; If *scratch* is selected and it is empty, insert an
1929 ;; initial message saying not to create a file there.
1930 (when (and initial-scratch-message
1931 (equal (buffer-name) "*scratch*")
1932 (= 0 (buffer-size)))
1933 (insert initial-scratch-message)
1934 (set-buffer-modified-p nil))
1936 ;; If user typed input during all that work,
1937 ;; abort the startup screen. Otherwise, display it now.
1938 (unless (input-pending-p)
1939 (display-splash-screen t))))
1942 (defun command-line-normalize-file-name (file)
1943 "Collapse multiple slashes to one, to handle non-Emacs file names."
1945 ;; Use arg 1 so that we don't collapse // at the start of the file name.
1946 ;; That is significant on some systems.
1947 ;; However, /// at the beginning is supposed to mean just /, not //.
1948 (if (string-match "^///+" file)
1949 (setq file (replace-match "/" t t file)))
1950 (while (string-match "//+" file 1)
1951 (setq file (replace-match "/" t t file)))
1954 ;; arch-tag: 7e294698-244d-4758-984b-4047f887a5db
1955 ;;; startup.el ends here