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