次のアドバイスを使用してkill-region
、選択した領域を削除するか、最初にポイントの単語を削除してから行全体を削除することができます。
単語または行を殺す
(defadvice kill-region (before slick-cut-line first activate compile)
"When called interactively kill the current word or line.
Calling it once without a region will kill the current word.
Calling it a second time will kill the current line."
(interactive
(if mark-active (list (region-beginning) (region-end))
(if (eq last-command 'kill-region)
(progn
;; Return the previous kill to rebuild the line
(yank)
;; Add a blank kill, otherwise the word gets appended.
;; Change to (kill-new "" t) to remove the word and only
;; keep the whole line.
(kill-new "")
(message "Killed Line")
(list (line-beginning-position)
(line-beginning-position 2)))
(save-excursion
(forward-char)
(backward-word)
(mark-word)
(message "Killed Word")
(list (mark) (point)))))))
これは同じことを行いますが、殺すのではなくコピーします。
単語または行をコピーする
(defadvice kill-ring-save (before slick-copy-line activate compile)
"When called interactively with no region, copy the word or line
Calling it once without a region will copy the current word.
Calling it a second time will copy the current line."
(interactive
(if mark-active (list (region-beginning) (region-end))
(if (eq last-command 'kill-ring-save)
(progn
;; Uncomment to only keep the line in the kill ring
;; (kill-new "" t)
(message "Copied line")
(list (line-beginning-position)
(line-beginning-position 2)))
(save-excursion
(forward-char)
(backward-word)
(mark-word)
(message "Copied word")
(list (mark) (point)))))))
どちらも、このブログ投稿のコマンドを基にしています。