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 (defgroup initialization nil
40 "Emacs start-up procedure."
43 (defcustom inhibit-splash-screen nil
44 "Non-nil inhibits the startup screen.
45 It also inhibits display of the initial message in the *scratch* buffer.
47 This is for use in your personal init file, once you are familiar
48 with the contents of the startup screen."
50 :group
'initialization
)
52 (defvaralias 'inhibit-startup-message
'inhibit-splash-screen
)
54 (defcustom inhibit-startup-echo-area-message nil
55 "*Non-nil inhibits the initial startup echo area message.
56 Setting this variable takes effect
57 only if you do it with the customization buffer
58 or if your `.emacs' file contains a line of this form:
59 (setq inhibit-startup-echo-area-message \"YOUR-USER-NAME\")
60 If your `.emacs' file is byte-compiled, use the following form instead:
61 (eval '(setq inhibit-startup-echo-area-message \"YOUR-USER-NAME\"))
62 Thus, someone else using a copy of your `.emacs' file will see
63 the startup message unless he personally acts to inhibit it."
64 :type
'(choice (const :tag
"Don't inhibit")
65 (string :tag
"Enter your user name, to inhibit"))
66 :group
'initialization
)
68 (defcustom inhibit-default-init nil
69 "*Non-nil inhibits loading the `default' library."
71 :group
'initialization
)
73 (defcustom inhibit-startup-buffer-menu nil
74 "*Non-nil inhibits display of buffer list when more than 2 files are loaded."
76 :group
'initialization
)
78 (defvar command-switch-alist nil
79 "Alist of command-line switches.
80 Elements look like (SWITCH-STRING . HANDLER-FUNCTION).
81 HANDLER-FUNCTION receives the switch string as its sole argument;
82 the remaining command-line args are in the variable `command-line-args-left'.")
84 (defvar command-line-args-left nil
85 "List of command-line args not yet processed.")
87 (defvar command-line-functions nil
;; lrs 7/31/89
88 "List of functions to process unrecognized command-line arguments.
89 Each function should access the dynamically bound variables
90 `argi' (the current argument) and `command-line-args-left' (the remaining
91 arguments). The function should return non-nil only if it recognizes and
92 processes `argi'. If it does so, it may consume successive arguments by
93 altering `command-line-args-left' to remove them.")
95 (defvar command-line-default-directory nil
96 "Default directory to use for command line arguments.
97 This is normally copied from `default-directory' when Emacs starts.")
99 ;;; This is here, rather than in x-win.el, so that we can ignore these
100 ;;; options when we are not using X.
101 (defconst command-line-x-option-alist
102 '(("-bw" 1 x-handle-numeric-switch border-width
)
103 ("-d" 1 x-handle-display
)
104 ("-display" 1 x-handle-display
)
105 ("-name" 1 x-handle-name-switch
)
106 ("-title" 1 x-handle-switch title
)
107 ("-T" 1 x-handle-switch title
)
108 ("-r" 0 x-handle-switch reverse t
)
109 ("-rv" 0 x-handle-switch reverse t
)
110 ("-reverse" 0 x-handle-switch reverse t
)
111 ("-reverse-video" 0 x-handle-switch reverse t
)
112 ("-fn" 1 x-handle-switch font
)
113 ("-font" 1 x-handle-switch font
)
114 ("-fs" 0 x-handle-initial-switch fullscreen fullboth
)
115 ("-fw" 0 x-handle-initial-switch fullscreen fullwidth
)
116 ("-fh" 0 x-handle-initial-switch fullscreen fullheight
)
117 ("-ib" 1 x-handle-numeric-switch internal-border-width
)
118 ("-g" 1 x-handle-geometry
)
119 ("-lsp" 1 x-handle-numeric-switch line-spacing
)
120 ("-geometry" 1 x-handle-geometry
)
121 ("-fg" 1 x-handle-switch foreground-color
)
122 ("-foreground" 1 x-handle-switch foreground-color
)
123 ("-bg" 1 x-handle-switch background-color
)
124 ("-background" 1 x-handle-switch background-color
)
125 ("-ms" 1 x-handle-switch mouse-color
)
126 ("-nbi" 0 x-handle-switch icon-type nil
)
127 ("-iconic" 0 x-handle-iconic
)
128 ("-xrm" 1 x-handle-xrm-switch
)
129 ("-cr" 1 x-handle-switch cursor-color
)
130 ("-vb" 0 x-handle-switch vertical-scroll-bars t
)
131 ("-hb" 0 x-handle-switch horizontal-scroll-bars t
)
132 ("-bd" 1 x-handle-switch
)
133 ("--border-width" 1 x-handle-numeric-switch border-width
)
134 ("--display" 1 x-handle-display
)
135 ("--name" 1 x-handle-name-switch
)
136 ("--title" 1 x-handle-switch title
)
137 ("--reverse-video" 0 x-handle-switch reverse t
)
138 ("--font" 1 x-handle-switch font
)
139 ("--fullscreen" 0 x-handle-initial-switch fullscreen fullboth
)
140 ("--fullwidth" 0 x-handle-initial-switch fullscreen fullwidth
)
141 ("--fullheight" 0 x-handle-initial-switch fullscreen fullheight
)
142 ("--internal-border" 1 x-handle-numeric-switch internal-border-width
)
143 ("--geometry" 1 x-handle-geometry
)
144 ("--foreground-color" 1 x-handle-switch foreground-color
)
145 ("--background-color" 1 x-handle-switch background-color
)
146 ("--mouse-color" 1 x-handle-switch mouse-color
)
147 ("--no-bitmap-icon" 0 x-handle-switch icon-type nil
)
148 ("--iconic" 0 x-handle-iconic
)
149 ("--xrm" 1 x-handle-xrm-switch
)
150 ("--cursor-color" 1 x-handle-switch cursor-color
)
151 ("--vertical-scroll-bars" 0 x-handle-switch vertical-scroll-bars t
)
152 ("--line-spacing" 1 x-handle-numeric-switch line-spacing
)
153 ("--border-color" 1 x-handle-switch border-color
)
154 ("--smid" 1 x-handle-smid
))
155 "Alist of X Windows options.
156 Each element has the form
157 (NAME NUMARGS HANDLER FRAME-PARAM VALUE)
158 where NAME is the option name string, NUMARGS is the number of arguments
159 that the option accepts, HANDLER is a function to call to handle the option.
160 FRAME-PARAM (optional) is the frame parameter this option specifies,
161 and VALUE is the value which is given to that frame parameter
162 \(most options use the argument for this, so VALUE is not present).")
164 (defvar before-init-hook nil
165 "Normal hook run after handling urgent options but before loading init files.")
167 (defvar after-init-hook nil
168 "Normal hook run after loading the init files, `~/.emacs' and `default.el'.
169 There is no `condition-case' around the running of these functions;
170 therefore, if you set `debug-on-error' non-nil in `.emacs',
171 an error in one of these functions will invoke the debugger.")
173 (defvar emacs-startup-hook nil
174 "Normal hook run after loading init files and handling the command line.")
176 (defvar term-setup-hook nil
177 "Normal hook run after loading terminal-specific Lisp code.
178 It also follows `emacs-startup-hook'. This hook exists for users to set,
179 so as to override the definitions made by the terminal-specific file.
180 Emacs never sets this variable itself.")
182 (defvar inhibit-startup-hooks nil
183 "Non-nil means don't run `term-setup-hook' and `emacs-startup-hook'.
184 This is because we already did so.")
186 (defvar keyboard-type nil
187 "The brand of keyboard you are using.
188 This variable is used to define the proper function and keypad
189 keys for use under X. It is used in a fashion analogous to the
190 environment variable TERM.")
192 (defvar window-setup-hook nil
193 "Normal hook run to initialize window system display.
194 Emacs runs this hook after processing the command line arguments and loading
195 the user's init file.")
197 (defcustom initial-major-mode
'lisp-interaction-mode
198 "Major mode command symbol to use for the initial *scratch* buffer."
200 :group
'initialization
)
202 (defvar init-file-user nil
203 "Identity of user whose `.emacs' file is or was read.
204 The value is nil if `-q' or `--no-init-file' was specified,
205 meaning do not load any init file.
207 Otherwise, the value may be an empty string, meaning
208 use the init file for the user who originally logged in,
209 or it may be a string containing a user's name meaning
210 use that person's init file.
212 In either of the latter cases, `(concat \"~\" init-file-user \"/\")'
213 evaluates to the name of the directory where the `.emacs' file was
216 Setting `init-file-user' does not prevent Emacs from loading
217 `site-start.el'. The only way to do that is to use `--no-site-file'.")
219 (defcustom site-run-file
"site-start"
220 "File containing site-wide run-time initializations.
221 This file is loaded at run-time before `~/.emacs'. It contains inits
222 that need to be in place for the entire site, but which, due to their
223 higher incidence of change, don't make sense to load into Emacs's
224 dumped image. Thus, the run-time load order is: 1. file described in
225 this variable, if non-nil; 2. `~/.emacs'; 3. `default.el'.
227 Don't use the `site-start.el' file for things some users may not like.
228 Put them in `default.el' instead, so that users can more easily
229 override them. Users can prevent loading `default.el' with the `-q'
230 option or by setting `inhibit-default-init' in their own init files,
231 but inhibiting `site-start.el' requires `--no-site-file', which
234 This variable is defined for customization so as to make
235 it visible in the relevant context. However, actually customizing it
236 is not allowed, since it would not work anyway. The only way to set
237 this variable usefully is to set it while building and dumping Emacs."
238 :type
'(choice (const :tag
"none" nil
) string
)
239 :group
'initialization
240 :initialize
'custom-initialize-default
241 :set
'(lambda (variable value
)
242 (error "Customizing `site-run-file' does not work")))
244 (defcustom mail-host-address nil
245 "*Name of this machine, for purposes of naming users."
246 :type
'(choice (const nil
) string
)
249 (defcustom user-mail-address
(if command-line-processed
251 (concat (user-login-name) "@"
252 (or mail-host-address
254 ;; Empty string means "not set yet".
256 "*Full mailing address of this user.
257 This is initialized with environment variable `EMAIL' or, as a
258 fallback, using `mail-host-address'. This is done after your
259 init file is read, in case it sets `mail-host-address'."
263 (defcustom auto-save-list-file-prefix
264 (cond ((eq system-type
'ms-dos
)
265 ;; MS-DOS cannot have initial dot, and allows only 8.3 names
266 "~/_emacs.d/auto-save.list/_s")
268 "~/.emacs.d/auto-save-list/.saves-"))
269 "Prefix for generating `auto-save-list-file-name'.
270 This is used after reading your `.emacs' file to initialize
271 `auto-save-list-file-name', by appending Emacs's pid and the system name,
272 if you have not already set `auto-save-list-file-name' yourself.
273 Directories in the prefix will be created if necessary.
274 Set this to nil if you want to prevent `auto-save-list-file-name'
275 from being initialized."
276 :type
'(choice (const :tag
"Don't record a session's auto save list" nil
)
280 (defvar emacs-quick-startup nil
)
282 (defvar emacs-basic-display nil
)
284 (defvar init-file-debug nil
)
286 (defvar init-file-had-error nil
287 "Non-nil if there was an error loading the user's init file.")
289 (defvar normal-top-level-add-subdirs-inode-list nil
)
291 (defvar no-blinking-cursor nil
)
293 (defvar default-frame-background-mode
)
295 (defvar pure-space-overflow nil
296 "Non-nil if building Emacs overflowed pure space.")
298 (defun normal-top-level-add-subdirs-to-load-path ()
299 "Add all subdirectories of current directory to `load-path'.
300 More precisely, this uses only the subdirectories whose names
301 start with letters or digits; it excludes any subdirectory named `RCS'
302 or `CVS', and any subdirectory that contains a file named `.nosearch'."
305 (pending (list default-directory
)))
306 ;; This loop does a breadth-first tree walk on DIR's subtree,
307 ;; putting each subdir into DIRS as its contents are examined.
309 (push (pop pending
) dirs
)
310 (let* ((this-dir (car dirs
))
311 (contents (directory-files this-dir
))
312 (default-directory this-dir
)
313 (canonicalized (if (fboundp 'untranslated-canonical-name
)
314 (untranslated-canonical-name this-dir
))))
315 ;; The Windows version doesn't report meaningful inode
316 ;; numbers, so use the canonicalized absolute file name of the
317 ;; directory instead.
318 (setq attrs
(or canonicalized
319 (nthcdr 10 (file-attributes this-dir
))))
320 (unless (member attrs normal-top-level-add-subdirs-inode-list
)
321 (push attrs normal-top-level-add-subdirs-inode-list
)
322 (dolist (file contents
)
323 ;; The lower-case variants of RCS and CVS are for DOS/Windows.
324 (unless (member file
'("." ".." "RCS" "CVS" "rcs" "cvs"))
325 (when (and (string-match "\\`[[:alnum:]]" file
)
326 ;; Avoid doing a `stat' when it isn't necessary
327 ;; because that can cause trouble when an NFS server
329 (not (string-match "\\.elc?\\'" file
))
330 (file-directory-p file
))
331 (let ((expanded (expand-file-name file
)))
332 (unless (file-exists-p (expand-file-name ".nosearch"
334 (setq pending
(nconc pending
(list expanded
)))))))))))
335 (normal-top-level-add-to-load-path (cdr (nreverse dirs
)))))
337 ;; This function is called from a subdirs.el file.
338 ;; It assumes that default-directory is the directory
339 ;; in which the subdirs.el file exists,
340 ;; and it adds to load-path the subdirs of that directory
341 ;; as specified in DIRS. Normally the elements of DIRS are relative.
342 (defun normal-top-level-add-to-load-path (dirs)
343 (let ((tail load-path
)
344 (thisdir (directory-file-name default-directory
)))
346 ;;Don't go all the way to the nil terminator.
348 (not (equal thisdir
(car tail
)))
349 (not (and (memq system-type
'(ms-dos windows-nt
))
350 (equal (downcase thisdir
) (downcase (car tail
))))))
351 (setq tail
(cdr tail
)))
352 ;;Splice the new section in.
354 (setcdr tail
(append (mapcar 'expand-file-name dirs
) (cdr tail
))))))
356 (defun normal-top-level ()
357 (if command-line-processed
358 (message "Back to top level.")
359 (setq command-line-processed t
)
360 ;; Give *Messages* the same default-directory as *scratch*,
361 ;; just to keep things predictable.
362 (let ((dir default-directory
))
363 (with-current-buffer "*Messages*"
364 (setq default-directory dir
)))
365 ;; `user-full-name' is now known; reset its standard-value here.
366 (put 'user-full-name
'standard-value
367 (list (default-value 'user-full-name
)))
368 ;; For root, preserve owner and group when editing files.
369 (if (equal (user-uid) 0)
370 (setq backup-by-copying-when-mismatch t
))
371 ;; Look in each dir in load-path for a subdirs.el file.
372 ;; If we find one, load it, which will add the appropriate subdirs
373 ;; of that dir into load-path,
374 ;; Look for a leim-list.el file too. Loading it will register
375 ;; available input methods.
376 (let ((tail load-path
) dir
)
378 (setq dir
(car tail
))
379 (let ((default-directory dir
))
380 (load (expand-file-name "subdirs.el") t t t
))
381 (let ((default-directory dir
))
382 (load (expand-file-name "leim-list.el") t t t
))
383 ;; We don't use a dolist loop and we put this "setq-cdr" command at
384 ;; the end, because the subdirs.el files may add elements to the end
385 ;; of load-path and we want to take it into account.
386 (setq tail
(cdr tail
))))
387 (unless (eq system-type
'vax-vms
)
388 ;; If the PWD environment variable isn't accurate, delete it.
389 (let ((pwd (getenv "PWD")))
391 ;; Use FOO/., so that if FOO is a symlink, file-attributes
392 ;; describes the directory linked to, not FOO itself.
393 (or (equal (file-attributes
394 (concat (file-name-as-directory pwd
) "."))
396 (concat (file-name-as-directory default-directory
)
398 (setq process-environment
399 (delete (concat "PWD=" pwd
)
400 process-environment
))))))
401 (setq default-directory
(abbreviate-file-name default-directory
))
402 (let ((menubar-bindings-done nil
))
405 ;; Do this again, in case .emacs defined more abbreviations.
406 (setq default-directory
(abbreviate-file-name default-directory
))
407 ;; Specify the file for recording all the auto save files of this session.
408 ;; This is used by recover-session.
409 (or auto-save-list-file-name
410 (and auto-save-list-file-prefix
411 (setq auto-save-list-file-name
412 ;; Under MS-DOS our PID is almost always reused between
413 ;; Emacs invocations. We need something more unique.
414 (cond ((eq system-type
'ms-dos
)
415 ;; We are going to access the auto-save
416 ;; directory, so make sure it exists.
418 (file-name-directory auto-save-list-file-prefix
)
423 auto-save-list-file-prefix
))
428 auto-save-list-file-prefix
431 (unless inhibit-startup-hooks
432 (run-hooks 'emacs-startup-hook
)
434 (run-hooks 'term-setup-hook
)))
436 ;; Don't do this if we failed to create the initial frame,
437 ;; for instance due to a dense colormap.
438 (when (or frame-initial-frame
439 ;; If frame-initial-frame has no meaning, do this anyway.
440 (not (and window-system
442 (not (eq window-system
'pc
)))))
443 ;; Modify the initial frame based on what .emacs puts into
445 (if (fboundp 'frame-notice-user-settings
)
446 (frame-notice-user-settings))
447 (if (fboundp 'frame-set-background-mode
)
448 ;; Set the faces for the initial background mode even if
449 ;; frame-notice-user-settings didn't (such as on a tty).
450 ;; frame-set-background-mode is idempotent, so it won't
451 ;; cause any harm if it's already been done.
452 (let ((frame (selected-frame))
454 (when (and (null window-system
)
455 ;; Don't override default set by files in lisp/term.
456 (null default-frame-background-mode
)
457 (let ((bg (frame-parameter frame
'background-color
)))
459 (member bg
'(unspecified "unspecified-bg"
460 "unspecified-fg")))))
462 (setq term
(getenv "TERM"))
463 ;; Some files in lisp/term do a better job with the
464 ;; background mode, but we leave this here anyway, in
465 ;; case they remove those files.
466 (if (string-match "^\\(xterm\\|rxvt\\|dtterm\\|eterm\\)"
468 (setq default-frame-background-mode
'light
)))
469 (frame-set-background-mode (selected-frame)))))
471 ;; Now we know the user's default font, so add it to the menu.
472 (if (fboundp 'font-menu-add-default
)
473 (font-menu-add-default))
474 (and window-setup-hook
475 (run-hooks 'window-setup-hook
))
476 (or menubar-bindings-done
477 (if (display-popup-menus-p)
478 (precompute-menubar-bindings)))))))
480 ;; Precompute the keyboard equivalents in the menu bar items.
481 (defun precompute-menubar-bindings ()
482 (let ((submap (lookup-key global-map
[menu-bar
])))
484 (and (consp (car submap
))
485 (symbolp (car (car submap
)))
486 (stringp (car-safe (cdr (car submap
))))
487 (keymapp (cdr (cdr (car submap
))))
489 (x-popup-menu nil
(cdr (cdr (car submap
))))
492 (setq submap
(cdr submap
))))
493 (setq define-key-rebound-commands t
))
495 ;; Command-line options supported by tty's:
496 (defconst tty-long-option-alist
497 '(("--name" .
"-name")
499 ("--reverse-video" .
"-reverse")
500 ("--foreground-color" .
"-fg")
501 ("--background-color" .
"-bg")
502 ("--color" .
"-color")))
504 (defconst tool-bar-images-pixel-height
24
505 "Height in pixels of images in the tool bar.")
507 (defvar tool-bar-originally-present nil
508 "Non-nil if tool-bars are present before user and site init files are read.")
510 ;; Handle the X-like command-line arguments "-fg", "-bg", "-name", etc.
511 (defun tty-handle-args (args)
515 (not (equal (car args
) "--")))
516 (let* ((argi (pop args
))
519 ;; Check for long options with attached arguments
520 ;; and separate out the attached option argument into argval.
521 (when (string-match "^\\(--[^=]*\\)=" argi
)
522 (setq argval
(substring argi
(match-end 0))
523 argi
(match-string 1 argi
)))
524 (when (string-match "^--" argi
)
525 (setq completion
(try-completion argi tty-long-option-alist
))
526 (if (eq completion t
)
527 ;; Exact match for long option.
528 (setq argi
(cdr (assoc argi tty-long-option-alist
)))
529 (if (stringp completion
)
530 (let ((elt (assoc completion tty-long-option-alist
)))
531 ;; Check for abbreviated long option.
533 (error "Option `%s' is ambiguous" argi
))
534 (setq argi
(cdr elt
)))
535 ;; Check for a short option.
538 (cond ((member argi
'("-fg" "-foreground"))
539 (push (cons 'foreground-color
(or argval
(pop args
)))
540 default-frame-alist
))
541 ((member argi
'("-bg" "-background"))
542 (push (cons 'background-color
(or argval
(pop args
)))
543 default-frame-alist
))
544 ((member argi
'("-T" "-name"))
545 (unless argval
(setq argval
(pop args
)))
549 (let ((case-fold-search t
)
551 (setq argval
(invocation-name))
553 ;; Change any . or * characters in name to
554 ;; hyphens, so as to emulate behavior on X.
556 (setq i
(string-match "[.*]" argval
))
559 default-frame-alist
))
560 ((member argi
'("-r" "-rv" "-reverse"))
562 default-frame-alist
))
563 ((equal argi
"-color")
564 (unless argval
(setq argval
8)) ; default --color means 8 ANSI colors
565 (push (cons 'tty-color-mode
567 ((numberp argval
) argval
)
568 ((string-match "-?[0-9]+" argval
)
569 (string-to-number argval
))
570 (t (intern argval
))))
571 default-frame-alist
))
576 (defun command-line ()
577 (setq command-line-default-directory default-directory
)
579 ;; Choose a reasonable location for temporary files.
580 (custom-reevaluate-setting 'temporary-file-directory
)
581 (custom-reevaluate-setting 'small-temporary-file-directory
)
582 (custom-reevaluate-setting 'auto-save-file-name-transforms
)
584 ;; See if we should import version-control from the environment variable.
585 (let ((vc (getenv "VERSION_CONTROL")))
586 (cond ((eq vc nil
)) ;don't do anything if not set
587 ((member vc
'("t" "numbered"))
588 (setq version-control t
))
589 ((member vc
'("nil" "existing"))
590 (setq version-control nil
))
591 ((member vc
'("never" "simple"))
592 (setq version-control
'never
))))
594 ;;! This has been commented out; I currently find the behavior when
595 ;;! split-window-keep-point is nil disturbing, but if I can get used
596 ;;! to it, then it would be better to eliminate the option.
597 ;;! ;; Choose a good default value for split-window-keep-point.
598 ;;! (setq split-window-keep-point (> baud-rate 2400))
600 ;; Set the default strings to display in mode line for
601 ;; end-of-line formats that aren't native to this platform.
603 ((memq system-type
'(ms-dos windows-nt emx
))
604 (setq eol-mnemonic-unix
"(Unix)"
605 eol-mnemonic-mac
"(Mac)"))
606 ;; Both Mac and Unix EOLs are now "native" on Mac OS so keep the
607 ;; abbreviated strings `/' and `:' set in coding.c for them.
608 ((eq system-type
'macos
)
609 (setq eol-mnemonic-dos
"(DOS)"))
610 (t ; this is for Unix/GNU/Linux systems
611 (setq eol-mnemonic-dos
"(DOS)"
612 eol-mnemonic-mac
"(Mac)")))
614 ;; Read window system's init file if using a window system.
615 (condition-case error
616 (if (and window-system
(not noninteractive
))
617 (load (concat term-file-prefix
618 (symbol-name window-system
)
620 ;; Every window system should have a startup file;
621 ;; barf if we can't find it.
623 ;; If we can't read it, print the error message and exit.
626 (if (eq (car error
) 'error
)
627 (apply 'concat
(cdr error
))
628 (if (memq 'file-error
(get (car error
) 'error-conditions
))
631 (mapconcat (lambda (obj) (prin1-to-string obj t
))
632 (cdr (cdr error
)) ", "))
634 (get (car error
) 'error-message
)
635 (mapconcat (lambda (obj) (prin1-to-string obj t
))
637 'external-debugging-output
)
638 (terpri 'external-debugging-output
)
639 (setq window-system nil
)
642 ;; Windowed displays do this inside their *-win.el.
643 (unless (or (display-graphic-p) noninteractive
)
644 (setq command-line-args
(tty-handle-args command-line-args
)))
646 (set-locale-environment nil
)
648 ;; Convert preloaded file names to absolute.
652 (locate-file "simple" load-path
653 (get-load-suffixes))))))
656 (mapcar (lambda (elt)
657 (if (and (stringp (car elt
))
658 (not (file-name-absolute-p (car elt
))))
659 (cons (concat lisp-dir
665 ;; Convert the arguments to Emacs internal representation.
666 (let ((args (cdr command-line-args
)))
669 (decode-coding-string (car args
) locale-coding-system t
))
673 (args (cdr command-line-args
)))
675 ;; Figure out which user's init file to load,
676 ;; either from the environment or from the options.
677 (setq init-file-user
(if noninteractive nil
(user-login-name)))
678 ;; If user has not done su, use current $HOME to find .emacs.
680 (equal init-file-user
(user-real-login-name))
681 (setq init-file-user
""))
683 ;; Process the command-line args, and delete the arguments
684 ;; processed. This is consistent with the way main in emacs.c
686 (while (and (not done
) args
)
687 (let* ((longopts '(("--no-init-file") ("--no-site-file") ("--debug-init")
688 ("--user") ("--iconic") ("--icon-type") ("--quick")
689 ("--no-blinking-cursor") ("--basic-display")))
693 ;; Handle --OPTION=VALUE format.
694 (when (string-match "^\\(--[^=]*\\)=" argi
)
695 (setq argval
(substring argi
(match-end 0))
696 argi
(match-string 1 argi
)))
697 (unless (equal argi
"--")
698 (let ((completion (try-completion argi longopts
)))
699 (if (eq completion t
)
700 (setq argi
(substring argi
1))
701 (if (stringp completion
)
702 (let ((elt (assoc completion longopts
)))
704 (error "Option `%s' is ambiguous" argi
))
705 (setq argi
(substring (car elt
) 1)))
709 ((member argi
'("-Q" "-quick"))
710 (setq init-file-user nil
712 emacs-quick-startup t
))
713 ((member argi
'("-D" "-basic-display"))
714 (setq no-blinking-cursor t
715 emacs-basic-display t
)
716 (push '(vertical-scroll-bars . nil
) initial-frame-alist
))
717 ((member argi
'("-q" "-no-init-file"))
718 (setq init-file-user nil
))
719 ((member argi
'("-u" "-user"))
720 (setq init-file-user
(or argval
(pop args
))
722 ((equal argi
"-no-site-file")
723 (setq site-run-file nil
))
724 ((equal argi
"-debug-init")
725 (setq init-file-debug t
))
726 ((equal argi
"-iconic")
727 (push '(visibility . icon
) initial-frame-alist
))
728 ((member argi
'("-icon-type" "-i" "-itype"))
729 (push '(icon-type . t
) default-frame-alist
))
730 ((member argi
'("-nbc" "-no-blinking-cursor"))
731 (setq no-blinking-cursor t
))
732 ;; Push the popped arg back on the list of arguments.
736 ;; Was argval set but not used?
738 (error "Option `%s' doesn't allow an argument" argi
))))
740 ;; Re-attach the program name to the front of the arg list.
741 (and command-line-args
742 (setcdr command-line-args args
)))
744 (run-hooks 'before-init-hook
)
746 ;; Under X Window, this creates the X frame and deletes the terminal frame.
747 (when (fboundp 'frame-initialize
)
750 ;; Turn off blinking cursor if so specified in X resources. This is here
751 ;; only because all other settings of no-blinking-cursor are here.
752 (unless (or noninteractive
754 (and (memq window-system
'(x w32 mac
))
755 (not (member (x-get-resource "cursorBlink" "CursorBlink")
757 (setq no-blinking-cursor t
))
759 ;; If frame was created with a menu bar, set menu-bar-mode on.
760 (unless (or noninteractive
762 (and (memq window-system
'(x w32
))
763 (<= (frame-parameter nil
'menu-bar-lines
) 0)))
766 ;; If frame was created with a tool bar, switch tool-bar-mode on.
767 (unless (or noninteractive
769 (not (display-graphic-p))
770 (<= (frame-parameter nil
'tool-bar-lines
) 0))
773 ;; Can't do this init in defcustom because the relevant variables
775 (custom-reevaluate-setting 'blink-cursor-mode
)
776 (custom-reevaluate-setting 'normal-erase-is-backspace
)
777 (custom-reevaluate-setting 'tooltip-mode
)
778 (custom-reevaluate-setting 'global-font-lock-mode
)
779 (custom-reevaluate-setting 'mouse-wheel-down-event
)
780 (custom-reevaluate-setting 'mouse-wheel-up-event
)
781 (custom-reevaluate-setting 'file-name-shadow-mode
)
782 (custom-reevaluate-setting 'send-mail-function
)
783 (custom-reevaluate-setting 'focus-follows-mouse
)
785 ;; Register default TTY colors for the case the terminal hasn't a
786 ;; terminal init file.
787 (unless (memq window-system
'(x w32 mac
))
788 ;; We do this regardles of whether the terminal supports colors
789 ;; or not, since they can switch that support on or off in
790 ;; mid-session by setting the tty-color-mode frame parameter.
791 (tty-register-default-colors))
793 ;; Record whether the tool-bar is present before the user and site
794 ;; init files are processed. frame-notice-user-settings uses this
795 ;; to determine if the tool-bar has been disabled by the init files,
796 ;; and the frame needs to be resized.
797 (when (fboundp 'frame-notice-user-settings
)
798 (let ((tool-bar-lines (or (assq 'tool-bar-lines initial-frame-alist
)
799 (assq 'tool-bar-lines default-frame-alist
))))
800 (setq tool-bar-originally-present
803 (not (eq 0 (cdr tool-bar-lines
)))))))
805 (let ((old-scalable-fonts-allowed scalable-fonts-allowed
)
806 (old-font-list-limit font-list-limit
)
807 (old-face-ignored-fonts face-ignored-fonts
))
809 ;; Run the site-start library if it exists. The point of this file is
810 ;; that it is run before .emacs. There is no point in doing this after
811 ;; .emacs; that is useless.
813 (load site-run-file t t
))
815 ;; Sites should not disable this. Only individuals should disable
816 ;; the startup message.
817 (setq inhibit-startup-message nil
)
819 ;; Warn for invalid user name.
821 (if (string-match "[~/:\n]" init-file-user
)
822 (display-warning 'initialization
823 (format "Invalid user name %s"
826 (if (file-directory-p (expand-file-name
827 ;; We don't support ~USER on MS-Windows except
828 ;; for the current user, and always load .emacs
829 ;; from the current user's home directory (see
830 ;; below). So always check "~", even if invoked
831 ;; with "-u USER", or if $USER or $LOGNAME are
832 ;; set to something different.
833 (if (eq system-type
'windows-nt
)
835 (concat "~" init-file-user
))))
837 (display-warning 'initialization
838 (format "User %s has no home directory"
842 ;; Load that user's init file, or the default one, or none.
843 (let (debug-on-error-from-init-file
844 debug-on-error-should-be-set
845 (debug-on-error-initial
846 (if (eq init-file-debug t
) 'startup init-file-debug
))
847 (orig-enable-multibyte default-enable-multibyte-characters
))
848 (let ((debug-on-error debug-on-error-initial
)
849 ;; This function actually reads the init files.
854 (let ((user-init-file-1
856 ((eq system-type
'ms-dos
)
857 (concat "~" init-file-user
"/_emacs"))
858 ((eq system-type
'windows-nt
)
859 ;; Prefer .emacs on Windows.
860 (if (directory-files "~" nil
"^\\.emacs\\(\\.elc?\\)?$")
862 ;; Also support _emacs for compatibility.
863 (if (directory-files "~" nil
"^_emacs\\(\\.elc?\\)?$")
865 ;; But default to .emacs if _emacs does not exist.
867 ((eq system-type
'vax-vms
)
870 (concat "~" init-file-user
"/.emacs")))))
871 ;; This tells `load' to store the file name found
872 ;; into user-init-file.
873 (setq user-init-file t
)
874 (load user-init-file-1 t t
)
876 (when (eq user-init-file t
)
877 ;; If we did not find ~/.emacs, try
878 ;; ~/.emacs.d/init.el.
882 (file-name-as-directory
883 (concat "~" init-file-user
"/.emacs.d")))))
886 ;; If we did not find the user's init file,
887 ;; set user-init-file conclusively.
888 ;; Don't let it be set from default.el.
889 (when (eq user-init-file t
)
890 (setq user-init-file user-init-file-1
))))
892 ;; If we loaded a compiled file, set
893 ;; `user-init-file' to the source version if that
895 (when (and user-init-file
896 (equal (file-name-extension user-init-file
)
898 (let* ((source (file-name-sans-extension user-init-file
))
899 (alt (concat source
".el")))
900 (setq source
(cond ((file-exists-p alt
) alt
)
901 ((file-exists-p source
) source
)
904 (when (file-newer-than-file-p source user-init-file
)
905 (message "Warning: %s is newer than %s"
906 source user-init-file
)
908 (setq user-init-file source
))))
910 (unless inhibit-default-init
911 (let ((inhibit-startup-message nil
))
912 ;; Users are supposed to be told their rights.
913 ;; (Plus how to get help and how to undo.)
914 ;; Don't you dare turn this off for anyone
916 (load "default" t t
)))))))))
918 ;; Do this without a condition-case if the user wants to debug.
920 (condition-case error
923 (setq init-file-had-error nil
))
925 (let ((message-log-max nil
))
927 (set-buffer (get-buffer-create "*Messages*"))
929 (format "An error has occurred while loading `%s':\n\n"
932 (get (car error
) 'error-message
)
933 (if (cdr error
) ": " "")
934 (mapconcat (lambda (s) (prin1-to-string s t
)) (cdr error
) ", "))
936 "To ensure normal operation, you should investigate and remove the\n"
937 "cause of the error in your initialization file. Start Emacs with\n"
938 "the `--debug-init' option to view a complete error backtrace.\n\n"))
939 (message "Error in init file: %s%s%s"
940 (get (car error
) 'error-message
)
941 (if (cdr error
) ": " "")
942 (mapconcat 'prin1-to-string
(cdr error
) ", "))
943 (let ((pop-up-windows nil
))
944 (pop-to-buffer "*Messages*"))
945 (setq init-file-had-error t
)))))
947 (if (and deactivate-mark transient-mark-mode
)
948 (with-current-buffer (window-buffer)
951 ;; If the user has a file of abbrevs, read it.
952 (if (file-exists-p abbrev-file-name
)
953 (quietly-read-abbrev-file abbrev-file-name
))
955 ;; If the abbrevs came entirely from the init file or the
956 ;; abbrevs file, they do not need saving.
957 (setq abbrevs-changed nil
)
959 ;; If we can tell that the init file altered debug-on-error,
960 ;; arrange to preserve the value that it set up.
961 (or (eq debug-on-error debug-on-error-initial
)
962 (setq debug-on-error-should-be-set t
963 debug-on-error-from-init-file debug-on-error
)))
964 (if debug-on-error-should-be-set
965 (setq debug-on-error debug-on-error-from-init-file
))
966 (unless (or default-enable-multibyte-characters
967 (eq orig-enable-multibyte default-enable-multibyte-characters
))
968 ;; Init file changed to unibyte. Reset existing multibyte
969 ;; buffers (probably *scratch*, *Messages*, *Minibuff-0*).
970 ;; Arguably this should only be done if they're free of
971 ;; multibyte characters.
972 (mapcar (lambda (buffer)
973 (with-current-buffer buffer
974 (if enable-multibyte-characters
975 (set-buffer-multibyte nil
))))
977 ;; Also re-set the language environment in case it was
978 ;; originally done before unibyte was set and is sensitive to
979 ;; unibyte (display table, terminal coding system &c).
980 (set-language-environment current-language-environment
)))
982 ;; Do this here in case the init file sets mail-host-address.
983 (if (equal user-mail-address
"")
984 (setq user-mail-address
(or (getenv "EMAIL")
985 (concat (user-login-name) "@"
986 (or mail-host-address
989 ;; Originally face attributes were specified via
990 ;; `font-lock-face-attributes'. Users then changed the default
991 ;; face attributes by setting that variable. However, we try and
992 ;; be back-compatible and respect its value if set except for
993 ;; faces where M-x customize has been used to save changes for the
995 (when (boundp 'font-lock-face-attributes
)
996 (let ((face-attributes font-lock-face-attributes
))
997 (while face-attributes
998 (let* ((face-attribute (pop face-attributes
))
999 (face (car face-attribute
)))
1000 ;; Rustle up a `defface' SPEC from a
1001 ;; `font-lock-face-attributes' entry.
1002 (unless (get face
'saved-face
)
1003 (let ((foreground (nth 1 face-attribute
))
1004 (background (nth 2 face-attribute
))
1005 (bold-p (nth 3 face-attribute
))
1006 (italic-p (nth 4 face-attribute
))
1007 (underline-p (nth 5 face-attribute
))
1010 (setq face-spec
(cons ':foreground
(cons foreground face-spec
))))
1012 (setq face-spec
(cons ':background
(cons background face-spec
))))
1014 (setq face-spec
(append '(:weight bold
) face-spec
)))
1016 (setq face-spec
(append '(:slant italic
) face-spec
)))
1018 (setq face-spec
(append '(:underline t
) face-spec
)))
1019 (face-spec-set face
(list (list t face-spec
)) nil
)))))))
1021 ;; If parameter have been changed in the init file which influence
1022 ;; face realization, clear the face cache so that new faces will
1024 (unless (and (eq scalable-fonts-allowed old-scalable-fonts-allowed
)
1025 (eq font-list-limit old-font-list-limit
)
1026 (eq face-ignored-fonts old-face-ignored-fonts
))
1027 (clear-face-cache)))
1029 (run-hooks 'after-init-hook
)
1031 ;; Decode all default-directory.
1032 (if (and default-enable-multibyte-characters locale-coding-system
)
1034 (dolist (elt (buffer-list))
1036 (if default-directory
1037 (setq default-directory
1038 (decode-coding-string default-directory
1039 locale-coding-system t
))))
1040 (setq command-line-default-directory
1041 (decode-coding-string command-line-default-directory
1042 locale-coding-system t
))))
1044 ;; If *scratch* exists and init file didn't change its mode, initialize it.
1045 (if (get-buffer "*scratch*")
1046 (with-current-buffer "*scratch*"
1047 (if (eq major-mode
'fundamental-mode
)
1048 (funcall initial-major-mode
))))
1050 ;; Load library for our terminal type.
1051 ;; User init file can set term-file-prefix to nil to prevent this.
1052 (unless (or noninteractive
1054 (null term-file-prefix
))
1055 (let* ((TERM (getenv "TERM"))
1059 (not (load (concat term-file-prefix term
) t t
)))
1060 ;; Strip off last hyphen and what follows, then try again
1062 (if (setq hyphend
(string-match "[-_][^-_]+\\'" term
))
1063 (substring term
0 hyphend
)
1066 ;; The terminal file has been loaded, now call the terminal specific
1067 ;; initialization function.
1069 (let ((term-init-func (intern-soft (concat "terminal-init-" term
))))
1070 (if (not (fboundp term-init-func
))
1071 ;; Strip off last hyphen and what follows, then try again
1073 (if (setq hyphend
(string-match "[-_][^-_]+\\'" term
))
1074 (substring term
0 hyphend
)
1077 (funcall term-init-func
))))))
1079 ;; Update the out-of-memory error message based on user's key bindings
1080 ;; for save-some-buffers.
1081 (setq memory-signal-data
1083 (substitute-command-keys "Memory exhausted--use \\[save-some-buffers] then exit and restart Emacs")))
1085 ;; Process the remaining args.
1086 (command-line-1 (cdr command-line-args
))
1088 ;; If -batch, terminate after processing the command options.
1089 (if noninteractive
(kill-emacs t
))
1091 ;; Run emacs-session-restore (session management) if started by
1092 ;; the session manager and we have a session manager connection.
1093 (if (and (boundp 'x-session-previous-id
)
1094 (stringp x-session-previous-id
))
1096 (emacs-session-restore x-session-previous-id
))))
1098 (defcustom initial-scratch-message
(purecopy "\
1099 ;; This buffer is for notes you don't want to save, and for Lisp evaluation.
1100 ;; If you want to create a file, visit that file with C-x C-f,
1101 ;; then enter the text in that file's own buffer.
1104 "Initial message displayed in *scratch* buffer at startup.
1105 If this is nil, no message will be displayed.
1106 If `inhibit-splash-screen' is non-nil, then no message is displayed,
1107 regardless of the value of this variable."
1108 :type
'(choice (text :tag
"Message")
1109 (const :tag
"none" nil
))
1110 :group
'initialization
)
1113 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1114 ;;; Fancy splash screen
1115 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1117 (defvar fancy-splash-text
1118 '((:face
(variable-pitch :weight bold
)
1119 "Important Help menu items:\n"
1120 :face variable-pitch
1122 (let* ((en "TUTORIAL")
1123 (tut (or (get-language-info current-language-environment
1126 (title (with-temp-buffer
1127 (insert-file-contents
1128 (expand-file-name tut data-directory
)
1130 (search-forward ".")
1131 (buffer-substring (point-min) (1- (point))))))
1132 ;; If there is a specific tutorial for the current language
1133 ;; environment and it is not English, append its title.
1135 "Emacs Tutorial\tLearn how to use Emacs efficiently"
1136 (if (string= en tut
)
1138 (concat " (" title
")"))
1140 :face variable-pitch
"\
1141 Emacs FAQ\tFrequently asked questions and answers
1142 View Emacs Manual\tView the Emacs manual using Info
1143 Absence of Warranty\tGNU Emacs comes with "
1144 :face
(variable-pitch :slant oblique
)
1145 "ABSOLUTELY NO WARRANTY\n"
1146 :face variable-pitch
1148 Copying Conditions\tConditions for redistributing and changing Emacs
1149 Getting New Versions\tHow to obtain the latest version of Emacs
1150 More Manuals / Ordering Manuals Buying printed manuals from the FSF\n")
1151 (:face
(variable-pitch :weight bold
)
1152 "Useful File menu items:\n"
1153 :face variable-pitch
1154 "Exit Emacs\t\t(Or type "
1157 :face variable-pitch
1161 :face variable-pitch
1163 Recover Crashed Session\tRecover files you were editing before a crash
1171 "A list of texts to show in the middle part of splash screens.
1172 Each element in the list should be a list of strings or pairs
1173 `:face FACE', like `fancy-splash-insert' accepts them.")
1176 (defgroup fancy-splash-screen
()
1177 "Fancy splash screen when Emacs starts."
1179 :group
'initialization
)
1182 (defcustom fancy-splash-delay
7
1183 "*Delay in seconds between splash screens."
1184 :group
'fancy-splash-screen
1188 (defcustom fancy-splash-max-time
30
1189 "*Show splash screens for at most this number of seconds.
1190 Values less than twice `fancy-splash-delay' are ignored."
1191 :group
'fancy-splash-screen
1195 (defcustom fancy-splash-image nil
1196 "*The image to show in the splash screens, or nil for defaults."
1197 :group
'fancy-splash-screen
1198 :type
'(choice (const :tag
"Default" nil
)
1199 (file :tag
"File")))
1202 ;; These are temporary storage areas for the splash screen display.
1204 (defvar fancy-current-text nil
)
1205 (defvar fancy-splash-help-echo nil
)
1206 (defvar fancy-splash-stop-time nil
)
1207 (defvar fancy-splash-outer-buffer nil
)
1209 (defun fancy-splash-insert (&rest args
)
1210 "Insert text into the current buffer, with faces.
1211 Arguments from ARGS should be either strings, functions called
1212 with no args that return a string, or pairs `:face FACE',
1213 where FACE is a valid face specification, as it can be used with
1214 `put-text-property'."
1215 (let ((current-face nil
))
1217 (if (eq (car args
) :face
)
1218 (setq args
(cdr args
) current-face
(car args
))
1219 (insert (propertize (let ((it (car args
)))
1224 'help-echo fancy-splash-help-echo
)))
1225 (setq args
(cdr args
)))))
1228 (defun fancy-splash-head ()
1229 "Insert the head part of the splash screen into the current buffer."
1230 (let* ((image-file (cond ((stringp fancy-splash-image
)
1232 ((and (display-color-p)
1233 (image-type-available-p 'xpm
))
1234 (if (and (fboundp 'x-display-planes
)
1235 (= (funcall 'x-display-planes
) 8))
1239 (img (create-image image-file
))
1240 (image-width (and img
(car (image-size img
))))
1241 (window-width (window-width (selected-window))))
1243 (when (> window-width image-width
)
1244 ;; Center the image in the window.
1245 (insert (propertize " " 'display
1246 `(space :align-to
(+ center
(-0.5 .
,img
)))))
1248 ;; Change the color of the XPM version of the splash image
1249 ;; so that it is visible with a dark frame background.
1250 (when (and (memq 'xpm img
)
1251 (eq (frame-parameter nil
'background-mode
) 'dark
))
1252 (setq img
(append img
'(:color-symbols
(("#000000" .
"gray30"))))))
1254 ;; Insert the image with a help-echo and a keymap.
1255 (let ((map (make-sparse-keymap))
1256 (help-echo "mouse-2: browse http://www.gnu.org/"))
1257 (define-key map
[mouse-2
]
1260 (browse-url "http://www.gnu.org/")
1262 (define-key map
[down-mouse-2
] 'ignore
)
1263 (define-key map
[up-mouse-2
] 'ignore
)
1264 (insert-image img
(propertize "xxx" 'help-echo help-echo
1267 (fancy-splash-insert
1268 :face
'(variable-pitch :foreground
"red")
1269 (if (eq system-type
'gnu
/linux
)
1270 "GNU Emacs is one component of the GNU/Linux operating system."
1271 "GNU Emacs is one component of the GNU operating system."))
1273 (fancy-splash-insert
1274 :face
'variable-pitch
1275 "You can do basic editing with the menu bar and scroll bar \
1276 using the mouse.\n\n")
1277 (when fancy-splash-outer-buffer
1278 (fancy-splash-insert
1279 :face
'variable-pitch
1282 (substitute-command-keys
1284 :face
'variable-pitch
1286 (if (equal (buffer-name fancy-splash-outer-buffer
)
1291 (defun fancy-splash-tail ()
1292 "Insert the tail part of the splash screen into the current buffer."
1293 (let ((fg (if (eq (frame-parameter nil
'background-mode
) 'dark
)
1294 "cyan" "darkblue")))
1295 (fancy-splash-insert :face
`(variable-pitch :foreground
,fg
)
1299 :face
'(variable-pitch :height
0.5)
1300 "Copyright (C) 2006 Free Software Foundation, Inc.")
1301 (and auto-save-list-file-prefix
1302 ;; Don't signal an error if the
1303 ;; directory for auto-save-list files
1304 ;; does not yet exist.
1305 (file-directory-p (file-name-directory
1306 auto-save-list-file-prefix
))
1308 (file-name-directory auto-save-list-file-prefix
)
1311 (regexp-quote (file-name-nondirectory
1312 auto-save-list-file-prefix
)))
1314 (fancy-splash-insert :face
'(variable-pitch :foreground
"red")
1315 "\n\nIf an Emacs session crashed recently, "
1317 :face
'(fixed-pitch :foreground
"red")
1318 "Meta-x recover-session RET"
1319 :face
'(variable-pitch :foreground
"red")
1321 " the files you were editing."))))
1323 (defun fancy-splash-screens-1 (buffer)
1324 "Timer function displaying a splash screen."
1325 (when (> (float-time) fancy-splash-stop-time
)
1326 (throw 'stop-splashing nil
))
1327 (unless fancy-current-text
1328 (setq fancy-current-text fancy-splash-text
))
1329 (let ((text (car fancy-current-text
)))
1332 (if pure-space-overflow
1334 Warning Warning!!! Pure space overflow !!!Warning Warning
1335 \(See the node Pure Storage in the Lisp manual for details.)\n"))
1337 (apply #'fancy-splash-insert text
)
1339 (unless (current-message)
1340 (message fancy-splash-help-echo
))
1341 (set-buffer-modified-p nil
)
1342 (goto-char (point-min))
1343 (force-mode-line-update)
1344 (setq fancy-current-text
(cdr fancy-current-text
))))
1347 (defun fancy-splash-default-action ()
1348 "Stop displaying the splash screen buffer.
1349 This is an internal function used to turn off the splash screen after
1350 the user caused an input event by hitting a key or clicking with the
1353 (if (and (memq 'down
(event-modifiers last-command-event
))
1354 (eq (posn-window (event-start last-command-event
))
1356 ;; This is a mouse-down event in the spash screen window.
1357 ;; Ignore it and consume the corresponding mouse-up event.
1359 (push last-command-event unread-command-events
))
1363 (defun fancy-splash-screens (&optional hide-on-input
)
1364 "Display fancy splash screens when Emacs starts."
1366 (let ((old-hourglass display-hourglass
)
1367 (fancy-splash-outer-buffer (current-buffer))
1369 (old-minor-mode-map-alist minor-mode-map-alist
)
1370 (old-emulation-mode-map-alists emulation-mode-map-alists
)
1371 (frame (fancy-splash-frame))
1373 (save-selected-window
1374 (select-frame frame
)
1375 (switch-to-buffer "GNU Emacs")
1376 (setq splash-buffer
(current-buffer))
1377 (catch 'stop-splashing
1379 (let ((map (make-sparse-keymap))
1382 (define-key map
[switch-frame
] 'ignore
)
1383 (define-key map
[t] 'fancy-splash-default-action)
1384 (define-key map [mouse-movement] 'ignore)
1385 (define-key map [mode-line t] 'ignore)
1386 (setq display-hourglass nil
1387 minor-mode-map-alist nil
1388 emulation-mode-map-alists nil
1390 mode-line-format (propertize "---- %b %-"
1391 'face 'mode-line-buffer-id)
1392 fancy-splash-stop-time (+ (float-time)
1393 fancy-splash-max-time)
1394 timer (run-with-timer 0 fancy-splash-delay
1395 #'fancy-splash-screens-1
1397 (message "%s" (startup-echo-area-message))
1399 (cancel-timer timer)
1400 (setq display-hourglass old-hourglass
1401 minor-mode-map-alist old-minor-mode-map-alist
1402 emulation-mode-map-alists old-emulation-mode-map-alists)
1403 (kill-buffer splash-buffer)))))
1404 ;; If hide-on-input is nil, don't hide the buffer on input.
1405 (if (or (window-minibuffer-p)
1406 (window-dedicated-p (selected-window)))
1407 (pop-to-buffer (current-buffer))
1408 (switch-to-buffer "*About GNU Emacs*"))
1409 (setq buffer-read-only nil)
1411 (if pure-space-overflow
1413 Warning Warning!!! Pure space overflow !!!Warning Warning
1414 \(See the node Pure Storage in the Lisp manual for details.)\n"))
1415 (let (fancy-splash-outer-buffer)
1417 (dolist (text fancy-splash-text)
1418 (apply #'fancy-splash-insert text)
1420 (skip-chars-backward "\n")
1421 (delete-region (point) (point-max))
1424 (set-buffer-modified-p nil)
1425 (setq buffer-read-only t)
1426 (if (and view-read-only (not view-mode))
1427 (view-mode-enter nil 'kill-buffer))
1428 (goto-char (point-min)))))
1430 (defun fancy-splash-frame ()
1431 "Return the frame to use for the fancy splash screen.
1432 Returning non-nil does not mean we should necessarily
1433 use the fancy splash screen, but if we do use it,
1434 we put it on this frame."
1436 (dolist (frame (append (frame-list) (list (selected-frame))))
1437 (if (and (frame-visible-p frame)
1438 (not (window-minibuffer-p (frame-selected-window frame))))
1439 (setq chosen-frame frame)))
1442 (defun use-fancy-splash-screens-p ()
1443 "Return t if fancy splash screens should be used."
1444 (when (and (display-graphic-p)
1445 (or (and (display-color-p)
1446 (image-type-available-p 'xpm))
1447 (image-type-available-p 'pbm)))
1448 (let ((frame (fancy-splash-frame)))
1450 (let* ((img (create-image (or fancy-splash-image
1451 (if (and (display-color-p)
1452 (image-type-available-p 'xpm))
1453 "splash.xpm" "splash.pbm"))))
1454 (image-height (and img (cdr (image-size img))))
1455 (window-height (1- (window-height (frame-selected-window frame)))))
1456 (> window-height (+ image-height 19)))))))
1459 (defun normal-splash-screen (&optional hide-on-input)
1460 "Display splash screen when Emacs starts."
1461 (let ((prev-buffer (current-buffer)))
1463 (with-current-buffer (get-buffer-create "GNU Emacs")
1464 (setq buffer-read-only nil)
1466 (set (make-local-variable 'tab-width) 8)
1468 (set (make-local-variable 'mode-line-format)
1469 (propertize "---- %b %-" 'face 'mode-line-buffer-id)))
1471 (if pure-space-overflow
1473 Warning Warning!!! Pure space overflow !!!Warning Warning
1474 \(See the node Pure Storage in the Lisp manual for details.)\n"))
1476 ;; The convention for this piece of code is that
1477 ;; each piece of output starts with one or two newlines
1478 ;; and does not end with any newlines.
1479 (insert "Welcome to GNU Emacs")
1481 (if (eq system-type 'gnu/linux)
1482 ", one component of the GNU/Linux operating system.\n"
1483 ", a part of the GNU operating system.\n"))
1486 (insert (substitute-command-keys
1488 "\nType \\[recenter] to begin editing"
1489 (if (equal (buffer-name prev-buffer) "*scratch*")
1491 " your file.\n")))))
1493 (if (display-mouse-p)
1494 ;; The user can use the mouse to activate menus
1495 ;; so give help in terms of menu items.
1498 You can do basic editing with the menu bar and scroll bar using the mouse.
1500 Useful File menu items:
1501 Exit Emacs (or type Control-x followed by Control-c)
1502 Recover Crashed Session Recover files you were editing before a crash
1504 Important Help menu items:
1505 Emacs Tutorial Learn how to use Emacs efficiently
1506 Emacs FAQ Frequently asked questions and answers
1507 Read the Emacs Manual View the Emacs manual using Info
1508 \(Non)Warranty GNU Emacs comes with ABSOLUTELY NO WARRANTY
1509 Copying Conditions Conditions for redistributing and changing Emacs
1510 Getting New Versions How to obtain the latest version of Emacs
1511 More Manuals / Ordering Manuals How to order printed manuals from the FSF
1513 (insert "\n\n" (emacs-version)
1515 Copyright (C) 2006 Free Software Foundation, Inc."))
1517 ;; No mouse menus, so give help using kbd commands.
1519 ;; If keys have their default meanings,
1520 ;; use precomputed string to save lots of time.
1521 (if (and (eq (key-binding "\C-h") 'help-command)
1522 (eq (key-binding "\C-xu") 'advertised-undo)
1523 (eq (key-binding "\C-x\C-c") 'save-buffers-kill-emacs)
1524 (eq (key-binding "\C-ht") 'help-with-tutorial)
1525 (eq (key-binding "\C-hi") 'info)
1526 (eq (key-binding "\C-hr") 'info-emacs-manual)
1527 (eq (key-binding "\C-h\C-n") 'view-emacs-news))
1529 Get help C-h (Hold down CTRL and press h)
1531 Emacs tutorial C-h t Undo changes C-x u
1532 Buy manuals C-h C-m Exit Emacs C-x C-c
1533 Browse manuals C-h i")
1535 (insert (substitute-command-keys
1538 Emacs manual \\[info-emacs-manual]
1539 Emacs tutorial \\[help-with-tutorial]\tUndo changes\t\\[advertised-undo]
1540 Buy manuals \\[view-order-manuals]\tExit Emacs\t\\[save-buffers-kill-emacs]
1541 Browse manuals \\[info]"
1542 (let ((where (where-is-internal
1543 'help-command nil t)))
1545 (key-description where)
1548 ;; Say how to use the menu bar with the keyboard.
1549 (if (and (eq (key-binding "\M-`") 'tmm-menubar)
1550 (eq (key-binding [f10]) 'tmm-menubar))
1552 Activate menubar F10 or ESC ` or M-`")
1553 (insert (substitute-command-keys "
1554 Activate menubar \\[tmm-menubar]")))
1556 ;; Many users seem to have problems with these.
1558 \(`C-' means use the CTRL key. `M-' means use the Meta (or Alt) key.
1559 If you have no Meta key, you may instead type ESC followed by the character.)")
1561 (insert "\n\n" (emacs-version)
1563 Copyright (C) 2006 Free Software Foundation, Inc.")
1565 (if (and (eq (key-binding "\C-h\C-c") 'describe-copying)
1566 (eq (key-binding "\C-h\C-d") 'describe-distribution)
1567 (eq (key-binding "\C-h\C-w") 'describe-no-warranty))
1570 GNU Emacs comes with ABSOLUTELY NO WARRANTY; type C-h C-w for full details.
1571 Emacs is Free Software--Free as in Freedom--so you can redistribute copies
1572 of Emacs and modify it; type C-h C-c to see the conditions.
1573 Type C-h C-d for information on getting the latest version.")
1574 (insert (substitute-command-keys
1576 GNU Emacs comes with ABSOLUTELY NO WARRANTY; type \\[describe-no-warranty] for full details.
1577 Emacs is Free Software--Free as in Freedom--so you can redistribute copies
1578 of Emacs and modify it; type \\[describe-copying] to see the conditions.
1579 Type \\[describe-distribution] for information on getting the latest version."))))
1581 ;; The rest of the startup screen is the same on all
1582 ;; kinds of terminals.
1584 ;; Give information on recovering, if there was a crash.
1585 (and auto-save-list-file-prefix
1586 ;; Don't signal an error if the
1587 ;; directory for auto-save-list files
1588 ;; does not yet exist.
1589 (file-directory-p (file-name-directory
1590 auto-save-list-file-prefix))
1592 (file-name-directory auto-save-list-file-prefix)
1595 (regexp-quote (file-name-nondirectory
1596 auto-save-list-file-prefix)))
1598 (insert "\n\nIf an Emacs session crashed recently, "
1599 "type Meta-x recover-session RET\nto recover"
1600 " the files you were editing."))
1602 ;; Display the input that we set up in the buffer.
1603 (set-buffer-modified-p nil)
1604 (setq buffer-read-only t)
1605 (if (and view-read-only (not view-mode))
1606 (view-mode-enter nil 'kill-buffer))
1607 (goto-char (point-min))
1609 (if (or (window-minibuffer-p)
1610 (window-dedicated-p (selected-window)))
1611 ;; If hide-on-input is nil, creating a new frame will
1612 ;; generate enough events that the subsequent `sit-for'
1613 ;; will immediately return anyway.
1614 nil ;; (pop-to-buffer (current-buffer))
1615 (save-window-excursion
1616 (switch-to-buffer (current-buffer))
1619 (switch-to-buffer (current-buffer))
1620 ;; In case the window is dedicated or something.
1621 (error (pop-to-buffer (current-buffer))))))
1622 ;; Unwind ... ensure splash buffer is killed
1624 (kill-buffer "GNU Emacs")
1625 (switch-to-buffer "GNU Emacs")
1626 (rename-buffer "*About GNU Emacs*" t)))))
1629 (defun startup-echo-area-message ()
1630 (if (eq (key-binding "\C-h\C-p") 'describe-project)
1631 "For information about the GNU Project and its goals, type C-h C-p."
1632 (substitute-command-keys
1633 "For information about the GNU Project and its goals, type \
1634 \\[describe-project].")))
1637 (defun display-startup-echo-area-message ()
1638 (let ((resize-mini-windows t))
1639 (message "%s" (startup-echo-area-message))))
1642 (defun display-splash-screen (&optional hide-on-input)
1643 "Display splash screen according to display.
1644 Fancy splash screens are used on graphic displays,
1646 With a prefix argument, any user input hides the splash screen."
1648 (if (use-fancy-splash-screens-p)
1649 (fancy-splash-screens hide-on-input)
1650 (normal-splash-screen hide-on-input)))
1653 (defun command-line-1 (command-line-args-left)
1654 (or noninteractive (input-pending-p) init-file-had-error
1655 ;; t if the init file says to inhibit the echo area startup message.
1656 (and inhibit-startup-echo-area-message
1658 (or (and (get 'inhibit-startup-echo-area-message 'saved-value)
1659 (equal inhibit-startup-echo-area-message
1660 (if (equal init-file-user "")
1663 ;; Wasn't set with custom; see if .emacs has a setq.
1664 (let ((buffer (get-buffer-create " *temp*")))
1669 (insert-file-contents user-init-file)
1672 "([ \t\n]*setq[ \t\n]+"
1673 "inhibit-startup-echo-area-message[ \t\n]+"
1676 (if (equal init-file-user "")
1682 (kill-buffer buffer)))))
1683 ;; display-splash-screen at the end of command-line-1 calls
1684 ;; use-fancy-splash-screens-p. This can cause image.el to be
1685 ;; loaded, putting "Loading image... done" in the echo area.
1686 ;; This hides startup-echo-area-message. So
1687 ;; use-fancy-splash-screens-p is called here simply to get the
1688 ;; loading of image.el (if needed) out of the way before
1689 ;; display-startup-echo-area-message runs.
1691 (use-fancy-splash-screens-p)
1692 (display-startup-echo-area-message)))
1694 ;; Delay 2 seconds after an init file error message
1695 ;; was displayed, so user can read it.
1696 (when init-file-had-error
1699 (when (and pure-space-overflow
1700 (not noninteractive))
1703 "Building Emacs overflowed pure space. (See the node Pure Storage in the Lisp manual for details.)"
1706 (when command-line-args-left
1707 ;; We have command args; process them.
1708 (let ((dir command-line-default-directory)
1712 ;; This approach loses for "-batch -L DIR --eval "(require foo)",
1713 ;; if foo is intended to be found in DIR.
1715 ;; ;; The directories listed in --directory/-L options will *appear*
1716 ;; ;; at the front of `load-path' in the order they appear on the
1717 ;; ;; command-line. We cannot do this by *placing* them at the front
1718 ;; ;; in the order they appear, so we need this variable to hold them,
1722 ;; To DTRT we keep track of the splice point and modify `load-path'
1723 ;; straight away upon any --directory/-L option.
1725 just-files ;; t if this follows the magic -- option.
1726 ;; This includes our standard options' long versions
1727 ;; and long versions of what's on command-switch-alist.
1729 (append '(("--funcall") ("--load") ("--insert") ("--kill")
1730 ("--directory") ("--eval") ("--execute") ("--no-splash")
1731 ("--find-file") ("--visit") ("--file") ("--no-desktop"))
1732 (mapcar (lambda (elt)
1733 (list (concat "-" (car elt))))
1734 command-switch-alist)))
1738 ;; Add the long X options to longopts.
1739 (dolist (tem command-line-x-option-alist)
1740 (if (string-match "^--" (car tem))
1741 (push (list (car tem)) longopts)))
1743 ;; Loop, processing options.
1744 (while command-line-args-left
1745 (let* ((argi (car command-line-args-left))
1748 (setq command-line-args-left (cdr command-line-args-left))
1750 ;; Do preliminary decoding of the option.
1752 ;; After --, don't look for options; treat all args as files.
1754 ;; Convert long options to ordinary options
1755 ;; and separate out an attached option argument into argval.
1756 (when (string-match "^\\(--[^=]*\\)=" argi)
1757 (setq argval (substring argi (match-end 0))
1758 argi (match-string 1 argi)))
1759 (if (equal argi "--")
1760 (setq completion nil)
1761 (setq completion (try-completion argi longopts)))
1762 (if (eq completion t)
1763 (setq argi (substring argi 1))
1764 (if (stringp completion)
1765 (let ((elt (assoc completion longopts)))
1767 (error "Option `%s' is ambiguous" argi))
1768 (setq argi (substring (car elt) 1)))
1772 ;; Execute the option.
1773 (cond ((setq tem (assoc argi command-switch-alist))
1775 (let ((command-line-args-left
1776 (cons argval command-line-args-left)))
1777 (funcall (cdr tem) argi))
1778 (funcall (cdr tem) argi)))
1780 ((equal argi "-no-splash")
1781 (setq inhibit-startup-message t))
1783 ((member argi '("-f" ; what the manual claims
1785 "-e")) ; what the source used to say
1786 (setq tem (intern (or argval (pop command-line-args-left))))
1788 (command-execute tem)
1791 ((member argi '("-eval" "-execute"))
1792 (eval (read (or argval (pop command-line-args-left)))))
1794 ((member argi '("-L" "-directory"))
1795 (setq tem (expand-file-name
1796 (command-line-normalize-file-name
1797 (or argval (pop command-line-args-left)))))
1798 (cond (splice (setcdr splice (cons tem (cdr splice)))
1799 (setq splice (cdr splice)))
1800 (t (setq load-path (cons tem load-path)
1801 splice load-path))))
1803 ((member argi '("-l" "-load"))
1804 (let* ((file (command-line-normalize-file-name
1805 (or argval (pop command-line-args-left))))
1806 ;; Take file from default dir if it exists there;
1807 ;; otherwise let `load' search for it.
1808 (file-ex (expand-file-name file)))
1809 (when (file-exists-p file-ex)
1810 (setq file file-ex))
1813 ;; This is used to handle -script. It's not clear
1814 ;; we need to document it.
1815 ((member argi '("-scriptload"))
1816 (let* ((file (command-line-normalize-file-name
1817 (or argval (pop command-line-args-left))))
1818 ;; Take file from default dir.
1819 (file-ex (expand-file-name file)))
1820 (load file-ex nil t t)))
1822 ((equal argi "-insert")
1823 (setq tem (or argval (pop command-line-args-left)))
1825 (error "File name omitted from `-insert' option"))
1826 (insert-file-contents (command-line-normalize-file-name tem)))
1828 ((equal argi "-kill")
1831 ;; This is for when they use --no-desktop with -q, or
1832 ;; don't load Desktop in their .emacs. If desktop.el
1833 ;; _is_ loaded, it will handle this switch, and we
1834 ;; won't see it by the time we get here.
1835 ((equal argi "-no-desktop")
1836 (message "\"--no-desktop\" ignored because the Desktop package is not loaded"))
1838 ((string-match "^\\+[0-9]+\\'" argi)
1839 (setq line (string-to-number argi)))
1841 ((string-match "^\\+\\([0-9]+\\):\\([0-9]+\\)\\'" argi)
1842 (setq line (string-to-number (match-string 1 argi))
1843 column (string-to-number (match-string 2 argi))))
1845 ((setq tem (assoc argi command-line-x-option-alist))
1846 ;; Ignore X-windows options and their args if not using X.
1847 (setq command-line-args-left
1848 (nthcdr (nth 1 tem) command-line-args-left)))
1850 ((member argi '("-find-file" "-file" "-visit"))
1851 ;; An explicit option to specify visiting a file.
1852 (setq tem (or argval (pop command-line-args-left)))
1853 (unless (stringp tem)
1854 (error "File name omitted from `%s' option" argi))
1855 (setq file-count (1+ file-count))
1856 (let ((file (expand-file-name
1857 (command-line-normalize-file-name tem) dir)))
1858 (if (= file-count 1)
1859 (setq first-file-buffer (find-file file))
1860 (find-file-other-window file)))
1864 (unless (< column 1)
1865 (move-to-column (1- column)))
1869 (setq just-files t))
1871 ;; We have almost exhausted our options. See if the
1872 ;; user has made any other command-line options available
1873 (let ((hooks command-line-functions) ;; lrs 7/31/89
1876 (not (setq did-hook (funcall (car hooks)))))
1877 (setq hooks (cdr hooks)))
1879 ;; Presume that the argument is a file name.
1881 (if (string-match "\\`-" argi)
1882 (error "Unknown option `%s'" argi))
1883 (setq file-count (1+ file-count))
1886 (command-line-normalize-file-name orig-argi)
1888 (if (= file-count 1)
1889 (setq first-file-buffer (find-file file))
1890 (find-file-other-window file)))
1894 (unless (< column 1)
1895 (move-to-column (1- column)))
1896 (setq column 0))))))
1897 ;; In unusual circumstances, the execution of Lisp code due
1898 ;; to command-line options can cause the last visible frame
1899 ;; to be deleted. In this case, kill emacs to avoid an
1901 (unless (frame-live-p (selected-frame)) (kill-emacs nil))))
1903 ;; If 3 or more files visited, and not all visible,
1904 ;; show user what they all are. But leave the last one current.
1905 (and (> file-count 2)
1906 (not noninteractive)
1907 (not inhibit-startup-buffer-menu)
1908 (or (get-buffer-window first-file-buffer)
1911 ;; Maybe display a startup screen.
1912 (unless (or inhibit-startup-message
1914 emacs-quick-startup)
1915 ;; Display a startup screen, after some preparations.
1917 ;; If there are no switches to process, we might as well
1918 ;; run this hook now, and there may be some need to do it
1919 ;; before doing any output.
1920 (run-hooks 'emacs-startup-hook)
1921 (and term-setup-hook
1922 (run-hooks 'term-setup-hook))
1923 (setq inhibit-startup-hooks t)
1925 ;; It's important to notice the user settings before we
1926 ;; display the startup message; otherwise, the settings
1927 ;; won't take effect until the user gives the first
1928 ;; keystroke, and that's distracting.
1929 (when (fboundp 'frame-notice-user-settings)
1930 (frame-notice-user-settings))
1932 ;; If there are no switches to process, we might as well
1933 ;; run this hook now, and there may be some need to do it
1934 ;; before doing any output.
1935 (when window-setup-hook
1936 (run-hooks 'window-setup-hook)
1937 ;; Don't let the hook be run twice.
1938 (setq window-setup-hook nil))
1940 ;; Do this now to avoid an annoying delay if the user
1941 ;; clicks the menu bar during the sit-for.
1942 (when (display-popup-menus-p)
1943 (precompute-menubar-bindings))
1945 (setq menubar-bindings-done t))
1947 ;; If *scratch* is selected and it is empty, insert an
1948 ;; initial message saying not to create a file there.
1949 (when (and initial-scratch-message
1950 (equal (buffer-name) "*scratch*")
1951 (= 0 (buffer-size)))
1952 (insert initial-scratch-message)
1953 (set-buffer-modified-p nil))
1955 ;; If user typed input during all that work,
1956 ;; abort the startup screen. Otherwise, display it now.
1957 (unless (input-pending-p)
1958 (display-splash-screen t))))
1961 (defun command-line-normalize-file-name (file)
1962 "Collapse multiple slashes to one, to handle non-Emacs file names."
1964 ;; Use arg 1 so that we don't collapse // at the start of the file name.
1965 ;; That is significant on some systems.
1966 ;; However, /// at the beginning is supposed to mean just /, not //.
1967 (if (string-match "^///+" file)
1968 (setq file (replace-match "/" t t file)))
1969 (while (string-match "//+" file 1)
1970 (setq file (replace-match "/" t t file)))
1973 ;; arch-tag: 7e294698-244d-4758-984b-4047f887a5db
1974 ;;; startup.el ends here