Allow 'browse-url-emacs' to fetch URL in the selected window
[emacs.git] / lisp / bindings.el
blob6ef8ffb093358758575ff1dfe01d4cd3db1f5905
1 ;;; bindings.el --- define standard key bindings and some variables
3 ;; Copyright (C) 1985-1987, 1992-1996, 1999-2018 Free Software
4 ;; Foundation, Inc.
6 ;; Maintainer: emacs-devel@gnu.org
7 ;; Keywords: internal
8 ;; Package: emacs
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
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.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
25 ;;; Commentary:
27 ;;; Code:
29 (defun make-mode-line-mouse-map (mouse function) "\
30 Return a keymap with single entry for mouse key MOUSE on the mode line.
31 MOUSE is defined to run function FUNCTION with no args in the buffer
32 corresponding to the mode line clicked."
33 (let ((map (make-sparse-keymap)))
34 (define-key map (vector 'mode-line mouse) function)
35 map))
38 (defun mode-line-toggle-read-only (event)
39 "Like toggling `read-only-mode', for the mode-line."
40 (interactive "e")
41 (with-selected-window (posn-window (event-start event))
42 (read-only-mode 'toggle)))
44 (defun mode-line-toggle-modified (event)
45 "Toggle the buffer-modified flag from the mode-line."
46 (interactive "e")
47 (with-selected-window (posn-window (event-start event))
48 (set-buffer-modified-p (not (buffer-modified-p)))
49 (force-mode-line-update)))
51 (defun mode-line-widen (event)
52 "Widen a buffer from the mode-line."
53 (interactive "e")
54 (with-selected-window (posn-window (event-start event))
55 (widen)
56 (force-mode-line-update)))
58 (defvar mode-line-input-method-map
59 (let ((map (make-sparse-keymap)))
60 (define-key map [mode-line mouse-2]
61 (lambda (e)
62 (interactive "e")
63 (with-selected-window (posn-window (event-start e))
64 (toggle-input-method)
65 (force-mode-line-update))))
66 (define-key map [mode-line mouse-3]
67 (lambda (e)
68 (interactive "e")
69 (with-selected-window (posn-window (event-start e))
70 (describe-current-input-method))))
71 (purecopy map)))
73 (defvar mode-line-coding-system-map
74 (let ((map (make-sparse-keymap)))
75 (define-key map [mode-line mouse-1]
76 (lambda (e)
77 (interactive "e")
78 (with-selected-window (posn-window (event-start e))
79 (when (and enable-multibyte-characters
80 buffer-file-coding-system)
81 (describe-coding-system buffer-file-coding-system)))))
82 (define-key map [mode-line mouse-3]
83 (lambda (e)
84 (interactive "e")
85 (with-selected-window (posn-window (event-start e))
86 (call-interactively 'set-buffer-file-coding-system))))
87 (purecopy map))
88 "Local keymap for the coding-system part of the mode line.")
90 (defun mode-line-change-eol (event)
91 "Cycle through the various possible kinds of end-of-line styles."
92 (interactive "e")
93 (with-selected-window (posn-window (event-start event))
94 (let ((eol (coding-system-eol-type buffer-file-coding-system)))
95 (set-buffer-file-coding-system
96 (cond ((eq eol 0) 'dos) ((eq eol 1) 'mac) (t 'unix))))))
98 (defvar mode-line-eol-desc-cache nil)
100 (defun mode-line-eol-desc ()
101 (let* ((eol (coding-system-eol-type buffer-file-coding-system))
102 (mnemonic (coding-system-eol-type-mnemonic buffer-file-coding-system))
103 (desc (assoc eol mode-line-eol-desc-cache)))
104 (if (and desc (eq (cadr desc) mnemonic))
105 (cddr desc)
106 (if desc (setq mode-line-eol-desc-cache nil)) ;Flush the cache if stale.
107 (setq desc
108 (propertize
109 mnemonic
110 'help-echo (format "End-of-line style: %s\nmouse-1: Cycle"
111 (if (eq eol 0) "Unix-style LF"
112 (if (eq eol 1) "DOS-style CRLF"
113 (if (eq eol 2) "Mac-style CR"
114 "Undecided"))))
115 'keymap
116 (eval-when-compile
117 (let ((map (make-sparse-keymap)))
118 (define-key map [mode-line mouse-1] 'mode-line-change-eol)
119 map))
120 'mouse-face 'mode-line-highlight))
121 (push (cons eol (cons mnemonic desc)) mode-line-eol-desc-cache)
122 desc)))
125 ;;; Mode line contents
127 (defun mode-line-default-help-echo (window)
128 "Return default help echo text for WINDOW's mode line."
129 (let* ((frame (window-frame window))
130 (line-1a
131 ;; Show text to select window only if the window is not
132 ;; selected.
133 (not (eq window (frame-selected-window frame))))
134 (line-1b
135 ;; Show text to drag mode line if either the window is not
136 ;; at the bottom of its frame or the minibuffer window of
137 ;; this frame can be resized. This matches a corresponding
138 ;; check in `mouse-drag-mode-line'.
139 (or (not (window-at-side-p window 'bottom))
140 (let ((mini-window (minibuffer-window frame)))
141 (and (eq frame (window-frame mini-window))
142 (or (minibuffer-window-active-p mini-window)
143 (not resize-mini-windows))))))
144 (line-2
145 ;; Show text make window occupy the whole frame
146 ;; only if it doesn't already do that.
147 (not (eq window (frame-root-window frame))))
148 (line-3
149 ;; Show text to delete window only if that's possible.
150 (not (eq window (frame-root-window frame)))))
151 (when (or line-1a line-1b line-2 line-3)
152 (concat
153 (when (or line-1a line-1b)
154 (concat
155 "mouse-1: "
156 (when line-1a "Select window")
157 (when line-1b
158 (if line-1a " (drag to resize)" "Drag to resize"))
159 (when (or line-2 line-3) "\n")))
160 (when line-2
161 (concat
162 "mouse-2: Make window occupy whole frame"
163 (when line-3 "\n")))
164 (when line-3
165 "mouse-3: Remove window from frame")))))
167 (defcustom mode-line-default-help-echo #'mode-line-default-help-echo
168 "Default help text for the mode line.
169 If the value is a string, it specifies the tooltip or echo area
170 message to display when the mouse is moved over the mode line.
171 If the value is a function, call that function with one argument
172 - the window whose mode line to display. If the text at the
173 mouse position has a `help-echo' text property, that overrides
174 this variable."
175 :type '(choice
176 (const :tag "No help" :value nil)
177 function
178 (string :value "mouse-1: Select (drag to resize)\n\
179 mouse-2: Make current window occupy the whole frame\n\
180 mouse-3: Remove current window from display"))
181 :version "27.1"
182 :group 'mode-line)
184 (defvar mode-line-front-space '(:eval (if (display-graphic-p) " " "-"))
185 "Mode line construct to put at the front of the mode line.
186 By default, this construct is displayed right at the beginning of
187 the mode line, except that if there is a memory-full message, it
188 is displayed first.")
189 (put 'mode-line-front-space 'risky-local-variable t)
191 (defun mode-line-mule-info-help-echo (window _object _point)
192 "Return help text specifying WINDOW's buffer coding system."
193 (with-current-buffer (window-buffer window)
194 (if buffer-file-coding-system
195 (format "Buffer coding system (%s): %s
196 mouse-1: Describe coding system
197 mouse-3: Set coding system"
198 (if enable-multibyte-characters "multi-byte" "unibyte")
199 (symbol-name buffer-file-coding-system))
200 "Buffer coding system: none specified")))
202 (defvar mode-line-mule-info
203 `(""
204 (current-input-method
205 (:propertize ("" current-input-method-title)
206 help-echo (concat
207 ,(purecopy "Current input method: ")
208 current-input-method
209 ,(purecopy "\n\
210 mouse-2: Disable input method\n\
211 mouse-3: Describe current input method"))
212 local-map ,mode-line-input-method-map
213 mouse-face mode-line-highlight))
214 ,(propertize
215 "%z"
216 'help-echo 'mode-line-mule-info-help-echo
217 'mouse-face 'mode-line-highlight
218 'local-map mode-line-coding-system-map)
219 (:eval (mode-line-eol-desc)))
220 "Mode line construct to report the multilingual environment.
221 Normally it displays current input method (if any activated) and
222 mnemonics of the following coding systems:
223 coding system for saving or writing the current buffer
224 coding system for keyboard input (on a text terminal)
225 coding system for terminal output (on a text terminal)")
226 ;;;###autoload
227 (put 'mode-line-mule-info 'risky-local-variable t)
228 (make-variable-buffer-local 'mode-line-mule-info)
230 (defvar mode-line-client
231 `(""
232 (:propertize ("" (:eval (if (frame-parameter nil 'client) "@" "")))
233 help-echo ,(purecopy "emacsclient frame")))
234 "Mode line construct for identifying emacsclient frames.")
235 ;;;###autoload
236 (put 'mode-line-client 'risky-local-variable t)
238 (defun mode-line-read-only-help-echo (window _object _point)
239 "Return help text specifying WINDOW's buffer read-only status."
240 (format "Buffer is %s\nmouse-1: Toggle"
241 (if (buffer-local-value 'buffer-read-only (window-buffer window))
242 "read-only"
243 "writable")))
245 (defun mode-line-modified-help-echo (window _object _point)
246 "Return help text specifying WINDOW's buffer modification status."
247 (format "Buffer is %smodified\nmouse-1: Toggle modification state"
248 (if (buffer-modified-p (window-buffer window)) "" "not ")))
250 (defvar mode-line-modified
251 (list (propertize
252 "%1*"
253 'help-echo 'mode-line-read-only-help-echo
254 'local-map (purecopy (make-mode-line-mouse-map
255 'mouse-1
256 #'mode-line-toggle-read-only))
257 'mouse-face 'mode-line-highlight)
258 (propertize
259 "%1+"
260 'help-echo 'mode-line-modified-help-echo
261 'local-map (purecopy (make-mode-line-mouse-map
262 'mouse-1 #'mode-line-toggle-modified))
263 'mouse-face 'mode-line-highlight))
264 "Mode line construct for displaying whether current buffer is modified.")
265 ;;;###autoload
266 (put 'mode-line-modified 'risky-local-variable t)
267 (make-variable-buffer-local 'mode-line-modified)
269 (defvar mode-line-remote
270 (list (propertize
271 "%1@"
272 'mouse-face 'mode-line-highlight
273 'help-echo (purecopy (lambda (window _object _point)
274 (format "%s"
275 (with-selected-window window
276 (if (stringp default-directory)
277 (concat
278 (if (file-remote-p default-directory)
279 "Current directory is remote: "
280 "Current directory is local: ")
281 default-directory)
282 "Current directory is nil")))))))
283 "Mode line construct to indicate a remote buffer.")
284 ;;;###autoload
285 (put 'mode-line-remote 'risky-local-variable t)
286 (make-variable-buffer-local 'mode-line-remote)
288 ;; MSDOS frames have window-system, but want the Fn identification.
289 (defun mode-line-frame-control ()
290 "Compute mode line construct for frame identification.
291 Value is used for `mode-line-frame-identification', which see."
292 (if (or (null window-system)
293 (eq window-system 'pc))
294 "-%F "
295 " "))
297 ;; We need to defer the call to mode-line-frame-control to the time
298 ;; the mode line is actually displayed.
299 (defvar mode-line-frame-identification '(:eval (mode-line-frame-control))
300 "Mode line construct to describe the current frame.")
301 ;;;###autoload
302 (put 'mode-line-frame-identification 'risky-local-variable t)
304 (defvar mode-line-process nil
305 "Mode line construct for displaying info on process status.
306 Normally nil in most modes, since there is no process to display.")
307 ;;;###autoload
308 (put 'mode-line-process 'risky-local-variable t)
309 (make-variable-buffer-local 'mode-line-process)
311 (defun bindings--define-key (map key item)
312 "Make as much as possible of the menus pure."
313 (declare (indent 2))
314 (define-key map key
315 (cond
316 ((not (consp item)) item) ;Not sure that could be other than a symbol.
317 ;; Keymaps can't be made pure otherwise users can't remove/add elements
318 ;; from/to them any more.
319 ((keymapp item) item)
320 ((stringp (car item))
321 (if (keymapp (cdr item))
322 (cons (purecopy (car item)) (cdr item))
323 (purecopy item)))
324 ((eq 'menu-item (car item))
325 (if (keymapp (nth 2 item))
326 `(menu-item ,(purecopy (nth 1 item)) ,(nth 2 item)
327 ,@(purecopy (nthcdr 3 item)))
328 (purecopy item)))
329 (t (message "non-menu-item: %S" item) item))))
331 (defvar mode-line-mode-menu (make-sparse-keymap "Minor Modes") "\
332 Menu of mode operations in the mode line.")
334 (defvar mode-line-major-mode-keymap
335 (let ((map (make-sparse-keymap)))
336 (bindings--define-key map [mode-line down-mouse-1]
337 `(menu-item "Menu Bar" ignore
338 :filter ,(lambda (_) (mouse-menu-major-mode-map))))
339 (define-key map [mode-line mouse-2] 'describe-mode)
340 (define-key map [mode-line down-mouse-3] mode-line-mode-menu)
341 map) "\
342 Keymap to display on major mode.")
344 (defvar mode-line-minor-mode-keymap
345 (let ((map (make-sparse-keymap)))
346 (define-key map [mode-line down-mouse-1] 'mouse-minor-mode-menu)
347 (define-key map [mode-line mouse-2] 'mode-line-minor-mode-help)
348 (define-key map [mode-line down-mouse-3] mode-line-mode-menu)
349 (define-key map [header-line down-mouse-3] mode-line-mode-menu)
350 map) "\
351 Keymap to display on minor modes.")
353 (defvar mode-line-modes
354 (let ((recursive-edit-help-echo "Recursive edit, type C-M-c to get out"))
355 (list (propertize "%[" 'help-echo recursive-edit-help-echo)
357 `(:propertize ("" mode-name)
358 help-echo "Major mode\n\
359 mouse-1: Display major mode menu\n\
360 mouse-2: Show help for major mode\n\
361 mouse-3: Toggle minor modes"
362 mouse-face mode-line-highlight
363 local-map ,mode-line-major-mode-keymap)
364 '("" mode-line-process)
365 `(:propertize ("" minor-mode-alist)
366 mouse-face mode-line-highlight
367 help-echo "Minor mode\n\
368 mouse-1: Display minor mode menu\n\
369 mouse-2: Show help for minor mode\n\
370 mouse-3: Toggle minor modes"
371 local-map ,mode-line-minor-mode-keymap)
372 (propertize "%n" 'help-echo "mouse-2: Remove narrowing from buffer"
373 'mouse-face 'mode-line-highlight
374 'local-map (make-mode-line-mouse-map
375 'mouse-2 #'mode-line-widen))
377 (propertize "%]" 'help-echo recursive-edit-help-echo)
378 " "))
379 "Mode line construct for displaying major and minor modes.")
380 (put 'mode-line-modes 'risky-local-variable t)
382 (defvar mode-line-column-line-number-mode-map
383 (let ((map (make-sparse-keymap))
384 (menu-map (make-sparse-keymap "Toggle Line and Column Number Display")))
385 (bindings--define-key menu-map [size-indication-mode]
386 '(menu-item "Display Size Indication" size-indication-mode
387 :help "Toggle displaying a size indication in the mode-line"
388 :button (:toggle . size-indication-mode)))
389 (bindings--define-key menu-map [line-number-mode]
390 '(menu-item "Display Line Numbers" line-number-mode
391 :help "Toggle displaying line numbers in the mode-line"
392 :button (:toggle . line-number-mode)))
393 (bindings--define-key menu-map [column-number-mode]
394 '(menu-item "Display Column Numbers" column-number-mode
395 :help "Toggle displaying column numbers in the mode-line"
396 :button (:toggle . column-number-mode)))
397 (define-key map [mode-line down-mouse-1] menu-map)
398 map) "\
399 Keymap to display on column and line numbers.")
401 (defcustom column-number-indicator-zero-based t
402 "When non-nil, mode line displays column numbers zero-based.
404 This variable has effect only when Column Number mode is turned on,
405 which displays column numbers in the mode line.
406 If the value is non-nil, the displayed column numbers start from
407 zero, otherwise they start from one."
408 :type 'boolean
409 :group 'mode-line
410 :version "26.1")
412 (defcustom mode-line-percent-position '(-3 "%p")
413 "Specification of \"percentage offset\" of window through buffer.
414 This option specifies both the field width and the type of offset
415 displayed in `mode-line-position', a component of the default
416 `mode-line-format'."
417 :type `(radio
418 (const :tag "nil: No offset is displayed" nil)
419 (const :tag "\"%o\": Proportion of \"travel\" of the window through the buffer"
420 (-3 "%o"))
421 (const :tag "\"%p\": Percentage offset of top of window"
422 (-3 "%p"))
423 (const :tag "\"%P\": Percentage offset of bottom of window"
424 (-3 "%P"))
425 (const :tag "\"%q\": Offsets of both top and bottom of window"
426 (6 "%q")))
427 :version "26.1"
428 :group 'mode-line)
429 (put 'mode-line-percent-position 'risky-local-variable t)
431 (defvar mode-line-position
432 `((:propertize
433 mode-line-percent-position
434 local-map ,mode-line-column-line-number-mode-map
435 mouse-face mode-line-highlight
436 ;; XXX needs better description
437 help-echo "Size indication mode\n\
438 mouse-1: Display Line and Column Mode Menu")
439 (size-indication-mode
440 (8 ,(propertize
441 " of %I"
442 'local-map mode-line-column-line-number-mode-map
443 'mouse-face 'mode-line-highlight
444 ;; XXX needs better description
445 'help-echo "Size indication mode\n\
446 mouse-1: Display Line and Column Mode Menu")))
447 (line-number-mode
448 ((column-number-mode
449 (column-number-indicator-zero-based
450 (10 ,(propertize
451 " (%l,%c)"
452 'local-map mode-line-column-line-number-mode-map
453 'mouse-face 'mode-line-highlight
454 'help-echo "Line number and Column number\n\
455 mouse-1: Display Line and Column Mode Menu"))
456 (10 ,(propertize
457 " (%l,%C)"
458 'local-map mode-line-column-line-number-mode-map
459 'mouse-face 'mode-line-highlight
460 'help-echo "Line number and Column number\n\
461 mouse-1: Display Line and Column Mode Menu")))
462 (6 ,(propertize
463 " L%l"
464 'local-map mode-line-column-line-number-mode-map
465 'mouse-face 'mode-line-highlight
466 'help-echo "Line Number\n\
467 mouse-1: Display Line and Column Mode Menu"))))
468 ((column-number-mode
469 (column-number-indicator-zero-based
470 (5 ,(propertize
471 " C%c"
472 'local-map mode-line-column-line-number-mode-map
473 'mouse-face 'mode-line-highlight
474 'help-echo "Column number\n\
475 mouse-1: Display Line and Column Mode Menu"))
476 (5 ,(propertize
477 " C%C"
478 'local-map mode-line-column-line-number-mode-map
479 'mouse-face 'mode-line-highlight
480 'help-echo "Column number\n\
481 mouse-1: Display Line and Column Mode Menu")))))))
482 "Mode line construct for displaying the position in the buffer.
483 Normally displays the buffer percentage and, optionally, the
484 buffer size, the line number and the column number.")
485 (put 'mode-line-position 'risky-local-variable t)
487 (defvar mode-line-buffer-identification-keymap
488 ;; Add menu of buffer operations to the buffer identification part
489 ;; of the mode line.or header line.
490 (let ((map (make-sparse-keymap)))
491 ;; Bind down- events so that the global keymap won't ``shine
492 ;; through''.
493 (define-key map [mode-line mouse-1] 'mode-line-previous-buffer)
494 (define-key map [header-line down-mouse-1] 'ignore)
495 (define-key map [header-line mouse-1] 'mode-line-previous-buffer)
496 (define-key map [mode-line mouse-3] 'mode-line-next-buffer)
497 (define-key map [header-line down-mouse-3] 'ignore)
498 (define-key map [header-line mouse-3] 'mode-line-next-buffer)
499 map) "\
500 Keymap for what is displayed by `mode-line-buffer-identification'.")
502 (defun propertized-buffer-identification (fmt)
503 "Return a list suitable for `mode-line-buffer-identification'.
504 FMT is a format specifier such as \"%12b\". This function adds
505 text properties for face, help-echo, and local-map to it."
506 (list (propertize fmt
507 'face 'mode-line-buffer-id
508 'help-echo
509 (purecopy "Buffer name
510 mouse-1: Previous buffer\nmouse-3: Next buffer")
511 'mouse-face 'mode-line-highlight
512 'local-map mode-line-buffer-identification-keymap)))
514 (defvar mode-line-buffer-identification
515 (propertized-buffer-identification "%12b")
516 "Mode line construct for identifying the buffer being displayed.
517 Its default value is (\"%12b\") with some text properties added.
518 Major modes that edit things other than ordinary files may change this
519 \(e.g. Info, Dired,...)")
520 ;;;###autoload
521 (put 'mode-line-buffer-identification 'risky-local-variable t)
522 (make-variable-buffer-local 'mode-line-buffer-identification)
524 (defvar mode-line-misc-info
525 '((global-mode-string ("" global-mode-string " ")))
526 "Mode line construct for miscellaneous information.
527 By default, this shows the information specified by `global-mode-string'.")
528 (put 'mode-line-misc-info 'risky-local-variable t)
530 (defvar mode-line-end-spaces '(:eval (unless (display-graphic-p) "-%-"))
531 "Mode line construct to put at the end of the mode line.")
532 (put 'mode-line-end-spaces 'risky-local-variable t)
534 ;; Default value of the top-level `mode-line-format' variable:
535 (let ((standard-mode-line-format
536 (list "%e"
537 'mode-line-front-space
538 'mode-line-mule-info
539 'mode-line-client
540 'mode-line-modified
541 'mode-line-remote
542 'mode-line-frame-identification
543 'mode-line-buffer-identification
545 'mode-line-position
546 '(vc-mode vc-mode)
548 'mode-line-modes
549 'mode-line-misc-info
550 'mode-line-end-spaces)))
551 (setq-default mode-line-format standard-mode-line-format)
552 (put 'mode-line-format 'standard-value
553 (list `(quote ,standard-mode-line-format))))
556 (defun mode-line-unbury-buffer (event) "\
557 Call `unbury-buffer' in this window."
558 (interactive "e")
559 (with-selected-window (posn-window (event-start event))
560 (unbury-buffer)))
562 (defun mode-line-bury-buffer (event) "\
563 Like `bury-buffer', but temporarily select EVENT's window."
564 (interactive "e")
565 (with-selected-window (posn-window (event-start event))
566 (bury-buffer)))
568 (defun mode-line-other-buffer () "\
569 Switch to the most recently selected buffer other than the current one."
570 (interactive)
571 (switch-to-buffer (other-buffer) nil t))
573 (defun mode-line-next-buffer (event)
574 "Like `next-buffer', but temporarily select EVENT's window."
575 (interactive "e")
576 (with-selected-window (posn-window (event-start event))
577 (next-buffer)))
579 (defun mode-line-previous-buffer (event)
580 "Like `previous-buffer', but temporarily select EVENT's window."
581 (interactive "e")
582 (with-selected-window (posn-window (event-start event))
583 (previous-buffer)))
585 (defmacro bound-and-true-p (var)
586 "Return the value of symbol VAR if it is bound, else nil."
587 `(and (boundp (quote ,var)) ,var))
589 ;; Use mode-line-mode-menu for local minor-modes only.
590 ;; Global ones can go on the menubar (Options --> Show/Hide).
591 (bindings--define-key mode-line-mode-menu [overwrite-mode]
592 '(menu-item "Overwrite (Ovwrt)" overwrite-mode
593 :help "Overwrite mode: typed characters replace existing text"
594 :button (:toggle . overwrite-mode)))
595 (bindings--define-key mode-line-mode-menu [outline-minor-mode]
596 '(menu-item "Outline (Outl)" outline-minor-mode
597 ;; XXX: This needs a good, brief description.
598 :help ""
599 :button (:toggle . (bound-and-true-p outline-minor-mode))))
600 (bindings--define-key mode-line-mode-menu [highlight-changes-mode]
601 '(menu-item "Highlight changes (Chg)" highlight-changes-mode
602 :help "Show changes in the buffer in a distinctive color"
603 :button (:toggle . (bound-and-true-p highlight-changes-mode))))
604 (bindings--define-key mode-line-mode-menu [hide-ifdef-mode]
605 '(menu-item "Hide ifdef (Ifdef)" hide-ifdef-mode
606 :help "Show/Hide code within #ifdef constructs"
607 :button (:toggle . (bound-and-true-p hide-ifdef-mode))))
608 (bindings--define-key mode-line-mode-menu [glasses-mode]
609 '(menu-item "Glasses (o^o)" glasses-mode
610 :help "Insert virtual separators to make long identifiers easy to read"
611 :button (:toggle . (bound-and-true-p glasses-mode))))
612 (bindings--define-key mode-line-mode-menu [font-lock-mode]
613 '(menu-item "Font Lock" font-lock-mode
614 :help "Syntax coloring"
615 :button (:toggle . font-lock-mode)))
616 (bindings--define-key mode-line-mode-menu [flyspell-mode]
617 '(menu-item "Flyspell (Fly)" flyspell-mode
618 :help "Spell checking on the fly"
619 :button (:toggle . (bound-and-true-p flyspell-mode))))
620 (bindings--define-key mode-line-mode-menu [auto-revert-tail-mode]
621 '(menu-item "Auto revert tail (Tail)" auto-revert-tail-mode
622 :help "Revert the tail of the buffer when the file on disk grows"
623 :enable (buffer-file-name)
624 :button (:toggle . (bound-and-true-p auto-revert-tail-mode))))
625 (bindings--define-key mode-line-mode-menu [auto-revert-mode]
626 '(menu-item "Auto revert (ARev)" auto-revert-mode
627 :help "Revert the buffer when the file on disk changes"
628 :button (:toggle . (bound-and-true-p auto-revert-mode))))
629 (bindings--define-key mode-line-mode-menu [auto-fill-mode]
630 '(menu-item "Auto fill (Fill)" auto-fill-mode
631 :help "Automatically insert new lines"
632 :button (:toggle . auto-fill-function)))
633 (bindings--define-key mode-line-mode-menu [abbrev-mode]
634 '(menu-item "Abbrev (Abbrev)" abbrev-mode
635 :help "Automatically expand abbreviations"
636 :button (:toggle . abbrev-mode)))
638 (defun mode-line-minor-mode-help (event)
639 "Describe minor mode for EVENT on minor modes area of the mode line."
640 (interactive "@e")
641 (let ((indicator (car (nth 4 (car (cdr event))))))
642 (describe-minor-mode-from-indicator indicator)))
644 (defvar minor-mode-alist nil "\
645 Alist saying how to show minor modes in the mode line.
646 Each element looks like (VARIABLE STRING);
647 STRING is included in the mode line if VARIABLE's value is non-nil.
649 Actually, STRING need not be a string; any mode-line construct is
650 okay. See `mode-line-format'.")
651 ;;;###autoload
652 (put 'minor-mode-alist 'risky-local-variable t)
653 ;; Don't use purecopy here--some people want to change these strings.
654 (setq minor-mode-alist
655 '((abbrev-mode " Abbrev")
656 (overwrite-mode overwrite-mode)
657 (auto-fill-function " Fill")
658 ;; not really a minor mode...
659 (defining-kbd-macro " Def")))
661 ;; These variables are used by autoloadable packages.
662 ;; They are defined here so that they do not get overridden
663 ;; by the loading of those packages.
665 ;; Names in directory that end in one of these
666 ;; are ignored in completion,
667 ;; making it more likely you will get a unique match.
668 (setq completion-ignored-extensions
669 (append
670 (cond ((memq system-type '(ms-dos windows-nt))
671 (mapcar 'purecopy
672 '(".o" "~" ".bin" ".bak" ".obj" ".map" ".ico" ".pif" ".lnk"
673 ".a" ".ln" ".blg" ".bbl" ".dll" ".drv" ".vxd" ".386")))
675 (mapcar 'purecopy
676 '(".o" "~" ".bin" ".lbin" ".so"
677 ".a" ".ln" ".blg" ".bbl"))))
678 (mapcar 'purecopy
679 '(".elc" ".lof"
680 ".glo" ".idx" ".lot"
681 ;; VCS metadata directories
682 ".svn/" ".hg/" ".git/" ".bzr/" "CVS/" "_darcs/" "_MTN/"
683 ;; TeX-related
684 ".fmt" ".tfm"
685 ;; Java compiled
686 ".class"
687 ;; CLISP
688 ".fas" ".lib" ".mem"
689 ;; CMUCL
690 ".x86f" ".sparcf"
691 ;; OpenMCL / Clozure CL
692 ".dfsl" ".pfsl" ".d64fsl" ".p64fsl" ".lx64fsl" ".lx32fsl"
693 ".dx64fsl" ".dx32fsl" ".fx64fsl" ".fx32fsl" ".sx64fsl"
694 ".sx32fsl" ".wx64fsl" ".wx32fsl"
695 ;; Other CL implementations (Allegro, LispWorks)
696 ".fasl" ".ufsl" ".fsl" ".dxl"
697 ;; Libtool
698 ".lo" ".la"
699 ;; Gettext
700 ".gmo" ".mo"
701 ;; Texinfo-related
702 ;; This used to contain .log, but that's commonly used for log
703 ;; files you do want to see, not just TeX stuff. -- fx
704 ".toc" ".aux"
705 ".cp" ".fn" ".ky" ".pg" ".tp" ".vr"
706 ".cps" ".fns" ".kys" ".pgs" ".tps" ".vrs"
707 ;; Python byte-compiled
708 ".pyc" ".pyo"))))
710 ;; Suffixes used for executables.
711 (setq exec-suffixes
712 (cond
713 ((memq system-type '(ms-dos windows-nt))
714 '(".exe" ".com" ".bat" ".cmd" ".btm" ""))
716 '(""))))
718 ;; Packages should add to this list appropriately when they are
719 ;; loaded, rather than listing everything here.
720 (setq debug-ignored-errors
721 ;; FIXME: Maybe beginning-of-line, beginning-of-buffer, end-of-line,
722 ;; end-of-buffer, end-of-file, buffer-read-only, and
723 ;; file-supersession should all be user-errors!
724 `(beginning-of-line beginning-of-buffer end-of-line
725 end-of-buffer end-of-file buffer-read-only
726 file-supersession mark-inactive
727 user-error ;; That's the main one!
730 (make-variable-buffer-local 'indent-tabs-mode)
732 ;; These per-buffer variables are never reset by
733 ;; `kill-all-local-variables', because they have no default value.
734 ;; For consistency, we give them the `permanent-local' property, even
735 ;; though `kill-all-local-variables' does not actually consult it.
736 ;; See init_buffer_once in buffer.c for the origins of this list.
738 (mapc (lambda (sym) (put sym 'permanent-local t))
739 '(buffer-file-name default-directory buffer-backed-up
740 buffer-saved-size buffer-auto-save-file-name
741 buffer-read-only buffer-undo-list mark-active
742 point-before-scroll buffer-file-truename
743 buffer-file-format buffer-auto-save-file-format
744 buffer-display-count buffer-display-time
745 enable-multibyte-characters
746 buffer-file-coding-system truncate-lines))
748 ;; We have base64, md5 and sha1 functions built in now.
749 (provide 'base64)
750 (provide 'md5)
751 (provide 'sha1)
752 (provide 'overlay '(display syntax-table field))
753 (provide 'text-properties '(display syntax-table field point-entered))
755 (define-key esc-map "\t" 'complete-symbol)
757 (defun complete-symbol (arg)
758 "Perform completion on the text around point.
759 The completion method is determined by `completion-at-point-functions'.
761 With a prefix argument, this command does completion within
762 the collection of symbols listed in the index of the manual for the
763 language you are using."
764 (interactive "P")
765 (if arg (info-complete-symbol) (completion-at-point)))
767 ;; Reduce total amount of space we must allocate during this function
768 ;; that we will not need to keep permanently.
769 (garbage-collect)
772 (setq help-event-list '(help f1 ?\?))
774 (make-variable-buffer-local 'minor-mode-overriding-map-alist)
776 ;; From frame.c
777 (global-set-key [switch-frame] 'handle-switch-frame)
778 (global-set-key [select-window] 'handle-select-window)
780 ;; FIXME: Do those 3 events really ever reach the global-map ?
781 ;; It seems that they can't because they're handled via
782 ;; special-event-map which is used at very low-level. -stef
783 (global-set-key [delete-frame] 'handle-delete-frame)
784 (global-set-key [iconify-frame] 'ignore-event)
785 (global-set-key [make-frame-visible] 'ignore-event)
788 ;These commands are defined in editfns.c
789 ;but they are not assigned to keys there.
790 (put 'narrow-to-region 'disabled t)
792 ;; Moving with arrows in bidi-sensitive direction.
793 (defcustom visual-order-cursor-movement nil
794 "If non-nil, moving cursor with arrow keys follows the visual order.
796 When this is non-nil, \\[right-char] will move to the character that is
797 to the right of point on display, and \\[left-char] will move to the left,
798 disregarding the surrounding bidirectional context. Depending on the
799 bidirectional context of the surrounding characters, this can move point
800 many buffer positions away.
802 When the text is entirely left-to-right, logical-order and visual-order
803 cursor movements produce identical results."
804 :type '(choice (const :tag "Logical-order cursor movement" nil)
805 (const :tag "Visual-order cursor movement" t))
806 :group 'display
807 :version "24.4")
809 (defun right-char (&optional n)
810 "Move point N characters to the right (to the left if N is negative).
811 On reaching beginning or end of buffer, stop and signal error.
813 If `visual-order-cursor-movement' is non-nil, this always moves
814 to the right on display, wherever that is in the buffer.
815 Otherwise, depending on the bidirectional context, this may move
816 one position either forward or backward in the buffer. This is
817 in contrast with \\[forward-char] and \\[backward-char], which
818 see."
819 (interactive "^p")
820 (if visual-order-cursor-movement
821 (dotimes (i (if (numberp n) (abs n) 1))
822 (move-point-visually (if (and (numberp n) (< n 0)) -1 1)))
823 (if (eq (current-bidi-paragraph-direction) 'left-to-right)
824 (forward-char n)
825 (backward-char n))))
827 (defun left-char ( &optional n)
828 "Move point N characters to the left (to the right if N is negative).
829 On reaching beginning or end of buffer, stop and signal error.
831 If `visual-order-cursor-movement' is non-nil, this always moves
832 to the left on display, wherever that is in the buffer.
833 Otherwise, depending on the bidirectional context, this may move
834 one position either backward or forward in the buffer. This is
835 in contrast with \\[forward-char] and \\[backward-char], which
836 see."
837 (interactive "^p")
838 (if visual-order-cursor-movement
839 (dotimes (i (if (numberp n) (abs n) 1))
840 (move-point-visually (if (and (numberp n) (< n 0)) 1 -1)))
841 (if (eq (current-bidi-paragraph-direction) 'left-to-right)
842 (backward-char n)
843 (forward-char n))))
845 (defun right-word (&optional n)
846 "Move point N words to the right (to the left if N is negative).
848 Depending on the bidirectional context, this may move either forward
849 or backward in the buffer. This is in contrast with \\[forward-word]
850 and \\[backward-word], which see.
852 Value is normally t.
853 If an edge of the buffer or a field boundary is reached, point is left there
854 there and the function returns nil. Field boundaries are not noticed
855 if `inhibit-field-text-motion' is non-nil."
856 (interactive "^p")
857 (if (eq (current-bidi-paragraph-direction) 'left-to-right)
858 (forward-word n)
859 (backward-word n)))
861 (defun left-word (&optional n)
862 "Move point N words to the left (to the right if N is negative).
864 Depending on the bidirectional context, this may move either backward
865 or forward in the buffer. This is in contrast with \\[backward-word]
866 and \\[forward-word], which see.
868 Value is normally t.
869 If an edge of the buffer or a field boundary is reached, point is left there
870 there and the function returns nil. Field boundaries are not noticed
871 if `inhibit-field-text-motion' is non-nil."
872 (interactive "^p")
873 (if (eq (current-bidi-paragraph-direction) 'left-to-right)
874 (backward-word n)
875 (forward-word n)))
877 (defvar narrow-map (make-sparse-keymap)
878 "Keymap for narrowing commands.")
879 (define-key ctl-x-map "n" narrow-map)
881 (define-key narrow-map "n" 'narrow-to-region)
882 (define-key narrow-map "w" 'widen)
884 ;; Quitting
885 (define-key global-map "\e\e\e" 'keyboard-escape-quit)
886 (define-key global-map "\C-g" 'keyboard-quit)
888 ;; Used to be in termdev.el: when using several terminals, make C-z
889 ;; suspend only the relevant terminal.
890 (substitute-key-definition 'suspend-emacs 'suspend-frame global-map)
892 (define-key global-map "\C-m" 'newline)
893 (define-key global-map "\C-o" 'open-line)
894 (define-key esc-map "\C-o" 'split-line)
895 (define-key global-map "\C-q" 'quoted-insert)
896 (define-key esc-map "^" 'delete-indentation)
897 (define-key esc-map "\\" 'delete-horizontal-space)
898 (define-key esc-map "m" 'back-to-indentation)
899 (define-key ctl-x-map "\C-o" 'delete-blank-lines)
900 (define-key esc-map " " 'just-one-space)
901 (define-key esc-map "z" 'zap-to-char)
902 (define-key esc-map "=" 'count-words-region)
903 (define-key ctl-x-map "=" 'what-cursor-position)
904 (define-key esc-map ":" 'eval-expression)
905 ;; Define ESC ESC : like ESC : for people who type ESC ESC out of habit.
906 (define-key esc-map "\M-:" 'eval-expression)
907 ;; Changed from C-x ESC so that function keys work following C-x.
908 (define-key ctl-x-map "\e\e" 'repeat-complex-command)
909 ;; New binding analogous to M-:.
910 (define-key ctl-x-map "\M-:" 'repeat-complex-command)
911 (define-key ctl-x-map "u" 'undo)
912 (put 'undo :advertised-binding [?\C-x ?u])
913 ;; Many people are used to typing C-/ on X terminals and getting C-_.
914 (define-key global-map [?\C-/] 'undo)
915 (define-key global-map "\C-_" 'undo)
916 ;; Richard said that we should not use C-x <uppercase letter> and I have
917 ;; no idea whereas to bind it. Any suggestion welcome. -stef
918 ;; (define-key ctl-x-map "U" 'undo-only)
920 (define-key esc-map "!" 'shell-command)
921 (define-key esc-map "|" 'shell-command-on-region)
922 (define-key esc-map "&" 'async-shell-command)
924 (define-key ctl-x-map [right] 'next-buffer)
925 (define-key ctl-x-map [C-right] 'next-buffer)
926 (define-key global-map [XF86Forward] 'next-buffer)
927 (define-key ctl-x-map [left] 'previous-buffer)
928 (define-key ctl-x-map [C-left] 'previous-buffer)
929 (define-key global-map [XF86Back] 'previous-buffer)
931 (let ((map minibuffer-local-map))
932 (define-key map "\en" 'next-history-element)
933 (define-key map [next] 'next-history-element)
934 (define-key map [down] 'next-line-or-history-element)
935 (define-key map [XF86Forward] 'next-history-element)
936 (define-key map "\ep" 'previous-history-element)
937 (define-key map [prior] 'previous-history-element)
938 (define-key map [up] 'previous-line-or-history-element)
939 (define-key map [XF86Back] 'previous-history-element)
940 (define-key map "\es" 'next-matching-history-element)
941 (define-key map "\er" 'previous-matching-history-element)
942 ;; Override the global binding (which calls indent-relative via
943 ;; indent-for-tab-command). The alignment that indent-relative tries to
944 ;; do doesn't make much sense here since the prompt messes it up.
945 (define-key map "\t" 'self-insert-command)
946 (define-key map [C-tab] 'file-cache-minibuffer-complete))
948 (define-key global-map "\C-u" 'universal-argument)
949 (let ((i ?0))
950 (while (<= i ?9)
951 (define-key esc-map (char-to-string i) 'digit-argument)
952 (setq i (1+ i))))
953 (define-key esc-map "-" 'negative-argument)
954 ;; Define control-digits.
955 (let ((i ?0))
956 (while (<= i ?9)
957 (define-key global-map (read (format "[?\\C-%c]" i)) 'digit-argument)
958 (setq i (1+ i))))
959 (define-key global-map [?\C--] 'negative-argument)
960 ;; Define control-meta-digits.
961 (let ((i ?0))
962 (while (<= i ?9)
963 (define-key esc-map (read (format "[?\\C-%c]" i)) 'digit-argument)
964 (setq i (1+ i))))
965 (define-key global-map [?\C-\M--] 'negative-argument)
967 ;; Update tutorial--default-keys if you change these.
968 (define-key global-map "\177" 'delete-backward-char)
969 ;; We explicitly want C-d to use `delete-char' instead of
970 ;; `delete-forward-char' so that it ignores `delete-active-region':
971 ;; Most C-d users are old-timers who don't expect
972 ;; `delete-active-region' here, while newer users who expect
973 ;; `delete-active-region' use C-d much less.
974 (define-key global-map "\C-d" 'delete-char)
976 (define-key global-map "\C-k" 'kill-line)
977 (define-key global-map "\C-w" 'kill-region)
978 (define-key esc-map "w" 'kill-ring-save)
979 (define-key esc-map "\C-w" 'append-next-kill)
980 (define-key global-map "\C-y" 'yank)
981 (define-key esc-map "y" 'yank-pop)
983 ;; (define-key ctl-x-map "a" 'append-to-buffer)
985 (define-key global-map "\C-@" 'set-mark-command)
986 ;; Many people are used to typing C-SPC and getting C-@.
987 (define-key global-map [?\C- ] 'set-mark-command)
988 (put 'set-mark-command :advertised-binding [?\C- ])
990 (define-key ctl-x-map "\C-x" 'exchange-point-and-mark)
991 (define-key ctl-x-map "\C-@" 'pop-global-mark)
992 (define-key ctl-x-map " " 'rectangle-mark-mode)
993 (define-key ctl-x-map [?\C- ] 'pop-global-mark)
995 (define-key global-map "\C-n" 'next-line)
996 (define-key global-map "\C-p" 'previous-line)
997 (define-key ctl-x-map "\C-n" 'set-goal-column)
998 (define-key global-map "\C-a" 'move-beginning-of-line)
999 (define-key global-map "\C-e" 'move-end-of-line)
1001 (define-key ctl-x-map "`" 'next-error)
1003 (defvar goto-map (make-sparse-keymap)
1004 "Keymap for navigation commands.")
1005 (define-key esc-map "g" goto-map)
1007 (define-key goto-map "c" 'goto-char)
1008 (define-key goto-map "g" 'goto-line)
1009 (define-key goto-map "\M-g" 'goto-line)
1010 (define-key goto-map "n" 'next-error)
1011 (define-key goto-map "\M-n" 'next-error)
1012 (define-key goto-map "p" 'previous-error)
1013 (define-key goto-map "\M-p" 'previous-error)
1014 (define-key goto-map "\t" 'move-to-column)
1016 (defvar search-map (make-sparse-keymap)
1017 "Keymap for search related commands.")
1018 (define-key esc-map "s" search-map)
1020 (define-key search-map "o" 'occur)
1021 (define-key search-map "\M-w" 'eww-search-words)
1022 (define-key search-map "hr" 'highlight-regexp)
1023 (define-key search-map "hp" 'highlight-phrase)
1024 (define-key search-map "hl" 'highlight-lines-matching-regexp)
1025 (define-key search-map "h." 'highlight-symbol-at-point)
1026 (define-key search-map "hu" 'unhighlight-regexp)
1027 (define-key search-map "hf" 'hi-lock-find-patterns)
1028 (define-key search-map "hw" 'hi-lock-write-interactive-patterns)
1030 ;;(defun function-key-error ()
1031 ;; (interactive)
1032 ;; (error "That function key is not bound to anything"))
1034 (define-key global-map [menu] 'execute-extended-command)
1035 (define-key global-map [find] 'search-forward)
1037 ;; Don't do this. We define <delete> in function-key-map instead.
1038 ;(define-key global-map [delete] 'backward-delete-char)
1040 ;; natural bindings for terminal keycaps --- defined in X keysym order
1041 (define-key global-map [C-S-backspace] 'kill-whole-line)
1042 (define-key global-map [home] 'move-beginning-of-line)
1043 (define-key global-map [C-home] 'beginning-of-buffer)
1044 (define-key global-map [M-home] 'beginning-of-buffer-other-window)
1045 (define-key esc-map [home] 'beginning-of-buffer-other-window)
1046 (define-key global-map [left] 'left-char)
1047 (define-key global-map [up] 'previous-line)
1048 (define-key global-map [right] 'right-char)
1049 (define-key global-map [down] 'next-line)
1050 (define-key global-map [prior] 'scroll-down-command)
1051 (define-key global-map [next] 'scroll-up-command)
1052 (define-key global-map [C-up] 'backward-paragraph)
1053 (define-key global-map [C-down] 'forward-paragraph)
1054 (define-key global-map [C-prior] 'scroll-right)
1055 (put 'scroll-left 'disabled t)
1056 (define-key global-map [C-next] 'scroll-left)
1057 (define-key global-map [M-next] 'scroll-other-window)
1058 (define-key esc-map [next] 'scroll-other-window)
1059 (define-key global-map [M-prior] 'scroll-other-window-down)
1060 (define-key esc-map [prior] 'scroll-other-window-down)
1061 (define-key esc-map [?\C-\S-v] 'scroll-other-window-down)
1062 (define-key global-map [end] 'move-end-of-line)
1063 (define-key global-map [C-end] 'end-of-buffer)
1064 (define-key global-map [M-end] 'end-of-buffer-other-window)
1065 (define-key esc-map [end] 'end-of-buffer-other-window)
1066 (define-key global-map [begin] 'beginning-of-buffer)
1067 (define-key global-map [M-begin] 'beginning-of-buffer-other-window)
1068 (define-key esc-map [begin] 'beginning-of-buffer-other-window)
1069 ;; (define-key global-map [select] 'function-key-error)
1070 ;; (define-key global-map [print] 'function-key-error)
1071 (define-key global-map [execute] 'execute-extended-command)
1072 (define-key global-map [insert] 'overwrite-mode)
1073 (define-key global-map [C-insert] 'kill-ring-save)
1074 (define-key global-map [S-insert] 'yank)
1075 ;; `insertchar' is what term.c produces. Should we change term.c
1076 ;; to produce `insert' instead?
1077 (define-key global-map [insertchar] 'overwrite-mode)
1078 (define-key global-map [C-insertchar] 'kill-ring-save)
1079 (define-key global-map [S-insertchar] 'yank)
1080 (define-key global-map [undo] 'undo)
1081 (define-key global-map [redo] 'repeat-complex-command)
1082 (define-key global-map [again] 'repeat-complex-command) ; Sun keyboard
1083 (define-key global-map [open] 'find-file) ; Sun
1084 ;; The following wouldn't work to interrupt running code since C-g is
1085 ;; treated specially in the event loop.
1086 ;; (define-key global-map [stop] 'keyboard-quit) ; Sun
1087 ;; (define-key global-map [clearline] 'function-key-error)
1088 (define-key global-map [insertline] 'open-line)
1089 (define-key global-map [deleteline] 'kill-line)
1090 (define-key global-map [deletechar] 'delete-forward-char)
1091 ;; (define-key global-map [backtab] 'function-key-error)
1092 ;; (define-key global-map [f1] 'function-key-error)
1093 ;; (define-key global-map [f2] 'function-key-error)
1094 ;; (define-key global-map [f3] 'function-key-error)
1095 ;; (define-key global-map [f4] 'function-key-error)
1096 ;; (define-key global-map [f5] 'function-key-error)
1097 ;; (define-key global-map [f6] 'function-key-error)
1098 ;; (define-key global-map [f7] 'function-key-error)
1099 ;; (define-key global-map [f8] 'function-key-error)
1100 ;; (define-key global-map [f9] 'function-key-error)
1101 ;; (define-key global-map [f10] 'function-key-error)
1102 ;; (define-key global-map [f11] 'function-key-error)
1103 ;; (define-key global-map [f12] 'function-key-error)
1104 ;; (define-key global-map [f13] 'function-key-error)
1105 ;; (define-key global-map [f14] 'function-key-error)
1106 ;; (define-key global-map [f15] 'function-key-error)
1107 ;; (define-key global-map [f16] 'function-key-error)
1108 ;; (define-key global-map [f17] 'function-key-error)
1109 ;; (define-key global-map [f18] 'function-key-error)
1110 ;; (define-key global-map [f19] 'function-key-error)
1111 ;; (define-key global-map [f20] 'function-key-error)
1112 ;; (define-key global-map [f21] 'function-key-error)
1113 ;; (define-key global-map [f22] 'function-key-error)
1114 ;; (define-key global-map [f23] 'function-key-error)
1115 ;; (define-key global-map [f24] 'function-key-error)
1116 ;; (define-key global-map [f25] 'function-key-error)
1117 ;; (define-key global-map [f26] 'function-key-error)
1118 ;; (define-key global-map [f27] 'function-key-error)
1119 ;; (define-key global-map [f28] 'function-key-error)
1120 ;; (define-key global-map [f29] 'function-key-error)
1121 ;; (define-key global-map [f30] 'function-key-error)
1122 ;; (define-key global-map [f31] 'function-key-error)
1123 ;; (define-key global-map [f32] 'function-key-error)
1124 ;; (define-key global-map [f33] 'function-key-error)
1125 ;; (define-key global-map [f34] 'function-key-error)
1126 ;; (define-key global-map [f35] 'function-key-error)
1127 ;; (define-key global-map [kp-backtab] 'function-key-error)
1128 ;; (define-key global-map [kp-space] 'function-key-error)
1129 ;; (define-key global-map [kp-tab] 'function-key-error)
1130 ;; (define-key global-map [kp-enter] 'function-key-error)
1131 ;; (define-key global-map [kp-f1] 'function-key-error)
1132 ;; (define-key global-map [kp-f2] 'function-key-error)
1133 ;; (define-key global-map [kp-f3] 'function-key-error)
1134 ;; (define-key global-map [kp-f4] 'function-key-error)
1135 ;; (define-key global-map [kp-multiply] 'function-key-error)
1136 ;; (define-key global-map [kp-add] 'function-key-error)
1137 ;; (define-key global-map [kp-separator] 'function-key-error)
1138 ;; (define-key global-map [kp-subtract] 'function-key-error)
1139 ;; (define-key global-map [kp-decimal] 'function-key-error)
1140 ;; (define-key global-map [kp-divide] 'function-key-error)
1141 ;; (define-key global-map [kp-0] 'function-key-error)
1142 ;; (define-key global-map [kp-1] 'function-key-error)
1143 ;; (define-key global-map [kp-2] 'function-key-error)
1144 ;; (define-key global-map [kp-3] 'function-key-error)
1145 ;; (define-key global-map [kp-4] 'function-key-error)
1146 ;; (define-key global-map [kp-5] 'recenter)
1147 ;; (define-key global-map [kp-6] 'function-key-error)
1148 ;; (define-key global-map [kp-7] 'function-key-error)
1149 ;; (define-key global-map [kp-8] 'function-key-error)
1150 ;; (define-key global-map [kp-9] 'function-key-error)
1151 ;; (define-key global-map [kp-equal] 'function-key-error)
1153 ;; X11R6 distinguishes these keys from the non-kp keys.
1154 ;; Make them behave like the non-kp keys unless otherwise bound.
1155 ;; FIXME: rather than list such mappings for every modifier-combination,
1156 ;; we should come up with a way to do it generically, something like
1157 ;; (define-key function-key-map [*-kp-home] [*-home])
1158 ;; Currently we add keypad key combinations with basic modifiers
1159 ;; (to complement plain bindings in "Keypad support" section in simple.el)
1160 ;; Until [*-kp-home] is implemented, for more modifiers we could also use:
1161 ;; (todo-powerset '(control meta shift hyper super alt)) (Bug#14397)
1162 (let ((modifiers '(nil (control) (meta) (control meta) (shift)
1163 (control shift) (meta shift) (control meta shift)))
1164 (keys '((kp-delete delete) (kp-insert insert)
1165 (kp-end end) (kp-down down) (kp-next next)
1166 (kp-left left) (kp-begin begin) (kp-right right)
1167 (kp-home home) (kp-up up) (kp-prior prior)
1168 (kp-enter enter) (kp-decimal ?.)
1169 (kp-0 ?0) (kp-1 ?1) (kp-2 ?2) (kp-3 ?3) (kp-4 ?4)
1170 (kp-5 ?5) (kp-6 ?6) (kp-7 ?7) (kp-8 ?8) (kp-9 ?9)
1171 (kp-add ?+) (kp-subtract ?-) (kp-multiply ?*) (kp-divide ?/))))
1172 (dolist (pair keys)
1173 (let ((keypad (nth 0 pair))
1174 (normal (nth 1 pair)))
1175 (when (characterp normal)
1176 (put keypad 'ascii-character normal))
1177 (dolist (mod modifiers)
1178 (define-key function-key-map
1179 (vector (append mod (list keypad)))
1180 (vector (append mod (list normal))))))))
1182 (define-key function-key-map [backspace] [?\C-?])
1183 (define-key function-key-map [delete] [?\C-?])
1184 (define-key function-key-map [kp-delete] [?\C-?])
1186 ;; Don't bind shifted keypad numeric keys, they reportedly
1187 ;; interfere with the feature of some keyboards to produce
1188 ;; numbers when NumLock is off.
1189 ;(define-key function-key-map [S-kp-1] [S-end])
1190 ;(define-key function-key-map [S-kp-2] [S-down])
1191 ;(define-key function-key-map [S-kp-3] [S-next])
1192 ;(define-key function-key-map [S-kp-4] [S-left])
1193 ;(define-key function-key-map [S-kp-6] [S-right])
1194 ;(define-key function-key-map [S-kp-7] [S-home])
1195 ;(define-key function-key-map [S-kp-8] [S-up])
1196 ;(define-key function-key-map [S-kp-9] [S-prior])
1197 ;(define-key function-key-map [C-S-kp-1] [C-S-end])
1198 ;(define-key function-key-map [C-S-kp-2] [C-S-down])
1199 ;(define-key function-key-map [C-S-kp-3] [C-S-next])
1200 ;(define-key function-key-map [C-S-kp-4] [C-S-left])
1201 ;(define-key function-key-map [C-S-kp-6] [C-S-right])
1202 ;(define-key function-key-map [C-S-kp-7] [C-S-home])
1203 ;(define-key function-key-map [C-S-kp-8] [C-S-up])
1204 ;(define-key function-key-map [C-S-kp-9] [C-S-prior])
1206 ;; Hitting C-SPC on text terminals, usually sends the ascii code 0 (aka C-@),
1207 ;; so we can't distinguish those two keys, but usually we consider C-SPC
1208 ;; (rather than C-@) as the "canonical" binding.
1209 (define-key function-key-map [?\C-@] [?\C-\s])
1210 ;; Many keyboards don't have a `backtab' key, so by convention the user
1211 ;; can use S-tab instead to access that binding.
1212 (define-key function-key-map [S-tab] [backtab])
1214 (define-key global-map [mouse-movement] 'ignore)
1216 (define-key global-map "\C-t" 'transpose-chars)
1217 (define-key esc-map "t" 'transpose-words)
1218 (define-key esc-map "\C-t" 'transpose-sexps)
1219 (define-key ctl-x-map "\C-t" 'transpose-lines)
1221 (define-key esc-map ";" 'comment-dwim)
1222 (define-key esc-map "j" 'indent-new-comment-line)
1223 (define-key esc-map "\C-j" 'indent-new-comment-line)
1224 (define-key ctl-x-map ";" 'comment-set-column)
1225 (define-key ctl-x-map [?\C-\;] 'comment-line)
1226 (define-key ctl-x-map "f" 'set-fill-column)
1227 (define-key ctl-x-map "$" 'set-selective-display)
1229 (define-key esc-map "@" 'mark-word)
1230 (define-key esc-map "f" 'forward-word)
1231 (define-key esc-map "b" 'backward-word)
1232 (define-key esc-map "d" 'kill-word)
1233 (define-key esc-map "\177" 'backward-kill-word)
1235 (define-key esc-map "<" 'beginning-of-buffer)
1236 (define-key esc-map ">" 'end-of-buffer)
1237 (define-key ctl-x-map "h" 'mark-whole-buffer)
1238 (define-key esc-map "\\" 'delete-horizontal-space)
1240 (defalias 'mode-specific-command-prefix (make-sparse-keymap))
1241 (defvar mode-specific-map (symbol-function 'mode-specific-command-prefix)
1242 "Keymap for characters following C-c.")
1243 (define-key global-map "\C-c" 'mode-specific-command-prefix)
1245 (global-set-key [M-right] 'right-word)
1246 (define-key esc-map [right] 'forward-word)
1247 (global-set-key [M-left] 'left-word)
1248 (define-key esc-map [left] 'backward-word)
1249 ;; ilya@math.ohio-state.edu says these bindings are standard on PC editors.
1250 (global-set-key [C-right] 'right-word)
1251 (global-set-key [C-left] 'left-word)
1252 ;; This is not quite compatible, but at least is analogous
1253 (global-set-key [C-delete] 'kill-word)
1254 (global-set-key [C-backspace] 'backward-kill-word)
1255 ;; This is "move to the clipboard", or as close as we come.
1256 (global-set-key [S-delete] 'kill-region)
1258 (global-set-key [C-M-left] 'backward-sexp)
1259 (define-key esc-map [C-left] 'backward-sexp)
1260 (global-set-key [C-M-right] 'forward-sexp)
1261 (define-key esc-map [C-right] 'forward-sexp)
1262 (global-set-key [C-M-up] 'backward-up-list)
1263 (define-key esc-map [C-up] 'backward-up-list)
1264 (global-set-key [C-M-down] 'down-list)
1265 (define-key esc-map [C-down] 'down-list)
1266 (global-set-key [C-M-home] 'beginning-of-defun)
1267 (define-key esc-map [C-home] 'beginning-of-defun)
1268 (global-set-key [C-M-end] 'end-of-defun)
1269 (define-key esc-map [C-end] 'end-of-defun)
1271 (define-key esc-map "\C-f" 'forward-sexp)
1272 (define-key esc-map "\C-b" 'backward-sexp)
1273 (define-key esc-map "\C-u" 'backward-up-list)
1274 (define-key esc-map "\C-@" 'mark-sexp)
1275 (define-key esc-map [?\C-\ ] 'mark-sexp)
1276 (define-key esc-map "\C-d" 'down-list)
1277 (define-key esc-map "\C-k" 'kill-sexp)
1278 ;;; These are dangerous in various situations,
1279 ;;; so let's not encourage anyone to use them.
1280 ;;;(define-key global-map [C-M-delete] 'backward-kill-sexp)
1281 ;;;(define-key global-map [C-M-backspace] 'backward-kill-sexp)
1282 (define-key esc-map [C-delete] 'backward-kill-sexp)
1283 (define-key esc-map [C-backspace] 'backward-kill-sexp)
1284 (define-key esc-map "\C-n" 'forward-list)
1285 (define-key esc-map "\C-p" 'backward-list)
1286 (define-key esc-map "\C-a" 'beginning-of-defun)
1287 (define-key esc-map "\C-e" 'end-of-defun)
1288 (define-key esc-map "\C-h" 'mark-defun)
1289 (define-key ctl-x-map "nd" 'narrow-to-defun)
1290 (define-key esc-map "(" 'insert-parentheses)
1291 (define-key esc-map ")" 'move-past-close-and-reindent)
1293 (define-key ctl-x-map "\C-e" 'eval-last-sexp)
1295 (define-key ctl-x-map "m" 'compose-mail)
1296 (define-key ctl-x-4-map "m" 'compose-mail-other-window)
1297 (define-key ctl-x-5-map "m" 'compose-mail-other-frame)
1300 (defvar ctl-x-r-map
1301 (let ((map (make-sparse-keymap)))
1302 (define-key map "c" 'clear-rectangle)
1303 (define-key map "k" 'kill-rectangle)
1304 (define-key map "d" 'delete-rectangle)
1305 (define-key map "y" 'yank-rectangle)
1306 (define-key map "o" 'open-rectangle)
1307 (define-key map "t" 'string-rectangle)
1308 (define-key map "N" 'rectangle-number-lines)
1309 (define-key map "\M-w" 'copy-rectangle-as-kill)
1310 (define-key map "\C-@" 'point-to-register)
1311 (define-key map [?\C-\ ] 'point-to-register)
1312 (define-key map " " 'point-to-register)
1313 (define-key map "j" 'jump-to-register)
1314 (define-key map "s" 'copy-to-register)
1315 (define-key map "x" 'copy-to-register)
1316 (define-key map "i" 'insert-register)
1317 (define-key map "g" 'insert-register)
1318 (define-key map "r" 'copy-rectangle-to-register)
1319 (define-key map "n" 'number-to-register)
1320 (define-key map "+" 'increment-register)
1321 (define-key map "w" 'window-configuration-to-register)
1322 (define-key map "f" 'frameset-to-register)
1323 map)
1324 "Keymap for subcommands of C-x r.")
1325 (define-key ctl-x-map "r" ctl-x-r-map)
1327 (define-key esc-map "q" 'fill-paragraph)
1328 (define-key ctl-x-map "." 'set-fill-prefix)
1330 (define-key esc-map "{" 'backward-paragraph)
1331 (define-key esc-map "}" 'forward-paragraph)
1332 (define-key esc-map "h" 'mark-paragraph)
1333 (define-key esc-map "a" 'backward-sentence)
1334 (define-key esc-map "e" 'forward-sentence)
1335 (define-key esc-map "k" 'kill-sentence)
1336 (define-key ctl-x-map "\177" 'backward-kill-sentence)
1338 (define-key ctl-x-map "[" 'backward-page)
1339 (define-key ctl-x-map "]" 'forward-page)
1340 (define-key ctl-x-map "\C-p" 'mark-page)
1341 (define-key ctl-x-map "l" 'count-lines-page)
1342 (define-key ctl-x-map "np" 'narrow-to-page)
1343 ;; (define-key ctl-x-map "p" 'narrow-to-page)
1345 (defvar abbrev-map (make-sparse-keymap)
1346 "Keymap for abbrev commands.")
1347 (define-key ctl-x-map "a" abbrev-map)
1349 (define-key abbrev-map "l" 'add-mode-abbrev)
1350 (define-key abbrev-map "\C-a" 'add-mode-abbrev)
1351 (define-key abbrev-map "g" 'add-global-abbrev)
1352 (define-key abbrev-map "+" 'add-mode-abbrev)
1353 (define-key abbrev-map "ig" 'inverse-add-global-abbrev)
1354 (define-key abbrev-map "il" 'inverse-add-mode-abbrev)
1355 ;; (define-key abbrev-map "\C-h" 'inverse-add-global-abbrev)
1356 (define-key abbrev-map "-" 'inverse-add-global-abbrev)
1357 (define-key abbrev-map "e" 'expand-abbrev)
1358 (define-key abbrev-map "'" 'expand-abbrev)
1359 ;; (define-key ctl-x-map "\C-a" 'add-mode-abbrev)
1360 ;; (define-key ctl-x-map "+" 'add-global-abbrev)
1361 ;; (define-key ctl-x-map "\C-h" 'inverse-add-mode-abbrev)
1362 ;; (define-key ctl-x-map "-" 'inverse-add-global-abbrev)
1363 (define-key esc-map "'" 'abbrev-prefix-mark)
1364 (define-key ctl-x-map "'" 'expand-abbrev)
1365 (define-key ctl-x-map "\C-b" 'list-buffers)
1367 (define-key ctl-x-map "z" 'repeat)
1369 (define-key esc-map "\C-l" 'reposition-window)
1371 (define-key ctl-x-4-map "a" 'add-change-log-entry-other-window)
1372 (define-key ctl-x-4-map "c" 'clone-indirect-buffer-other-window)
1374 ;; Signal handlers
1375 (define-key special-event-map [sigusr1] 'ignore)
1376 (define-key special-event-map [sigusr2] 'ignore)
1378 ;; Don't look for autoload cookies in this file.
1379 ;; Local Variables:
1380 ;; no-update-autoloads: t
1381 ;; End:
1383 ;;; bindings.el ends here