Skip to content

Commit

Permalink
Fix mishandled deprecation
Browse files Browse the repository at this point in the history
Deprecate/alias didn’t work because we use a built-in function to
validate the selector (‘org-super-agenda--get-selector-fn’).

This commit addresses this problem by creating the variable
‘org-super-agenda-deprecated-selectors-alist’ in which each cons is
written as (deprecated-selector . new-selector).  We then use this
variable to validate the selector before we throwing an error in
‘org-super-agenda--get-selector-fn’.
  • Loading branch information
zaeph committed Jul 15, 2019
1 parent 8e088ab commit 7ee72a0
Showing 1 changed file with 41 additions and 28 deletions.
69 changes: 41 additions & 28 deletions org-super-agenda.el
Original file line number Diff line number Diff line change
Expand Up @@ -881,39 +881,52 @@ of the arguments to the function."
"Return function for SELECTOR, or nil if special selector.
Raise error if invalid selector."
(cond
((cl-member selector org-super-agenda-special-selectors)
;; Special selector, so no associated function; return nil
nil)
;; Valid selector: return function
((plist-get org-super-agenda-group-types selector))
((eq selector :habit)
;; :habit selector used but `org-habit' not loaded
(user-error "Please `require' the `org-habit' library to use the :habit selector"))
;; Invalid selector: raise error
((user-error "Invalid org-super-agenda-groups selector: %s" selector))))
((cl-member selector org-super-agenda-special-selectors)
;; Special selector, so no associated function; return nil
nil)
;; Valid selector: return function
((plist-get org-super-agenda-group-types selector))
((eq selector :habit)
;; :habit selector used but `org-habit' not loaded
(user-error "Please `require' the `org-habit' library to use the :habit selector"))
;; Deprecated selector: raise warning
((when-let ((new-selector (alist-get selector
org-super-agenda-deprecated-selectors-alist)))
(let ((old (symbol-name selector))
(new (symbol-name new-selector)))
(display-warning 'org-super-agenda
(concat "Deprecated selector, please use `" new
"' instead of `" old "'"))
(plist-get org-super-agenda-group-types new-selector))))
;; Invalid selector: raise error
((user-error "Invalid org-super-agenda-groups selector: %s" selector))))

(defvar org-super-agenda-deprecated-selectors-alist
'((:date . :timestamp))
"Alist of deprecated selectors and their replacements.")

(defun org-super-agenda--group-dispatch (items group)
"Group ITEMS with the appropriate grouping functions for GROUP.
Grouping functions are listed in `org-super-agenda-group-types', which
see."
(cl-loop for (selector args) on group by 'cddr ; plist access
for fn = (org-super-agenda--get-selector-fn selector)
;; This double "when fn" is an ugly hack, but it lets us
;; use the destructuring-bind; otherwise we'd have to put
;; all the collection logic in a progn, or do the
;; destructuring ourselves, which would be uglier.
when fn
for (auto-section-name non-matching matching) = (funcall fn items args)
when fn
;; This is the implicit OR
append matching into all-matches
and collect auto-section-name into names
and do (setq items non-matching)
for name = (if (stringp (car names))
(s-join " and " (-non-nil names))
;; Probably an :auto-group
(car names))
finally return (list name items all-matches)))
(cl-loop for (selector args) on group by 'cddr ; plist access
for fn = (org-super-agenda--get-selector-fn selector)
;; This double "when fn" is an ugly hack, but it lets us
;; use the destructuring-bind; otherwise we'd have to put
;; all the collection logic in a progn, or do the
;; destructuring ourselves, which would be uglier.
when fn
for (auto-section-name non-matching matching) = (funcall fn items args)
when fn
;; This is the implicit OR
append matching into all-matches
and collect auto-section-name into names
and do (setq items non-matching)
for name = (if (stringp (car names))
(s-join " and " (-non-nil names))
;; Probably an :auto-group
(car names))
finally return (list name items all-matches)))

;; TODO: This works, but it seems inelegant to basically copy the
;; group-dispatch function. A more pure-functional approach might be
Expand Down

0 comments on commit 7ee72a0

Please sign in to comment.