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