LoginSignup
3
0

More than 3 years have passed since last update.

iflipbの設定を改善:カレントバッファと同じメジャーモードのバッファのみを切り替え対象とする

Last updated at Posted at 2019-05-04

バッファ切り替えのためのパッケージ、iflipbの記事は色々見つかる。

特定のバッファを切り替え対象から除外する手段は本パッケージにいくつか用意されている。しかしながら、カレントバッファと同じメジャーモードを持つバッファたちに切り替え対象を限定する手段は存在しなかったので、設定を書いたというわけだ。こんな感じだ:

(require 'iflipb)
(defun my-iflipb-buffer-list ()
  "Returns list of buffers whose major-mode is the same as current buffer's one."
  (let ((cur-buf-list (buffer-list (selected-frame)))
        (same-major-mode-buflist nil)
        (currbuf-major-mode
         (buffer-local-value 'major-mode (current-buffer))))
     (dolist (buffer cur-buf-list)
      (if (eq (buffer-local-value 'major-mode buffer) currbuf-major-mode)
          (add-to-list 'same-major-mode-buflist buffer)))
     (nreverse same-major-mode-buflist)))
(setq iflipb-buffer-list-function 'my-iflipb-buffer-list)

その他は以下の通り。

(setq iflipb-wrap-around t)
(setq iflipb-ignore-buffers (list "^[*]"))
(global-set-key (kbd "C-<tab>") 'iflipb-next-buffer)
(global-set-key (kbd "C-S-<tab>") 'iflipb-previous-buffer)

キーバインドについては以下も押しやすさの観点からは悪くない選択だと思われる:

(global-set-key (kbd "M-]") 'iflipb-next-buffer)
(global-set-key (kbd "M-[") 'iflipb-previous-buffer)

追記:
iflipb-ignore-buffersで特定のバッファ名を除外しつつ、特定のメジャーモードではそのバッファ名の除外を解除したい場合が存在する。例えば、eww-modeではバッファ名は*eww**eww*<2>のように「アスタリスクから始まるバッファ名」であるから、上記のiflipb-ignore-buffersの除外パターン"^[*]"にマッチしてしまう。

そこで、特定のメジャーモードではその制約を外すよう、変数iflipb-except-major-modeを用意したうえで、キーバインドを以下のように設定する。設定ではeww-modeのみになっているが、それ以外のメジャーモードもリストに加えることができる。

(defvar iflipb-except-major-mode (list 'eww-mode)
  "A list of major modes that ignore even the exclusion
buffers specified by iflipb-ignore-buffers.")

(global-set-key (kbd "C-<tab>")
                #'(lambda ()
                    (interactive)
                    (let ((currbuf-major-mode
                           (buffer-local-value 'major-mode (current-buffer))))
                      (if (memq currbuf-major-mode iflipb-except-major-mode)
                          (iflipb-next-buffer 4)
                        (iflipb-next-buffer 1)))))
3
0
1

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
3
0