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