home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / elisp / functions / undo-with-space.el < prev    next >
Encoding:
Text File  |  1991-03-20  |  1.8 KB  |  52 lines

  1. ; From: narten@cs.albany.edu (Thomas Narten)
  2. ; Subject: Undo-with-space
  3. ; Date: 18 Oct 90 02:06:11 GMT
  4. ; Organization: Computer Science Department, SUNY at Albany, Albany, NY 12222
  5. ; All this chatter about undo prompts me to post the following undo
  6. ; code.  I find it much more convenient for undoing things than the
  7. ; standard undo. When invoked, just keep in hitting space until you've
  8. ; gone back as far as you want.  One of those things from gosmacs that
  9. ; caused enormous withdrawal pains. :-)
  10. (defun undo-with-space ()
  11.   (interactive)
  12.   (undo-start)
  13.   (undo-more 2)
  14.   (message "Hit <space> to undo more")
  15.   (let ((char (read-char)))
  16.     (while (= char 32)
  17.       (message "undoing..")
  18.       (undo-more 1)
  19.       (message "Hit <space> to undo more")
  20.       (setq char (read-char)))
  21.     (message "Finished undoing")
  22.     (if (not (= char search-exit-char))    ; make exit character the same as isearch
  23.     (undo-with-space-execute-key-binding char)))
  24. )
  25.  
  26. (defun undo-with-space-execute-key-binding (ch) "execute command associated with keystroke"
  27.     (interactive "cWhat Key? ")        ; only asks question if interactive
  28.     (setq str (char-to-string ch))
  29.     (cond
  30.         ((equal ch 24)            ; ^X prefix
  31.         (progn
  32.             (message "C-x-")
  33.         (setq str (concat str (char-to-string (read-char))))))
  34.         ((equal ch 3)            ; ^C prefix
  35.         (progn
  36.             (message "C-c-")
  37.         (setq str (concat str (char-to-string (read-char))))))
  38.         ((equal ch 27)            ; ESC prefix
  39.         (progn
  40.             (message "ESC-")
  41.         (setq str (concat str (char-to-string (read-char))))))
  42.     )
  43.     (setq cmd (key-binding str))
  44.     ;(print (symbol-name cmd))          ; for debugging
  45.     (if (equal (symbol-name cmd) "self-insert-command")
  46.         (insert-char ch 1)        ; doesn't work right otherwise
  47.         (command-execute (symbol-function cmd) t) ; put cmd in command-history
  48.     )
  49. )
  50.