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