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