1 ;; -*- Mode: Emacs-Lisp -*-
3 ;; Copyright (C) 2000, 2001 Ben Wing.
4 ;; Copyright (C) 2007 Steve Youngs
6 ;; Author: Mostly Ben Wing <ben@xemacs.org>
7 ;; Updated for SXEmacs by Steve Youngs <steve@sxemacs.org>
8 ;; Maintainer: SXEmacs Development Team
9 ;; Keywords: sample, initialization
11 ;; This file is part of SXEmacs.
13 ;; SXEmacs is free software: you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation, either version 3 of the License, or
16 ;; (at your option) any later version.
18 ;; SXEmacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
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, in
32 ;; (sxemacs)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. In SXEmacs, this file, called `init.el', is
37 ;;; located in the directory defined in the `user-init-directory'
38 ;;; variable. It normally defaults to `${XDG_CONFIG_HOME}/sxemacs',
39 ;;; or `${HOME}/.config/sxemacs' if the XDG environment isn't set.
40 ;;; Historically, this file was located in `~/.sxemacs', and indeed,
41 ;;; that directory is still supported.
43 ;;; To find out exactly where your SXEmacs would look for your init.el
46 ;;; M-: user-init-directory RET
48 ;;; Other files are also located here, such as custom-${USER}.el (the
49 ;;; auto-generated file containing Customization options that you
50 ;;; saved when using Options->Save Options).
52 ;;; Changes to your init.el file will not take effect until the next
53 ;;; time you start up SXEmacs, unless you load it explicitly with
57 ;;; You'll then be prompted for a file name, give it the full path
58 ;;; to your init.el and hit `RET'
60 ;;; The language that this file (and most other SXEmacs init files) is
61 ;;; written in is called "Emacs Lisp" or more commonly "elisp".
63 ;;; Brief descriptions of how the init process works and how to
64 ;;; accomplish many useful customizations are given below in this
65 ;;; file. There are many sources of further information:
67 ;;; -- the SXEmacs User's Manual (Access using the online Info browser:
68 ;;; Use `Help->Info (Online Docs)->SXEmacs User's Manual'
69 ;;; (if there is such an entry); or get to the Info contents
70 ;;; page using `Help->Info Contents' or `C-h i', and then
71 ;;; *middle-click* the SXEmacs link or move the cursor into
72 ;;; the link and hit ENTER. This manual contains a great
73 ;;; deal of documentation on customization: Scroll down to
74 ;;; the Customization link and select it in the same fashion
75 ;;; as for the SXEmacs link just mentioned.)
77 ;;; -- the SXEmacs FAQ (`C-h F' for the local version; get either the
78 ;;; local version or the very latest version off the net using
81 ;;; -- the SXEmacs Lisp Reference Manual, containing detailed
82 ;;; documentation on elisp. (Access using Info, just like for the
83 ;;; SXEmacs User's Manual.)
85 ;;; -- the documentation strings for specific commands, functions,
86 ;;; key sequences, and variables. NOTE: This is *not* the same
87 ;;; information as in the SXEmacs User's Manual or SXEmacs Lisp
88 ;;; Reference Manual! In general, the doc strings are more
89 ;;; terse and more up-to-date than what is found in the manuals.
90 ;;; Once you understand the general concepts, these doc strings
91 ;;; should be your first point of reference for further
92 ;;; info. (Access using menu entries under `Help->Commands,
93 ;;; Variables, Keys' or using the keyboard: `C-h k' for a key
94 ;;; sequence, `C-h f' for a named command or Elisp function,
95 ;;; `C-h v' for a variable. There is various other useful
96 ;;; information accessible similarly, such as `C-h a'
97 ;;; ["Apropos", i.e. search for a command, function, or variable
98 ;;; by name]; `C-h C-a' ["Apropos Docs", i.e. search through the
99 ;;; text of the doc strings]; `C-h b' to list all key bindings;
100 ;;; `C-h m' to describe the current major and minor modes; etc.
101 ;;; Type `C-h ? ?' for a complete list.)
103 ;;; -- Getting Started with SXEmacs [aka the "New User's Guide"], a
104 ;;; more introductory manual than the SXEmacs User's Manual.
105 ;;; (Access using Info, just like for the SXEmacs User's Manual.
106 ;;; There are some sections on customization here.)
108 ;;; -- the SXEmacs tutorial, a very simple introduction to SXEmacs for
109 ;;; total beginners. (`C-h t' for English; get the version in
110 ;;; various languages from the Help menu)
112 ;;; -- the SXEmacs web site, www.sxemacs.org. And the XEmacs web
113 ;;; site, www.xemacs.org.
115 ;;; -- the XEmacs mailing lists (xemacs-FOO@xemacs.org;
116 ;;; see http://www.xemacs.org/Lists/ for more info. Before
117 ;;; posting, consider looking through the archives -- they go back
118 ;;; years and there is a powerful searching interface. Currently
119 ;;; the archives are at http://list-archive.xemacs.org/, but if
120 ;;; this doesn't work, you can always access them through
123 ;;; -- the SXEmacs mailing lists (sxemacs-devel@sxemacs.org and
124 ;;; sxemacs-patches@sxemacs.org). These lists are set to
125 ;;; "member-only" posts because of SPAM issues, but subscribing
126 ;;; isn't all that painful (normal mailman procedure) and the
127 ;;; archives are publically accessible at
128 ;;; http://www.sxemacs.org/list-archives/html/
130 ;;; -- the XEmacs newsgroup, comp.emacs.xemacs. The SXEmacs developers
131 ;;; don't normally watch this newsgroup very closely.
133 ;;; -- the SXEmacs internals manual, for those interested in working on
134 ;;; the SXEmacs C code. (Available through Info.)
136 ;;; -- the freenode IRC channel, #sxemacs. Most of the core SXEmacs
137 ;;; developers can be found in this channel.
139 ;;; -- `Help->About SXEmacs' to find out who the maintainers are.
142 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
143 ;; Theory of Operation ;;
144 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
146 ;;; SXEmacs allows you to make persistent changes to editor behavior by
147 ;;; saving code in files which are by default loaded at startup.
149 ;; These files are just Lisp libraries with names built in to SXEmacs.
150 ;; There are files for the use of the user (the init file and the
151 ;; custom file), for the site administrator (default.el and
152 ;; site-start.el), and for the SXEmacs maintainers (auto-autoloads
153 ;; files). See the Lispref for user and site files (node Starting Up,
154 ;; currently inaccurate (it doesn't describe the custom
155 ;; file)). Interactions among the files are complex; see
156 ;; lisp/startup.el for details.
158 ;; Briefly, after very basic initializations including processing a
159 ;; special command line options (including GUI toolkit options),
160 ;; setting up the terminal, and setting up `load-path', it executes
161 ;; customization code as follows:
163 ;; 1. It runs the normal hook `before-init-hook'.
164 ;; 2. It loads the library `site-start' (by default `site-start.el').
165 ;; 3. It loads the init file (by default `${XDG_CONFIG_HOME}/sxemacs/init.el').
166 ;; 4. It loads the custom file (by default `${XDG_CONFIG_HOME}/sxemacs/custom-${USER}.el').
167 ;; 5. It loads the library `default' (by default `default.el').
168 ;; 6. It runs the normal hook `after-init-hook'.
170 ;; After this the *scratch* buffer is set up and the remaining command
171 ;; line arguments (actions and file names) are processed.
173 ;; Step 2 is inhibited by the -no-site-file command line switch.
174 ;; Steps 3 and 4 are inhibited (as a unit) by the -no-init-file
175 ;; command line switch (-q is a convenient synonym). Step 5 is
176 ;; inhibited by -no-init-file or a non-nil value of
177 ;; `inhibit-default-init' (set it in the init file). From now on the
178 ;; hooks and the site initialization files will be ignored.
180 ;; The custom file and the init file contain customizations managed by
181 ;; SXEmacs itself via the Custom subsystem and manual customizations,
182 ;; respectively. Originally (in XEmacs),both were placed in the same
183 ;; file, usually ~/.emacs, but occasionally XEmacs would trash user
184 ;; settings when automatically changing options, and more frequently
185 ;; users would trash the automatically generated code. So these
186 ;; functions have been reallocated to separate files, usually named
187 ;; custom-${USER}.el (where `${USER}' is your user login name), and
188 ;; init.el, respectively.
190 ;; The Custom system is accessed most conveniently from the
191 ;; Options->Advanced (Customize) menu (also, the Options->Fonts and
192 ;; Options->Sizes menus are implicitly managed by Custom, and
193 ;; Options->Edit Faces explicitly invokes Custom). You can also use
194 ;; the suite of customize commands directly (cf C-h a customize RET).
195 ;; Currently, Custom possesses specialized facilities for setting
196 ;; ordinary variables of many types, and for customizing faces. As a
197 ;; general rule, variable and face initialization should be done using
198 ;; Custom, and other initializations should be done in the init file.
200 ;; A possible exception is a subsystem with its own complex init file,
201 ;; eg, Gnus and .gnus. In these cases it is often preferable to keep
202 ;; even simple variable initializations together, and you may wish to
203 ;; maintain these configurations by hand.
205 ;; You should avoid editing the custom file by hand. The syntax used
206 ;; is complex but concise, and it is easy to silently break the whole
207 ;; file with a single error that happens to result in a valid Lisp
208 ;; form. On the other hand, the init file is just a Lisp library that
209 ;; is loaded before starting the read-eval-redisplay loop.
211 ;; The interactions between the custom file and other init files are
212 ;; governed by a simple idea:
214 ;; Custom to User: ALL VARIABLES YOURS OURS NOW ARE.
216 ;; To be precise, Custom is pretty good about noticing and respecting
217 ;; existing settings in interactive use. However, it is weak in
218 ;; understanding advanced use of specifier variables (these are used
219 ;; for customizations which depend on display characteristics and
220 ;; configuration in complex ways), and can be quite brutal at
223 ;; Normal practice for Custom at initialization is to (1) reset
224 ;; all customized faces before applying customizations and (2)
225 ;; force all variables to the values specified in custom.el. For
226 ;; this reason, and because it is generally the case that the init
227 ;; file can usefully depend on customized variables, but Custom
228 ;; pays no attention to behavior of the init file, it is probably
229 ;; a good idea to force custom.el to be loaded before the init
230 ;; file. Making this the default has been discussed in the XEmacs
231 ;; camp (though no decision has been made yet).
233 ;; To enable early loading of custom.el, uncomment the following line:
234 ;(setq Init-inhibit-custom-file-p (not (assoc custom-file load-history)))
236 ;; Code to implement early loading where late loading is the default.
237 ;; A crucial snippet of code must be the last thing in this file.
239 ;; defvars only initialize uninitialized variables; if the setq above
240 ;; is active, the variable below is defined but the value will not be
242 (defvar Init-inhibit-custom-file-p nil
243 "Internal user init flag. Don't use this yourself.
245 Non-nil if we need to inhibit SXEmacs from loading custom.el after init.el.")
247 (when Init-inhibit-custom-file-p
248 ;; This is the default custom-file.
249 (let ((file (expand-file-name (concat "custom-" (user-login-name) ".el")
250 user-init-directory)))
251 (add-one-shot-hook 'after-init-hook
252 `(lambda () (setq custom-file ,file)))
253 (cond ((file-readable-p file)
255 ((file-exists-p file)
256 (warn "Existing custom file \"%s\" is not readable!" file)))
257 (cond ((not (file-exists-p file))
258 (display-warning 'resource
259 (format "Custom file \"%s\" not found." file)
261 ((not (file-writable-p file))
262 (warn "Existing custom file \"%s\" is not writable!" file)))))
265 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
266 ;; Basic Customization ;;
267 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
269 ;; TIP: Control-L characters are ignored in Lisp files and are the
270 ;; standard way of indicating major section divisions. You can enter
271 ;; such a character using C-q C-l.
273 ;; TIP: At this point you may be wondering how I wrote all these nice,
274 ;; long, nicely-justified textual stretches -- didn't I go crazy
275 ;; sticking in the semicolons everywhere and having to delete them and
276 ;; rearrange everything whenever I wanted to make any corrections to
277 ;; the text? The answer is -- of course not! Use M-q. This does all
278 ;; the magic for you, justifying and breaking lines appropriately and
279 ;; putting any necessary semicolons or whatever at the left (it
280 ;; figures out what this ought to be by looking in a very clever
281 ;; fashion at what's already at the beginning of each line in the
282 ;; paragraph). You may need `filladapt' set up (it's done below in
283 ;; this file) in order for this to work properly. Finally, if you
284 ;; want to turn on automatic filling (like in a word processor, but
285 ;; not quite as automatic), use M-x auto-fill-mode or the binding set
286 ;; up below in this file (Meta-F9).
288 (defun Init-safe-require (feat)
289 "Try to REQUIRE the specified feature. Errors occurring are silenced.
290 \(Perhaps in the future there will be a way to get at the error.)
291 Returns t if the feature was successfully required."
293 (progn (require feat) t)))
295 ;; `ignore-errors' is a handy way to wrapping code that may be prone to
296 ;; error (for example, loading a library that you don't have) without
297 ;; the error getting in your way. Here is its documentation...
299 ;; ,----[ C-h f ignore-errors RET ]
300 ;; | `ignore-errors' is a compiled Lisp macro
301 ;; | -- loaded from "cl-macs"
302 ;; | (ignore-errors &rest BODY)
305 ;; | Execute FORMS; if an error occurs, return nil.
306 ;; | Otherwise, return result of last FORM.
311 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
312 ;; Key Definitions ;;
313 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
315 ;;; Set up the function keys to do common tasks to reduce Emacs pinky
318 ;; You can set a key sequence either to a command or to another key
319 ;; sequence. (Use `C-h k' to map a key sequence to its command. Use
320 ;; `C-h w' to go the other way.) In general, however, it works better
321 ;; to specify the command name. For example, it does not currently
324 ;; (global-set-key 'f5 "\C-x\C-f")
326 ;; The reason is that macros (which is what the string on the right
327 ;; really is) can't currently use the minibuffer. This is an
328 ;; extremely longstanding bug in Emacs. Eventually, it will be
329 ;; fixed. (Hopefully ..)
331 ;; Note also that you may sometimes see the idiom
333 ;; (define-key global-map ...)
335 ;; in place of (global-set-key ...). These are exactly the same.
337 ;; Here I've tried to put all the most common commands on simple
338 ;; non-modifier function keys to take the pressure off your modifier
339 ;; fingers. Furthermore, on my keyboard at least, the function keys
340 ;; are grouped into three groups of four with spaces between them, and
341 ;; so it's easier to hit the keys at the edge of the groups --
342 ;; i.e. f1, f4, f5, f8, f9, and f12. Finally, you may note that f9,
343 ;; f11, and f12 are purposely left blank. [F6 is defined below.]
344 ;; That's because I use them for _, {, and } -- see below. (Ben Wing)
346 ;; f1 is bound to the help prefix (C-h) by default, and because f1 ==
347 ;; help is so common I think it makes more sense to leave it at the
350 ;; (global-set-key 'f1 'advertised-undo) ;; Undo
351 (global-set-key 'f2 'kill-primary-selection) ;; Cut
352 (global-set-key 'f3 'copy-primary-selection) ;; Copy
353 (global-set-key 'f4 'yank-clipboard-selection) ;; Paste
354 (global-set-key 'f5 'find-file) ;; C-x C-f
355 (global-set-key 'f7 'save-buffer) ;; C-x C-s
357 (global-set-key 'f8 'kill-entire-line)
359 ;; A keystroke repeated incredible amounts of times. We need to patch
360 ;; into the isearch keymap so that repeat searches while in isearch
361 ;; mode still work. Here we show how to make a key in a keymap have the
362 ;; same binding as another key in the keymap, without knowing what the
363 ;; binding is in advance; instead, we find it with `lookup-key'. This
364 ;; way, if the binding of C-s changes (e.g. to a different function) but
365 ;; the meaning is basically the same, we automatically do the right thing.
366 ;; If we put in the actual binding, which is 'isearch-repeat-forward,
367 ;; this automatic tracking wouldn't happen.
369 ;; TIP: To find out what the (lookup-key ...) expression evaluates to,
370 ;; move just to the right of the closing paren and type C-x C-e.
372 (global-set-key 'f10 'isearch-forward)
373 (define-key isearch-mode-map 'f10 (lookup-key isearch-mode-map "\C-s"))
374 (define-key minibuffer-local-isearch-map 'f10
375 (lookup-key minibuffer-local-isearch-map "\C-s"))
376 (global-set-key '(shift f10) 'isearch-backward)
377 (define-key isearch-mode-map '(shift f10) (lookup-key isearch-mode-map "\C-r"))
378 (define-key minibuffer-local-isearch-map '(shift f10)
379 (lookup-key minibuffer-local-isearch-map "\C-r"))
381 ;; Here we define our own function and then bind a key to it.
383 (defun start-or-end-kbd-macro ()
384 ;; A doc string. This is optional.
385 "Start defining a keyboard macro, or stop if we're already defining."
386 ;; IMPORTANT: Any function bound to a key MUST have an interactive spec,
387 ;; usually just the following line:
389 (if defining-kbd-macro
391 (start-kbd-macro nil)))
393 ;; The macros used to have their place in the function keys, but I
394 ;; find that I use them significantly less than the really basic
395 ;; things on the function keys. When using a macro, you call the
396 ;; macro much more than define it, so the setup below makes some
399 (global-set-key '(shift kp-multiply) 'start-or-end-kbd-macro)
400 (global-set-key 'kp-multiply 'call-last-kbd-macro) ;; C-x e
402 ;; Note that you can refer to a key sequence either using an ASCII
403 ;; string or the "long way", with vectors and conses. You saw above
404 ;; (in a comment) the string form for specifying the key sequence `C-x
405 ;; C-f', which is "\C-x\C-f". (For those curious, \C-x is just an
406 ;; escape sequence that puts a ^X character into the string. Thus,
407 ;; the string just mentioned really just contains two characters, a ^X
408 ;; and a ^F.) The long way to specify the sequence `C-x C-f' would be
410 ;; [(control x) (control f)]
412 ;; The long format lets you specify all possible key sequences, while the
413 ;; string form only lets you specify sequences involving ASCII characters
414 ;; and/or modifiers and in fact only a subset of them.
416 ;; Other examples are:
420 ;; (You can leave out the parens when there is no modifier specified in
421 ;; the keystroke, and that's normally done.)
423 ;; [(shift control meta left)]
425 ;; (You can put more than one modifier in a keystroke.)
427 ;; (shift control meta left)
429 ;; (This is the same as the previous. when there's only one keystroke in
430 ;; the sequence, you can leave out the brackets, and that's normally
433 ;; [(control x) (shift button3)]
435 ;; (You can refer to mouse buttons just like keys -- apply modifiers,
436 ;; intermingle them in key sequences, etc. But there's only problem
437 ;; here, which is that with the mouse you don't just have one possible
438 ;; gesture, like with keys. You'd really like to control button-down,
439 ;; button-up, button-click (down and up without selecting anything),
440 ;; button drag, button double-click, etc. This is normally done by
441 ;; binding your key sequence to `mouse-track', and then putting hooks
442 ;; onto `mouse-track-click-hook', `mouse-track-drag-up-hook', etc. to
443 ;; customize the specific behavior.)
447 ;; (Ultimate reductionism -- no brackets, no parens. This is the form, in
448 ;; that, that the 'f1, 'f2, etc. took, which where in fact "long"
453 ;; (You cannot use '(control shift c) here. This applies whenever Shift +
454 ;; key translates to a single character. Note also that you can't use
455 ;; "\C-C" either; this refers to the non-shifted C-c, just like "\C-c"
459 ;; (Put a backslash in front of characters used in Lisp syntax.)
461 ;; Also, you can find out the name of a key using C-h c. WARNING:
462 ;; This does not report the correct name of the keys named `delete',
463 ;; `backspace', `return', `tab', `space', `escape', and `linefeed'!
464 ;; (More correct results can be achieved using
466 ;; ESC : (read-key-sequence "foo: ")
470 ;;;;;;;;;;;;;;;;;;;;;;;;
472 ;; Keystrokes to conveniently switch buffers.
474 ;; F6 is invaluable for flipping back and forth between two buffers
475 ;; you're working with.
477 (global-set-key 'f6 'switch-to-other-buffer) ;; M-C-l
479 ;; The definitions of these switch-to-* functions are further down.
480 (global-set-key '(meta n) 'switch-to-next-buffer-in-group)
481 (global-set-key '(meta p) 'switch-to-previous-buffer-in-group)
482 (global-set-key '(meta N) 'switch-to-next-buffer)
483 (global-set-key '(meta P) 'switch-to-previous-buffer)
485 ;; Define our own function to deal with the possibility that the newer
486 ;; stuff in the gutter code may not be present -- i.e. we're running
487 ;; an older XEmacs. Note that we avoid trying to "helpfully" define a
488 ;; function that is present in new versions of XEmacs, but not in
489 ;; older ones. That can very easily screw up code trying to determine
490 ;; what functionality is present using `fboundp' checks. See above,
491 ;; near `emacs-version>=', for a full discussion of this.
493 (defun Init-buffers-tab-omit (buf)
494 ;; a function specifying the buffers to omit from the buffers tab.
495 ;; This is passed a buffer and should return non-nil if the buffer
496 ;; should be omitted. If the standard buffers-tab functionality is
497 ;; there, we just call it to do things "right". Otherwise we just
498 ;; omit invisible buffers, snarfing the code from
499 ;; `buffers-menu-omit-invisible-buffers'.
500 (if (boundp 'buffers-tab-omit-function)
501 (funcall buffers-tab-omit-function buf)
502 (not (null (string-match "\\` " (buffer-name buf))))))
504 (defun switch-to-next-buffer (&optional n)
505 "Switch to the next-most-recent buffer.
506 This essentially rotates the buffer list forward.
507 N (interactively, the prefix arg) specifies how many times to rotate
508 forward, and defaults to 1. Buffers whose name begins with a space
509 \(i.e. \"invisible\" buffers) are ignored."
510 ;; Here is a different interactive spec. Look up the function
511 ;; `interactive' (i.e. `C-h f interactive') to understand how this
514 (dotimes (n (or n 1))
516 do (bury-buffer (car (buffer-list)))
517 while (Init-buffers-tab-omit (car (buffer-list))))
518 (switch-to-buffer (car (buffer-list)))))
520 (defun buffers-menu-omit-invisible-buffers (buf)
521 "For use as a value of `buffers-menu-omit-function'.
522 Omits normally invisible buffers (those whose name begins with a space)."
523 (not (null (string-match "\\` " (buffer-name buf)))))
525 (defvar Init-buffers-tab-grouping-regexp
526 '("^\\(gnus-\\|message-mode\\|mime/viewer-mode\\)"
527 "^\\(emacs-lisp-\\|lisp-\\)")
528 ;; If non-nil, a list of regular expressions for buffer grouping.
529 ;; Each regular expression is applied to the current major-mode symbol
530 ;; name and mode-name, if it matches then any other buffers that match
531 ;; the same regular expression be added to the current group. This is
532 ;; a copy of `buffers-tab-grouping-regexp'.
535 (defun Init-select-buffers-tab-buffers (buffer-to-select buf1)
536 ;; Specifies the buffers to select from the buffers tab. This is
537 ;; passed two buffers and should return non-nil if the second buffer
538 ;; should be selected. If the standard buffers-tab functionality is
539 ;; there, we just call it to do things "right". Otherwise, we group
540 ;; buffers by major mode and by `Init-buffers-tab-grouping-regexp'.
541 ;; [We've copied `select-buffers-tab-buffers-by-mode' and
542 ;; `buffers-tab-grouping-regexp'.]
543 (if (boundp 'buffers-tab-selection-function)
544 (funcall buffers-tab-selection-function buffer-to-select buf1)
545 (let ((mode1 (symbol-name (symbol-value-in-buffer 'major-mode buf1)))
546 (mode2 (symbol-name (symbol-value-in-buffer 'major-mode
548 (modenm1 (symbol-value-in-buffer 'mode-name buf1))
549 (modenm2 (symbol-value-in-buffer 'mode-name buffer-to-select)))
550 (cond ((or (eq mode1 mode2)
552 (and (string-match "^[^-]+-" mode1)
554 (concat "^" (regexp-quote
555 (substring mode1 0 (match-end 0))))
557 (and Init-buffers-tab-grouping-regexp
558 (find-if #'(lambda (x)
560 (and (string-match x mode1)
561 (string-match x mode2))
562 (and (string-match x modenm1)
563 (string-match x modenm2))))
564 Init-buffers-tab-grouping-regexp)))
568 (defun switch-to-previous-buffer (&optional n)
569 "Switch to the previously most-recent buffer.
570 This essentially rotates the buffer list backward.
571 N (interactively, the prefix arg) specifies how many times to rotate
572 backward, and defaults to 1. Buffers whose name begins with a space
573 \(i.e. \"invisible\" buffers) are ignored."
575 (dotimes (n (or n 1))
577 do (switch-to-buffer (car (last (buffer-list))))
578 while (Init-buffers-tab-omit (car (buffer-list))))))
580 (defun switch-to-next-buffer-in-group (&optional n)
581 "Switch to the next-most-recent buffer in the current group.
582 This essentially rotates the buffer list forward.
583 N (interactively, the prefix arg) specifies how many times to rotate
584 forward, and defaults to 1. Buffers whose name begins with a space
585 \(i.e. \"invisible\" buffers) are ignored."
587 (dotimes (n (or n 1))
588 (let ((curbuf (car (buffer-list))))
590 do (bury-buffer (car (buffer-list)))
591 while (or (Init-buffers-tab-omit (car (buffer-list)))
592 (not (Init-select-buffers-tab-buffers
593 curbuf (car (buffer-list)))))))
594 (switch-to-buffer (car (buffer-list)))))
596 (defun switch-to-previous-buffer-in-group (&optional n)
597 "Switch to the previously most-recent buffer in the current group.
598 This essentially rotates the buffer list backward.
599 N (interactively, the prefix arg) specifies how many times to rotate
600 backward, and defaults to 1. Buffers whose name begins with a space
601 \(i.e. \"invisible\" buffers) are ignored."
603 (dotimes (n (or n 1))
604 (let ((curbuf (car (buffer-list))))
606 do (switch-to-buffer (car (last (buffer-list))))
607 while (or (Init-buffers-tab-omit (car (buffer-list)))
608 (not (Init-select-buffers-tab-buffers
609 curbuf (car (buffer-list)))))))))
611 ;;;;;;;;;;;;;;;;;;;;;;;;
613 ;; Other text keystrokes.
615 ;; Make a keystroke to insert a literal TAB character. (`C-q TAB' is
616 ;; annoying because difficult to repeat.) Note that this does not work
617 ;; in TTY frames, where TAB and Shift-TAB are indistinguishable.
618 (define-key global-map '(shift tab) 'tab-to-tab-stop)
620 ;; Toggle auto-filling. Useful with text but annoying with code. You
621 ;; can manually fill with M-q.
622 (global-set-key '(meta f9) 'auto-fill-mode)
624 ;;;;;;;;;;;;;;;;;;;;;;;;
626 ;; Rearrange some inconvenient bindings.
628 ;; I've commented this section out, simply because I disagree with the
629 ;; proposed bindings. I've never had any of the problems that these
630 ;; bindings are supposed to address. Yeah, I'm one of these "odd"
631 ;; folk who actually _like_ most of the default bindings. :-) --SY.
633 ;; ;; ESC ESC ESC is a useful command, but too long. ESC ESC would be
634 ;; ;; much more logical, but interferes with Meta + keypad/arrow keys on
635 ;; ;; TTY's. But most people only use window systems and no such problem
636 ;; ;; exists there, so set up the more logical binding there.
638 ;; ;; Note also the use of if vs. cond/when/unless/or/and to express
639 ;; ;; conditional statements. The difference is purely stylistic.
641 ;; (when (console-on-window-system-p)
642 ;; (global-set-key '(meta escape) 'keyboard-escape-quit)
643 ;; (define-key isearch-mode-map '(meta escape) 'isearch-cancel))
645 ;; ;; When not on a TTY, remove the binding of C-x C-c, which normally
646 ;; ;; exits XEmacs. It's easy to hit this by mistake, and that can be
647 ;; ;; annoying. You can always quit with the "Exit XEmacs" option on the
650 ;; (when (console-on-window-system-p)
651 ;; (global-set-key "\C-x\C-c"
652 ;; #'(lambda () (interactive)
654 ;; (message "Use the \"File/Exit XEmacs\" menu item to exit XEmacs"))))
656 ;; ;; Make C-k always delete the whole line, which is what most people want,
658 ;; (setq kill-whole-line 'always)
659 ;; ;; M-k does the old behavior (kill to end of line).
660 ;; (global-set-key '(meta k) #'(lambda ()
662 ;; (if (fboundp 'historical-kill-line)
663 ;; (call-interactively #'historical-kill-line)
664 ;; (let ((kill-whole-line nil))
665 ;; (call-interactively #'kill-line)))))
666 ;; ;; and Meta-Shift-K does what used to be on M-k, and should
667 ;; ;; (hopefully) even work under TTY's.
668 ;; (global-set-key '(meta K) 'kill-sentence)
670 ;; ;; Make sure we get Windows-like shifted-motion key selection behavior
671 ;; ;; on recent XEmacs versions.
672 ;; (cond ((boundp 'shifted-motion-keys-select-region)
673 ;; (setq shifted-motion-keys-select-region t))
674 ;; ;; otherwise, try the pc-select package --
675 ;; ((Init-safe-require 'pc-select)
676 ;; (pc-select-mode 1)))
678 ;; The following commented-out code rearranges the keymap in an
679 ;; unconventional but extremely useful way for programmers. Parens
680 ;; and braces are both available without using the shift key (using
681 ;; the bracket keys and f11/f12, respectively). Brackets (much less
682 ;; used) are the shifted versions of the new paren keys (i.e. where
683 ;; the braces normally are).
685 ;; The idea for this comes from Jamie Zawinski.
687 ;; Also make a convenient keystroke for _, used constantly in C code.
689 ;; NOTE: you can (semi-) conveniently uncomment a region using
690 ;; C-u M-x comment-region, or the "Uncomment Region" menu item on the
691 ;; Lisp menu in new enough versions of XEmacs.
693 ;(keyboard-translate ?[ ?()
694 ;(keyboard-translate ?] ?))
695 ;(keyboard-translate ?{ ?[)
696 ;(keyboard-translate ?} ?])
697 ;;; We don't use `keyboard-translate' for these because it messes up
698 ;;; bindings for M-F9 and the like.
699 ;(define-key key-translation-map 'f11 "{")
700 ;(define-key key-translation-map 'f12 "}")
701 ;(define-key key-translation-map 'f9 "_")
704 ;;;;;;;;;;;;;;;;;;;;;;;;
706 ;; Useful programming-related keystrokes.
708 (defun describe-foo-at-point ()
709 "Show the documentation of the Elisp function and variable near point.
712 -- for a function name where point is
713 -- for a variable name where point is
714 -- for a surrounding function call
718 ;; sigh, function-at-point is too clever. we want only the first half.
719 (cond ((setq sym (ignore-errors
720 (with-syntax-table emacs-lisp-mode-syntax-table
722 (or (not (zerop (skip-syntax-backward "_w")))
723 (eq (char-syntax (char-after (point))) ?w)
724 (eq (char-syntax (char-after (point))) ?_)
726 (skip-chars-forward "`'")
727 (let ((obj (read (current-buffer))))
728 (and (symbolp obj) (fboundp obj) obj))))))
729 (describe-function sym))
730 ((setq sym (variable-at-point)) (describe-variable sym))
731 ;; now let it operate fully -- i.e. also check the
732 ;; surrounding sexp for a function call.
733 ((setq sym (function-at-point)) (describe-function sym)))))
735 (global-set-key '(shift f4) 'next-error) ;; C-x `
736 (global-set-key '(control f4) 'previous-error)
737 (global-set-key '(shift f5) 'find-library)
738 (global-set-key '(control f5) 'find-function)
739 (global-set-key '(meta f5) 'find-variable)
740 (global-set-key '(shift f11) 'describe-foo-at-point)
741 (global-set-key '(control f11) 'eval-last-sexp)
742 ;; Edebug is a source-level debugger for Emacs Lisp programs. Put
743 ;; the cursor at the end of a function definition and "instrument" it
744 ;; with this command; then, you can single step through it the next
746 (global-set-key '(meta f11) 'edebug-defun)
747 (global-set-key '(meta f12) 'add-change-log-entry)
749 ;; This nicely parallels M-*, which pops the tag stack. See below for
750 ;; how to set up tags.
751 (global-set-key '(control *) 'find-tag-at-point)
753 ;; Define a function to conveniently determine where time is being
754 ;; spent when executing commands or Lisp code.
755 (defun toggle-profiling ()
756 "Start profiling, or stop it and print results.
757 This lets you figure out where time is being spent when executing Lisp code."
759 (if (profiling-active-p)
762 (message "...Finished profiling")
764 (message "Profiling...")
765 (clear-profiling-info)
768 ;; Note that sequences of C-c plus a letter are specifically
769 ;; reserved for users and should never be bound by any packages.
771 (global-set-key "\C-cp" 'toggle-profiling)
773 ;; LISPM bindings of Control-Shift-C and Control-Shift-E.
774 ;; See comment above about bindings like this.
775 (define-key emacs-lisp-mode-map '(control C) 'compile-defun)
776 (define-key emacs-lisp-mode-map '(control E) 'eval-defun)
778 ;;;;;;;;;;;;;;;;;;;;;;;;
782 ;; The numeric keypad as a whole is underused, and it's a good source
783 ;; of keys to bind to commands. Here we add some useful bindings.
784 ;; Because this is a sample file and I want to avoid unpleasant
785 ;; surprises for novices, I don't actually bind the shared
786 ;; numeric/cursor-motion keys because
788 ;; (a) someone keypads don't have separate motion keys (e.g. laptops?), and
789 ;; (b) TTY's and some X servers might not distinguish the regular and
790 ;; numeric-keypad motion keys.
792 ;; `kill-current-buffer' (defined below) deletes the current
793 ;; buffer. (Don't worry, you will be prompted to save if it's
794 ;; modified.) By repeatedly pressing keypad-minus, you can
795 ;; conveniently reduce the number of open buffers to a manageable size
796 ;; after you've opened a whole bunch of files and finished working on
797 ;; them. Shift plus keypad-minus kills both the current buffer and
798 ;; its window, and Control plus keypad-minus kills just the current
801 (global-set-key 'kp-subtract 'kill-current-buffer)
802 (global-set-key '(shift kp-subtract) 'kill-current-buffer-and-window)
803 (global-set-key '(control kp-subtract) 'delete-window)
804 ;; Ugh, modes that use `suppress-keymap' and are dumped with XEmacs will
805 ;; need their own definition. There is no easy way to fix this.
806 (define-key help-mode-map 'kp-subtract 'kill-current-buffer)
807 (define-key help-mode-map '(shift kp-subtract)
808 'kill-current-buffer-and-window)
809 (define-key list-mode-map 'kp-subtract 'kill-current-buffer)
810 (define-key list-mode-map '(shift kp-subtract)
811 'kill-current-buffer-and-window)
813 (defun kill-current-buffer ()
814 "Kill the current buffer (prompting if it is modified)."
816 (kill-buffer (current-buffer)))
818 (defun kill-current-buffer-and-window ()
819 "Kill the current buffer (prompting if it is modified) and its window."
821 (kill-buffer (current-buffer))
824 (defvar grep-all-files-history nil)
826 (defvar grep-all-files-omitted-expressions
827 '("*~" "#*" ".#*" ",*" "*.elc" "*.obj" "*.o" "*.exe" "*.dll" "*.lib" "*.a"
828 "*.dvi" "*.class" "*.bin")
829 "List of expressions matching files to be omitted in `grep-all-files-...'.
830 Each entry should be a simple name or a shell wildcard expression.")
832 (defvar grep-all-files-omitted-directories '("CVS" "RCS" "SCCS")
833 "List of directories not to recurse into in `grep-all-files-...'.
834 Each entry should be a simple name or a shell wildcard expression.")
836 (defun construct-grep-all-files-command (find-segment grep-segment)
838 (mapconcat #'(lambda (wildcard)
839 (concat "-name '" wildcard "' -or "))
840 grep-all-files-omitted-expressions
842 (cond ((eq grep-find-use-xargs 'gnu)
843 (format "find . %s %s -type f -print0 | xargs -0 -e %s"
844 find-segment omit-annoying grep-segment))
846 (format "find . %s %s -type f -print | xargs %s"
847 find-segment omit-annoying grep-segment))
849 (format "find . %s %s -type f -exec %s {} /dev/null \\;"
850 find-segment omit-annoying grep-segment)))))
852 (defun grep-all-files-in-current-directory (command)
853 "Run `grep' in all non-annoying files in the current directory.
854 `Non-annoying' excludes backup files, autosave files, CVS merge files, etc.
855 More specifically, this is controlled by `grep-all-files-omitted-expressions'.
857 This function does not recurse into subdirectories. If you want this,
858 use \\[grep-all-files-in-current-directory-and-below]."
862 (list (read-shell-command "Run grep (like this): "
863 grep-command 'grep-all-files-history))))
865 (grep (construct-grep-all-files-command
866 "-name . -or -type d -prune -or" command)))
868 (defun grep-all-files-in-current-directory-and-below (command)
869 "Run `grep' in all non-annoying files in the current directory and below.
870 `Non-annoying' excludes backup files, autosave files, CVS merge files, etc.
871 More specifically, this is controlled by `grep-all-files-omitted-expressions'.
873 This function recurses into subdirectories. If you do not want this,
874 use \\[grep-all-files-in-current-directory]."
878 (list (read-shell-command "Run grep (like this): "
879 grep-command 'grep-all-files-history))))
881 (grep (construct-grep-all-files-command
882 ;; prune all specified directories.
883 (mapconcat #'(lambda (wildcard)
884 (concat "-name '" wildcard "' -prune -or "))
885 grep-all-files-omitted-directories
889 (defun clear-select ()
890 "Repeatedly select ever larger balanced expressions around the cursor.
891 Once you have such an expression marked, you can expand to the end of
892 the following expression with \\[mark-sexp] and to the beginning of the
893 previous with \\[backward-sexp]."
894 (interactive "_") ;this means "preserve the active region after this command"
896 (let ((end (save-excursion (forward-sexp) (point))))
897 (push-mark end nil t)))
899 (global-set-key 'kp-add 'query-replace)
900 (global-set-key '(shift kp-add) 'query-replace-regexp)
901 (global-set-key '(control kp-add) 'grep-all-files-in-current-directory)
902 (global-set-key '(meta kp-add) 'grep-all-files-in-current-directory-and-below)
903 (global-set-key 'clear 'clear-select)
904 ;; Note that you can use a "lambda" expression (an anonymous function)
905 ;; in place of a function name. This function would be called
906 ;; `pop-local-mark' and lets you repeatedly cycle back through recent
907 ;; marks (marks are set whenever you begin a selection, begin a
908 ;; successful search, are about to jump to the beginning or end of the
910 (global-set-key 'kp-enter (lambda () (interactive) (set-mark-command t)))
911 (global-set-key '(shift kp-enter) 'repeat-complex-command)
912 (global-set-key 'pause 'repeat-complex-command) ;; useful on Windows-style kbds
913 (global-set-key '(control kp-enter) 'eval-expression)
915 ;;;;;;;;;;;;;;;;;;;;;;;;
919 ;; If you want button2 to insert the selected text
920 ;; at point (where the text cursor is), instead of at the
921 ;; position clicked, uncomment the following:
923 ;(setq mouse-yank-at-point t)
925 ;; If you like the FSF Emacs binding of button3 (single-click
926 ;; extends the selection, double-click kills the selection),
927 ;; uncomment the following:
929 ;(define-key global-map 'button3 'mouse-track-adjust)
931 ;(add-hook 'mouse-track-click-hook
932 ; (lambda (event count)
933 ; (if (or (/= (event-button event) 3)
935 ; nil ;; do the normal operation
936 ; (kill-region (point) (mark))
937 ; t ;; don't do the normal operations.
940 ;; Uncomment this to enable "sticky modifier keys". With sticky
941 ;; modifier keys enabled, you can press and release a modifier key
942 ;; before pressing the key to be modified, like how the ESC key works
943 ;; always. If you hold the modifier key down, however, you still get
944 ;; the standard behavior. I personally think this is the best thing
945 ;; since sliced bread (and a *major* win when it comes to reducing
946 ;; Emacs pinky), but it's disorienting at first so I'm not enabling it
949 ;(setq modifier-keys-are-sticky t)
951 ;; Enable the command `narrow-to-region' ("C-x n n"). It's a useful
952 ;; command, but possibly confusing to a new user, so it's disabled by
954 (put 'narrow-to-region 'disabled nil)
956 ;; Enable obvious hyperlink following with button1.
957 (setq Info-button1-follows-hyperlink t)
960 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
961 ;; Change Some Basic Behaviors ;;
962 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
964 ;; Change the values of some variables.
965 ;; (t means true; nil means false.)
967 ;; Use C-h v or `Help->Commands, Variables, Keys->Describe Variable...'
968 ;; to find out what these variables mean.
970 find-file-compare-truenames t
971 minibuffer-max-depth nil
974 ;; When running ispell, consider all 1-3 character words as correct.
975 (setq ispell-extra-args '("-W" "3"))
977 ;;; pending-delete-mode causes typed text to replace a selection,
978 ;;; rather than append -- standard behavior under all window systems
981 (if (fboundp 'pending-delete-mode)
982 (pending-delete-mode 1))
984 ;; This shows how to set up the XEmacs side of tags. (To create the
985 ;; TAGS table, use the `etags' program found in the XEmacs bin
986 ;; directory. Run it in the root directory of your source tree and
987 ;; specify all source and include files on the command line.)
988 ;(setq tag-table-alist
990 ; ;; Everywhere in the /src/xemacs/gui/ source tree will use the TAGS
991 ; ;; file in /src/xemacs/gui/.
992 ; ("/src/xemacs/gui/" . "/src/xemacs/gui/")
993 ; ;; Everywhere in the /src/xemacs/mule/ source tree will use the TAGS
994 ; ;; file in /src/xemacs/mule/.
995 ; ("/src/xemacs/mule/" . "/src/xemacs/mule/")
997 ; ("/src/xemacs/fixup/" . "/src/xemacs/fixup/")
998 ; ("/src/emacs/emacs-20.6/" . "/src/emacs/emacs-20.6/")
999 ; ("/src/xemacs/latest/" . "/src/xemacs/latest/")
1000 ; ;; Everywhere else will use the TAGS file in
1001 ; ;; /src/xemacs/fixup/.
1002 ; ("" . "/src/xemacs/fixup/")
1006 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1007 ;; Change Some Aspects of GUI Appearance ;;
1008 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1010 ;; Changes the text in the window title bar.
1012 ;; Commented out. Even though this works fine in SXEmacs, the title
1013 ;; bar text you'd end up with would be...
1015 ;; "sample.init.el - SXEmacs steve@sxemacs.org--2007/sxemacs--main--22.1.8--patch-66 [/usr/local/bin/sxemacs]"
1017 ;; ...which is probably a whee bit loooooong. --SY.
1018 ;; (if (or (equal frame-title-format "%S: %b")
1019 ;; (equal frame-title-format "%b - XEmacs"))
1020 ;; (setq frame-title-format
1021 ;; (concat "%b - XEmacs "
1022 ;; (progn (string-match "\\(.*?\\)\\( XEmacs Lucid\\)?$"
1024 ;; (match-string 1 emacs-version))
1025 ;; " [" invocation-directory invocation-name "]")))
1027 ;; To get a similar thing in SXEmacs, try...
1028 (setq frame-title-format
1029 (concat "%b - SXEmacs "
1030 emacs-program-version
1031 " [" invocation-directory invocation-name "]"))
1034 ;; Load some nifty sounds that will replace the default beep.
1036 ;; The folloing requires that PulseAudio is installed. But don't
1037 ;; fear, SXEmacs also supports:
1039 ;; ALSA, ao, ESD, OSS, Jack, and NAS
1041 (setq default-audio-device (make-audio-device 'pulse))
1043 ;; SXEmacs multi-media is threaded (you can play an MP3 or OGG (or
1044 ;; any other supported format) and not have to wait for it to finish
1045 ;; playback before your SXEmacs is usable again)
1047 (setq synchronous-sounds nil)
1050 (setq bell-volume 100)
1051 (when (device-sound-enabled-p)
1052 (load-sound-file "low-smash" 'auto-save-error)
1053 (load-sound-file "bark" 'command-error)
1054 (load-sound-file "slap" 'undefined-key)
1055 (load-sound-file "slap" 'undefined-click)
1056 (load-sound-file "clink" 'no-completion)
1057 (load-sound-file "bong" 'y-or-n-p)
1058 (load-sound-file "explosion" 'yes-or-no-p)
1059 (load-sound-file "drip" 'buffer-bound)
1060 (load-sound-file "whip" 'read-only)
1061 (load-sound-file "bass-snap" 'default)
1062 (load-sound-file "yeep" 'quit)
1063 (load-sound-file "drum-beep" 'isearch-failed)
1064 (load-sound-file "bass-snap" 'isearch-quit)
1065 (load-sound-file "slap" 'ready)
1066 (load-sound-file "return" 'warp)
1067 (load-sound-file "cuckoo" 'alarm))
1069 ;; Change the continuation glyph face so it stands out more
1070 (make-face-bold (glyph-face continuation-glyph))
1072 ;; Change the pointer used during garbage collection.
1074 ;; Note that this pointer image is rather large as pointers go,
1075 ;; and so it won't work on some X servers (such as the MIT
1076 ;; R5 Sun server) because servers may have lamentably small
1077 ;; upper limits on pointer size.
1078 ;;(if (featurep 'xpm)
1079 ;; (set-glyph-image gc-pointer-glyph
1080 ;; (expand-file-name "trash.xpm" data-directory)))
1082 ;; Here's another way to do that: it first tries to load the
1083 ;; pointer once and traps the error, just to see if it's
1084 ;; possible to load that pointer on this system; if it is,
1085 ;; then it sets gc-pointer-glyph, because we know that
1086 ;; will work. Otherwise, it doesn't change that variable
1087 ;; because we know it will just cause some error messages.
1089 (let ((file (expand-file-name "recycle.xpm" data-directory)))
1090 (if (condition-case nil
1091 ;; check to make sure we can use the pointer.
1092 (make-image-instance file nil
1094 (error nil)) ; returns nil if an error occurred.
1095 (set-glyph-image gc-pointer-glyph file))))
1097 ;(when (featurep 'menubar)
1098 ; ;; Add `dired' to the File menu
1099 ; (add-menu-button '("File") ["Edit Directory" dired])
1101 ;; You get this by default with big-menubar.el now. --SY.
1102 ; ;; Here's a way to add scrollbar-like buttons to the menubar
1103 ; (add-menu-button nil ["Top" beginning-of-buffer])
1104 ; (add-menu-button nil ["<<<" scroll-down])
1105 ; (add-menu-button nil [" . " recenter])
1106 ; (add-menu-button nil [">>>" scroll-up])
1107 ; (add-menu-button nil ["Bot" end-of-buffer]))
1109 ;; Here's a cute hack that shows how to programmatically change some
1110 ;; text colors. It changes the background color of the window if it's
1111 ;; not on the local machine, or if it's running as root:
1113 ;; local emacs background: whitesmoke [i.e. the default color]
1114 ;; remote emacs background: palegreen1
1115 ;; root emacs background: coral2
1117 ;; Uncomment to enable.
1120 ; ((and running-sxemacs
1121 ; (console-on-window-system-p))
1122 ; (let* ((root-p (eq 0 (user-uid)))
1123 ; (dpy (or (getenv "DISPLAY") ""))
1125 ; (or (string-match "^\\(\\|unix\\|localhost\\):" dpy)
1126 ; (let ((s (system-name)))
1127 ; (if (string-match "\\.\\(netscape\\|mcom\\)\\.com" s)
1128 ; (setq s (substring s 0 (match-beginning 0))))
1129 ; (string-match (concat "^" (regexp-quote s)) dpy)))))
1130 ; (bg (cond (root-p "coral2")
1131 ; (remote-p "palegreen1")
1134 ; (let ((def (color-name (face-background 'default)))
1135 ; (faces (face-list)))
1137 ; (let ((obg (face-background (car faces))))
1138 ; (if (and obg (equal def (color-name obg)))
1139 ; (set-face-background (car faces) bg)))
1140 ; (setq faces (cdr faces)))))))))
1143 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1144 ;; Changing the Modeline ;;
1145 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1147 ;; Enable line numbers and column numbers. This is done in C code now
1148 ;; and is very fast.
1149 (line-number-mode 1)
1150 (column-number-mode 1)
1152 ;; Rearrange the modeline so that everything is to the left of the
1153 ;; long list of minor modes, which is relatively unimportant but takes
1154 ;; up so much room that anything to the right is obliterated.
1160 (if (boundp 'modeline-multibyte-status) 'modeline-multibyte-status "")
1161 (cons modeline-modified-extent 'modeline-modified)
1162 (cons modeline-buffer-id-extent
1163 (list (cons modeline-buffer-id-left-extent
1165 (list 'line-number-mode "L%l ")
1166 (list 'column-number-mode "C%c ")
1168 (cons modeline-buffer-id-right-extent "%17b")))
1172 (cons modeline-minor-mode-extent
1173 (list "" 'mode-name 'minor-mode-alist))
1174 (cons modeline-narrowed-extent "%n")
1180 ;; Get rid of modeline information taking up too much space -- in
1181 ;; particular, minor modes that are always enabled.
1182 (setq pending-delete-modeline-string "")
1183 (setq filladapt-mode-line-string "")
1184 ;; lazy-lock doesn't have a variable for its modeline name, so we have
1185 ;; to do a bit of surgery.
1186 (and (assoc 'lazy-lock-mode minor-mode-alist)
1187 (setcdr (cdr (cadr (assoc 'lazy-lock-mode minor-mode-alist))) ""))
1191 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1192 ;; Customization of Specific Packages ;;
1193 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1196 ;;; ********************
1197 ;;; Load gnuserv, which will allow you to connect to SXEmacs sessions
1198 ;;; using `gnuclient'.
1200 ;; If you never run more than one SXEmacs at a time, you might want to
1201 ;; always start gnuserv. Otherwise it is preferable to specify
1202 ;; `-f gnuserv-start' on the command line to one of the XEmacsen.
1206 ;;; ********************
1207 ;;; Load the default-dir.el package which installs fancy handling of
1208 ;;; the initial contents in the minibuffer when reading file names.
1209 ;; #### but it seems to cause some breakage.
1210 ;(Init-safe-require 'default-dir))
1212 ;;; ********************
1213 ;;; Put all of your autosave files in one place, instead of scattering
1214 ;;; them around the file system. This has many advantages -- e.g. it
1215 ;;; will eliminate slowdowns caused by editing files on a slow NFS
1216 ;;; server. (*Provided* that your home directory is local or on a
1217 ;;; fast server! If not, pick a value for `auto-save-directory' that
1218 ;;; is fast fast fast!)
1219 (setq auto-save-directory (file-name-as-directory
1220 (expand-file-name ".autosave" (user-home-directory)))
1221 auto-save-directory-fallback auto-save-directory
1222 auto-save-hash-p nil
1224 efs-auto-save-remotely nil
1225 ;; now that we have auto-save-timeout, let's crank this up
1226 ;; for better interactive response.
1227 auto-save-interval 2000
1231 ;;; ********************
1232 ;;; cc-mode (the mode you're in when editing C, C++, and Objective C files)
1234 ;; Tell cc-mode not to check for old-style (K&R) function declarations.
1235 ;; This speeds up indenting a lot.
1236 (setq c-recognize-knr-p nil)
1238 ;; Change the indentation amount to 4 spaces instead of 2.
1239 ;; You have to do it in this complicated way because of the
1240 ;; strange way the cc-mode initializes the value of `c-basic-offset'.
1241 ;; (add-hook 'c-mode-hook (lambda () (setq c-basic-offset 4)))
1243 ;; 4 spaces? you gotta be kidding me! a TAB is 8 in my book --SY.
1244 ;; Also cc-mode is much smarter and easier to get along with these
1245 ;; days. Here are my settings. Note that I set up 3 separate "styles"
1246 ;; at once. They are dependent on the directory the C source is in. --SY.
1249 (setq c-default-style
1250 '((c-mode . "linux")
1251 (c++-mode . "linux")
1252 (java-mode . "java")
1253 (python-mode . "python")
1256 ;; Special style for Linux source files
1257 (defun linux-c-mode ()
1258 "C mode with adjusted defaults for use with the Linux kernel.
1263 (c-set-style "linux")
1264 (setq mode-name "Linux/C"))
1266 (add-to-list 'auto-mode-alist '("^.*/linux.*/.*\\.[ch]$" . linux-c-mode)))
1268 ;; C style for XEmacs core source files
1269 (defun xemacs-c-mode ()
1270 "C mode with adjusted defaults for use with XEmacs core sources.
1276 (setq mode-name "XE/C"))
1278 (add-to-list 'auto-mode-alist '("^.*/xemacs.*/.*\\.[ch]$" . xemacs-c-mode)))
1280 ;; C style for SXEmacs core source files
1281 (defun sxemacs-c-mode ()
1282 "C mode with adjusted defaults for use with SXEmacs core sources.
1287 (c-set-style "linux")
1288 (setq mode-name "SXE/C")
1289 (make-variable-buffer-local 'c-enable-xemacs-performance-kludge-p)
1290 (setq c-enable-xemacs-performance-kludge-p t))
1292 (add-to-list 'auto-mode-alist '("^.*/sxemacs.*/.*\\.[ch]$" . sxemacs-c-mode)))
1295 ;;; ********************
1296 ;;; Load a partial-completion mechanism, which makes minibuffer completion
1297 ;;; search multiple words instead of just prefixes; for example, the command
1298 ;;; `M-x byte-compile-and-load-file RET' can be abbreviated as `M-x b-c-a RET'
1299 ;;; because there are no other commands whose first three words begin with
1300 ;;; the letters `b', `c', and `a' respectively.
1302 (Init-safe-require 'completer)
1305 ;;; ********************
1306 ;;; Load crypt, which is a package for automatically decoding and reencoding
1307 ;;; files by various methods - for example, you can visit a .Z or .gz file,
1308 ;;; edit it, and have it automatically re-compressed when you save it again.
1310 ; (setq crypt-encryption-type 'pgp ; default encryption mechanism
1311 ; crypt-confirm-password t ; make sure new passwords are correct
1312 ; ;crypt-never-ever-decrypt t ; if you don't encrypt anything, set this to
1313 ; ; tell it not to assume that "binary" files
1314 ; ; are encrypted and require a password.
1316 ; (Init-safe-require 'crypt)
1318 ;; crypt has its drawbacks (like it doesn't work all that well), IMO, a
1319 ;; better approach is jka-compr plus EasyPG. The former for handling
1320 ;; compressed files, and the latter for encrypted files. --SY.
1322 ;; Handle automatic (de)compresion of [bg]zip files
1323 (Init-safe-require 'jka-compr)
1326 (Init-safe-require 'epa-setup)
1328 ;;; ********************
1329 ;;; Filladapt is an adaptive text-filling package. When it is enabled it
1330 ;;; makes filling (e.g. using M-q) much much smarter about paragraphs
1331 ;;; that are indented and/or are set off with semicolons, dashes, etc.
1333 (Init-safe-require 'filladapt)
1334 (setq-default filladapt-mode t)
1335 (when (fboundp 'turn-off-filladapt-mode)
1336 (add-hook 'c-mode-hook 'turn-off-filladapt-mode)
1337 (add-hook 'outline-mode-hook 'turn-off-filladapt-mode))
1340 ;;; ********************
1341 ;;; Font-Lock is a syntax-highlighting package. When it is enabled and you
1342 ;;; are editing a program, different parts of your program will appear in
1343 ;;; different fonts or colors. For example, with the code below, comments
1344 ;;; appear in red italics, function names in function definitions appear in
1345 ;;; blue bold, etc. The code below will cause font-lock to automatically be
1346 ;;; enabled when you edit C, C++, Emacs-Lisp, and many other kinds of
1349 ;;; The "Options" menu has some commands for controlling this as well.
1351 ;; The commented-out code below is an example of setting up custom
1352 ;; font-lock colors.
1354 ; ;; If you want the default colors, you could do this:
1355 ; ;; (setq font-lock-use-default-fonts nil)
1356 ; ;; (setq font-lock-use-default-colors t)
1357 ; ;; but I want to specify my own colors, so I turn off all
1358 ; ;; default values.
1359 ; (setq font-lock-use-default-fonts nil)
1360 ; (setq font-lock-use-default-colors nil)
1362 (Init-safe-require 'font-lock)
1364 ; ;; Mess around with the faces a bit. Note that you have
1365 ; ;; to change the font-lock-use-default-* variables *before*
1366 ; ;; loading font-lock, and wait till *after* loading font-lock
1367 ; ;; to customize the faces.
1369 ; ;; string face is green
1370 ; (set-face-foreground 'font-lock-string-face "forest green")
1372 ; ;; comments are italic and red; doc strings are italic
1373 ; (set-face-font 'font-lock-comment-face [italic])
1374 ; ;; Underlining comments looks terrible on tty's
1375 ; (set-face-underline-p 'font-lock-comment-face nil 'global 'tty)
1376 ; (set-face-highlight-p 'font-lock-comment-face t 'global 'tty)
1377 ; (copy-face 'font-lock-comment-face 'font-lock-doc-string-face)
1378 ; (set-face-foreground 'font-lock-comment-face "red")
1380 ; ;; function names are bold and blue
1381 ; (set-face-font 'font-lock-function-name-face [bold])
1382 ; (set-face-foreground 'font-lock-function-name-face "blue")
1385 ; (set-face-font 'font-lock-preprocessor-face [bold])
1386 ; (set-face-font 'font-lock-type-face [italic])
1387 ; (set-face-font 'font-lock-keyword-face [bold])
1390 ;;; ********************
1391 ;;; lazy-lock is a package which speeds up the highlighting of files
1392 ;;; by doing it "on-the-fly" -- only the visible portion of the
1393 ;;; buffer is fontified. The results may not always be quite as
1394 ;;; accurate as using full font-lock or fast-lock, but it's *much*
1395 ;;; faster. No more annoying pauses when you load files.
1397 (if (fboundp 'turn-on-lazy-lock)
1398 (add-hook 'font-lock-mode-hook 'turn-on-lazy-lock))
1400 ;; I personally don't like "stealth mode" (where lazy-lock starts
1401 ;; fontifying in the background if you're idle for 30 seconds)
1402 ;; because it takes too long to wake up again.
1403 (setq lazy-lock-stealth-time nil)
1406 ;;; ********************
1407 ;;; func-menu is a package that scans your source file for function
1408 ;;; definitions and makes a menubar entry that lets you jump to any
1409 ;;; particular function definition by selecting it from the menu. The
1410 ;;; following code turns this on for all of the recognized languages.
1411 ;;; Scanning the buffer takes some time, but not much.
1413 ;;; Send bug reports, enhancements etc to:
1414 ;;; David Hughes <ukchugd@ukpmr.cs.philips.nl>
1416 (Init-safe-require 'func-menu)
1417 (global-set-key '(shift f12) 'function-menu)
1418 (add-hook 'find-file-hooks 'fume-add-menubar-entry)
1419 (global-set-key "\C-cl" 'fume-list-functions)
1420 (global-set-key "\C-cg" 'fume-prompt-function-goto)
1422 ;; The Hyperbole information manager package uses (shift button2) and
1423 ;; (shift button3) to provide context-sensitive mouse keys. If you
1424 ;; use this next binding, it will conflict with Hyperbole's setup.
1425 ;; Choose another mouse key if you use Hyperbole.
1426 (global-set-key '(shift button3) 'mouse-function-menu)
1428 ;; For descriptions of the following user-customizable variables,
1429 ;; type C-h v <variable>
1430 (setq fume-max-items 25
1431 fume-fn-window-position 3
1432 fume-auto-position-popup t
1433 fume-display-in-modeline-p t
1434 fume-menubar-menu-name
1435 (if (fboundp 'submenu-generate-accelerator-spec)
1436 "Function%_s" "Functions")
1437 fume-buffer-name "*Function List*"
1438 fume-no-prompt-on-valid-default nil))
1441 ;;; ********************
1442 ;;; MH is a mail-reading system from the Rand Corporation that relies on a
1443 ;;; number of external filter programs (which do not come with emacs.)
1444 ;;; Emacs provides a nice front-end onto MH, called "mh-e".
1446 ;; Bindings that let you send or read mail using MH
1447 ;(global-set-key "\C-xm" 'mh-smail)
1448 ;(global-set-key "\C-x4m" 'mh-smail-other-window)
1449 ;(global-set-key "\C-cr" 'mh-rmail)
1451 ;; Customization of MH behavior.
1452 (setq mh-delete-yanked-msg-window t)
1453 (setq mh-yank-from-start-of-msg 'body)
1454 (setq mh-summary-height 11)
1456 ;; Use lines like the following if your version of MH
1457 ;; is in a special place.
1458 ;(setq mh-progs "/usr/dist/pkgs/mh/bin.svr4/")
1459 ;(setq mh-lib "/usr/dist/pkgs/mh/lib.svr4/")
1462 ;;; ********************
1463 ;;; resize-minibuffer-mode makes the minibuffer automatically
1464 ;;; resize as necessary when it's too small to hold its contents.
1466 (when (fboundp 'resize-minibuffer-mode)
1467 (resize-minibuffer-mode)
1468 (setq resize-minibuffer-window-exactly nil))
1471 ;;; ********************
1472 ;;; scroll-in-place is a package that keeps the cursor on the same
1473 ;;; line (and in the same column) when scrolling by a page using
1476 (if (Init-safe-require 'scroll-in-place)
1477 (turn-on-scroll-in-place))
1480 ;;; ********************
1481 ;;; W3 is a browser for the World Wide Web, and takes advantage of the very
1482 ;;; latest redisplay features in XEmacs. You can access it simply by typing
1483 ;;; 'M-x w3'; however, if you're unlucky enough to be on a machine that is
1484 ;;; behind a firewall, you will have to do something like this first:
1486 ;(setq w3-use-telnet t
1488 ; ;; If the Telnet program you use to access the outside world is
1489 ; ;; not called "telnet", specify its name like this.
1490 ; w3-telnet-prog "itelnet"
1492 ; ;; If your Telnet program adds lines of junk at the beginning
1493 ; ;; of the session, specify the number of lines here.
1494 ; w3-telnet-header-length 4
1497 ;;; Inhibit loading of custom-file
1499 ;; make-temp-name returns a name which does not refer to an existing file,
1500 ;; and thus the named file is unreadable.
1501 (when Init-inhibit-custom-file-p
1502 (setq custom-file (make-temp-name "/tmp/non-existent-")))