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