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