6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

C-x b で存在しないバッファを指定した時に新規バッファで開くようにする

6
Posted at

はじめに

GNU Emacs 24.3.1を使用しているが、C-x bで存在しないバッファを指定するとミニバッファにQuitと表示され、新規バッファを生成してくれなくなった。
以前は新規バッファを生成してくれたと思うんだが…

原因

いろいろ調べた結果、*scratch*バッファでswitch-to-bufferを評価すると新規バッファを生成してくれるのに対し、M-x switch-to-buffer や C-x b の時は生成してくれない事がわかった。
switch-to-buffer内で使用されている read-buffer-to-switch が原因っぽい。
代用として、read-buffer を使うと問題なさそうだ。
そこで新しい関数 switch-to-buffer-extension を作成し、その中でswitch-to-bufferを呼ぶことにした。

.emacs.elに追加したもの

.emacs.el
;; switch-to-buffer で 存在しないバッファ名を指定した時に新規バッファとして開けるようにする。
(defun switch-to-buffer-extension (prompt)
	(interactive
	 (list (read-buffer "Switch to buffer: " (other-buffer (current-buffer)))))
	(switch-to-buffer prompt))
(global-set-key "\C-xb" 'switch-to-buffer-extension)

C-x bはそのままがいいけど新規バッファは簡単に作りたい方へ

http://noqisofon.hatenablog.com/entry/20101102/1288647885
のやり方でいいと思いますまる

6
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?