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