[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: New to elisp, learning by doing

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: Gecko/20020406 Netscape6/6.2.2

John Rabkin wrote:

 (defun html-yank-header ()
  "Copies and yanks HTML headers"
(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)

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
      (goto-char ...);; where the header should be inserted
      (insert (buffer-substring beg end) "\n"))))

<a href="mailto:&lt;kevin.rodgers&#64;;";>Kevin Rodgers</a>

reply via email to

[Prev in Thread] Current Thread [Next in Thread]