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