|
From: | Kevin Rodgers |
Subject: | Re: New to elisp, learning by doing |
Date: | Mon, 17 Feb 2003 11:47:16 -0700 |
User-agent: | Mozilla/5.0 (X11; U; SunOS i86pc; en-US; rv:0.9.4.1) Gecko/20020406 Netscape6/6.2.2 |
John Rabkin wrote:
(defun html-yank-header () "Copies and yanks HTML headers" (interactive) (save-excursion(setq start_p (- (re-search-forward "\<h[12345]*\>") 4)) (setq end_p (re-search-forward "\<\/h[12345]\>")) (copy-region-as-kill start_p end_p)) (yank) )
I would avoid using the kill ring, and instead use `buffer-substring' to get the header text and insert to `insert' in the buffer. I would also be a little more careful with the regexps used to match the start and end tags: (let ((case-fold-search t) beg end level) (while (re-search-forward "<h\\([1-5]\\)[^>]*>" nil t) (setq beg (match-beginning 0) level (string-to-int (match-string 1)) end (re-search-forward (format "</h%d>" level) nil t))a (save-excursion (goto-char ...);; where the header should be inserted (insert (buffer-substring beg end) "\n")))) -- <a href="mailto:<kevin.rodgers@ihs.com>">Kevin Rodgers</a>
[Prev in Thread] | Current Thread | [Next in Thread] |