]> code.delx.au - gnu-emacs/blob - lisp/bindings.el
(last-buffer): Use buffer-list with frame arg.
[gnu-emacs] / lisp / bindings.el
1 ;;; bindings.el --- define standard key bindings and some variables
2
3 ;; Copyright (C) 1985,86,87,92,93,94,95,96,99,2000, 2001
4 ;; Free Software Foundation, Inc.
5
6 ;; Maintainer: FSF
7 ;; Keywords: internal
8
9 ;; This file is part of GNU Emacs.
10
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
15
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to
23 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
25
26 ;;; Commentary:
27
28 ;;; !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
29 ;;; Special formatting conventions are used in this file!
30 ;;;
31 ;;; a backslash-newline is used at the beginning of a documentation string
32 ;;; when that string should be stored in the file etc/DOCnnn, not in core.
33 ;;;
34 ;;; Such strings read into Lisp as numbers (during the pure-loading phase).
35 ;;;
36 ;;; But you must obey certain rules to make sure the string is understood
37 ;;; and goes into etc/DOCnnn properly.
38 ;;;
39 ;;; The doc string must appear in the standard place in a call to
40 ;;; defun, autoload, defvar or defconst. No Lisp macros are recognized.
41 ;;; The open-paren starting the definition must appear in column 0.
42 ;;;
43 ;;; In defvar and defconst, there is an additional rule:
44 ;;; The double-quote that starts the string must be on the same
45 ;;; line as the defvar or defconst.
46 ;;; !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
47
48 ;;; Code:
49
50 (defun make-mode-line-mouse-map (mouse function) "\
51 Return a keymap with single entry for mouse key MOUSE on the mode line.
52 MOUSE is defined to run function FUNCTION with no args in the buffer
53 corresponding to the mode line clicked."
54 (let ((map (make-sparse-keymap)))
55 (define-key map (vector 'mode-line mouse) function)
56 map))
57
58
59 (defun mode-line-toggle-read-only (event)
60 "Like `toggle-read-only', for the mode-line."
61 (interactive "e")
62 (save-selected-window
63 (select-window (posn-window (event-start event)))
64 (toggle-read-only)
65 (force-mode-line-update)))
66
67
68 (defun mode-line-toggle-modified (event)
69 "Toggle the buffer-modified flag from the mode-line."
70 (interactive "e")
71 (save-selected-window
72 (select-window (posn-window (event-start event)))
73 (set-buffer-modified-p (not (buffer-modified-p)))
74 (force-mode-line-update)))
75
76
77 (defun mode-line-widen (event)
78 "Widen a buffer from the mode-line."
79 (interactive "e")
80 (save-selected-window
81 (select-window (posn-window (event-start event)))
82 (widen)
83 (force-mode-line-update)))
84
85
86 (defun mode-line-abbrev-mode (event)
87 "Turn off `abbrev-mode' from the mode-line."
88 (interactive "e")
89 (save-selected-window
90 (select-window (posn-window (event-start event)))
91 (abbrev-mode)
92 (force-mode-line-update)))
93
94
95 (defun mode-line-auto-fill-mode (event)
96 "Turn off `auto-fill-mode' from the mode-line."
97 (interactive "e")
98 (save-selected-window
99 (select-window (posn-window (event-start event)))
100 (auto-fill-mode)
101 (force-mode-line-update)))
102
103
104 (defvar mode-line-input-method-map
105 (let ((map (make-sparse-keymap)))
106 (define-key map [mode-line mouse-2]
107 (lambda (e)
108 (interactive "e")
109 (save-selected-window
110 (select-window
111 (posn-window (event-start e)))
112 (toggle-input-method)
113 (force-mode-line-update))))
114 (define-key map [mode-line mouse-3]
115 (lambda (e)
116 (interactive "e")
117 (save-selected-window
118 (select-window
119 (posn-window (event-start e)))
120 (describe-current-input-method))))
121 (purecopy map)))
122
123
124 (defvar mode-line-coding-system-map
125 (let ((map (make-sparse-keymap)))
126 (define-key map [mode-line mouse-3]
127 (lambda (e)
128 (interactive "e")
129 (save-selected-window
130 (select-window (posn-window (event-start e)))
131 (when (and enable-multibyte-characters
132 buffer-file-coding-system)
133 (describe-coding-system buffer-file-coding-system)))))
134 (purecopy map))
135 "Local keymap for the coding-system part of the mode line.")
136
137
138 (defvar mode-line-mule-info
139 `(""
140 (current-input-method
141 (:propertize ("" current-input-method-title)
142 help-echo (concat
143 "Input method: "
144 current-input-method
145 ". mouse-2: disable, mouse-3: describe")
146 local-map ,mode-line-input-method-map))
147 ,(propertize
148 "%Z"
149 'help-echo
150 #'(lambda (window object point)
151 (with-current-buffer (window-buffer window)
152 ;; Don't show this tip if the coding system is nil,
153 ;; it reads like a bug, and is not useful anyway.
154 (when buffer-file-coding-system
155 (if enable-multibyte-characters
156 (concat (symbol-name buffer-file-coding-system)
157 " buffer; mouse-3: describe coding system")
158 (concat "Unibyte " (symbol-name buffer-file-coding-system)
159 " buffer")))))
160 'local-map mode-line-coding-system-map))
161 "Mode-line control for displaying information of multilingual environment.
162 Normally it displays current input method (if any activated) and
163 mnemonics of the following coding systems:
164 coding system for saving or writing the current buffer
165 coding system for keyboard input (if Emacs is running on terminal)
166 coding system for terminal output (if Emacs is running on terminal)"
167 ;;; Currently not:
168 ;;; coding system for decoding output of buffer process (if any)
169 ;;; coding system for encoding text to send to buffer process (if any)."
170 )
171
172 (make-variable-buffer-local 'mode-line-mule-info)
173
174 (defvar mode-line-buffer-identification (purecopy '("%12b")) "\
175 Mode-line control for identifying the buffer being displayed.
176 Its default value is (\"%12b\").
177 Major modes that edit things other than ordinary files may change this
178 \(e.g. Info, Dired,...)")
179
180 (make-variable-buffer-local 'mode-line-buffer-identification)
181
182 (defvar mode-line-frame-identification '("-%F ")
183 "Mode-line control to describe the current frame.")
184
185 (defvar mode-line-process nil "\
186 Mode-line control for displaying info on process status.
187 Normally nil in most modes, since there is no process to display.")
188
189 (make-variable-buffer-local 'mode-line-process)
190
191 (defvar mode-line-modified
192 (list (propertize
193 "%1*"
194 'help-echo (purecopy (lambda (window object point)
195 (format "%sead-only: mouse-3 toggles"
196 (save-selected-window
197 (select-window window)
198 (if buffer-read-only
199 "R"
200 "Not r")))))
201 'local-map (purecopy (make-mode-line-mouse-map
202 'mouse-3
203 #'mode-line-toggle-read-only)))
204 (propertize
205 "%1+"
206 'help-echo (purecopy (lambda (window object point)
207 (format "%sodified: mouse-3 toggles"
208 (save-selected-window
209 (select-window window)
210 (if (buffer-modified-p)
211 "M"
212 "Not m")))))
213 'local-map (purecopy (make-mode-line-mouse-map
214 'mouse-3 #'mode-line-toggle-modified))))
215 "Mode-line control for displaying whether current buffer is modified.")
216
217 (make-variable-buffer-local 'mode-line-modified)
218
219 ;; Actual initialization is below.
220 (defvar mode-line-position nil
221 "Mode-line control for displaying line number, column number and fraction.")
222
223 (defvar mode-line-modes nil
224 "Mode-line control for displaying major and minor modes.")
225
226 (defvar mode-line-minor-mode-keymap nil "\
227 Keymap to display on major and minor modes.")
228
229 ;; Menu of minor modes.
230 (let ((map (make-sparse-keymap)))
231 (define-key map [mode-line down-mouse-3] 'mode-line-mode-menu-1)
232 (define-key map [header-line down-mouse-3] 'mode-line-mode-menu-1)
233 (setq mode-line-minor-mode-keymap map))
234
235 (let* ((help-echo
236 ;; The multi-line message doesn't work terribly well on the
237 ;; bottom mode line... Better ideas?
238 ;; "\
239 ;; mouse-1: select window, mouse-2: delete others, mouse-3: delete,
240 ;; drag-mouse-1: resize, C-mouse-2: split horizontally"
241 "mouse-1: select (drag to resize), mouse-2: delete others, mouse-3: delete")
242 (dashes (propertize "--" 'help-echo help-echo)))
243 (setq-default mode-line-format
244 (list
245 (propertize "-" 'help-echo help-echo)
246 'mode-line-mule-info
247 'mode-line-modified
248 'mode-line-frame-identification
249 'mode-line-buffer-identification
250 (propertize " " 'help-echo help-echo)
251 'global-mode-string
252 'mode-line-modes
253 `(which-func-mode ("" which-func-format ,dashes))
254 'mode-line-position
255 (propertize "-%-" 'help-echo help-echo)))
256
257 (setq-default mode-line-modes
258 (list
259 (propertize " %[(" 'help-echo help-echo)
260 `(:propertize ("" mode-name mode-line-process minor-mode-alist)
261 help-echo "mouse-3: minor mode menu"
262 local-map ,mode-line-minor-mode-keymap)
263 (propertize "%n" 'help-echo "mouse-2: widen"
264 'local-map (make-mode-line-mouse-map
265 'mouse-2 #'mode-line-widen))
266 (propertize ")%]--" 'help-echo help-echo)))
267
268 (setq-default mode-line-position
269 `((line-number-mode (,(propertize "L%l" 'help-echo help-echo) ,dashes))
270 (column-number-mode (,(propertize "C%c" 'help-echo help-echo) ,dashes))
271 (-3 . ,(propertize "%p" 'help-echo help-echo)))))
272
273 (defvar mode-line-buffer-identification-keymap nil "\
274 Keymap for what is displayed by `mode-line-buffer-identification'.")
275
276 (defun last-buffer () "\
277 Return the last non-hidden buffer in the buffer list."
278 ;; This logic is more or less copied from bury-buffer,
279 ;; except that we reverse the buffer list.
280 (let ((list (nreverse (buffer-list (selected-frame))))
281 (pred (frame-parameter nil 'buffer-predicate))
282 found notsogood)
283 (while (and list (not found))
284 (unless (or (eq (aref (buffer-name (car list)) 0) ? )
285 ;; If the selected frame has a buffer_predicate,
286 ;; disregard buffers that don't fit the predicate.
287 (and pred (not (funcall pred (car list)))))
288 (if (get-buffer-window (car list) 'visible)
289 (or notsogood (eq (car list) (current-buffer)))
290 (setq found (car list))))
291 (pop list))
292 (or found notsogood
293 (get-buffer "*scratch*")
294 (progn
295 (set-buffer-major-mode
296 (get-buffer-create "*scratch*"))
297 (get-buffer "*scratch*")))))
298
299 (defun unbury-buffer () "\
300 Switch to the last buffer in the buffer list."
301 (interactive)
302 (switch-to-buffer (last-buffer)))
303
304 (defun mode-line-unbury-buffer (event) "\
305 Call `unbury-buffer' in this window."
306 (interactive "e")
307 (save-selected-window
308 (select-window (posn-window (event-start event)))
309 (unbury-buffer)))
310
311 (defun mode-line-bury-buffer (event) "\
312 Like `bury-buffer', but temporarily select EVENT's window."
313 (interactive "e")
314 (save-selected-window
315 (select-window (posn-window (event-start event)))
316 (bury-buffer)))
317
318 (defun mode-line-other-buffer () "\
319 Switch to the most recently selected buffer other than the current one."
320 (interactive)
321 (switch-to-buffer (other-buffer)))
322
323 (defvar mode-line-mode-menu (make-sparse-keymap "Minor Modes") "\
324 Menu of mode operations in the mode line.")
325
326 (defun mode-line-mode-menu-1 (event)
327 (interactive "e")
328 (save-selected-window
329 (select-window (posn-window (event-start event)))
330 (let* ((selection (mode-line-mode-menu event))
331 (binding (and selection (lookup-key mode-line-mode-menu
332 (vector (car selection))))))
333 (if binding
334 (call-interactively binding)))))
335
336 (defmacro bound-and-true-p (var)
337 "Return the value of symbol VAR if it is bound, else nil."
338 `(and (boundp (quote ,var)) ,var))
339
340 (define-key mode-line-mode-menu [overwrite-mode]
341 `(menu-item ,(purecopy "Overwrite (Ovwrt)") overwrite-mode
342 :button (:toggle . overwrite-mode)))
343 (define-key mode-line-mode-menu [outline-minor-mode]
344 `(menu-item ,(purecopy "Outline (Outl)") outline-minor-mode
345 :button (:toggle . (bound-and-true-p outline-minor-mode))))
346 (define-key mode-line-mode-menu [line-number-mode]
347 `(menu-item ,(purecopy "Line number") line-number-mode
348 :button (:toggle . line-number-mode)))
349 (define-key mode-line-mode-menu [highlight-changes-mode]
350 `(menu-item ,(purecopy "Highlight changes (Chg)") highlight-changes-mode
351 :button (:toggle . highlight-changes-mode)))
352 (define-key mode-line-mode-menu [glasses-mode]
353 `(menu-item ,(purecopy "Glasses (o^o)") glasses-mode
354 :button (:toggle . (bound-and-true-p glasses-mode))))
355 (define-key mode-line-mode-menu [hide-ifdef-mode]
356 `(menu-item ,(purecopy "Hide ifdef (Ifdef)") hide-ifdef-mode
357 :button (:toggle . (bound-and-true-p hide-ifdef-mode))))
358 (define-key mode-line-mode-menu [font-lock-mode]
359 `(menu-item ,(purecopy "Font Lock") font-lock-mode
360 :button (:toggle . font-lock-mode)))
361 (define-key mode-line-mode-menu [flyspell-mode]
362 `(menu-item ,(purecopy "Flyspell (Fly)") flyspell-mode
363 :button (:toggle . (bound-and-true-p flyspell-mode))))
364 (define-key mode-line-mode-menu [column-number-mode]
365 `(menu-item ,(purecopy "Column number") column-number-mode
366 :button (:toggle . column-number-mode)))
367 (define-key mode-line-mode-menu [auto-fill-mode]
368 `(menu-item ,(purecopy "Auto Fill (Fill)") auto-fill-mode
369 :button (:toggle . auto-fill-function)))
370 (define-key mode-line-mode-menu [auto-revert-mode]
371 `(menu-item ,(purecopy "Auto revert (ARev)") auto-revert-mode
372 :button (:toggle . auto-revert-mode)))
373 (define-key mode-line-mode-menu [abbrev-mode]
374 `(menu-item ,(purecopy "Abbrev (Abbrev)") abbrev-mode
375 :button (:toggle . abbrev-mode)))
376
377 (defun mode-line-mode-menu (event)
378 (interactive "@e")
379 (x-popup-menu event mode-line-mode-menu))
380
381 ;; Add menu of buffer operations to the buffer identification part
382 ;; of the mode line.or header line.
383 ;
384 (let ((map (make-sparse-keymap)))
385 ;; Bind down- events so that the global keymap won't ``shine
386 ;; through''.
387 (define-key map [mode-line down-mouse-1] 'ignore)
388 (define-key map [mode-line mouse-1] 'mode-line-unbury-buffer)
389 (define-key map [header-line down-mouse-1] 'ignore)
390 (define-key map [header-line mouse-1] 'mode-line-unbury-buffer)
391 (define-key map [header-line down-mouse-3] 'ignore)
392 (define-key map [mode-line mouse-3] 'mode-line-bury-buffer)
393 (define-key map [header-line down-mouse-3] 'ignore)
394 (define-key map [header-line mouse-3] 'mode-line-bury-buffer)
395 (setq mode-line-buffer-identification-keymap map))
396
397 (defun propertized-buffer-identification (fmt)
398 "Return a list suitable for `mode-line-buffer-identification'.
399 FMT is a format specifier such as \"%12b\". This function adds
400 text properties for face, help-echo, and local-map to it."
401 (list (propertize fmt
402 'face '(:weight bold)
403 'help-echo
404 (purecopy "mouse-1: previous buffer, mouse-3: next buffer")
405 'local-map mode-line-buffer-identification-keymap)))
406
407 (setq-default mode-line-buffer-identification
408 (propertized-buffer-identification "%12b"))
409
410 (defvar minor-mode-alist nil "\
411 Alist saying how to show minor modes in the mode line.
412 Each element looks like (VARIABLE STRING);
413 STRING is included in the mode line iff VARIABLE's value is non-nil.
414
415 Actually, STRING need not be a string; any possible mode-line element
416 is okay. See `mode-line-format'.")
417 ;; Don't use purecopy here--some people want to change these strings.
418 (setq minor-mode-alist
419 (list
420 (list 'abbrev-mode " Abbrev")
421 '(overwrite-mode overwrite-mode)
422 (list 'auto-fill-function " Fill")
423 ;; not really a minor mode...
424 '(defining-kbd-macro " Def")))
425
426 ;; These variables are used by autoloadable packages.
427 ;; They are defined here so that they do not get overridden
428 ;; by the loading of those packages.
429
430 ;; Names in directory that end in one of these
431 ;; are ignored in completion,
432 ;; making it more likely you will get a unique match.
433 (setq completion-ignored-extensions
434 (append
435 (cond ((memq system-type '(ms-dos windows-nt))
436 '(".o" "~" ".bin" ".bak" ".obj" ".map" ".ico" ".pif" ".lnk"
437 ".a" ".ln" ".blg" ".bbl" ".dll" ".drv" ".vxd" ".386"))
438 ((eq system-type 'vax-vms)
439 '(".obj" ".exe" ".bin" ".lbin" ".sbin"
440 ".brn" ".rnt" ".lni" ".lis"
441 ".olb" ".tlb" ".mlb" ".hlb"))
442 (t
443 '(".o" "~" ".bin" ".lbin" ".so"
444 ".a" ".ln" ".blg" ".bbl")))
445 '(".elc" ".lof"
446 ".glo" ".idx" ".lot"
447 ;; TeX-related
448 ".dvi" ".fmt" ".tfm" ".pdf"
449 ;; Java compiled
450 ".class"
451 ;; CLISP
452 ".fas" ".lib" ".mem"
453 ;; CMUCL
454 ".x86f" ".sparcf"
455 ;; Other CL implementations (Allegro, LispWorks)
456 ".fasl" ".ufsl" ".fsl" ".dxl"
457 ;; Libtool
458 ".lo" ".la"
459 ;; Gettext
460 ".gmo" ".mo"
461 ;; Texinfo-related
462 ".toc" ".log" ".aux"
463 ".cp" ".fn" ".ky" ".pg" ".tp" ".vr"
464 ".cps" ".fns" ".kys" ".pgs" ".tps" ".vrs")))
465
466 ;; Suffixes used for executables.
467 (setq exec-suffixes
468 (cond
469 ((memq system-type '(ms-dos windows-nt))
470 '(".exe" ".com" ".bat" ".cmd" ".btm" ""))
471 (t
472 '(""))))
473
474 ;; Packages should add to this list appropriately when they are
475 ;; loaded, rather than listing everything here.
476 (setq debug-ignored-errors
477 '(beginning-of-line beginning-of-buffer end-of-line
478 end-of-buffer end-of-file buffer-read-only
479 file-supersession
480 "^Previous command was not a yank$"
481 "^Minibuffer window is not active$"
482 "^End of history; no next item$"
483 "^Beginning of history; no preceding item$"
484 "^No recursive edit is in progress$"
485 "^Changes to be undone are outside visible portion of buffer$"
486 "^No undo information in this buffer$"
487 "^No further undo information$"
488 "^Save not confirmed$"
489 "^Recover-file cancelled\\.$"
490 "^Cannot switch buffers in a dedicated window$"
491
492 ;; ediff
493 "^Errors in diff output. Diff output is in "
494 "^Hmm... I don't see an Ediff command around here...$"
495 "^Undocumented command! Type `G' in Ediff Control Panel to drop a note to the Ediff maintainer$"
496 ": This command runs in Ediff Control Buffer only!$"
497 ": Invalid op in ediff-check-version$"
498 "^ediff-shrink-window-C can be used only for merging jobs$"
499 "^Lost difference info on these directories$"
500 "^This command is inapplicable in the present context$"
501 "^This session group has no parent$"
502 "^Can't hide active session, $"
503 "^Ediff: something wrong--no multiple diffs buffer$"
504 "^Can't make context diff for Session $"
505 "^The patch buffer wasn't found$"
506 "^Aborted$"
507 "^This Ediff session is not part of a session group$"
508 "^No active Ediff sessions or corrupted session registry$"
509 "^No session info in this line$"
510 "^`.*' is not an ordinary file$"
511 "^Patch appears to have failed$"
512 "^Recomputation of differences cancelled$"
513 "^No fine differences in this mode$"
514 "^Lost connection to ancestor buffer...sorry$"
515 "^Not merging with ancestor$"
516 "^Don't know how to toggle read-only in buffer "
517 "Emacs is not running as a window application$"
518 "^This command makes sense only when merging with an ancestor$"
519 "^At end of the difference list$"
520 "^At beginning of the difference list$"
521 "^Nothing saved for diff .* in buffer "
522 "^Buffer is out of sync for file "
523 "^Buffer out of sync for file "
524 "^Output from `diff' not found$"
525 "^You forgot to specify a region in buffer "
526 "^All right. Make up your mind and come back...$"
527 "^Current buffer is not visiting any file$"
528 "^Failed to retrieve revision: $"
529 "^Can't determine display width.$"
530 "^File `.*' does not exist or is not readable$"
531 "^File `.*' is a directory$"
532 "^Buffer .* doesn't exist$"
533 "^Directories . and . are the same: "
534 "^Directory merge aborted$"
535 "^Merge of directory revisions aborted$"
536 "^Buffer .* doesn't exist$"
537 "^There is no file to merge$"
538 "^Version control package .*.el not found. Use vc.el instead$"))
539
540
541 (make-variable-buffer-local 'indent-tabs-mode)
542
543 ;; We have base64 and md5 functions built in now.
544 (provide 'base64)
545 (provide 'md5)
546 (provide 'overlay '(display syntax-table field))
547 (provide 'text-properties '(display syntax-table field point-entered))
548
549 (define-key esc-map "\t" 'complete-symbol)
550
551 (defun complete-symbol (arg) "\
552 Perform tags completion on the text around point.
553 Completes to the set of names listed in the current tags table.
554 The string to complete is chosen in the same way as the default
555 for \\[find-tag] (which see).
556
557 With a prefix argument, this command does completion within
558 the collection of symbols listed in the index of the manual for the
559 language you are using."
560 (interactive "P")
561 (if arg
562 (info-complete-symbol)
563 (if (fboundp 'complete-tag)
564 (complete-tag)
565 ;; Don't autoload etags if we have no tags table.
566 (error (substitute-command-keys
567 "No tags table loaded; use \\[visit-tags-table] to load one")))))
568
569 ;; Reduce total amount of space we must allocate during this function
570 ;; that we will not need to keep permanently.
571 (garbage-collect)
572 \f
573 ;; Make all multibyte characters self-insert.
574 (let ((l (generic-character-list))
575 (table (nth 1 global-map)))
576 (while l
577 (set-char-table-default table (car l) 'self-insert-command)
578 (setq l (cdr l))))
579
580 (setq help-event-list '(help f1))
581
582 (make-variable-buffer-local 'minor-mode-overriding-map-alist)
583
584 ;; From macros.c
585 (define-key ctl-x-map "(" 'start-kbd-macro)
586 (define-key ctl-x-map ")" 'end-kbd-macro)
587 (define-key ctl-x-map "e" 'call-last-kbd-macro)
588 ;; From frame.c
589 (global-set-key [switch-frame] 'handle-switch-frame)
590 (global-set-key [delete-frame] 'handle-delete-frame)
591 (global-set-key [iconify-frame] 'ignore-event)
592 (global-set-key [make-frame-visible] 'ignore-event)
593
594
595 ;These commands are defined in editfns.c
596 ;but they are not assigned to keys there.
597 (put 'narrow-to-region 'disabled t)
598 (define-key ctl-x-map "nn" 'narrow-to-region)
599 (define-key ctl-x-map "nw" 'widen)
600 ;; (define-key ctl-x-map "n" 'narrow-to-region)
601 ;; (define-key ctl-x-map "w" 'widen)
602
603 (define-key global-map "\C-j" 'newline-and-indent)
604 (define-key global-map "\C-m" 'newline)
605 (define-key global-map "\C-o" 'open-line)
606 (define-key esc-map "\C-o" 'split-line)
607 (define-key global-map "\C-q" 'quoted-insert)
608 (define-key esc-map "^" 'delete-indentation)
609 (define-key esc-map "\\" 'delete-horizontal-space)
610 (define-key esc-map "m" 'back-to-indentation)
611 (define-key ctl-x-map "\C-o" 'delete-blank-lines)
612 (define-key esc-map " " 'just-one-space)
613 (define-key esc-map "z" 'zap-to-char)
614 (define-key esc-map "=" 'count-lines-region)
615 (define-key ctl-x-map "=" 'what-cursor-position)
616 (define-key esc-map ":" 'eval-expression)
617 ;; Define ESC ESC : like ESC : for people who type ESC ESC out of habit.
618 (define-key esc-map "\M-:" 'eval-expression)
619 ;; Changed from C-x ESC so that function keys work following C-x.
620 (define-key ctl-x-map "\e\e" 'repeat-complex-command)
621 ;; New binding analogous to M-:.
622 (define-key ctl-x-map "\M-:" 'repeat-complex-command)
623 (define-key ctl-x-map "u" 'advertised-undo)
624 ;; Many people are used to typing C-/ on X terminals and getting C-_.
625 (define-key global-map [?\C-/] 'undo)
626 (define-key global-map "\C-_" 'undo)
627 (define-key esc-map "!" 'shell-command)
628 (define-key esc-map "|" 'shell-command-on-region)
629
630 (let ((map minibuffer-local-map))
631 (define-key map "\en" 'next-history-element)
632 (define-key map [next] 'next-history-element)
633 (define-key map [down] 'next-history-element)
634 (define-key map "\ep" 'previous-history-element)
635 (define-key map [prior] 'previous-history-element)
636 (define-key map [up] 'previous-history-element)
637 (define-key map "\es" 'next-matching-history-element)
638 (define-key map "\er" 'previous-matching-history-element))
639
640 (define-key global-map "\C-u" 'universal-argument)
641 (let ((i ?0))
642 (while (<= i ?9)
643 (define-key esc-map (char-to-string i) 'digit-argument)
644 (setq i (1+ i))))
645 (define-key esc-map "-" 'negative-argument)
646 ;; Define control-digits.
647 (let ((i ?0))
648 (while (<= i ?9)
649 (define-key global-map (read (format "[?\\C-%c]" i)) 'digit-argument)
650 (setq i (1+ i))))
651 (define-key global-map [?\C--] 'negative-argument)
652 ;; Define control-meta-digits.
653 (let ((i ?0))
654 (while (<= i ?9)
655 (define-key esc-map (read (format "[?\\C-%c]" i)) 'digit-argument)
656 (setq i (1+ i))))
657 (define-key global-map [?\C-\M--] 'negative-argument)
658
659 (define-key global-map "\C-k" 'kill-line)
660 (define-key global-map "\C-w" 'kill-region)
661 (define-key esc-map "w" 'kill-ring-save)
662 (define-key esc-map "\C-w" 'append-next-kill)
663 (define-key global-map "\C-y" 'yank)
664 (define-key esc-map "y" 'yank-pop)
665
666 ;; (define-key ctl-x-map "a" 'append-to-buffer)
667
668 (define-key global-map "\C-@" 'set-mark-command)
669 ;; Many people are used to typing C-SPC and getting C-@.
670 (define-key global-map [?\C- ] 'set-mark-command)
671 (define-key ctl-x-map "\C-x" 'exchange-point-and-mark)
672 (define-key ctl-x-map "\C-@" 'pop-global-mark)
673 (define-key ctl-x-map [?\C- ] 'pop-global-mark)
674
675 (define-key global-map "\C-n" 'next-line)
676 (define-key global-map "\C-p" 'previous-line)
677 (define-key ctl-x-map "\C-n" 'set-goal-column)
678
679 ;;(defun function-key-error ()
680 ;; (interactive)
681 ;; (error "That function key is not bound to anything"))
682
683 (define-key global-map [menu] 'execute-extended-command)
684 (define-key global-map [find] 'search-forward)
685
686 ;; Don't do this. We define <delete> in function-key-map instead.
687 ;(define-key global-map [delete] 'backward-delete-char)
688
689 ;; natural bindings for terminal keycaps --- defined in X keysym order
690 (define-key global-map [home] 'beginning-of-line)
691 (define-key global-map [C-home] 'beginning-of-buffer)
692 (define-key global-map [M-home] 'beginning-of-buffer-other-window)
693 (define-key global-map [left] 'backward-char)
694 (define-key global-map [up] 'previous-line)
695 (define-key global-map [right] 'forward-char)
696 (define-key global-map [down] 'next-line)
697 (define-key global-map [prior] 'scroll-down)
698 (define-key global-map [next] 'scroll-up)
699 (define-key global-map [C-up] 'backward-paragraph)
700 (define-key global-map [C-down] 'forward-paragraph)
701 (define-key global-map [C-prior] 'scroll-right)
702 (define-key global-map [C-next] 'scroll-left)
703 (define-key global-map [M-next] 'scroll-other-window)
704 (define-key global-map [M-prior] 'scroll-other-window-down)
705 (define-key global-map [end] 'end-of-line)
706 (define-key global-map [C-end] 'end-of-buffer)
707 (define-key global-map [M-end] 'end-of-buffer-other-window)
708 (define-key global-map [begin] 'beginning-of-buffer)
709 (define-key global-map [M-begin] 'beginning-of-buffer-other-window)
710 ;; (define-key global-map [select] 'function-key-error)
711 ;; (define-key global-map [print] 'function-key-error)
712 (define-key global-map [execute] 'execute-extended-command)
713 (define-key global-map [insert] 'overwrite-mode)
714 (define-key global-map [C-insert] 'kill-ring-save)
715 (define-key global-map [S-insert] 'yank)
716 (define-key global-map [undo] 'undo)
717 (define-key global-map [redo] 'repeat-complex-command)
718 ;; (define-key global-map [clearline] 'function-key-error)
719 (define-key global-map [insertline] 'open-line)
720 (define-key global-map [deleteline] 'kill-line)
721 ;; (define-key global-map [insertchar] 'function-key-error)
722 (define-key global-map [deletechar] 'delete-char)
723 ;; (define-key global-map [backtab] 'function-key-error)
724 ;; (define-key global-map [f1] 'function-key-error)
725 ;; (define-key global-map [f2] 'function-key-error)
726 ;; (define-key global-map [f3] 'function-key-error)
727 ;; (define-key global-map [f4] 'function-key-error)
728 ;; (define-key global-map [f5] 'function-key-error)
729 ;; (define-key global-map [f6] 'function-key-error)
730 ;; (define-key global-map [f7] 'function-key-error)
731 ;; (define-key global-map [f8] 'function-key-error)
732 ;; (define-key global-map [f9] 'function-key-error)
733 ;; (define-key global-map [f10] 'function-key-error)
734 ;; (define-key global-map [f11] 'function-key-error)
735 ;; (define-key global-map [f12] 'function-key-error)
736 ;; (define-key global-map [f13] 'function-key-error)
737 ;; (define-key global-map [f14] 'function-key-error)
738 ;; (define-key global-map [f15] 'function-key-error)
739 ;; (define-key global-map [f16] 'function-key-error)
740 ;; (define-key global-map [f17] 'function-key-error)
741 ;; (define-key global-map [f18] 'function-key-error)
742 ;; (define-key global-map [f19] 'function-key-error)
743 ;; (define-key global-map [f20] 'function-key-error)
744 ;; (define-key global-map [f21] 'function-key-error)
745 ;; (define-key global-map [f22] 'function-key-error)
746 ;; (define-key global-map [f23] 'function-key-error)
747 ;; (define-key global-map [f24] 'function-key-error)
748 ;; (define-key global-map [f25] 'function-key-error)
749 ;; (define-key global-map [f26] 'function-key-error)
750 ;; (define-key global-map [f27] 'function-key-error)
751 ;; (define-key global-map [f28] 'function-key-error)
752 ;; (define-key global-map [f29] 'function-key-error)
753 ;; (define-key global-map [f30] 'function-key-error)
754 ;; (define-key global-map [f31] 'function-key-error)
755 ;; (define-key global-map [f32] 'function-key-error)
756 ;; (define-key global-map [f33] 'function-key-error)
757 ;; (define-key global-map [f34] 'function-key-error)
758 ;; (define-key global-map [f35] 'function-key-error)
759 ;; (define-key global-map [kp-backtab] 'function-key-error)
760 ;; (define-key global-map [kp-space] 'function-key-error)
761 ;; (define-key global-map [kp-tab] 'function-key-error)
762 ;; (define-key global-map [kp-enter] 'function-key-error)
763 ;; (define-key global-map [kp-f1] 'function-key-error)
764 ;; (define-key global-map [kp-f2] 'function-key-error)
765 ;; (define-key global-map [kp-f3] 'function-key-error)
766 ;; (define-key global-map [kp-f4] 'function-key-error)
767 ;; (define-key global-map [kp-multiply] 'function-key-error)
768 ;; (define-key global-map [kp-add] 'function-key-error)
769 ;; (define-key global-map [kp-separator] 'function-key-error)
770 ;; (define-key global-map [kp-subtract] 'function-key-error)
771 ;; (define-key global-map [kp-decimal] 'function-key-error)
772 ;; (define-key global-map [kp-divide] 'function-key-error)
773 ;; (define-key global-map [kp-0] 'function-key-error)
774 ;; (define-key global-map [kp-1] 'function-key-error)
775 ;; (define-key global-map [kp-2] 'function-key-error)
776 ;; (define-key global-map [kp-3] 'function-key-error)
777 ;; (define-key global-map [kp-4] 'function-key-error)
778 ;; (define-key global-map [kp-5] 'recenter)
779 ;; (define-key global-map [kp-6] 'function-key-error)
780 ;; (define-key global-map [kp-7] 'function-key-error)
781 ;; (define-key global-map [kp-8] 'function-key-error)
782 ;; (define-key global-map [kp-9] 'function-key-error)
783 ;; (define-key global-map [kp-equal] 'function-key-error)
784
785 ;; X11R6 distinguishes these keys from the non-kp keys.
786 ;; Make them behave like the non-kp keys unless otherwise bound.
787 (define-key function-key-map [kp-home] [home])
788 (define-key function-key-map [kp-left] [left])
789 (define-key function-key-map [kp-up] [up])
790 (define-key function-key-map [kp-right] [right])
791 (define-key function-key-map [kp-down] [down])
792 (define-key function-key-map [kp-prior] [prior])
793 (define-key function-key-map [kp-next] [next])
794 (define-key function-key-map [M-kp-next] [M-next])
795 (define-key function-key-map [kp-end] [end])
796 (define-key function-key-map [kp-begin] [begin])
797 (define-key function-key-map [kp-insert] [insert])
798 (define-key function-key-map [backspace] [?\C-?])
799 (define-key function-key-map [delete] [?\C-?])
800 (define-key function-key-map [kp-delete] [?\C-?])
801 (define-key function-key-map [S-kp-end] [S-end])
802 (define-key function-key-map [S-kp-down] [S-down])
803 (define-key function-key-map [S-kp-next] [S-next])
804 (define-key function-key-map [S-kp-left] [S-left])
805 (define-key function-key-map [S-kp-right] [S-right])
806 (define-key function-key-map [S-kp-home] [S-home])
807 (define-key function-key-map [S-kp-up] [S-up])
808 (define-key function-key-map [S-kp-prior] [S-prior])
809 (define-key function-key-map [C-S-kp-end] [C-S-end])
810 (define-key function-key-map [C-S-kp-down] [C-S-down])
811 (define-key function-key-map [C-S-kp-next] [C-S-next])
812 (define-key function-key-map [C-S-kp-left] [C-S-left])
813 (define-key function-key-map [C-S-kp-right] [C-S-right])
814 (define-key function-key-map [C-S-kp-home] [C-S-home])
815 (define-key function-key-map [C-S-kp-up] [C-S-up])
816 (define-key function-key-map [C-S-kp-prior] [C-S-prior])
817 ;; Don't bind shifted keypad numeric keys, they reportedly
818 ;; interfere with the feature of some keyboards to produce
819 ;; numbers when NumLock is off.
820 ;(define-key function-key-map [S-kp-1] [S-end])
821 ;(define-key function-key-map [S-kp-2] [S-down])
822 ;(define-key function-key-map [S-kp-3] [S-next])
823 ;(define-key function-key-map [S-kp-4] [S-left])
824 ;(define-key function-key-map [S-kp-6] [S-right])
825 ;(define-key function-key-map [S-kp-7] [S-home])
826 ;(define-key function-key-map [S-kp-8] [S-up])
827 ;(define-key function-key-map [S-kp-9] [S-prior])
828 (define-key function-key-map [C-S-kp-1] [C-S-end])
829 (define-key function-key-map [C-S-kp-2] [C-S-down])
830 (define-key function-key-map [C-S-kp-3] [C-S-next])
831 (define-key function-key-map [C-S-kp-4] [C-S-left])
832 (define-key function-key-map [C-S-kp-6] [C-S-right])
833 (define-key function-key-map [C-S-kp-7] [C-S-home])
834 (define-key function-key-map [C-S-kp-8] [C-S-up])
835 (define-key function-key-map [C-S-kp-9] [C-S-prior])
836
837 (define-key global-map [mouse-movement] 'ignore)
838
839 (define-key global-map "\C-t" 'transpose-chars)
840 (define-key esc-map "t" 'transpose-words)
841 (define-key esc-map "\C-t" 'transpose-sexps)
842 (define-key ctl-x-map "\C-t" 'transpose-lines)
843
844 (define-key esc-map ";" 'comment-dwim)
845 (define-key esc-map "j" 'indent-new-comment-line)
846 (define-key esc-map "\C-j" 'indent-new-comment-line)
847 (define-key ctl-x-map ";" 'comment-set-column)
848 (define-key ctl-x-map "f" 'set-fill-column)
849 (define-key ctl-x-map "$" 'set-selective-display)
850
851 (define-key esc-map "@" 'mark-word)
852 (define-key esc-map "f" 'forward-word)
853 (define-key esc-map "b" 'backward-word)
854 (define-key esc-map "d" 'kill-word)
855 (define-key esc-map "\177" 'backward-kill-word)
856
857 (define-key esc-map "<" 'beginning-of-buffer)
858 (define-key esc-map ">" 'end-of-buffer)
859 (define-key ctl-x-map "h" 'mark-whole-buffer)
860 (define-key esc-map "\\" 'delete-horizontal-space)
861
862 (defalias 'mode-specific-command-prefix (make-sparse-keymap))
863 (defvar mode-specific-map (symbol-function 'mode-specific-command-prefix)
864 "Keymap for characters following C-c.")
865 (define-key global-map "\C-c" 'mode-specific-command-prefix)
866
867 (global-set-key [M-right] 'forward-word)
868 (global-set-key [M-left] 'backward-word)
869 ;; ilya@math.ohio-state.edu says these bindings are standard on PC editors.
870 (global-set-key [C-right] 'forward-word)
871 (global-set-key [C-left] 'backward-word)
872 ;; This is not quite compatible, but at least is analogous
873 (global-set-key [C-delete] 'backward-kill-word)
874 (global-set-key [C-backspace] 'kill-word)
875 ;; This is "move to the clipboard", or as close as we come.
876 (global-set-key [S-delete] 'kill-region)
877
878 (define-key esc-map "\C-f" 'forward-sexp)
879 (define-key esc-map "\C-b" 'backward-sexp)
880 (define-key esc-map "\C-u" 'backward-up-list)
881 (define-key esc-map "\C-@" 'mark-sexp)
882 (define-key esc-map [?\C-\ ] 'mark-sexp)
883 (define-key esc-map "\C-d" 'down-list)
884 (define-key esc-map "\C-k" 'kill-sexp)
885 (define-key global-map [C-M-delete] 'backward-kill-sexp)
886 (define-key global-map [C-M-backspace] 'backward-kill-sexp)
887 (define-key esc-map [C-delete] 'backward-kill-sexp)
888 (define-key esc-map [C-backspace] 'backward-kill-sexp)
889 (define-key esc-map "\C-n" 'forward-list)
890 (define-key esc-map "\C-p" 'backward-list)
891 (define-key esc-map "\C-a" 'beginning-of-defun)
892 (define-key esc-map "\C-e" 'end-of-defun)
893 (define-key esc-map "\C-h" 'mark-defun)
894 (define-key ctl-x-map "nd" 'narrow-to-defun)
895 (define-key esc-map "(" 'insert-parentheses)
896 (define-key esc-map ")" 'move-past-close-and-reindent)
897
898 (define-key ctl-x-map "\C-e" 'eval-last-sexp)
899
900 (define-key ctl-x-map "m" 'compose-mail)
901 (define-key ctl-x-4-map "m" 'compose-mail-other-window)
902 (define-key ctl-x-5-map "m" 'compose-mail-other-frame)
903 \f
904 (define-key ctl-x-map "r\C-@" 'point-to-register)
905 (define-key ctl-x-map [?r ?\C-\ ] 'point-to-register)
906 (define-key ctl-x-map "r " 'point-to-register)
907 (define-key ctl-x-map "rj" 'jump-to-register)
908 (define-key ctl-x-map "rs" 'copy-to-register)
909 (define-key ctl-x-map "rx" 'copy-to-register)
910 (define-key ctl-x-map "ri" 'insert-register)
911 (define-key ctl-x-map "rg" 'insert-register)
912 (define-key ctl-x-map "rr" 'copy-rectangle-to-register)
913 (define-key ctl-x-map "rn" 'number-to-register)
914 (define-key ctl-x-map "r+" 'increment-register)
915 (define-key ctl-x-map "rc" 'clear-rectangle)
916 (define-key ctl-x-map "rk" 'kill-rectangle)
917 (define-key ctl-x-map "rd" 'delete-rectangle)
918 (define-key ctl-x-map "ry" 'yank-rectangle)
919 (define-key ctl-x-map "ro" 'open-rectangle)
920 (define-key ctl-x-map "rt" 'string-rectangle)
921 (define-key ctl-x-map "rw" 'window-configuration-to-register)
922 (define-key ctl-x-map "rf" 'frame-configuration-to-register)
923
924 ;; These key bindings are deprecated; use the above C-x r map instead.
925 ;; We use these aliases so \[...] will show the C-x r bindings instead.
926 (defalias 'point-to-register-compatibility-binding 'point-to-register)
927 (defalias 'jump-to-register-compatibility-binding 'jump-to-register)
928 (defalias 'copy-to-register-compatibility-binding 'copy-to-register)
929 (defalias 'insert-register-compatibility-binding 'insert-register)
930 (define-key ctl-x-map "/" 'point-to-register-compatibility-binding)
931 (define-key ctl-x-map "j" 'jump-to-register-compatibility-binding)
932 (define-key ctl-x-map "x" 'copy-to-register-compatibility-binding)
933 (define-key ctl-x-map "g" 'insert-register-compatibility-binding)
934 ;; (define-key ctl-x-map "r" 'copy-rectangle-to-register)
935
936 (define-key esc-map "q" 'fill-paragraph)
937 ;; (define-key esc-map "g" 'fill-region)
938 (define-key ctl-x-map "." 'set-fill-prefix)
939 \f
940 (define-key esc-map "{" 'backward-paragraph)
941 (define-key esc-map "}" 'forward-paragraph)
942 (define-key esc-map "h" 'mark-paragraph)
943 (define-key esc-map "a" 'backward-sentence)
944 (define-key esc-map "e" 'forward-sentence)
945 (define-key esc-map "k" 'kill-sentence)
946 (define-key ctl-x-map "\177" 'backward-kill-sentence)
947
948 (define-key ctl-x-map "[" 'backward-page)
949 (define-key ctl-x-map "]" 'forward-page)
950 (define-key ctl-x-map "\C-p" 'mark-page)
951 (define-key ctl-x-map "l" 'count-lines-page)
952 (define-key ctl-x-map "np" 'narrow-to-page)
953 ;; (define-key ctl-x-map "p" 'narrow-to-page)
954 \f
955 (define-key ctl-x-map "al" 'add-mode-abbrev)
956 (define-key ctl-x-map "a\C-a" 'add-mode-abbrev)
957 (define-key ctl-x-map "ag" 'add-global-abbrev)
958 (define-key ctl-x-map "a+" 'add-mode-abbrev)
959 (define-key ctl-x-map "aig" 'inverse-add-global-abbrev)
960 (define-key ctl-x-map "ail" 'inverse-add-mode-abbrev)
961 ;; (define-key ctl-x-map "a\C-h" 'inverse-add-global-abbrev)
962 (define-key ctl-x-map "a-" 'inverse-add-global-abbrev)
963 (define-key ctl-x-map "ae" 'expand-abbrev)
964 (define-key ctl-x-map "a'" 'expand-abbrev)
965 ;; (define-key ctl-x-map "\C-a" 'add-mode-abbrev)
966 ;; (define-key ctl-x-map "\+" 'add-global-abbrev)
967 ;; (define-key ctl-x-map "\C-h" 'inverse-add-mode-abbrev)
968 ;; (define-key ctl-x-map "\-" 'inverse-add-global-abbrev)
969 (define-key esc-map "'" 'abbrev-prefix-mark)
970 (define-key ctl-x-map "'" 'expand-abbrev)
971
972 (define-key ctl-x-map "z" 'repeat)
973
974 ;; Don't look for autoload cookies in this file.
975 ;; Local Variables:
976 ;; no-update-autoloads: t
977 ;; End:
978
979 ;;; bindings.el ends here