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