aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorStefan Monnier2012-05-04 22:50:20 -0400
committerStefan Monnier2012-05-04 22:50:20 -0400
commitdf96ab1e0a29e4d178b1406ceacc70d5f9e5c2d6 (patch)
tree3508d5f0daa190d0bcbe3611a1e68eef06ee8605 /lisp
parent5342bb062f39a387e9a770b3edef881ee4a72f17 (diff)
downloademacs-df96ab1e0a29e4d178b1406ceacc70d5f9e5c2d6.tar.gz
emacs-df96ab1e0a29e4d178b1406ceacc70d5f9e5c2d6.zip
Use set-temporary-overlay-map.
* lisp/repeat.el: Use lexical-binding. (repeat-last-self-insert, repeat-num-input-keys-at-self-insert) (repeat-undo-count): Remove. (repeat): * lisp/progmodes/octave-mod.el (octave-abbrev-start): * lisp/progmodes/f90.el (f90-abbrev-start): * lisp/face-remap.el (text-scale-adjust): * lisp/kmacro.el (kmacro-call-macro): Use set-temporary-overlay-map.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/ChangeLog9
-rw-r--r--lisp/face-remap.el39
-rw-r--r--lisp/kmacro.el34
-rw-r--r--lisp/progmodes/f90.el19
-rw-r--r--lisp/progmodes/octave-mod.el19
-rw-r--r--lisp/repeat.el142
6 files changed, 98 insertions, 164 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 9780e1265fb..664c7734f1a 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,5 +1,14 @@
12012-05-05 Stefan Monnier <monnier@iro.umontreal.ca> 12012-05-05 Stefan Monnier <monnier@iro.umontreal.ca>
2 2
3 * repeat.el: Use lexical-binding.
4 (repeat-last-self-insert, repeat-num-input-keys-at-self-insert)
5 (repeat-undo-count): Remove.
6 (repeat):
7 * progmodes/octave-mod.el (octave-abbrev-start):
8 * progmodes/f90.el (f90-abbrev-start):
9 * face-remap.el (text-scale-adjust):
10 * kmacro.el (kmacro-call-macro): Use set-temporary-overlay-map.
11
3 * emacs-lisp/pcase.el (pcase--let*): New function. 12 * emacs-lisp/pcase.el (pcase--let*): New function.
4 (pcase--expand, pcase-codegen, pcase--q1): Use it to reduce nesting 13 (pcase--expand, pcase-codegen, pcase--q1): Use it to reduce nesting
5 a bit more. 14 a bit more.
diff --git a/lisp/face-remap.el b/lisp/face-remap.el
index ca7a28328f9..46dad0fca3a 100644
--- a/lisp/face-remap.el
+++ b/lisp/face-remap.el
@@ -303,26 +303,29 @@ a top-level keymap, `text-scale-increase' or
303`text-scale-decrease' may be more appropriate." 303`text-scale-decrease' may be more appropriate."
304 (interactive "p") 304 (interactive "p")
305 (let ((first t) 305 (let ((first t)
306 (step t)
307 (ev last-command-event) 306 (ev last-command-event)
308 (echo-keystrokes nil)) 307 (echo-keystrokes nil))
309 (while step 308 (let* ((base (event-basic-type ev))
310 (let ((base (event-basic-type ev))) 309 (step
311 (cond ((or (eq base ?+) (eq base ?=)) 310 (pcase base
312 (setq step inc)) 311 ((or `?+ `?=) inc)
313 ((eq base ?-) 312 (`?- (- inc))
314 (setq step (- inc))) 313 (`?0 0)
315 ((eq base ?0) 314 (t inc))))
316 (setq step 0)) 315 (text-scale-increase step)
317 (first 316 ;; FIXME: do it after everu "iteration of the loop".
318 (setq step inc)) 317 (message "+,-,0 for further adjustment: ")
319 (t 318 (set-temporary-overlay-map
320 (setq step nil)))) 319 (let ((map (make-sparse-keymap)))
321 (when step 320 (dolist (mods '(() (control)))
322 (text-scale-increase step) 321 (define-key map (vector (append mods '(?-))) 'text-scale-decrease)
323 (setq inc 1 first nil) 322 (define-key map (vector (append mods '(?+))) 'text-scale-increase)
324 (setq ev (read-event "+,-,0 for further adjustment: ")))) 323 ;; = is unshifted + on most keyboards.
325 (push ev unread-command-events))) 324 (define-key map (vector (append mods '(?=))) 'text-scale-increase)
325 (define-key map (vector (append mods '(?0)))
326 (lambda () (interactive) (text-scale-increase 0))))
327 map)
328 t))))
326 329
327 330
328;; ---------------------------------------------------------------- 331;; ----------------------------------------------------------------
diff --git a/lisp/kmacro.el b/lisp/kmacro.el
index b715e44387e..ffc97085a69 100644
--- a/lisp/kmacro.el
+++ b/lisp/kmacro.el
@@ -625,8 +625,10 @@ for details on how to adjust or disable this behavior.
625To make a macro permanent so you can call it even after defining 625To make a macro permanent so you can call it even after defining
626others, use \\[kmacro-name-last-macro]." 626others, use \\[kmacro-name-last-macro]."
627 (interactive "p") 627 (interactive "p")
628 (let ((repeat-key (and (null no-repeat) 628 (let ((repeat-key (and (or (and (null no-repeat)
629 (> (length (this-single-command-keys)) 1) 629 (> (length (this-single-command-keys)) 1))
630 ;; Used when we're in the process of repeating.
631 (eq no-repeat 'repeating))
630 last-input-event)) 632 last-input-event))
631 repeat-key-str) 633 repeat-key-str)
632 (if end-macro 634 (if end-macro
@@ -640,24 +642,16 @@ others, use \\[kmacro-name-last-macro]."
640 repeat-key 642 repeat-key
641 kmacro-call-repeat-key))) 643 kmacro-call-repeat-key)))
642 (setq repeat-key-str (format-kbd-macro (vector repeat-key) nil)) 644 (setq repeat-key-str (format-kbd-macro (vector repeat-key) nil))
643 (while repeat-key 645 ;; Can't use the `keep-pred' arg because this overlay keymap needs to be
644 ;; Issue a hint to the user, if the echo area isn't in use. 646 ;; removed during the next run of the kmacro (i.e. we need to add&remove
645 (unless (current-message) 647 ;; this overlay-map at each repetition).
646 (message "(Type %s to repeat macro%s)" 648 (set-temporary-overlay-map
647 repeat-key-str 649 (let ((map (make-sparse-keymap)))
648 (if (and kmacro-call-repeat-with-arg 650 (define-key map (vector repeat-key)
649 arg (> arg 1)) 651 `(lambda () (interactive)
650 (format " %d times" arg) ""))) 652 (kmacro-call-macro ,(and kmacro-call-repeat-with-arg arg)
651 (if (equal repeat-key (read-event)) 653 'repeating)))
652 (progn 654 map)))))
653 (clear-this-command-keys t)
654 (call-last-kbd-macro (and kmacro-call-repeat-with-arg arg)
655 #'kmacro-loop-setup-function)
656 (setq last-input-event nil))
657 (setq repeat-key nil)))
658 (when last-input-event
659 (clear-this-command-keys t)
660 (setq unread-command-events (list last-input-event))))))
661 655
662 656
663;;; Combined function key bindings: 657;;; Combined function key bindings:
diff --git a/lisp/progmodes/f90.el b/lisp/progmodes/f90.el
index 1d2beedd191..712725ffaf0 100644
--- a/lisp/progmodes/f90.el
+++ b/lisp/progmodes/f90.el
@@ -2204,18 +2204,13 @@ Leave point at the end of line."
2204 "Typing `\\[help-command] or `? lists all the F90 abbrevs. 2204 "Typing `\\[help-command] or `? lists all the F90 abbrevs.
2205Any other key combination is executed normally." 2205Any other key combination is executed normally."
2206 (interactive "*") 2206 (interactive "*")
2207 (insert last-command-event) 2207 (self-insert-command 1)
2208 (let (char event) 2208 (when abbrev-mode
2209 (if (fboundp 'next-command-event) ; XEmacs 2209 (set-temporary-overlay-map
2210 (setq event (next-command-event) 2210 (let ((map (make-sparse-keymap)))
2211 char (and (fboundp 'event-to-character) 2211 (define-key map [??] 'f90-abbrev-help)
2212 (event-to-character event))) 2212 (define-key map (vector help-char) 'f90-abbrev-help)
2213 (setq event (read-event) 2213 map))))
2214 char event))
2215 ;; Insert char if not equal to `?', or if abbrev-mode is off.
2216 (if (and abbrev-mode (memq char (list ?? help-char)))
2217 (f90-abbrev-help)
2218 (setq unread-command-events (list event)))))
2219 2214
2220(defun f90-abbrev-help () 2215(defun f90-abbrev-help ()
2221 "List the currently defined abbrevs in F90 mode." 2216 "List the currently defined abbrevs in F90 mode."
diff --git a/lisp/progmodes/octave-mod.el b/lisp/progmodes/octave-mod.el
index 7091a9468c5..79b3fcee720 100644
--- a/lisp/progmodes/octave-mod.el
+++ b/lisp/progmodes/octave-mod.el
@@ -989,18 +989,13 @@ If Abbrev mode is turned on, typing ` (grave accent) followed by ? or
989executed normally. 989executed normally.
990Note that all Octave mode abbrevs start with a grave accent." 990Note that all Octave mode abbrevs start with a grave accent."
991 (interactive) 991 (interactive)
992 (if (not abbrev-mode) 992 (self-insert-command 1)
993 (self-insert-command 1) 993 (when abbrev-mode
994 (let (c) 994 (set-temporary-overlay-map
995 (insert last-command-event) 995 (let ((map (make-sparse-keymap)))
996 (if (if (featurep 'xemacs) 996 (define-key map [??] 'list-abbrevs)
997 (or (eq (event-to-character (setq c (next-event))) ??) 997 (define-key map (vector help-char) 'list-abbrevs)
998 (eq (event-to-character c) help-char)) 998 map))))
999 (or (eq (setq c (read-event)) ??)
1000 (eq c help-char)))
1001 (let ((abbrev-table-name-list '(octave-abbrev-table)))
1002 (list-abbrevs))
1003 (setq unread-command-events (list c))))))
1004 999
1005(define-skeleton octave-insert-defun 1000(define-skeleton octave-insert-defun
1006 "Insert an Octave function skeleton. 1001 "Insert an Octave function skeleton.
diff --git a/lisp/repeat.el b/lisp/repeat.el
index 94efc717be5..e577c461bc5 100644
--- a/lisp/repeat.el
+++ b/lisp/repeat.el
@@ -1,4 +1,4 @@
1;;; repeat.el --- convenient way to repeat the previous command 1;;; repeat.el --- convenient way to repeat the previous command -*- lexical-binding: t -*-
2 2
3;; Copyright (C) 1998, 2001-2012 Free Software Foundation, Inc. 3;; Copyright (C) 1998, 2001-2012 Free Software Foundation, Inc.
4 4
@@ -156,15 +156,6 @@ member of that sequence. If this variable is nil, no re-execution occurs."
156;; `repeat' now repeats that command instead of `real-last-command' to 156;; `repeat' now repeats that command instead of `real-last-command' to
157;; avoid a "... must be bound to an event with parameters" error. 157;; avoid a "... must be bound to an event with parameters" error.
158 158
159(defvar repeat-last-self-insert nil
160 "If last repeated command was `self-insert-command', it inserted this.")
161
162;; That'll require another keystroke count so we know we're in a string of
163;; repetitions of self-insert commands:
164
165(defvar repeat-num-input-keys-at-self-insert -1
166 "# key sequences read in Emacs session when `self-insert-command' repeated.")
167
168;;;;; *************** ANALOGOUS HACKS TO `repeat' ITSELF **************** ;;;;; 159;;;;; *************** ANALOGOUS HACKS TO `repeat' ITSELF **************** ;;;;;
169 160
170;; That mechanism of checking num-input-keys to figure out what's really 161;; That mechanism of checking num-input-keys to figure out what's really
@@ -199,14 +190,6 @@ this function is always whether the value of `this-command' would've been
199(defvar repeat-previous-repeated-command nil 190(defvar repeat-previous-repeated-command nil
200 "The previous repeated command.") 191 "The previous repeated command.")
201 192
202;; The following variable counts repeated self-insertions. The idea is
203;; that repeating a self-insertion command and subsequently undoing it
204;; should have almost the same effect as if the characters were inserted
205;; manually. The basic difference is that we leave in one undo-boundary
206;; between the original insertion and its first repetition.
207(defvar repeat-undo-count nil
208 "Number of self-insertions since last `undo-boundary'.")
209
210;;;###autoload 193;;;###autoload
211(defun repeat (repeat-arg) 194(defun repeat (repeat-arg)
212 "Repeat most recently executed command. 195 "Repeat most recently executed command.
@@ -254,7 +237,7 @@ recently executed command not bound to an input event\"."
254 (let ((repeat-repeat-char 237 (let ((repeat-repeat-char
255 (if (eq repeat-on-final-keystroke t) 238 (if (eq repeat-on-final-keystroke t)
256 last-command-event 239 last-command-event
257 ;; allow only specified final keystrokes 240 ;; Allow only specified final keystrokes.
258 (car (memq last-command-event 241 (car (memq last-command-event
259 (listify-key-sequence 242 (listify-key-sequence
260 repeat-on-final-keystroke)))))) 243 repeat-on-final-keystroke))))))
@@ -269,90 +252,45 @@ recently executed command not bound to an input event\"."
269 (setq current-prefix-arg repeat-arg) 252 (setq current-prefix-arg repeat-arg)
270 (repeat-message 253 (repeat-message
271 "Repeating command %S %S" repeat-arg last-repeatable-command)) 254 "Repeating command %S %S" repeat-arg last-repeatable-command))
272 (if (eq last-repeatable-command 'self-insert-command) 255 (when (eq last-repeatable-command 'self-insert-command)
273 (let ((insertion 256 ;; We used to use a much more complex code to try and figure out
274 (if (<= (- num-input-keys 257 ;; what key was used to run that self-insert-command:
275 repeat-num-input-keys-at-self-insert) 258 ;; (if (<= (- num-input-keys
276 1) 259 ;; repeat-num-input-keys-at-self-insert)
277 repeat-last-self-insert 260 ;; 1)
278 (let ((range (nth 1 buffer-undo-list))) 261 ;; repeat-last-self-insert
279 (condition-case nil 262 ;; (let ((range (nth 1 buffer-undo-list)))
280 (setq repeat-last-self-insert 263 ;; (condition-case nil
281 (buffer-substring (car range) 264 ;; (setq repeat-last-self-insert
282 (cdr range))) 265 ;; (buffer-substring (car range)
283 (error (error "%s %s %s" ;Danger, Will Robinson! 266 ;; (cdr range)))
284 "repeat can't intuit what you" 267 ;; (error (error "%s %s %s" ;Danger, Will Robinson!
285 "inserted before auto-fill" 268 ;; "repeat can't intuit what you"
286 "clobbered it, sorry"))))))) 269 ;; "inserted before auto-fill"
287 (setq repeat-num-input-keys-at-self-insert num-input-keys) 270 ;; "clobbered it, sorry")))))
288 ;; If the self-insert had a repeat count, INSERTION 271 (setq last-command-event (char-before)))
289 ;; includes that many copies of the same character. 272 (let ((indirect (indirect-function last-repeatable-command)))
290 ;; So use just the first character 273 (if (or (stringp indirect)
291 ;; and repeat it the right number of times. 274 (vectorp indirect))
292 (setq insertion (substring insertion -1)) 275 ;; Bind last-repeatable-command so that executing the macro does
293 (let ((count (prefix-numeric-value repeat-arg)) 276 ;; not alter it.
294 (i 0)) 277 (let ((last-repeatable-command last-repeatable-command))
295 ;; Run pre- and post-command hooks for self-insertion too. 278 (execute-kbd-macro last-repeatable-command))
296 (run-hooks 'pre-command-hook) 279 (call-interactively last-repeatable-command))))
297 (cond
298 ((not repeat-undo-count))
299 ((< repeat-undo-count 20)
300 ;; Don't make an undo-boundary here.
301 (setq repeat-undo-count (1+ repeat-undo-count)))
302 (t
303 ;; Make an undo-boundary after 20 repetitions only.
304 (undo-boundary)
305 (setq repeat-undo-count 1)))
306 (while (< i count)
307 (repeat-self-insert insertion)
308 (setq i (1+ i)))
309 (run-hooks 'post-command-hook)))
310 (let ((indirect (indirect-function last-repeatable-command)))
311 ;; Make each repetition undo separately.
312 (undo-boundary)
313 (if (or (stringp indirect)
314 (vectorp indirect))
315 ;; Bind real-last-command so that executing the macro does
316 ;; not alter it. Do the same for last-repeatable-command.
317 (let ((real-last-command real-last-command)
318 (last-repeatable-command last-repeatable-command))
319 (execute-kbd-macro last-repeatable-command))
320 (run-hooks 'pre-command-hook)
321 (call-interactively last-repeatable-command)
322 (run-hooks 'post-command-hook)))))
323 (when repeat-repeat-char 280 (when repeat-repeat-char
324 ;; A simple recursion here gets into trouble with max-lisp-eval-depth 281 (set-temporary-overlay-map
325 ;; on long sequences of repetitions of a command like `forward-word' 282 (let ((map (make-sparse-keymap)))
326 ;; (only 32 repetitions are possible given the default value of 200 for 283 (define-key map (vector repeat-repeat-char)
327 ;; max-lisp-eval-depth), but if I now locally disable the repeat char I 284 (if (null repeat-message-function) 'repeat
328 ;; can iterate indefinitely here around a single level of recursion. 285 ;; If repeat-message-function is let-bound, preserve it for the
329 (let (repeat-on-final-keystroke 286 ;; next "iterations of the loop".
330 ;; Bind `undo-inhibit-record-point' to t in order to avoid 287 (let ((fun repeat-message-function))
331 ;; recording point in `buffer-undo-list' here. We have to 288 (lambda ()
332 ;; do this since the command loop does not set the last 289 (interactive)
333 ;; position of point thus confusing the point recording 290 (let ((repeat-message-function fun))
334 ;; mechanism when inserting or deleting text. 291 (setq this-command 'repeat)
335 (undo-inhibit-record-point t)) 292 (call-interactively 'repeat))))))
336 (setq real-last-command 'repeat) 293 map)))))
337 (setq repeat-undo-count 1)
338 (unwind-protect
339 (while (let ((evt (read-key)))
340 ;; For clicks, we need to strip the meta-data to
341 ;; check the underlying event name.
342 (eq (or (car-safe evt) evt)
343 (or (car-safe repeat-repeat-char)
344 repeat-repeat-char)))
345 (repeat repeat-arg))
346 ;; Make sure `repeat-undo-count' is reset.
347 (setq repeat-undo-count nil))
348 (setq unread-command-events (list last-input-event))))))
349
350(defun repeat-self-insert (string)
351 (let ((i 0))
352 (while (< i (length string))
353 (let ((last-command-event (aref string i)))
354 (self-insert-command 1))
355 (setq i (1+ i)))))
356 294
357(defun repeat-message (format &rest args) 295(defun repeat-message (format &rest args)
358 "Like `message' but displays with `repeat-message-function' if non-nil." 296 "Like `message' but displays with `repeat-message-function' if non-nil."