elisp - Running emacs keyboard macros in batch mode -
i want able save keyboard macro in emacs , apply file repeatedly in batch mode. give simple example, made following file paren-delete.el supposed delete parentheses , contents. when run emacs --batch target.txt --load paren-delete.el, nothing seems have changed. appears first kbd function it's supposed to, don't understand how command works.
i know preferable avoid keyboard macros , write functions in proper elisp, i'd prefer quick-and-dirty solution, , feel i'm close.
(kbd "m-x load-library kmacro") (fset 'delete-paren (lambda (&optional arg) "keyboard macro." (interactive "p") (kmacro-exec-ring-item (quote ("^s(^m^b^@^[^n^w" 0 "%d")) arg))) (start-kbd-macro nil) (kbd "m-x delete-paren") (end-kbd-macro) (kbd "c-u 0 c-x e") (save-buffer)
one answer:
define function runs macro: write in emacs-lisp buffer leaving cursor @ end::
(defun foo ()
m-x insert-kbd-macro ret
now have text, definition of keyboard macro in place of
xxxxx
:(defun foo () (setq last-kbd-macro xxxxx)
replace
setq last-kbd-macro
execute-kbd-macro
, , add final)
:(defun foo () (execute-kbd-macro xxxxx)
then use
c-x c-e
after definition orc-m-x
anywhere inside it.that defines function
foo
, keyboard macro did (in same context, e.g., same mode, same key bindings).save definition init file. can use emacs in batch mode. can add
(interactive)
after()
make command, can usem-x
.
another answer:
with bookmark+, use c-u m-x bmkp-make-function-bookmark
create bookmark last keyboard macro. prompted bookmark name.
bookmarks persistent. use bookmark in batch mode, call argument of bookmark-jump
, so: (bookmark-jump the-bookmark-name)
.
Comments
Post a Comment