Skip to content

Commit

Permalink
set-window-purpose: new optional window argument
Browse files Browse the repository at this point in the history
  • Loading branch information
bmag committed Oct 7, 2016
1 parent d51aab2 commit fd7118d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.org
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@
*** ~purpose-load-recent-frame-layout~ now loads the correct layout
Previous it would always load the most recent layout (index 0), disregarding
the function's ~index~ argument.
*** [[https://github.com/bmag/emacs-purpose/issues/96][#96]]: ~purpose-set-window-purpose~ now receives an optional ~window~ argument
Function signature has changed from:
#+BEGIN_SRC elisp
purpose-set-window-purpose (purpose &optional dont-dedicate)
#+END_SRC
To:
#+BEGIN_SRC elisp
purpose-set-window-purpose (purpose &optional window dont-dedicate)
#+END_SRC
** Changed test framework to Buttercup
It is now easier to read, modify and add new tests, thanks to [[https://github.com/jorgenschaefer/emacs-buttercup][Buttercup]].

Expand Down
11 changes: 8 additions & 3 deletions tests/test-layout.el
Original file line number Diff line number Diff line change
Expand Up @@ -170,17 +170,22 @@
(it "should change window's purpose"
(purpose-set-window-purpose 'foo)
(expect (purpose-window-purpose) :to-be 'foo))
(it "can receive an optional window argument"
(build-two-windows '((:name "xxx-p0-0" :selected t) (:name "xxx-p0-1")))
(purpose-set-window-purpose 'foo (next-window))
(expect (purpose-window-purpose) :to-be 'general)
(expect (purpose-window-purpose (next-window)) :to-be 'foo))
(it "uses purpose inputted by the user"
(spy-on 'purpose--set-window-buffer)
(spy-on 'purpose-set-window-purpose-dedicated-p)
(insert-user-input "foo2")
(call-interactively 'purpose-set-window-purpose)
(expect 'purpose--set-window-buffer :to-have-been-called-with 'foo2)
(expect 'purpose--set-window-buffer :to-have-been-called-with 'foo2 nil)
(expect 'purpose-set-window-purpose-dedicated-p :to-have-been-called-with nil t)
(insert-user-input "foo3")
(let ((current-prefix-arg t))
(call-interactively 'purpose-set-window-purpose))
(expect 'purpose--set-window-buffer :to-have-been-called-with 'foo3)
(expect 'purpose--set-window-buffer :to-have-been-called-with 'foo3 nil)
(expect 'purpose-set-window-purpose-dedicated-p :to-have-been-called-with nil nil)))

(describe "purpose-delete-non-dedicated-windows"
Expand Down Expand Up @@ -242,7 +247,7 @@
(spy-on 'frame-width :and-call-fake #'fake-frame-width)
(spy-on 'frame-height :and-call-fake #'fake-frame-height))
(setq win2 (split-window nil nil 'below))
(purpose-set-window-purpose 'foo1 'dont-dedicate)
(purpose-set-window-purpose 'foo1 nil 'dont-dedicate)
(with-selected-window win2
(purpose-set-window-purpose 'foo2))
(setq result (purpose-get-window-layout)))
Expand Down
10 changes: 6 additions & 4 deletions window-purpose-layout.el
Original file line number Diff line number Diff line change
Expand Up @@ -619,18 +619,20 @@ Use INDEX=0 for most recent."
(window-list)))

;;;###autoload
(defun purpose-set-window-purpose (purpose &optional dont-dedicate)
"Set window's purpose to PURPOSE, and dedicate it.
(defun purpose-set-window-purpose (purpose &optional window dont-dedicate)
"Set WINDOW's purpose to PURPOSE, and dedicate it.
WINDOW must be a live window and defaults to the selected one.
With prefix argument (DONT-DEDICATE is non-nil), don't dedicate the
window. If DONT-DEDICATE is non-nil, and the current window is
dedicated, un-dedicate the window.
Changing the window's purpose is done by displaying a buffer of
the right purpose in it, or creating a dummy buffer."
(interactive
(list (purpose-read-purpose "Purpose: " nil 'confirm)
nil
current-prefix-arg))
(purpose--set-window-buffer purpose)
(purpose-set-window-purpose-dedicated-p nil (not dont-dedicate)))
(purpose--set-window-buffer purpose window)
(purpose-set-window-purpose-dedicated-p window (not dont-dedicate)))

(defun purpose--delete-window-at (window-getter &optional frame)
"Delete window returned by WINDOW-GETTER.
Expand Down

0 comments on commit fd7118d

Please sign in to comment.