Mercurial > emacs
annotate lisp/eshell/em-rebind.el @ 112453:06719a229a46 default tip
* calc/calc.el (calc-default-power-reference-level)
(calc-default-field-reference-level): New variables.
* calc/calc-units.el (math-standard-units): Add dB and Np.
(math-logunits): New variable.
(math-extract-logunits, math-logcombine, calcFunc-luplus)
(calcFunc-luminus, calc-luplus, calc-luminus, math-logunit-level)
(calcFunc-fieldlevel, calcFunc-powerlevel, calc-level): New
functions.
(math-find-base-units-rec): Add entry for ln(10).
* calc/calc-help.el (calc-u-prefix-help): Add logarithmic help.
(calc-ul-prefix-help): New function.
* calc/calc-ext.el (calc-init-extensions): Autoload new units
functions. Add keybindings for new units functions.
author | Jay Belanger <jay.p.belanger@gmail.com> |
---|---|
date | Sun, 23 Jan 2011 23:08:04 -0600 |
parents | ef719132ddfa |
children |
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, |
112218
376148b31b5e
Add 2011 to FSF/AIST copyright years.
Glenn Morris <rgm@gnu.org>
parents:
106815
diff
changeset
|
4 ;; 2008, 2009, 2010, 2011 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) | |
110580
f57f72bb4757
Cosmetic doc fixes for eshell.
Glenn Morris <rgm@gnu.org>
parents:
106815
diff
changeset
|
46 "A list of functions to call when loading `eshell-rebind'." |
29876 | 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)) | |
110580
f57f72bb4757
Cosmetic doc fixes for eshell.
Glenn Morris <rgm@gnu.org>
parents:
106815
diff
changeset
|
58 "Bind some keys differently if point is in input text." |
29876 | 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 | |
110580
f57f72bb4757
Cosmetic doc fixes for eshell.
Glenn Morris <rgm@gnu.org>
parents:
106815
diff
changeset
|
65 "If non-nil, do not allow the point to leave the current input. |
29876 | 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 | |
110580
f57f72bb4757
Cosmetic doc fixes for eshell.
Glenn Morris <rgm@gnu.org>
parents:
106815
diff
changeset
|
80 "If non-nil, consider it an error to try to move outside current input. |
29876 | 81 This is default behavior of shells like bash." |
82 :type 'boolean | |
83 :group 'eshell-rebind) | |
84 | |
85 (defcustom eshell-remap-previous-input t | |
110580
f57f72bb4757
Cosmetic doc fixes for eshell.
Glenn Morris <rgm@gnu.org>
parents:
106815
diff
changeset
|
86 "If non-nil, remap input keybindings on previous prompts as well." |
29876 | 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-left-margin | |
95 move-to-tab-stop | |
96 forward-char | |
97 backward-char | |
98 delete-char | |
99 delete-backward-char | |
100 backward-delete-char | |
101 backward-delete-char-untabify | |
102 kill-paragraph | |
103 backward-kill-paragraph | |
104 kill-sentence | |
105 backward-kill-sentence | |
106 kill-sexp | |
107 backward-kill-sexp | |
108 kill-word | |
109 backward-kill-word | |
110 kill-region | |
111 forward-list | |
112 backward-list | |
113 forward-page | |
114 backward-page | |
115 forward-point | |
116 forward-paragraph | |
117 backward-paragraph | |
118 backward-prefix-chars | |
119 forward-sentence | |
120 backward-sentence | |
121 forward-sexp | |
122 backward-sexp | |
123 forward-to-indentation | |
124 backward-to-indentation | |
125 backward-up-list | |
126 forward-word | |
127 backward-word | |
128 forward-line | |
129 previous-line | |
130 next-line | |
131 forward-visible-line | |
132 forward-comment | |
133 forward-thing) | |
110580
f57f72bb4757
Cosmetic doc fixes for eshell.
Glenn Morris <rgm@gnu.org>
parents:
106815
diff
changeset
|
134 "A list of commands that cannot leave the input area." |
29876 | 135 :type '(repeat function) |
136 :group 'eshell-rebind) | |
137 | |
138 ;; Internal Variables: | |
139 | |
140 (defvar eshell-input-keymap) | |
141 (defvar eshell-previous-point) | |
142 (defvar eshell-lock-keymap) | |
143 | |
144 ;;; Functions: | |
145 | |
146 (defun eshell-rebind-initialize () | |
147 "Initialize the inputing code." | |
148 (unless eshell-non-interactive-p | |
149 (add-hook 'eshell-mode-hook 'eshell-setup-input-keymap nil t) | |
150 (make-local-variable 'eshell-previous-point) | |
151 (add-hook 'pre-command-hook 'eshell-save-previous-point nil t) | |
152 (make-local-variable 'overriding-local-map) | |
153 (add-hook 'post-command-hook 'eshell-rebind-input-map nil t) | |
154 (set (make-local-variable 'eshell-lock-keymap) nil) | |
155 (define-key eshell-command-map [(meta ?l)] 'eshell-lock-local-map))) | |
156 | |
157 (defun eshell-lock-local-map (&optional arg) | |
158 "Lock or unlock the current local keymap. | |
159 Within a prefix arg, set the local keymap to its normal value, and | |
160 lock it at that." | |
161 (interactive "P") | |
162 (if (or arg (not eshell-lock-keymap)) | |
163 (progn | |
164 (use-local-map eshell-mode-map) | |
165 (setq eshell-lock-keymap t) | |
166 (message "Local keymap locked in normal mode")) | |
167 (use-local-map eshell-input-keymap) | |
168 (setq eshell-lock-keymap nil) | |
169 (message "Local keymap unlocked: obey context"))) | |
170 | |
171 (defun eshell-save-previous-point () | |
172 "Save the location of point before the next command is run." | |
173 (setq eshell-previous-point (point))) | |
174 | |
175 (defsubst eshell-point-within-input-p (pos) | |
176 "Test whether POS is within an input range." | |
177 (let (begin) | |
178 (or (and (>= pos eshell-last-output-end) | |
179 eshell-last-output-end) | |
180 (and eshell-remap-previous-input | |
181 (setq begin | |
182 (save-excursion | |
183 (eshell-bol) | |
184 (and (not (bolp)) (point)))) | |
185 (>= pos begin) | |
186 (<= pos (line-end-position)) | |
187 begin)))) | |
188 | |
189 (defun eshell-rebind-input-map () | |
190 "Rebind the input keymap based on the location of the cursor." | |
191 (ignore-errors | |
192 (unless eshell-lock-keymap | |
193 (if (eshell-point-within-input-p (point)) | |
194 (use-local-map eshell-input-keymap) | |
195 (let (begin) | |
196 (if (and eshell-confine-point-to-input | |
197 (setq begin | |
198 (eshell-point-within-input-p eshell-previous-point)) | |
199 (memq this-command eshell-cannot-leave-input-list)) | |
200 (progn | |
201 (use-local-map eshell-input-keymap) | |
202 (goto-char begin) | |
203 (if (and eshell-error-if-move-away | |
204 (not (eq this-command 'kill-region))) | |
205 (beep))) | |
206 (use-local-map eshell-mode-map))))))) | |
207 | |
208 (defun eshell-setup-input-keymap () | |
209 "Setup the input keymap to be used during input editing." | |
210 (make-local-variable 'eshell-input-keymap) | |
211 (setq eshell-input-keymap (make-sparse-keymap)) | |
212 (set-keymap-parent eshell-input-keymap eshell-mode-map) | |
213 (let ((bindings eshell-rebind-keys-alist)) | |
214 (while bindings | |
215 (define-key eshell-input-keymap (caar bindings) | |
216 (cdar bindings)) | |
217 (setq bindings (cdr bindings))))) | |
218 | |
219 (defun eshell-delete-backward-char (n &optional killflag) | |
220 "Delete the last character, unless it's part of the output." | |
221 (interactive "P") | |
222 (let ((count (prefix-numeric-value n))) | |
223 (if (eshell-point-within-input-p (- (point) count)) | |
224 (delete-backward-char count n) | |
225 (beep)))) | |
226 | |
227 (defun eshell-delchar-or-maybe-eof (arg) | |
228 "Delete ARG characters forward or send an EOF to subprocess. | |
229 Sends an EOF only if point is at the end of the buffer and there is no | |
230 input." | |
231 (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
|
232 (let ((proc (eshell-interactive-process))) |
29876 | 233 (if (eobp) |
234 (cond | |
31241 | 235 ((/= (point) eshell-last-output-end) |
29876 | 236 (beep)) |
237 (proc | |
238 (process-send-eof)) | |
239 (t | |
240 (eshell-life-is-too-much))) | |
241 (eshell-delete-backward-char (- arg))))) | |
242 | |
87072
2bdf985b1c49
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
243 (provide 'em-rebind) |
29876 | 244 |
95152
ad5d26b1d5d1
Use eshell-defgroup rather than defgroup.
Glenn Morris <rgm@gnu.org>
parents:
94661
diff
changeset
|
245 ;; Local Variables: |
ad5d26b1d5d1
Use eshell-defgroup rather than defgroup.
Glenn Morris <rgm@gnu.org>
parents:
94661
diff
changeset
|
246 ;; generated-autoload-file: "esh-groups.el" |
ad5d26b1d5d1
Use eshell-defgroup rather than defgroup.
Glenn Morris <rgm@gnu.org>
parents:
94661
diff
changeset
|
247 ;; End: |
ad5d26b1d5d1
Use eshell-defgroup rather than defgroup.
Glenn Morris <rgm@gnu.org>
parents:
94661
diff
changeset
|
248 |
29876 | 249 ;;; em-rebind.el ends here |