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