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 ;; -- #### figure out how init.el and custom.el interact and put
28 ;; documentation about it here. (perhaps it already exists
31 ;;; This is a sample init.el file. It can be used without
32 ;;; modification as your init.el or .emacs. In older versions of
33 ;;; XEmacs, this file was called .emacs and placed in your home
34 ;;; directory. (Under MS Windows, that directory is controlled by the
35 ;;; HOME environment variable and defaults to C:\. You can find out
36 ;;; where XEmacs thinks your home directory is using
38 ;;; ESC : (expand-file-name "~")
40 ;;; . This means type ESC, then colon, then the following text, then hit
41 ;;; return.) In more recent versions of XEmacs, this file has migrated to
42 ;;; the .xemacs/ subdirectory and is called init.el. Other files are
43 ;;; also located here, such as custom.el (the auto-generated file
44 ;;; containing Customization options that you saved when using
45 ;;; Options->Save Options).
47 ;;; Changes to your init.el file will not take effect until the next
48 ;;; time you start up XEmacs, unless you load it explicitly with
50 ;;; M-x load-file RET ~/.xemacs/init.el RET
52 ;;; The language that this file (and most other XEmacs init files) is
53 ;;; written in is called "XEmacs Lisp" or more commonly "Elisp".
55 ;;; There are many sources of further information:
57 ;;; -- the XEmacs User's Manual (Access using the online Info browser:
58 ;;; Use `Help->Info (Online Docs)->XEmacs User's Manual' (if
59 ;;; there is such an entry); or get to the Info contents page
60 ;;; using `Help->Info Contents' or `C-h i', and then
61 ;;; *middle-click* the XEmacs link or move the cursor into the
62 ;;; link and hit ENTER. This manual contains a great deal of
63 ;;; documentation on customization: Scroll down to the
64 ;;; Customization link and select it in the same fashion as for
65 ;;; the XEmacs link just mentioned.)
67 ;;; -- the XEmacs FAQ (`C-h F' for the local version; get either the
68 ;;; local version or the very latest version off the net using
71 ;;; -- the XEmacs Lisp Reference Manual, containing detailed
72 ;;; documentation on Elisp. (Access using Info, just like for the
73 ;;; XEmacs User's Manual.)
75 ;;; -- the documentation strings for specific commands, functions,
76 ;;; key sequences, and variables. NOTE: This is *not* the same
77 ;;; information as in the XEmacs User's Manual or XEmacs Lisp
78 ;;; Reference Manual! In general, the doc strings are more
79 ;;; terse and more up-to-date than what is found in the manuals.
80 ;;; Once you understand the general concepts, these doc strings
81 ;;; should be your first point of reference for further
82 ;;; info. (Access using menu entries under `Help->Commands,
83 ;;; Variables, Keys' or using the keyboard: `C-h k' for a key
84 ;;; sequence, `C-h f' for a named command or Elisp function,
85 ;;; `C-h v' for a variable. There is various other useful
86 ;;; information accessible similarly, such as `C-h a'
87 ;;; ["Apropos", i.e. search for a command, function, or variable
88 ;;; by name]; `C-h C-a' ["Apropos Docs", i.e. search through the
89 ;;; text of the doc strings]; `C-h b' to list all key bindings;
90 ;;; `C-h m' to describe the current major and minor modes; etc.
91 ;;; Type `C-h ? ?' for a complete list.)
93 ;;; -- Getting Started with XEmacs [aka the "New User's Guide"], a
94 ;;; more introductory manual than the XEmacs User's Manual.
95 ;;; (Access using Info, just like for the XEmacs User's Manual.
96 ;;; There are some sections on customization here.)
98 ;;; -- the XEmacs tutorial, a very simple introduction to XEmacs for
99 ;;; total beginners. (`C-h t' for English; get the version in
100 ;;; various languages from the Help menu)
102 ;;; -- the XEmacs web site, www.xemacs.org.
104 ;;; -- the XEmacs mailing lists (xemacs-FOO@xemacs.org;
105 ;;; see http://www.xemacs.org/Lists/ for more info. Before
106 ;;; posting, consider looking through the archives -- they go back
107 ;;; years and there is a powerful searching interface. Currently
108 ;;; the archives are at http://list-archive.xemacs.org/, but if
109 ;;; this doesn't work, you can always access them through
112 ;;; -- the XEmacs newsgroup, comp.emacs.xemacs. This is
113 ;;; bi-directionally gatewayed with xemacs@xemacs.org. WARNING:
114 ;;; The developers do not normally hang out on this newsgroup. If
115 ;;; you need to contact them, use xemacs-beta@xemacs.org.
117 ;;; -- the XEmacs internals manual, for those interested in working on
118 ;;; the XEmacs C code. (Available through Info.)
120 ;;; -- `Help->About XEmacs' to find out who the maintainers are.
123 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
124 ;; Basic Customization ;;
125 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
127 ;; TIP: Control-L characters are ignored in Lisp files and are the
128 ;; standard way of indicating major section divisions. You can enter
129 ;; such a character using C-q C-l.
131 ;; Define a variable to indicate whether we're running XEmacs/Lucid
132 ;; Emacs. (You do not have to defvar a global variable before using
133 ;; it -- you can just call `setq' directly. It's clearer this way,
134 ;; though. Note also how we check if this variable already exists
135 ;; using `boundp', because it's defined in recent versions of
138 (or (boundp 'running-xemacs)
139 (defvar running-xemacs (string-match "XEmacs\\|Lucid" emacs-version)))
141 ;; Define a function to make it easier to check which version we're
142 ;; running. This function already exists in recent XEmacs versions,
143 ;; and in fact all we've done is copied the definition. Note again
144 ;; how we check to avoid clobbering an existing definition. (It's good
145 ;; style to do this, in case some improvement was made to the
146 ;; already-existing function -- otherwise we might subsitute an older
147 ;; definition and possibly break some code elsewhere.)
149 ;; NOTE ALSO: It is in general *NOT* a good idea to do what we're
150 ;; doing -- i.e. provide a definition of a function that is present in
151 ;; newer versions of XEmacs but not older ones. The reason is that it
152 ;; may confuse code that notices the presence of the function and
153 ;; proceeds to use it and other functionality that goes along with it
154 ;; -- but which we may not have defined. What's better is to create
155 ;; the function with a different name -- typically, prefix it with the
156 ;; name of your module, which in this case might be `Init-'. For
157 ;; `emacs-version>=' we make an exception because (a) the function has
158 ;; been around a long time, (b) there isn't really any other
159 ;; functionality that is paired with it, (c) it's definition hasn't
160 ;; changed and isn't likely to, and (d) the calls to `emacs-version>='
161 ;; or its renamed replacement would be scattered throughout the code
162 ;; below, and with a replacement name the code would become
163 ;; significantly less portable into someone else's init.el file. (BUT
164 ;; NOTE BELOW: We do follow the procedure outlined above with renaming
165 ;; in a different case where the specifics are much different.)
167 ;; TIP: At this point you may be wondering how I wrote all these nice,
168 ;; long, nicely-justified textual stretches -- didn't I go crazy
169 ;; sticking in the semicolons everywhere and having to delete them and
170 ;; rearrange everything whenever I wanted to make any corrections to
171 ;; the text? The answer is -- of course not! Use M-q. This does all
172 ;; the magic for you, justifying and breaking lines appropriately and
173 ;; putting any necessary semicolons or whatever at the left (it
174 ;; figures out what this ought to be by looking in a very clever
175 ;; fashion at what's already at the beginning of each line in the
176 ;; paragraph). You may need `filladapt' set up (it's done below in
177 ;; this file) in order for this to work properly. Finally, if you
178 ;; want to turn on automatic filling (like in a word processor, but
179 ;; not quite as automatic), use M-x auto-fill-mode or the binding set
180 ;; up below in this file (Meta-F9).
182 (or (fboundp 'emacs-version>=)
183 (defun emacs-version>= (major &optional minor patch)
184 "Return true if the Emacs version is >= to the given MAJOR, MINOR,
186 The MAJOR version number argument is required, but the other arguments
187 argument are optional. Only the Non-nil arguments are used in the test."
188 (let ((emacs-patch (or emacs-patch-level emacs-beta-version -1)))
189 (cond ((> emacs-major-version major))
190 ((< emacs-major-version major) nil)
192 ((> emacs-minor-version minor))
193 ((< emacs-minor-version minor) nil)
195 ((>= emacs-patch patch))))))
197 ;; 19.13 was released ages ago (Sep. 1995), and lots of graphic and
198 ;; window-system stuff doesn't work before then.
200 (or (not running-xemacs)
201 (emacs-version>= 19 13)
202 (error "This init file does not support XEmacs before 19.13"))
204 ;; Here are some example code snippets that you can use if you need to
205 ;; conditionalize on a particular version of Emacs (in general, though,
206 ;; it is much better to use `fboundp', `featurep', or other such
207 ;; feature-specific checks rather than version-specific checks):
209 ; (cond ((and running-xemacs
210 ; (emacs-version>= 21 2))
212 ; ;; Code requiring XEmacs version 21.2 or newer goes here
216 ; (cond ((emacs-version >= 19 0)
218 ; ;; Code for any vintage-19 Emacs goes here
222 ; (cond ((and (not running-xemacs)
223 ; (emacs-version>= 20 0))
225 ; ;; Code specific to GNU Emacs 20 or newer (not XEmacs) goes here
230 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
231 ;; Key Definitions ;;
232 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
234 ;;; Set up the function keys to do common tasks to reduce Emacs pinky
237 ;; You can set a key sequence either to a command or to another key
238 ;; sequence. (Use `C-h k' to map a key sequence to its command. Use
239 ;; `C-h w' to go the other way.) In general, however, it works better
240 ;; to specify the command name. For example, it does not currently
243 ;; (global-set-key 'f5 "\C-x\C-f")
245 ;; The reason is that macros (which is what the string on the right
246 ;; really is) can't currently use the minibuffer. This is an
247 ;; extremely longstanding bug in Emacs. Eventually, it will be
248 ;; fixed. (Hopefully ..)
250 ;; Note also that you may sometimes see the idiom
252 ;; (define-key global-map ...)
254 ;; in place of (global-set-key ...). These are exactly the same.
256 ;; Here I've tried to put all the most common commands on simple
257 ;; non-modifier function keys to take the pressure off your modifier
258 ;; fingers. Furthermore, on my keyboard at least, the function keys
259 ;; are grouped into three groups of four with spaces between them, and
260 ;; so it's easier to hit the keys at the edge of the groups --
261 ;; i.e. f1, f4, f5, f8, f9, and f12. Finally, you may note that f9,
262 ;; f11, and f12 are purposely left blank. [F6 is defined below.]
263 ;; That's because I use them for _, {, and } -- see below.
265 (global-set-key 'f1 'advertised-undo) ;; Undo
266 (global-set-key 'f2 'kill-primary-selection) ;; Cut
267 (global-set-key 'f3 'copy-primary-selection) ;; Copy
268 (global-set-key 'f4 'yank-clipboard-selection) ;; Paste
269 (global-set-key 'f5 'find-file) ;; C-x C-f
270 (global-set-key 'f7 'save-buffer) ;; C-x C-s
272 ;; I considered having this retain the current column after killing
273 ;; the line, but that messes up the common idiom `f8 move-cursor f4'.
275 (defun Init-kill-entire-line (&optional arg)
277 (let ((kill-whole-line t))
279 (call-interactively 'kill-line)))
282 (if (fboundp 'kill-entire-line) 'kill-entire-line 'Init-kill-entire-line))
284 ;; A keystroke repeated incredible amounts of times. We need to patch
285 ;; into the isearch keymap so that repeat searches while in isearch
286 ;; mode still work. Here we show how to make a key in a keymap have the
287 ;; same binding as another key in the keymap, without knowing what the
288 ;; binding is in advance; instead, we find it with `lookup-key'. This
289 ;; way, if the binding of C-s changes (e.g. to a different function) but
290 ;; the meaning is basically the same, we automatically do the right thing.
291 ;; If we put in the actual binding, which is 'isearch-repeat-forward,
292 ;; this automatic tracking wouldn't happen.
294 ;; TIP: To find out what the (lookup-key ...) expression evaluates to,
295 ;; move just to the right of the closing paren and type C-x C-e.
297 (global-set-key 'f10 'isearch-forward)
298 (define-key isearch-mode-map 'f10 (lookup-key isearch-mode-map "\C-s"))
299 (define-key minibuffer-local-isearch-map 'f10
300 (lookup-key minibuffer-local-isearch-map "\C-s"))
301 (global-set-key '(shift f10) 'isearch-backward)
302 (define-key isearch-mode-map '(shift f10) (lookup-key isearch-mode-map "\C-r"))
303 (define-key minibuffer-local-isearch-map '(shift f10)
304 (lookup-key minibuffer-local-isearch-map "\C-r"))
306 ;; Here we define our own function and then bind a key to it.
308 (defun start-or-end-kbd-macro ()
309 ;; A doc string. This is optional.
310 "Start defining a keyboard macro, or stop if we're already defining."
311 ;; IMPORTANT: Any function bound to a key MUST have an interactive spec,
312 ;; usually just the following line:
314 (if defining-kbd-macro
316 (start-kbd-macro nil)))
318 ;; The macros used to have their place in the function keys, but I
319 ;; find that I use them significantly less than the really basic
320 ;; things on the function keys. When using a macro, you call the
321 ;; macro much more than define it, so the setup below makes some
324 (global-set-key '(shift kp-multiply) 'start-or-end-kbd-macro)
325 (global-set-key 'kp-multiply 'call-last-kbd-macro) ;; C-x e
327 ;; Note that you can refer to a key sequence either using an ASCII
328 ;; string or the "long way", with vectors and conses. You saw above
329 ;; (in a comment) the string form for specifying the key sequence `C-x
330 ;; C-f', which is "\C-x\C-f". (For those curious, \C-x is just an
331 ;; escape sequence that puts a ^X character into the string. Thus,
332 ;; the string just mentioned really just contains two characters, a ^X
333 ;; and a ^F.) The long way to specify the sequence `C-x C-f' would be
335 ;; [(control x) (control f)]
337 ;; The long format lets you specify all possible key sequences, while the
338 ;; string form only lets you specify sequences involving ASCII characters
339 ;; and/or modifiers and in fact only a subset of them.
341 ;; Other examples are:
345 ;; (You can leave out the parens when there is no modifier specified in
346 ;; the keystroke, and that's normally done.)
348 ;; [(shift control meta left)]
350 ;; (You can put more than one modifier in a keystroke.)
352 ;; (shift control meta left)
354 ;; (This is the same as the previous. when there's only one keystroke in
355 ;; the sequence, you can leave out the brackets, and that's normally
358 ;; [(control x) (shift button3)]
360 ;; (You can refer to mouse buttons just like keys -- apply modifiers,
361 ;; intermingle them in key sequences, etc. But there's only problem
362 ;; here, which is that with the mouse you don't just have one possible
363 ;; gesture, like with keys. You'd really like to control button-down,
364 ;; button-up, button-click (down and up without selecting anything),
365 ;; button drag, button double-click, etc. This is normally done by
366 ;; binding your key sequence to `mouse-track', and then putting hooks
367 ;; onto `mouse-track-click-hook', `mouse-track-drag-up-hook', etc. to
368 ;; customize the specific behavior.)
372 ;; (Ultimate reductionism -- no brackets, no parens. This is the form, in
373 ;; that, that the 'f1, 'f2, etc. took, which where in fact "long"
378 ;; (You cannot use '(control shift c) here. This applies whenever Shift +
379 ;; key translates to a single character. Note also that you can't use
380 ;; "\C-C" either; this refers to the non-shifted C-c, just like "\C-c"
384 ;; (Put a backslash in front of characters used in Lisp syntax.)
386 ;; Also, you can find out the name of a key using C-h c. WARNING:
387 ;; This does not report the correct name of the keys named `delete',
388 ;; `backspace', `return', `tab', `space', `escape', and `linefeed'!
389 ;; (More correct results can be achieved using
391 ;; ESC : (read-key-sequence "foo: ")
395 ;;;;;;;;;;;;;;;;;;;;;;;;
397 ;; Keystrokes to conveniently switch buffers.
399 ;; F6 is invaluable for flipping back and forth between two buffers
400 ;; you're working with.
402 (global-set-key 'f6 'switch-to-other-buffer) ;; M-C-l
403 (global-set-key '(meta n) 'switch-to-next-buffer-in-group)
404 (global-set-key '(meta p) 'switch-to-previous-buffer-in-group)
405 (global-set-key '(meta N) 'switch-to-next-buffer)
406 (global-set-key '(meta P) 'switch-to-previous-buffer)
408 ;; Define our own function to deal with the possibility that the newer
409 ;; stuff in the gutter code may not be present -- i.e. we're running
410 ;; an older XEmacs. Note that we avoid trying to "helpfully" define a
411 ;; function that is present in new versions of XEmacs, but not in
412 ;; older ones. That can very easily screw up code trying to determine
413 ;; what functionality is present using `fboundp' checks. See above,
414 ;; near `emacs-version>=', for a full discussion of this.
416 (defun Init-buffers-tab-omit (buf)
417 ;; a function specifying the buffers to omit from the buffers tab.
418 ;; This is passed a buffer and should return non-nil if the buffer
419 ;; should be omitted. If the standard buffers-tab functionality is
420 ;; there, we just call it to do things "right". Otherwise we just
421 ;; omit invisible buffers, snarfing the code from
422 ;; `buffers-menu-omit-invisible-buffers'.
423 (if (boundp 'buffers-tab-omit-function)
424 (funcall buffers-tab-omit-function buf)
425 (not (null (string-match "\\` " (buffer-name buf))))))
427 (defun switch-to-next-buffer (&optional n)
428 "Switch to the next-most-recent buffer.
429 This essentially rotates the buffer list forward.
430 N (interactively, the prefix arg) specifies how many times to rotate
431 forward, and defaults to 1. Buffers whose name begins with a space
432 \(i.e. \"invisible\" buffers) are ignored."
433 ;; Here is a different interactive spec. Look up the function
434 ;; `interactive' (i.e. `C-h f interactive') to understand how this
437 (dotimes (n (or n 1))
439 do (bury-buffer (car (buffer-list)))
440 while (Init-buffers-tab-omit (car (buffer-list))))
441 (switch-to-buffer (car (buffer-list)))))
443 (defun buffers-menu-omit-invisible-buffers (buf)
444 "For use as a value of `buffers-menu-omit-function'.
445 Omits normally invisible buffers (those whose name begins with a space)."
446 (not (null (string-match "\\` " (buffer-name buf)))))
448 (defvar Init-buffers-tab-grouping-regexp
449 '("^\\(gnus-\\|message-mode\\|mime/viewer-mode\\)"
450 "^\\(emacs-lisp-\\|lisp-\\)")
451 ;; If non-nil, a list of regular expressions for buffer grouping.
452 ;; Each regular expression is applied to the current major-mode symbol
453 ;; name and mode-name, if it matches then any other buffers that match
454 ;; the same regular expression be added to the current group. This is
455 ;; a copy of `buffers-tab-grouping-regexp'.
458 (defun Init-select-buffers-tab-buffers (buffer-to-select buf1)
459 ;; Specifies the buffers to select from the buffers tab. This is
460 ;; passed two buffers and should return non-nil if the second buffer
461 ;; should be selected. If the standard buffers-tab functionality is
462 ;; there, we just call it to do things "right". Otherwise, we group
463 ;; buffers by major mode and by `Init-buffers-tab-grouping-regexp'.
464 ;; [We've copied `select-buffers-tab-buffers-by-mode' and
465 ;; `buffers-tab-grouping-regexp'.]
466 (if (boundp 'buffers-tab-selection-function)
467 (funcall buffers-tab-selection-function buffer-to-select buf1)
468 (let ((mode1 (symbol-name (symbol-value-in-buffer 'major-mode buf1)))
469 (mode2 (symbol-name (symbol-value-in-buffer 'major-mode
471 (modenm1 (symbol-value-in-buffer 'mode-name buf1))
472 (modenm2 (symbol-value-in-buffer 'mode-name buffer-to-select)))
473 (cond ((or (eq mode1 mode2)
475 (and (string-match "^[^-]+-" mode1)
477 (concat "^" (regexp-quote
478 (substring mode1 0 (match-end 0))))
480 (and Init-buffers-tab-grouping-regexp
481 (find-if #'(lambda (x)
483 (and (string-match x mode1)
484 (string-match x mode2))
485 (and (string-match x modenm1)
486 (string-match x modenm2))))
487 Init-buffers-tab-grouping-regexp)))
491 (defun switch-to-previous-buffer (&optional n)
492 "Switch to the previously most-recent buffer.
493 This essentially rotates the buffer list backward.
494 N (interactively, the prefix arg) specifies how many times to rotate
495 backward, and defaults to 1. Buffers whose name begins with a space
496 \(i.e. \"invisible\" buffers) are ignored."
498 (dotimes (n (or n 1))
500 do (switch-to-buffer (car (last (buffer-list))))
501 while (Init-buffers-tab-omit (car (buffer-list))))))
503 (defun switch-to-next-buffer-in-group (&optional n)
504 "Switch to the next-most-recent buffer in the current group.
505 This essentially rotates the buffer list forward.
506 N (interactively, the prefix arg) specifies how many times to rotate
507 forward, and defaults to 1. Buffers whose name begins with a space
508 \(i.e. \"invisible\" buffers) are ignored."
510 (dotimes (n (or n 1))
511 (let ((curbuf (car (buffer-list))))
513 do (bury-buffer (car (buffer-list)))
514 while (or (Init-buffers-tab-omit (car (buffer-list)))
515 (not (Init-select-buffers-tab-buffers
516 curbuf (car (buffer-list)))))))
517 (switch-to-buffer (car (buffer-list)))))
519 (defun switch-to-previous-buffer-in-group (&optional n)
520 "Switch to the previously most-recent buffer in the current group.
521 This essentially rotates the buffer list backward.
522 N (interactively, the prefix arg) specifies how many times to rotate
523 backward, and defaults to 1. Buffers whose name begins with a space
524 \(i.e. \"invisible\" buffers) are ignored."
526 (dotimes (n (or n 1))
527 (let ((curbuf (car (buffer-list))))
529 do (switch-to-buffer (car (last (buffer-list))))
530 while (or (Init-buffers-tab-omit (car (buffer-list)))
531 (not (Init-select-buffers-tab-buffers
532 curbuf (car (buffer-list)))))))))
534 ;;;;;;;;;;;;;;;;;;;;;;;;
536 ;; Other text keystrokes.
538 ;; Make a keystroke to insert a literal TAB character. (`C-q TAB' is
539 ;; annoying because difficult to repeat.) Note that this does not work
540 ;; in TTY frames, where TAB and Shift-TAB are indistinguishable.
541 (define-key global-map '(shift tab) 'tab-to-tab-stop)
543 ;; Toggle auto-filling. Useful with text but annoying with code. You
544 ;; can manually fill with M-q.
545 (global-set-key '(meta f9) 'auto-fill-mode)
547 ;; You cannot say '(meta shift t) here -- see above.
548 (if (fboundp 'transpose-line-down)
549 (global-set-key '(meta T) 'transpose-line-down))
550 (if (fboundp 'transpose-line-up)
551 (global-set-key '(control T) 'transpose-line-up))
553 ;;;;;;;;;;;;;;;;;;;;;;;;
555 ;; Rearrange some inconvenient bindings.
557 ;; ESC ESC ESC is a useful command, but too long. ESC ESC would be
558 ;; much more logical, but interferes with Meta + keypad/arrow keys on
559 ;; TTY's. But most people only use window systems and no such problem
560 ;; exists there, so set up the more logical binding there.
562 ;; Note also the use of if vs. cond/when/unless/or/and to express
563 ;; conditional statements. The difference is purely stylistic.
565 (when (console-on-window-system-p)
566 (global-set-key '(meta escape) 'keyboard-escape-quit)
567 (define-key isearch-mode-map '(meta escape) 'isearch-cancel))
569 ;; The standard definition of C-z causes iconification on window
570 ;; systems, which is both useless and annoying. Instead, bind it to a
571 ;; useful command that's not on any keys. (This also makes a neat
572 ;; parallelism with M-z, which does zap-to-char.) Don't override the
573 ;; TTY binding, which does "Suspend". If you want this new binding on
574 ;; TTY's, and can train yourself to use C-x C-z to suspend, then
575 ;; remove or comment out the `when' statement. (Here's the proper way
576 ;; to comment out such a statement:
578 ;; ;(when (console-on-window-system-p)
579 ;; (global-set-key "\C-z" 'zap-up-to-char)
582 ;; To do this, I first moved the closing paren to a new line,
583 ;; reindented with TAB, then added the semicolons.)
585 (when (console-on-window-system-p)
586 (global-set-key "\C-z" 'zap-up-to-char))
588 ;; When not on a TTY, remove the binding of C-x C-c, which normally
589 ;; exits XEmacs. It's easy to hit this by mistake, and that can be
590 ;; annoying. You can always quit with the "Exit XEmacs" option on the
593 (when (console-on-window-system-p)
594 (global-set-key "\C-x\C-c" nil))
596 ;; Make C-k always delete the whole line, which is what most people want,
598 (setq kill-whole-line 'always)
599 ;; M-k does the old behavior (kill to end of line).
600 (global-set-key '(meta k) #'(lambda ()
602 (if (fboundp 'historical-kill-line)
603 (call-interactively #'historical-kill-line)
604 (let ((kill-whole-line nil))
605 (call-interactively #'kill-line)))))
606 ;; and Meta-Shift-K does what used to be on M-k, and should
607 ;; (hopefully) even work under TTY's.
608 (global-set-key '(meta K) 'kill-sentence)
610 ;; Make sure we get Windows-like shifted-motion key selection behavior
611 ;; on recent XEmacs versions.
612 (if (boundp 'shifted-motion-keys-select-region)
613 (setq shifted-motion-keys-select-region t)
614 ;; otherwise, try the pc-select package --
621 ;; The following commented-out code rearranges the keymap in an
622 ;; unconventional but extremely useful way for programmers. Parens
623 ;; and braces are both available without using the shift key (using
624 ;; the bracket keys and f11/f12, respectively). Brackets (much less
625 ;; used) are the shifted versions of the new paren keys (i.e. where
626 ;; the braces normally are).
628 ;; The idea for this comes from Jamie Zawinski.
630 ;; Also make a convenient keystroke for _, used constantly in C code.
632 ;; NOTE: you can (semi-) conveniently uncomment a region using
633 ;; C-u M-x comment-region, or the "Uncomment Region" menu item on the
634 ;; Lisp menu in new enough versions of XEmacs.
636 ;(keyboard-translate ?[ ?()
637 ;(keyboard-translate ?] ?))
638 ;(keyboard-translate ?{ ?[)
639 ;(keyboard-translate ?} ?])
640 ;;; We don't use `keyboard-translate' for these because it messes up
641 ;;; bindings for M-F9 and the like.
642 ;(define-key key-translation-map 'f11 "{")
643 ;(define-key key-translation-map 'f12 "}")
644 ;(define-key key-translation-map 'f9 "_")
647 ;;;;;;;;;;;;;;;;;;;;;;;;
649 ;; Useful programming-related keystrokes.
651 (defun describe-foo-at-point ()
654 ;; sigh, function-at-point is too clever. we want only the first half.
655 (cond ((setq sym (ignore-errors
656 (with-syntax-table emacs-lisp-mode-syntax-table
658 (or (not (zerop (skip-syntax-backward "_w")))
659 (eq (char-syntax (char-after (point))) ?w)
660 (eq (char-syntax (char-after (point))) ?_)
662 (skip-chars-forward "`'")
663 (let ((obj (read (current-buffer))))
664 (and (symbolp obj) (fboundp obj) obj))))))
665 (describe-function sym))
666 ((setq sym (variable-at-point)) (describe-variable sym))
667 ;; now let it operate fully -- i.e. also check the
668 ;; surrounding sexp for a function call.
669 ((setq sym (function-at-point)) (describe-function sym)))))
671 (global-set-key '(shift f4) 'next-error) ;; C-x `
672 (global-set-key '(control f4) 'previous-error)
673 (global-set-key '(shift f5) 'find-library)
674 (global-set-key '(control f5) 'find-function)
675 (global-set-key '(meta f5) 'find-variable)
676 (global-set-key '(shift f11) 'describe-foo-at-point)
677 (global-set-key '(control f11) 'eval-last-sexp)
678 ;; Edebug is a source-level debugger for Emacs Lisp programs. Put
679 ;; the cursor at the end of a function definition and "instrument" it
680 ;; with this command; then, you can single step through it the next
682 (global-set-key '(meta f11) 'edebug-defun)
683 (global-set-key '(meta f12) 'add-change-log-entry)
685 ;; This nicely parallels M-*, which pops the tag stack. See below for
686 ;; how to set up tags.
687 (global-set-key '(control *) 'find-tag-at-point)
689 ;; Define a function to conveniently determine where time is being
690 ;; spent when executing commands or Lisp code.
691 (defun toggle-profiling ()
692 "Start profiling, or stop it and print results.
693 This lets you figure out where time is being spent when executing Lisp code."
695 (if (profiling-active-p)
698 (message "...Finished profiling")
700 (message "Profiling...")
701 (clear-profiling-info)
704 ;; Note that sequences of C-c plus a letter are specifically
705 ;; reserved for users and should never be bound by any packages.
707 (global-set-key "\C-cp" 'toggle-profiling)
709 ;; LISPM bindings of Control-Shift-C and Control-Shift-E.
710 ;; See comment above about bindings like this.
711 (define-key emacs-lisp-mode-map '(control C) 'compile-defun)
712 (define-key emacs-lisp-mode-map '(control E) 'eval-defun)
714 ;;;;;;;;;;;;;;;;;;;;;;;;
718 ;; The numeric keypad as a whole is underused, and it's a good source
719 ;; of keys to bind to commands. Here we add some useful bindings.
720 ;; Because this is a sample file and I want to avoid unpleasant
721 ;; surprises for novices, I don't actually bind the shared
722 ;; numeric/cursor-motion keys because
724 ;; (a) someone keypads don't have separate motion keys (e.g. laptops?), and
725 ;; (b) TTY's and some X servers might not distinguish the regular and
726 ;; numeric-keypad motion keys.
728 ;; `kill-current-buffer' (defined below) deletes the current
729 ;; buffer. (Don't worry, you will be prompted to save if it's
730 ;; modified.) By repeatedly pressing keypad-minus, you can
731 ;; conveniently reduce the number of open buffers to a manageable size
732 ;; after you've opened a whole bunch of files and finished working on
733 ;; them. Shift plus keypad-minus kills both the current buffer and
734 ;; its window, and Control plus keypad-minus kills just the current
737 (global-set-key 'kp-subtract 'kill-current-buffer)
738 (global-set-key '(shift kp-subtract) 'kill-current-buffer-and-window)
739 (global-set-key '(control kp-subtract) 'delete-window)
740 ;; Ugh, modes that use `suppress-keymap' and are dumped with XEmacs will
741 ;; need their own definition. There is no easy way to fix this.
742 (define-key help-mode-map 'kp-subtract 'kill-current-buffer)
743 (define-key help-mode-map '(shift kp-subtract)
744 'kill-current-buffer-and-window)
745 (define-key list-mode-map 'kp-subtract 'kill-current-buffer)
746 (define-key list-mode-map '(shift kp-subtract)
747 'kill-current-buffer-and-window)
749 (defun kill-current-buffer ()
751 (kill-buffer (current-buffer)))
753 (defun kill-current-buffer-and-window ()
755 (kill-buffer (current-buffer))
758 (defun grep-c-files ()
762 (cons (concat grep-command " *.[chCH]"
763 ; i wanted to also use *.cc and *.hh.
764 ; see long comment below under Perl.
766 (length grep-command))))
767 (call-interactively 'grep)))
769 (defun grep-lisp-files ()
773 (cons (concat grep-command " *.el"
774 ; i wanted to also use *.cc and *.hh.
775 ; see long comment below under Perl.
777 (length grep-command))))
778 (call-interactively 'grep)))
780 ;; This repeatedly selects larger and larger balanced expressions
781 ;; around the cursor. Once you have such an expression marked, you
782 ;; can expand to the end of the following expression with C-M-SPC and
783 ;; to the beginning of the previous with M-left.
785 (defun clear-select ()
786 (interactive "_") ;this means "preserve the active region after this command"
788 (let ((end (save-excursion (forward-sexp) (point))))
789 (push-mark end nil t)))
791 ;; #### no kp-divide because it doesn't (currently) work on MS Windows
792 ;; -- always reports as /. #### this should be fixable.
793 (global-set-key 'kp-add 'query-replace)
794 (global-set-key '(shift kp-add) 'query-replace-regexp)
795 (global-set-key '(control kp-add) 'grep-c-files)
796 (global-set-key '(meta kp-add) 'grep-lisp-files)
797 (global-set-key 'clear 'clear-select)
798 ;; Note that you can use a "lambda" expression (an anonymous function)
799 ;; in place of a function name. This function would be called
800 ;; `pop-local-mark' and lets you repeatedly cycle back through recent
801 ;; marks (marks are set whenever you begin a selection, begin a
802 ;; successful search, are about to jump to the beginning or end of the
804 (global-set-key 'kp-enter (lambda () (interactive) (set-mark-command t)))
805 (global-set-key '(shift kp-enter) 'repeat-complex-command)
806 (global-set-key 'pause 'repeat-complex-command) ;; useful on Windows-stlye kbds
807 (global-set-key '(control kp-enter) 'eval-expression)
809 ;;;;;;;;;;;;;;;;;;;;;;;;
813 ;; If you want button2 to insert the selected text
814 ;; at point (where the text cursor is), instead of at the
815 ;; position clicked, uncomment the following:
817 ;(setq mouse-yank-at-point t)
819 ;; If you like the FSF Emacs binding of button3 (single-click
820 ;; extends the selection, double-click kills the selection),
821 ;; uncomment the following:
823 ;(define-key global-map 'button3 'mouse-track-adjust)
825 ;(add-hook 'mouse-track-click-hook
826 ; (lambda (event count)
827 ; (if (or (/= (event-button event) 3)
829 ; nil ;; do the normal operation
830 ; (kill-region (point) (mark))
831 ; t ;; don't do the normal operations.
834 ;; Uncomment this to enable "sticky modifier keys". With sticky
835 ;; modifier keys enabled, you can press and release a modifier key
836 ;; before pressing the key to be modified, like how the ESC key works
837 ;; always. If you hold the modifier key down, however, you still get
838 ;; the standard behavior. I personally think this is the best thing
839 ;; since sliced bread (and a *major* win when it comes to reducing
840 ;; Emacs pinky), but it's disorienting at first so I'm not enabling it
843 ;(setq modifier-keys-are-sticky t)
845 ;; Enable the command `narrow-to-region' ("C-x n n"). It's a useful
846 ;; command, but possibly confusing to a new user, so it's disabled by
848 (put 'narrow-to-region 'disabled nil)
850 ;; Enable obvious hyperlink following with button1.
851 (setq Info-button1-follows-hyperlink t)
854 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
855 ;; Change Some Basic Behaviors ;;
856 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
858 ;; Change the values of some variables.
859 ;; (t means true; nil means false.)
861 ;; Use C-h v or `Help->Commands, Variables, Keys->Describe Variable...'
862 ;; to find out what these variables mean.
864 find-file-compare-truenames t
865 minibuffer-max-depth nil
868 ;; When running ispell, consider all 1-3 character words as correct.
869 (setq ispell-extra-args '("-W" "3"))
871 ;;; pending-delete-mode causes typed text to replace a selection,
872 ;;; rather than append -- standard behavior under all window systems
875 (pending-delete-mode 1)
877 ;;; enable region selection with shift+arrows (on by default in 21.5
879 (setq shifted-motion-keys-select-region t)
881 ;;; NOTE: In this context, `windows-nt' actually refers to all MS
882 ;;; Windows operating systems!
883 (when (eq system-type 'windows-nt)
884 ;; Get mail working under Windows.
885 (setq send-mail-function 'smtpmail-send-it)
886 (setq smtpmail-debug-info t)
887 ;; Substitute your info here.
888 ;(setq user-mail-address "ben@xemacs.org")
889 ;(setq user-full-name "Ben Wing")
890 ;(setq smtpmail-smtp-server "pop.tcsn.uswest.net")
892 ;; Make Alt+accelerator traverse to the menu in new enough XEmacs
893 ;; versions. Note that this only overrides Meta bindings that would
894 ;; actually invoke a menu, and that none of the most common commands
895 ;; are overridden. You can use ESC+key to access the overridden
896 ;; ones if necessary.
897 (setq menu-accelerator-enabled 'menu-force)
899 ;; Make Cygwin `make' work inside a shell buffer.
900 (setenv "MAKE_MODE" "UNIX"))
902 ;; This shows how to set up the XEmacs side of tags. (To create the
903 ;; TAGS table, use the `etags' program found in the XEmacs bin
904 ;; directory. Run it in the root directory of your source tree and
905 ;; specify all source and include files on the command line.)
906 ;(setq tag-table-alist
908 ; ;; Everywhere in the /src/xemacs/gui/ source tree will use the TAGS
909 ; ;; file in /src/xemacs/gui/.
910 ; ("/src/xemacs/gui/" . "/src/xemacs/gui/")
911 ; ;; Everywhere in the /src/xemacs/mule/ source tree will use the TAGS
912 ; ;; file in /src/xemacs/mule/.
913 ; ("/src/xemacs/mule/" . "/src/xemacs/mule/")
915 ; ("/src/xemacs/fixup/" . "/src/xemacs/fixup/")
916 ; ("/src/emacs/emacs-20.6/" . "/src/emacs/emacs-20.6/")
917 ; ("/src/xemacs/latest/" . "/src/xemacs/latest/")
918 ; ;; Everywhere else will use the TAGS file in
919 ; ;; /src/xemacs/fixup/.
920 ; ("" . "/src/xemacs/fixup/")
924 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
925 ;; Change Some Aspects of GUI Appearance ;;
926 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
928 ;; Changes the text in the window title bar, to switch to MS Windows
929 ;; format (filename goes first, for best identification in icons) and
930 ;; add the version and full executable path. (However, it is not
931 ;; changed unless it currently has the default value, to avoid
932 ;; interfering with a -wn command line argument I may have started
935 (if (or (equal frame-title-format "%S: %b")
936 (equal frame-title-format "%b - XEmacs"))
937 (setq frame-title-format
938 (concat "%b - XEmacs "
939 (progn (string-match "\\(.*?\\)\\( XEmacs Lucid\\)?$"
941 (match-string 1 emacs-version))
942 " [" invocation-directory invocation-name "]")))
944 ;; Load some nifty sounds that will replace the default beep.
946 ;; (Note that sampled sounds only work if XEmacs was compiled with
947 ;; sound support and we're running on MS Windows, on a machine which
948 ;; has a NetAudio or ESD server, or on the console of a Linux, Sparc,
949 ;; HP, or SGI machine. Otherwise, you just get the standard beep.)
951 (cond ((or (and (getenv "DISPLAY")
952 (string-match ":0" (getenv "DISPLAY")))
953 (and (eq (console-type) 'mswindows)
954 (device-sound-enabled-p)))
955 (load-default-sounds)
956 ;; On Windows, at least, the sound "quiet-beep", which is normally
957 ;; given the symbolic name `quiet' and is used for Quit and such,
958 ;; is just totally disgusting. So make this name correspond to a
959 ;; more innocuous sound.
960 (load-sound-file "drum-beep" 'quiet 80))
962 (setq bell-volume 40)
964 (append sound-alist '((no-completion :pitch 500))))
967 ;; Change the continuation glyph face so it stands out more
968 (make-face-bold (glyph-face continuation-glyph))
970 ;; Change the pointer used during garbage collection.
972 ;; Note that this pointer image is rather large as pointers go,
973 ;; and so it won't work on some X servers (such as the MIT
974 ;; R5 Sun server) because servers may have lamentably small
975 ;; upper limits on pointer size.
976 ;;(if (featurep 'xpm)
977 ;; (set-glyph-image gc-pointer-glyph
978 ;; (expand-file-name "trash.xpm" data-directory)))
980 ;; Here's another way to do that: it first tries to load the
981 ;; pointer once and traps the error, just to see if it's
982 ;; possible to load that pointer on this system; if it is,
983 ;; then it sets gc-pointer-glyph, because we know that
984 ;; will work. Otherwise, it doesn't change that variable
985 ;; because we know it will just cause some error messages.
987 (let ((file (expand-file-name "recycle.xpm" data-directory)))
988 (if (condition-case nil
989 ;; check to make sure we can use the pointer.
990 (make-image-instance file nil
992 (error nil)) ; returns nil if an error occurred.
993 (set-glyph-image gc-pointer-glyph file))))
995 ;(when (featurep 'menubar)
996 ; ;; Add `dired' to the File menu
997 ; (add-menu-button '("File") ["Edit Directory" dired])
999 ; ;; Here's a way to add scrollbar-like buttons to the menubar
1000 ; (add-menu-button nil ["Top" beginning-of-buffer])
1001 ; (add-menu-button nil ["<<<" scroll-down])
1002 ; (add-menu-button nil [" . " recenter])
1003 ; (add-menu-button nil [">>>" scroll-up])
1004 ; (add-menu-button nil ["Bot" end-of-buffer]))
1006 ;; Here's a cute hack that shows how to programmatically change some
1007 ;; text colors. It changes the background color of the window if it's
1008 ;; not on the local machine, or if it's running as root:
1010 ;; local emacs background: whitesmoke [i.e. the default color]
1011 ;; remote emacs background: palegreen1
1012 ;; root emacs background: coral2
1014 ;; Uncomment to enable.
1017 ; ((and running-xemacs
1018 ; (console-on-window-system-p)
1019 ; ;; this does not make much sense on Windows.
1020 ; (not (eq system-type 'windows-nt)))
1021 ; (let* ((root-p (eq 0 (user-uid)))
1022 ; (dpy (or (getenv "DISPLAY") ""))
1024 ; (or (string-match "^\\(\\|unix\\|localhost\\):" dpy)
1025 ; (let ((s (system-name)))
1026 ; (if (string-match "\\.\\(netscape\\|mcom\\)\\.com" s)
1027 ; (setq s (substring s 0 (match-beginning 0))))
1028 ; (string-match (concat "^" (regexp-quote s)) dpy)))))
1029 ; (bg (cond (root-p "coral2")
1030 ; (remote-p "palegreen1")
1033 ; (let ((def (color-name (face-background 'default)))
1034 ; (faces (face-list)))
1036 ; (let ((obg (face-background (car faces))))
1037 ; (if (and obg (equal def (color-name obg)))
1038 ; (set-face-background (car faces) bg)))
1039 ; (setq faces (cdr faces)))))))))
1042 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1043 ;; Changing the Modeline ;;
1044 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1046 ;; Enable line numbers and column numbers. This is done in C code now
1047 ;; and is very fast.
1048 (line-number-mode 1)
1049 (column-number-mode 1)
1051 ;; Rearrange the modeline so that everything is to the left of the
1052 ;; long list of minor modes, which is relatively unimportant but takes
1053 ;; up so much room that anything to the right is obliterated.
1059 (if (boundp 'modeline-multibyte-status) 'modeline-multibyte-status "")
1060 (cons modeline-modified-extent 'modeline-modified)
1061 (cons modeline-buffer-id-extent
1062 (list (cons modeline-buffer-id-left-extent
1064 (list 'line-number-mode "L%l ")
1065 (list 'column-number-mode "C%c ")
1067 (cons modeline-buffer-id-right-extent "%17b")))
1071 (cons modeline-minor-mode-extent
1072 (list "" 'mode-name 'minor-mode-alist))
1073 (cons modeline-narrowed-extent "%n")
1079 ;; Get rid of modeline information taking up too much space -- in
1080 ;; particular, minor modes that are always enabled.
1081 (setq pending-delete-modeline-string "")
1082 (setq filladapt-mode-line-string "")
1083 ;; lazy-lock doesn't have a variable for its modeline name, so we have
1084 ;; to do a bit of surgery.
1085 (and (assoc 'lazy-lock-mode minor-mode-alist)
1086 (setcdr (cdr (cadr (assoc 'lazy-lock-mode minor-mode-alist))) ""))
1090 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1091 ;; Customization of Specific Packages ;;
1092 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1095 ;;; ********************
1096 ;;; Load gnuserv, which will allow you to connect to XEmacs sessions
1097 ;;; using `gnuclient'.
1099 ;; If you never run more than one XEmacs at a time, you might want to
1100 ;; always start gnuserv. Otherwise it is preferable to specify
1101 ;; `-f gnuserv-start' on the command line to one of the XEmacsen.
1105 ;;; ********************
1106 ;;; Load efs, which uses the FTP protocol as a pseudo-filesystem.
1107 ;;; When this is loaded, the pathname syntax /user@host:/remote/path
1108 ;;; refers to files accessible through ftp.
1111 ;; compatible ange-ftp/efs initialization derived from code
1112 ;; from John Turner <turner@lanl.gov>
1114 ;; The environment variable EMAIL_ADDRESS is used as the password
1115 ;; for access to anonymous ftp sites, if it is set. If not, one is
1116 ;; constructed using the environment variables USER and DOMAINNAME
1117 ;; (e.g. turner@lanl.gov), if set.
1123 (setq efs-default-user (getenv "USER")))
1124 (if (getenv "EMAIL_ADDRESS")
1125 (setq efs-generate-anonymous-password (getenv "EMAIL_ADDRESS"))
1126 (if (and (getenv "USER")
1127 (getenv "DOMAINNAME"))
1128 (setq efs-generate-anonymous-password
1129 (concat (getenv "USER")"@"(getenv "DOMAINNAME")))))
1130 (setq efs-auto-save 1))
1134 (setq ange-ftp-default-user (getenv "USER")))
1135 (if (getenv "EMAIL_ADDRESS")
1136 (setq ange-ftp-generate-anonymous-password (getenv "EMAIL_ADDRESS"))
1137 (if (and (getenv "USER")
1138 (getenv "DOMAINNAME"))
1139 (setq ange-ftp-generate-anonymous-password
1140 (concat (getenv "USER")"@"(getenv "DOMAINNAME")))))
1141 (setq ange-ftp-auto-save 1)
1145 ;;; ********************
1146 ;;; Load the default-dir.el package which installs fancy handling of
1147 ;;; the initial contents in the minibuffer when reading file names.
1149 ;(condition-case nil
1150 ; (require 'default-dir)
1154 ;;; ********************
1155 ;;; Put all of your autosave files in one place, instead of scattering
1156 ;;; them around the file system. This has many advantages -- e.g. it
1157 ;;; will eliminate slowdowns caused by editing files on a slow NFS
1158 ;;; server. (*Provided* that your home directory is local or on a
1159 ;;; fast server! If not, pick a value for `auto-save-directory' that
1160 ;;; is fast fast fast!)
1162 ;;; Unfortunately, the code that implements this (auto-save.el) is
1163 ;;; broken on Windows in 21.4 and earlier.
1164 (unless (and (eq system-type 'windows-nt)
1165 (not (emacs-version>= 21 5)))
1166 (setq auto-save-directory (expand-file-name "~/.autosave/")
1167 auto-save-directory-fallback auto-save-directory
1168 auto-save-hash-p nil
1170 efs-auto-save-remotely nil
1171 ;; now that we have auto-save-timeout, let's crank this up
1172 ;; for better interactive response.
1173 auto-save-interval 2000
1175 ;; We load this afterwards because it checks to make sure the
1176 ;; auto-save-directory exists (creating it if not) when it's loaded.
1177 (require 'auto-save)
1181 ;;; ********************
1182 ;;; cc-mode (the mode you're in when editing C, C++, and Objective C files)
1184 ;; Tell cc-mode not to check for old-style (K&R) function declarations.
1185 ;; This speeds up indenting a lot.
1186 (setq c-recognize-knr-p nil)
1188 ;; Change the indentation amount to 4 spaces instead of 2.
1189 ;; You have to do it in this complicated way because of the
1190 ;; strange way the cc-mode initializes the value of `c-basic-offset'.
1191 ;; (add-hook 'c-mode-hook (lambda () (setq c-basic-offset 4)))
1194 ;;; ********************
1195 ;;; Load a partial-completion mechanism, which makes minibuffer completion
1196 ;;; search multiple words instead of just prefixes; for example, the command
1197 ;;; `M-x byte-compile-and-load-file RET' can be abbreviated as `M-x b-c-a RET'
1198 ;;; because there are no other commands whose first three words begin with
1199 ;;; the letters `b', `c', and `a' respectively.
1201 (load-library "completer")
1204 ;;; ********************
1205 ;;; Load crypt, which is a package for automatically decoding and reencoding
1206 ;;; files by various methods - for example, you can visit a .Z or .gz file,
1207 ;;; edit it, and have it automatically re-compressed when you save it again.
1209 (setq crypt-encryption-type 'pgp ; default encryption mechanism
1210 crypt-confirm-password t ; make sure new passwords are correct
1211 ;crypt-never-ever-decrypt t ; if you don't encrypt anything, set this to
1212 ; tell it not to assume that "binary" files
1213 ; are encrypted and require a password.
1218 ;;; ********************
1219 ;;; Filladapt is a syntax-highlighting package. When it is enabled it
1220 ;;; makes filling (e.g. using M-q) much much smarter about paragraphs
1221 ;;; that are indented and/or are set off with semicolons, dashes, etc.
1223 (require 'filladapt)
1224 (setq-default filladapt-mode t)
1225 (add-hook 'c-mode-hook 'turn-off-filladapt-mode)
1228 ;;; ********************
1229 ;;; Font-Lock is a syntax-highlighting package. When it is enabled and you
1230 ;;; are editing a program, different parts of your program will appear in
1231 ;;; different fonts or colors. For example, with the code below, comments
1232 ;;; appear in red italics, function names in function definitions appear in
1233 ;;; blue bold, etc. The code below will cause font-lock to automatically be
1234 ;;; enabled when you edit C, C++, Emacs-Lisp, and many other kinds of
1237 ;;; The "Options" menu has some commands for controlling this as well.
1239 (cond (running-xemacs
1241 ;; The commented-out code below is an example of setting up custom
1242 ;; font-lock colors.
1244 ; ;; If you want the default colors, you could do this:
1245 ; ;; (setq font-lock-use-default-fonts nil)
1246 ; ;; (setq font-lock-use-default-colors t)
1247 ; ;; but I want to specify my own colors, so I turn off all
1248 ; ;; default values.
1249 ; (setq font-lock-use-default-fonts nil)
1250 ; (setq font-lock-use-default-colors nil)
1252 (require 'font-lock)
1254 ; ;; Mess around with the faces a bit. Note that you have
1255 ; ;; to change the font-lock-use-default-* variables *before*
1256 ; ;; loading font-lock, and wait till *after* loading font-lock
1257 ; ;; to customize the faces.
1259 ; ;; string face is green
1260 ; (set-face-foreground 'font-lock-string-face "forest green")
1262 ; ;; comments are italic and red; doc strings are italic
1263 ; (set-face-font 'font-lock-comment-face [italic])
1264 ; ;; Underlining comments looks terrible on tty's
1265 ; (set-face-underline-p 'font-lock-comment-face nil 'global 'tty)
1266 ; (set-face-highlight-p 'font-lock-comment-face t 'global 'tty)
1267 ; (copy-face 'font-lock-comment-face 'font-lock-doc-string-face)
1268 ; (set-face-foreground 'font-lock-comment-face "red")
1270 ; ;; function names are bold and blue
1271 ; (set-face-font 'font-lock-function-name-face [bold])
1272 ; (set-face-foreground 'font-lock-function-name-face "blue")
1275 ; (set-face-font 'font-lock-preprocessor-face [bold])
1276 ; (set-face-font 'font-lock-type-face [italic])
1277 ; (set-face-font 'font-lock-keyword-face [bold])
1281 ;;; ********************
1282 ;;; lazy-lock is a package which speeds up the highlighting of files
1283 ;;; by doing it "on-the-fly" -- only the visible portion of the
1284 ;;; buffer is fontified. The results may not always be quite as
1285 ;;; accurate as using full font-lock or fast-lock, but it's *much*
1286 ;;; faster. No more annoying pauses when you load files.
1288 (add-hook 'font-lock-mode-hook 'turn-on-lazy-lock)
1289 ;; I personally don't like "stealth mode" (where lazy-lock starts
1290 ;; fontifying in the background if you're idle for 30 seconds)
1291 ;; because it takes too long to wake up again on my piddly Sparc 1+.
1292 (setq lazy-lock-stealth-time nil)
1295 ;;; ********************
1296 ;;; func-menu is a package that scans your source file for function
1297 ;;; definitions and makes a menubar entry that lets you jump to any
1298 ;;; particular function definition by selecting it from the menu. The
1299 ;;; following code turns this on for all of the recognized languages.
1300 ;;; Scanning the buffer takes some time, but not much.
1302 ;;; Send bug reports, enhancements etc to:
1303 ;;; David Hughes <ukchugd@ukpmr.cs.philips.nl>
1305 (cond (running-xemacs
1306 (require 'func-menu)
1307 (global-set-key '(shift f12) 'function-menu)
1308 (add-hook 'find-file-hooks 'fume-add-menubar-entry)
1309 (global-set-key "\C-cl" 'fume-list-functions)
1310 (global-set-key "\C-cg" 'fume-prompt-function-goto)
1312 ;; The Hyperbole information manager package uses (shift button2) and
1313 ;; (shift button3) to provide context-sensitive mouse keys. If you
1314 ;; use this next binding, it will conflict with Hyperbole's setup.
1315 ;; Choose another mouse key if you use Hyperbole.
1316 (global-set-key '(shift button3) 'mouse-function-menu)
1318 ;; For descriptions of the following user-customizable variables,
1319 ;; type C-h v <variable>
1320 (setq fume-max-items 25
1321 fume-fn-window-position 3
1322 fume-auto-position-popup t
1323 fume-display-in-modeline-p t
1324 fume-menubar-menu-name
1325 (if (fboundp 'submenu-generate-accelerator-spec)
1326 "Function%_s" "Functions")
1327 fume-buffer-name "*Function List*"
1328 fume-no-prompt-on-valid-default nil)
1332 ;;; ********************
1333 ;;; MH is a mail-reading system from the Rand Corporation that relies on a
1334 ;;; number of external filter programs (which do not come with emacs.)
1335 ;;; Emacs provides a nice front-end onto MH, called "mh-e".
1337 ;; Bindings that let you send or read mail using MH
1338 ;(global-set-key "\C-xm" 'mh-smail)
1339 ;(global-set-key "\C-x4m" 'mh-smail-other-window)
1340 ;(global-set-key "\C-cr" 'mh-rmail)
1342 ;; Customization of MH behavior.
1343 (setq mh-delete-yanked-msg-window t)
1344 (setq mh-yank-from-start-of-msg 'body)
1345 (setq mh-summary-height 11)
1347 ;; Use lines like the following if your version of MH
1348 ;; is in a special place.
1349 ;(setq mh-progs "/usr/dist/pkgs/mh/bin.svr4/")
1350 ;(setq mh-lib "/usr/dist/pkgs/mh/lib.svr4/")
1353 ;;; ********************
1354 ;;; resize-minibuffer-mode makes the minibuffer automatically
1355 ;;; resize as necessary when it's too big to hold its contents.
1357 (autoload 'resize-minibuffer-mode "rsz-minibuf" nil t)
1358 (resize-minibuffer-mode)
1359 (setq resize-minibuffer-window-exactly nil)
1362 ;;; ********************
1363 ;;; 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.
1365 (require 'scroll-in-place)
1366 (turn-on-scroll-in-place)
1369 ;;; ********************
1370 ;;; W3 is a browser for the World Wide Web, and takes advantage of the very
1371 ;;; latest redisplay features in XEmacs. You can access it simply by typing
1372 ;;; 'M-x w3'; however, if you're unlucky enough to be on a machine that is
1373 ;;; behind a firewall, you will have to do something like this first:
1375 ;(setq w3-use-telnet t
1377 ; ;; If the Telnet program you use to access the outside world is
1378 ; ;; not called "telnet", specify its name like this.
1379 ; w3-telnet-prog "itelnet"
1381 ; ;; If your Telnet program adds lines of junk at the beginning
1382 ; ;; of the session, specify the number of lines here.
1383 ; w3-telnet-header-length 4