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 or
45 directory using `find-file'. If t, open the `*scratch*' buffer."
47 (const :tag
"Startup screen" nil
)
48 (directory :tag
"Directory" :value
"~/")
49 (file :tag
"File" :value
"~/.emacs")
50 (const :tag
"Lisp scratch buffer" t
))
52 :group
'initialization
)
54 (defcustom inhibit-startup-screen nil
55 "Non-nil inhibits the startup screen.
57 This is for use in your personal init file (but NOT site-start.el),
58 once you are familiar with the contents of the startup screen."
60 :group
'initialization
)
62 (defvaralias 'inhibit-splash-screen
'inhibit-startup-screen
)
63 (defvaralias 'inhibit-startup-message
'inhibit-startup-screen
)
65 (defvar startup-screen-inhibit-startup-screen nil
)
67 (defcustom inhibit-startup-echo-area-message nil
68 "Non-nil inhibits the initial startup echo area message.
69 Setting this variable takes effect
70 only if you do it with the customization buffer
71 or if your `.emacs' file contains a line of this form:
72 (setq inhibit-startup-echo-area-message \"YOUR-USER-NAME\")
73 If your `.emacs' file is byte-compiled, use the following form instead:
74 (eval '(setq inhibit-startup-echo-area-message \"YOUR-USER-NAME\"))
75 Thus, someone else using a copy of your `.emacs' file will see
76 the startup message unless he personally acts to inhibit it."
77 :type
'(choice (const :tag
"Don't inhibit")
78 (string :tag
"Enter your user name, to inhibit"))
79 :group
'initialization
)
81 (defcustom inhibit-default-init nil
82 "Non-nil inhibits loading the `default' library."
84 :group
'initialization
)
86 (defcustom inhibit-startup-buffer-menu nil
87 "Non-nil inhibits display of buffer list when more than 2 files are loaded."
89 :group
'initialization
)
91 (defvar command-switch-alist nil
92 "Alist of command-line switches.
93 Elements look like (SWITCH-STRING . HANDLER-FUNCTION).
94 HANDLER-FUNCTION receives the switch string as its sole argument;
95 the remaining command-line args are in the variable `command-line-args-left'.")
97 (defvar command-line-args-left nil
98 "List of command-line args not yet processed.")
100 (defvaralias 'argv
'command-line-args-left
101 ;; FIXME: Bad name for a dynamically bound variable.
102 "List of command-line args not yet processed.
103 This is a convenience alias, so that one can write \(pop argv\)
104 inside of --eval command line arguments in order to access
105 following arguments.")
107 (defvar command-line-functions nil
;; lrs 7/31/89
108 "List of functions to process unrecognized command-line arguments.
109 Each function should access the dynamically bound variables
110 `argi' (the current argument) and `command-line-args-left' (the remaining
111 arguments). The function should return non-nil only if it recognizes and
112 processes `argi'. If it does so, it may consume successive arguments by
113 altering `command-line-args-left' to remove them.")
115 (defvar command-line-default-directory nil
116 "Default directory to use for command line arguments.
117 This is normally copied from `default-directory' when Emacs starts.")
119 ;;; This is here, rather than in x-win.el, so that we can ignore these
120 ;;; options when we are not using X.
121 (defconst command-line-x-option-alist
122 '(("-bw" 1 x-handle-numeric-switch border-width
)
123 ("-d" 1 x-handle-display
)
124 ("-display" 1 x-handle-display
)
125 ("-name" 1 x-handle-name-switch
)
126 ("-title" 1 x-handle-switch title
)
127 ("-T" 1 x-handle-switch title
)
128 ("-r" 0 x-handle-switch reverse t
)
129 ("-rv" 0 x-handle-switch reverse t
)
130 ("-reverse" 0 x-handle-switch reverse t
)
131 ("-reverse-video" 0 x-handle-switch reverse t
)
132 ("-fn" 1 x-handle-switch font
)
133 ("-font" 1 x-handle-switch font
)
134 ("-fs" 0 x-handle-initial-switch fullscreen fullboth
)
135 ("-fw" 0 x-handle-initial-switch fullscreen fullwidth
)
136 ("-fh" 0 x-handle-initial-switch fullscreen fullheight
)
137 ("-mm" 0 x-handle-initial-switch fullscreen maximized
)
138 ("-ib" 1 x-handle-numeric-switch internal-border-width
)
139 ("-g" 1 x-handle-geometry
)
140 ("-lsp" 1 x-handle-numeric-switch line-spacing
)
141 ("-geometry" 1 x-handle-geometry
)
142 ("-fg" 1 x-handle-switch foreground-color
)
143 ("-foreground" 1 x-handle-switch foreground-color
)
144 ("-bg" 1 x-handle-switch background-color
)
145 ("-background" 1 x-handle-switch background-color
)
146 ("-ms" 1 x-handle-switch mouse-color
)
147 ("-nbi" 0 x-handle-switch icon-type nil
)
148 ("-iconic" 0 x-handle-iconic
)
149 ("-xrm" 1 x-handle-xrm-switch
)
150 ("-cr" 1 x-handle-switch cursor-color
)
151 ("-vb" 0 x-handle-switch vertical-scroll-bars t
)
152 ("-hb" 0 x-handle-switch horizontal-scroll-bars t
)
153 ("-bd" 1 x-handle-switch
)
154 ("--border-width" 1 x-handle-numeric-switch border-width
)
155 ("--display" 1 x-handle-display
)
156 ("--name" 1 x-handle-name-switch
)
157 ("--title" 1 x-handle-switch title
)
158 ("--reverse-video" 0 x-handle-switch reverse t
)
159 ("--font" 1 x-handle-switch font
)
160 ("--fullscreen" 0 x-handle-initial-switch fullscreen fullboth
)
161 ("--fullwidth" 0 x-handle-initial-switch fullscreen fullwidth
)
162 ("--fullheight" 0 x-handle-initial-switch fullscreen fullheight
)
163 ("--maximized" 0 x-handle-initial-switch fullscreen maximized
)
164 ("--internal-border" 1 x-handle-numeric-switch internal-border-width
)
165 ("--geometry" 1 x-handle-geometry
)
166 ("--foreground-color" 1 x-handle-switch foreground-color
)
167 ("--background-color" 1 x-handle-switch background-color
)
168 ("--mouse-color" 1 x-handle-switch mouse-color
)
169 ("--no-bitmap-icon" 0 x-handle-no-bitmap-icon
)
170 ("--iconic" 0 x-handle-iconic
)
171 ("--xrm" 1 x-handle-xrm-switch
)
172 ("--cursor-color" 1 x-handle-switch cursor-color
)
173 ("--vertical-scroll-bars" 0 x-handle-switch vertical-scroll-bars t
)
174 ("--line-spacing" 1 x-handle-numeric-switch line-spacing
)
175 ("--border-color" 1 x-handle-switch border-color
)
176 ("--smid" 1 x-handle-smid
)
177 ("--parent-id" 1 x-handle-parent-id
))
178 "Alist of X Windows options.
179 Each element has the form
180 (NAME NUMARGS HANDLER FRAME-PARAM VALUE)
181 where NAME is the option name string, NUMARGS is the number of arguments
182 that the option accepts, HANDLER is a function to call to handle the option.
183 FRAME-PARAM (optional) is the frame parameter this option specifies,
184 and VALUE is the value which is given to that frame parameter
185 \(most options use the argument for this, so VALUE is not present).")
187 (defconst command-line-ns-option-alist
188 '(("-NSAutoLaunch" 1 ns-ignore-1-arg
)
189 ("-NXAutoLaunch" 1 ns-ignore-1-arg
)
191 ("-NSHost" 1 ns-ignore-1-arg
)
192 ("-_NSMachLaunch" 1 ns-ignore-1-arg
)
193 ("-MachLaunch" 1 ns-ignore-1-arg
)
194 ("-NXOpen" 1 ns-ignore-1-arg
)
195 ("-NSOpen" 1 ns-handle-nxopen
)
196 ("-NXOpenTemp" 1 ns-ignore-1-arg
)
197 ("-NSOpenTemp" 1 ns-handle-nxopentemp
)
198 ("-GSFilePath" 1 ns-handle-nxopen
)
199 ;;("-bw" . x-handle-numeric-switch)
200 ;;("-d" . x-handle-display)
201 ;;("-display" . x-handle-display)
202 ("-name" 1 x-handle-name-switch
)
203 ("-title" 1 x-handle-switch title
)
204 ("-T" 1 x-handle-switch title
)
205 ("-r" 0 x-handle-switch reverse t
)
206 ("-rv" 0 x-handle-switch reverse t
)
207 ("-reverse" 0 x-handle-switch reverse t
)
208 ("-fn" 1 x-handle-switch font
)
209 ("-font" 1 x-handle-switch font
)
210 ("-ib" 1 x-handle-numeric-switch internal-border-width
)
211 ;;("-g" . x-handle-geometry)
212 ;;("-geometry" . x-handle-geometry)
213 ("-fg" 1 x-handle-switch foreground-color
)
214 ("-foreground" 1 x-handle-switch foreground-color
)
215 ("-bg" 1 x-handle-switch background-color
)
216 ("-background" 1 x-handle-switch background-color
)
217 ; ("-ms" 1 x-handle-switch mouse-color)
218 ("-itype" 0 x-handle-switch icon-type t
)
219 ("-i" 0 x-handle-switch icon-type t
)
220 ("-iconic" 0 x-handle-iconic icon-type t
)
221 ;;("-xrm" . x-handle-xrm-switch)
222 ("-cr" 1 x-handle-switch cursor-color
)
223 ("-vb" 0 x-handle-switch vertical-scroll-bars t
)
224 ("-hb" 0 x-handle-switch horizontal-scroll-bars t
)
225 ("-bd" 1 x-handle-switch
)
226 ;; ("--border-width" 1 x-handle-numeric-switch border-width)
227 ;; ("--display" 1 ns-handle-display)
228 ("--name" 1 x-handle-name-switch
)
229 ("--title" 1 x-handle-switch title
)
230 ("--reverse-video" 0 x-handle-switch reverse t
)
231 ("--font" 1 x-handle-switch font
)
232 ("--internal-border" 1 x-handle-numeric-switch internal-border-width
)
233 ;; ("--geometry" 1 ns-handle-geometry)
234 ("--foreground-color" 1 x-handle-switch foreground-color
)
235 ("--background-color" 1 x-handle-switch background-color
)
236 ("--mouse-color" 1 x-handle-switch mouse-color
)
237 ("--icon-type" 0 x-handle-switch icon-type t
)
238 ("--iconic" 0 x-handle-iconic
)
239 ;; ("--xrm" 1 ns-handle-xrm-switch)
240 ("--cursor-color" 1 x-handle-switch cursor-color
)
241 ("--vertical-scroll-bars" 0 x-handle-switch vertical-scroll-bars t
)
242 ("--border-color" 1 x-handle-switch border-width
))
243 "Alist of NS options.
244 Each element has the form
245 (NAME NUMARGS HANDLER FRAME-PARAM VALUE)
246 where NAME is the option name string, NUMARGS is the number of arguments
247 that the option accepts, HANDLER is a function to call to handle the option.
248 FRAME-PARAM (optional) is the frame parameter this option specifies,
249 and VALUE is the value which is given to that frame parameter
250 \(most options use the argument for this, so VALUE is not present).")
253 (defvar before-init-hook nil
254 "Normal hook run after handling urgent options but before loading init files.")
256 (defvar after-init-hook nil
257 "Normal hook run after loading the init files, `~/.emacs' and `default.el'.
258 There is no `condition-case' around the running of these functions;
259 therefore, if you set `debug-on-error' non-nil in `.emacs',
260 an error in one of these functions will invoke the debugger.")
262 (defvar emacs-startup-hook nil
263 "Normal hook run after loading init files and handling the command line.")
265 (defvar term-setup-hook nil
266 "Normal hook run after loading terminal-specific Lisp code.
267 It also follows `emacs-startup-hook'. This hook exists for users to set,
268 so as to override the definitions made by the terminal-specific file.
269 Emacs never sets this variable itself.")
271 (defvar inhibit-startup-hooks nil
272 "Non-nil means don't run `term-setup-hook' and `emacs-startup-hook'.
273 This is because we already did so.")
275 (defvar keyboard-type nil
276 "The brand of keyboard you are using.
277 This variable is used to define the proper function and keypad
278 keys for use under X. It is used in a fashion analogous to the
279 environment variable TERM.")
281 (defvar window-setup-hook nil
282 "Normal hook run to initialize window system display.
283 Emacs runs this hook after processing the command line arguments and loading
284 the user's init file.")
286 (defcustom initial-major-mode
'lisp-interaction-mode
287 "Major mode command symbol to use for the initial `*scratch*' buffer."
289 :group
'initialization
)
291 (defvar init-file-user nil
292 "Identity of user whose `.emacs' file is or was read.
293 The value is nil if `-q' or `--no-init-file' was specified,
294 meaning do not load any init file.
296 Otherwise, the value may be an empty string, meaning
297 use the init file for the user who originally logged in,
298 or it may be a string containing a user's name meaning
299 use that person's init file.
301 In either of the latter cases, `(concat \"~\" init-file-user \"/\")'
302 evaluates to the name of the directory where the `.emacs' file was
305 Setting `init-file-user' does not prevent Emacs from loading
306 `site-start.el'. The only way to do that is to use `--no-site-file'.")
308 (defcustom site-run-file
(purecopy "site-start")
309 "File containing site-wide run-time initializations.
310 This file is loaded at run-time before `~/.emacs'. It contains inits
311 that need to be in place for the entire site, but which, due to their
312 higher incidence of change, don't make sense to load into Emacs's
313 dumped image. Thus, the run-time load order is: 1. file described in
314 this variable, if non-nil; 2. `~/.emacs'; 3. `default.el'.
316 Don't use the `site-start.el' file for things some users may not like.
317 Put them in `default.el' instead, so that users can more easily
318 override them. Users can prevent loading `default.el' with the `-q'
319 option or by setting `inhibit-default-init' in their own init files,
320 but inhibiting `site-start.el' requires `--no-site-file', which
323 This variable is defined for customization so as to make
324 it visible in the relevant context. However, actually customizing it
325 is not allowed, since it would not work anyway. The only way to set
326 this variable usefully is to set it while building and dumping Emacs."
327 :type
'(choice (const :tag
"none" nil
) string
)
328 :group
'initialization
329 :initialize
'custom-initialize-default
330 :set
(lambda (_variable _value
)
331 (error "Customizing `site-run-file' does not work")))
333 (defcustom mail-host-address nil
334 "Name of this machine, for purposes of naming users."
335 :type
'(choice (const nil
) string
)
338 (defcustom user-mail-address
(if command-line-processed
340 (concat (user-login-name) "@"
341 (or mail-host-address
343 ;; Empty string means "not set yet".
345 "Full mailing address of this user.
346 This is initialized with environment variable `EMAIL' or, as a
347 fallback, using `mail-host-address'. This is done after your
348 init file is read, in case it sets `mail-host-address'."
352 (defcustom auto-save-list-file-prefix
353 (cond ((eq system-type
'ms-dos
)
354 ;; MS-DOS cannot have initial dot, and allows only 8.3 names
355 (concat user-emacs-directory
"auto-save.list/_s"))
357 (concat user-emacs-directory
"auto-save-list/.saves-")))
358 "Prefix for generating `auto-save-list-file-name'.
359 This is used after reading your `.emacs' file to initialize
360 `auto-save-list-file-name', by appending Emacs's pid and the system name,
361 if you have not already set `auto-save-list-file-name' yourself.
362 Directories in the prefix will be created if necessary.
363 Set this to nil if you want to prevent `auto-save-list-file-name'
364 from being initialized."
365 :type
'(choice (const :tag
"Don't record a session's auto save list" nil
)
369 (defvar emacs-basic-display nil
)
371 (defvar init-file-debug nil
)
373 (defvar init-file-had-error nil
374 "Non-nil if there was an error loading the user's init file.")
376 (defvar normal-top-level-add-subdirs-inode-list nil
)
378 (defvar no-blinking-cursor nil
)
380 (defvar default-frame-background-mode
)
382 (defvar pure-space-overflow nil
383 "Non-nil if building Emacs overflowed pure space.")
385 (defvar pure-space-overflow-message
(purecopy "\
386 Warning Warning!!! Pure space overflow !!!Warning Warning
387 \(See the node Pure Storage in the Lisp manual for details.)\n"))
389 (defcustom tutorial-directory
390 (file-name-as-directory (expand-file-name "tutorials" data-directory
))
391 "Directory containing the Emacs TUTORIAL files."
394 :initialize
'custom-initialize-delay
)
396 (defconst package-subdirectory-regexp
397 "\\([^.].*?\\)-\\([0-9]+\\(?:[.][0-9]+\\|\\(?:pre\\|beta\\|alpha\\)[0-9]+\\)*\\)"
398 "Regular expression matching the name of a package subdirectory.
399 The first subexpression is the package name.
400 The second subexpression is the version string.
402 The regexp should not contain a starting \"\\`\" or a trailing
403 \"\\'\"; those are added automatically by callers.")
405 (defun normal-top-level-add-subdirs-to-load-path ()
406 "Add all subdirectories of current directory to `load-path'.
407 More precisely, this uses only the subdirectories whose names
408 start with letters or digits; it excludes any subdirectory named `RCS'
409 or `CVS', and any subdirectory that contains a file named `.nosearch'."
412 (pending (list default-directory
)))
413 ;; This loop does a breadth-first tree walk on DIR's subtree,
414 ;; putting each subdir into DIRS as its contents are examined.
416 (push (pop pending
) dirs
)
417 (let* ((this-dir (car dirs
))
418 (contents (directory-files this-dir
))
419 (default-directory this-dir
)
420 (canonicalized (if (fboundp 'untranslated-canonical-name
)
421 (untranslated-canonical-name this-dir
))))
422 ;; The Windows version doesn't report meaningful inode numbers, so
423 ;; use the canonicalized absolute file name of the directory instead.
424 (setq attrs
(or canonicalized
425 (nthcdr 10 (file-attributes this-dir
))))
426 (unless (member attrs normal-top-level-add-subdirs-inode-list
)
427 (push attrs normal-top-level-add-subdirs-inode-list
)
428 (dolist (file contents
)
429 (and (string-match "\\`[[:alnum:]]" file
)
430 ;; The lower-case variants of RCS and CVS are for DOS/Windows.
431 (not (member file
'("RCS" "CVS" "rcs" "cvs")))
432 ;; Avoid doing a `stat' when it isn't necessary because
433 ;; that can cause trouble when an NFS server is down.
434 (not (string-match "\\.elc?\\'" file
))
435 (file-directory-p file
)
436 (let ((expanded (expand-file-name file
)))
437 (or (file-exists-p (expand-file-name ".nosearch" expanded
))
438 (setq pending
(nconc pending
(list expanded
))))))))))
439 (normal-top-level-add-to-load-path (cdr (nreverse dirs
)))))
441 (defun normal-top-level-add-to-load-path (dirs)
442 "This function is called from a subdirs.el file.
443 It assumes that `default-directory' is the directory in which the
444 subdirs.el file exists, and it adds to `load-path' the subdirs of
445 that directory as specified in DIRS. Normally the elements of
447 (let ((tail load-path
)
448 (thisdir (directory-file-name default-directory
)))
450 ;;Don't go all the way to the nil terminator.
452 (not (equal thisdir
(car tail
)))
453 (not (and (memq system-type
'(ms-dos windows-nt
))
454 (equal (downcase thisdir
) (downcase (car tail
))))))
455 (setq tail
(cdr tail
)))
456 ;;Splice the new section in.
458 (setcdr tail
(append (mapcar 'expand-file-name dirs
) (cdr tail
))))))
460 (defun normal-top-level ()
461 (if command-line-processed
462 (message "Back to top level.")
463 (setq command-line-processed t
)
464 (let ((dir default-directory
))
465 (with-current-buffer "*Messages*"
466 ;; Make it easy to do like "tail -f".
467 (set (make-local-variable 'window-point-insertion-type
) t
)
468 ;; Give *Messages* the same default-directory as *scratch*,
469 ;; just to keep things predictable.
470 (setq default-directory dir
)))
471 ;; `user-full-name' is now known; reset its standard-value here.
472 (put 'user-full-name
'standard-value
473 (list (default-value 'user-full-name
)))
474 ;; Look in each dir in load-path for a subdirs.el file.
475 ;; If we find one, load it, which will add the appropriate subdirs
476 ;; of that dir into load-path,
477 ;; Look for a leim-list.el file too. Loading it will register
478 ;; available input methods.
479 (let ((tail load-path
) dir
)
481 (setq dir
(car tail
))
482 (let ((default-directory dir
))
483 (load (expand-file-name "subdirs.el") t t t
))
484 (let ((default-directory dir
))
485 (load (expand-file-name "leim-list.el") t t t
))
486 ;; We don't use a dolist loop and we put this "setq-cdr" command at
487 ;; the end, because the subdirs.el files may add elements to the end
488 ;; of load-path and we want to take it into account.
489 (setq tail
(cdr tail
))))
490 ;; If the PWD environment variable isn't accurate, delete it.
491 (let ((pwd (getenv "PWD")))
493 ;; Use FOO/., so that if FOO is a symlink, file-attributes
494 ;; describes the directory linked to, not FOO itself.
495 (or (equal (file-attributes
496 (concat (file-name-as-directory pwd
) "."))
498 (concat (file-name-as-directory default-directory
)
500 (setq process-environment
501 (delete (concat "PWD=" pwd
)
502 process-environment
)))))
503 (setq default-directory
(abbreviate-file-name default-directory
))
504 (let ((old-face-font-rescale-alist face-font-rescale-alist
))
507 ;; Do this again, in case .emacs defined more abbreviations.
508 (setq default-directory
(abbreviate-file-name default-directory
))
509 ;; Specify the file for recording all the auto save files of this session.
510 ;; This is used by recover-session.
511 (or auto-save-list-file-name
512 (and auto-save-list-file-prefix
513 (setq auto-save-list-file-name
514 ;; Under MS-DOS our PID is almost always reused between
515 ;; Emacs invocations. We need something more unique.
516 (cond ((eq system-type
'ms-dos
)
517 ;; We are going to access the auto-save
518 ;; directory, so make sure it exists.
520 (file-name-directory auto-save-list-file-prefix
)
525 auto-save-list-file-prefix
))
530 auto-save-list-file-prefix
533 (unless inhibit-startup-hooks
534 (run-hooks 'emacs-startup-hook
)
536 (run-hooks 'term-setup-hook
)))
538 ;; Don't do this if we failed to create the initial frame,
539 ;; for instance due to a dense colormap.
540 (when (or frame-initial-frame
541 ;; If frame-initial-frame has no meaning, do this anyway.
542 (not (and initial-window-system
544 (not (eq initial-window-system
'pc
)))))
546 ;; FIXME: The user's init file may change
547 ;; face-font-rescale-alist. However, the default face
548 ;; already has an assigned font object, which does not take
549 ;; face-font-rescale-alist into account. For such
550 ;; situations, we ought to have a way to find all font
551 ;; objects and regenerate them; currently we do not. As a
552 ;; workaround, we specifically reset te default face's :font
553 ;; attribute here. See bug#1785.
554 (unless (eq face-font-rescale-alist
555 old-face-font-rescale-alist
)
556 (set-face-attribute 'default nil
:font
(font-spec)))
558 ;; Modify the initial frame based on what .emacs puts into
560 (if (fboundp 'frame-notice-user-settings
)
561 (frame-notice-user-settings))
562 ;; Set the faces for the initial background mode even if
563 ;; frame-notice-user-settings didn't (such as on a tty).
564 ;; frame-set-background-mode is idempotent, so it won't
565 ;; cause any harm if it's already been done.
566 (if (fboundp 'frame-set-background-mode
)
567 (frame-set-background-mode (selected-frame))))
569 ;; Now we know the user's default font, so add it to the menu.
570 (if (fboundp 'font-menu-add-default
)
571 (font-menu-add-default))
572 (and window-setup-hook
573 (run-hooks 'window-setup-hook
))))
574 ;; Subprocesses of Emacs do not have direct access to the terminal, so
575 ;; unless told otherwise they should only assume a dumb terminal.
576 ;; We are careful to do it late (after term-setup-hook), although the
577 ;; new multi-tty code does not use $TERM any more there anyway.
578 (setenv "TERM" "dumb")
579 ;; Remove DISPLAY from the process-environment as well. This allows
580 ;; `callproc.c' to give it a useful adaptive default which is either
581 ;; the value of the `display' frame-parameter or the DISPLAY value
582 ;; from initial-environment.
583 (let ((display (frame-parameter nil
'display
)))
584 ;; Be careful which DISPLAY to remove from process-environment: follow
585 ;; the logic of `callproc.c'.
586 (if (stringp display
) (setq display
(concat "DISPLAY=" display
))
587 (dolist (varval initial-environment
)
588 (if (string-match "\\`DISPLAY=" varval
)
589 (setq display varval
))))
591 (delete display process-environment
)))))
593 ;; Precompute the keyboard equivalents in the menu bar items.
594 ;; Command-line options supported by tty's:
595 (defconst tty-long-option-alist
596 '(("--name" .
"-name")
598 ("--reverse-video" .
"-reverse")
599 ("--foreground-color" .
"-fg")
600 ("--background-color" .
"-bg")
601 ("--color" .
"-color")))
603 (defconst tool-bar-images-pixel-height
24
604 "Height in pixels of images in the tool-bar.")
606 (defvar tool-bar-originally-present nil
607 "Non-nil if tool-bars are present before user and site init files are read.")
609 (defvar handle-args-function-alist
'((nil . tty-handle-args
))
610 "Functions for processing window-system dependent command-line arguments.
611 Window system startup files should add their own function to this
612 alist, which should parse the command line arguments. Those
613 pertaining to the window system should be processed and removed
614 from the returned command line.")
616 (defvar window-system-initialization-alist
'((nil . ignore
))
617 "Alist of window-system initialization functions.
618 Window-system startup files should add their own initialization
619 function to this list. The function should take no arguments,
620 and initialize the window system environment to prepare for
621 opening the first frame (e.g. open a connection to an X server).")
623 (defun tty-handle-args (args)
624 "Handle the X-like command-line arguments \"-fg\", \"-bg\", \"-name\", etc."
628 (not (equal (car args
) "--")))
629 (let* ((argi (pop args
))
632 ;; Check for long options with attached arguments
633 ;; and separate out the attached option argument into argval.
634 (when (string-match "^\\(--[^=]*\\)=" argi
)
635 (setq argval
(substring argi
(match-end 0))
636 argi
(match-string 1 argi
)))
637 (when (string-match "^--" argi
)
638 (setq completion
(try-completion argi tty-long-option-alist
))
639 (if (eq completion t
)
640 ;; Exact match for long option.
641 (setq argi
(cdr (assoc argi tty-long-option-alist
)))
642 (if (stringp completion
)
643 (let ((elt (assoc completion tty-long-option-alist
)))
644 ;; Check for abbreviated long option.
646 (error "Option `%s' is ambiguous" argi
))
647 (setq argi
(cdr elt
)))
648 ;; Check for a short option.
651 (cond ((member argi
'("-fg" "-foreground"))
652 (push (cons 'foreground-color
(or argval
(pop args
)))
653 default-frame-alist
))
654 ((member argi
'("-bg" "-background"))
655 (push (cons 'background-color
(or argval
(pop args
)))
656 default-frame-alist
))
657 ((member argi
'("-T" "-name"))
658 (unless argval
(setq argval
(pop args
)))
662 (let ((case-fold-search t
)
664 (setq argval
(invocation-name))
666 ;; Change any . or * characters in name to
667 ;; hyphens, so as to emulate behavior on X.
669 (setq i
(string-match "[.*]" argval
))
672 default-frame-alist
))
673 ((member argi
'("-r" "-rv" "-reverse"))
675 default-frame-alist
))
676 ((equal argi
"-color")
677 (unless argval
(setq argval
8)) ; default --color means 8 ANSI colors
678 (push (cons 'tty-color-mode
680 ((numberp argval
) argval
)
681 ((string-match "-?[0-9]+" argval
)
682 (string-to-number argval
))
683 (t (intern argval
))))
684 default-frame-alist
))
689 (declare-function x-get-resource
"frame.c"
690 (attribute class
&optional component subclass
))
691 (declare-function tool-bar-mode
"tool-bar" (&optional arg
))
692 (declare-function tool-bar-setup
"tool-bar")
695 (defvar server-process
)
697 (defun command-line ()
698 (setq before-init-time
(current-time)
700 command-line-default-directory default-directory
)
702 ;; Force recomputation, in case it was computed during the dump.
703 (setq abbreviated-home-dir nil
)
705 ;; See if we should import version-control from the environment variable.
706 (let ((vc (getenv "VERSION_CONTROL")))
707 (cond ((eq vc nil
)) ;don't do anything if not set
708 ((member vc
'("t" "numbered"))
709 (setq version-control t
))
710 ((member vc
'("nil" "existing"))
711 (setq version-control nil
))
712 ((member vc
'("never" "simple"))
713 (setq version-control
'never
))))
715 ;;! This has been commented out; I currently find the behavior when
716 ;;! split-window-keep-point is nil disturbing, but if I can get used
717 ;;! to it, then it would be better to eliminate the option.
718 ;;! ;; Choose a good default value for split-window-keep-point.
719 ;;! (setq split-window-keep-point (> baud-rate 2400))
721 ;; Set the default strings to display in mode line for
722 ;; end-of-line formats that aren't native to this platform.
724 ((memq system-type
'(ms-dos windows-nt
))
725 (setq eol-mnemonic-unix
"(Unix)"
726 eol-mnemonic-mac
"(Mac)"))
727 (t ; this is for Unix/GNU/Linux systems
728 (setq eol-mnemonic-dos
"(DOS)"
729 eol-mnemonic-mac
"(Mac)")))
731 (set-locale-environment nil
)
733 ;; Convert preloaded file names in load-history to absolute.
734 (let ((simple-file-name
735 ;; Look for simple.el or simple.elc and use their directory
736 ;; as the place where all Lisp files live.
737 (locate-file "simple" load-path
(get-load-suffixes)))
739 ;; Don't abort if simple.el cannot be found, but print a warning.
740 (if (null simple-file-name
)
742 (princ "Warning: Could not find simple.el nor simple.elc"
743 'external-debugging-output
)
744 (terpri 'external-debugging-output
))
745 (setq lisp-dir
(file-truename (file-name-directory simple-file-name
)))
747 (mapcar (lambda (elt)
748 (if (and (stringp (car elt
))
749 (not (file-name-absolute-p (car elt
))))
750 (cons (concat lisp-dir
756 ;; Convert the arguments to Emacs internal representation.
757 (let ((args (cdr command-line-args
)))
760 (decode-coding-string (car args
) locale-coding-system t
))
764 (args (cdr command-line-args
))
767 ;; Figure out which user's init file to load,
768 ;; either from the environment or from the options.
769 (setq init-file-user
(if noninteractive nil
(user-login-name)))
770 ;; If user has not done su, use current $HOME to find .emacs.
772 (equal init-file-user
(user-real-login-name))
773 (setq init-file-user
""))
775 ;; Process the command-line args, and delete the arguments
776 ;; processed. This is consistent with the way main in emacs.c
778 (while (and (not done
) args
)
779 (let* ((longopts '(("--no-init-file") ("--no-site-file") ("--debug-init")
780 ("--user") ("--iconic") ("--icon-type") ("--quick")
781 ("--no-blinking-cursor") ("--basic-display")))
785 ;; Handle --OPTION=VALUE format.
786 (when (string-match "\\`\\(--[^=]*\\)=" argi
)
787 (setq argval
(substring argi
(match-end 0))
788 argi
(match-string 1 argi
)))
789 (when (string-match "\\`--." orig-argi
)
790 (let ((completion (try-completion argi longopts
)))
791 (cond ((eq completion t
)
792 (setq argi
(substring argi
1)))
793 ((stringp completion
)
794 (let ((elt (assoc completion longopts
)))
796 (error "Option `%s' is ambiguous" argi
))
797 (setq argi
(substring (car elt
) 1))))
802 ;; The --display arg is handled partly in C, partly in Lisp.
803 ;; When it shows up here, we just put it back to be handled
804 ;; by `command-line-1'.
805 ((member argi
'("-d" "-display"))
806 (setq display-arg
(list argi
(pop args
))))
807 ((member argi
'("-Q" "-quick"))
808 (setq init-file-user nil
810 inhibit-x-resources t
))
811 ((member argi
'("-D" "-basic-display"))
812 (setq no-blinking-cursor t
813 emacs-basic-display t
)
814 (push '(vertical-scroll-bars . nil
) initial-frame-alist
))
815 ((member argi
'("-q" "-no-init-file"))
816 (setq init-file-user nil
))
817 ((member argi
'("-u" "-user"))
818 (setq init-file-user
(or argval
(pop args
))
820 ((equal argi
"-no-site-file")
821 (setq site-run-file nil
))
822 ((equal argi
"-debug-init")
823 (setq init-file-debug t
))
824 ((equal argi
"-iconic")
825 (push '(visibility . icon
) initial-frame-alist
))
826 ((member argi
'("-nbc" "-no-blinking-cursor"))
827 (setq no-blinking-cursor t
))
828 ;; Push the popped arg back on the list of arguments.
832 ;; Was argval set but not used?
834 (error "Option `%s' doesn't allow an argument" argi
))))
836 ;; Re-attach the --display arg.
837 (and display-arg
(setq args
(append display-arg args
)))
839 ;; Re-attach the program name to the front of the arg list.
840 (and command-line-args
841 (setcdr command-line-args args
)))
843 ;; Make sure window system's init file was loaded in loadup.el if
844 ;; using a window system.
845 ;; Initialize the window-system only after processing the command-line
846 ;; args so that -Q can influence this initialization.
847 (condition-case error
848 (unless noninteractive
849 (if (and initial-window-system
852 (concat (symbol-name initial-window-system
) "-win")))))
853 (error "Unsupported window system `%s'" initial-window-system
))
854 ;; Process window-system specific command line parameters.
855 (setq command-line-args
857 (or (cdr (assq initial-window-system handle-args-function-alist
))
858 (error "Unsupported window system `%s'" initial-window-system
))
860 ;; Initialize the window system. (Open connection, etc.)
862 (or (cdr (assq initial-window-system window-system-initialization-alist
))
863 (error "Unsupported window system `%s'" initial-window-system
))))
864 ;; If there was an error, print the error message and exit.
867 (if (eq (car error
) 'error
)
868 (apply 'concat
(cdr error
))
869 (if (memq 'file-error
(get (car error
) 'error-conditions
))
872 (mapconcat (lambda (obj) (prin1-to-string obj t
))
873 (cdr (cdr error
)) ", "))
875 (get (car error
) 'error-message
)
876 (mapconcat (lambda (obj) (prin1-to-string obj t
))
878 'external-debugging-output
)
879 (terpri 'external-debugging-output
)
880 (setq initial-window-system nil
)
883 (run-hooks 'before-init-hook
)
885 ;; Under X, this creates the X frame and deletes the terminal frame.
888 ;; If X resources are available, use them to initialize the values
889 ;; of `tool-bar-mode' and `menu-bar-mode', as well as the value of
890 ;; `no-blinking-cursor' and the `cursor' face.
892 ((or noninteractive emacs-basic-display
)
893 (setq menu-bar-mode nil
895 no-blinking-cursor t
))
896 ((memq initial-window-system
'(x w32 ns
))
897 (let ((no-vals '("no" "off" "false" "0")))
898 (if (member (x-get-resource "menuBar" "MenuBar") no-vals
)
899 (setq menu-bar-mode nil
))
900 (if (member (x-get-resource "toolBar" "ToolBar") no-vals
)
901 (setq tool-bar-mode nil
))
902 (if (member (x-get-resource "cursorBlink" "CursorBlink")
904 (setq no-blinking-cursor t
)))
905 ;; If the cursorColor X resource exists, alter the `cursor' face
906 ;; spec, but mark it as changed outside of Customize.
907 (let ((color (x-get-resource "cursorColor" "CursorColor")))
909 (put 'cursor
'theme-face
910 `((changed ((t :background
,color
)))))
911 (put 'cursor
'face-modified t
)))))
914 (when (fboundp 'x-create-frame
)
915 ;; Set up the tool-bar (even in tty frames, since Emacs might open a
916 ;; graphical frame later).
917 (unless noninteractive
920 ;; Turn off blinking cursor if so specified in X resources. This is here
921 ;; only because all other settings of no-blinking-cursor are here.
922 (unless (or noninteractive
924 (and (memq window-system
'(x w32 ns
))
925 (not (member (x-get-resource "cursorBlink" "CursorBlink")
927 (setq no-blinking-cursor t
))
929 ;; Re-evaluate predefined variables whose initial value depends on
930 ;; the runtime context.
931 (mapc 'custom-reevaluate-setting
932 ;; Initialize them in the same order they were loaded, in case there
933 ;; are dependencies between them.
934 (prog1 (nreverse custom-delayed-init-variables
)
935 (setq custom-delayed-init-variables nil
)))
937 (normal-erase-is-backspace-setup-frame)
939 ;; Register default TTY colors for the case the terminal hasn't a
940 ;; terminal init file. We do this regardles of whether the terminal
941 ;; supports colors or not and regardless the current display type,
942 ;; since users can connect to color-capable terminals and also
943 ;; switch color support on or off in mid-session by setting the
944 ;; tty-color-mode frame parameter.
945 ;; Exception: the `pc' ``window system'' has only 16 fixed colors,
946 ;; and they are already set at this point by a suitable function in
947 ;; window-system-initialization-alist.
948 (or (eq initial-window-system
'pc
)
949 (tty-register-default-colors))
951 ;; Record whether the tool-bar is present before the user and site
952 ;; init files are processed. frame-notice-user-settings uses this
953 ;; to determine if the tool-bar has been disabled by the init files,
954 ;; and the frame needs to be resized.
955 (when (fboundp 'frame-notice-user-settings
)
956 (let ((tool-bar-lines (or (assq 'tool-bar-lines initial-frame-alist
)
957 (assq 'tool-bar-lines default-frame-alist
))))
958 (setq tool-bar-originally-present
961 (not (eq 0 (cdr tool-bar-lines
)))))))
963 (let ((old-scalable-fonts-allowed scalable-fonts-allowed
)
964 (old-font-list-limit font-list-limit
)
965 (old-face-ignored-fonts face-ignored-fonts
))
967 ;; Run the site-start library if it exists. The point of this file is
968 ;; that it is run before .emacs. There is no point in doing this after
969 ;; .emacs; that is useless.
970 ;; Note that user-init-file is nil at this point. Code that might
971 ;; be loaded from site-run-file and wants to test if -q was given
972 ;; should check init-file-user instead, since that is already set.
973 ;; See cus-edit.el for an example.
975 (load site-run-file t t
))
977 ;; Sites should not disable this. Only individuals should disable
978 ;; the startup screen.
979 (setq inhibit-startup-screen nil
)
981 ;; Warn for invalid user name.
983 (if (string-match "[~/:\n]" init-file-user
)
984 (display-warning 'initialization
985 (format "Invalid user name %s"
988 (if (file-directory-p (expand-file-name
989 ;; We don't support ~USER on MS-Windows
990 ;; and MS-DOS except for the current
991 ;; user, and always load .emacs from
992 ;; the current user's home directory
993 ;; (see below). So always check "~",
994 ;; even if invoked with "-u USER", or
995 ;; if $USER or $LOGNAME are set to
996 ;; something different.
997 (if (memq system-type
'(windows-nt ms-dos
))
999 (concat "~" init-file-user
))))
1001 (display-warning 'initialization
1002 (format "User %s has no home directory"
1006 ;; Load that user's init file, or the default one, or none.
1007 (let (debug-on-error-from-init-file
1008 debug-on-error-should-be-set
1009 (debug-on-error-initial
1010 (if (eq init-file-debug t
) 'startup init-file-debug
))
1011 (orig-enable-multibyte (default-value 'enable-multibyte-characters
)))
1012 (let ((debug-on-error debug-on-error-initial
)
1013 ;; This function actually reads the init files.
1018 (let ((user-init-file-1
1020 ((eq system-type
'ms-dos
)
1021 (concat "~" init-file-user
"/_emacs"))
1022 ((not (eq system-type
'windows-nt
))
1023 (concat "~" init-file-user
"/.emacs"))
1024 ;; Else deal with the Windows situation
1025 ((directory-files "~" nil
"^\\.emacs\\(\\.elc?\\)?$")
1026 ;; Prefer .emacs on Windows.
1028 ((directory-files "~" nil
"^_emacs\\(\\.elc?\\)?$")
1029 ;; Also support _emacs for compatibility, but warn about it.
1030 (push '(initialization
1031 "`_emacs' init file is deprecated, please use `.emacs'")
1032 delayed-warnings-list
)
1034 (t ;; But default to .emacs if _emacs does not exist.
1036 ;; This tells `load' to store the file name found
1037 ;; into user-init-file.
1038 (setq user-init-file t
)
1039 (load user-init-file-1 t t
)
1041 (when (eq user-init-file t
)
1042 ;; If we did not find ~/.emacs, try
1043 ;; ~/.emacs.d/init.el.
1047 (file-name-as-directory
1048 (concat "~" init-file-user
"/.emacs.d")))))
1049 (load otherfile t t
)
1051 ;; If we did not find the user's init file,
1052 ;; set user-init-file conclusively.
1053 ;; Don't let it be set from default.el.
1054 (when (eq user-init-file t
)
1055 (setq user-init-file user-init-file-1
))))
1057 ;; If we loaded a compiled file, set
1058 ;; `user-init-file' to the source version if that
1060 (when (and user-init-file
1061 (equal (file-name-extension user-init-file
)
1063 (let* ((source (file-name-sans-extension user-init-file
))
1064 (alt (concat source
".el")))
1065 (setq source
(cond ((file-exists-p alt
) alt
)
1066 ((file-exists-p source
) source
)
1069 (when (file-newer-than-file-p source user-init-file
)
1070 (message "Warning: %s is newer than %s"
1071 source user-init-file
)
1073 (setq user-init-file source
))))
1075 (unless inhibit-default-init
1076 (let ((inhibit-startup-screen nil
))
1077 ;; Users are supposed to be told their rights.
1078 ;; (Plus how to get help and how to undo.)
1079 ;; Don't you dare turn this off for anyone
1081 (load "default" t t
)))))))))
1083 ;; Do this without a condition-case if the user wants to debug.
1085 (condition-case error
1088 (setq init-file-had-error nil
))
1092 (format "An error occurred while loading `%s':\n\n%s%s%s\n\n\
1093 To ensure normal operation, you should investigate and remove the
1094 cause of the error in your initialization file. Start Emacs with
1095 the `--debug-init' option to view a complete error backtrace."
1097 (get (car error
) 'error-message
)
1098 (if (cdr error
) ": " "")
1099 (mapconcat (lambda (s) (prin1-to-string s t
))
1102 (setq init-file-had-error t
))))
1104 (if (and deactivate-mark transient-mark-mode
)
1105 (with-current-buffer (window-buffer)
1108 ;; If the user has a file of abbrevs, read it (unless -batch).
1109 (when (and (not noninteractive
)
1110 (file-exists-p abbrev-file-name
)
1111 (file-readable-p abbrev-file-name
))
1112 (quietly-read-abbrev-file abbrev-file-name
))
1114 ;; If the abbrevs came entirely from the init file or the
1115 ;; abbrevs file, they do not need saving.
1116 (setq abbrevs-changed nil
)
1118 ;; If we can tell that the init file altered debug-on-error,
1119 ;; arrange to preserve the value that it set up.
1120 (or (eq debug-on-error debug-on-error-initial
)
1121 (setq debug-on-error-should-be-set t
1122 debug-on-error-from-init-file debug-on-error
)))
1123 (if debug-on-error-should-be-set
1124 (setq debug-on-error debug-on-error-from-init-file
))
1125 (unless (or (default-value 'enable-multibyte-characters
)
1126 (eq orig-enable-multibyte
(default-value
1127 'enable-multibyte-characters
)))
1128 ;; Init file changed to unibyte. Reset existing multibyte
1129 ;; buffers (probably *scratch*, *Messages*, *Minibuff-0*).
1130 ;; Arguably this should only be done if they're free of
1131 ;; multibyte characters.
1132 (mapc (lambda (buffer)
1133 (with-current-buffer buffer
1134 (if enable-multibyte-characters
1135 (set-buffer-multibyte nil
))))
1137 ;; Also re-set the language environment in case it was
1138 ;; originally done before unibyte was set and is sensitive to
1139 ;; unibyte (display table, terminal coding system &c).
1140 (set-language-environment current-language-environment
)))
1142 ;; Do this here in case the init file sets mail-host-address.
1143 (if (equal user-mail-address
"")
1144 (setq user-mail-address
(or (getenv "EMAIL")
1145 (concat (user-login-name) "@"
1146 (or mail-host-address
1149 ;; Originally face attributes were specified via
1150 ;; `font-lock-face-attributes'. Users then changed the default
1151 ;; face attributes by setting that variable. However, we try and
1152 ;; be back-compatible and respect its value if set except for
1153 ;; faces where M-x customize has been used to save changes for the
1155 (when (boundp 'font-lock-face-attributes
)
1156 (let ((face-attributes font-lock-face-attributes
))
1157 (while face-attributes
1158 (let* ((face-attribute (pop face-attributes
))
1159 (face (car face-attribute
)))
1160 ;; Rustle up a `defface' SPEC from a
1161 ;; `font-lock-face-attributes' entry.
1162 (unless (get face
'saved-face
)
1163 (let ((foreground (nth 1 face-attribute
))
1164 (background (nth 2 face-attribute
))
1165 (bold-p (nth 3 face-attribute
))
1166 (italic-p (nth 4 face-attribute
))
1167 (underline-p (nth 5 face-attribute
))
1170 (setq face-spec
(cons ':foreground
(cons foreground face-spec
))))
1172 (setq face-spec
(cons ':background
(cons background face-spec
))))
1174 (setq face-spec
(append '(:weight bold
) face-spec
)))
1176 (setq face-spec
(append '(:slant italic
) face-spec
)))
1178 (setq face-spec
(append '(:underline t
) face-spec
)))
1179 (face-spec-set face
(list (list t face-spec
)) nil
)))))))
1181 ;; If parameter have been changed in the init file which influence
1182 ;; face realization, clear the face cache so that new faces will
1184 (unless (and (eq scalable-fonts-allowed old-scalable-fonts-allowed
)
1185 (eq font-list-limit old-font-list-limit
)
1186 (eq face-ignored-fonts old-face-ignored-fonts
))
1187 (clear-face-cache)))
1189 ;; If any package directory exists, initialize the package system.
1191 package-enable-at-startup
1192 (catch 'package-dir-found
1194 (if (boundp 'package-directory-list
)
1195 (setq dirs package-directory-list
)
1196 (dolist (f load-path
)
1198 (equal (file-name-nondirectory f
) "site-lisp")
1199 (push (expand-file-name "elpa" f
) dirs
))))
1200 (push (if (boundp 'package-user-dir
)
1202 (locate-user-emacs-file "elpa"))
1205 (when (file-directory-p dir
)
1206 (dolist (subdir (directory-files dir
))
1207 (when (and (file-directory-p (expand-file-name subdir dir
))
1209 (concat "\\`" package-subdirectory-regexp
"\\'")
1211 (throw 'package-dir-found t
)))))))
1212 (package-initialize))
1214 (setq after-init-time
(current-time))
1215 (run-hooks 'after-init-hook
)
1217 ;; Decode all default-directory.
1218 (if (and (default-value 'enable-multibyte-characters
) locale-coding-system
)
1220 (dolist (elt (buffer-list))
1222 (if default-directory
1223 (setq default-directory
1224 (decode-coding-string default-directory
1225 locale-coding-system t
))))
1226 (setq command-line-default-directory
1227 (decode-coding-string command-line-default-directory
1228 locale-coding-system t
))))
1230 ;; If *scratch* exists and init file didn't change its mode, initialize it.
1231 (if (get-buffer "*scratch*")
1232 (with-current-buffer "*scratch*"
1233 (if (eq major-mode
'fundamental-mode
)
1234 (funcall initial-major-mode
))))
1236 ;; Load library for our terminal type.
1237 ;; User init file can set term-file-prefix to nil to prevent this.
1238 (unless (or noninteractive
1239 initial-window-system
)
1240 (tty-run-terminal-initialization (selected-frame)))
1242 ;; Update the out-of-memory error message based on user's key bindings
1243 ;; for save-some-buffers.
1244 (setq memory-signal-data
1246 (substitute-command-keys "Memory exhausted--use \\[save-some-buffers] then exit and restart Emacs")))
1248 ;; Process the remaining args.
1249 (command-line-1 (cdr command-line-args
))
1251 ;; If -batch, terminate after processing the command options.
1252 (if noninteractive
(kill-emacs t
))
1254 ;; In daemon mode, start the server to allow clients to connect.
1255 ;; This is done after loading the user's init file and after
1256 ;; processing all command line arguments to allow e.g. `server-name'
1257 ;; to be changed before the server starts.
1258 (let ((dn (daemonp)))
1260 (when (stringp dn
) (setq server-name dn
))
1263 (daemon-initialized)
1266 "Unable to start daemon: Emacs server named %S already running"
1268 (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."))
1271 ;; Run emacs-session-restore (session management) if started by
1272 ;; the session manager and we have a session manager connection.
1273 (if (and (boundp 'x-session-previous-id
)
1274 (stringp x-session-previous-id
))
1276 (emacs-session-restore x-session-previous-id
))))
1278 (defcustom initial-scratch-message
(purecopy "\
1279 ;; This buffer is for notes you don't want to save, and for Lisp evaluation.
1280 ;; If you want to create a file, visit that file with C-x C-f,
1281 ;; then enter the text in that file's own buffer.
1284 "Initial message displayed in *scratch* buffer at startup.
1285 If this is nil, no message will be displayed."
1286 :type
'(choice (text :tag
"Message")
1287 (const :tag
"none" nil
))
1288 :group
'initialization
)
1291 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1292 ;;; Fancy splash screen
1293 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1295 (defconst fancy-startup-text
1296 `((:face
(variable-pitch (:foreground
"red"))
1299 ,(lambda (_button) (browse-url "http://www.gnu.org/software/emacs/"))
1300 "Browse http://www.gnu.org/software/emacs/")
1301 ", one component of the "
1304 (if (eq system-type
'gnu
/linux
)
1306 ,(lambda (_button) (browse-url "http://www.gnu.org/gnu/linux-and-gnu.html"))
1307 "Browse http://www.gnu.org/gnu/linux-and-gnu.html")
1308 `("GNU" ,(lambda (_button) (describe-gnu-project))
1309 "Display info on the GNU project")))
1310 " operating system.\n\n"
1311 :face variable-pitch
1312 :link
("Emacs Tutorial" ,(lambda (_button) (help-with-tutorial)))
1313 "\tLearn basic keystroke commands"
1315 (let* ((en "TUTORIAL")
1316 (tut (or (get-language-info current-language-environment
1319 (title (with-temp-buffer
1320 (insert-file-contents
1321 (expand-file-name tut tutorial-directory
)
1323 (search-forward ".")
1324 (buffer-substring (point-min) (1- (point))))))
1325 ;; If there is a specific tutorial for the current language
1326 ;; environment and it is not English, append its title.
1327 (if (string= en tut
)
1329 (concat " (" title
")"))))
1331 :link
("Emacs Guided Tour"
1333 (browse-url "http://www.gnu.org/software/emacs/tour/"))
1334 "Browse http://www.gnu.org/software/emacs/tour/")
1335 "\tOverview of Emacs features at gnu.org\n"
1336 :link
("View Emacs Manual" ,(lambda (_button) (info-emacs-manual)))
1337 "\tView the Emacs manual using Info\n"
1338 :link
("Absence of Warranty" ,(lambda (_button) (describe-no-warranty)))
1339 "\tGNU Emacs comes with "
1340 :face
(variable-pitch (:slant oblique
))
1341 "ABSOLUTELY NO WARRANTY\n"
1342 :face variable-pitch
1343 :link
("Copying Conditions" ,(lambda (_button) (describe-copying)))
1344 "\tConditions for redistributing and changing Emacs\n"
1345 :link
("Ordering Manuals" ,(lambda (_button) (view-order-manuals)))
1346 "\tPurchasing printed copies of manuals\n"
1348 "A list of texts to show in the middle part of splash screens.
1349 Each element in the list should be a list of strings or pairs
1350 `:face FACE', like `fancy-splash-insert' accepts them.")
1352 (defconst fancy-about-text
1353 `((:face
(variable-pitch (:foreground
"red"))
1356 ,(lambda (_button) (browse-url "http://www.gnu.org/software/emacs/"))
1357 "Browse http://www.gnu.org/software/emacs/")
1358 ", one component of the "
1361 (if (eq system-type
'gnu
/linux
)
1364 (browse-url "http://www.gnu.org/gnu/linux-and-gnu.html"))
1365 "Browse http://www.gnu.org/gnu/linux-and-gnu.html")
1366 `("GNU" ,(lambda (_button) (describe-gnu-project))
1367 "Display info on the GNU project.")))
1368 " operating system.\n"
1370 (list 'variable-pitch
1372 (if (eq (frame-parameter nil
'background-mode
) 'dark
)
1373 "cyan" "darkblue"))))
1375 ,(lambda () (emacs-version))
1377 :face
(variable-pitch (:height
0.8))
1378 ,(lambda () emacs-copyright
)
1380 :face variable-pitch
1383 (view-file (expand-file-name "AUTHORS" data-directory
))
1384 (goto-char (point-min))))
1385 "\tMany people have contributed code included in GNU Emacs\n"
1386 :link
("Contributing"
1388 (view-file (expand-file-name "CONTRIBUTE" data-directory
))
1389 (goto-char (point-min))))
1390 "\tHow to contribute improvements to Emacs\n"
1392 :link
("GNU and Freedom" ,(lambda (_button) (describe-gnu-project)))
1393 "\tWhy we developed GNU Emacs, and the GNU operating system\n"
1394 :link
("Absence of Warranty" ,(lambda (_button) (describe-no-warranty)))
1395 "\tGNU Emacs comes with "
1396 :face
(variable-pitch (:slant oblique
))
1397 "ABSOLUTELY NO WARRANTY\n"
1398 :face variable-pitch
1399 :link
("Copying Conditions" ,(lambda (_button) (describe-copying)))
1400 "\tConditions for redistributing and changing Emacs\n"
1401 :link
("Getting New Versions" ,(lambda (_button) (describe-distribution)))
1402 "\tHow to obtain the latest version of Emacs\n"
1403 :link
("Ordering Manuals" ,(lambda (_button) (view-order-manuals)))
1404 "\tBuying printed manuals from the FSF\n"
1406 :link
("Emacs Tutorial" ,(lambda (_button) (help-with-tutorial)))
1407 "\tLearn basic Emacs keystroke commands"
1409 (let* ((en "TUTORIAL")
1410 (tut (or (get-language-info current-language-environment
1413 (title (with-temp-buffer
1414 (insert-file-contents
1415 (expand-file-name tut tutorial-directory
)
1417 (search-forward ".")
1418 (buffer-substring (point-min) (1- (point))))))
1419 ;; If there is a specific tutorial for the current language
1420 ;; environment and it is not English, append its title.
1421 (if (string= en tut
)
1423 (concat " (" title
")"))))
1425 :link
("Emacs Guided Tour"
1427 (browse-url "http://www.gnu.org/software/emacs/tour/"))
1428 "Browse http://www.gnu.org/software/emacs/tour/")
1429 "\tSee an overview of Emacs features at gnu.org"
1431 "A list of texts to show in the middle part of the About screen.
1432 Each element in the list should be a list of strings or pairs
1433 `:face FACE', like `fancy-splash-insert' accepts them.")
1436 (defgroup fancy-splash-screen
()
1437 "Fancy splash screen when Emacs starts."
1439 :group
'initialization
)
1441 (defcustom fancy-splash-image nil
1442 "The image to show in the splash screens, or nil for defaults."
1443 :group
'fancy-splash-screen
1444 :type
'(choice (const :tag
"Default" nil
)
1445 (file :tag
"File")))
1448 (defvar splash-screen-keymap
1449 (let ((map (make-sparse-keymap)))
1450 (suppress-keymap map
)
1451 (set-keymap-parent map button-buffer-map
)
1452 (define-key map
"\C-?" 'scroll-down
)
1453 (define-key map
" " 'scroll-up
)
1454 (define-key map
"q" 'exit-splash-screen
)
1456 "Keymap for splash screen buffer.")
1458 ;; These are temporary storage areas for the splash screen display.
1460 (defun fancy-splash-insert (&rest args
)
1461 "Insert text into the current buffer, with faces.
1462 Arguments from ARGS should be either strings; functions called
1463 with no args that return a string; pairs `:face FACE', where FACE
1464 is a face specification usable with `put-text-property'; or pairs
1465 `:link LINK' where LINK is a list of arguments to pass to
1466 `insert-button', of the form (LABEL ACTION [HELP-ECHO]), which
1467 specifies the button's label, `action' property and help-echo string.
1468 FACE and LINK can also be functions, which are evaluated to obtain
1469 a face or button specification."
1470 (let ((current-face nil
))
1472 (cond ((eq (car args
) :face
)
1473 (setq args
(cdr args
) current-face
(car args
))
1474 (if (functionp current-face
)
1475 (setq current-face
(funcall current-face
))))
1476 ((eq (car args
) :link
)
1477 (setq args
(cdr args
))
1478 (let ((spec (car args
)))
1479 (if (functionp spec
)
1480 (setq spec
(funcall spec
)))
1481 (insert-button (car spec
)
1482 'face
(list 'link current-face
)
1484 'help-echo
(concat "mouse-2, RET: "
1486 "Follow this link"))
1488 (t (insert (propertize (let ((it (car args
)))
1493 'help-echo
(startup-echo-area-message)))))
1494 (setq args
(cdr args
)))))
1496 (declare-function image-size
"image.c" (spec &optional pixels frame
))
1498 (defun fancy-splash-head ()
1499 "Insert the head part of the splash screen into the current buffer."
1500 (let* ((image-file (cond ((stringp fancy-splash-image
)
1503 (cond ((<= (display-planes) 8)
1504 (if (image-type-available-p 'xpm
)
1507 ((image-type-available-p 'svg
)
1509 ((image-type-available-p 'png
)
1511 ((image-type-available-p 'xpm
)
1515 (img (create-image image-file
))
1516 (image-width (and img
(car (image-size img
))))
1517 (window-width (window-width (selected-window))))
1519 (when (> window-width image-width
)
1520 ;; Center the image in the window.
1521 (insert (propertize " " 'display
1522 `(space :align-to
(+ center
(-0.5 .
,img
)))))
1524 ;; Change the color of the XPM version of the splash image
1525 ;; so that it is visible with a dark frame background.
1526 (when (and (memq 'xpm img
)
1527 (eq (frame-parameter nil
'background-mode
) 'dark
))
1528 (setq img
(append img
'(:color-symbols
(("#000000" .
"gray30"))))))
1530 ;; Insert the image with a help-echo and a link.
1531 (make-button (prog1 (point) (insert-image img
)) (point)
1533 'help-echo
"mouse-2, RET: Browse http://www.gnu.org/"
1534 'action
(lambda (_button) (browse-url "http://www.gnu.org/"))
1538 (defun fancy-startup-tail (&optional concise
)
1539 "Insert the tail part of the splash screen into the current buffer."
1540 (let ((fg (if (eq (frame-parameter nil
'background-mode
) 'dark
)
1541 "cyan" "darkblue")))
1543 (fancy-splash-insert
1544 :face
'variable-pitch
1546 :link
`("Open a File"
1547 ,(lambda (_button) (call-interactively 'find-file
))
1548 "Specify a new file's name, to edit the file")
1550 :link
`("Open Home Directory"
1551 ,(lambda (_button) (dired "~"))
1552 "Open your home directory, to operate on its files")
1554 :link
`("Customize Startup"
1555 ,(lambda (_button) (customize-group 'initialization
))
1556 "Change initialization settings including this screen")
1558 (fancy-splash-insert
1559 :face
'variable-pitch
"To quit a partially entered command, type "
1560 :face
'default
"Control-g"
1561 :face
'variable-pitch
".\n")
1562 (fancy-splash-insert :face
`(variable-pitch (:foreground
,fg
))
1566 :face
'(variable-pitch (:height
0.8))
1569 (and auto-save-list-file-prefix
1570 ;; Don't signal an error if the
1571 ;; directory for auto-save-list files
1572 ;; does not yet exist.
1573 (file-directory-p (file-name-directory
1574 auto-save-list-file-prefix
))
1576 (file-name-directory auto-save-list-file-prefix
)
1579 (regexp-quote (file-name-nondirectory
1580 auto-save-list-file-prefix
)))
1582 (fancy-splash-insert :face
'(variable-pitch (:foreground
"red"))
1583 "\nIf an Emacs session crashed recently, "
1585 :face
'(fixed-pitch :foreground
"red")
1586 "Meta-x recover-session RET"
1587 :face
'(variable-pitch (:foreground
"red"))
1589 " the files you were editing."))
1592 (fancy-splash-insert
1593 :face
'variable-pitch
"\n"
1594 :link
`("Dismiss this startup screen"
1596 (when startup-screen-inhibit-startup-screen
1597 (customize-set-variable 'inhibit-startup-screen t
)
1598 (customize-mark-to-save 'inhibit-startup-screen
)
1600 (let ((w (get-buffer-window "*GNU Emacs*")))
1601 (and w
(not (one-window-p)) (delete-window w
)))
1602 (kill-buffer "*GNU Emacs*")))
1604 (when (or user-init-file custom-file
)
1605 (let ((checked (create-image "checked.xpm"
1606 nil nil
:ascent
'center
))
1607 (unchecked (create-image "unchecked.xpm"
1608 nil nil
:ascent
'center
)))
1612 :off-glyph unchecked
1613 'checked nil
'display unchecked
'follow-link t
1614 'action
(lambda (button)
1615 (if (overlay-get button
'checked
)
1616 (progn (overlay-put button
'checked nil
)
1617 (overlay-put button
'display
1618 (overlay-get button
:off-glyph
))
1619 (setq startup-screen-inhibit-startup-screen
1621 (overlay-put button
'checked t
)
1622 (overlay-put button
'display
1623 (overlay-get button
:on-glyph
))
1624 (setq startup-screen-inhibit-startup-screen t
)))))
1625 (fancy-splash-insert :face
'(variable-pitch (:height
0.9))
1626 " Never show it again.")))))
1628 (defun exit-splash-screen ()
1629 "Stop displaying the splash screen buffer."
1633 (defun fancy-startup-screen (&optional concise
)
1634 "Display fancy startup screen.
1635 If CONCISE is non-nil, display a concise version of the
1636 splash screen in another window."
1637 (let ((splash-buffer (get-buffer-create "*GNU Emacs*")))
1638 (with-current-buffer splash-buffer
1639 (let ((inhibit-read-only t
))
1641 (setq default-directory command-line-default-directory
)
1642 (make-local-variable 'startup-screen-inhibit-startup-screen
)
1643 (if pure-space-overflow
1644 (insert pure-space-overflow-message
))
1646 (fancy-splash-head))
1647 (dolist (text fancy-startup-text
)
1648 (apply #'fancy-splash-insert text
)
1650 (skip-chars-backward "\n")
1651 (delete-region (point) (point-max))
1653 (fancy-startup-tail concise
))
1654 (use-local-map splash-screen-keymap
)
1657 (set-buffer-modified-p nil
)
1658 (if (and view-read-only
(not view-mode
))
1659 (view-mode-enter nil
'kill-buffer
))
1660 (goto-char (point-min))
1661 (forward-line (if concise
2 4)))
1664 (display-buffer splash-buffer
)
1665 ;; If the splash screen is in a split window, fit it.
1666 (let ((window (get-buffer-window splash-buffer t
)))
1668 (eq window
(selected-window))
1669 (eq window
(next-window window
))
1670 (fit-window-to-buffer window
))))
1671 (switch-to-buffer splash-buffer
))))
1673 (defun fancy-about-screen ()
1674 "Display fancy About screen."
1675 (let ((frame (fancy-splash-frame)))
1676 (save-selected-window
1677 (select-frame frame
)
1678 (switch-to-buffer "*About GNU Emacs*")
1679 (setq buffer-undo-list t
1682 (propertize "%b" 'face
'mode-line-buffer-id
)
1684 (let ((inhibit-read-only t
))
1686 (if pure-space-overflow
1687 (insert pure-space-overflow-message
))
1689 (dolist (text fancy-about-text
)
1690 (apply #'fancy-splash-insert text
)
1692 (set-buffer-modified-p nil
)
1693 (goto-char (point-min))
1694 (force-mode-line-update))
1695 (use-local-map splash-screen-keymap
)
1697 (message "%s" (startup-echo-area-message))
1698 (setq buffer-read-only t
)
1699 (goto-char (point-min))
1702 (defun fancy-splash-frame ()
1703 "Return the frame to use for the fancy splash screen.
1704 Returning non-nil does not mean we should necessarily
1705 use the fancy splash screen, but if we do use it,
1706 we put it on this frame."
1708 (dolist (frame (append (frame-list) (list (selected-frame))))
1709 (if (and (frame-visible-p frame
)
1710 (not (window-minibuffer-p (frame-selected-window frame
))))
1711 (setq chosen-frame frame
)))
1714 (defun use-fancy-splash-screens-p ()
1715 "Return t if fancy splash screens should be used."
1716 (when (and (display-graphic-p)
1717 (or (and (display-color-p)
1718 (image-type-available-p 'xpm
))
1719 (image-type-available-p 'pbm
)))
1720 (let ((frame (fancy-splash-frame)))
1722 (let* ((img (create-image (or fancy-splash-image
1723 (if (and (display-color-p)
1724 (image-type-available-p 'xpm
))
1725 "splash.xpm" "splash.pbm"))))
1726 (image-height (and img
(cdr (image-size img nil frame
))))
1727 ;; We test frame-height so that, if the frame is split
1728 ;; by displaying a warning, that doesn't cause the normal
1729 ;; splash screen to be used.
1730 (frame-height (1- (frame-height frame
))))
1731 (> frame-height
(+ image-height
19)))))))
1734 (defun normal-splash-screen (&optional startup concise
)
1735 "Display non-graphic splash screen.
1736 If optional argument STARTUP is non-nil, display the startup screen
1737 after Emacs starts. If STARTUP is nil, display the About screen.
1738 If CONCISE is non-nil, display a concise version of the
1739 splash screen in another window."
1740 (let ((splash-buffer (get-buffer-create "*About GNU Emacs*")))
1741 (with-current-buffer splash-buffer
1742 (setq buffer-read-only nil
)
1744 (setq default-directory command-line-default-directory
)
1745 (set (make-local-variable 'tab-width
) 8)
1747 (set (make-local-variable 'mode-line-format
)
1748 (propertize "---- %b %-" 'face
'mode-line-buffer-id
)))
1750 (if pure-space-overflow
1751 (insert pure-space-overflow-message
))
1753 ;; The convention for this piece of code is that
1754 ;; each piece of output starts with one or two newlines
1755 ;; and does not end with any newlines.
1756 (insert (if startup
"Welcome to GNU Emacs" "This is GNU Emacs"))
1758 (if (eq system-type
'gnu
/linux
)
1759 ", one component of the GNU/Linux operating system.\n"
1760 ", a part of the GNU operating system.\n"))
1763 (if (display-mouse-p)
1764 ;; The user can use the mouse to activate menus
1765 ;; so give help in terms of menu items.
1766 (normal-mouse-startup-screen)
1768 ;; No mouse menus, so give help using kbd commands.
1769 (normal-no-mouse-startup-screen))
1771 (normal-about-screen))
1773 ;; The rest of the startup screen is the same on all
1774 ;; kinds of terminals.
1776 ;; Give information on recovering, if there was a crash.
1778 auto-save-list-file-prefix
1779 ;; Don't signal an error if the
1780 ;; directory for auto-save-list files
1781 ;; does not yet exist.
1782 (file-directory-p (file-name-directory
1783 auto-save-list-file-prefix
))
1785 (file-name-directory auto-save-list-file-prefix
)
1788 (regexp-quote (file-name-nondirectory
1789 auto-save-list-file-prefix
)))
1791 (insert "\n\nIf an Emacs session crashed recently, "
1792 "type Meta-x recover-session RET\nto recover"
1793 " the files you were editing.\n"))
1795 (use-local-map splash-screen-keymap
)
1797 ;; Display the input that we set up in the buffer.
1798 (set-buffer-modified-p nil
)
1799 (setq buffer-read-only t
)
1800 (if (and view-read-only
(not view-mode
))
1801 (view-mode-enter nil
'kill-buffer
))
1802 (if startup
(rename-buffer "*GNU Emacs*" t
))
1803 (goto-char (point-min)))
1805 (display-buffer splash-buffer
)
1806 (switch-to-buffer splash-buffer
))))
1808 (defun normal-mouse-startup-screen ()
1809 ;; The user can use the mouse to activate menus
1810 ;; so give help in terms of menu items.
1812 To follow a link, click Mouse-1 on it, or move to it and type RET.
1813 To quit a partially entered command, type Control-g.\n")
1815 (insert "\nImportant Help menu items:\n")
1816 (insert-button "Emacs Tutorial"
1817 'action
(lambda (_button) (help-with-tutorial))
1819 (insert "\t\tLearn basic Emacs keystroke commands\n")
1820 (insert-button "Read the Emacs Manual"
1821 'action
(lambda (_button) (info-emacs-manual))
1823 (insert "\tView the Emacs manual using Info\n")
1824 (insert-button "\(Non)Warranty"
1825 'action
(lambda (_button) (describe-no-warranty))
1827 (insert "\t\tGNU Emacs comes with ABSOLUTELY NO WARRANTY\n")
1828 (insert-button "Copying Conditions"
1829 'action
(lambda (_button) (describe-copying))
1831 (insert "\tConditions for redistributing and changing Emacs\n")
1832 (insert-button "More Manuals / Ordering Manuals"
1833 'action
(lambda (_button) (view-order-manuals))
1835 (insert " How to order printed manuals from the FSF\n")
1837 (insert "\nUseful tasks:\n")
1838 (insert-button "Visit New File"
1839 'action
(lambda (_button) (call-interactively 'find-file
))
1841 (insert "\t\tSpecify a new file's name, to edit the file\n")
1842 (insert-button "Open Home Directory"
1843 'action
(lambda (_button) (dired "~"))
1845 (insert "\tOpen your home directory, to operate on its files\n")
1846 (insert-button "Customize Startup"
1847 'action
(lambda (_button) (customize-group 'initialization
))
1849 (insert "\tChange initialization settings including this screen\n")
1851 (insert "\n" (emacs-version)
1852 "\n" emacs-copyright
))
1854 ;; No mouse menus, so give help using kbd commands.
1855 (defun normal-no-mouse-startup-screen ()
1857 ;; If keys have their default meanings,
1858 ;; use precomputed string to save lots of time.
1859 (let* ((c-h-accessible
1860 ;; If normal-erase-is-backspace is used on a tty, there's
1861 ;; no way to invoke C-h and you have to use F1 instead.
1862 (or (not (char-table-p keyboard-translate-table
))
1863 (eq (aref keyboard-translate-table ?\C-h
) ?\C-h
)))
1864 (minor-mode-overriding-map-alist
1865 (cons (cons (not c-h-accessible
)
1866 ;; If C-h can't be invoked, temporarily disable its
1867 ;; binding, so where-is uses alternative bindings.
1868 (let ((map (make-sparse-keymap)))
1869 (define-key map
[?\C-h
] 'undefined
)
1871 minor-mode-overriding-map-alist
)))
1873 (insert (format "\nGet help\t %s\n"
1874 (let ((where (where-is-internal 'help-command nil t
)))
1876 ((equal where
[?\C-h
])
1877 "C-h (Hold down CTRL and press h)")
1878 (where (key-description where
))
1880 (insert-button "Emacs manual"
1881 'action
(lambda (_button) (info-emacs-manual))
1883 (insert (substitute-command-keys"\t \\[info-emacs-manual]\t"))
1884 (insert-button "Browse manuals"
1885 'action
(lambda (_button) (Info-directory))
1887 (insert (substitute-command-keys "\t \\[info]\n"))
1888 (insert-button "Emacs tutorial"
1889 'action
(lambda (_button) (help-with-tutorial))
1891 (insert (substitute-command-keys
1892 "\t \\[help-with-tutorial]\tUndo changes\t \\[undo]\n"))
1893 (insert-button "Buy manuals"
1894 'action
(lambda (_button) (view-order-manuals))
1896 (insert (substitute-command-keys
1897 "\t \\[view-order-manuals]\tExit Emacs\t \\[save-buffers-kill-terminal]")))
1899 ;; Say how to use the menu bar with the keyboard.
1901 (insert-button "Activate menubar"
1902 'action
(lambda (_button) (tmm-menubar))
1904 (if (and (eq (key-binding "\M-`") 'tmm-menubar
)
1905 (eq (key-binding [f10]) 'tmm-menubar))
1906 (insert " F10 or ESC ` or M-`")
1907 (insert (substitute-command-keys " \\[tmm-menubar]")))
1909 ;; Many users seem to have problems with these.
1911 \(`C-' means use the CTRL key. `M-' means use the Meta (or Alt) key.
1912 If you have no Meta key, you may instead type ESC followed by the character.)")
1914 ;; Insert links to useful tasks
1915 (insert "\nUseful tasks:\n")
1917 (insert-button "Visit New File"
1918 'action (lambda (_button) (call-interactively 'find-file))
1921 (insert-button "Open Home Directory"
1922 'action (lambda (_button) (dired "~"))
1926 (insert-button "Customize Startup"
1927 'action (lambda (_button) (customize-group 'initialization))
1930 (insert-button "Open *scratch* buffer"
1931 'action (lambda (_button) (switch-to-buffer
1932 (get-buffer-create "*scratch*")))
1935 (insert "\n" (emacs-version) "\n" emacs-copyright "\n")
1937 (if (and (eq (key-binding "\C-h\C-c") 'describe-copying)
1938 (eq (key-binding "\C-h\C-d") 'describe-distribution)
1939 (eq (key-binding "\C-h\C-w") 'describe-no-warranty))
1943 GNU Emacs comes with ABSOLUTELY NO WARRANTY; type C-h C-w for ")
1944 (insert-button "full details"
1945 'action (lambda (_button) (describe-no-warranty))
1948 Emacs is Free Software--Free as in Freedom--so you can redistribute copies
1949 of Emacs and modify it; type C-h C-c to see ")
1950 (insert-button "the conditions"
1951 'action (lambda (_button) (describe-copying))
1954 Type C-h C-d for information on ")
1955 (insert-button "getting the latest version"
1956 'action (lambda (_button) (describe-distribution))
1959 (insert (substitute-command-keys
1961 GNU Emacs comes with ABSOLUTELY NO WARRANTY; type \\[describe-no-warranty] for "))
1962 (insert-button "full details"
1963 'action (lambda (_button) (describe-no-warranty))
1965 (insert (substitute-command-keys ".
1966 Emacs is Free Software--Free as in Freedom--so you can redistribute copies
1967 of Emacs and modify it; type \\[describe-copying] to see "))
1968 (insert-button "the conditions"
1969 'action (lambda (_button) (describe-copying))
1971 (insert (substitute-command-keys".
1972 Type \\[describe-distribution] for information on "))
1973 (insert-button "getting the latest version"
1974 'action (lambda (_button) (describe-distribution))
1978 (defun normal-about-screen ()
1979 (insert "\n" (emacs-version) "\n" emacs-copyright "\n\n")
1981 (insert "To follow a link, click Mouse-1 on it, or move to it and type RET.\n\n")
1983 (insert-button "Authors"
1986 (view-file (expand-file-name "AUTHORS" data-directory))
1987 (goto-char (point-min)))
1989 (insert "\t\tMany people have contributed code included in GNU Emacs\n")
1991 (insert-button "Contributing"
1994 (view-file (expand-file-name "CONTRIBUTE" data-directory))
1995 (goto-char (point-min)))
1997 (insert "\tHow to contribute improvements to Emacs\n\n")
1999 (insert-button "GNU and Freedom"
2000 'action (lambda (_button) (describe-gnu-project))
2002 (insert "\t\tWhy we developed GNU Emacs and the GNU system\n")
2004 (insert-button "Absence of Warranty"
2005 'action (lambda (_button) (describe-no-warranty))
2007 (insert "\tGNU Emacs comes with ABSOLUTELY NO WARRANTY\n")
2009 (insert-button "Copying Conditions"
2010 'action (lambda (_button) (describe-copying))
2012 (insert "\tConditions for redistributing and changing Emacs\n")
2014 (insert-button "Getting New Versions"
2015 'action (lambda (_button) (describe-distribution))
2017 (insert "\tHow to get the latest version of GNU Emacs\n")
2019 (insert-button "More Manuals / Ordering Manuals"
2020 'action (lambda (_button) (view-order-manuals))
2022 (insert "\tBuying printed manuals from the FSF\n"))
2024 (defun startup-echo-area-message ()
2026 "Starting Emacs daemon.")
2027 ((eq (key-binding "\C-h\C-a") 'about-emacs)
2028 "For information about GNU Emacs and the GNU system, type C-h C-a.")
2030 (substitute-command-keys
2031 "For information about GNU Emacs and the GNU system, type \
2032 \\[about-emacs]."))))
2034 (defun display-startup-echo-area-message ()
2035 (let ((resize-mini-windows t))
2036 (or noninteractive ;(input-pending-p) init-file-had-error
2037 ;; t if the init file says to inhibit the echo area startup message.
2038 (and inhibit-startup-echo-area-message
2040 (or (and (get 'inhibit-startup-echo-area-message 'saved-value)
2041 (equal inhibit-startup-echo-area-message
2042 (if (equal init-file-user "")
2045 ;; Wasn't set with custom; see if .emacs has a setq.
2048 (insert-file-contents user-init-file)
2051 "([ \t\n]*setq[ \t\n]+"
2052 "inhibit-startup-echo-area-message[ \t\n]+"
2055 (if (equal init-file-user "")
2061 (message "%s" (startup-echo-area-message)))))
2063 (defun display-startup-screen (&optional concise)
2064 "Display startup screen according to display.
2065 A fancy display is used on graphic displays, normal otherwise.
2067 If CONCISE is non-nil, display a concise version of the startup
2069 ;; Prevent recursive calls from server-process-filter.
2070 (if (not (get-buffer "*GNU Emacs*"))
2071 (if (use-fancy-splash-screens-p)
2072 (fancy-startup-screen concise)
2073 (normal-splash-screen t concise))))
2075 (defun display-about-screen ()
2076 "Display the *About GNU Emacs* buffer.
2077 A fancy display is used on graphic displays, normal otherwise."
2079 (if (use-fancy-splash-screens-p)
2080 (fancy-about-screen)
2081 (normal-splash-screen nil)))
2083 (defalias 'about-emacs 'display-about-screen)
2084 (defalias 'display-splash-screen 'display-startup-screen)
2086 (defun command-line-1 (args-left)
2087 (display-startup-echo-area-message)
2088 (when (and pure-space-overflow
2089 (not noninteractive))
2092 "Building Emacs overflowed pure space.\
2093 (See the node Pure Storage in the Lisp manual for details.)"
2096 (let ((file-count 0)
2097 (command-line-args-left args-left)
2099 (when command-line-args-left
2100 ;; We have command args; process them.
2101 (let ((dir command-line-default-directory)
2103 ;; This approach loses for "-batch -L DIR --eval "(require foo)",
2104 ;; if foo is intended to be found in DIR.
2106 ;; ;; The directories listed in --directory/-L options will *appear*
2107 ;; ;; at the front of `load-path' in the order they appear on the
2108 ;; ;; command-line. We cannot do this by *placing* them at the front
2109 ;; ;; in the order they appear, so we need this variable to hold them,
2113 ;; To DTRT we keep track of the splice point and modify `load-path'
2114 ;; straight away upon any --directory/-L option.
2116 just-files ;; t if this follows the magic -- option.
2117 ;; This includes our standard options' long versions
2118 ;; and long versions of what's on command-switch-alist.
2120 (append '("--funcall" "--load" "--insert" "--kill"
2121 "--directory" "--eval" "--execute" "--no-splash"
2122 "--find-file" "--visit" "--file" "--no-desktop")
2123 (mapcar (lambda (elt) (concat "-" (car elt)))
2124 command-switch-alist)))
2128 ;; Add the long X options to longopts.
2129 (dolist (tem command-line-x-option-alist)
2130 (if (string-match "^--" (car tem))
2131 (push (car tem) longopts)))
2133 ;; Add the long NS options to longopts.
2134 (dolist (tem command-line-ns-option-alist)
2135 (if (string-match "^--" (car tem))
2136 (push (list (car tem)) longopts)))
2138 ;; Loop, processing options.
2139 (while command-line-args-left
2140 (let* ((argi (car command-line-args-left))
2143 (setq command-line-args-left (cdr command-line-args-left))
2145 ;; Do preliminary decoding of the option.
2147 ;; After --, don't look for options; treat all args as files.
2149 ;; Convert long options to ordinary options
2150 ;; and separate out an attached option argument into argval.
2151 (when (string-match "\\`\\(--[^=]*\\)=" argi)
2152 (setq argval (substring argi (match-end 0))
2153 argi (match-string 1 argi)))
2154 (when (string-match "\\`--?[^-]" orig-argi)
2155 (setq completion (try-completion argi longopts))
2156 (if (eq completion t)
2157 (setq argi (substring argi 1))
2158 (if (stringp completion)
2159 (let ((elt (member completion longopts)))
2161 (error "Option `%s' is ambiguous" argi))
2162 (setq argi (substring (car elt) 1)))
2166 ;; Execute the option.
2167 (cond ((setq tem (assoc argi command-switch-alist))
2169 (let ((command-line-args-left
2170 (cons argval command-line-args-left)))
2171 (funcall (cdr tem) argi))
2172 (funcall (cdr tem) argi)))
2174 ((equal argi "-no-splash")
2175 (setq inhibit-startup-screen t))
2177 ((member argi '("-f" ; what the manual claims
2179 "-e")) ; what the source used to say
2180 (setq inhibit-startup-screen t)
2181 (setq tem (intern (or argval (pop command-line-args-left))))
2183 (command-execute tem)
2186 ((member argi '("-eval" "-execute"))
2187 (setq inhibit-startup-screen t)
2188 (eval (read (or argval (pop command-line-args-left)))))
2190 ((member argi '("-L" "-directory"))
2191 (setq tem (expand-file-name
2192 (command-line-normalize-file-name
2193 (or argval (pop command-line-args-left)))))
2194 (cond (splice (setcdr splice (cons tem (cdr splice)))
2195 (setq splice (cdr splice)))
2196 (t (setq load-path (cons tem load-path)
2197 splice load-path))))
2199 ((member argi '("-l" "-load"))
2200 (let* ((file (command-line-normalize-file-name
2201 (or argval (pop command-line-args-left))))
2202 ;; Take file from default dir if it exists there;
2203 ;; otherwise let `load' search for it.
2204 (file-ex (expand-file-name file)))
2205 (when (file-exists-p file-ex)
2206 (setq file file-ex))
2209 ;; This is used to handle -script. It's not clear
2210 ;; we need to document it (it is totally internal).
2211 ((member argi '("-scriptload"))
2212 (let* ((file (command-line-normalize-file-name
2213 (or argval (pop command-line-args-left))))
2214 ;; Take file from default dir.
2215 (file-ex (expand-file-name file)))
2216 (load file-ex nil t t)))
2218 ((equal argi "-insert")
2219 (setq inhibit-startup-screen t)
2220 (setq tem (or argval (pop command-line-args-left)))
2222 (error "File name omitted from `-insert' option"))
2223 (insert-file-contents (command-line-normalize-file-name tem)))
2225 ((equal argi "-kill")
2228 ;; This is for when they use --no-desktop with -q, or
2229 ;; don't load Desktop in their .emacs. If desktop.el
2230 ;; _is_ loaded, it will handle this switch, and we
2231 ;; won't see it by the time we get here.
2232 ((equal argi "-no-desktop")
2233 (message "\"--no-desktop\" ignored because the Desktop package is not loaded"))
2235 ((string-match "^\\+[0-9]+\\'" argi)
2236 (setq line (string-to-number argi)))
2238 ((string-match "^\\+\\([0-9]+\\):\\([0-9]+\\)\\'" argi)
2239 (setq line (string-to-number (match-string 1 argi))
2240 column (string-to-number (match-string 2 argi))))
2242 ((setq tem (assoc orig-argi command-line-x-option-alist))
2243 ;; Ignore X-windows options and their args if not using X.
2244 (setq command-line-args-left
2245 (nthcdr (nth 1 tem) command-line-args-left)))
2247 ((setq tem (assoc orig-argi command-line-ns-option-alist))
2248 ;; Ignore NS-windows options and their args if not using NS.
2249 (setq command-line-args-left
2250 (nthcdr (nth 1 tem) command-line-args-left)))
2252 ((member argi '("-find-file" "-file" "-visit"))
2253 (setq inhibit-startup-screen t)
2254 ;; An explicit option to specify visiting a file.
2255 (setq tem (or argval (pop command-line-args-left)))
2256 (unless (stringp tem)
2257 (error "File name omitted from `%s' option" argi))
2258 (setq file-count (1+ file-count))
2259 (let ((file (expand-file-name
2260 (command-line-normalize-file-name tem)
2262 (if (= file-count 1)
2263 (setq first-file-buffer (find-file file))
2264 (find-file-other-window file)))
2265 (unless (zerop line)
2266 (goto-char (point-min))
2267 (forward-line (1- line)))
2269 (unless (< column 1)
2270 (move-to-column (1- column)))
2273 ;; These command lines now have no effect.
2274 ((string-match "\\`--?\\(no-\\)?\\(uni\\|multi\\)byte$" argi)
2275 (display-warning 'initialization
2276 (format "Ignoring obsolete arg %s" argi)))
2279 (setq just-files t))
2281 ;; We have almost exhausted our options. See if the
2282 ;; user has made any other command-line options available
2283 (let ((hooks command-line-functions)
2286 (not (setq did-hook (funcall (car hooks)))))
2287 (setq hooks (cdr hooks)))
2289 ;; Presume that the argument is a file name.
2291 (if (string-match "\\`-" argi)
2292 (error "Unknown option `%s'" argi))
2293 (unless initial-window-system
2294 (setq inhibit-startup-screen t))
2295 (setq file-count (1+ file-count))
2298 (command-line-normalize-file-name orig-argi)
2300 (cond ((= file-count 1)
2301 (setq first-file-buffer (find-file file)))
2302 (inhibit-startup-screen
2303 (find-file-other-window file))
2304 (t (find-file file))))
2305 (unless (zerop line)
2306 (goto-char (point-min))
2307 (forward-line (1- line)))
2309 (unless (< column 1)
2310 (move-to-column (1- column)))
2311 (setq column 0))))))
2312 ;; In unusual circumstances, the execution of Lisp code due
2313 ;; to command-line options can cause the last visible frame
2314 ;; to be deleted. In this case, kill emacs to avoid an
2316 (unless (frame-live-p (selected-frame)) (kill-emacs nil))))))
2318 (when initial-buffer-choice
2319 (cond ((eq initial-buffer-choice t)
2320 (switch-to-buffer (get-buffer-create "*scratch*")))
2321 ((stringp initial-buffer-choice)
2322 (find-file initial-buffer-choice))))
2324 ;; If *scratch* exists and is empty, insert initial-scratch-message.
2325 (and initial-scratch-message
2326 (get-buffer "*scratch*")
2327 (with-current-buffer "*scratch*"
2328 (when (zerop (buffer-size))
2329 (insert initial-scratch-message)
2330 (set-buffer-modified-p nil))))
2332 (if (or inhibit-startup-screen
2333 initial-buffer-choice
2335 inhibit-x-resources)
2337 ;; Not displaying a startup screen. If 3 or more files
2338 ;; visited, and not all visible, show user what they all are.
2339 (and (> file-count 2)
2340 (not noninteractive)
2341 (not inhibit-startup-buffer-menu)
2342 (or (get-buffer-window first-file-buffer)
2345 ;; Display a startup screen, after some preparations.
2347 ;; If there are no switches to process, we might as well
2348 ;; run this hook now, and there may be some need to do it
2349 ;; before doing any output.
2350 (run-hooks 'emacs-startup-hook)
2351 (and term-setup-hook
2352 (run-hooks 'term-setup-hook))
2353 (setq inhibit-startup-hooks t)
2355 ;; It's important to notice the user settings before we
2356 ;; display the startup message; otherwise, the settings
2357 ;; won't take effect until the user gives the first
2358 ;; keystroke, and that's distracting.
2359 (when (fboundp 'frame-notice-user-settings)
2360 (frame-notice-user-settings))
2362 ;; If there are no switches to process, we might as well
2363 ;; run this hook now, and there may be some need to do it
2364 ;; before doing any output.
2365 (when window-setup-hook
2366 (run-hooks 'window-setup-hook)
2367 ;; Don't let the hook be run twice.
2368 (setq window-setup-hook nil))
2370 ;; ;; Do this now to avoid an annoying delay if the user
2371 ;; ;; clicks the menu bar during the sit-for.
2372 ;; (when (display-popup-menus-p)
2373 ;; (precompute-menubar-bindings))
2374 ;; (with-no-warnings
2375 ;; (setq menubar-bindings-done t))
2377 (if (> file-count 0)
2378 (display-startup-screen t)
2379 (display-startup-screen nil)))))
2381 (defun command-line-normalize-file-name (file)
2382 "Collapse multiple slashes to one, to handle non-Emacs file names."
2384 ;; Use arg 1 so that we don't collapse // at the start of the file name.
2385 ;; That is significant on some systems.
2386 ;; However, /// at the beginning is supposed to mean just /, not //.
2387 (if (string-match "^///+" file)
2388 (setq file (replace-match "/" t t file)))
2389 (and (memq system-type '(ms-dos windows-nt))
2390 (string-match "^[A-Za-z]:\\(\\\\[\\\\/]\\)" file) ; C:\/ or C:\\
2391 (setq file (replace-match "/" t t file 1)))
2392 (while (string-match "//+" file 1)
2393 (setq file (replace-match "/" t t file)))
2396 ;;; startup.el ends here