|
From: | Kevin Rodgers |
Subject: | Re: elisp question |
Date: | Thu, 01 May 2008 07:08:32 -0600 |
User-agent: | Thunderbird 2.0.0.12 (Macintosh/20080213) |
harven wrote:
I am trying to device a short command to interactively resize the current window: (defun resize-window (key) "resize interactively the window" (interactive "c- widen, _ shrink") (cond ((eq key (string-to-char "-")) (enlarge-window 1) (call-interactively 'resize-window)) ((eq key (string-to-char "_")) (enlarge-window -1) (call-interactively 'resize-window)) (t (insert key)))) I type -/_ a number of times, the window enlarges/shrinks, and if I type another character, the window resizing stops and the character is inserted. However, I would like the following effect. Any entry other than -/_ should end the resizing and be executed. How can I achieve such effect ?
See the unread-command-events variable. Here's an iterative version to compare to your recursive implementation: (defvar enlarge-window-char ?_) ; or ?+ (defvar shrink-window-char ?-) (defun resize-window (&optional arg) "Interactively resize the selected window. Repeatedly prompt whether to enlarge or shrink the window until the response is neither `enlarge-window-char' or `shrink-window-char'. When called with a prefix arg, resize the window by ARG lines." (interactive "p") (let ((prompt (format "Enlarge/Shrink window (%c/%c)? " enlarge-window-char shrink-window-char)) response) (while (progn (setq response (read-event prompt)) (cond ((equal response enlarge-window-char) (enlarge-window arg) t) ((equal response shrink-window-char) (enlarge-window (- arg)) t) (t nil))) ;; no loop body needed ) (push response unread-command-events))) -- Kevin Rodgers Denver, Colorado, USA
[Prev in Thread] | Current Thread | [Next in Thread] |