summaryrefslogtreecommitdiff
path: root/lisp/macros.el
diff options
context:
space:
mode:
authorJim Blandy <jimb@redhat.com>1991-05-17 00:15:22 +0000
committerJim Blandy <jimb@redhat.com>1991-05-17 00:15:22 +0000
commit06e4c53ff85ccb2e06908d4fea9e8c7c0a04d052 (patch)
treeb0430bdfb506f3a0c6623d7660e8d52c58e1938c /lisp/macros.el
parentb51ec287f3373bf946fee6faafe77ad34efa63d6 (diff)
downloademacs-06e4c53ff85ccb2e06908d4fea9e8c7c0a04d052.tar.gz
*** empty log message ***
Diffstat (limited to 'lisp/macros.el')
-rw-r--r--lisp/macros.el56
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)