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