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