bindings.el 47 KB

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