[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How do i say it in emacs lisp
From: |
Matthias Pfeifer |
Subject: |
Re: How do i say it in emacs lisp |
Date: |
Mon, 28 Nov 2016 11:50:32 +0000 |
Hi Tomas,
thanks for the general clarification. I was suspecting hooks to be the way to
go. However I was running in some sort of recursion (i guess) until i figured
out to temporarily set my hook to nil. This is what I fiddled together: My plan
is to have a package called "neotree" update it's buffer whenever another
window's buffer is switched and the selected frame's configuration matches a
certain layout. Let me try to re-phrase: When the current frame hosts two
windows. And any of these windows is showing the neotree buffer and other
window's buffers is switched then I want neotree to go to the buffers file.
Here is my elisp:
(defun mp:neotree-updater ()
(when (eq 2 (length (window-list)))
(let* ((wnd-0 (nth 0 (window-list)))
(wnd-1 (nth 1 (window-list)))
(buf-0 (window-buffer wnd-0))
(buf-1 (window-buffer wnd-1))
(neo-buf nil)
(other-buf nil)
(neo-wnd nil)
(other-wnd nil)
(filename nil)
(neo-buffer (get-buffer " *NeoTree*")))
(when (and neo-buffer
(or (eq buf-0 neo-buffer)
(eq buf-1 neo-buffer)))
(progn
(if (eq buf-0 neo-global--buffer)
(setq neo-buf buf-0
other-buf buf-1
neo-wnd wnd-0
other-wnd wnd-1)
(setq neo-buf buf-1
other-buf buf-0
neo-wnd wnd-1
other-wnd wnd-0))
(setq filename (buffer-file-name other-buf))
(when (and filename
(file-exists-p filename))
(progn
(setq mp:neotree-go-to-dir filename)
(let ((buffer-list-update-hook buffer-list-update-hook))
(neotree-find filename)
(select-window other-wnd)))))))))
;; (add-hook 'buffer-list-update-hook 'mp:neotree-updater)
;; (remove-hook 'buffer-list-update-hook 'mp:neotree-updater)
It seems to be working the way I expected it. Second opinion is welcome :-)
Matthias Pfeifer