1 ;;; startup.el --- process Emacs shell arguments -*- lexical-binding: t -*-
3 ;; Copyright (C) 1985-1986, 1992, 1994-2016 Free Software Foundation,
6 ;; Maintainer: emacs-devel@gnu.org
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/>.
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.
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."
42 (defcustom initial-buffer-choice nil
43 "Buffer to show after starting Emacs.
44 If the value is nil and `inhibit-startup-screen' is nil, show the
45 startup screen. If the value is a string, switch to a buffer
46 visiting the file or directory that the string specifies. If the
47 value is a function, call it with no arguments and switch to the buffer
48 that it returns. If t, open the `*scratch*' buffer.
50 When `initial-buffer-choice' is non-nil, the startup screen is
53 If you use `emacsclient' with no target file, then it obeys any
54 string or function value that this variable has."
56 (const :tag
"Startup screen" nil
)
57 (directory :tag
"Directory" :value
"~/")
58 (file :tag
"File" :value
"~/.emacs")
59 ;; Note sure about hard-coding this as an option...
60 (const :tag
"Remember Mode notes buffer" remember-notes
)
61 (function :tag
"Function")
62 (const :tag
"Lisp scratch buffer" t
))
64 :group
'initialization
)
66 (defcustom inhibit-startup-screen nil
67 "Non-nil inhibits the startup screen.
69 This is for use in your personal init file (but NOT site-start.el),
70 once you are familiar with the contents of the startup screen."
72 :group
'initialization
)
74 (defvaralias 'inhibit-splash-screen
'inhibit-startup-screen
)
75 (defvaralias 'inhibit-startup-message
'inhibit-startup-screen
)
77 (defvar startup-screen-inhibit-startup-screen nil
)
79 ;; The mechanism used to ensure that only end users can disable this
80 ;; message is not complex. Clearly, it is possible for a determined
81 ;; system administrator to inhibit this message anyway, but at least
82 ;; they will do so with knowledge of why the Emacs developers think
83 ;; this is a bad idea.
84 (defcustom inhibit-startup-echo-area-message nil
85 "Non-nil inhibits the initial startup echo area message.
87 The startup message is in the echo area as it provides information
88 about GNU Emacs and the GNU system in general, which we want all
89 users to see. As this is the least intrusive startup message,
90 this variable gets specialized treatment to prevent the message
91 from being disabled site-wide by systems administrators, while
92 still allowing individual users to do so.
94 Setting this variable takes effect only if you do it with the
95 customization buffer or if your init file contains a line of this
97 (setq inhibit-startup-echo-area-message \"YOUR-USER-NAME\")
98 If your init file is byte-compiled, use the following form
100 (eval \\='(setq inhibit-startup-echo-area-message \"YOUR-USER-NAME\"))
101 Thus, someone else using a copy of your init file will see the
102 startup message unless he personally acts to inhibit it."
103 :type
'(choice (const :tag
"Don't inhibit")
104 (string :tag
"Enter your user name, to inhibit"))
105 :group
'initialization
)
107 (defcustom inhibit-default-init nil
108 "Non-nil inhibits loading the `default' library."
110 :group
'initialization
)
112 (defcustom inhibit-startup-buffer-menu nil
113 "Non-nil inhibits display of buffer list when more than 2 files are loaded."
115 :group
'initialization
)
117 (defvar command-switch-alist nil
118 "Alist of command-line switches.
119 Elements look like (SWITCH-STRING . HANDLER-FUNCTION).
120 HANDLER-FUNCTION receives the switch string as its sole argument;
121 the remaining command-line args are in the variable `command-line-args-left'.")
123 (defvar command-line-args-left nil
124 "List of command-line args not yet processed.")
126 (defvaralias 'argv
'command-line-args-left
127 "List of command-line args not yet processed.
128 This is a convenience alias, so that one can write \(pop argv)
129 inside of --eval command line arguments in order to access
130 following arguments.")
131 (internal-make-var-non-special 'argv
)
134 "Current command-line argument.")
135 (internal-make-var-non-special 'argi
)
137 (defvar command-line-functions nil
;; lrs 7/31/89
138 "List of functions to process unrecognized command-line arguments.
139 Each function should access the dynamically bound variables
140 `argi' (the current argument) and `command-line-args-left' (the remaining
141 arguments). The function should return non-nil only if it recognizes and
142 processes `argi'. If it does so, it may consume successive arguments by
143 altering `command-line-args-left' to remove them.")
145 (defvar command-line-default-directory nil
146 "Default directory to use for command line arguments.
147 This is normally copied from `default-directory' when Emacs starts.")
149 ;; This is here, rather than in x-win.el, so that we can ignore these
150 ;; options when we are not using X.
151 (defconst command-line-x-option-alist
152 '(("-bw" 1 x-handle-numeric-switch border-width
)
153 ("-d" 1 x-handle-display
)
154 ("-display" 1 x-handle-display
)
155 ("-name" 1 x-handle-name-switch
)
156 ("-title" 1 x-handle-switch title
)
157 ("-T" 1 x-handle-switch title
)
158 ("-r" 0 x-handle-switch reverse t
)
159 ("-rv" 0 x-handle-switch reverse t
)
160 ("-reverse" 0 x-handle-switch reverse t
)
161 ("-reverse-video" 0 x-handle-switch reverse t
)
162 ("-fn" 1 x-handle-switch font
)
163 ("-font" 1 x-handle-switch font
)
164 ("-fs" 0 x-handle-initial-switch fullscreen fullboth
)
165 ("-fw" 0 x-handle-initial-switch fullscreen fullwidth
)
166 ("-fh" 0 x-handle-initial-switch fullscreen fullheight
)
167 ("-mm" 0 x-handle-initial-switch fullscreen maximized
)
168 ("-ib" 1 x-handle-numeric-switch internal-border-width
)
169 ("-g" 1 x-handle-geometry
)
170 ("-lsp" 1 x-handle-numeric-switch line-spacing
)
171 ("-geometry" 1 x-handle-geometry
)
172 ("-fg" 1 x-handle-switch foreground-color
)
173 ("-foreground" 1 x-handle-switch foreground-color
)
174 ("-bg" 1 x-handle-switch background-color
)
175 ("-background" 1 x-handle-switch background-color
)
176 ("-ms" 1 x-handle-switch mouse-color
)
177 ("-nbi" 0 x-handle-switch icon-type nil
)
178 ("-iconic" 0 x-handle-iconic
)
179 ("-xrm" 1 x-handle-xrm-switch
)
180 ("-cr" 1 x-handle-switch cursor-color
)
181 ("-vb" 0 x-handle-switch vertical-scroll-bars t
)
182 ("-hb" 0 x-handle-switch horizontal-scroll-bars t
)
183 ("-bd" 1 x-handle-switch
)
184 ("--border-width" 1 x-handle-numeric-switch border-width
)
185 ("--display" 1 x-handle-display
)
186 ("--name" 1 x-handle-name-switch
)
187 ("--title" 1 x-handle-switch title
)
188 ("--reverse-video" 0 x-handle-switch reverse t
)
189 ("--font" 1 x-handle-switch font
)
190 ("--fullscreen" 0 x-handle-initial-switch fullscreen fullboth
)
191 ("--fullwidth" 0 x-handle-initial-switch fullscreen fullwidth
)
192 ("--fullheight" 0 x-handle-initial-switch fullscreen fullheight
)
193 ("--maximized" 0 x-handle-initial-switch fullscreen maximized
)
194 ("--internal-border" 1 x-handle-numeric-switch internal-border-width
)
195 ("--geometry" 1 x-handle-geometry
)
196 ("--foreground-color" 1 x-handle-switch foreground-color
)
197 ("--background-color" 1 x-handle-switch background-color
)
198 ("--mouse-color" 1 x-handle-switch mouse-color
)
199 ("--no-bitmap-icon" 0 x-handle-no-bitmap-icon
)
200 ("--iconic" 0 x-handle-iconic
)
201 ("--xrm" 1 x-handle-xrm-switch
)
202 ("--cursor-color" 1 x-handle-switch cursor-color
)
203 ("--vertical-scroll-bars" 0 x-handle-switch vertical-scroll-bars t
)
204 ("--line-spacing" 1 x-handle-numeric-switch line-spacing
)
205 ("--border-color" 1 x-handle-switch border-color
)
206 ("--smid" 1 x-handle-smid
)
207 ("--parent-id" 1 x-handle-parent-id
))
208 "Alist of X Windows options.
209 Each element has the form
210 (NAME NUMARGS HANDLER FRAME-PARAM VALUE)
211 where NAME is the option name string, NUMARGS is the number of arguments
212 that the option accepts, HANDLER is a function to call to handle the option.
213 FRAME-PARAM (optional) is the frame parameter this option specifies,
214 and VALUE is the value which is given to that frame parameter
215 \(most options use the argument for this, so VALUE is not present).")
217 (defconst command-line-ns-option-alist
218 '(("-NSAutoLaunch" 1 ns-ignore-1-arg
)
219 ("-NXAutoLaunch" 1 ns-ignore-1-arg
)
221 ("-NSHost" 1 ns-ignore-1-arg
)
222 ("-_NSMachLaunch" 1 ns-ignore-1-arg
)
223 ("-MachLaunch" 1 ns-ignore-1-arg
)
224 ("-NXOpen" 1 ns-ignore-1-arg
)
225 ("-NSOpen" 1 ns-handle-nxopen
)
226 ("-NXOpenTemp" 1 ns-ignore-1-arg
)
227 ("-NSOpenTemp" 1 ns-handle-nxopentemp
)
228 ("-GSFilePath" 1 ns-handle-nxopen
)
229 ;;("-bw" . x-handle-numeric-switch)
230 ;;("-d" . x-handle-display)
231 ;;("-display" . x-handle-display)
232 ("-name" 1 x-handle-name-switch
)
233 ("-title" 1 x-handle-switch title
)
234 ("-T" 1 x-handle-switch title
)
235 ("-r" 0 x-handle-switch reverse t
)
236 ("-rv" 0 x-handle-switch reverse t
)
237 ("-reverse" 0 x-handle-switch reverse t
)
238 ("-fn" 1 x-handle-switch font
)
239 ("-font" 1 x-handle-switch font
)
240 ("-ib" 1 x-handle-numeric-switch internal-border-width
)
241 ("-g" 1 x-handle-geometry
)
242 ("-geometry" 1 x-handle-geometry
)
243 ("-fg" 1 x-handle-switch foreground-color
)
244 ("-foreground" 1 x-handle-switch foreground-color
)
245 ("-bg" 1 x-handle-switch background-color
)
246 ("-background" 1 x-handle-switch background-color
)
247 ; ("-ms" 1 x-handle-switch mouse-color)
248 ("-itype" 0 x-handle-switch icon-type t
)
249 ("-i" 0 x-handle-switch icon-type t
)
250 ("-iconic" 0 x-handle-iconic icon-type t
)
251 ;;("-xrm" . x-handle-xrm-switch)
252 ("-cr" 1 x-handle-switch cursor-color
)
253 ("-vb" 0 x-handle-switch vertical-scroll-bars t
)
254 ("-hb" 0 x-handle-switch horizontal-scroll-bars t
)
255 ("-bd" 1 x-handle-switch
)
256 ;; ("--border-width" 1 x-handle-numeric-switch border-width)
257 ;; ("--display" 1 ns-handle-display)
258 ("--name" 1 x-handle-name-switch
)
259 ("--title" 1 x-handle-switch title
)
260 ("--reverse-video" 0 x-handle-switch reverse t
)
261 ("--font" 1 x-handle-switch font
)
262 ("--internal-border" 1 x-handle-numeric-switch internal-border-width
)
263 ;; ("--geometry" 1 ns-handle-geometry)
264 ("--foreground-color" 1 x-handle-switch foreground-color
)
265 ("--background-color" 1 x-handle-switch background-color
)
266 ("--mouse-color" 1 x-handle-switch mouse-color
)
267 ("--icon-type" 0 x-handle-switch icon-type t
)
268 ("--iconic" 0 x-handle-iconic
)
269 ;; ("--xrm" 1 ns-handle-xrm-switch)
270 ("--cursor-color" 1 x-handle-switch cursor-color
)
271 ("--vertical-scroll-bars" 0 x-handle-switch vertical-scroll-bars t
)
272 ("--border-color" 1 x-handle-switch border-width
))
273 "Alist of NS options.
274 Each element has the form
275 (NAME NUMARGS HANDLER FRAME-PARAM VALUE)
276 where NAME is the option name string, NUMARGS is the number of arguments
277 that the option accepts, HANDLER is a function to call to handle the option.
278 FRAME-PARAM (optional) is the frame parameter this option specifies,
279 and VALUE is the value which is given to that frame parameter
280 \(most options use the argument for this, so VALUE is not present).")
283 (defvar before-init-hook nil
284 "Normal hook run after handling urgent options but before loading init files.")
286 (defvar after-init-hook nil
287 "Normal hook run after initializing the Emacs session.
288 It is run after Emacs loads the init file, `default' library, the
289 abbrevs file, and additional Lisp packages (if any), and setting
290 the value of `after-init-time'.
292 There is no `condition-case' around the running of this hook;
293 therefore, if `debug-on-error' is non-nil, an error in one of
294 these functions will invoke the debugger.")
296 (defvar emacs-startup-hook nil
297 "Normal hook run after loading init files and handling the command line.")
299 (defvar term-setup-hook nil
300 "Normal hook run immediately after `emacs-startup-hook'.
301 In new code, there is no reason to use this instead of `emacs-startup-hook'.
302 If you want to execute terminal-specific Lisp code, for example
303 to override the definitions made by the terminal-specific file,
304 see `tty-setup-hook'.")
306 (make-obsolete-variable 'term-setup-hook
307 "use either `emacs-startup-hook' or \
308 `tty-setup-hook' instead." "24.4")
310 (defvar inhibit-startup-hooks nil
311 "Non-nil means don't run some startup hooks, because we already did.
312 Currently this applies to: `emacs-startup-hook', `term-setup-hook',
313 and `window-setup-hook'.")
315 (defvar keyboard-type nil
316 "The brand of keyboard you are using.
317 This variable is used to define the proper function and keypad
318 keys for use under X. It is used in a fashion analogous to the
319 environment variable TERM.")
321 (defvar window-setup-hook nil
322 "Normal hook run after loading init files and handling the command line.
323 This is very similar to `emacs-startup-hook'. The only difference
324 is that this hook runs after frame parameters have been set up in
325 response to any settings from your init file. Unless this matters
326 to you, use `emacs-startup-hook' instead. (The name of this hook
327 is due to historical reasons, and does not reflect its purpose very well.)")
329 (defcustom initial-major-mode
'lisp-interaction-mode
330 "Major mode command symbol to use for the initial `*scratch*' buffer."
332 :group
'initialization
)
334 (defvar init-file-user nil
335 "Identity of user whose init file is or was read.
336 The value is nil if `-q' or `--no-init-file' was specified,
337 meaning do not load any init file.
339 Otherwise, the value may be an empty string, meaning
340 use the init file for the user who originally logged in,
341 or it may be a string containing a user's name meaning
342 use that person's init file.
344 In either of the latter cases, `(concat \"~\" init-file-user \"/\")'
345 evaluates to the name of the directory where the init file was
348 Setting `init-file-user' does not prevent Emacs from loading
349 `site-start.el'. The only way to do that is to use `--no-site-file'.")
351 (defcustom site-run-file
(purecopy "site-start")
352 "File containing site-wide run-time initializations.
353 This file is loaded at run-time before `~/.emacs'. It contains inits
354 that need to be in place for the entire site, but which, due to their
355 higher incidence of change, don't make sense to load into Emacs's
356 dumped image. Thus, the run-time load order is: 1. file described in
357 this variable, if non-nil; 2. `~/.emacs'; 3. `default.el'.
359 Don't use the `site-start.el' file for things some users may not like.
360 Put them in `default.el' instead, so that users can more easily
361 override them. Users can prevent loading `default.el' with the `-q'
362 option or by setting `inhibit-default-init' in their own init files,
363 but inhibiting `site-start.el' requires `--no-site-file', which
366 This variable is defined for customization so as to make
367 it visible in the relevant context. However, actually customizing it
368 is not allowed, since it would not work anyway. The only way to set
369 this variable usefully is to set it while building and dumping Emacs."
370 :type
'(choice (const :tag
"none" nil
) string
)
371 :group
'initialization
372 :initialize
#'custom-initialize-default
373 :set
(lambda (_variable _value
)
374 (error "Customizing `site-run-file' does not work")))
376 (make-obsolete-variable 'system-name
"use (system-name) instead" "25.1")
378 (defcustom mail-host-address nil
379 "Name of this machine, for purposes of naming users.
380 If non-nil, Emacs uses this instead of `system-name' when constructing
382 :type
'(choice (const nil
) string
)
385 (defcustom user-mail-address
(if command-line-processed
387 (concat (user-login-name) "@"
388 (or mail-host-address
390 ;; Empty string means "not set yet".
392 "Full mailing address of this user.
393 This is initialized with environment variable `EMAIL' or, as a
394 fallback, using `mail-host-address'. This is done after your
395 init file is read, in case it sets `mail-host-address'."
399 (defcustom auto-save-list-file-prefix
400 (cond ((eq system-type
'ms-dos
)
401 ;; MS-DOS cannot have initial dot, and allows only 8.3 names
402 (concat user-emacs-directory
"auto-save.list/_s"))
404 (concat user-emacs-directory
"auto-save-list/.saves-")))
405 "Prefix for generating `auto-save-list-file-name'.
406 This is used after reading your init file to initialize
407 `auto-save-list-file-name', by appending Emacs's pid and the system name,
408 if you have not already set `auto-save-list-file-name' yourself.
409 Directories in the prefix will be created if necessary.
410 Set this to nil if you want to prevent `auto-save-list-file-name'
411 from being initialized."
412 :type
'(choice (const :tag
"Don't record a session's auto save list" nil
)
416 (defvar emacs-basic-display nil
)
418 (defvar init-file-debug nil
)
420 (defvar init-file-had-error nil
421 "Non-nil if there was an error loading the user's init file.")
423 (defvar normal-top-level-add-subdirs-inode-list nil
)
425 (defvar no-blinking-cursor nil
)
427 (defvar pure-space-overflow nil
428 "Non-nil if building Emacs overflowed pure space.")
430 (defvar pure-space-overflow-message
(purecopy "\
431 Warning Warning!!! Pure space overflow !!!Warning Warning
432 \(See the node Pure Storage in the Lisp manual for details.)\n"))
434 (defcustom tutorial-directory
435 (file-name-as-directory (expand-file-name "tutorials" data-directory
))
436 "Directory containing the Emacs TUTORIAL files."
439 :initialize
#'custom-initialize-delay
)
441 (defun normal-top-level-add-subdirs-to-load-path ()
442 "Recursively add all subdirectories of `default-directory' to `load-path'.
443 More precisely, this uses only the subdirectories whose names
444 start with letters or digits; it excludes any subdirectory named `RCS'
445 or `CVS', and any subdirectory that contains a file named `.nosearch'."
448 (pending (list default-directory
)))
449 ;; This loop does a breadth-first tree walk on DIR's subtree,
450 ;; putting each subdir into DIRS as its contents are examined.
452 (push (pop pending
) dirs
)
453 (let* ((this-dir (car dirs
))
454 (contents (directory-files this-dir
))
455 (default-directory this-dir
)
456 (canonicalized (if (fboundp 'w32-untranslated-canonical-name
)
457 (w32-untranslated-canonical-name this-dir
))))
458 ;; The Windows version doesn't report meaningful inode numbers, so
459 ;; use the canonicalized absolute file name of the directory instead.
460 (setq attrs
(or canonicalized
461 (nthcdr 10 (file-attributes this-dir
))))
462 (unless (member attrs normal-top-level-add-subdirs-inode-list
)
463 (push attrs normal-top-level-add-subdirs-inode-list
)
464 (dolist (file contents
)
465 (and (string-match "\\`[[:alnum:]]" file
)
466 ;; The lower-case variants of RCS and CVS are for DOS/Windows.
467 (not (member file
'("RCS" "CVS" "rcs" "cvs")))
468 ;; Avoid doing a `stat' when it isn't necessary because
469 ;; that can cause trouble when an NFS server is down.
470 (not (string-match "\\.elc?\\'" file
))
471 (file-directory-p file
)
472 (let ((expanded (expand-file-name file
)))
473 (or (file-exists-p (expand-file-name ".nosearch" expanded
))
474 (setq pending
(nconc pending
(list expanded
))))))))))
475 (normal-top-level-add-to-load-path (cdr (nreverse dirs
)))))
477 (defun normal-top-level-add-to-load-path (dirs)
478 "This function is called from a subdirs.el file.
479 It assumes that `default-directory' is the directory in which the
480 subdirs.el file exists, and it adds to `load-path' the subdirs of
481 that directory as specified in DIRS. Normally the elements of
483 (let ((tail load-path
)
484 (thisdir (directory-file-name default-directory
)))
486 ;;Don't go all the way to the nil terminator.
488 (not (equal thisdir
(car tail
)))
489 (not (and (memq system-type
'(ms-dos windows-nt
))
490 (equal (downcase thisdir
) (downcase (car tail
))))))
491 (setq tail
(cdr tail
)))
492 ;;Splice the new section in.
494 (setcdr tail
(append (mapcar 'expand-file-name dirs
) (cdr tail
))))))
496 (defun normal-top-level ()
497 "Emacs calls this function when it first starts up.
498 It sets `command-line-processed', processes the command-line,
499 reads the initialization files, etc.
500 It is the default value of the variable `top-level'."
501 (if command-line-processed
502 (message internal--top-level-message
)
503 (setq command-line-processed t
)
505 ;; Look in each dir in load-path for a subdirs.el file. If we
506 ;; find one, load it, which will add the appropriate subdirs of
507 ;; that dir into load-path. This needs to be done before setting
508 ;; the locale environment, because the latter might need to load
509 ;; some support files.
510 ;; Look for a leim-list.el file too. Loading it will register
511 ;; available input methods.
512 (let ((tail load-path
)
513 (lispdir (expand-file-name "../lisp" data-directory
))
516 (setq dir
(car tail
))
517 (let ((default-directory dir
))
518 (load (expand-file-name "subdirs.el") t t t
))
519 ;; Do not scan standard directories that won't contain a leim-list.el.
520 ;; http://lists.gnu.org/archive/html/emacs-devel/2009-10/msg00502.html
521 ;; (Except the preloaded one in lisp/leim.)
522 (or (string-prefix-p lispdir dir
)
523 (let ((default-directory dir
))
524 (load (expand-file-name "leim-list.el") t t t
)))
525 ;; We don't use a dolist loop and we put this "setq-cdr" command at
526 ;; the end, because the subdirs.el files may add elements to the end
527 ;; of load-path and we want to take it into account.
528 (setq tail
(cdr tail
))))
530 ;; Set the default strings to display in mode line for end-of-line
531 ;; formats that aren't native to this platform. This should be
532 ;; done before calling set-locale-environment, as the latter might
533 ;; use these mnemonics.
535 ((memq system-type
'(ms-dos windows-nt
))
536 (setq eol-mnemonic-unix
"(Unix)"
537 eol-mnemonic-mac
"(Mac)"))
538 (t ; this is for Unix/GNU/Linux systems
539 (setq eol-mnemonic-dos
"(DOS)"
540 eol-mnemonic-mac
"(Mac)")))
542 (set-locale-environment nil
)
543 ;; Decode all default-directory's (probably, only *scratch* exists
544 ;; at this point). default-directory of *scratch* is the basis
545 ;; for many other file-name variables and directory lists, so it
546 ;; is important to decode it ASAP.
547 (when locale-coding-system
548 (let ((coding (if (eq system-type
'windows-nt
)
549 ;; MS-Windows build converts all file names to
550 ;; UTF-8 during startup.
552 locale-coding-system
)))
554 (dolist (elt (buffer-list))
556 (if default-directory
557 (setq default-directory
558 (if (eq system-type
'windows-nt
)
559 ;; Convert backslashes to forward slashes.
561 (decode-coding-string default-directory coding t
))
562 (decode-coding-string default-directory coding t
))))))
564 ;; Decode all the important variables and directory lists, now
565 ;; that we know the locale's encoding. This is because the
566 ;; values of these variables are until here unibyte undecoded
567 ;; strings created by build_unibyte_string. data-directory in
568 ;; particular is used to construct many other standard
569 ;; directory names, so it must be decoded ASAP. Note that
570 ;; charset-map-path cannot be decoded here, since we could
571 ;; then be trapped in infinite recursion below, when we load
572 ;; subdirs.el, because encoding a directory name might need to
573 ;; load a charset map, which will want to encode
574 ;; charset-map-path, which will want to load the same charset
575 ;; map... So decoding of charset-map-path is delayed until
576 ;; further down below.
577 (dolist (pathsym '(load-path exec-path
))
578 (let ((path (symbol-value pathsym
)))
580 (set pathsym
(mapcar (lambda (dir)
581 (decode-coding-string dir coding t
))
583 (dolist (filesym '(data-directory doc-directory exec-directory
584 installation-directory
585 invocation-directory invocation-name
587 shared-game-score-directory
))
588 (let ((file (symbol-value filesym
)))
590 (set filesym
(decode-coding-string file coding t
)))))))
592 (let ((dir default-directory
))
593 (with-current-buffer "*Messages*"
594 (messages-buffer-mode)
595 ;; Make it easy to do like "tail -f".
596 (set (make-local-variable 'window-point-insertion-type
) t
)
597 ;; Give *Messages* the same default-directory as *scratch*,
598 ;; just to keep things predictable.
599 (setq default-directory
(or dir
(expand-file-name "~/")))))
600 ;; `user-full-name' is now known; reset its standard-value here.
601 (put 'user-full-name
'standard-value
602 (list (default-value 'user-full-name
)))
603 ;; If the PWD environment variable isn't accurate, delete it.
604 (let ((pwd (getenv "PWD")))
606 ;; Use FOO/., so that if FOO is a symlink, file-attributes
607 ;; describes the directory linked to, not FOO itself.
608 (or (and default-directory
609 (equal (file-attributes
610 (concat (file-name-as-directory pwd
) "."))
612 (concat (file-name-as-directory default-directory
)
614 (setq process-environment
615 (delete (concat "PWD=" pwd
)
616 process-environment
)))))
617 ;; Now, that other directories were searched, and any charsets we
618 ;; need for encoding them are already loaded, we are ready to
619 ;; decode charset-map-path.
620 (if (listp charset-map-path
)
621 (let ((coding (if (eq system-type
'windows-nt
)
623 locale-coding-system
)))
624 (setq charset-map-path
625 (mapcar (lambda (dir)
626 (decode-coding-string dir coding t
))
628 (if default-directory
629 (setq default-directory
(abbreviate-file-name default-directory
))
630 (display-warning 'initialization
"Error setting default-directory"))
631 (let ((old-face-font-rescale-alist face-font-rescale-alist
))
634 ;; Do this again, in case .emacs defined more abbreviations.
635 (if default-directory
636 (setq default-directory
(abbreviate-file-name default-directory
)))
637 ;; Specify the file for recording all the auto save files of this session.
638 ;; This is used by recover-session.
639 (or auto-save-list-file-name
640 (and auto-save-list-file-prefix
641 (setq auto-save-list-file-name
642 ;; Under MS-DOS our PID is almost always reused between
643 ;; Emacs invocations. We need something more unique.
644 (cond ((eq system-type
'ms-dos
)
645 ;; We are going to access the auto-save
646 ;; directory, so make sure it exists.
648 (file-name-directory auto-save-list-file-prefix
)
653 auto-save-list-file-prefix
))
658 auto-save-list-file-prefix
661 (unless inhibit-startup-hooks
662 (run-hooks 'emacs-startup-hook
'term-setup-hook
))
664 ;; Don't do this if we failed to create the initial frame,
665 ;; for instance due to a dense colormap.
666 (when (or frame-initial-frame
667 ;; If frame-initial-frame has no meaning, do this anyway.
668 (not (and initial-window-system
670 (not (eq initial-window-system
'pc
)))))
672 ;; FIXME: The user's init file may change
673 ;; face-font-rescale-alist. However, the default face
674 ;; already has an assigned font object, which does not take
675 ;; face-font-rescale-alist into account. For such
676 ;; situations, we ought to have a way to find all font
677 ;; objects and regenerate them; currently we do not. As a
678 ;; workaround, we specifically reset te default face's :font
679 ;; attribute here. See bug#1785.
680 (unless (eq face-font-rescale-alist
681 old-face-font-rescale-alist
)
682 (set-face-attribute 'default nil
:font
(font-spec)))
684 ;; Modify the initial frame based on what .emacs puts into
686 (if (fboundp 'frame-notice-user-settings
)
687 (frame-notice-user-settings))
688 ;; Set the faces for the initial background mode even if
689 ;; frame-notice-user-settings didn't (such as on a tty).
690 ;; frame-set-background-mode is idempotent, so it won't
691 ;; cause any harm if it's already been done.
692 (if (fboundp 'frame-set-background-mode
)
693 (frame-set-background-mode (selected-frame))))
695 ;; Now we know the user's default font, so add it to the menu.
696 (if (fboundp 'font-menu-add-default
)
697 (font-menu-add-default))
698 (unless inhibit-startup-hooks
699 (run-hooks 'window-setup-hook
))))
700 ;; Subprocesses of Emacs do not have direct access to the terminal, so
701 ;; unless told otherwise they should only assume a dumb terminal.
702 ;; We are careful to do it late (after term-setup-hook), although the
703 ;; new multi-tty code does not use $TERM any more there anyway.
704 (setenv "TERM" "dumb")
705 ;; Remove DISPLAY from the process-environment as well. This allows
706 ;; `callproc.c' to give it a useful adaptive default which is either
707 ;; the value of the `display' frame-parameter or the DISPLAY value
708 ;; from initial-environment.
709 (let ((display (frame-parameter nil
'display
)))
710 ;; Be careful which DISPLAY to remove from process-environment: follow
711 ;; the logic of `callproc.c'.
712 (if (stringp display
) (setq display
(concat "DISPLAY=" display
))
713 (dolist (varval initial-environment
)
714 (if (string-match "\\`DISPLAY=" varval
)
715 (setq display varval
))))
717 (delete display process-environment
)))))
719 ;; Precompute the keyboard equivalents in the menu bar items.
720 ;; Command-line options supported by tty's:
721 (defconst tty-long-option-alist
722 '(("--name" .
"-name")
724 ("--reverse-video" .
"-reverse")
725 ("--foreground-color" .
"-fg")
726 ("--background-color" .
"-bg")
727 ("--color" .
"-color")))
729 (defconst tool-bar-images-pixel-height
24
730 "Height in pixels of images in the tool-bar.")
732 (cl-defgeneric handle-args-function
(args)
733 "Method for processing window-system dependent command-line arguments.
734 Window system startup files should add their own function to this
735 method, which should parse the command line arguments. Those
736 pertaining to the window system should be processed and removed
737 from the returned command line.")
738 (cl-defmethod handle-args-function (args &context
(window-system nil
))
739 (tty-handle-args args
))
741 (cl-defgeneric window-system-initialization
(&optional _display
)
742 "Method for window-system initialization.
743 Window-system startup files should add their own implementation
744 to this method. The function should initialize the window system environment
745 to prepare for opening the first frame (e.g. open a connection to an X server)."
748 (defun tty-handle-args (args)
749 "Handle the X-like command-line arguments \"-fg\", \"-bg\", \"-name\", etc."
752 (not (equal (car args
) "--")))
753 (let* ((argi (pop args
))
756 ;; Check for long options with attached arguments
757 ;; and separate out the attached option argument into argval.
758 (when (string-match "^\\(--[^=]*\\)=" argi
)
759 (setq argval
(substring argi
(match-end 0))
760 argi
(match-string 1 argi
)))
761 (when (string-match "^--" argi
)
762 (setq completion
(try-completion argi tty-long-option-alist
))
763 (if (eq completion t
)
764 ;; Exact match for long option.
765 (setq argi
(cdr (assoc argi tty-long-option-alist
)))
766 (if (stringp completion
)
767 (let ((elt (assoc completion tty-long-option-alist
)))
768 ;; Check for abbreviated long option.
770 (error "Option `%s' is ambiguous" argi
))
771 (setq argi
(cdr elt
)))
772 ;; Check for a short option.
775 (cond ((member argi
'("-fg" "-foreground"))
776 (push (cons 'foreground-color
(or argval
(pop args
)))
777 default-frame-alist
))
778 ((member argi
'("-bg" "-background"))
779 (push (cons 'background-color
(or argval
(pop args
)))
780 default-frame-alist
))
781 ((member argi
'("-T" "-name"))
782 (unless argval
(setq argval
(pop args
)))
786 (let ((case-fold-search t
)
788 (setq argval
(invocation-name))
790 ;; Change any . or * characters in name to
791 ;; hyphens, so as to emulate behavior on X.
793 (setq i
(string-match "[.*]" argval
))
796 default-frame-alist
))
797 ((member argi
'("-r" "-rv" "-reverse"))
799 default-frame-alist
))
800 ((equal argi
"-color")
801 (unless argval
(setq argval
8)) ; default --color means 8 ANSI colors
802 (push (cons 'tty-color-mode
804 ((numberp argval
) argval
)
805 ((string-match "-?[0-9]+" argval
)
806 (string-to-number argval
))
807 (t (intern argval
))))
808 default-frame-alist
))
811 (nconc (nreverse rest
) args
)))
813 (declare-function x-get-resource
"frame.c"
814 (attribute class
&optional component subclass
))
815 (declare-function tool-bar-mode
"tool-bar" (&optional arg
))
816 (declare-function tool-bar-setup
"tool-bar")
819 (defvar server-process
)
821 (defun startup--setup-quote-display (&optional style
)
822 "If needed, display ASCII approximations to curved quotes.
823 Do this by modifying `standard-display-table'. Optional STYLE
824 specifies the desired quoting style, as in `text-quoting-style'.
825 If STYLE is nil, display appropriately for the terminal."
826 (let ((repls (let ((style-repls (assq style
'((grave .
"`'\"\"")
827 (straight .
"''\"\"")))))
828 (if style-repls
(cdr style-repls
) (make-vector 4 nil
))))
830 ;; REPLS is a sequence of the four replacements for "‘’“”", respectively.
831 ;; If STYLE is nil, infer REPLS from terminal characteristics.
833 ;; On a terminal that supports glyph codes,
834 ;; GLYPH-COUNT[i] is the number of times that glyph code I
835 ;; represents either an ASCII character or one of the 4
836 ;; quote characters. This assumes glyph codes are valid
837 ;; Elisp characters, which is a safe assumption in practice.
838 (when (integerp (internal-char-font nil
(max-char)))
839 (setq glyph-count
(make-char-table nil
0))
841 (let ((glyph (internal-char-font
842 nil
(if (< i
128) i
(aref "‘’“”" (- i
128))))))
844 (aset glyph-count glyph
(1+ (aref glyph-count glyph
)))))))
846 (let ((lq (aref "‘“" i
)) (rq (aref "’”" i
))
847 (lr (aref "`\"" i
)) (rr (aref "'\"" i
))
849 (unless (if glyph-count
850 ;; On a terminal that supports glyph codes, use
851 ;; ASCII replacements unless both quotes are displayable.
852 ;; If not using ASCII replacements, highlight
853 ;; quotes unless they are both unique among the
854 ;; 128 + 4 characters of concern.
855 (let ((lglyph (internal-char-font nil lq
))
856 (rglyph (internal-char-font nil rq
)))
857 (when (and (<= 0 lglyph
) (<= 0 rglyph
))
859 (and (= 1 (aref glyph-count lglyph
))
860 (= 1 (aref glyph-count rglyph
)))))
861 ;; On a terminal that does not support glyph codes, use
862 ;; ASCII replacements unless both quotes are displayable.
863 (and (char-displayable-p lq
)
864 (char-displayable-p rq
)))
866 (aset repls
(1+ i2
) rr
)))))
868 (let ((char (aref "‘’“”" i
))
869 (repl (aref repls i
)))
871 (aset (or standard-display-table
872 (setq standard-display-table
(make-display-table)))
873 char
(vector (make-glyph-code repl
'escape-glyph
)))
874 (when standard-display-table
875 (aset standard-display-table char nil
)))))))
877 (defun command-line ()
878 "A subroutine of `normal-top-level'.
879 Amongst another things, it parses the command-line arguments."
880 (setq before-init-time
(current-time)
882 command-line-default-directory default-directory
)
884 ;; Force recomputation, in case it was computed during the dump.
885 (setq abbreviated-home-dir nil
)
887 ;; See if we should import version-control from the environment variable.
888 (let ((vc (getenv "VERSION_CONTROL")))
889 (cond ((eq vc nil
)) ;don't do anything if not set
890 ((member vc
'("t" "numbered"))
891 (setq version-control t
))
892 ((member vc
'("nil" "existing"))
893 (setq version-control nil
))
894 ((member vc
'("never" "simple"))
895 (setq version-control
'never
))))
897 ;;! This has been commented out; I currently find the behavior when
898 ;;! split-window-keep-point is nil disturbing, but if I can get used
899 ;;! to it, then it would be better to eliminate the option.
900 ;;! ;; Choose a good default value for split-window-keep-point.
901 ;;! (setq split-window-keep-point (> baud-rate 2400))
903 ;; Convert preloaded file names in load-history to absolute.
904 (let ((simple-file-name
905 ;; Look for simple.el or simple.elc and use their directory
906 ;; as the place where all Lisp files live.
907 (locate-file "simple" load-path
(get-load-suffixes)))
909 ;; Don't abort if simple.el cannot be found, but print a warning.
910 ;; Although in most usage we are going to cryptically abort a moment
911 ;; later anyway, due to missing required bidi data files (eg bug#13430).
912 (if (null simple-file-name
)
913 (let ((standard-output 'external-debugging-output
)
914 (lispdir (expand-file-name "../lisp" data-directory
)))
915 (princ "Warning: Could not find simple.el or simple.elc")
917 (when (getenv "EMACSLOADPATH")
918 (princ "The EMACSLOADPATH environment variable is set, \
919 please check its value")
921 (unless (file-readable-p lispdir
)
922 (princ (format "Lisp directory %s not readable?" lispdir
))
924 (setq lisp-dir
(file-truename (file-name-directory simple-file-name
)))
926 (mapcar (lambda (elt)
927 (if (and (stringp (car elt
))
928 (not (file-name-absolute-p (car elt
))))
929 (cons (concat lisp-dir
935 ;; Convert the arguments to Emacs internal representation.
936 (let ((args command-line-args
))
939 (decode-coding-string (car args
) locale-coding-system t
))
943 (args (cdr command-line-args
))
946 ;; Figure out which user's init file to load,
947 ;; either from the environment or from the options.
948 (setq init-file-user
(if noninteractive nil
(user-login-name)))
949 ;; If user has not done su, use current $HOME to find .emacs.
951 (equal init-file-user
(user-real-login-name))
952 (setq init-file-user
""))
954 ;; Process the command-line args, and delete the arguments
955 ;; processed. This is consistent with the way main in emacs.c
957 (while (and (not done
) args
)
958 (let* ((longopts '(("--no-init-file") ("--no-site-file")
959 ("--no-x-resources") ("--debug-init")
960 ("--user") ("--iconic") ("--icon-type") ("--quick")
961 ("--no-blinking-cursor") ("--basic-display")))
965 ;; Handle --OPTION=VALUE format.
966 (when (string-match "\\`\\(--[^=]*\\)=" argi
)
967 (setq argval
(substring argi
(match-end 0))
968 argi
(match-string 1 argi
)))
969 (when (string-match "\\`--." orig-argi
)
970 (let ((completion (try-completion argi longopts
)))
971 (cond ((eq completion t
)
972 (setq argi
(substring argi
1)))
973 ((stringp completion
)
974 (let ((elt (assoc completion longopts
)))
976 (error "Option `%s' is ambiguous" argi
))
977 (setq argi
(substring (car elt
) 1))))
982 ;; The --display arg is handled partly in C, partly in Lisp.
983 ;; When it shows up here, we just put it back to be handled
984 ;; by `command-line-1'.
985 ((member argi
'("-d" "-display"))
986 (setq display-arg
(list argi
(pop args
))))
987 ((member argi
'("-Q" "-quick"))
988 (setq init-file-user nil
990 inhibit-x-resources t
)
991 ;; Stop it showing up in emacs -Q's customize-rogue.
992 (put 'site-run-file
'standard-value
'(nil)))
993 ((member argi
'("-no-x-resources"))
994 (setq inhibit-x-resources t
))
995 ((member argi
'("-D" "-basic-display"))
996 (setq no-blinking-cursor t
997 emacs-basic-display t
)
998 (push '(vertical-scroll-bars . nil
) initial-frame-alist
))
999 ((member argi
'("-q" "-no-init-file"))
1000 (setq init-file-user nil
))
1001 ((member argi
'("-u" "-user"))
1002 (setq init-file-user
(or argval
(pop args
))
1004 ((equal argi
"-no-site-file")
1005 (setq site-run-file nil
)
1006 (put 'site-run-file
'standard-value
'(nil)))
1007 ((equal argi
"-debug-init")
1008 (setq init-file-debug t
))
1009 ((equal argi
"-iconic")
1010 (push '(visibility . icon
) initial-frame-alist
))
1011 ((member argi
'("-nbc" "-no-blinking-cursor"))
1012 (setq no-blinking-cursor t
))
1013 ;; Push the popped arg back on the list of arguments.
1017 ;; Was argval set but not used?
1019 (error "Option `%s' doesn't allow an argument" argi
))))
1021 ;; Re-attach the --display arg.
1022 (and display-arg
(setq args
(append display-arg args
)))
1024 ;; Re-attach the program name to the front of the arg list.
1025 (and command-line-args
1026 (setcdr command-line-args args
)))
1028 ;; Make sure window system's init file was loaded in loadup.el if
1029 ;; using a window system.
1030 ;; Initialize the window-system only after processing the command-line
1031 ;; args so that -Q can influence this initialization.
1032 (condition-case error
1033 (unless noninteractive
1034 (if (and initial-window-system
1037 (concat (symbol-name initial-window-system
) "-win")))))
1038 (error "Unsupported window system `%s'" initial-window-system
))
1039 ;; Process window-system specific command line parameters.
1040 (setq command-line-args
1041 (let ((window-system initial-window-system
)) ;Hack attack!
1042 (handle-args-function command-line-args
)))
1043 ;; Initialize the window system. (Open connection, etc.)
1044 (let ((window-system initial-window-system
)) ;Hack attack!
1045 (window-system-initialization))
1046 (put initial-window-system
'window-system-initialized t
))
1047 ;; If there was an error, print the error message and exit.
1050 (if (eq (car error
) 'error
)
1051 (apply 'concat
(cdr error
))
1052 (if (memq 'file-error
(get (car error
) 'error-conditions
))
1055 (mapconcat (lambda (obj) (prin1-to-string obj t
))
1056 (cdr (cdr error
)) ", "))
1058 (get (car error
) 'error-message
)
1059 (mapconcat (lambda (obj) (prin1-to-string obj t
))
1060 (cdr error
) ", "))))
1061 'external-debugging-output
)
1062 (terpri 'external-debugging-output
)
1063 (setq initial-window-system nil
)
1066 (run-hooks 'before-init-hook
)
1068 ;; Under X, create the X frame and delete the terminal frame.
1070 (if (or noninteractive emacs-basic-display
)
1071 (setq menu-bar-mode nil
1073 no-blinking-cursor t
))
1076 (when (fboundp 'x-create-frame
)
1077 ;; Set up the tool-bar (even in tty frames, since Emacs might open a
1078 ;; graphical frame later).
1079 (unless noninteractive
1082 ;; Turn off blinking cursor if so specified in X resources. This is here
1083 ;; only because all other settings of no-blinking-cursor are here.
1084 (unless (or noninteractive
1086 (and (memq window-system
'(x w32 ns
))
1087 (not (member (x-get-resource "cursorBlink" "CursorBlink")
1088 '("no" "off" "false" "0")))))
1089 (setq no-blinking-cursor t
))
1091 (unless noninteractive
1092 (startup--setup-quote-display)
1093 (setq internal--text-quoting-flag t
))
1095 ;; Re-evaluate predefined variables whose initial value depends on
1096 ;; the runtime context.
1097 (mapc 'custom-reevaluate-setting
1098 ;; Initialize them in the same order they were loaded, in case there
1099 ;; are dependencies between them.
1100 (prog1 (nreverse custom-delayed-init-variables
)
1101 (setq custom-delayed-init-variables nil
)))
1103 (normal-erase-is-backspace-setup-frame)
1105 ;; Register default TTY colors for the case the terminal hasn't a
1106 ;; terminal init file. We do this regardless of whether the terminal
1107 ;; supports colors or not and regardless the current display type,
1108 ;; since users can connect to color-capable terminals and also
1109 ;; switch color support on or off in mid-session by setting the
1110 ;; tty-color-mode frame parameter.
1111 ;; Exception: the `pc' ``window system'' has only 16 fixed colors,
1112 ;; and they are already set at this point by a suitable method of
1113 ;; window-system-initialization.
1114 (or (eq initial-window-system
'pc
)
1115 (tty-register-default-colors))
1117 (let ((old-scalable-fonts-allowed scalable-fonts-allowed
)
1118 (old-face-ignored-fonts face-ignored-fonts
))
1120 ;; Run the site-start library if it exists. The point of this file is
1121 ;; that it is run before .emacs. There is no point in doing this after
1122 ;; .emacs; that is useless.
1123 ;; Note that user-init-file is nil at this point. Code that might
1124 ;; be loaded from site-run-file and wants to test if -q was given
1125 ;; should check init-file-user instead, since that is already set.
1126 ;; See cus-edit.el for an example.
1128 (load site-run-file t t
))
1130 ;; Sites should not disable this. Only individuals should disable
1131 ;; the startup screen.
1132 (setq inhibit-startup-screen nil
)
1134 ;; Warn for invalid user name.
1135 (when init-file-user
1136 (if (string-match "[~/:\n]" init-file-user
)
1137 (display-warning 'initialization
1138 (format "Invalid user name %s"
1141 (if (file-directory-p (expand-file-name
1142 ;; We don't support ~USER on MS-Windows
1143 ;; and MS-DOS except for the current
1144 ;; user, and always load .emacs from
1145 ;; the current user's home directory
1146 ;; (see below). So always check "~",
1147 ;; even if invoked with "-u USER", or
1148 ;; if $USER or $LOGNAME are set to
1149 ;; something different.
1150 (if (memq system-type
'(windows-nt ms-dos
))
1152 (concat "~" init-file-user
))))
1154 (display-warning 'initialization
1155 (format "User %s has no home directory"
1156 (if (equal init-file-user
"")
1157 (user-real-login-name)
1161 ;; Load that user's init file, or the default one, or none.
1162 (let (debug-on-error-from-init-file
1163 debug-on-error-should-be-set
1164 (debug-on-error-initial
1165 (if (eq init-file-debug t
) 'startup init-file-debug
))
1166 (orig-enable-multibyte (default-value 'enable-multibyte-characters
)))
1167 (let ((debug-on-error debug-on-error-initial
)
1168 ;; This function actually reads the init files.
1173 (let ((user-init-file-1
1175 ((eq system-type
'ms-dos
)
1176 (concat "~" init-file-user
"/_emacs"))
1177 ((not (eq system-type
'windows-nt
))
1178 (concat "~" init-file-user
"/.emacs"))
1179 ;; Else deal with the Windows situation
1180 ((directory-files "~" nil
"^\\.emacs\\(\\.elc?\\)?$")
1181 ;; Prefer .emacs on Windows.
1183 ((directory-files "~" nil
"^_emacs\\(\\.elc?\\)?$")
1184 ;; Also support _emacs for compatibility, but warn about it.
1185 (push `(initialization
1187 "`_emacs' init file is deprecated, please use `.emacs'"))
1188 delayed-warnings-list
)
1190 (t ;; But default to .emacs if _emacs does not exist.
1192 ;; This tells `load' to store the file name found
1193 ;; into user-init-file.
1194 (setq user-init-file t
)
1195 (load user-init-file-1 t t
)
1197 (when (eq user-init-file t
)
1198 ;; If we did not find ~/.emacs, try
1199 ;; ~/.emacs.d/init.el.
1203 (file-name-as-directory
1204 (concat "~" init-file-user
"/.emacs.d")))))
1205 (load otherfile t t
)
1207 ;; If we did not find the user's init file,
1208 ;; set user-init-file conclusively.
1209 ;; Don't let it be set from default.el.
1210 (when (eq user-init-file t
)
1211 (setq user-init-file user-init-file-1
))))
1213 ;; If we loaded a compiled file, set
1214 ;; `user-init-file' to the source version if that
1216 (when (and user-init-file
1217 (equal (file-name-extension user-init-file
)
1219 (let* ((source (file-name-sans-extension user-init-file
))
1220 (alt (concat source
".el")))
1221 (setq source
(cond ((file-exists-p alt
) alt
)
1222 ((file-exists-p source
) source
)
1225 (when (file-newer-than-file-p source user-init-file
)
1226 (message "Warning: %s is newer than %s"
1227 source user-init-file
)
1229 (setq user-init-file source
))))
1231 (unless inhibit-default-init
1232 (let ((inhibit-startup-screen nil
))
1233 ;; Users are supposed to be told their rights.
1234 ;; (Plus how to get help and how to undo.)
1235 ;; Don't you dare turn this off for anyone
1237 (load "default" t t
)))))))))
1239 ;; Do this without a condition-case if the user wants to debug.
1241 (condition-case error
1244 (setq init-file-had-error nil
))
1249 An error occurred while loading `%s':\n\n%s%s%s\n\n\
1250 To ensure normal operation, you should investigate and remove the
1251 cause of the error in your initialization file. Start Emacs with
1252 the `--debug-init' option to view a complete error backtrace."
1254 (get (car error
) 'error-message
)
1255 (if (cdr error
) ": " "")
1256 (mapconcat (lambda (s) (prin1-to-string s t
))
1259 (setq init-file-had-error t
))))
1261 (if (and deactivate-mark transient-mark-mode
)
1262 (with-current-buffer (window-buffer)
1265 ;; If the user has a file of abbrevs, read it (unless -batch).
1266 (when (and (not noninteractive
)
1267 (file-exists-p abbrev-file-name
)
1268 (file-readable-p abbrev-file-name
))
1269 (quietly-read-abbrev-file abbrev-file-name
))
1271 ;; If the abbrevs came entirely from the init file or the
1272 ;; abbrevs file, they do not need saving.
1273 (setq abbrevs-changed nil
)
1275 ;; If we can tell that the init file altered debug-on-error,
1276 ;; arrange to preserve the value that it set up.
1277 (or (eq debug-on-error debug-on-error-initial
)
1278 (setq debug-on-error-should-be-set t
1279 debug-on-error-from-init-file debug-on-error
)))
1280 (if debug-on-error-should-be-set
1281 (setq debug-on-error debug-on-error-from-init-file
))
1282 (unless (or (default-value 'enable-multibyte-characters
)
1283 (eq orig-enable-multibyte
(default-value
1284 'enable-multibyte-characters
)))
1285 ;; Init file changed to unibyte. Reset existing multibyte
1286 ;; buffers (probably *scratch*, *Messages*, *Minibuf-0*).
1287 ;; Arguably this should only be done if they're free of
1288 ;; multibyte characters.
1289 (mapc (lambda (buffer)
1290 (with-current-buffer buffer
1291 (if enable-multibyte-characters
1292 (set-buffer-multibyte nil
))))
1294 ;; Also re-set the language environment in case it was
1295 ;; originally done before unibyte was set and is sensitive to
1296 ;; unibyte (display table, terminal coding system &c).
1297 (set-language-environment current-language-environment
)))
1299 ;; Do this here in case the init file sets mail-host-address.
1300 (if (equal user-mail-address
"")
1301 (setq user-mail-address
(or (getenv "EMAIL")
1302 (concat (user-login-name) "@"
1303 (or mail-host-address
1306 ;; If parameter have been changed in the init file which influence
1307 ;; face realization, clear the face cache so that new faces will
1309 (unless (and (eq scalable-fonts-allowed old-scalable-fonts-allowed
)
1310 (eq face-ignored-fonts old-face-ignored-fonts
))
1311 (clear-face-cache)))
1313 ;; If any package directory exists, initialize the package system.
1315 package-enable-at-startup
1316 (catch 'package-dir-found
1318 (if (boundp 'package-directory-list
)
1319 (setq dirs package-directory-list
)
1320 (dolist (f load-path
)
1322 (equal (file-name-nondirectory f
) "site-lisp")
1323 (push (expand-file-name "elpa" f
) dirs
))))
1324 (push (if (boundp 'package-user-dir
)
1326 (locate-user-emacs-file "elpa"))
1329 (when (file-directory-p dir
)
1330 (dolist (subdir (directory-files dir
))
1331 (when (let ((subdir (expand-file-name subdir dir
)))
1332 (and (file-directory-p subdir
)
1335 (package--description-file subdir
)
1337 (throw 'package-dir-found t
)))))))
1338 (package-initialize))
1340 (setq after-init-time
(current-time))
1341 ;; Display any accumulated warnings after all functions in
1342 ;; `after-init-hook' like `desktop-read' have finalized possible
1343 ;; changes in the window configuration.
1344 (run-hooks 'after-init-hook
'delayed-warnings-hook
)
1346 ;; If *scratch* exists and init file didn't change its mode, initialize it.
1347 (if (get-buffer "*scratch*")
1348 (with-current-buffer "*scratch*"
1349 (if (eq major-mode
'fundamental-mode
)
1350 (funcall initial-major-mode
))))
1352 ;; Load library for our terminal type.
1353 ;; User init file can set term-file-prefix to nil to prevent this.
1354 (unless (or noninteractive
1355 initial-window-system
1357 (tty-run-terminal-initialization (selected-frame) nil t
))
1359 ;; Update the out-of-memory error message based on user's key bindings
1360 ;; for save-some-buffers.
1361 (setq memory-signal-data
1363 (substitute-command-keys "Memory exhausted--use \\[save-some-buffers] then exit and restart Emacs")))
1365 ;; Process the remaining args.
1366 (command-line-1 (cdr command-line-args
))
1368 ;; This is a problem because, e.g. if emacs.d/gnus.el exists,
1369 ;; trying to load gnus could load the wrong file.
1370 ;; OK, it would not matter if .emacs.d were at the end of load-path.
1371 ;; but for the sake of simplicity, we discourage it full-stop.
1372 ;; Ref eg http://lists.gnu.org/archive/html/emacs-devel/2012-03/msg00056.html
1374 ;; A bad element could come from user-emacs-file, the command line,
1375 ;; or EMACSLOADPATH, so we basically always have to check.
1377 (dolist (dir load-path
)
1380 (string-equal (file-name-as-directory (expand-file-name dir
))
1381 (expand-file-name user-emacs-directory
))
1383 (display-warning 'initialization
1385 Your `load-path' seems to contain\n\
1386 your `.emacs.d' directory: %s\n\
1387 This is likely to cause problems...\n\
1388 Consider using a subdirectory instead, e.g.: %s"
1389 dir
(expand-file-name
1390 "lisp" user-emacs-directory
))
1393 ;; If -batch, terminate after processing the command options.
1394 (if noninteractive
(kill-emacs t
))
1396 ;; In daemon mode, start the server to allow clients to connect.
1397 ;; This is done after loading the user's init file and after
1398 ;; processing all command line arguments to allow e.g. `server-name'
1399 ;; to be changed before the server starts.
1400 (let ((dn (daemonp)))
1402 (when (stringp dn
) (setq server-name dn
))
1405 (daemon-initialized)
1408 "Unable to start daemon: Emacs server named %S already running"
1410 (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."))
1413 ;; Run emacs-session-restore (session management) if started by
1414 ;; the session manager and we have a session manager connection.
1415 (if (and (boundp 'x-session-previous-id
)
1416 (stringp x-session-previous-id
))
1418 (emacs-session-restore x-session-previous-id
))))
1420 (defun x-apply-session-resources ()
1421 "Apply X resources which specify initial values for Emacs variables.
1422 This is called from a window-system initialization function, such
1423 as `x-initialize-window-system' for X, either at startup (prior
1424 to reading the init file), or afterwards when the user first
1425 opens a graphical frame.
1427 This can set the values of `menu-bar-mode', `tool-bar-mode', and
1428 `no-blinking-cursor', as well as the `cursor' face. Changed
1429 settings will be marked as \"CHANGED outside of Customize\"."
1430 (let ((no-vals '("no" "off" "false" "0"))
1431 (settings '(("menuBar" "MenuBar" menu-bar-mode nil
)
1432 ("toolBar" "ToolBar" tool-bar-mode nil
)
1433 ("cursorBlink" "CursorBlink" no-blinking-cursor t
))))
1434 (dolist (x settings
)
1435 (if (member (x-get-resource (nth 0 x
) (nth 1 x
)) no-vals
)
1436 (set (nth 2 x
) (nth 3 x
)))))
1437 (let ((color (x-get-resource "cursorColor" "Foreground")))
1439 (put 'cursor
'theme-face
1440 `((changed ((t :background
,color
)))))
1441 (put 'cursor
'face-modified t
))))
1443 (defcustom initial-scratch-message
(purecopy "\
1444 ;; This buffer is for text that is not saved, and for Lisp evaluation.
1445 ;; To create a file, visit it with \\[find-file] and enter text in its buffer.
1448 "Initial documentation displayed in *scratch* buffer at startup.
1449 If this is nil, no message will be displayed."
1450 :type
'(choice (text :tag
"Message")
1451 (const :tag
"none" nil
))
1452 :group
'initialization
)
1455 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1456 ;;; Fancy splash screen
1457 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1459 (defconst fancy-startup-text
1460 `((:face
(variable-pitch font-lock-comment-face
)
1463 ,(lambda (_button) (browse-url "http://www.gnu.org/software/emacs/"))
1464 "Browse http://www.gnu.org/software/emacs/")
1465 ", one component of the "
1468 (if (eq system-type
'gnu
/linux
)
1470 ,(lambda (_button) (browse-url "http://www.gnu.org/gnu/linux-and-gnu.html"))
1471 "Browse http://www.gnu.org/gnu/linux-and-gnu.html")
1472 `("GNU" ,(lambda (_button)
1473 (browse-url "http://www.gnu.org/gnu/thegnuproject.html"))
1474 "Browse http://www.gnu.org/gnu/thegnuproject.html")))
1475 " operating system.\n\n"
1476 :face variable-pitch
1477 :link
("Emacs Tutorial" ,(lambda (_button) (help-with-tutorial)))
1478 "\tLearn basic keystroke commands"
1480 (let* ((en "TUTORIAL")
1481 (tut (or (get-language-info current-language-environment
1484 (title (with-temp-buffer
1485 (insert-file-contents
1486 (expand-file-name tut tutorial-directory
)
1487 ;; We used to read only the first 256 bytes of
1488 ;; the tutorial, but that prevents the coding:
1489 ;; setting, if any, in file-local variables
1490 ;; section to be seen by insert-file-contents,
1491 ;; and results in gibberish when the language
1492 ;; environment's preferred encoding is
1493 ;; different from what the file-local variable
1494 ;; says. One case in point is Hebrew.
1496 (search-forward ".")
1497 (buffer-substring (point-min) (1- (point))))))
1498 ;; If there is a specific tutorial for the current language
1499 ;; environment and it is not English, append its title.
1500 (if (string= en tut
)
1502 (concat " (" title
")"))))
1504 :link
("Emacs Guided Tour"
1506 (browse-url "http://www.gnu.org/software/emacs/tour/"))
1507 "Browse http://www.gnu.org/software/emacs/tour/")
1508 "\tOverview of Emacs features at gnu.org\n"
1509 :link
("View Emacs Manual" ,(lambda (_button) (info-emacs-manual)))
1510 "\tView the Emacs manual using Info\n"
1511 :link
("Absence of Warranty" ,(lambda (_button) (describe-no-warranty)))
1512 "\tGNU Emacs comes with "
1513 :face
(variable-pitch (:slant oblique
))
1514 "ABSOLUTELY NO WARRANTY\n"
1515 :face variable-pitch
1516 :link
("Copying Conditions" ,(lambda (_button) (describe-copying)))
1517 "\tConditions for redistributing and changing Emacs\n"
1518 :link
("Ordering Manuals" ,(lambda (_button) (view-order-manuals)))
1519 "\tPurchasing printed copies of manuals\n"
1521 "A list of texts to show in the middle part of splash screens.
1522 Each element in the list should be a list of strings or pairs
1523 `:face FACE', like `fancy-splash-insert' accepts them.")
1525 (defconst fancy-about-text
1526 `((:face
(variable-pitch font-lock-comment-face
)
1529 ,(lambda (_button) (browse-url "http://www.gnu.org/software/emacs/"))
1530 "Browse http://www.gnu.org/software/emacs/")
1531 ", one component of the "
1534 (if (eq system-type
'gnu
/linux
)
1537 (browse-url "http://www.gnu.org/gnu/linux-and-gnu.html"))
1538 "Browse http://www.gnu.org/gnu/linux-and-gnu.html")
1539 `("GNU" ,(lambda (_button) (describe-gnu-project))
1540 "Display info on the GNU project.")))
1541 " operating system.\n"
1542 :face
(variable-pitch font-lock-builtin-face
)
1544 ,(lambda () (emacs-version))
1546 :face
(variable-pitch (:height
0.8))
1547 ,(lambda () emacs-copyright
)
1549 :face variable-pitch
1552 (view-file (expand-file-name "AUTHORS" data-directory
))
1553 (goto-char (point-min))))
1554 "\tMany people have contributed code included in GNU Emacs\n"
1555 :link
("Contributing"
1556 ,(lambda (_button) (info "(emacs)Contributing")))
1557 "\tHow to contribute improvements to Emacs\n"
1559 :link
("GNU and Freedom" ,(lambda (_button) (describe-gnu-project)))
1560 "\tWhy we developed GNU Emacs, and the GNU operating system\n"
1561 :link
("Absence of Warranty" ,(lambda (_button) (describe-no-warranty)))
1562 "\tGNU Emacs comes with "
1563 :face
(variable-pitch (:slant oblique
))
1564 "ABSOLUTELY NO WARRANTY\n"
1565 :face variable-pitch
1566 :link
("Copying Conditions" ,(lambda (_button) (describe-copying)))
1567 "\tConditions for redistributing and changing Emacs\n"
1568 :link
("Getting New Versions" ,(lambda (_button) (describe-distribution)))
1569 "\tHow to obtain the latest version of Emacs\n"
1570 :link
("Ordering Manuals" ,(lambda (_button) (view-order-manuals)))
1571 "\tBuying printed manuals from the FSF\n"
1573 :link
("Emacs Tutorial" ,(lambda (_button) (help-with-tutorial)))
1574 "\tLearn basic Emacs keystroke commands"
1576 (let* ((en "TUTORIAL")
1577 (tut (or (get-language-info current-language-environment
1580 (title (with-temp-buffer
1581 (insert-file-contents
1582 (expand-file-name tut tutorial-directory
)
1583 ;; Read the entire file, to make sure any
1584 ;; coding cookies and other local variables
1587 (search-forward ".")
1588 (buffer-substring (point-min) (1- (point))))))
1589 ;; If there is a specific tutorial for the current language
1590 ;; environment and it is not English, append its title.
1591 (if (string= en tut
)
1593 (concat " (" title
")"))))
1595 :link
("Emacs Guided Tour"
1597 (browse-url "http://www.gnu.org/software/emacs/tour/"))
1598 "Browse http://www.gnu.org/software/emacs/tour/")
1599 "\tSee an overview of Emacs features at gnu.org"))
1600 "A list of texts to show in the middle part of the About screen.
1601 Each element in the list should be a list of strings or pairs
1602 `:face FACE', like `fancy-splash-insert' accepts them.")
1605 (defgroup fancy-splash-screen
()
1606 "Fancy splash screen when Emacs starts."
1608 :group
'initialization
)
1610 (defcustom fancy-splash-image nil
1611 "The image to show in the splash screens, or nil for defaults."
1612 :group
'fancy-splash-screen
1613 :type
'(choice (const :tag
"Default" nil
)
1614 (file :tag
"File")))
1617 (defvar splash-screen-keymap
1618 (let ((map (make-sparse-keymap)))
1619 (suppress-keymap map
)
1620 (set-keymap-parent map button-buffer-map
)
1621 (define-key map
"\C-?" 'scroll-down-command
)
1622 (define-key map
[?\S-\
] 'scroll-down-command
)
1623 (define-key map
" " 'scroll-up-command
)
1624 (define-key map
"q" 'exit-splash-screen
)
1626 "Keymap for splash screen buffer.")
1628 ;; These are temporary storage areas for the splash screen display.
1630 (defun fancy-splash-insert (&rest args
)
1631 "Insert text into the current buffer, with faces.
1632 Arguments from ARGS should be either strings; functions called
1633 with no args that return a string; pairs `:face FACE', where FACE
1634 is a face specification usable with `put-text-property'; or pairs
1635 `:link LINK' where LINK is a list of arguments to pass to
1636 `insert-button', of the form (LABEL ACTION [HELP-ECHO]), which
1637 specifies the button's label, `action' property and help-echo string.
1638 FACE and LINK can also be functions, which are evaluated to obtain
1639 a face or button specification."
1640 (let ((current-face nil
))
1642 (cond ((eq (car args
) :face
)
1643 (setq args
(cdr args
) current-face
(car args
))
1644 (if (functionp current-face
)
1645 (setq current-face
(funcall current-face
))))
1646 ((eq (car args
) :link
)
1647 (setq args
(cdr args
))
1648 (let ((spec (car args
)))
1649 (if (functionp spec
)
1650 (setq spec
(funcall spec
)))
1651 (insert-button (car spec
)
1652 'face
(list 'link current-face
)
1654 'help-echo
(concat "mouse-2, RET: "
1656 "Follow this link"))
1658 (t (insert (propertize (let ((it (car args
)))
1663 'help-echo
(startup-echo-area-message)))))
1664 (setq args
(cdr args
)))))
1666 (declare-function image-size
"image.c" (spec &optional pixels frame
))
1668 (defun fancy-splash-image-file ()
1669 (cond ((stringp fancy-splash-image
) fancy-splash-image
)
1671 (cond ((<= (display-planes) 8)
1672 (if (image-type-available-p 'xpm
)
1675 ((or (image-type-available-p 'svg
)
1676 (image-type-available-p 'imagemagick
))
1678 ((image-type-available-p 'png
)
1680 ((image-type-available-p 'xpm
)
1685 (defun fancy-splash-head ()
1686 "Insert the head part of the splash screen into the current buffer."
1687 (let* ((image-file (fancy-splash-image-file))
1688 (img (create-image image-file
))
1689 (image-width (and img
(car (image-size img
))))
1690 (window-width (window-width)))
1692 (when (> window-width image-width
)
1693 ;; Center the image in the window.
1694 (insert (propertize " " 'display
1695 `(space :align-to
(+ center
(-0.5 .
,img
)))))
1697 ;; Change the color of the XPM version of the splash image
1698 ;; so that it is visible with a dark frame background.
1699 (when (and (memq 'xpm img
)
1700 (eq (frame-parameter nil
'background-mode
) 'dark
))
1701 (setq img
(append img
'(:color-symbols
(("#000000" .
"gray30"))))))
1703 ;; Insert the image with a help-echo and a link.
1704 (make-button (prog1 (point) (insert-image img
)) (point)
1706 'help-echo
"mouse-2, RET: Browse http://www.gnu.org/"
1707 'action
(lambda (_button) (browse-url "http://www.gnu.org/"))
1711 (defun fancy-startup-tail (&optional concise
)
1712 "Insert the tail part of the splash screen into the current buffer."
1714 (fancy-splash-insert
1715 :face
'variable-pitch
1717 :link
`("Open a File"
1718 ,(lambda (_button) (call-interactively 'find-file
))
1719 "Specify a new file's name, to edit the file")
1721 :link
`("Open Home Directory"
1722 ,(lambda (_button) (dired "~"))
1723 "Open your home directory, to operate on its files")
1725 :link
`("Customize Startup"
1726 ,(lambda (_button) (customize-group 'initialization
))
1727 "Change initialization settings including this screen")
1729 (fancy-splash-insert
1730 :face
'variable-pitch
"To quit a partially entered command, type "
1731 :face
'default
"Control-g"
1732 :face
'variable-pitch
".\n")
1733 (fancy-splash-insert :face
`(variable-pitch font-lock-builtin-face
)
1737 :face
'(variable-pitch (:height
0.8))
1740 (when auto-save-list-file-prefix
1741 (let ((dir (file-name-directory auto-save-list-file-prefix
))
1742 (name (file-name-nondirectory auto-save-list-file-prefix
))
1744 ;; Don't warn if the directory for auto-save-list files does not
1746 (and (file-directory-p dir
)
1747 (setq files
(directory-files dir nil
(concat "\\`" name
) t
))
1748 (fancy-splash-insert :face
'(variable-pitch font-lock-comment-face
)
1749 (if (= (length files
) 1)
1750 "\nAn auto-save file list was found. "
1751 "\nAuto-save file lists were found. ")
1752 "If an Emacs session crashed recently,\ntype "
1753 :link
`("M-x recover-session RET"
1757 " to recover the files you were editing."))))
1760 (fancy-splash-insert
1761 :face
'variable-pitch
"\n"
1762 :link
`("Dismiss this startup screen"
1764 (when startup-screen-inhibit-startup-screen
1765 (customize-set-variable 'inhibit-startup-screen t
)
1766 (customize-mark-to-save 'inhibit-startup-screen
)
1768 (let ((w (get-buffer-window "*GNU Emacs*")))
1769 (and w
(not (one-window-p)) (delete-window w
)))
1770 (kill-buffer "*GNU Emacs*")))
1772 (when (or user-init-file custom-file
)
1773 (let ((checked (create-image "checked.xpm"
1774 nil nil
:ascent
'center
))
1775 (unchecked (create-image "unchecked.xpm"
1776 nil nil
:ascent
'center
)))
1780 :off-glyph unchecked
1781 'checked nil
'display unchecked
'follow-link t
1782 'action
(lambda (button)
1783 (if (overlay-get button
'checked
)
1784 (progn (overlay-put button
'checked nil
)
1785 (overlay-put button
'display
1786 (overlay-get button
:off-glyph
))
1787 (setq startup-screen-inhibit-startup-screen
1789 (overlay-put button
'checked t
)
1790 (overlay-put button
'display
1791 (overlay-get button
:on-glyph
))
1792 (setq startup-screen-inhibit-startup-screen t
)))))
1793 (fancy-splash-insert :face
'(variable-pitch (:height
0.9))
1794 " Never show it again."))))
1796 (defun exit-splash-screen ()
1797 "Stop displaying the splash screen buffer."
1801 (defun fancy-startup-screen (&optional concise
)
1802 "Display fancy startup screen.
1803 If CONCISE is non-nil, display a concise version of the
1804 splash screen in another window."
1805 (let ((splash-buffer (get-buffer-create "*GNU Emacs*")))
1806 (with-current-buffer splash-buffer
1807 (let ((inhibit-read-only t
))
1809 (setq default-directory command-line-default-directory
)
1810 (make-local-variable 'startup-screen-inhibit-startup-screen
)
1811 (if pure-space-overflow
1812 (insert pure-space-overflow-message
))
1814 (fancy-splash-head))
1815 (dolist (text fancy-startup-text
)
1816 (apply #'fancy-splash-insert text
)
1818 (skip-chars-backward "\n")
1819 (delete-region (point) (point-max))
1821 (fancy-startup-tail concise
))
1822 (use-local-map splash-screen-keymap
)
1823 (setq-local browse-url-browser-function
'eww-browse-url
)
1826 (set-buffer-modified-p nil
)
1827 (if (and view-read-only
(not view-mode
))
1828 (view-mode-enter nil
'kill-buffer
))
1829 (goto-char (point-min))
1830 (forward-line (if concise
2 4)))
1833 (display-buffer splash-buffer
)
1834 ;; If the splash screen is in a split window, fit it.
1835 (let ((window (get-buffer-window splash-buffer t
)))
1837 (eq window
(selected-window))
1838 (eq window
(next-window window
))
1839 (fit-window-to-buffer window
))))
1840 (switch-to-buffer splash-buffer
))))
1842 (defun fancy-about-screen ()
1843 "Display fancy About screen."
1844 (let ((frame (fancy-splash-frame)))
1845 (save-selected-window
1846 (select-frame frame
)
1847 (switch-to-buffer "*About GNU Emacs*")
1848 (setq buffer-undo-list t
)
1849 (let ((inhibit-read-only t
))
1851 (if pure-space-overflow
1852 (insert pure-space-overflow-message
))
1854 (dolist (text fancy-about-text
)
1855 (apply #'fancy-splash-insert text
)
1857 (set-buffer-modified-p nil
)
1858 (goto-char (point-min))
1859 (force-mode-line-update))
1860 (use-local-map splash-screen-keymap
)
1861 (setq-local browse-url-browser-function
'eww-browse-url
)
1863 (setq buffer-read-only t
)
1864 (goto-char (point-min))
1867 (defun fancy-splash-frame ()
1868 "Return the frame to use for the fancy splash screen.
1869 Returning non-nil does not mean we should necessarily
1870 use the fancy splash screen, but if we do use it,
1871 we put it on this frame."
1873 ;; MS-Windows needs this to have a chance to make the initial
1875 (if (eq (window-system) 'w32
)
1877 (dolist (frame (append (frame-list) (list (selected-frame))))
1878 (if (and (frame-visible-p frame
)
1879 (not (window-minibuffer-p (frame-selected-window frame
))))
1880 (setq chosen-frame frame
)))
1883 (defun use-fancy-splash-screens-p ()
1884 "Return t if fancy splash screens should be used."
1885 (when (and (display-graphic-p)
1886 (or (and (display-color-p)
1887 (image-type-available-p 'xpm
))
1888 (image-type-available-p 'pbm
)))
1889 (let ((frame (fancy-splash-frame)))
1891 (let* ((img (create-image (fancy-splash-image-file)))
1892 (image-height (and img
(cdr (image-size img nil frame
))))
1893 ;; We test frame-height and not window-height so that,
1894 ;; if the frame is split by displaying a warning, that
1895 ;; doesn't cause the normal splash screen to be used.
1896 ;; We subtract 2 from frame-height to account for the
1897 ;; echo area and the mode line.
1898 (frame-height (- (frame-height frame
) 2)))
1899 (> frame-height
(+ image-height
19)))))))
1902 (defun normal-splash-screen (&optional startup concise
)
1903 "Display non-graphic splash screen.
1904 If optional argument STARTUP is non-nil, display the startup screen
1905 after Emacs starts. If STARTUP is nil, display the About screen.
1906 If CONCISE is non-nil, display a concise version of the
1907 splash screen in another window."
1908 (let ((splash-buffer (get-buffer-create "*About GNU Emacs*")))
1909 (with-current-buffer splash-buffer
1910 (setq buffer-read-only nil
)
1912 (setq default-directory command-line-default-directory
)
1913 (set (make-local-variable 'tab-width
) 8)
1915 (if pure-space-overflow
1916 (insert pure-space-overflow-message
))
1918 ;; The convention for this piece of code is that
1919 ;; each piece of output starts with one or two newlines
1920 ;; and does not end with any newlines.
1921 (insert (if startup
"Welcome to GNU Emacs" "This is GNU Emacs"))
1923 (if (eq system-type
'gnu
/linux
)
1924 ", one component of the GNU/Linux operating system.\n"
1925 ", a part of the GNU operating system.\n"))
1928 (if (display-mouse-p)
1929 ;; The user can use the mouse to activate menus
1930 ;; so give help in terms of menu items.
1931 (normal-mouse-startup-screen)
1933 ;; No mouse menus, so give help using kbd commands.
1934 (normal-no-mouse-startup-screen))
1936 (normal-about-screen))
1938 ;; The rest of the startup screen is the same on all
1939 ;; kinds of terminals.
1941 ;; Give information on recovering, if there was a crash.
1943 auto-save-list-file-prefix
1944 ;; Don't signal an error if the
1945 ;; directory for auto-save-list files
1946 ;; does not yet exist.
1947 (file-directory-p (file-name-directory
1948 auto-save-list-file-prefix
))
1950 (file-name-directory auto-save-list-file-prefix
)
1953 (regexp-quote (file-name-nondirectory
1954 auto-save-list-file-prefix
)))
1956 (insert "\n\nIf an Emacs session crashed recently, "
1957 "type M-x recover-session RET\nto recover"
1958 " the files you were editing.\n"))
1960 (use-local-map splash-screen-keymap
)
1962 ;; Display the input that we set up in the buffer.
1963 (set-buffer-modified-p nil
)
1964 (setq buffer-read-only t
)
1965 (if (and view-read-only
(not view-mode
))
1966 (view-mode-enter nil
'kill-buffer
))
1967 (if startup
(rename-buffer "*GNU Emacs*" t
))
1968 (goto-char (point-min)))
1970 (display-buffer splash-buffer
)
1971 (switch-to-buffer splash-buffer
))))
1973 (defun normal-mouse-startup-screen ()
1974 ;; The user can use the mouse to activate menus
1975 ;; so give help in terms of menu items.
1977 To follow a link, click Mouse-1 on it, or move to it and type RET.
1978 To quit a partially entered command, type Control-g.\n")
1980 (insert "\nImportant Help menu items:\n")
1981 (insert-button "Emacs Tutorial"
1982 'action
(lambda (_button) (help-with-tutorial))
1984 (insert "\t\tLearn basic Emacs keystroke commands\n")
1985 (insert-button "Read the Emacs Manual"
1986 'action
(lambda (_button) (info-emacs-manual))
1988 (insert "\tView the Emacs manual using Info\n")
1989 (insert-button "(Non)Warranty"
1990 'action
(lambda (_button) (describe-no-warranty))
1992 (insert "\t\tGNU Emacs comes with ABSOLUTELY NO WARRANTY\n")
1993 (insert-button "Copying Conditions"
1994 'action
(lambda (_button) (describe-copying))
1996 (insert "\tConditions for redistributing and changing Emacs\n")
1997 (insert-button "More Manuals / Ordering Manuals"
1998 'action
(lambda (_button) (view-order-manuals))
2000 (insert " How to order printed manuals from the FSF\n")
2002 (insert "\nUseful tasks:\n")
2003 (insert-button "Visit New File"
2004 'action
(lambda (_button) (call-interactively 'find-file
))
2006 (insert (substitute-command-keys
2007 "\t\tSpecify a new file's name, to edit the file\n"))
2008 (insert-button "Open Home Directory"
2009 'action
(lambda (_button) (dired "~"))
2011 (insert "\tOpen your home directory, to operate on its files\n")
2012 (insert-button "Customize Startup"
2013 'action
(lambda (_button) (customize-group 'initialization
))
2015 (insert "\tChange initialization settings including this screen\n")
2017 (insert "\n" (emacs-version)
2018 "\n" emacs-copyright
))
2020 (defun normal-no-mouse-startup-screen ()
2021 "Show a splash screen suitable for displays without mouse support."
2022 (let* ((c-h-accessible
2023 ;; If normal-erase-is-backspace is used on a tty, there's
2024 ;; no way to invoke C-h and you have to use F1 instead.
2025 (or (not (char-table-p keyboard-translate-table
))
2026 (eq (aref keyboard-translate-table ?\C-h
) ?\C-h
)))
2027 (minor-mode-overriding-map-alist
2028 (cons (cons (not c-h-accessible
)
2029 ;; If C-h can't be invoked, temporarily disable its
2030 ;; binding, so where-is uses alternative bindings.
2031 (let ((map (make-sparse-keymap)))
2032 (define-key map
[?\C-h
] 'undefined
)
2034 minor-mode-overriding-map-alist
)))
2036 (insert (format "\nGet help\t %s\n"
2037 (let ((where (where-is-internal 'help-command nil t
)))
2039 ((equal where
[?\C-h
])
2040 "C-h (Hold down CTRL and press h)")
2041 (where (key-description where
))
2043 (insert-button "Emacs manual"
2044 'action
(lambda (_button) (info-emacs-manual))
2046 (insert (substitute-command-keys"\t \\[info-emacs-manual]\t"))
2047 (insert-button "Browse manuals"
2048 'action
(lambda (_button) (Info-directory))
2050 (insert (substitute-command-keys "\t \\[info]\n"))
2051 (insert-button "Emacs tutorial"
2052 'action
(lambda (_button) (help-with-tutorial))
2054 (insert (substitute-command-keys
2055 "\t \\[help-with-tutorial]\tUndo changes\t \\[undo]\n"))
2056 (insert-button "Buy manuals"
2057 'action
(lambda (_button) (view-order-manuals))
2059 (insert (substitute-command-keys
2060 "\t \\[view-order-manuals]\tExit Emacs\t \\[save-buffers-kill-terminal]")))
2062 ;; Say how to use the menu bar with the keyboard.
2064 (insert-button "Activate menubar"
2065 'action
(lambda (_button) (tmm-menubar))
2067 (if (and (eq (key-binding "\M-`") 'tmm-menubar
)
2068 (eq (key-binding [f10]) 'tmm-menubar))
2069 (insert " F10 or ESC ` or M-`")
2070 (insert (substitute-command-keys " \\[tmm-menubar]")))
2072 ;; Many users seem to have problems with these.
2073 (insert (substitute-command-keys "
2074 \(`C-' means use the CTRL key. `M-' means use the Meta (or Alt) key.
2075 If you have no Meta key, you may instead type ESC followed by the character.)"))
2077 ;; Insert links to useful tasks
2078 (insert "\nUseful tasks:\n")
2080 (insert-button "Visit New File"
2081 'action (lambda (_button) (call-interactively 'find-file))
2084 (insert-button "Open Home Directory"
2085 'action (lambda (_button) (dired "~"))
2089 (insert-button "Customize Startup"
2090 'action (lambda (_button) (customize-group 'initialization))
2093 (insert-button "Open *scratch* buffer"
2094 'action (lambda (_button) (switch-to-buffer
2095 (get-buffer-create "*scratch*")))
2098 (insert "\n" (emacs-version) "\n" emacs-copyright "\n")
2099 (insert (substitute-command-keys
2101 GNU Emacs comes with ABSOLUTELY NO WARRANTY; type \\[describe-no-warranty] for "))
2102 (insert-button "full details"
2103 'action (lambda (_button) (describe-no-warranty))
2105 (insert (substitute-command-keys ".
2106 Emacs is Free Software--Free as in Freedom--so you can redistribute copies
2107 of Emacs and modify it; type \\[describe-copying] to see "))
2108 (insert-button "the conditions"
2109 'action (lambda (_button) (describe-copying))
2111 (insert (substitute-command-keys".
2112 Type \\[describe-distribution] for information on "))
2113 (insert-button "getting the latest version"
2114 'action (lambda (_button) (describe-distribution))
2118 (defun normal-about-screen ()
2119 (insert "\n" (emacs-version) "\n" emacs-copyright "\n\n")
2121 (insert "To follow a link, click Mouse-1 on it, or move to it and type RET.\n\n")
2123 (insert-button "Authors"
2126 (view-file (expand-file-name "AUTHORS" data-directory))
2127 (goto-char (point-min)))
2129 (insert "\t\tMany people have contributed code included in GNU Emacs\n")
2131 (insert-button "Contributing"
2133 (lambda (_button) (info "(emacs)Contributing"))
2135 (insert "\tHow to contribute improvements to Emacs\n\n")
2137 (insert-button "GNU and Freedom"
2138 'action (lambda (_button) (describe-gnu-project))
2140 (insert "\t\tWhy we developed GNU Emacs and the GNU system\n")
2142 (insert-button "Absence of Warranty"
2143 'action (lambda (_button) (describe-no-warranty))
2145 (insert "\tGNU Emacs comes with ABSOLUTELY NO WARRANTY\n")
2147 (insert-button "Copying Conditions"
2148 'action (lambda (_button) (describe-copying))
2150 (insert "\tConditions for redistributing and changing Emacs\n")
2152 (insert-button "Getting New Versions"
2153 'action (lambda (_button) (describe-distribution))
2155 (insert "\tHow to get the latest version of GNU Emacs\n")
2157 (insert-button "More Manuals / Ordering Manuals"
2158 'action (lambda (_button) (view-order-manuals))
2160 (insert "\tBuying printed manuals from the FSF\n"))
2162 (defun startup-echo-area-message ()
2164 "Starting Emacs daemon."
2165 (substitute-command-keys
2166 "For information about GNU Emacs and the GNU system, type \
2167 \\[about-emacs].")))
2169 (defun display-startup-echo-area-message ()
2170 (let ((resize-mini-windows t))
2171 (or noninteractive ;(input-pending-p) init-file-had-error
2172 ;; t if the init file says to inhibit the echo area startup message.
2173 (and inhibit-startup-echo-area-message
2175 (or (and (get 'inhibit-startup-echo-area-message 'saved-value)
2176 (equal inhibit-startup-echo-area-message
2177 (if (equal init-file-user "")
2180 ;; Wasn't set with custom; see if .emacs has a setq.
2183 (insert-file-contents user-init-file)
2186 "([ \t\n]*setq[ \t\n]+"
2187 "inhibit-startup-echo-area-message[ \t\n]+"
2190 (if (equal init-file-user "")
2196 (message "%s" (startup-echo-area-message)))))
2198 (defun display-startup-screen (&optional concise)
2199 "Display startup screen according to display.
2200 A fancy display is used on graphic displays, normal otherwise.
2202 If CONCISE is non-nil, display a concise version of the startup
2204 ;; Prevent recursive calls from server-process-filter.
2205 (if (not (get-buffer "*GNU Emacs*"))
2206 (if (use-fancy-splash-screens-p)
2207 (fancy-startup-screen concise)
2208 (normal-splash-screen t concise))))
2210 (defun display-about-screen ()
2211 "Display the *About GNU Emacs* buffer.
2212 A fancy display is used on graphic displays, normal otherwise."
2214 (if (use-fancy-splash-screens-p)
2215 (fancy-about-screen)
2216 (normal-splash-screen nil)))
2218 (defalias 'about-emacs 'display-about-screen)
2219 (defalias 'display-splash-screen 'display-startup-screen)
2221 (defun command-line-1 (args-left)
2222 "A subroutine of `command-line'."
2223 (display-startup-echo-area-message)
2224 (when (and pure-space-overflow
2225 (not noninteractive))
2228 "Building Emacs overflowed pure space.\
2229 (See the node Pure Storage in the Lisp manual for details.)"
2232 ;; `displayable-buffers' is a list of buffers that may be displayed,
2233 ;; which includes files parsed from the command line arguments and
2234 ;; `initial-buffer-choice'. All of the display logic happens at the
2235 ;; end of this `let'. As files as processed from the command line
2236 ;; arguments, their buffers are prepended to `displayable-buffers'.
2237 ;; In order for options like "--eval" to work with the "--file" arg,
2238 ;; the file buffers are set as the current buffer as they are seen
2239 ;; on the command line (so "emacs --batch --file a --file b
2240 ;; --eval='(message "%s" (buffer-name))'" will print "b"), but this
2241 ;; does not affect the final displayed state of the buffers.
2242 (let ((displayable-buffers nil))
2243 ;; This `let' processes the command line arguments.
2244 (let ((command-line-args-left args-left))
2245 (when command-line-args-left
2246 ;; We have command args; process them.
2247 (let* ((dir command-line-default-directory)
2249 ;; This approach loses for "-batch -L DIR --eval "(require foo)",
2250 ;; if foo is intended to be found in DIR.
2252 ;; The directories listed in --directory/-L options will *appear*
2253 ;; at the front of `load-path' in the order they appear on the
2254 ;; command-line. We cannot do this by *placing* them at the front
2255 ;; in the order they appear, so we need this variable to hold them,
2258 ;; To DTRT we keep track of the splice point and modify `load-path'
2259 ;; straight away upon any --directory/-L option.
2261 just-files ;; t if this follows the magic -- option.
2262 ;; This includes our standard options' long versions
2263 ;; and long versions of what's on command-switch-alist.
2265 (append '("--funcall" "--load" "--insert" "--kill"
2266 "--directory" "--eval" "--execute" "--no-splash"
2267 "--find-file" "--visit" "--file" "--no-desktop")
2268 (mapcar (lambda (elt) (concat "-" (car elt)))
2269 command-switch-alist)))
2272 ;; `process-file-arg' opens a file buffer for `name',
2273 ;; sets that buffer as the current buffer without
2274 ;; displaying it, adds the buffer to
2275 ;; `displayable-buffers', and puts the point at
2276 ;; `line':`column'. `line' and `column' are both reset
2277 ;; to zero when `process-file-arg' returns.
2280 ;; This can only happen if PWD is deleted.
2281 (if (not (or dir (file-name-absolute-p name)))
2282 (message "Ignoring relative file name (%s) due to \
2283 nil default-directory" name)
2284 (let* ((file (expand-file-name
2285 (command-line-normalize-file-name name)
2287 (buf (find-file-noselect file)))
2288 (setq displayable-buffers (cons buf displayable-buffers))
2289 ;; Set the file buffer to the current buffer so
2290 ;; that it will be used with "--eval" and
2293 ;; Put the point at `line':`column' in the file
2294 ;; buffer, and reset `line' and `column' to 0.
2295 (unless (zerop line)
2296 (goto-char (point-min))
2297 (forward-line (1- line)))
2299 (unless (< column 1)
2300 (move-to-column (1- column)))
2301 (setq column 0))))))
2303 ;; Add the long X options to longopts.
2304 (dolist (tem command-line-x-option-alist)
2305 (if (string-match "^--" (car tem))
2306 (push (car tem) longopts)))
2308 ;; Add the long NS options to longopts.
2309 (dolist (tem command-line-ns-option-alist)
2310 (if (string-match "^--" (car tem))
2311 (push (list (car tem)) longopts)))
2313 ;; Loop, processing options.
2314 (while command-line-args-left
2315 (let* ((argi (car command-line-args-left))
2318 (setq command-line-args-left (cdr command-line-args-left))
2320 ;; Do preliminary decoding of the option.
2322 ;; After --, don't look for options; treat all args as files.
2324 ;; Convert long options to ordinary options
2325 ;; and separate out an attached option argument into argval.
2326 (when (string-match "\\`\\(--[^=]*\\)=" argi)
2327 (setq argval (substring argi (match-end 0))
2328 argi (match-string 1 argi)))
2329 (when (string-match "\\`--?[^-]" orig-argi)
2330 (setq completion (try-completion argi longopts))
2331 (if (eq completion t)
2332 (setq argi (substring argi 1))
2333 (if (stringp completion)
2334 (let ((elt (member completion longopts)))
2336 (error "Option `%s' is ambiguous" argi))
2337 (setq argi (substring (car elt) 1)))
2341 ;; Execute the option.
2342 (cond ((setq tem (assoc argi command-switch-alist))
2344 (let ((command-line-args-left
2345 (cons argval command-line-args-left)))
2346 (funcall (cdr tem) argi))
2347 (funcall (cdr tem) argi)))
2349 ((equal argi "-no-splash")
2350 (setq inhibit-startup-screen t))
2352 ((member argi '("-f" ; what the manual claims
2354 "-e")) ; what the source used to say
2355 (setq inhibit-startup-screen t)
2356 (setq tem (intern (or argval (pop command-line-args-left))))
2358 (command-execute tem)
2361 ((member argi '("-eval" "-execute"))
2362 (setq inhibit-startup-screen t)
2363 (eval (read (or argval (pop command-line-args-left)))))
2365 ((member argi '("-L" "-directory"))
2366 ;; -L :/foo adds /foo to the _end_ of load-path.
2369 (format "\\`%s" path-separator)
2370 (setq tem (or argval (pop command-line-args-left))))
2371 (setq tem (substring tem 1)
2373 (setq tem (expand-file-name
2374 (command-line-normalize-file-name tem)))
2375 (cond (append (setq load-path
2376 (append load-path (list tem)))
2377 (if splice (setq splice load-path)))
2378 (splice (setcdr splice (cons tem (cdr splice)))
2379 (setq splice (cdr splice)))
2380 (t (setq load-path (cons tem load-path)
2381 splice load-path)))))
2383 ((member argi '("-l" "-load"))
2384 (let* ((file (command-line-normalize-file-name
2385 (or argval (pop command-line-args-left))))
2386 ;; Take file from default dir if it exists there;
2387 ;; otherwise let `load' search for it.
2388 (file-ex (expand-file-name file)))
2389 (when (file-exists-p file-ex)
2390 (setq file file-ex))
2393 ;; This is used to handle -script. It's not clear
2394 ;; we need to document it (it is totally internal).
2395 ((member argi '("-scriptload"))
2396 (let* ((file (command-line-normalize-file-name
2397 (or argval (pop command-line-args-left))))
2398 ;; Take file from default dir.
2399 (file-ex (expand-file-name file)))
2400 (load file-ex nil t t)))
2402 ((equal argi "-insert")
2403 (setq inhibit-startup-screen t)
2404 (setq tem (or argval (pop command-line-args-left)))
2406 (error "File name omitted from `-insert' option"))
2407 (insert-file-contents (command-line-normalize-file-name tem)))
2409 ((equal argi "-kill")
2412 ;; This is for when they use --no-desktop with -q, or
2413 ;; don't load Desktop in their .emacs. If desktop.el
2414 ;; _is_ loaded, it will handle this switch, and we
2415 ;; won't see it by the time we get here.
2416 ((equal argi "-no-desktop")
2417 (message "\"--no-desktop\" ignored because the Desktop package is not loaded"))
2419 ((string-match "^\\+[0-9]+\\'" argi)
2420 (setq line (string-to-number argi)))
2422 ((string-match "^\\+\\([0-9]+\\):\\([0-9]+\\)\\'" argi)
2423 (setq line (string-to-number (match-string 1 argi))
2424 column (string-to-number (match-string 2 argi))))
2426 ((setq tem (assoc orig-argi command-line-x-option-alist))
2427 ;; Ignore X-windows options and their args if not using X.
2428 (setq command-line-args-left
2429 (nthcdr (nth 1 tem) command-line-args-left)))
2431 ((setq tem (assoc orig-argi command-line-ns-option-alist))
2432 ;; Ignore NS-windows options and their args if not using NS.
2433 (setq command-line-args-left
2434 (nthcdr (nth 1 tem) command-line-args-left)))
2436 ((member argi '("-find-file" "-file" "-visit"))
2437 (setq inhibit-startup-screen t)
2438 ;; An explicit option to specify visiting a file.
2439 (setq tem (or argval (pop command-line-args-left)))
2440 (unless (stringp tem)
2441 (error "File name omitted from `%s' option" argi))
2442 (funcall process-file-arg tem))
2444 ;; These command lines now have no effect.
2445 ((string-match "\\`--?\\(no-\\)?\\(uni\\|multi\\)byte$" argi)
2446 (display-warning 'initialization
2447 (format "Ignoring obsolete arg %s" argi)))
2450 (setq just-files t))
2452 ;; We have almost exhausted our options. See if the
2453 ;; user has made any other command-line options available
2454 (let ((hooks command-line-functions)
2457 (not (setq did-hook (funcall (car hooks)))))
2458 (setq hooks (cdr hooks)))
2460 ;; Presume that the argument is a file name.
2461 (if (string-match "\\`-" argi)
2462 (error "Unknown option `%s'" argi))
2463 ;; FIXME: Why do we only inhibit the startup
2465 (unless initial-window-system
2466 (setq inhibit-startup-screen t))
2467 (funcall process-file-arg orig-argi)))))
2469 ;; In unusual circumstances, the execution of Lisp code due
2470 ;; to command-line options can cause the last visible frame
2471 ;; to be deleted. In this case, kill emacs to avoid an
2473 (unless (frame-live-p (selected-frame)) (kill-emacs nil)))))))
2475 (when (eq initial-buffer-choice t)
2476 ;; When `initial-buffer-choice' equals t make sure that *scratch*
2478 (get-buffer-create "*scratch*"))
2480 ;; If *scratch* exists and is empty, insert initial-scratch-message.
2481 ;; Do this before switching to *scratch* below to handle bug#9605.
2482 (and initial-scratch-message
2483 (get-buffer "*scratch*")
2484 (with-current-buffer "*scratch*"
2485 (when (zerop (buffer-size))
2486 (insert (substitute-command-keys initial-scratch-message))
2487 (set-buffer-modified-p nil))))
2489 ;; Prepend `initial-buffer-choice' to `displayable-buffers'.
2490 (when initial-buffer-choice
2492 (cond ((stringp initial-buffer-choice)
2493 (find-file-noselect initial-buffer-choice))
2494 ((functionp initial-buffer-choice)
2495 (funcall initial-buffer-choice))
2496 ((eq initial-buffer-choice t)
2497 (get-buffer-create "*scratch*"))
2499 (error "initial-buffer-choice must be a string, a function, or t.")))))
2500 (unless (buffer-live-p buf)
2501 (error "initial-buffer-choice is not a live buffer."))
2502 (setq displayable-buffers (cons buf displayable-buffers))))
2504 ;; Display the first two buffers in `displayable-buffers'. If
2505 ;; `initial-buffer-choice' is non-nil, its buffer will be the
2506 ;; first buffer in `displayable-buffers'. The first buffer will
2508 (let ((displayable-buffers-len (length displayable-buffers))
2509 ;; `nondisplayed-buffers-p' is true if there exist buffers
2510 ;; in `displayable-buffers' that were not displayed to the
2512 (nondisplayed-buffers-p nil))
2513 (when (> displayable-buffers-len 0)
2514 (switch-to-buffer (car displayable-buffers)))
2515 (when (> displayable-buffers-len 1)
2516 (switch-to-buffer-other-window (car (cdr displayable-buffers)))
2517 ;; Focus on the first buffer.
2519 (when (> displayable-buffers-len 2)
2520 (setq nondisplayed-buffers-p t))
2522 (if (or inhibit-startup-screen
2523 initial-buffer-choice
2526 inhibit-x-resources)
2528 ;; Not displaying a startup screen. Display *Buffer List* if
2529 ;; there exist buffers that were not displayed.
2530 (when (and nondisplayed-buffers-p
2531 (not noninteractive)
2532 (not inhibit-startup-buffer-menu))
2535 ;; Display a startup screen, after some preparations.
2537 ;; If there are no switches to process, we might as well
2538 ;; run this hook now, and there may be some need to do it
2539 ;; before doing any output.
2540 (run-hooks 'emacs-startup-hook 'term-setup-hook)
2542 ;; It's important to notice the user settings before we
2543 ;; display the startup message; otherwise, the settings
2544 ;; won't take effect until the user gives the first
2545 ;; keystroke, and that's distracting.
2546 (when (fboundp 'frame-notice-user-settings)
2547 (frame-notice-user-settings))
2549 ;; If there are no switches to process, we might as well
2550 ;; run this hook now, and there may be some need to do it
2551 ;; before doing any output.
2552 (run-hooks 'window-setup-hook)
2554 (setq inhibit-startup-hooks t)
2556 ;; ;; Do this now to avoid an annoying delay if the user
2557 ;; ;; clicks the menu bar during the sit-for.
2558 ;; (when (display-popup-menus-p)
2559 ;; (precompute-menubar-bindings))
2560 ;; (with-no-warnings
2561 ;; (setq menubar-bindings-done t))
2563 (display-startup-screen (> displayable-buffers-len 0))))))
2565 (defun command-line-normalize-file-name (file)
2566 "Collapse multiple slashes to one, to handle non-Emacs file names."
2568 ;; Use arg 1 so that we don't collapse // at the start of the file name.
2569 ;; That is significant on some systems.
2570 ;; However, /// at the beginning is supposed to mean just /, not //.
2572 (if (memq system-type '(ms-dos windows-nt))
2573 "^\\([\\/][\\/][\\/]\\)+"
2576 (setq file (replace-match "/" t t file)))
2577 (if (memq system-type '(ms-dos windows-nt))
2578 (while (string-match "\\([\\/][\\/]\\)+" file 1)
2579 (setq file (replace-match "/" t t file)))
2580 (while (string-match "//+" file 1)
2581 (setq file (replace-match "/" t t file))))
2584 ;;; startup.el ends here