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