LoginSignup
3
5

More than 3 years have passed since last update.

perspective modeの設定

Last updated at Posted at 2020-02-16

以下の記事を参考に、perspective modeの設定を書いてみた。

キーバインドを設定するためのpersp-set-keybindにおいて、バッククオートによる評価を埋め込んだところが違う点である。元記事ではlexical-letを使っていた。

筆者はivyをよく利用しているので、persp-ivy-switch-bufferは重宝する。これはivy-switch-bufferによるバッファ切り替えの対象を、現在のperspectiveで開いているバッファたちに限定するコマンドである。C-uをつけて実行すれば、切り替え対象が全バッファになる(つまり通常のivy-switch-bufferと同じ挙動)。その他、バッファ一覧表示のためのbs-showのperspective版もあり、たまに利用している。

;; -*- mode: emacs-lisp; coding: utf-8-unix -*-

(require 'perspective)

;; 有効化
(persp-mode 1)

;; 現在のperspectiveに限定したivy-switch-buffer
(global-set-key (kbd "C-x b") 'persp-ivy-switch-buffer)

;; 現在のperspectiveに限定したbs-show
(global-set-key (kbd "C-x C-M-b") 'persp-bs-show)

(setq persp-state-default-file "~/.emacs.d/persp-state-file")
(add-hook 'kill-emacs-hook #'persp-state-save)

(defvar persp-switch-prefix "C-M-%d")
(defvar persp-first-perspective "2") ;; 最初のワークスペースは"2"に設定
(defvar persp-top-perspective "0")
(defvar persp-bottom-perspective "5")

(defun persp-set-keybind ()
  (mapc (lambda (i)
          (persp-switch (int-to-string i))
          (global-set-key (kbd (format persp-switch-prefix i))
                          `(lambda ()
                             (interactive)
                             (persp-switch ,(int-to-string i)))))
        (number-sequence (string-to-number persp-top-perspective)
                         (string-to-number persp-bottom-perspective))))

(defun persp-my-setup ()
  (persp-set-keybind)
  (persp-switch persp-first-perspective)
  (persp-kill "main"))

(add-hook 'persp-state-after-load-hook 'persp-my-setup)
(add-hook 'after-init-hook 'persp-my-setup)
3
5
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
3
5