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