Subject: Re: bug#4136: 23.1; delete-pair

From: Eli Barzilay <[email-masked]>
Date: Sat, 15 Aug 2009 20:00:22 -0400

On Aug 16, Juri Linkov wrote:
> >> It seems you and Martin prefer checking against the
> >> `insert-pair-alist' because the function name `delete-pair'
> >> suggests it should be a counterpart of `insert-pair'.
> >
> > ...this is exactly the issue: it is much better if `delete-foo' is
> > always an operation that reverts what `insert-foo' does.
> 
> The exact reverse is impossible.

Of course it isn't, but the operation is one that negates in what it
"generally does" the thing that `insert-foo' does.  Just like
`scroll-down' and `scroll-up' are opposites even though they don't
always cancel out.

> > The current state of `delete-pair' is so bad that my guess is that
> > hardly anyone used it, so adding another command doesn't make much
> > sense.  How about making it do the proper thing (removing only
> > balanced pairs as specified by `insert-pair-alist'), and ignoring
> > errors with a prefix argument?
> 
> I've been using `delete-pair' for many years several times a day
> without any problem because my lists are always correctly balanced
> thanks to `insert-pair' that I exclusively use to create balanced
> lists and strings.

Believe me, I've written a paren or two, and I use `insert-pair'
enough to have my own improved version of it.  (In fact, guess why I
almost never use smileys in emails.)  Still, the first time I tried
this, the cursor was at the beginning of an indented line.  But the
point is still the same: having two nearly identical functions is
exactly what prefix arguments are for.

> That's why even in the current state of `delete-pair' it is the
> useful reverse of `insert-pair' because the latter creates balanced
> lists and the former deletes them.

... unless you happen to have your cursor on a non-paren.

> >> This is fixed in the following version:
> >> [...]
> >
> > This version doesn't make much sense as an operation you'd want to do
> > on code:
> >
> >   (foo '(x y z))
> >   -->
> >   (foo 'x y z)
> 
> It makes sense when `foo' is a multi-argument function like `list',
> e.g.
> 
>     (list 'x y z)
> 
> So I see no reason to introduce more restrictions to decide what
> parens the user is allowed to delete in his/her code.

You've missed my point: the difference between "y" and "'y" is *huge*,
changing one to the other is something that you don't want to do by
mistake.

On Aug 16, Juri Linkov wrote:
> >> This is fixed in the following version:
> >>
> >> (defun delete-pair ()
> >>   "Delete a pair of characters enclosing the sexp that follows point."
> >>   (interactive)
> >>   (save-excursion
> >>     (forward-sexp 1)
> >>     (save-excursion
> >>       (backward-sexp 1)
> >>       (skip-syntax-forward "'")
> >>       (delete-char 1))
> >>     (delete-char -1)))
> >
> > Still doesn't seem TDTRT with `point' before something like
> >
> >        `foo'
> 
> I know, I know, after I fix this, you'll come up with another
> test case like
> 
>          `foo bar'

Those examples are very good IMO -- it's not being picky for nothing,
it's an attempt to avoid nasty surprises that make you end up with
erroneous code.  Emacs is usually good at being a careful editor for
code, `delete-pair' is very exceptional in this aspect.

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