]> code.delx.au - gnu-emacs/blob - lisp/startup.el
(command-line): Revert 2008-09-26 change, not
[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 frame was created with a menu bar, set menu-bar-mode on.
893 (unless (or noninteractive
894 emacs-basic-display
895 (and (memq initial-window-system '(x w32))
896 (<= (frame-parameter nil 'menu-bar-lines) 0)))
897 (menu-bar-mode 1))
898
899 ;; Enable tool-bar-mode if necessary. Note that we might enable it
900 ;; even in tty frames, which means that there is a tool-bar if Emacs
901 ;; later opens a graphical frame.
902 (unless (or noninteractive emacs-basic-display
903 (not (fboundp 'tool-bar-mode))
904 ;; The tool-bar-lines parameter is nil if starting on a
905 ;; tty; it is 0 if starting on a graphical display with
906 ;; the toolbar disabled via X resources.
907 (and (numberp (frame-parameter nil 'tool-bar-lines))
908 (<= (frame-parameter nil 'tool-bar-lines) 0)))
909 (tool-bar-mode 1))
910
911 ;; Can't do this init in defcustom because the relevant variables
912 ;; are not set.
913 (custom-reevaluate-setting 'blink-cursor-mode)
914 (custom-reevaluate-setting 'tooltip-mode)
915 (custom-reevaluate-setting 'global-font-lock-mode)
916 (custom-reevaluate-setting 'mouse-wheel-down-event)
917 (custom-reevaluate-setting 'mouse-wheel-up-event)
918 (custom-reevaluate-setting 'file-name-shadow-mode)
919 (custom-reevaluate-setting 'send-mail-function)
920 (custom-reevaluate-setting 'focus-follows-mouse)
921 (custom-reevaluate-setting 'global-auto-composition-mode)
922 (custom-reevaluate-setting 'transient-mark-mode)
923 (custom-reevaluate-setting 'auto-encryption-mode)
924
925 (normal-erase-is-backspace-setup-frame)
926
927 ;; Register default TTY colors for the case the terminal hasn't a
928 ;; terminal init file. We do this regardles of whether the terminal
929 ;; supports colors or not and regardless the current display type,
930 ;; since users can connect to color-capable terminals and also
931 ;; switch color support on or off in mid-session by setting the
932 ;; tty-color-mode frame parameter.
933 ;; Exception: the `pc' ``window system'' has only 16 fixed colors,
934 ;; and they are already set at this point by a suitable function in
935 ;; window-system-initialization-alist.
936 (or (eq initial-window-system 'pc)
937 (tty-register-default-colors))
938
939 ;; Record whether the tool-bar is present before the user and site
940 ;; init files are processed. frame-notice-user-settings uses this
941 ;; to determine if the tool-bar has been disabled by the init files,
942 ;; and the frame needs to be resized.
943 (when (fboundp 'frame-notice-user-settings)
944 (let ((tool-bar-lines (or (assq 'tool-bar-lines initial-frame-alist)
945 (assq 'tool-bar-lines default-frame-alist))))
946 (setq tool-bar-originally-present
947 (and tool-bar-lines
948 (cdr tool-bar-lines)
949 (not (eq 0 (cdr tool-bar-lines)))))))
950
951 (let ((old-scalable-fonts-allowed scalable-fonts-allowed)
952 (old-font-list-limit font-list-limit)
953 (old-face-ignored-fonts face-ignored-fonts))
954
955 ;; Run the site-start library if it exists. The point of this file is
956 ;; that it is run before .emacs. There is no point in doing this after
957 ;; .emacs; that is useless.
958 ;; Note that user-init-file is nil at this point. Code that might
959 ;; be loaded from site-run-file and wants to test if -q was given
960 ;; should check init-file-user instead, since that is already set.
961 ;; See cus-edit.el for an example.
962 (if site-run-file
963 (load site-run-file t t))
964
965 ;; Sites should not disable this. Only individuals should disable
966 ;; the startup screen.
967 (setq inhibit-startup-screen nil)
968
969 ;; Warn for invalid user name.
970 (when init-file-user
971 (if (string-match "[~/:\n]" init-file-user)
972 (display-warning 'initialization
973 (format "Invalid user name %s"
974 init-file-user)
975 :error)
976 (if (file-directory-p (expand-file-name
977 ;; We don't support ~USER on MS-Windows except
978 ;; for the current user, and always load .emacs
979 ;; from the current user's home directory (see
980 ;; below). So always check "~", even if invoked
981 ;; with "-u USER", or if $USER or $LOGNAME are
982 ;; set to something different.
983 (if (eq system-type 'windows-nt)
984 "~"
985 (concat "~" init-file-user))))
986 nil
987 (display-warning 'initialization
988 (format "User %s has no home directory"
989 init-file-user)
990 :error))))
991
992 ;; Load that user's init file, or the default one, or none.
993 (let (debug-on-error-from-init-file
994 debug-on-error-should-be-set
995 (debug-on-error-initial
996 (if (eq init-file-debug t) 'startup init-file-debug))
997 (orig-enable-multibyte default-enable-multibyte-characters))
998 (let ((debug-on-error debug-on-error-initial)
999 ;; This function actually reads the init files.
1000 (inner
1001 (function
1002 (lambda ()
1003 (if init-file-user
1004 (let ((user-init-file-1
1005 (cond
1006 ((eq system-type 'ms-dos)
1007 (concat "~" init-file-user "/_emacs"))
1008 ((eq system-type 'windows-nt)
1009 ;; Prefer .emacs on Windows.
1010 (if (directory-files "~" nil "^\\.emacs\\(\\.elc?\\)?$")
1011 "~/.emacs"
1012 ;; Also support _emacs for compatibility.
1013 (if (directory-files "~" nil "^_emacs\\(\\.elc?\\)?$")
1014 "~/_emacs"
1015 ;; But default to .emacs if _emacs does not exist.
1016 "~/.emacs")))
1017 (t
1018 (concat "~" init-file-user "/.emacs")))))
1019 ;; This tells `load' to store the file name found
1020 ;; into user-init-file.
1021 (setq user-init-file t)
1022 (load user-init-file-1 t t)
1023
1024 (when (eq user-init-file t)
1025 ;; If we did not find ~/.emacs, try
1026 ;; ~/.emacs.d/init.el.
1027 (let ((otherfile
1028 (expand-file-name
1029 "init"
1030 (file-name-as-directory
1031 (concat "~" init-file-user "/.emacs.d")))))
1032 (load otherfile t t)
1033
1034 ;; If we did not find the user's init file,
1035 ;; set user-init-file conclusively.
1036 ;; Don't let it be set from default.el.
1037 (when (eq user-init-file t)
1038 (setq user-init-file user-init-file-1))))
1039
1040 ;; If we loaded a compiled file, set
1041 ;; `user-init-file' to the source version if that
1042 ;; exists.
1043 (when (and user-init-file
1044 (equal (file-name-extension user-init-file)
1045 "elc"))
1046 (let* ((source (file-name-sans-extension user-init-file))
1047 (alt (concat source ".el")))
1048 (setq source (cond ((file-exists-p alt) alt)
1049 ((file-exists-p source) source)
1050 (t nil)))
1051 (when source
1052 (when (file-newer-than-file-p source user-init-file)
1053 (message "Warning: %s is newer than %s"
1054 source user-init-file)
1055 (sit-for 1))
1056 (setq user-init-file source))))
1057
1058 (unless inhibit-default-init
1059 (let ((inhibit-startup-screen nil))
1060 ;; Users are supposed to be told their rights.
1061 ;; (Plus how to get help and how to undo.)
1062 ;; Don't you dare turn this off for anyone
1063 ;; except yourself.
1064 (load "default" t t)))))))))
1065 (if init-file-debug
1066 ;; Do this without a condition-case if the user wants to debug.
1067 (funcall inner)
1068 (condition-case error
1069 (progn
1070 (funcall inner)
1071 (setq init-file-had-error nil))
1072 (error
1073 (display-warning
1074 'initialization
1075 (format "An error occurred while loading `%s':\n\n%s%s%s\n\n\
1076 To ensure normal operation, you should investigate and remove the
1077 cause of the error in your initialization file. Start Emacs with
1078 the `--debug-init' option to view a complete error backtrace."
1079 user-init-file
1080 (get (car error) 'error-message)
1081 (if (cdr error) ": " "")
1082 (mapconcat (lambda (s) (prin1-to-string s t)) (cdr error) ", "))
1083 :warning)
1084 (setq init-file-had-error t))))
1085
1086 (if (and deactivate-mark transient-mark-mode)
1087 (with-current-buffer (window-buffer)
1088 (deactivate-mark)))
1089
1090 ;; If the user has a file of abbrevs, read it (unless -batch).
1091 (when (and (not noninteractive)
1092 (file-exists-p abbrev-file-name)
1093 (file-readable-p abbrev-file-name))
1094 (quietly-read-abbrev-file abbrev-file-name))
1095
1096 ;; If the abbrevs came entirely from the init file or the
1097 ;; abbrevs file, they do not need saving.
1098 (setq abbrevs-changed nil)
1099
1100 ;; If we can tell that the init file altered debug-on-error,
1101 ;; arrange to preserve the value that it set up.
1102 (or (eq debug-on-error debug-on-error-initial)
1103 (setq debug-on-error-should-be-set t
1104 debug-on-error-from-init-file debug-on-error)))
1105 (if debug-on-error-should-be-set
1106 (setq debug-on-error debug-on-error-from-init-file))
1107 (unless (or default-enable-multibyte-characters
1108 (eq orig-enable-multibyte default-enable-multibyte-characters))
1109 ;; Init file changed to unibyte. Reset existing multibyte
1110 ;; buffers (probably *scratch*, *Messages*, *Minibuff-0*).
1111 ;; Arguably this should only be done if they're free of
1112 ;; multibyte characters.
1113 (mapc (lambda (buffer)
1114 (with-current-buffer buffer
1115 (if enable-multibyte-characters
1116 (set-buffer-multibyte nil))))
1117 (buffer-list))
1118 ;; Also re-set the language environment in case it was
1119 ;; originally done before unibyte was set and is sensitive to
1120 ;; unibyte (display table, terminal coding system &c).
1121 (set-language-environment current-language-environment)))
1122
1123 ;; Do this here in case the init file sets mail-host-address.
1124 (if (equal user-mail-address "")
1125 (setq user-mail-address (or (getenv "EMAIL")
1126 (concat (user-login-name) "@"
1127 (or mail-host-address
1128 (system-name))))))
1129
1130 ;; Originally face attributes were specified via
1131 ;; `font-lock-face-attributes'. Users then changed the default
1132 ;; face attributes by setting that variable. However, we try and
1133 ;; be back-compatible and respect its value if set except for
1134 ;; faces where M-x customize has been used to save changes for the
1135 ;; face.
1136 (when (boundp 'font-lock-face-attributes)
1137 (let ((face-attributes font-lock-face-attributes))
1138 (while face-attributes
1139 (let* ((face-attribute (pop face-attributes))
1140 (face (car face-attribute)))
1141 ;; Rustle up a `defface' SPEC from a
1142 ;; `font-lock-face-attributes' entry.
1143 (unless (get face 'saved-face)
1144 (let ((foreground (nth 1 face-attribute))
1145 (background (nth 2 face-attribute))
1146 (bold-p (nth 3 face-attribute))
1147 (italic-p (nth 4 face-attribute))
1148 (underline-p (nth 5 face-attribute))
1149 face-spec)
1150 (when foreground
1151 (setq face-spec (cons ':foreground (cons foreground face-spec))))
1152 (when background
1153 (setq face-spec (cons ':background (cons background face-spec))))
1154 (when bold-p
1155 (setq face-spec (append '(:weight bold) face-spec)))
1156 (when italic-p
1157 (setq face-spec (append '(:slant italic) face-spec)))
1158 (when underline-p
1159 (setq face-spec (append '(:underline t) face-spec)))
1160 (face-spec-set face (list (list t face-spec)) nil)))))))
1161
1162 ;; If parameter have been changed in the init file which influence
1163 ;; face realization, clear the face cache so that new faces will
1164 ;; be realized.
1165 (unless (and (eq scalable-fonts-allowed old-scalable-fonts-allowed)
1166 (eq font-list-limit old-font-list-limit)
1167 (eq face-ignored-fonts old-face-ignored-fonts))
1168 (clear-face-cache)))
1169
1170 (setq after-init-time (current-time))
1171 (run-hooks 'after-init-hook)
1172
1173 ;; Decode all default-directory.
1174 (if (and default-enable-multibyte-characters locale-coding-system)
1175 (save-excursion
1176 (dolist (elt (buffer-list))
1177 (set-buffer elt)
1178 (if default-directory
1179 (setq default-directory
1180 (decode-coding-string default-directory
1181 locale-coding-system t))))
1182 (setq command-line-default-directory
1183 (decode-coding-string command-line-default-directory
1184 locale-coding-system t))))
1185
1186 ;; If *scratch* exists and init file didn't change its mode, initialize it.
1187 (if (get-buffer "*scratch*")
1188 (with-current-buffer "*scratch*"
1189 (if (eq major-mode 'fundamental-mode)
1190 (funcall initial-major-mode))))
1191
1192 ;; Load library for our terminal type.
1193 ;; User init file can set term-file-prefix to nil to prevent this.
1194 (unless (or noninteractive
1195 initial-window-system)
1196 (tty-run-terminal-initialization (selected-frame)))
1197
1198 ;; Update the out-of-memory error message based on user's key bindings
1199 ;; for save-some-buffers.
1200 (setq memory-signal-data
1201 (list 'error
1202 (substitute-command-keys "Memory exhausted--use \\[save-some-buffers] then exit and restart Emacs")))
1203
1204 ;; Process the remaining args.
1205 (command-line-1 (cdr command-line-args))
1206
1207 ;; If -batch, terminate after processing the command options.
1208 (if noninteractive (kill-emacs t))
1209
1210 ;; In daemon mode, start the server to allow clients to connect.
1211 ;; This is done after loading the user's init file and after
1212 ;; processing all command line arguments to allow e.g. `server-name'
1213 ;; to be changed before the server starts.
1214 (when (daemonp)
1215 (server-start))
1216
1217 ;; Run emacs-session-restore (session management) if started by
1218 ;; the session manager and we have a session manager connection.
1219 (if (and (boundp 'x-session-previous-id)
1220 (stringp x-session-previous-id))
1221 (with-no-warnings
1222 (emacs-session-restore x-session-previous-id))))
1223
1224 (defcustom initial-scratch-message (purecopy "\
1225 ;; This buffer is for notes you don't want to save, and for Lisp evaluation.
1226 ;; If you want to create a file, visit that file with C-x C-f,
1227 ;; then enter the text in that file's own buffer.
1228
1229 ")
1230 "Initial message displayed in *scratch* buffer at startup.
1231 If this is nil, no message will be displayed."
1232 :type '(choice (text :tag "Message")
1233 (const :tag "none" nil))
1234 :group 'initialization)
1235
1236 \f
1237 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1238 ;;; Fancy splash screen
1239 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1240
1241 (defvar fancy-startup-text
1242 '((:face (variable-pitch (:foreground "red"))
1243 "Welcome to "
1244 :link ("GNU Emacs"
1245 (lambda (button) (browse-url "http://www.gnu.org/software/emacs/"))
1246 "Browse http://www.gnu.org/software/emacs/")
1247 ", one component of the "
1248 :link
1249 (lambda ()
1250 (if (eq system-type 'gnu/linux)
1251 '("GNU/Linux"
1252 (lambda (button) (browse-url "http://www.gnu.org/gnu/linux-and-gnu.html"))
1253 "Browse http://www.gnu.org/gnu/linux-and-gnu.html")
1254 '("GNU" (lambda (button) (describe-gnu-project))
1255 "Display info on the GNU project")))
1256 " operating system.\n\n"
1257 :link ("Emacs Tutorial" (lambda (button) (help-with-tutorial)))
1258 "\tLearn basic keystroke commands"
1259 (lambda ()
1260 (let* ((en "TUTORIAL")
1261 (tut (or (get-language-info current-language-environment
1262 'tutorial)
1263 en))
1264 (title (with-temp-buffer
1265 (insert-file-contents
1266 (expand-file-name tut tutorial-directory)
1267 nil 0 256)
1268 (search-forward ".")
1269 (buffer-substring (point-min) (1- (point))))))
1270 ;; If there is a specific tutorial for the current language
1271 ;; environment and it is not English, append its title.
1272 (if (string= en tut)
1273 ""
1274 (concat " (" title ")"))))
1275 "\n"
1276 :face variable-pitch
1277 :link ("Emacs Guided Tour"
1278 (lambda (button) (browse-url "http://www.gnu.org/software/emacs/tour/"))
1279 "Browse http://www.gnu.org/software/emacs/tour/")
1280 "\tOverview of Emacs features at gnu.org\n"
1281 :link ("View Emacs Manual" (lambda (button) (info-emacs-manual)))
1282 "\tView the Emacs manual using Info\n"
1283 :link ("Absence of Warranty" (lambda (button) (describe-no-warranty)))
1284 "\tGNU Emacs comes with "
1285 :face (variable-pitch (:slant oblique))
1286 "ABSOLUTELY NO WARRANTY\n"
1287 :face variable-pitch
1288 :link ("Copying Conditions" (lambda (button) (describe-copying)))
1289 "\tConditions for redistributing and changing Emacs\n"
1290 :link ("Ordering Manuals" (lambda (button) (view-order-manuals)))
1291 "\tPurchasing printed copies of manuals\n"
1292 "\n"))
1293 "A list of texts to show in the middle part of splash screens.
1294 Each element in the list should be a list of strings or pairs
1295 `:face FACE', like `fancy-splash-insert' accepts them.")
1296
1297 (defvar fancy-about-text
1298 '((:face (variable-pitch (:foreground "red"))
1299 "This is "
1300 :link ("GNU Emacs"
1301 (lambda (button) (browse-url "http://www.gnu.org/software/emacs/"))
1302 "Browse http://www.gnu.org/software/emacs/")
1303 ", one component of the "
1304 :link
1305 (lambda ()
1306 (if (eq system-type 'gnu/linux)
1307 '("GNU/Linux"
1308 (lambda (button) (browse-url "http://www.gnu.org/gnu/linux-and-gnu.html"))
1309 "Browse http://www.gnu.org/gnu/linux-and-gnu.html")
1310 '("GNU" (lambda (button) (describe-gnu-project))
1311 "Display info on the GNU project.")))
1312 " operating system.\n"
1313 :face (lambda ()
1314 (list 'variable-pitch
1315 (list :foreground
1316 (if (eq (frame-parameter nil 'background-mode) 'dark)
1317 "cyan" "darkblue"))))
1318 "\n"
1319 (lambda () (emacs-version))
1320 "\n"
1321 :face (variable-pitch (:height 0.8))
1322 (lambda () emacs-copyright)
1323 "\n\n"
1324 :face variable-pitch
1325 :link ("Authors"
1326 (lambda (button)
1327 (view-file (expand-file-name "AUTHORS" data-directory))
1328 (goto-char (point-min))))
1329 "\tMany people have contributed code included in GNU Emacs\n"
1330 :link ("Contributing"
1331 (lambda (button)
1332 (view-file (expand-file-name "CONTRIBUTE" data-directory))
1333 (goto-char (point-min))))
1334 "\tHow to contribute improvements to Emacs\n"
1335 "\n"
1336 :link ("GNU and Freedom" (lambda (button) (describe-gnu-project)))
1337 "\tWhy we developed GNU Emacs, and the GNU operating system\n"
1338 :link ("Absence of Warranty" (lambda (button) (describe-no-warranty)))
1339 "\tGNU Emacs comes with "
1340 :face (variable-pitch (:slant oblique))
1341 "ABSOLUTELY NO WARRANTY\n"
1342 :face variable-pitch
1343 :link ("Copying Conditions" (lambda (button) (describe-copying)))
1344 "\tConditions for redistributing and changing Emacs\n"
1345 :link ("Getting New Versions" (lambda (button) (describe-distribution)))
1346 "\tHow to obtain the latest version of Emacs\n"
1347 :link ("Ordering Manuals" (lambda (button) (view-order-manuals)))
1348 "\tBuying printed manuals from the FSF\n"
1349 "\n"
1350 :link ("Emacs Tutorial" (lambda (button) (help-with-tutorial)))
1351 "\tLearn basic Emacs keystroke commands"
1352 (lambda ()
1353 (let* ((en "TUTORIAL")
1354 (tut (or (get-language-info current-language-environment
1355 'tutorial)
1356 en))
1357 (title (with-temp-buffer
1358 (insert-file-contents
1359 (expand-file-name tut tutorial-directory)
1360 nil 0 256)
1361 (search-forward ".")
1362 (buffer-substring (point-min) (1- (point))))))
1363 ;; If there is a specific tutorial for the current language
1364 ;; environment and it is not English, append its title.
1365 (if (string= en tut)
1366 ""
1367 (concat " (" title ")"))))
1368 "\n"
1369 :link ("Emacs Guided Tour"
1370 (lambda (button) (browse-url "http://www.gnu.org/software/emacs/tour/"))
1371 "Browse http://www.gnu.org/software/emacs/tour/")
1372 "\tSee an overview of the many facilities of GNU Emacs"
1373 ))
1374 "A list of texts to show in the middle part of the About screen.
1375 Each element in the list should be a list of strings or pairs
1376 `:face FACE', like `fancy-splash-insert' accepts them.")
1377
1378
1379 (defgroup fancy-splash-screen ()
1380 "Fancy splash screen when Emacs starts."
1381 :version "21.1"
1382 :group 'initialization)
1383
1384 (defcustom fancy-splash-image nil
1385 "*The image to show in the splash screens, or nil for defaults."
1386 :group 'fancy-splash-screen
1387 :type '(choice (const :tag "Default" nil)
1388 (file :tag "File")))
1389
1390
1391 (defvar splash-screen-keymap
1392 (let ((map (make-sparse-keymap)))
1393 (suppress-keymap map)
1394 (set-keymap-parent map button-buffer-map)
1395 (define-key map "\C-?" 'scroll-down)
1396 (define-key map " " 'scroll-up)
1397 (define-key map "q" 'exit-splash-screen)
1398 map)
1399 "Keymap for splash screen buffer.")
1400
1401 ;; These are temporary storage areas for the splash screen display.
1402
1403 (defun fancy-splash-insert (&rest args)
1404 "Insert text into the current buffer, with faces.
1405 Arguments from ARGS should be either strings; functions called
1406 with no args that return a string; pairs `:face FACE', where FACE
1407 is a face specification usable with `put-text-property'; or pairs
1408 `:link LINK' where LINK is a list of arguments to pass to
1409 `insert-button', of the form (LABEL ACTION [HELP-ECHO]), which
1410 specifies the button's label, `action' property and help-echo string.
1411 FACE and LINK can also be functions, which are evaluated to obtain
1412 a face or button specification."
1413 (let ((current-face nil))
1414 (while args
1415 (cond ((eq (car args) :face)
1416 (setq args (cdr args) current-face (car args))
1417 (if (functionp current-face)
1418 (setq current-face (funcall current-face))))
1419 ((eq (car args) :link)
1420 (setq args (cdr args))
1421 (let ((spec (car args)))
1422 (if (functionp spec)
1423 (setq spec (funcall spec)))
1424 (insert-button (car spec)
1425 'face (list 'link current-face)
1426 'action (cadr spec)
1427 'help-echo (concat "mouse-2, RET: "
1428 (or (nth 2 spec)
1429 "Follow this link"))
1430 'follow-link t)))
1431 (t (insert (propertize (let ((it (car args)))
1432 (if (functionp it)
1433 (funcall it)
1434 it))
1435 'face current-face
1436 'help-echo (startup-echo-area-message)))))
1437 (setq args (cdr args)))))
1438
1439 (declare-function image-size "image.c" (spec &optional pixels frame))
1440
1441 (defun fancy-splash-head ()
1442 "Insert the head part of the splash screen into the current buffer."
1443 (let* ((image-file (cond ((stringp fancy-splash-image)
1444 fancy-splash-image)
1445 ((display-color-p)
1446 (cond ((<= (display-planes) 8)
1447 (if (image-type-available-p 'xpm)
1448 "splash.xpm"
1449 "splash.pbm"))
1450 ((image-type-available-p 'svg)
1451 "splash.svg")
1452 ((image-type-available-p 'png)
1453 "splash.png")
1454 ((image-type-available-p 'xpm)
1455 "splash.xpm")
1456 (t "splash.pbm")))
1457 (t "splash.pbm")))
1458 (img (create-image image-file))
1459 (image-width (and img (car (image-size img))))
1460 (window-width (window-width (selected-window))))
1461 (when img
1462 (when (> window-width image-width)
1463 ;; Center the image in the window.
1464 (insert (propertize " " 'display
1465 `(space :align-to (+ center (-0.5 . ,img)))))
1466
1467 ;; Change the color of the XPM version of the splash image
1468 ;; so that it is visible with a dark frame background.
1469 (when (and (memq 'xpm img)
1470 (eq (frame-parameter nil 'background-mode) 'dark))
1471 (setq img (append img '(:color-symbols (("#000000" . "gray30"))))))
1472
1473 ;; Insert the image with a help-echo and a link.
1474 (make-button (prog1 (point) (insert-image img)) (point)
1475 'face 'default
1476 'help-echo "mouse-2, RET: Browse http://www.gnu.org/"
1477 'action (lambda (button) (browse-url "http://www.gnu.org/"))
1478 'follow-link t)
1479 (insert "\n\n")))))
1480
1481 (defun fancy-startup-tail (&optional concise)
1482 "Insert the tail part of the splash screen into the current buffer."
1483 (let ((fg (if (eq (frame-parameter nil 'background-mode) 'dark)
1484 "cyan" "darkblue")))
1485 (unless concise
1486 (fancy-splash-insert
1487 :face 'variable-pitch
1488 "\nTo start... "
1489 :link '("Open a File"
1490 (lambda (button) (call-interactively 'find-file))
1491 "Specify a new file's name, to edit the file")
1492 " "
1493 :link '("Open Home Directory"
1494 (lambda (button) (dired "~"))
1495 "Open your home directory, to operate on its files")
1496 " "
1497 :link '("Customize Startup"
1498 (lambda (button) (customize-group 'initialization))
1499 "Change initialization settings including this screen")
1500 "\n"))
1501 (fancy-splash-insert
1502 :face 'variable-pitch "To quit a partially entered command, type "
1503 :face 'default "Control-g"
1504 :face 'variable-pitch ".\n")
1505 (fancy-splash-insert :face `(variable-pitch (:foreground ,fg))
1506 "\nThis is "
1507 (emacs-version)
1508 "\n"
1509 :face '(variable-pitch (:height 0.8))
1510 emacs-copyright
1511 "\n")
1512 (and auto-save-list-file-prefix
1513 ;; Don't signal an error if the
1514 ;; directory for auto-save-list files
1515 ;; does not yet exist.
1516 (file-directory-p (file-name-directory
1517 auto-save-list-file-prefix))
1518 (directory-files
1519 (file-name-directory auto-save-list-file-prefix)
1520 nil
1521 (concat "\\`"
1522 (regexp-quote (file-name-nondirectory
1523 auto-save-list-file-prefix)))
1524 t)
1525 (fancy-splash-insert :face '(variable-pitch (:foreground "red"))
1526 "\nIf an Emacs session crashed recently, "
1527 "type "
1528 :face '(fixed-pitch :foreground "red")
1529 "Meta-x recover-session RET"
1530 :face '(variable-pitch (:foreground "red"))
1531 "\nto recover"
1532 " the files you were editing."))
1533
1534 (when concise
1535 (fancy-splash-insert
1536 :face 'variable-pitch "\n"
1537 :link '("Dismiss this startup screen"
1538 (lambda (button)
1539 (when startup-screen-inhibit-startup-screen
1540 (customize-set-variable 'inhibit-startup-screen t)
1541 (customize-mark-to-save 'inhibit-startup-screen)
1542 (custom-save-all))
1543 (let ((w (get-buffer-window "*GNU Emacs*")))
1544 (and w (not (one-window-p)) (delete-window w)))
1545 (kill-buffer "*GNU Emacs*")))
1546 " ")
1547 (when (or user-init-file custom-file)
1548 (let ((checked (create-image "\300\300\141\143\067\076\034\030"
1549 'xbm t :width 8 :height 8 :background "grey75"
1550 :foreground "black" :relief -2 :ascent 'center))
1551 (unchecked (create-image (make-string 8 0)
1552 'xbm t :width 8 :height 8 :background "grey75"
1553 :foreground "black" :relief -2 :ascent 'center)))
1554 (insert-button
1555 " " :on-glyph checked :off-glyph unchecked 'checked nil
1556 'display unchecked 'follow-link t
1557 'action (lambda (button)
1558 (if (overlay-get button 'checked)
1559 (progn (overlay-put button 'checked nil)
1560 (overlay-put button 'display (overlay-get button :off-glyph))
1561 (setq startup-screen-inhibit-startup-screen nil))
1562 (overlay-put button 'checked t)
1563 (overlay-put button 'display (overlay-get button :on-glyph))
1564 (setq startup-screen-inhibit-startup-screen t)))))
1565 (fancy-splash-insert :face '(variable-pitch (:height 0.9))
1566 " Never show it again.")))))
1567
1568 (defun exit-splash-screen ()
1569 "Stop displaying the splash screen buffer."
1570 (interactive)
1571 (quit-window t))
1572
1573 (defun fancy-startup-screen (&optional concise)
1574 "Display fancy startup screen.
1575 If CONCISE is non-nil, display a concise version of the
1576 splash screen in another window."
1577 (let ((splash-buffer (get-buffer-create "*GNU Emacs*")))
1578 (with-current-buffer splash-buffer
1579 (let ((inhibit-read-only t))
1580 (erase-buffer)
1581 (setq default-directory command-line-default-directory)
1582 (make-local-variable 'startup-screen-inhibit-startup-screen)
1583 (if pure-space-overflow
1584 (insert pure-space-overflow-message))
1585 (unless concise
1586 (fancy-splash-head))
1587 (dolist (text fancy-startup-text)
1588 (apply #'fancy-splash-insert text)
1589 (insert "\n"))
1590 (skip-chars-backward "\n")
1591 (delete-region (point) (point-max))
1592 (insert "\n")
1593 (fancy-startup-tail concise))
1594 (use-local-map splash-screen-keymap)
1595 (setq tab-width 22
1596 buffer-read-only t)
1597 (set-buffer-modified-p nil)
1598 (if (and view-read-only (not view-mode))
1599 (view-mode-enter nil 'kill-buffer))
1600 (goto-char (point-min))
1601 (forward-line (if concise 2 4)))
1602 (if concise
1603 (progn
1604 (display-buffer splash-buffer)
1605 ;; If the splash screen is in a split window, fit it.
1606 (let ((window (get-buffer-window splash-buffer t)))
1607 (or (null window)
1608 (eq window (selected-window))
1609 (eq window (next-window window))
1610 (fit-window-to-buffer window))))
1611 (switch-to-buffer splash-buffer))))
1612
1613 (defun fancy-about-screen ()
1614 "Display fancy About screen."
1615 (let ((frame (fancy-splash-frame)))
1616 (save-selected-window
1617 (select-frame frame)
1618 (switch-to-buffer "*About GNU Emacs*")
1619 (setq buffer-undo-list t
1620 mode-line-format (propertize "---- %b %-"
1621 'face 'mode-line-buffer-id))
1622 (let ((inhibit-read-only t))
1623 (erase-buffer)
1624 (if pure-space-overflow
1625 (insert pure-space-overflow-message))
1626 (fancy-splash-head)
1627 (dolist (text fancy-about-text)
1628 (apply #'fancy-splash-insert text)
1629 (insert "\n"))
1630 (set-buffer-modified-p nil)
1631 (goto-char (point-min))
1632 (force-mode-line-update))
1633 (use-local-map splash-screen-keymap)
1634 (setq tab-width 22)
1635 (message "%s" (startup-echo-area-message))
1636 (setq buffer-read-only t)
1637 (goto-char (point-min))
1638 (forward-line 3))))
1639
1640 (defun fancy-splash-frame ()
1641 "Return the frame to use for the fancy splash screen.
1642 Returning non-nil does not mean we should necessarily
1643 use the fancy splash screen, but if we do use it,
1644 we put it on this frame."
1645 (let (chosen-frame)
1646 (dolist (frame (append (frame-list) (list (selected-frame))))
1647 (if (and (frame-visible-p frame)
1648 (not (window-minibuffer-p (frame-selected-window frame))))
1649 (setq chosen-frame frame)))
1650 chosen-frame))
1651
1652 (defun use-fancy-splash-screens-p ()
1653 "Return t if fancy splash screens should be used."
1654 (when (and (display-graphic-p)
1655 (or (and (display-color-p)
1656 (image-type-available-p 'xpm))
1657 (image-type-available-p 'pbm)))
1658 (let ((frame (fancy-splash-frame)))
1659 (when frame
1660 (let* ((img (create-image (or fancy-splash-image
1661 (if (and (display-color-p)
1662 (image-type-available-p 'xpm))
1663 "splash.xpm" "splash.pbm"))))
1664 (image-height (and img (cdr (image-size img nil frame))))
1665 ;; We test frame-height so that, if the frame is split
1666 ;; by displaying a warning, that doesn't cause the normal
1667 ;; splash screen to be used.
1668 (frame-height (1- (frame-height frame))))
1669 (> frame-height (+ image-height 19)))))))
1670
1671
1672 (defun normal-splash-screen (&optional startup concise)
1673 "Display non-graphic splash screen.
1674 If optional argument STARTUP is non-nil, display the startup screen
1675 after Emacs starts. If STARTUP is nil, display the About screen.
1676 If CONCISE is non-nil, display a concise version of the
1677 splash screen in another window."
1678 (let ((splash-buffer (get-buffer-create "*About GNU Emacs*")))
1679 (with-current-buffer splash-buffer
1680 (setq buffer-read-only nil)
1681 (erase-buffer)
1682 (setq default-directory command-line-default-directory)
1683 (set (make-local-variable 'tab-width) 8)
1684 (if (not startup)
1685 (set (make-local-variable 'mode-line-format)
1686 (propertize "---- %b %-" 'face 'mode-line-buffer-id)))
1687
1688 (if pure-space-overflow
1689 (insert pure-space-overflow-message))
1690
1691 ;; The convention for this piece of code is that
1692 ;; each piece of output starts with one or two newlines
1693 ;; and does not end with any newlines.
1694 (insert (if startup "Welcome to GNU Emacs" "This is GNU Emacs"))
1695 (insert
1696 (if (eq system-type 'gnu/linux)
1697 ", one component of the GNU/Linux operating system.\n"
1698 ", a part of the GNU operating system.\n"))
1699
1700 (if startup
1701 (if (display-mouse-p)
1702 ;; The user can use the mouse to activate menus
1703 ;; so give help in terms of menu items.
1704 (normal-mouse-startup-screen)
1705
1706 ;; No mouse menus, so give help using kbd commands.
1707 (normal-no-mouse-startup-screen))
1708
1709 (normal-about-screen))
1710
1711 ;; The rest of the startup screen is the same on all
1712 ;; kinds of terminals.
1713
1714 ;; Give information on recovering, if there was a crash.
1715 (and startup
1716 auto-save-list-file-prefix
1717 ;; Don't signal an error if the
1718 ;; directory for auto-save-list files
1719 ;; does not yet exist.
1720 (file-directory-p (file-name-directory
1721 auto-save-list-file-prefix))
1722 (directory-files
1723 (file-name-directory auto-save-list-file-prefix)
1724 nil
1725 (concat "\\`"
1726 (regexp-quote (file-name-nondirectory
1727 auto-save-list-file-prefix)))
1728 t)
1729 (insert "\n\nIf an Emacs session crashed recently, "
1730 "type Meta-x recover-session RET\nto recover"
1731 " the files you were editing.\n"))
1732
1733 (use-local-map splash-screen-keymap)
1734
1735 ;; Display the input that we set up in the buffer.
1736 (set-buffer-modified-p nil)
1737 (setq buffer-read-only t)
1738 (if (and view-read-only (not view-mode))
1739 (view-mode-enter nil 'kill-buffer))
1740 (if startup (rename-buffer "*GNU Emacs*" t))
1741 (goto-char (point-min)))
1742 (if concise
1743 (display-buffer splash-buffer)
1744 (switch-to-buffer splash-buffer))))
1745
1746 (defun normal-mouse-startup-screen ()
1747 ;; The user can use the mouse to activate menus
1748 ;; so give help in terms of menu items.
1749 (insert "\
1750 To follow a link, click Mouse-1 on it, or move to it and type RET.
1751 To quit a partially entered command, type Control-g.\n")
1752
1753 (insert "\nImportant Help menu items:\n")
1754 (insert-button "Emacs Tutorial"
1755 'action (lambda (button) (help-with-tutorial))
1756 'follow-link t)
1757 (insert "\t\tLearn basic Emacs keystroke commands\n")
1758 (insert-button "Read the Emacs Manual"
1759 'action (lambda (button) (info-emacs-manual))
1760 'follow-link t)
1761 (insert "\tView the Emacs manual using Info\n")
1762 (insert-button "\(Non)Warranty"
1763 'action (lambda (button) (describe-no-warranty))
1764 'follow-link t)
1765 (insert "\t\tGNU Emacs comes with ABSOLUTELY NO WARRANTY\n")
1766 (insert-button "Copying Conditions"
1767 'action (lambda (button) (describe-copying))
1768 'follow-link t)
1769 (insert "\tConditions for redistributing and changing Emacs\n")
1770 (insert-button "More Manuals / Ordering Manuals"
1771 'action (lambda (button) (view-order-manuals))
1772 'follow-link t)
1773 (insert " How to order printed manuals from the FSF\n")
1774
1775 (insert "\nUseful tasks:\n")
1776 (insert-button "Visit New File"
1777 'action (lambda (button) (call-interactively 'find-file))
1778 'follow-link t)
1779 (insert "\t\tSpecify a new file's name, to edit the file\n")
1780 (insert-button "Open Home Directory"
1781 'action (lambda (button) (dired "~"))
1782 'follow-link t)
1783 (insert "\tOpen your home directory, to operate on its files\n")
1784 (insert-button "Customize Startup"
1785 'action (lambda (button) (customize-group 'initialization))
1786 'follow-link t)
1787 (insert "\tChange initialization settings including this screen\n")
1788
1789 (insert "\n" (emacs-version)
1790 "\n" emacs-copyright))
1791
1792 ;; No mouse menus, so give help using kbd commands.
1793 (defun normal-no-mouse-startup-screen ()
1794
1795 ;; If keys have their default meanings,
1796 ;; use precomputed string to save lots of time.
1797 (if (and (eq (key-binding "\C-h") 'help-command)
1798 (eq (key-binding "\C-xu") 'advertised-undo)
1799 (eq (key-binding "\C-x\C-c") 'save-buffers-kill-terminal)
1800 (eq (key-binding "\C-ht") 'help-with-tutorial)
1801 (eq (key-binding "\C-hi") 'info)
1802 (eq (key-binding "\C-hr") 'info-emacs-manual)
1803 (eq (key-binding "\C-h\C-n") 'view-emacs-news))
1804 (progn
1805 (insert "
1806 Get help\t C-h (Hold down CTRL and press h)
1807 ")
1808 (insert-button "Emacs manual"
1809 'action (lambda (button) (info-emacs-manual))
1810 'follow-link t)
1811 (insert " C-h r\t")
1812 (insert-button "Browse manuals"
1813 'action (lambda (button) (Info-directory))
1814 'follow-link t)
1815 (insert "\t C-h i
1816 ")
1817 (insert-button "Emacs tutorial"
1818 'action (lambda (button) (help-with-tutorial))
1819 'follow-link t)
1820 (insert " C-h t\tUndo changes\t C-x u
1821 ")
1822 (insert-button "Buy manuals"
1823 'action (lambda (button) (view-order-manuals))
1824 'follow-link t)
1825 (insert "\t C-h C-m\tExit Emacs\t C-x C-c"))
1826
1827 (insert (format "
1828 Get help\t %s
1829 "
1830 (let ((where (where-is-internal
1831 'help-command nil t)))
1832 (if where
1833 (key-description where)
1834 "M-x help"))))
1835 (insert-button "Emacs manual"
1836 'action (lambda (button) (info-emacs-manual))
1837 'follow-link t)
1838 (insert (substitute-command-keys"\t \\[info-emacs-manual]\t"))
1839 (insert-button "Browse manuals"
1840 'action (lambda (button) (Info-directory))
1841 'follow-link t)
1842 (insert (substitute-command-keys "\t \\[info]
1843 "))
1844 (insert-button "Emacs tutorial"
1845 'action (lambda (button) (help-with-tutorial))
1846 'follow-link t)
1847 (insert (substitute-command-keys
1848 "\t \\[help-with-tutorial]\tUndo changes\t \\[advertised-undo]
1849 "))
1850 (insert-button "Buy manuals"
1851 'action (lambda (button) (view-order-manuals))
1852 'follow-link t)
1853 (insert (substitute-command-keys
1854 "\t \\[view-order-manuals]\tExit Emacs\t \\[save-buffers-kill-terminal]")))
1855
1856 ;; Say how to use the menu bar with the keyboard.
1857 (insert "\n")
1858 (insert-button "Activate menubar"
1859 'action (lambda (button) (tmm-menubar))
1860 'follow-link t)
1861 (if (and (eq (key-binding "\M-`") 'tmm-menubar)
1862 (eq (key-binding [f10]) 'tmm-menubar))
1863 (insert " F10 or ESC ` or M-`")
1864 (insert (substitute-command-keys " \\[tmm-menubar]")))
1865
1866 ;; Many users seem to have problems with these.
1867 (insert "
1868 \(`C-' means use the CTRL key. `M-' means use the Meta (or Alt) key.
1869 If you have no Meta key, you may instead type ESC followed by the character.)")
1870
1871 ;; Insert links to useful tasks
1872 (insert "\nUseful tasks:\n")
1873
1874 (insert-button "Visit New File"
1875 'action (lambda (button) (call-interactively 'find-file))
1876 'follow-link t)
1877 (insert "\t\t\t")
1878 (insert-button "Open Home Directory"
1879 'action (lambda (button) (dired "~"))
1880 'follow-link t)
1881 (insert "\n")
1882
1883 (insert-button "Customize Startup"
1884 'action (lambda (button) (customize-group 'initialization))
1885 'follow-link t)
1886 (insert "\t\t")
1887 (insert-button "Open *scratch* buffer"
1888 'action (lambda (button) (switch-to-buffer
1889 (get-buffer-create "*scratch*")))
1890 'follow-link t)
1891 (insert "\n")
1892 (insert "\n" (emacs-version) "\n" emacs-copyright "\n")
1893
1894 (if (and (eq (key-binding "\C-h\C-c") 'describe-copying)
1895 (eq (key-binding "\C-h\C-d") 'describe-distribution)
1896 (eq (key-binding "\C-h\C-w") 'describe-no-warranty))
1897 (progn
1898 (insert
1899 "
1900 GNU Emacs comes with ABSOLUTELY NO WARRANTY; type C-h C-w for ")
1901 (insert-button "full details"
1902 'action (lambda (button) (describe-no-warranty))
1903 'follow-link t)
1904 (insert ".
1905 Emacs is Free Software--Free as in Freedom--so you can redistribute copies
1906 of Emacs and modify it; type C-h C-c to see ")
1907 (insert-button "the conditions"
1908 'action (lambda (button) (describe-copying))
1909 'follow-link t)
1910 (insert ".
1911 Type C-h C-d for information on ")
1912 (insert-button "getting the latest version"
1913 'action (lambda (button) (describe-distribution))
1914 'follow-link t)
1915 (insert "."))
1916 (insert (substitute-command-keys
1917 "
1918 GNU Emacs comes with ABSOLUTELY NO WARRANTY; type \\[describe-no-warranty] for "))
1919 (insert-button "full details"
1920 'action (lambda (button) (describe-no-warranty))
1921 'follow-link t)
1922 (insert (substitute-command-keys ".
1923 Emacs is Free Software--Free as in Freedom--so you can redistribute copies
1924 of Emacs and modify it; type \\[describe-copying] to see "))
1925 (insert-button "the conditions"
1926 'action (lambda (button) (describe-copying))
1927 'follow-link t)
1928 (insert (substitute-command-keys".
1929 Type \\[describe-distribution] for information on "))
1930 (insert-button "getting the latest version"
1931 'action (lambda (button) (describe-distribution))
1932 'follow-link t)
1933 (insert ".")))
1934
1935 (defun normal-about-screen ()
1936 (insert "\n" (emacs-version) "\n" emacs-copyright "\n\n")
1937
1938 (insert "To follow a link, click Mouse-1 on it, or move to it and type RET.\n\n")
1939
1940 (insert-button "Authors"
1941 'action
1942 (lambda (button)
1943 (view-file (expand-file-name "AUTHORS" data-directory))
1944 (goto-char (point-min)))
1945 'follow-link t)
1946 (insert "\t\tMany people have contributed code included in GNU Emacs\n")
1947
1948 (insert-button "Contributing"
1949 'action
1950 (lambda (button)
1951 (view-file (expand-file-name "CONTRIBUTE" data-directory))
1952 (goto-char (point-min)))
1953 'follow-link t)
1954 (insert "\tHow to contribute improvements to Emacs\n\n")
1955
1956 (insert-button "GNU and Freedom"
1957 'action (lambda (button) (describe-gnu-project))
1958 'follow-link t)
1959 (insert "\t\tWhy we developed GNU Emacs and the GNU system\n")
1960
1961 (insert-button "Absence of Warranty"
1962 'action (lambda (button) (describe-no-warranty))
1963 'follow-link t)
1964 (insert "\tGNU Emacs comes with ABSOLUTELY NO WARRANTY\n")
1965
1966 (insert-button "Copying Conditions"
1967 'action (lambda (button) (describe-copying))
1968 'follow-link t)
1969 (insert "\tConditions for redistributing and changing Emacs\n")
1970
1971 (insert-button "Getting New Versions"
1972 'action (lambda (button) (describe-distribution))
1973 'follow-link t)
1974 (insert "\tHow to get the latest version of GNU Emacs\n")
1975
1976 (insert-button "More Manuals / Ordering Manuals"
1977 'action (lambda (button) (view-order-manuals))
1978 'follow-link t)
1979 (insert "\tBuying printed manuals from the FSF\n"))
1980
1981 (defun startup-echo-area-message ()
1982 (if (eq (key-binding "\C-h\C-a") 'about-emacs)
1983 "For information about GNU Emacs and the GNU system, type C-h C-a."
1984 (substitute-command-keys
1985 "For information about GNU Emacs and the GNU system, type \
1986 \\[about-emacs].")))
1987
1988
1989 (defun display-startup-echo-area-message ()
1990 (let ((resize-mini-windows t))
1991 (or noninteractive ;(input-pending-p) init-file-had-error
1992 ;; t if the init file says to inhibit the echo area startup message.
1993 (and inhibit-startup-echo-area-message
1994 user-init-file
1995 (or (and (get 'inhibit-startup-echo-area-message 'saved-value)
1996 (equal inhibit-startup-echo-area-message
1997 (if (equal init-file-user "")
1998 (user-login-name)
1999 init-file-user)))
2000 ;; Wasn't set with custom; see if .emacs has a setq.
2001 (let ((buffer (get-buffer-create " *temp*")))
2002 (prog1
2003 (condition-case nil
2004 (save-excursion
2005 (set-buffer buffer)
2006 (insert-file-contents user-init-file)
2007 (re-search-forward
2008 (concat
2009 "([ \t\n]*setq[ \t\n]+"
2010 "inhibit-startup-echo-area-message[ \t\n]+"
2011 (regexp-quote
2012 (prin1-to-string
2013 (if (equal init-file-user "")
2014 (user-login-name)
2015 init-file-user)))
2016 "[ \t\n]*)")
2017 nil t))
2018 (error nil))
2019 (kill-buffer buffer)))))
2020 (message "%s" (startup-echo-area-message)))))
2021
2022 (defun display-startup-screen (&optional concise)
2023 "Display startup screen according to display.
2024 A fancy display is used on graphic displays, normal otherwise.
2025
2026 If CONCISE is non-nil, display a concise version of the startup
2027 screen."
2028 ;; Prevent recursive calls from server-process-filter.
2029 (if (not (get-buffer "*GNU Emacs*"))
2030 (if (use-fancy-splash-screens-p)
2031 (fancy-startup-screen concise)
2032 (normal-splash-screen t concise))))
2033
2034 (defun display-about-screen ()
2035 "Display the *About GNU Emacs* buffer.
2036 A fancy display is used on graphic displays, normal otherwise."
2037 (interactive)
2038 (if (use-fancy-splash-screens-p)
2039 (fancy-about-screen)
2040 (normal-splash-screen nil)))
2041
2042 (defalias 'about-emacs 'display-about-screen)
2043 (defalias 'display-splash-screen 'display-startup-screen)
2044
2045 (defun command-line-1 (command-line-args-left)
2046 (display-startup-echo-area-message)
2047 (when (and pure-space-overflow
2048 (not noninteractive))
2049 (display-warning
2050 'initialization
2051 "Building Emacs overflowed pure space.\
2052 (See the node Pure Storage in the Lisp manual for details.)"
2053 :warning))
2054
2055 (let ((file-count 0)
2056 first-file-buffer)
2057 (when command-line-args-left
2058 ;; We have command args; process them.
2059 (let ((dir command-line-default-directory)
2060 tem
2061 ;; This approach loses for "-batch -L DIR --eval "(require foo)",
2062 ;; if foo is intended to be found in DIR.
2063 ;;
2064 ;; ;; The directories listed in --directory/-L options will *appear*
2065 ;; ;; at the front of `load-path' in the order they appear on the
2066 ;; ;; command-line. We cannot do this by *placing* them at the front
2067 ;; ;; in the order they appear, so we need this variable to hold them,
2068 ;; ;; temporarily.
2069 ;; extra-load-path
2070 ;;
2071 ;; To DTRT we keep track of the splice point and modify `load-path'
2072 ;; straight away upon any --directory/-L option.
2073 splice
2074 just-files ;; t if this follows the magic -- option.
2075 ;; This includes our standard options' long versions
2076 ;; and long versions of what's on command-switch-alist.
2077 (longopts
2078 (append '(("--funcall") ("--load") ("--insert") ("--kill")
2079 ("--directory") ("--eval") ("--execute") ("--no-splash")
2080 ("--find-file") ("--visit") ("--file") ("--no-desktop"))
2081 (mapcar (lambda (elt)
2082 (list (concat "-" (car elt))))
2083 command-switch-alist)))
2084 (line 0)
2085 (column 0))
2086
2087 ;; Add the long X options to longopts.
2088 (dolist (tem command-line-x-option-alist)
2089 (if (string-match "^--" (car tem))
2090 (push (list (car tem)) longopts)))
2091
2092 ;; Add the long NS options to longopts.
2093 (dolist (tem command-line-ns-option-alist)
2094 (if (string-match "^--" (car tem))
2095 (push (list (car tem)) longopts)))
2096
2097 ;; Loop, processing options.
2098 (while command-line-args-left
2099 (let* ((argi (car command-line-args-left))
2100 (orig-argi argi)
2101 argval completion)
2102 (setq command-line-args-left (cdr command-line-args-left))
2103
2104 ;; Do preliminary decoding of the option.
2105 (if just-files
2106 ;; After --, don't look for options; treat all args as files.
2107 (setq argi "")
2108 ;; Convert long options to ordinary options
2109 ;; and separate out an attached option argument into argval.
2110 (when (string-match "^\\(--[^=]*\\)=" argi)
2111 (setq argval (substring argi (match-end 0))
2112 argi (match-string 1 argi)))
2113 (if (equal argi "--")
2114 (setq completion nil)
2115 (setq completion (try-completion argi longopts)))
2116 (if (eq completion t)
2117 (setq argi (substring argi 1))
2118 (if (stringp completion)
2119 (let ((elt (assoc completion longopts)))
2120 (or elt
2121 (error "Option `%s' is ambiguous" argi))
2122 (setq argi (substring (car elt) 1)))
2123 (setq argval nil
2124 argi orig-argi))))
2125
2126 ;; Execute the option.
2127 (cond ((setq tem (assoc argi command-switch-alist))
2128 (if argval
2129 (let ((command-line-args-left
2130 (cons argval command-line-args-left)))
2131 (funcall (cdr tem) argi))
2132 (funcall (cdr tem) argi)))
2133
2134 ((equal argi "-no-splash")
2135 (setq inhibit-startup-screen t))
2136
2137 ((member argi '("-f" ; what the manual claims
2138 "-funcall"
2139 "-e")) ; what the source used to say
2140 (setq inhibit-startup-screen t)
2141 (setq tem (intern (or argval (pop command-line-args-left))))
2142 (if (commandp tem)
2143 (command-execute tem)
2144 (funcall tem)))
2145
2146 ((member argi '("-eval" "-execute"))
2147 (setq inhibit-startup-screen t)
2148 (eval (read (or argval (pop command-line-args-left)))))
2149
2150 ((member argi '("-L" "-directory"))
2151 (setq tem (expand-file-name
2152 (command-line-normalize-file-name
2153 (or argval (pop command-line-args-left)))))
2154 (cond (splice (setcdr splice (cons tem (cdr splice)))
2155 (setq splice (cdr splice)))
2156 (t (setq load-path (cons tem load-path)
2157 splice load-path))))
2158
2159 ((member argi '("-l" "-load"))
2160 (let* ((file (command-line-normalize-file-name
2161 (or argval (pop command-line-args-left))))
2162 ;; Take file from default dir if it exists there;
2163 ;; otherwise let `load' search for it.
2164 (file-ex (expand-file-name file)))
2165 (when (file-exists-p file-ex)
2166 (setq file file-ex))
2167 (load file nil t)))
2168
2169 ;; This is used to handle -script. It's not clear
2170 ;; we need to document it (it is totally internal).
2171 ((member argi '("-scriptload"))
2172 (let* ((file (command-line-normalize-file-name
2173 (or argval (pop command-line-args-left))))
2174 ;; Take file from default dir.
2175 (file-ex (expand-file-name file)))
2176 (load file-ex nil t t)))
2177
2178 ((equal argi "-insert")
2179 (setq inhibit-startup-screen t)
2180 (setq tem (or argval (pop command-line-args-left)))
2181 (or (stringp tem)
2182 (error "File name omitted from `-insert' option"))
2183 (insert-file-contents (command-line-normalize-file-name tem)))
2184
2185 ((equal argi "-kill")
2186 (kill-emacs t))
2187
2188 ;; This is for when they use --no-desktop with -q, or
2189 ;; don't load Desktop in their .emacs. If desktop.el
2190 ;; _is_ loaded, it will handle this switch, and we
2191 ;; won't see it by the time we get here.
2192 ((equal argi "-no-desktop")
2193 (message "\"--no-desktop\" ignored because the Desktop package is not loaded"))
2194
2195 ((string-match "^\\+[0-9]+\\'" argi)
2196 (setq line (string-to-number argi)))
2197
2198 ((string-match "^\\+\\([0-9]+\\):\\([0-9]+\\)\\'" argi)
2199 (setq line (string-to-number (match-string 1 argi))
2200 column (string-to-number (match-string 2 argi))))
2201
2202 ((setq tem (assoc argi command-line-x-option-alist))
2203 ;; Ignore X-windows options and their args if not using X.
2204 (setq command-line-args-left
2205 (nthcdr (nth 1 tem) command-line-args-left)))
2206
2207 ((setq tem (assoc argi command-line-ns-option-alist))
2208 ;; Ignore NS-windows options and their args if not using NS.
2209 (setq command-line-args-left
2210 (nthcdr (nth 1 tem) command-line-args-left)))
2211
2212 ((member argi '("-find-file" "-file" "-visit"))
2213 (setq inhibit-startup-screen t)
2214 ;; An explicit option to specify visiting a file.
2215 (setq tem (or argval (pop command-line-args-left)))
2216 (unless (stringp tem)
2217 (error "File name omitted from `%s' option" argi))
2218 (setq file-count (1+ file-count))
2219 (let ((file (expand-file-name
2220 (command-line-normalize-file-name tem) dir)))
2221 (if (= file-count 1)
2222 (setq first-file-buffer (find-file file))
2223 (find-file-other-window file)))
2224 (or (zerop line)
2225 (goto-line line))
2226 (setq line 0)
2227 (unless (< column 1)
2228 (move-to-column (1- column)))
2229 (setq column 0))
2230
2231 ((equal argi "--")
2232 (setq just-files t))
2233 (t
2234 ;; We have almost exhausted our options. See if the
2235 ;; user has made any other command-line options available
2236 (let ((hooks command-line-functions)
2237 (did-hook nil))
2238 (while (and hooks
2239 (not (setq did-hook (funcall (car hooks)))))
2240 (setq hooks (cdr hooks)))
2241 (if (not did-hook)
2242 ;; Presume that the argument is a file name.
2243 (progn
2244 (if (string-match "\\`-" argi)
2245 (error "Unknown option `%s'" argi))
2246 (unless initial-window-system
2247 (setq inhibit-startup-screen t))
2248 (setq file-count (1+ file-count))
2249 (let ((file
2250 (expand-file-name
2251 (command-line-normalize-file-name orig-argi)
2252 dir)))
2253 (cond ((= file-count 1)
2254 (setq first-file-buffer (find-file file)))
2255 (inhibit-startup-screen
2256 (find-file-other-window file))
2257 (t (find-file file))))
2258 (or (zerop line)
2259 (goto-line line))
2260 (setq line 0)
2261 (unless (< column 1)
2262 (move-to-column (1- column)))
2263 (setq column 0))))))
2264 ;; In unusual circumstances, the execution of Lisp code due
2265 ;; to command-line options can cause the last visible frame
2266 ;; to be deleted. In this case, kill emacs to avoid an
2267 ;; abort later.
2268 (unless (frame-live-p (selected-frame)) (kill-emacs nil))))))
2269
2270 (when initial-buffer-choice
2271 (cond ((eq initial-buffer-choice t)
2272 (switch-to-buffer (get-buffer-create "*scratch*")))
2273 ((stringp initial-buffer-choice)
2274 (find-file initial-buffer-choice))))
2275
2276 ;; If *scratch* exists and is empty, insert initial-scratch-message.
2277 (and initial-scratch-message
2278 (get-buffer "*scratch*")
2279 (with-current-buffer "*scratch*"
2280 (when (zerop (buffer-size))
2281 (insert initial-scratch-message)
2282 (set-buffer-modified-p nil))))
2283
2284 (if (or inhibit-startup-screen
2285 initial-buffer-choice
2286 noninteractive
2287 emacs-quick-startup)
2288
2289 ;; Not displaying a startup screen. If 3 or more files
2290 ;; visited, and not all visible, show user what they all are.
2291 (and (> file-count 2)
2292 (not noninteractive)
2293 (not inhibit-startup-buffer-menu)
2294 (or (get-buffer-window first-file-buffer)
2295 (list-buffers)))
2296
2297 ;; Display a startup screen, after some preparations.
2298
2299 ;; If there are no switches to process, we might as well
2300 ;; run this hook now, and there may be some need to do it
2301 ;; before doing any output.
2302 (run-hooks 'emacs-startup-hook)
2303 (and term-setup-hook
2304 (run-hooks 'term-setup-hook))
2305 (setq inhibit-startup-hooks t)
2306
2307 ;; It's important to notice the user settings before we
2308 ;; display the startup message; otherwise, the settings
2309 ;; won't take effect until the user gives the first
2310 ;; keystroke, and that's distracting.
2311 (when (fboundp 'frame-notice-user-settings)
2312 (frame-notice-user-settings))
2313
2314 ;; If there are no switches to process, we might as well
2315 ;; run this hook now, and there may be some need to do it
2316 ;; before doing any output.
2317 (when window-setup-hook
2318 (run-hooks 'window-setup-hook)
2319 ;; Don't let the hook be run twice.
2320 (setq window-setup-hook nil))
2321
2322 ;; ;; Do this now to avoid an annoying delay if the user
2323 ;; ;; clicks the menu bar during the sit-for.
2324 ;; (when (display-popup-menus-p)
2325 ;; (precompute-menubar-bindings))
2326 ;; (with-no-warnings
2327 ;; (setq menubar-bindings-done t))
2328
2329 (if (> file-count 0)
2330 (display-startup-screen t)
2331 (display-startup-screen nil)))))
2332
2333 (defun command-line-normalize-file-name (file)
2334 "Collapse multiple slashes to one, to handle non-Emacs file names."
2335 (save-match-data
2336 ;; Use arg 1 so that we don't collapse // at the start of the file name.
2337 ;; That is significant on some systems.
2338 ;; However, /// at the beginning is supposed to mean just /, not //.
2339 (if (string-match "^///+" file)
2340 (setq file (replace-match "/" t t file)))
2341 (while (string-match "//+" file 1)
2342 (setq file (replace-match "/" t t file)))
2343 file))
2344
2345 ;; arch-tag: 7e294698-244d-4758-984b-4047f887a5db
2346 ;;; startup.el ends here