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