1 ;; -*- Mode: Emacs-Lisp -*-
3 ;; Copyright (C) 2000, 2001 Ben Wing.
5 ;; Author: Mostly Ben Wing <ben@xemacs.org>
6 ;; Maintainer: XEmacs Development Team
7 ;; Keywords: sample, initialization
9 ;; This file is part of XEmacs.
11 ;; XEmacs is free software; you can redistribute it and/or modify it
12 ;; under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; XEmacs is distributed in the hope that it will be useful, but
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ;; General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with XEmacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
27 ;; -- scan for #### markers and fix the problems noted there.
28 ;; -- #### maybe the setqs in this file should be changed to defvars
29 ;; to avoid tromping on customizations when custom.el is loaded
30 ;; early (dv and sjt at least favor making this the default)
31 ;; -- #### update documentation in (lispref)Starting Up XEmacs, in
32 ;; (xemacs)Entering Emacs, and in (custom), then point to them
33 ;; instead of going into detail here.
35 ;;; This is a sample init file. It can be used without modification
36 ;;; as your init.el or .emacs. In older versions of XEmacs, this file
37 ;;; was called .emacs and placed in your home directory. (Under MS
38 ;;; Windows, that directory is controlled by the HOME environment
39 ;;; variable and defaults to C:\. You can find out where XEmacs
40 ;;; thinks your home directory is using
42 ;;; ESC : (expand-file-name "~")
44 ;;; . This means type ESC, then colon, then the following text, then hit
45 ;;; return.) In more recent versions of XEmacs, this file has migrated to
46 ;;; the .xemacs/ subdirectory and is called init.el. Other files are
47 ;;; also located here, such as custom.el (the auto-generated file
48 ;;; containing Customization options that you saved when using
49 ;;; Options->Save Options).
51 ;;; Changes to your init.el file will not take effect until the next
52 ;;; time you start up XEmacs, unless you load it explicitly with
54 ;;; M-x load-file RET ~/.xemacs/init.el RET
56 ;;; The language that this file (and most other XEmacs init files) is
57 ;;; written in is called "XEmacs Lisp" or more commonly "Elisp".
59 ;;; Brief descriptions of how the init process works and how to
60 ;;; accomplish many useful customizations are given below in this
61 ;;; file. There are many sources of further information:
63 ;;; -- the XEmacs User's Manual (Access using the online Info browser:
64 ;;; Use `Help->Info (Online Docs)->XEmacs User's Manual' (if
65 ;;; there is such an entry); or get to the Info contents page
66 ;;; using `Help->Info Contents' or `C-h i', and then
67 ;;; *middle-click* the XEmacs link or move the cursor into the
68 ;;; link and hit ENTER. This manual contains a great deal of
69 ;;; documentation on customization: Scroll down to the
70 ;;; Customization link and select it in the same fashion as for
71 ;;; the XEmacs link just mentioned.)
73 ;;; -- the XEmacs FAQ (`C-h F' for the local version; get either the
74 ;;; local version or the very latest version off the net using
77 ;;; -- the XEmacs Lisp Reference Manual, containing detailed
78 ;;; documentation on Elisp. (Access using Info, just like for the
79 ;;; XEmacs User's Manual.)
81 ;;; -- the documentation strings for specific commands, functions,
82 ;;; key sequences, and variables. NOTE: This is *not* the same
83 ;;; information as in the XEmacs User's Manual or XEmacs Lisp
84 ;;; Reference Manual! In general, the doc strings are more
85 ;;; terse and more up-to-date than what is found in the manuals.
86 ;;; Once you understand the general concepts, these doc strings
87 ;;; should be your first point of reference for further
88 ;;; info. (Access using menu entries under `Help->Commands,
89 ;;; Variables, Keys' or using the keyboard: `C-h k' for a key
90 ;;; sequence, `C-h f' for a named command or Elisp function,
91 ;;; `C-h v' for a variable. There is various other useful
92 ;;; information accessible similarly, such as `C-h a'
93 ;;; ["Apropos", i.e. search for a command, function, or variable
94 ;;; by name]; `C-h C-a' ["Apropos Docs", i.e. search through the
95 ;;; text of the doc strings]; `C-h b' to list all key bindings;
96 ;;; `C-h m' to describe the current major and minor modes; etc.
97 ;;; Type `C-h ? ?' for a complete list.)
99 ;;; -- Getting Started with XEmacs [aka the "New User's Guide"], a
100 ;;; more introductory manual than the XEmacs User's Manual.
101 ;;; (Access using Info, just like for the XEmacs User's Manual.
102 ;;; There are some sections on customization here.)
104 ;;; -- the XEmacs tutorial, a very simple introduction to XEmacs for
105 ;;; total beginners. (`C-h t' for English; get the version in
106 ;;; various languages from the Help menu)
108 ;;; -- the XEmacs web site, www.xemacs.org.
110 ;;; -- the XEmacs mailing lists (xemacs-FOO@xemacs.org;
111 ;;; see http://www.xemacs.org/Lists/ for more info. Before
112 ;;; posting, consider looking through the archives -- they go back
113 ;;; years and there is a powerful searching interface. Currently
114 ;;; the archives are at http://list-archive.xemacs.org/, but if
115 ;;; this doesn't work, you can always access them through
118 ;;; -- the XEmacs newsgroup, comp.emacs.xemacs. This is
119 ;;; bi-directionally gatewayed with xemacs@xemacs.org. WARNING:
120 ;;; The developers do not normally hang out on this newsgroup. If
121 ;;; you need to contact them, use xemacs-beta@xemacs.org.
123 ;;; -- the XEmacs internals manual, for those interested in working on
124 ;;; the XEmacs C code. (Available through Info.)
126 ;;; -- `Help->About XEmacs' to find out who the maintainers are.
129 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
130 ;; Theory of Operation ;;
131 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
133 ;;; XEmacs allows you to make persistent changes to editor behavior by
134 ;;; saving code in files which are by default loaded at startup.
136 ;; These files are just Lisp libraries with names built in to XEmacs.
137 ;; There are files for the use of the user (the init file and the
138 ;; custom file), for the site administrator (default.el and
139 ;; site-start.el), and for the XEmacs maintainers (auto-autoloads
140 ;; files). See the Lispref for user and site files (node Starting Up
141 ;; XEmacs, currently inaccurate (it doesn't describe the custom
142 ;; file)). Interactions among the files are complex; see
143 ;; lisp/startup.el for details.
145 ;; Briefly, after very basic initializations including processing a
146 ;; special command line options (including GUI toolkit options),
147 ;; setting up the terminal, and setting up `load-path', it executes
148 ;; customization code as follows:
150 ;; 1. It runs the normal hook `before-init-hook'.
151 ;; 2. It loads the library `site-start' (by default `site-start.el').
152 ;; 3. It loads the init file (by default `~/.xemacs/init.el').
153 ;; 4. It loads the custom file (by default `~/.xemacs/custom.el').
154 ;; 5. It loads the library `default' (by default `default.el').
155 ;; 6. It runs the normal hook `after-init-hook'.
157 ;; After this the *scratch* buffer is set up and the remaining command
158 ;; line arguments (actions and file names) are processed.
160 ;; N.B. Switching the order of steps 3 and 4 is under discussion and
161 ;; favored by several core developers.
163 ;; Step 2 is inhibited by the -no-site-file command line switch.
164 ;; Steps 3 and 4 are inhibited (as a unit) by the -no-init-file
165 ;; command line switch (-q is a convenient synonym). Step 5 is
166 ;; inhibited by -no-init-file or a non-nil value of
167 ;; `inhibit-default-init' (set it in the init file). From now on the
168 ;; hooks and the site initialization files will be ignored.
170 ;; The custom file and the init file contain customizations managed by
171 ;; XEmacs itself via the Custom subsystem and manual customizations,
172 ;; respectively. Originally both were placed in the same file,
173 ;; usually ~/.emacs, but occasionally XEmacs would trash user settings
174 ;; when automatically changing options, and more frequently users
175 ;; would trash the automatically generated code. So these functions
176 ;; have been reallocated to separate files, usually named custom.el
177 ;; and init.el, respectively.
179 ;; The Custom system is accessed most conveniently from the
180 ;; Options->Advanced (Customize) menu (also, the Options->Fonts and
181 ;; Options->Sizes menus are implicitly managed by Custom, and
182 ;; Options->Edit Faces explicitly invokes Custom). You can also use
183 ;; the suite of customize commands directly (cf C-h a customize RET).
184 ;; Currently, Custom possesses specialized facilities for setting
185 ;; ordinary variables of many types, and for customizing faces. As a
186 ;; general rule, variable and face initialization should be done using
187 ;; Custom, and other initializations should be done in the init file.
189 ;; A possible exception is a subsystem with its own complex init file,
190 ;; eg, Gnus and .gnus. In these cases it is often preferable to keep
191 ;; even simple variable initializations together, and you may wish to
192 ;; maintain these configurations by hand.
194 ;; You should avoid editing the custom file by hand. The syntax used
195 ;; is complex but concise, and it is easy to silently break the whole
196 ;; file with a single error that happens to result in a valid Lisp
197 ;; form. On the other hand, the init file is just a Lisp library that
198 ;; is loaded before starting the read-eval-redisplay loop.
200 ;; The interactions between the custom file and other init files are
201 ;; governed by a simple idea:
203 ;; Custom to User: ALL VARIABLES YOURS OURS NOW ARE.
205 ;; To be precise, Custom is pretty good about noticing and respecting
206 ;; existing settings in interactive use. However, it is weak in
207 ;; understanding advanced use of specifier variables (these are used
208 ;; for customizations which depend on display characteristics and
209 ;; configuration in complex ways), and can be quite brutal at
212 ;; Normal practice for Custom at initialization is to (1) reset all
213 ;; customized faces before applying customizations and (2) force all
214 ;; variables to the values specified in custom.el. For this reason,
215 ;; and because it is generally the case that the init file can
216 ;; usefully depend on customized variables, but Custom pays no
217 ;; attention to behavior of the init file, it is probably a good idea
218 ;; to force custom.el to be loaded before the init file. (As
219 ;; mentioned, this will probably become the default in future versions
222 ;; To enable early loading of custom.el, uncomment the following line:
223 ;(setq Init-inhibit-custom-file-p (not (assoc custom-file load-history)))
225 ;; Code to implement early loading where late loading is the default.
226 ;; A crucial snippet of code must be the last thing in this file.
228 ;; defvars only initialize uninitialized variables; if the setq above
229 ;; is active, the variable below is defined but the value will not be
231 (defvar Init-inhibit-custom-file-p nil
232 "Internal user init flag. Don't use this yourself.
234 Non-nil if we need to inhibit XEmacs from loading custom.el after init.el.")
236 (when Init-inhibit-custom-file-p
237 ;; This is the default custom-file.
238 (let ((file (expand-file-name "~/.xemacs/custom.el")))
239 (add-one-shot-hook 'after-init-hook
240 `(lambda () (setq custom-file ,file)))
241 (cond ((file-readable-p file)
243 ((file-exists-p file)
244 (warn "Existing custom file \"%s\" is not readable!" file)))
245 (cond ((not (file-exists-p file))
246 (display-warning ' resource
247 (format "Custom file \"%s\" not found." file)
249 ((not (file-writable-p file))
250 (warn "Existing custom file \"%s\" is not writable!" file)))))
253 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
254 ;; Basic Customization ;;
255 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
257 ;; TIP: Control-L characters are ignored in Lisp files and are the
258 ;; standard way of indicating major section divisions. You can enter
259 ;; such a character using C-q C-l.
261 ;; Define a variable to indicate whether we're running XEmacs/Lucid
262 ;; Emacs. (You do not have to defvar a global variable before using
263 ;; it -- you can just call `setq' directly. It's clearer this way,
264 ;; though. Note also how we check if this variable already exists
265 ;; using `boundp', because it's defined in recent versions of
268 (or (boundp 'running-xemacs)
269 (defvar running-xemacs (string-match "XEmacs\\|Lucid" emacs-version)))
271 ;; Define a function to make it easier to check which version we're
272 ;; running. This function already exists in recent XEmacs versions,
273 ;; and in fact all we've done is copied the definition. Note again
274 ;; how we check to avoid clobbering an existing definition. (It's good
275 ;; style to do this, in case some improvement was made to the
276 ;; already-existing function -- otherwise we might substitute an older
277 ;; definition and possibly break some code elsewhere.)
279 ;; NOTE ALSO: It is in general *NOT* a good idea to do what we're
280 ;; doing -- i.e. provide a definition of a function that is present in
281 ;; newer versions of XEmacs but not older ones. The reason is that it
282 ;; may confuse code that notices the presence of the function and
283 ;; proceeds to use it and other functionality that goes along with it
284 ;; -- but which we may not have defined. What's better is to create
285 ;; the function with a different name -- typically, prefix it with the
286 ;; name of your module, which in this case might be `Init-'. For
287 ;; `emacs-version>=' we make an exception because (a) the function has
288 ;; been around a long time, (b) there isn't really any other
289 ;; functionality that is paired with it, (c) it's definition hasn't
290 ;; changed and isn't likely to, and (d) the calls to `emacs-version>='
291 ;; or its renamed replacement would be scattered throughout the code
292 ;; below, and with a replacement name the code would become
293 ;; significantly less portable into someone else's init.el file. (BUT
294 ;; NOTE BELOW: We do follow the procedure outlined above with renaming
295 ;; in a different case where the specifics are much different.)
297 ;; TIP: At this point you may be wondering how I wrote all these nice,
298 ;; long, nicely-justified textual stretches -- didn't I go crazy
299 ;; sticking in the semicolons everywhere and having to delete them and
300 ;; rearrange everything whenever I wanted to make any corrections to
301 ;; the text? The answer is -- of course not! Use M-q. This does all
302 ;; the magic for you, justifying and breaking lines appropriately and
303 ;; putting any necessary semicolons or whatever at the left (it
304 ;; figures out what this ought to be by looking in a very clever
305 ;; fashion at what's already at the beginning of each line in the
306 ;; paragraph). You may need `filladapt' set up (it's done below in
307 ;; this file) in order for this to work properly. Finally, if you
308 ;; want to turn on automatic filling (like in a word processor, but
309 ;; not quite as automatic), use M-x auto-fill-mode or the binding set
310 ;; up below in this file (Meta-F9).
312 (or (fboundp 'emacs-version>=)
313 (defun emacs-version>= (major &optional minor patch)
314 "Return true if the Emacs version is >= to the given MAJOR, MINOR,
316 The MAJOR version number argument is required, but the other arguments
317 argument are optional. Only the Non-nil arguments are used in the test."
318 (let ((emacs-patch (or emacs-patch-level emacs-beta-version -1)))
319 (cond ((> emacs-major-version major))
320 ((< emacs-major-version major) nil)
322 ((> emacs-minor-version minor))
323 ((< emacs-minor-version minor) nil)
325 ((>= emacs-patch patch))))))
327 ;; 19.13 was released ages ago (Sep. 1995), and lots of graphic and
328 ;; window-system stuff doesn't work before then.
330 (or (not running-xemacs)
331 (emacs-version>= 19 13)
332 (error "This init file does not support XEmacs before 19.13"))
334 ;; Here are some example code snippets that you can use if you need to
335 ;; conditionalize on a particular version of Emacs (in general, though,
336 ;; it is much better to use `fboundp', `featurep', or other such
337 ;; feature-specific checks rather than version-specific checks):
339 ; (cond ((and running-xemacs
340 ; (emacs-version>= 21 2))
342 ; ;; Code requiring XEmacs version 21.2 or newer goes here
346 ; (cond ((emacs-version >= 19 0)
348 ; ;; Code for any vintage-19 Emacs goes here
352 ; (cond ((and (not running-xemacs)
353 ; (emacs-version>= 20 0))
355 ; ;; Code specific to GNU Emacs 20 or newer (not XEmacs) goes here
359 (defun Init-safe-require (feat)
360 "Try to REQUIRE the specified feature. Errors occurring are silenced.
361 \(Perhaps in the future there will be a way to get at the error.)
362 Returns t if the feature was successfully required."
364 (progn (require feat) t)
368 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
369 ;; Key Definitions ;;
370 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
372 ;;; Set up the function keys to do common tasks to reduce Emacs pinky
375 ;; You can set a key sequence either to a command or to another key
376 ;; sequence. (Use `C-h k' to map a key sequence to its command. Use
377 ;; `C-h w' to go the other way.) In general, however, it works better
378 ;; to specify the command name. For example, it does not currently
381 ;; (global-set-key 'f5 "\C-x\C-f")
383 ;; The reason is that macros (which is what the string on the right
384 ;; really is) can't currently use the minibuffer. This is an
385 ;; extremely longstanding bug in Emacs. Eventually, it will be
386 ;; fixed. (Hopefully ..)
388 ;; Note also that you may sometimes see the idiom
390 ;; (define-key global-map ...)
392 ;; in place of (global-set-key ...). These are exactly the same.
394 ;; Here I've tried to put all the most common commands on simple
395 ;; non-modifier function keys to take the pressure off your modifier
396 ;; fingers. Furthermore, on my keyboard at least, the function keys
397 ;; are grouped into three groups of four with spaces between them, and
398 ;; so it's easier to hit the keys at the edge of the groups --
399 ;; i.e. f1, f4, f5, f8, f9, and f12. Finally, you may note that f9,
400 ;; f11, and f12 are purposely left blank. [F6 is defined below.]
401 ;; That's because I use them for _, {, and } -- see below.
403 (global-set-key 'f1 'advertised-undo) ;; Undo
404 (global-set-key 'f2 'kill-primary-selection) ;; Cut
405 (global-set-key 'f3 'copy-primary-selection) ;; Copy
406 (global-set-key 'f4 'yank-clipboard-selection) ;; Paste
407 (global-set-key 'f5 'find-file) ;; C-x C-f
408 (global-set-key 'f7 'save-buffer) ;; C-x C-s
410 ;; I considered having this retain the current column after killing
411 ;; the line, but that messes up the common idiom `f8 move-cursor f4'.
413 (defun Init-kill-entire-line (&optional arg)
414 "Kill the entire line.
415 With prefix argument, kill that many lines from point. Negative
416 arguments kill lines backward.
418 When calling from a program, nil means \"no arg\",
419 a number counts as a prefix arg."
421 (let ((kill-whole-line t))
423 (call-interactively 'kill-line)))
426 (if (fboundp 'kill-entire-line) 'kill-entire-line 'Init-kill-entire-line))
428 ;; A keystroke repeated incredible amounts of times. We need to patch
429 ;; into the isearch keymap so that repeat searches while in isearch
430 ;; mode still work. Here we show how to make a key in a keymap have the
431 ;; same binding as another key in the keymap, without knowing what the
432 ;; binding is in advance; instead, we find it with `lookup-key'. This
433 ;; way, if the binding of C-s changes (e.g. to a different function) but
434 ;; the meaning is basically the same, we automatically do the right thing.
435 ;; If we put in the actual binding, which is 'isearch-repeat-forward,
436 ;; this automatic tracking wouldn't happen.
438 ;; TIP: To find out what the (lookup-key ...) expression evaluates to,
439 ;; move just to the right of the closing paren and type C-x C-e.
441 (global-set-key 'f10 'isearch-forward)
442 (define-key isearch-mode-map 'f10 (lookup-key isearch-mode-map "\C-s"))
443 (define-key minibuffer-local-isearch-map 'f10
444 (lookup-key minibuffer-local-isearch-map "\C-s"))
445 (global-set-key '(shift f10) 'isearch-backward)
446 (define-key isearch-mode-map '(shift f10) (lookup-key isearch-mode-map "\C-r"))
447 (define-key minibuffer-local-isearch-map '(shift f10)
448 (lookup-key minibuffer-local-isearch-map "\C-r"))
450 ;; Here we define our own function and then bind a key to it.
452 (defun start-or-end-kbd-macro ()
453 ;; A doc string. This is optional.
454 "Start defining a keyboard macro, or stop if we're already defining."
455 ;; IMPORTANT: Any function bound to a key MUST have an interactive spec,
456 ;; usually just the following line:
458 (if defining-kbd-macro
460 (start-kbd-macro nil)))
462 ;; The macros used to have their place in the function keys, but I
463 ;; find that I use them significantly less than the really basic
464 ;; things on the function keys. When using a macro, you call the
465 ;; macro much more than define it, so the setup below makes some
468 (global-set-key '(shift kp-multiply) 'start-or-end-kbd-macro)
469 (global-set-key 'kp-multiply 'call-last-kbd-macro) ;; C-x e
471 ;; Note that you can refer to a key sequence either using an ASCII
472 ;; string or the "long way", with vectors and conses. You saw above
473 ;; (in a comment) the string form for specifying the key sequence `C-x
474 ;; C-f', which is "\C-x\C-f". (For those curious, \C-x is just an
475 ;; escape sequence that puts a ^X character into the string. Thus,
476 ;; the string just mentioned really just contains two characters, a ^X
477 ;; and a ^F.) The long way to specify the sequence `C-x C-f' would be
479 ;; [(control x) (control f)]
481 ;; The long format lets you specify all possible key sequences, while the
482 ;; string form only lets you specify sequences involving ASCII characters
483 ;; and/or modifiers and in fact only a subset of them.
485 ;; Other examples are:
489 ;; (You can leave out the parens when there is no modifier specified in
490 ;; the keystroke, and that's normally done.)
492 ;; [(shift control meta left)]
494 ;; (You can put more than one modifier in a keystroke.)
496 ;; (shift control meta left)
498 ;; (This is the same as the previous. when there's only one keystroke in
499 ;; the sequence, you can leave out the brackets, and that's normally
502 ;; [(control x) (shift button3)]
504 ;; (You can refer to mouse buttons just like keys -- apply modifiers,
505 ;; intermingle them in key sequences, etc. But there's only problem
506 ;; here, which is that with the mouse you don't just have one possible
507 ;; gesture, like with keys. You'd really like to control button-down,
508 ;; button-up, button-click (down and up without selecting anything),
509 ;; button drag, button double-click, etc. This is normally done by
510 ;; binding your key sequence to `mouse-track', and then putting hooks
511 ;; onto `mouse-track-click-hook', `mouse-track-drag-up-hook', etc. to
512 ;; customize the specific behavior.)
516 ;; (Ultimate reductionism -- no brackets, no parens. This is the form, in
517 ;; that, that the 'f1, 'f2, etc. took, which where in fact "long"
522 ;; (You cannot use '(control shift c) here. This applies whenever Shift +
523 ;; key translates to a single character. Note also that you can't use
524 ;; "\C-C" either; this refers to the non-shifted C-c, just like "\C-c"
528 ;; (Put a backslash in front of characters used in Lisp syntax.)
530 ;; Also, you can find out the name of a key using C-h c. WARNING:
531 ;; This does not report the correct name of the keys named `delete',
532 ;; `backspace', `return', `tab', `space', `escape', and `linefeed'!
533 ;; (More correct results can be achieved using
535 ;; ESC : (read-key-sequence "foo: ")
539 ;;;;;;;;;;;;;;;;;;;;;;;;
541 ;; Keystrokes to conveniently switch buffers.
543 ;; F6 is invaluable for flipping back and forth between two buffers
544 ;; you're working with.
546 (global-set-key 'f6 'switch-to-other-buffer) ;; M-C-l
547 (global-set-key '(meta n) 'switch-to-next-buffer-in-group)
548 (global-set-key '(meta p) 'switch-to-previous-buffer-in-group)
549 (global-set-key '(meta N) 'switch-to-next-buffer)
550 (global-set-key '(meta P) 'switch-to-previous-buffer)
552 ;; Define our own function to deal with the possibility that the newer
553 ;; stuff in the gutter code may not be present -- i.e. we're running
554 ;; an older XEmacs. Note that we avoid trying to "helpfully" define a
555 ;; function that is present in new versions of XEmacs, but not in
556 ;; older ones. That can very easily screw up code trying to determine
557 ;; what functionality is present using `fboundp' checks. See above,
558 ;; near `emacs-version>=', for a full discussion of this.
560 (defun Init-buffers-tab-omit (buf)
561 ;; a function specifying the buffers to omit from the buffers tab.
562 ;; This is passed a buffer and should return non-nil if the buffer
563 ;; should be omitted. If the standard buffers-tab functionality is
564 ;; there, we just call it to do things "right". Otherwise we just
565 ;; omit invisible buffers, snarfing the code from
566 ;; `buffers-menu-omit-invisible-buffers'.
567 (if (boundp 'buffers-tab-omit-function)
568 (funcall buffers-tab-omit-function buf)
569 (not (null (string-match "\\` " (buffer-name buf))))))
571 (defun switch-to-next-buffer (&optional n)
572 "Switch to the next-most-recent buffer.
573 This essentially rotates the buffer list forward.
574 N (interactively, the prefix arg) specifies how many times to rotate
575 forward, and defaults to 1. Buffers whose name begins with a space
576 \(i.e. \"invisible\" buffers) are ignored."
577 ;; Here is a different interactive spec. Look up the function
578 ;; `interactive' (i.e. `C-h f interactive') to understand how this
581 (dotimes (n (or n 1))
583 do (bury-buffer (car (buffer-list)))
584 while (Init-buffers-tab-omit (car (buffer-list))))
585 (switch-to-buffer (car (buffer-list)))))
587 (defun buffers-menu-omit-invisible-buffers (buf)
588 "For use as a value of `buffers-menu-omit-function'.
589 Omits normally invisible buffers (those whose name begins with a space)."
590 (not (null (string-match "\\` " (buffer-name buf)))))
592 (defvar Init-buffers-tab-grouping-regexp
593 '("^\\(gnus-\\|message-mode\\|mime/viewer-mode\\)"
594 "^\\(emacs-lisp-\\|lisp-\\)")
595 ;; If non-nil, a list of regular expressions for buffer grouping.
596 ;; Each regular expression is applied to the current major-mode symbol
597 ;; name and mode-name, if it matches then any other buffers that match
598 ;; the same regular expression be added to the current group. This is
599 ;; a copy of `buffers-tab-grouping-regexp'.
602 (defun Init-select-buffers-tab-buffers (buffer-to-select buf1)
603 ;; Specifies the buffers to select from the buffers tab. This is
604 ;; passed two buffers and should return non-nil if the second buffer
605 ;; should be selected. If the standard buffers-tab functionality is
606 ;; there, we just call it to do things "right". Otherwise, we group
607 ;; buffers by major mode and by `Init-buffers-tab-grouping-regexp'.
608 ;; [We've copied `select-buffers-tab-buffers-by-mode' and
609 ;; `buffers-tab-grouping-regexp'.]
610 (if (boundp 'buffers-tab-selection-function)
611 (funcall buffers-tab-selection-function buffer-to-select buf1)
612 (let ((mode1 (symbol-name (symbol-value-in-buffer 'major-mode buf1)))
613 (mode2 (symbol-name (symbol-value-in-buffer 'major-mode
615 (modenm1 (symbol-value-in-buffer 'mode-name buf1))
616 (modenm2 (symbol-value-in-buffer 'mode-name buffer-to-select)))
617 (cond ((or (eq mode1 mode2)
619 (and (string-match "^[^-]+-" mode1)
621 (concat "^" (regexp-quote
622 (substring mode1 0 (match-end 0))))
624 (and Init-buffers-tab-grouping-regexp
625 (find-if #'(lambda (x)
627 (and (string-match x mode1)
628 (string-match x mode2))
629 (and (string-match x modenm1)
630 (string-match x modenm2))))
631 Init-buffers-tab-grouping-regexp)))
635 (defun switch-to-previous-buffer (&optional n)
636 "Switch to the previously most-recent buffer.
637 This essentially rotates the buffer list backward.
638 N (interactively, the prefix arg) specifies how many times to rotate
639 backward, and defaults to 1. Buffers whose name begins with a space
640 \(i.e. \"invisible\" buffers) are ignored."
642 (dotimes (n (or n 1))
644 do (switch-to-buffer (car (last (buffer-list))))
645 while (Init-buffers-tab-omit (car (buffer-list))))))
647 (defun switch-to-next-buffer-in-group (&optional n)
648 "Switch to the next-most-recent buffer in the current group.
649 This essentially rotates the buffer list forward.
650 N (interactively, the prefix arg) specifies how many times to rotate
651 forward, and defaults to 1. Buffers whose name begins with a space
652 \(i.e. \"invisible\" buffers) are ignored."
654 (dotimes (n (or n 1))
655 (let ((curbuf (car (buffer-list))))
657 do (bury-buffer (car (buffer-list)))
658 while (or (Init-buffers-tab-omit (car (buffer-list)))
659 (not (Init-select-buffers-tab-buffers
660 curbuf (car (buffer-list)))))))
661 (switch-to-buffer (car (buffer-list)))))
663 (defun switch-to-previous-buffer-in-group (&optional n)
664 "Switch to the previously most-recent buffer in the current group.
665 This essentially rotates the buffer list backward.
666 N (interactively, the prefix arg) specifies how many times to rotate
667 backward, and defaults to 1. Buffers whose name begins with a space
668 \(i.e. \"invisible\" buffers) are ignored."
670 (dotimes (n (or n 1))
671 (let ((curbuf (car (buffer-list))))
673 do (switch-to-buffer (car (last (buffer-list))))
674 while (or (Init-buffers-tab-omit (car (buffer-list)))
675 (not (Init-select-buffers-tab-buffers
676 curbuf (car (buffer-list)))))))))
678 ;;;;;;;;;;;;;;;;;;;;;;;;
680 ;; Other text keystrokes.
682 ;; Make a keystroke to insert a literal TAB character. (`C-q TAB' is
683 ;; annoying because difficult to repeat.) Note that this does not work
684 ;; in TTY frames, where TAB and Shift-TAB are indistinguishable.
685 (define-key global-map '(shift tab) 'tab-to-tab-stop)
687 ;; Toggle auto-filling. Useful with text but annoying with code. You
688 ;; can manually fill with M-q.
689 (global-set-key '(meta f9) 'auto-fill-mode)
691 ;; You cannot say '(meta shift t) here -- see above.
692 (if (fboundp 'transpose-line-down)
693 (global-set-key '(meta T) 'transpose-line-down))
694 (if (fboundp 'transpose-line-up)
695 (global-set-key '(control T) 'transpose-line-up))
697 ;;;;;;;;;;;;;;;;;;;;;;;;
699 ;; Rearrange some inconvenient bindings.
701 ;; ESC ESC ESC is a useful command, but too long. ESC ESC would be
702 ;; much more logical, but interferes with Meta + keypad/arrow keys on
703 ;; TTY's. But most people only use window systems and no such problem
704 ;; exists there, so set up the more logical binding there.
706 ;; Note also the use of if vs. cond/when/unless/or/and to express
707 ;; conditional statements. The difference is purely stylistic.
709 (when (console-on-window-system-p)
710 (global-set-key '(meta escape) 'keyboard-escape-quit)
711 (define-key isearch-mode-map '(meta escape) 'isearch-cancel))
713 ;; The standard definition of C-z causes iconification on window
714 ;; systems, which is both useless and annoying. Instead, bind it to a
715 ;; useful command that's not on any keys. (This also makes a neat
716 ;; parallelism with M-z, which does zap-to-char.) Don't override the
717 ;; TTY binding, which does "Suspend". If you want this new binding on
718 ;; TTY's, and can train yourself to use C-x C-z to suspend, then
719 ;; remove or comment out the `when' statement. (Here's the proper way
720 ;; to comment out such a statement:
722 ;; ;(when (console-on-window-system-p)
723 ;; (global-set-key "\C-z" 'zap-up-to-char)
726 ;; To do this, I first moved the closing paren to a new line,
727 ;; reindented with TAB, then added the semicolons.)
729 (when (console-on-window-system-p)
730 (global-set-key "\C-z" 'zap-up-to-char))
732 ;; When not on a TTY, remove the binding of C-x C-c, which normally
733 ;; exits XEmacs. It's easy to hit this by mistake, and that can be
734 ;; annoying. You can always quit with the "Exit XEmacs" option on the
737 (when (console-on-window-system-p)
738 (global-set-key "\C-x\C-c"
739 #'(lambda () (interactive)
741 (message "Use the \"File/Exit XEmacs\" menu item to exit XEmacs"))))
743 ;; Make C-k always delete the whole line, which is what most people want,
745 (setq kill-whole-line 'always)
746 ;; M-k does the old behavior (kill to end of line).
747 (global-set-key '(meta k) #'(lambda ()
749 (if (fboundp 'historical-kill-line)
750 (call-interactively #'historical-kill-line)
751 (let ((kill-whole-line nil))
752 (call-interactively #'kill-line)))))
753 ;; and Meta-Shift-K does what used to be on M-k, and should
754 ;; (hopefully) even work under TTY's.
755 (global-set-key '(meta K) 'kill-sentence)
757 ;; Make sure we get Windows-like shifted-motion key selection behavior
758 ;; on recent XEmacs versions.
759 (cond ((boundp 'shifted-motion-keys-select-region)
760 (setq shifted-motion-keys-select-region t))
761 ;; otherwise, try the pc-select package --
762 ((Init-safe-require 'pc-select)
765 ;; The following commented-out code rearranges the keymap in an
766 ;; unconventional but extremely useful way for programmers. Parens
767 ;; and braces are both available without using the shift key (using
768 ;; the bracket keys and f11/f12, respectively). Brackets (much less
769 ;; used) are the shifted versions of the new paren keys (i.e. where
770 ;; the braces normally are).
772 ;; The idea for this comes from Jamie Zawinski.
774 ;; Also make a convenient keystroke for _, used constantly in C code.
776 ;; NOTE: you can (semi-) conveniently uncomment a region using
777 ;; C-u M-x comment-region, or the "Uncomment Region" menu item on the
778 ;; Lisp menu in new enough versions of XEmacs.
780 ;(keyboard-translate ?[ ?()
781 ;(keyboard-translate ?] ?))
782 ;(keyboard-translate ?{ ?[)
783 ;(keyboard-translate ?} ?])
784 ;;; We don't use `keyboard-translate' for these because it messes up
785 ;;; bindings for M-F9 and the like.
786 ;(define-key key-translation-map 'f11 "{")
787 ;(define-key key-translation-map 'f12 "}")
788 ;(define-key key-translation-map 'f9 "_")
791 ;;;;;;;;;;;;;;;;;;;;;;;;
793 ;; Useful programming-related keystrokes.
795 (defun describe-foo-at-point ()
796 "Show the documentation of the Elisp function and variable near point.
799 -- for a function name where point is
800 -- for a variable name where point is
801 -- for a surrounding function call
805 ;; sigh, function-at-point is too clever. we want only the first half.
806 (cond ((setq sym (ignore-errors
807 (with-syntax-table emacs-lisp-mode-syntax-table
809 (or (not (zerop (skip-syntax-backward "_w")))
810 (eq (char-syntax (char-after (point))) ?w)
811 (eq (char-syntax (char-after (point))) ?_)
813 (skip-chars-forward "`'")
814 (let ((obj (read (current-buffer))))
815 (and (symbolp obj) (fboundp obj) obj))))))
816 (describe-function sym))
817 ((setq sym (variable-at-point)) (describe-variable sym))
818 ;; now let it operate fully -- i.e. also check the
819 ;; surrounding sexp for a function call.
820 ((setq sym (function-at-point)) (describe-function sym)))))
822 (global-set-key '(shift f4) 'next-error) ;; C-x `
823 (global-set-key '(control f4) 'previous-error)
824 (global-set-key '(shift f5) 'find-library)
825 (global-set-key '(control f5) 'find-function)
826 (global-set-key '(meta f5) 'find-variable)
827 (global-set-key '(shift f11) 'describe-foo-at-point)
828 (global-set-key '(control f11) 'eval-last-sexp)
829 ;; Edebug is a source-level debugger for Emacs Lisp programs. Put
830 ;; the cursor at the end of a function definition and "instrument" it
831 ;; with this command; then, you can single step through it the next
833 (global-set-key '(meta f11) 'edebug-defun)
834 (global-set-key '(meta f12) 'add-change-log-entry)
836 ;; This nicely parallels M-*, which pops the tag stack. See below for
837 ;; how to set up tags.
838 (global-set-key '(control *) 'find-tag-at-point)
840 ;; Define a function to conveniently determine where time is being
841 ;; spent when executing commands or Lisp code.
842 (defun toggle-profiling ()
843 "Start profiling, or stop it and print results.
844 This lets you figure out where time is being spent when executing Lisp code."
846 (if (profiling-active-p)
849 (message "...Finished profiling")
851 (message "Profiling...")
852 (clear-profiling-info)
855 ;; Note that sequences of C-c plus a letter are specifically
856 ;; reserved for users and should never be bound by any packages.
858 (global-set-key "\C-cp" 'toggle-profiling)
860 ;; LISPM bindings of Control-Shift-C and Control-Shift-E.
861 ;; See comment above about bindings like this.
862 (define-key emacs-lisp-mode-map '(control C) 'compile-defun)
863 (define-key emacs-lisp-mode-map '(control E) 'eval-defun)
865 ;;;;;;;;;;;;;;;;;;;;;;;;
869 ;; The numeric keypad as a whole is underused, and it's a good source
870 ;; of keys to bind to commands. Here we add some useful bindings.
871 ;; Because this is a sample file and I want to avoid unpleasant
872 ;; surprises for novices, I don't actually bind the shared
873 ;; numeric/cursor-motion keys because
875 ;; (a) someone keypads don't have separate motion keys (e.g. laptops?), and
876 ;; (b) TTY's and some X servers might not distinguish the regular and
877 ;; numeric-keypad motion keys.
879 ;; `kill-current-buffer' (defined below) deletes the current
880 ;; buffer. (Don't worry, you will be prompted to save if it's
881 ;; modified.) By repeatedly pressing keypad-minus, you can
882 ;; conveniently reduce the number of open buffers to a manageable size
883 ;; after you've opened a whole bunch of files and finished working on
884 ;; them. Shift plus keypad-minus kills both the current buffer and
885 ;; its window, and Control plus keypad-minus kills just the current
888 (global-set-key 'kp-subtract 'kill-current-buffer)
889 (global-set-key '(shift kp-subtract) 'kill-current-buffer-and-window)
890 (global-set-key '(control kp-subtract) 'delete-window)
891 ;; Ugh, modes that use `suppress-keymap' and are dumped with XEmacs will
892 ;; need their own definition. There is no easy way to fix this.
893 (define-key help-mode-map 'kp-subtract 'kill-current-buffer)
894 (define-key help-mode-map '(shift kp-subtract)
895 'kill-current-buffer-and-window)
896 (define-key list-mode-map 'kp-subtract 'kill-current-buffer)
897 (define-key list-mode-map '(shift kp-subtract)
898 'kill-current-buffer-and-window)
900 (defun kill-current-buffer ()
901 "Kill the current buffer (prompting if it is modified)."
903 (kill-buffer (current-buffer)))
905 (defun kill-current-buffer-and-window ()
906 "Kill the current buffer (prompting if it is modified) and its window."
908 (kill-buffer (current-buffer))
911 (defvar grep-all-files-history nil)
913 (defvar grep-all-files-omitted-expressions
914 '("*~" "#*" ".#*" ",*" "*.elc" "*.obj" "*.o" "*.exe" "*.dll" "*.lib" "*.a"
915 "*.dvi" "*.class" "*.bin")
916 "List of expressions matching files to be omitted in `grep-all-files-...'.
917 Each entry should be a simple name or a shell wildcard expression.")
919 (defvar grep-all-files-omitted-directories '("CVS" "RCS" "SCCS")
920 "List of directories not to recurse into in `grep-all-files-...'.
921 Each entry should be a simple name or a shell wildcard expression.")
923 (defun construct-grep-all-files-command (find-segment grep-segment)
925 (mapconcat #'(lambda (wildcard)
926 (concat "-name '" wildcard "' -or "))
927 grep-all-files-omitted-expressions
929 (cond ((eq grep-find-use-xargs 'gnu)
930 (format "find . %s %s -type f -print0 | xargs -0 -e %s"
931 find-segment omit-annoying grep-segment))
933 (format "find . %s %s -type f -print | xargs %s"
934 find-segment omit-annoying grep-segment))
936 (format "find . %s %s -type f -exec %s {} /dev/null \\;"
937 find-segment omit-annoying grep-segment)))))
939 (defun grep-all-files-in-current-directory (command)
940 "Run `grep' in all non-annoying files in the current directory.
941 `Non-annoying' excludes backup files, autosave files, CVS merge files, etc.
942 More specifically, this is controlled by `grep-all-files-omitted-expressions'.
944 This function does not recurse into subdirectories. If you want this,
945 use \\[grep-all-files-in-current-directory-and-below]."
949 (list (read-shell-command "Run grep (like this): "
950 grep-command 'grep-all-files-history))))
952 (grep (construct-grep-all-files-command
953 "-name . -or -type d -prune -or" command)))
955 (defun grep-all-files-in-current-directory-and-below (command)
956 "Run `grep' in all non-annoying files in the current directory and below.
957 `Non-annoying' excludes backup files, autosave files, CVS merge files, etc.
958 More specifically, this is controlled by `grep-all-files-omitted-expressions'.
960 This function recurses into subdirectories. If you do not want this,
961 use \\[grep-all-files-in-current-directory]."
965 (list (read-shell-command "Run grep (like this): "
966 grep-command 'grep-all-files-history))))
968 (grep (construct-grep-all-files-command
969 ;; prune all specified directories.
970 (mapconcat #'(lambda (wildcard)
971 (concat "-name '" wildcard "' -prune -or "))
972 grep-all-files-omitted-directories
976 (defun clear-select ()
977 "Repeatedly select ever larger balanced expressions around the cursor.
978 Once you have such an expression marked, you can expand to the end of
979 the following expression with \\[mark-sexp] and to the beginning of the
980 previous with \\[backward-sexp]."
981 (interactive "_") ;this means "preserve the active region after this command"
983 (let ((end (save-excursion (forward-sexp) (point))))
984 (push-mark end nil t)))
986 ;; #### no kp-divide because it doesn't (currently) work on MS Windows
987 ;; -- always reports as /. #### this should be fixable.
988 (global-set-key 'kp-add 'query-replace)
989 (global-set-key '(shift kp-add) 'query-replace-regexp)
990 (global-set-key '(control kp-add) 'grep-all-files-in-current-directory)
991 (global-set-key '(meta kp-add) 'grep-all-files-in-current-directory-and-below)
992 (global-set-key 'clear 'clear-select)
993 ;; Note that you can use a "lambda" expression (an anonymous function)
994 ;; in place of a function name. This function would be called
995 ;; `pop-local-mark' and lets you repeatedly cycle back through recent
996 ;; marks (marks are set whenever you begin a selection, begin a
997 ;; successful search, are about to jump to the beginning or end of the
999 (global-set-key 'kp-enter (lambda () (interactive) (set-mark-command t)))
1000 (global-set-key '(shift kp-enter) 'repeat-complex-command)
1001 (global-set-key 'pause 'repeat-complex-command) ;; useful on Windows-style kbds
1002 (global-set-key '(control kp-enter) 'eval-expression)
1004 ;;;;;;;;;;;;;;;;;;;;;;;;
1008 ;; If you want button2 to insert the selected text
1009 ;; at point (where the text cursor is), instead of at the
1010 ;; position clicked, uncomment the following:
1012 ;(setq mouse-yank-at-point t)
1014 ;; If you like the FSF Emacs binding of button3 (single-click
1015 ;; extends the selection, double-click kills the selection),
1016 ;; uncomment the following:
1018 ;(define-key global-map 'button3 'mouse-track-adjust)
1020 ;(add-hook 'mouse-track-click-hook
1021 ; (lambda (event count)
1022 ; (if (or (/= (event-button event) 3)
1024 ; nil ;; do the normal operation
1025 ; (kill-region (point) (mark))
1026 ; t ;; don't do the normal operations.
1029 ;; Uncomment this to enable "sticky modifier keys". With sticky
1030 ;; modifier keys enabled, you can press and release a modifier key
1031 ;; before pressing the key to be modified, like how the ESC key works
1032 ;; always. If you hold the modifier key down, however, you still get
1033 ;; the standard behavior. I personally think this is the best thing
1034 ;; since sliced bread (and a *major* win when it comes to reducing
1035 ;; Emacs pinky), but it's disorienting at first so I'm not enabling it
1038 ;(setq modifier-keys-are-sticky t)
1040 ;; Enable the command `narrow-to-region' ("C-x n n"). It's a useful
1041 ;; command, but possibly confusing to a new user, so it's disabled by
1043 (put 'narrow-to-region 'disabled nil)
1045 ;; Enable obvious hyperlink following with button1.
1046 (setq Info-button1-follows-hyperlink t)
1049 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1050 ;; Change Some Basic Behaviors ;;
1051 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1053 ;; Change the values of some variables.
1054 ;; (t means true; nil means false.)
1056 ;; Use C-h v or `Help->Commands, Variables, Keys->Describe Variable...'
1057 ;; to find out what these variables mean.
1059 find-file-compare-truenames t
1060 minibuffer-max-depth nil
1063 ;; When running ispell, consider all 1-3 character words as correct.
1064 (setq ispell-extra-args '("-W" "3"))
1066 ;;; pending-delete-mode causes typed text to replace a selection,
1067 ;;; rather than append -- standard behavior under all window systems
1070 (if (fboundp 'pending-delete-mode)
1071 (pending-delete-mode 1))
1073 ;;; NOTE: In this context, `windows-nt' actually refers to all MS
1074 ;;; Windows operating systems!
1075 (when (eq system-type 'windows-nt)
1076 ;; Get mail working under Windows.
1077 (setq send-mail-function 'smtpmail-send-it)
1078 (setq smtpmail-debug-info t)
1079 ;; Substitute your info here.
1080 ;(setq user-mail-address "ben@xemacs.org")
1081 ;(setq user-full-name "Ben Wing")
1082 ;(setq smtpmail-smtp-server "pop.tcsn.uswest.net")
1084 ;; Make Meta+accelerator traverse to the menu in new enough XEmacs
1085 ;; versions. Note that this only overrides Meta bindings that would
1086 ;; actually invoke a menu, and the most common commands that are
1087 ;; overridden have preferred alternative bindings using the arrow
1088 ;; keys. You can always access the overridden ones using
1089 ;; Shift+Meta+Key. (Note that "Alt" and "Meta" normally refer to the
1090 ;; same key, except on some Sun keyboards [where "Meta" is actually
1091 ;; labelled with a diamond] or if you have explicitly made them
1092 ;; different under X Windows using `xmodmap'.)
1094 ;; More specifically, the following bindings are overridden:
1096 ;; M-f (use C-right or Sh-M-f instead)
1097 ;; M-e (use M-C-right or Sh-M-e instead)
1098 ;; M-v (use Prior aka PgUp or Sh-M-v instead)
1099 ;; M-m (use Sh-M-m instead)
1100 ;; M-t (use Sh-M-t instead)
1101 ;; M-o (normally undefined)
1102 ;; M-b (use C-left or Sh-M-b instead)
1103 ;; M-h (use M-e h or Sh-M-h instead)
1104 ;; in Lisp mode, M-l (use Sh-M-l instead)
1105 ;; in C mode, M-c (use Sh-M-c instead)
1107 (setq menu-accelerator-enabled 'menu-force)
1109 ;; Make Cygwin `make' work inside a shell buffer.
1110 (if (boundp 'setenv) (setenv "MAKE_MODE" "UNIX")))
1112 ;; This shows how to set up the XEmacs side of tags. (To create the
1113 ;; TAGS table, use the `etags' program found in the XEmacs bin
1114 ;; directory. Run it in the root directory of your source tree and
1115 ;; specify all source and include files on the command line.)
1116 ;(setq tag-table-alist
1118 ; ;; Everywhere in the /src/xemacs/gui/ source tree will use the TAGS
1119 ; ;; file in /src/xemacs/gui/.
1120 ; ("/src/xemacs/gui/" . "/src/xemacs/gui/")
1121 ; ;; Everywhere in the /src/xemacs/mule/ source tree will use the TAGS
1122 ; ;; file in /src/xemacs/mule/.
1123 ; ("/src/xemacs/mule/" . "/src/xemacs/mule/")
1125 ; ("/src/xemacs/fixup/" . "/src/xemacs/fixup/")
1126 ; ("/src/emacs/emacs-20.6/" . "/src/emacs/emacs-20.6/")
1127 ; ("/src/xemacs/latest/" . "/src/xemacs/latest/")
1128 ; ;; Everywhere else will use the TAGS file in
1129 ; ;; /src/xemacs/fixup/.
1130 ; ("" . "/src/xemacs/fixup/")
1134 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1135 ;; Change Some Aspects of GUI Appearance ;;
1136 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1138 ;; Changes the text in the window title bar, to switch to MS Windows
1139 ;; format (filename goes first, for best identification in icons) and
1140 ;; add the version and full executable path. (However, it is not
1141 ;; changed unless it currently has the default value, to avoid
1142 ;; interfering with a -wn command line argument I may have started
1145 (if (or (equal frame-title-format "%S: %b")
1146 (equal frame-title-format "%b - XEmacs"))
1147 (setq frame-title-format
1148 (concat "%b - XEmacs "
1149 (progn (string-match "\\(.*?\\)\\( XEmacs Lucid\\)?$"
1151 (match-string 1 emacs-version))
1152 " [" invocation-directory invocation-name "]")))
1154 ;; Load some nifty sounds that will replace the default beep.
1156 ;; (Note that sampled sounds only work if XEmacs was compiled with
1157 ;; sound support and we're running on MS Windows, on a machine which
1158 ;; has a NetAudio or ESD server, or on the console of a Linux, Sparc,
1159 ;; HP, or SGI machine. Otherwise, you just get the standard beep.)
1161 (cond ((and (fboundp 'load-default-sounds)
1162 (or (and (getenv "DISPLAY")
1163 (string-match ":0" (getenv "DISPLAY")))
1164 (and (eq (console-type) 'mswindows)
1165 (device-sound-enabled-p))))
1168 (load-default-sounds)
1169 ;; On Windows, at least, the sound "quiet-beep", which is normally
1170 ;; given the symbolic name `quiet' and is used for Quit and such,
1171 ;; is just totally disgusting. So make this name correspond to a
1172 ;; more innocuous sound.
1173 (load-sound-file "drum-beep" 'quiet 80))
1176 (setq bell-volume 40)
1178 (append sound-alist '((no-completion :pitch 500))))
1181 ;; Change the continuation glyph face so it stands out more
1182 (make-face-bold (glyph-face continuation-glyph))
1184 ;; Change the pointer used during garbage collection.
1186 ;; Note that this pointer image is rather large as pointers go,
1187 ;; and so it won't work on some X servers (such as the MIT
1188 ;; R5 Sun server) because servers may have lamentably small
1189 ;; upper limits on pointer size.
1190 ;;(if (featurep 'xpm)
1191 ;; (set-glyph-image gc-pointer-glyph
1192 ;; (expand-file-name "trash.xpm" data-directory)))
1194 ;; Here's another way to do that: it first tries to load the
1195 ;; pointer once and traps the error, just to see if it's
1196 ;; possible to load that pointer on this system; if it is,
1197 ;; then it sets gc-pointer-glyph, because we know that
1198 ;; will work. Otherwise, it doesn't change that variable
1199 ;; because we know it will just cause some error messages.
1201 (let ((file (expand-file-name "recycle.xpm" data-directory)))
1202 (if (condition-case nil
1203 ;; check to make sure we can use the pointer.
1204 (make-image-instance file nil
1206 (error nil)) ; returns nil if an error occurred.
1207 (set-glyph-image gc-pointer-glyph file))))
1209 ;(when (featurep 'menubar)
1210 ; ;; Add `dired' to the File menu
1211 ; (add-menu-button '("File") ["Edit Directory" dired])
1213 ; ;; Here's a way to add scrollbar-like buttons to the menubar
1214 ; (add-menu-button nil ["Top" beginning-of-buffer])
1215 ; (add-menu-button nil ["<<<" scroll-down])
1216 ; (add-menu-button nil [" . " recenter])
1217 ; (add-menu-button nil [">>>" scroll-up])
1218 ; (add-menu-button nil ["Bot" end-of-buffer]))
1220 ;; Here's a cute hack that shows how to programmatically change some
1221 ;; text colors. It changes the background color of the window if it's
1222 ;; not on the local machine, or if it's running as root:
1224 ;; local emacs background: whitesmoke [i.e. the default color]
1225 ;; remote emacs background: palegreen1
1226 ;; root emacs background: coral2
1228 ;; Uncomment to enable.
1231 ; ((and running-xemacs
1232 ; (console-on-window-system-p)
1233 ; ;; this does not make much sense on Windows.
1234 ; (not (eq system-type 'windows-nt)))
1235 ; (let* ((root-p (eq 0 (user-uid)))
1236 ; (dpy (or (getenv "DISPLAY") ""))
1238 ; (or (string-match "^\\(\\|unix\\|localhost\\):" dpy)
1239 ; (let ((s (system-name)))
1240 ; (if (string-match "\\.\\(netscape\\|mcom\\)\\.com" s)
1241 ; (setq s (substring s 0 (match-beginning 0))))
1242 ; (string-match (concat "^" (regexp-quote s)) dpy)))))
1243 ; (bg (cond (root-p "coral2")
1244 ; (remote-p "palegreen1")
1247 ; (let ((def (color-name (face-background 'default)))
1248 ; (faces (face-list)))
1250 ; (let ((obg (face-background (car faces))))
1251 ; (if (and obg (equal def (color-name obg)))
1252 ; (set-face-background (car faces) bg)))
1253 ; (setq faces (cdr faces)))))))))
1256 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1257 ;; Changing the Modeline ;;
1258 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1260 ;; Enable line numbers and column numbers. This is done in C code now
1261 ;; and is very fast.
1262 (line-number-mode 1)
1263 (column-number-mode 1)
1265 ;; Rearrange the modeline so that everything is to the left of the
1266 ;; long list of minor modes, which is relatively unimportant but takes
1267 ;; up so much room that anything to the right is obliterated.
1273 (if (boundp 'modeline-multibyte-status) 'modeline-multibyte-status "")
1274 (cons modeline-modified-extent 'modeline-modified)
1275 (cons modeline-buffer-id-extent
1276 (list (cons modeline-buffer-id-left-extent
1278 (list 'line-number-mode "L%l ")
1279 (list 'column-number-mode "C%c ")
1281 (cons modeline-buffer-id-right-extent "%17b")))
1285 (cons modeline-minor-mode-extent
1286 (list "" 'mode-name 'minor-mode-alist))
1287 (cons modeline-narrowed-extent "%n")
1293 ;; Get rid of modeline information taking up too much space -- in
1294 ;; particular, minor modes that are always enabled.
1295 (setq pending-delete-modeline-string "")
1296 (setq filladapt-mode-line-string "")
1297 ;; lazy-lock doesn't have a variable for its modeline name, so we have
1298 ;; to do a bit of surgery.
1299 (and (assoc 'lazy-lock-mode minor-mode-alist)
1300 (setcdr (cdr (cadr (assoc 'lazy-lock-mode minor-mode-alist))) ""))
1304 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1305 ;; Customization of Specific Packages ;;
1306 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1309 ;;; ********************
1310 ;;; Load gnuserv, which will allow you to connect to XEmacs sessions
1311 ;;; using `gnuclient'.
1313 ;; If you never run more than one XEmacs at a time, you might want to
1314 ;; always start gnuserv. Otherwise it is preferable to specify
1315 ;; `-f gnuserv-start' on the command line to one of the XEmacsen.
1319 ;;; ********************
1320 ;;; Load efs, which uses the FTP protocol as a pseudo-filesystem.
1321 ;;; When this is loaded, the pathname syntax /user@host:/remote/path
1322 ;;; refers to files accessible through ftp.
1324 (Init-safe-require 'dired)
1326 (or (Init-safe-require 'efs-auto) (Init-safe-require 'ange-ftp))
1328 ;;; ********************
1329 ;;; Load the default-dir.el package which installs fancy handling of
1330 ;;; the initial contents in the minibuffer when reading file names.
1331 ;; #### but it seems to cause some breakage.
1332 ;(Init-safe-require 'default-dir))
1334 ;;; ********************
1335 ;;; Put all of your autosave files in one place, instead of scattering
1336 ;;; them around the file system. This has many advantages -- e.g. it
1337 ;;; will eliminate slowdowns caused by editing files on a slow NFS
1338 ;;; server. (*Provided* that your home directory is local or on a
1339 ;;; fast server! If not, pick a value for `auto-save-directory' that
1340 ;;; is fast fast fast!)
1342 ;;; Unfortunately, the code that implements this (auto-save.el) is
1343 ;;; broken on Windows prior to 21.4.
1344 (unless (and (eq system-type 'windows-nt)
1345 (not (emacs-version>= 21 4)))
1346 (setq auto-save-directory (expand-file-name "~/.autosave/")
1347 auto-save-directory-fallback auto-save-directory
1348 auto-save-hash-p nil
1350 efs-auto-save-remotely nil
1351 ;; now that we have auto-save-timeout, let's crank this up
1352 ;; for better interactive response.
1353 auto-save-interval 2000
1358 ;;; ********************
1359 ;;; cc-mode (the mode you're in when editing C, C++, and Objective C files)
1361 ;; Tell cc-mode not to check for old-style (K&R) function declarations.
1362 ;; This speeds up indenting a lot.
1363 (setq c-recognize-knr-p nil)
1365 ;; Change the indentation amount to 4 spaces instead of 2.
1366 ;; You have to do it in this complicated way because of the
1367 ;; strange way the cc-mode initializes the value of `c-basic-offset'.
1368 ;; (add-hook 'c-mode-hook (lambda () (setq c-basic-offset 4)))
1371 ;;; ********************
1372 ;;; Load a partial-completion mechanism, which makes minibuffer completion
1373 ;;; search multiple words instead of just prefixes; for example, the command
1374 ;;; `M-x byte-compile-and-load-file RET' can be abbreviated as `M-x b-c-a RET'
1375 ;;; because there are no other commands whose first three words begin with
1376 ;;; the letters `b', `c', and `a' respectively.
1378 (Init-safe-require 'completer)
1381 ;;; ********************
1382 ;;; Load crypt, which is a package for automatically decoding and reencoding
1383 ;;; files by various methods - for example, you can visit a .Z or .gz file,
1384 ;;; edit it, and have it automatically re-compressed when you save it again.
1386 (setq crypt-encryption-type 'pgp ; default encryption mechanism
1387 crypt-confirm-password t ; make sure new passwords are correct
1388 ;crypt-never-ever-decrypt t ; if you don't encrypt anything, set this to
1389 ; tell it not to assume that "binary" files
1390 ; are encrypted and require a password.
1392 (Init-safe-require 'crypt)
1395 ;;; ********************
1396 ;;; Filladapt is an adaptive text-filling package. When it is enabled it
1397 ;;; makes filling (e.g. using M-q) much much smarter about paragraphs
1398 ;;; that are indented and/or are set off with semicolons, dashes, etc.
1400 (Init-safe-require 'filladapt)
1401 (setq-default filladapt-mode t)
1402 (when (fboundp 'turn-off-filladapt-mode)
1403 (add-hook 'c-mode-hook 'turn-off-filladapt-mode)
1404 (add-hook 'outline-mode-hook 'turn-off-filladapt-mode))
1407 ;;; ********************
1408 ;;; Font-Lock is a syntax-highlighting package. When it is enabled and you
1409 ;;; are editing a program, different parts of your program will appear in
1410 ;;; different fonts or colors. For example, with the code below, comments
1411 ;;; appear in red italics, function names in function definitions appear in
1412 ;;; blue bold, etc. The code below will cause font-lock to automatically be
1413 ;;; enabled when you edit C, C++, Emacs-Lisp, and many other kinds of
1416 ;;; The "Options" menu has some commands for controlling this as well.
1418 (cond (running-xemacs
1420 ;; The commented-out code below is an example of setting up custom
1421 ;; font-lock colors.
1423 ; ;; If you want the default colors, you could do this:
1424 ; ;; (setq font-lock-use-default-fonts nil)
1425 ; ;; (setq font-lock-use-default-colors t)
1426 ; ;; but I want to specify my own colors, so I turn off all
1427 ; ;; default values.
1428 ; (setq font-lock-use-default-fonts nil)
1429 ; (setq font-lock-use-default-colors nil)
1431 (Init-safe-require 'font-lock)
1433 ; ;; Mess around with the faces a bit. Note that you have
1434 ; ;; to change the font-lock-use-default-* variables *before*
1435 ; ;; loading font-lock, and wait till *after* loading font-lock
1436 ; ;; to customize the faces.
1438 ; ;; string face is green
1439 ; (set-face-foreground 'font-lock-string-face "forest green")
1441 ; ;; comments are italic and red; doc strings are italic
1442 ; (set-face-font 'font-lock-comment-face [italic])
1443 ; ;; Underlining comments looks terrible on tty's
1444 ; (set-face-underline-p 'font-lock-comment-face nil 'global 'tty)
1445 ; (set-face-highlight-p 'font-lock-comment-face t 'global 'tty)
1446 ; (copy-face 'font-lock-comment-face 'font-lock-doc-string-face)
1447 ; (set-face-foreground 'font-lock-comment-face "red")
1449 ; ;; function names are bold and blue
1450 ; (set-face-font 'font-lock-function-name-face [bold])
1451 ; (set-face-foreground 'font-lock-function-name-face "blue")
1454 ; (set-face-font 'font-lock-preprocessor-face [bold])
1455 ; (set-face-font 'font-lock-type-face [italic])
1456 ; (set-face-font 'font-lock-keyword-face [bold])
1460 ;;; ********************
1461 ;;; lazy-lock is a package which speeds up the highlighting of files
1462 ;;; by doing it "on-the-fly" -- only the visible portion of the
1463 ;;; buffer is fontified. The results may not always be quite as
1464 ;;; accurate as using full font-lock or fast-lock, but it's *much*
1465 ;;; faster. No more annoying pauses when you load files.
1467 (if (fboundp 'turn-on-lazy-lock)
1468 (add-hook 'font-lock-mode-hook 'turn-on-lazy-lock))
1470 ;; I personally don't like "stealth mode" (where lazy-lock starts
1471 ;; fontifying in the background if you're idle for 30 seconds)
1472 ;; because it takes too long to wake up again.
1473 (setq lazy-lock-stealth-time nil)
1476 ;;; ********************
1477 ;;; func-menu is a package that scans your source file for function
1478 ;;; definitions and makes a menubar entry that lets you jump to any
1479 ;;; particular function definition by selecting it from the menu. The
1480 ;;; following code turns this on for all of the recognized languages.
1481 ;;; Scanning the buffer takes some time, but not much.
1483 ;;; Send bug reports, enhancements etc to:
1484 ;;; David Hughes <ukchugd@ukpmr.cs.philips.nl>
1486 (cond ((and running-xemacs (Init-safe-require 'func-menu))
1487 (global-set-key '(shift f12) 'function-menu)
1488 (add-hook 'find-file-hooks 'fume-add-menubar-entry)
1489 (global-set-key "\C-cl" 'fume-list-functions)
1490 (global-set-key "\C-cg" 'fume-prompt-function-goto)
1492 ;; The Hyperbole information manager package uses (shift button2) and
1493 ;; (shift button3) to provide context-sensitive mouse keys. If you
1494 ;; use this next binding, it will conflict with Hyperbole's setup.
1495 ;; Choose another mouse key if you use Hyperbole.
1496 (global-set-key '(shift button3) 'mouse-function-menu)
1498 ;; For descriptions of the following user-customizable variables,
1499 ;; type C-h v <variable>
1500 (setq fume-max-items 25
1501 fume-fn-window-position 3
1502 fume-auto-position-popup t
1503 fume-display-in-modeline-p t
1504 fume-menubar-menu-name
1505 (if (fboundp 'submenu-generate-accelerator-spec)
1506 "Function%_s" "Functions")
1507 fume-buffer-name "*Function List*"
1508 fume-no-prompt-on-valid-default nil)
1512 ;;; ********************
1513 ;;; MH is a mail-reading system from the Rand Corporation that relies on a
1514 ;;; number of external filter programs (which do not come with emacs.)
1515 ;;; Emacs provides a nice front-end onto MH, called "mh-e".
1517 ;; Bindings that let you send or read mail using MH
1518 ;(global-set-key "\C-xm" 'mh-smail)
1519 ;(global-set-key "\C-x4m" 'mh-smail-other-window)
1520 ;(global-set-key "\C-cr" 'mh-rmail)
1522 ;; Customization of MH behavior.
1523 (setq mh-delete-yanked-msg-window t)
1524 (setq mh-yank-from-start-of-msg 'body)
1525 (setq mh-summary-height 11)
1527 ;; Use lines like the following if your version of MH
1528 ;; is in a special place.
1529 ;(setq mh-progs "/usr/dist/pkgs/mh/bin.svr4/")
1530 ;(setq mh-lib "/usr/dist/pkgs/mh/lib.svr4/")
1533 ;;; ********************
1534 ;;; resize-minibuffer-mode makes the minibuffer automatically
1535 ;;; resize as necessary when it's too small to hold its contents.
1537 (when (fboundp 'resize-minibuffer-mode)
1538 (resize-minibuffer-mode)
1539 (setq resize-minibuffer-window-exactly nil))
1542 ;;; ********************
1543 ;;; scroll-in-place is a package that keeps the cursor on the same line (and in the same column) when scrolling by a page using PgUp/PgDn.
1545 (if (Init-safe-require 'scroll-in-place)
1546 (turn-on-scroll-in-place))
1549 ;;; ********************
1550 ;;; W3 is a browser for the World Wide Web, and takes advantage of the very
1551 ;;; latest redisplay features in XEmacs. You can access it simply by typing
1552 ;;; 'M-x w3'; however, if you're unlucky enough to be on a machine that is
1553 ;;; behind a firewall, you will have to do something like this first:
1555 ;(setq w3-use-telnet t
1557 ; ;; If the Telnet program you use to access the outside world is
1558 ; ;; not called "telnet", specify its name like this.
1559 ; w3-telnet-prog "itelnet"
1561 ; ;; If your Telnet program adds lines of junk at the beginning
1562 ; ;; of the session, specify the number of lines here.
1563 ; w3-telnet-header-length 4
1566 ;;; Inhibit loading of custom-file
1568 ;; make-temp-name returns a name which does not refer to an existing file,
1569 ;; and thus the named file is unreadable.
1570 (when Init-inhibit-custom-file-p
1571 (setq custom-file (make-temp-name "/tmp/non-existent-")))