diff options
author | Sean Allred <code@seanallred.com> | 2014-12-26 17:55:48 -0500 |
---|---|---|
committer | Sean Allred <code@seanallred.com> | 2014-12-26 17:55:48 -0500 |
commit | b006537bb48201cf7996958ef0cc3b918268ff33 (patch) | |
tree | 1b3663727ecbfb1559f3140593ff4b189d4e4551 /sx.el | |
parent | 7d2cccd82cf6c658e330767d0e20e48e42ff1ac6 (diff) | |
parent | a919c72f2b58d889bf3fbdde100f9912a90c64ab (diff) |
Merge branch 'master' into issue-151--dot-variables
Conflicts:
sx.el
Diffstat (limited to 'sx.el')
-rw-r--r-- | sx.el | 34 |
1 files changed, 34 insertions, 0 deletions
@@ -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 |