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