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