bindings.el 45.5 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,
4 5
;;   2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
;;   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 65 66
  (save-selected-window
    (select-window (posn-window (event-start event)))
    (widen)
    (force-mode-line-update)))


(defun mode-line-abbrev-mode (event)
  "Turn off `abbrev-mode' from the mode-line."
67
  (interactive "e")
Gerd Moellmann's avatar
Gerd Moellmann committed
68 69 70 71 72 73 74 75
  (save-selected-window
    (select-window (posn-window (event-start event)))
    (abbrev-mode)
    (force-mode-line-update)))


(defun mode-line-auto-fill-mode (event)
  "Turn off `auto-fill-mode' from the mode-line."
76
  (interactive "e")
Gerd Moellmann's avatar
Gerd Moellmann committed
77 78 79 80 81 82
  (save-selected-window
    (select-window (posn-window (event-start event)))
    (auto-fill-mode)
    (force-mode-line-update)))


83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
(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)))

102 103 104

(defvar mode-line-coding-system-map
  (let ((map (make-sparse-keymap)))
105
    (define-key map [mode-line mouse-1]
106 107 108 109 110 111 112 113 114 115 116
      (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
117
(defun mode-line-change-eol (event)
118
  "Cycle through the various possible kinds of end-of-line styles."
Kenichi Handa's avatar
Kenichi Handa committed
119
  (interactive "e")
120
  (with-selected-window (posn-window (event-start event))
Kenichi Handa's avatar
Kenichi Handa committed
121 122 123
    (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))))))
124 125 126 127 128 129

(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))
130
	 (desc (assoc eol mode-line-eol-desc-cache)))
131 132 133 134 135 136
    (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
137
	     'help-echo (format "End-of-line style: %s\nmouse-1 to cycle"
138
				(if (eq eol 0) "Unix-style LF"
139
				  (if (eq eol 1) "DOS-style CRLF"
140 141 142 143 144
				    (if (eq eol 2) "Mac-style CR"
				      "Undecided"))))
	     'keymap
	     (eval-when-compile
	       (let ((map (make-sparse-keymap)))
145
		 (define-key map [mode-line mouse-1] 'mode-line-change-eol)
146 147
		 map))
	     'mouse-face 'mode-line-highlight))
148 149 150
      (push (cons eol (cons mnemonic desc)) mode-line-eol-desc-cache)
      desc)))

151 152 153
(defvar mode-line-client
  `(""
    (:propertize ("" (:eval (if (frame-parameter nil 'client) "@" "")))
154
		 help-echo ,(purecopy "emacsclient frame")))
155
  "Mode-line control for identifying emacsclient frames.")
156
;;;###autoload
157
(put 'mode-line-client 'risky-local-variable t)
158

159 160
(defvar mode-line-mule-info
  `(""
161
    (current-input-method
162 163
     (:propertize ("" current-input-method-title)
		  help-echo (concat
164
			     ,(purecopy "Current input method: ")
165
			     current-input-method
166
			     ,(purecopy "\n\
167
mouse-2: Disable input method\n\
168
mouse-3: Describe current input method"))
169 170
		  local-map ,mode-line-input-method-map
		  mouse-face mode-line-highlight))
171
    ,(propertize
172
      "%z"
173
      'help-echo
174 175 176 177 178
      #'(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
179 180 181 182 183 184
	      (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)))))))
185
      'mouse-face 'mode-line-highlight
186 187
      'local-map mode-line-coding-system-map)
    (:eval (mode-line-eol-desc)))
188 189 190 191 192
  "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
193
  coding system for terminal output (if Emacs is running on terminal)"
194 195 196
  ;; 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
197
)
198

