[OS X Emacs] Re: delete parantheses pair
Marinos K
marinos at agxivatein.com
Thu Feb 10 11:42:02 EST 2011
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
I think I finished my homework..
it looks for strings of the type .something() or .something{} and kills them
thx
(defun sc-delete-delimiters-and-msg ()
"deletes a pair of delimiters and the msg-expression attached in the
end (if one) leaving what' s inside intact. eg: [1,2,3].choose;->1,2,3"
(interactive)
(cond ((or (looking-at "\\s(") (looking-at "\\s[") (looking-at "\\s{")
(looking-at "\\s\"") )
(save-excursion
(let ((open-paren (point)))
(forward-sexp)
(delete-char -1)
(if (char-equal (char-after) ?.)
(progn (kill-word 1)
(if (or (char-equal (char-after) ?\() (char-equal (char-after) ?\{))
(kill-sexp))))
(goto-char open-paren)
(delete-char 1))))
(t
(error "Not looking at open parenthesis")
)))
On 10/02/2011 11:20 ?.?., Marinos K wrote:
> thx Marc !
>
> it seems pretty elegant..
>
> m
>
> On 09/02/2011 10:34 ?.?., Marc Shapiro -- at work wrote:
>>>
>>> Message: 1
>>> Date: Tue, 08 Feb 2011 21:40:26 -0800
>>> From: David Rogoff <cs80 at therogoffs.com>
>>> Subject: Re: [OS X Emacs] delete parantheses pair
>>> To: Emacs on Mac OS X Mailing List <macosx-emacs at email.esm.psu.edu>
>>> Message-ID: <4D5228CA.10102 at therogoffs.com>
>>> Content-Type: text/plain; charset="iso-8859-1"
>>>
>>>
>>>>
>>>> I want to code a function or a macro that would delete a pair of
>>>> delimiters (but not what is inside) and optionally the adjoined word
>>>>
>>>> so this
>>>>
>>>> { abcdefgh }.sth
>>>>
>>>> would become
>>>>
>>>> abcdefgh
>>>>
>>>> but as soon as I delete one of the delimiters I cannot move to the other
>>>> as it is no longer balanced.. how can I do this ?
>>>>
>>>> maybe there is already sth similar implemented ??
>
>> Here is a solution for you. I just implemented deleting the parentheses. Deleting the adjoined word is left as an exercise for the reader.
>
>> (defun delete-balanced-parentheses ()
>> (interactive)
>> (cond ((looking-at "\\s(")
>> (save-excursion
>> (let ((open-paren (point)))
>> (forward-sexp)
>> (delete-char -1)
>> (goto-char open-paren)
>> (delete-char 1))))
>> (t
>> (error "Not looking at open parenthesis")
>> )))
>
>> Just in case this gets mangled during transmission, the string on the third line is: backslash backslash lowercase_s open_parenthesis
>
>> Marc
>
>
>
>
>
>
>
>> _____________________________________________________________
>> MacOSX-Emacs mailing list
>> MacOSX-Emacs at email.esm.psu.edu
>> http://email.esm.psu.edu/mailman/listinfo/macosx-emacs
>> List Archives: http://dir.gmane.org/gmane.emacs.macintosh.osx
_____________________________________________________________
MacOSX-Emacs mailing list
MacOSX-Emacs at email.esm.psu.edu
http://email.esm.psu.edu/mailman/listinfo/macosx-emacs
List Archives: http://dir.gmane.org/gmane.emacs.macintosh.osx
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.8 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iQEcBAEBAgAGBQJNVBVMAAoJEHtg0hV818BQI84IALy+63pASwZ904B2hWadOniq
m8ekNBudVrB6+5SJXJI/KjCj73OBzMfbOiOyPsUQxv/V+gZMzaOXQHYLlZqW0LbU
GvjsNeOdf225NUGLT1win0VEImnCBOfaN4t/Yk9Du/2BvfAW8AAM2gw17I3IaT31
Ni6QBG3Uczhzs2Ibf4vKXoyNwF6XUYHoVeLyI0rRDUdunwQm2UdEJ7m7dFl6oIV5
URsSrSlkgTc29fbXXw7B1HhHVZ34gAkbFOZ3+azbwRCekn5HSnuz8hQ2Kp4Gal2X
Y7EMp9o81WTWM7wL1WsnZ5pnvGMTc4rJD73FXV4VewK7bXyeMj7qd62DlshiL4A=
=KHpM
-----END PGP SIGNATURE-----
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0x7CD7C050.asc
Type: application/pgp-keys
Size: 4258 bytes
Desc: not available
URL: <http://email.esm.psu.edu/pipermail/macosx-emacs/attachments/20110210/522065e0/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0x7CD7C050.asc.sig
Type: application/octet-stream
Size: 287 bytes
Desc: not available
URL: <http://email.esm.psu.edu/pipermail/macosx-emacs/attachments/20110210/522065e0/attachment.obj>
More information about the MacOSX-Emacs
mailing list