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