[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Zap-to-char behaviour
From: |
Ehud Karni |
Subject: |
Re: Zap-to-char behaviour |
Date: |
Wed, 21 May 2003 23:31:43 +0300 |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Wed, 21 May 2003 12:37:14 -0500 (CDT), Luc Teirlinck <address@hidden> wrote:
>
> No, as John Paul Wallington already pointed out, all you need to do is
> uncomment a comment in the function definition. If you are planning
> on using both functions, I would also suggest differentiating between
> the two echo area messages. Result:
>
> (defun zap-up-to-char (arg char)
> "Kill up to, but not including ARG'th occurrence of CHAR.
> Case is ignored if `case-fold-search' is non-nil in the current buffer.
> Goes backward if ARG is negative; error if CHAR not found."
> (interactive "p\ncZap up to char: ")
> (kill-region (point) (progn
> (search-forward (char-to-string char) nil nil arg)
> (goto-char (if (> arg 0) (1- (point)) (1+ (point))))
> (point))))
>
> The problem now is that if you want to keep the regular M-z binding to
> zap-to-char, then you probably will need to bind the new command to a
> longer key sequence and it takes only one keystroke to retype the
> character anyway.
No, that is not enough, because, as RMS pointed out, running this a
second time (when arg = 1, the default) will do nothing. This will
make it inconsistent (2 times M-3 `zap-up-to-char' will be different
from 3 * M-2 `zap-up-to-char'). If you want a consistent function I
propose the following:
(defun zap-up-to-char (arg char)
"Kill up to, but not including ARG'th occurrence of CHAR.
Case is ignored if `case-fold-search' is non-nil in the current buffer.
Goes backward if ARG is negative; error if CHAR not found.
If ARG is 0, do nothing. If character at (point) is CHAR skip it."
(interactive "p\ncZap up to char: ")
(or (zerop arg)
(let ((direction (if (> arg 0) 1 -1)))
(kill-region (point)
(progn
(forward-char direction)
(search-forward (char-to-string char) nil nil arg)
(- (point) direction)))
(backward-char direction))))
This was was tested lightly and it seems consistent. The kill ring
is also seems OK when repeating the operation several times.
My personal opinion is that `zap-to-char' is good enough for me and
I don't need this one, but if you want it, it better be good.
Ehud.
- --
Ehud Karni Tel: +972-3-7966-561 /"\
Mivtach - Simon Fax: +972-3-7966-667 \ / ASCII Ribbon Campaign
Insurance agencies (USA) voice mail and X Against HTML Mail
http://www.mvs.co.il FAX: 1-815-5509341 / \
mailto:address@hidden Better Safe Than Sorry
-----BEGIN PGP SIGNATURE-----
Comment: use http://www.keyserver.net/ to get my key (and others)
iD8DBQE+y+IuLFvTvpjqOY0RAmAiAJ0YLJxEe8cZhuZLKBIbNxRWMcJk5gCfY9Kj
QpPJf2tv/z+aHmQWFRwRz/w=
=CsQ7
-----END PGP SIGNATURE-----
Re: Zap-to-char behaviour, Jérôme Marant, 2003/05/22