bmag / emacs-purpose

Manage Windows and Buffers According to Purposes
GNU General Public License v3.0
498 stars 23 forks source link

I'm having trouble understanding how this works #131

Closed alienbogart closed 6 years ago

alienbogart commented 6 years ago

Are the purposes pre-built. or can I determine its position and size? How could I, for instance, make all org-capture-mode windows always open in the bottom with a 30% height?

bmag commented 6 years ago

There are default purposes, and you can define your own purposes as well. It's described in full detail in the wiki.

There is no direct generic way to determine just the position and size of windows. Instead, you customize how a buffer is displayed via purpose-special-action-sequences variable. See the variable's documentation and this example from the README for more details. In the case of org-capture-mode windows, it could be:

(purpose-add-user-purposes :modes ’((org-capture-mode . bottom)))

;; very rough draft, could be improved
(defun display-at-bottom (buffer alist)
  ;; `window--major-non-side-window` was renamed to `window-main-window` in Emacs 26.1
  ;; using 10 lines cause `split-window` doesn't do percentages
  (let ((new-window (split-window (window--major-non-side-window) 10 'below)))
    (when new-window
      (window--display-buffer buffer new-window 'window alist))))

(add-to-list 'purpose-special-action-sequences
             '(bottom
               purpose-display-reuse-window-buffer
               purpose-display-reuse-window-purpose
               display-at-bottom))