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