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