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