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