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