2010-09-12 75 views
4

时候当我打C-K,Emacs的杀死结束的行。当我再次击中C-K时,它“杀死了换行符”,并带来了下一条线。但是,下一行的缩进仍然完好无损,并且最终可能会有一行中间有很多空格的行。获取Emacs的加入线杀线

所以,从这个:

previous line material 
    next line material 

这样:

previous line material  next line material 

我明白我可以用M- ^正确联接线,但是这需要光标将在下一行。如何修改C-k,以便在杀死换行符时还杀死下一行的缩进?

+0

你应该问问superuser.com的好人。 – zneak 2010-09-12 17:39:46

回答

4

对于C-k我不知道,但你可以使用just-one-space函数变换任意数量的空间分成中庸之道一个空间(它必将对M-space

+0

我其实很喜欢Sean和Remi的答案,但是发现M-space对我来说更容易一些。谢谢 :) – qrest 2010-09-12 21:13:44

0

这将做到这一点:

(defun my-kill-line (&optional arg) 
    (interactive "P") 
    (if arg 
     (kill-line arg) 
    (when (prog1 (eolp) (kill-line)) 
     (just-one-space 1)))) 
4

如果你给M-^参数(例如铜M-^),它将加入下一行到当前行。

1

下面是行为(我觉得)你想成为kill-line堵塞的方式:杀死一个换行符时,也杀下面的压痕。请注意,这可能会导致没有空间被光标,这就是为什么我想我会用M-1 M-^C-k M-SPC,而不是去后存在。

(defadvice kill-line (around kill-indentation 
         activate compile) 
    "When killing a line break, also kill any subsequent indentation." 
    (let ((f-v-l (symbol-function 'forward-visible-line))) 
    (flet ((forward-visible-line (arg) 
      (funcall f-v-l arg) 
      (skip-chars-forward " \t"))) 
     ad-do-it))) 
0

我有这个在我的.emacs:

(defun pull-line() 
    "Pull the next line that contains anything up to the end of this one" 
    (interactive) 
    (save-excursion 
    (end-of-line) 
    (while (looking-at "[ \n\r\t]") 
     (delete-char 1)) 
    (if (looking-back "^[[:blank:]]*[[:punct:][:alnum:]].*") 
(fixup-whitespace) 
     (indent-according-to-mode)))) 
(global-set-key "\C-cp" 'pull-line) 

它拉下一个非空行到this一个,如果有上this行任何它使得其不调用(fixup-whitespace)大约95%的时间是正确的,否则它会缩小到emacs认为合适的水平。我认为我从vim复制了这个概念?

我用它所有的时间,无论如何。

0

我才意识到我也有这个在我的.emacs,更正是你想要的,但我忘了我有它,因为我用拉线更加频繁。我想我从emacswiki偷了这个:

(defun kill-and-join-forward (&optional arg) 
    "If at end of line, join with following; otherwise kill line. 
Deletes whitespace at join." 
    (interactive "P") 
    (if (and (eolp) (not (bolp))) 
     (progn 
    (delete-indentation t) 
    (if (looking-at " $") 
     (delete-char 1))) 
    (kill-line arg))) 
(global-set-key "\C-k" 'kill-and-join-forward)