aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Allred <code@seanallred.com>2014-12-23 22:55:09 -0500
committerSean Allred <code@seanallred.com>2014-12-23 22:55:09 -0500
commita919c72f2b58d889bf3fbdde100f9912a90c64ab (patch)
tree77633ed8e6581f4e9e5a1e792589379eb6bfe880
parent845cd697b1326f8c270dd2c76a6c120d3196428b (diff)
parent6eb53ee0f12dd9f7d444e6749f6cc55c6db62078 (diff)
Merge pull request #176 from vermiculus/define-assoc-let-first
Define assoc let first
-rw-r--r--sx.el68
1 files changed, 34 insertions, 34 deletions
diff --git a/sx.el b/sx.el
index 6f4e7c7..a31c0a0 100644
--- a/sx.el
+++ b/sx.el
@@ -51,6 +51,40 @@
(browse-url "https://github.com/vermiculus/sx.el/issues/new"))
+;;; Site
+(defun sx--site (data)
+ "Get the site in which DATA belongs.
+DATA can be a question, answer, comment, or user (or any object
+with a `link' property).
+DATA can also be the link itself."
+ (let ((link (if (stringp data) data
+ (cdr (assoc 'link data)))))
+ (when (stringp link)
+ (replace-regexp-in-string
+ "^https?://\\(?:\\(?1:[^/]+\\)\\.stackexchange\\|\\(?2:[^/]+\\)\\)\\.[^.]+/.*$"
+ "\\1\\2" link))))
+
+(defun sx--ensure-site (data)
+ "Add a `site' property to DATA if it doesn't have one. Return DATA.
+DATA can be a question, answer, comment, or user (or any object
+with a `link' property)."
+ (when data
+ (unless (assq 'site data)
+ (setcdr data (cons (cons 'site (sx--site data))
+ (cdr data))))
+ data))
+
+(defmacro sx-assoc-let (alist &rest body)
+ "Identical to `let-alist', except `.site' has a special meaning.
+If ALIST doesn't have a `site' property, one is created using the
+`link' property."
+ (declare (indent 1) (debug t))
+ `(progn
+ (require 'let-alist)
+ (sx--ensure-site ,alist)
+ (let-alist ,alist ,@body)))
+
+
;;; Browsing filter
(defvar sx-browse-filter
'((question.body_markdown
@@ -284,40 +318,6 @@ removed from the display name before it is returned."
(format "[%s]" (car kar)) (cdr kar) string)))
string))
-
-;;; Site
-(defun sx--site (data)
- "Get the site in which DATA belongs.
-DATA can be a question, answer, comment, or user (or any object
-with a `link' property).
-DATA can also be the link itself."
- (let ((link (if (stringp data) data
- (cdr (assoc 'link data)))))
- (when (stringp link)
- (replace-regexp-in-string
- "^https?://\\(?:\\(?1:[^/]+\\)\\.stackexchange\\|\\(?2:[^/]+\\)\\)\\.[^.]+/.*$"
- "\\1\\2" link))))
-
-(defun sx--ensure-site (data)
- "Add a `site' property to DATA if it doesn't have one. Return DATA.
-DATA can be a question, answer, comment, or user (or any object
-with a `link' property)."
- (when data
- (unless (assq 'site data)
- (setcdr data (cons (cons 'site (sx--site data))
- (cdr data))))
- data))
-
-(defmacro sx-assoc-let (alist &rest body)
- "Identical to `let-alist', except `.site' has a special meaning.
-If ALIST doesn't have a `site' property, one is created using the
-`link' property."
- (declare (indent 1) (debug t))
- `(progn
- (require 'let-alist)
- (sx--ensure-site ,alist)
- (let-alist ,alist ,@body)))
-
(defcustom sx-init-hook nil
"Hook run when SX initializes.
Run after `sx-init--internal-hook'."