sabof / project-explorer

A project explorer sidebar
266 stars 17 forks source link

Allow users to provide their own windows #6

Closed vemv closed 10 years ago

vemv commented 10 years ago

Hi sabof, thank you for an good implementation of a feature -directory trees- which hadn't been properly implemented in Emacs until now, in my opinion.

I'd like the plugin to use a window object I provide, rather than one created by project-explorer. Why? Because I might want the window to have some specific dimensions, to be placed in a particular layout in a frame, or to be allocated in one of multiple frames.

This, of course, would be substantially simpler than passing options telling how to render the window.

Do you think you could make these changes yourself? Or should I work on a pull request?

Thanks - Victor

sabof commented 10 years ago

Pretty much, it's just a matter of overwriting pe/show-buffer-in-side-widow, to handle your personal use-case. You might also want to tweak pe/quit to burry the buffer, instead of quiting the window.

(eval-after-load 'project-explorer
  '(progn

    (defun pe/show-buffer-in-side-window (buffer)
      (let (( window (or (cl-find-if (lambda (win)
                                       (with-current-buffer (window-buffer win)
                                         (derived-mode-p 'project-explorer-mode)))
                                     (window-list))
                         (selected-window))))
        (select-window window)
        (setf (window-buffer window) buffer)))

    ))

I'm not sure there's point in implementing a pe/show-buffer-function variable, if that's what you are proposing, since people who can benefit from it, don't need it anyway.

vemv commented 10 years ago

Awesome solution - calling (selected-window) is way more solid than handling window objects: less state to keep, no risk of getting objects that represent closed windows, etc.

What if the plugin provided a simple use-current-window option? Overwriting functions is somewhat fragile...

;; old name: pe/show-buffer-in-side-window
(defun pe/show-buffer-in-window (buffer)
  (if use-current-window
      (set-window-buffer (selected-window) buffer)
      ;; old implementation - unaltered:
      (let* (( project-explorer-buffers
               (pe/get-project-explorer-buffers))
             ( --clean-up--
               (mapc (lambda (win)
                       (and (memq (window-buffer win) project-explorer-buffers)
                            (not (window-parameter win 'window-side))
                            (window-deletable-p win)
                            (delete-window win)))
                     (window-list)))
             ( existing-window
               (cl-find-if
                (lambda (window)
                  (and (memq (window-buffer window) project-explorer-buffers)
                       (window-parameter window 'window-side)))
                (window-list)))
             ( window
               (or existing-window
                   (display-buffer-in-side-window
                    buffer
                    `((side . ,pe/side)
                      )))))
        (when existing-window
          (set-window-dedicated-p window nil)
          (set-window-buffer window buffer))
        (set-window-dedicated-p window t)
        (unless existing-window
          (es-set-window-body-width window pe/width))
        (select-window window)
        window)))
sabof commented 10 years ago

I've updated the my previous comment with a better version. I might make it "official" at a later point.

sabof commented 10 years ago

I've added pe/display-tree-buffer-function which may contain a custom function to display the tree.