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