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