all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Seweryn Kokot <s.kokot@po.opole.pl>
To: help-gnu-emacs@gnu.org
Subject: Re: elisp, replace-regexp and re-search-forward
Date: Mon, 01 Oct 2007 18:11:06 +0200	[thread overview]
Message-ID: <87wsu6lsrp.fsf@poczta.po.opole.pl> (raw)
In-Reply-To: 1191238610.992573.294470@n39g2000hsh.googlegroups.com

weber <hugows@gmail.com> writes:

> Another version imitates what you would do if you were going to do it
> manually (jump one line, press ret, jump one line..) :
>
> (defun insert-lines (beg end)
>   (interactive "r")
>   (goto-char beg)
>   (while (< (point) end)
> 	(insert "\n")
> 	(next-line 1)))
>
> Regards,
> weber

thanks for another approach. However I needed to modify the function a
little. So now I have two working functions

; works
(defun insert-lines (beg end)
  (interactive "r")
  (save-excursion
	(let ((line 1)
		  (region-lines (count-lines beg end)))
	  (goto-char beg)
	  (while (< line region-lines)
		(end-of-line)
		(insert "\n")
		(forward-line)
		(setq line (+ line 1))))))

; works
(defun my-test (beg end)
  (interactive "r")
  (replace-regexp "\n" "\n\n" nil beg end))

and one which doesn't work

(defun insert-empty-lines (beg end)
  (interactive "r")
	(goto-char beg)
	(while (re-search-forward "\n" end t)
	  (replace-match "\n\n" nil nil)))

namely if I select the following region from 1 (mark at 1) to 7 (mark
after 7)

1
2
3
4
5
6
7

I get something like this

1

2

3

4

5
6
7

(note that there is no \n after 5 and 6). It seems that the replacement
doesn't reach the end bound which was after number 7.  Any ideas what is
wrong?

regards,
-- 
Seweryn Kokot

  reply	other threads:[~2007-10-01 16:11 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <mailman.1531.1191229744.18990.help-gnu-emacs@gnu.org>
2007-10-01 11:36 ` elisp, replace-regexp and re-search-forward weber
2007-10-01 16:11   ` Seweryn Kokot [this message]
2007-10-01 16:21     ` Bastien
     [not found]     ` <mailman.1550.1191255727.18990.help-gnu-emacs@gnu.org>
2007-10-01 20:03       ` weber
2007-10-01 20:06       ` weber
2007-10-01  9:08 Bourgneuf Francois
  -- strict thread matches above, loose matches on Subject: below --
2007-10-01  7:56 Seweryn Kokot

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=87wsu6lsrp.fsf@poczta.po.opole.pl \
    --to=s.kokot@po.opole.pl \
    --cc=help-gnu-emacs@gnu.org \
    /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.