0
|
1 ;;; delbackspace.el --- rebind backspace and delete to be correct
|
|
2
|
|
3 ;; Copyright (C) 1994, 1995 Free Software Foundation, Inc.
|
|
4 ;; Copyright (C) 1996 Ben Wing.
|
|
5 ;;
|
|
6 ;; Author: Tibor Polgar??
|
|
7 ;; Maintainer: Ben Wing <wing@666.com>
|
|
8 ;; Keywords: terminals
|
|
9 ;;
|
|
10
|
|
11 ;;; Synched up with: Not in FSF.
|
|
12 ;;; #### should port FSF pc-bindings.el and nuke this.
|
|
13
|
|
14 ;; this is a hack that will have to do until function-key-map is implemented
|
|
15 (defconst delbackspace-backspace
|
|
16 (if (not (eq 'tty (device-type (selected-device))))
|
|
17 'backspace
|
|
18 "\C-h"))
|
|
19
|
|
20 (global-unset-key delbackspace-backspace)
|
|
21 (local-unset-key delbackspace-backspace)
|
|
22 (global-unset-key [(control delete)])
|
|
23 (global-unset-key [(meta delete)])
|
|
24 (global-unset-key [(meta shift delete)])
|
|
25 (global-unset-key [(control backspace)])
|
|
26 (global-unset-key [(meta backspace)])
|
|
27 (global-unset-key [(meta shift backspace)])
|
|
28
|
|
29 (if (eq 'tty (device-type (selected-device)))
|
|
30 (progn
|
|
31 (setq help-char '(meta h))
|
|
32 (define-key global-map "\M-h" 'help-command)))
|
|
33
|
|
34 (define-key key-translation-map 'delete 'delbackspace-compute-delete-value)
|
|
35 (define-key global-map 'intercepted_delete 'delete-char)
|
|
36
|
|
37 (defun delbackspace-compute-delete-value (prompt)
|
|
38 (let ((orig-binding (key-binding 'delete)))
|
|
39 (if (memq orig-binding '(delete-backward-char
|
|
40 backward-delete-char
|
|
41 backward-delete-char-untabify
|
|
42 c-electric-delete
|
|
43 c++-electric-delete
|
|
44 cperl-electric-backspace))
|
|
45 [intercepted_delete]
|
|
46 [delete])))
|
|
47
|
|
48 (define-key key-translation-map delbackspace-backspace [delete])
|
|
49
|
|
50 ;; (ctrl) backspace to beginning of line
|
|
51 (global-set-key [(control backspace)] 'backward-kill-line)
|
|
52
|
|
53 ;; (meta) backspace word before cursor
|
|
54 (define-key key-translation-map [(meta backspace)]
|
|
55 [intercepted_meta_backspace])
|
|
56 (define-key global-map 'intercepted_meta_backspace 'backward-kill-word)
|
|
57
|
|
58 ;; (alt) backspace sentence before cursor; backspace sexp before cursor
|
|
59 ;; in language modes
|
|
60 (define-key key-translation-map [(alt backspace)]
|
|
61 [intercepted_alt_backspace])
|
|
62 (define-key global-map 'intercepted_alt_backspace 'backward-kill-sentence)
|
10
|
63 (if (boundp 'c-mode-map)
|
|
64 (mapcar (lambda (map)
|
|
65 (define-key map [(alt backspace)] 'backward-kill-sexp))
|
|
66 (list
|
|
67 c-mode-map c++-mode-map objc-mode-map java-mode-map
|
|
68 emacs-lisp-mode-map lisp-mode-map minibuffer-local-map))
|
|
69 (setq after-load-alist
|
|
70 (append '(("cc-mode"
|
|
71 (mapcar (lambda (map)
|
|
72 (define-key map
|
|
73 [(alt backspace)]
|
|
74 'backward-kill-sexp)
|
|
75 (define-key map [(alt delete)] 'kill-sexp))
|
|
76 (list
|
|
77 c-mode-map
|
|
78 c++-mode-map
|
|
79 objc-mode-map
|
|
80 java-mode-map))))
|
|
81 after-load-alist)))
|
|
82
|
0
|
83
|
|
84 ;; (meta shift) backspace paragraph before cursor
|
|
85 (global-set-key [(meta shift backspace)] 'backward-kill-paragraph)
|
|
86
|
|
87 ;; (alt) delete rest of line (erase EOF)
|
|
88 (global-set-key [(control delete)] 'kill-line)
|
|
89
|
|
90 ;; (meta) delete word before cursor
|
|
91 (define-key key-translation-map [(meta delete)]
|
|
92 [intercepted_meta_delete])
|
|
93 (define-key global-map 'intercepted_meta_delete 'kill-word)
|
|
94
|
|
95 ;; (alt) delete sentence forward; delete sexp forward
|
|
96 ;; in language modes
|
|
97 (define-key key-translation-map [(alt delete)]
|
|
98 [intercepted_alt_delete])
|
|
99 (define-key global-map 'intercepted_alt_delete 'kill-sentence)
|
10
|
100 (mapcar (lambda (map)
|
|
101 (define-key map [(alt delete)] 'kill-sexp))
|
0
|
102 (list
|
|
103 emacs-lisp-mode-map lisp-mode-map minibuffer-local-map))
|
10
|
104 (when (boundp 'c-mode-map)
|
|
105 (mapcar (lambda (map)
|
|
106 (define-key map [(alt delete)] 'kill-sexp))
|
|
107 (list
|
|
108 c-mode-map c++-mode-map objc-mode-map java-mode-map)))
|
0
|
109
|
|
110 ;; (meta shift) delete next paragraph
|
|
111 (global-set-key [(meta shift delete)] 'kill-paragraph)
|
10
|
112
|
|
113 (provide 'delbackspace)
|
|
114
|
|
115 ;;; delbackspace.el ends here
|