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:

  1. define function runs macro: write in emacs-lisp buffer leaving cursor @ end:: (defun foo ()

  2. m-x insert-kbd-macro ret

    now have text, definition of keyboard macro in place of xxxxx:

    (defun foo () (setq last-kbd-macro xxxxx)

  3. replace setq last-kbd-macro execute-kbd-macro, , add final ):

    (defun foo () (execute-kbd-macro xxxxx)

  4. then use c-x c-e after definition or c-m-x anywhere inside it.

    that defines function foo, keyboard macro did (in same context, e.g., same mode, same key bindings).

  5. save definition init file. can use emacs in batch mode. can add (interactive) after () make command, can use m-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

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -