From: Xah Lee <xah@xahlee.org>
To: help-gnu-emacs@gnu.org
Subject: Re: Help with keybinding to delete between {}
Date: Wed, 5 Dec 2007 22:33:20 -0800 (PST) [thread overview]
Message-ID: <922740c0-88f0-42c0-a373-d7a28c354c4a@s12g2000prg.googlegroups.com> (raw)
In-Reply-To: 598472b5-c766-483a-93e5-15b31bfd880f@b40g2000prf.googlegroups.com
you wrote:
<<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.>>
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: ()[]<><<>>""''「」, 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 "^<>("{[「<<\"")
(setq b1 (point))
(goto-char (+ e2 1))
(skip-chars-forward "^<>)"}]」>>\"")
(setq b2 (point))
(push-mark b1 nil t)
)
(progn
(push-mark
(save-excursion
(skip-chars-backward "^<>("{[「<<\"")
(point)
) nil t)
(skip-chars-forward "^<>)"}]」>>\"")
)
)
)
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
\xAD\xF4 http://xahlee.org/
On Dec 4, 5:33 pm, lampshade <mwolff...@gmail.com> 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
next prev parent reply other threads:[~2007-12-06 6:33 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-12-05 1:33 Help with keybinding to delete between {} lampshade
2007-12-05 10:48 ` Bernardo Bacic
2007-12-05 12:55 ` William Xu
2007-12-05 13:30 ` Andreas Röhler
2007-12-05 23:50 ` Ilya Zakharevich
2007-12-06 6:33 ` Xah Lee [this message]
2007-12-06 17:14 ` Xah Lee
2007-12-12 9:20 ` lampshade
2007-12-13 3:59 ` Mike Mattie
[not found] ` <mailman.4961.1197518641.18990.help-gnu-emacs@gnu.org>
2007-12-13 10:39 ` Xah Lee
2007-12-13 10:44 ` Mike Mattie
2007-12-13 12:46 ` Mike Mattie
2007-12-13 13:01 ` Peter Dyballa
2007-12-14 11:43 ` Xah Lee
2007-12-07 16:30 ` Stefan Monnier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=922740c0-88f0-42c0-a373-d7a28c354c4a@s12g2000prg.googlegroups.com \
--to=xah@xahlee.org \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).