emacs-devel
[Top][All Lists]
Advanced

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

Re: Addition to lisp/misc.el


From: Lute Kamstra
Subject: Re: Addition to lisp/misc.el
Date: Mon, 08 Sep 2003 12:55:47 +0200
User-agent: Gnus/5.1003 (Gnus v5.10.3) Emacs/21.3.50 (gnu/linux)

Jérôme Marant <address@hidden> writes:

> Could someone please install this (zap-up-to-char)
>
>   http://mail.gnu.org/archive/html/emacs-devel/2003-05/msg00478.html
>
> in lisp/misc.el. I use it very often so I think it would deserve
> being part of Emacs. Richard proposed to include it in misc.el.

I reread the original discussion.  In the archived mail Jérôme Marant
refers to, Ehud Karni proposes this implementation:

(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 way, point is moved forward by one character if the
search-forward fails.  Seems undesirable to me.  I think this
implementation would be better:

(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.
Ignores CHAR at point."
  (interactive "p\ncZap up to char: ")
  (let ((direction (if (>= arg 0) 1 -1)))
    (kill-region (point)
                 (progn
                   (forward-char direction)
                   (unwind-protect
                       (search-forward (char-to-string char) nil nil arg)
                     (backward-char direction))
                   (point)))))

If nobody objects, I'll put it in lisp/misc.el.


  Lute.




reply via email to

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