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