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