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?

Drew
  • 75,699
  • 9
  • 109
  • 225
Chillar Anand
  • 4,042
  • 1
  • 23
  • 52
  • 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 '15 at 23:59
  • @Drew updated with an example. – Chillar Anand Sep 19 '15 at 05:00
  • @wvxvw i want to delete expression only, but i want to cleanup white space along with them – Chillar Anand Sep 19 '15 at 05:04
  • 3
    [Paredit](http://www.emacswiki.org/emacs/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 '15 at 08:35
  • @wvxvw: +1 for `C-M-k` and `M-SPC` or `M-/`. (But I'm not a fan of paredit.) – Drew Sep 19 '15 at 16:00
  • @wvxvw By default, `M-/` is `dabbrev-expand`. I didn't understand why you would do `M-/` after `C-M-k`. `M-SPC` makes sense as it is bound it `just-one-space`. – Kaushal Modi Sep 21 '15 at 01:47
  • 1
    @kaushalmodi Sorry, wrong slash, it should be ``M-\`` - `delete-horizontal-space`. – wvxvw Sep 21 '15 at 05:22

1 Answers1

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.

Kaushal Modi
  • 25,203
  • 3
  • 74
  • 179