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