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