diff options
| author | Craig Jennings <c@cjennings.net> | 2026-05-27 15:36:20 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-05-27 15:36:20 -0500 |
| commit | 4d159e7d1ab5b85892eee81e596d95a5a55855e8 (patch) | |
| tree | 02208e83bd0da0c63ac21a9de4b8d83cfa92fc13 /tests | |
| parent | a2a155c785cdf43c971b88db174c33ac1e867da3 (diff) | |
| download | pearl-4d159e7d1ab5b85892eee81e596d95a5a55855e8.tar.gz pearl-4d159e7d1ab5b85892eee81e596d95a5a55855e8.zip | |
feat(keys): add pearl-mode and complete the command keymap
Pearl is now drivable entirely from the keyboard. pearl-mode turns on automatically in any buffer Pearl renders, detected by the #+LINEAR-SOURCE header on org-mode-hook, and binds the command map under pearl-keymap-prefix (default "C-; L"), so the keys are live without any global setup.
I filled out pearl-prefix-map so every day-to-day command is reachable. The hot-path commands bind directly under the prefix (list, refresh view, refresh issue, save, edit description, new comment). The rest sit in category sub-maps (fetch, edit, new, delete, url). The common ones appear in both places, so edit-description is the direct d and also e d. Delete moved from d to k so d is the direct edit key, and the old save sub-map is gone now that save is the direct s and S.
The org-mode-hook is registered at load rather than through an autoload cookie. An autoloaded hook would fire before pearl loaded, calling a void function, and would pull the whole package into every org buffer the user opens. Freshly fetched buffers also enable the mode directly in the writer.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test-pearl-keymap.el | 153 |
1 files changed, 115 insertions, 38 deletions
diff --git a/tests/test-pearl-keymap.el b/tests/test-pearl-keymap.el index 7cfc603..0e12da3 100644 --- a/tests/test-pearl-keymap.el +++ b/tests/test-pearl-keymap.el @@ -1,4 +1,4 @@ -;;; test-pearl-keymap.el --- Tests for the opt-in prefix keymap -*- lexical-binding: t; -*- +;;; test-pearl-keymap.el --- Tests for the prefix keymap and minor mode -*- lexical-binding: t; -*- ;; Copyright (C) 2026 Craig Jennings @@ -19,10 +19,11 @@ ;;; Commentary: -;; Tests for `pearl-prefix-map' (see docs/ticket-save-model-spec.org, the -;; keybinding section): the opt-in prefix keymap that organizes the commands -;; under save / edit / new / delete sub-maps with which-key labels. The map is -;; defined but never bound at load -- the user binds it to a free prefix. +;; Tests for `pearl-prefix-map' and `pearl-mode'. Hot-path commands bind +;; directly under the prefix; the rest live in category sub-maps (fetch / edit +;; / new / delete / url). The common commands appear in both places. +;; `pearl-mode' makes the map live inside Pearl buffers under +;; `pearl-keymap-prefix'. ;;; Code: @@ -44,52 +45,128 @@ Walks MAP looking for a labeled binding (\"label\" . COMMAND)." "`pearl-prefix-map' is defined as a keymap." (should (keymapp pearl-prefix-map))) -(ert-deftest test-pearl-prefix-map-resolves-leaf-commands () - "Each chord resolves to its command." - (should (eq 'pearl-save-issue (lookup-key pearl-prefix-map (kbd "s s")))) - (should (eq 'pearl-save-all (lookup-key pearl-prefix-map (kbd "s a")))) - (should (eq 'pearl-edit-description (lookup-key pearl-prefix-map (kbd "e d")))) - (should (eq 'pearl-edit-current-comment (lookup-key pearl-prefix-map (kbd "e c")))) - (should (eq 'pearl-edit-state (lookup-key pearl-prefix-map (kbd "e s")))) - (should (eq 'pearl-edit-assignee (lookup-key pearl-prefix-map (kbd "e a")))) - (should (eq 'pearl-edit-labels (lookup-key pearl-prefix-map (kbd "e l")))) - ;; priority has no edit command (org-native cookie); e p is unbound - (should-not (lookup-key pearl-prefix-map (kbd "e p"))) - (should (eq 'pearl-new-issue (lookup-key pearl-prefix-map (kbd "n t")))) - (should (eq 'pearl-add-comment (lookup-key pearl-prefix-map (kbd "n c")))) - (should (eq 'pearl-delete-current-issue (lookup-key pearl-prefix-map (kbd "d t")))) +(ert-deftest test-pearl-prefix-map-direct-hot-keys () + "The hot-path commands resolve in one key under the prefix." + (should (eq 'pearl-list-issues (lookup-key pearl-prefix-map (kbd "l")))) + (should (eq 'pearl-refresh-current-view (lookup-key pearl-prefix-map (kbd "g")))) + (should (eq 'pearl-refresh-current-issue (lookup-key pearl-prefix-map (kbd "r")))) + (should (eq 'pearl-save-issue (lookup-key pearl-prefix-map (kbd "s")))) + (should (eq 'pearl-save-all (lookup-key pearl-prefix-map (kbd "S")))) + (should (eq 'pearl-edit-description (lookup-key pearl-prefix-map (kbd "d")))) + (should (eq 'pearl-add-comment (lookup-key pearl-prefix-map (kbd "c")))) (should (eq 'pearl-menu (lookup-key pearl-prefix-map (kbd "m"))))) (ert-deftest test-pearl-prefix-map-sub-prefixes-are-keymaps () "The category keys are sub-prefixes, not commands." - (should (keymapp (lookup-key pearl-prefix-map (kbd "s")))) + (should (keymapp (lookup-key pearl-prefix-map (kbd "f")))) (should (keymapp (lookup-key pearl-prefix-map (kbd "e")))) (should (keymapp (lookup-key pearl-prefix-map (kbd "n")))) - (should (keymapp (lookup-key pearl-prefix-map (kbd "d"))))) - -(ert-deftest test-pearl-prefix-map-delete-comment-bound () - "Delete-comment fills the d c slot under the delete prefix." - (should (eq 'pearl-delete-current-comment (lookup-key pearl-prefix-map (kbd "d c"))))) + (should (keymapp (lookup-key pearl-prefix-map (kbd "k")))) + (should (keymapp (lookup-key pearl-prefix-map (kbd "u"))))) + +(ert-deftest test-pearl-prefix-map-fetch-group () + "The fetch group resolves each source command." + (should (eq 'pearl-list-issues (lookup-key pearl-prefix-map (kbd "f o")))) + (should (eq 'pearl-list-issues-by-project (lookup-key pearl-prefix-map (kbd "f p")))) + (should (eq 'pearl-list-issues-filtered (lookup-key pearl-prefix-map (kbd "f f")))) + (should (eq 'pearl-run-view (lookup-key pearl-prefix-map (kbd "f v")))) + (should (eq 'pearl-run-saved-query (lookup-key pearl-prefix-map (kbd "f q"))))) + +(ert-deftest test-pearl-prefix-map-edit-group () + "The edit group resolves each field-edit command." + (should (eq 'pearl-edit-description (lookup-key pearl-prefix-map (kbd "e d")))) + (should (eq 'pearl-edit-state (lookup-key pearl-prefix-map (kbd "e s")))) + (should (eq 'pearl-edit-assignee (lookup-key pearl-prefix-map (kbd "e a")))) + (should (eq 'pearl-edit-labels (lookup-key pearl-prefix-map (kbd "e l")))) + (should (eq 'pearl-edit-current-comment (lookup-key pearl-prefix-map (kbd "e c")))) + ;; priority has no edit command (org-native cookie); e p is unbound + (should-not (lookup-key pearl-prefix-map (kbd "e p")))) -(ert-deftest test-pearl-prefix-map-not-bound-at-load () - "Loading pearl does not bind the commands to any active key (opt-in)." - (should-not (where-is-internal 'pearl-save-issue)) - (should-not (where-is-internal 'pearl-save-all))) +(ert-deftest test-pearl-prefix-map-new-and-delete-groups () + "New and delete groups resolve ticket/comment, with delete under k." + (should (eq 'pearl-new-issue (lookup-key pearl-prefix-map (kbd "n t")))) + (should (eq 'pearl-add-comment (lookup-key pearl-prefix-map (kbd "n c")))) + (should (eq 'pearl-delete-current-issue (lookup-key pearl-prefix-map (kbd "k t")))) + (should (eq 'pearl-delete-current-comment (lookup-key pearl-prefix-map (kbd "k c"))))) + +(ert-deftest test-pearl-prefix-map-url-group () + "The url group resolves open-in-browser and open-view; copy-url is not yet bound." + (should (eq 'pearl-open-current-issue (lookup-key pearl-prefix-map (kbd "u o")))) + (should (eq 'pearl-open-current-view-in-linear (lookup-key pearl-prefix-map (kbd "u v")))) + ;; "u c" (copy URL) lands with `pearl-copy-issue-url' + (should-not (lookup-key pearl-prefix-map (kbd "u c")))) + +(ert-deftest test-pearl-prefix-map-common-commands-bound-twice () + "The most common commands resolve both directly and inside their group." + ;; edit-description: direct d and e d + (should (eq (lookup-key pearl-prefix-map (kbd "d")) + (lookup-key pearl-prefix-map (kbd "e d")))) + ;; new comment: direct c and n c + (should (eq (lookup-key pearl-prefix-map (kbd "c")) + (lookup-key pearl-prefix-map (kbd "n c")))) + ;; list issues: direct l and f o + (should (eq (lookup-key pearl-prefix-map (kbd "l")) + (lookup-key pearl-prefix-map (kbd "f o"))))) (ert-deftest test-pearl-prefix-map-which-key-labels () - "Leaf bindings carry the edit/new verb labels; sub-prefixes carry +labels." + "Leaf bindings carry verb labels; sub-prefixes carry +labels." (should (string= "edit state" (test-pearl-keymap--label-of pearl-edit-map 'pearl-edit-state))) - (should (string= "edit description" - (test-pearl-keymap--label-of pearl-edit-map 'pearl-edit-description))) (should (string= "new ticket" (test-pearl-keymap--label-of pearl-new-map 'pearl-new-issue))) - (should (string= "new comment" - (test-pearl-keymap--label-of pearl-new-map 'pearl-add-comment))) - (should (string= "save ticket" - (test-pearl-keymap--label-of pearl-save-map 'pearl-save-issue))) - ;; sub-prefix label on the base map - (should (string= "+edit" (test-pearl-keymap--label-of pearl-prefix-map pearl-edit-map)))) + (should (string= "open issue in browser" + (test-pearl-keymap--label-of pearl-url-map 'pearl-open-current-issue))) + (should (string= "+edit" (test-pearl-keymap--label-of pearl-prefix-map pearl-edit-map))) + (should (string= "+url" (test-pearl-keymap--label-of pearl-prefix-map pearl-url-map)))) + +(ert-deftest test-pearl-prefix-map-not-bound-at-load () + "Loading pearl binds nothing globally; the keys are live only via pearl-mode." + (should-not (where-is-internal 'pearl-save-issue (current-global-map))) + (should-not (where-is-internal 'pearl-list-issues (current-global-map)))) + +;;; minor mode + +(ert-deftest test-pearl-mode-is-a-minor-mode () + "`pearl-mode' is defined as a command." + (should (fboundp 'pearl-mode)) + (should (commandp 'pearl-mode))) + +(ert-deftest test-pearl-mode-map-binds-the-prefix () + "`pearl-mode-map' binds `pearl-keymap-prefix' to the command map." + (should (eq pearl-prefix-map + (lookup-key pearl-mode-map (kbd pearl-keymap-prefix))))) + +(ert-deftest test-pearl-buffer-is-pearl-p-detects-source-header () + "A buffer with a #+LINEAR-SOURCE header reads as a Pearl buffer; one without does not." + (with-temp-buffer + (insert "#+title: x\n#+LINEAR-SOURCE: (:type filter)\n") + (should (pearl--buffer-is-pearl-p))) + (with-temp-buffer + (insert "#+title: notes\n* a heading\n") + (should-not (pearl--buffer-is-pearl-p)))) + +(ert-deftest test-pearl-maybe-enable-mode-only-in-pearl-org-buffers () + "`pearl--maybe-enable-mode' turns the mode on in a Pearl org buffer, not elsewhere." + ;; Pearl org buffer -> enabled. `delay-mode-hooks' keeps `org-mode-hook' + ;; (which itself carries the auto-enable) from firing, so the explicit call + ;; is what flips the mode. + (with-temp-buffer + (delay-mode-hooks (org-mode)) + (insert "#+title: x\n#+LINEAR-SOURCE: (:type filter)\n") + (pearl--maybe-enable-mode) + (should pearl-mode)) + ;; Plain org buffer -> left off. + (with-temp-buffer + (delay-mode-hooks (org-mode)) + (insert "#+title: notes\n* a heading\n") + (pearl--maybe-enable-mode) + (should-not pearl-mode)) + ;; Non-org buffer with the header -> left off (org-mode gate). + (with-temp-buffer + (fundamental-mode) + (insert "#+LINEAR-SOURCE: (:type filter)\n") + (pearl--maybe-enable-mode) + (should-not pearl-mode))) (provide 'test-pearl-keymap) ;;; test-pearl-keymap.el ends here |
