1 ;;; startup.el --- process Emacs shell arguments -*- lexical-binding: t -*-
3 ;; Copyright (C) 1985-1986, 1992, 1994-2012 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, visit the specified file
45 or directory using `find-file'. If t, open the `*scratch*'
48 (const :tag
"Startup screen" nil
)
49 (directory :tag
"Directory" :value
"~/")
50 (file :tag
"File" :value
"~/.emacs")
51 (const :tag
"Lisp scratch buffer" t
))
53 :group
'initialization
)
55 (defcustom inhibit-startup-screen nil
56 "Non-nil inhibits the startup screen.
58 This is for use in your personal init file (but NOT site-start.el),
59 once you are familiar with the contents of the startup screen."
61 :group
'initialization
)
63 (defvaralias 'inhibit-splash-screen
'inhibit-startup-screen
)
64 (defvaralias 'inhibit-startup-message
'inhibit-startup-screen
)
66 (defvar startup-screen-inhibit-startup-screen nil
)
68 ;; FIXME? Why does this get such weirdly extreme treatment, when the
69 ;; more important inhibit-startup-screen does not.
70 (defcustom inhibit-startup-echo-area-message nil
71 "Non-nil inhibits the initial startup echo area message.
72 Setting this variable takes effect
73 only if you do it with the customization buffer
74 or if your `.emacs' file contains a line of this form:
75 (setq inhibit-startup-echo-area-message \"YOUR-USER-NAME\")
76 If your `.emacs' file is byte-compiled, use the following form instead:
77 (eval '(setq inhibit-startup-echo-area-message \"YOUR-USER-NAME\"))
78 Thus, someone else using a copy of your `.emacs' file will see
79 the startup message unless he personally acts to inhibit it."
80 :type
'(choice (const :tag
"Don't inhibit")
81 (string :tag
"Enter your user name, to inhibit"))
82 :group
'initialization
)
84 (defcustom inhibit-default-init nil
85 "Non-nil inhibits loading the `default' library."
87 :group
'initialization
)
89 (defcustom inhibit-startup-buffer-menu nil
90 "Non-nil inhibits display of buffer list when more than 2 files are loaded."
92 :group
'initialization
)
94 (defvar command-switch-alist nil
95 "Alist of command-line switches.
96 Elements look like (SWITCH-STRING . HANDLER-FUNCTION).
97 HANDLER-FUNCTION receives the switch string as its sole argument;
98 the remaining command-line args are in the variable `command-line-args-left'.")
100 (defvar command-line-args-left nil
101 "List of command-line args not yet processed.")
103 (defvaralias 'argv
'command-line-args-left
104 ;; FIXME: Bad name for a dynamically bound variable.
105 "List of command-line args not yet processed.
106 This is a convenience alias, so that one can write \(pop argv\)
107 inside of --eval command line arguments in order to access
108 following arguments.")
111 ;; FIXME: Bad name for a dynamically bound variable
113 "Current command-line argument."))
115 (defvar command-line-functions nil
;; lrs 7/31/89
116 "List of functions to process unrecognized command-line arguments.
117 Each function should access the dynamically bound variables
118 `argi' (the current argument) and `command-line-args-left' (the remaining
119 arguments). The function should return non-nil only if it recognizes and
120 processes `argi'. If it does so, it may consume successive arguments by
121 altering `command-line-args-left' to remove them.")
123 (defvar command-line-default-directory nil
124 "Default directory to use for command line arguments.
125 This is normally copied from `default-directory' when Emacs starts.")
127 ;;; This is here, rather than in x-win.el, so that we can ignore these
128 ;;; options when we are not using X.
129 (defconst command-line-x-option-alist
130 '(("-bw" 1 x-handle-numeric-switch border-width
)
131 ("-d" 1 x-handle-display
)
132 ("-display" 1 x-handle-display
)
133 ("-name" 1 x-handle-name-switch
)
134 ("-title" 1 x-handle-switch title
)
135 ("-T" 1 x-handle-switch title
)
136 ("-r" 0 x-handle-switch reverse t
)
137 ("-rv" 0 x-handle-switch reverse t
)
138 ("-reverse" 0 x-handle-switch reverse t
)
139 ("-reverse-video" 0 x-handle-switch reverse t
)
140 ("-fn" 1 x-handle-switch font
)
141 ("-font" 1 x-handle-switch font
)
142 ("-fs" 0 x-handle-initial-switch fullscreen fullboth
)
143 ("-fw" 0 x-handle-initial-switch fullscreen fullwidth
)
144 ("-fh" 0 x-handle-initial-switch fullscreen fullheight
)
145 ("-mm" 0 x-handle-initial-switch fullscreen maximized
)
146 ("-ib" 1 x-handle-numeric-switch internal-border-width
)
147 ("-g" 1 x-handle-geometry
)
148 ("-lsp" 1 x-handle-numeric-switch line-spacing
)
149 ("-geometry" 1 x-handle-geometry
)
150 ("-fg" 1 x-handle-switch foreground-color
)
151 ("-foreground" 1 x-handle-switch foreground-color
)
152 ("-bg" 1 x-handle-switch background-color
)
153 ("-background" 1 x-handle-switch background-color
)
154 ("-ms" 1 x-handle-switch mouse-color
)
155 ("-nbi" 0 x-handle-switch icon-type nil
)
156 ("-iconic" 0 x-handle-iconic
)
157 ("-xrm" 1 x-handle-xrm-switch
)
158 ("-cr" 1 x-handle-switch cursor-color
)
159 ("-vb" 0 x-handle-switch vertical-scroll-bars t
)
160 ("-hb" 0 x-handle-switch horizontal-scroll-bars t
)
161 ("-bd" 1 x-handle-switch
)
162 ("--border-width" 1 x-handle-numeric-switch border-width
)
163 ("--display" 1 x-handle-display
)
164 ("--name" 1 x-handle-name-switch
)
165 ("--title" 1 x-handle-switch title
)
166 ("--reverse-video" 0 x-handle-switch reverse t
)
167 ("--font" 1 x-handle-switch font
)
168 ("--fullscreen" 0 x-handle-initial-switch fullscreen fullboth
)
169 ("--fullwidth" 0 x-handle-initial-switch fullscreen fullwidth
)
170 ("--fullheight" 0 x-handle-initial-switch fullscreen fullheight
)
171 ("--maximized" 0 x-handle-initial-switch fullscreen maximized
)
172 ("--internal-border" 1 x-handle-numeric-switch internal-border-width
)
173 ("--geometry" 1 x-handle-geometry
)
174 ("--foreground-color" 1 x-handle-switch foreground-color
)
175 ("--background-color" 1 x-handle-switch background-color
)
176 ("--mouse-color" 1 x-handle-switch mouse-color
)
177 ("--no-bitmap-icon" 0 x-handle-no-bitmap-icon
)
178 ("--iconic" 0 x-handle-iconic
)
179 ("--xrm" 1 x-handle-xrm-switch
)
180 ("--cursor-color" 1 x-handle-switch cursor-color
)
181 ("--vertical-scroll-bars" 0 x-handle-switch vertical-scroll-bars t
)
182 ("--line-spacing" 1 x-handle-numeric-switch line-spacing
)
183 ("--border-color" 1 x-handle-switch border-color
)
184 ("--smid" 1 x-handle-smid
)
185 ("--parent-id" 1 x-handle-parent-id
))
186 "Alist of X Windows options.
187 Each element has the form
188 (NAME NUMARGS HANDLER FRAME-PARAM VALUE)
189 where NAME is the option name string, NUMARGS is the number of arguments
190 that the option accepts, HANDLER is a function to call to handle the option.
191 FRAME-PARAM (optional) is the frame parameter this option specifies,
192 and VALUE is the value which is given to that frame parameter
193 \(most options use the argument for this, so VALUE is not present).")
195 (defconst command-line-ns-option-alist
196 '(("-NSAutoLaunch" 1 ns-ignore-1-arg
)
197 ("-NXAutoLaunch" 1 ns-ignore-1-arg
)
199 ("-NSHost" 1 ns-ignore-1-arg
)
200 ("-_NSMachLaunch" 1 ns-ignore-1-arg
)
201 ("-MachLaunch" 1 ns-ignore-1-arg
)
202 ("-NXOpen" 1 ns-ignore-1-arg
)
203 ("-NSOpen" 1 ns-handle-nxopen
)
204 ("-NXOpenTemp" 1 ns-ignore-1-arg
)
205 ("-NSOpenTemp" 1 ns-handle-nxopentemp
)
206 ("-GSFilePath" 1 ns-handle-nxopen
)
207 ;;("-bw" . x-handle-numeric-switch)
208 ;;("-d" . x-handle-display)
209 ;;("-display" . x-handle-display)
210 ("-name" 1 x-handle-name-switch
)
211 ("-title" 1 x-handle-switch title
)
212 ("-T" 1 x-handle-switch title
)
213 ("-r" 0 x-handle-switch reverse t
)
214 ("-rv" 0 x-handle-switch reverse t
)
215 ("-reverse" 0 x-handle-switch reverse t
)
216 ("-fn" 1 x-handle-switch font
)
217 ("-font" 1 x-handle-switch font
)
218 ("-ib" 1 x-handle-numeric-switch internal-border-width
)
219 ;;("-g" . x-handle-geometry)
220 ;;("-geometry" . x-handle-geometry)
221 ("-fg" 1 x-handle-switch foreground-color
)
222 ("-foreground" 1 x-handle-switch foreground-color
)
223 ("-bg" 1 x-handle-switch background-color
)
224 ("-background" 1 x-handle-switch background-color
)
225 ; ("-ms" 1 x-handle-switch mouse-color)
226 ("-itype" 0 x-handle-switch icon-type t
)
227 ("-i" 0 x-handle-switch icon-type t
)
228 ("-iconic" 0 x-handle-iconic icon-type t
)
229 ;;("-xrm" . x-handle-xrm-switch)
230 ("-cr" 1 x-handle-switch cursor-color
)
231 ("-vb" 0 x-handle-switch vertical-scroll-bars t
)
232 ("-hb" 0 x-handle-switch horizontal-scroll-bars t
)
233 ("-bd" 1 x-handle-switch
)
234 ;; ("--border-width" 1 x-handle-numeric-switch border-width)
235 ;; ("--display" 1 ns-handle-display)
236 ("--name" 1 x-handle-name-switch
)
237 ("--title" 1 x-handle-switch title
)
238 ("--reverse-video" 0 x-handle-switch reverse t
)
239 ("--font" 1 x-handle-switch font
)
240 ("--internal-border" 1 x-handle-numeric-switch internal-border-width
)
241 ;; ("--geometry" 1 ns-handle-geometry)
242 ("--foreground-color" 1 x-handle-switch foreground-color
)
243 ("--background-color" 1 x-handle-switch background-color
)
244 ("--mouse-color" 1 x-handle-switch mouse-color
)
245 ("--icon-type" 0 x-handle-switch icon-type t
)
246 ("--iconic" 0 x-handle-iconic
)
247 ;; ("--xrm" 1 ns-handle-xrm-switch)
248 ("--cursor-color" 1 x-handle-switch cursor-color
)
249 ("--vertical-scroll-bars" 0 x-handle-switch vertical-scroll-bars t
)
250 ("--border-color" 1 x-handle-switch border-width
))
251 "Alist of NS options.
252 Each element has the form
253 (NAME NUMARGS HANDLER FRAME-PARAM VALUE)
254 where NAME is the option name string, NUMARGS is the number of arguments
255 that the option accepts, HANDLER is a function to call to handle the option.
256 FRAME-PARAM (optional) is the frame parameter this option specifies,
257 and VALUE is the value which is given to that frame parameter
258 \(most options use the argument for this, so VALUE is not present).")
261 (defvar before-init-hook nil
262 "Normal hook run after handling urgent options but before loading init files.")
264 (defvar after-init-hook nil
265 "Normal hook run after loading the init files, `~/.emacs' and `default.el'.
266 There is no `condition-case' around the running of these functions;
267 therefore, if you set `debug-on-error' non-nil in `.emacs',
268 an error in one of these functions will invoke the debugger.")
270 (defvar emacs-startup-hook nil
271 "Normal hook run after loading init files and handling the command line.")
273 (defvar term-setup-hook nil
274 "Normal hook run after loading terminal-specific Lisp code.
275 It also follows `emacs-startup-hook'. This hook exists for users to set,
276 so as to override the definitions made by the terminal-specific file.
277 Emacs never sets this variable itself.")
279 (defvar inhibit-startup-hooks nil
280 "Non-nil means don't run `term-setup-hook' and `emacs-startup-hook'.
281 This is because we already did so.")
283 (defvar keyboard-type nil
284 "The brand of keyboard you are using.
285 This variable is used to define the proper function and keypad
286 keys for use under X. It is used in a fashion analogous to the
287 environment variable TERM.")
289 (defvar window-setup-hook nil
290 "Normal hook run to initialize window system display.
291 Emacs runs this hook after processing the command line arguments and loading
292 the user's init file.")
294 (defcustom initial-major-mode
'lisp-interaction-mode
295 "Major mode command symbol to use for the initial `*scratch*' buffer."
297 :group
'initialization
)
299 (defvar init-file-user nil
300 "Identity of user whose `.emacs' file is or was read.
301 The value is nil if `-q' or `--no-init-file' was specified,
302 meaning do not load any init file.
304 Otherwise, the value may be an empty string, meaning
305 use the init file for the user who originally logged in,
306 or it may be a string containing a user's name meaning
307 use that person's init file.
309 In either of the latter cases, `(concat \"~\" init-file-user \"/\")'
310 evaluates to the name of the directory where the `.emacs' file was
313 Setting `init-file-user' does not prevent Emacs from loading
314 `site-start.el'. The only way to do that is to use `--no-site-file'.")
316 (defcustom site-run-file
(purecopy "site-start")
317 "File containing site-wide run-time initializations.
318 This file is loaded at run-time before `~/.emacs'. It contains inits
319 that need to be in place for the entire site, but which, due to their
320 higher incidence of change, don't make sense to load into Emacs's
321 dumped image. Thus, the run-time load order is: 1. file described in
322 this variable, if non-nil; 2. `~/.emacs'; 3. `default.el'.
324 Don't use the `site-start.el' file for things some users may not like.
325 Put them in `default.el' instead, so that users can more easily
326 override them. Users can prevent loading `default.el' with the `-q'
327 option or by setting `inhibit-default-init' in their own init files,
328 but inhibiting `site-start.el' requires `--no-site-file', which
331 This variable is defined for customization so as to make
332 it visible in the relevant context. However, actually customizing it
333 is not allowed, since it would not work anyway. The only way to set
334 this variable usefully is to set it while building and dumping Emacs."
335 :type
'(choice (const :tag
"none" nil
) string
)
336 :group
'initialization
337 :initialize
'custom-initialize-default
338 :set
(lambda (_variable _value
)
339 (error "Customizing `site-run-file' does not work")))
341 (defcustom mail-host-address nil
342 "Name of this machine, for purposes of naming users.
343 If non-nil, Emacs uses this instead of `system-name' when constructing
345 :type
'(choice (const nil
) string
)
348 (defcustom user-mail-address
(if command-line-processed
350 (concat (user-login-name) "@"
351 (or mail-host-address
353 ;; Empty string means "not set yet".
355 "Full mailing address of this user.
356 This is initialized with environment variable `EMAIL' or, as a
357 fallback, using `mail-host-address'. This is done after your
358 init file is read, in case it sets `mail-host-address'."
362 (defcustom auto-save-list-file-prefix
363 (cond ((eq system-type
'ms-dos
)
364 ;; MS-DOS cannot have initial dot, and allows only 8.3 names
365 (concat user-emacs-directory
"auto-save.list/_s"))
367 (concat user-emacs-directory
"auto-save-list/.saves-")))
368 "Prefix for generating `auto-save-list-file-name'.
369 This is used after reading your `.emacs' file to initialize
370 `auto-save-list-file-name', by appending Emacs's pid and the system name,
371 if you have not already set `auto-save-list-file-name' yourself.
372 Directories in the prefix will be created if necessary.
373 Set this to nil if you want to prevent `auto-save-list-file-name'
374 from being initialized."
375 :type
'(choice (const :tag
"Don't record a session's auto save list" nil
)
379 (defvar emacs-basic-display nil
)
381 (defvar init-file-debug nil
)
383 (defvar init-file-had-error nil
384 "Non-nil if there was an error loading the user's init file.")
386 (defvar normal-top-level-add-subdirs-inode-list nil
)
388 (defvar no-blinking-cursor nil
)
390 (defvar default-frame-background-mode
)
392 (defvar pure-space-overflow nil
393 "Non-nil if building Emacs overflowed pure space.")
395 (defvar pure-space-overflow-message
(purecopy "\
396 Warning Warning!!! Pure space overflow !!!Warning Warning
397 \(See the node Pure Storage in the Lisp manual for details.)\n"))
399 (defcustom tutorial-directory
400 (file-name-as-directory (expand-file-name "tutorials" data-directory
))
401 "Directory containing the Emacs TUTORIAL files."
404 :initialize
'custom-initialize-delay
)
406 (defconst package-subdirectory-regexp
407 "\\([^.].*?\\)-\\([0-9]+\\(?:[.][0-9]+\\|\\(?:pre\\|beta\\|alpha\\)[0-9]+\\)*\\)"
408 "Regular expression matching the name of a package subdirectory.
409 The first subexpression is the package name.
410 The second subexpression is the version string.
412 The regexp should not contain a starting \"\\`\" or a trailing
413 \"\\'\"; those are added automatically by callers.")
415 (defun normal-top-level-add-subdirs-to-load-path ()
416 "Add all subdirectories of `default-directory' to `load-path'.
417 More precisely, this uses only the subdirectories whose names
418 start with letters or digits; it excludes any subdirectory named `RCS'
419 or `CVS', and any subdirectory that contains a file named `.nosearch'."
422 (pending (list default-directory
)))
423 ;; This loop does a breadth-first tree walk on DIR's subtree,
424 ;; putting each subdir into DIRS as its contents are examined.
426 (push (pop pending
) dirs
)
427 (let* ((this-dir (car dirs
))
428 (contents (directory-files this-dir
))
429 (default-directory this-dir
)
430 (canonicalized (if (fboundp 'untranslated-canonical-name
)
431 (untranslated-canonical-name this-dir
))))
432 ;; The Windows version doesn't report meaningful inode numbers, so
433 ;; use the canonicalized absolute file name of the directory instead.
434 (setq attrs
(or canonicalized
435 (nthcdr 10 (file-attributes this-dir
))))
436 (unless (member attrs normal-top-level-add-subdirs-inode-list
)
437 (push attrs normal-top-level-add-subdirs-inode-list
)
438 (dolist (file contents
)
439 (and (string-match "\\`[[:alnum:]]" file
)
440 ;; The lower-case variants of RCS and CVS are for DOS/Windows.
441 (not (member file
'("RCS" "CVS" "rcs" "cvs")))
442 ;; Avoid doing a `stat' when it isn't necessary because
443 ;; that can cause trouble when an NFS server is down.
444 (not (string-match "\\.elc?\\'" file
))
445 (file-directory-p file
)
446 (let ((expanded (expand-file-name file
)))
447 (or (file-exists-p (expand-file-name ".nosearch" expanded
))
448 (setq pending
(nconc pending
(list expanded
))))))))))
449 (normal-top-level-add-to-load-path (cdr (nreverse dirs
)))))
451 (defun normal-top-level-add-to-load-path (dirs)
452 "This function is called from a subdirs.el file.
453 It assumes that `default-directory' is the directory in which the
454 subdirs.el file exists, and it adds to `load-path' the subdirs of
455 that directory as specified in DIRS. Normally the elements of
457 (let ((tail load-path
)
458 (thisdir (directory-file-name default-directory
)))
460 ;;Don't go all the way to the nil terminator.
462 (not (equal thisdir
(car tail
)))
463 (not (and (memq system-type
'(ms-dos windows-nt
))
464 (equal (downcase thisdir
) (downcase (car tail
))))))
465 (setq tail
(cdr tail
)))
466 ;;Splice the new section in.
468 (setcdr tail
(append (mapcar 'expand-file-name dirs
) (cdr tail
))))))
470 (defun normal-top-level ()
471 "Emacs calls this function when it first starts up.
472 It sets `command-line-processed', processes the command-line,
473 reads the initialization files, etc.
474 It is the default value of the variable `top-level'."
475 (if command-line-processed
476 (message "Back to top level.")
477 (setq command-line-processed t
)
478 (let ((dir default-directory
))
479 (with-current-buffer "*Messages*"
480 ;; Make it easy to do like "tail -f".
481 (set (make-local-variable 'window-point-insertion-type
) t
)
482 ;; Give *Messages* the same default-directory as *scratch*,
483 ;; just to keep things predictable.
484 (setq default-directory dir
)))
485 ;; `user-full-name' is now known; reset its standard-value here.
486 (put 'user-full-name
'standard-value
487 (list (default-value 'user-full-name
)))
488 ;; Look in each dir in load-path for a subdirs.el file.
489 ;; If we find one, load it, which will add the appropriate subdirs
490 ;; of that dir into load-path,
491 ;; Look for a leim-list.el file too. Loading it will register
492 ;; available input methods.
493 (let ((tail load-path
) dir
)
495 (setq dir
(car tail
))
496 (let ((default-directory dir
))
497 (load (expand-file-name "subdirs.el") t t t
))
498 (let ((default-directory dir
))
499 (load (expand-file-name "leim-list.el") t t t
))
500 ;; We don't use a dolist loop and we put this "setq-cdr" command at
501 ;; the end, because the subdirs.el files may add elements to the end
502 ;; of load-path and we want to take it into account.
503 (setq tail
(cdr tail
))))
504 ;; If the PWD environment variable isn't accurate, delete it.
505 (let ((pwd (getenv "PWD")))
507 ;; Use FOO/., so that if FOO is a symlink, file-attributes
508 ;; describes the directory linked to, not FOO itself.
509 (or (equal (file-attributes
510 (concat (file-name-as-directory pwd
) "."))
512 (concat (file-name-as-directory default-directory
)
514 (setq process-environment
515 (delete (concat "PWD=" pwd
)
516 process-environment
)))))
517 (setq default-directory
(abbreviate-file-name default-directory
))
518 (let ((old-face-font-rescale-alist face-font-rescale-alist
))
521 ;; Do this again, in case .emacs defined more abbreviations.
522 (setq default-directory
(abbreviate-file-name default-directory
))
523 ;; Specify the file for recording all the auto save files of this session.
524 ;; This is used by recover-session.
525 (or auto-save-list-file-name
526 (and auto-save-list-file-prefix
527 (setq auto-save-list-file-name
528 ;; Under MS-DOS our PID is almost always reused between
529 ;; Emacs invocations. We need something more unique.
530 (cond ((eq system-type
'ms-dos
)
531 ;; We are going to access the auto-save
532 ;; directory, so make sure it exists.
534 (file-name-directory auto-save-list-file-prefix
)
539 auto-save-list-file-prefix
))
544 auto-save-list-file-prefix
547 (unless inhibit-startup-hooks
548 (run-hooks 'emacs-startup-hook
)
550 (run-hooks 'term-setup-hook
)))
552 ;; Don't do this if we failed to create the initial frame,
553 ;; for instance due to a dense colormap.
554 (when (or frame-initial-frame
555 ;; If frame-initial-frame has no meaning, do this anyway.
556 (not (and initial-window-system
558 (not (eq initial-window-system
'pc
)))))
560 ;; FIXME: The user's init file may change
561 ;; face-font-rescale-alist. However, the default face
562 ;; already has an assigned font object, which does not take
563 ;; face-font-rescale-alist into account. For such
564 ;; situations, we ought to have a way to find all font
565 ;; objects and regenerate them; currently we do not. As a
566 ;; workaround, we specifically reset te default face's :font
567 ;; attribute here. See bug#1785.
568 (unless (eq face-font-rescale-alist
569 old-face-font-rescale-alist
)
570 (set-face-attribute 'default nil
:font
(font-spec)))
572 ;; Modify the initial frame based on what .emacs puts into
574 (if (fboundp 'frame-notice-user-settings
)
575 (frame-notice-user-settings))
576 ;; Set the faces for the initial background mode even if
577 ;; frame-notice-user-settings didn't (such as on a tty).
578 ;; frame-set-background-mode is idempotent, so it won't
579 ;; cause any harm if it's already been done.
580 (if (fboundp 'frame-set-background-mode
)
581 (frame-set-background-mode (selected-frame))))
583 ;; Now we know the user's default font, so add it to the menu.
584 (if (fboundp 'font-menu-add-default
)
585 (font-menu-add-default))
586 (and window-setup-hook
587 (run-hooks 'window-setup-hook
))))
588 ;; Subprocesses of Emacs do not have direct access to the terminal, so
589 ;; unless told otherwise they should only assume a dumb terminal.
590 ;; We are careful to do it late (after term-setup-hook), although the
591 ;; new multi-tty code does not use $TERM any more there anyway.
592 (setenv "TERM" "dumb")
593 ;; Remove DISPLAY from the process-environment as well. This allows
594 ;; `callproc.c' to give it a useful adaptive default which is either
595 ;; the value of the `display' frame-parameter or the DISPLAY value
596 ;; from initial-environment.
597 (let ((display (frame-parameter nil
'display
)))
598 ;; Be careful which DISPLAY to remove from process-environment: follow
599 ;; the logic of `callproc.c'.
600 (if (stringp display
) (setq display
(concat "DISPLAY=" display
))
601 (dolist (varval initial-environment
)
602 (if (string-match "\\`DISPLAY=" varval
)
603 (setq display varval
))))
605 (delete display process-environment
)))))
607 ;; Precompute the keyboard equivalents in the menu bar items.
608 ;; Command-line options supported by tty's:
609 (defconst tty-long-option-alist
610 '(("--name" .
"-name")
612 ("--reverse-video" .
"-reverse")
613 ("--foreground-color" .
"-fg")
614 ("--background-color" .
"-bg")
615 ("--color" .
"-color")))
617 (defconst tool-bar-images-pixel-height
24
618 "Height in pixels of images in the tool-bar.")
620 (defvar tool-bar-originally-present nil
621 "Non-nil if tool-bars are present before user and site init files are read.")
623 (defvar handle-args-function-alist
'((nil . tty-handle-args
))
624 "Functions for processing window-system dependent command-line arguments.
625 Window system startup files should add their own function to this
626 alist, which should parse the command line arguments. Those
627 pertaining to the window system should be processed and removed
628 from the returned command line.")
630 (defvar window-system-initialization-alist
'((nil . ignore
))
631 "Alist of window-system initialization functions.
632 Window-system startup files should add their own initialization
633 function to this list. The function should take no arguments,
634 and initialize the window system environment to prepare for
635 opening the first frame (e.g. open a connection to an X server).")
637 (defun tty-handle-args (args)
638 "Handle the X-like command-line arguments \"-fg\", \"-bg\", \"-name\", etc."
642 (not (equal (car args
) "--")))
643 (let* ((argi (pop args
))
646 ;; Check for long options with attached arguments
647 ;; and separate out the attached option argument into argval.
648 (when (string-match "^\\(--[^=]*\\)=" argi
)
649 (setq argval
(substring argi
(match-end 0))
650 argi
(match-string 1 argi
)))
651 (when (string-match "^--" argi
)
652 (setq completion
(try-completion argi tty-long-option-alist
))
653 (if (eq completion t
)
654 ;; Exact match for long option.
655 (setq argi
(cdr (assoc argi tty-long-option-alist
)))
656 (if (stringp completion
)
657 (let ((elt (assoc completion tty-long-option-alist
)))
658 ;; Check for abbreviated long option.
660 (error "Option `%s' is ambiguous" argi
))
661 (setq argi
(cdr elt
)))
662 ;; Check for a short option.
665 (cond ((member argi
'("-fg" "-foreground"))
666 (push (cons 'foreground-color
(or argval
(pop args
)))
667 default-frame-alist
))
668 ((member argi
'("-bg" "-background"))
669 (push (cons 'background-color
(or argval
(pop args
)))
670 default-frame-alist
))
671 ((member argi
'("-T" "-name"))
672 (unless argval
(setq argval
(pop args
)))
676 (let ((case-fold-search t
)
678 (setq argval
(invocation-name))
680 ;; Change any . or * characters in name to
681 ;; hyphens, so as to emulate behavior on X.
683 (setq i
(string-match "[.*]" argval
))
686 default-frame-alist
))
687 ((member argi
'("-r" "-rv" "-reverse"))
689 default-frame-alist
))
690 ((equal argi
"-color")
691 (unless argval
(setq argval
8)) ; default --color means 8 ANSI colors
692 (push (cons 'tty-color-mode
694 ((numberp argval
) argval
)
695 ((string-match "-?[0-9]+" argval
)
696 (string-to-number argval
))
697 (t (intern argval
))))
698 default-frame-alist
))
703 (declare-function x-get-resource
"frame.c"
704 (attribute class
&optional component subclass
))
705 (declare-function tool-bar-mode
"tool-bar" (&optional arg
))
706 (declare-function tool-bar-setup
"tool-bar")
709 (defvar server-process
)
711 (defun command-line ()
712 "A subroutine of `normal-top-level'.
713 Amongst another things, it parses the command-line arguments."
714 (setq before-init-time
(current-time)
716 command-line-default-directory default-directory
)
718 ;; Force recomputation, in case it was computed during the dump.
719 (setq abbreviated-home-dir nil
)
721 ;; See if we should import version-control from the environment variable.
722 (let ((vc (getenv "VERSION_CONTROL")))
723 (cond ((eq vc nil
)) ;don't do anything if not set
724 ((member vc
'("t" "numbered"))
725 (setq version-control t
))
726 ((member vc
'("nil" "existing"))
727 (setq version-control nil
))
728 ((member vc
'("never" "simple"))
729 (setq version-control
'never
))))
731 ;;! This has been commented out; I currently find the behavior when
732 ;;! split-window-keep-point is nil disturbing, but if I can get used
733 ;;! to it, then it would be better to eliminate the option.
734 ;;! ;; Choose a good default value for split-window-keep-point.
735 ;;! (setq split-window-keep-point (> baud-rate 2400))
737 ;; Set the default strings to display in mode line for
738 ;; end-of-line formats that aren't native to this platform.
740 ((memq system-type
'(ms-dos windows-nt
))
741 (setq eol-mnemonic-unix
"(Unix)"
742 eol-mnemonic-mac
"(Mac)"))
743 (t ; this is for Unix/GNU/Linux systems
744 (setq eol-mnemonic-dos
"(DOS)"
745 eol-mnemonic-mac
"(Mac)")))
747 (set-locale-environment nil
)
749 ;; Convert preloaded file names in load-history to absolute.
750 (let ((simple-file-name
751 ;; Look for simple.el or simple.elc and use their directory
752 ;; as the place where all Lisp files live.
753 (locate-file "simple" load-path
(get-load-suffixes)))
755 ;; Don't abort if simple.el cannot be found, but print a warning.
756 (if (null simple-file-name
)
758 (princ "Warning: Could not find simple.el nor simple.elc"
759 'external-debugging-output
)
760 (terpri 'external-debugging-output
))
761 (setq lisp-dir
(file-truename (file-name-directory simple-file-name
)))
763 (mapcar (lambda (elt)
764 (if (and (stringp (car elt
))
765 (not (file-name-absolute-p (car elt
))))
766 (cons (concat lisp-dir
772 ;; Convert the arguments to Emacs internal representation.
773 (let ((args (cdr command-line-args
)))
776 (decode-coding-string (car args
) locale-coding-system t
))
780 (args (cdr command-line-args
))
783 ;; Figure out which user's init file to load,
784 ;; either from the environment or from the options.
785 (setq init-file-user
(if noninteractive nil
(user-login-name)))
786 ;; If user has not done su, use current $HOME to find .emacs.
788 (equal init-file-user
(user-real-login-name))
789 (setq init-file-user
""))
791 ;; Process the command-line args, and delete the arguments
792 ;; processed. This is consistent with the way main in emacs.c
794 (while (and (not done
) args
)
795 (let* ((longopts '(("--no-init-file") ("--no-site-file") ("--debug-init")
796 ("--user") ("--iconic") ("--icon-type") ("--quick")
797 ("--no-blinking-cursor") ("--basic-display")))
801 ;; Handle --OPTION=VALUE format.
802 (when (string-match "\\`\\(--[^=]*\\)=" argi
)
803 (setq argval
(substring argi
(match-end 0))
804 argi
(match-string 1 argi
)))
805 (when (string-match "\\`--." orig-argi
)
806 (let ((completion (try-completion argi longopts
)))
807 (cond ((eq completion t
)
808 (setq argi
(substring argi
1)))
809 ((stringp completion
)
810 (let ((elt (assoc completion longopts
)))
812 (error "Option `%s' is ambiguous" argi
))
813 (setq argi
(substring (car elt
) 1))))
818 ;; The --display arg is handled partly in C, partly in Lisp.
819 ;; When it shows up here, we just put it back to be handled
820 ;; by `command-line-1'.
821 ((member argi
'("-d" "-display"))
822 (setq display-arg
(list argi
(pop args
))))
823 ((member argi
'("-Q" "-quick"))
824 (setq init-file-user nil
826 inhibit-x-resources t
))
827 ((member argi
'("-D" "-basic-display"))
828 (setq no-blinking-cursor t
829 emacs-basic-display t
)
830 (push '(vertical-scroll-bars . nil
) initial-frame-alist
))
831 ((member argi
'("-q" "-no-init-file"))
832 (setq init-file-user nil
))
833 ((member argi
'("-u" "-user"))
834 (setq init-file-user
(or argval
(pop args
))
836 ((equal argi
"-no-site-file")
837 (setq site-run-file nil
))
838 ((equal argi
"-debug-init")
839 (setq init-file-debug t
))
840 ((equal argi
"-iconic")
841 (push '(visibility . icon
) initial-frame-alist
))
842 ((member argi
'("-nbc" "-no-blinking-cursor"))
843 (setq no-blinking-cursor t
))
844 ;; Push the popped arg back on the list of arguments.
848 ;; Was argval set but not used?
850 (error "Option `%s' doesn't allow an argument" argi
))))
852 ;; Re-attach the --display arg.
853 (and display-arg
(setq args
(append display-arg args
)))
855 ;; Re-attach the program name to the front of the arg list.
856 (and command-line-args
857 (setcdr command-line-args args
)))
859 ;; Make sure window system's init file was loaded in loadup.el if
860 ;; using a window system.
861 ;; Initialize the window-system only after processing the command-line
862 ;; args so that -Q can influence this initialization.
863 (condition-case error
864 (unless noninteractive
865 (if (and initial-window-system
868 (concat (symbol-name initial-window-system
) "-win")))))
869 (error "Unsupported window system `%s'" initial-window-system
))
870 ;; Process window-system specific command line parameters.
871 (setq command-line-args
873 (or (cdr (assq initial-window-system handle-args-function-alist
))
874 (error "Unsupported window system `%s'" initial-window-system
))
876 ;; Initialize the window system. (Open connection, etc.)
878 (or (cdr (assq initial-window-system window-system-initialization-alist
))
879 (error "Unsupported window system `%s'" initial-window-system
))))
880 ;; If there was an error, print the error message and exit.
883 (if (eq (car error
) 'error
)
884 (apply 'concat
(cdr error
))
885 (if (memq 'file-error
(get (car error
) 'error-conditions
))
888 (mapconcat (lambda (obj) (prin1-to-string obj t
))
889 (cdr (cdr error
)) ", "))
891 (get (car error
) 'error-message
)
892 (mapconcat (lambda (obj) (prin1-to-string obj t
))
894 'external-debugging-output
)
895 (terpri 'external-debugging-output
)
896 (setq initial-window-system nil
)
899 (run-hooks 'before-init-hook
)
901 ;; Under X, this creates the X frame and deletes the terminal frame.
904 ;; If X resources are available, use them to initialize the values
905 ;; of `tool-bar-mode' and `menu-bar-mode', as well as the value of
906 ;; `no-blinking-cursor' and the `cursor' face.
908 ((or noninteractive emacs-basic-display
)
909 (setq menu-bar-mode nil
911 no-blinking-cursor t
))
912 ((memq initial-window-system
'(x w32 ns
))
913 (let ((no-vals '("no" "off" "false" "0")))
914 (if (member (x-get-resource "menuBar" "MenuBar") no-vals
)
915 (setq menu-bar-mode nil
))
916 (if (member (x-get-resource "toolBar" "ToolBar") no-vals
)
917 (setq tool-bar-mode nil
))
918 (if (member (x-get-resource "cursorBlink" "CursorBlink")
920 (setq no-blinking-cursor t
)))
921 ;; If the cursorColor X resource exists, alter the `cursor' face
922 ;; spec, but mark it as changed outside of Customize.
923 (let ((color (x-get-resource "cursorColor" "Foreground")))
925 (put 'cursor
'theme-face
926 `((changed ((t :background
,color
)))))
927 (put 'cursor
'face-modified t
)))))
930 (when (fboundp 'x-create-frame
)
931 ;; Set up the tool-bar (even in tty frames, since Emacs might open a
932 ;; graphical frame later).
933 (unless noninteractive
936 ;; Turn off blinking cursor if so specified in X resources. This is here
937 ;; only because all other settings of no-blinking-cursor are here.
938 (unless (or noninteractive
940 (and (memq window-system
'(x w32 ns
))
941 (not (member (x-get-resource "cursorBlink" "CursorBlink")
942 '("no" "off" "false" "0")))))
943 (setq no-blinking-cursor t
))
945 ;; Re-evaluate predefined variables whose initial value depends on
946 ;; the runtime context.
947 (mapc 'custom-reevaluate-setting
948 ;; Initialize them in the same order they were loaded, in case there
949 ;; are dependencies between them.
950 (prog1 (nreverse custom-delayed-init-variables
)
951 (setq custom-delayed-init-variables nil
)))
953 (normal-erase-is-backspace-setup-frame)
955 ;; Register default TTY colors for the case the terminal hasn't a
956 ;; terminal init file. We do this regardless of whether the terminal
957 ;; supports colors or not and regardless the current display type,
958 ;; since users can connect to color-capable terminals and also
959 ;; switch color support on or off in mid-session by setting the
960 ;; tty-color-mode frame parameter.
961 ;; Exception: the `pc' ``window system'' has only 16 fixed colors,
962 ;; and they are already set at this point by a suitable function in
963 ;; window-system-initialization-alist.
964 (or (eq initial-window-system
'pc
)
965 (tty-register-default-colors))
967 ;; Record whether the tool-bar is present before the user and site
968 ;; init files are processed. frame-notice-user-settings uses this
969 ;; to determine if the tool-bar has been disabled by the init files,
970 ;; and the frame needs to be resized.
971 (when (fboundp 'frame-notice-user-settings
)
972 (let ((tool-bar-lines (or (assq 'tool-bar-lines initial-frame-alist
)
973 (assq 'tool-bar-lines default-frame-alist
))))
974 (setq tool-bar-originally-present
977 (not (eq 0 (cdr tool-bar-lines
)))))))
979 (let ((old-scalable-fonts-allowed scalable-fonts-allowed
)
980 (old-font-list-limit font-list-limit
)
981 (old-face-ignored-fonts face-ignored-fonts
))
983 ;; Run the site-start library if it exists. The point of this file is
984 ;; that it is run before .emacs. There is no point in doing this after
985 ;; .emacs; that is useless.
986 ;; Note that user-init-file is nil at this point. Code that might
987 ;; be loaded from site-run-file and wants to test if -q was given
988 ;; should check init-file-user instead, since that is already set.
989 ;; See cus-edit.el for an example.
991 (load site-run-file t t
))
993 ;; Sites should not disable this. Only individuals should disable
994 ;; the startup screen.
995 (setq inhibit-startup-screen nil
)
997 ;; Warn for invalid user name.
999 (if (string-match "[~/:\n]" init-file-user
)
1000 (display-warning 'initialization
1001 (format "Invalid user name %s"
1004 (if (file-directory-p (expand-file-name
1005 ;; We don't support ~USER on MS-Windows
1006 ;; and MS-DOS except for the current
1007 ;; user, and always load .emacs from
1008 ;; the current user's home directory
1009 ;; (see below). So always check "~",
1010 ;; even if invoked with "-u USER", or
1011 ;; if $USER or $LOGNAME are set to
1012 ;; something different.
1013 (if (memq system-type
'(windows-nt ms-dos
))
1015 (concat "~" init-file-user
))))
1017 (display-warning 'initialization
1018 (format "User %s has no home directory"
1022 ;; Load that user's init file, or the default one, or none.
1023 (let (debug-on-error-from-init-file
1024 debug-on-error-should-be-set
1025 (debug-on-error-initial
1026 (if (eq init-file-debug t
) 'startup init-file-debug
))
1027 (orig-enable-multibyte (default-value 'enable-multibyte-characters
)))
1028 (let ((debug-on-error debug-on-error-initial
)
1029 ;; This function actually reads the init files.
1034 (let ((user-init-file-1
1036 ((eq system-type
'ms-dos
)
1037 (concat "~" init-file-user
"/_emacs"))
1038 ((not (eq system-type
'windows-nt
))
1039 (concat "~" init-file-user
"/.emacs"))
1040 ;; Else deal with the Windows situation
1041 ((directory-files "~" nil
"^\\.emacs\\(\\.elc?\\)?$")
1042 ;; Prefer .emacs on Windows.
1044 ((directory-files "~" nil
"^_emacs\\(\\.elc?\\)?$")
1045 ;; Also support _emacs for compatibility, but warn about it.
1046 (push '(initialization
1047 "`_emacs' init file is deprecated, please use `.emacs'")
1048 delayed-warnings-list
)
1050 (t ;; But default to .emacs if _emacs does not exist.
1052 ;; This tells `load' to store the file name found
1053 ;; into user-init-file.
1054 (setq user-init-file t
)
1055 (load user-init-file-1 t t
)
1057 (when (eq user-init-file t
)
1058 ;; If we did not find ~/.emacs, try
1059 ;; ~/.emacs.d/init.el.
1063 (file-name-as-directory
1064 (concat "~" init-file-user
"/.emacs.d")))))
1065 (load otherfile t t
)
1067 ;; If we did not find the user's init file,
1068 ;; set user-init-file conclusively.
1069 ;; Don't let it be set from default.el.
1070 (when (eq user-init-file t
)
1071 (setq user-init-file user-init-file-1
))))
1073 ;; If we loaded a compiled file, set
1074 ;; `user-init-file' to the source version if that
1076 (when (and user-init-file
1077 (equal (file-name-extension user-init-file
)
1079 (let* ((source (file-name-sans-extension user-init-file
))
1080 (alt (concat source
".el")))
1081 (setq source
(cond ((file-exists-p alt
) alt
)
1082 ((file-exists-p source
) source
)
1085 (when (file-newer-than-file-p source user-init-file
)
1086 (message "Warning: %s is newer than %s"
1087 source user-init-file
)
1089 (setq user-init-file source
))))
1091 (unless inhibit-default-init
1092 (let ((inhibit-startup-screen nil
))
1093 ;; Users are supposed to be told their rights.
1094 ;; (Plus how to get help and how to undo.)
1095 ;; Don't you dare turn this off for anyone
1097 (load "default" t t
)))))))))
1099 ;; Do this without a condition-case if the user wants to debug.
1101 (condition-case error
1104 (setq init-file-had-error nil
))
1108 (format "An error occurred while loading `%s':\n\n%s%s%s\n\n\
1109 To ensure normal operation, you should investigate and remove the
1110 cause of the error in your initialization file. Start Emacs with
1111 the `--debug-init' option to view a complete error backtrace."
1113 (get (car error
) 'error-message
)
1114 (if (cdr error
) ": " "")
1115 (mapconcat (lambda (s) (prin1-to-string s t
))
1118 (setq init-file-had-error t
))))
1120 (if (and deactivate-mark transient-mark-mode
)
1121 (with-current-buffer (window-buffer)
1124 ;; If the user has a file of abbrevs, read it (unless -batch).
1125 (when (and (not noninteractive
)
1126 (file-exists-p abbrev-file-name
)
1127 (file-readable-p abbrev-file-name
))
1128 (quietly-read-abbrev-file abbrev-file-name
))
1130 ;; If the abbrevs came entirely from the init file or the
1131 ;; abbrevs file, they do not need saving.
1132 (setq abbrevs-changed nil
)
1134 ;; If we can tell that the init file altered debug-on-error,
1135 ;; arrange to preserve the value that it set up.
1136 (or (eq debug-on-error debug-on-error-initial
)
1137 (setq debug-on-error-should-be-set t
1138 debug-on-error-from-init-file debug-on-error
)))
1139 (if debug-on-error-should-be-set
1140 (setq debug-on-error debug-on-error-from-init-file
))
1141 (unless (or (default-value 'enable-multibyte-characters
)
1142 (eq orig-enable-multibyte
(default-value
1143 'enable-multibyte-characters
)))
1144 ;; Init file changed to unibyte. Reset existing multibyte
1145 ;; buffers (probably *scratch*, *Messages*, *Minibuf-0*).
1146 ;; Arguably this should only be done if they're free of
1147 ;; multibyte characters.
1148 (mapc (lambda (buffer)
1149 (with-current-buffer buffer
1150 (if enable-multibyte-characters
1151 (set-buffer-multibyte nil
))))
1153 ;; Also re-set the language environment in case it was
1154 ;; originally done before unibyte was set and is sensitive to
1155 ;; unibyte (display table, terminal coding system &c).
1156 (set-language-environment current-language-environment
)))
1158 ;; Do this here in case the init file sets mail-host-address.
1159 (if (equal user-mail-address
"")
1160 (setq user-mail-address
(or (getenv "EMAIL")
1161 (concat (user-login-name) "@"
1162 (or mail-host-address
1165 ;; Originally face attributes were specified via
1166 ;; `font-lock-face-attributes'. Users then changed the default
1167 ;; face attributes by setting that variable. However, we try and
1168 ;; be back-compatible and respect its value if set except for
1169 ;; faces where M-x customize has been used to save changes for the
1171 (when (boundp 'font-lock-face-attributes
)
1172 (let ((face-attributes font-lock-face-attributes
))
1173 (while face-attributes
1174 (let* ((face-attribute (pop face-attributes
))
1175 (face (car face-attribute
)))
1176 ;; Rustle up a `defface' SPEC from a
1177 ;; `font-lock-face-attributes' entry.
1178 (unless (get face
'saved-face
)
1179 (let ((foreground (nth 1 face-attribute
))
1180 (background (nth 2 face-attribute
))
1181 (bold-p (nth 3 face-attribute
))
1182 (italic-p (nth 4 face-attribute
))
1183 (underline-p (nth 5 face-attribute
))
1186 (setq face-spec
(cons ':foreground
(cons foreground face-spec
))))
1188 (setq face-spec
(cons ':background
(cons background face-spec
))))
1190 (setq face-spec
(append '(:weight bold
) face-spec
)))
1192 (setq face-spec
(append '(:slant italic
) face-spec
)))
1194 (setq face-spec
(append '(:underline t
) face-spec
)))
1195 (face-spec-set face
(list (list t face-spec
)) nil
)))))))
1197 ;; If parameter have been changed in the init file which influence
1198 ;; face realization, clear the face cache so that new faces will
1200 (unless (and (eq scalable-fonts-allowed old-scalable-fonts-allowed
)
1201 (eq font-list-limit old-font-list-limit
)
1202 (eq face-ignored-fonts old-face-ignored-fonts
))
1203 (clear-face-cache)))
1205 ;; If any package directory exists, initialize the package system.
1207 package-enable-at-startup
1208 (catch 'package-dir-found
1210 (if (boundp 'package-directory-list
)
1211 (setq dirs package-directory-list
)
1212 (dolist (f load-path
)
1214 (equal (file-name-nondirectory f
) "site-lisp")
1215 (push (expand-file-name "elpa" f
) dirs
))))
1216 (push (if (boundp 'package-user-dir
)
1218 (locate-user-emacs-file "elpa"))
1221 (when (file-directory-p dir
)
1222 (dolist (subdir (directory-files dir
))
1223 (when (and (file-directory-p (expand-file-name subdir dir
))
1225 (concat "\\`" package-subdirectory-regexp
"\\'")
1227 (throw 'package-dir-found t
)))))))
1228 (package-initialize))
1230 (setq after-init-time
(current-time))
1231 (run-hooks 'after-init-hook
)
1233 ;; Decode all default-directory.
1234 (if (and (default-value 'enable-multibyte-characters
) locale-coding-system
)
1236 (dolist (elt (buffer-list))
1238 (if default-directory
1239 (setq default-directory
1240 (decode-coding-string default-directory
1241 locale-coding-system t
))))
1242 (setq command-line-default-directory
1243 (decode-coding-string command-line-default-directory
1244 locale-coding-system t
))))
1246 ;; If *scratch* exists and init file didn't change its mode, initialize it.
1247 (if (get-buffer "*scratch*")
1248 (with-current-buffer "*scratch*"
1249 (if (eq major-mode
'fundamental-mode
)
1250 (funcall initial-major-mode
))))
1252 ;; Load library for our terminal type.
1253 ;; User init file can set term-file-prefix to nil to prevent this.
1254 (unless (or noninteractive
1255 initial-window-system
)
1256 (tty-run-terminal-initialization (selected-frame)))
1258 ;; Update the out-of-memory error message based on user's key bindings
1259 ;; for save-some-buffers.
1260 (setq memory-signal-data
1262 (substitute-command-keys "Memory exhausted--use \\[save-some-buffers] then exit and restart Emacs")))
1264 ;; Process the remaining args.
1265 (command-line-1 (cdr command-line-args
))
1267 ;; If -batch, terminate after processing the command options.
1268 (if noninteractive
(kill-emacs t
))
1270 ;; In daemon mode, start the server to allow clients to connect.
1271 ;; This is done after loading the user's init file and after
1272 ;; processing all command line arguments to allow e.g. `server-name'
1273 ;; to be changed before the server starts.
1274 (let ((dn (daemonp)))
1276 (when (stringp dn
) (setq server-name dn
))
1279 (daemon-initialized)
1282 "Unable to start daemon: Emacs server named %S already running"
1284 (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."))
1287 ;; Run emacs-session-restore (session management) if started by
1288 ;; the session manager and we have a session manager connection.
1289 (if (and (boundp 'x-session-previous-id
)
1290 (stringp x-session-previous-id
))
1292 (emacs-session-restore x-session-previous-id
))))
1294 (defcustom initial-scratch-message
(purecopy "\
1295 ;; This buffer is for notes you don't want to save, and for Lisp evaluation.
1296 ;; If you want to create a file, visit that file with C-x C-f,
1297 ;; then enter the text in that file's own buffer.
1300 "Initial message displayed in *scratch* buffer at startup.
1301 If this is nil, no message will be displayed."
1302 :type
'(choice (text :tag
"Message")
1303 (const :tag
"none" nil
))
1304 :group
'initialization
)
1307 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1308 ;;; Fancy splash screen
1309 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1311 (defconst fancy-startup-text
1312 `((:face
(variable-pitch font-lock-comment-face
)
1315 ,(lambda (_button) (browse-url "http://www.gnu.org/software/emacs/"))
1316 "Browse http://www.gnu.org/software/emacs/")
1317 ", one component of the "
1320 (if (eq system-type
'gnu
/linux
)
1322 ,(lambda (_button) (browse-url "http://www.gnu.org/gnu/linux-and-gnu.html"))
1323 "Browse http://www.gnu.org/gnu/linux-and-gnu.html")
1324 `("GNU" ,(lambda (_button) (describe-gnu-project))
1325 "Display info on the GNU project")))
1326 " operating system.\n\n"
1327 :face variable-pitch
1328 :link
("Emacs Tutorial" ,(lambda (_button) (help-with-tutorial)))
1329 "\tLearn basic keystroke commands"
1331 (let* ((en "TUTORIAL")
1332 (tut (or (get-language-info current-language-environment
1335 (title (with-temp-buffer
1336 (insert-file-contents
1337 (expand-file-name tut tutorial-directory
)
1339 (search-forward ".")
1340 (buffer-substring (point-min) (1- (point))))))
1341 ;; If there is a specific tutorial for the current language
1342 ;; environment and it is not English, append its title.
1343 (if (string= en tut
)
1345 (concat " (" title
")"))))
1347 :link
("Emacs Guided Tour"
1349 (browse-url "http://www.gnu.org/software/emacs/tour/"))
1350 "Browse http://www.gnu.org/software/emacs/tour/")
1351 "\tOverview of Emacs features at gnu.org\n"
1352 :link
("View Emacs Manual" ,(lambda (_button) (info-emacs-manual)))
1353 "\tView the Emacs manual using Info\n"
1354 :link
("Absence of Warranty" ,(lambda (_button) (describe-no-warranty)))
1355 "\tGNU Emacs comes with "
1356 :face
(variable-pitch (:slant oblique
))
1357 "ABSOLUTELY NO WARRANTY\n"
1358 :face variable-pitch
1359 :link
("Copying Conditions" ,(lambda (_button) (describe-copying)))
1360 "\tConditions for redistributing and changing Emacs\n"
1361 :link
("Ordering Manuals" ,(lambda (_button) (view-order-manuals)))
1362 "\tPurchasing printed copies of manuals\n"
1364 "A list of texts to show in the middle part of splash screens.
1365 Each element in the list should be a list of strings or pairs
1366 `:face FACE', like `fancy-splash-insert' accepts them.")
1368 (defconst fancy-about-text
1369 `((:face
(variable-pitch font-lock-comment-face
)
1372 ,(lambda (_button) (browse-url "http://www.gnu.org/software/emacs/"))
1373 "Browse http://www.gnu.org/software/emacs/")
1374 ", one component of the "
1377 (if (eq system-type
'gnu
/linux
)
1380 (browse-url "http://www.gnu.org/gnu/linux-and-gnu.html"))
1381 "Browse http://www.gnu.org/gnu/linux-and-gnu.html")
1382 `("GNU" ,(lambda (_button) (describe-gnu-project))
1383 "Display info on the GNU project.")))
1384 " operating system.\n"
1385 :face
(variable-pitch font-lock-builtin-face
)
1387 ,(lambda () (emacs-version))
1389 :face
(variable-pitch (:height
0.8))
1390 ,(lambda () emacs-copyright
)
1392 :face variable-pitch
1395 (view-file (expand-file-name "AUTHORS" data-directory
))
1396 (goto-char (point-min))))
1397 "\tMany people have contributed code included in GNU Emacs\n"
1398 :link
("Contributing"
1400 (view-file (expand-file-name "CONTRIBUTE" data-directory
))
1401 (goto-char (point-min))))
1402 "\tHow to contribute improvements to Emacs\n"
1404 :link
("GNU and Freedom" ,(lambda (_button) (describe-gnu-project)))
1405 "\tWhy we developed GNU Emacs, and the GNU operating system\n"
1406 :link
("Absence of Warranty" ,(lambda (_button) (describe-no-warranty)))
1407 "\tGNU Emacs comes with "
1408 :face
(variable-pitch (:slant oblique
))
1409 "ABSOLUTELY NO WARRANTY\n"
1410 :face variable-pitch
1411 :link
("Copying Conditions" ,(lambda (_button) (describe-copying)))
1412 "\tConditions for redistributing and changing Emacs\n"
1413 :link
("Getting New Versions" ,(lambda (_button) (describe-distribution)))
1414 "\tHow to obtain the latest version of Emacs\n"
1415 :link
("Ordering Manuals" ,(lambda (_button) (view-order-manuals)))
1416 "\tBuying printed manuals from the FSF\n"
1418 :link
("Emacs Tutorial" ,(lambda (_button) (help-with-tutorial)))
1419 "\tLearn basic Emacs keystroke commands"
1421 (let* ((en "TUTORIAL")
1422 (tut (or (get-language-info current-language-environment
1425 (title (with-temp-buffer
1426 (insert-file-contents
1427 (expand-file-name tut tutorial-directory
)
1429 (search-forward ".")
1430 (buffer-substring (point-min) (1- (point))))))
1431 ;; If there is a specific tutorial for the current language
1432 ;; environment and it is not English, append its title.
1433 (if (string= en tut
)
1435 (concat " (" title
")"))))
1437 :link
("Emacs Guided Tour"
1439 (browse-url "http://www.gnu.org/software/emacs/tour/"))
1440 "Browse http://www.gnu.org/software/emacs/tour/")
1441 "\tSee an overview of Emacs features at gnu.org"))
1442 "A list of texts to show in the middle part of the About screen.
1443 Each element in the list should be a list of strings or pairs
1444 `:face FACE', like `fancy-splash-insert' accepts them.")
1447 (defgroup fancy-splash-screen
()
1448 "Fancy splash screen when Emacs starts."
1450 :group
'initialization
)
1452 (defcustom fancy-splash-image nil
1453 "The image to show in the splash screens, or nil for defaults."
1454 :group
'fancy-splash-screen
1455 :type
'(choice (const :tag
"Default" nil
)
1456 (file :tag
"File")))
1459 (defvar splash-screen-keymap
1460 (let ((map (make-sparse-keymap)))
1461 (suppress-keymap map
)
1462 (set-keymap-parent map button-buffer-map
)
1463 (define-key map
"\C-?" 'scroll-down-command
)
1464 (define-key map
" " 'scroll-up-command
)
1465 (define-key map
"q" 'exit-splash-screen
)
1467 "Keymap for splash screen buffer.")
1469 ;; These are temporary storage areas for the splash screen display.
1471 (defun fancy-splash-insert (&rest args
)
1472 "Insert text into the current buffer, with faces.
1473 Arguments from ARGS should be either strings; functions called
1474 with no args that return a string; pairs `:face FACE', where FACE
1475 is a face specification usable with `put-text-property'; or pairs
1476 `:link LINK' where LINK is a list of arguments to pass to
1477 `insert-button', of the form (LABEL ACTION [HELP-ECHO]), which
1478 specifies the button's label, `action' property and help-echo string.
1479 FACE and LINK can also be functions, which are evaluated to obtain
1480 a face or button specification."
1481 (let ((current-face nil
))
1483 (cond ((eq (car args
) :face
)
1484 (setq args
(cdr args
) current-face
(car args
))
1485 (if (functionp current-face
)
1486 (setq current-face
(funcall current-face
))))
1487 ((eq (car args
) :link
)
1488 (setq args
(cdr args
))
1489 (let ((spec (car args
)))
1490 (if (functionp spec
)
1491 (setq spec
(funcall spec
)))
1492 (insert-button (car spec
)
1493 'face
(list 'link current-face
)
1495 'help-echo
(concat "mouse-2, RET: "
1497 "Follow this link"))
1499 (t (insert (propertize (let ((it (car args
)))
1504 'help-echo
(startup-echo-area-message)))))
1505 (setq args
(cdr args
)))))
1507 (declare-function image-size
"image.c" (spec &optional pixels frame
))
1509 (defun fancy-splash-head ()
1510 "Insert the head part of the splash screen into the current buffer."
1511 (let* ((image-file (cond ((stringp fancy-splash-image
)
1514 (cond ((<= (display-planes) 8)
1515 (if (image-type-available-p 'xpm
)
1518 ((image-type-available-p 'svg
)
1520 ((image-type-available-p 'png
)
1522 ((image-type-available-p 'xpm
)
1526 (img (create-image image-file
))
1527 (image-width (and img
(car (image-size img
))))
1528 (window-width (window-width (selected-window))))
1530 (when (> window-width image-width
)
1531 ;; Center the image in the window.
1532 (insert (propertize " " 'display
1533 `(space :align-to
(+ center
(-0.5 .
,img
)))))
1535 ;; Change the color of the XPM version of the splash image
1536 ;; so that it is visible with a dark frame background.
1537 (when (and (memq 'xpm img
)
1538 (eq (frame-parameter nil
'background-mode
) 'dark
))
1539 (setq img
(append img
'(:color-symbols
(("#000000" .
"gray30"))))))
1541 ;; Insert the image with a help-echo and a link.
1542 (make-button (prog1 (point) (insert-image img
)) (point)
1544 'help-echo
"mouse-2, RET: Browse http://www.gnu.org/"
1545 'action
(lambda (_button) (browse-url "http://www.gnu.org/"))
1549 (defun fancy-startup-tail (&optional concise
)
1550 "Insert the tail part of the splash screen into the current buffer."
1552 (fancy-splash-insert
1553 :face
'variable-pitch
1555 :link
`("Open a File"
1556 ,(lambda (_button) (call-interactively 'find-file
))
1557 "Specify a new file's name, to edit the file")
1559 :link
`("Open Home Directory"
1560 ,(lambda (_button) (dired "~"))
1561 "Open your home directory, to operate on its files")
1563 :link
`("Customize Startup"
1564 ,(lambda (_button) (customize-group 'initialization
))
1565 "Change initialization settings including this screen")
1567 (fancy-splash-insert
1568 :face
'variable-pitch
"To quit a partially entered command, type "
1569 :face
'default
"Control-g"
1570 :face
'variable-pitch
".\n")
1571 (fancy-splash-insert :face
`(variable-pitch font-lock-builtin-face
)
1575 :face
'(variable-pitch (:height
0.8))
1578 (and auto-save-list-file-prefix
1579 ;; Don't signal an error if the
1580 ;; directory for auto-save-list files
1581 ;; does not yet exist.
1582 (file-directory-p (file-name-directory
1583 auto-save-list-file-prefix
))
1585 (file-name-directory auto-save-list-file-prefix
)
1588 (regexp-quote (file-name-nondirectory
1589 auto-save-list-file-prefix
)))
1591 (fancy-splash-insert :face
'(variable-pitch font-lock-comment-face
)
1592 "\nIf an Emacs session crashed recently, "
1594 :face
'(fixed-pitch font-lock-comment-face
)
1595 "Meta-x recover-session RET"
1596 :face
'(variable-pitch font-lock-comment-face
)
1598 " the files you were editing."))
1601 (fancy-splash-insert
1602 :face
'variable-pitch
"\n"
1603 :link
`("Dismiss this startup screen"
1605 (when startup-screen-inhibit-startup-screen
1606 (customize-set-variable 'inhibit-startup-screen t
)
1607 (customize-mark-to-save 'inhibit-startup-screen
)
1609 (let ((w (get-buffer-window "*GNU Emacs*")))
1610 (and w
(not (one-window-p)) (delete-window w
)))
1611 (kill-buffer "*GNU Emacs*")))
1613 (when (or user-init-file custom-file
)
1614 (let ((checked (create-image "checked.xpm"
1615 nil nil
:ascent
'center
))
1616 (unchecked (create-image "unchecked.xpm"
1617 nil nil
:ascent
'center
)))
1621 :off-glyph unchecked
1622 'checked nil
'display unchecked
'follow-link t
1623 'action
(lambda (button)
1624 (if (overlay-get button
'checked
)
1625 (progn (overlay-put button
'checked nil
)
1626 (overlay-put button
'display
1627 (overlay-get button
:off-glyph
))
1628 (setq startup-screen-inhibit-startup-screen
1630 (overlay-put button
'checked t
)
1631 (overlay-put button
'display
1632 (overlay-get button
:on-glyph
))
1633 (setq startup-screen-inhibit-startup-screen t
)))))
1634 (fancy-splash-insert :face
'(variable-pitch (:height
0.9))
1635 " Never show it again."))))
1637 (defun exit-splash-screen ()
1638 "Stop displaying the splash screen buffer."
1642 (defun fancy-startup-screen (&optional concise
)
1643 "Display fancy startup screen.
1644 If CONCISE is non-nil, display a concise version of the
1645 splash screen in another window."
1646 (let ((splash-buffer (get-buffer-create "*GNU Emacs*")))
1647 (with-current-buffer splash-buffer
1648 (let ((inhibit-read-only t
))
1650 (setq default-directory command-line-default-directory
)
1651 (make-local-variable 'startup-screen-inhibit-startup-screen
)
1652 (if pure-space-overflow
1653 (insert pure-space-overflow-message
))
1655 (fancy-splash-head))
1656 (dolist (text fancy-startup-text
)
1657 (apply #'fancy-splash-insert text
)
1659 (skip-chars-backward "\n")
1660 (delete-region (point) (point-max))
1662 (fancy-startup-tail concise
))
1663 (use-local-map splash-screen-keymap
)
1666 (set-buffer-modified-p nil
)
1667 (if (and view-read-only
(not view-mode
))
1668 (view-mode-enter nil
'kill-buffer
))
1669 (goto-char (point-min))
1670 (forward-line (if concise
2 4)))
1673 (display-buffer splash-buffer
)
1674 ;; If the splash screen is in a split window, fit it.
1675 (let ((window (get-buffer-window splash-buffer t
)))
1677 (eq window
(selected-window))
1678 (eq window
(next-window window
))
1679 (fit-window-to-buffer window
))))
1680 (switch-to-buffer splash-buffer
))))
1682 (defun fancy-about-screen ()
1683 "Display fancy About screen."
1684 (let ((frame (fancy-splash-frame)))
1685 (save-selected-window
1686 (select-frame frame
)
1687 (switch-to-buffer "*About GNU Emacs*")
1688 (setq buffer-undo-list t
)
1689 (let ((inhibit-read-only t
))
1691 (if pure-space-overflow
1692 (insert pure-space-overflow-message
))
1694 (dolist (text fancy-about-text
)
1695 (apply #'fancy-splash-insert text
)
1697 (set-buffer-modified-p nil
)
1698 (goto-char (point-min))
1699 (force-mode-line-update))
1700 (use-local-map splash-screen-keymap
)
1702 (message "%s" (startup-echo-area-message))
1703 (setq buffer-read-only t
)
1704 (goto-char (point-min))
1707 (defun fancy-splash-frame ()
1708 "Return the frame to use for the fancy splash screen.
1709 Returning non-nil does not mean we should necessarily
1710 use the fancy splash screen, but if we do use it,
1711 we put it on this frame."
1713 (dolist (frame (append (frame-list) (list (selected-frame))))
1714 (if (and (frame-visible-p frame
)
1715 (not (window-minibuffer-p (frame-selected-window frame
))))
1716 (setq chosen-frame frame
)))
1719 (defun use-fancy-splash-screens-p ()
1720 "Return t if fancy splash screens should be used."
1721 (when (and (display-graphic-p)
1722 (or (and (display-color-p)
1723 (image-type-available-p 'xpm
))
1724 (image-type-available-p 'pbm
)))
1725 (let ((frame (fancy-splash-frame)))
1727 (let* ((img (create-image (or fancy-splash-image
1728 (if (and (display-color-p)
1729 (image-type-available-p 'xpm
))
1730 "splash.xpm" "splash.pbm"))))
1731 (image-height (and img
(cdr (image-size img nil frame
))))
1732 ;; We test frame-height so that, if the frame is split
1733 ;; by displaying a warning, that doesn't cause the normal
1734 ;; splash screen to be used.
1735 (frame-height (1- (frame-height frame
))))
1736 (> frame-height
(+ image-height
19)))))))
1739 (defun normal-splash-screen (&optional startup concise
)
1740 "Display non-graphic splash screen.
1741 If optional argument STARTUP is non-nil, display the startup screen
1742 after Emacs starts. If STARTUP is nil, display the About screen.
1743 If CONCISE is non-nil, display a concise version of the
1744 splash screen in another window."
1745 (let ((splash-buffer (get-buffer-create "*About GNU Emacs*")))
1746 (with-current-buffer splash-buffer
1747 (setq buffer-read-only nil
)
1749 (setq default-directory command-line-default-directory
)
1750 (set (make-local-variable 'tab-width
) 8)
1752 (if pure-space-overflow
1753 (insert pure-space-overflow-message
))
1755 ;; The convention for this piece of code is that
1756 ;; each piece of output starts with one or two newlines
1757 ;; and does not end with any newlines.
1758 (insert (if startup
"Welcome to GNU Emacs" "This is GNU Emacs"))
1760 (if (eq system-type
'gnu
/linux
)
1761 ", one component of the GNU/Linux operating system.\n"
1762 ", a part of the GNU operating system.\n"))
1765 (if (display-mouse-p)
1766 ;; The user can use the mouse to activate menus
1767 ;; so give help in terms of menu items.
1768 (normal-mouse-startup-screen)
1770 ;; No mouse menus, so give help using kbd commands.
1771 (normal-no-mouse-startup-screen))
1773 (normal-about-screen))
1775 ;; The rest of the startup screen is the same on all
1776 ;; kinds of terminals.
1778 ;; Give information on recovering, if there was a crash.
1780 auto-save-list-file-prefix
1781 ;; Don't signal an error if the
1782 ;; directory for auto-save-list files
1783 ;; does not yet exist.
1784 (file-directory-p (file-name-directory
1785 auto-save-list-file-prefix
))
1787 (file-name-directory auto-save-list-file-prefix
)
1790 (regexp-quote (file-name-nondirectory
1791 auto-save-list-file-prefix
)))
1793 (insert "\n\nIf an Emacs session crashed recently, "
1794 "type Meta-x recover-session RET\nto recover"
1795 " the files you were editing.\n"))
1797 (use-local-map splash-screen-keymap
)
1799 ;; Display the input that we set up in the buffer.
1800 (set-buffer-modified-p nil
)
1801 (setq buffer-read-only t
)
1802 (if (and view-read-only
(not view-mode
))
1803 (view-mode-enter nil
'kill-buffer
))
1804 (if startup
(rename-buffer "*GNU Emacs*" t
))
1805 (goto-char (point-min)))
1807 (display-buffer splash-buffer
)
1808 (switch-to-buffer splash-buffer
))))
1810 (defun normal-mouse-startup-screen ()
1811 ;; The user can use the mouse to activate menus
1812 ;; so give help in terms of menu items.
1814 To follow a link, click Mouse-1 on it, or move to it and type RET.
1815 To quit a partially entered command, type Control-g.\n")
1817 (insert "\nImportant Help menu items:\n")
1818 (insert-button "Emacs Tutorial"
1819 'action
(lambda (_button) (help-with-tutorial))
1821 (insert "\t\tLearn basic Emacs keystroke commands\n")
1822 (insert-button "Read the Emacs Manual"
1823 'action
(lambda (_button) (info-emacs-manual))
1825 (insert "\tView the Emacs manual using Info\n")
1826 (insert-button "\(Non)Warranty"
1827 'action
(lambda (_button) (describe-no-warranty))
1829 (insert "\t\tGNU Emacs comes with ABSOLUTELY NO WARRANTY\n")
1830 (insert-button "Copying Conditions"
1831 'action
(lambda (_button) (describe-copying))
1833 (insert "\tConditions for redistributing and changing Emacs\n")
1834 (insert-button "More Manuals / Ordering Manuals"
1835 'action
(lambda (_button) (view-order-manuals))
1837 (insert " How to order printed manuals from the FSF\n")
1839 (insert "\nUseful tasks:\n")
1840 (insert-button "Visit New File"
1841 'action
(lambda (_button) (call-interactively 'find-file
))
1843 (insert "\t\tSpecify a new file's name, to edit the file\n")
1844 (insert-button "Open Home Directory"
1845 'action
(lambda (_button) (dired "~"))
1847 (insert "\tOpen your home directory, to operate on its files\n")
1848 (insert-button "Customize Startup"
1849 'action
(lambda (_button) (customize-group 'initialization
))
1851 (insert "\tChange initialization settings including this screen\n")
1853 (insert "\n" (emacs-version)
1854 "\n" emacs-copyright
))
1856 ;; No mouse menus, so give help using kbd commands.
1857 (defun normal-no-mouse-startup-screen ()
1859 ;; If keys have their default meanings,
1860 ;; use precomputed string to save lots of time.
1861 (let* ((c-h-accessible
1862 ;; If normal-erase-is-backspace is used on a tty, there's
1863 ;; no way to invoke C-h and you have to use F1 instead.
1864 (or (not (char-table-p keyboard-translate-table
))
1865 (eq (aref keyboard-translate-table ?\C-h
) ?\C-h
)))
1866 (minor-mode-overriding-map-alist
1867 (cons (cons (not c-h-accessible
)
1868 ;; If C-h can't be invoked, temporarily disable its
1869 ;; binding, so where-is uses alternative bindings.
1870 (let ((map (make-sparse-keymap)))
1871 (define-key map
[?\C-h
] 'undefined
)
1873 minor-mode-overriding-map-alist
)))
1875 (insert (format "\nGet help\t %s\n"
1876 (let ((where (where-is-internal 'help-command nil t
)))
1878 ((equal where
[?\C-h
])
1879 "C-h (Hold down CTRL and press h)")
1880 (where (key-description where
))
1882 (insert-button "Emacs manual"
1883 'action
(lambda (_button) (info-emacs-manual))
1885 (insert (substitute-command-keys"\t \\[info-emacs-manual]\t"))
1886 (insert-button "Browse manuals"
1887 'action
(lambda (_button) (Info-directory))
1889 (insert (substitute-command-keys "\t \\[info]\n"))
1890 (insert-button "Emacs tutorial"
1891 'action
(lambda (_button) (help-with-tutorial))
1893 (insert (substitute-command-keys
1894 "\t \\[help-with-tutorial]\tUndo changes\t \\[undo]\n"))
1895 (insert-button "Buy manuals"
1896 'action
(lambda (_button) (view-order-manuals))
1898 (insert (substitute-command-keys
1899 "\t \\[view-order-manuals]\tExit Emacs\t \\[save-buffers-kill-terminal]")))
1901 ;; Say how to use the menu bar with the keyboard.
1903 (insert-button "Activate menubar"
1904 'action
(lambda (_button) (tmm-menubar))
1906 (if (and (eq (key-binding "\M-`") 'tmm-menubar
)
1907 (eq (key-binding [f10]) 'tmm-menubar))
1908 (insert " F10 or ESC ` or M-`")
1909 (insert (substitute-command-keys " \\[tmm-menubar]")))
1911 ;; Many users seem to have problems with these.
1913 \(`C-' means use the CTRL key. `M-' means use the Meta (or Alt) key.
1914 If you have no Meta key, you may instead type ESC followed by the character.)")
1916 ;; Insert links to useful tasks
1917 (insert "\nUseful tasks:\n")
1919 (insert-button "Visit New File"
1920 'action (lambda (_button) (call-interactively 'find-file))
1923 (insert-button "Open Home Directory"
1924 'action (lambda (_button) (dired "~"))
1928 (insert-button "Customize Startup"
1929 'action (lambda (_button) (customize-group 'initialization))
1932 (insert-button "Open *scratch* buffer"
1933 'action (lambda (_button) (switch-to-buffer
1934 (get-buffer-create "*scratch*")))
1937 (insert "\n" (emacs-version) "\n" emacs-copyright "\n")
1939 (if (and (eq (key-binding "\C-h\C-c") 'describe-copying)
1940 (eq (key-binding "\C-h\C-d") 'describe-distribution)
1941 (eq (key-binding "\C-h\C-w") 'describe-no-warranty))
1945 GNU Emacs comes with ABSOLUTELY NO WARRANTY; type C-h C-w for ")
1946 (insert-button "full details"
1947 'action (lambda (_button) (describe-no-warranty))
1950 Emacs is Free Software--Free as in Freedom--so you can redistribute copies
1951 of Emacs and modify it; type C-h C-c to see ")
1952 (insert-button "the conditions"
1953 'action (lambda (_button) (describe-copying))
1956 Type C-h C-d for information on ")
1957 (insert-button "getting the latest version"
1958 'action (lambda (_button) (describe-distribution))
1961 (insert (substitute-command-keys
1963 GNU Emacs comes with ABSOLUTELY NO WARRANTY; type \\[describe-no-warranty] for "))
1964 (insert-button "full details"
1965 'action (lambda (_button) (describe-no-warranty))
1967 (insert (substitute-command-keys ".
1968 Emacs is Free Software--Free as in Freedom--so you can redistribute copies
1969 of Emacs and modify it; type \\[describe-copying] to see "))
1970 (insert-button "the conditions"
1971 'action (lambda (_button) (describe-copying))
1973 (insert (substitute-command-keys".
1974 Type \\[describe-distribution] for information on "))
1975 (insert-button "getting the latest version"
1976 'action (lambda (_button) (describe-distribution))
1980 (defun normal-about-screen ()
1981 (insert "\n" (emacs-version) "\n" emacs-copyright "\n\n")
1983 (insert "To follow a link, click Mouse-1 on it, or move to it and type RET.\n\n")
1985 (insert-button "Authors"
1988 (view-file (expand-file-name "AUTHORS" data-directory))
1989 (goto-char (point-min)))
1991 (insert "\t\tMany people have contributed code included in GNU Emacs\n")
1993 (insert-button "Contributing"
1996 (view-file (expand-file-name "CONTRIBUTE" data-directory))
1997 (goto-char (point-min)))
1999 (insert "\tHow to contribute improvements to Emacs\n\n")
2001 (insert-button "GNU and Freedom"
2002 'action (lambda (_button) (describe-gnu-project))
2004 (insert "\t\tWhy we developed GNU Emacs and the GNU system\n")
2006 (insert-button "Absence of Warranty"
2007 'action (lambda (_button) (describe-no-warranty))
2009 (insert "\tGNU Emacs comes with ABSOLUTELY NO WARRANTY\n")
2011 (insert-button "Copying Conditions"
2012 'action (lambda (_button) (describe-copying))
2014 (insert "\tConditions for redistributing and changing Emacs\n")
2016 (insert-button "Getting New Versions"
2017 'action (lambda (_button) (describe-distribution))
2019 (insert "\tHow to get the latest version of GNU Emacs\n")
2021 (insert-button "More Manuals / Ordering Manuals"
2022 'action (lambda (_button) (view-order-manuals))
2024 (insert "\tBuying printed manuals from the FSF\n"))
2026 (defun startup-echo-area-message ()
2028 "Starting Emacs daemon.")
2029 ((eq (key-binding "\C-h\C-a") 'about-emacs)
2030 "For information about GNU Emacs and the GNU system, type C-h C-a.")
2032 (substitute-command-keys
2033 "For information about GNU Emacs and the GNU system, type \
2034 \\[about-emacs]."))))
2036 (defun display-startup-echo-area-message ()
2037 (let ((resize-mini-windows t))
2038 (or noninteractive ;(input-pending-p) init-file-had-error
2039 ;; t if the init file says to inhibit the echo area startup message.
2040 (and inhibit-startup-echo-area-message
2042 (or (and (get 'inhibit-startup-echo-area-message 'saved-value)
2043 (equal inhibit-startup-echo-area-message
2044 (if (equal init-file-user "")
2047 ;; Wasn't set with custom; see if .emacs has a setq.
2050 (insert-file-contents user-init-file)
2053 "([ \t\n]*setq[ \t\n]+"
2054 "inhibit-startup-echo-area-message[ \t\n]+"
2057 (if (equal init-file-user "")
2063 (message "%s" (startup-echo-area-message)))))
2065 (defun display-startup-screen (&optional concise)
2066 "Display startup screen according to display.
2067 A fancy display is used on graphic displays, normal otherwise.
2069 If CONCISE is non-nil, display a concise version of the startup
2071 ;; Prevent recursive calls from server-process-filter.
2072 (if (not (get-buffer "*GNU Emacs*"))
2073 (if (use-fancy-splash-screens-p)
2074 (fancy-startup-screen concise)
2075 (normal-splash-screen t concise))))
2077 (defun display-about-screen ()
2078 "Display the *About GNU Emacs* buffer.
2079 A fancy display is used on graphic displays, normal otherwise."
2081 (if (use-fancy-splash-screens-p)
2082 (fancy-about-screen)
2083 (normal-splash-screen nil)))
2085 (defalias 'about-emacs 'display-about-screen)
2086 (defalias 'display-splash-screen 'display-startup-screen)
2088 (defun command-line-1 (args-left)
2089 "A subroutine of `command-line'."
2090 (display-startup-echo-area-message)
2091 (when (and pure-space-overflow
2092 (not noninteractive))
2095 "Building Emacs overflowed pure space.\
2096 (See the node Pure Storage in the Lisp manual for details.)"
2099 (let ((file-count 0)
2100 (command-line-args-left args-left)
2102 (when command-line-args-left
2103 ;; We have command args; process them.
2104 (let ((dir command-line-default-directory)
2106 ;; This approach loses for "-batch -L DIR --eval "(require foo)",
2107 ;; if foo is intended to be found in DIR.
2109 ;; ;; The directories listed in --directory/-L options will *appear*
2110 ;; ;; at the front of `load-path' in the order they appear on the
2111 ;; ;; command-line. We cannot do this by *placing* them at the front
2112 ;; ;; in the order they appear, so we need this variable to hold them,
2116 ;; To DTRT we keep track of the splice point and modify `load-path'
2117 ;; straight away upon any --directory/-L option.
2119 just-files ;; t if this follows the magic -- option.
2120 ;; This includes our standard options' long versions
2121 ;; and long versions of what's on command-switch-alist.
2123 (append '("--funcall" "--load" "--insert" "--kill"
2124 "--directory" "--eval" "--execute" "--no-splash"
2125 "--find-file" "--visit" "--file" "--no-desktop")
2126 (mapcar (lambda (elt) (concat "-" (car elt)))
2127 command-switch-alist)))
2131 ;; Add the long X options to longopts.
2132 (dolist (tem command-line-x-option-alist)
2133 (if (string-match "^--" (car tem))
2134 (push (car tem) longopts)))
2136 ;; Add the long NS options to longopts.
2137 (dolist (tem command-line-ns-option-alist)
2138 (if (string-match "^--" (car tem))
2139 (push (list (car tem)) longopts)))
2141 ;; Loop, processing options.
2142 (while command-line-args-left
2143 (let* ((argi (car command-line-args-left))
2146 (setq command-line-args-left (cdr command-line-args-left))
2148 ;; Do preliminary decoding of the option.
2150 ;; After --, don't look for options; treat all args as files.
2152 ;; Convert long options to ordinary options
2153 ;; and separate out an attached option argument into argval.
2154 (when (string-match "\\`\\(--[^=]*\\)=" argi)
2155 (setq argval (substring argi (match-end 0))
2156 argi (match-string 1 argi)))
2157 (when (string-match "\\`--?[^-]" orig-argi)
2158 (setq completion (try-completion argi longopts))
2159 (if (eq completion t)
2160 (setq argi (substring argi 1))
2161 (if (stringp completion)
2162 (let ((elt (member completion longopts)))
2164 (error "Option `%s' is ambiguous" argi))
2165 (setq argi (substring (car elt) 1)))
2169 ;; Execute the option.
2170 (cond ((setq tem (assoc argi command-switch-alist))
2172 (let ((command-line-args-left
2173 (cons argval command-line-args-left)))
2174 (funcall (cdr tem) argi))
2175 (funcall (cdr tem) argi)))
2177 ((equal argi "-no-splash")
2178 (setq inhibit-startup-screen t))
2180 ((member argi '("-f" ; what the manual claims
2182 "-e")) ; what the source used to say
2183 (setq inhibit-startup-screen t)
2184 (setq tem (intern (or argval (pop command-line-args-left))))
2186 (command-execute tem)
2189 ((member argi '("-eval" "-execute"))
2190 (setq inhibit-startup-screen t)
2191 (eval (read (or argval (pop command-line-args-left)))))
2193 ((member argi '("-L" "-directory"))
2194 (setq tem (expand-file-name
2195 (command-line-normalize-file-name
2196 (or argval (pop command-line-args-left)))))
2197 (cond (splice (setcdr splice (cons tem (cdr splice)))
2198 (setq splice (cdr splice)))
2199 (t (setq load-path (cons tem load-path)
2200 splice load-path))))
2202 ((member argi '("-l" "-load"))
2203 (let* ((file (command-line-normalize-file-name
2204 (or argval (pop command-line-args-left))))
2205 ;; Take file from default dir if it exists there;
2206 ;; otherwise let `load' search for it.
2207 (file-ex (expand-file-name file)))
2208 (when (file-exists-p file-ex)
2209 (setq file file-ex))
2212 ;; This is used to handle -script. It's not clear
2213 ;; we need to document it (it is totally internal).
2214 ((member argi '("-scriptload"))
2215 (let* ((file (command-line-normalize-file-name
2216 (or argval (pop command-line-args-left))))
2217 ;; Take file from default dir.
2218 (file-ex (expand-file-name file)))
2219 (load file-ex nil t t)))
2221 ((equal argi "-insert")
2222 (setq inhibit-startup-screen t)
2223 (setq tem (or argval (pop command-line-args-left)))
2225 (error "File name omitted from `-insert' option"))
2226 (insert-file-contents (command-line-normalize-file-name tem)))
2228 ((equal argi "-kill")
2231 ;; This is for when they use --no-desktop with -q, or
2232 ;; don't load Desktop in their .emacs. If desktop.el
2233 ;; _is_ loaded, it will handle this switch, and we
2234 ;; won't see it by the time we get here.
2235 ((equal argi "-no-desktop")
2236 (message "\"--no-desktop\" ignored because the Desktop package is not loaded"))
2238 ((string-match "^\\+[0-9]+\\'" argi)
2239 (setq line (string-to-number argi)))
2241 ((string-match "^\\+\\([0-9]+\\):\\([0-9]+\\)\\'" argi)
2242 (setq line (string-to-number (match-string 1 argi))
2243 column (string-to-number (match-string 2 argi))))
2245 ((setq tem (assoc orig-argi command-line-x-option-alist))
2246 ;; Ignore X-windows options and their args if not using X.
2247 (setq command-line-args-left
2248 (nthcdr (nth 1 tem) command-line-args-left)))
2250 ((setq tem (assoc orig-argi command-line-ns-option-alist))
2251 ;; Ignore NS-windows options and their args if not using NS.
2252 (setq command-line-args-left
2253 (nthcdr (nth 1 tem) command-line-args-left)))
2255 ((member argi '("-find-file" "-file" "-visit"))
2256 (setq inhibit-startup-screen t)
2257 ;; An explicit option to specify visiting a file.
2258 (setq tem (or argval (pop command-line-args-left)))
2259 (unless (stringp tem)
2260 (error "File name omitted from `%s' option" argi))
2261 (setq file-count (1+ file-count))
2262 (let ((file (expand-file-name
2263 (command-line-normalize-file-name tem)
2265 (if (= file-count 1)
2266 (setq first-file-buffer (find-file file))
2267 (find-file-other-window file)))
2268 (unless (zerop line)
2269 (goto-char (point-min))
2270 (forward-line (1- line)))
2272 (unless (< column 1)
2273 (move-to-column (1- column)))
2276 ;; These command lines now have no effect.
2277 ((string-match "\\`--?\\(no-\\)?\\(uni\\|multi\\)byte$" argi)
2278 (display-warning 'initialization
2279 (format "Ignoring obsolete arg %s" argi)))
2282 (setq just-files t))
2284 ;; We have almost exhausted our options. See if the
2285 ;; user has made any other command-line options available
2286 (let ((hooks command-line-functions)
2289 (not (setq did-hook (funcall (car hooks)))))
2290 (setq hooks (cdr hooks)))
2292 ;; Presume that the argument is a file name.
2294 (if (string-match "\\`-" argi)
2295 (error "Unknown option `%s'" argi))
2296 (unless initial-window-system
2297 (setq inhibit-startup-screen t))
2298 (setq file-count (1+ file-count))
2301 (command-line-normalize-file-name orig-argi)
2303 (cond ((= file-count 1)
2304 (setq first-file-buffer (find-file file)))
2305 (inhibit-startup-screen
2306 (find-file-other-window file))
2307 (t (find-file file))))
2308 (unless (zerop line)
2309 (goto-char (point-min))
2310 (forward-line (1- line)))
2312 (unless (< column 1)
2313 (move-to-column (1- column)))
2314 (setq column 0))))))
2315 ;; In unusual circumstances, the execution of Lisp code due
2316 ;; to command-line options can cause the last visible frame
2317 ;; to be deleted. In this case, kill emacs to avoid an
2319 (unless (frame-live-p (selected-frame)) (kill-emacs nil))))))
2321 (when (eq initial-buffer-choice t)
2322 ;; When initial-buffer-choice equals t make sure that *scratch*
2324 (get-buffer-create "*scratch*"))
2326 ;; If *scratch* exists and is empty, insert initial-scratch-message.
2327 ;; Do this before switching to *scratch* below to handle bug#9605.
2328 (and initial-scratch-message
2329 (get-buffer "*scratch*")
2330 (with-current-buffer "*scratch*"
2331 (when (zerop (buffer-size))
2332 (insert initial-scratch-message)
2333 (set-buffer-modified-p nil))))
2335 (when initial-buffer-choice
2336 (cond ((eq initial-buffer-choice t)
2337 (switch-to-buffer (get-buffer-create "*scratch*")))
2338 ((stringp initial-buffer-choice)
2339 (find-file initial-buffer-choice))))
2341 (if (or inhibit-startup-screen
2342 initial-buffer-choice
2345 inhibit-x-resources)
2347 ;; Not displaying a startup screen. If 3 or more files
2348 ;; visited, and not all visible, show user what they all are.
2349 (and (> file-count 2)
2350 (not noninteractive)
2351 (not inhibit-startup-buffer-menu)
2352 (or (get-buffer-window first-file-buffer)
2355 ;; Display a startup screen, after some preparations.
2357 ;; If there are no switches to process, we might as well
2358 ;; run this hook now, and there may be some need to do it
2359 ;; before doing any output.
2360 (run-hooks 'emacs-startup-hook)
2361 (and term-setup-hook
2362 (run-hooks 'term-setup-hook))
2363 (setq inhibit-startup-hooks t)
2365 ;; It's important to notice the user settings before we
2366 ;; display the startup message; otherwise, the settings
2367 ;; won't take effect until the user gives the first
2368 ;; keystroke, and that's distracting.
2369 (when (fboundp 'frame-notice-user-settings)
2370 (frame-notice-user-settings))
2372 ;; If there are no switches to process, we might as well
2373 ;; run this hook now, and there may be some need to do it
2374 ;; before doing any output.
2375 (when window-setup-hook
2376 (run-hooks 'window-setup-hook)
2377 ;; Don't let the hook be run twice.
2378 (setq window-setup-hook nil))
2380 ;; ;; Do this now to avoid an annoying delay if the user
2381 ;; ;; clicks the menu bar during the sit-for.
2382 ;; (when (display-popup-menus-p)
2383 ;; (precompute-menubar-bindings))
2384 ;; (with-no-warnings
2385 ;; (setq menubar-bindings-done t))
2387 (display-startup-screen (> file-count 0)))))
2389 (defun command-line-normalize-file-name (file)
2390 "Collapse multiple slashes to one, to handle non-Emacs file names."
2392 ;; Use arg 1 so that we don't collapse // at the start of the file name.
2393 ;; That is significant on some systems.
2394 ;; However, /// at the beginning is supposed to mean just /, not //.
2395 (if (string-match "^///+" file)
2396 (setq file (replace-match "/" t t file)))
2397 (and (memq system-type '(ms-dos windows-nt))
2398 (string-match "^[A-Za-z]:\\(\\\\[\\\\/]\\)" file) ; C:\/ or C:\\
2399 (setq file (replace-match "/" t t file 1)))
2400 (while (string-match "//+" file 1)
2401 (setq file (replace-match "/" t t file)))
2404 ;;; startup.el ends here