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