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