Help us understand the problem. What is going on with this article?

Emacs で M-backspace で kill-ring に追加したくない

More than 1 year has passed since last update.

環境

Macbook Air (US keyboard)

elisp

Meta-backspace で1単語を消してくれるのは便利なんですけど、いちいち kill-ring に入ってほしくない。用途としては、ただ消したいのであって後からその文字列をペースト(ヤンク)したいわけではないからです。こういう人は多いと思います。

結論から言うと、http://www.emacswiki.org/emacs/BackwardDeleteWord でおk.

上記URLからLispを転記すると、以下のとおり。

(defun delete-word (arg)
  "Delete characters forward until encountering the end of a word.
With argument, do this that many times."
  (interactive "p")
  (delete-region (point) (progn (forward-word arg) (point))))

(defun backward-delete-word (arg)
  "Delete characters backward until encountering the end of a word.
With argument, do this that many times."
  (interactive "p")
  (delete-word (- arg)))

(global-set-key (read-kbd-macro "<M-DEL>") 'backward-delete-word)

を init.el に追加するだけでOK。注意してほしいのは、

(global-set-key [(meta backspace)] 'backward-delete-word) ;; doesn't work

これだと何故かうまくいかないということ。もしかしたら Windows ではちゃんと動くかも。

また、上記に定義されている delete-word がキーマップに割あたっていないので、 M-d に割り当てるようにします。

(global-set-key [(meta d)] 'delete-word) ;; works fine!

こちらはちゃんと動きます。

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away