unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Addition to lisp/misc.el
@ 2003-08-31  9:14 Jérôme Marant
  2003-09-08 10:55 ` Lute Kamstra
  0 siblings, 1 reply; 6+ messages in thread
From: Jérôme Marant @ 2003-08-31  9:14 UTC (permalink / raw)


Hi,

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.

Thanks in advance.

Regards,

-- 
Jérôme Marant <jerome.marant@free.fr>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Addition to lisp/misc.el
  2003-08-31  9:14 Addition to lisp/misc.el Jérôme Marant
@ 2003-09-08 10:55 ` Lute Kamstra
  2003-09-11 21:30   ` Miles Bader
  2003-09-23 11:54   ` Jérôme Marant
  0 siblings, 2 replies; 6+ messages in thread
From: Lute Kamstra @ 2003-09-08 10:55 UTC (permalink / raw)
  Cc: Jérôme Marant

Jérôme Marant <jerome.marant@free.fr> 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.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Addition to lisp/misc.el
  2003-09-08 10:55 ` Lute Kamstra
@ 2003-09-11 21:30   ` Miles Bader
  2003-09-12  5:01     ` Lute Kamstra
  2003-09-12 21:05     ` Richard Stallman
  2003-09-23 11:54   ` Jérôme Marant
  1 sibling, 2 replies; 6+ messages in thread
From: Miles Bader @ 2003-09-11 21:30 UTC (permalink / raw)


Lute Kamstra <Lute.Kamstra@cwi.nl> writes:
> 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."

Why the `Ignores CHAR at point' anyway?  That seems the cause of the
slight code ugliness.  What uses are proposed for this function (which
might help to understand this point)?

-Miles
-- 
Yo mama's so fat when she gets on an elevator it HAS to go down.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Addition to lisp/misc.el
  2003-09-11 21:30   ` Miles Bader
@ 2003-09-12  5:01     ` Lute Kamstra
  2003-09-12 21:05     ` Richard Stallman
  1 sibling, 0 replies; 6+ messages in thread
From: Lute Kamstra @ 2003-09-12  5:01 UTC (permalink / raw)
  Cc: emacs-devel

Miles Bader <miles@gnu.org> writes:

> Lute Kamstra <Lute.Kamstra@cwi.nl> writes:
>> 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."
>
> Why the `Ignores CHAR at point' anyway?  That seems the cause of the
> slight code ugliness.  What uses are proposed for this function (which
> might help to understand this point)?

If it ignores CHAR at point, repeating the command is not a no-op.
(This was discussed before.)

  Lute.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Addition to lisp/misc.el
  2003-09-11 21:30   ` Miles Bader
  2003-09-12  5:01     ` Lute Kamstra
@ 2003-09-12 21:05     ` Richard Stallman
  1 sibling, 0 replies; 6+ messages in thread
From: Richard Stallman @ 2003-09-12 21:05 UTC (permalink / raw)
  Cc: emacs-devel

    > (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."

    Why the `Ignores CHAR at point' anyway?

Because otherwise it would be a no-op when CHAR appear there; in
particular, repeating it would be useless.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Addition to lisp/misc.el
  2003-09-08 10:55 ` Lute Kamstra
  2003-09-11 21:30   ` Miles Bader
@ 2003-09-23 11:54   ` Jérôme Marant
  1 sibling, 0 replies; 6+ messages in thread
From: Jérôme Marant @ 2003-09-23 11:54 UTC (permalink / raw)
  Cc: emacs-devel


Hi,

(Back from vacation)

Quoting Lute Kamstra <Lute.Kamstra@cwi.nl>:

> 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.

This one works for me as well. Could you please commit it?

Thanks in advance.

-- 
Jérôme Marant

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2003-09-23 11:54 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-08-31  9:14 Addition to lisp/misc.el Jérôme Marant
2003-09-08 10:55 ` Lute Kamstra
2003-09-11 21:30   ` Miles Bader
2003-09-12  5:01     ` Lute Kamstra
2003-09-12 21:05     ` Richard Stallman
2003-09-23 11:54   ` Jérôme Marant

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).