From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Xah Lee Newsgroups: gmane.emacs.help Subject: Re: Help with keybinding to delete between {} Date: Wed, 5 Dec 2007 22:33:20 -0800 (PST) Organization: http://groups.google.com Message-ID: <922740c0-88f0-42c0-a373-d7a28c354c4a@s12g2000prg.googlegroups.com> References: <598472b5-c766-483a-93e5-15b31bfd880f@b40g2000prf.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-2022-JP Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1196923253 24155 80.91.229.12 (6 Dec 2007 06:40:53 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 6 Dec 2007 06:40:53 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Dec 06 07:41:02 2007 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1J0APr-0001PI-3f for geh-help-gnu-emacs@m.gmane.org; Thu, 06 Dec 2007 07:40:59 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1J0APa-0007rQ-6E for geh-help-gnu-emacs@m.gmane.org; Thu, 06 Dec 2007 01:40:42 -0500 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!postnews.google.com!s12g2000prg.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 105 Original-NNTP-Posting-Host: 64.9.239.250 Original-X-Trace: posting.google.com 1196922800 1514 127.0.0.1 (6 Dec 2007 06:33:20 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Thu, 6 Dec 2007 06:33:20 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: s12g2000prg.googlegroups.com; posting-host=64.9.239.250; posting-account=qPxGtQkAAADb6PWdLGiWVucht1ZDR6fn User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/523.12 (KHTML, like Gecko) Version/3.0.4 Safari/523.12, gzip(gfe), gzip(gfe) Original-Xref: shelby.stanford.edu gnu.emacs.help:154451 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:49880 Archived-At: you wrote: <> I wrote a code few months ago that does exactly what you asked. (defun delete-enclosed-text () "Delete texts between any pair of delimiters." (interactive) (skip-chars-backward "^<>()""") (delete-char (skip-chars-forward "^<>()"""))) For more, see: http://xahlee.org/emacs/elisp_examples.html These days i don't use the above. Instead, i have a extend-selection that selects text inside matching pairs. (then i can delete or cop or cut with another keystroke) Here's the code: (defun extend-selection () "Highlight a region between the nearest left and right delimiters. Delimiters are paired characters: ()[]<><<>>""''$B!V!W(B, including \"\". When the function is run again, it extends the selection to the next level of enclosing delimiters. " (interactive) (if (or (and (eq last-command this-command) (mark t)) (and transient-mark-mode mark-active)) (let ((e1 (region-beginning)) (e2 (region-end)) b1 b2) (goto-char (- e1 1)) (skip-chars-backward "^<>("{[$B!V(B<<\"") (setq b1 (point)) (goto-char (+ e2 1)) (skip-chars-forward "^<>)"}]$B!W(B>>\"") (setq b2 (point)) (push-mark b1 nil t) ) (progn (push-mark (save-excursion (skip-chars-backward "^<>("{[$B!V(B<<\"") (point) ) nil t) (skip-chars-forward "^<>)"}]$B!W(B>>\"") ) ) ) This is currently assigned to Alt+7. In the near future i'll rework the code so that, on repeated press of Alt+7, it extend to outer matching pairs. (skiping pairs of delimiters that's siblings) For more detail on this concept, see: A Text Editor Feature: Syntax Tree Walk http://xahlee.org/emacs/syntax_tree_walk.html This concept of code selection is far more powerful (and simpler) than existing sexp forward/backward or the whole set of paren-edit.el, in particular when combined with a auto-lisp-formater. (detailed at: A Simple Lisp Code Formatter http://xahlee.org/emacs/lisp_formatter.html ) PS this message is posted thur groups.google.com. It in the past half a year has been diddling with the french quote charaters "<<>>" (double angle quotes; unicode U+00AB and U+00BB) that i use often for quation in my posts. For a period google groups will omit them, another period it'll replace it with << and >>, and in the past week sometimes it'll omit the closing char. In this post, the elisp code above also contain the french quote. Let's see what google transformed it to this time. Xah xah@xahlee.org $B-t(B http://xahlee.org/ On Dec 4, 5:33 pm, lampshade wrote: > Hello, > > I would really like a keybinding that would allow me to delete any > text between sexp's like {} (), etc no matter where I am between them > and whether or not that text has spaces. > > For example > {asdfdsfa asdfasdf asd} > I would like to delete between leaving only the {} with my cursor > inside ready to type. So far I've been trying > (defun delete_between () > (interactive) > (backward-sexp) > (kill-sexp)) > (global-set-key [(control meta k)] 'delete_between) > > but that doesn't quite work. Anyone have any improvements or help > they could give me? > > Thanks in advance, > lampshade