Mercurial > emacs
annotate lisp/eshell/em-rebind.el @ 98017:4f69bd0a8c9f
(pmail-dont-reply-to, pmail-desc-get-marker-end)
(pmail-desc-get-marker-start): Remove declarations of undefined functions.
(pmail-select-correspondent): Use rmail-dont-reply-to from mail-utils
rather than non-existent pmail-dont-reply-to.
author | Glenn Morris <rgm@gnu.org> |
---|---|
date | Sat, 06 Sep 2008 02:50:14 +0000 |
parents | ad5d26b1d5d1 |
children | a9dc0e7c3f2b |
rev | line source |
---|---|
38414
67b464da13ec
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
35973
diff
changeset
|
1 ;;; em-rebind.el --- rebind keys when point is at current input |
29876 | 2 |
95152
ad5d26b1d5d1
Use eshell-defgroup rather than defgroup.
Glenn Morris <rgm@gnu.org>
parents:
94661
diff
changeset
|
3 ;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, |
ad5d26b1d5d1
Use eshell-defgroup rather than defgroup.
Glenn Morris <rgm@gnu.org>
parents:
94661
diff
changeset
|
4 ;; 2008 Free Software Foundation, Inc. |
29876 | 5 |
32526 | 6 ;; Author: John Wiegley <johnw@gnu.org> |
7 | |
29876 | 8 ;; This file is part of GNU Emacs. |
9 | |
94661
b5b0801a7637
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
10 ;; GNU Emacs is free software: you can redistribute it and/or modify |
29876 | 11 ;; it under the terms of the GNU General Public License as published by |
94661
b5b0801a7637
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
12 ;; the Free Software Foundation, either version 3 of the License, or |
b5b0801a7637
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
13 ;; (at your option) any later version. |
29876 | 14 |
15 ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
94661
b5b0801a7637
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
29876 | 22 |
87072
2bdf985b1c49
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
23 ;;; Commentary: |
29876 | 24 |
87072
2bdf985b1c49
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
25 ;;; Code: |
2bdf985b1c49
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
26 |
2bdf985b1c49
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
27 (eval-when-compile (require 'eshell)) |
29876 | 28 |
95152
ad5d26b1d5d1
Use eshell-defgroup rather than defgroup.
Glenn Morris <rgm@gnu.org>
parents:
94661
diff
changeset
|
29 ;;;###autoload |
ad5d26b1d5d1
Use eshell-defgroup rather than defgroup.
Glenn Morris <rgm@gnu.org>
parents:
94661
diff
changeset
|
30 (eshell-defgroup eshell-rebind nil |
29876 | 31 "This module allows for special keybindings that only take effect |
32 while the point is in a region of input text. By default, it binds | |
33 C-a to move to the beginning of the input text (rather than just the | |
34 beginning of the line), and C-p and C-n to move through the input | |
35 history, C-u kills the current input text, etc. It also, if | |
36 `eshell-confine-point-to-input' is non-nil, does not allow certain | |
37 commands to cause the point to leave the input area, such as | |
38 `backward-word', `previous-line', etc. This module intends to mimic | |
39 the behavior of normal shells while the user editing new input text." | |
40 :tag "Rebind keys at input" | |
41 :group 'eshell-module) | |
42 | |
43 ;;; User Variables: | |
44 | |
45 (defcustom eshell-rebind-load-hook '(eshell-rebind-initialize) | |
46 "*A list of functions to call when loading `eshell-rebind'." | |
47 :type 'hook | |
48 :group 'eshell-rebind) | |
49 | |
50 (defcustom eshell-rebind-keys-alist | |
51 '(([(control ?a)] . eshell-bol) | |
52 ([home] . eshell-bol) | |
53 ([(control ?d)] . eshell-delchar-or-maybe-eof) | |
54 ([backspace] . eshell-delete-backward-char) | |
55 ([delete] . eshell-delete-backward-char) | |
56 ([(control ?w)] . backward-kill-word) | |
57 ([(control ?u)] . eshell-kill-input)) | |
58 "*Bind some keys differently if point is in input text." | |
59 :type '(repeat (cons (vector :tag "Keys to bind" | |
60 (repeat :inline t sexp)) | |
61 (function :tag "Command"))) | |
62 :group 'eshell-rebind) | |
63 | |
64 (defcustom eshell-confine-point-to-input t | |
65 "*If non-nil, do not allow the point to leave the current input. | |
66 This is more difficult to do nicely in Emacs than one might think. | |
67 Basically, the `point-left' attribute is added to the input text, and | |
68 a function is placed on that hook to take the point back to | |
69 `eshell-last-output-end' every time the user tries to move away. But | |
70 since there are many cases in which the point _ought_ to move away | |
71 \(for programmatic reasons), the variable | |
72 `eshell-cannot-leave-input-list' defines commands which are affected | |
73 from this rule. However, this list is by no means as complete as it | |
74 probably should be, so basically all one can hope for is that other | |
75 people will left the point alone in the Eshell buffer. Sigh." | |
76 :type 'boolean | |
77 :group 'eshell-rebind) | |
78 | |
79 (defcustom eshell-error-if-move-away t | |
80 "*If non-nil, consider it an error to try to move outside current input. | |
81 This is default behavior of shells like bash." | |
82 :type 'boolean | |
83 :group 'eshell-rebind) | |
84 | |
85 (defcustom eshell-remap-previous-input t | |
86 "*If non-nil, remap input keybindings on previous prompts as well." | |
87 :type 'boolean | |
88 :group 'eshell-rebind) | |
89 | |
90 (defcustom eshell-cannot-leave-input-list | |
91 '(beginning-of-line-text | |
92 beginning-of-line | |
93 move-to-column | |
94 move-to-column-force | |
95 move-to-left-margin | |
96 move-to-tab-stop | |
97 forward-char | |
98 backward-char | |
99 delete-char | |
100 delete-backward-char | |
101 backward-delete-char | |
102 backward-delete-char-untabify | |
103 kill-paragraph | |
104 backward-kill-paragraph | |
105 kill-sentence | |
106 backward-kill-sentence | |
107 kill-sexp | |
108 backward-kill-sexp | |
109 kill-word | |
110 backward-kill-word | |
111 kill-region | |
112 forward-list | |
113 backward-list | |
114 forward-page | |
115 backward-page | |
116 forward-point | |
117 forward-paragraph | |
118 backward-paragraph | |
119 backward-prefix-chars | |
120 forward-sentence | |
121 backward-sentence | |
122 forward-sexp | |
123 backward-sexp | |
124 forward-to-indentation | |
125 backward-to-indentation | |
126 backward-up-list | |
127 forward-word | |
128 backward-word | |
129 forward-line | |
130 previous-line | |
131 next-line | |
132 forward-visible-line | |
133 forward-comment | |
134 forward-thing) | |
135 "*A list of commands that cannot leave the input area." | |
136 :type '(repeat function) | |
137 :group 'eshell-rebind) | |
138 | |
139 ;; Internal Variables: | |
140 | |
141 (defvar eshell-input-keymap) | |
142 (defvar eshell-previous-point) | |
143 (defvar eshell-lock-keymap) | |
144 | |
145 ;;; Functions: | |
146 | |
147 (defun eshell-rebind-initialize () | |
148 "Initialize the inputing code." | |
149 (unless eshell-non-interactive-p | |
150 (add-hook 'eshell-mode-hook 'eshell-setup-input-keymap nil t) | |
151 (make-local-variable 'eshell-previous-point) | |
152 (add-hook 'pre-command-hook 'eshell-save-previous-point nil t) | |
153 (make-local-variable 'overriding-local-map) | |
154 (add-hook 'post-command-hook 'eshell-rebind-input-map nil t) | |
155 (set (make-local-variable 'eshell-lock-keymap) nil) | |
156 (define-key eshell-command-map [(meta ?l)] 'eshell-lock-local-map))) | |
157 | |
158 (defun eshell-lock-local-map (&optional arg) | |
159 "Lock or unlock the current local keymap. | |
160 Within a prefix arg, set the local keymap to its normal value, and | |
161 lock it at that." | |
162 (interactive "P") | |
163 (if (or arg (not eshell-lock-keymap)) | |
164 (progn | |
165 (use-local-map eshell-mode-map) | |
166 (setq eshell-lock-keymap t) | |
167 (message "Local keymap locked in normal mode")) | |
168 (use-local-map eshell-input-keymap) | |
169 (setq eshell-lock-keymap nil) | |
170 (message "Local keymap unlocked: obey context"))) | |
171 | |
172 (defun eshell-save-previous-point () | |
173 "Save the location of point before the next command is run." | |
174 (setq eshell-previous-point (point))) | |
175 | |
176 (defsubst eshell-point-within-input-p (pos) | |
177 "Test whether POS is within an input range." | |
178 (let (begin) | |
179 (or (and (>= pos eshell-last-output-end) | |
180 eshell-last-output-end) | |
181 (and eshell-remap-previous-input | |
182 (setq begin | |
183 (save-excursion | |
184 (eshell-bol) | |
185 (and (not (bolp)) (point)))) | |
186 (>= pos begin) | |
187 (<= pos (line-end-position)) | |
188 begin)))) | |
189 | |
190 (defun eshell-rebind-input-map () | |
191 "Rebind the input keymap based on the location of the cursor." | |
192 (ignore-errors | |
193 (unless eshell-lock-keymap | |
194 (if (eshell-point-within-input-p (point)) | |
195 (use-local-map eshell-input-keymap) | |
196 (let (begin) | |
197 (if (and eshell-confine-point-to-input | |
198 (setq begin | |
199 (eshell-point-within-input-p eshell-previous-point)) | |
200 (memq this-command eshell-cannot-leave-input-list)) | |
201 (progn | |
202 (use-local-map eshell-input-keymap) | |
203 (goto-char begin) | |
204 (if (and eshell-error-if-move-away | |
205 (not (eq this-command 'kill-region))) | |
206 (beep))) | |
207 (use-local-map eshell-mode-map))))))) | |
208 | |
209 (defun eshell-setup-input-keymap () | |
210 "Setup the input keymap to be used during input editing." | |
211 (make-local-variable 'eshell-input-keymap) | |
212 (setq eshell-input-keymap (make-sparse-keymap)) | |
213 (set-keymap-parent eshell-input-keymap eshell-mode-map) | |
214 (let ((bindings eshell-rebind-keys-alist)) | |
215 (while bindings | |
216 (define-key eshell-input-keymap (caar bindings) | |
217 (cdar bindings)) | |
218 (setq bindings (cdr bindings))))) | |
219 | |
220 (defun eshell-delete-backward-char (n &optional killflag) | |
221 "Delete the last character, unless it's part of the output." | |
222 (interactive "P") | |
223 (let ((count (prefix-numeric-value n))) | |
224 (if (eshell-point-within-input-p (- (point) count)) | |
225 (delete-backward-char count n) | |
226 (beep)))) | |
227 | |
228 (defun eshell-delchar-or-maybe-eof (arg) | |
229 "Delete ARG characters forward or send an EOF to subprocess. | |
230 Sends an EOF only if point is at the end of the buffer and there is no | |
231 input." | |
232 (interactive "p") | |
32446
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
233 (let ((proc (eshell-interactive-process))) |
29876 | 234 (if (eobp) |
235 (cond | |
31241 | 236 ((/= (point) eshell-last-output-end) |
29876 | 237 (beep)) |
238 (proc | |
239 (process-send-eof)) | |
240 (t | |
241 (eshell-life-is-too-much))) | |
242 (eshell-delete-backward-char (- arg))))) | |
243 | |
87072
2bdf985b1c49
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
244 (provide 'em-rebind) |
29876 | 245 |
95152
ad5d26b1d5d1
Use eshell-defgroup rather than defgroup.
Glenn Morris <rgm@gnu.org>
parents:
94661
diff
changeset
|
246 ;; Local Variables: |
ad5d26b1d5d1
Use eshell-defgroup rather than defgroup.
Glenn Morris <rgm@gnu.org>
parents:
94661
diff
changeset
|
247 ;; generated-autoload-file: "esh-groups.el" |
ad5d26b1d5d1
Use eshell-defgroup rather than defgroup.
Glenn Morris <rgm@gnu.org>
parents:
94661
diff
changeset
|
248 ;; End: |
ad5d26b1d5d1
Use eshell-defgroup rather than defgroup.
Glenn Morris <rgm@gnu.org>
parents:
94661
diff
changeset
|
249 |
93975
1e3a407766b9
Fix up comment convention on the arch-tag lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
250 ;; arch-tag: 76d84f12-cc56-4d67-9b7d-c6b44ad20530 |
29876 | 251 ;;; em-rebind.el ends here |