emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Insert character pairs


From: Juri Linkov
Subject: Re: Insert character pairs
Date: Thu, 06 May 2004 15:02:15 +0300
User-agent: Gnus/5.110002 (No Gnus v0.2) Emacs/21.3.50 (gnu/linux)

Richard Stallman <address@hidden> writes:
>     Good names, but not completely true.  Actually, this function deletes
>     all the text inside the sexp out of one level of parentheses, except
>     sexps selected by the argument or active region in transient-mark-mode.
>
> The name delete-surrounding-sexp would fit that command, but
> that doesn't seem like a very useful command.
>
> I had misunderstood the previous description; I though the idea was
> to delete just the parentheses, more or less the opposite of what
> insert-parentheses does.  The name delete-surrounding-sexp would
> not fit that at all, but raise-sexp or promote-sexp would fit it.

This suggests that actually two separate commands would be useful:
`delete-parentheses' and `raise-sexp'.

Both would operate on the sexp that follows point, with the
difference that the latter simply deletes enclosing parentheses,
and the former deletes the whole surrounding sexp excluding some
selected inner sexps.

Both are useful: `delete-parentheses' is useful to delete not only
parentheses, but any enclosing characters, including all kinds of
quotes.  And `raise-sexp' is very handy for editing Emacs Lisp
programs to replace the surrounding sexp by selected inner sexps:
e.g. to move sexps from `if' condition, from `save-excursion' and
in many other similar situations.  For example, suppose that there
is the need to change `(save-excursion (insert s))' into `(insert s)'.
Currently, this requires too many keystrokes.  `raise-sexp' will
allow to do this with only one command.

Index: emacs/lisp/emacs-lisp/lisp.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/emacs-lisp/lisp.el,v
retrieving revision 1.53
diff -u -r1.53 lisp.el
--- emacs/lisp/emacs-lisp/lisp.el       1 May 2004 03:58:43 -0000       1.53
+++ emacs/lisp/emacs-lisp/lisp.el       6 May 2004 11:56:44 -0000
@@ -348,6 +371,27 @@

+(defun delete-pair ()
+  "Delete a pair of characters enclosing the sexp that follows point."
+  (interactive)
+  (save-excursion (forward-sexp 1) (delete-char -1))
+  (delete-char 1))
+
+(defalias 'delete-parentheses 'delete-pair)
+
+(defun raise-sexp (&optional arg)
+  "Raise ARG sexps higher up the tree."
+  (interactive "p")
+  (let ((s (if (and transient-mark-mode mark-active)
+               (buffer-substring (region-beginning) (region-end))
+             (buffer-substring
+              (point)
+              (save-excursion (forward-sexp arg) (point))))))
+    (backward-up-list 1)
+    (delete-region (point) (save-excursion (forward-sexp 1) (point)))
+    (save-excursion (insert s))))

-- 
Juri Linkov
http://www.jurta.org/emacs/





reply via email to

[Prev in Thread] Current Thread [Next in Thread]