GNU bug report logs - #4136
23.1; delete-pair

Previous Next

Package: emacs;

Reported by: Eli Barzilay <eli <at> barzilay.org>

Date: Thu, 13 Aug 2009 06:30:04 UTC

Severity: normal

Tags: fixed, moreinfo

Fixed in version 28.1

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

Full log


Message #25 received at 4136 <at> emacsbugs.donarmstrong.com (full text, mbox):

From: Eli Barzilay <eli <at> barzilay.org>
To: martin rudalics <rudalics <at> gmx.at>, Juri Linkov <juri <at> jurta.org>
Cc: 4136 <at> debbugs.gnu.org
Subject: Re: bug#4136: 23.1; delete-pair
Date: Thu, 13 Aug 2009 21:18:52 -0400
On Aug 13, martin rudalics wrote:
>  > `delete-pair' is deleting what it documents -- instead of removing the
>  > open paren of the following sexp, it deletes the current one.  So, if
>  > the cursor is on some whitespace that precedes an expression, the
>  > whitespace is deleted, and the open paren is left intact.
> 
> `delete-pair' shouldn't delete anything but matching elements of
> `insert-pair-alist'.

This is a very good point.


On Aug 14, Juri Linkov wrote:
> >> `delete-pair' is deleting what it documents -- instead of removing the
> >> open paren of the following sexp, it deletes the current one.  So, if
> >> the cursor is on some whitespace that precedes an expression, the
> >> whitespace is deleted, and the open paren is left intact.
> >
> > `delete-pair' shouldn't delete anything but matching elements of
> > `insert-pair-alist'.
> 
> This is rather vague semantics.  I suggest to keep the current simple
> semantics and just to fix it with the patch I sent.

I disagree in two different ways: (a) it can be put into code, so it's
not vague at all; (b) it sounds like a very good feature -- as it
stands, this function is nearly useless without human supervision,
which makes it useless for keyboard macros.

Here is a version that checks that does exactly what Martin suggested.
It even fails on something like (...] -- which is very useful for
keyboard macros, since if you have that text in a buffer, then
something is probably messed up enough to require your attention.


(defun delete-pair ()
  "Delete a pair of characters enclosing the sexp that follows point."
  (interactive)
  (save-excursion
    (let* ((end      (progn (forward-sexp  1) (point)))
           (start    (progn (forward-sexp -1) (point)))
           (start-ch (char-after start))
           (end-ch   (char-before end))
           (match-p  nil))
      (let ((p insert-pair-alist))
        (while p
          (let* ((q (car p))
                 (fst (if (= (length q) 3) 1 0))
                 (snd (1+ fst)))
            (if (and (equal start-ch (nth fst q))
                     (equal end-ch   (nth snd q)))
              (setq p nil match-p t)
              (setq p (cdr p))))))
      (if match-p
        (progn (delete-region (1- end) end)
               (delete-region start (1+ start)))
        (error "not a matching pair")))))


-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                    http://barzilay.org/                   Maze is Life!



This bug report was last modified 4 years and 182 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.