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