Advertisement
Guest User

Untitled

a guest
Apr 29th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.87 KB | None | 0 0
  1.  
  2.  
  3. (setf *command-loop-interface-function* #'(lambda (x) (print x)))
  4. (setf *command-printer-class* 'printer-1)
  5.  
  6. (defun my-command-loop ()
  7. "`*command-loop-interface-function*' takes in an object of class command, and any non-nil return is passed to `write-command-to-emacs'.
  8. This allows `*command-loop-interface-function*' to sit as an itermediary bettween the user command input and the Emacs command input.
  9. I made the input a global variable because a method for `write-command-to-emacs' needs to call `my-command-loop' without having
  10. access to the `interface-function'."
  11. (catch 'exit-command-loop
  12. (while t
  13. (let* ((command (funcall *command-loop-interface-function*
  14. (read-key-sequence-interface-hack))))
  15. (if command
  16. (write-command-to-emacs (make-instance *command-printer-class*
  17. :command command)))))))
  18.  
  19.  
  20. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  21. ;;;write Version 1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  22.  
  23. ;;keyboard-macros are acting buggy with printer-1. Goes into a recursion of keyboard-macros which can exceed maximum depth and such.
  24. ;;I plan on replacing the record and play keyboard macro functions, so it doesnt seem very important atm.
  25.  
  26. (defclass printer-1 (printer)
  27. ())
  28.  
  29. (defmethod write-command-to-emacs ((command printer-1))
  30. "First version of the command writter. Uses the variable `unread-command-events'."
  31. (let ((command-sequence (get-command command)))
  32. (setf unread-command-events
  33. (append unread-command-events
  34. (apply #'append
  35. (mapcar #'listify-key-sequence
  36. (flatten-tree command-sequence))))))
  37. (add-hook 'post-command-hook 're-enter-command-loop)
  38. (throw 'exit-command-loop nil))
  39.  
  40. (defun re-enter-command-loop ()
  41. (if (null unread-command-events)
  42. (progn
  43. ;;Cleans the post-command-hook after it is set in `write-command-to-emacs'.
  44. (remove-hook 'post-command-hook 're-enter-command-loop)
  45. ;;Re-enters the command-loop.
  46. (my-command-loop))))
  47.  
  48. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  49. ;;;write Version 2;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  50. ;;;Thought this was going to obsolete version 1, but the behavior is not robust enough.
  51. ;;;Exits whenever there is a beep, cant do macros, and other oddities.
  52.  
  53.  
  54.  
  55. (defclass printer-2 (printer)
  56. ())
  57.  
  58. (defmethod write-command-to-emacs ((command printer-2))
  59. (let ((command-list (flatten-tree
  60. (get-command command))))
  61. (while command-list
  62. (print command-list)
  63. (execute-kbd-macro (pop command-list)))))
  64.  
  65. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  66. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement