aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sx-cache.el13
-rw-r--r--sx-filter.el2
-rw-r--r--sx-network.el36
-rw-r--r--sx-question-list.el2
-rw-r--r--sx-question.el8
-rw-r--r--sx-site.el45
-rw-r--r--sx.el9
7 files changed, 59 insertions, 56 deletions
diff --git a/sx-cache.el b/sx-cache.el
index 098c292..e3b356b 100644
--- a/sx-cache.el
+++ b/sx-cache.el
@@ -38,18 +38,21 @@
(concat (symbol-name filename) ".el")
sx-cache-directory))
-(defun sx-cache-get (cache)
+(defun sx-cache-get (cache &optional form)
"Return the data within CACHE.
+If CACHE does not exist, evaluate FORM and set it to its return.
+
As with `sx-cache-set', CACHE is a file name within the
context of `sx-cache-directory'."
(unless (file-exists-p sx-cache-directory)
(mkdir sx-cache-directory))
(let ((file (sx-cache-get-file-name cache)))
- (when (file-exists-p file)
- (with-temp-buffer
- (insert-file-contents (sx-cache-get-file-name cache))
- (read (buffer-string))))))
+ (if (file-exists-p file)
+ (with-temp-buffer
+ (insert-file-contents (sx-cache-get-file-name cache))
+ (read (buffer-string)))
+ (sx-cache-set cache (eval form)))))
(defun sx-cache-set (cache data)
"Set the content of CACHE to DATA.
diff --git a/sx-filter.el b/sx-filter.el
index acd8fc1..90681e8 100644
--- a/sx-filter.el
+++ b/sx-filter.el
@@ -54,7 +54,7 @@ or string."
"filter/create"
keyword-arguments)))
(sx-assoc-let (elt response 0)
- (url-hexify-string .filter)))))
+ .filter))))
;;; Storage and Retrieval
diff --git a/sx-network.el b/sx-network.el
deleted file mode 100644
index f756a26..0000000
--- a/sx-network.el
+++ /dev/null
@@ -1,36 +0,0 @@
-;;; sx-network.el --- browsing networks -*- lexical-binding: t; -*-
-
-;; Copyright (C) 2014 Sean Allred
-
-;; Author: Sean Allred <code@seanallred.com>
-
-;; This program is free software; you can redistribute it and/or modify
-;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation, either version 3 of the License, or
-;; (at your option) any later version.
-
-;; This program is distributed in the hope that it will be useful,
-;; but WITHOUT ANY WARRANTY; without even the implied warranty of
-;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-;; GNU General Public License for more details.
-
-;; You should have received a copy of the GNU General Public License
-;; along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-;;; Commentary:
-
-;;
-
-;;; Code:
-
-(require 'sx-request)
-
-(defun sx-network-get-networks ()
- (sx-request-make "sites"))
-
-(provide 'sx-network)
-;;; sx-network.el ends here
-
-;; Local Variables:
-;; indent-tabs-mode: nil
-;; End:
diff --git a/sx-question-list.el b/sx-question-list.el
index a1dec7a..c6d298a 100644
--- a/sx-question-list.el
+++ b/sx-question-list.el
@@ -122,7 +122,7 @@ Letters do not insert themselves; instead, they are commands.
(defun sx-question-list--date-more-recent-p (x y)
"Non-nil if tabulated-entry X is newer than Y."
- (sx-question--<
+ (sx--<
sx-question-list-date-sort-method
(car x) (car y) #'>))
diff --git a/sx-question.el b/sx-question.el
index d15cc80..2fa9d2b 100644
--- a/sx-question.el
+++ b/sx-question.el
@@ -26,7 +26,6 @@
(require 'sx)
(require 'sx-filter)
-(require 'sx-lto)
(require 'sx-method)
(defvar sx-question-browse-filter
@@ -78,13 +77,6 @@
"Mark QUESTION as being read, until it is updated again."
nil)
-(defun sx-question--< (property x y &optional pred)
- "Non-nil if PROPERTY attribute of question X is less than that of Y.
-With optional argument predicate, use it instead of `<'."
- (funcall (or pred #'<)
- (cdr (assoc property x))
- (cdr (assoc property y))))
-
(defun sx-question--tag-format (tag)
"Formats TAG for display"
(concat "[" tag "]"))
diff --git a/sx-site.el b/sx-site.el
index 8775542..6bef91f 100644
--- a/sx-site.el
+++ b/sx-site.el
@@ -1,4 +1,4 @@
-;;; sx-site.el --- site functions
+;;; sx-site.el --- browsing sites -*- lexical-binding: t; -*-
;; Copyright (C) 2014 Sean Allred
@@ -19,16 +19,53 @@
;;; Commentary:
-;;
+;;
;;; Code:
-;;; @TODO use new caching system implemented in branch `network-list'
+(require 'sx-method)
+(require 'sx-cache)
+
+(defvar sx-site-browse-filter
+ '((.backoff
+ .error_id
+ .error_message
+ .error_name
+ .has_more
+ .items
+ .quota_max
+ .quota_remaining
+ site.site_type
+ site.name
+ site.site_url
+ site.api_site_parameter
+ site.related_sites
+ related_site.api_site_parameter
+ related_site.relation)
+ nil
+ none))
+
+(defun sx-site--get-site-list ()
+ (sx-cache-get
+ 'site-list
+ '(sx-method-call
+ "sites" '((pagesize . 999))
+ sx-site-browse-filter)))
+
+(defcustom sx-site-favorites
+ nil
+ "Favorite sites."
+ :group 'sx-site)
+
(defun sx-site-get-api-tokens ()
"Return a list of all known site tokens."
(mapcar
(lambda (site) (cdr (assoc 'api_site_parameter site)))
- (sx-method-call "sites" '((pagesize . 9999)))))
+ (sx-site--get-site-list)))
(provide 'sx-site)
;;; sx-site.el ends here
+
+;; Local Variables:
+;; indent-tabs-mode: nil
+;; End:
diff --git a/sx.el b/sx.el
index 058230c..53aae84 100644
--- a/sx.el
+++ b/sx.el
@@ -111,7 +111,7 @@ is equivalent to
(debug t))
(let ((symbol-alist (sx--deep-dot-search body)))
`(let ,(mapcar (lambda (x) `(,(car x) (cdr (assoc ',(cdr x) ,alist))))
- symbol-alist)
+ (delete-dups symbol-alist))
,@body)))
(defcustom sx-init-hook nil
@@ -125,6 +125,13 @@ Run after `sx-init--internal-hook'.")
This is used internally to set initial values for variables such
as filters.")
+(defun sx--< (property x y &optional pred)
+ "Non-nil if PROPERTY attribute of question X is less than that of Y.
+With optional argument predicate, use it instead of `<'."
+ (funcall (or pred #'<)
+ (cdr (assoc property x))
+ (cdr (assoc property y))))
+
(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,