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