diff options
author | Jim Blandy <jimb@redhat.com> | 1991-05-17 00:15:22 +0000 |
---|---|---|
committer | Jim Blandy <jimb@redhat.com> | 1991-05-17 00:15:22 +0000 |
commit | 63c86e176db3da13697a283615420b6223f81f9e (patch) | |
tree | cbea635ad26a9498a40c6a36d3062b2f1976aaf8 /lisp/macros.el | |
parent | db9f027896e815f919b717e699cd3a6c3daef956 (diff) | |
download | emacs-63c86e176db3da13697a283615420b6223f81f9e.tar.gz |
*** empty log message ***
Diffstat (limited to 'lisp/macros.el')
-rw-r--r-- | lisp/macros.el | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/lisp/macros.el b/lisp/macros.el index 75510a48ed9..42fedffafdc 100644 --- a/lisp/macros.el +++ b/lisp/macros.el @@ -105,4 +105,60 @@ C-l -- redisplay screen and ask again." (recursive-edit)))))))))) ;;;###autoload +(defun apply-macro-to-region-lines (top bottom &optional macro) + "For each complete line in the current region, move to the beginning of +the line, and run the last keyboard macro. + +When called from lisp, this function takes two arguments TOP and +BOTTOM, describing the current region. TOP must be before BOTTOM. +The optional third argument MACRO specifies a keyboard macro to +execute. + +This is useful for quoting or unquoting included text, adding and +removing comments, or producing tables where the entries are regular. + +For example, in Usenet articles, sections of text quoted from another +author are indented, or have each line start with `>'. To quote a +section of text, define a keyboard macro which inserts `>', put point +and mark at opposite ends of the quoted section, and use +`\\[apply-macro-to-region-lines]' to mark the entire section. + +Suppose you wanted to build a keyword table in C where each entry +looked like this: + + { \"foo\", foo_data, foo_function }, + { \"bar\", bar_data, bar_function }, + { \"baz\", baz_data, baz_function }, + +You could enter the names in this format: + + foo + bar + baz + +and write a macro to massage a word into a table entry: + + \\C-x ( + \\M-d { \"\\C-y\", \\C-y_data, \\C-y_function }, + \\C-x ) + +and then select the region of un-tablified names and use +`\\[apply-macro-to-region-lines]' to build the table from the names. +" + (interactive "r") + (if (null last-kbd-macro) + (error "No keyboard macro has been defined.")) + (save-excursion + (let ((end-marker (progn + (goto-char bottom) + (beginning-of-line) + (point-marker)))) + (goto-char top) + (if (not (bolp)) + (forward-line 1)) + (while (< (point) end-marker) + (execute-kbd-macro (or macro last-kbd-macro)) + (forward-line 1))))) + +;;;###autoload (define-key ctl-x-map "q" 'kbd-macro-query) |