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
)
788 (normal-erase-is-backspace-setup-frame)
790 ;; Register default TTY colors for the case the terminal hasn't a
791 ;; terminal init file. We do this regardles of whether the terminal
792 ;; supports colors or not and regardless the current display type,
793 ;; since users can connect to color-capable terminals and also
794 ;; switch color support on or off in mid-session by setting the
795 ;; tty-color-mode frame parameter.
796 (tty-register-default-colors)
798 ;; Record whether the tool-bar is present before the user and site
799 ;; init files are processed. frame-notice-user-settings uses this
800 ;; to determine if the tool-bar has been disabled by the init files,
801 ;; and the frame needs to be resized.
802 (when (fboundp 'frame-notice-user-settings
)
803 (let ((tool-bar-lines (or (assq 'tool-bar-lines initial-frame-alist
)
804 (assq 'tool-bar-lines default-frame-alist
))))
805 (setq tool-bar-originally-present
808 (not (eq 0 (cdr tool-bar-lines
)))))))
810 (let ((old-scalable-fonts-allowed scalable-fonts-allowed
)
811 (old-font-list-limit font-list-limit
)
812 (old-face-ignored-fonts face-ignored-fonts
))
814 ;; Run the site-start library if it exists. The point of this file is
815 ;; that it is run before .emacs. There is no point in doing this after
816 ;; .emacs; that is useless.
818 (load site-run-file t t
))
820 ;; Sites should not disable this. Only individuals should disable
821 ;; the startup message.
822 (setq inhibit-startup-message nil
)
824 ;; Warn for invalid user name.
826 (if (string-match "[~/:\n]" init-file-user
)
827 (display-warning 'initialization
828 (format "Invalid user name %s"
831 (if (file-directory-p (expand-file-name
832 ;; We don't support ~USER on MS-Windows except
833 ;; for the current user, and always load .emacs
834 ;; from the current user's home directory (see
835 ;; below). So always check "~", even if invoked
836 ;; with "-u USER", or if $USER or $LOGNAME are
837 ;; set to something different.
838 (if (eq system-type
'windows-nt
)
840 (concat "~" init-file-user
))))
842 (display-warning 'initialization
843 (format "User %s has no home directory"
847 ;; Load that user's init file, or the default one, or none.
848 (let (debug-on-error-from-init-file
849 debug-on-error-should-be-set
850 (debug-on-error-initial
851 (if (eq init-file-debug t
) 'startup init-file-debug
))
852 (orig-enable-multibyte default-enable-multibyte-characters
))
853 (let ((debug-on-error debug-on-error-initial
)
854 ;; This function actually reads the init files.
859 (let ((user-init-file-1
861 ((eq system-type
'ms-dos
)
862 (concat "~" init-file-user
"/_emacs"))
863 ((eq system-type
'windows-nt
)
864 ;; Prefer .emacs on Windows.
865 (if (directory-files "~" nil
"^\\.emacs\\(\\.elc?\\)?$")
867 ;; Also support _emacs for compatibility.
868 (if (directory-files "~" nil
"^_emacs\\(\\.elc?\\)?$")
870 ;; But default to .emacs if _emacs does not exist.
872 ((eq system-type
'vax-vms
)
875 (concat "~" init-file-user
"/.emacs")))))
876 ;; This tells `load' to store the file name found
877 ;; into user-init-file.
878 (setq user-init-file t
)
879 (load user-init-file-1 t t
)
881 (when (eq user-init-file t
)
882 ;; If we did not find ~/.emacs, try
883 ;; ~/.emacs.d/init.el.
887 (file-name-as-directory
888 (concat "~" init-file-user
"/.emacs.d")))))
891 ;; If we did not find the user's init file,
892 ;; set user-init-file conclusively.
893 ;; Don't let it be set from default.el.
894 (when (eq user-init-file t
)
895 (setq user-init-file user-init-file-1
))))
897 ;; If we loaded a compiled file, set
898 ;; `user-init-file' to the source version if that
900 (when (and user-init-file
901 (equal (file-name-extension user-init-file
)
903 (let* ((source (file-name-sans-extension user-init-file
))
904 (alt (concat source
".el")))
905 (setq source
(cond ((file-exists-p alt
) alt
)
906 ((file-exists-p source
) source
)
909 (when (file-newer-than-file-p source user-init-file
)
910 (message "Warning: %s is newer than %s"
911 source user-init-file
)
913 (setq user-init-file source
))))
915 (unless inhibit-default-init
916 (let ((inhibit-startup-message nil
))
917 ;; Users are supposed to be told their rights.
918 ;; (Plus how to get help and how to undo.)
919 ;; Don't you dare turn this off for anyone
921 (load "default" t t
)))))))))
923 ;; Do this without a condition-case if the user wants to debug.
925 (condition-case error
928 (setq init-file-had-error nil
))
930 (let ((message-log-max nil
))
932 (set-buffer (get-buffer-create "*Messages*"))
934 (format "An error has occurred while loading `%s':\n\n"
937 (get (car error
) 'error-message
)
938 (if (cdr error
) ": " "")
939 (mapconcat (lambda (s) (prin1-to-string s t
)) (cdr error
) ", "))
941 "To ensure normal operation, you should investigate and remove the\n"
942 "cause of the error in your initialization file. Start Emacs with\n"
943 "the `--debug-init' option to view a complete error backtrace.\n\n"))
944 (message "Error in init file: %s%s%s"
945 (get (car error
) 'error-message
)
946 (if (cdr error
) ": " "")
947 (mapconcat 'prin1-to-string
(cdr error
) ", "))
948 (let ((pop-up-windows nil
))
949 (pop-to-buffer "*Messages*"))
950 (setq init-file-had-error t
)))))
952 (if (and deactivate-mark transient-mark-mode
)
953 (with-current-buffer (window-buffer)
956 ;; If the user has a file of abbrevs, read it.
957 (if (file-exists-p abbrev-file-name
)
958 (quietly-read-abbrev-file abbrev-file-name
))
960 ;; If the abbrevs came entirely from the init file or the
961 ;; abbrevs file, they do not need saving.
962 (setq abbrevs-changed nil
)
964 ;; If we can tell that the init file altered debug-on-error,
965 ;; arrange to preserve the value that it set up.
966 (or (eq debug-on-error debug-on-error-initial
)
967 (setq debug-on-error-should-be-set t
968 debug-on-error-from-init-file debug-on-error
)))
969 (if debug-on-error-should-be-set
970 (setq debug-on-error debug-on-error-from-init-file
))
971 (unless (or default-enable-multibyte-characters
972 (eq orig-enable-multibyte default-enable-multibyte-characters
))
973 ;; Init file changed to unibyte. Reset existing multibyte
974 ;; buffers (probably *scratch*, *Messages*, *Minibuff-0*).
975 ;; Arguably this should only be done if they're free of
976 ;; multibyte characters.
977 (mapcar (lambda (buffer)
978 (with-current-buffer buffer
979 (if enable-multibyte-characters
980 (set-buffer-multibyte nil
))))
982 ;; Also re-set the language environment in case it was
983 ;; originally done before unibyte was set and is sensitive to
984 ;; unibyte (display table, terminal coding system &c).
985 (set-language-environment current-language-environment
)))
987 ;; Do this here in case the init file sets mail-host-address.
988 (if (equal user-mail-address
"")
989 (setq user-mail-address
(or (getenv "EMAIL")
990 (concat (user-login-name) "@"
991 (or mail-host-address
994 ;; Originally face attributes were specified via
995 ;; `font-lock-face-attributes'. Users then changed the default
996 ;; face attributes by setting that variable. However, we try and
997 ;; be back-compatible and respect its value if set except for
998 ;; faces where M-x customize has been used to save changes for the
1000 (when (boundp 'font-lock-face-attributes
)
1001 (let ((face-attributes font-lock-face-attributes
))
1002 (while face-attributes
1003 (let* ((face-attribute (pop face-attributes
))
1004 (face (car face-attribute
)))
1005 ;; Rustle up a `defface' SPEC from a
1006 ;; `font-lock-face-attributes' entry.
1007 (unless (get face
'saved-face
)
1008 (let ((foreground (nth 1 face-attribute
))
1009 (background (nth 2 face-attribute
))
1010 (bold-p (nth 3 face-attribute
))
1011 (italic-p (nth 4 face-attribute
))
1012 (underline-p (nth 5 face-attribute
))
1015 (setq face-spec
(cons ':foreground
(cons foreground face-spec
))))
1017 (setq face-spec
(cons ':background
(cons background face-spec
))))
1019 (setq face-spec
(append '(:weight bold
) face-spec
)))
1021 (setq face-spec
(append '(:slant italic
) face-spec
)))
1023 (setq face-spec
(append '(:underline t
) face-spec
)))
1024 (face-spec-set face
(list (list t face-spec
)) nil
)))))))
1026 ;; If parameter have been changed in the init file which influence
1027 ;; face realization, clear the face cache so that new faces will
1029 (unless (and (eq scalable-fonts-allowed old-scalable-fonts-allowed
)
1030 (eq font-list-limit old-font-list-limit
)
1031 (eq face-ignored-fonts old-face-ignored-fonts
))
1032 (clear-face-cache)))
1034 (run-hooks 'after-init-hook
)
1036 ;; Decode all default-directory.
1037 (if (and default-enable-multibyte-characters locale-coding-system
)
1039 (dolist (elt (buffer-list))
1041 (if default-directory
1042 (setq default-directory
1043 (decode-coding-string default-directory
1044 locale-coding-system t
))))
1045 (setq command-line-default-directory
1046 (decode-coding-string command-line-default-directory
1047 locale-coding-system t
))))
1049 ;; If *scratch* exists and init file didn't change its mode, initialize it.
1050 (if (get-buffer "*scratch*")
1051 (with-current-buffer "*scratch*"
1052 (if (eq major-mode
'fundamental-mode
)
1053 (funcall initial-major-mode
))))
1055 ;; Load library for our terminal type.
1056 ;; User init file can set term-file-prefix to nil to prevent this.
1057 (unless (or noninteractive
1058 initial-window-system
)
1059 (tty-run-terminal-initialization (selected-frame)))
1061 ;; Update the out-of-memory error message based on user's key bindings
1062 ;; for save-some-buffers.
1063 (setq memory-signal-data
1065 (substitute-command-keys "Memory exhausted--use \\[save-some-buffers] then exit and restart Emacs")))
1067 ;; Process the remaining args.
1068 (command-line-1 (cdr command-line-args
))
1070 ;; If -batch, terminate after processing the command options.
1071 (if noninteractive
(kill-emacs t
))
1073 ;; Run emacs-session-restore (session management) if started by
1074 ;; the session manager and we have a session manager connection.
1075 (if (and (boundp 'x-session-previous-id
)
1076 (stringp x-session-previous-id
))
1078 (emacs-session-restore x-session-previous-id
))))
1080 (defcustom initial-scratch-message
(purecopy "\
1081 ;; This buffer is for notes you don't want to save, and for Lisp evaluation.
1082 ;; If you want to create a file, visit that file with C-x C-f,
1083 ;; then enter the text in that file's own buffer.
1086 "Initial message displayed in *scratch* buffer at startup.
1087 If this is nil, no message will be displayed.
1088 If `inhibit-splash-screen' is non-nil, then no message is displayed,
1089 regardless of the value of this variable."
1090 :type
'(choice (text :tag
"Message")
1091 (const :tag
"none" nil
))
1092 :group
'initialization
)
1095 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1096 ;;; Fancy splash screen
1097 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1099 (defvar fancy-splash-text
1100 '((:face variable-pitch
1101 "You can do basic editing with the menu bar and scroll bar \
1102 using the mouse.\n\n"
1103 :face
(variable-pitch :weight bold
)
1104 "Important Help menu items:\n"
1105 :face variable-pitch
1107 (let* ((en "TUTORIAL")
1108 (tut (or (get-language-info current-language-environment
1111 (title (with-temp-buffer
1112 (insert-file-contents
1113 (expand-file-name tut data-directory
)
1115 (search-forward ".")
1116 (buffer-substring (point-min) (1- (point))))))
1117 ;; If there is a specific tutorial for the current language
1118 ;; environment and it is not English, append its title.
1120 "Emacs Tutorial\tLearn how to use Emacs efficiently"
1121 (if (string= en tut
)
1123 (concat " (" title
")"))
1125 :face variable-pitch
"\
1126 Emacs FAQ\tFrequently asked questions and answers
1127 Read the Emacs Manual\tView the Emacs manual using Info
1128 \(Non)Warranty\tGNU Emacs comes with "
1129 :face
(variable-pitch :slant oblique
)
1130 "ABSOLUTELY NO WARRANTY\n"
1131 :face variable-pitch
1133 Copying Conditions\tConditions for redistributing and changing Emacs
1134 Getting New Versions\tHow to obtain the latest version of Emacs
1135 More Manuals / Ordering Manuals Buying printed manuals from the FSF\n")
1136 (:face variable-pitch
1137 "You can do basic editing with the menu bar and scroll bar \
1138 using the mouse.\n\n"
1139 :face
(variable-pitch :weight bold
)
1140 "Useful File menu items:\n"
1141 :face variable-pitch
"\
1142 Exit Emacs\t(Or type Control-x followed by Control-c)
1143 Recover Crashed Session\tRecover files you were editing before a crash
1150 "A list of texts to show in the middle part of splash screens.
1151 Each element in the list should be a list of strings or pairs
1152 `:face FACE', like `fancy-splash-insert' accepts them.")
1155 (defgroup fancy-splash-screen
()
1156 "Fancy splash screen when Emacs starts."
1158 :group
'initialization
)
1161 (defcustom fancy-splash-delay
7
1162 "*Delay in seconds between splash screens."
1163 :group
'fancy-splash-screen
1167 (defcustom fancy-splash-max-time
30
1168 "*Show splash screens for at most this number of seconds.
1169 Values less than twice `fancy-splash-delay' are ignored."
1170 :group
'fancy-splash-screen
1174 (defcustom fancy-splash-image nil
1175 "*The image to show in the splash screens, or nil for defaults."
1176 :group
'fancy-splash-screen
1177 :type
'(choice (const :tag
"Default" nil
)
1178 (file :tag
"File")))
1181 ;; These are temporary storage areas for the splash screen display.
1183 (defvar fancy-current-text nil
)
1184 (defvar fancy-splash-help-echo nil
)
1185 (defvar fancy-splash-stop-time nil
)
1186 (defvar fancy-splash-outer-buffer nil
)
1188 (defun fancy-splash-insert (&rest args
)
1189 "Insert text into the current buffer, with faces.
1190 Arguments from ARGS should be either strings, functions called
1191 with no args that return a string, or pairs `:face FACE',
1192 where FACE is a valid face specification, as it can be used with
1193 `put-text-property'."
1194 (let ((current-face nil
))
1196 (if (eq (car args
) :face
)
1197 (setq args
(cdr args
) current-face
(car args
))
1198 (insert (propertize (let ((it (car args
)))
1203 'help-echo fancy-splash-help-echo
)))
1204 (setq args
(cdr args
)))))
1207 (defun fancy-splash-head ()
1208 "Insert the head part of the splash screen into the current buffer."
1209 (let* ((image-file (cond ((stringp fancy-splash-image
)
1211 ((and (display-color-p)
1212 (image-type-available-p 'xpm
))
1213 (if (and (fboundp 'x-display-planes
)
1214 (= (funcall 'x-display-planes
) 8))
1218 (img (create-image image-file
))
1219 (image-width (and img
(car (image-size img
))))
1220 (window-width (window-width (selected-window))))
1222 (when (> window-width image-width
)
1223 ;; Center the image in the window.
1224 (insert (propertize " " 'display
1225 `(space :align-to
(+ center
(-0.5 .
,img
)))))
1227 ;; Change the color of the XPM version of the splash image
1228 ;; so that it is visible with a dark frame background.
1229 (when (and (memq 'xpm img
)
1230 (eq (frame-parameter nil
'background-mode
) 'dark
))
1231 (setq img
(append img
'(:color-symbols
(("#000000" .
"gray30"))))))
1233 ;; Insert the image with a help-echo and a keymap.
1234 (let ((map (make-sparse-keymap))
1235 (help-echo "mouse-2: browse http://www.gnu.org/"))
1236 (define-key map
[mouse-2
]
1239 (browse-url "http://www.gnu.org/")
1241 (define-key map
[down-mouse-2
] 'ignore
)
1242 (define-key map
[up-mouse-2
] 'ignore
)
1243 (insert-image img
(propertize "xxx" 'help-echo help-echo
1246 (fancy-splash-insert
1247 :face
'(variable-pitch :foreground
"red")
1248 (if (eq system-type
'gnu
/linux
)
1249 "GNU Emacs is one component of the GNU/Linux operating system."
1250 "GNU Emacs is one component of the GNU operating system."))
1252 (unless (equal (buffer-name fancy-splash-outer-buffer
) "*scratch*")
1253 (fancy-splash-insert :face
'variable-pitch
1254 (substitute-command-keys
1255 "Type \\[recenter] to begin editing your file.\n"))))
1258 (defun fancy-splash-tail ()
1259 "Insert the tail part of the splash screen into the current buffer."
1260 (let ((fg (if (eq (frame-parameter nil
'background-mode
) 'dark
)
1261 "cyan" "darkblue")))
1262 (fancy-splash-insert :face
`(variable-pitch :foreground
,fg
)
1266 :face
'(variable-pitch :height
0.5)
1267 "Copyright (C) 2006 Free Software Foundation, Inc.")
1268 (and auto-save-list-file-prefix
1269 ;; Don't signal an error if the
1270 ;; directory for auto-save-list files
1271 ;; does not yet exist.
1272 (file-directory-p (file-name-directory
1273 auto-save-list-file-prefix
))
1275 (file-name-directory auto-save-list-file-prefix
)
1278 (regexp-quote (file-name-nondirectory
1279 auto-save-list-file-prefix
)))
1281 (fancy-splash-insert :face
'(variable-pitch :foreground
"red")
1282 "\n\nIf an Emacs session crashed recently, "
1283 "type M-x recover-session RET\nto recover"
1284 " the files you were editing."))))
1286 (defun fancy-splash-screens-1 (buffer)
1287 "Timer function displaying a splash screen."
1288 (when (> (float-time) fancy-splash-stop-time
)
1289 (throw 'stop-splashing nil
))
1290 (unless fancy-current-text
1291 (setq fancy-current-text fancy-splash-text
))
1292 (let ((text (car fancy-current-text
)))
1295 (if pure-space-overflow
1297 Warning Warning!!! Pure space overflow !!!Warning Warning
1298 \(See the node Pure Storage in the Lisp manual for details.)\n"))
1300 (apply #'fancy-splash-insert text
)
1302 (unless (current-message)
1303 (message fancy-splash-help-echo
))
1304 (set-buffer-modified-p nil
)
1305 (goto-char (point-min))
1306 (force-mode-line-update)
1307 (setq fancy-current-text
(cdr fancy-current-text
))))
1309 (defun fancy-splash-default-action ()
1310 "Stop displaying the splash screen buffer.
1311 This is an internal function used to turn off the splash screen after
1312 the user caused an input event by hitting a key or clicking with the
1315 (if (and (memq 'down
(event-modifiers last-command-event
))
1316 (eq (posn-window (event-start last-command-event
))
1318 ;; This is a mouse-down event in the splash screen window.
1319 ;; Ignore it and consume the corresponding mouse-up event.
1321 (push last-command-event unread-command-events
))
1324 (defun fancy-splash-exit ()
1325 "Exit the splash screen."
1326 (if (get-buffer "GNU Emacs")
1327 (throw 'stop-splashing nil
)))
1329 (defun fancy-splash-delete-frame (frame)
1330 "Exit the splash screen after the frame is deleted."
1331 ;; We can not throw from `delete-frame-events', so we set up a timer
1332 ;; to exit the recursive edit as soon as Emacs is idle again.
1333 (if (frame-live-p frame
)
1334 (run-at-time 0 nil
'fancy-splash-exit
)))
1336 (defun fancy-splash-screens ()
1337 "Display fancy splash screens when Emacs starts."
1338 (setq fancy-splash-help-echo
(startup-echo-area-message))
1339 (let ((old-hourglass display-hourglass
)
1340 (fancy-splash-outer-buffer (current-buffer))
1342 (old-minor-mode-map-alist minor-mode-map-alist
)
1343 (old-emulation-mode-map-alists emulation-mode-map-alists
)
1344 (frame (fancy-splash-frame))
1346 (save-selected-window
1347 (select-frame frame
)
1348 (switch-to-buffer "GNU Emacs")
1350 (setq splash-buffer
(current-buffer))
1351 (catch 'stop-splashing
1353 (let* ((map (make-sparse-keymap))
1354 (overriding-local-map map
)
1355 ;; Catch if our frame is deleted; the delete-frame
1356 ;; event is unreliable and is handled by
1357 ;; `special-event-map' anyway.
1358 (delete-frame-functions (cons 'fancy-splash-delete-frame
1359 delete-frame-functions
)))
1360 (define-key map
[t] 'fancy-splash-default-action)
1361 (define-key map [mouse-movement] 'ignore)
1362 (define-key map [mode-line t] 'ignore)
1363 (define-key map [select-window] 'ignore)
1364 (setq cursor-type nil
1365 display-hourglass nil
1366 minor-mode-map-alist nil
1367 emulation-mode-map-alists nil
1369 mode-line-format (propertize "---- %b %-"
1370 'face 'mode-line-buffer-id)
1371 fancy-splash-stop-time (+ (float-time)
1372 fancy-splash-max-time)
1373 timer (run-with-timer 0 fancy-splash-delay
1374 #'fancy-splash-screens-1
1377 (cancel-timer timer)
1378 (setq display-hourglass old-hourglass
1379 minor-mode-map-alist old-minor-mode-map-alist
1380 emulation-mode-map-alists old-emulation-mode-map-alists)
1381 (kill-buffer splash-buffer)
1382 (when (frame-live-p frame)
1383 (select-frame frame)
1384 (switch-to-buffer fancy-splash-outer-buffer)))))))
1386 (defun fancy-splash-frame ()
1387 "Return the frame to use for the fancy splash screen.
1388 Returning non-nil does not mean we should necessarily
1389 use the fancy splash screen, but if we do use it,
1390 we put it on this frame."
1392 (dolist (frame (append (frame-list) (list (selected-frame))))
1393 (if (and (frame-visible-p frame)
1394 (not (window-minibuffer-p (frame-selected-window frame))))
1395 (setq chosen-frame frame)))
1398 (defun use-fancy-splash-screens-p ()
1399 "Return t if fancy splash screens should be used."
1400 (when (and (display-graphic-p)
1401 (or (and (display-color-p)
1402 (image-type-available-p 'xpm))
1403 (image-type-available-p 'pbm)))
1404 (let ((frame (fancy-splash-frame)))
1406 (let* ((img (create-image (or fancy-splash-image
1407 (if (and (display-color-p)
1408 (image-type-available-p 'xpm))
1409 "splash.xpm" "splash.pbm"))))
1410 (image-height (and img (cdr (image-size img))))
1411 (window-height (1- (window-height (frame-selected-window frame)))))
1412 (> window-height (+ image-height 19)))))))
1415 (defun normal-splash-screen ()
1416 "Display splash screen when Emacs starts."
1417 (let ((prev-buffer (current-buffer)))
1419 (with-current-buffer (get-buffer-create "GNU Emacs")
1420 (set (make-local-variable 'tab-width) 8)
1421 (set (make-local-variable 'mode-line-format)
1422 (propertize "---- %b %-" 'face 'mode-line-buffer-id))
1424 (if pure-space-overflow
1426 Warning Warning!!! Pure space overflow !!!Warning Warning
1427 \(See the node Pure Storage in the Lisp manual for details.)\n"))
1429 ;; The convention for this piece of code is that
1430 ;; each piece of output starts with one or two newlines
1431 ;; and does not end with any newlines.
1432 (insert "Welcome to GNU Emacs")
1434 (if (eq system-type 'gnu/linux)
1435 ", one component of the GNU/Linux operating system.\n"
1436 ", a part of the GNU operating system.\n"))
1438 (unless (equal (buffer-name prev-buffer) "*scratch*")
1439 (insert (substitute-command-keys
1440 "\nType \\[recenter] to begin editing your file.\n")))
1442 (if (display-mouse-p)
1443 ;; The user can use the mouse to activate menus
1444 ;; so give help in terms of menu items.
1447 You can do basic editing with the menu bar and scroll bar using the mouse.
1449 Useful File menu items:
1450 Exit Emacs (or type Control-x followed by Control-c)
1451 Recover Crashed Session Recover files you were editing before a crash
1453 Important Help menu items:
1454 Emacs Tutorial Learn how to use Emacs efficiently
1455 Emacs FAQ Frequently asked questions and answers
1456 Read the Emacs Manual View the Emacs manual using Info
1457 \(Non)Warranty GNU Emacs comes with ABSOLUTELY NO WARRANTY
1458 Copying Conditions Conditions for redistributing and changing Emacs
1459 Getting New Versions How to obtain the latest version of Emacs
1460 More Manuals / Ordering Manuals How to order printed manuals from the FSF
1462 (insert "\n\n" (emacs-version)
1464 Copyright (C) 2006 Free Software Foundation, Inc."))
1466 ;; No mouse menus, so give help using kbd commands.
1468 ;; If keys have their default meanings,
1469 ;; use precomputed string to save lots of time.
1470 (if (and (eq (key-binding "\C-h") 'help-command)
1471 (eq (key-binding "\C-xu") 'advertised-undo)
1472 (eq (key-binding "\C-x\C-c") 'save-buffers-kill-terminal)
1473 (eq (key-binding "\C-ht") 'help-with-tutorial)
1474 (eq (key-binding "\C-hi") 'info)
1475 (eq (key-binding "\C-hr") 'info-emacs-manual)
1476 (eq (key-binding "\C-h\C-n") 'view-emacs-news))
1478 Get help C-h (Hold down CTRL and press h)
1480 Emacs tutorial C-h t Undo changes C-x u
1481 Buy manuals C-h C-m Exit Emacs C-x C-c
1482 Browse manuals C-h i")
1484 (insert (substitute-command-keys
1487 Emacs manual \\[info-emacs-manual]
1488 Emacs tutorial \\[help-with-tutorial]\tUndo changes\t\\[advertised-undo]
1489 Buy manuals \\[view-order-manuals]\tExit Emacs\t\\[save-buffers-kill-terminal]
1490 Browse manuals \\[info]"
1491 (let ((where (where-is-internal
1492 'help-command nil t)))
1494 (key-description where)
1497 ;; Say how to use the menu bar with the keyboard.
1498 (if (and (eq (key-binding "\M-`") 'tmm-menubar)
1499 (eq (key-binding [f10]) 'tmm-menubar))
1501 Activate menubar F10 or ESC ` or M-`")
1502 (insert (substitute-command-keys "
1503 Activate menubar \\[tmm-menubar]")))
1505 ;; Many users seem to have problems with these.
1507 \(`C-' means use the CTRL key. `M-' means use the Meta (or Alt) key.
1508 If you have no Meta key, you may instead type ESC followed by the character.)")
1510 (insert "\n\n" (emacs-version)
1512 Copyright (C) 2006 Free Software Foundation, Inc.")
1514 (if (and (eq (key-binding "\C-h\C-c") 'describe-copying)
1515 (eq (key-binding "\C-h\C-d") 'describe-distribution)
1516 (eq (key-binding "\C-h\C-w") 'describe-no-warranty))
1519 GNU Emacs comes with ABSOLUTELY NO WARRANTY; type C-h C-w for full details.
1520 Emacs is Free Software--Free as in Freedom--so you can redistribute copies
1521 of Emacs and modify it; type C-h C-c to see the conditions.
1522 Type C-h C-d for information on getting the latest version.")
1523 (insert (substitute-command-keys
1525 GNU Emacs comes with ABSOLUTELY NO WARRANTY; type \\[describe-no-warranty] for full details.
1526 Emacs is Free Software--Free as in Freedom--so you can redistribute copies
1527 of Emacs and modify it; type \\[describe-copying] to see the conditions.
1528 Type \\[describe-distribution] for information on getting the latest version."))))
1530 ;; The rest of the startup screen is the same on all
1531 ;; kinds of terminals.
1533 ;; Give information on recovering, if there was a crash.
1534 (and auto-save-list-file-prefix
1535 ;; Don't signal an error if the
1536 ;; directory for auto-save-list files
1537 ;; does not yet exist.
1538 (file-directory-p (file-name-directory
1539 auto-save-list-file-prefix))
1541 (file-name-directory auto-save-list-file-prefix)
1544 (regexp-quote (file-name-nondirectory
1545 auto-save-list-file-prefix)))
1547 (insert "\n\nIf an Emacs session crashed recently, "
1548 "type M-x recover-session RET\nto recover"
1549 " the files you were editing."))
1551 ;; Display the input that we set up in the buffer.
1552 (set-buffer-modified-p nil)
1553 (goto-char (point-min))
1554 (if (or (window-minibuffer-p)
1555 (window-dedicated-p (selected-window)))
1556 ;; There's no point is using pop-to-buffer since creating
1557 ;; a new frame will generate enough events that the
1558 ;; subsequent `sit-for' will immediately return anyway.
1559 nil ;; (pop-to-buffer (current-buffer))
1560 (save-window-excursion
1561 (switch-to-buffer (current-buffer))
1563 ;; Unwind ... ensure splash buffer is killed
1564 (kill-buffer "GNU Emacs"))))
1567 (defun startup-echo-area-message ()
1568 (if (eq (key-binding "\C-h\C-p") 'describe-project)
1569 "For information about the GNU Project and its goals, type C-h C-p."
1570 (substitute-command-keys
1571 "For information about the GNU Project and its goals, type \
1572 \\[describe-project].")))
1575 (defun display-startup-echo-area-message ()
1576 (let ((resize-mini-windows t))
1577 (or noninteractive ;(input-pending-p) init-file-had-error
1578 ;; t if the init file says to inhibit the echo area startup message.
1579 (and inhibit-startup-echo-area-message
1581 (or (and (get 'inhibit-startup-echo-area-message 'saved-value)
1582 (equal inhibit-startup-echo-area-message
1583 (if (equal init-file-user "")
1586 ;; Wasn't set with custom; see if .emacs has a setq.
1587 (let ((buffer (get-buffer-create " *temp*")))
1592 (insert-file-contents user-init-file)
1595 "([ \t\n]*setq[ \t\n]+"
1596 "inhibit-startup-echo-area-message[ \t\n]+"
1599 (if (equal init-file-user "")
1605 (kill-buffer buffer)))))
1606 ;; display-splash-screen at the end of command-line-1 calls
1607 ;; use-fancy-splash-screens-p. This can cause image.el to be
1608 ;; loaded, putting "Loading image... done" in the echo area.
1609 ;; This hides startup-echo-area-message. So
1610 ;; use-fancy-splash-screens-p is called here simply to get the
1611 ;; loading of image.el (if needed) out of the way before
1612 ;; display-startup-echo-area-message runs.
1614 (use-fancy-splash-screens-p)
1615 (message "%s" (startup-echo-area-message))))))
1618 (defun display-splash-screen ()
1619 "Display splash screen according to display.
1620 Fancy splash screens are used on graphic displays,
1623 ;; Prevent recursive calls from server-process-filter.
1624 (if (not (get-buffer "GNU Emacs"))
1625 (if (use-fancy-splash-screens-p)
1626 (fancy-splash-screens)
1627 (normal-splash-screen))))
1629 (defun command-line-1 (command-line-args-left)
1630 (display-startup-echo-area-message)
1632 ;; Delay 2 seconds after an init file error message
1633 ;; was displayed, so user can read it.
1634 (when init-file-had-error
1637 (when (and pure-space-overflow
1638 (not noninteractive))
1641 "Building Emacs overflowed pure space. (See the node Pure Storage in the Lisp manual for details.)"
1644 (when command-line-args-left
1645 ;; We have command args; process them.
1646 (let ((dir command-line-default-directory)
1650 ;; This approach loses for "-batch -L DIR --eval "(require foo)",
1651 ;; if foo is intended to be found in DIR.
1653 ;; ;; The directories listed in --directory/-L options will *appear*
1654 ;; ;; at the front of `load-path' in the order they appear on the
1655 ;; ;; command-line. We cannot do this by *placing* them at the front
1656 ;; ;; in the order they appear, so we need this variable to hold them,
1660 ;; To DTRT we keep track of the splice point and modify `load-path'
1661 ;; straight away upon any --directory/-L option.
1663 just-files ;; t if this follows the magic -- option.
1664 ;; This includes our standard options' long versions
1665 ;; and long versions of what's on command-switch-alist.
1667 (append '(("--funcall") ("--load") ("--insert") ("--kill")
1668 ("--directory") ("--eval") ("--execute") ("--no-splash")
1669 ("--find-file") ("--visit") ("--file") ("--no-desktop"))
1670 (mapcar (lambda (elt)
1671 (list (concat "-" (car elt))))
1672 command-switch-alist)))
1676 ;; Add the long X options to longopts.
1677 (dolist (tem command-line-x-option-alist)
1678 (if (string-match "^--" (car tem))
1679 (push (list (car tem)) longopts)))
1681 ;; Loop, processing options.
1682 (while command-line-args-left
1683 (let* ((argi (car command-line-args-left))
1686 (setq command-line-args-left (cdr command-line-args-left))
1688 ;; Do preliminary decoding of the option.
1690 ;; After --, don't look for options; treat all args as files.
1692 ;; Convert long options to ordinary options
1693 ;; and separate out an attached option argument into argval.
1694 (when (string-match "^\\(--[^=]*\\)=" argi)
1695 (setq argval (substring argi (match-end 0))
1696 argi (match-string 1 argi)))
1697 (if (equal argi "--")
1698 (setq completion nil)
1699 (setq completion (try-completion argi longopts)))
1700 (if (eq completion t)
1701 (setq argi (substring argi 1))
1702 (if (stringp completion)
1703 (let ((elt (assoc completion longopts)))
1705 (error "Option `%s' is ambiguous" argi))
1706 (setq argi (substring (car elt) 1)))
1710 ;; Execute the option.
1711 (cond ((setq tem (assoc argi command-switch-alist))
1713 (let ((command-line-args-left
1714 (cons argval command-line-args-left)))
1715 (funcall (cdr tem) argi))
1716 (funcall (cdr tem) argi)))
1718 ((equal argi "-no-splash")
1719 (setq inhibit-startup-message t))
1721 ((member argi '("-f" ; what the manual claims
1723 "-e")) ; what the source used to say
1724 (setq tem (intern (or argval (pop command-line-args-left))))
1726 (command-execute tem)
1729 ((member argi '("-eval" "-execute"))
1730 (eval (read (or argval (pop command-line-args-left)))))
1732 ((member argi '("-L" "-directory"))
1733 (setq tem (expand-file-name
1734 (command-line-normalize-file-name
1735 (or argval (pop command-line-args-left)))))
1736 (cond (splice (setcdr splice (cons tem (cdr splice)))
1737 (setq splice (cdr splice)))
1738 (t (setq load-path (cons tem load-path)
1739 splice load-path))))
1741 ((member argi '("-l" "-load"))
1742 (let* ((file (command-line-normalize-file-name
1743 (or argval (pop command-line-args-left))))
1744 ;; Take file from default dir if it exists there;
1745 ;; otherwise let `load' search for it.
1746 (file-ex (expand-file-name file)))
1747 (when (file-exists-p file-ex)
1748 (setq file file-ex))
1751 ;; This is used to handle -script. It's not clear
1752 ;; we need to document it.
1753 ((member argi '("-scriptload"))
1754 (let* ((file (command-line-normalize-file-name
1755 (or argval (pop command-line-args-left))))
1756 ;; Take file from default dir.
1757 (file-ex (expand-file-name file)))
1758 (load file-ex nil t t)))
1760 ((equal argi "-insert")
1761 (setq tem (or argval (pop command-line-args-left)))
1763 (error "File name omitted from `-insert' option"))
1764 (insert-file-contents (command-line-normalize-file-name tem)))
1766 ((equal argi "-kill")
1769 ;; This is for when they use --no-desktop with -q, or
1770 ;; don't load Desktop in their .emacs. If desktop.el
1771 ;; _is_ loaded, it will handle this switch, and we
1772 ;; won't see it by the time we get here.
1773 ((equal argi "-no-desktop")
1774 (message "\"--no-desktop\" ignored because the Desktop package is not loaded"))
1776 ((string-match "^\\+[0-9]+\\'" argi)
1777 (setq line (string-to-number argi)))
1779 ((string-match "^\\+\\([0-9]+\\):\\([0-9]+\\)\\'" argi)
1780 (setq line (string-to-number (match-string 1 argi))
1781 column (string-to-number (match-string 2 argi))))
1783 ((setq tem (assoc argi command-line-x-option-alist))
1784 ;; Ignore X-windows options and their args if not using X.
1785 (setq command-line-args-left
1786 (nthcdr (nth 1 tem) command-line-args-left)))
1788 ((member argi '("-find-file" "-file" "-visit"))
1789 ;; An explicit option to specify visiting a file.
1790 (setq tem (or argval (pop command-line-args-left)))
1791 (unless (stringp tem)
1792 (error "File name omitted from `%s' option" argi))
1793 (setq file-count (1+ file-count))
1794 (let ((file (expand-file-name
1795 (command-line-normalize-file-name tem) dir)))
1796 (if (= file-count 1)
1797 (setq first-file-buffer (find-file file))
1798 (find-file-other-window file)))
1802 (unless (< column 1)
1803 (move-to-column (1- column)))
1807 (setq just-files t))
1809 ;; We have almost exhausted our options. See if the
1810 ;; user has made any other command-line options available
1811 (let ((hooks command-line-functions) ;; lrs 7/31/89
1814 (not (setq did-hook (funcall (car hooks)))))
1815 (setq hooks (cdr hooks)))
1817 ;; Presume that the argument is a file name.
1819 (if (string-match "\\`-" argi)
1820 (error "Unknown option `%s'" argi))
1821 (setq file-count (1+ file-count))
1824 (command-line-normalize-file-name orig-argi)
1826 (if (= file-count 1)
1827 (setq first-file-buffer (find-file file))
1828 (find-file-other-window file)))
1832 (unless (< column 1)
1833 (move-to-column (1- column)))
1834 (setq column 0))))))))
1836 ;; If 3 or more files visited, and not all visible,
1837 ;; show user what they all are. But leave the last one current.
1838 (and (> file-count 2)
1839 (not noninteractive)
1840 (not inhibit-startup-buffer-menu)
1841 (or (get-buffer-window first-file-buffer)
1844 ;; Maybe display a startup screen.
1845 (unless (or inhibit-startup-message
1847 emacs-quick-startup)
1848 ;; Display a startup screen, after some preparations.
1850 ;; If there are no switches to process, we might as well
1851 ;; run this hook now, and there may be some need to do it
1852 ;; before doing any output.
1853 (run-hooks 'emacs-startup-hook)
1854 (and term-setup-hook
1855 (run-hooks 'term-setup-hook))
1856 (setq inhibit-startup-hooks t)
1858 ;; It's important to notice the user settings before we
1859 ;; display the startup message; otherwise, the settings
1860 ;; won't take effect until the user gives the first
1861 ;; keystroke, and that's distracting.
1862 (when (fboundp 'frame-notice-user-settings)
1863 (frame-notice-user-settings))
1865 ;; If there are no switches to process, we might as well
1866 ;; run this hook now, and there may be some need to do it
1867 ;; before doing any output.
1868 (when window-setup-hook
1869 (run-hooks 'window-setup-hook)
1870 ;; Don't let the hook be run twice.
1871 (setq window-setup-hook nil))
1873 ;; Do this now to avoid an annoying delay if the user
1874 ;; clicks the menu bar during the sit-for.
1875 (when (display-popup-menus-p)
1876 (precompute-menubar-bindings))
1878 (setq menubar-bindings-done t))
1880 ;; If *scratch* is selected and it is empty, insert an
1881 ;; initial message saying not to create a file there.
1882 (when (and initial-scratch-message
1883 (equal (buffer-name) "*scratch*")
1884 (= 0 (buffer-size)))
1885 (insert initial-scratch-message)
1886 (set-buffer-modified-p nil))
1888 ;; If user typed input during all that work,
1889 ;; abort the startup screen. Otherwise, display it now.
1890 (unless (input-pending-p)
1891 (display-splash-screen))))
1894 (defun command-line-normalize-file-name (file)
1895 "Collapse multiple slashes to one, to handle non-Emacs file names."
1897 ;; Use arg 1 so that we don't collapse // at the start of the file name.
1898 ;; That is significant on some systems.
1899 ;; However, /// at the beginning is supposed to mean just /, not //.
1900 (if (string-match "^///+" file)
1901 (setq file (replace-match "/" t t file)))
1902 (while (string-match "//+" file 1)
1903 (setq file (replace-match "/" t t file)))
1906 ;; arch-tag: 7e294698-244d-4758-984b-4047f887a5db
1907 ;;; startup.el ends here