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