選択しているbufferに応じてneotreeのディレクトリを移動させる
emacsでbufferを選択するたびにneotreeのディレクトリがそれに応じて変わると便利なのではないかと思い, 設定してみた.
bufferの選択に応じて呼び出されるhookは存在しないらしいので, switch-buffer-functionsを利用する
(use-package switch-buffer-functions :ensure t)
switch-buffer-functions
にhookを追加.
(add-hook 'switch-buffer-functions (lambda (prev current) (let ((neotree-buffer (neo-global--get-buffer))) (if (and ;; Ignore if new buffer is neotree (not (eq current neotree-buffer)) ;; Ignore if the buffer is not assosiated with a file buffer-file-name ;; Ignore if neotree is not active (neo-global--window-exists-p)) (progn (neo-buffer--change-root default-directory) (switch-to-buffer current) ) ) ) ))