diff options
| author | Craig Jennings <c@cjennings.net> | 2026-06-02 12:59:54 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-06-02 12:59:54 -0500 |
| commit | 1a34cb26cbaec7af31a0d93a8f1c563eb5e45be5 (patch) | |
| tree | 8cb0c7fb7fbeb0c3ddd5bf721565fdfec7d09c7a /pearl.el | |
| parent | 42f3a75651ed8d2f8e601c654e482dc85363bb83 (diff) | |
| download | pearl-1a34cb26cbaec7af31a0d93a8f1c563eb5e45be5.tar.gz pearl-1a34cb26cbaec7af31a0d93a8f1c563eb5e45be5.zip | |
feat(views): set-default-view command
Phase 2 of the default-view spec: the command that sets the default that phase 1 reads. It's the v D slot the keybinding work reserved (the binding itself lands in phase 3).
From a buffer that's showing a local view, pearl-set-default-view offers that view as the default. Otherwise it prompts over the local-view names with a my-open-issues sentinel on top that clears the default. Quitting leaves it unchanged.
pearl--persist-default-view writes through customize-save-variable so the choice survives a restart. In accounts mode it updates the active account's :default-view and preserves the account's other plist keys, the same metadata-preserving rewrite local-view edits use. In legacy mode it writes the global pearl-default-view.
Eight tests: persist scope-targeting and key preservation in both modes, plus the offer, prompt, clear, and cancel paths. Suite 801 to 809, compile and lint clean.
Diffstat (limited to 'pearl.el')
| -rw-r--r-- | pearl.el | 62 |
1 files changed, 62 insertions, 0 deletions
@@ -6182,6 +6182,68 @@ never blocks the hot key." default) (pearl-list-issues))))) +(defconst pearl--default-view-clear "[ My open issues ]" + "Sentinel shown atop the `pearl-set-default-view' prompt. +Choosing it clears the default back to nil -- the built-in my-open-issues +fetch -- rather than naming a local view.") + +(defun pearl--persist-default-view (value) + "Persist VALUE (a local-view name string, or nil) as the default view. +In accounts mode, write VALUE to the active account's `:default-view' in +`pearl-accounts', preserving the account's other plist keys; in legacy +single-account mode, write the global `pearl-default-view'. Both persist +durably through `customize-save-variable' so the choice survives a restart." + (let ((ctx (pearl--current-account-context))) + (if ctx + (let ((name (plist-get ctx :name))) + (setq pearl-accounts + (mapcar (lambda (entry) + (if (string-equal (car entry) name) + (cons (car entry) + (plist-put (copy-sequence (cdr entry)) + :default-view value)) + entry)) + pearl-accounts)) + (customize-save-variable 'pearl-accounts pearl-accounts)) + (setq pearl-default-view value) + (customize-save-variable 'pearl-default-view value)))) + +;;;###autoload +(defun pearl-set-default-view () + "Set and persist the default view `pearl-open-default-view' opens. +When the current buffer shows a local view, offers that view as the default. +Otherwise prompts over `pearl-local-views' names with a clear-to-my-open-issues +sentinel at the top; choosing it clears the default, and quitting leaves it +unchanged. Persists per scope (the active account's `:default-view' in +accounts mode, `pearl-default-view' in legacy) via `customize-save-variable'. +Bound to \\='C-; L v D\\='." + (interactive) + (let* ((source (pearl--read-active-source)) + (buf-view (and source + (eq (plist-get source :type) 'filter) + (let ((n (plist-get source :name))) + (and (stringp n) (assoc n pearl-local-views) n)))) + (value + (if (and buf-view + (pearl--read-yes-no + (format "Set '%s' as the default view? " buf-view))) + buf-view + (let ((choice (completing-read + "Default view: " + (pearl--completion-table-keep-order + (pearl--with-sentinel pearl--default-view-clear + (mapcar #'car pearl-local-views))) + nil t))) + (cond + ((or (null choice) (string-empty-p choice)) :unchanged) + ((string= choice pearl--default-view-clear) nil) + (t choice)))))) + (if (eq value :unchanged) + (message "Default view unchanged") + (pearl--persist-default-view value) + (message "Default view set to %s" + (if value (format "'%s'" value) "my open issues"))))) + ;;;###autoload (defun pearl-list-issues-by-project () "List every open Linear issue in a chosen project (all assignees). |
