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 51eaf84
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions org-super-agenda.el
Original file line number Diff line number Diff line change
Expand Up @@ -881,16 +881,29 @@ 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.
Expand Down

0 comments on commit 51eaf84

Please sign in to comment.