diff options
-rw-r--r-- | sx-question.el | 9 | ||||
-rw-r--r-- | sx.el | 27 |
2 files changed, 31 insertions, 5 deletions
diff --git a/sx-question.el b/sx-question.el index e9634f7..0ce5413 100644 --- a/sx-question.el +++ b/sx-question.el @@ -30,11 +30,10 @@ (require 'sx-request) ;; I don't know why this is here, but it was causing an API request on require. -(defvar sx-question-browse-filter nil - ;; (stack-filter-compile - ;; nil - ;; '(user.profile_image shallow_user.profile_image)) - ) +(defvar sx-question-browse-filter nil) +(sx-init-variable + sx-question-browse-filter + (sx-filter-compile nil '(user.profile_image shallow_user.profile_image))) ;; (stack-filter-store 'question-browse sx-question-browse-filter) @@ -112,6 +112,33 @@ is equivalent to `(let ,(mapcar (lambda (x) `(,x (cdr (assoc ',x ,alist)))) symbols) ,@body))) +(defcustom sx-init-hook nil + "Hook run when stack-mode initializes. + +Run after `sx-init--internal-hook'.") + +(defvar sx-init--internal-hook nil + "Hook run when stack-mode initializes. + +This is used internally to set initial values for variables such +as filters.") + +(defmacro sx-init-variable (variable value &optional setter) + "Set VARIABLE to VALUE using SETTER. +SETTER should be a function of two arguments. If SETTER is nil, +`set' is used." + (eval + `(add-hook + 'sx-init--internal-hook + (lambda () + (,(or setter #'setq) ,variable ,value)))) + nil) + +(defun stack-initialize () + (run-hooks + 'sx-init--internal-hook + 'sx-init-hook)) + (provide 'sx) ;;; sx.el ends here |