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