diff options
author | Sean Allred <code@seanallred.com> | 2014-11-07 18:51:23 -0500 |
---|---|---|
committer | Sean Allred <code@seanallred.com> | 2014-11-07 18:51:23 -0500 |
commit | 1207f47bd2340922268a1340601d45e6c336c11a (patch) | |
tree | d4ff02bcfcf8ce1f2d7ccb46998dff647c4b3cd7 | |
parent | e9277af61fe725ef70769add9c050bfed4509a22 (diff) |
Introduce initialization logic and hooks
-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 |