bindings.el 46.6 KB
Newer Older
1
;;; bindings.el --- define standard key bindings and some variables
Richard M. Stallman's avatar
Richard M. Stallman committed
2

3
;; Copyright (C) 1985, 1986, 1987, 1992, 1993, 1994, 1995, 1996, 1999,
Glenn Morris's avatar
Glenn Morris committed
4
;;   2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
5
;;   Free Software Foundation, Inc.
Richard M. Stallman's avatar
Richard M. Stallman committed
6 7 8 9 10 11

;; Maintainer: FSF
;; Keywords: internal

;; This file is part of GNU Emacs.

12
;; GNU Emacs is free software: you can redistribute it and/or modify
Richard M. Stallman's avatar
Richard M. Stallman committed
13
;; it under the terms of the GNU General Public License as published by
14 15
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
Richard M. Stallman's avatar
Richard M. Stallman committed
16 17 18 19 20 21 22

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
23
;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
Richard M. Stallman's avatar
Richard M. Stallman committed
24 25 26 27 28

;;; Commentary:

;;; Code:

29 30 31
(defun make-mode-line-mouse-map (mouse function) "\
Return a keymap with single entry for mouse key MOUSE on the mode line.
MOUSE is defined to run function FUNCTION with no args in the buffer
32 33
corresponding to the mode line clicked."
  (let ((map (make-sparse-keymap)))
34
    (define-key map (vector 'mode-line mouse) function)
35 36
    map))

Gerd Moellmann's avatar
Gerd Moellmann committed
37 38 39 40 41 42 43 44 45 46 47 48

(defun mode-line-toggle-read-only (event)
  "Like `toggle-read-only', for the mode-line."
  (interactive "e")
  (save-selected-window
    (select-window (posn-window (event-start event)))
    (toggle-read-only)
    (force-mode-line-update)))


(defun mode-line-toggle-modified (event)
  "Toggle the buffer-modified flag from the mode-line."
49
  (interactive "e")
Gerd Moellmann's avatar
Gerd Moellmann committed
50 51 52 53 54 55 56 57
  (save-selected-window
    (select-window (posn-window (event-start event)))
    (set-buffer-modified-p (not (buffer-modified-p)))
    (force-mode-line-update)))


(defun mode-line-widen (event)
  "Widen a buffer from the mode-line."
58
  (interactive "e")
Gerd Moellmann's avatar
Gerd Moellmann committed
59 60 61 62 63 64
  (save-selected-window
    (select-window (posn-window (event-start event)))
    (widen)
    (force-mode-line-update)))


65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
(defvar mode-line-input-method-map
  (let ((map (make-sparse-keymap)))
    (define-key map [mode-line mouse-2]
      (lambda (e)
	(interactive "e")
	(save-selected-window
	  (select-window
	   (posn-window (event-start e)))
	  (toggle-input-method)
	  (force-mode-line-update))))
    (define-key map [mode-line mouse-3]
      (lambda (e)
	(interactive "e")
	(save-selected-window
	  (select-window
	   (posn-window (event-start e)))
	  (describe-current-input-method))))
    (purecopy map)))

84 85 86

(defvar mode-line-coding-system-map
  (let ((map (make-sparse-keymap)))
87
    (define-key map [mode-line mouse-1]
88 89 90 91 92 93 94 95 96 97 98
      (lambda (e)
	(interactive "e")
	(save-selected-window
	  (select-window (posn-window (event-start e)))
	  (when (and enable-multibyte-characters
		     buffer-file-coding-system)
	    (describe-coding-system buffer-file-coding-system)))))
    (purecopy map))
  "Local keymap for the coding-system part of the mode line.")


Kenichi Handa's avatar
Kenichi Handa committed
99
(defun mode-line-change-eol (event)
100
  "Cycle through the various possible kinds of end-of-line styles."
Kenichi Handa's avatar
Kenichi Handa committed
101
  (interactive "e")
102
  (with-selected-window (posn-window (event-start event))
Kenichi Handa's avatar
Kenichi Handa committed
103 104 105
    (let ((eol (coding-system-eol-type buffer-file-coding-system)))
      (set-buffer-file-coding-system
       (cond ((eq eol 0) 'dos) ((eq eol 1) 'mac) (t 'unix))))))
106 107 108 109 110 111

(defvar mode-line-eol-desc-cache nil)

(defun mode-line-eol-desc ()
  (let* ((eol (coding-system-eol-type buffer-file-coding-system))
	 (mnemonic (coding-system-eol-type-mnemonic buffer-file-coding-system))
112
	 (desc (assoc eol mode-line-eol-desc-cache)))
113 114 115 116 117 118
    (if (and desc (eq (cadr desc) mnemonic))
	(cddr desc)
      (if desc (setq mode-line-eol-desc-cache nil)) ;Flush the cache if stale.
      (setq desc
	    (propertize
	     mnemonic
Dan Nicolaescu's avatar
Dan Nicolaescu committed
119
	     'help-echo (format "End-of-line style: %s\nmouse-1 to cycle"
120
				(if (eq eol 0) "Unix-style LF"
121
				  (if (eq eol 1) "DOS-style CRLF"
122 123 124 125 126
				    (if (eq eol 2) "Mac-style CR"
				      "Undecided"))))
	     'keymap
	     (eval-when-compile
	       (let ((map (make-sparse-keymap)))
127
		 (define-key map [mode-line mouse-1] 'mode-line-change-eol)
128 129
		 map))
	     'mouse-face 'mode-line-highlight))
130 131 132
      (push (cons eol (cons mnemonic desc)) mode-line-eol-desc-cache)
      desc)))

133 134 135
(defvar mode-line-client
  `(""
    (:propertize ("" (:eval (if (frame-parameter nil 'client) "@" "")))
136
		 help-echo ,(purecopy "emacsclient frame")))
137
  "Mode-line control for identifying emacsclient frames.")
138
;;;###autoload
139
(put 'mode-line-client 'risky-local-variable t)
140

141 142
(defvar mode-line-mule-info
  `(""
143
    (current-input-method
144 145
     (:propertize ("" current-input-method-title)
		  help-echo (concat
146
			     ,(purecopy "Current input method: ")
147
			     current-input-method
148
			     ,(purecopy "\n\
149
mouse-2: Disable input method\n\
150
mouse-3: Describe current input method"))
151 152
		  local-map ,mode-line-input-method-map
		  mouse-face mode-line-highlight))
153
    ,(propertize
154
      "%z"
155
      'help-echo
156 157 158 159 160
      #'(lambda (window object point)
	  (with-current-buffer (window-buffer window)
	    ;; Don't show this tip if the coding system is nil,
	    ;; it reads like a bug, and is not useful anyway.
	    (when buffer-file-coding-system
161 162 163 164 165 166
	      (format "Buffer coding system %s\nmouse-1: describe coding system"
		      (if enable-multibyte-characters
			  (concat "(multi-byte): "
				  (symbol-name buffer-file-coding-system))
			(concat "(unibyte): "
				(symbol-name buffer-file-coding-system)))))))
167
      'mouse-face 'mode-line-highlight
168 169
      'local-map mode-line-coding-system-map)
    (:eval (mode-line-eol-desc)))
170 171 172 173 174
  "Mode-line control for displaying information of multilingual environment.
Normally it displays current input method (if any activated) and
mnemonics of the following coding systems:
  coding system for saving or writing the current buffer
  coding system for keyboard input (if Emacs is running on terminal)
Dave Love's avatar
Dave Love committed
175
  coding system for terminal output (if Emacs is running on terminal)"
176 177 178
  ;; Currently not:
  ;;  coding system for decoding output of buffer process (if any)
  ;;  coding system for encoding text to send to buffer process (if any)."
Dave Love's avatar
Dave Love committed
179
)
180

181
;;;###autoload
182
(put 'mode-line-mule-info 'risky-local-variable t)
183 184
(make-variable-buffer-local 'mode-line-mule-info)

185 186 187 188
;; MSDOS frames have window-system, but want the Fn identification.
(defun mode-line-frame-control ()
  "Compute mode-line control for frame identification.
Value is used for `mode-line-frame-identification', which see."
189 190
  (if (or (null window-system)
	  (eq window-system 'pc))
191 192 193
      "-%F  "
    "  "))

194 195
;; We need to defer the call to mode-line-frame-control to the time
;; the mode line is actually displayed.
196 197
(defvar mode-line-frame-identification '(:eval (mode-line-frame-control))
  "Mode-line control to describe the current frame.")
198
;;;###autoload
199
(put 'mode-line-frame-identification 'risky-local-variable t)
200

201 202
(defvar mode-line-process nil "\
Mode-line control for displaying info on process status.
Richard M. Stallman's avatar
Richard M. Stallman committed
203 204
Normally nil in most modes, since there is no process to display.")

205
;;;###autoload
206
(put 'mode-line-process 'risky-local-variable t)
Richard M. Stallman's avatar
Richard M. Stallman committed
207 208
(make-variable-buffer-local 'mode-line-process)

209 210
(defvar mode-line-modified
  (list (propertize
211 212
	 "%1*"
	 'help-echo (purecopy (lambda (window object point)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
213
 				(format "Buffer is %s\nmouse-1 toggles"
214 215 216
					(save-selected-window
					  (select-window window)
					  (if buffer-read-only
Dan Nicolaescu's avatar
Dan Nicolaescu committed
217 218
					      "read-only"
					    "writable")))))
219
	 'local-map (purecopy (make-mode-line-mouse-map
220
			       'mouse-1
221 222
			       #'mode-line-toggle-read-only))
	 'mouse-face 'mode-line-highlight)
223 224 225
	(propertize
	 "%1+"
	 'help-echo  (purecopy (lambda (window object point)
226
				 (format "Buffer is %sodified\nmouse-1 toggles modified state"
227 228 229
					 (save-selected-window
					   (select-window window)
					   (if (buffer-modified-p)
230 231
					     "m"
					   "not m")))))
232
	 'local-map (purecopy (make-mode-line-mouse-map
233
			       'mouse-1 #'mode-line-toggle-modified))
234
	 'mouse-face 'mode-line-highlight))
Richard M. Stallman's avatar
Richard M. Stallman committed
235 236
  "Mode-line control for displaying whether current buffer is modified.")

237
;;;###autoload
238
(put 'mode-line-modified 'risky-local-variable t)
Richard M. Stallman's avatar
Richard M. Stallman committed
239 240
(make-variable-buffer-local 'mode-line-modified)

241 242
(defvar mode-line-remote
  (list (propertize
243
	 "%1@"
244
	 'mouse-face 'mode-line-highlight
245 246 247 248
	 'help-echo (purecopy (lambda (window object point)
 				(format "%s"
					(save-selected-window
					  (select-window window)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
249
					  (concat
250 251 252 253
					   (if (file-remote-p default-directory)
					       "Current directory is remote: "
					     "Current directory is local: ")
					   default-directory)))))))
254
  "Mode-line flag to show if default-directory for current buffer is remote.")
255
;;;###autoload
256
(put 'mode-line-remote 'risky-local-variable t)
257 258 259

(make-variable-buffer-local 'mode-line-remote)

260 261
;; Actual initialization is below.
(defvar mode-line-position nil
Kenichi Handa's avatar
Kenichi Handa committed
262 263 264
  "Mode-line control for displaying the position in the buffer.
Normally displays the buffer percentage and, optionally, the
buffer size, the line number and the column number.")
265
;;;###autoload
266
(put 'mode-line-position 'risky-local-variable t)
267 268 269

(defvar mode-line-modes nil
  "Mode-line control for displaying major and minor modes.")
270
;;;###autoload
271
(put 'mode-line-modes 'risky-local-variable t)
272

273 274 275
(defvar mode-line-mode-menu (make-sparse-keymap "Minor Modes") "\
Menu of mode operations in the mode line.")

Kenichi Handa's avatar
Kenichi Handa committed
276
(defvar mode-line-major-mode-keymap
277
  (let ((map (make-sparse-keymap)))
278
    (define-key map [mode-line down-mouse-1]
279
      `(menu-item ,(purecopy "Menu Bar") ignore
280
        :filter (lambda (_) (mouse-menu-major-mode-map))))
281
    (define-key map [mode-line mouse-2] 'describe-mode)
282
    (define-key map [mode-line down-mouse-3] mode-line-mode-menu)
283
    map) "\
284 285
Keymap to display on major mode.")

Kenichi Handa's avatar
Kenichi Handa committed
286
(defvar mode-line-minor-mode-keymap
287
  (let ((map (make-sparse-keymap)))
288
    (define-key map [mode-line down-mouse-1] 'mouse-minor-mode-menu)
289
    (define-key map [mode-line mouse-2] 'mode-line-minor-mode-help)
290 291
    (define-key map [mode-line down-mouse-3] mode-line-mode-menu)
    (define-key map [header-line down-mouse-3] mode-line-mode-menu)
292
    map) "\
293 294
Keymap to display on minor modes.")

295 296 297 298 299
(defvar mode-line-column-line-number-mode-map
  (let ((map (make-sparse-keymap))
	(menu-map (make-sparse-keymap "Toggle Line and Column Number Display")))
    (define-key menu-map [line-number-mode]
      `(menu-item ,(purecopy "Display Line Numbers") line-number-mode
300
		  :help ,(purecopy "Toggle displaying line numbers in the mode-line")
301 302 303
		  :button (:toggle . line-number-mode)))
    (define-key menu-map [column-number-mode]
      `(menu-item ,(purecopy "Display Column Numbers") column-number-mode
304
		  :help ,(purecopy "Toggle displaying column numbers in the mode-line")
305 306 307 308 309
		  :button (:toggle . column-number-mode)))
    (define-key map [mode-line down-mouse-1] menu-map)
    map) "\
Keymap to display on column and line numbers.")

310 311 312
(let* ((help-echo
	;; The multi-line message doesn't work terribly well on the
	;; bottom mode line...  Better ideas?
313 314 315
	;; 	  "\
	;; mouse-1: select window, mouse-2: delete others, mouse-3: delete,
	;; drag-mouse-1: resize, C-mouse-2: split horizontally"
Dan Nicolaescu's avatar
Dan Nicolaescu committed
316 317 318
	"mouse-1: Select (drag to resize)\n\
mouse-2: Make current window occupy the whole frame\n\
mouse-3: Remove current window from display")
319
       (recursive-edit-help-echo "Recursive edit, type C-M-c to get out")
320 321 322 323 324 325
       (dashes (propertize "--" 'help-echo help-echo))
       (standard-mode-line-format
	(list
	 "%e"
	 (propertize "-" 'help-echo help-echo)
	 'mode-line-mule-info
Karoly Lorentey's avatar
Karoly Lorentey committed
326
	 'mode-line-client
327
	 'mode-line-modified
328
	 'mode-line-remote
329 330 331 332 333 334 335 336
	 'mode-line-frame-identification
	 'mode-line-buffer-identification
	 (propertize "   " 'help-echo help-echo)
	 'mode-line-position
	 '(vc-mode vc-mode)
	 (propertize "  " 'help-echo help-echo)
	 'mode-line-modes
	 `(which-func-mode ("" which-func-format ,dashes))
337
	 `(global-mode-string ("" global-mode-string ,dashes))
338 339 340
	 (propertize "-%-" 'help-echo help-echo)))
       (standard-mode-line-modes
	(list
341
	 (propertize "%[" 'help-echo recursive-edit-help-echo)
342
	 (propertize "(" 'help-echo help-echo)
343
	 `(:propertize ("" mode-name)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
344 345 346 347
		       help-echo "Major mode\n\
mouse-1: Display major mode menu\n\
mouse-2: Show help for major mode\n\
mouse-3: Toggle minor modes"
348 349 350 351 352
		       mouse-face mode-line-highlight
		       local-map ,mode-line-major-mode-keymap)
	 '("" mode-line-process)
	 `(:propertize ("" minor-mode-alist)
		       mouse-face mode-line-highlight
Dan Nicolaescu's avatar
Dan Nicolaescu committed
353 354 355 356
		       help-echo "Minor mode\n\
mouse-1: Display minor mode menu\n\
mouse-2: Show help for minor mode\n\
mouse-3: Toggle minor modes"
357
		       local-map ,mode-line-minor-mode-keymap)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
358
	 (propertize "%n" 'help-echo "mouse-2: Remove narrowing from the current buffer"
359 360 361
		     'mouse-face 'mode-line-highlight
		     'local-map (make-mode-line-mouse-map
				 'mouse-2 #'mode-line-widen))
362
	 (propertize ")" 'help-echo help-echo)
363
	 (propertize "%]" 'help-echo recursive-edit-help-echo)
364
	 (propertize "--" 'help-echo help-echo)))
Karoly Lorentey's avatar
Karoly Lorentey committed
365

366
       (standard-mode-line-position
367 368 369
	`((-3 ,(propertize
		"%p"
		'local-map mode-line-column-line-number-mode-map
370
		'mouse-face 'mode-line-highlight
371 372 373
		;; XXX needs better description
		'help-echo "Size indication mode\n\
mouse-1: Display Line and Column Mode Menu"))
374
	  (size-indication-mode
Dan Nicolaescu's avatar
Dan Nicolaescu committed
375
	   (8 ,(propertize
Dan Nicolaescu's avatar
Dan Nicolaescu committed
376
		" of %I"
377
		'local-map mode-line-column-line-number-mode-map
378
		'mouse-face 'mode-line-highlight
Dan Nicolaescu's avatar
Dan Nicolaescu committed
379
		;; XXX needs better description
380 381
		'help-echo "Size indication mode\n\
mouse-1: Display Line and Column Mode Menu")))
382 383
	  (line-number-mode
	   ((column-number-mode
Dan Nicolaescu's avatar
Dan Nicolaescu committed
384 385
	     (10 ,(propertize
		   " (%l,%c)"
386
		   'local-map mode-line-column-line-number-mode-map
387
		   'mouse-face 'mode-line-highlight
388 389
		   'help-echo "Line number and Column number\n\
mouse-1: Display Line and Column Mode Menu"))
Dan Nicolaescu's avatar
Dan Nicolaescu committed
390 391
	     (6 ,(propertize
		  " L%l"
392
		  'local-map mode-line-column-line-number-mode-map
393
		  'mouse-face 'mode-line-highlight
394 395
		  'help-echo "Line Number\n\
mouse-1: Display Line and Column Mode Menu"))))
396
	   ((column-number-mode
Dan Nicolaescu's avatar
Dan Nicolaescu committed
397 398
	     (5 ,(propertize
		  " C%c"
399
		  'local-map mode-line-column-line-number-mode-map
400
		  'mouse-face 'mode-line-highlight
401 402
		  'help-echo "Column number\n\
mouse-1: Display Line and Column Mode Menu"))))))))
403 404 405 406 407 408 409 410 411 412 413 414

  (setq-default mode-line-format standard-mode-line-format)
  (put 'mode-line-format 'standard-value
       (list `(quote ,standard-mode-line-format)))

  (setq-default mode-line-modes standard-mode-line-modes)
  (put 'mode-line-modes 'standard-value
       (list `(quote ,standard-mode-line-modes)))

  (setq-default mode-line-position standard-mode-line-position)
  (put 'mode-line-position 'standard-value
       (list `(quote ,standard-mode-line-position))))
Richard M. Stallman's avatar
Richard M. Stallman committed
415

416 417 418 419 420 421 422 423 424 425 426 427 428
(defvar mode-line-buffer-identification-keymap
  ;; Add menu of buffer operations to the buffer identification part
  ;; of the mode line.or header line.
  (let ((map (make-sparse-keymap)))
    ;; Bind down- events so that the global keymap won't ``shine
    ;; through''.
    (define-key map [mode-line mouse-1] 'mode-line-previous-buffer)
    (define-key map [header-line down-mouse-1] 'ignore)
    (define-key map [header-line mouse-1] 'mode-line-previous-buffer)
    (define-key map [mode-line mouse-3] 'mode-line-next-buffer)
    (define-key map [header-line down-mouse-3] 'ignore)
    (define-key map [header-line mouse-3] 'mode-line-next-buffer)
    map) "\
429
Keymap for what is displayed by `mode-line-buffer-identification'.")
430

431 432 433 434
(defun propertized-buffer-identification (fmt)
  "Return a list suitable for `mode-line-buffer-identification'.
FMT is a format specifier such as \"%12b\".  This function adds
text properties for face, help-echo, and local-map to it."
435
  (list (propertize fmt
436 437
		    'face 'mode-line-buffer-id
		    'help-echo
438
		    (purecopy "Buffer name\n\
Dan Nicolaescu's avatar
Dan Nicolaescu committed
439 440
mouse-1: previous buffer\n\
mouse-3: next buffer")
441 442 443
		    'mouse-face 'mode-line-highlight
		    'local-map mode-line-buffer-identification-keymap)))

444
(defvar mode-line-buffer-identification (propertized-buffer-identification "%12b") "\
445 446 447 448 449
Mode-line control for identifying the buffer being displayed.
Its default value is (\"%12b\") with some text properties added.
Major modes that edit things other than ordinary files may change this
\(e.g. Info, Dired,...)")

450
;;;###autoload
451
(put 'mode-line-buffer-identification 'risky-local-variable t)
452 453
(make-variable-buffer-local 'mode-line-buffer-identification)

454 455
(defun unbury-buffer () "\
Switch to the last buffer in the buffer list."
456 457 458
  (interactive)
  (switch-to-buffer (last-buffer)))

459
(defun mode-line-unbury-buffer (event) "\
460
Call `unbury-buffer' in this window."
461 462 463
  (interactive "e")
  (save-selected-window
    (select-window (posn-window (event-start event)))
464
    (unbury-buffer)))
465 466

(defun mode-line-bury-buffer (event) "\
Sam Steingold's avatar
Sam Steingold committed
467
Like `bury-buffer', but temporarily select EVENT's window."
468 469 470 471
  (interactive "e")
  (save-selected-window
    (select-window (posn-window (event-start event)))
    (bury-buffer)))
472

473 474
(defun mode-line-other-buffer () "\
Switch to the most recently selected buffer other than the current one."
475 476 477
  (interactive)
  (switch-to-buffer (other-buffer)))

478 479 480 481 482 483 484 485 486 487 488 489 490 491
(defun mode-line-next-buffer (event)
  "Like `next-buffer', but temporarily select EVENT's window."
  (interactive "e")
  (save-selected-window
    (select-window (posn-window (event-start event)))
    (next-buffer)))

(defun mode-line-previous-buffer (event)
  "Like `previous-buffer', but temporarily select EVENT's window."
  (interactive "e")
  (save-selected-window
    (select-window (posn-window (event-start event)))
    (previous-buffer)))

Dave Love's avatar
Dave Love committed
492 493
(defmacro bound-and-true-p (var)
  "Return the value of symbol VAR if it is bound, else nil."
494
  `(and (boundp (quote ,var)) ,var))
Dave Love's avatar
Dave Love committed
495

496 497
;; Use mode-line-mode-menu for local minor-modes only.
;; Global ones can go on the menubar (Options --> Show/Hide).
498
(define-key mode-line-mode-menu [overwrite-mode]
499
  `(menu-item ,(purecopy "Overwrite (Ovwrt)") overwrite-mode
500
	      :help ,(purecopy "Overwrite mode: typed characters replace existing text")
501
	      :button (:toggle . overwrite-mode)))
502
(define-key mode-line-mode-menu [outline-minor-mode]
503
  `(menu-item ,(purecopy "Outline (Outl)") outline-minor-mode
Dan Nicolaescu's avatar
Dan Nicolaescu committed
504
	      ;; XXX: This needs a good, brief description.
505
	      :help ,(purecopy "")
506 507
	      :button (:toggle . (bound-and-true-p outline-minor-mode))))
(define-key mode-line-mode-menu [highlight-changes-mode]
508
  `(menu-item ,(purecopy "Highlight changes (Chg)") highlight-changes-mode
509
	      :help ,(purecopy "Show changes in the buffer in a distinctive color")
510
	      :button (:toggle . (bound-and-true-p highlight-changes-mode))))
511
(define-key mode-line-mode-menu [hide-ifdef-mode]
512
  `(menu-item ,(purecopy "Hide ifdef (Ifdef)") hide-ifdef-mode
513
	      :help ,(purecopy "Show/Hide code within #ifdef constructs")
514
	      :button (:toggle . (bound-and-true-p hide-ifdef-mode))))
515 516
(define-key mode-line-mode-menu [glasses-mode]
  `(menu-item ,(purecopy "Glasses (o^o)") glasses-mode
517
	      :help ,(purecopy "Insert virtual separators to make long identifiers easy to read")
518
	      :button (:toggle . (bound-and-true-p glasses-mode))))
519
(define-key mode-line-mode-menu [font-lock-mode]
520
  `(menu-item ,(purecopy "Font Lock") font-lock-mode
521
	      :help ,(purecopy "Syntax coloring")
522 523
	      :button (:toggle . font-lock-mode)))
(define-key mode-line-mode-menu [flyspell-mode]
524
  `(menu-item ,(purecopy "Flyspell (Fly)") flyspell-mode
525
	      :help ,(purecopy "Spell checking on the fly")
526
	      :button (:toggle . (bound-and-true-p flyspell-mode))))
527 528
(define-key mode-line-mode-menu [auto-revert-tail-mode]
  `(menu-item ,(purecopy "Auto revert tail (Tail)") auto-revert-tail-mode
529
	      :help ,(purecopy "Revert the tail of the buffer when buffer grows")
530
	      :enable (buffer-file-name)
531
	      :button (:toggle . (bound-and-true-p auto-revert-tail-mode))))
532
(define-key mode-line-mode-menu [auto-revert-mode]
533
  `(menu-item ,(purecopy "Auto revert (ARev)") auto-revert-mode
534
	      :help ,(purecopy "Revert the buffer when the file on disk changes")
535
	      :button (:toggle . (bound-and-true-p auto-revert-mode))))
536 537
(define-key mode-line-mode-menu [auto-fill-mode]
  `(menu-item ,(purecopy "Auto fill (Fill)") auto-fill-mode
538
	      :help ,(purecopy "Automatically insert new lines")
539
	      :button (:toggle . auto-fill-function)))
540
(define-key mode-line-mode-menu [abbrev-mode]
541
  `(menu-item ,(purecopy "Abbrev (Abbrev)") abbrev-mode
542
	      :help ,(purecopy "Automatically expand abbreviations")
543
	      :button (:toggle . abbrev-mode)))
544

545
(defun mode-line-minor-mode-help (event)
546
  "Describe minor mode for EVENT on minor modes area of the mode line."
547 548 549 550
  (interactive "@e")
  (let ((indicator (car (nth 4 (car (cdr event))))))
    (describe-minor-mode-from-indicator indicator)))

551 552 553
(defvar minor-mode-alist nil "\
Alist saying how to show minor modes in the mode line.
Each element looks like (VARIABLE STRING);
554
STRING is included in the mode line if VARIABLE's value is non-nil.
555 556 557

Actually, STRING need not be a string; any possible mode-line element
is okay.  See `mode-line-format'.")
558
;;;###autoload
559
(put 'minor-mode-alist 'risky-local-variable t)
560 561
;; Don't use purecopy here--some people want to change these strings.
(setq minor-mode-alist
562 563 564 565 566
      '((abbrev-mode " Abbrev")
        (overwrite-mode overwrite-mode)
        (auto-fill-function " Fill")
        ;; not really a minor mode...
        (defining-kbd-macro " Def")))
567

Richard M. Stallman's avatar
Richard M. Stallman committed
568 569 570 571 572 573 574 575
;; These variables are used by autoloadable packages.
;; They are defined here so that they do not get overridden
;; by the loading of those packages.

;; Names in directory that end in one of these
;; are ignored in completion,
;; making it more likely you will get a unique match.
(setq completion-ignored-extensions
576
      (append
577
       (cond ((memq system-type '(ms-dos windows-nt))
578
	      (mapcar 'purecopy
579
	      '(".o" "~" ".bin" ".bak" ".obj" ".map" ".ico" ".pif" ".lnk"
580
		".a" ".ln" ".blg" ".bbl" ".dll" ".drv" ".vxd" ".386")))
581
	     (t
582
	      (mapcar 'purecopy
583
	      '(".o" "~" ".bin" ".lbin" ".so"
584 585
		".a" ".ln" ".blg" ".bbl"))))
       (mapcar 'purecopy
586 587
       '(".elc" ".lof"
	 ".glo" ".idx" ".lot"
588 589
	 ;; VCS metadata directories
	 ".svn/" ".hg/" ".git/" ".bzr/" "CVS/" "_darcs/" "_MTN/"
590
	 ;; TeX-related
591
	 ".fmt" ".tfm"
592 593
	 ;; Java compiled
	 ".class"
594 595
	 ;; CLISP
	 ".fas" ".lib" ".mem"
596
	 ;; CMUCL
597
	 ".x86f" ".sparcf"
Kenichi Handa's avatar
Kenichi Handa committed
598
         ;; Other CL implementations (Allegro, LispWorks, OpenMCL)
599
         ".fasl" ".ufsl" ".fsl" ".dxl" ".pfsl" ".dfsl"
600
	 ".p64fsl" ".d64fsl" ".dx64fsl"
601 602
	 ;; Libtool
	 ".lo" ".la"
603 604
	 ;; Gettext
	 ".gmo" ".mo"
605
	 ;; Texinfo-related
Kenichi Handa's avatar
Kenichi Handa committed
606 607 608
	 ;; This used to contain .log, but that's commonly used for log
	 ;; files you do want to see, not just TeX stuff.  -- fx
	 ".toc" ".aux"
609
	 ".cp" ".fn" ".ky" ".pg" ".tp" ".vr"
610 611
	 ".cps" ".fns" ".kys" ".pgs" ".tps" ".vrs"
	 ;; Python byte-compiled
612
	 ".pyc" ".pyo"))))
Richard M. Stallman's avatar
Richard M. Stallman committed
613

614 615 616 617 618 619 620 621
;; Suffixes used for executables.
(setq exec-suffixes
      (cond
       ((memq system-type '(ms-dos windows-nt))
	'(".exe" ".com" ".bat" ".cmd" ".btm" ""))
       (t
	'(""))))

622 623
;; Packages should add to this list appropriately when they are
;; loaded, rather than listing everything here.
Richard M. Stallman's avatar
Richard M. Stallman committed
624
(setq debug-ignored-errors
625
      `(beginning-of-line beginning-of-buffer end-of-line
Richard M. Stallman's avatar
Richard M. Stallman committed
626
	end-of-buffer end-of-file buffer-read-only
627
	file-supersession
628 629 630 631 632 633 634 635 636 637 638 639 640 641 642
      	,(purecopy "^Previous command was not a yank$")
	,(purecopy "^Minibuffer window is not active$")
	,(purecopy "^No previous history search regexp$")
	,(purecopy "^No later matching history item$")
	,(purecopy "^No earlier matching history item$")
	,(purecopy "^End of history; no default available$")
	,(purecopy "^End of defaults; no next item$")
	,(purecopy "^Beginning of history; no preceding item$")
	,(purecopy "^No recursive edit is in progress$")
	,(purecopy "^Changes to be undone are outside visible portion of buffer$")
	,(purecopy "^No undo information in this buffer$")
	,(purecopy "^No further undo information")
	,(purecopy "^Save not confirmed$")
	,(purecopy "^Recover-file cancelled\\.$")
	,(purecopy "^Cannot switch buffers in a dedicated window$")
643
        ))
Richard M. Stallman's avatar
Richard M. Stallman committed
644 645 646 647


(make-variable-buffer-local 'indent-tabs-mode)

648
;; We have base64 and md5 functions built in now.
649 650 651 652
(provide 'base64)
(provide 'md5)
(provide 'overlay '(display syntax-table field))
(provide 'text-properties '(display syntax-table field point-entered))
653

654 655
(define-key esc-map "\t" 'complete-symbol)

Richard M. Stallman's avatar
Richard M. Stallman committed
656 657 658 659
;; Reduce total amount of space we must allocate during this function
;; that we will not need to keep permanently.
(garbage-collect)

660

Richard M. Stallman's avatar
Richard M. Stallman committed
661 662
(setq help-event-list '(help f1))

663 664
(make-variable-buffer-local 'minor-mode-overriding-map-alist)

665 666
;; From frame.c
(global-set-key [switch-frame] 'handle-switch-frame)
667 668 669 670 671
(global-set-key [select-window] 'handle-select-window)

;; FIXME: Do those 3 events really ever reach the global-map ?
;;        It seems that they can't because they're handled via
;;        special-event-map which is used at very low-level.  -stef
672 673 674 675 676
(global-set-key [delete-frame] 'handle-delete-frame)
(global-set-key [iconify-frame] 'ignore-event)
(global-set-key [make-frame-visible] 'ignore-event)


Richard M. Stallman's avatar
Richard M. Stallman committed
677 678 679
;These commands are defined in editfns.c
;but they are not assigned to keys there.
(put 'narrow-to-region 'disabled t)
680

681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737
;; Moving with arrows in bidi-sensitive direction.
(defun right-char (&optional n)
  "Move point N characters to the right (to the left if N is negative).
On reaching beginning or end of buffer, stop and signal error.

Depending on the bidirectional context, this may move either forward
or backward in the buffer.  This is in contrast with \\[forward-char]
and \\[backward-char], which see."
  (interactive "^p")
  (if (eq (current-bidi-paragraph-direction) 'left-to-right)
      (forward-char n)
    (backward-char n)))

(defun left-char ( &optional n)
  "Move point N characters to the left (to the right if N is negative).
On reaching beginning or end of buffer, stop and signal error.

Depending on the bidirectional context, this may move either backward
or forward in the buffer.  This is in contrast with \\[backward-char]
and \\[forward-char], which see."
  (interactive "^p")
  (if (eq (current-bidi-paragraph-direction) 'left-to-right)
      (backward-char n)
    (forward-char n)))

(defun right-word (&optional n)
  "Move point N words to the right (to the left if N is negative).

Depending on the bidirectional context, this may move either forward
or backward in the buffer.  This is in contrast with \\[forward-word]
and \\[backward-word], which see.

Value is normally t.
If an edge of the buffer or a field boundary is reached, point is left there
there and the function returns nil.  Field boundaries are not noticed
if `inhibit-field-text-motion' is non-nil."
  (interactive "^p")
  (if (eq (current-bidi-paragraph-direction) 'left-to-right)
      (forward-word n)
    (backward-word n)))

(defun left-word (&optional n)
  "Move point N words to the left (to the right if N is negative).

Depending on the bidirectional context, this may move either backward
or forward in the buffer.  This is in contrast with \\[backward-word]
and \\[forward-word], which see.

Value is normally t.
If an edge of the buffer or a field boundary is reached, point is left there
there and the function returns nil.  Field boundaries are not noticed
if `inhibit-field-text-motion' is non-nil."
  (interactive "^p")
  (if (eq (current-bidi-paragraph-direction) 'left-to-right)
      (backward-word n)
    (forward-word n)))

738 739 740 741 742 743
(defvar narrow-map (make-sparse-keymap)
  "Keymap for narrowing commands.")
(define-key ctl-x-map "n" narrow-map)

(define-key narrow-map "n" 'narrow-to-region)
(define-key narrow-map "w" 'widen)
Richard M. Stallman's avatar
Richard M. Stallman committed
744

745 746 747 748
;; Quitting
(define-key global-map "\e\e\e" 'keyboard-escape-quit)
(define-key global-map "\C-g" 'keyboard-quit)

749 750 751 752
;; Used to be in termdev.el: when using several terminals, make C-z
;; suspend only the relevant terminal.
(substitute-key-definition 'suspend-emacs 'suspend-frame global-map)

Richard M. Stallman's avatar
Richard M. Stallman committed
753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772
(define-key global-map "\C-j" 'newline-and-indent)
(define-key global-map "\C-m" 'newline)
(define-key global-map "\C-o" 'open-line)
(define-key esc-map "\C-o" 'split-line)
(define-key global-map "\C-q" 'quoted-insert)
(define-key esc-map "^" 'delete-indentation)
(define-key esc-map "\\" 'delete-horizontal-space)
(define-key esc-map "m" 'back-to-indentation)
(define-key ctl-x-map "\C-o" 'delete-blank-lines)
(define-key esc-map " " 'just-one-space)
(define-key esc-map "z" 'zap-to-char)
(define-key esc-map "=" 'count-lines-region)
(define-key ctl-x-map "=" 'what-cursor-position)
(define-key esc-map ":" 'eval-expression)
;; Define ESC ESC : like ESC : for people who type ESC ESC out of habit.
(define-key esc-map "\M-:" 'eval-expression)
;; Changed from C-x ESC so that function keys work following C-x.
(define-key ctl-x-map "\e\e" 'repeat-complex-command)
;; New binding analogous to M-:.
(define-key ctl-x-map "\M-:" 'repeat-complex-command)
773 774
(define-key ctl-x-map "u" 'undo)
(put 'undo :advertised-binding [?\C-x ?u])
Richard M. Stallman's avatar
Richard M. Stallman committed
775 776 777
;; Many people are used to typing C-/ on X terminals and getting C-_.
(define-key global-map [?\C-/] 'undo)
(define-key global-map "\C-_" 'undo)
778 779 780 781
;; Richard said that we should not use C-x <uppercase letter> and I have
;; no idea whereas to bind it.  Any suggestion welcome.  -stef
;; (define-key ctl-x-map "U" 'undo-only)

Richard M. Stallman's avatar
Richard M. Stallman committed
782 783
(define-key esc-map "!" 'shell-command)
(define-key esc-map "|" 'shell-command-on-region)
784
(define-key esc-map "&" 'async-shell-command)
Richard M. Stallman's avatar
Richard M. Stallman committed
785

786 787 788 789
(define-key ctl-x-map [right] 'next-buffer)
(define-key ctl-x-map [C-right] 'next-buffer)
(define-key ctl-x-map [left] 'previous-buffer)
(define-key ctl-x-map [C-left] 'previous-buffer)
790

791 792 793 794 795 796 797 798
(let ((map minibuffer-local-map))
  (define-key map "\en"   'next-history-element)
  (define-key map [next]  'next-history-element)
  (define-key map [down]  'next-history-element)
  (define-key map "\ep"   'previous-history-element)
  (define-key map [prior] 'previous-history-element)
  (define-key map [up]    'previous-history-element)
  (define-key map "\es"   'next-matching-history-element)
799 800 801 802
  (define-key map "\er"   'previous-matching-history-element)
  ;; Override the global binding (which calls indent-relative via
  ;; indent-for-tab-command).  The alignment that indent-relative tries to
  ;; do doesn't make much sense here since the prompt messes it up.
803
  (define-key map "\t"    'self-insert-command)
804
  (define-key map [C-tab] 'file-cache-minibuffer-complete))
Richard M. Stallman's avatar
Richard M. Stallman committed
805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835

(define-key global-map "\C-u" 'universal-argument)
(let ((i ?0))
  (while (<= i ?9)
    (define-key esc-map (char-to-string i) 'digit-argument)
    (setq i (1+ i))))
(define-key esc-map "-" 'negative-argument)
;; Define control-digits.
(let ((i ?0))
  (while (<= i ?9)
    (define-key global-map (read (format "[?\\C-%c]" i)) 'digit-argument)
    (setq i (1+ i))))
(define-key global-map [?\C--] 'negative-argument)
;; Define control-meta-digits.
(let ((i ?0))
  (while (<= i ?9)
    (define-key esc-map (read (format "[?\\C-%c]" i)) 'digit-argument)
    (setq i (1+ i))))
(define-key global-map [?\C-\M--] 'negative-argument)

(define-key global-map "\C-k" 'kill-line)
(define-key global-map "\C-w" 'kill-region)
(define-key esc-map "w" 'kill-ring-save)
(define-key esc-map "\C-w" 'append-next-kill)
(define-key global-map "\C-y" 'yank)
(define-key esc-map "y" 'yank-pop)

;; (define-key ctl-x-map "a" 'append-to-buffer)

(define-key global-map "\C-@" 'set-mark-command)
;; Many people are used to typing C-SPC and getting C-@.
836
(define-key global-map [?\C- ] 'set-mark-command)
Richard M. Stallman's avatar
Richard M. Stallman committed
837 838
(define-key ctl-x-map "\C-x" 'exchange-point-and-mark)
(define-key ctl-x-map "\C-@" 'pop-global-mark)
839
(define-key ctl-x-map [?\C- ] 'pop-global-mark)
Richard M. Stallman's avatar
Richard M. Stallman committed
840 841 842 843

(define-key global-map "\C-n" 'next-line)
(define-key global-map "\C-p" 'previous-line)
(define-key ctl-x-map "\C-n" 'set-goal-column)
844
(define-key global-map "\C-a" 'move-beginning-of-line)
845
(define-key global-map "\C-e" 'move-end-of-line)
Richard M. Stallman's avatar
Richard M. Stallman committed
846

847 848
(define-key ctl-x-map "`" 'next-error)

849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870
(defvar goto-map (make-sparse-keymap)
  "Keymap for navigation commands.")
(define-key esc-map "g" goto-map)

(define-key goto-map    "g" 'goto-line)
(define-key goto-map "\M-g" 'goto-line)
(define-key goto-map    "n" 'next-error)
(define-key goto-map "\M-n" 'next-error)
(define-key goto-map    "p" 'previous-error)
(define-key goto-map "\M-p" 'previous-error)

(defvar search-map (make-sparse-keymap)
  "Keymap for search related commands.")
(define-key esc-map "s" search-map)

(define-key search-map "o"  'occur)
(define-key search-map "hr" 'highlight-regexp)
(define-key search-map "hp" 'highlight-phrase)
(define-key search-map "hl" 'highlight-lines-matching-regexp)
(define-key search-map "hu" 'unhighlight-regexp)
(define-key search-map "hf" 'hi-lock-find-patterns)
(define-key search-map "hw" 'hi-lock-write-interactive-patterns)
871

Richard M. Stallman's avatar
Richard M. Stallman committed
872 873
;;(defun function-key-error ()
;;  (interactive)
874
;;  (error "That function key is not bound to anything"))
Richard M. Stallman's avatar
Richard M. Stallman committed
875 876 877 878

(define-key global-map [menu] 'execute-extended-command)
(define-key global-map [find] 'search-forward)

879 880
;; Don't do this.  We define <delete> in function-key-map instead.
;(define-key global-map [delete] 'backward-delete-char)
881

Richard M. Stallman's avatar
Richard M. Stallman committed
882
;; natural bindings for terminal keycaps --- defined in X keysym order
883
(define-key global-map [C-S-backspace]  'kill-whole-line)
884
(define-key global-map [home]		'move-beginning-of-line)
885
(define-key global-map [C-home]		'beginning-of-buffer)
Richard M. Stallman's avatar
Richard M. Stallman committed
886
(define-key global-map [M-home]		'beginning-of-buffer-other-window)
887
(define-key esc-map    [home]		'beginning-of-buffer-other-window)
888
(define-key global-map [left]		'left-char)
Richard M. Stallman's avatar
Richard M. Stallman committed
889
(define-key global-map [up]		'previous-line)
890
(define-key global-map [right]		'right-char)
Richard M. Stallman's avatar
Richard M. Stallman committed
891
(define-key global-map [down]		'next-line)
892 893
(define-key global-map [prior]		'scroll-down-command)
(define-key global-map [next]		'scroll-up-command)
Richard M. Stallman's avatar
Richard M. Stallman committed
894 895 896
(define-key global-map [C-up]		'backward-paragraph)
(define-key global-map [C-down]		'forward-paragraph)
(define-key global-map [C-prior]	'scroll-right)
897
(put 'scroll-left 'disabled t)
Richard M. Stallman's avatar
Richard M. Stallman committed
898 899
(define-key global-map [C-next]		'scroll-left)
(define-key global-map [M-next]		'scroll-other-window)
900
(define-key esc-map    [next]		'scroll-other-window)
Richard M. Stallman's avatar
Richard M. Stallman committed
901
(define-key global-map [M-prior]	'scroll-other-window-down)
902
(define-key esc-map    [prior]		'scroll-other-window-down)
903
(define-key esc-map [?\C-\S-v]		'scroll-other-window-down)
904
(define-key global-map [end]		'move-end-of-line)
905
(define-key global-map [C-end]		'end-of-buffer)
Richard M. Stallman's avatar
Richard M. Stallman committed
906
(define-key global-map [M-end]		'end-of-buffer-other-window)
907
(define-key esc-map    [end]		'end-of-buffer-other-window)
Richard M. Stallman's avatar
Richard M. Stallman committed
908 909