199
;;;###autoload
200
(put 'mode-line-mule-info 'risky-local-variable t)
201 202
(make-variable-buffer-local 'mode-line-mule-info)

203 204 205 206
;; 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."
207 208
  (if (or (null window-system)
	  (eq window-system 'pc))
209 210 211
      "-%F  "
    "  "))

212 213
;; We need to defer the call to mode-line-frame-control to the time
;; the mode line is actually displayed.
214 215
(defvar mode-line-frame-identification '(:eval (mode-line-frame-control))
  "Mode-line control to describe the current frame.")
216
;;;###autoload
217
(put 'mode-line-frame-identification 'risky-local-variable t)
218

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

223
;;;###autoload
224
(put 'mode-line-process 'risky-local-variable t)
Richard M. Stallman's avatar
Richard M. Stallman committed
225 226
(make-variable-buffer-local 'mode-line-process)

227 228
(defvar mode-line-modified
  (list (propertize
229 230
	 "%1*"
	 'help-echo (purecopy (lambda (window object point)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
231
 				(format "Buffer is %s\nmouse-1 toggles"
232 233 234
					(save-selected-window
					  (select-window window)
					  (if buffer-read-only
Dan Nicolaescu's avatar
Dan Nicolaescu committed
235 236
					      "read-only"
					    "writable")))))
237
	 'local-map (purecopy (make-mode-line-mouse-map
238
			       'mouse-1
239 240
			       #'mode-line-toggle-read-only))
	 'mouse-face 'mode-line-highlight)
241 242 243
	(propertize
	 "%1+"
	 'help-echo  (purecopy (lambda (window object point)
244
				 (format "Buffer is %sodified\nmouse-1 toggles modified state"
245 246 247
					 (save-selected-window
					   (select-window window)
					   (if (buffer-modified-p)
248 249
					     "m"
					   "not m")))))
250
	 'local-map (purecopy (make-mode-line-mouse-map
251
			       'mouse-1 #'mode-line-toggle-modified))
252
	 'mouse-face 'mode-line-highlight))
Richard M. Stallman's avatar
Richard M. Stallman committed
253 254
  "Mode-line control for displaying whether current buffer is modified.")

255
;;;###autoload
256
(put 'mode-line-modified 'risky-local-variable t)
Richard M. Stallman's avatar
Richard M. Stallman committed
257 258
(make-variable-buffer-local 'mode-line-modified)

259 260
(defvar mode-line-remote
  (list (propertize
261
	 "%1@"
262
	 'mouse-face 'mode-line-highlight
263 264 265 266
	 'help-echo (purecopy (lambda (window object point)
 				(format "%s"
					(save-selected-window
					  (select-window window)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
267
					  (concat
268 269 270 271
					   (if (file-remote-p default-directory)
					       "Current directory is remote: "
					     "Current directory is local: ")
					   default-directory)))))))
272
  "Mode-line flag to show if default-directory for current buffer is remote.")
273
;;;###autoload
274
(put 'mode-line-remote 'risky-local-variable t)
275 276 277

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

278 279
;; Actual initialization is below.
(defvar mode-line-position nil
Kenichi Handa's avatar
Kenichi Handa committed
280 281 282
  "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.")
283
;;;###autoload
284
(put 'mode-line-position 'risky-local-variable t)
285 286 287

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

