lisp/loadup.el (top): Remove bogus `if' choice (brought by 2008-06-21T01:38:39Z!monni...
[bpt/emacs.git] / lisp / bindings.el
CommitLineData
1cd7adc6 1;;; bindings.el --- define standard key bindings and some variables
4d120e8c 2
acaf905b 3;; Copyright (C) 1985-1987, 1992-1996, 1999-2012
e49c0179 4;; Free Software Foundation, Inc.
4d120e8c
RS
5
6;; Maintainer: FSF
7;; Keywords: internal
bd78fa1d 8;; Package: emacs
4d120e8c
RS
9
10;; This file is part of GNU Emacs.
11
eb3fa2cf 12;; GNU Emacs is free software: you can redistribute it and/or modify
4d120e8c 13;; it under the terms of the GNU General Public License as published by
eb3fa2cf
GM
14;; the Free Software Foundation, either version 3 of the License, or
15;; (at your option) any later version.
4d120e8c
RS
16
17;; GNU Emacs is distributed in the hope that it will be useful,
18;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20;; GNU General Public License for more details.
21
22;; You should have received a copy of the GNU General Public License
eb3fa2cf 23;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
4d120e8c
RS
24
25;;; Commentary:
26
4d120e8c
RS
27;;; Code:
28
1ebfdece
GM
29(defun make-mode-line-mouse-map (mouse function) "\
30Return a keymap with single entry for mouse key MOUSE on the mode line.
31MOUSE is defined to run function FUNCTION with no args in the buffer
dfdabcf9
DL
32corresponding to the mode line clicked."
33 (let ((map (make-sparse-keymap)))
1ebfdece 34 (define-key map (vector 'mode-line mouse) function)
dfdabcf9
DL
35 map))
36
e9580d71
GM
37
38(defun mode-line-toggle-read-only (event)
39 "Like `toggle-read-only', for the mode-line."
40 (interactive "e")
41 (save-selected-window
42 (select-window (posn-window (event-start event)))
b68b3337 43 (toggle-read-only nil t)
e9580d71
GM
44 (force-mode-line-update)))
45
e9580d71
GM
46(defun mode-line-toggle-modified (event)
47 "Toggle the buffer-modified flag from the mode-line."
24127af0 48 (interactive "e")
e9580d71
GM
49 (save-selected-window
50 (select-window (posn-window (event-start event)))
51 (set-buffer-modified-p (not (buffer-modified-p)))
52 (force-mode-line-update)))
53
e9580d71
GM
54(defun mode-line-widen (event)
55 "Widen a buffer from the mode-line."
24127af0 56 (interactive "e")
e9580d71
GM
57 (save-selected-window
58 (select-window (posn-window (event-start event)))
59 (widen)
60 (force-mode-line-update)))
61
5e1cddda
DL
62(defvar mode-line-input-method-map
63 (let ((map (make-sparse-keymap)))
64 (define-key map [mode-line mouse-2]
65 (lambda (e)
66 (interactive "e")
67 (save-selected-window
68 (select-window
69 (posn-window (event-start e)))
70 (toggle-input-method)
71 (force-mode-line-update))))
72 (define-key map [mode-line mouse-3]
73 (lambda (e)
74 (interactive "e")
75 (save-selected-window
76 (select-window
77 (posn-window (event-start e)))
78 (describe-current-input-method))))
79 (purecopy map)))
80
f3185924
GM
81(defvar mode-line-coding-system-map
82 (let ((map (make-sparse-keymap)))
da16962a 83 (define-key map [mode-line mouse-1]
f3185924
GM
84 (lambda (e)
85 (interactive "e")
86 (save-selected-window
87 (select-window (posn-window (event-start e)))
88 (when (and enable-multibyte-characters
89 buffer-file-coding-system)
90 (describe-coding-system buffer-file-coding-system)))))
cbe46e5f
CY
91 (define-key map [mode-line mouse-3]
92 (lambda (e)
93 (interactive "e")
94 (save-selected-window
95 (select-window (posn-window (event-start e)))
96 (call-interactively 'set-buffer-file-coding-system))))
f3185924
GM
97 (purecopy map))
98 "Local keymap for the coding-system part of the mode line.")
99
6b61353c 100(defun mode-line-change-eol (event)
18a9f968 101 "Cycle through the various possible kinds of end-of-line styles."
6b61353c 102 (interactive "e")
0ec08b38 103 (with-selected-window (posn-window (event-start event))
6b61353c
KH
104 (let ((eol (coding-system-eol-type buffer-file-coding-system)))
105 (set-buffer-file-coding-system
106 (cond ((eq eol 0) 'dos) ((eq eol 1) 'mac) (t 'unix))))))
18a9f968
SM
107
108(defvar mode-line-eol-desc-cache nil)
109
110(defun mode-line-eol-desc ()
111 (let* ((eol (coding-system-eol-type buffer-file-coding-system))
112 (mnemonic (coding-system-eol-type-mnemonic buffer-file-coding-system))
1aa956a1 113 (desc (assoc eol mode-line-eol-desc-cache)))
18a9f968
SM
114 (if (and desc (eq (cadr desc) mnemonic))
115 (cddr desc)
116 (if desc (setq mode-line-eol-desc-cache nil)) ;Flush the cache if stale.
117 (setq desc
118 (propertize
119 mnemonic
383f7350 120 'help-echo (format "End-of-line style: %s\nmouse-1: Cycle"
18a9f968 121 (if (eq eol 0) "Unix-style LF"
44d15ae0 122 (if (eq eol 1) "DOS-style CRLF"
18a9f968
SM
123 (if (eq eol 2) "Mac-style CR"
124 "Undecided"))))
125 'keymap
126 (eval-when-compile
127 (let ((map (make-sparse-keymap)))
da16962a 128 (define-key map [mode-line mouse-1] 'mode-line-change-eol)
359e4563
MY
129 map))
130 'mouse-face 'mode-line-highlight))
18a9f968
SM
131 (push (cons eol (cons mnemonic desc)) mode-line-eol-desc-cache)
132 desc)))
133
5f2c76c6
CY
134\f
135;;; Mode line contents
136
137(defcustom mode-line-default-help-echo
138 "mouse-1: Select (drag to resize)\n\
139mouse-2: Make current window occupy the whole frame\n\
140mouse-3: Remove current window from display"
141 "Default help text for the mode line.
142If the value is a string, it specifies the tooltip or echo area
143message to display when the mouse is moved over the mode line.
144If the text at the mouse position has a `help-echo' text
145property, that overrides this variable."
146 :type '(choice (const :tag "No help" :value nil) string)
147 :version "24.2"
148 :group 'mode-line)
149
150(defvar mode-line-front-space '(:eval (if (display-graphic-p) " " "-"))
151 "Mode line construct to put at the front of the mode line.
152By default, this construct is displayed right at the beginning of
153the mode line, except that if there is a memory-full message, it
154is displayed first.")
155(put 'mode-line-front-space 'risky-local-variable t)
27d8b4bf 156
383f7350
CY
157(defun mode-line-mule-info-help-echo (window _object _point)
158 "Return help text specifying WINDOW's buffer coding system."
159 (with-current-buffer (window-buffer window)
160 (if buffer-file-coding-system
161 (format "Buffer coding system (%s): %s
cbe46e5f
CY
162mouse-1: Describe coding system
163mouse-3: Set coding system"
383f7350
CY
164 (if enable-multibyte-characters "multi-byte" "unibyte")
165 (symbol-name buffer-file-coding-system))
166 "Buffer coding system: none specified")))
167
dfdabcf9
DL
168(defvar mode-line-mule-info
169 `(""
9ff33afb 170 (current-input-method
27451bb4
RS
171 (:propertize ("" current-input-method-title)
172 help-echo (concat
6bdad9ae 173 ,(purecopy "Current input method: ")
27451bb4 174 current-input-method
6bdad9ae 175 ,(purecopy "\n\
f46b8f6d 176mouse-2: Disable input method\n\
6bdad9ae 177mouse-3: Describe current input method"))
359e4563
MY
178 local-map ,mode-line-input-method-map
179 mouse-face mode-line-highlight))
3beb81fc 180 ,(propertize
18a9f968 181 "%z"
383f7350 182 'help-echo 'mode-line-mule-info-help-echo
359e4563 183 'mouse-face 'mode-line-highlight
18a9f968
SM
184 'local-map mode-line-coding-system-map)
185 (:eval (mode-line-eol-desc)))
383f7350 186 "Mode line construct to report the multilingual environment.
44c034c1
KH
187Normally it displays current input method (if any activated) and
188mnemonics of the following coding systems:
189 coding system for saving or writing the current buffer
383f7350
CY
190 coding system for keyboard input (on a text terminal)
191 coding system for terminal output (on a text terminal)")
ac549fa5 192;;;###autoload
6dc3311d 193(put 'mode-line-mule-info 'risky-local-variable t)
f8bce5df
KH
194(make-variable-buffer-local 'mode-line-mule-info)
195
5f2c76c6
CY
196(defvar mode-line-client
197 `(""
198 (:propertize ("" (:eval (if (frame-parameter nil 'client) "@" "")))
199 help-echo ,(purecopy "emacsclient frame")))
200 "Mode line construct for identifying emacsclient frames.")
ac549fa5 201;;;###autoload
5f2c76c6 202(put 'mode-line-client 'risky-local-variable t)
4d120e8c 203
383f7350
CY
204(defun mode-line-read-only-help-echo (window _object _point)
205 "Return help text specifying WINDOW's buffer read-only status."
206 (format "Buffer is %s\nmouse-1: Toggle"
207 (if (buffer-local-value 'buffer-read-only (window-buffer window))
208 "read-only"
209 "writable")))
210
211(defun mode-line-modified-help-echo (window _object _point)
212 "Return help text specifying WINDOW's buffer modification status."
213 (format "Buffer is %smodified\nmouse-1: Toggle modification state"
214 (if (buffer-modified-p (window-buffer window)) "" "not ")))
215
dfdabcf9
DL
216(defvar mode-line-modified
217 (list (propertize
3beb81fc 218 "%1*"
383f7350 219 'help-echo 'mode-line-read-only-help-echo
1ebfdece 220 'local-map (purecopy (make-mode-line-mouse-map
da16962a 221 'mouse-1
359e4563
MY
222 #'mode-line-toggle-read-only))
223 'mouse-face 'mode-line-highlight)
3beb81fc
DL
224 (propertize
225 "%1+"
383f7350 226 'help-echo 'mode-line-modified-help-echo
1ebfdece 227 'local-map (purecopy (make-mode-line-mouse-map
da16962a 228 'mouse-1 #'mode-line-toggle-modified))
359e4563 229 'mouse-face 'mode-line-highlight))
5f2c76c6 230 "Mode line construct for displaying whether current buffer is modified.")
ac549fa5 231;;;###autoload
6dc3311d 232(put 'mode-line-modified 'risky-local-variable t)
4d120e8c
RS
233(make-variable-buffer-local 'mode-line-modified)
234
4c43ca07
NR
235(defvar mode-line-remote
236 (list (propertize
2c5b4e79 237 "%1@"
38805987 238 'mouse-face 'mode-line-highlight
06b60517 239 'help-echo (purecopy (lambda (window _object _point)
4c43ca07
NR
240 (format "%s"
241 (save-selected-window
242 (select-window window)
2826687d 243 (concat
38805987
DN
244 (if (file-remote-p default-directory)
245 "Current directory is remote: "
246 "Current directory is local: ")
247 default-directory)))))))
5f2c76c6 248 "Mode line construct to indicate a remote buffer.")
ac549fa5 249;;;###autoload
6dc3311d 250(put 'mode-line-remote 'risky-local-variable t)
4c43ca07
NR
251(make-variable-buffer-local 'mode-line-remote)
252
5f2c76c6
CY
253;; MSDOS frames have window-system, but want the Fn identification.
254(defun mode-line-frame-control ()
255 "Compute mode line construct for frame identification.
256Value is used for `mode-line-frame-identification', which see."
257 (if (or (null window-system)
258 (eq window-system 'pc))
259 "-%F "
260 " "))
261
262;; We need to defer the call to mode-line-frame-control to the time
263;; the mode line is actually displayed.
264(defvar mode-line-frame-identification '(:eval (mode-line-frame-control))
265 "Mode line construct to describe the current frame.")
ac549fa5 266;;;###autoload
5f2c76c6 267(put 'mode-line-frame-identification 'risky-local-variable t)
e6188964 268
5f2c76c6
CY
269(defvar mode-line-process nil
270 "Mode line construct for displaying info on process status.
271Normally nil in most modes, since there is no process to display.")
ac549fa5 272;;;###autoload
5f2c76c6
CY
273(put 'mode-line-process 'risky-local-variable t)
274(make-variable-buffer-local 'mode-line-process)
e6188964 275
1ec4b7b2
SM
276(defun bindings--define-key (map key item)
277 "Make as much as possible of the menus pure."
278 (declare (indent 2))
279 (define-key map key
280 (cond
281 ((not (consp item)) item) ;Not sure that could be other than a symbol.
282 ;; Keymaps can't be made pure otherwise users can't remove/add elements
283 ;; from/to them any more.
284 ((keymapp item) item)
285 ((stringp (car item))
286 (if (keymapp (cdr item))
287 (cons (purecopy (car item)) (cdr item))
288 (purecopy item)))
289 ((eq 'menu-item (car item))
290 (if (keymapp (nth 2 item))
291 `(menu-item ,(purecopy (nth 1 item)) ,(nth 2 item)
292 ,@(purecopy (nthcdr 3 item)))
293 (purecopy item)))
294 (t (message "non-menu-item: %S" item) item))))
295
03b63ba9
SM
296(defvar mode-line-mode-menu (make-sparse-keymap "Minor Modes") "\
297Menu of mode operations in the mode line.")
298
6b61353c 299(defvar mode-line-major-mode-keymap
335028c3 300 (let ((map (make-sparse-keymap)))
1ec4b7b2
SM
301 (bindings--define-key map [mode-line down-mouse-1]
302 `(menu-item "Menu Bar" ignore
303 :filter ,(lambda (_) (mouse-menu-major-mode-map))))
335028c3 304 (define-key map [mode-line mouse-2] 'describe-mode)
03b63ba9 305 (define-key map [mode-line down-mouse-3] mode-line-mode-menu)
335028c3 306 map) "\
8a42b336
JB
307Keymap to display on major mode.")
308
6b61353c 309(defvar mode-line-minor-mode-keymap
335028c3 310 (let ((map (make-sparse-keymap)))
fe1afc9b 311 (define-key map [mode-line down-mouse-1] 'mouse-minor-mode-menu)
335028c3 312 (define-key map [mode-line mouse-2] 'mode-line-minor-mode-help)
03b63ba9
SM
313 (define-key map [mode-line down-mouse-3] mode-line-mode-menu)
314 (define-key map [header-line down-mouse-3] mode-line-mode-menu)
335028c3 315 map) "\
8a42b336
JB
316Keymap to display on minor modes.")
317
5f2c76c6
CY
318(defvar mode-line-modes
319 (let ((recursive-edit-help-echo "Recursive edit, type C-M-c to get out"))
320 (list (propertize "%[" 'help-echo recursive-edit-help-echo)
321 "("
322 `(:propertize ("" mode-name)
323 help-echo "Major mode\n\
324mouse-1: Display major mode menu\n\
325mouse-2: Show help for major mode\n\
326mouse-3: Toggle minor modes"
327 mouse-face mode-line-highlight
328 local-map ,mode-line-major-mode-keymap)
329 '("" mode-line-process)
330 `(:propertize ("" minor-mode-alist)
331 mouse-face mode-line-highlight
332 help-echo "Minor mode\n\
333mouse-1: Display minor mode menu\n\
334mouse-2: Show help for minor mode\n\
335mouse-3: Toggle minor modes"
336 local-map ,mode-line-minor-mode-keymap)
383f7350 337 (propertize "%n" 'help-echo "mouse-2: Remove narrowing from buffer"
5f2c76c6
CY
338 'mouse-face 'mode-line-highlight
339 'local-map (make-mode-line-mouse-map
340 'mouse-2 #'mode-line-widen))
341 ")"
342 (propertize "%]" 'help-echo recursive-edit-help-echo)
343 " "))
344 "Mode line construct for displaying major and minor modes.")
345(put 'mode-line-modes 'risky-local-variable t)
346
10a55ba0
DN
347(defvar mode-line-column-line-number-mode-map
348 (let ((map (make-sparse-keymap))
349 (menu-map (make-sparse-keymap "Toggle Line and Column Number Display")))
1ec4b7b2
SM
350 (bindings--define-key menu-map [line-number-mode]
351 '(menu-item "Display Line Numbers" line-number-mode
352 :help "Toggle displaying line numbers in the mode-line"
10a55ba0 353 :button (:toggle . line-number-mode)))
1ec4b7b2
SM
354 (bindings--define-key menu-map [column-number-mode]
355 '(menu-item "Display Column Numbers" column-number-mode
356 :help "Toggle displaying column numbers in the mode-line"
10a55ba0
DN
357 :button (:toggle . column-number-mode)))
358 (define-key map [mode-line down-mouse-1] menu-map)
359 map) "\
360Keymap to display on column and line numbers.")
361
5f2c76c6
CY
362(defvar mode-line-position
363 `((-3 ,(propertize
364 "%p"
365 'local-map mode-line-column-line-number-mode-map
366 'mouse-face 'mode-line-highlight
367 ;; XXX needs better description
368 'help-echo "Size indication mode\n\
10a55ba0 369mouse-1: Display Line and Column Mode Menu"))
5f2c76c6
CY
370 (size-indication-mode
371 (8 ,(propertize
372 " of %I"
373 'local-map mode-line-column-line-number-mode-map
374 'mouse-face 'mode-line-highlight
375 ;; XXX needs better description
376 'help-echo "Size indication mode\n\
10a55ba0 377mouse-1: Display Line and Column Mode Menu")))
5f2c76c6
CY
378 (line-number-mode
379 ((column-number-mode
380 (10 ,(propertize
381 " (%l,%c)"
382 'local-map mode-line-column-line-number-mode-map
383 'mouse-face 'mode-line-highlight
384 'help-echo "Line number and Column number\n\
10a55ba0 385mouse-1: Display Line and Column Mode Menu"))
5f2c76c6
CY
386 (6 ,(propertize
387 " L%l"
388 'local-map mode-line-column-line-number-mode-map
389 'mouse-face 'mode-line-highlight
390 'help-echo "Line Number\n\
10a55ba0 391mouse-1: Display Line and Column Mode Menu"))))
5f2c76c6
CY
392 ((column-number-mode
393 (5 ,(propertize
394 " C%c"
395 'local-map mode-line-column-line-number-mode-map
396 'mouse-face 'mode-line-highlight
397 'help-echo "Column number\n\
398mouse-1: Display Line and Column Mode Menu"))))))
399 "Mode line construct for displaying the position in the buffer.
400Normally displays the buffer percentage and, optionally, the
401buffer size, the line number and the column number.")
402(put 'mode-line-position 'risky-local-variable t)
4d120e8c 403
a8b7149d
SM
404(defvar mode-line-buffer-identification-keymap
405 ;; Add menu of buffer operations to the buffer identification part
406 ;; of the mode line.or header line.
407 (let ((map (make-sparse-keymap)))
408 ;; Bind down- events so that the global keymap won't ``shine
409 ;; through''.
410 (define-key map [mode-line mouse-1] 'mode-line-previous-buffer)
411 (define-key map [header-line down-mouse-1] 'ignore)
412 (define-key map [header-line mouse-1] 'mode-line-previous-buffer)
a8b7149d
SM
413 (define-key map [mode-line mouse-3] 'mode-line-next-buffer)
414 (define-key map [header-line down-mouse-3] 'ignore)
415 (define-key map [header-line mouse-3] 'mode-line-next-buffer)
416 map) "\
688953b5 417Keymap for what is displayed by `mode-line-buffer-identification'.")
b1dcba7b 418
3bd80f8b
RS
419(defun propertized-buffer-identification (fmt)
420 "Return a list suitable for `mode-line-buffer-identification'.
421FMT is a format specifier such as \"%12b\". This function adds
422text properties for face, help-echo, and local-map to it."
e0fcce78 423 (list (propertize fmt
3bd80f8b
RS
424 'face 'mode-line-buffer-id
425 'help-echo
383f7350
CY
426 (purecopy "Buffer name
427mouse-1: Previous buffer\nmouse-3: Next buffer")
3bd80f8b
RS
428 'mouse-face 'mode-line-highlight
429 'local-map mode-line-buffer-identification-keymap)))
430
5f2c76c6
CY
431(defvar mode-line-buffer-identification
432 (propertized-buffer-identification "%12b")
433 "Mode line construct for identifying the buffer being displayed.
3bd80f8b
RS
434Its default value is (\"%12b\") with some text properties added.
435Major modes that edit things other than ordinary files may change this
436\(e.g. Info, Dired,...)")
ac549fa5 437;;;###autoload
6dc3311d 438(put 'mode-line-buffer-identification 'risky-local-variable t)
3bd80f8b
RS
439(make-variable-buffer-local 'mode-line-buffer-identification)
440
5f2c76c6
CY
441(defvar mode-line-misc-info
442 '((which-func-mode ("" which-func-format " "))
443 (global-mode-string ("" global-mode-string " ")))
444 "Mode line construct for miscellaneous information.
445By default, this shows the information specified by
446`which-func-mode' and `global-mode-string'.")
447(put 'mode-line-misc-info 'risky-local-variable t)
448
449(defvar mode-line-end-spaces '(:eval (unless (display-graphic-p) "-%-"))
450 "Mode line construct to put at the end of the mode line.")
451(put 'mode-line-end-spaces 'risky-local-variable t)
452
453;; Default value of the top-level `mode-line-format' variable:
454(let ((standard-mode-line-format
455 (list "%e"
456 'mode-line-front-space
457 'mode-line-mule-info
458 'mode-line-client
459 'mode-line-modified
460 'mode-line-remote
461 'mode-line-frame-identification
462 'mode-line-buffer-identification
463 " "
464 'mode-line-position
465 '(vc-mode vc-mode)
466 " "
467 'mode-line-modes
468 'mode-line-misc-info
469 'mode-line-end-spaces)))
470 (setq-default mode-line-format standard-mode-line-format)
471 (put 'mode-line-format 'standard-value
472 (list `(quote ,standard-mode-line-format))))
473
474\f
22b50772 475(defun mode-line-unbury-buffer (event) "\
545f7310 476Call `unbury-buffer' in this window."
22b50772
GM
477 (interactive "e")
478 (save-selected-window
479 (select-window (posn-window (event-start event)))
545f7310 480 (unbury-buffer)))
22b50772
GM
481
482(defun mode-line-bury-buffer (event) "\
c85ee897 483Like `bury-buffer', but temporarily select EVENT's window."
22b50772
GM
484 (interactive "e")
485 (save-selected-window
486 (select-window (posn-window (event-start event)))
487 (bury-buffer)))
b1dcba7b 488
688953b5
DL
489(defun mode-line-other-buffer () "\
490Switch to the most recently selected buffer other than the current one."
b1dcba7b 491 (interactive)
8bdfa064 492 (switch-to-buffer (other-buffer) nil t))
b1dcba7b 493
4ec983f1
JL
494(defun mode-line-next-buffer (event)
495 "Like `next-buffer', but temporarily select EVENT's window."
496 (interactive "e")
497 (save-selected-window
498 (select-window (posn-window (event-start event)))
499 (next-buffer)))
500
501(defun mode-line-previous-buffer (event)
502 "Like `previous-buffer', but temporarily select EVENT's window."
503 (interactive "e")
504 (save-selected-window
505 (select-window (posn-window (event-start event)))
506 (previous-buffer)))
507
842d2ee9
DL
508(defmacro bound-and-true-p (var)
509 "Return the value of symbol VAR if it is bound, else nil."
ff69e012 510 `(and (boundp (quote ,var)) ,var))
842d2ee9 511
5400586c
NR
512;; Use mode-line-mode-menu for local minor-modes only.
513;; Global ones can go on the menubar (Options --> Show/Hide).
1ec4b7b2
SM
514(bindings--define-key mode-line-mode-menu [overwrite-mode]
515 '(menu-item "Overwrite (Ovwrt)" overwrite-mode
516 :help "Overwrite mode: typed characters replace existing text"
dfdabcf9 517 :button (:toggle . overwrite-mode)))
1ec4b7b2
SM
518(bindings--define-key mode-line-mode-menu [outline-minor-mode]
519 '(menu-item "Outline (Outl)" outline-minor-mode
40fabc71 520 ;; XXX: This needs a good, brief description.
1ec4b7b2 521 :help ""
2a5405b6 522 :button (:toggle . (bound-and-true-p outline-minor-mode))))
1ec4b7b2
SM
523(bindings--define-key mode-line-mode-menu [highlight-changes-mode]
524 '(menu-item "Highlight changes (Chg)" highlight-changes-mode
525 :help "Show changes in the buffer in a distinctive color"
6455508d 526 :button (:toggle . (bound-and-true-p highlight-changes-mode))))
1ec4b7b2
SM
527(bindings--define-key mode-line-mode-menu [hide-ifdef-mode]
528 '(menu-item "Hide ifdef (Ifdef)" hide-ifdef-mode
529 :help "Show/Hide code within #ifdef constructs"
2a5405b6 530 :button (:toggle . (bound-and-true-p hide-ifdef-mode))))
1ec4b7b2
SM
531(bindings--define-key mode-line-mode-menu [glasses-mode]
532 '(menu-item "Glasses (o^o)" glasses-mode
533 :help "Insert virtual separators to make long identifiers easy to read"
c29a05c8 534 :button (:toggle . (bound-and-true-p glasses-mode))))
1ec4b7b2
SM
535(bindings--define-key mode-line-mode-menu [font-lock-mode]
536 '(menu-item "Font Lock" font-lock-mode
537 :help "Syntax coloring"
2a5405b6 538 :button (:toggle . font-lock-mode)))
1ec4b7b2
SM
539(bindings--define-key mode-line-mode-menu [flyspell-mode]
540 '(menu-item "Flyspell (Fly)" flyspell-mode
541 :help "Spell checking on the fly"
2a5405b6 542 :button (:toggle . (bound-and-true-p flyspell-mode))))
1ec4b7b2
SM
543(bindings--define-key mode-line-mode-menu [auto-revert-tail-mode]
544 '(menu-item "Auto revert tail (Tail)" auto-revert-tail-mode
545 :help "Revert the tail of the buffer when buffer grows"
9f37aef4 546 :enable (buffer-file-name)
6455508d 547 :button (:toggle . (bound-and-true-p auto-revert-tail-mode))))
1ec4b7b2
SM
548(bindings--define-key mode-line-mode-menu [auto-revert-mode]
549 '(menu-item "Auto revert (ARev)" auto-revert-mode
550 :help "Revert the buffer when the file on disk changes"
6455508d 551 :button (:toggle . (bound-and-true-p auto-revert-mode))))
1ec4b7b2
SM
552(bindings--define-key mode-line-mode-menu [auto-fill-mode]
553 '(menu-item "Auto fill (Fill)" auto-fill-mode
554 :help "Automatically insert new lines"
c29a05c8 555 :button (:toggle . auto-fill-function)))
1ec4b7b2
SM
556(bindings--define-key mode-line-mode-menu [abbrev-mode]
557 '(menu-item "Abbrev (Abbrev)" abbrev-mode
558 :help "Automatically expand abbreviations"
2a5405b6 559 :button (:toggle . abbrev-mode)))
dfdabcf9 560
8a42b336 561(defun mode-line-minor-mode-help (event)
fe1afc9b 562 "Describe minor mode for EVENT on minor modes area of the mode line."
8a42b336
JB
563 (interactive "@e")
564 (let ((indicator (car (nth 4 (car (cdr event))))))
565 (describe-minor-mode-from-indicator indicator)))
566
541b8aff
GM
567(defvar minor-mode-alist nil "\
568Alist saying how to show minor modes in the mode line.
569Each element looks like (VARIABLE STRING);
4837b516 570STRING is included in the mode line if VARIABLE's value is non-nil.
541b8aff 571
5f2c76c6
CY
572Actually, STRING need not be a string; any mode-line construct is
573okay. See `mode-line-format'.")
ac549fa5 574;;;###autoload
6dc3311d 575(put 'minor-mode-alist 'risky-local-variable t)
541b8aff
GM
576;; Don't use purecopy here--some people want to change these strings.
577(setq minor-mode-alist
0b2b62ff
SM
578 '((abbrev-mode " Abbrev")
579 (overwrite-mode overwrite-mode)
580 (auto-fill-function " Fill")
581 ;; not really a minor mode...
582 (defining-kbd-macro " Def")))
541b8aff 583
4d120e8c
RS
584;; These variables are used by autoloadable packages.
585;; They are defined here so that they do not get overridden
586;; by the loading of those packages.
587
588;; Names in directory that end in one of these
589;; are ignored in completion,
590;; making it more likely you will get a unique match.
591(setq completion-ignored-extensions
d34c1b05 592 (append
a12ca054 593 (cond ((memq system-type '(ms-dos windows-nt))
a7610c52 594 (mapcar 'purecopy
a12ca054 595 '(".o" "~" ".bin" ".bak" ".obj" ".map" ".ico" ".pif" ".lnk"
a7610c52 596 ".a" ".ln" ".blg" ".bbl" ".dll" ".drv" ".vxd" ".386")))
d34c1b05 597 (t
a7610c52 598 (mapcar 'purecopy
a12ca054 599 '(".o" "~" ".bin" ".lbin" ".so"
a7610c52
DN
600 ".a" ".ln" ".blg" ".bbl"))))
601 (mapcar 'purecopy
d34c1b05
RS
602 '(".elc" ".lof"
603 ".glo" ".idx" ".lot"
bcca751d
JB
604 ;; VCS metadata directories
605 ".svn/" ".hg/" ".git/" ".bzr/" "CVS/" "_darcs/" "_MTN/"
d34c1b05 606 ;; TeX-related
640602f7 607 ".fmt" ".tfm"
c79e04d8
RS
608 ;; Java compiled
609 ".class"
7ed93890
SS
610 ;; CLISP
611 ".fas" ".lib" ".mem"
c79e04d8 612 ;; CMUCL
ff69e012 613 ".x86f" ".sparcf"
b6c78ef2
JB
614 ;; OpenMCL / Clozure CL
615 ".dfsl" ".pfsl" ".d64fsl" ".p64fsl" ".lx64fsl" ".lx32fsl"
616 ".dx64fsl" ".dx32fsl" ".fx64fsl" ".fx32fsl" ".sx64fsl"
617 ".sx32fsl" ".wx64fsl" ".wx32fsl"
618 ;; Other CL implementations (Allegro, LispWorks)
619 ".fasl" ".ufsl" ".fsl" ".dxl"
f7e1a28d
GM
620 ;; Libtool
621 ".lo" ".la"
008c915c
RS
622 ;; Gettext
623 ".gmo" ".mo"
d34c1b05 624 ;; Texinfo-related
6b61353c
KH
625 ;; This used to contain .log, but that's commonly used for log
626 ;; files you do want to see, not just TeX stuff. -- fx
627 ".toc" ".aux"
d34c1b05 628 ".cp" ".fn" ".ky" ".pg" ".tp" ".vr"
7c226e40
EZ
629 ".cps" ".fns" ".kys" ".pgs" ".tps" ".vrs"
630 ;; Python byte-compiled
a7610c52 631 ".pyc" ".pyo"))))
4d120e8c 632
ae95a95a
SM
633;; Suffixes used for executables.
634(setq exec-suffixes
635 (cond
636 ((memq system-type '(ms-dos windows-nt))
637 '(".exe" ".com" ".bat" ".cmd" ".btm" ""))
638 (t
639 '(""))))
640
2b4b2add
DL
641;; Packages should add to this list appropriately when they are
642;; loaded, rather than listing everything here.
4d120e8c 643(setq debug-ignored-errors
71873e2b
SM
644 ;; FIXME: Maybe beginning-of-line, beginning-of-buffer, end-of-line,
645 ;; end-of-buffer, end-of-file, buffer-read-only, and
646 ;; file-supersession should all be user-errors!
a7610c52 647 `(beginning-of-line beginning-of-buffer end-of-line
4d120e8c 648 end-of-buffer end-of-file buffer-read-only
c79e04d8 649 file-supersession
71873e2b 650 user-error ;; That's the main one!
cd8d6674 651 ))
4d120e8c 652
4d120e8c
RS
653(make-variable-buffer-local 'indent-tabs-mode)
654
dea31bd3
CY
655;; These per-buffer variables are never reset by
656;; `kill-all-local-variables', because they have no default value.
657;; For consistency, we give them the `permanent-local' property, even
658;; though `kill-all-local-variables' does not actually consult it.
659
660(mapcar (lambda (sym) (put sym 'permanent-local t))
661 '(buffer-file-name default-directory buffer-backed-up
662 buffer-saved-size buffer-auto-save-file-name
663 buffer-read-only buffer-undo-list mark-active
664 point-before-scroll buffer-file-truename
665 buffer-file-format buffer-auto-save-file-format
666 buffer-display-count buffer-display-time
667 enable-multibyte-characters))
668
e1b90ef6 669;; We have base64, md5 and sha1 functions built in now.
d1bf2a73
SM
670(provide 'base64)
671(provide 'md5)
e1b90ef6 672(provide 'sha1)
d1bf2a73
SM
673(provide 'overlay '(display syntax-table field))
674(provide 'text-properties '(display syntax-table field point-entered))
acafa9cf 675
0094907b
RS
676(define-key esc-map "\t" 'complete-symbol)
677
67027b49
SM
678(defun complete-symbol (arg)
679 "Perform completion on the text around point.
680The completion method is determined by `completion-at-point-functions'.
681
682With a prefix argument, this command does completion within
683the collection of symbols listed in the index of the manual for the
684language you are using."
685 (interactive "P")
686 (if arg (info-complete-symbol) (completion-at-point)))
687
4d120e8c
RS
688;; Reduce total amount of space we must allocate during this function
689;; that we will not need to keep permanently.
690(garbage-collect)
691\f
3607b64d 692
4d120e8c
RS
693(setq help-event-list '(help f1))
694
97710114
RS
695(make-variable-buffer-local 'minor-mode-overriding-map-alist)
696
d1bf2a73
SM
697;; From frame.c
698(global-set-key [switch-frame] 'handle-switch-frame)
b6cb37ae
SM
699(global-set-key [select-window] 'handle-select-window)
700
701;; FIXME: Do those 3 events really ever reach the global-map ?
702;; It seems that they can't because they're handled via
703;; special-event-map which is used at very low-level. -stef
d1bf2a73
SM
704(global-set-key [delete-frame] 'handle-delete-frame)
705(global-set-key [iconify-frame] 'ignore-event)
706(global-set-key [make-frame-visible] 'ignore-event)
707
708
4d120e8c
RS
709;These commands are defined in editfns.c
710;but they are not assigned to keys there.
711(put 'narrow-to-region 'disabled t)
d455ee85 712
db5dce9d
EZ
713;; Moving with arrows in bidi-sensitive direction.
714(defun right-char (&optional n)
715 "Move point N characters to the right (to the left if N is negative).
716On reaching beginning or end of buffer, stop and signal error.
717
718Depending on the bidirectional context, this may move either forward
719or backward in the buffer. This is in contrast with \\[forward-char]
720and \\[backward-char], which see."
721 (interactive "^p")
722 (if (eq (current-bidi-paragraph-direction) 'left-to-right)
723 (forward-char n)
724 (backward-char n)))
725
726(defun left-char ( &optional n)
727 "Move point N characters to the left (to the right if N is negative).
728On reaching beginning or end of buffer, stop and signal error.
729
730Depending on the bidirectional context, this may move either backward
731or forward in the buffer. This is in contrast with \\[backward-char]
732and \\[forward-char], which see."
733 (interactive "^p")
734 (if (eq (current-bidi-paragraph-direction) 'left-to-right)
735 (backward-char n)
736 (forward-char n)))
737
738(defun right-word (&optional n)
739 "Move point N words to the right (to the left if N is negative).
740
741Depending on the bidirectional context, this may move either forward
742or backward in the buffer. This is in contrast with \\[forward-word]
743and \\[backward-word], which see.
744
745Value is normally t.
746If an edge of the buffer or a field boundary is reached, point is left there
747there and the function returns nil. Field boundaries are not noticed
748if `inhibit-field-text-motion' is non-nil."
749 (interactive "^p")
750 (if (eq (current-bidi-paragraph-direction) 'left-to-right)
751 (forward-word n)
752 (backward-word n)))
753
754(defun left-word (&optional n)
755 "Move point N words to the left (to the right if N is negative).
756
757Depending on the bidirectional context, this may move either backward
758or forward in the buffer. This is in contrast with \\[backward-word]
759and \\[forward-word], which see.
760
761Value is normally t.
762If an edge of the buffer or a field boundary is reached, point is left there
763there and the function returns nil. Field boundaries are not noticed
764if `inhibit-field-text-motion' is non-nil."
765 (interactive "^p")
766 (if (eq (current-bidi-paragraph-direction) 'left-to-right)
767 (backward-word n)
768 (forward-word n)))
769
d455ee85
JL
770(defvar narrow-map (make-sparse-keymap)
771 "Keymap for narrowing commands.")
772(define-key ctl-x-map "n" narrow-map)
773
774(define-key narrow-map "n" 'narrow-to-region)
775(define-key narrow-map "w" 'widen)
4d120e8c 776
ad1cc346
KS
777;; Quitting
778(define-key global-map "\e\e\e" 'keyboard-escape-quit)
779(define-key global-map "\C-g" 'keyboard-quit)
780
d3615887
SM
781;; Used to be in termdev.el: when using several terminals, make C-z
782;; suspend only the relevant terminal.
783(substitute-key-definition 'suspend-emacs 'suspend-frame global-map)
784
4d120e8c
RS
785(define-key global-map "\C-j" 'newline-and-indent)
786(define-key global-map "\C-m" 'newline)
787(define-key global-map "\C-o" 'open-line)
788(define-key esc-map "\C-o" 'split-line)
789(define-key global-map "\C-q" 'quoted-insert)
790(define-key esc-map "^" 'delete-indentation)
791(define-key esc-map "\\" 'delete-horizontal-space)
792(define-key esc-map "m" 'back-to-indentation)
793(define-key ctl-x-map "\C-o" 'delete-blank-lines)
794(define-key esc-map " " 'just-one-space)
795(define-key esc-map "z" 'zap-to-char)
b2b0776e 796(define-key esc-map "=" 'count-words-region)
4d120e8c
RS
797(define-key ctl-x-map "=" 'what-cursor-position)
798(define-key esc-map ":" 'eval-expression)
799;; Define ESC ESC : like ESC : for people who type ESC ESC out of habit.
800(define-key esc-map "\M-:" 'eval-expression)
801;; Changed from C-x ESC so that function keys work following C-x.
802(define-key ctl-x-map "\e\e" 'repeat-complex-command)
803;; New binding analogous to M-:.
804(define-key ctl-x-map "\M-:" 'repeat-complex-command)
8cb95edf
SM
805(define-key ctl-x-map "u" 'undo)
806(put 'undo :advertised-binding [?\C-x ?u])
4d120e8c
RS
807;; Many people are used to typing C-/ on X terminals and getting C-_.
808(define-key global-map [?\C-/] 'undo)
809(define-key global-map "\C-_" 'undo)
ad1cc346
KS
810;; Richard said that we should not use C-x <uppercase letter> and I have
811;; no idea whereas to bind it. Any suggestion welcome. -stef
812;; (define-key ctl-x-map "U" 'undo-only)
813
4d120e8c
RS
814(define-key esc-map "!" 'shell-command)
815(define-key esc-map "|" 'shell-command-on-region)
6f2d8b35 816(define-key esc-map "&" 'async-shell-command)
4d120e8c 817
d455ee85
JL
818(define-key ctl-x-map [right] 'next-buffer)
819(define-key ctl-x-map [C-right] 'next-buffer)
3d10db47 820(define-key global-map [XF86Forward] 'next-buffer)
d455ee85
JL
821(define-key ctl-x-map [left] 'previous-buffer)
822(define-key ctl-x-map [C-left] 'previous-buffer)
3d10db47 823(define-key global-map [XF86Back] 'previous-buffer)
ad1cc346 824
a77dfeb0
SM
825(let ((map minibuffer-local-map))
826 (define-key map "\en" 'next-history-element)
827 (define-key map [next] 'next-history-element)
828 (define-key map [down] 'next-history-element)
3d10db47 829 (define-key map [XF86Forward] 'next-history-element)
a77dfeb0
SM
830 (define-key map "\ep" 'previous-history-element)
831 (define-key map [prior] 'previous-history-element)
832 (define-key map [up] 'previous-history-element)
3d10db47 833 (define-key map [XF86Back] 'previous-history-element)
a77dfeb0 834 (define-key map "\es" 'next-matching-history-element)
b0c24554
SM
835 (define-key map "\er" 'previous-matching-history-element)
836 ;; Override the global binding (which calls indent-relative via
837 ;; indent-for-tab-command). The alignment that indent-relative tries to
838 ;; do doesn't make much sense here since the prompt messes it up.
2d914448 839 (define-key map "\t" 'self-insert-command)
77e0c5b6 840 (define-key map [C-tab] 'file-cache-minibuffer-complete))
4d120e8c
RS
841
842(define-key global-map "\C-u" 'universal-argument)
843(let ((i ?0))
844 (while (<= i ?9)
845 (define-key esc-map (char-to-string i) 'digit-argument)
846 (setq i (1+ i))))
847(define-key esc-map "-" 'negative-argument)
848;; Define control-digits.
849(let ((i ?0))
850 (while (<= i ?9)
851 (define-key global-map (read (format "[?\\C-%c]" i)) 'digit-argument)
852 (setq i (1+ i))))
853(define-key global-map [?\C--] 'negative-argument)
854;; Define control-meta-digits.
855(let ((i ?0))
856 (while (<= i ?9)
857 (define-key esc-map (read (format "[?\\C-%c]" i)) 'digit-argument)
858 (setq i (1+ i))))
859(define-key global-map [?\C-\M--] 'negative-argument)
860
59ee0542 861;; Update tutorial--default-keys if you change these.
b9229673 862(define-key global-map "\177" 'delete-backward-char)
b8a47412 863(define-key global-map "\C-d" 'delete-char)
b9229673 864
4d120e8c
RS
865(define-key global-map "\C-k" 'kill-line)
866(define-key global-map "\C-w" 'kill-region)
867(define-key esc-map "w" 'kill-ring-save)
868(define-key esc-map "\C-w" 'append-next-kill)
869(define-key global-map "\C-y" 'yank)
870(define-key esc-map "y" 'yank-pop)
871
872;; (define-key ctl-x-map "a" 'append-to-buffer)
873
874(define-key global-map "\C-@" 'set-mark-command)
875;; Many people are used to typing C-SPC and getting C-@.
e68e61b5 876(define-key global-map [?\C- ] 'set-mark-command)
27fa387a
CY
877(put 'set-mark-command :advertised-binding [?\C- ])
878
4d120e8c
RS
879(define-key ctl-x-map "\C-x" 'exchange-point-and-mark)
880(define-key ctl-x-map "\C-@" 'pop-global-mark)
e68e61b5 881(define-key ctl-x-map [?\C- ] 'pop-global-mark)
4d120e8c
RS
882
883(define-key global-map "\C-n" 'next-line)
884(define-key global-map "\C-p" 'previous-line)
885(define-key ctl-x-map "\C-n" 'set-goal-column)
d17a638d 886(define-key global-map "\C-a" 'move-beginning-of-line)
c77ddea7 887(define-key global-map "\C-e" 'move-end-of-line)
4d120e8c 888
ad1cc346
KS
889(define-key ctl-x-map "`" 'next-error)
890
56d62ee1
JL
891(defvar goto-map (make-sparse-keymap)
892 "Keymap for navigation commands.")
893(define-key esc-map "g" goto-map)
894
5dd1713e 895(define-key goto-map "c" 'goto-char)
56d62ee1
JL
896(define-key goto-map "g" 'goto-line)
897(define-key goto-map "\M-g" 'goto-line)
898(define-key goto-map "n" 'next-error)
899(define-key goto-map "\M-n" 'next-error)
900(define-key goto-map "p" 'previous-error)
901(define-key goto-map "\M-p" 'previous-error)
902
903(defvar search-map (make-sparse-keymap)
904 "Keymap for search related commands.")
905(define-key esc-map "s" search-map)
906
907(define-key search-map "o" 'occur)
908(define-key search-map "hr" 'highlight-regexp)
909(define-key search-map "hp" 'highlight-phrase)
910(define-key search-map "hl" 'highlight-lines-matching-regexp)
911(define-key search-map "hu" 'unhighlight-regexp)
912(define-key search-map "hf" 'hi-lock-find-patterns)
913(define-key search-map "hw" 'hi-lock-write-interactive-patterns)
ad1cc346 914
4d120e8c
RS
915;;(defun function-key-error ()
916;; (interactive)
1cd7adc6 917;; (error "That function key is not bound to anything"))
4d120e8c
RS
918
919(define-key global-map [menu] 'execute-extended-command)
920(define-key global-map [find] 'search-forward)
921
9d4850e5
GM
922;; Don't do this. We define <delete> in function-key-map instead.
923;(define-key global-map [delete] 'backward-delete-char)
4e4f9651 924
4d120e8c 925;; natural bindings for terminal keycaps --- defined in X keysym order
d391e05c 926(define-key global-map [C-S-backspace] 'kill-whole-line)
f88febbb 927(define-key global-map [home] 'move-beginning-of-line)
1dfca644 928(define-key global-map [C-home] 'beginning-of-buffer)
4d120e8c 929(define-key global-map [M-home] 'beginning-of-buffer-other-window)
480c8cd3 930(define-key esc-map [home] 'beginning-of-buffer-other-window)
db5dce9d 931(define-key global-map [left] 'left-char)
4d120e8c 932(define-key global-map [up] 'previous-line)
db5dce9d 933(define-key global-map [right] 'right-char)
4d120e8c 934(define-key global-map [down] 'next-line)
79ce172a
JL
935(define-key global-map [prior] 'scroll-down-command)
936(define-key global-map [next] 'scroll-up-command)
4d120e8c
RS
937(define-key global-map [C-up] 'backward-paragraph)
938(define-key global-map [C-down] 'forward-paragraph)
939(define-key global-map [C-prior] 'scroll-right)
e980968d 940(put 'scroll-left 'disabled t)
4d120e8c
RS
941(define-key global-map [C-next] 'scroll-left)
942(define-key global-map [M-next] 'scroll-other-window)
480c8cd3 943(define-key esc-map [next] 'scroll-other-window)
4d120e8c 944(define-key global-map [M-prior] 'scroll-other-window-down)
480c8cd3 945(define-key esc-map [prior] 'scroll-other-window-down)
ad1cc346 946(define-key esc-map [?\C-\S-v] 'scroll-other-window-down)
f88febbb 947(define-key global-map [end] 'move-end-of-line)
1dfca644 948(define-key global-map [C-end] 'end-of-buffer)
4d120e8c 949(define-key global-map [M-end] 'end-of-buffer-other-window)
480c8cd3 950(define-key esc-map [end] 'end-of-buffer-other-window)
4d120e8c
RS
951(define-key global-map [begin] 'beginning-of-buffer)
952(define-key global-map [M-begin] 'beginning-of-buffer-other-window)
480c8cd3 953(define-key esc-map [begin] 'beginning-of-buffer-other-window)
4d120e8c
RS
954;; (define-key global-map [select] 'function-key-error)
955;; (define-key global-map [print] 'function-key-error)
956(define-key global-map [execute] 'execute-extended-command)
957(define-key global-map [insert] 'overwrite-mode)
958(define-key global-map [C-insert] 'kill-ring-save)
959(define-key global-map [S-insert] 'yank)
8d79731e
RS
960;; `insertchar' is what term.c produces. Should we change term.c
961;; to produce `insert' instead?
962(define-key global-map [insertchar] 'overwrite-mode)
963(define-key global-map [C-insertchar] 'kill-ring-save)
964(define-key global-map [S-insertchar] 'yank)
4d120e8c
RS
965(define-key global-map [undo] 'undo)
966(define-key global-map [redo] 'repeat-complex-command)
6b61353c
KH
967(define-key global-map [again] 'repeat-complex-command) ; Sun keyboard
968(define-key global-map [open] 'find-file) ; Sun
969;; The following wouldn't work to interrupt running code since C-g is
970;; treated specially in the event loop.
971;; (define-key global-map [stop] 'keyboard-quit) ; Sun
4d120e8c
RS
972;; (define-key global-map [clearline] 'function-key-error)
973(define-key global-map [insertline] 'open-line)
974(define-key global-map [deleteline] 'kill-line)
b8a47412 975(define-key global-map [deletechar] 'delete-forward-char)
4d120e8c
RS
976;; (define-key global-map [backtab] 'function-key-error)
977;; (define-key global-map [f1] 'function-key-error)
978;; (define-key global-map [f2] 'function-key-error)
979;; (define-key global-map [f3] 'function-key-error)
980;; (define-key global-map [f4] 'function-key-error)
981;; (define-key global-map [f5] 'function-key-error)
982;; (define-key global-map [f6] 'function-key-error)
983;; (define-key global-map [f7] 'function-key-error)
984;; (define-key global-map [f8] 'function-key-error)
985;; (define-key global-map [f9] 'function-key-error)
986;; (define-key global-map [f10] 'function-key-error)
987;; (define-key global-map [f11] 'function-key-error)
988;; (define-key global-map [f12] 'function-key-error)
989;; (define-key global-map [f13] 'function-key-error)
990;; (define-key global-map [f14] 'function-key-error)
991;; (define-key global-map [f15] 'function-key-error)
992;; (define-key global-map [f16] 'function-key-error)
993;; (define-key global-map [f17] 'function-key-error)
994;; (define-key global-map [f18] 'function-key-error)
995;; (define-key global-map [f19] 'function-key-error)
996;; (define-key global-map [f20] 'function-key-error)
997;; (define-key global-map [f21] 'function-key-error)
998;; (define-key global-map [f22] 'function-key-error)
999;; (define-key global-map [f23] 'function-key-error)
1000;; (define-key global-map [f24] 'function-key-error)
1001;; (define-key global-map [f25] 'function-key-error)
1002;; (define-key global-map [f26] 'function-key-error)
1003;; (define-key global-map [f27] 'function-key-error)
1004;; (define-key global-map [f28] 'function-key-error)
1005;; (define-key global-map [f29] 'function-key-error)
1006;; (define-key global-map [f30] 'function-key-error)
1007;; (define-key global-map [f31] 'function-key-error)
1008;; (define-key global-map [f32] 'function-key-error)
1009;; (define-key global-map [f33] 'function-key-error)
1010;; (define-key global-map [f34] 'function-key-error)
1011;; (define-key global-map [f35] 'function-key-error)
1012;; (define-key global-map [kp-backtab] 'function-key-error)
1013;; (define-key global-map [kp-space] 'function-key-error)
1014;; (define-key global-map [kp-tab] 'function-key-error)
1015;; (define-key global-map [kp-enter] 'function-key-error)
1016;; (define-key global-map [kp-f1] 'function-key-error)
1017;; (define-key global-map [kp-f2] 'function-key-error)
1018;; (define-key global-map [kp-f3] 'function-key-error)
1019;; (define-key global-map [kp-f4] 'function-key-error)
1020;; (define-key global-map [kp-multiply] 'function-key-error)
1021;; (define-key global-map [kp-add] 'function-key-error)
1022;; (define-key global-map [kp-separator] 'function-key-error)
1023;; (define-key global-map [kp-subtract] 'function-key-error)
1024;; (define-key global-map [kp-decimal] 'function-key-error)
1025;; (define-key global-map [kp-divide] 'function-key-error)
1026;; (define-key global-map [kp-0] 'function-key-error)
1027;; (define-key global-map [kp-1] 'function-key-error)
1028;; (define-key global-map [kp-2] 'function-key-error)
1029;; (define-key global-map [kp-3] 'function-key-error)
1030;; (define-key global-map [kp-4] 'function-key-error)
1031;; (define-key global-map [kp-5] 'recenter)
1032;; (define-key global-map [kp-6] 'function-key-error)
1033;; (define-key global-map [kp-7] 'function-key-error)
1034;; (define-key global-map [kp-8] 'function-key-error)
1035;; (define-key global-map [kp-9] 'function-key-error)
1036;; (define-key global-map [kp-equal] 'function-key-error)
1037
1038;; X11R6 distinguishes these keys from the non-kp keys.
1039;; Make them behave like the non-kp keys unless otherwise bound.
554efd10
SM
1040;; FIXME: rather than list such mappings for every modifier-combination,
1041;; we should come up with a way to do it generically, something like
1042;; (define-key function-key-map [*-kp-home] [*-home])
4d120e8c
RS
1043(define-key function-key-map [kp-home] [home])
1044(define-key function-key-map [kp-left] [left])
1045(define-key function-key-map [kp-up] [up])
1046(define-key function-key-map [kp-right] [right])
1047(define-key function-key-map [kp-down] [down])
1048(define-key function-key-map [kp-prior] [prior])
1049(define-key function-key-map [kp-next] [next])
1050(define-key function-key-map [M-kp-next] [M-next])
1051(define-key function-key-map [kp-end] [end])
1052(define-key function-key-map [kp-begin] [begin])
1053(define-key function-key-map [kp-insert] [insert])
9d4850e5
GM
1054(define-key function-key-map [backspace] [?\C-?])
1055(define-key function-key-map [delete] [?\C-?])
ee5cece0 1056(define-key function-key-map [kp-delete] [?\C-?])
9761cd3a
EZ
1057(define-key function-key-map [S-kp-end] [S-end])
1058(define-key function-key-map [S-kp-down] [S-down])
1059(define-key function-key-map [S-kp-next] [S-next])
1060(define-key function-key-map [S-kp-left] [S-left])
1061(define-key function-key-map [S-kp-right] [S-right])
1062(define-key function-key-map [S-kp-home] [S-home])
1063(define-key function-key-map [S-kp-up] [S-up])
1064(define-key function-key-map [S-kp-prior] [S-prior])
1065(define-key function-key-map [C-S-kp-end] [C-S-end])
1066(define-key function-key-map [C-S-kp-down] [C-S-down])
1067(define-key function-key-map [C-S-kp-next] [C-S-next])
1068(define-key function-key-map [C-S-kp-left] [C-S-left])
1069(define-key function-key-map [C-S-kp-right] [C-S-right])
1070(define-key function-key-map [C-S-kp-home] [C-S-home])
1071(define-key function-key-map [C-S-kp-up] [C-S-up])
1072(define-key function-key-map [C-S-kp-prior] [C-S-prior])
7bc60154
EZ
1073;; Don't bind shifted keypad numeric keys, they reportedly
1074;; interfere with the feature of some keyboards to produce
1075;; numbers when NumLock is off.
1076;(define-key function-key-map [S-kp-1] [S-end])
1077;(define-key function-key-map [S-kp-2] [S-down])
1078;(define-key function-key-map [S-kp-3] [S-next])
1079;(define-key function-key-map [S-kp-4] [S-left])
1080;(define-key function-key-map [S-kp-6] [S-right])
1081;(define-key function-key-map [S-kp-7] [S-home])
1082;(define-key function-key-map [S-kp-8] [S-up])
1083;(define-key function-key-map [S-kp-9] [S-prior])
9761cd3a
EZ
1084(define-key function-key-map [C-S-kp-1] [C-S-end])
1085(define-key function-key-map [C-S-kp-2] [C-S-down])
1086(define-key function-key-map [C-S-kp-3] [C-S-next])
1087(define-key function-key-map [C-S-kp-4] [C-S-left])
1088(define-key function-key-map [C-S-kp-6] [C-S-right])
1089(define-key function-key-map [C-S-kp-7] [C-S-home])
1090(define-key function-key-map [C-S-kp-8] [C-S-up])
1091(define-key function-key-map [C-S-kp-9] [C-S-prior])
4d120e8c 1092
554efd10
SM
1093;; Hitting C-SPC on text terminals, usually sends the ascii code 0 (aka C-@),
1094;; so we can't distinguish those two keys, but usually we consider C-SPC
1095;; (rather than C-@) as the "canonical" binding.
1096(define-key function-key-map [?\C-@] [?\C-\s])
a7e26d8b
SM
1097;; Many keyboards don't have a `backtab' key, so by convention the user
1098;; can use S-tab instead to access that binding.
1099(define-key function-key-map [S-tab] [backtab])
554efd10 1100
4d120e8c
RS
1101(define-key global-map [mouse-movement] 'ignore)
1102
1103(define-key global-map "\C-t" 'transpose-chars)
1104(define-key esc-map "t" 'transpose-words)
1105(define-key esc-map "\C-t" 'transpose-sexps)
1106(define-key ctl-x-map "\C-t" 'transpose-lines)
1107
5589b330 1108(define-key esc-map ";" 'comment-dwim)
fedff3c6
SM
1109(define-key esc-map "j" 'indent-new-comment-line)
1110(define-key esc-map "\C-j" 'indent-new-comment-line)
5589b330 1111(define-key ctl-x-map ";" 'comment-set-column)
4d120e8c
RS
1112(define-key ctl-x-map "f" 'set-fill-column)
1113(define-key ctl-x-map "$" 'set-selective-display)
1114
1115(define-key esc-map "@" 'mark-word)
1116(define-key esc-map "f" 'forward-word)
1117(define-key esc-map "b" 'backward-word)
1118(define-key esc-map "d" 'kill-word)
1119(define-key esc-map "\177" 'backward-kill-word)
1120
1121(define-key esc-map "<" 'beginning-of-buffer)
1122(define-key esc-map ">" 'end-of-buffer)
1123(define-key ctl-x-map "h" 'mark-whole-buffer)
1124(define-key esc-map "\\" 'delete-horizontal-space)
1125
1126(defalias 'mode-specific-command-prefix (make-sparse-keymap))
4b189189 1127(defvar mode-specific-map (symbol-function 'mode-specific-command-prefix)
4d120e8c
RS
1128 "Keymap for characters following C-c.")
1129(define-key global-map "\C-c" 'mode-specific-command-prefix)
1130
c3833279 1131(global-set-key [M-right] 'right-word)
480c8cd3 1132(define-key esc-map [right] 'forward-word)
c3833279 1133(global-set-key [M-left] 'left-word)
480c8cd3 1134(define-key esc-map [left] 'backward-word)
4d120e8c 1135;; ilya@math.ohio-state.edu says these bindings are standard on PC editors.
db5dce9d
EZ
1136(global-set-key [C-right] 'right-word)
1137(global-set-key [C-left] 'left-word)
4d120e8c 1138;; This is not quite compatible, but at least is analogous
7957d2f5
CY
1139(global-set-key [C-delete] 'kill-word)
1140(global-set-key [C-backspace] 'backward-kill-word)
4d120e8c
RS
1141;; This is "move to the clipboard", or as close as we come.
1142(global-set-key [S-delete] 'kill-region)
1143
480c8cd3
AS
1144(global-set-key [C-M-left] 'backward-sexp)
1145(define-key esc-map [C-left] 'backward-sexp)
1146(global-set-key [C-M-right] 'forward-sexp)
1147(define-key esc-map [C-right] 'forward-sexp)
1148(global-set-key [C-M-up] 'backward-up-list)
1149(define-key esc-map [C-up] 'backward-up-list)
1150(global-set-key [C-M-down] 'down-list)
1151(define-key esc-map [C-down] 'down-list)
1152(global-set-key [C-M-home] 'beginning-of-defun)
1153(define-key esc-map [C-home] 'beginning-of-defun)
1154(global-set-key [C-M-end] 'end-of-defun)
1155(define-key esc-map [C-end] 'end-of-defun)
486add9d 1156
4d120e8c
RS
1157(define-key esc-map "\C-f" 'forward-sexp)
1158(define-key esc-map "\C-b" 'backward-sexp)
1159(define-key esc-map "\C-u" 'backward-up-list)
1160(define-key esc-map "\C-@" 'mark-sexp)
1161(define-key esc-map [?\C-\ ] 'mark-sexp)
1162(define-key esc-map "\C-d" 'down-list)
1163(define-key esc-map "\C-k" 'kill-sexp)
0c3a466c
RS
1164;;; These are dangerous in various situations,
1165;;; so let's not encourage anyone to use them.
1166;;;(define-key global-map [C-M-delete] 'backward-kill-sexp)
1167;;;(define-key global-map [C-M-backspace] 'backward-kill-sexp)
da7ddbed
GM
1168(define-key esc-map [C-delete] 'backward-kill-sexp)
1169(define-key esc-map [C-backspace] 'backward-kill-sexp)
4d120e8c
RS
1170(define-key esc-map "\C-n" 'forward-list)
1171(define-key esc-map "\C-p" 'backward-list)
1172(define-key esc-map "\C-a" 'beginning-of-defun)
1173(define-key esc-map "\C-e" 'end-of-defun)
1174(define-key esc-map "\C-h" 'mark-defun)
1175(define-key ctl-x-map "nd" 'narrow-to-defun)
1176(define-key esc-map "(" 'insert-parentheses)
1177(define-key esc-map ")" 'move-past-close-and-reindent)
4d120e8c
RS
1178
1179(define-key ctl-x-map "\C-e" 'eval-last-sexp)
6d64bc9f
RS
1180
1181(define-key ctl-x-map "m" 'compose-mail)
1182(define-key ctl-x-4-map "m" 'compose-mail-other-window)
1183(define-key ctl-x-5-map "m" 'compose-mail-other-frame)
4d120e8c 1184\f
d455ee85
JL
1185
1186(defvar ctl-x-r-map (make-sparse-keymap)
1187 "Keymap for subcommands of C-x r.")
1188(define-key ctl-x-map "r" ctl-x-r-map)
4d120e8c 1189
792eb719 1190(define-key esc-map "q" 'fill-paragraph)
4d120e8c
RS
1191(define-key ctl-x-map "." 'set-fill-prefix)
1192\f
1193(define-key esc-map "{" 'backward-paragraph)
1194(define-key esc-map "}" 'forward-paragraph)
1195(define-key esc-map "h" 'mark-paragraph)
1196(define-key esc-map "a" 'backward-sentence)
1197(define-key esc-map "e" 'forward-sentence)
1198(define-key esc-map "k" 'kill-sentence)
1199(define-key ctl-x-map "\177" 'backward-kill-sentence)
1200
1201(define-key ctl-x-map "[" 'backward-page)
1202(define-key ctl-x-map "]" 'forward-page)
1203(define-key ctl-x-map "\C-p" 'mark-page)
1204(define-key ctl-x-map "l" 'count-lines-page)
1205(define-key ctl-x-map "np" 'narrow-to-page)
1206;; (define-key ctl-x-map "p" 'narrow-to-page)
1207\f
d455ee85
JL
1208(defvar abbrev-map (make-sparse-keymap)
1209 "Keymap for abbrev commands.")
1210(define-key ctl-x-map "a" abbrev-map)
1211
1212(define-key abbrev-map "l" 'add-mode-abbrev)
1213(define-key abbrev-map "\C-a" 'add-mode-abbrev)
1214(define-key abbrev-map "g" 'add-global-abbrev)
1215(define-key abbrev-map "+" 'add-mode-abbrev)
1216(define-key abbrev-map "ig" 'inverse-add-global-abbrev)
1217(define-key abbrev-map "il" 'inverse-add-mode-abbrev)
1218;; (define-key abbrev-map "\C-h" 'inverse-add-global-abbrev)
1219(define-key abbrev-map "-" 'inverse-add-global-abbrev)
1220(define-key abbrev-map "e" 'expand-abbrev)
1221(define-key abbrev-map "'" 'expand-abbrev)
4d120e8c
RS
1222;; (define-key ctl-x-map "\C-a" 'add-mode-abbrev)
1223;; (define-key ctl-x-map "\+" 'add-global-abbrev)
1224;; (define-key ctl-x-map "\C-h" 'inverse-add-mode-abbrev)
1225;; (define-key ctl-x-map "\-" 'inverse-add-global-abbrev)
1226(define-key esc-map "'" 'abbrev-prefix-mark)
1227(define-key ctl-x-map "'" 'expand-abbrev)
3cc99f68 1228(define-key ctl-x-map "\C-b" 'list-buffers)
4d120e8c 1229
aa5ba90e 1230(define-key ctl-x-map "z" 'repeat)
e4ade21b 1231
ef2cfb2e
RS
1232(define-key esc-map "\C-l" 'reposition-window)
1233
1234(define-key ctl-x-4-map "a" 'add-change-log-entry-other-window)
ad1cc346
KS
1235(define-key ctl-x-4-map "c" 'clone-indirect-buffer-other-window)
1236
56c5808a 1237;; Signal handlers
653a9100
KS
1238(define-key special-event-map [sigusr1] 'ignore)
1239(define-key special-event-map [sigusr2] 'ignore)
56c5808a 1240
d1bf2a73
SM
1241;; Don't look for autoload cookies in this file.
1242;; Local Variables:
1243;; no-update-autoloads: t
1244;; End:
4d120e8c
RS
1245
1246;;; bindings.el ends here