2

kill-whole-line is quite useful as it completely deletes both content and whitespace unlike kill-line which only deletes contents in line. But in lisp-mode, it is necessary to keep parens in tact and kill-whole-line fails there.

Update:

If point is in a buffer like this

|(setq foo "bar")
(setq foo1 "bar1")

if i kill line, it should become

|(setq foo1 "bar1")

but not

|    
(setq foo1 "bar1")

On the other hand, if point is in a buffer like this

(defun foo ()
 |(message "foo"))

if i kill line, it should become

(defun foo ()
 |)

How can i kill whole line and keep parens intact?

7
  • Did you try paredit? I'm not using it, but I know it has lots of lisp-specific editing tricks. I also don't think that deleting a line can be implemented very usefully--it's better to delete expressions rather than lines.
    – wvxvw
    Sep 18, 2015 at 23:59
  • @Drew updated with an example. Sep 19, 2015 at 5:00
  • @wvxvw i want to delete expression only, but i want to cleanup white space along with them Sep 19, 2015 at 5:04
  • 3
    Paredit would certainly do it, but my normal editing practice is C-M-k then M-SPC or M-/ depending on a situation.
    – wvxvw
    Sep 19, 2015 at 8:35
  • 1
    @kaushalmodi Sorry, wrong slash, it should be M-\ - delete-horizontal-space.
    – wvxvw
    Sep 21, 2015 at 5:22

1 Answer 1

2

As @wvxvw and @Drew implied in the comments, I too believe that kill-sexp (bound by default to C-M-k) is a more appropriate command to use than kill-whole-line for the use cases in your examples.


For your first example, I would either use

  • C-M-k followed by C-k (to delete the empty line), or
  • kill-whole-line (bound to a convenient key if I use it too often)

That would do the below,

▮(setq foo "bar")        -- C-M-k, C-k -->   (setq foo1 "bar1") 
(setq foo1 "bar1")

For your second example, just C-M-k would suffice.

(defun foo ()            -- C-M-k -->        (defun foo ()  
 ▮(message "foo"))                           ▮)  

What I like about C-M-k is that it always "does what I mean" in situations like this,

(defun foo ()            -- C-M-k -->        (defun foo ()
 ▮                                           ▮) 
  ;; some comment 1  
  ;; some comment 2
  (message "foo"))

Note that just that one single command removed the extra new line + comments before the sexp.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.