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