aboutsummaryrefslogtreecommitdiff
path: root/pearl.el
diff options
context:
space:
mode:
Diffstat (limited to 'pearl.el')
-rw-r--r--pearl.el62
1 files changed, 62 insertions, 0 deletions
diff --git a/pearl.el b/pearl.el
index a352fd1..7705e0b 100644
--- a/pearl.el
+++ b/pearl.el
@@ -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).