Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete current (non-atomic) s-expression in Emacs

Tags:

emacs

paredit

Is there an easy way to delete the smallest-possible non-atomic s-expression based on the cursor location? I want to turn this (the "|" is the cursor)

(defun foo (bar)
  (if bar
      |789
    (+ 456 123)))

into this

(defun foo (bar)
  |)

It seems like a useful thing to be able to do, but I couldn't find a relevant (one-step) command on the Paredit cheat sheet.

like image 715
Patrick Brinich-Langlois Avatar asked Sep 27 '12 08:09

Patrick Brinich-Langlois


2 Answers

I didn't find a predefined command either.

Fortunately, with Emacs it's really easy to implement your own.

For example:

(define-key global-map (kbd "C-c C-d") 
    (lambda () (interactive) (backward-up-list) (paredit-kill)))
like image 179
Oleg Pavliv Avatar answered Nov 07 '22 10:11

Oleg Pavliv


C-M-u does the right thing inside strings in paredit 23, so `C-M-u C-M-k' will work even inside a string.

like image 1
Ronald L. Frobnitz Avatar answered Nov 07 '22 11:11

Ronald L. Frobnitz