Update docstrings and comments to use "init file" terminology.
[emacs.git] / lisp / startup.el
blobdb5efb89eed086760aeca6f6168639541abaf371
1 ;;; startup.el --- process Emacs shell arguments -*- lexical-binding: t -*-
3 ;; Copyright (C) 1985-1986, 1992, 1994-2012 Free Software Foundation, Inc.
5 ;; Maintainer: FSF
6 ;; Keywords: internal
7 ;; Package: emacs
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 3 of the License, or
14 ;; (at your option) any later version.
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. If not, see <http://www.gnu.org/licenses/>.
24 ;;; Commentary:
26 ;; This file parses the command line and gets Emacs running. Options
27 ;; on the command line are handled in precedence order. For priorities
28 ;; see the structure standard_args in the emacs.c file.
30 ;;; Code:
32 (setq top-level '(normal-top-level))
34 (defvar command-line-processed nil
35 "Non-nil once command line has been processed.")
37 (defgroup initialization nil
38 "Emacs start-up procedure."
39 :group 'environment)
41 (defcustom initial-buffer-choice nil
42 "Buffer to show after starting Emacs.
43 If the value is nil and `inhibit-startup-screen' is nil, show the
44 startup screen. If the value is a string, visit the specified file
45 or directory using `find-file'. If t, open the `*scratch*'
46 buffer."
47 :type '(choice
48 (const :tag "Startup screen" nil)
49 (directory :tag "Directory" :value "~/")
50 (file :tag "File" :value "~/.emacs")
51 (const :tag "Lisp scratch buffer" t))
52 :version "23.1"
53 :group 'initialization)
55 (defcustom inhibit-startup-screen nil
56 "Non-nil inhibits the startup screen.
58 This is for use in your personal init file (but NOT site-start.el),
59 once you are familiar with the contents of the startup screen."
60 :type 'boolean
61 :group 'initialization)
63 (defvaralias 'inhibit-splash-screen 'inhibit-startup-screen)
64 (defvaralias 'inhibit-startup-message 'inhibit-startup-screen)
66 (defvar startup-screen-inhibit-startup-screen nil)
68 ;; FIXME? Why does this get such weirdly extreme treatment, when the
69 ;; more important inhibit-startup-screen does not.
70 (defcustom inhibit-startup-echo-area-message nil
71 "Non-nil inhibits the initial startup echo area message.
72 Setting this variable takes effect
73 only if you do it with the customization buffer
74 or if your init file contains a line of this form:
75 (setq inhibit-startup-echo-area-message \"YOUR-USER-NAME\")
76 If your init file is byte-compiled, use the following form
77 instead:
78 (eval '(setq inhibit-startup-echo-area-message \"YOUR-USER-NAME\"))
79 Thus, someone else using a copy of your init file will see the
80 startup message unless he personally acts to inhibit it."
81 :type '(choice (const :tag "Don't inhibit")
82 (string :tag "Enter your user name, to inhibit"))
83 :group 'initialization)
85 (defcustom inhibit-default-init nil
86 "Non-nil inhibits loading the `default' library."
87 :type 'boolean
88 :group 'initialization)
90 (defcustom inhibit-startup-buffer-menu nil
91 "Non-nil inhibits display of buffer list when more than 2 files are loaded."
92 :type 'boolean
93 :group 'initialization)
95 (defvar command-switch-alist nil
96 "Alist of command-line switches.
97 Elements look like (SWITCH-STRING . HANDLER-FUNCTION).
98 HANDLER-FUNCTION receives the switch string as its sole argument;
99 the remaining command-line args are in the variable `command-line-args-left'.")
101 (defvar command-line-args-left nil
102 "List of command-line args not yet processed.")
104 (defvaralias 'argv 'command-line-args-left
105 "List of command-line args not yet processed.
106 This is a convenience alias, so that one can write \(pop argv\)
107 inside of --eval command line arguments in order to access
108 following arguments.")
109 (internal-make-var-non-special 'argv)
111 (defvar argi nil
112 "Current command-line argument.")
113 (internal-make-var-non-special 'argi)
115 (defvar command-line-functions nil ;; lrs 7/31/89
116 "List of functions to process unrecognized command-line arguments.
117 Each function should access the dynamically bound variables
118 `argi' (the current argument) and `command-line-args-left' (the remaining
119 arguments). The function should return non-nil only if it recognizes and
120 processes `argi'. If it does so, it may consume successive arguments by
121 altering `command-line-args-left' to remove them.")
123 (defvar command-line-default-directory nil
124 "Default directory to use for command line arguments.
125 This is normally copied from `default-directory' when Emacs starts.")
127 ;; This is here, rather than in x-win.el, so that we can ignore these
128 ;; options when we are not using X.
129 (defconst command-line-x-option-alist
130 '(("-bw" 1 x-handle-numeric-switch border-width)
131 ("-d" 1 x-handle-display)
132 ("-display" 1 x-handle-display)
133 ("-name" 1 x-handle-name-switch)
134 ("-title" 1 x-handle-switch title)
135 ("-T" 1 x-handle-switch title)
136 ("-r" 0 x-handle-switch reverse t)
137 ("-rv" 0 x-handle-switch reverse t)
138 ("-reverse" 0 x-handle-switch reverse t)
139 ("-reverse-video" 0 x-handle-switch reverse t)
140 ("-fn" 1 x-handle-switch font)
141 ("-font" 1 x-handle-switch font)
142 ("-fs" 0 x-handle-initial-switch fullscreen fullboth)
143 ("-fw" 0 x-handle-initial-switch fullscreen fullwidth)
144 ("-fh" 0 x-handle-initial-switch fullscreen fullheight)
145 ("-mm" 0 x-handle-initial-switch fullscreen maximized)
146 ("-ib" 1 x-handle-numeric-switch internal-border-width)
147 ("-g" 1 x-handle-geometry)
148 ("-lsp" 1 x-handle-numeric-switch line-spacing)
149 ("-geometry" 1 x-handle-geometry)
150 ("-fg" 1 x-handle-switch foreground-color)
151 ("-foreground" 1 x-handle-switch foreground-color)
152 ("-bg" 1 x-handle-switch background-color)
153 ("-background" 1 x-handle-switch background-color)
154 ("-ms" 1 x-handle-switch mouse-color)
155 ("-nbi" 0 x-handle-switch icon-type nil)
156 ("-iconic" 0 x-handle-iconic)
157 ("-xrm" 1 x-handle-xrm-switch)
158 ("-cr" 1 x-handle-switch cursor-color)
159 ("-vb" 0 x-handle-switch vertical-scroll-bars t)
160 ("-hb" 0 x-handle-switch horizontal-scroll-bars t)
161 ("-bd" 1 x-handle-switch)
162 ("--border-width" 1 x-handle-numeric-switch border-width)
163 ("--display" 1 x-handle-display)
164 ("--name" 1 x-handle-name-switch)
165 ("--title" 1 x-handle-switch title)
166 ("--reverse-video" 0 x-handle-switch reverse t)
167 ("--font" 1 x-handle-switch font)
168 ("--fullscreen" 0 x-handle-initial-switch fullscreen fullboth)
169 ("--fullwidth" 0 x-handle-initial-switch fullscreen fullwidth)
170 ("--fullheight" 0 x-handle-initial-switch fullscreen fullheight)
171 ("--maximized" 0 x-handle-initial-switch fullscreen maximized)
172 ("--internal-border" 1 x-handle-numeric-switch internal-border-width)
173 ("--geometry" 1 x-handle-geometry)
174 ("--foreground-color" 1 x-handle-switch foreground-color)
175 ("--background-color" 1 x-handle-switch background-color)
176 ("--mouse-color" 1 x-handle-switch mouse-color)
177 ("--no-bitmap-icon" 0 x-handle-no-bitmap-icon)
178 ("--iconic" 0 x-handle-iconic)
179 ("--xrm" 1 x-handle-xrm-switch)
180 ("--cursor-color" 1 x-handle-switch cursor-color)
181 ("--vertical-scroll-bars" 0 x-handle-switch vertical-scroll-bars t)
182 ("--line-spacing" 1 x-handle-numeric-switch line-spacing)
183 ("--border-color" 1 x-handle-switch border-color)
184 ("--smid" 1 x-handle-smid)
185 ("--parent-id" 1 x-handle-parent-id))
186 "Alist of X Windows options.
187 Each element has the form
188 (NAME NUMARGS HANDLER FRAME-PARAM VALUE)
189 where NAME is the option name string, NUMARGS is the number of arguments
190 that the option accepts, HANDLER is a function to call to handle the option.
191 FRAME-PARAM (optional) is the frame parameter this option specifies,
192 and VALUE is the value which is given to that frame parameter
193 \(most options use the argument for this, so VALUE is not present).")
195 (defconst command-line-ns-option-alist
196 '(("-NSAutoLaunch" 1 ns-ignore-1-arg)
197 ("-NXAutoLaunch" 1 ns-ignore-1-arg)
198 ("-macosx" 0 ignore)
199 ("-NSHost" 1 ns-ignore-1-arg)
200 ("-_NSMachLaunch" 1 ns-ignore-1-arg)
201 ("-MachLaunch" 1 ns-ignore-1-arg)
202 ("-NXOpen" 1 ns-ignore-1-arg)
203 ("-NSOpen" 1 ns-handle-nxopen)
204 ("-NXOpenTemp" 1 ns-ignore-1-arg)
205 ("-NSOpenTemp" 1 ns-handle-nxopentemp)
206 ("-GSFilePath" 1 ns-handle-nxopen)
207 ;;("-bw" . x-handle-numeric-switch)
208 ;;("-d" . x-handle-display)
209 ;;("-display" . x-handle-display)
210 ("-name" 1 x-handle-name-switch)
211 ("-title" 1 x-handle-switch title)
212 ("-T" 1 x-handle-switch title)
213 ("-r" 0 x-handle-switch reverse t)
214 ("-rv" 0 x-handle-switch reverse t)
215 ("-reverse" 0 x-handle-switch reverse t)
216 ("-fn" 1 x-handle-switch font)
217 ("-font" 1 x-handle-switch font)
218 ("-ib" 1 x-handle-numeric-switch internal-border-width)
219 ;;("-g" . x-handle-geometry)
220 ;;("-geometry" . x-handle-geometry)
221 ("-fg" 1 x-handle-switch foreground-color)
222 ("-foreground" 1 x-handle-switch foreground-color)
223 ("-bg" 1 x-handle-switch background-color)
224 ("-background" 1 x-handle-switch background-color)
225 ; ("-ms" 1 x-handle-switch mouse-color)
226 ("-itype" 0 x-handle-switch icon-type t)
227 ("-i" 0 x-handle-switch icon-type t)
228 ("-iconic" 0 x-handle-iconic icon-type t)
229 ;;("-xrm" . x-handle-xrm-switch)
230 ("-cr" 1 x-handle-switch cursor-color)
231 ("-vb" 0 x-handle-switch vertical-scroll-bars t)
232 ("-hb" 0 x-handle-switch horizontal-scroll-bars t)
233 ("-bd" 1 x-handle-switch)
234 ;; ("--border-width" 1 x-handle-numeric-switch border-width)
235 ;; ("--display" 1 ns-handle-display)
236 ("--name" 1 x-handle-name-switch)
237 ("--title" 1 x-handle-switch title)
238 ("--reverse-video" 0 x-handle-switch reverse t)
239 ("--font" 1 x-handle-switch font)
240 ("--internal-border" 1 x-handle-numeric-switch internal-border-width)
241 ;; ("--geometry" 1 ns-handle-geometry)
242 ("--foreground-color" 1 x-handle-switch foreground-color)
243 ("--background-color" 1 x-handle-switch background-color)
244 ("--mouse-color" 1 x-handle-switch mouse-color)
245 ("--icon-type" 0 x-handle-switch icon-type t)
246 ("--iconic" 0 x-handle-iconic)
247 ;; ("--xrm" 1 ns-handle-xrm-switch)
248 ("--cursor-color" 1 x-handle-switch cursor-color)
249 ("--vertical-scroll-bars" 0 x-handle-switch vertical-scroll-bars t)
250 ("--border-color" 1 x-handle-switch border-width))
251 "Alist of NS options.
252 Each element has the form
253 (NAME NUMARGS HANDLER FRAME-PARAM VALUE)
254 where NAME is the option name string, NUMARGS is the number of arguments
255 that the option accepts, HANDLER is a function to call to handle the option.
256 FRAME-PARAM (optional) is the frame parameter this option specifies,
257 and VALUE is the value which is given to that frame parameter
258 \(most options use the argument for this, so VALUE is not present).")
261 (defvar before-init-hook nil
262 "Normal hook run after handling urgent options but before loading init files.")
264 (defvar after-init-hook nil
265 "Normal hook run after initializing the Emacs session.
266 It is run after Emacs loads the init file, `default' library, the
267 abbrevs file, and additional Lisp packages (if any), and setting
268 the value of `after-init-time'.
270 There is no `condition-case' around the running of this hook;
271 therefore, if `debug-on-error' is non-nil, an error in one of
272 these functions will invoke the debugger.")
274 (defvar emacs-startup-hook nil
275 "Normal hook run after loading init files and handling the command line.")
277 (defvar term-setup-hook nil
278 "Normal hook run after loading terminal-specific Lisp code.
279 It also follows `emacs-startup-hook'. This hook exists for users to set,
280 so as to override the definitions made by the terminal-specific file.
281 Emacs never sets this variable itself.")
283 (defvar inhibit-startup-hooks nil
284 "Non-nil means don't run `term-setup-hook' and `emacs-startup-hook'.
285 This is because we already did so.")
287 (defvar keyboard-type nil
288 "The brand of keyboard you are using.
289 This variable is used to define the proper function and keypad
290 keys for use under X. It is used in a fashion analogous to the
291 environment variable TERM.")
293 (defvar window-setup-hook nil
294 "Normal hook run to initialize window system display.
295 Emacs runs this hook after processing the command line arguments and loading
296 the user's init file.")
298 (defcustom initial-major-mode 'lisp-interaction-mode
299 "Major mode command symbol to use for the initial `*scratch*' buffer."
300 :type 'function
301 :group 'initialization)
303 (defvar init-file-user nil
304 "Identity of user whose init file is or was read.
305 The value is nil if `-q' or `--no-init-file' was specified,
306 meaning do not load any init file.
308 Otherwise, the value may be an empty string, meaning
309 use the init file for the user who originally logged in,
310 or it may be a string containing a user's name meaning
311 use that person's init file.
313 In either of the latter cases, `(concat \"~\" init-file-user \"/\")'
314 evaluates to the name of the directory where the init file was
315 looked for.
317 Setting `init-file-user' does not prevent Emacs from loading
318 `site-start.el'. The only way to do that is to use `--no-site-file'.")
320 (defcustom site-run-file (purecopy "site-start")
321 "File containing site-wide run-time initializations.
322 This file is loaded at run-time before `~/.emacs'. It contains inits
323 that need to be in place for the entire site, but which, due to their
324 higher incidence of change, don't make sense to load into Emacs's
325 dumped image. Thus, the run-time load order is: 1. file described in
326 this variable, if non-nil; 2. `~/.emacs'; 3. `default.el'.
328 Don't use the `site-start.el' file for things some users may not like.
329 Put them in `default.el' instead, so that users can more easily
330 override them. Users can prevent loading `default.el' with the `-q'
331 option or by setting `inhibit-default-init' in their own init files,
332 but inhibiting `site-start.el' requires `--no-site-file', which
333 is less convenient.
335 This variable is defined for customization so as to make
336 it visible in the relevant context. However, actually customizing it
337 is not allowed, since it would not work anyway. The only way to set
338 this variable usefully is to set it while building and dumping Emacs."
339 :type '(choice (const :tag "none" nil) string)
340 :group 'initialization
341 :initialize 'custom-initialize-default
342 :set (lambda (_variable _value)
343 (error "Customizing `site-run-file' does not work")))
345 (defcustom mail-host-address nil
346 "Name of this machine, for purposes of naming users.
347 If non-nil, Emacs uses this instead of `system-name' when constructing
348 email addresses."
349 :type '(choice (const nil) string)
350 :group 'mail)
352 (defcustom user-mail-address (if command-line-processed
353 (or (getenv "EMAIL")
354 (concat (user-login-name) "@"
355 (or mail-host-address
356 (system-name))))
357 ;; Empty string means "not set yet".
359 "Full mailing address of this user.
360 This is initialized with environment variable `EMAIL' or, as a
361 fallback, using `mail-host-address'. This is done after your
362 init file is read, in case it sets `mail-host-address'."
363 :type 'string
364 :group 'mail)
366 (defcustom auto-save-list-file-prefix
367 (cond ((eq system-type 'ms-dos)
368 ;; MS-DOS cannot have initial dot, and allows only 8.3 names
369 (concat user-emacs-directory "auto-save.list/_s"))
371 (concat user-emacs-directory "auto-save-list/.saves-")))
372 "Prefix for generating `auto-save-list-file-name'.
373 This is used after reading your init file to initialize
374 `auto-save-list-file-name', by appending Emacs's pid and the system name,
375 if you have not already set `auto-save-list-file-name' yourself.
376 Directories in the prefix will be created if necessary.
377 Set this to nil if you want to prevent `auto-save-list-file-name'
378 from being initialized."
379 :type '(choice (const :tag "Don't record a session's auto save list" nil)
380 string)
381 :group 'auto-save)
383 (defvar emacs-basic-display nil)
385 (defvar init-file-debug nil)
387 (defvar init-file-had-error nil
388 "Non-nil if there was an error loading the user's init file.")
390 (defvar normal-top-level-add-subdirs-inode-list nil)
392 (defvar no-blinking-cursor nil)
394 (defvar default-frame-background-mode)
396 (defvar pure-space-overflow nil
397 "Non-nil if building Emacs overflowed pure space.")
399 (defvar pure-space-overflow-message (purecopy "\
400 Warning Warning!!! Pure space overflow !!!Warning Warning
401 \(See the node Pure Storage in the Lisp manual for details.)\n"))
403 (defcustom tutorial-directory
404 (file-name-as-directory (expand-file-name "tutorials" data-directory))
405 "Directory containing the Emacs TUTORIAL files."
406 :group 'installation
407 :type 'directory
408 :initialize 'custom-initialize-delay)
410 (defconst package-subdirectory-regexp
411 "\\([^.].*?\\)-\\([0-9]+\\(?:[.][0-9]+\\|\\(?:pre\\|beta\\|alpha\\)[0-9]+\\)*\\)"
412 "Regular expression matching the name of a package subdirectory.
413 The first subexpression is the package name.
414 The second subexpression is the version string.
416 The regexp should not contain a starting \"\\`\" or a trailing
417 \"\\'\"; those are added automatically by callers.")
419 (defun normal-top-level-add-subdirs-to-load-path ()
420 "Add all subdirectories of `default-directory' to `load-path'.
421 More precisely, this uses only the subdirectories whose names
422 start with letters or digits; it excludes any subdirectory named `RCS'
423 or `CVS', and any subdirectory that contains a file named `.nosearch'."
424 (let (dirs
425 attrs
426 (pending (list default-directory)))
427 ;; This loop does a breadth-first tree walk on DIR's subtree,
428 ;; putting each subdir into DIRS as its contents are examined.
429 (while pending
430 (push (pop pending) dirs)
431 (let* ((this-dir (car dirs))
432 (contents (directory-files this-dir))
433 (default-directory this-dir)
434 (canonicalized (if (fboundp 'untranslated-canonical-name)
435 (untranslated-canonical-name this-dir))))
436 ;; The Windows version doesn't report meaningful inode numbers, so
437 ;; use the canonicalized absolute file name of the directory instead.
438 (setq attrs (or canonicalized
439 (nthcdr 10 (file-attributes this-dir))))
440 (unless (member attrs normal-top-level-add-subdirs-inode-list)
441 (push attrs normal-top-level-add-subdirs-inode-list)
442 (dolist (file contents)
443 (and (string-match "\\`[[:alnum:]]" file)
444 ;; The lower-case variants of RCS and CVS are for DOS/Windows.
445 (not (member file '("RCS" "CVS" "rcs" "cvs")))
446 ;; Avoid doing a `stat' when it isn't necessary because
447 ;; that can cause trouble when an NFS server is down.
448 (not (string-match "\\.elc?\\'" file))
449 (file-directory-p file)
450 (let ((expanded (expand-file-name file)))
451 (or (file-exists-p (expand-file-name ".nosearch" expanded))
452 (setq pending (nconc pending (list expanded))))))))))
453 (normal-top-level-add-to-load-path (cdr (nreverse dirs)))))
455 (defun normal-top-level-add-to-load-path (dirs)
456 "This function is called from a subdirs.el file.
457 It assumes that `default-directory' is the directory in which the
458 subdirs.el file exists, and it adds to `load-path' the subdirs of
459 that directory as specified in DIRS. Normally the elements of
460 DIRS are relative."
461 (let ((tail load-path)
462 (thisdir (directory-file-name default-directory)))
463 (while (and tail
464 ;;Don't go all the way to the nil terminator.
465 (cdr tail)
466 (not (equal thisdir (car tail)))
467 (not (and (memq system-type '(ms-dos windows-nt))
468 (equal (downcase thisdir) (downcase (car tail))))))
469 (setq tail (cdr tail)))
470 ;;Splice the new section in.
471 (when tail
472 (setcdr tail (append (mapcar 'expand-file-name dirs) (cdr tail))))))
474 (defun normal-top-level ()
475 "Emacs calls this function when it first starts up.
476 It sets `command-line-processed', processes the command-line,
477 reads the initialization files, etc.
478 It is the default value of the variable `top-level'."
479 (if command-line-processed
480 (message "Back to top level.")
481 (setq command-line-processed t)
482 (let ((dir default-directory))
483 (with-current-buffer "*Messages*"
484 ;; Make it easy to do like "tail -f".
485 (set (make-local-variable 'window-point-insertion-type) t)
486 ;; Give *Messages* the same default-directory as *scratch*,
487 ;; just to keep things predictable.
488 (setq default-directory dir)))
489 ;; `user-full-name' is now known; reset its standard-value here.
490 (put 'user-full-name 'standard-value
491 (list (default-value 'user-full-name)))
492 ;; Look in each dir in load-path for a subdirs.el file.
493 ;; If we find one, load it, which will add the appropriate subdirs
494 ;; of that dir into load-path,
495 ;; Look for a leim-list.el file too. Loading it will register
496 ;; available input methods.
497 (let ((tail load-path)
498 (lispdir (expand-file-name "../lisp" data-directory))
499 ;; For out-of-tree builds, leim-list is generated in the build dir.
500 ;;; (leimdir (expand-file-name "../leim" doc-directory))
501 dir)
502 (while tail
503 (setq dir (car tail))
504 (let ((default-directory dir))
505 (load (expand-file-name "subdirs.el") t t t))
506 ;; Do not scan standard directories that won't contain a leim-list.el.
507 ;; http://lists.gnu.org/archive/html/emacs-devel/2009-10/msg00502.html
508 (or (string-match (concat "\\`" lispdir) dir)
509 (let ((default-directory dir))
510 (load (expand-file-name "leim-list.el") t t t)))
511 ;; We don't use a dolist loop and we put this "setq-cdr" command at
512 ;; the end, because the subdirs.el files may add elements to the end
513 ;; of load-path and we want to take it into account.
514 (setq tail (cdr tail))))
515 ;; If the PWD environment variable isn't accurate, delete it.
516 (let ((pwd (getenv "PWD")))
517 (and (stringp pwd)
518 ;; Use FOO/., so that if FOO is a symlink, file-attributes
519 ;; describes the directory linked to, not FOO itself.
520 (or (equal (file-attributes
521 (concat (file-name-as-directory pwd) "."))
522 (file-attributes
523 (concat (file-name-as-directory default-directory)
524 ".")))
525 (setq process-environment
526 (delete (concat "PWD=" pwd)
527 process-environment)))))
528 (setq default-directory (abbreviate-file-name default-directory))
529 (let ((old-face-font-rescale-alist face-font-rescale-alist))
530 (unwind-protect
531 (command-line)
532 ;; Do this again, in case .emacs defined more abbreviations.
533 (setq default-directory (abbreviate-file-name default-directory))
534 ;; Specify the file for recording all the auto save files of this session.
535 ;; This is used by recover-session.
536 (or auto-save-list-file-name
537 (and auto-save-list-file-prefix
538 (setq auto-save-list-file-name
539 ;; Under MS-DOS our PID is almost always reused between
540 ;; Emacs invocations. We need something more unique.
541 (cond ((eq system-type 'ms-dos)
542 ;; We are going to access the auto-save
543 ;; directory, so make sure it exists.
544 (make-directory
545 (file-name-directory auto-save-list-file-prefix)
547 (concat
548 (make-temp-name
549 (expand-file-name
550 auto-save-list-file-prefix))
551 "~"))
553 (expand-file-name
554 (format "%s%d-%s~"
555 auto-save-list-file-prefix
556 (emacs-pid)
557 (system-name))))))))
558 (unless inhibit-startup-hooks
559 (run-hooks 'emacs-startup-hook)
560 (and term-setup-hook
561 (run-hooks 'term-setup-hook)))
563 ;; Don't do this if we failed to create the initial frame,
564 ;; for instance due to a dense colormap.
565 (when (or frame-initial-frame
566 ;; If frame-initial-frame has no meaning, do this anyway.
567 (not (and initial-window-system
568 (not noninteractive)
569 (not (eq initial-window-system 'pc)))))
571 ;; FIXME: The user's init file may change
572 ;; face-font-rescale-alist. However, the default face
573 ;; already has an assigned font object, which does not take
574 ;; face-font-rescale-alist into account. For such
575 ;; situations, we ought to have a way to find all font
576 ;; objects and regenerate them; currently we do not. As a
577 ;; workaround, we specifically reset te default face's :font
578 ;; attribute here. See bug#1785.
579 (unless (eq face-font-rescale-alist
580 old-face-font-rescale-alist)
581 (set-face-attribute 'default nil :font (font-spec)))
583 ;; Modify the initial frame based on what .emacs puts into
584 ;; ...-frame-alist.
585 (if (fboundp 'frame-notice-user-settings)
586 (frame-notice-user-settings))
587 ;; Set the faces for the initial background mode even if
588 ;; frame-notice-user-settings didn't (such as on a tty).
589 ;; frame-set-background-mode is idempotent, so it won't
590 ;; cause any harm if it's already been done.
591 (if (fboundp 'frame-set-background-mode)
592 (frame-set-background-mode (selected-frame))))
594 ;; Now we know the user's default font, so add it to the menu.
595 (if (fboundp 'font-menu-add-default)
596 (font-menu-add-default))
597 (and window-setup-hook
598 (run-hooks 'window-setup-hook))))
599 ;; Subprocesses of Emacs do not have direct access to the terminal, so
600 ;; unless told otherwise they should only assume a dumb terminal.
601 ;; We are careful to do it late (after term-setup-hook), although the
602 ;; new multi-tty code does not use $TERM any more there anyway.
603 (setenv "TERM" "dumb")
604 ;; Remove DISPLAY from the process-environment as well. This allows
605 ;; `callproc.c' to give it a useful adaptive default which is either
606 ;; the value of the `display' frame-parameter or the DISPLAY value
607 ;; from initial-environment.
608 (let ((display (frame-parameter nil 'display)))
609 ;; Be careful which DISPLAY to remove from process-environment: follow
610 ;; the logic of `callproc.c'.
611 (if (stringp display) (setq display (concat "DISPLAY=" display))
612 (dolist (varval initial-environment)
613 (if (string-match "\\`DISPLAY=" varval)
614 (setq display varval))))
615 (when display
616 (delete display process-environment)))))
618 ;; Precompute the keyboard equivalents in the menu bar items.
619 ;; Command-line options supported by tty's:
620 (defconst tty-long-option-alist
621 '(("--name" . "-name")
622 ("--title" . "-T")
623 ("--reverse-video" . "-reverse")
624 ("--foreground-color" . "-fg")
625 ("--background-color" . "-bg")
626 ("--color" . "-color")))
628 (defconst tool-bar-images-pixel-height 24
629 "Height in pixels of images in the tool-bar.")
631 (defvar tool-bar-originally-present nil
632 "Non-nil if tool-bars are present before user and site init files are read.")
634 (defvar handle-args-function-alist '((nil . tty-handle-args))
635 "Functions for processing window-system dependent command-line arguments.
636 Window system startup files should add their own function to this
637 alist, which should parse the command line arguments. Those
638 pertaining to the window system should be processed and removed
639 from the returned command line.")
641 (defvar window-system-initialization-alist '((nil . ignore))
642 "Alist of window-system initialization functions.
643 Window-system startup files should add their own initialization
644 function to this list. The function should take no arguments,
645 and initialize the window system environment to prepare for
646 opening the first frame (e.g. open a connection to an X server).")
648 (defun tty-handle-args (args)
649 "Handle the X-like command-line arguments \"-fg\", \"-bg\", \"-name\", etc."
650 (let (rest)
651 (message "%S" args)
652 (while (and args
653 (not (equal (car args) "--")))
654 (let* ((argi (pop args))
655 (orig-argi argi)
656 argval completion)
657 ;; Check for long options with attached arguments
658 ;; and separate out the attached option argument into argval.
659 (when (string-match "^\\(--[^=]*\\)=" argi)
660 (setq argval (substring argi (match-end 0))
661 argi (match-string 1 argi)))
662 (when (string-match "^--" argi)
663 (setq completion (try-completion argi tty-long-option-alist))
664 (if (eq completion t)
665 ;; Exact match for long option.
666 (setq argi (cdr (assoc argi tty-long-option-alist)))
667 (if (stringp completion)
668 (let ((elt (assoc completion tty-long-option-alist)))
669 ;; Check for abbreviated long option.
670 (or elt
671 (error "Option `%s' is ambiguous" argi))
672 (setq argi (cdr elt)))
673 ;; Check for a short option.
674 (setq argval nil
675 argi orig-argi))))
676 (cond ((member argi '("-fg" "-foreground"))
677 (push (cons 'foreground-color (or argval (pop args)))
678 default-frame-alist))
679 ((member argi '("-bg" "-background"))
680 (push (cons 'background-color (or argval (pop args)))
681 default-frame-alist))
682 ((member argi '("-T" "-name"))
683 (unless argval (setq argval (pop args)))
684 (push (cons 'title
685 (if (stringp argval)
686 argval
687 (let ((case-fold-search t)
689 (setq argval (invocation-name))
691 ;; Change any . or * characters in name to
692 ;; hyphens, so as to emulate behavior on X.
693 (while
694 (setq i (string-match "[.*]" argval))
695 (aset argval i ?-))
696 argval)))
697 default-frame-alist))
698 ((member argi '("-r" "-rv" "-reverse"))
699 (push '(reverse . t)
700 default-frame-alist))
701 ((equal argi "-color")
702 (unless argval (setq argval 8)) ; default --color means 8 ANSI colors
703 (push (cons 'tty-color-mode
704 (cond
705 ((numberp argval) argval)
706 ((string-match "-?[0-9]+" argval)
707 (string-to-number argval))
708 (t (intern argval))))
709 default-frame-alist))
711 (push argi rest)))))
712 (nreverse rest)))
714 (declare-function x-get-resource "frame.c"
715 (attribute class &optional component subclass))
716 (declare-function tool-bar-mode "tool-bar" (&optional arg))
717 (declare-function tool-bar-setup "tool-bar")
719 (defvar server-name)
720 (defvar server-process)
722 (defun command-line ()
723 "A subroutine of `normal-top-level'.
724 Amongst another things, it parses the command-line arguments."
725 (setq before-init-time (current-time)
726 after-init-time nil
727 command-line-default-directory default-directory)
729 ;; Force recomputation, in case it was computed during the dump.
730 (setq abbreviated-home-dir nil)
732 ;; See if we should import version-control from the environment variable.
733 (let ((vc (getenv "VERSION_CONTROL")))
734 (cond ((eq vc nil)) ;don't do anything if not set
735 ((member vc '("t" "numbered"))
736 (setq version-control t))
737 ((member vc '("nil" "existing"))
738 (setq version-control nil))
739 ((member vc '("never" "simple"))
740 (setq version-control 'never))))
742 ;;! This has been commented out; I currently find the behavior when
743 ;;! split-window-keep-point is nil disturbing, but if I can get used
744 ;;! to it, then it would be better to eliminate the option.
745 ;;! ;; Choose a good default value for split-window-keep-point.
746 ;;! (setq split-window-keep-point (> baud-rate 2400))
748 ;; Set the default strings to display in mode line for
749 ;; end-of-line formats that aren't native to this platform.
750 (cond
751 ((memq system-type '(ms-dos windows-nt))
752 (setq eol-mnemonic-unix "(Unix)"
753 eol-mnemonic-mac "(Mac)"))
754 (t ; this is for Unix/GNU/Linux systems
755 (setq eol-mnemonic-dos "(DOS)"
756 eol-mnemonic-mac "(Mac)")))
758 (set-locale-environment nil)
760 ;; Convert preloaded file names in load-history to absolute.
761 (let ((simple-file-name
762 ;; Look for simple.el or simple.elc and use their directory
763 ;; as the place where all Lisp files live.
764 (locate-file "simple" load-path (get-load-suffixes)))
765 lisp-dir)
766 ;; Don't abort if simple.el cannot be found, but print a warning.
767 (if (null simple-file-name)
768 (progn
769 (princ "Warning: Could not find simple.el nor simple.elc"
770 'external-debugging-output)
771 (terpri 'external-debugging-output))
772 (setq lisp-dir (file-truename (file-name-directory simple-file-name)))
773 (setq load-history
774 (mapcar (lambda (elt)
775 (if (and (stringp (car elt))
776 (not (file-name-absolute-p (car elt))))
777 (cons (concat lisp-dir
778 (car elt))
779 (cdr elt))
780 elt))
781 load-history))))
783 ;; Convert the arguments to Emacs internal representation.
784 (let ((args (cdr command-line-args)))
785 (while args
786 (setcar args
787 (decode-coding-string (car args) locale-coding-system t))
788 (pop args)))
790 (let ((done nil)
791 (args (cdr command-line-args))
792 display-arg)
794 ;; Figure out which user's init file to load,
795 ;; either from the environment or from the options.
796 (setq init-file-user (if noninteractive nil (user-login-name)))
797 ;; If user has not done su, use current $HOME to find .emacs.
798 (and init-file-user
799 (equal init-file-user (user-real-login-name))
800 (setq init-file-user ""))
802 ;; Process the command-line args, and delete the arguments
803 ;; processed. This is consistent with the way main in emacs.c
804 ;; does things.
805 (while (and (not done) args)
806 (let* ((longopts '(("--no-init-file") ("--no-site-file") ("--debug-init")
807 ("--user") ("--iconic") ("--icon-type") ("--quick")
808 ("--no-blinking-cursor") ("--basic-display")))
809 (argi (pop args))
810 (orig-argi argi)
811 argval)
812 ;; Handle --OPTION=VALUE format.
813 (when (string-match "\\`\\(--[^=]*\\)=" argi)
814 (setq argval (substring argi (match-end 0))
815 argi (match-string 1 argi)))
816 (when (string-match "\\`--." orig-argi)
817 (let ((completion (try-completion argi longopts)))
818 (cond ((eq completion t)
819 (setq argi (substring argi 1)))
820 ((stringp completion)
821 (let ((elt (assoc completion longopts)))
822 (unless elt
823 (error "Option `%s' is ambiguous" argi))
824 (setq argi (substring (car elt) 1))))
826 (setq argval nil
827 argi orig-argi)))))
828 (cond
829 ;; The --display arg is handled partly in C, partly in Lisp.
830 ;; When it shows up here, we just put it back to be handled
831 ;; by `command-line-1'.
832 ((member argi '("-d" "-display"))
833 (setq display-arg (list argi (pop args))))
834 ((member argi '("-Q" "-quick"))
835 (setq init-file-user nil
836 site-run-file nil
837 inhibit-x-resources t))
838 ((member argi '("-D" "-basic-display"))
839 (setq no-blinking-cursor t
840 emacs-basic-display t)
841 (push '(vertical-scroll-bars . nil) initial-frame-alist))
842 ((member argi '("-q" "-no-init-file"))
843 (setq init-file-user nil))
844 ((member argi '("-u" "-user"))
845 (setq init-file-user (or argval (pop args))
846 argval nil))
847 ((equal argi "-no-site-file")
848 (setq site-run-file nil))
849 ((equal argi "-debug-init")
850 (setq init-file-debug t))
851 ((equal argi "-iconic")
852 (push '(visibility . icon) initial-frame-alist))
853 ((member argi '("-nbc" "-no-blinking-cursor"))
854 (setq no-blinking-cursor t))
855 ;; Push the popped arg back on the list of arguments.
857 (push argi args)
858 (setq done t)))
859 ;; Was argval set but not used?
860 (and argval
861 (error "Option `%s' doesn't allow an argument" argi))))
863 ;; Re-attach the --display arg.
864 (and display-arg (setq args (append display-arg args)))
866 ;; Re-attach the program name to the front of the arg list.
867 (and command-line-args
868 (setcdr command-line-args args)))
870 ;; Make sure window system's init file was loaded in loadup.el if
871 ;; using a window system.
872 ;; Initialize the window-system only after processing the command-line
873 ;; args so that -Q can influence this initialization.
874 (condition-case error
875 (unless noninteractive
876 (if (and initial-window-system
877 (not (featurep
878 (intern
879 (concat (symbol-name initial-window-system) "-win")))))
880 (error "Unsupported window system `%s'" initial-window-system))
881 ;; Process window-system specific command line parameters.
882 (setq command-line-args
883 (funcall
884 (or (cdr (assq initial-window-system handle-args-function-alist))
885 (error "Unsupported window system `%s'" initial-window-system))
886 command-line-args))
887 ;; Initialize the window system. (Open connection, etc.)
888 (funcall
889 (or (cdr (assq initial-window-system window-system-initialization-alist))
890 (error "Unsupported window system `%s'" initial-window-system))))
891 ;; If there was an error, print the error message and exit.
892 (error
893 (princ
894 (if (eq (car error) 'error)
895 (apply 'concat (cdr error))
896 (if (memq 'file-error (get (car error) 'error-conditions))
897 (format "%s: %s"
898 (nth 1 error)
899 (mapconcat (lambda (obj) (prin1-to-string obj t))
900 (cdr (cdr error)) ", "))
901 (format "%s: %s"
902 (get (car error) 'error-message)
903 (mapconcat (lambda (obj) (prin1-to-string obj t))
904 (cdr error) ", "))))
905 'external-debugging-output)
906 (terpri 'external-debugging-output)
907 (setq initial-window-system nil)
908 (kill-emacs)))
910 (run-hooks 'before-init-hook)
912 ;; Under X, create the X frame and delete the terminal frame.
913 (unless (daemonp)
914 (if (or noninteractive emacs-basic-display)
915 (setq menu-bar-mode nil
916 tool-bar-mode nil
917 no-blinking-cursor t))
918 (frame-initialize))
920 (when (fboundp 'x-create-frame)
921 ;; Set up the tool-bar (even in tty frames, since Emacs might open a
922 ;; graphical frame later).
923 (unless noninteractive
924 (tool-bar-setup)))
926 ;; Turn off blinking cursor if so specified in X resources. This is here
927 ;; only because all other settings of no-blinking-cursor are here.
928 (unless (or noninteractive
929 emacs-basic-display
930 (and (memq window-system '(x w32 ns))
931 (not (member (x-get-resource "cursorBlink" "CursorBlink")
932 '("no" "off" "false" "0")))))
933 (setq no-blinking-cursor t))
935 ;; Re-evaluate predefined variables whose initial value depends on
936 ;; the runtime context.
937 (mapc 'custom-reevaluate-setting
938 ;; Initialize them in the same order they were loaded, in case there
939 ;; are dependencies between them.
940 (prog1 (nreverse custom-delayed-init-variables)
941 (setq custom-delayed-init-variables nil)))
943 (normal-erase-is-backspace-setup-frame)
945 ;; Register default TTY colors for the case the terminal hasn't a
946 ;; terminal init file. We do this regardless of whether the terminal
947 ;; supports colors or not and regardless the current display type,
948 ;; since users can connect to color-capable terminals and also
949 ;; switch color support on or off in mid-session by setting the
950 ;; tty-color-mode frame parameter.
951 ;; Exception: the `pc' ``window system'' has only 16 fixed colors,
952 ;; and they are already set at this point by a suitable function in
953 ;; window-system-initialization-alist.
954 (or (eq initial-window-system 'pc)
955 (tty-register-default-colors))
957 ;; Record whether the tool-bar is present before the user and site
958 ;; init files are processed. frame-notice-user-settings uses this
959 ;; to determine if the tool-bar has been disabled by the init files,
960 ;; and the frame needs to be resized.
961 (when (fboundp 'frame-notice-user-settings)
962 (let ((tool-bar-lines (or (assq 'tool-bar-lines initial-frame-alist)
963 (assq 'tool-bar-lines default-frame-alist))))
964 (setq tool-bar-originally-present
965 (and tool-bar-lines
966 (cdr tool-bar-lines)
967 (not (eq 0 (cdr tool-bar-lines)))))))
969 (let ((old-scalable-fonts-allowed scalable-fonts-allowed)
970 (old-font-list-limit font-list-limit)
971 (old-face-ignored-fonts face-ignored-fonts))
973 ;; Run the site-start library if it exists. The point of this file is
974 ;; that it is run before .emacs. There is no point in doing this after
975 ;; .emacs; that is useless.
976 ;; Note that user-init-file is nil at this point. Code that might
977 ;; be loaded from site-run-file and wants to test if -q was given
978 ;; should check init-file-user instead, since that is already set.
979 ;; See cus-edit.el for an example.
980 (if site-run-file
981 (load site-run-file t t))
983 ;; Sites should not disable this. Only individuals should disable
984 ;; the startup screen.
985 (setq inhibit-startup-screen nil)
987 ;; Warn for invalid user name.
988 (when init-file-user
989 (if (string-match "[~/:\n]" init-file-user)
990 (display-warning 'initialization
991 (format "Invalid user name %s"
992 init-file-user)
993 :error)
994 (if (file-directory-p (expand-file-name
995 ;; We don't support ~USER on MS-Windows
996 ;; and MS-DOS except for the current
997 ;; user, and always load .emacs from
998 ;; the current user's home directory
999 ;; (see below). So always check "~",
1000 ;; even if invoked with "-u USER", or
1001 ;; if $USER or $LOGNAME are set to
1002 ;; something different.
1003 (if (memq system-type '(windows-nt ms-dos))
1005 (concat "~" init-file-user))))
1007 (display-warning 'initialization
1008 (format "User %s has no home directory"
1009 (if (equal init-file-user "")
1010 (user-real-login-name)
1011 init-file-user))
1012 :error))))
1014 ;; Load that user's init file, or the default one, or none.
1015 (let (debug-on-error-from-init-file
1016 debug-on-error-should-be-set
1017 (debug-on-error-initial
1018 (if (eq init-file-debug t) 'startup init-file-debug))
1019 (orig-enable-multibyte (default-value 'enable-multibyte-characters)))
1020 (let ((debug-on-error debug-on-error-initial)
1021 ;; This function actually reads the init files.
1022 (inner
1023 (function
1024 (lambda ()
1025 (if init-file-user
1026 (let ((user-init-file-1
1027 (cond
1028 ((eq system-type 'ms-dos)
1029 (concat "~" init-file-user "/_emacs"))
1030 ((not (eq system-type 'windows-nt))
1031 (concat "~" init-file-user "/.emacs"))
1032 ;; Else deal with the Windows situation
1033 ((directory-files "~" nil "^\\.emacs\\(\\.elc?\\)?$")
1034 ;; Prefer .emacs on Windows.
1035 "~/.emacs")
1036 ((directory-files "~" nil "^_emacs\\(\\.elc?\\)?$")
1037 ;; Also support _emacs for compatibility, but warn about it.
1038 (push '(initialization
1039 "`_emacs' init file is deprecated, please use `.emacs'")
1040 delayed-warnings-list)
1041 "~/_emacs")
1042 (t ;; But default to .emacs if _emacs does not exist.
1043 "~/.emacs"))))
1044 ;; This tells `load' to store the file name found
1045 ;; into user-init-file.
1046 (setq user-init-file t)
1047 (load user-init-file-1 t t)
1049 (when (eq user-init-file t)
1050 ;; If we did not find ~/.emacs, try
1051 ;; ~/.emacs.d/init.el.
1052 (let ((otherfile
1053 (expand-file-name
1054 "init"
1055 (file-name-as-directory
1056 (concat "~" init-file-user "/.emacs.d")))))
1057 (load otherfile t t)
1059 ;; If we did not find the user's init file,
1060 ;; set user-init-file conclusively.
1061 ;; Don't let it be set from default.el.
1062 (when (eq user-init-file t)
1063 (setq user-init-file user-init-file-1))))
1065 ;; If we loaded a compiled file, set
1066 ;; `user-init-file' to the source version if that
1067 ;; exists.
1068 (when (and user-init-file
1069 (equal (file-name-extension user-init-file)
1070 "elc"))
1071 (let* ((source (file-name-sans-extension user-init-file))
1072 (alt (concat source ".el")))
1073 (setq source (cond ((file-exists-p alt) alt)
1074 ((file-exists-p source) source)
1075 (t nil)))
1076 (when source
1077 (when (file-newer-than-file-p source user-init-file)
1078 (message "Warning: %s is newer than %s"
1079 source user-init-file)
1080 (sit-for 1))
1081 (setq user-init-file source))))
1083 (unless inhibit-default-init
1084 (let ((inhibit-startup-screen nil))
1085 ;; Users are supposed to be told their rights.
1086 ;; (Plus how to get help and how to undo.)
1087 ;; Don't you dare turn this off for anyone
1088 ;; except yourself.
1089 (load "default" t t)))))))))
1090 (if init-file-debug
1091 ;; Do this without a condition-case if the user wants to debug.
1092 (funcall inner)
1093 (condition-case error
1094 (progn
1095 (funcall inner)
1096 (setq init-file-had-error nil))
1097 (error
1098 (display-warning
1099 'initialization
1100 (format "An error occurred while loading `%s':\n\n%s%s%s\n\n\
1101 To ensure normal operation, you should investigate and remove the
1102 cause of the error in your initialization file. Start Emacs with
1103 the `--debug-init' option to view a complete error backtrace."
1104 user-init-file
1105 (get (car error) 'error-message)
1106 (if (cdr error) ": " "")
1107 (mapconcat (lambda (s) (prin1-to-string s t))
1108 (cdr error) ", "))
1109 :warning)
1110 (setq init-file-had-error t))))
1112 (if (and deactivate-mark transient-mark-mode)
1113 (with-current-buffer (window-buffer)
1114 (deactivate-mark)))
1116 ;; If the user has a file of abbrevs, read it (unless -batch).
1117 (when (and (not noninteractive)
1118 (file-exists-p abbrev-file-name)
1119 (file-readable-p abbrev-file-name))
1120 (quietly-read-abbrev-file abbrev-file-name))
1122 ;; If the abbrevs came entirely from the init file or the
1123 ;; abbrevs file, they do not need saving.
1124 (setq abbrevs-changed nil)
1126 ;; If we can tell that the init file altered debug-on-error,
1127 ;; arrange to preserve the value that it set up.
1128 (or (eq debug-on-error debug-on-error-initial)
1129 (setq debug-on-error-should-be-set t
1130 debug-on-error-from-init-file debug-on-error)))
1131 (if debug-on-error-should-be-set
1132 (setq debug-on-error debug-on-error-from-init-file))
1133 (unless (or (default-value 'enable-multibyte-characters)
1134 (eq orig-enable-multibyte (default-value
1135 'enable-multibyte-characters)))
1136 ;; Init file changed to unibyte. Reset existing multibyte
1137 ;; buffers (probably *scratch*, *Messages*, *Minibuf-0*).
1138 ;; Arguably this should only be done if they're free of
1139 ;; multibyte characters.
1140 (mapc (lambda (buffer)
1141 (with-current-buffer buffer
1142 (if enable-multibyte-characters
1143 (set-buffer-multibyte nil))))
1144 (buffer-list))
1145 ;; Also re-set the language environment in case it was
1146 ;; originally done before unibyte was set and is sensitive to
1147 ;; unibyte (display table, terminal coding system &c).
1148 (set-language-environment current-language-environment)))
1150 ;; Do this here in case the init file sets mail-host-address.
1151 (if (equal user-mail-address "")
1152 (setq user-mail-address (or (getenv "EMAIL")
1153 (concat (user-login-name) "@"
1154 (or mail-host-address
1155 (system-name))))))
1157 ;; If parameter have been changed in the init file which influence
1158 ;; face realization, clear the face cache so that new faces will
1159 ;; be realized.
1160 (unless (and (eq scalable-fonts-allowed old-scalable-fonts-allowed)
1161 (eq font-list-limit old-font-list-limit)
1162 (eq face-ignored-fonts old-face-ignored-fonts))
1163 (clear-face-cache)))
1165 ;; If any package directory exists, initialize the package system.
1166 (and user-init-file
1167 package-enable-at-startup
1168 (catch 'package-dir-found
1169 (let (dirs)
1170 (if (boundp 'package-directory-list)
1171 (setq dirs package-directory-list)
1172 (dolist (f load-path)
1173 (and (stringp f)
1174 (equal (file-name-nondirectory f) "site-lisp")
1175 (push (expand-file-name "elpa" f) dirs))))
1176 (push (if (boundp 'package-user-dir)
1177 package-user-dir
1178 (locate-user-emacs-file "elpa"))
1179 dirs)
1180 (dolist (dir dirs)
1181 (when (file-directory-p dir)
1182 (dolist (subdir (directory-files dir))
1183 (when (and (file-directory-p (expand-file-name subdir dir))
1184 (string-match
1185 (concat "\\`" package-subdirectory-regexp "\\'")
1186 subdir))
1187 (throw 'package-dir-found t)))))))
1188 (package-initialize))
1190 (setq after-init-time (current-time))
1191 (run-hooks 'after-init-hook)
1193 ;; Decode all default-directory.
1194 (if (and (default-value 'enable-multibyte-characters) locale-coding-system)
1195 (save-excursion
1196 (dolist (elt (buffer-list))
1197 (set-buffer elt)
1198 (if default-directory
1199 (setq default-directory
1200 (decode-coding-string default-directory
1201 locale-coding-system t))))
1202 (setq command-line-default-directory
1203 (decode-coding-string command-line-default-directory
1204 locale-coding-system t))))
1206 ;; If *scratch* exists and init file didn't change its mode, initialize it.
1207 (if (get-buffer "*scratch*")
1208 (with-current-buffer "*scratch*"
1209 (if (eq major-mode 'fundamental-mode)
1210 (funcall initial-major-mode))))
1212 ;; Load library for our terminal type.
1213 ;; User init file can set term-file-prefix to nil to prevent this.
1214 (unless (or noninteractive
1215 initial-window-system)
1216 (tty-run-terminal-initialization (selected-frame)))
1218 ;; Update the out-of-memory error message based on user's key bindings
1219 ;; for save-some-buffers.
1220 (setq memory-signal-data
1221 (list 'error
1222 (substitute-command-keys "Memory exhausted--use \\[save-some-buffers] then exit and restart Emacs")))
1224 ;; Process the remaining args.
1225 (command-line-1 (cdr command-line-args))
1227 ;; If -batch, terminate after processing the command options.
1228 (if noninteractive (kill-emacs t))
1230 ;; In daemon mode, start the server to allow clients to connect.
1231 ;; This is done after loading the user's init file and after
1232 ;; processing all command line arguments to allow e.g. `server-name'
1233 ;; to be changed before the server starts.
1234 (let ((dn (daemonp)))
1235 (when dn
1236 (when (stringp dn) (setq server-name dn))
1237 (server-start)
1238 (if server-process
1239 (daemon-initialized)
1240 (if (stringp dn)
1241 (message
1242 "Unable to start daemon: Emacs server named %S already running"
1243 server-name)
1244 (message "Unable to start the daemon.\nAnother instance of Emacs is running the server, either as daemon or interactively.\nYou can use emacsclient to connect to that Emacs process."))
1245 (kill-emacs 1))))
1247 ;; Run emacs-session-restore (session management) if started by
1248 ;; the session manager and we have a session manager connection.
1249 (if (and (boundp 'x-session-previous-id)
1250 (stringp x-session-previous-id))
1251 (with-no-warnings
1252 (emacs-session-restore x-session-previous-id))))
1254 (defun x-apply-session-resources ()
1255 "Apply X resources which specify initial values for Emacs variables.
1256 This is called from a window-system initialization function, such
1257 as `x-initialize-window-system' for X, either at startup (prior
1258 to reading the init file), or afterwards when the user first
1259 opens a graphical frame.
1261 This can set the values of `menu-bar-mode', `tool-bar-mode', and
1262 `no-blinking-cursor', as well as the `cursor' face. Changed
1263 settings will be marked as \"CHANGED outside of Customize\"."
1264 (let ((no-vals '("no" "off" "false" "0"))
1265 (settings '(("menuBar" "MenuBar" menu-bar-mode nil)
1266 ("toolBar" "ToolBar" tool-bar-mode nil)
1267 ("cursorBlink" "CursorBlink" no-blinking-cursor t))))
1268 (dolist (x settings)
1269 (if (member (x-get-resource (nth 0 x) (nth 1 x)) no-vals)
1270 (set (nth 2 x) (nth 3 x)))))
1271 (let ((color (x-get-resource "cursorColor" "Foreground")))
1272 (when color
1273 (put 'cursor 'theme-face
1274 `((changed ((t :background ,color)))))
1275 (put 'cursor 'face-modified t))))
1277 (defcustom initial-scratch-message (purecopy "\
1278 ;; This buffer is for notes you don't want to save, and for Lisp evaluation.
1279 ;; If you want to create a file, visit that file with C-x C-f,
1280 ;; then enter the text in that file's own buffer.
1283 "Initial message displayed in *scratch* buffer at startup.
1284 If this is nil, no message will be displayed."
1285 :type '(choice (text :tag "Message")
1286 (const :tag "none" nil))
1287 :group 'initialization)
1290 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1291 ;;; Fancy splash screen
1292 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1294 (defconst fancy-startup-text
1295 `((:face (variable-pitch font-lock-comment-face)
1296 "Welcome to "
1297 :link ("GNU Emacs"
1298 ,(lambda (_button) (browse-url "http://www.gnu.org/software/emacs/"))
1299 "Browse http://www.gnu.org/software/emacs/")
1300 ", one component of the "
1301 :link
1302 ,(lambda ()
1303 (if (eq system-type 'gnu/linux)
1304 `("GNU/Linux"
1305 ,(lambda (_button) (browse-url "http://www.gnu.org/gnu/linux-and-gnu.html"))
1306 "Browse http://www.gnu.org/gnu/linux-and-gnu.html")
1307 `("GNU" ,(lambda (_button) (describe-gnu-project))
1308 "Display info on the GNU project")))
1309 " operating system.\n\n"
1310 :face variable-pitch
1311 :link ("Emacs Tutorial" ,(lambda (_button) (help-with-tutorial)))
1312 "\tLearn basic keystroke commands"
1313 ,(lambda ()
1314 (let* ((en "TUTORIAL")
1315 (tut (or (get-language-info current-language-environment
1316 'tutorial)
1317 en))
1318 (title (with-temp-buffer
1319 (insert-file-contents
1320 (expand-file-name tut tutorial-directory)
1321 ;; We used to read only the first 256 bytes of
1322 ;; the tutorial, but that prevents the coding:
1323 ;; setting, if any, in file-local variables
1324 ;; section to be seen by insert-file-contents,
1325 ;; and results in gibberish when the language
1326 ;; environment's preferred encoding is
1327 ;; different from what the file-local variable
1328 ;; says. One case in point is Hebrew.
1329 nil)
1330 (search-forward ".")
1331 (buffer-substring (point-min) (1- (point))))))
1332 ;; If there is a specific tutorial for the current language
1333 ;; environment and it is not English, append its title.
1334 (if (string= en tut)
1336 (concat " (" title ")"))))
1337 "\n"
1338 :link ("Emacs Guided Tour"
1339 ,(lambda (_button)
1340 (browse-url "http://www.gnu.org/software/emacs/tour/"))
1341 "Browse http://www.gnu.org/software/emacs/tour/")
1342 "\tOverview of Emacs features at gnu.org\n"
1343 :link ("View Emacs Manual" ,(lambda (_button) (info-emacs-manual)))
1344 "\tView the Emacs manual using Info\n"
1345 :link ("Absence of Warranty" ,(lambda (_button) (describe-no-warranty)))
1346 "\tGNU Emacs comes with "
1347 :face (variable-pitch (:slant oblique))
1348 "ABSOLUTELY NO WARRANTY\n"
1349 :face variable-pitch
1350 :link ("Copying Conditions" ,(lambda (_button) (describe-copying)))
1351 "\tConditions for redistributing and changing Emacs\n"
1352 :link ("Ordering Manuals" ,(lambda (_button) (view-order-manuals)))
1353 "\tPurchasing printed copies of manuals\n"
1354 "\n"))
1355 "A list of texts to show in the middle part of splash screens.
1356 Each element in the list should be a list of strings or pairs
1357 `:face FACE', like `fancy-splash-insert' accepts them.")
1359 (defconst fancy-about-text
1360 `((:face (variable-pitch font-lock-comment-face)
1361 "This is "
1362 :link ("GNU Emacs"
1363 ,(lambda (_button) (browse-url "http://www.gnu.org/software/emacs/"))
1364 "Browse http://www.gnu.org/software/emacs/")
1365 ", one component of the "
1366 :link
1367 ,(lambda ()
1368 (if (eq system-type 'gnu/linux)
1369 `("GNU/Linux"
1370 ,(lambda (_button)
1371 (browse-url "http://www.gnu.org/gnu/linux-and-gnu.html"))
1372 "Browse http://www.gnu.org/gnu/linux-and-gnu.html")
1373 `("GNU" ,(lambda (_button) (describe-gnu-project))
1374 "Display info on the GNU project.")))
1375 " operating system.\n"
1376 :face (variable-pitch font-lock-builtin-face)
1377 "\n"
1378 ,(lambda () (emacs-version))
1379 "\n"
1380 :face (variable-pitch (:height 0.8))
1381 ,(lambda () emacs-copyright)
1382 "\n\n"
1383 :face variable-pitch
1384 :link ("Authors"
1385 ,(lambda (_button)
1386 (view-file (expand-file-name "AUTHORS" data-directory))
1387 (goto-char (point-min))))
1388 "\tMany people have contributed code included in GNU Emacs\n"
1389 :link ("Contributing"
1390 ,(lambda (_button)
1391 (view-file (expand-file-name "CONTRIBUTE" data-directory))
1392 (goto-char (point-min))))
1393 "\tHow to contribute improvements to Emacs\n"
1394 "\n"
1395 :link ("GNU and Freedom" ,(lambda (_button) (describe-gnu-project)))
1396 "\tWhy we developed GNU Emacs, and the GNU operating system\n"
1397 :link ("Absence of Warranty" ,(lambda (_button) (describe-no-warranty)))
1398 "\tGNU Emacs comes with "
1399 :face (variable-pitch (:slant oblique))
1400 "ABSOLUTELY NO WARRANTY\n"
1401 :face variable-pitch
1402 :link ("Copying Conditions" ,(lambda (_button) (describe-copying)))
1403 "\tConditions for redistributing and changing Emacs\n"
1404 :link ("Getting New Versions" ,(lambda (_button) (describe-distribution)))
1405 "\tHow to obtain the latest version of Emacs\n"
1406 :link ("Ordering Manuals" ,(lambda (_button) (view-order-manuals)))
1407 "\tBuying printed manuals from the FSF\n"
1408 "\n"
1409 :link ("Emacs Tutorial" ,(lambda (_button) (help-with-tutorial)))
1410 "\tLearn basic Emacs keystroke commands"
1411 ,(lambda ()
1412 (let* ((en "TUTORIAL")
1413 (tut (or (get-language-info current-language-environment
1414 'tutorial)
1415 en))
1416 (title (with-temp-buffer
1417 (insert-file-contents
1418 (expand-file-name tut tutorial-directory)
1419 nil 0 256)
1420 (search-forward ".")
1421 (buffer-substring (point-min) (1- (point))))))
1422 ;; If there is a specific tutorial for the current language
1423 ;; environment and it is not English, append its title.
1424 (if (string= en tut)
1426 (concat " (" title ")"))))
1427 "\n"
1428 :link ("Emacs Guided Tour"
1429 ,(lambda (_button)
1430 (browse-url "http://www.gnu.org/software/emacs/tour/"))
1431 "Browse http://www.gnu.org/software/emacs/tour/")
1432 "\tSee an overview of Emacs features at gnu.org"))
1433 "A list of texts to show in the middle part of the About screen.
1434 Each element in the list should be a list of strings or pairs
1435 `:face FACE', like `fancy-splash-insert' accepts them.")
1438 (defgroup fancy-splash-screen ()
1439 "Fancy splash screen when Emacs starts."
1440 :version "21.1"
1441 :group 'initialization)
1443 (defcustom fancy-splash-image nil
1444 "The image to show in the splash screens, or nil for defaults."
1445 :group 'fancy-splash-screen
1446 :type '(choice (const :tag "Default" nil)
1447 (file :tag "File")))
1450 (defvar splash-screen-keymap
1451 (let ((map (make-sparse-keymap)))
1452 (suppress-keymap map)
1453 (set-keymap-parent map button-buffer-map)
1454 (define-key map "\C-?" 'scroll-down-command)
1455 (define-key map " " 'scroll-up-command)
1456 (define-key map "q" 'exit-splash-screen)
1457 map)
1458 "Keymap for splash screen buffer.")
1460 ;; These are temporary storage areas for the splash screen display.
1462 (defun fancy-splash-insert (&rest args)
1463 "Insert text into the current buffer, with faces.
1464 Arguments from ARGS should be either strings; functions called
1465 with no args that return a string; pairs `:face FACE', where FACE
1466 is a face specification usable with `put-text-property'; or pairs
1467 `:link LINK' where LINK is a list of arguments to pass to
1468 `insert-button', of the form (LABEL ACTION [HELP-ECHO]), which
1469 specifies the button's label, `action' property and help-echo string.
1470 FACE and LINK can also be functions, which are evaluated to obtain
1471 a face or button specification."
1472 (let ((current-face nil))
1473 (while args
1474 (cond ((eq (car args) :face)
1475 (setq args (cdr args) current-face (car args))
1476 (if (functionp current-face)
1477 (setq current-face (funcall current-face))))
1478 ((eq (car args) :link)
1479 (setq args (cdr args))
1480 (let ((spec (car args)))
1481 (if (functionp spec)
1482 (setq spec (funcall spec)))
1483 (insert-button (car spec)
1484 'face (list 'link current-face)
1485 'action (cadr spec)
1486 'help-echo (concat "mouse-2, RET: "
1487 (or (nth 2 spec)
1488 "Follow this link"))
1489 'follow-link t)))
1490 (t (insert (propertize (let ((it (car args)))
1491 (if (functionp it)
1492 (funcall it)
1493 it))
1494 'face current-face
1495 'help-echo (startup-echo-area-message)))))
1496 (setq args (cdr args)))))
1498 (declare-function image-size "image.c" (spec &optional pixels frame))
1500 (defun fancy-splash-head ()
1501 "Insert the head part of the splash screen into the current buffer."
1502 (let* ((image-file (cond ((stringp fancy-splash-image)
1503 fancy-splash-image)
1504 ((display-color-p)
1505 (cond ((<= (display-planes) 8)
1506 (if (image-type-available-p 'xpm)
1507 "splash.xpm"
1508 "splash.pbm"))
1509 ((or (image-type-available-p 'svg)
1510 (image-type-available-p 'imagemagick))
1511 "splash.svg")
1512 ((image-type-available-p 'png)
1513 "splash.png")
1514 ((image-type-available-p 'xpm)
1515 "splash.xpm")
1516 (t "splash.pbm")))
1517 (t "splash.pbm")))
1518 (img (create-image image-file))
1519 (image-width (and img (car (image-size img))))
1520 (window-width (window-width (selected-window))))
1521 (when img
1522 (when (> window-width image-width)
1523 ;; Center the image in the window.
1524 (insert (propertize " " 'display
1525 `(space :align-to (+ center (-0.5 . ,img)))))
1527 ;; Change the color of the XPM version of the splash image
1528 ;; so that it is visible with a dark frame background.
1529 (when (and (memq 'xpm img)
1530 (eq (frame-parameter nil 'background-mode) 'dark))
1531 (setq img (append img '(:color-symbols (("#000000" . "gray30"))))))
1533 ;; Insert the image with a help-echo and a link.
1534 (make-button (prog1 (point) (insert-image img)) (point)
1535 'face 'default
1536 'help-echo "mouse-2, RET: Browse http://www.gnu.org/"
1537 'action (lambda (_button) (browse-url "http://www.gnu.org/"))
1538 'follow-link t)
1539 (insert "\n\n")))))
1541 (defun fancy-startup-tail (&optional concise)
1542 "Insert the tail part of the splash screen into the current buffer."
1543 (unless concise
1544 (fancy-splash-insert
1545 :face 'variable-pitch
1546 "\nTo start... "
1547 :link `("Open a File"
1548 ,(lambda (_button) (call-interactively 'find-file))
1549 "Specify a new file's name, to edit the file")
1551 :link `("Open Home Directory"
1552 ,(lambda (_button) (dired "~"))
1553 "Open your home directory, to operate on its files")
1555 :link `("Customize Startup"
1556 ,(lambda (_button) (customize-group 'initialization))
1557 "Change initialization settings including this screen")
1558 "\n"))
1559 (fancy-splash-insert
1560 :face 'variable-pitch "To quit a partially entered command, type "
1561 :face 'default "Control-g"
1562 :face 'variable-pitch ".\n")
1563 (fancy-splash-insert :face `(variable-pitch font-lock-builtin-face)
1564 "\nThis is "
1565 (emacs-version)
1566 "\n"
1567 :face '(variable-pitch (:height 0.8))
1568 emacs-copyright
1569 "\n")
1570 (and auto-save-list-file-prefix
1571 ;; Don't signal an error if the
1572 ;; directory for auto-save-list files
1573 ;; does not yet exist.
1574 (file-directory-p (file-name-directory
1575 auto-save-list-file-prefix))
1576 (directory-files
1577 (file-name-directory auto-save-list-file-prefix)
1579 (concat "\\`"
1580 (regexp-quote (file-name-nondirectory
1581 auto-save-list-file-prefix)))
1583 (fancy-splash-insert :face '(variable-pitch font-lock-comment-face)
1584 "\nIf an Emacs session crashed recently, "
1585 "type "
1586 :face '(fixed-pitch font-lock-comment-face)
1587 "Meta-x recover-session RET"
1588 :face '(variable-pitch font-lock-comment-face)
1589 "\nto recover"
1590 " the files you were editing."))
1592 (when concise
1593 (fancy-splash-insert
1594 :face 'variable-pitch "\n"
1595 :link `("Dismiss this startup screen"
1596 ,(lambda (_button)
1597 (when startup-screen-inhibit-startup-screen
1598 (customize-set-variable 'inhibit-startup-screen t)
1599 (customize-mark-to-save 'inhibit-startup-screen)
1600 (custom-save-all))
1601 (let ((w (get-buffer-window "*GNU Emacs*")))
1602 (and w (not (one-window-p)) (delete-window w)))
1603 (kill-buffer "*GNU Emacs*")))
1604 " ")
1605 (when (or user-init-file custom-file)
1606 (let ((checked (create-image "checked.xpm"
1607 nil nil :ascent 'center))
1608 (unchecked (create-image "unchecked.xpm"
1609 nil nil :ascent 'center)))
1610 (insert-button
1612 :on-glyph checked
1613 :off-glyph unchecked
1614 'checked nil 'display unchecked 'follow-link t
1615 'action (lambda (button)
1616 (if (overlay-get button 'checked)
1617 (progn (overlay-put button 'checked nil)
1618 (overlay-put button 'display
1619 (overlay-get button :off-glyph))
1620 (setq startup-screen-inhibit-startup-screen
1621 nil))
1622 (overlay-put button 'checked t)
1623 (overlay-put button 'display
1624 (overlay-get button :on-glyph))
1625 (setq startup-screen-inhibit-startup-screen t)))))
1626 (fancy-splash-insert :face '(variable-pitch (:height 0.9))
1627 " Never show it again."))))
1629 (defun exit-splash-screen ()
1630 "Stop displaying the splash screen buffer."
1631 (interactive)
1632 (quit-window t))
1634 (defun fancy-startup-screen (&optional concise)
1635 "Display fancy startup screen.
1636 If CONCISE is non-nil, display a concise version of the
1637 splash screen in another window."
1638 (let ((splash-buffer (get-buffer-create "*GNU Emacs*")))
1639 (with-current-buffer splash-buffer
1640 (let ((inhibit-read-only t))
1641 (erase-buffer)
1642 (setq default-directory command-line-default-directory)
1643 (make-local-variable 'startup-screen-inhibit-startup-screen)
1644 (if pure-space-overflow
1645 (insert pure-space-overflow-message))
1646 (unless concise
1647 (fancy-splash-head))
1648 (dolist (text fancy-startup-text)
1649 (apply #'fancy-splash-insert text)
1650 (insert "\n"))
1651 (skip-chars-backward "\n")
1652 (delete-region (point) (point-max))
1653 (insert "\n")
1654 (fancy-startup-tail concise))
1655 (use-local-map splash-screen-keymap)
1656 (setq tab-width 22
1657 buffer-read-only t)
1658 (set-buffer-modified-p nil)
1659 (if (and view-read-only (not view-mode))
1660 (view-mode-enter nil 'kill-buffer))
1661 (goto-char (point-min))
1662 (forward-line (if concise 2 4)))
1663 (if concise
1664 (progn
1665 (display-buffer splash-buffer)
1666 ;; If the splash screen is in a split window, fit it.
1667 (let ((window (get-buffer-window splash-buffer t)))
1668 (or (null window)
1669 (eq window (selected-window))
1670 (eq window (next-window window))
1671 (fit-window-to-buffer window))))
1672 (switch-to-buffer splash-buffer))))
1674 (defun fancy-about-screen ()
1675 "Display fancy About screen."
1676 (let ((frame (fancy-splash-frame)))
1677 (save-selected-window
1678 (select-frame frame)
1679 (switch-to-buffer "*About GNU Emacs*")
1680 (setq buffer-undo-list t)
1681 (let ((inhibit-read-only t))
1682 (erase-buffer)
1683 (if pure-space-overflow
1684 (insert pure-space-overflow-message))
1685 (fancy-splash-head)
1686 (dolist (text fancy-about-text)
1687 (apply #'fancy-splash-insert text)
1688 (insert "\n"))
1689 (set-buffer-modified-p nil)
1690 (goto-char (point-min))
1691 (force-mode-line-update))
1692 (use-local-map splash-screen-keymap)
1693 (setq tab-width 22)
1694 (message "%s" (startup-echo-area-message))
1695 (setq buffer-read-only t)
1696 (goto-char (point-min))
1697 (forward-line 3))))
1699 (defun fancy-splash-frame ()
1700 "Return the frame to use for the fancy splash screen.
1701 Returning non-nil does not mean we should necessarily
1702 use the fancy splash screen, but if we do use it,
1703 we put it on this frame."
1704 (let (chosen-frame)
1705 (dolist (frame (append (frame-list) (list (selected-frame))))
1706 (if (and (frame-visible-p frame)
1707 (not (window-minibuffer-p (frame-selected-window frame))))
1708 (setq chosen-frame frame)))
1709 chosen-frame))
1711 (defun use-fancy-splash-screens-p ()
1712 "Return t if fancy splash screens should be used."
1713 (when (and (display-graphic-p)
1714 (or (and (display-color-p)
1715 (image-type-available-p 'xpm))
1716 (image-type-available-p 'pbm)))
1717 (let ((frame (fancy-splash-frame)))
1718 (when frame
1719 (let* ((img (create-image (or fancy-splash-image
1720 (if (and (display-color-p)
1721 (image-type-available-p 'xpm))
1722 "splash.xpm" "splash.pbm"))))
1723 (image-height (and img (cdr (image-size img nil frame))))
1724 ;; We test frame-height so that, if the frame is split
1725 ;; by displaying a warning, that doesn't cause the normal
1726 ;; splash screen to be used.
1727 (frame-height (1- (frame-height frame))))
1728 (> frame-height (+ image-height 19)))))))
1731 (defun normal-splash-screen (&optional startup concise)
1732 "Display non-graphic splash screen.
1733 If optional argument STARTUP is non-nil, display the startup screen
1734 after Emacs starts. If STARTUP is nil, display the About screen.
1735 If CONCISE is non-nil, display a concise version of the
1736 splash screen in another window."
1737 (let ((splash-buffer (get-buffer-create "*About GNU Emacs*")))
1738 (with-current-buffer splash-buffer
1739 (setq buffer-read-only nil)
1740 (erase-buffer)
1741 (setq default-directory command-line-default-directory)
1742 (set (make-local-variable 'tab-width) 8)
1744 (if pure-space-overflow
1745 (insert pure-space-overflow-message))
1747 ;; The convention for this piece of code is that
1748 ;; each piece of output starts with one or two newlines
1749 ;; and does not end with any newlines.
1750 (insert (if startup "Welcome to GNU Emacs" "This is GNU Emacs"))
1751 (insert
1752 (if (eq system-type 'gnu/linux)
1753 ", one component of the GNU/Linux operating system.\n"
1754 ", a part of the GNU operating system.\n"))
1756 (if startup
1757 (if (display-mouse-p)
1758 ;; The user can use the mouse to activate menus
1759 ;; so give help in terms of menu items.
1760 (normal-mouse-startup-screen)
1762 ;; No mouse menus, so give help using kbd commands.
1763 (normal-no-mouse-startup-screen))
1765 (normal-about-screen))
1767 ;; The rest of the startup screen is the same on all
1768 ;; kinds of terminals.
1770 ;; Give information on recovering, if there was a crash.
1771 (and startup
1772 auto-save-list-file-prefix
1773 ;; Don't signal an error if the
1774 ;; directory for auto-save-list files
1775 ;; does not yet exist.
1776 (file-directory-p (file-name-directory
1777 auto-save-list-file-prefix))
1778 (directory-files
1779 (file-name-directory auto-save-list-file-prefix)
1781 (concat "\\`"
1782 (regexp-quote (file-name-nondirectory
1783 auto-save-list-file-prefix)))
1785 (insert "\n\nIf an Emacs session crashed recently, "
1786 "type Meta-x recover-session RET\nto recover"
1787 " the files you were editing.\n"))
1789 (use-local-map splash-screen-keymap)
1791 ;; Display the input that we set up in the buffer.
1792 (set-buffer-modified-p nil)
1793 (setq buffer-read-only t)
1794 (if (and view-read-only (not view-mode))
1795 (view-mode-enter nil 'kill-buffer))
1796 (if startup (rename-buffer "*GNU Emacs*" t))
1797 (goto-char (point-min)))
1798 (if concise
1799 (display-buffer splash-buffer)
1800 (switch-to-buffer splash-buffer))))
1802 (defun normal-mouse-startup-screen ()
1803 ;; The user can use the mouse to activate menus
1804 ;; so give help in terms of menu items.
1805 (insert "\
1806 To follow a link, click Mouse-1 on it, or move to it and type RET.
1807 To quit a partially entered command, type Control-g.\n")
1809 (insert "\nImportant Help menu items:\n")
1810 (insert-button "Emacs Tutorial"
1811 'action (lambda (_button) (help-with-tutorial))
1812 'follow-link t)
1813 (insert "\t\tLearn basic Emacs keystroke commands\n")
1814 (insert-button "Read the Emacs Manual"
1815 'action (lambda (_button) (info-emacs-manual))
1816 'follow-link t)
1817 (insert "\tView the Emacs manual using Info\n")
1818 (insert-button "\(Non)Warranty"
1819 'action (lambda (_button) (describe-no-warranty))
1820 'follow-link t)
1821 (insert "\t\tGNU Emacs comes with ABSOLUTELY NO WARRANTY\n")
1822 (insert-button "Copying Conditions"
1823 'action (lambda (_button) (describe-copying))
1824 'follow-link t)
1825 (insert "\tConditions for redistributing and changing Emacs\n")
1826 (insert-button "More Manuals / Ordering Manuals"
1827 'action (lambda (_button) (view-order-manuals))
1828 'follow-link t)
1829 (insert " How to order printed manuals from the FSF\n")
1831 (insert "\nUseful tasks:\n")
1832 (insert-button "Visit New File"
1833 'action (lambda (_button) (call-interactively 'find-file))
1834 'follow-link t)
1835 (insert "\t\tSpecify a new file's name, to edit the file\n")
1836 (insert-button "Open Home Directory"
1837 'action (lambda (_button) (dired "~"))
1838 'follow-link t)
1839 (insert "\tOpen your home directory, to operate on its files\n")
1840 (insert-button "Customize Startup"
1841 'action (lambda (_button) (customize-group 'initialization))
1842 'follow-link t)
1843 (insert "\tChange initialization settings including this screen\n")
1845 (insert "\n" (emacs-version)
1846 "\n" emacs-copyright))
1848 ;; No mouse menus, so give help using kbd commands.
1849 (defun normal-no-mouse-startup-screen ()
1851 ;; If keys have their default meanings,
1852 ;; use precomputed string to save lots of time.
1853 (let* ((c-h-accessible
1854 ;; If normal-erase-is-backspace is used on a tty, there's
1855 ;; no way to invoke C-h and you have to use F1 instead.
1856 (or (not (char-table-p keyboard-translate-table))
1857 (eq (aref keyboard-translate-table ?\C-h) ?\C-h)))
1858 (minor-mode-overriding-map-alist
1859 (cons (cons (not c-h-accessible)
1860 ;; If C-h can't be invoked, temporarily disable its
1861 ;; binding, so where-is uses alternative bindings.
1862 (let ((map (make-sparse-keymap)))
1863 (define-key map [?\C-h] 'undefined)
1864 map))
1865 minor-mode-overriding-map-alist)))
1867 (insert (format "\nGet help\t %s\n"
1868 (let ((where (where-is-internal 'help-command nil t)))
1869 (cond
1870 ((equal where [?\C-h])
1871 "C-h (Hold down CTRL and press h)")
1872 (where (key-description where))
1873 (t "M-x help")))))
1874 (insert-button "Emacs manual"
1875 'action (lambda (_button) (info-emacs-manual))
1876 'follow-link t)
1877 (insert (substitute-command-keys"\t \\[info-emacs-manual]\t"))
1878 (insert-button "Browse manuals"
1879 'action (lambda (_button) (Info-directory))
1880 'follow-link t)
1881 (insert (substitute-command-keys "\t \\[info]\n"))
1882 (insert-button "Emacs tutorial"
1883 'action (lambda (_button) (help-with-tutorial))
1884 'follow-link t)
1885 (insert (substitute-command-keys
1886 "\t \\[help-with-tutorial]\tUndo changes\t \\[undo]\n"))
1887 (insert-button "Buy manuals"
1888 'action (lambda (_button) (view-order-manuals))
1889 'follow-link t)
1890 (insert (substitute-command-keys
1891 "\t \\[view-order-manuals]\tExit Emacs\t \\[save-buffers-kill-terminal]")))
1893 ;; Say how to use the menu bar with the keyboard.
1894 (insert "\n")
1895 (insert-button "Activate menubar"
1896 'action (lambda (_button) (tmm-menubar))
1897 'follow-link t)
1898 (if (and (eq (key-binding "\M-`") 'tmm-menubar)
1899 (eq (key-binding [f10]) 'tmm-menubar))
1900 (insert " F10 or ESC ` or M-`")
1901 (insert (substitute-command-keys " \\[tmm-menubar]")))
1903 ;; Many users seem to have problems with these.
1904 (insert "
1905 \(`C-' means use the CTRL key. `M-' means use the Meta (or Alt) key.
1906 If you have no Meta key, you may instead type ESC followed by the character.)")
1908 ;; Insert links to useful tasks
1909 (insert "\nUseful tasks:\n")
1911 (insert-button "Visit New File"
1912 'action (lambda (_button) (call-interactively 'find-file))
1913 'follow-link t)
1914 (insert "\t\t\t")
1915 (insert-button "Open Home Directory"
1916 'action (lambda (_button) (dired "~"))
1917 'follow-link t)
1918 (insert "\n")
1920 (insert-button "Customize Startup"
1921 'action (lambda (_button) (customize-group 'initialization))
1922 'follow-link t)
1923 (insert "\t\t")
1924 (insert-button "Open *scratch* buffer"
1925 'action (lambda (_button) (switch-to-buffer
1926 (get-buffer-create "*scratch*")))
1927 'follow-link t)
1928 (insert "\n")
1929 (insert "\n" (emacs-version) "\n" emacs-copyright "\n")
1931 (if (and (eq (key-binding "\C-h\C-c") 'describe-copying)
1932 (eq (key-binding "\C-h\C-d") 'describe-distribution)
1933 (eq (key-binding "\C-h\C-w") 'describe-no-warranty))
1934 (progn
1935 (insert
1937 GNU Emacs comes with ABSOLUTELY NO WARRANTY; type C-h C-w for ")
1938 (insert-button "full details"
1939 'action (lambda (_button) (describe-no-warranty))
1940 'follow-link t)
1941 (insert ".
1942 Emacs is Free Software--Free as in Freedom--so you can redistribute copies
1943 of Emacs and modify it; type C-h C-c to see ")
1944 (insert-button "the conditions"
1945 'action (lambda (_button) (describe-copying))
1946 'follow-link t)
1947 (insert ".
1948 Type C-h C-d for information on ")
1949 (insert-button "getting the latest version"
1950 'action (lambda (_button) (describe-distribution))
1951 'follow-link t)
1952 (insert "."))
1953 (insert (substitute-command-keys
1955 GNU Emacs comes with ABSOLUTELY NO WARRANTY; type \\[describe-no-warranty] for "))
1956 (insert-button "full details"
1957 'action (lambda (_button) (describe-no-warranty))
1958 'follow-link t)
1959 (insert (substitute-command-keys ".
1960 Emacs is Free Software--Free as in Freedom--so you can redistribute copies
1961 of Emacs and modify it; type \\[describe-copying] to see "))
1962 (insert-button "the conditions"
1963 'action (lambda (_button) (describe-copying))
1964 'follow-link t)
1965 (insert (substitute-command-keys".
1966 Type \\[describe-distribution] for information on "))
1967 (insert-button "getting the latest version"
1968 'action (lambda (_button) (describe-distribution))
1969 'follow-link t)
1970 (insert ".")))
1972 (defun normal-about-screen ()
1973 (insert "\n" (emacs-version) "\n" emacs-copyright "\n\n")
1975 (insert "To follow a link, click Mouse-1 on it, or move to it and type RET.\n\n")
1977 (insert-button "Authors"
1978 'action
1979 (lambda (_button)
1980 (view-file (expand-file-name "AUTHORS" data-directory))
1981 (goto-char (point-min)))
1982 'follow-link t)
1983 (insert "\t\tMany people have contributed code included in GNU Emacs\n")
1985 (insert-button "Contributing"
1986 'action
1987 (lambda (_button)
1988 (view-file (expand-file-name "CONTRIBUTE" data-directory))
1989 (goto-char (point-min)))
1990 'follow-link t)
1991 (insert "\tHow to contribute improvements to Emacs\n\n")
1993 (insert-button "GNU and Freedom"
1994 'action (lambda (_button) (describe-gnu-project))
1995 'follow-link t)
1996 (insert "\t\tWhy we developed GNU Emacs and the GNU system\n")
1998 (insert-button "Absence of Warranty"
1999 'action (lambda (_button) (describe-no-warranty))
2000 'follow-link t)
2001 (insert "\tGNU Emacs comes with ABSOLUTELY NO WARRANTY\n")
2003 (insert-button "Copying Conditions"
2004 'action (lambda (_button) (describe-copying))
2005 'follow-link t)
2006 (insert "\tConditions for redistributing and changing Emacs\n")
2008 (insert-button "Getting New Versions"
2009 'action (lambda (_button) (describe-distribution))
2010 'follow-link t)
2011 (insert "\tHow to get the latest version of GNU Emacs\n")
2013 (insert-button "More Manuals / Ordering Manuals"
2014 'action (lambda (_button) (view-order-manuals))
2015 'follow-link t)
2016 (insert "\tBuying printed manuals from the FSF\n"))
2018 (defun startup-echo-area-message ()
2019 (cond ((daemonp)
2020 "Starting Emacs daemon.")
2021 ((eq (key-binding "\C-h\C-a") 'about-emacs)
2022 "For information about GNU Emacs and the GNU system, type C-h C-a.")
2024 (substitute-command-keys
2025 "For information about GNU Emacs and the GNU system, type \
2026 \\[about-emacs]."))))
2028 (defun display-startup-echo-area-message ()
2029 (let ((resize-mini-windows t))
2030 (or noninteractive ;(input-pending-p) init-file-had-error
2031 ;; t if the init file says to inhibit the echo area startup message.
2032 (and inhibit-startup-echo-area-message
2033 user-init-file
2034 (or (and (get 'inhibit-startup-echo-area-message 'saved-value)
2035 (equal inhibit-startup-echo-area-message
2036 (if (equal init-file-user "")
2037 (user-login-name)
2038 init-file-user)))
2039 ;; Wasn't set with custom; see if .emacs has a setq.
2040 (condition-case nil
2041 (with-temp-buffer
2042 (insert-file-contents user-init-file)
2043 (re-search-forward
2044 (concat
2045 "([ \t\n]*setq[ \t\n]+"
2046 "inhibit-startup-echo-area-message[ \t\n]+"
2047 (regexp-quote
2048 (prin1-to-string
2049 (if (equal init-file-user "")
2050 (user-login-name)
2051 init-file-user)))
2052 "[ \t\n]*)")
2053 nil t))
2054 (error nil))))
2055 (message "%s" (startup-echo-area-message)))))
2057 (defun display-startup-screen (&optional concise)
2058 "Display startup screen according to display.
2059 A fancy display is used on graphic displays, normal otherwise.
2061 If CONCISE is non-nil, display a concise version of the startup
2062 screen."
2063 ;; Prevent recursive calls from server-process-filter.
2064 (if (not (get-buffer "*GNU Emacs*"))
2065 (if (use-fancy-splash-screens-p)
2066 (fancy-startup-screen concise)
2067 (normal-splash-screen t concise))))
2069 (defun display-about-screen ()
2070 "Display the *About GNU Emacs* buffer.
2071 A fancy display is used on graphic displays, normal otherwise."
2072 (interactive)
2073 (if (use-fancy-splash-screens-p)
2074 (fancy-about-screen)
2075 (normal-splash-screen nil)))
2077 (defalias 'about-emacs 'display-about-screen)
2078 (defalias 'display-splash-screen 'display-startup-screen)
2080 (defun command-line-1 (args-left)
2081 "A subroutine of `command-line'."
2082 (display-startup-echo-area-message)
2083 (when (and pure-space-overflow
2084 (not noninteractive))
2085 (display-warning
2086 'initialization
2087 "Building Emacs overflowed pure space.\
2088 (See the node Pure Storage in the Lisp manual for details.)"
2089 :warning))
2091 (let ((file-count 0)
2092 (command-line-args-left args-left)
2093 first-file-buffer)
2094 (when command-line-args-left
2095 ;; We have command args; process them.
2096 (let ((dir command-line-default-directory)
2098 ;; This approach loses for "-batch -L DIR --eval "(require foo)",
2099 ;; if foo is intended to be found in DIR.
2101 ;; ;; The directories listed in --directory/-L options will *appear*
2102 ;; ;; at the front of `load-path' in the order they appear on the
2103 ;; ;; command-line. We cannot do this by *placing* them at the front
2104 ;; ;; in the order they appear, so we need this variable to hold them,
2105 ;; ;; temporarily.
2106 ;; extra-load-path
2108 ;; To DTRT we keep track of the splice point and modify `load-path'
2109 ;; straight away upon any --directory/-L option.
2110 splice
2111 just-files ;; t if this follows the magic -- option.
2112 ;; This includes our standard options' long versions
2113 ;; and long versions of what's on command-switch-alist.
2114 (longopts
2115 (append '("--funcall" "--load" "--insert" "--kill"
2116 "--directory" "--eval" "--execute" "--no-splash"
2117 "--find-file" "--visit" "--file" "--no-desktop")
2118 (mapcar (lambda (elt) (concat "-" (car elt)))
2119 command-switch-alist)))
2120 (line 0)
2121 (column 0))
2123 ;; Add the long X options to longopts.
2124 (dolist (tem command-line-x-option-alist)
2125 (if (string-match "^--" (car tem))
2126 (push (car tem) longopts)))
2128 ;; Add the long NS options to longopts.
2129 (dolist (tem command-line-ns-option-alist)
2130 (if (string-match "^--" (car tem))
2131 (push (list (car tem)) longopts)))
2133 ;; Loop, processing options.
2134 (while command-line-args-left
2135 (let* ((argi (car command-line-args-left))
2136 (orig-argi argi)
2137 argval completion)
2138 (setq command-line-args-left (cdr command-line-args-left))
2140 ;; Do preliminary decoding of the option.
2141 (if just-files
2142 ;; After --, don't look for options; treat all args as files.
2143 (setq argi "")
2144 ;; Convert long options to ordinary options
2145 ;; and separate out an attached option argument into argval.
2146 (when (string-match "\\`\\(--[^=]*\\)=" argi)
2147 (setq argval (substring argi (match-end 0))
2148 argi (match-string 1 argi)))
2149 (when (string-match "\\`--?[^-]" orig-argi)
2150 (setq completion (try-completion argi longopts))
2151 (if (eq completion t)
2152 (setq argi (substring argi 1))
2153 (if (stringp completion)
2154 (let ((elt (member completion longopts)))
2155 (or elt
2156 (error "Option `%s' is ambiguous" argi))
2157 (setq argi (substring (car elt) 1)))
2158 (setq argval nil
2159 argi orig-argi)))))
2161 ;; Execute the option.
2162 (cond ((setq tem (assoc argi command-switch-alist))
2163 (if argval
2164 (let ((command-line-args-left
2165 (cons argval command-line-args-left)))
2166 (funcall (cdr tem) argi))
2167 (funcall (cdr tem) argi)))
2169 ((equal argi "-no-splash")
2170 (setq inhibit-startup-screen t))
2172 ((member argi '("-f" ; what the manual claims
2173 "-funcall"
2174 "-e")) ; what the source used to say
2175 (setq inhibit-startup-screen t)
2176 (setq tem (intern (or argval (pop command-line-args-left))))
2177 (if (commandp tem)
2178 (command-execute tem)
2179 (funcall tem)))
2181 ((member argi '("-eval" "-execute"))
2182 (setq inhibit-startup-screen t)
2183 (eval (read (or argval (pop command-line-args-left)))))
2185 ((member argi '("-L" "-directory"))
2186 (setq tem (expand-file-name
2187 (command-line-normalize-file-name
2188 (or argval (pop command-line-args-left)))))
2189 (cond (splice (setcdr splice (cons tem (cdr splice)))
2190 (setq splice (cdr splice)))
2191 (t (setq load-path (cons tem load-path)
2192 splice load-path))))
2194 ((member argi '("-l" "-load"))
2195 (let* ((file (command-line-normalize-file-name
2196 (or argval (pop command-line-args-left))))
2197 ;; Take file from default dir if it exists there;
2198 ;; otherwise let `load' search for it.
2199 (file-ex (expand-file-name file)))
2200 (when (file-exists-p file-ex)
2201 (setq file file-ex))
2202 (load file nil t)))
2204 ;; This is used to handle -script. It's not clear
2205 ;; we need to document it (it is totally internal).
2206 ((member argi '("-scriptload"))
2207 (let* ((file (command-line-normalize-file-name
2208 (or argval (pop command-line-args-left))))
2209 ;; Take file from default dir.
2210 (file-ex (expand-file-name file)))
2211 (load file-ex nil t t)))
2213 ((equal argi "-insert")
2214 (setq inhibit-startup-screen t)
2215 (setq tem (or argval (pop command-line-args-left)))
2216 (or (stringp tem)
2217 (error "File name omitted from `-insert' option"))
2218 (insert-file-contents (command-line-normalize-file-name tem)))
2220 ((equal argi "-kill")
2221 (kill-emacs t))
2223 ;; This is for when they use --no-desktop with -q, or
2224 ;; don't load Desktop in their .emacs. If desktop.el
2225 ;; _is_ loaded, it will handle this switch, and we
2226 ;; won't see it by the time we get here.
2227 ((equal argi "-no-desktop")
2228 (message "\"--no-desktop\" ignored because the Desktop package is not loaded"))
2230 ((string-match "^\\+[0-9]+\\'" argi)
2231 (setq line (string-to-number argi)))
2233 ((string-match "^\\+\\([0-9]+\\):\\([0-9]+\\)\\'" argi)
2234 (setq line (string-to-number (match-string 1 argi))
2235 column (string-to-number (match-string 2 argi))))
2237 ((setq tem (assoc orig-argi command-line-x-option-alist))
2238 ;; Ignore X-windows options and their args if not using X.
2239 (setq command-line-args-left
2240 (nthcdr (nth 1 tem) command-line-args-left)))
2242 ((setq tem (assoc orig-argi command-line-ns-option-alist))
2243 ;; Ignore NS-windows options and their args if not using NS.
2244 (setq command-line-args-left
2245 (nthcdr (nth 1 tem) command-line-args-left)))
2247 ((member argi '("-find-file" "-file" "-visit"))
2248 (setq inhibit-startup-screen t)
2249 ;; An explicit option to specify visiting a file.
2250 (setq tem (or argval (pop command-line-args-left)))
2251 (unless (stringp tem)
2252 (error "File name omitted from `%s' option" argi))
2253 (setq file-count (1+ file-count))
2254 (let ((file (expand-file-name
2255 (command-line-normalize-file-name tem)
2256 dir)))
2257 (if (= file-count 1)
2258 (setq first-file-buffer (find-file file))
2259 (find-file-other-window file)))
2260 (unless (zerop line)
2261 (goto-char (point-min))
2262 (forward-line (1- line)))
2263 (setq line 0)
2264 (unless (< column 1)
2265 (move-to-column (1- column)))
2266 (setq column 0))
2268 ;; These command lines now have no effect.
2269 ((string-match "\\`--?\\(no-\\)?\\(uni\\|multi\\)byte$" argi)
2270 (display-warning 'initialization
2271 (format "Ignoring obsolete arg %s" argi)))
2273 ((equal argi "--")
2274 (setq just-files t))
2276 ;; We have almost exhausted our options. See if the
2277 ;; user has made any other command-line options available
2278 (let ((hooks command-line-functions)
2279 (did-hook nil))
2280 (while (and hooks
2281 (not (setq did-hook (funcall (car hooks)))))
2282 (setq hooks (cdr hooks)))
2283 (if (not did-hook)
2284 ;; Presume that the argument is a file name.
2285 (progn
2286 (if (string-match "\\`-" argi)
2287 (error "Unknown option `%s'" argi))
2288 (unless initial-window-system
2289 (setq inhibit-startup-screen t))
2290 (setq file-count (1+ file-count))
2291 (let ((file
2292 (expand-file-name
2293 (command-line-normalize-file-name orig-argi)
2294 dir)))
2295 (cond ((= file-count 1)
2296 (setq first-file-buffer (find-file file)))
2297 (inhibit-startup-screen
2298 (find-file-other-window file))
2299 (t (find-file file))))
2300 (unless (zerop line)
2301 (goto-char (point-min))
2302 (forward-line (1- line)))
2303 (setq line 0)
2304 (unless (< column 1)
2305 (move-to-column (1- column)))
2306 (setq column 0))))))
2307 ;; In unusual circumstances, the execution of Lisp code due
2308 ;; to command-line options can cause the last visible frame
2309 ;; to be deleted. In this case, kill emacs to avoid an
2310 ;; abort later.
2311 (unless (frame-live-p (selected-frame)) (kill-emacs nil))))))
2313 (when (eq initial-buffer-choice t)
2314 ;; When initial-buffer-choice equals t make sure that *scratch*
2315 ;; exists.
2316 (get-buffer-create "*scratch*"))
2318 ;; If *scratch* exists and is empty, insert initial-scratch-message.
2319 ;; Do this before switching to *scratch* below to handle bug#9605.
2320 (and initial-scratch-message
2321 (get-buffer "*scratch*")
2322 (with-current-buffer "*scratch*"
2323 (when (zerop (buffer-size))
2324 (insert initial-scratch-message)
2325 (set-buffer-modified-p nil))))
2327 (when initial-buffer-choice
2328 (cond ((eq initial-buffer-choice t)
2329 (switch-to-buffer (get-buffer-create "*scratch*")))
2330 ((stringp initial-buffer-choice)
2331 (find-file initial-buffer-choice))))
2333 (if (or inhibit-startup-screen
2334 initial-buffer-choice
2335 noninteractive
2336 (daemonp)
2337 inhibit-x-resources)
2339 ;; Not displaying a startup screen. If 3 or more files
2340 ;; visited, and not all visible, show user what they all are.
2341 (and (> file-count 2)
2342 (not noninteractive)
2343 (not inhibit-startup-buffer-menu)
2344 (or (get-buffer-window first-file-buffer)
2345 (list-buffers)))
2347 ;; Display a startup screen, after some preparations.
2349 ;; If there are no switches to process, we might as well
2350 ;; run this hook now, and there may be some need to do it
2351 ;; before doing any output.
2352 (run-hooks 'emacs-startup-hook)
2353 (and term-setup-hook
2354 (run-hooks 'term-setup-hook))
2355 (setq inhibit-startup-hooks t)
2357 ;; It's important to notice the user settings before we
2358 ;; display the startup message; otherwise, the settings
2359 ;; won't take effect until the user gives the first
2360 ;; keystroke, and that's distracting.
2361 (when (fboundp 'frame-notice-user-settings)
2362 (frame-notice-user-settings))
2364 ;; If there are no switches to process, we might as well
2365 ;; run this hook now, and there may be some need to do it
2366 ;; before doing any output.
2367 (when window-setup-hook
2368 (run-hooks 'window-setup-hook)
2369 ;; Don't let the hook be run twice.
2370 (setq window-setup-hook nil))
2372 ;; ;; Do this now to avoid an annoying delay if the user
2373 ;; ;; clicks the menu bar during the sit-for.
2374 ;; (when (display-popup-menus-p)
2375 ;; (precompute-menubar-bindings))
2376 ;; (with-no-warnings
2377 ;; (setq menubar-bindings-done t))
2379 (display-startup-screen (> file-count 0)))))
2381 (defun command-line-normalize-file-name (file)
2382 "Collapse multiple slashes to one, to handle non-Emacs file names."
2383 (save-match-data
2384 ;; Use arg 1 so that we don't collapse // at the start of the file name.
2385 ;; That is significant on some systems.
2386 ;; However, /// at the beginning is supposed to mean just /, not //.
2387 (if (string-match "^///+" file)
2388 (setq file (replace-match "/" t t file)))
2389 (and (memq system-type '(ms-dos windows-nt))
2390 (string-match "^[A-Za-z]:\\(\\\\[\\\\/]\\)" file) ; C:\/ or C:\\
2391 (setq file (replace-match "/" t t file 1)))
2392 (while (string-match "//+" file 1)
2393 (setq file (replace-match "/" t t file)))
2394 file))
2396 ;;; startup.el ends here