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