bindings.el 51 KB

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