[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#4136: 23.1; delete-pair
From: |
Eli Barzilay |
Subject: |
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!
- bug#4136: 23.1; delete-pair, Eli Barzilay, 2009/08/13
- bug#4136: 23.1; delete-pair, martin rudalics, 2009/08/13
- bug#4136: 23.1; delete-pair, Juri Linkov, 2009/08/13
- bug#4136: 23.1; delete-pair,
Eli Barzilay <=
- bug#4136: 23.1; delete-pair, Stefan Monnier, 2009/08/14
- bug#4136: 23.1; delete-pair, Juri Linkov, 2009/08/14
- bug#4136: 23.1; delete-pair, Eli Barzilay, 2009/08/14
- bug#4136: 23.1; delete-pair, Juri Linkov, 2009/08/15
- bug#4136: 23.1; delete-pair, Eli Barzilay, 2009/08/15
- bug#4136: 23.1; delete-pair, Juri Linkov, 2009/08/16
- bug#4136: 23.1; delete-pair, Eli Barzilay, 2009/08/16
- bug#4136: 23.1; delete-pair, Juri Linkov, 2009/08/20
- bug#4136: 23.1; delete-pair, martin rudalics, 2009/08/20
- bug#4136: 23.1; delete-pair, Juri Linkov, 2009/08/20