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