Skip to content

Commit

Permalink
default to 'edit purpose for buffers visiting files
Browse files Browse the repository at this point in the history
Fixes bmag#113
  • Loading branch information
deb0ch authored and wyuenho committed May 27, 2018
1 parent 5e1b769 commit 6426500
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
16 changes: 16 additions & 0 deletions test/core-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,22 @@ The prompt is chosen according to `purpose-preferred-prompt'."
(purpose-insert-user-input "foo")
(should (equal (purpose-read-purpose "Purpose: " '(foo bar baz)) 'foo)))

(ert-deftest purpose-test-default-purpose-when-visiting-file ()
"Test that the default purpose for a buffer visiting a file is 'edit.
Also test that if there was a predefined purpose for that buffer
it gets that one, and that the default purpose for a buffer not
visiting a file is still `default-purpose'."
(unwind-protect
(purpose-with-temp-config
nil '(("foo" . yolo)) nil
(find-file "foo")
(should (equal (purpose-buffer-purpose (get-buffer "foo")) 'yolo))
(find-file "bar")
(should (equal (purpose-buffer-purpose (get-buffer "bar")) 'edit))
(get-buffer-create "baz")
(should (equal (purpose-buffer-purpose (get-buffer "baz")) default-purpose))
(purpose-kill-buffers-safely "foo" "bar" "baz"))))

(provide 'core-test)

;;; core-test.el ends here
9 changes: 9 additions & 0 deletions window-purpose-core.el
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@
:type 'symbol
:package-version "1.2")

(defcustom default-file-purpose 'edit
"The default purpose for buffers visiting a file which didn't get a purpose."
:group 'purpose
:type 'symbol
:package-version "1.2")

(defcustom purpose-preferred-prompt 'auto
"Which interface should Purpose use when prompting the user.
Available options are: 'auto - use IDO when `ido-mode' is enabled,
Expand Down Expand Up @@ -212,6 +218,9 @@ If no purpose was determined, return `default-purpose'."
(purpose--buffer-purpose-mode buffer-or-name
purpose--default-mode-purposes)))

;; If the buffer is visiting a file, fallback to 'edit purpose
(when (buffer-file-name (get-buffer buffer-or-name))
default-file-purpose)
;; fallback to default purpose
default-purpose))

Expand Down

0 comments on commit 6426500

Please sign in to comment.