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