Commit | Line | Data |
---|---|---|
c88ab9ce ER |
1 | ;;; startup.el --- process Emacs shell arguments |
2 | ||
848c7757 | 3 | ;; Copyright (C) 1985, 86, 92, 94, 95, 96, 97, 98, 99, 2000, 2001 |
347d0813 | 4 | ;; Free Software Foundation, Inc. |
eea8d4ef | 5 | |
630cc463 | 6 | ;; Maintainer: FSF |
d7b4d18f | 7 | ;; Keywords: internal |
630cc463 | 8 | |
a726e0d1 JB |
9 | ;; This file is part of GNU Emacs. |
10 | ||
11 | ;; GNU Emacs is free software; you can redistribute it and/or modify | |
12 | ;; it under the terms of the GNU General Public License as published by | |
4746118a | 13 | ;; the Free Software Foundation; either version 2, or (at your option) |
a726e0d1 JB |
14 | ;; any later version. |
15 | ||
16 | ;; GNU Emacs is distributed in the hope that it will be useful, | |
17 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 | ;; GNU General Public License for more details. | |
20 | ||
21 | ;; You should have received a copy of the GNU General Public License | |
b578f267 EN |
22 | ;; along with GNU Emacs; see the file COPYING. If not, write to the |
23 | ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
24 | ;; Boston, MA 02111-1307, USA. | |
a726e0d1 | 25 | |
630cc463 | 26 | ;;; Commentary: |
a726e0d1 | 27 | |
ab30fc8a RS |
28 | ;; This file parses the command line and gets Emacs running. Options on |
29 | ;; the command line are handled in precedence order. The order is the | |
30 | ;; one in the list below; first described means first handled. Options | |
31 | ;; within each category (delimited by a bar) are handled in the order | |
32 | ;; encountered on the command line. | |
33 | ||
34 | ;; ------------------------- | |
35 | ;; -version Print Emacs version to stderr, then exit | |
36 | ;; --version successfully right away. | |
37 | ;; This option is handled by emacs.c | |
38 | ;; ------------------------- | |
39 | ;; -help Print a short usage description and exit | |
40 | ;; --help successfully right away. | |
41 | ;; This option is handled by emacs.c | |
42 | ;; ------------------------- | |
43 | ;; -nl Do not use shared memory (for systems that | |
44 | ;; -no-shared-memory support this) for the dumped Emacs data. | |
45 | ;; This option is handled by emacs.c | |
46 | ;; | |
47 | ;; -map For VMS. | |
48 | ;; --map-data This option is handled by emacs.c | |
49 | ;; ------------------------- | |
50 | ;; -t FILE Use FILE as the name of the terminal. | |
51 | ;; --terminal FILE Using this implies "-nw" also. | |
52 | ;; This option is handled by emacs.c | |
53 | ;; ------------------------- | |
64b0dbdb | 54 | ;; -d DISPNAME Use DISPNAME as the name of the X |
ab30fc8a RS |
55 | ;; -display DISPNAME display for the initial frame. |
56 | ;; --display DISPNAME This option is handled by emacs.c | |
57 | ;; ------------------------- | |
58 | ;; -nw Do not use a windows system (but use the | |
568bd708 | 59 | ;; --no-window-system terminal instead.) |
ab30fc8a RS |
60 | ;; This option is handled by emacs.c |
61 | ;; ------------------------- | |
62 | ;; -batch Execute noninteractively (messages go to stdout, | |
63 | ;; --batch variable noninteractive set to t) | |
64 | ;; This option is handled by emacs.c | |
65 | ;; ------------------------- | |
66 | ;; -q Do not load user's init file and do not load | |
67 | ;; -no-init-file "default.el". Regardless of this switch, | |
6f9340dd | 68 | ;; --no-init-file "site-start" is still loaded. |
ab30fc8a | 69 | ;; ------------------------- |
6f9340dd | 70 | ;; -no-site-file Do not load "site-start.el". (This is the ONLY |
ab30fc8a RS |
71 | ;; --no-site-file way to prevent loading that file.) |
72 | ;; ------------------------- | |
73 | ;; -u USER Load USER's init file instead of the init | |
74 | ;; -user USER file belonging to the user starting Emacs. | |
75 | ;; --user USER | |
76 | ;; ------------------------- | |
77 | ;; -debug-init Don't catch errors in init files; let the | |
78 | ;; --debug-init debugger run. | |
79 | ;; ------------------------- | |
80 | ;; -i ICONTYPE Set type of icon using when Emacs is | |
64b0dbdb | 81 | ;; -itype ICONTYPE iconified under X. |
ab30fc8a RS |
82 | ;; --icon-type ICONTYPE This option is passed on to term/x-win.el |
83 | ;; | |
64b0dbdb | 84 | ;; -iconic Start Emacs iconified. |
ab30fc8a RS |
85 | ;; --iconic This option is passed on to term/x-win.el |
86 | ;; ------------------------- | |
64b0dbdb | 87 | ;; Various X options for colors/fonts/geometry/title etc. |
f5627e93 | 88 | ;; These options are passed on to term/x-win.el which see. |
ab30fc8a RS |
89 | ;; ------------------------- |
90 | ;; FILE Visit FILE. | |
dc2cd811 GM |
91 | ;; -visit FILE |
92 | ;; --visit FILE | |
93 | ;; -file FILE | |
94 | ;; --file FILE | |
ab30fc8a RS |
95 | ;; |
96 | ;; -L DIRNAME Add DIRNAME to load-path | |
97 | ;; -directory DIRNAME | |
98 | ;; --directory DIRNAME | |
99 | ;; | |
100 | ;; -l FILE Load and execute the Emacs lisp code | |
101 | ;; -load FILE in FILE. | |
102 | ;; --load FILE | |
103 | ;; | |
104 | ;; -f FUNC Execute Emacs lisp function FUNC with | |
105 | ;; -funcall FUNC no arguments. The "-e" form is outdated | |
106 | ;; --funcall FUNC and should not be used. (It's a typo | |
107 | ;; -e FUNC promoted to a feature.) | |
108 | ;; | |
955093c9 EN |
109 | ;; -eval FORM Execute Emacs lisp form FORM. |
110 | ;; --eval FORM | |
dc2cd811 GM |
111 | ;; -execute EXPR |
112 | ;; --execute EXPR | |
e6b75e30 | 113 | ;; |
ab30fc8a RS |
114 | ;; -insert FILE Insert the contents of FILE into buffer. |
115 | ;; --insert FILE | |
116 | ;; ------------------------- | |
117 | ;; -kill Kill (exit) Emacs right away. | |
118 | ;; --kill | |
119 | ;; ------------------------- | |
a726e0d1 | 120 | |
630cc463 ER |
121 | ;;; Code: |
122 | ||
a726e0d1 JB |
123 | (setq top-level '(normal-top-level)) |
124 | ||
42a3e6fa | 125 | (defvar command-line-processed nil |
2879a13b | 126 | "Non-nil once command line has been processed.") |
a726e0d1 | 127 | |
42a3e6fa RS |
128 | (defgroup initialization nil |
129 | "Emacs start-up procedure" | |
130 | :group 'internal) | |
131 | ||
132 | (defcustom inhibit-startup-message nil | |
1d7da582 | 133 | "*Non-nil inhibits the initial startup message. |
a726e0d1 | 134 | This is for use in your personal init file, once you are familiar |
42a3e6fa RS |
135 | with the contents of the startup message." |
136 | :type 'boolean | |
137 | :group 'initialization) | |
a726e0d1 | 138 | |
42a3e6fa | 139 | (defcustom inhibit-startup-echo-area-message nil |
1d7da582 | 140 | "*Non-nil inhibits the initial startup echo area message. |
42a3e6fa RS |
141 | Setting this variable takes effect |
142 | only if you do it with the customization buffer | |
94487c4e | 143 | or if your `.emacs' file contains a line of this form: |
54a003f7 | 144 | (setq inhibit-startup-echo-area-message \"YOUR-USER-NAME\") |
e5575c06 RS |
145 | If your `.emacs' file is byte-compiled, use the following form instead: |
146 | (eval '(setq inhibit-startup-echo-area-message \"YOUR-USER-NAME\")) | |
1d7da582 | 147 | Thus, someone else using a copy of your `.emacs' file will see |
42a3e6fa RS |
148 | the startup message unless he personally acts to inhibit it." |
149 | :type '(choice (const :tag "Don't inhibit") | |
150 | (string :tag "Enter your user name, to inhibit")) | |
151 | :group 'initialization) | |
1d7da582 | 152 | |
42a3e6fa RS |
153 | (defcustom inhibit-default-init nil |
154 | "*Non-nil inhibits loading the `default' library." | |
155 | :type 'boolean | |
156 | :group 'initialization) | |
a726e0d1 | 157 | |
802a980a GM |
158 | (defcustom inhibit-startup-buffer-menu nil |
159 | "*Non-nil inhibits display of buffer list when more than 2 files are loaded." | |
160 | :type 'boolean | |
161 | :group 'initialization) | |
162 | ||
d7fa5aa2 | 163 | (defvar command-switch-alist nil |
a726e0d1 JB |
164 | "Alist of command-line switches. |
165 | Elements look like (SWITCH-STRING . HANDLER-FUNCTION). | |
166 | HANDLER-FUNCTION receives switch name as sole arg; | |
167 | remaining command-line args are in the variable `command-line-args-left'.") | |
168 | ||
860befc8 RS |
169 | (defvar command-line-args-left nil |
170 | "List of command-line args not yet processed.") | |
171 | ||
a726e0d1 JB |
172 | (defvar command-line-functions nil ;; lrs 7/31/89 |
173 | "List of functions to process unrecognized command-line arguments. | |
174 | Each function should access the dynamically bound variables | |
b4484ea8 | 175 | `argi' (the current argument) and `command-line-args-left' (the remaining |
a726e0d1 | 176 | arguments). The function should return non-nil only if it recognizes and |
b4484ea8 RS |
177 | processes `argi'. If it does so, it may consume successive arguments by |
178 | altering `command-line-args-left' to remove them.") | |
a726e0d1 | 179 | |
09a1077c RS |
180 | (defvar command-line-default-directory nil |
181 | "Default directory to use for command line arguments. | |
182 | This is normally copied from `default-directory' when Emacs starts.") | |
183 | ||
b3afdeb8 RS |
184 | ;;; This is here, rather than in x-win.el, so that we can ignore these |
185 | ;;; options when we are not using X. | |
46cfd295 | 186 | (defconst command-line-x-option-alist |
b3afdeb8 RS |
187 | '(("-bw" 1 x-handle-numeric-switch border-width) |
188 | ("-d" 1 x-handle-display) | |
189 | ("-display" 1 x-handle-display) | |
5676ab57 | 190 | ("-name" 1 x-handle-name-switch) |
2c3fef40 RS |
191 | ("-title" 1 x-handle-switch title) |
192 | ("-T" 1 x-handle-switch title) | |
b3afdeb8 RS |
193 | ("-r" 0 x-handle-switch reverse t) |
194 | ("-rv" 0 x-handle-switch reverse t) | |
195 | ("-reverse" 0 x-handle-switch reverse t) | |
196 | ("-reverse-video" 0 x-handle-switch reverse t) | |
197 | ("-fn" 1 x-handle-switch font) | |
198 | ("-font" 1 x-handle-switch font) | |
188b6a5e EZ |
199 | ("-fs" 0 x-handle-initial-switch fullscreen fullboth) |
200 | ("-fw" 0 x-handle-initial-switch fullscreen fullwidth) | |
201 | ("-fh" 0 x-handle-initial-switch fullscreen fullheight) | |
b3afdeb8 | 202 | ("-ib" 1 x-handle-numeric-switch internal-border-width) |
1f7f78f1 | 203 | ("-g" 1 x-handle-geometry) |
9ff6bda1 | 204 | ("-lsp" 1 x-handle-numeric-switch line-spacing) |
1f7f78f1 | 205 | ("-geometry" 1 x-handle-geometry) |
b3afdeb8 RS |
206 | ("-fg" 1 x-handle-switch foreground-color) |
207 | ("-foreground" 1 x-handle-switch foreground-color) | |
208 | ("-bg" 1 x-handle-switch background-color) | |
209 | ("-background" 1 x-handle-switch background-color) | |
210 | ("-ms" 1 x-handle-switch mouse-color) | |
211 | ("-itype" 0 x-handle-switch icon-type t) | |
212 | ("-i" 0 x-handle-switch icon-type t) | |
213 | ("-iconic" 0 x-handle-iconic) | |
214 | ("-xrm" 1 x-handle-xrm-switch) | |
215 | ("-cr" 1 x-handle-switch cursor-color) | |
216 | ("-vb" 0 x-handle-switch vertical-scroll-bars t) | |
217 | ("-hb" 0 x-handle-switch horizontal-scroll-bars t) | |
218 | ("-bd" 1 x-handle-switch) | |
219 | ("--border-width" 1 x-handle-numeric-switch border-width) | |
220 | ("--display" 1 x-handle-display) | |
5676ab57 | 221 | ("--name" 1 x-handle-name-switch) |
7775acb8 | 222 | ("--title" 1 x-handle-switch title) |
b3afdeb8 RS |
223 | ("--reverse-video" 0 x-handle-switch reverse t) |
224 | ("--font" 1 x-handle-switch font) | |
188b6a5e EZ |
225 | ("--fullscreen" 0 x-handle-initial-switch fullscreen fullboth) |
226 | ("--fullwidth" 0 x-handle-initial-switch fullscreen fullwidth) | |
227 | ("--fullheight" 0 x-handle-initial-switch fullscreen fullheight) | |
b3afdeb8 | 228 | ("--internal-border" 1 x-handle-numeric-switch internal-border-width) |
1f7f78f1 | 229 | ("--geometry" 1 x-handle-geometry) |
b3afdeb8 RS |
230 | ("--foreground-color" 1 x-handle-switch foreground-color) |
231 | ("--background-color" 1 x-handle-switch background-color) | |
232 | ("--mouse-color" 1 x-handle-switch mouse-color) | |
233 | ("--icon-type" 0 x-handle-switch icon-type t) | |
234 | ("--iconic" 0 x-handle-iconic) | |
235 | ("--xrm" 1 x-handle-xrm-switch) | |
236 | ("--cursor-color" 1 x-handle-switch cursor-color) | |
237 | ("--vertical-scroll-bars" 0 x-handle-switch vertical-scroll-bars t) | |
9ff6bda1 | 238 | ("--line-spacing" 1 x-handle-numeric-switch line-spacing) |
b3afdeb8 RS |
239 | ("--border-color" 1 x-handle-switch border-width)) |
240 | "Alist of X Windows options. | |
241 | Each element has the form | |
242 | (NAME NUMARGS HANDLER FRAME-PARAM VALUE) | |
243 | where NAME is the option name string, NUMARGS is the number of arguments | |
244 | that the option accepts, HANDLER is a function to call to handle the option. | |
245 | FRAME-PARAM (optional) is the frame parameter this option specifies, | |
246 | and VALUE is the value which is given to that frame parameter | |
247 | \(most options use the argument for this, so VALUE is not present).") | |
248 | ||
e3bd99f5 | 249 | (defvar before-init-hook nil |
db3f571a | 250 | "Normal hook run after handling urgent options but before loading init files.") |
3fc958a4 | 251 | |
e3bd99f5 | 252 | (defvar after-init-hook nil |
db3f571a KH |
253 | "Normal hook run after loading the init files, `~/.emacs' and `default.el'. |
254 | There is no `condition-case' around the running of these functions; | |
255 | therefore, if you set `debug-on-error' non-nil in `.emacs', | |
256 | an error in one of these functions will invoke the debugger.") | |
257 | ||
258 | (defvar emacs-startup-hook nil | |
259 | "Normal hook run after loading init files and handling the command line.") | |
e3bd99f5 | 260 | |
a726e0d1 | 261 | (defvar term-setup-hook nil |
db3f571a KH |
262 | "Normal hook run after loading terminal-specific Lisp code. |
263 | It also follows `emacs-startup-hook'. This hook exists for users to set, | |
a726e0d1 JB |
264 | so as to override the definitions made by the terminal-specific file. |
265 | Emacs never sets this variable itself.") | |
266 | ||
267 | (defvar keyboard-type nil | |
b4484ea8 RS |
268 | "The brand of keyboard you are using. |
269 | This variable is used to define | |
a726e0d1 | 270 | the proper function and keypad keys for use under X. It is used in a |
94487c4e | 271 | fashion analogous to the environment variable TERM.") |
a726e0d1 JB |
272 | |
273 | (defvar window-setup-hook nil | |
b4484ea8 RS |
274 | "Normal hook run to initialize window system display. |
275 | Emacs runs this hook after processing the command line arguments and loading | |
276 | the user's init file.") | |
a726e0d1 | 277 | |
42a3e6fa RS |
278 | (defcustom initial-major-mode 'lisp-interaction-mode |
279 | "Major mode command symbol to use for the initial *scratch* buffer." | |
ce2f921e | 280 | :type 'function |
42a3e6fa | 281 | :group 'initialization) |
a726e0d1 | 282 | |
42a3e6fa | 283 | (defcustom init-file-user nil |
a726e0d1 | 284 | "Identity of user whose `.emacs' file is or was read. |
d7fa5aa2 RS |
285 | The value is nil if `-q' or `--no-init-file' was specified, |
286 | meaning do not load any init file. | |
287 | ||
288 | Otherwise, the value may be the null string, meaning use the init file | |
289 | for the user that originally logged in, or it may be a | |
290 | string containing a user's name meaning use that person's init file. | |
a726e0d1 | 291 | |
2bdfaa42 KH |
292 | In either of the latter cases, `(concat \"~\" init-file-user \"/\")' |
293 | evaluates to the name of the directory where the `.emacs' file was | |
13fce4e6 RS |
294 | looked for. |
295 | ||
296 | Setting `init-file-user' does not prevent Emacs from loading | |
42a3e6fa RS |
297 | `site-start.el'. The only way to do that is to use `--no-site-file'." |
298 | :type '(choice (const :tag "none" nil) string) | |
299 | :group 'initialization) | |
a726e0d1 | 300 | |
42a3e6fa | 301 | (defcustom site-run-file "site-start" |
b7444d31 RS |
302 | "File containing site-wide run-time initializations. |
303 | This file is loaded at run-time before `~/.emacs'. It contains inits | |
304 | that need to be in place for the entire site, but which, due to their | |
305 | higher incidence of change, don't make sense to load into emacs' | |
306 | dumped image. Thus, the run-time load order is: 1. file described in | |
13fce4e6 RS |
307 | this variable, if non-nil; 2. `~/.emacs'; 3. `default.el'. |
308 | ||
309 | Don't use the `site-start.el' file for things some users may not like. | |
310 | Put them in `default.el' instead, so that users can more easily | |
311 | override them. Users can prevent loading `default.el' with the `-q' | |
312 | option or by setting `inhibit-default-init' in their own init files, | |
313 | but inhibiting `site-start.el' requires `--no-site-file', which | |
42a3e6fa | 314 | is less convenient." |
93812130 | 315 | :type '(choice (const :tag "none" nil) string) |
42a3e6fa | 316 | :group 'initialization) |
b7444d31 | 317 | |
42a3e6fa RS |
318 | (defcustom mail-host-address nil |
319 | "*Name of this machine, for purposes of naming users." | |
320 | :type '(choice (const nil) string) | |
321 | :group 'mail) | |
c13fbb62 | 322 | |
42a3e6fa | 323 | (defcustom user-mail-address nil |
452e9090 RS |
324 | "*Full mailing address of this user. |
325 | This is initialized based on `mail-host-address', | |
42a3e6fa RS |
326 | after your init file is read, in case it sets `mail-host-address'." |
327 | :type 'string | |
328 | :group 'mail) | |
c10d1f06 | 329 | |
42a3e6fa | 330 | (defcustom auto-save-list-file-prefix |
73f13e5a GM |
331 | (cond ((eq system-type 'ms-dos) |
332 | ;; MS-DOS cannot have initial dot, and allows only 8.3 names | |
4b33deaa | 333 | "~/_emacs.d/auto-save.list/_s") |
73f13e5a GM |
334 | (t |
335 | "~/.emacs.d/auto-save-list/.saves-")) | |
cdee38c3 KH |
336 | "Prefix for generating `auto-save-list-file-name'. |
337 | This is used after reading your `.emacs' file to initialize | |
338 | `auto-save-list-file-name', by appending Emacs's pid and the system name, | |
339 | if you have not already set `auto-save-list-file-name' yourself. | |
73f13e5a | 340 | Directories in the prefix will be created if necessary. |
cdee38c3 | 341 | Set this to nil if you want to prevent `auto-save-list-file-name' |
42a3e6fa | 342 | from being initialized." |
3671f444 KH |
343 | :type '(choice (const :tag "Don't record a session's auto save list" nil) |
344 | string) | |
42a3e6fa | 345 | :group 'auto-save) |
2e05d063 | 346 | |
a726e0d1 JB |
347 | (defvar init-file-debug nil) |
348 | ||
52320897 RS |
349 | (defvar init-file-had-error nil) |
350 | ||
95eada65 RS |
351 | (defvar normal-top-level-add-subdirs-inode-list nil) |
352 | ||
859e15c1 | 353 | (defun normal-top-level-add-subdirs-to-load-path () |
0412d833 RS |
354 | "Add all subdirectories of current directory to `load-path'. |
355 | More precisely, this uses only the subdirectories whose names | |
f734a13e DL |
356 | start with letters or digits; it excludes any subdirectory named `RCS' |
357 | or `CVS', and any subdirectory that contains a file named `.nosearch'." | |
859e15c1 | 358 | (let (dirs |
95eada65 | 359 | attrs |
859e15c1 KH |
360 | (pending (list default-directory))) |
361 | ;; This loop does a breadth-first tree walk on DIR's subtree, | |
362 | ;; putting each subdir into DIRS as its contents are examined. | |
363 | (while pending | |
4e0a3971 | 364 | (push (pop pending) dirs) |
722a451d EZ |
365 | (let* ((this-dir (car dirs)) |
366 | (contents (directory-files this-dir)) | |
367 | (default-directory this-dir) | |
368 | (canonicalized (and (eq system-type 'windows-nt) | |
369 | (untranslated-canonical-name this-dir)))) | |
370 | ;; The Windows version doesn't report meaningful inode | |
371 | ;; numbers, so use the canonicalized absolute file name of the | |
372 | ;; directory instead. | |
373 | (setq attrs (or canonicalized | |
374 | (nthcdr 10 (file-attributes this-dir)))) | |
95eada65 | 375 | (unless (member attrs normal-top-level-add-subdirs-inode-list) |
4e0a3971 SM |
376 | (push attrs normal-top-level-add-subdirs-inode-list) |
377 | (dolist (file contents) | |
c4a40544 | 378 | ;; The lower-case variants of RCS and CVS are for DOS/Windows. |
4e0a3971 SM |
379 | (unless (member file '("." ".." "RCS" "CVS" "rcs" "cvs")) |
380 | (when (and (string-match "\\`[[:alnum:]]" file) | |
9d1fb179 RS |
381 | ;; Avoid doing a `stat' when it isn't necessary |
382 | ;; because that can cause trouble when an NFS server | |
383 | ;; is down. | |
4e0a3971 SM |
384 | (not (string-match "\\.elc?\\'" file)) |
385 | (file-directory-p file)) | |
386 | (let ((expanded (expand-file-name file))) | |
95eada65 RS |
387 | (unless (file-exists-p (expand-file-name ".nosearch" |
388 | expanded)) | |
4e0a3971 | 389 | (setq pending (nconc pending (list expanded))))))))))) |
bb15e81a | 390 | (normal-top-level-add-to-load-path (cdr (nreverse dirs))))) |
859e15c1 | 391 | |
537b6e4e RS |
392 | ;; This function is called from a subdirs.el file. |
393 | ;; It assumes that default-directory is the directory | |
394 | ;; in which the subdirs.el file exists, | |
395 | ;; and it adds to load-path the subdirs of that directory | |
396 | ;; as specified in DIRS. Normally the elements of DIRS are relative. | |
e87a7309 | 397 | (defun normal-top-level-add-to-load-path (dirs) |
cd1c10f6 RS |
398 | (let ((tail load-path) |
399 | (thisdir (directory-file-name default-directory))) | |
400 | (while (and tail | |
138e541f GM |
401 | ;;Don't go all the way to the nil terminator. |
402 | (cdr tail) | |
cd1c10f6 RS |
403 | (not (equal thisdir (car tail))) |
404 | (not (and (memq system-type '(ms-dos windows-nt)) | |
405 | (equal (downcase thisdir) (downcase (car tail)))))) | |
406 | (setq tail (cdr tail))) | |
138e541f GM |
407 | ;;Splice the new section in. |
408 | (when tail | |
409 | (setcdr tail (append (mapcar 'expand-file-name dirs) (cdr tail)))))) | |
e87a7309 | 410 | |
a726e0d1 JB |
411 | (defun normal-top-level () |
412 | (if command-line-processed | |
413 | (message "Back to top level.") | |
414 | (setq command-line-processed t) | |
8d4c2221 RS |
415 | ;; Give *Messages* the same default-directory as *scratch*, |
416 | ;; just to keep things predictable. | |
417 | (let ((dir default-directory)) | |
418 | (save-excursion | |
419 | (set-buffer (get-buffer "*Messages*")) | |
420 | (setq default-directory dir))) | |
80d71556 KH |
421 | ;; For root, preserve owner and group when editing files. |
422 | (if (equal (user-uid) 0) | |
423 | (setq backup-by-copying-when-mismatch t)) | |
e87a7309 RS |
424 | ;; Look in each dir in load-path for a subdirs.el file. |
425 | ;; If we find one, load it, which will add the appropriate subdirs | |
426 | ;; of that dir into load-path, | |
357438eb KH |
427 | ;; Look for a leim-list.el file too. Loading it will register |
428 | ;; available input methods. | |
e87a7309 RS |
429 | (let ((tail load-path) |
430 | new) | |
431 | (while tail | |
4e0a3971 | 432 | (push (car tail) new) |
bbfc7591 GM |
433 | (condition-case nil |
434 | (let ((default-directory (car tail))) | |
435 | (load (expand-file-name "subdirs.el" (car tail)) t t t))) | |
357438eb KH |
436 | (condition-case nil |
437 | (let ((default-directory (car tail))) | |
438 | (load (expand-file-name "leim-list.el" (car tail)) t t t))) | |
e87a7309 | 439 | (setq tail (cdr tail)))) |
ffd56f97 | 440 | (if (not (eq system-type 'vax-vms)) |
a4b33896 JB |
441 | (progn |
442 | ;; If the PWD environment variable isn't accurate, delete it. | |
443 | (let ((pwd (getenv "PWD"))) | |
444 | (and (stringp pwd) | |
445 | ;; Use FOO/., so that if FOO is a symlink, file-attributes | |
446 | ;; describes the directory linked to, not FOO itself. | |
447 | (or (equal (file-attributes | |
448 | (concat (file-name-as-directory pwd) ".")) | |
449 | (file-attributes | |
450 | (concat (file-name-as-directory default-directory) | |
451 | "."))) | |
452 | (setq process-environment | |
453 | (delete (concat "PWD=" pwd) | |
454 | process-environment))))))) | |
492878e4 | 455 | (setq default-directory (abbreviate-file-name default-directory)) |
6f2c86fa KH |
456 | (let ((menubar-bindings-done nil)) |
457 | (unwind-protect | |
458 | (command-line) | |
459 | ;; Do this again, in case .emacs defined more abbreviations. | |
460 | (setq default-directory (abbreviate-file-name default-directory)) | |
b3c7c12c RS |
461 | ;; Specify the file for recording all the auto save files of this session. |
462 | ;; This is used by recover-session. | |
cdee38c3 KH |
463 | (or auto-save-list-file-name |
464 | (and auto-save-list-file-prefix | |
465 | (setq auto-save-list-file-name | |
1f7f78f1 RS |
466 | ;; Under MS-DOS our PID is almost always reused between |
467 | ;; Emacs invocations. We need something more unique. | |
4b33deaa EZ |
468 | (cond ((eq system-type 'ms-dos) |
469 | ;; We are going to access the auto-save | |
470 | ;; directory, so make sure it exists. | |
471 | (make-directory | |
472 | (file-name-directory auto-save-list-file-prefix) | |
473 | t) | |
474 | (concat | |
475 | (make-temp-name | |
476 | (expand-file-name | |
477 | auto-save-list-file-prefix)) | |
478 | "~")) | |
479 | (t | |
480 | (expand-file-name | |
481 | (format "%s%d-%s~" | |
482 | auto-save-list-file-prefix | |
483 | (emacs-pid) | |
484 | (system-name)))))))) | |
6f2c86fa KH |
485 | (run-hooks 'emacs-startup-hook) |
486 | (and term-setup-hook | |
487 | (run-hooks 'term-setup-hook)) | |
6a1e7d67 GM |
488 | |
489 | ;; Don't do this if we failed to create the initial frame, | |
490 | ;; for instance due to a dense colormap. | |
538ef02a GM |
491 | (when (or frame-initial-frame |
492 | ;; If frame-initial-frame has no meaning, do this anyway. | |
493 | (not (and window-system | |
494 | (not noninteractive) | |
495 | (not (eq window-system 'pc))))) | |
6a1e7d67 GM |
496 | ;; Modify the initial frame based on what .emacs puts into |
497 | ;; ...-frame-alist. | |
498 | (if (fboundp 'frame-notice-user-settings) | |
499 | (frame-notice-user-settings)) | |
500 | (if (fboundp 'frame-set-background-mode) | |
501 | ;; Set the faces for the initial background mode even if | |
502 | ;; frame-notice-user-settings didn't (such as on a tty). | |
503 | ;; frame-set-background-mode is idempotent, so it won't | |
504 | ;; cause any harm if it's already been done. | |
505 | (let ((frame-background-mode frame-background-mode) | |
506 | (frame (selected-frame)) | |
507 | term) | |
508 | (when (and (null window-system) | |
509 | ;; Don't override a possibly customized value. | |
510 | (null frame-background-mode) | |
511 | ;; Don't override user specifications. | |
512 | (null (frame-parameter frame 'reverse)) | |
513 | (let ((bg (frame-parameter frame 'background-color))) | |
514 | (or (null bg) | |
515 | (member bg '(unspecified "unspecified-bg"))))) | |
516 | (setq term (getenv "TERM")) | |
818cd248 EZ |
517 | ;; Some files in lisp/term do a better job with the |
518 | ;; background mode, but we leave this here anyway, in | |
519 | ;; case they remove those files. | |
6a1e7d67 GM |
520 | (if (string-match "^\\(xterm\\|rxvt\\|dtterm\\|eterm\\)" |
521 | term) | |
522 | (setq frame-background-mode 'light))) | |
523 | (frame-set-background-mode (selected-frame))))) | |
13ab33c4 | 524 | |
6f2c86fa KH |
525 | ;; Now we know the user's default font, so add it to the menu. |
526 | (if (fboundp 'font-menu-add-default) | |
527 | (font-menu-add-default)) | |
528 | (and window-setup-hook | |
529 | (run-hooks 'window-setup-hook)) | |
530 | (or menubar-bindings-done | |
66c24e1e EZ |
531 | (if (display-popup-menus-p) |
532 | (precompute-menubar-bindings))))))) | |
6f2c86fa KH |
533 | |
534 | ;; Precompute the keyboard equivalents in the menu bar items. | |
535 | (defun precompute-menubar-bindings () | |
365636dc RS |
536 | (let ((submap (lookup-key global-map [menu-bar]))) |
537 | (while submap | |
538 | (and (consp (car submap)) | |
539 | (symbolp (car (car submap))) | |
540 | (stringp (car-safe (cdr (car submap)))) | |
541 | (keymapp (cdr (cdr (car submap)))) | |
a18042d7 RS |
542 | (progn |
543 | (x-popup-menu nil (cdr (cdr (car submap)))) | |
544 | (if purify-flag | |
545 | (garbage-collect)))) | |
365636dc | 546 | (setq submap (cdr submap)))) |
5b61c6a7 | 547 | (setq define-key-rebound-commands t)) |
a726e0d1 | 548 | |
c381f482 EZ |
549 | ;; Command-line options supported by tty's: |
550 | (defconst tty-long-option-alist | |
8957d2bf EZ |
551 | '(("--name" . "-name") |
552 | ("--title" . "-T") | |
553 | ("--reverse-video" . "-reverse") | |
c381f482 | 554 | ("--foreground-color" . "-fg") |
8957d2bf EZ |
555 | ("--background-color" . "-bg") |
556 | ("--color" . "-color"))) | |
c381f482 | 557 | |
b66b6aeb GM |
558 | (defconst tool-bar-images-pixel-height 24 |
559 | "Height in pixels of images in the tool bar.") | |
560 | ||
3a55d3d0 JR |
561 | (defvar tool-bar-originally-present nil |
562 | "Non-nil if tool-bars are present before user and site init files are read.") | |
563 | ||
c381f482 EZ |
564 | ;; Handle the X-like command line parameters "-fg", "-bg", "-name", etc. |
565 | (defun tty-handle-args (args) | |
566 | (let ((rest nil)) | |
567 | (message "%s" args) | |
568 | (while (and args | |
569 | (not (equal (car args) "--"))) | |
570 | (let* ((this (car args)) | |
571 | (orig-this this) | |
572 | completion argval) | |
573 | (setq args (cdr args)) | |
574 | ;; Check for long options with attached arguments | |
575 | ;; and separate out the attached option argument into argval. | |
576 | (if (string-match "^--[^=]*=" this) | |
577 | (setq argval (substring this (match-end 0)) | |
578 | this (substring this 0 (1- (match-end 0))))) | |
579 | (when (string-match "^--" this) | |
580 | (setq completion (try-completion this tty-long-option-alist)) | |
581 | (if (eq completion t) | |
582 | ;; Exact match for long option. | |
583 | (setq this (cdr (assoc this tty-long-option-alist))) | |
584 | (if (stringp completion) | |
585 | (let ((elt (assoc completion tty-long-option-alist))) | |
586 | ;; Check for abbreviated long option. | |
587 | (or elt | |
588 | (error "Option `%s' is ambiguous" this)) | |
589 | (setq this (cdr elt))) | |
590 | ;; Check for a short option. | |
591 | (setq argval nil this orig-this)))) | |
592 | (cond ((or (string= this "-fg") (string= this "-foreground")) | |
593 | (or argval (setq argval (car args) args (cdr args))) | |
594 | (setq default-frame-alist | |
595 | (cons (cons 'foreground-color argval) | |
596 | default-frame-alist))) | |
597 | ((or (string= this "-bg") (string= this "-background")) | |
598 | (or argval (setq argval (car args) args (cdr args))) | |
599 | (setq default-frame-alist | |
600 | (cons (cons 'background-color argval) | |
601 | default-frame-alist))) | |
602 | ((or (string= this "-T") (string= this "-name")) | |
603 | (or argval (setq argval (car args) args (cdr args))) | |
604 | (setq default-frame-alist | |
605 | (cons | |
606 | (cons 'title | |
607 | (if (stringp argval) | |
608 | argval | |
609 | (let ((case-fold-search t) | |
610 | i) | |
611 | (setq argval (invocation-name)) | |
612 | ||
613 | ;; Change any . or * characters in name to | |
614 | ;; hyphens, so as to emulate behavior on X. | |
615 | (while | |
616 | (setq i (string-match "[.*]" argval)) | |
617 | (aset argval i ?-)) | |
618 | argval))) | |
619 | default-frame-alist))) | |
620 | ((or (string= this "-r") | |
621 | (string= this "-rv") | |
622 | (string= this "-reverse")) | |
623 | (setq default-frame-alist | |
624 | (cons '(reverse . t) | |
625 | default-frame-alist))) | |
8957d2bf EZ |
626 | ((string= this "-color") |
627 | (if (null argval) | |
628 | (setq argval 8)) ; default --color means 8 ANSI colors | |
629 | (setq default-frame-alist | |
630 | (cons (cons 'tty-color-mode | |
631 | (cond | |
632 | ((numberp argval) argval) | |
633 | ((string-match "-?[0-9]+" argval) | |
634 | (string-to-number argval)) | |
635 | (t (intern argval)))) | |
636 | default-frame-alist))) | |
c381f482 EZ |
637 | (t (setq rest (cons this rest)))))) |
638 | (nreverse rest))) | |
639 | ||
a726e0d1 | 640 | (defun command-line () |
09a1077c RS |
641 | (setq command-line-default-directory default-directory) |
642 | ||
849eedba RS |
643 | ;; Choose a reasonable location for temporary files. |
644 | (setq temporary-file-directory | |
645 | (file-name-as-directory | |
646 | (cond ((memq system-type '(ms-dos windows-nt)) | |
647 | (or (getenv "TEMP") (getenv "TMPDIR") (getenv "TMP") "c:/temp")) | |
648 | ((memq system-type '(vax-vms axp-vms)) | |
649 | (or (getenv "TMPDIR") (getenv "TMP") (getenv "TEMP") "SYS$SCRATCH:")) | |
650 | (t | |
651 | (or (getenv "TMPDIR") (getenv "TMP") (getenv "TEMP") "/tmp"))))) | |
607f86f5 EZ |
652 | (setq small-temporary-file-directory |
653 | (if (eq system-type 'ms-dos) | |
f5568df0 | 654 | (getenv "TMPDIR"))) |
849eedba | 655 | |
74f2ab06 | 656 | ;; See if we should import version-control from the environment variable. |
a726e0d1 JB |
657 | (let ((vc (getenv "VERSION_CONTROL"))) |
658 | (cond ((eq vc nil)) ;don't do anything if not set | |
659 | ((or (string= vc "t") | |
660 | (string= vc "numbered")) | |
661 | (setq version-control t)) | |
662 | ((or (string= vc "nil") | |
663 | (string= vc "existing")) | |
664 | (setq version-control nil)) | |
665 | ((or (string= vc "never") | |
666 | (string= vc "simple")) | |
667 | (setq version-control 'never)))) | |
668 | ||
79058860 JB |
669 | ;;! This has been commented out; I currently find the behavior when |
670 | ;;! split-window-keep-point is nil disturbing, but if I can get used | |
671 | ;;! to it, then it would be better to eliminate the option. | |
672 | ;;! ;; Choose a good default value for split-window-keep-point. | |
673 | ;;! (setq split-window-keep-point (> baud-rate 2400)) | |
f35fe3c6 | 674 | |
d4308a4d EZ |
675 | ;; Set the default strings to display in mode line for |
676 | ;; end-of-line formats that aren't native to this platform. | |
677 | (cond | |
678 | ((memq system-type '(ms-dos windows-nt emx)) | |
679 | (setq eol-mnemonic-unix "(Unix)") | |
680 | (setq eol-mnemonic-mac "(Mac)")) | |
bde61f8b EZ |
681 | ;; Both Mac and Unix EOLs are now "native" on Mac OS so keep the |
682 | ;; abbreviated strings `/' and `:' set in coding.c for them. | |
683 | ((eq system-type 'macos) | |
684 | (setq eol-mnemonic-dos "(DOS)")) | |
d4308a4d EZ |
685 | (t ; this is for Unix/GNU/Linux systems |
686 | (setq eol-mnemonic-dos "(DOS)") | |
687 | (setq eol-mnemonic-mac "(Mac)"))) | |
688 | ||
a726e0d1 | 689 | ;; Read window system's init file if using a window system. |
1ed14cfd RS |
690 | (condition-case error |
691 | (if (and window-system (not noninteractive)) | |
692 | (load (concat term-file-prefix | |
693 | (symbol-name window-system) | |
694 | "-win") | |
695 | ;; Every window system should have a startup file; | |
696 | ;; barf if we can't find it. | |
697 | nil t)) | |
698 | ;; If we can't read it, print the error message and exit. | |
699 | (error | |
2677ad61 RS |
700 | (princ |
701 | (if (eq (car error) 'error) | |
702 | (apply 'concat (cdr error)) | |
703 | (if (memq 'file-error (get (car error) 'error-conditions)) | |
704 | (format "%s: %s" | |
705 | (nth 1 error) | |
ffaf8bbb | 706 | (mapconcat (lambda (obj) (prin1-to-string obj t)) |
2677ad61 RS |
707 | (cdr (cdr error)) ", ")) |
708 | (format "%s: %s" | |
709 | (get (car error) 'error-message) | |
ffaf8bbb | 710 | (mapconcat (lambda (obj) (prin1-to-string obj t)) |
2677ad61 RS |
711 | (cdr error) ", ")))) |
712 | 'external-debugging-output) | |
27f5188c | 713 | (terpri 'external-debugging-output) |
2677ad61 | 714 | (setq window-system nil) |
1ed14cfd | 715 | (kill-emacs))) |
a726e0d1 | 716 | |
c381f482 EZ |
717 | ;; Windowed displays do this inside their *-win.el. |
718 | (when (and (not (display-graphic-p)) | |
719 | (not noninteractive)) | |
720 | (setq command-line-args (tty-handle-args command-line-args))) | |
721 | ||
640a9cdd JR |
722 | (set-locale-environment nil) |
723 | ||
c16eb7b0 RS |
724 | ;; Convert the arguments to Emacs internal representation. |
725 | (let ((args (cdr command-line-args))) | |
726 | (while args | |
727 | (setcar args | |
728 | (decode-coding-string (car args) locale-coding-system t)) | |
729 | (setq args (cdr args)))) | |
730 | ||
03e3c30a JB |
731 | (let ((done nil) |
732 | (args (cdr command-line-args))) | |
733 | ||
a726e0d1 JB |
734 | ;; Figure out which user's init file to load, |
735 | ;; either from the environment or from the options. | |
736 | (setq init-file-user (if noninteractive nil (user-login-name))) | |
737 | ;; If user has not done su, use current $HOME to find .emacs. | |
738 | (and init-file-user (string= init-file-user (user-real-login-name)) | |
739 | (setq init-file-user "")) | |
03e3c30a JB |
740 | |
741 | ;; Process the command-line args, and delete the arguments | |
742 | ;; processed. This is consistent with the way main in emacs.c | |
743 | ;; does things. | |
a726e0d1 | 744 | (while (and (not done) args) |
096b7031 | 745 | (let ((longopts '(("--no-init-file") ("--no-site-file") ("--user") |
a360cae9 | 746 | ("--debug-init") ("--iconic") ("--icon-type"))) |
4e0a3971 | 747 | (argi (pop args)) |
096b7031 | 748 | (argval nil)) |
452e9090 RS |
749 | ;; Handle --OPTION=VALUE format. |
750 | (if (and (string-match "\\`--" argi) | |
751 | (string-match "=" argi)) | |
a981e7ff KH |
752 | (setq argval (substring argi (match-end 0)) |
753 | argi (substring argi 0 (match-beginning 0)))) | |
f7ad212d RS |
754 | (or (equal argi "--") |
755 | (let ((completion (try-completion argi longopts))) | |
756 | (if (eq completion t) | |
757 | (setq argi (substring argi 1)) | |
758 | (if (stringp completion) | |
759 | (let ((elt (assoc completion longopts))) | |
760 | (or elt | |
761 | (error "Option `%s' is ambiguous" argi)) | |
762 | (setq argi (substring (car elt) 1))) | |
763 | (setq argval nil))))) | |
a726e0d1 | 764 | (cond |
4e0a3971 SM |
765 | ((member argi '("-q" "-no-init-file")) |
766 | (setq init-file-user nil)) | |
767 | ((member argi '("-u" "-user")) | |
096b7031 | 768 | (or argval |
4e0a3971 | 769 | (setq argval (pop args))) |
096b7031 | 770 | (setq init-file-user argval |
4e0a3971 | 771 | argval nil)) |
b7444d31 | 772 | ((string-equal argi "-no-site-file") |
4e0a3971 | 773 | (setq site-run-file nil)) |
a726e0d1 | 774 | ((string-equal argi "-debug-init") |
4e0a3971 | 775 | (setq init-file-debug t)) |
a360cae9 | 776 | ((string-equal argi "-iconic") |
4e0a3971 | 777 | (push '(visibility . icon) initial-frame-alist)) |
a360cae9 RS |
778 | ((or (string-equal argi "-icon-type") |
779 | (string-equal argi "-i") | |
780 | (string-equal argi "-itype")) | |
4e0a3971 SM |
781 | (push '(icon-type . t) default-frame-alist)) |
782 | ;; Push the popped arg back on the list of arguments. | |
783 | (t (push argi args) (setq done t))) | |
096b7031 KH |
784 | ;; Was argval set but not used? |
785 | (and argval | |
786 | (error "Option `%s' doesn't allow an argument" argi)))) | |
787 | ||
03e3c30a | 788 | ;; Re-attach the program name to the front of the arg list. |
4048e56d | 789 | (and command-line-args (setcdr command-line-args args))) |
a726e0d1 | 790 | |
c722566c | 791 | ;; Under X Windows, this creates the X frame and deletes the terminal frame. |
14f16b9c GM |
792 | (when (fboundp 'frame-initialize) |
793 | (frame-initialize)) | |
794 | ||
1fe0333f | 795 | ;; If frame was created with a menu bar, set menu-bar-mode on. |
ffaf8bbb SM |
796 | (if (and (not noninteractive) |
797 | (or (not (memq window-system '(x w32))) | |
4e0a3971 | 798 | (> (frame-parameter nil 'menu-bar-lines) 0))) |
1fe0333f | 799 | (menu-bar-mode t)) |
c722566c | 800 | |
7d1eb6a4 GM |
801 | ;; If frame was created with a tool bar, switch tool-bar-mode on. |
802 | (when (and (not noninteractive) | |
66c24e1e | 803 | (display-graphic-p) |
7d1eb6a4 | 804 | (> (frame-parameter nil 'tool-bar-lines) 0)) |
b66b6aeb | 805 | (tool-bar-mode 1)) |
7d1eb6a4 | 806 | |
6753393b GM |
807 | ;; Can't do this init in defcustom because window-system isn't set. |
808 | (when (and (not noninteractive) | |
809 | (not (eq system-type 'ms-dos)) | |
810 | (memq window-system '(x w32))) | |
811 | (setq-default blink-cursor t) | |
812 | (blink-cursor-mode 1)) | |
813 | ||
3ecd8ad0 GM |
814 | (unless noninteractive |
815 | ;; DOS/Windows systems have a PC-type keyboard which has both | |
816 | ;; <delete> and <backspace> keys. | |
817 | (when (or (memq system-type '(ms-dos windows-nt)) | |
818 | (and (memq window-system '(x)) | |
819 | (fboundp 'x-backspace-delete-keys-p) | |
7360b8aa GM |
820 | (x-backspace-delete-keys-p)) |
821 | ;; If the terminal Emacs is running on has erase char | |
822 | ;; set to ^H, use the Backspace key for deleting | |
823 | ;; backward and, and the Delete key for deleting forward. | |
824 | (and (null window-system) | |
825 | (eq tty-erase-char 8))) | |
d8e17bc6 EZ |
826 | (setq-default normal-erase-is-backspace t) |
827 | (normal-erase-is-backspace-mode 1))) | |
14f076a8 | 828 | |
3b73087e GM |
829 | (when (and (not noninteractive) |
830 | (display-graphic-p) | |
831 | (fboundp 'x-show-tip)) | |
832 | (setq-default tooltip-mode t) | |
833 | (tooltip-mode 1)) | |
834 | ||
1592c1ef EZ |
835 | ;; Register default TTY colors for the case the terminal hasn't a |
836 | ;; terminal init file. | |
837 | (or (memq window-system '(x w32)) | |
8957d2bf EZ |
838 | ;; We do this regardles of whether the terminal supports colors |
839 | ;; or not, since they can switch that support on or off in | |
840 | ;; mid-session by setting the tty-color-mode frame parameter. | |
d4bc31e9 | 841 | (tty-register-default-colors)) |
1592c1ef | 842 | |
3a55d3d0 JR |
843 | ;; Record whether the tool-bar is present before the user and site |
844 | ;; init files are processed. frame-notice-user-settings uses this | |
845 | ;; to determine if the tool-bar has been disabled by the init files, | |
846 | ;; and the frame needs to be resized. | |
847 | (when (fboundp 'frame-notice-user-settings) | |
848 | (let ((tool-bar-lines (or (assq 'tool-bar-lines initial-frame-alist) | |
849 | (assq 'tool-bar-lines default-frame-alist)))) | |
850 | (setq tool-bar-originally-present | |
851 | (not (or (null tool-bar-lines) | |
852 | (null (cdr tool-bar-lines)) | |
6811051d | 853 | (eq 0 (cdr tool-bar-lines))))))) |
3a55d3d0 | 854 | |
752ef254 GM |
855 | (let ((old-scalable-fonts-allowed scalable-fonts-allowed) |
856 | (old-font-list-limit font-list-limit) | |
857 | (old-face-ignored-fonts face-ignored-fonts)) | |
858 | ||
859 | (run-hooks 'before-init-hook) | |
860 | ||
861 | ;; Run the site-start library if it exists. The point of this file is | |
862 | ;; that it is run before .emacs. There is no point in doing this after | |
863 | ;; .emacs; that is useless. | |
864 | (if site-run-file | |
865 | (load site-run-file t t)) | |
866 | ||
867 | ;; Sites should not disable this. Only individuals should disable | |
868 | ;; the startup message. | |
869 | (setq inhibit-startup-message nil) | |
870 | ||
871 | ;; Load that user's init file, or the default one, or none. | |
872 | (let (debug-on-error-from-init-file | |
873 | debug-on-error-should-be-set | |
874 | (debug-on-error-initial | |
875 | (if (eq init-file-debug t) 'startup init-file-debug)) | |
876 | (orig-enable-multibyte default-enable-multibyte-characters)) | |
877 | (let ((debug-on-error debug-on-error-initial) | |
878 | ;; This function actually reads the init files. | |
879 | (inner | |
880 | (function | |
881 | (lambda () | |
882 | (if init-file-user | |
883 | (let ((user-init-file-1 | |
4e0a3971 | 884 | (cond |
752ef254 GM |
885 | ((eq system-type 'ms-dos) |
886 | (concat "~" init-file-user "/_emacs")) | |
887 | ((eq system-type 'windows-nt) | |
888 | (if (directory-files "~" nil "^\\.emacs\\(\\.elc?\\)?$") | |
889 | "~/.emacs" | |
890 | "~/_emacs")) | |
891 | ((eq system-type 'vax-vms) | |
892 | "sys$login:.emacs") | |
4e0a3971 | 893 | (t |
752ef254 GM |
894 | (concat "~" init-file-user "/.emacs"))))) |
895 | ;; This tells `load' to store the file name found | |
896 | ;; into user-init-file. | |
897 | (setq user-init-file t) | |
898 | (load user-init-file-1 t t) | |
899 | ||
900 | ;; If we did not find the user's init file, | |
901 | ;; set user-init-file conclusively to nil; | |
902 | ;; don't let it be set from default.el. | |
903 | (if (eq user-init-file t) | |
4e0a3971 | 904 | (setq user-init-file user-init-file-1)) |
752ef254 GM |
905 | |
906 | ;; If we loaded a compiled file, set | |
907 | ;; `user-init-file' to the source version if that | |
908 | ;; exists. | |
909 | (when (and user-init-file | |
910 | (equal (file-name-extension user-init-file) | |
911 | "elc")) | |
912 | (let* ((source (file-name-sans-extension user-init-file)) | |
913 | (alt (concat source ".el"))) | |
914 | (setq source (cond ((file-exists-p alt) alt) | |
915 | ((file-exists-p source) source) | |
916 | (t nil))) | |
917 | (when source | |
918 | (when (file-newer-than-file-p source user-init-file) | |
919 | (message "Warning: %s is newer than %s" | |
920 | source user-init-file) | |
921 | (sit-for 1)) | |
922 | (setq user-init-file source)))) | |
923 | ||
924 | (or inhibit-default-init | |
925 | (let ((inhibit-startup-message nil)) | |
926 | ;; Users are supposed to be told their rights. | |
927 | ;; (Plus how to get help and how to undo.) | |
928 | ;; Don't you dare turn this off for anyone | |
929 | ;; except yourself. | |
930 | (load "default" t t))))))))) | |
931 | (if init-file-debug | |
932 | ;; Do this without a condition-case if the user wants to debug. | |
933 | (funcall inner) | |
934 | (condition-case error | |
935 | (progn | |
936 | (funcall inner) | |
937 | (setq init-file-had-error nil)) | |
938 | (error | |
939 | (let ((message-log-max nil)) | |
940 | (save-excursion | |
941 | (set-buffer (get-buffer-create "*Messages*")) | |
942 | (insert "\n\n" | |
943 | (format "An error has occurred while loading `%s':\n\n" | |
944 | user-init-file) | |
945 | (format "%s%s%s" | |
946 | (get (car error) 'error-message) | |
947 | (if (cdr error) ": " "") | |
948 | (mapconcat 'prin1-to-string (cdr error) ", ")) | |
949 | "\n\n" | |
950 | "To ensure normal operation, you should investigate the cause\n" | |
951 | "of the error in your initialization file and remove it. Start\n" | |
952 | "Emacs with the `--debug-init' option to view a complete error\n" | |
953 | "backtrace\n")) | |
954 | (message "Error in init file: %s%s%s" | |
955 | (get (car error) 'error-message) | |
956 | (if (cdr error) ": " "") | |
957 | (mapconcat 'prin1-to-string (cdr error) ", ")) | |
958 | (pop-to-buffer "*Messages*") | |
959 | (setq init-file-had-error t))))) | |
ac3186fd RS |
960 | |
961 | ;; If the user has a file of abbrevs, read it. | |
962 | (if (file-exists-p abbrev-file-name) | |
963 | (quietly-read-abbrev-file abbrev-file-name)) | |
964 | ||
70b199c3 RS |
965 | ;; If the abbrevs came entirely from the init file or the |
966 | ;; abbrevs file, they do not need saving. | |
967 | (setq abbrevs-changed nil) | |
968 | ||
752ef254 GM |
969 | ;; If we can tell that the init file altered debug-on-error, |
970 | ;; arrange to preserve the value that it set up. | |
971 | (or (eq debug-on-error debug-on-error-initial) | |
972 | (setq debug-on-error-should-be-set t | |
973 | debug-on-error-from-init-file debug-on-error))) | |
974 | (if debug-on-error-should-be-set | |
975 | (setq debug-on-error debug-on-error-from-init-file)) | |
976 | (unless (or default-enable-multibyte-characters | |
977 | (eq orig-enable-multibyte default-enable-multibyte-characters)) | |
978 | ;; Init file changed to unibyte. Reset existing multibyte | |
979 | ;; buffers (probably *scratch*, *Messages*, *Minibuff-0*). | |
980 | ;; Arguably this should only be done if they're free of | |
981 | ;; multibyte characters. | |
982 | (mapcar (lambda (buffer) | |
983 | (with-current-buffer buffer | |
984 | (if enable-multibyte-characters | |
985 | (set-buffer-multibyte nil)))) | |
986 | (buffer-list)) | |
987 | ;; Also re-set the language environment in case it was | |
988 | ;; originally done before unibyte was set and is sensitive to | |
989 | ;; unibyte (display table, terminal coding system &c). | |
990 | (set-language-environment current-language-environment))) | |
991 | ||
992 | ;; Do this here in case the init file sets mail-host-address. | |
993 | (or user-mail-address | |
994 | (setq user-mail-address (concat (user-login-name) "@" | |
995 | (or mail-host-address | |
996 | (system-name))))) | |
997 | ||
998 | ;; If parameter have been changed in the init file which influence | |
999 | ;; face realization, clear the face cache so that new faces will | |
1000 | ;; be realized. | |
1001 | (unless (and (eq scalable-fonts-allowed old-scalable-fonts-allowed) | |
1002 | (eq font-list-limit old-font-list-limit) | |
1003 | (eq face-ignored-fonts old-face-ignored-fonts)) | |
1004 | (clear-face-cache))) | |
1005 | ||
e3bd99f5 RM |
1006 | (run-hooks 'after-init-hook) |
1007 | ||
a726e0d1 JB |
1008 | ;; If *scratch* exists and init file didn't change its mode, initialize it. |
1009 | (if (get-buffer "*scratch*") | |
1010 | (save-excursion | |
1011 | (set-buffer "*scratch*") | |
1012 | (if (eq major-mode 'fundamental-mode) | |
1013 | (funcall initial-major-mode)))) | |
e724900d | 1014 | |
a726e0d1 JB |
1015 | ;; Load library for our terminal type. |
1016 | ;; User init file can set term-file-prefix to nil to prevent this. | |
1017 | (and term-file-prefix (not noninteractive) (not window-system) | |
1018 | (let ((term (getenv "TERM")) | |
1019 | hyphend) | |
1020 | (while (and term | |
1021 | (not (load (concat term-file-prefix term) t t))) | |
1022 | ;; Strip off last hyphen and what follows, then try again | |
1023 | (if (setq hyphend (string-match "[-_][^-_]+$" term)) | |
1024 | (setq term (substring term 0 hyphend)) | |
1025 | (setq term nil))))) | |
1026 | ||
03e3c30a | 1027 | ;; Process the remaining args. |
a726e0d1 JB |
1028 | (command-line-1 (cdr command-line-args)) |
1029 | ||
1030 | ;; If -batch, terminate after processing the command options. | |
1031 | (if noninteractive (kill-emacs t))) | |
1032 | ||
46cfd295 | 1033 | (defcustom initial-scratch-message (purecopy "\ |
3b79c219 GM |
1034 | ;; This buffer is for notes you don't want to save, and for Lisp evaluation. |
1035 | ;; If you want to create a file, visit that file with C-x C-f, | |
1036 | ;; then enter the text in that file's own buffer. | |
9fe3219e | 1037 | |
46cfd295 | 1038 | ") |
9fe3219e RS |
1039 | "Initial message displayed in *scratch* buffer at startup. |
1040 | If this is nil, no message will be displayed." | |
fa071a47 RS |
1041 | :type '(choice (text :tag "Message") |
1042 | (const :tag "none" nil)) | |
1043 | :group 'initialization) | |
9fe3219e | 1044 | |
ce9ded5d GM |
1045 | \f |
1046 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
1047 | ;;; Fancy splash screen | |
1048 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
1049 | ||
1050 | (defvar fancy-splash-text | |
26ff68aa | 1051 | '((:face variable-pitch |
926aa0ee | 1052 | "You can do basic editing with the menu bar and scroll bar \ |
926aa0ee | 1053 | using the mouse.\n\n" |
26ff68aa | 1054 | :face (variable-pitch :weight bold) |
ce9ded5d | 1055 | "Important Help menu items:\n" |
26ff68aa | 1056 | :face variable-pitch "\ |
d7618b60 | 1057 | Emacs Tutorial\tLearn-by-doing tutorial for using Emacs efficiently |
1fc02b3c GM |
1058 | Emacs FAQ\tFrequently asked questions and answers |
1059 | \(Non)Warranty\tGNU Emacs comes with " | |
26ff68aa | 1060 | :face (variable-pitch :slant oblique) |
ce9ded5d | 1061 | "ABSOLUTELY NO WARRANTY\n" |
26ff68aa | 1062 | :face variable-pitch |
d3c5bad2 | 1063 | "\ |
d7618b60 GM |
1064 | Copying Conditions\tConditions for redistributing and changing Emacs |
1065 | Ordering Manuals\tHow to order Emacs manuals from the Free Software Foundation\n") | |
1066 | (:face variable-pitch | |
1067 | "You can do basic editing with the menu bar and scroll bar \ | |
1068 | using the mouse.\n\n" | |
1069 | :face (variable-pitch :weight bold) | |
1070 | "Useful File menu items:\n" | |
1071 | :face variable-pitch "\ | |
1072 | Exit Emacs\t(Or type Control-x followed by Control-c) | |
1073 | Recover Session\tRecover files you were editing before a crash | |
1074 | ||
1075 | ||
1076 | ||
1077 | " | |
1078 | )) | |
ce9ded5d GM |
1079 | "A list of texts to show in the middle part of splash screens. |
1080 | Each element in the list should be a list of strings or pairs | |
1081 | `:face FACE', like `fancy-splash-insert' accepts them.") | |
1082 | ||
1083 | ||
fb275c02 | 1084 | (defgroup fancy-splash-screen () |
a01bb1db | 1085 | "Fancy splash screen when Emacs starts." |
fb275c02 | 1086 | :version "21.1" |
a01bb1db GM |
1087 | :group 'initialization) |
1088 | ||
1089 | ||
e9da51a1 | 1090 | (defcustom fancy-splash-delay 10 |
49939379 | 1091 | "*Delay in seconds between splash screens." |
a01bb1db | 1092 | :group 'fancy-splash-screen |
ce9ded5d GM |
1093 | :type 'integer) |
1094 | ||
1095 | ||
e9da51a1 GM |
1096 | (defcustom fancy-splash-max-time 60 |
1097 | "*Show splash screens for at most this number of seconds. | |
1098 | Values less than 60 seconds are ignored." | |
1099 | :group 'fancy-splash-screen | |
1100 | :type 'integer) | |
1101 | ||
1102 | ||
8ad8561b GM |
1103 | (defcustom fancy-splash-image nil |
1104 | "*The image to show in the splash screens, or nil for defaults." | |
a01bb1db | 1105 | :group 'fancy-splash-screen |
8ad8561b GM |
1106 | :type '(choice (const :tag "Default" nil) |
1107 | (file :tag "File"))) | |
ce9ded5d GM |
1108 | |
1109 | ||
f645586f GM |
1110 | ;; These are temporary storage areas for the splash screen display. |
1111 | ||
1112 | (defvar fancy-current-text nil) | |
1113 | (defvar fancy-splash-help-echo nil) | |
e9da51a1 | 1114 | (defvar fancy-splash-stop-time nil) |
eae91b60 | 1115 | (defvar fancy-splash-outer-buffer nil) |
f645586f | 1116 | |
ce9ded5d GM |
1117 | (defun fancy-splash-insert (&rest args) |
1118 | "Insert text into the current buffer, with faces. | |
1119 | Arguments from ARGS should be either strings or pairs `:face FACE', | |
1120 | where FACE is a valid face specification, as it can be used with | |
1121 | `put-text-properties'." | |
1122 | (let ((current-face nil)) | |
1123 | (while args | |
1124 | (if (eq (car args) :face) | |
1125 | (setq args (cdr args) current-face (car args)) | |
f645586f GM |
1126 | (insert (propertize (car args) |
1127 | 'face current-face | |
1128 | 'help-echo fancy-splash-help-echo))) | |
ce9ded5d GM |
1129 | (setq args (cdr args))))) |
1130 | ||
1131 | ||
1132 | (defun fancy-splash-head () | |
1133 | "Insert the head part of the splash screen into the current buffer." | |
51e8cfdd GM |
1134 | (let* ((image-file (cond ((stringp fancy-splash-image) |
1135 | fancy-splash-image) | |
1136 | ((and (display-color-p) | |
1137 | (image-type-available-p 'xpm)) | |
1138 | (if (and (fboundp 'x-display-planes) | |
1139 | (= (funcall 'x-display-planes) 8)) | |
1140 | "splash8.xpm" | |
1141 | "splash.xpm")) | |
1142 | (t "splash.pbm"))) | |
1143 | (img (create-image image-file)) | |
ce9ded5d GM |
1144 | (image-width (and img (car (image-size img)))) |
1145 | (window-width (window-width (selected-window)))) | |
1146 | (when img | |
1147 | (when (> window-width image-width) | |
f645586f | 1148 | ;; Center the image in the window. |
ce9ded5d GM |
1149 | (let ((pos (/ (- window-width image-width) 2))) |
1150 | (insert (propertize " " 'display `(space :align-to ,pos)))) | |
f645586f | 1151 | |
e7f3afa9 MB |
1152 | ;; Change the color of the XPM version of the splash image |
1153 | ;; so that it is visible with a dark frame background. | |
1154 | (when (and (memq 'xpm img) | |
1155 | (eq (frame-parameter nil 'background-mode) 'dark)) | |
1156 | (setq img (append img '(:color-symbols (("#000000" . "gray30")))))) | |
1157 | ||
f645586f GM |
1158 | ;; Insert the image with a help-echo and a keymap. |
1159 | (let ((map (make-sparse-keymap)) | |
a622451f | 1160 | (help-echo "mouse-2: browse http://www.gnu.org/")) |
f645586f GM |
1161 | (define-key map [mouse-2] |
1162 | (lambda () | |
1163 | (interactive) | |
a622451f | 1164 | (browse-url "http://www.gnu.org/") |
f645586f GM |
1165 | (throw 'exit nil))) |
1166 | (define-key map [down-mouse-2] 'ignore) | |
1167 | (define-key map [up-mouse-2] 'ignore) | |
1168 | (insert-image img (propertize "xxx" 'help-echo help-echo | |
1169 | 'keymap map))) | |
ce9ded5d | 1170 | (insert "\n")))) |
b831c087 GM |
1171 | (if (eq system-type 'gnu/linux) |
1172 | (fancy-splash-insert | |
1173 | :face '(variable-pitch :foreground "red") | |
1174 | "GNU Emacs is one component of a Linux-based GNU system.") | |
ce9ded5d GM |
1175 | (fancy-splash-insert |
1176 | :face '(variable-pitch :foreground "red") | |
b831c087 | 1177 | "GNU Emacs is one component of the GNU operating system.")) |
eae91b60 RS |
1178 | (insert "\n") |
1179 | (unless (equal (buffer-name fancy-splash-outer-buffer) "*scratch*") | |
1180 | (fancy-splash-insert :face 'variable-pitch | |
1181 | (substitute-command-keys | |
1182 | "Type \\[recenter] to begin editing your file.\n")))) | |
ce9ded5d GM |
1183 | |
1184 | ||
1185 | (defun fancy-splash-tail () | |
1186 | "Insert the tail part of the splash screen into the current buffer." | |
95fadcca GM |
1187 | (let ((fg (if (eq (frame-parameter nil 'background-mode) 'dark) |
1188 | "cyan" "darkblue"))) | |
1189 | (fancy-splash-insert :face `(variable-pitch :foreground ,fg) | |
1190 | "\nThis is " | |
1191 | (emacs-version) | |
1192 | "\n" | |
1193 | :face '(variable-pitch :height 0.5) | |
ed638cc9 RS |
1194 | "Copyright (C) 2001 Free Software Foundation, Inc.") |
1195 | (and auto-save-list-file-prefix | |
1196 | ;; Don't signal an error if the | |
1197 | ;; directory for auto-save-list files | |
1198 | ;; does not yet exist. | |
1199 | (file-directory-p (file-name-directory | |
1200 | auto-save-list-file-prefix)) | |
1201 | (directory-files | |
1202 | (file-name-directory auto-save-list-file-prefix) | |
1203 | nil | |
1204 | (concat "\\`" | |
1205 | (regexp-quote (file-name-nondirectory | |
1206 | auto-save-list-file-prefix))) | |
1207 | t) | |
1208 | (fancy-splash-insert :face '(variable-pitch :foreground "red") | |
1209 | "\n\nIf an Emacs session crashed recently, " | |
1210 | "type M-x recover-session RET\nto recover" | |
1211 | " the files you were editing.")))) | |
ce9ded5d | 1212 | |
f645586f GM |
1213 | (defun fancy-splash-screens-1 (buffer) |
1214 | "Timer function displaying a splash screen." | |
e9da51a1 GM |
1215 | (when (> (float-time) fancy-splash-stop-time) |
1216 | (throw 'stop-splashing nil)) | |
f645586f GM |
1217 | (unless fancy-current-text |
1218 | (setq fancy-current-text fancy-splash-text)) | |
1219 | (let ((text (car fancy-current-text))) | |
1220 | (set-buffer buffer) | |
1221 | (erase-buffer) | |
1222 | (fancy-splash-head) | |
1223 | (apply #'fancy-splash-insert text) | |
1224 | (fancy-splash-tail) | |
1225 | (unless (current-message) | |
1226 | (message fancy-splash-help-echo)) | |
1227 | (set-buffer-modified-p nil) | |
dbeb499b | 1228 | (goto-char (point-min)) |
f645586f GM |
1229 | (force-mode-line-update) |
1230 | (setq fancy-current-text (cdr fancy-current-text)))) | |
1231 | ||
1232 | ||
1233 | (defun fancy-splash-default-action () | |
1234 | "Default action for events in the splash screen buffer." | |
1235 | (interactive) | |
1236 | (push last-command-event unread-command-events) | |
1237 | (throw 'exit nil)) | |
1238 | ||
1239 | ||
ce9ded5d | 1240 | (defun fancy-splash-screens () |
f645586f | 1241 | "Display fancy splash screens when Emacs starts." |
5b61c6a7 | 1242 | (setq fancy-splash-help-echo (startup-echo-area-message)) |
848c7757 | 1243 | (let ((old-hourglass display-hourglass) |
eae91b60 RS |
1244 | (fancy-splash-outer-buffer (current-buffer)) |
1245 | splash-buffer | |
ff4ec1f7 | 1246 | (old-minor-mode-map-alist minor-mode-map-alist) |
5b61c6a7 | 1247 | timer) |
eae91b60 | 1248 | (switch-to-buffer "GNU Emacs") |
7df56142 | 1249 | (setq tab-width 20) |
eae91b60 | 1250 | (setq splash-buffer (current-buffer)) |
e9da51a1 GM |
1251 | (catch 'stop-splashing |
1252 | (unwind-protect | |
56d9d0ed | 1253 | (let ((map (make-sparse-keymap))) |
e9da51a1 GM |
1254 | (use-local-map map) |
1255 | (define-key map [t] 'fancy-splash-default-action) | |
1256 | (define-key map [mouse-movement] 'ignore) | |
e85e809a | 1257 | (define-key map [mode-line t] 'ignore) |
e9da51a1 | 1258 | (setq cursor-type nil |
848c7757 | 1259 | display-hourglass nil |
ff4ec1f7 | 1260 | minor-mode-map-alist nil |
e9da51a1 | 1261 | buffer-undo-list t |
e85e809a GM |
1262 | mode-line-format (propertize "---- %b %-" |
1263 | 'face '(:weight bold)) | |
e9da51a1 GM |
1264 | fancy-splash-stop-time (+ (float-time) |
1265 | (max 60 fancy-splash-max-time)) | |
1266 | timer (run-with-timer 0 fancy-splash-delay | |
1267 | #'fancy-splash-screens-1 | |
1268 | splash-buffer)) | |
1269 | (recursive-edit)) | |
1270 | (cancel-timer timer) | |
ff4ec1f7 GM |
1271 | (setq display-hourglass old-hourglass |
1272 | minor-mode-map-alist old-minor-mode-map-alist) | |
51e8cfdd | 1273 | (kill-buffer splash-buffer))))) |
f645586f GM |
1274 | |
1275 | ||
285991dc GM |
1276 | (defun use-fancy-splash-screens-p () |
1277 | "Return t if fancy splash screens should be used." | |
1278 | (when (or (and (display-color-p) | |
1279 | (image-type-available-p 'xpm)) | |
1280 | (image-type-available-p 'pbm)) | |
1281 | (let* ((img (create-image (or fancy-splash-image | |
1282 | (if (and (display-color-p) | |
1283 | (image-type-available-p 'xpm)) | |
1284 | "splash.xpm" "splash.pbm")))) | |
1285 | (image-height (and img (cdr (image-size img)))) | |
1286 | (window-height (1- (window-height (selected-window))))) | |
d7618b60 | 1287 | (> window-height (+ image-height 15))))) |
285991dc GM |
1288 | |
1289 | ||
f645586f GM |
1290 | (defun startup-echo-area-message () |
1291 | (if (eq (key-binding "\C-h\C-p") 'describe-project) | |
1292 | "For information about the GNU Project and its goals, type C-h C-p." | |
1293 | (substitute-command-keys | |
1294 | "For information about the GNU Project and its goals, type \ | |
1295 | \\[describe-project]."))) | |
ce9ded5d GM |
1296 | |
1297 | ||
49939379 | 1298 | (defun display-startup-echo-area-message () |
15fa6db0 GM |
1299 | (let ((resize-mini-windows t)) |
1300 | (message (startup-echo-area-message)))) | |
f645586f | 1301 | |
49939379 | 1302 | |
a726e0d1 | 1303 | (defun command-line-1 (command-line-args-left) |
52320897 | 1304 | (or noninteractive (input-pending-p) init-file-had-error |
ed638cc9 RS |
1305 | ;; t if the init file says to inhibit the echo area startup message. |
1306 | (and inhibit-startup-echo-area-message | |
1307 | user-init-file | |
1308 | (or (and (get 'inhibit-startup-echo-area-message 'saved-value) | |
1309 | (equal inhibit-startup-echo-area-message | |
1310 | (if (string= init-file-user "") | |
1311 | (user-login-name) | |
1312 | init-file-user))) | |
1313 | ;; Wasn't set with custom; see if .emacs has a setq. | |
1314 | (let ((buffer (get-buffer-create " *temp*"))) | |
1315 | (prog1 | |
1316 | (condition-case nil | |
1317 | (save-excursion | |
1318 | (set-buffer buffer) | |
1319 | (insert-file-contents user-init-file) | |
1320 | (re-search-forward | |
1321 | (concat | |
1322 | "([ \t\n]*setq[ \t\n]+" | |
1323 | "inhibit-startup-echo-area-message[ \t\n]+" | |
1324 | (regexp-quote | |
1325 | (prin1-to-string | |
1326 | (if (string= init-file-user "") | |
1327 | (user-login-name) | |
1328 | init-file-user))) | |
1329 | "[ \t\n]*)") | |
1330 | nil t)) | |
1331 | (error nil)) | |
1332 | (kill-buffer buffer))))) | |
1333 | (display-startup-echo-area-message)) | |
1334 | ||
1335 | ;; Delay 2 seconds after an init file error message | |
1336 | ;; was displayed, so user can read it. | |
1337 | (if init-file-had-error | |
1338 | (sit-for 2)) | |
1339 | ||
1340 | (if command-line-args-left | |
1341 | ;; We have command args; process them. | |
1342 | (let ((dir command-line-default-directory) | |
1343 | (file-count 0) | |
1344 | first-file-buffer | |
1345 | tem | |
1346 | just-files ;; t if this follows the magic -- option. | |
1347 | ;; This includes our standard options' long versions | |
1348 | ;; and long versions of what's on command-switch-alist. | |
1349 | (longopts | |
1350 | (append '(("--funcall") ("--load") ("--insert") ("--kill") | |
1351 | ("--directory") ("--eval") ("--execute") | |
1352 | ("--find-file") ("--visit") ("--file")) | |
1353 | (mapcar (lambda (elt) | |
1354 | (list (concat "-" (car elt)))) | |
1355 | command-switch-alist))) | |
1356 | (line 0) | |
1357 | (column 0)) | |
1358 | ||
1359 | ;; Add the long X options to longopts. | |
4e0a3971 SM |
1360 | (dolist (tem command-line-x-option-alist) |
1361 | (if (string-match "^--" (car tem)) | |
1362 | (push (list (car tem)) longopts))) | |
ed638cc9 RS |
1363 | |
1364 | ;; Loop, processing options. | |
1365 | (while (and command-line-args-left) | |
1366 | (let* ((argi (car command-line-args-left)) | |
1367 | (orig-argi argi) | |
1368 | argval completion | |
1369 | ;; List of directories specified in -L/--directory, | |
1370 | ;; in reverse of the order specified. | |
1371 | extra-load-path | |
1372 | (initial-load-path load-path)) | |
1373 | (setq command-line-args-left (cdr command-line-args-left)) | |
1374 | ||
1375 | ;; Do preliminary decoding of the option. | |
1376 | (if just-files | |
1377 | ;; After --, don't look for options; treat all args as files. | |
1378 | (setq argi "") | |
1379 | ;; Convert long options to ordinary options | |
1380 | ;; and separate out an attached option argument into argval. | |
1381 | (if (string-match "^--[^=]*=" argi) | |
1382 | (setq argval (substring argi (match-end 0)) | |
1383 | argi (substring argi 0 (1- (match-end 0))))) | |
1384 | (if (equal argi "--") | |
1385 | (setq completion nil) | |
1386 | (setq completion (try-completion argi longopts))) | |
1387 | (if (eq completion t) | |
1388 | (setq argi (substring argi 1)) | |
1389 | (if (stringp completion) | |
1390 | (let ((elt (assoc completion longopts))) | |
1391 | (or elt | |
1392 | (error "Option `%s' is ambiguous" argi)) | |
1393 | (setq argi (substring (car elt) 1))) | |
1394 | (setq argval nil argi orig-argi)))) | |
1395 | ||
1396 | ;; Execute the option. | |
1397 | (cond ((setq tem (assoc argi command-switch-alist)) | |
1398 | (if argval | |
1399 | (let ((command-line-args-left | |
1400 | (cons argval command-line-args-left))) | |
1401 | (funcall (cdr tem) argi)) | |
1402 | (funcall (cdr tem) argi))) | |
1403 | ||
4e0a3971 SM |
1404 | ((member argi '("-f" ;what the manual claims |
1405 | "-funcall" | |
1406 | "-e")) ; what the source used to say | |
ed638cc9 RS |
1407 | (if argval |
1408 | (setq tem (intern argval)) | |
1409 | (setq tem (intern (car command-line-args-left))) | |
1410 | (setq command-line-args-left (cdr command-line-args-left))) | |
1411 | (if (arrayp (symbol-function tem)) | |
1412 | (command-execute tem) | |
1413 | (funcall tem))) | |
1414 | ||
4e0a3971 | 1415 | ((member argi '("-eval" "-execute")) |
ed638cc9 RS |
1416 | (if argval |
1417 | (setq tem argval) | |
1418 | (setq tem (car command-line-args-left)) | |
1419 | (setq command-line-args-left (cdr command-line-args-left))) | |
1420 | (eval (read tem))) | |
1421 | ;; Set the default directory as specified in -L. | |
1422 | ||
4e0a3971 | 1423 | ((member argi '("-L" "-directory")) |
ed638cc9 RS |
1424 | (if argval |
1425 | (setq tem argval) | |
1426 | (setq tem (car command-line-args-left) | |
1427 | command-line-args-left (cdr command-line-args-left))) | |
1428 | (setq tem (command-line-normalize-file-name tem)) | |
1429 | (setq extra-load-path | |
1430 | (cons (expand-file-name tem) extra-load-path)) | |
1431 | (setq load-path (append (nreverse extra-load-path) | |
1432 | initial-load-path))) | |
1433 | ||
4e0a3971 | 1434 | ((member argi '("-l" "-load")) |
ed638cc9 RS |
1435 | (if argval |
1436 | (setq tem argval) | |
1437 | (setq tem (car command-line-args-left) | |
1438 | command-line-args-left (cdr command-line-args-left))) | |
1439 | (let ((file (command-line-normalize-file-name tem))) | |
1440 | ;; Take file from default dir if it exists there; | |
1441 | ;; otherwise let `load' search for it. | |
1442 | (if (file-exists-p (expand-file-name file)) | |
1443 | (setq file (expand-file-name file))) | |
1444 | (load file nil t))) | |
1445 | ||
1446 | ((string-equal argi "-insert") | |
1447 | (if argval | |
1448 | (setq tem argval) | |
1449 | (setq tem (car command-line-args-left) | |
1450 | command-line-args-left (cdr command-line-args-left))) | |
1451 | (or (stringp tem) | |
1452 | (error "File name omitted from `-insert' option")) | |
1453 | (insert-file-contents (command-line-normalize-file-name tem))) | |
1454 | ||
1455 | ((string-equal argi "-kill") | |
1456 | (kill-emacs t)) | |
1457 | ||
1458 | ((string-match "^\\+[0-9]+\\'" argi) | |
1459 | (setq line (string-to-int argi))) | |
1460 | ||
1461 | ((string-match "^\\+\\([0-9]+\\):\\([0-9]+\\)\\'" argi) | |
1462 | (setq line (string-to-int (match-string 1 argi)) | |
1463 | column (string-to-int (match-string 2 argi)))) | |
1464 | ||
1465 | ((setq tem (assoc argi command-line-x-option-alist)) | |
1466 | ;; Ignore X-windows options and their args if not using X. | |
1467 | (setq command-line-args-left | |
1468 | (nthcdr (nth 1 tem) command-line-args-left))) | |
1469 | ||
4e0a3971 | 1470 | ((member argi '("-find-file" "-file" "-visit")) |
ed638cc9 RS |
1471 | ;; An explicit option to specify visiting a file. |
1472 | (if argval | |
1473 | (setq tem argval) | |
1474 | (setq tem (car command-line-args-left) | |
1475 | command-line-args-left (cdr command-line-args-left))) | |
1476 | (unless (stringp tem) | |
1477 | (error "File name omitted from `%s' option" argi)) | |
1478 | (setq file-count (1+ file-count)) | |
1479 | (let ((file (expand-file-name | |
1480 | (command-line-normalize-file-name tem) dir))) | |
1481 | (if (= file-count 1) | |
1482 | (setq first-file-buffer (find-file file)) | |
1483 | (find-file-other-window file))) | |
1484 | (or (zerop line) | |
1485 | (goto-line line)) | |
1486 | (setq line 0) | |
1487 | (unless (< column 1) | |
1488 | (move-to-column (1- column))) | |
1489 | (setq column 0)) | |
1490 | ||
1491 | ((equal argi "--") | |
1492 | (setq just-files t)) | |
1493 | (t | |
1494 | ;; We have almost exhausted our options. See if the | |
1495 | ;; user has made any other command-line options available | |
1496 | (let ((hooks command-line-functions) ;; lrs 7/31/89 | |
1497 | (did-hook nil)) | |
1498 | (while (and hooks | |
1499 | (not (setq did-hook (funcall (car hooks))))) | |
1500 | (setq hooks (cdr hooks))) | |
1501 | (if (not did-hook) | |
1502 | ;; Ok, presume that the argument is a file name | |
1503 | (progn | |
1504 | (if (string-match "\\`-" argi) | |
1505 | (error "Unknown option `%s'" argi)) | |
1506 | (setq file-count (1+ file-count)) | |
1507 | (let ((file | |
1508 | (expand-file-name | |
1509 | (command-line-normalize-file-name orig-argi) | |
1510 | dir))) | |
1511 | (if (= file-count 1) | |
1512 | (setq first-file-buffer (find-file file)) | |
1513 | (find-file-other-window file))) | |
1514 | (or (zerop line) | |
1515 | (goto-line line)) | |
1516 | (setq line 0) | |
1517 | (unless (< column 1) | |
1518 | (move-to-column (1- column))) | |
1519 | (setq column 0)))))))) | |
1520 | ;; If 3 or more files visited, and not all visible, | |
1521 | ;; show user what they all are. But leave the last one current. | |
1522 | (and (> file-count 2) | |
1523 | (not noninteractive) | |
26780e5b | 1524 | (not inhibit-startup-buffer-menu) |
ed638cc9 | 1525 | (or (get-buffer-window first-file-buffer) |
eae91b60 RS |
1526 | (list-buffers))))) |
1527 | ||
1528 | ;; Maybe display a startup screen. | |
1529 | (when (and (not inhibit-startup-message) (not noninteractive) | |
1530 | ;; Don't display startup screen if init file | |
1531 | ;; has started some sort of server. | |
1532 | (not (and (fboundp 'process-list) | |
1533 | (process-list)))) | |
1534 | ;; Display a startup screen, after some preparations. | |
1535 | ||
1536 | ;; If there are no switches to process, we might as well | |
1537 | ;; run this hook now, and there may be some need to do it | |
1538 | ;; before doing any output. | |
1539 | (and term-setup-hook | |
1540 | (run-hooks 'term-setup-hook)) | |
1541 | ;; Don't let the hook be run twice. | |
1542 | (setq term-setup-hook nil) | |
1543 | ||
1544 | ;; It's important to notice the user settings before we | |
1545 | ;; display the startup message; otherwise, the settings | |
1546 | ;; won't take effect until the user gives the first | |
1547 | ;; keystroke, and that's distracting. | |
1548 | (when (fboundp 'frame-notice-user-settings) | |
1549 | (frame-notice-user-settings)) | |
1550 | ||
1551 | ;; If there are no switches to process, we might as well | |
1552 | ;; run this hook now, and there may be some need to do it | |
1553 | ;; before doing any output. | |
1554 | (when window-setup-hook | |
1555 | (run-hooks 'window-setup-hook) | |
1556 | ;; Don't let the hook be run twice. | |
1557 | (setq window-setup-hook nil)) | |
1558 | ||
1559 | ;; Do this now to avoid an annoying delay if the user | |
1560 | ;; clicks the menu bar during the sit-for. | |
1561 | (when (display-popup-menus-p) | |
1562 | (precompute-menubar-bindings)) | |
1563 | (setq menubar-bindings-done t) | |
ed638cc9 | 1564 | |
eae91b60 RS |
1565 | ;; If *scratch* is selected and it is empty, insert an |
1566 | ;; initial message saying not to create a file there. | |
1567 | (when (and initial-scratch-message | |
ed638cc9 | 1568 | (string= (buffer-name) "*scratch*") |
ed638cc9 | 1569 | (= 0 (buffer-size))) |
eae91b60 RS |
1570 | (insert initial-scratch-message) |
1571 | (set-buffer-modified-p nil)) | |
ed638cc9 | 1572 | |
eae91b60 RS |
1573 | ;; If user typed input during all that work, |
1574 | ;; abort the startup screen. Otherwise, display it now. | |
1575 | (let ((buffer (current-buffer))) | |
ed638cc9 | 1576 | (when (not (input-pending-p)) |
84403b77 RS |
1577 | (if (and (display-graphic-p) |
1578 | (use-fancy-splash-screens-p)) | |
1579 | (fancy-splash-screens) | |
1580 | (with-current-buffer (get-buffer-create "GNU Emacs") | |
0baffc68 RS |
1581 | (let ((tab-width 8) |
1582 | (mode-line-format (propertize "---- %b %-" | |
1583 | 'face '(:weight bold)))) | |
1584 | ||
ed638cc9 RS |
1585 | ;; The convention for this piece of code is that |
1586 | ;; each piece of output starts with one or two newlines | |
1587 | ;; and does not end with any newlines. | |
1588 | (insert "Welcome to GNU Emacs") | |
1589 | (if (eq system-type 'gnu/linux) | |
1590 | (insert ", one component of a Linux-based GNU system.")) | |
1591 | (insert "\n") | |
1592 | ||
eae91b60 RS |
1593 | (unless (equal (buffer-name buffer) "*scratch*") |
1594 | (insert (substitute-command-keys | |
1595 | "\nType \\[recenter] to begin editing your file.\n"))) | |
1596 | ||
ed638cc9 RS |
1597 | (if (display-mouse-p) |
1598 | ;; The user can use the mouse to activate menus | |
1599 | ;; so give help in terms of menu items. | |
1600 | (progn | |
1601 | (insert "\ | |
926aa0ee | 1602 | You can do basic editing with the menu bar and scroll bar using the mouse. |
acfd1011 | 1603 | |
347d0813 | 1604 | Useful File menu items: |
acfd1011 RS |
1605 | Exit Emacs (or type Control-x followed by Control-c) |
1606 | Recover Session recover files you were editing before a crash | |
1607 | ||
1608 | Important Help menu items: | |
1609 | Emacs Tutorial Learn-by-doing tutorial for using Emacs efficiently. | |
b11d37de | 1610 | Emacs FAQ Frequently asked questions and answers |
acfd1011 RS |
1611 | \(Non)Warranty GNU Emacs comes with ABSOLUTELY NO WARRANTY |
1612 | Copying Conditions Conditions for redistributing and changing Emacs. | |
1613 | Getting New Versions How to obtain the latest version of Emacs. | |
01459648 | 1614 | Ordering Manuals How to order manuals from the FSF. |
acfd1011 | 1615 | ") |
ed638cc9 RS |
1616 | (insert "\n\n" (emacs-version) |
1617 | " | |
1618 | Copyright (C) 2001 Free Software Foundation, Inc.")) | |
1619 | ||
1620 | ;; No mouse menus, so give help using kbd commands. | |
1621 | ||
1622 | ;; If keys have their default meanings, | |
1623 | ;; use precomputed string to save lots of time. | |
1624 | (if (and (eq (key-binding "\C-h") 'help-command) | |
1625 | (eq (key-binding "\C-xu") 'advertised-undo) | |
1626 | (eq (key-binding "\C-x\C-c") 'save-buffers-kill-emacs) | |
1627 | (eq (key-binding "\C-ht") 'help-with-tutorial) | |
1628 | (eq (key-binding "\C-hi") 'info) | |
1629 | (eq (key-binding "\C-h\C-n") 'view-emacs-news)) | |
1630 | (insert " | |
3f5a3e12 RS |
1631 | Get help C-h (Hold down CTRL and press h) |
1632 | Undo changes C-x u Exit Emacs C-x C-c | |
01459648 GM |
1633 | Get a tutorial C-h t Use Info to read docs C-h i |
1634 | Ordering manuals C-h RET") | |
ed638cc9 RS |
1635 | (insert (substitute-command-keys |
1636 | (format "\n | |
3f5a3e12 RS |
1637 | Get help %s |
1638 | Undo changes \\[advertised-undo] | |
1639 | Exit Emacs \\[save-buffers-kill-emacs] | |
1640 | Get a tutorial \\[help-with-tutorial] | |
01459648 GM |
1641 | Use Info to read docs \\[info] |
1642 | Ordering manuals \\[view-order-manuals]" | |
ed638cc9 RS |
1643 | (let ((where (where-is-internal |
1644 | 'help-command nil t))) | |
1645 | (if where | |
1646 | (key-description where) | |
1647 | "M-x help")))))) | |
1648 | ||
1649 | ;; Say how to use the menu bar with the keyboard. | |
1650 | (if (and (eq (key-binding "\M-`") 'tmm-menubar) | |
1651 | (eq (key-binding [f10]) 'tmm-menubar)) | |
1652 | (insert " | |
3f5a3e12 | 1653 | Activate menubar F10 or ESC ` or M-`") |
ed638cc9 | 1654 | (insert (substitute-command-keys " |
acfd1011 | 1655 | Activate menubar \\[tmm-menubar]"))) |
e65a6404 | 1656 | |
ed638cc9 RS |
1657 | ;; Many users seem to have problems with these. |
1658 | (insert " | |
3f5a3e12 RS |
1659 | \(`C-' means use the CTRL key. `M-' means use the Meta (or Alt) key. |
1660 | If you have no Meta key, you may instead type ESC followed by the character.)") | |
acfd1011 | 1661 | |
ed638cc9 RS |
1662 | (insert "\n\n" (emacs-version) |
1663 | " | |
30564c48 | 1664 | Copyright (C) 2001 Free Software Foundation, Inc.") |
ed638cc9 RS |
1665 | |
1666 | (if (and (eq (key-binding "\C-h\C-c") 'describe-copying) | |
1667 | (eq (key-binding "\C-h\C-d") 'describe-distribution) | |
1668 | (eq (key-binding "\C-h\C-w") 'describe-no-warranty)) | |
1669 | (insert | |
1670 | "\n | |
a726e0d1 | 1671 | GNU Emacs comes with ABSOLUTELY NO WARRANTY; type C-h C-w for full details. |
70e00413 KH |
1672 | Emacs is Free Software--Free as in Freedom--so you can redistribute copies |
1673 | of Emacs and modify it; type C-h C-c to see the conditions. | |
a726e0d1 | 1674 | Type C-h C-d for information on getting the latest version.") |
ed638cc9 RS |
1675 | (insert (substitute-command-keys |
1676 | "\n | |
a726e0d1 | 1677 | GNU Emacs comes with ABSOLUTELY NO WARRANTY; type \\[describe-no-warranty] for full details. |
70e00413 KH |
1678 | Emacs is Free Software--Free as in Freedom--so you can redistribute copies |
1679 | of Emacs and modify it; type \\[describe-copying] to see the conditions. | |
acfd1011 | 1680 | Type \\[describe-distribution] for information on getting the latest version.")))) |
ed638cc9 RS |
1681 | |
1682 | ;; The rest of the startup screen is the same on all | |
1683 | ;; kinds of terminals. | |
1684 | ||
1685 | ;; Give information on recovering, if there was a crash. | |
1686 | (and auto-save-list-file-prefix | |
1687 | ;; Don't signal an error if the | |
1688 | ;; directory for auto-save-list files | |
1689 | ;; does not yet exist. | |
1690 | (file-directory-p (file-name-directory | |
1691 | auto-save-list-file-prefix)) | |
1692 | (directory-files | |
1693 | (file-name-directory auto-save-list-file-prefix) | |
1694 | nil | |
1695 | (concat "\\`" | |
1696 | (regexp-quote (file-name-nondirectory | |
1697 | auto-save-list-file-prefix))) | |
1698 | t) | |
1699 | (insert "\n\nIf an Emacs session crashed recently, " | |
1700 | "type M-x recover-session RET\nto recover" | |
1701 | " the files you were editing.")) | |
1702 | ||
1703 | ;; Display the input that we set up in the buffer. | |
1704 | (set-buffer-modified-p nil) | |
1705 | (goto-char (point-min)) | |
1706 | (save-window-excursion | |
1707 | (switch-to-buffer (current-buffer)) | |
84403b77 RS |
1708 | (sit-for 120)))) |
1709 | (kill-buffer "GNU Emacs")))))) | |
c88ab9ce | 1710 | |
49939379 | 1711 | |
47c7adae RS |
1712 | (defun command-line-normalize-file-name (file) |
1713 | "Collapse multiple slashes to one, to handle non-Emacs file names." | |
6b9e794f RS |
1714 | (save-match-data |
1715 | ;; Use arg 1 so that we don't collapse // at the start of the file name. | |
1716 | ;; That is significant on some systems. | |
1717 | ;; However, /// at the beginning is supposed to mean just /, not //. | |
1718 | (if (string-match "^///+" file) | |
1719 | (setq file (replace-match "/" t t file))) | |
1720 | (while (string-match "//+" file 1) | |
1721 | (setq file (replace-match "/" t t file))) | |
1722 | file)) | |
47c7adae | 1723 | |
c88ab9ce | 1724 | ;;; startup.el ends here |