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