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