[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

keyboard macros



One of my favorite features of gnu emacs is the ability to define and 
execute keyboard macros.  I tried to make something similar work in
fred.  It works, but not very well---in particular, it won't work with
incremental searches or if *fred-hook* is not nil.  The latter could
easily be fixed, but I have no idea about the former.  I wonder if
anyone else has tried to impliment keyboard macros.

At any rate, here is my code.  It was written partly as an exercise in
the use of "advise", inspired by the recently posted "do-last-menu-command"

Suggestions and improvements are most welcome.

(defvar *command-list* nil)

(defmethod def-key-macro ((win fred-window) )
        (set-mini-buffer win "Defining keyboard macro")
        (setq *command-list* nil)
        (advise run-fred-command
                (push  (list (car arglist) 
                                  (cadr arglist) 
                                  *current-character*
                                  *current-keystroke*)
                      *command-list*)
                :when :after
                :name *command-list*))

(defmethod defed-key-macro ((win fred-window))
  (unadvise run-fred-command :when :after :name *command-list*)
  (pop *command-list*)
  (setq *command-list* (reverse *command-list*))
  (if *command-list*
    (set-mini-buffer win "keyboard macro defined")
    (set-mini-buffer win "empty keyboard macro")))

(defmethod ed-execute-key-macro ((win fred-window))
  (mapcar #'re-run-fred *command-list*))


(defun re-run-fred (params)
  (let ((*current-character* (caddr params))
        (*current-keystroke* (fourth params)))
    (run-fred-command (car params) (cadr params))))
      

(comtab-set-key *control-x-comtab* '(#\() 'def-key-macro)
(comtab-set-key *control-x-comtab* '(#\)) 'defed-key-macro)
(comtab-set-key *control-x-comtab* '(#\e) 'ed-execute-key-macro)