291 292 293
(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
294
(defvar mode-line-major-mode-keymap
295
  (let ((map (make-sparse-keymap)))
296
    (define-key map [mode-line down-mouse-1]
297
      `(menu-item ,(purecopy "Menu Bar") ignore
298
        :filter (lambda (_) (mouse-menu-major-mode-map))))
299
    (define-key map [mode-line mouse-2] 'describe-mode)
300
    (define-key map [mode-line down-mouse-3] mode-line-mode-menu)
301
    map) "\
302 303
Keymap to display on major mode.")

Kenichi Handa's avatar
Kenichi Handa committed
304
(defvar mode-line-minor-mode-keymap
305
  (let ((map (make-sparse-keymap)))
306
    (define-key map [mode-line down-mouse-1] 'mouse-minor-mode-menu)
307
    (define-key map [mode-line mouse-2] 'mode-line-minor-mode-help)
308 309
    (define-key map [mode-line down-mouse-3] mode-line-mode-menu)
    (define-key map [header-line down-mouse-3] mode-line-mode-menu)
310
    map) "\
311 312
Keymap to display on minor modes.")

313 314 315 316 317
(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
318
		  :help ,(purecopy "Toggle displaying line numbers in the mode-line")
319 320 321
		  :button (:toggle . line-number-mode)))
    (define-key menu-map [column-number-mode]
      `(menu-item ,(purecopy "Display Column Numbers") column-number-mode
322
		  :help ,(purecopy "Toggle displaying column numbers in the mode-line")
323 324 325 326 327
		  :button (:toggle . column-number-mode)))
    (define-key map [mode-line down-mouse-1] menu-map)
    map) "\
Keymap to display on column and line numbers.")

328 329 330
(let* ((help-echo
	;; The multi-line message doesn't work terribly well on the
	;; bottom mode line...  Better ideas?
331 332 333
	;; 	  "\
	;; 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
334 335 336
	"mouse-1: Select (drag to resize)\n\
mouse-2: Make current window occupy the whole frame\n\
mouse-3: Remove current window from display")
337
       (recursive-edit-help-echo "Recursive edit, type C-M-c to get out")
338 339 340 341 342 343
       (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
344
	 'mode-line-client
345
	 'mode-line-modified
346
	 'mode-line-remote
347 348 349 350 351 352 353 354
	 '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))
355
	 `(global-mode-string ("" global-mode-string ,dashes))
356 357 358
	 (propertize "-%-" 'help-echo help-echo)))
       (standard-mode-line-modes
	(list
359
	 (propertize "%[" 'help-echo recursive-edit-help-echo)
360
	 (propertize "(" 'help-echo help-echo)
361
	 `(:propertize ("" mode-name)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
362 363 364 365
		       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"
366 367 368 369 370
		       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
371 372 373 374
		       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"
375
		       local-map ,mode-line-minor-mode-keymap)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
376
	 (propertize "%n" 'help-echo "mouse-2: Remove narrowing from the current buffer"
377 378 379
		     'mouse-face 'mode-line-highlight
		     'local-map (make-mode-line-mouse-map
				 'mouse-2 #'mode-line-widen))
380
	 (propertize ")" 'help-echo help-echo)
381
	 (propertize "%]" 'help-echo recursive-edit-help-echo)
382
	 (propertize "--" 'help-echo help-echo)))
Karoly Lorentey's avatar
Karoly Lorentey committed
383

384
       (standard-mode-line-position
385 386 387
	`((-3 ,(propertize
		"%p"
		'local-map mode-line-column-line-number-mode-map
388
		'mouse-face 'mode-line-highlight
389 390 391
		;; XXX needs better description
		'help-echo "Size indication mode\n\
mouse-1: Display Line and Column Mode Menu"))
392
	  (size-indication-mode
Dan Nicolaescu's avatar
Dan Nicolaescu committed
393
	   (8 ,(propertize
Dan Nicolaescu's avatar
Dan Nicolaescu committed
394
		" of %I"
395
		'local-map mode-line-column-line-number-mode-map
396
		'mouse-face 'mode-line-highlight
Dan Nicolaescu's avatar
Dan Nicolaescu committed
397
		;; XXX needs better description
398 399
		'help-echo "Size indication mode\n\
mouse-1: Display Line and Column Mode Menu")))
400 401
	  (line-number-mode
	   ((column-number-mode
Dan Nicolaescu's avatar
Dan Nicolaescu committed
402 403
	     (10 ,(propertize
		   " (%l,%c)"
404
		   'local-map mode-line-column-line-number-mode-map
405
		   'mouse-face 'mode-line-highlight
406 407
		   'help-echo "Line number and Column number\n\
mouse-1: Display Line and Column Mode Menu"))
Dan Nicolaescu's avatar
Dan Nicolaescu committed
408 409
	     (6 ,(propertize
		  " L%l"
410
		  'local-map mode-line-column-line-number-mode-map
411
		  'mouse-face 'mode-line-highlight
412 413
		  'help-echo "Line Number\n\
mouse-1: Display Line and Column Mode Menu"))))
414
	   ((column-number-mode
Dan Nicolaescu's avatar
Dan Nicolaescu committed
415 416
	     (5 ,(propertize
		  " C%c"
417
		  'local-map mode-line-column-line-number-mode-map
418
		  'mouse-face 'mode-line-highlight
419 420
		  'help-echo "Column number\n\
mouse-1: Display Line and Column Mode Menu"))))))))
421 422 423 424 425 426 427 428 429 430 431 432

  (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
433

434 435 436 437 438 439 440 441 442 443 444 445 446
(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) "\
447
Keymap for what is displayed by `mode-line-buffer-identification'.")
448

449 450 451 452
(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."
453
  (list (propertize fmt
454 455
		    'face 'mode-line-buffer-id
		    'help-echo
456
		    (purecopy "Buffer name\n\
Dan Nicolaescu's avatar
Dan Nicolaescu committed
457 458
mouse-1: previous buffer\n\
mouse-3: next buffer")
459 460 461
		    'mouse-face 'mode-line-highlight
		    'local-map mode-line-buffer-identification-keymap)))

462
(defvar mode-line-buffer-identification (propertized-buffer-identification (purecopy "%12b")) "\
463 464 465 466 467
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,...)")

468
;;;###autoload
469
(put 'mode-line-buffer-identification 'risky-local-variable t)
470 471
(make-variable-buffer-local 'mode-line-buffer-identification)

472 473
(defun unbury-buffer () "\
Switch to the last buffer in the buffer list."
474 475 476
  (interactive)
  (switch-to-buffer (last-buffer)))

477
(defun mode-line-unbury-buffer (event) "\
478
Call `unbury-buffer' in this window."
479 480 481
  (interactive "e")
  (save-selected-window
    (select-window (posn-window (event-start event)))
482
    (unbury-buffer)))
483 484

(defun mode-line-bury-buffer (event) "\
Sam Steingold's avatar
Sam Steingold committed
485
Like `bury-buffer', but temporarily select EVENT's window."
486 487 488 489
  (interactive "e")
  (save-selected-window
    (select-window (posn-window (event-start event)))
    (bury-buffer)))
490

491 492
(defun mode-line-other-buffer () "\
Switch to the most recently selected buffer other than the current one."
493 494 495
  (interactive)
  (switch-to-buffer (other-buffer)))

496 497 498 499 500 501 502 503 504 505 506 507 508 509
(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
510 511
(defmacro bound-and-true-p (var)
  "Return the value of symbol VAR if it is bound, else nil."
512
  `(and (boundp (quote ,var)) ,var))
Dave Love's avatar
Dave Love committed
513

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

563
(defun mode-line-minor-mode-help (event)
564
  "Describe minor mode for EVENT on minor modes area of the mode line."
565 566 567 568
  (interactive "@e")
  (let ((indicator (car (nth 4 (car (cdr event))))))
    (describe-minor-mode-from-indicator indicator)))

569 570 571
(defvar minor-mode-alist nil "\
Alist saying how to show minor modes in the mode line.
Each element looks like (VARIABLE STRING);
572
STRING is included in the mode line if VARIABLE's value is non-nil.
573 574 575

Actually, STRING need not be a string; any possible mode-line element
is okay.  See `mode-line-format'.")
576
;;;###autoload
577
(put 'minor-mode-alist 'risky-local-variable t)
578 579
;; Don't use purecopy here--some people want to change these strings.
(setq minor-mode-alist
580 581 582 583 584
      '((abbrev-mode " Abbrev")
        (overwrite-mode overwrite-mode)
        (auto-fill-function " Fill")
        ;; not really a minor mode...
        (defining-kbd-macro " Def")))
585

Richard M. Stallman's avatar
Richard M. Stallman committed
586 587 588 589 590 591 592 593
;; 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
594
      (append
595
       (cond ((memq system-type '(ms-dos windows-nt))
596
	      (mapcar 'purecopy
597
	      '(".o" "~" ".bin" ".bak" ".obj" ".map" ".ico" ".pif" ".lnk"
598
		".a" ".ln" ".blg" ".bbl" ".dll" ".drv" ".vxd" ".386")))
599
	     (t
600
	      (mapcar 'purecopy
601
	      '(".o" "~" ".bin" ".lbin" ".so"
602 603
		".a" ".ln" ".blg" ".bbl"))))
       (mapcar 'purecopy
604 605
       '(".elc" ".lof"
	 ".glo" ".idx" ".lot"
606 607
	 ;; VCS metadata directories
	 ".svn/" ".hg/" ".git/" ".bzr/" "CVS/" "_darcs/" "_MTN/"
608
	 ;; TeX-related
609
	 ".fmt" ".tfm"
610 611
	 ;; Java compiled
	 ".class"
612 613
	 ;; CLISP
	 ".fas" ".lib" ".mem"
614
	 ;; CMUCL
615
	 ".x86f" ".sparcf"
Kenichi Handa's avatar
Kenichi Handa committed
616
         ;; Other CL implementations (Allegro, LispWorks, OpenMCL)
617
         ".fasl" ".ufsl" ".fsl" ".dxl" ".pfsl" ".dfsl"
618
	 ".p64fsl" ".d64fsl" ".dx64fsl"
619 620
	 ;; Libtool
	 ".lo" ".la"
621 622
	 ;; Gettext
	 ".gmo" ".mo"
623
	 ;; Texinfo-related
Kenichi Handa's avatar
Kenichi Handa committed
624 625 626
	 ;; 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"
627
	 ".cp" ".fn" ".ky" ".pg" ".tp" ".vr"
628 629
	 ".cps" ".fns" ".kys" ".pgs" ".tps" ".vrs"
	 ;; Python byte-compiled
630
	 ".pyc" ".pyo"))))
Richard M. Stallman's avatar
Richard M. Stallman committed
631

632 633 634 635 636 637 638 639
;; Suffixes used for executables.
(setq exec-suffixes
      (cond
       ((memq system-type '(ms-dos windows-nt))
	'(".exe" ".com" ".bat" ".cmd" ".btm" ""))
       (t
	'(""))))

640 641
;; 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
642
(setq debug-ignored-errors
643
      `(beginning-of-line beginning-of-buffer end-of-line
Richard M. Stallman's avatar
Richard M. Stallman committed
644
	end-of-buffer end-of-file buffer-read-only
645
	file-supersession
646 647 648 649 650 651 652 653 654 655 656 657 658 659 660
      	,(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$")
661
        ))
Richard M. Stallman's avatar
Richard M. Stallman committed
662 663 664 665


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

666
;; We have base64 and md5 functions built in now.
667 668 669 670
(provide 'base64)
(provide 'md5)
(provide 'overlay '(display syntax-table field))
(provide 'text-properties '(display syntax-table field point-entered))
671

672 673
(define-key esc-map "\t" 'complete-symbol)

674 675
(defun complete-symbol (arg) "\
Perform tags completion on the text around point.
Richard M. Stallman's avatar
Richard M. Stallman committed
676 677
Completes to the set of names listed in the current tags table.
The string to complete is chosen in the same way as the default
678 679 680 681 682
for \\[find-tag] (which see).

With a prefix argument, this command does completion within
the collection of symbols listed in the index of the manual for the
language you are using."
683 684
  (interactive "P")
  (if arg
685 686 687 688
      (info-complete-symbol)
    (if (fboundp 'complete-tag)
	(complete-tag)
      ;; Don't autoload etags if we have no tags table.
Deepak Goel's avatar
Deepak Goel committed
689
      (error "%s" (substitute-command-keys
690
	      "No tags table loaded; use \\[visit-tags-table] to load one")))))
Richard M. Stallman's avatar
Richard M. Stallman committed
691 692 693 694 695

;; Reduce total amount of space we must allocate during this function
;; that we will not need to keep permanently.
(garbage-collect)

696

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

699 700
(make-variable-buffer-local 'minor-mode-overriding-map-alist)

701 702
;; From frame.c
(global-set-key [switch-frame] 'handle-switch-frame)
703 704 705 706 707
(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
708 709 710 711 712
(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
713 714 715
;These commands are defined in editfns.c
;but they are not assigned to keys there.
(put 'narrow-to-region 'disabled t)
716 717 718 719 720 721 722

(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
723

724 725 726 727
;; Quitting
(define-key global-map "\e\e\e" 'keyboard-escape-quit)
(define-key global-map "\C-g" 'keyboard-quit)

728 729 730 731
;; 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
732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751
(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)
752 753
(define-key ctl-x-map "u" 'undo)
(put 'undo :advertised-binding [?\C-x ?u])
Richard M. Stallman's avatar
Richard M. Stallman committed
754 755 756
;; 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)
757 758 759 760
;; 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
761 762
(define-key esc-map "!" 'shell-command)
(define-key esc-map "|" 'shell-command-on-region)
763
(define-key esc-map "&" 'async-shell-command)
Richard M. Stallman's avatar
Richard M. Stallman committed
764

765 766 767 768
(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)
769

770 771 772 773 774 775 776 777
(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)
778 779 780 781
  (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.
782
  (define-key map "\t"    'self-insert-command)
783
  (define-key map [C-tab] 'file-cache-minibuffer-complete))
Richard M. Stallman's avatar
Richard M. Stallman committed
784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814

(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-@.
815
(define-key global-map [?\C- ] 'set-mark-command)
Richard M. Stallman's avatar
Richard M. Stallman committed
816 817
(define-key ctl-x-map "\C-x" 'exchange-point-and-mark)
(define-key ctl-x-map "\C-@" 'pop-global-mark)
818
(define-key ctl-x-map [?\C- ] 'pop-global-mark)
Richard M. Stallman's avatar
Richard M. Stallman committed
819 820 821 822

(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)
823
(define-key global-map "\C-a" 'move-beginning-of-line)
824
(define-key global-map "\C-e" 'move-end-of-line)
Richard M. Stallman's avatar
Richard M. Stallman committed
825

826 827
(define-key ctl-x-map "`" 'next-error)

828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849
(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)
850

Richard M. Stallman's avatar
Richard M. Stallman committed
851 852
;;(defun function-key-error ()
;;  (interactive)
853
;;  (error "That function key is not bound to anything"))
Richard M. Stallman's avatar
Richard M. Stallman committed
854 855 856 857

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

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

Richard M. Stallman's avatar
Richard M. Stallman committed
861
;; natural bindings for terminal keycaps --- defined in X keysym order
862
(define-key global-map [C-S-backspace]  'kill-whole-line)
863
(define-key global-map [home]		'move-beginning-of-line)
864
(define-key global-map [C-home]		'beginning-of-buffer)
Richard M. Stallman's avatar
Richard M. Stallman committed
865
(define-key global-map [M-home]		'beginning-of-buffer-other-window)
866
(define-key esc-map    [home]		'beginning-of-buffer-other-window)
Richard M. Stallman's avatar
Richard M. Stallman committed
867 868 869 870 871 872 873 874 875
(define-key global-map [left]		'backward-char)
(define-key global-map [up]		'previous-line)
(define-key global-map [right]		'forward-char)
(define-key global-map [down]		'next-line)
(define-key global-map [prior]		'scroll-down)
(define-key global-map [next]		'scroll-up)
(define-key global-map [C-up]		'backward-paragraph)
(define-key global-map [C-down]		'forward-paragraph)
(define-key global-map [C-prior]	'scroll-right)
876
(put 'scroll-left 'disabled t)
Richard M. Stallman's avatar
Richard M. Stallman committed
877 878
(define-key global-map [C-next]		'scroll-left)
(define-key global-map [M-next]		'scroll-other-window)
879
(define-key esc-map    [next]		'scroll-other-window)
Richard M. Stallman's avatar
Richard M. Stallman committed
880
(define-key global-map [M-prior]	'scroll-other-window-down)
881
(define-key esc-map    [prior]		'scroll-other-window-down)
882
(define-key esc-map [?\C-\S-v]		'scroll-other-window-down)
883
(define-key global-map [end]		'move-end-of-line)
884
(define-key global-map [C-end]		'end-of-buffer)
Richard M. Stallman's avatar
Richard M. Stallman committed
885
(define-key global-map [M-end]		'end-of-buffer-other-window)
886
(define-key esc-map    [end]		'end-of-buffer-other-window)
Richard M. Stallman's avatar
Richard M. Stallman committed
887 888
(define-key global-map [begin]		'beginning-of-buffer)
(define-key global-map [M-begin]	'beginning-of-buffer-other-window)
889
(define-key esc-map    [begin]		'beginning-of-buffer-other-window)
Richard M. Stallman's avatar
Richard M. Stallman committed