Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (setf *command-loop-interface-function* #'(lambda (x) (print x)))
- (setf *command-printer-class* 'printer-1)
- (defun my-command-loop ()
- "`*command-loop-interface-function*' takes in an object of class command, and any non-nil return is passed to `write-command-to-emacs'.
- This allows `*command-loop-interface-function*' to sit as an itermediary bettween the user command input and the Emacs command input.
- I made the input a global variable because a method for `write-command-to-emacs' needs to call `my-command-loop' without having
- access to the `interface-function'."
- (catch 'exit-command-loop
- (while t
- (let* ((command (funcall *command-loop-interface-function*
- (read-key-sequence-interface-hack))))
- (if command
- (write-command-to-emacs (make-instance *command-printer-class*
- :command command)))))))
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;;write Version 1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;keyboard-macros are acting buggy with printer-1. Goes into a recursion of keyboard-macros which can exceed maximum depth and such.
- ;;I plan on replacing the record and play keyboard macro functions, so it doesnt seem very important atm.
- (defclass printer-1 (printer)
- ())
- (defmethod write-command-to-emacs ((command printer-1))
- "First version of the command writter. Uses the variable `unread-command-events'."
- (let ((command-sequence (get-command command)))
- (setf unread-command-events
- (append unread-command-events
- (apply #'append
- (mapcar #'listify-key-sequence
- (flatten-tree command-sequence))))))
- (add-hook 'post-command-hook 're-enter-command-loop)
- (throw 'exit-command-loop nil))
- (defun re-enter-command-loop ()
- (if (null unread-command-events)
- (progn
- ;;Cleans the post-command-hook after it is set in `write-command-to-emacs'.
- (remove-hook 'post-command-hook 're-enter-command-loop)
- ;;Re-enters the command-loop.
- (my-command-loop))))
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;;write Version 2;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;;Thought this was going to obsolete version 1, but the behavior is not robust enough.
- ;;;Exits whenever there is a beep, cant do macros, and other oddities.
- (defclass printer-2 (printer)
- ())
- (defmethod write-command-to-emacs ((command printer-2))
- (let ((command-list (flatten-tree
- (get-command command))))
- (while command-list
- (print command-list)
- (execute-kbd-macro (pop command-list)))))
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement