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