diff options
author | Artur Malabarba <bruce.connor.am@gmail.com> | 2014-12-17 15:35:54 -0200 |
---|---|---|
committer | Artur Malabarba <bruce.connor.am@gmail.com> | 2014-12-17 15:43:16 -0200 |
commit | e39a909dc722dfdb48ecc4533cf061dbb209abf1 (patch) | |
tree | 7946e2806452036ca06435238caac372cb103be3 | |
parent | 925b4ef8b503b22481e624905fa6e3af8d6d4077 (diff) |
Implement identifying type, id, and site of a link.
-rw-r--r-- | sx-interaction.el | 1 | ||||
-rw-r--r-- | sx.el | 16 |
2 files changed, 17 insertions, 0 deletions
diff --git a/sx-interaction.el b/sx-interaction.el index e7a4d94..2c392e1 100644 --- a/sx-interaction.el +++ b/sx-interaction.el @@ -128,6 +128,7 @@ If DATA is a question, also mark it as read." (sx-question--mark-read data) (sx--maybe-update-display)))) + ;;; Displaying (defun sx-display-question (&optional data focus window) @@ -317,6 +317,22 @@ If ALIST doesn't have a `site' property, one is created using the (sx--ensure-site ,alist) (let-alist ,alist ,@body))) +(defun sx--link-to-data (link) + "Convert string LINK into data that can be displayed." + (let ((result (list (cons 'site (sx--site link))))) + (when (or + ;; Answer + (and (or (string-match "/a/\\([0-9]+\\)/[0-9]+\\(#.*\\|\\)\\'" link) + (string-match "/questions/[0-9]+/[^/]+/\\([0-9]\\)/?\\(#.*\\|\\)\\'" link)) + (push (cons 'type 'answer) result)) + ;; Question + (and (or (string-match "/q/\\([0-9]+\\)/[0-9]+\\(#.*\\|\\)\\'" link) + (string-match "/questions/\\([0-9]+\\)/" link)) + (push (cons 'type 'question) result))) + (push (cons 'id (string-to-number (match-string-no-properties 1 link))) + result)) + result)) + (defcustom sx-init-hook nil "Hook run when SX initializes. Run after `sx-init--internal-hook'." |