1 ;;; startup.el --- process Emacs shell arguments -*- lexical-binding: t -*-
3 ;; Copyright (C) 1985-1986, 1992, 1994-2011 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 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 (defcustom inhibit-startup-echo-area-message nil
69 "Non-nil inhibits the initial startup echo area message.
70 Setting this variable takes effect
71 only if you do it with the customization buffer
72 or if your `.emacs' file contains a line of this form:
73 (setq inhibit-startup-echo-area-message \"YOUR-USER-NAME\")
74 If your `.emacs' file is byte-compiled, use the following form instead:
75 (eval '(setq inhibit-startup-echo-area-message \"YOUR-USER-NAME\"))
76 Thus, someone else using a copy of your `.emacs' file will see
77 the startup message unless he personally acts to inhibit it."
78 :type
'(choice (const :tag
"Don't inhibit")
79 (string :tag
"Enter your user name, to inhibit"))
80 :group
'initialization
)
82 (defcustom inhibit-default-init nil
83 "Non-nil inhibits loading the `default' library."
85 :group
'initialization
)
87 (defcustom inhibit-startup-buffer-menu nil
88 "Non-nil inhibits display of buffer list when more than 2 files are loaded."
90 :group
'initialization
)
92 (defvar command-switch-alist nil
93 "Alist of command-line switches.
94 Elements look like (SWITCH-STRING . HANDLER-FUNCTION).
95 HANDLER-FUNCTION receives the switch string as its sole argument;
96 the remaining command-line args are in the variable `command-line-args-left'.")
98 (defvar command-line-args-left nil
99 "List of command-line args not yet processed.")
101 (defvaralias 'argv
'command-line-args-left
102 ;; FIXME: Bad name for a dynamically bound variable.
103 "List of command-line args not yet processed.
104 This is a convenience alias, so that one can write \(pop argv\)
105 inside of --eval command line arguments in order to access
106 following arguments.")
109 ;; FIXME: Bad name for a dynamically bound variable
111 "Current command-line argument."))
113 (defvar command-line-functions nil
;; lrs 7/31/89
114 "List of functions to process unrecognized command-line arguments.
115 Each function should access the dynamically bound variables
116 `argi' (the current argument) and `command-line-args-left' (the remaining
117 arguments). The function should return non-nil only if it recognizes and
118 processes `argi'. If it does so, it may consume successive arguments by
119 altering `command-line-args-left' to remove them.")
121 (defvar command-line-default-directory nil
122 "Default directory to use for command line arguments.
123 This is normally copied from `default-directory' when Emacs starts.")
125 ;;; This is here, rather than in x-win.el, so that we can ignore these
126 ;;; options when we are not using X.
127 (defconst command-line-x-option-alist
128 '(("-bw" 1 x-handle-numeric-switch border-width
)
129 ("-d" 1 x-handle-display
)
130 ("-display" 1 x-handle-display
)
131 ("-name" 1 x-handle-name-switch
)
132 ("-title" 1 x-handle-switch title
)
133 ("-T" 1 x-handle-switch title
)
134 ("-r" 0 x-handle-switch reverse t
)
135 ("-rv" 0 x-handle-switch reverse t
)
136 ("-reverse" 0 x-handle-switch reverse t
)
137 ("-reverse-video" 0 x-handle-switch reverse t
)
138 ("-fn" 1 x-handle-switch font
)
139 ("-font" 1 x-handle-switch font
)
140 ("-fs" 0 x-handle-initial-switch fullscreen fullboth
)
141 ("-fw" 0 x-handle-initial-switch fullscreen fullwidth
)
142 ("-fh" 0 x-handle-initial-switch fullscreen fullheight
)
143 ("-mm" 0 x-handle-initial-switch fullscreen maximized
)
144 ("-ib" 1 x-handle-numeric-switch internal-border-width
)
145 ("-g" 1 x-handle-geometry
)
146 ("-lsp" 1 x-handle-numeric-switch line-spacing
)
147 ("-geometry" 1 x-handle-geometry
)
148 ("-fg" 1 x-handle-switch foreground-color
)
149 ("-foreground" 1 x-handle-switch foreground-color
)
150 ("-bg" 1 x-handle-switch background-color
)
151 ("-background" 1 x-handle-switch background-color
)
152 ("-ms" 1 x-handle-switch mouse-color
)
153 ("-nbi" 0 x-handle-switch icon-type nil
)
154 ("-iconic" 0 x-handle-iconic
)
155 ("-xrm" 1 x-handle-xrm-switch
)
156 ("-cr" 1 x-handle-switch cursor-color
)
157 ("-vb" 0 x-handle-switch vertical-scroll-bars t
)
158 ("-hb" 0 x-handle-switch horizontal-scroll-bars t
)
159 ("-bd" 1 x-handle-switch
)
160 ("--border-width" 1 x-handle-numeric-switch border-width
)
161 ("--display" 1 x-handle-display
)
162 ("--name" 1 x-handle-name-switch
)
163 ("--title" 1 x-handle-switch title
)
164 ("--reverse-video" 0 x-handle-switch reverse t
)
165 ("--font" 1 x-handle-switch font
)
166 ("--fullscreen" 0 x-handle-initial-switch fullscreen fullboth
)
167 ("--fullwidth" 0 x-handle-initial-switch fullscreen fullwidth
)
168 ("--fullheight" 0 x-handle-initial-switch fullscreen fullheight
)
169 ("--maximized" 0 x-handle-initial-switch fullscreen maximized
)
170 ("--internal-border" 1 x-handle-numeric-switch internal-border-width
)
171 ("--geometry" 1 x-handle-geometry
)
172 ("--foreground-color" 1 x-handle-switch foreground-color
)
173 ("--background-color" 1 x-handle-switch background-color
)
174 ("--mouse-color" 1 x-handle-switch mouse-color
)
175 ("--no-bitmap-icon" 0 x-handle-no-bitmap-icon
)
176 ("--iconic" 0 x-handle-iconic
)
177 ("--xrm" 1 x-handle-xrm-switch
)
178 ("--cursor-color" 1 x-handle-switch cursor-color
)
179 ("--vertical-scroll-bars" 0 x-handle-switch vertical-scroll-bars t
)
180 ("--line-spacing" 1 x-handle-numeric-switch line-spacing
)
181 ("--border-color" 1 x-handle-switch border-color
)
182 ("--smid" 1 x-handle-smid
)
183 ("--parent-id" 1 x-handle-parent-id
))
184 "Alist of X Windows options.
185 Each element has the form
186 (NAME NUMARGS HANDLER FRAME-PARAM VALUE)
187 where NAME is the option name string, NUMARGS is the number of arguments
188 that the option accepts, HANDLER is a function to call to handle the option.
189 FRAME-PARAM (optional) is the frame parameter this option specifies,
190 and VALUE is the value which is given to that frame parameter
191 \(most options use the argument for this, so VALUE is not present).")
193 (defconst command-line-ns-option-alist
194 '(("-NSAutoLaunch" 1 ns-ignore-1-arg
)
195 ("-NXAutoLaunch" 1 ns-ignore-1-arg
)
197 ("-NSHost" 1 ns-ignore-1-arg
)
198 ("-_NSMachLaunch" 1 ns-ignore-1-arg
)
199 ("-MachLaunch" 1 ns-ignore-1-arg
)
200 ("-NXOpen" 1 ns-ignore-1-arg
)
201 ("-NSOpen" 1 ns-handle-nxopen
)
202 ("-NXOpenTemp" 1 ns-ignore-1-arg
)
203 ("-NSOpenTemp" 1 ns-handle-nxopentemp
)
204 ("-GSFilePath" 1 ns-handle-nxopen
)
205 ;;("-bw" . x-handle-numeric-switch)
206 ;;("-d" . x-handle-display)
207 ;;("-display" . x-handle-display)
208 ("-name" 1 x-handle-name-switch
)
209 ("-title" 1 x-handle-switch title
)
210 ("-T" 1 x-handle-switch title
)
211 ("-r" 0 x-handle-switch reverse t
)
212 ("-rv" 0 x-handle-switch reverse t
)
213 ("-reverse" 0 x-handle-switch reverse t
)
214 ("-fn" 1 x-handle-switch font
)
215 ("-font" 1 x-handle-switch font
)
216 ("-ib" 1 x-handle-numeric-switch internal-border-width
)
217 ;;("-g" . x-handle-geometry)
218 ;;("-geometry" . x-handle-geometry)
219 ("-fg" 1 x-handle-switch foreground-color
)
220 ("-foreground" 1 x-handle-switch foreground-color
)
221 ("-bg" 1 x-handle-switch background-color
)
222 ("-background" 1 x-handle-switch background-color
)
223 ; ("-ms" 1 x-handle-switch mouse-color)
224 ("-itype" 0 x-handle-switch icon-type t
)
225 ("-i" 0 x-handle-switch icon-type t
)
226 ("-iconic" 0 x-handle-iconic icon-type t
)
227 ;;("-xrm" . x-handle-xrm-switch)
228 ("-cr" 1 x-handle-switch cursor-color
)
229 ("-vb" 0 x-handle-switch vertical-scroll-bars t
)
230 ("-hb" 0 x-handle-switch horizontal-scroll-bars t
)
231 ("-bd" 1 x-handle-switch
)
232 ;; ("--border-width" 1 x-handle-numeric-switch border-width)
233 ;; ("--display" 1 ns-handle-display)
234 ("--name" 1 x-handle-name-switch
)
235 ("--title" 1 x-handle-switch title
)
236 ("--reverse-video" 0 x-handle-switch reverse t
)
237 ("--font" 1 x-handle-switch font
)
238 ("--internal-border" 1 x-handle-numeric-switch internal-border-width
)
239 ;; ("--geometry" 1 ns-handle-geometry)
240 ("--foreground-color" 1 x-handle-switch foreground-color
)
241 ("--background-color" 1 x-handle-switch background-color
)
242 ("--mouse-color" 1 x-handle-switch mouse-color
)
243 ("--icon-type" 0 x-handle-switch icon-type t
)
244 ("--iconic" 0 x-handle-iconic
)
245 ;; ("--xrm" 1 ns-handle-xrm-switch)
246 ("--cursor-color" 1 x-handle-switch cursor-color
)
247 ("--vertical-scroll-bars" 0 x-handle-switch vertical-scroll-bars t
)
248 ("--border-color" 1 x-handle-switch border-width
))
249 "Alist of NS options.
250 Each element has the form
251 (NAME NUMARGS HANDLER FRAME-PARAM VALUE)
252 where NAME is the option name string, NUMARGS is the number of arguments
253 that the option accepts, HANDLER is a function to call to handle the option.
254 FRAME-PARAM (optional) is the frame parameter this option specifies,
255 and VALUE is the value which is given to that frame parameter
256 \(most options use the argument for this, so VALUE is not present).")
259 (defvar before-init-hook nil
260 "Normal hook run after handling urgent options but before loading init files.")
262 (defvar after-init-hook nil
263 "Normal hook run after loading the init files, `~/.emacs' and `default.el'.
264 There is no `condition-case' around the running of these functions;
265 therefore, if you set `debug-on-error' non-nil in `.emacs',
266 an error in one of these functions will invoke the debugger.")
268 (defvar emacs-startup-hook nil
269 "Normal hook run after loading init files and handling the command line.")
271 (defvar term-setup-hook nil
272 "Normal hook run after loading terminal-specific Lisp code.
273 It also follows `emacs-startup-hook'. This hook exists for users to set,
274 so as to override the definitions made by the terminal-specific file.
275 Emacs never sets this variable itself.")
277 (defvar inhibit-startup-hooks nil
278 "Non-nil means don't run `term-setup-hook' and `emacs-startup-hook'.
279 This is because we already did so.")
281 (defvar keyboard-type nil
282 "The brand of keyboard you are using.
283 This variable is used to define the proper function and keypad
284 keys for use under X. It is used in a fashion analogous to the
285 environment variable TERM.")
287 (defvar window-setup-hook nil
288 "Normal hook run to initialize window system display.
289 Emacs runs this hook after processing the command line arguments and loading
290 the user's init file.")
292 (defcustom initial-major-mode
'lisp-interaction-mode
293 "Major mode command symbol to use for the initial `*scratch*' buffer."
295 :group
'initialization
)
297 (defvar init-file-user nil
298 "Identity of user whose `.emacs' file is or was read.
299 The value is nil if `-q' or `--no-init-file' was specified,
300 meaning do not load any init file.
302 Otherwise, the value may be an empty string, meaning
303 use the init file for the user who originally logged in,
304 or it may be a string containing a user's name meaning
305 use that person's init file.
307 In either of the latter cases, `(concat \"~\" init-file-user \"/\")'
308 evaluates to the name of the directory where the `.emacs' file was
311 Setting `init-file-user' does not prevent Emacs from loading
312 `site-start.el'. The only way to do that is to use `--no-site-file'.")
314 (defcustom site-run-file
(purecopy "site-start")
315 "File containing site-wide run-time initializations.
316 This file is loaded at run-time before `~/.emacs'. It contains inits
317 that need to be in place for the entire site, but which, due to their
318 higher incidence of change, don't make sense to load into Emacs's
319 dumped image. Thus, the run-time load order is: 1. file described in
320 this variable, if non-nil; 2. `~/.emacs'; 3. `default.el'.
322 Don't use the `site-start.el' file for things some users may not like.
323 Put them in `default.el' instead, so that users can more easily
324 override them. Users can prevent loading `default.el' with the `-q'
325 option or by setting `inhibit-default-init' in their own init files,
326 but inhibiting `site-start.el' requires `--no-site-file', which
329 This variable is defined for customization so as to make
330 it visible in the relevant context. However, actually customizing it
331 is not allowed, since it would not work anyway. The only way to set
332 this variable usefully is to set it while building and dumping Emacs."
333 :type
'(choice (const :tag
"none" nil
) string
)
334 :group
'initialization
335 :initialize
'custom-initialize-default
336 :set
(lambda (_variable _value
)
337 (error "Customizing `site-run-file' does not work")))
339 (defcustom mail-host-address nil
340 "Name of this machine, for purposes of naming users."
341 :type
'(choice (const nil
) string
)
344 (defcustom user-mail-address
(if command-line-processed
346 (concat (user-login-name) "@"
347 (or mail-host-address
349 ;; Empty string means "not set yet".
351 "Full mailing address of this user.
352 This is initialized with environment variable `EMAIL' or, as a
353 fallback, using `mail-host-address'. This is done after your
354 init file is read, in case it sets `mail-host-address'."
358 (defcustom auto-save-list-file-prefix
359 (cond ((eq system-type
'ms-dos
)
360 ;; MS-DOS cannot have initial dot, and allows only 8.3 names
361 (concat user-emacs-directory
"auto-save.list/_s"))
363 (concat user-emacs-directory
"auto-save-list/.saves-")))
364 "Prefix for generating `auto-save-list-file-name'.
365 This is used after reading your `.emacs' file to initialize
366 `auto-save-list-file-name', by appending Emacs's pid and the system name,
367 if you have not already set `auto-save-list-file-name' yourself.
368 Directories in the prefix will be created if necessary.
369 Set this to nil if you want to prevent `auto-save-list-file-name'
370 from being initialized."
371 :type
'(choice (const :tag
"Don't record a session's auto save list" nil
)
375 (defvar emacs-basic-display nil
)
377 (defvar init-file-debug nil
)
379 (defvar init-file-had-error nil
380 "Non-nil if there was an error loading the user's init file.")
382 (defvar normal-top-level-add-subdirs-inode-list nil
)
384 (defvar no-blinking-cursor nil
)
386 (defvar default-frame-background-mode
)
388 (defvar pure-space-overflow nil
389 "Non-nil if building Emacs overflowed pure space.")
391 (defvar pure-space-overflow-message
(purecopy "\
392 Warning Warning!!! Pure space overflow !!!Warning Warning
393 \(See the node Pure Storage in the Lisp manual for details.)\n"))
395 (defcustom tutorial-directory
396 (file-name-as-directory (expand-file-name "tutorials" data-directory
))
397 "Directory containing the Emacs TUTORIAL files."
400 :initialize
'custom-initialize-delay
)
402 (defconst package-subdirectory-regexp
403 "\\([^.].*?\\)-\\([0-9]+\\(?:[.][0-9]+\\|\\(?:pre\\|beta\\|alpha\\)[0-9]+\\)*\\)"
404 "Regular expression matching the name of a package subdirectory.
405 The first subexpression is the package name.
406 The second subexpression is the version string.
408 The regexp should not contain a starting \"\\`\" or a trailing
409 \"\\'\"; those are added automatically by callers.")
411 (defun normal-top-level-add-subdirs-to-load-path ()
412 "Add all subdirectories of `default-directory' to `load-path'.
413 More precisely, this uses only the subdirectories whose names
414 start with letters or digits; it excludes any subdirectory named `RCS'
415 or `CVS', and any subdirectory that contains a file named `.nosearch'."
418 (pending (list default-directory
)))
419 ;; This loop does a breadth-first tree walk on DIR's subtree,
420 ;; putting each subdir into DIRS as its contents are examined.
422 (push (pop pending
) dirs
)
423 (let* ((this-dir (car dirs
))
424 (contents (directory-files this-dir
))
425 (default-directory this-dir
)
426 (canonicalized (if (fboundp 'untranslated-canonical-name
)
427 (untranslated-canonical-name this-dir
))))
428 ;; The Windows version doesn't report meaningful inode numbers, so
429 ;; use the canonicalized absolute file name of the directory instead.
430 (setq attrs
(or canonicalized
431 (nthcdr 10 (file-attributes this-dir
))))
432 (unless (member attrs normal-top-level-add-subdirs-inode-list
)
433 (push attrs normal-top-level-add-subdirs-inode-list
)
434 (dolist (file contents
)
435 (and (string-match "\\`[[:alnum:]]" file
)
436 ;; The lower-case variants of RCS and CVS are for DOS/Windows.
437 (not (member file
'("RCS" "CVS" "rcs" "cvs")))
438 ;; Avoid doing a `stat' when it isn't necessary because
439 ;; that can cause trouble when an NFS server is down.
440 (not (string-match "\\.elc?\\'" file
))
441 (file-directory-p file
)
442 (let ((expanded (expand-file-name file
)))
443 (or (file-exists-p (expand-file-name ".nosearch" expanded
))
444 (setq pending
(nconc pending
(list expanded
))))))))))
445 (normal-top-level-add-to-load-path (cdr (nreverse dirs
)))))
447 (defun normal-top-level-add-to-load-path (dirs)
448 "This function is called from a subdirs.el file.
449 It assumes that `default-directory' is the directory in which the
450 subdirs.el file exists, and it adds to `load-path' the subdirs of
451 that directory as specified in DIRS. Normally the elements of
453 (let ((tail load-path
)
454 (thisdir (directory-file-name default-directory
)))
456 ;;Don't go all the way to the nil terminator.
458 (not (equal thisdir
(car tail
)))
459 (not (and (memq system-type
'(ms-dos windows-nt
))
460 (equal (downcase thisdir
) (downcase (car tail
))))))
461 (setq tail
(cdr tail
)))
462 ;;Splice the new section in.
464 (setcdr tail
(append (mapcar 'expand-file-name dirs
) (cdr tail
))))))
466 (defun normal-top-level ()
467 (if command-line-processed
468 (message "Back to top level.")
469 (setq command-line-processed t
)
470 (let ((dir default-directory
))
471 (with-current-buffer "*Messages*"
472 ;; Make it easy to do like "tail -f".
473 (set (make-local-variable 'window-point-insertion-type
) t
)
474 ;; Give *Messages* the same default-directory as *scratch*,
475 ;; just to keep things predictable.
476 (setq default-directory dir
)))
477 ;; `user-full-name' is now known; reset its standard-value here.
478 (put 'user-full-name
'standard-value
479 (list (default-value 'user-full-name
)))
480 ;; Look in each dir in load-path for a subdirs.el file.
481 ;; If we find one, load it, which will add the appropriate subdirs
482 ;; of that dir into load-path,
483 ;; Look for a leim-list.el file too. Loading it will register
484 ;; available input methods.
485 (let ((tail load-path
) dir
)
487 (setq dir
(car tail
))
488 (let ((default-directory dir
))
489 (load (expand-file-name "subdirs.el") t t t
))
490 (let ((default-directory dir
))
491 (load (expand-file-name "leim-list.el") t t t
))
492 ;; We don't use a dolist loop and we put this "setq-cdr" command at
493 ;; the end, because the subdirs.el files may add elements to the end
494 ;; of load-path and we want to take it into account.
495 (setq tail
(cdr tail
))))
496 ;; If the PWD environment variable isn't accurate, delete it.
497 (let ((pwd (getenv "PWD")))
499 ;; Use FOO/., so that if FOO is a symlink, file-attributes
500 ;; describes the directory linked to, not FOO itself.
501 (or (equal (file-attributes
502 (concat (file-name-as-directory pwd
) "."))
504 (concat (file-name-as-directory default-directory
)
506 (setq process-environment
507 (delete (concat "PWD=" pwd
)
508 process-environment
)))))
509 (setq default-directory
(abbreviate-file-name default-directory
))
510 (let ((old-face-font-rescale-alist face-font-rescale-alist
))
513 ;; Do this again, in case .emacs defined more abbreviations.
514 (setq default-directory
(abbreviate-file-name default-directory
))
515 ;; Specify the file for recording all the auto save files of this session.
516 ;; This is used by recover-session.
517 (or auto-save-list-file-name
518 (and auto-save-list-file-prefix
519 (setq auto-save-list-file-name
520 ;; Under MS-DOS our PID is almost always reused between
521 ;; Emacs invocations. We need something more unique.
522 (cond ((eq system-type
'ms-dos
)
523 ;; We are going to access the auto-save
524 ;; directory, so make sure it exists.
526 (file-name-directory auto-save-list-file-prefix
)
531 auto-save-list-file-prefix
))
536 auto-save-list-file-prefix
539 (unless inhibit-startup-hooks
540 (run-hooks 'emacs-startup-hook
)
542 (run-hooks 'term-setup-hook
)))
544 ;; Don't do this if we failed to create the initial frame,
545 ;; for instance due to a dense colormap.
546 (when (or frame-initial-frame
547 ;; If frame-initial-frame has no meaning, do this anyway.
548 (not (and initial-window-system
550 (not (eq initial-window-system
'pc
)))))
552 ;; FIXME: The user's init file may change
553 ;; face-font-rescale-alist. However, the default face
554 ;; already has an assigned font object, which does not take
555 ;; face-font-rescale-alist into account. For such
556 ;; situations, we ought to have a way to find all font
557 ;; objects and regenerate them; currently we do not. As a
558 ;; workaround, we specifically reset te default face's :font
559 ;; attribute here. See bug#1785.
560 (unless (eq face-font-rescale-alist
561 old-face-font-rescale-alist
)
562 (set-face-attribute 'default nil
:font
(font-spec)))
564 ;; Modify the initial frame based on what .emacs puts into
566 (if (fboundp 'frame-notice-user-settings
)
567 (frame-notice-user-settings))
568 ;; Set the faces for the initial background mode even if
569 ;; frame-notice-user-settings didn't (such as on a tty).
570 ;; frame-set-background-mode is idempotent, so it won't
571 ;; cause any harm if it's already been done.
572 (if (fboundp 'frame-set-background-mode
)
573 (frame-set-background-mode (selected-frame))))
575 ;; Now we know the user's default font, so add it to the menu.
576 (if (fboundp 'font-menu-add-default
)
577 (font-menu-add-default))
578 (and window-setup-hook
579 (run-hooks 'window-setup-hook
))))
580 ;; Subprocesses of Emacs do not have direct access to the terminal, so
581 ;; unless told otherwise they should only assume a dumb terminal.
582 ;; We are careful to do it late (after term-setup-hook), although the
583 ;; new multi-tty code does not use $TERM any more there anyway.
584 (setenv "TERM" "dumb")
585 ;; Remove DISPLAY from the process-environment as well. This allows
586 ;; `callproc.c' to give it a useful adaptive default which is either
587 ;; the value of the `display' frame-parameter or the DISPLAY value
588 ;; from initial-environment.
589 (let ((display (frame-parameter nil
'display
)))
590 ;; Be careful which DISPLAY to remove from process-environment: follow
591 ;; the logic of `callproc.c'.
592 (if (stringp display
) (setq display
(concat "DISPLAY=" display
))
593 (dolist (varval initial-environment
)
594 (if (string-match "\\`DISPLAY=" varval
)
595 (setq display varval
))))
597 (delete display process-environment
)))))
599 ;; Precompute the keyboard equivalents in the menu bar items.
600 ;; Command-line options supported by tty's:
601 (defconst tty-long-option-alist
602 '(("--name" .
"-name")
604 ("--reverse-video" .
"-reverse")
605 ("--foreground-color" .
"-fg")
606 ("--background-color" .
"-bg")
607 ("--color" .
"-color")))
609 (defconst tool-bar-images-pixel-height
24
610 "Height in pixels of images in the tool-bar.")
612 (defvar tool-bar-originally-present nil
613 "Non-nil if tool-bars are present before user and site init files are read.")
615 (defvar handle-args-function-alist
'((nil . tty-handle-args
))
616 "Functions for processing window-system dependent command-line arguments.
617 Window system startup files should add their own function to this
618 alist, which should parse the command line arguments. Those
619 pertaining to the window system should be processed and removed
620 from the returned command line.")
622 (defvar window-system-initialization-alist
'((nil . ignore
))
623 "Alist of window-system initialization functions.
624 Window-system startup files should add their own initialization
625 function to this list. The function should take no arguments,
626 and initialize the window system environment to prepare for
627 opening the first frame (e.g. open a connection to an X server).")
629 (defun tty-handle-args (args)
630 "Handle the X-like command-line arguments \"-fg\", \"-bg\", \"-name\", etc."
634 (not (equal (car args
) "--")))
635 (let* ((argi (pop args
))
638 ;; Check for long options with attached arguments
639 ;; and separate out the attached option argument into argval.
640 (when (string-match "^\\(--[^=]*\\)=" argi
)
641 (setq argval
(substring argi
(match-end 0))
642 argi
(match-string 1 argi
)))
643 (when (string-match "^--" argi
)
644 (setq completion
(try-completion argi tty-long-option-alist
))
645 (if (eq completion t
)
646 ;; Exact match for long option.
647 (setq argi
(cdr (assoc argi tty-long-option-alist
)))
648 (if (stringp completion
)
649 (let ((elt (assoc completion tty-long-option-alist
)))
650 ;; Check for abbreviated long option.
652 (error "Option `%s' is ambiguous" argi
))
653 (setq argi
(cdr elt
)))
654 ;; Check for a short option.
657 (cond ((member argi
'("-fg" "-foreground"))
658 (push (cons 'foreground-color
(or argval
(pop args
)))
659 default-frame-alist
))
660 ((member argi
'("-bg" "-background"))
661 (push (cons 'background-color
(or argval
(pop args
)))
662 default-frame-alist
))
663 ((member argi
'("-T" "-name"))
664 (unless argval
(setq argval
(pop args
)))
668 (let ((case-fold-search t
)
670 (setq argval
(invocation-name))
672 ;; Change any . or * characters in name to
673 ;; hyphens, so as to emulate behavior on X.
675 (setq i
(string-match "[.*]" argval
))
678 default-frame-alist
))
679 ((member argi
'("-r" "-rv" "-reverse"))
681 default-frame-alist
))
682 ((equal argi
"-color")
683 (unless argval
(setq argval
8)) ; default --color means 8 ANSI colors
684 (push (cons 'tty-color-mode
686 ((numberp argval
) argval
)
687 ((string-match "-?[0-9]+" argval
)
688 (string-to-number argval
))
689 (t (intern argval
))))
690 default-frame-alist
))
695 (declare-function x-get-resource
"frame.c"
696 (attribute class
&optional component subclass
))
697 (declare-function tool-bar-mode
"tool-bar" (&optional arg
))
698 (declare-function tool-bar-setup
"tool-bar")
701 (defvar server-process
)
703 (defun command-line ()
704 (setq before-init-time
(current-time)
706 command-line-default-directory default-directory
)
708 ;; Force recomputation, in case it was computed during the dump.
709 (setq abbreviated-home-dir nil
)
711 ;; See if we should import version-control from the environment variable.
712 (let ((vc (getenv "VERSION_CONTROL")))
713 (cond ((eq vc nil
)) ;don't do anything if not set
714 ((member vc
'("t" "numbered"))
715 (setq version-control t
))
716 ((member vc
'("nil" "existing"))
717 (setq version-control nil
))
718 ((member vc
'("never" "simple"))
719 (setq version-control
'never
))))
721 ;;! This has been commented out; I currently find the behavior when
722 ;;! split-window-keep-point is nil disturbing, but if I can get used
723 ;;! to it, then it would be better to eliminate the option.
724 ;;! ;; Choose a good default value for split-window-keep-point.
725 ;;! (setq split-window-keep-point (> baud-rate 2400))
727 ;; Set the default strings to display in mode line for
728 ;; end-of-line formats that aren't native to this platform.
730 ((memq system-type
'(ms-dos windows-nt
))
731 (setq eol-mnemonic-unix
"(Unix)"
732 eol-mnemonic-mac
"(Mac)"))
733 (t ; this is for Unix/GNU/Linux systems
734 (setq eol-mnemonic-dos
"(DOS)"
735 eol-mnemonic-mac
"(Mac)")))
737 (set-locale-environment nil
)
739 ;; Convert preloaded file names in load-history to absolute.
740 (let ((simple-file-name
741 ;; Look for simple.el or simple.elc and use their directory
742 ;; as the place where all Lisp files live.
743 (locate-file "simple" load-path
(get-load-suffixes)))
745 ;; Don't abort if simple.el cannot be found, but print a warning.
746 (if (null simple-file-name
)
748 (princ "Warning: Could not find simple.el nor simple.elc"
749 'external-debugging-output
)
750 (terpri 'external-debugging-output
))
751 (setq lisp-dir
(file-truename (file-name-directory simple-file-name
)))
753 (mapcar (lambda (elt)
754 (if (and (stringp (car elt
))
755 (not (file-name-absolute-p (car elt
))))
756 (cons (concat lisp-dir
762 ;; Convert the arguments to Emacs internal representation.
763 (let ((args (cdr command-line-args
)))
766 (decode-coding-string (car args
) locale-coding-system t
))
770 (args (cdr command-line-args
))
773 ;; Figure out which user's init file to load,
774 ;; either from the environment or from the options.
775 (setq init-file-user
(if noninteractive nil
(user-login-name)))
776 ;; If user has not done su, use current $HOME to find .emacs.
778 (equal init-file-user
(user-real-login-name))
779 (setq init-file-user
""))
781 ;; Process the command-line args, and delete the arguments
782 ;; processed. This is consistent with the way main in emacs.c
784 (while (and (not done
) args
)
785 (let* ((longopts '(("--no-init-file") ("--no-site-file") ("--debug-init")
786 ("--user") ("--iconic") ("--icon-type") ("--quick")
787 ("--no-blinking-cursor") ("--basic-display")))
791 ;; Handle --OPTION=VALUE format.
792 (when (string-match "\\`\\(--[^=]*\\)=" argi
)
793 (setq argval
(substring argi
(match-end 0))
794 argi
(match-string 1 argi
)))
795 (when (string-match "\\`--." orig-argi
)
796 (let ((completion (try-completion argi longopts
)))
797 (cond ((eq completion t
)
798 (setq argi
(substring argi
1)))
799 ((stringp completion
)
800 (let ((elt (assoc completion longopts
)))
802 (error "Option `%s' is ambiguous" argi
))
803 (setq argi
(substring (car elt
) 1))))
808 ;; The --display arg is handled partly in C, partly in Lisp.
809 ;; When it shows up here, we just put it back to be handled
810 ;; by `command-line-1'.
811 ((member argi
'("-d" "-display"))
812 (setq display-arg
(list argi
(pop args
))))
813 ((member argi
'("-Q" "-quick"))
814 (setq init-file-user nil
816 inhibit-x-resources t
))
817 ((member argi
'("-D" "-basic-display"))
818 (setq no-blinking-cursor t
819 emacs-basic-display t
)
820 (push '(vertical-scroll-bars . nil
) initial-frame-alist
))
821 ((member argi
'("-q" "-no-init-file"))
822 (setq init-file-user nil
))
823 ((member argi
'("-u" "-user"))
824 (setq init-file-user
(or argval
(pop args
))
826 ((equal argi
"-no-site-file")
827 (setq site-run-file nil
))
828 ((equal argi
"-debug-init")
829 (setq init-file-debug t
))
830 ((equal argi
"-iconic")
831 (push '(visibility . icon
) initial-frame-alist
))
832 ((member argi
'("-nbc" "-no-blinking-cursor"))
833 (setq no-blinking-cursor t
))
834 ;; Push the popped arg back on the list of arguments.
838 ;; Was argval set but not used?
840 (error "Option `%s' doesn't allow an argument" argi
))))
842 ;; Re-attach the --display arg.
843 (and display-arg
(setq args
(append display-arg args
)))
845 ;; Re-attach the program name to the front of the arg list.
846 (and command-line-args
847 (setcdr command-line-args args
)))
849 ;; Make sure window system's init file was loaded in loadup.el if
850 ;; using a window system.
851 ;; Initialize the window-system only after processing the command-line
852 ;; args so that -Q can influence this initialization.
853 (condition-case error
854 (unless noninteractive
855 (if (and initial-window-system
858 (concat (symbol-name initial-window-system
) "-win")))))
859 (error "Unsupported window system `%s'" initial-window-system
))
860 ;; Process window-system specific command line parameters.
861 (setq command-line-args
863 (or (cdr (assq initial-window-system handle-args-function-alist
))
864 (error "Unsupported window system `%s'" initial-window-system
))
866 ;; Initialize the window system. (Open connection, etc.)
868 (or (cdr (assq initial-window-system window-system-initialization-alist
))
869 (error "Unsupported window system `%s'" initial-window-system
))))
870 ;; If there was an error, print the error message and exit.
873 (if (eq (car error
) 'error
)
874 (apply 'concat
(cdr error
))
875 (if (memq 'file-error
(get (car error
) 'error-conditions
))
878 (mapconcat (lambda (obj) (prin1-to-string obj t
))
879 (cdr (cdr error
)) ", "))
881 (get (car error
) 'error-message
)
882 (mapconcat (lambda (obj) (prin1-to-string obj t
))
884 'external-debugging-output
)
885 (terpri 'external-debugging-output
)
886 (setq initial-window-system nil
)
889 (run-hooks 'before-init-hook
)
891 ;; Under X, this creates the X frame and deletes the terminal frame.
894 ;; If X resources are available, use them to initialize the values
895 ;; of `tool-bar-mode' and `menu-bar-mode', as well as the value of
896 ;; `no-blinking-cursor' and the `cursor' face.
898 ((or noninteractive emacs-basic-display
)
899 (setq menu-bar-mode nil
901 no-blinking-cursor t
))
902 ((memq initial-window-system
'(x w32 ns
))
903 (let ((no-vals '("no" "off" "false" "0")))
904 (if (member (x-get-resource "menuBar" "MenuBar") no-vals
)
905 (setq menu-bar-mode nil
))
906 (if (member (x-get-resource "toolBar" "ToolBar") no-vals
)
907 (setq tool-bar-mode nil
))
908 (if (member (x-get-resource "cursorBlink" "CursorBlink")
910 (setq no-blinking-cursor t
)))
911 ;; If the cursorColor X resource exists, alter the `cursor' face
912 ;; spec, but mark it as changed outside of Customize.
913 (let ((color (x-get-resource "cursorColor" "CursorColor")))
915 (put 'cursor
'theme-face
916 `((changed ((t :background
,color
)))))
917 (put 'cursor
'face-modified t
)))))
920 (when (fboundp 'x-create-frame
)
921 ;; Set up the tool-bar (even in tty frames, since Emacs might open a
922 ;; graphical frame later).
923 (unless noninteractive
926 ;; Turn off blinking cursor if so specified in X resources. This is here
927 ;; only because all other settings of no-blinking-cursor are here.
928 (unless (or noninteractive
930 (and (memq window-system
'(x w32 ns
))
931 (not (member (x-get-resource "cursorBlink" "CursorBlink")
933 (setq no-blinking-cursor t
))
935 ;; Re-evaluate predefined variables whose initial value depends on
936 ;; the runtime context.
937 (mapc 'custom-reevaluate-setting
938 ;; Initialize them in the same order they were loaded, in case there
939 ;; are dependencies between them.
940 (prog1 (nreverse custom-delayed-init-variables
)
941 (setq custom-delayed-init-variables nil
)))
943 (normal-erase-is-backspace-setup-frame)
945 ;; Register default TTY colors for the case the terminal hasn't a
946 ;; terminal init file. We do this regardles of whether the terminal
947 ;; supports colors or not and regardless the current display type,
948 ;; since users can connect to color-capable terminals and also
949 ;; switch color support on or off in mid-session by setting the
950 ;; tty-color-mode frame parameter.
951 ;; Exception: the `pc' ``window system'' has only 16 fixed colors,
952 ;; and they are already set at this point by a suitable function in
953 ;; window-system-initialization-alist.
954 (or (eq initial-window-system
'pc
)
955 (tty-register-default-colors))
957 ;; Record whether the tool-bar is present before the user and site
958 ;; init files are processed. frame-notice-user-settings uses this
959 ;; to determine if the tool-bar has been disabled by the init files,
960 ;; and the frame needs to be resized.
961 (when (fboundp 'frame-notice-user-settings
)
962 (let ((tool-bar-lines (or (assq 'tool-bar-lines initial-frame-alist
)
963 (assq 'tool-bar-lines default-frame-alist
))))
964 (setq tool-bar-originally-present
967 (not (eq 0 (cdr tool-bar-lines
)))))))
969 (let ((old-scalable-fonts-allowed scalable-fonts-allowed
)
970 (old-font-list-limit font-list-limit
)
971 (old-face-ignored-fonts face-ignored-fonts
))
973 ;; Run the site-start library if it exists. The point of this file is
974 ;; that it is run before .emacs. There is no point in doing this after
975 ;; .emacs; that is useless.
976 ;; Note that user-init-file is nil at this point. Code that might
977 ;; be loaded from site-run-file and wants to test if -q was given
978 ;; should check init-file-user instead, since that is already set.
979 ;; See cus-edit.el for an example.
981 (load site-run-file t t
))
983 ;; Sites should not disable this. Only individuals should disable
984 ;; the startup screen.
985 (setq inhibit-startup-screen nil
)
987 ;; Warn for invalid user name.
989 (if (string-match "[~/:\n]" init-file-user
)
990 (display-warning 'initialization
991 (format "Invalid user name %s"
994 (if (file-directory-p (expand-file-name
995 ;; We don't support ~USER on MS-Windows
996 ;; and MS-DOS except for the current
997 ;; user, and always load .emacs from
998 ;; the current user's home directory
999 ;; (see below). So always check "~",
1000 ;; even if invoked with "-u USER", or
1001 ;; if $USER or $LOGNAME are set to
1002 ;; something different.
1003 (if (memq system-type
'(windows-nt ms-dos
))
1005 (concat "~" init-file-user
))))
1007 (display-warning 'initialization
1008 (format "User %s has no home directory"
1012 ;; Load that user's init file, or the default one, or none.
1013 (let (debug-on-error-from-init-file
1014 debug-on-error-should-be-set
1015 (debug-on-error-initial
1016 (if (eq init-file-debug t
) 'startup init-file-debug
))
1017 (orig-enable-multibyte (default-value 'enable-multibyte-characters
)))
1018 (let ((debug-on-error debug-on-error-initial
)
1019 ;; This function actually reads the init files.
1024 (let ((user-init-file-1
1026 ((eq system-type
'ms-dos
)
1027 (concat "~" init-file-user
"/_emacs"))
1028 ((not (eq system-type
'windows-nt
))
1029 (concat "~" init-file-user
"/.emacs"))
1030 ;; Else deal with the Windows situation
1031 ((directory-files "~" nil
"^\\.emacs\\(\\.elc?\\)?$")
1032 ;; Prefer .emacs on Windows.
1034 ((directory-files "~" nil
"^_emacs\\(\\.elc?\\)?$")
1035 ;; Also support _emacs for compatibility, but warn about it.
1036 (push '(initialization
1037 "`_emacs' init file is deprecated, please use `.emacs'")
1038 delayed-warnings-list
)
1040 (t ;; But default to .emacs if _emacs does not exist.
1042 ;; This tells `load' to store the file name found
1043 ;; into user-init-file.
1044 (setq user-init-file t
)
1045 (load user-init-file-1 t t
)
1047 (when (eq user-init-file t
)
1048 ;; If we did not find ~/.emacs, try
1049 ;; ~/.emacs.d/init.el.
1053 (file-name-as-directory
1054 (concat "~" init-file-user
"/.emacs.d")))))
1055 (load otherfile t t
)
1057 ;; If we did not find the user's init file,
1058 ;; set user-init-file conclusively.
1059 ;; Don't let it be set from default.el.
1060 (when (eq user-init-file t
)
1061 (setq user-init-file user-init-file-1
))))
1063 ;; If we loaded a compiled file, set
1064 ;; `user-init-file' to the source version if that
1066 (when (and user-init-file
1067 (equal (file-name-extension user-init-file
)
1069 (let* ((source (file-name-sans-extension user-init-file
))
1070 (alt (concat source
".el")))
1071 (setq source
(cond ((file-exists-p alt
) alt
)
1072 ((file-exists-p source
) source
)
1075 (when (file-newer-than-file-p source user-init-file
)
1076 (message "Warning: %s is newer than %s"
1077 source user-init-file
)
1079 (setq user-init-file source
))))
1081 (unless inhibit-default-init
1082 (let ((inhibit-startup-screen nil
))
1083 ;; Users are supposed to be told their rights.
1084 ;; (Plus how to get help and how to undo.)
1085 ;; Don't you dare turn this off for anyone
1087 (load "default" t t
)))))))))
1089 ;; Do this without a condition-case if the user wants to debug.
1091 (condition-case error
1094 (setq init-file-had-error nil
))
1098 (format "An error occurred while loading `%s':\n\n%s%s%s\n\n\
1099 To ensure normal operation, you should investigate and remove the
1100 cause of the error in your initialization file. Start Emacs with
1101 the `--debug-init' option to view a complete error backtrace."
1103 (get (car error
) 'error-message
)
1104 (if (cdr error
) ": " "")
1105 (mapconcat (lambda (s) (prin1-to-string s t
))
1108 (setq init-file-had-error t
))))
1110 (if (and deactivate-mark transient-mark-mode
)
1111 (with-current-buffer (window-buffer)
1114 ;; If the user has a file of abbrevs, read it (unless -batch).
1115 (when (and (not noninteractive
)
1116 (file-exists-p abbrev-file-name
)
1117 (file-readable-p abbrev-file-name
))
1118 (quietly-read-abbrev-file abbrev-file-name
))
1120 ;; If the abbrevs came entirely from the init file or the
1121 ;; abbrevs file, they do not need saving.
1122 (setq abbrevs-changed nil
)
1124 ;; If we can tell that the init file altered debug-on-error,
1125 ;; arrange to preserve the value that it set up.
1126 (or (eq debug-on-error debug-on-error-initial
)
1127 (setq debug-on-error-should-be-set t
1128 debug-on-error-from-init-file debug-on-error
)))
1129 (if debug-on-error-should-be-set
1130 (setq debug-on-error debug-on-error-from-init-file
))
1131 (unless (or (default-value 'enable-multibyte-characters
)
1132 (eq orig-enable-multibyte
(default-value
1133 'enable-multibyte-characters
)))
1134 ;; Init file changed to unibyte. Reset existing multibyte
1135 ;; buffers (probably *scratch*, *Messages*, *Minibuff-0*).
1136 ;; Arguably this should only be done if they're free of
1137 ;; multibyte characters.
1138 (mapc (lambda (buffer)
1139 (with-current-buffer buffer
1140 (if enable-multibyte-characters
1141 (set-buffer-multibyte nil
))))
1143 ;; Also re-set the language environment in case it was
1144 ;; originally done before unibyte was set and is sensitive to
1145 ;; unibyte (display table, terminal coding system &c).
1146 (set-language-environment current-language-environment
)))
1148 ;; Do this here in case the init file sets mail-host-address.
1149 (if (equal user-mail-address
"")
1150 (setq user-mail-address
(or (getenv "EMAIL")
1151 (concat (user-login-name) "@"
1152 (or mail-host-address
1155 ;; Originally face attributes were specified via
1156 ;; `font-lock-face-attributes'. Users then changed the default
1157 ;; face attributes by setting that variable. However, we try and
1158 ;; be back-compatible and respect its value if set except for
1159 ;; faces where M-x customize has been used to save changes for the
1161 (when (boundp 'font-lock-face-attributes
)
1162 (let ((face-attributes font-lock-face-attributes
))
1163 (while face-attributes
1164 (let* ((face-attribute (pop face-attributes
))
1165 (face (car face-attribute
)))
1166 ;; Rustle up a `defface' SPEC from a
1167 ;; `font-lock-face-attributes' entry.
1168 (unless (get face
'saved-face
)
1169 (let ((foreground (nth 1 face-attribute
))
1170 (background (nth 2 face-attribute
))
1171 (bold-p (nth 3 face-attribute
))
1172 (italic-p (nth 4 face-attribute
))
1173 (underline-p (nth 5 face-attribute
))
1176 (setq face-spec
(cons ':foreground
(cons foreground face-spec
))))
1178 (setq face-spec
(cons ':background
(cons background face-spec
))))
1180 (setq face-spec
(append '(:weight bold
) face-spec
)))
1182 (setq face-spec
(append '(:slant italic
) face-spec
)))
1184 (setq face-spec
(append '(:underline t
) face-spec
)))
1185 (face-spec-set face
(list (list t face-spec
)) nil
)))))))
1187 ;; If parameter have been changed in the init file which influence
1188 ;; face realization, clear the face cache so that new faces will
1190 (unless (and (eq scalable-fonts-allowed old-scalable-fonts-allowed
)
1191 (eq font-list-limit old-font-list-limit
)
1192 (eq face-ignored-fonts old-face-ignored-fonts
))
1193 (clear-face-cache)))
1195 ;; If any package directory exists, initialize the package system.
1197 package-enable-at-startup
1198 (catch 'package-dir-found
1200 (if (boundp 'package-directory-list
)
1201 (setq dirs package-directory-list
)
1202 (dolist (f load-path
)
1204 (equal (file-name-nondirectory f
) "site-lisp")
1205 (push (expand-file-name "elpa" f
) dirs
))))
1206 (push (if (boundp 'package-user-dir
)
1208 (locate-user-emacs-file "elpa"))
1211 (when (file-directory-p dir
)
1212 (dolist (subdir (directory-files dir
))
1213 (when (and (file-directory-p (expand-file-name subdir dir
))
1215 (concat "\\`" package-subdirectory-regexp
"\\'")
1217 (throw 'package-dir-found t
)))))))
1218 (package-initialize))
1220 (setq after-init-time
(current-time))
1221 (run-hooks 'after-init-hook
)
1223 ;; Decode all default-directory.
1224 (if (and (default-value 'enable-multibyte-characters
) locale-coding-system
)
1226 (dolist (elt (buffer-list))
1228 (if default-directory
1229 (setq default-directory
1230 (decode-coding-string default-directory
1231 locale-coding-system t
))))
1232 (setq command-line-default-directory
1233 (decode-coding-string command-line-default-directory
1234 locale-coding-system t
))))
1236 ;; If *scratch* exists and init file didn't change its mode, initialize it.
1237 (if (get-buffer "*scratch*")
1238 (with-current-buffer "*scratch*"
1239 (if (eq major-mode
'fundamental-mode
)
1240 (funcall initial-major-mode
))))
1242 ;; Load library for our terminal type.
1243 ;; User init file can set term-file-prefix to nil to prevent this.
1244 (unless (or noninteractive
1245 initial-window-system
)
1246 (tty-run-terminal-initialization (selected-frame)))
1248 ;; Update the out-of-memory error message based on user's key bindings
1249 ;; for save-some-buffers.
1250 (setq memory-signal-data
1252 (substitute-command-keys "Memory exhausted--use \\[save-some-buffers] then exit and restart Emacs")))
1254 ;; Process the remaining args.
1255 (command-line-1 (cdr command-line-args
))
1257 ;; If -batch, terminate after processing the command options.
1258 (if noninteractive
(kill-emacs t
))
1260 ;; In daemon mode, start the server to allow clients to connect.
1261 ;; This is done after loading the user's init file and after
1262 ;; processing all command line arguments to allow e.g. `server-name'
1263 ;; to be changed before the server starts.
1264 (let ((dn (daemonp)))
1266 (when (stringp dn
) (setq server-name dn
))
1269 (daemon-initialized)
1272 "Unable to start daemon: Emacs server named %S already running"
1274 (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."))
1277 ;; Run emacs-session-restore (session management) if started by
1278 ;; the session manager and we have a session manager connection.
1279 (if (and (boundp 'x-session-previous-id
)
1280 (stringp x-session-previous-id
))
1282 (emacs-session-restore x-session-previous-id
))))
1284 (defcustom initial-scratch-message
(purecopy "\
1285 ;; This buffer is for notes you don't want to save, and for Lisp evaluation.
1286 ;; If you want to create a file, visit that file with C-x C-f,
1287 ;; then enter the text in that file's own buffer.
1290 "Initial message displayed in *scratch* buffer at startup.
1291 If this is nil, no message will be displayed."
1292 :type
'(choice (text :tag
"Message")
1293 (const :tag
"none" nil
))
1294 :group
'initialization
)
1297 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1298 ;;; Fancy splash screen
1299 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1301 (defconst fancy-startup-text
1302 `((:face
(variable-pitch font-lock-comment-face
)
1305 ,(lambda (_button) (browse-url "http://www.gnu.org/software/emacs/"))
1306 "Browse http://www.gnu.org/software/emacs/")
1307 ", one component of the "
1310 (if (eq system-type
'gnu
/linux
)
1312 ,(lambda (_button) (browse-url "http://www.gnu.org/gnu/linux-and-gnu.html"))
1313 "Browse http://www.gnu.org/gnu/linux-and-gnu.html")
1314 `("GNU" ,(lambda (_button) (describe-gnu-project))
1315 "Display info on the GNU project")))
1316 " operating system.\n\n"
1317 :face variable-pitch
1318 :link
("Emacs Tutorial" ,(lambda (_button) (help-with-tutorial)))
1319 "\tLearn basic keystroke commands"
1321 (let* ((en "TUTORIAL")
1322 (tut (or (get-language-info current-language-environment
1325 (title (with-temp-buffer
1326 (insert-file-contents
1327 (expand-file-name tut tutorial-directory
)
1329 (search-forward ".")
1330 (buffer-substring (point-min) (1- (point))))))
1331 ;; If there is a specific tutorial for the current language
1332 ;; environment and it is not English, append its title.
1333 (if (string= en tut
)
1335 (concat " (" title
")"))))
1337 :link
("Emacs Guided Tour"
1339 (browse-url "http://www.gnu.org/software/emacs/tour/"))
1340 "Browse http://www.gnu.org/software/emacs/tour/")
1341 "\tOverview of Emacs features at gnu.org\n"
1342 :link
("View Emacs Manual" ,(lambda (_button) (info-emacs-manual)))
1343 "\tView the Emacs manual using Info\n"
1344 :link
("Absence of Warranty" ,(lambda (_button) (describe-no-warranty)))
1345 "\tGNU Emacs comes with "
1346 :face
(variable-pitch (:slant oblique
))
1347 "ABSOLUTELY NO WARRANTY\n"
1348 :face variable-pitch
1349 :link
("Copying Conditions" ,(lambda (_button) (describe-copying)))
1350 "\tConditions for redistributing and changing Emacs\n"
1351 :link
("Ordering Manuals" ,(lambda (_button) (view-order-manuals)))
1352 "\tPurchasing printed copies of manuals\n"
1354 "A list of texts to show in the middle part of splash screens.
1355 Each element in the list should be a list of strings or pairs
1356 `:face FACE', like `fancy-splash-insert' accepts them.")
1358 (defconst fancy-about-text
1359 `((:face
(variable-pitch font-lock-comment-face
)
1362 ,(lambda (_button) (browse-url "http://www.gnu.org/software/emacs/"))
1363 "Browse http://www.gnu.org/software/emacs/")
1364 ", one component of the "
1367 (if (eq system-type
'gnu
/linux
)
1370 (browse-url "http://www.gnu.org/gnu/linux-and-gnu.html"))
1371 "Browse http://www.gnu.org/gnu/linux-and-gnu.html")
1372 `("GNU" ,(lambda (_button) (describe-gnu-project))
1373 "Display info on the GNU project.")))
1374 " operating system.\n"
1375 :face
(variable-pitch font-lock-builtin-face
)
1377 ,(lambda () (emacs-version))
1379 :face
(variable-pitch (:height
0.8))
1380 ,(lambda () emacs-copyright
)
1382 :face variable-pitch
1385 (view-file (expand-file-name "AUTHORS" data-directory
))
1386 (goto-char (point-min))))
1387 "\tMany people have contributed code included in GNU Emacs\n"
1388 :link
("Contributing"
1390 (view-file (expand-file-name "CONTRIBUTE" data-directory
))
1391 (goto-char (point-min))))
1392 "\tHow to contribute improvements to Emacs\n"
1394 :link
("GNU and Freedom" ,(lambda (_button) (describe-gnu-project)))
1395 "\tWhy we developed GNU Emacs, and the GNU operating system\n"
1396 :link
("Absence of Warranty" ,(lambda (_button) (describe-no-warranty)))
1397 "\tGNU Emacs comes with "
1398 :face
(variable-pitch (:slant oblique
))
1399 "ABSOLUTELY NO WARRANTY\n"
1400 :face variable-pitch
1401 :link
("Copying Conditions" ,(lambda (_button) (describe-copying)))
1402 "\tConditions for redistributing and changing Emacs\n"
1403 :link
("Getting New Versions" ,(lambda (_button) (describe-distribution)))
1404 "\tHow to obtain the latest version of Emacs\n"
1405 :link
("Ordering Manuals" ,(lambda (_button) (view-order-manuals)))
1406 "\tBuying printed manuals from the FSF\n"
1408 :link
("Emacs Tutorial" ,(lambda (_button) (help-with-tutorial)))
1409 "\tLearn basic Emacs keystroke commands"
1411 (let* ((en "TUTORIAL")
1412 (tut (or (get-language-info current-language-environment
1415 (title (with-temp-buffer
1416 (insert-file-contents
1417 (expand-file-name tut tutorial-directory
)
1419 (search-forward ".")
1420 (buffer-substring (point-min) (1- (point))))))
1421 ;; If there is a specific tutorial for the current language
1422 ;; environment and it is not English, append its title.
1423 (if (string= en tut
)
1425 (concat " (" title
")"))))
1427 :link
("Emacs Guided Tour"
1429 (browse-url "http://www.gnu.org/software/emacs/tour/"))
1430 "Browse http://www.gnu.org/software/emacs/tour/")
1431 "\tSee an overview of Emacs features at gnu.org"))
1432 "A list of texts to show in the middle part of the About screen.
1433 Each element in the list should be a list of strings or pairs
1434 `:face FACE', like `fancy-splash-insert' accepts them.")
1437 (defgroup fancy-splash-screen
()
1438 "Fancy splash screen when Emacs starts."
1440 :group
'initialization
)
1442 (defcustom fancy-splash-image nil
1443 "The image to show in the splash screens, or nil for defaults."
1444 :group
'fancy-splash-screen
1445 :type
'(choice (const :tag
"Default" nil
)
1446 (file :tag
"File")))
1449 (defvar splash-screen-keymap
1450 (let ((map (make-sparse-keymap)))
1451 (suppress-keymap map
)
1452 (set-keymap-parent map button-buffer-map
)
1453 (define-key map
"\C-?" 'scroll-down
)
1454 (define-key map
" " 'scroll-up
)
1455 (define-key map
"q" 'exit-splash-screen
)
1457 "Keymap for splash screen buffer.")
1459 ;; These are temporary storage areas for the splash screen display.
1461 (defun fancy-splash-insert (&rest args
)
1462 "Insert text into the current buffer, with faces.
1463 Arguments from ARGS should be either strings; functions called
1464 with no args that return a string; pairs `:face FACE', where FACE
1465 is a face specification usable with `put-text-property'; or pairs
1466 `:link LINK' where LINK is a list of arguments to pass to
1467 `insert-button', of the form (LABEL ACTION [HELP-ECHO]), which
1468 specifies the button's label, `action' property and help-echo string.
1469 FACE and LINK can also be functions, which are evaluated to obtain
1470 a face or button specification."
1471 (let ((current-face nil
))
1473 (cond ((eq (car args
) :face
)
1474 (setq args
(cdr args
) current-face
(car args
))
1475 (if (functionp current-face
)
1476 (setq current-face
(funcall current-face
))))
1477 ((eq (car args
) :link
)
1478 (setq args
(cdr args
))
1479 (let ((spec (car args
)))
1480 (if (functionp spec
)
1481 (setq spec
(funcall spec
)))
1482 (insert-button (car spec
)
1483 'face
(list 'link current-face
)
1485 'help-echo
(concat "mouse-2, RET: "
1487 "Follow this link"))
1489 (t (insert (propertize (let ((it (car args
)))
1494 'help-echo
(startup-echo-area-message)))))
1495 (setq args
(cdr args
)))))
1497 (declare-function image-size
"image.c" (spec &optional pixels frame
))
1499 (defun fancy-splash-head ()
1500 "Insert the head part of the splash screen into the current buffer."
1501 (let* ((image-file (cond ((stringp fancy-splash-image
)
1504 (cond ((<= (display-planes) 8)
1505 (if (image-type-available-p 'xpm
)
1508 ((image-type-available-p 'svg
)
1510 ((image-type-available-p 'png
)
1512 ((image-type-available-p 'xpm
)
1516 (img (create-image image-file
))
1517 (image-width (and img
(car (image-size img
))))
1518 (window-width (window-width (selected-window))))
1520 (when (> window-width image-width
)
1521 ;; Center the image in the window.
1522 (insert (propertize " " 'display
1523 `(space :align-to
(+ center
(-0.5 .
,img
)))))
1525 ;; Change the color of the XPM version of the splash image
1526 ;; so that it is visible with a dark frame background.
1527 (when (and (memq 'xpm img
)
1528 (eq (frame-parameter nil
'background-mode
) 'dark
))
1529 (setq img
(append img
'(:color-symbols
(("#000000" .
"gray30"))))))
1531 ;; Insert the image with a help-echo and a link.
1532 (make-button (prog1 (point) (insert-image img
)) (point)
1534 'help-echo
"mouse-2, RET: Browse http://www.gnu.org/"
1535 'action
(lambda (_button) (browse-url "http://www.gnu.org/"))
1539 (defun fancy-startup-tail (&optional concise
)
1540 "Insert the tail part of the splash screen into the current buffer."
1542 (fancy-splash-insert
1543 :face
'variable-pitch
1545 :link
`("Open a File"
1546 ,(lambda (_button) (call-interactively 'find-file
))
1547 "Specify a new file's name, to edit the file")
1549 :link
`("Open Home Directory"
1550 ,(lambda (_button) (dired "~"))
1551 "Open your home directory, to operate on its files")
1553 :link
`("Customize Startup"
1554 ,(lambda (_button) (customize-group 'initialization
))
1555 "Change initialization settings including this screen")
1557 (fancy-splash-insert
1558 :face
'variable-pitch
"To quit a partially entered command, type "
1559 :face
'default
"Control-g"
1560 :face
'variable-pitch
".\n")
1561 (fancy-splash-insert :face
`(variable-pitch font-lock-builtin-face
)
1565 :face
'(variable-pitch (:height
0.8))
1568 (and auto-save-list-file-prefix
1569 ;; Don't signal an error if the
1570 ;; directory for auto-save-list files
1571 ;; does not yet exist.
1572 (file-directory-p (file-name-directory
1573 auto-save-list-file-prefix
))
1575 (file-name-directory auto-save-list-file-prefix
)
1578 (regexp-quote (file-name-nondirectory
1579 auto-save-list-file-prefix
)))
1581 (fancy-splash-insert :face
'(variable-pitch font-lock-comment-face
)
1582 "\nIf an Emacs session crashed recently, "
1584 :face
'(fixed-pitch font-lock-comment-face
)
1585 "Meta-x recover-session RET"
1586 :face
'(variable-pitch font-lock-comment-face
)
1588 " the files you were editing."))
1591 (fancy-splash-insert
1592 :face
'variable-pitch
"\n"
1593 :link
`("Dismiss this startup screen"
1595 (when startup-screen-inhibit-startup-screen
1596 (customize-set-variable 'inhibit-startup-screen t
)
1597 (customize-mark-to-save 'inhibit-startup-screen
)
1599 (let ((w (get-buffer-window "*GNU Emacs*")))
1600 (and w
(not (one-window-p)) (delete-window w
)))
1601 (kill-buffer "*GNU Emacs*")))
1603 (when (or user-init-file custom-file
)
1604 (let ((checked (create-image "checked.xpm"
1605 nil nil
:ascent
'center
))
1606 (unchecked (create-image "unchecked.xpm"
1607 nil nil
:ascent
'center
)))
1611 :off-glyph unchecked
1612 'checked nil
'display unchecked
'follow-link t
1613 'action
(lambda (button)
1614 (if (overlay-get button
'checked
)
1615 (progn (overlay-put button
'checked nil
)
1616 (overlay-put button
'display
1617 (overlay-get button
:off-glyph
))
1618 (setq startup-screen-inhibit-startup-screen
1620 (overlay-put button
'checked t
)
1621 (overlay-put button
'display
1622 (overlay-get button
:on-glyph
))
1623 (setq startup-screen-inhibit-startup-screen t
)))))
1624 (fancy-splash-insert :face
'(variable-pitch (:height
0.9))
1625 " Never show it again."))))
1627 (defun exit-splash-screen ()
1628 "Stop displaying the splash screen buffer."
1632 (defun fancy-startup-screen (&optional concise
)
1633 "Display fancy startup screen.
1634 If CONCISE is non-nil, display a concise version of the
1635 splash screen in another window."
1636 (let ((splash-buffer (get-buffer-create "*GNU Emacs*")))
1637 (with-current-buffer splash-buffer
1638 (let ((inhibit-read-only t
))
1640 (setq default-directory command-line-default-directory
)
1641 (make-local-variable 'startup-screen-inhibit-startup-screen
)
1642 (if pure-space-overflow
1643 (insert pure-space-overflow-message
))
1645 (fancy-splash-head))
1646 (dolist (text fancy-startup-text
)
1647 (apply #'fancy-splash-insert text
)
1649 (skip-chars-backward "\n")
1650 (delete-region (point) (point-max))
1652 (fancy-startup-tail concise
))
1653 (use-local-map splash-screen-keymap
)
1656 (set-buffer-modified-p nil
)
1657 (if (and view-read-only
(not view-mode
))
1658 (view-mode-enter nil
'kill-buffer
))
1659 (goto-char (point-min))
1660 (forward-line (if concise
2 4)))
1663 (display-buffer splash-buffer
)
1664 ;; If the splash screen is in a split window, fit it.
1665 (let ((window (get-buffer-window splash-buffer t
)))
1667 (eq window
(selected-window))
1668 (eq window
(next-window window
))
1669 (fit-window-to-buffer window
))))
1670 (switch-to-buffer splash-buffer
))))
1672 (defun fancy-about-screen ()
1673 "Display fancy About screen."
1674 (let ((frame (fancy-splash-frame)))
1675 (save-selected-window
1676 (select-frame frame
)
1677 (switch-to-buffer "*About GNU Emacs*")
1678 (setq buffer-undo-list t
)
1679 (let ((inhibit-read-only t
))
1681 (if pure-space-overflow
1682 (insert pure-space-overflow-message
))
1684 (dolist (text fancy-about-text
)
1685 (apply #'fancy-splash-insert text
)
1687 (set-buffer-modified-p nil
)
1688 (goto-char (point-min))
1689 (force-mode-line-update))
1690 (use-local-map splash-screen-keymap
)
1692 (message "%s" (startup-echo-area-message))
1693 (setq buffer-read-only t
)
1694 (goto-char (point-min))
1697 (defun fancy-splash-frame ()
1698 "Return the frame to use for the fancy splash screen.
1699 Returning non-nil does not mean we should necessarily
1700 use the fancy splash screen, but if we do use it,
1701 we put it on this frame."
1703 (dolist (frame (append (frame-list) (list (selected-frame))))
1704 (if (and (frame-visible-p frame
)
1705 (not (window-minibuffer-p (frame-selected-window frame
))))
1706 (setq chosen-frame frame
)))
1709 (defun use-fancy-splash-screens-p ()
1710 "Return t if fancy splash screens should be used."
1711 (when (and (display-graphic-p)
1712 (or (and (display-color-p)
1713 (image-type-available-p 'xpm
))
1714 (image-type-available-p 'pbm
)))
1715 (let ((frame (fancy-splash-frame)))
1717 (let* ((img (create-image (or fancy-splash-image
1718 (if (and (display-color-p)
1719 (image-type-available-p 'xpm
))
1720 "splash.xpm" "splash.pbm"))))
1721 (image-height (and img
(cdr (image-size img nil frame
))))
1722 ;; We test frame-height so that, if the frame is split
1723 ;; by displaying a warning, that doesn't cause the normal
1724 ;; splash screen to be used.
1725 (frame-height (1- (frame-height frame
))))
1726 (> frame-height
(+ image-height
19)))))))
1729 (defun normal-splash-screen (&optional startup concise
)
1730 "Display non-graphic splash screen.
1731 If optional argument STARTUP is non-nil, display the startup screen
1732 after Emacs starts. If STARTUP is nil, display the About screen.
1733 If CONCISE is non-nil, display a concise version of the
1734 splash screen in another window."
1735 (let ((splash-buffer (get-buffer-create "*About GNU Emacs*")))
1736 (with-current-buffer splash-buffer
1737 (setq buffer-read-only nil
)
1739 (setq default-directory command-line-default-directory
)
1740 (set (make-local-variable 'tab-width
) 8)
1742 (if pure-space-overflow
1743 (insert pure-space-overflow-message
))
1745 ;; The convention for this piece of code is that
1746 ;; each piece of output starts with one or two newlines
1747 ;; and does not end with any newlines.
1748 (insert (if startup
"Welcome to GNU Emacs" "This is GNU Emacs"))
1750 (if (eq system-type
'gnu
/linux
)
1751 ", one component of the GNU/Linux operating system.\n"
1752 ", a part of the GNU operating system.\n"))
1755 (if (display-mouse-p)
1756 ;; The user can use the mouse to activate menus
1757 ;; so give help in terms of menu items.
1758 (normal-mouse-startup-screen)
1760 ;; No mouse menus, so give help using kbd commands.
1761 (normal-no-mouse-startup-screen))
1763 (normal-about-screen))
1765 ;; The rest of the startup screen is the same on all
1766 ;; kinds of terminals.
1768 ;; Give information on recovering, if there was a crash.
1770 auto-save-list-file-prefix
1771 ;; Don't signal an error if the
1772 ;; directory for auto-save-list files
1773 ;; does not yet exist.
1774 (file-directory-p (file-name-directory
1775 auto-save-list-file-prefix
))
1777 (file-name-directory auto-save-list-file-prefix
)
1780 (regexp-quote (file-name-nondirectory
1781 auto-save-list-file-prefix
)))
1783 (insert "\n\nIf an Emacs session crashed recently, "
1784 "type Meta-x recover-session RET\nto recover"
1785 " the files you were editing.\n"))
1787 (use-local-map splash-screen-keymap
)
1789 ;; Display the input that we set up in the buffer.
1790 (set-buffer-modified-p nil
)
1791 (setq buffer-read-only t
)
1792 (if (and view-read-only
(not view-mode
))
1793 (view-mode-enter nil
'kill-buffer
))
1794 (if startup
(rename-buffer "*GNU Emacs*" t
))
1795 (goto-char (point-min)))
1797 (display-buffer splash-buffer
)
1798 (switch-to-buffer splash-buffer
))))
1800 (defun normal-mouse-startup-screen ()
1801 ;; The user can use the mouse to activate menus
1802 ;; so give help in terms of menu items.
1804 To follow a link, click Mouse-1 on it, or move to it and type RET.
1805 To quit a partially entered command, type Control-g.\n")
1807 (insert "\nImportant Help menu items:\n")
1808 (insert-button "Emacs Tutorial"
1809 'action
(lambda (_button) (help-with-tutorial))
1811 (insert "\t\tLearn basic Emacs keystroke commands\n")
1812 (insert-button "Read the Emacs Manual"
1813 'action
(lambda (_button) (info-emacs-manual))
1815 (insert "\tView the Emacs manual using Info\n")
1816 (insert-button "\(Non)Warranty"
1817 'action
(lambda (_button) (describe-no-warranty))
1819 (insert "\t\tGNU Emacs comes with ABSOLUTELY NO WARRANTY\n")
1820 (insert-button "Copying Conditions"
1821 'action
(lambda (_button) (describe-copying))
1823 (insert "\tConditions for redistributing and changing Emacs\n")
1824 (insert-button "More Manuals / Ordering Manuals"
1825 'action
(lambda (_button) (view-order-manuals))
1827 (insert " How to order printed manuals from the FSF\n")
1829 (insert "\nUseful tasks:\n")
1830 (insert-button "Visit New File"
1831 'action
(lambda (_button) (call-interactively 'find-file
))
1833 (insert "\t\tSpecify a new file's name, to edit the file\n")
1834 (insert-button "Open Home Directory"
1835 'action
(lambda (_button) (dired "~"))
1837 (insert "\tOpen your home directory, to operate on its files\n")
1838 (insert-button "Customize Startup"
1839 'action
(lambda (_button) (customize-group 'initialization
))
1841 (insert "\tChange initialization settings including this screen\n")
1843 (insert "\n" (emacs-version)
1844 "\n" emacs-copyright
))
1846 ;; No mouse menus, so give help using kbd commands.
1847 (defun normal-no-mouse-startup-screen ()
1849 ;; If keys have their default meanings,
1850 ;; use precomputed string to save lots of time.
1851 (let* ((c-h-accessible
1852 ;; If normal-erase-is-backspace is used on a tty, there's
1853 ;; no way to invoke C-h and you have to use F1 instead.
1854 (or (not (char-table-p keyboard-translate-table
))
1855 (eq (aref keyboard-translate-table ?\C-h
) ?\C-h
)))
1856 (minor-mode-overriding-map-alist
1857 (cons (cons (not c-h-accessible
)
1858 ;; If C-h can't be invoked, temporarily disable its
1859 ;; binding, so where-is uses alternative bindings.
1860 (let ((map (make-sparse-keymap)))
1861 (define-key map
[?\C-h
] 'undefined
)
1863 minor-mode-overriding-map-alist
)))
1865 (insert (format "\nGet help\t %s\n"
1866 (let ((where (where-is-internal 'help-command nil t
)))
1868 ((equal where
[?\C-h
])
1869 "C-h (Hold down CTRL and press h)")
1870 (where (key-description where
))
1872 (insert-button "Emacs manual"
1873 'action
(lambda (_button) (info-emacs-manual))
1875 (insert (substitute-command-keys"\t \\[info-emacs-manual]\t"))
1876 (insert-button "Browse manuals"
1877 'action
(lambda (_button) (Info-directory))
1879 (insert (substitute-command-keys "\t \\[info]\n"))
1880 (insert-button "Emacs tutorial"
1881 'action
(lambda (_button) (help-with-tutorial))
1883 (insert (substitute-command-keys
1884 "\t \\[help-with-tutorial]\tUndo changes\t \\[undo]\n"))
1885 (insert-button "Buy manuals"
1886 'action
(lambda (_button) (view-order-manuals))
1888 (insert (substitute-command-keys
1889 "\t \\[view-order-manuals]\tExit Emacs\t \\[save-buffers-kill-terminal]")))
1891 ;; Say how to use the menu bar with the keyboard.
1893 (insert-button "Activate menubar"
1894 'action
(lambda (_button) (tmm-menubar))
1896 (if (and (eq (key-binding "\M-`") 'tmm-menubar
)
1897 (eq (key-binding [f10]) 'tmm-menubar))
1898 (insert " F10 or ESC ` or M-`")
1899 (insert (substitute-command-keys " \\[tmm-menubar]")))
1901 ;; Many users seem to have problems with these.
1903 \(`C-' means use the CTRL key. `M-' means use the Meta (or Alt) key.
1904 If you have no Meta key, you may instead type ESC followed by the character.)")
1906 ;; Insert links to useful tasks
1907 (insert "\nUseful tasks:\n")
1909 (insert-button "Visit New File"
1910 'action (lambda (_button) (call-interactively 'find-file))
1913 (insert-button "Open Home Directory"
1914 'action (lambda (_button) (dired "~"))
1918 (insert-button "Customize Startup"
1919 'action (lambda (_button) (customize-group 'initialization))
1922 (insert-button "Open *scratch* buffer"
1923 'action (lambda (_button) (switch-to-buffer
1924 (get-buffer-create "*scratch*")))
1927 (insert "\n" (emacs-version) "\n" emacs-copyright "\n")
1929 (if (and (eq (key-binding "\C-h\C-c") 'describe-copying)
1930 (eq (key-binding "\C-h\C-d") 'describe-distribution)
1931 (eq (key-binding "\C-h\C-w") 'describe-no-warranty))
1935 GNU Emacs comes with ABSOLUTELY NO WARRANTY; type C-h C-w for ")
1936 (insert-button "full details"
1937 'action (lambda (_button) (describe-no-warranty))
1940 Emacs is Free Software--Free as in Freedom--so you can redistribute copies
1941 of Emacs and modify it; type C-h C-c to see ")
1942 (insert-button "the conditions"
1943 'action (lambda (_button) (describe-copying))
1946 Type C-h C-d for information on ")
1947 (insert-button "getting the latest version"
1948 'action (lambda (_button) (describe-distribution))
1951 (insert (substitute-command-keys
1953 GNU Emacs comes with ABSOLUTELY NO WARRANTY; type \\[describe-no-warranty] for "))
1954 (insert-button "full details"
1955 'action (lambda (_button) (describe-no-warranty))
1957 (insert (substitute-command-keys ".
1958 Emacs is Free Software--Free as in Freedom--so you can redistribute copies
1959 of Emacs and modify it; type \\[describe-copying] to see "))
1960 (insert-button "the conditions"
1961 'action (lambda (_button) (describe-copying))
1963 (insert (substitute-command-keys".
1964 Type \\[describe-distribution] for information on "))
1965 (insert-button "getting the latest version"
1966 'action (lambda (_button) (describe-distribution))
1970 (defun normal-about-screen ()
1971 (insert "\n" (emacs-version) "\n" emacs-copyright "\n\n")
1973 (insert "To follow a link, click Mouse-1 on it, or move to it and type RET.\n\n")
1975 (insert-button "Authors"
1978 (view-file (expand-file-name "AUTHORS" data-directory))
1979 (goto-char (point-min)))
1981 (insert "\t\tMany people have contributed code included in GNU Emacs\n")
1983 (insert-button "Contributing"
1986 (view-file (expand-file-name "CONTRIBUTE" data-directory))
1987 (goto-char (point-min)))
1989 (insert "\tHow to contribute improvements to Emacs\n\n")
1991 (insert-button "GNU and Freedom"
1992 'action (lambda (_button) (describe-gnu-project))
1994 (insert "\t\tWhy we developed GNU Emacs and the GNU system\n")
1996 (insert-button "Absence of Warranty"
1997 'action (lambda (_button) (describe-no-warranty))
1999 (insert "\tGNU Emacs comes with ABSOLUTELY NO WARRANTY\n")
2001 (insert-button "Copying Conditions"
2002 'action (lambda (_button) (describe-copying))
2004 (insert "\tConditions for redistributing and changing Emacs\n")
2006 (insert-button "Getting New Versions"
2007 'action (lambda (_button) (describe-distribution))
2009 (insert "\tHow to get the latest version of GNU Emacs\n")
2011 (insert-button "More Manuals / Ordering Manuals"
2012 'action (lambda (_button) (view-order-manuals))
2014 (insert "\tBuying printed manuals from the FSF\n"))
2016 (defun startup-echo-area-message ()
2018 "Starting Emacs daemon.")
2019 ((eq (key-binding "\C-h\C-a") 'about-emacs)
2020 "For information about GNU Emacs and the GNU system, type C-h C-a.")
2022 (substitute-command-keys
2023 "For information about GNU Emacs and the GNU system, type \
2024 \\[about-emacs]."))))
2026 (defun display-startup-echo-area-message ()
2027 (let ((resize-mini-windows t))
2028 (or noninteractive ;(input-pending-p) init-file-had-error
2029 ;; t if the init file says to inhibit the echo area startup message.
2030 (and inhibit-startup-echo-area-message
2032 (or (and (get 'inhibit-startup-echo-area-message 'saved-value)
2033 (equal inhibit-startup-echo-area-message
2034 (if (equal init-file-user "")
2037 ;; Wasn't set with custom; see if .emacs has a setq.
2040 (insert-file-contents user-init-file)
2043 "([ \t\n]*setq[ \t\n]+"
2044 "inhibit-startup-echo-area-message[ \t\n]+"
2047 (if (equal init-file-user "")
2053 (message "%s" (startup-echo-area-message)))))
2055 (defun display-startup-screen (&optional concise)
2056 "Display startup screen according to display.
2057 A fancy display is used on graphic displays, normal otherwise.
2059 If CONCISE is non-nil, display a concise version of the startup
2061 ;; Prevent recursive calls from server-process-filter.
2062 (if (not (get-buffer "*GNU Emacs*"))
2063 (if (use-fancy-splash-screens-p)
2064 (fancy-startup-screen concise)
2065 (normal-splash-screen t concise))))
2067 (defun display-about-screen ()
2068 "Display the *About GNU Emacs* buffer.
2069 A fancy display is used on graphic displays, normal otherwise."
2071 (if (use-fancy-splash-screens-p)
2072 (fancy-about-screen)
2073 (normal-splash-screen nil)))
2075 (defalias 'about-emacs 'display-about-screen)
2076 (defalias 'display-splash-screen 'display-startup-screen)
2078 (defun command-line-1 (args-left)
2079 (display-startup-echo-area-message)
2080 (when (and pure-space-overflow
2081 (not noninteractive))
2084 "Building Emacs overflowed pure space.\
2085 (See the node Pure Storage in the Lisp manual for details.)"
2088 (let ((file-count 0)
2089 (command-line-args-left args-left)
2091 (when command-line-args-left
2092 ;; We have command args; process them.
2093 (let ((dir command-line-default-directory)
2095 ;; This approach loses for "-batch -L DIR --eval "(require foo)",
2096 ;; if foo is intended to be found in DIR.
2098 ;; ;; The directories listed in --directory/-L options will *appear*
2099 ;; ;; at the front of `load-path' in the order they appear on the
2100 ;; ;; command-line. We cannot do this by *placing* them at the front
2101 ;; ;; in the order they appear, so we need this variable to hold them,
2105 ;; To DTRT we keep track of the splice point and modify `load-path'
2106 ;; straight away upon any --directory/-L option.
2108 just-files ;; t if this follows the magic -- option.
2109 ;; This includes our standard options' long versions
2110 ;; and long versions of what's on command-switch-alist.
2112 (append '("--funcall" "--load" "--insert" "--kill"
2113 "--directory" "--eval" "--execute" "--no-splash"
2114 "--find-file" "--visit" "--file" "--no-desktop")
2115 (mapcar (lambda (elt) (concat "-" (car elt)))
2116 command-switch-alist)))
2120 ;; Add the long X options to longopts.
2121 (dolist (tem command-line-x-option-alist)
2122 (if (string-match "^--" (car tem))
2123 (push (car tem) longopts)))
2125 ;; Add the long NS options to longopts.
2126 (dolist (tem command-line-ns-option-alist)
2127 (if (string-match "^--" (car tem))
2128 (push (list (car tem)) longopts)))
2130 ;; Loop, processing options.
2131 (while command-line-args-left
2132 (let* ((argi (car command-line-args-left))
2135 (setq command-line-args-left (cdr command-line-args-left))
2137 ;; Do preliminary decoding of the option.
2139 ;; After --, don't look for options; treat all args as files.
2141 ;; Convert long options to ordinary options
2142 ;; and separate out an attached option argument into argval.
2143 (when (string-match "\\`\\(--[^=]*\\)=" argi)
2144 (setq argval (substring argi (match-end 0))
2145 argi (match-string 1 argi)))
2146 (when (string-match "\\`--?[^-]" orig-argi)
2147 (setq completion (try-completion argi longopts))
2148 (if (eq completion t)
2149 (setq argi (substring argi 1))
2150 (if (stringp completion)
2151 (let ((elt (member completion longopts)))
2153 (error "Option `%s' is ambiguous" argi))
2154 (setq argi (substring (car elt) 1)))
2158 ;; Execute the option.
2159 (cond ((setq tem (assoc argi command-switch-alist))
2161 (let ((command-line-args-left
2162 (cons argval command-line-args-left)))
2163 (funcall (cdr tem) argi))
2164 (funcall (cdr tem) argi)))
2166 ((equal argi "-no-splash")
2167 (setq inhibit-startup-screen t))
2169 ((member argi '("-f" ; what the manual claims
2171 "-e")) ; what the source used to say
2172 (setq inhibit-startup-screen t)
2173 (setq tem (intern (or argval (pop command-line-args-left))))
2175 (command-execute tem)
2178 ((member argi '("-eval" "-execute"))
2179 (setq inhibit-startup-screen t)
2180 (eval (read (or argval (pop command-line-args-left)))))
2182 ((member argi '("-L" "-directory"))
2183 (setq tem (expand-file-name
2184 (command-line-normalize-file-name
2185 (or argval (pop command-line-args-left)))))
2186 (cond (splice (setcdr splice (cons tem (cdr splice)))
2187 (setq splice (cdr splice)))
2188 (t (setq load-path (cons tem load-path)
2189 splice load-path))))
2191 ((member argi '("-l" "-load"))
2192 (let* ((file (command-line-normalize-file-name
2193 (or argval (pop command-line-args-left))))
2194 ;; Take file from default dir if it exists there;
2195 ;; otherwise let `load' search for it.
2196 (file-ex (expand-file-name file)))
2197 (when (file-exists-p file-ex)
2198 (setq file file-ex))
2201 ;; This is used to handle -script. It's not clear
2202 ;; we need to document it (it is totally internal).
2203 ((member argi '("-scriptload"))
2204 (let* ((file (command-line-normalize-file-name
2205 (or argval (pop command-line-args-left))))
2206 ;; Take file from default dir.
2207 (file-ex (expand-file-name file)))
2208 (load file-ex nil t t)))
2210 ((equal argi "-insert")
2211 (setq inhibit-startup-screen t)
2212 (setq tem (or argval (pop command-line-args-left)))
2214 (error "File name omitted from `-insert' option"))
2215 (insert-file-contents (command-line-normalize-file-name tem)))
2217 ((equal argi "-kill")
2220 ;; This is for when they use --no-desktop with -q, or
2221 ;; don't load Desktop in their .emacs. If desktop.el
2222 ;; _is_ loaded, it will handle this switch, and we
2223 ;; won't see it by the time we get here.
2224 ((equal argi "-no-desktop")
2225 (message "\"--no-desktop\" ignored because the Desktop package is not loaded"))
2227 ((string-match "^\\+[0-9]+\\'" argi)
2228 (setq line (string-to-number argi)))
2230 ((string-match "^\\+\\([0-9]+\\):\\([0-9]+\\)\\'" argi)
2231 (setq line (string-to-number (match-string 1 argi))
2232 column (string-to-number (match-string 2 argi))))
2234 ((setq tem (assoc orig-argi command-line-x-option-alist))
2235 ;; Ignore X-windows options and their args if not using X.
2236 (setq command-line-args-left
2237 (nthcdr (nth 1 tem) command-line-args-left)))
2239 ((setq tem (assoc orig-argi command-line-ns-option-alist))
2240 ;; Ignore NS-windows options and their args if not using NS.
2241 (setq command-line-args-left
2242 (nthcdr (nth 1 tem) command-line-args-left)))
2244 ((member argi '("-find-file" "-file" "-visit"))
2245 (setq inhibit-startup-screen t)
2246 ;; An explicit option to specify visiting a file.
2247 (setq tem (or argval (pop command-line-args-left)))
2248 (unless (stringp tem)
2249 (error "File name omitted from `%s' option" argi))
2250 (setq file-count (1+ file-count))
2251 (let ((file (expand-file-name
2252 (command-line-normalize-file-name tem)
2254 (if (= file-count 1)
2255 (setq first-file-buffer (find-file file))
2256 (find-file-other-window file)))
2257 (unless (zerop line)
2258 (goto-char (point-min))
2259 (forward-line (1- line)))
2261 (unless (< column 1)
2262 (move-to-column (1- column)))
2265 ;; These command lines now have no effect.
2266 ((string-match "\\`--?\\(no-\\)?\\(uni\\|multi\\)byte$" argi)
2267 (display-warning 'initialization
2268 (format "Ignoring obsolete arg %s" argi)))
2271 (setq just-files t))
2273 ;; We have almost exhausted our options. See if the
2274 ;; user has made any other command-line options available
2275 (let ((hooks command-line-functions)
2278 (not (setq did-hook (funcall (car hooks)))))
2279 (setq hooks (cdr hooks)))
2281 ;; Presume that the argument is a file name.
2283 (if (string-match "\\`-" argi)
2284 (error "Unknown option `%s'" argi))
2285 (unless initial-window-system
2286 (setq inhibit-startup-screen t))
2287 (setq file-count (1+ file-count))
2290 (command-line-normalize-file-name orig-argi)
2292 (cond ((= file-count 1)
2293 (setq first-file-buffer (find-file file)))
2294 (inhibit-startup-screen
2295 (find-file-other-window file))
2296 (t (find-file file))))
2297 (unless (zerop line)
2298 (goto-char (point-min))
2299 (forward-line (1- line)))
2301 (unless (< column 1)
2302 (move-to-column (1- column)))
2303 (setq column 0))))))
2304 ;; In unusual circumstances, the execution of Lisp code due
2305 ;; to command-line options can cause the last visible frame
2306 ;; to be deleted. In this case, kill emacs to avoid an
2308 (unless (frame-live-p (selected-frame)) (kill-emacs nil))))))
2310 (when initial-buffer-choice
2311 (cond ((eq initial-buffer-choice t)
2312 (switch-to-buffer (get-buffer-create "*scratch*")))
2313 ((stringp initial-buffer-choice)
2314 (find-file initial-buffer-choice))))
2316 ;; If *scratch* exists and is empty, insert initial-scratch-message.
2317 (and initial-scratch-message
2318 (get-buffer "*scratch*")
2319 (with-current-buffer "*scratch*"
2320 (when (zerop (buffer-size))
2321 (insert initial-scratch-message)
2322 (set-buffer-modified-p nil))))
2324 (if (or inhibit-startup-screen
2325 initial-buffer-choice
2327 inhibit-x-resources)
2329 ;; Not displaying a startup screen. If 3 or more files
2330 ;; visited, and not all visible, show user what they all are.
2331 (and (> file-count 2)
2332 (not noninteractive)
2333 (not inhibit-startup-buffer-menu)
2334 (or (get-buffer-window first-file-buffer)
2337 ;; Display a startup screen, after some preparations.
2339 ;; If there are no switches to process, we might as well
2340 ;; run this hook now, and there may be some need to do it
2341 ;; before doing any output.
2342 (run-hooks 'emacs-startup-hook)
2343 (and term-setup-hook
2344 (run-hooks 'term-setup-hook))
2345 (setq inhibit-startup-hooks t)
2347 ;; It's important to notice the user settings before we
2348 ;; display the startup message; otherwise, the settings
2349 ;; won't take effect until the user gives the first
2350 ;; keystroke, and that's distracting.
2351 (when (fboundp 'frame-notice-user-settings)
2352 (frame-notice-user-settings))
2354 ;; If there are no switches to process, we might as well
2355 ;; run this hook now, and there may be some need to do it
2356 ;; before doing any output.
2357 (when window-setup-hook
2358 (run-hooks 'window-setup-hook)
2359 ;; Don't let the hook be run twice.
2360 (setq window-setup-hook nil))
2362 ;; ;; Do this now to avoid an annoying delay if the user
2363 ;; ;; clicks the menu bar during the sit-for.
2364 ;; (when (display-popup-menus-p)
2365 ;; (precompute-menubar-bindings))
2366 ;; (with-no-warnings
2367 ;; (setq menubar-bindings-done t))
2369 (if (> file-count 0)
2370 (display-startup-screen t)
2371 (display-startup-screen nil)))))
2373 (defun command-line-normalize-file-name (file)
2374 "Collapse multiple slashes to one, to handle non-Emacs file names."
2376 ;; Use arg 1 so that we don't collapse // at the start of the file name.
2377 ;; That is significant on some systems.
2378 ;; However, /// at the beginning is supposed to mean just /, not //.
2379 (if (string-match "^///+" file)
2380 (setq file (replace-match "/" t t file)))
2381 (and (memq system-type '(ms-dos windows-nt))
2382 (string-match "^[A-Za-z]:\\(\\\\[\\\\/]\\)" file) ; C:\/ or C:\\
2383 (setq file (replace-match "/" t t file 1)))
2384 (while (string-match "//+" file 1)
2385 (setq file (replace-match "/" t t file)))
2388 ;;; startup.el ends here