all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Kevin Rodgers <kevin.rodgers@ihs.com>
Subject: Re: New to elisp, learning by doing
Date: Mon, 17 Feb 2003 11:47:16 -0700	[thread overview]
Message-ID: <3E512E34.6030605@ihs.com> (raw)
In-Reply-To: pan.2003.02.16.22.45.23.976208@actcom.com

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:&lt;kevin.rodgers&#64;ihs.com&gt;">Kevin Rodgers</a>

      parent reply	other threads:[~2003-02-17 18:47 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-02-16 22:45 New to elisp, learning by doing John Rabkin
2003-02-17  2:03 ` Christopher J. White
2003-02-17  7:16 ` Kai Großjohann
2003-02-17  9:27   ` Hannu Koivisto
2003-02-18  8:02     ` Kai Großjohann
2003-02-17 18:24   ` Ehud Karni
     [not found]   ` <mailman.2034.1045507046.21513.help-gnu-emacs@gnu.org>
2003-02-17 19:50     ` Kai Großjohann
2003-02-18 10:26   ` Oliver Scholz
2003-02-17 18:47 ` Kevin Rodgers [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3E512E34.6030605@ihs.com \
    --to=kevin.rodgers@ihs.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.