aboutsummaryrefslogtreecommitdiff
path: root/sx-interaction.el
diff options
context:
space:
mode:
authorSean Allred <code@seanallred.com>2014-12-30 17:47:42 -0500
committerSean Allred <code@seanallred.com>2014-12-30 17:47:42 -0500
commitb20f56b0c59b1e99fac745e408369d01de0f0bb5 (patch)
treefa30f72a8fbe94e5b319c9163b1d70d8768ad65e /sx-interaction.el
parentc215e84da4dcfa63c7a0c05996cc131e031efe64 (diff)
parent1267f300c850173e74dda0b7f704261b4a25b85c (diff)
Merge branch 'master' into issue-151--dot-variables
Conflicts: sx.el
Diffstat (limited to 'sx-interaction.el')
-rw-r--r--sx-interaction.el27
1 files changed, 23 insertions, 4 deletions
diff --git a/sx-interaction.el b/sx-interaction.el
index c6f2639..372a5b1 100644
--- a/sx-interaction.el
+++ b/sx-interaction.el
@@ -107,7 +107,7 @@ Only fields contained in TO are copied."
;;; Visiting
-(defun sx-visit (data &optional copy-as-kill)
+(defun sx-visit-externally (data &optional copy-as-kill)
"Visit DATA in a web browser.
DATA can be a question, answer, or comment. Interactively, it is
derived from point position.
@@ -129,13 +129,31 @@ If DATA is a question, also mark it as read."
(sx-question--mark-read data)
(sx--maybe-update-display))))
+(defun sx-open-link (link)
+ "Visit element given by LINK inside Emacs.
+Element can be a question, answer, or comment."
+ (interactive
+ (let ((def (with-temp-buffer
+ (save-excursion (yank))
+ (thing-at-point 'url))))
+ (list (read-string (concat "Link (" def "): ") nil nil def))))
+ (let ((data (sx--link-to-data link)))
+ (sx-assoc-let data
+ (cl-case .type
+ (answer
+ (sx-display-question
+ (sx-question-get-from-answer .site .id) 'focus))
+ (question
+ (sx-display-question
+ (sx-question-get-question .site .id) 'focus))))))
+
;;; Displaying
(defun sx-display-question (&optional data focus window)
"Display question given by DATA, on WINDOW.
When DATA is nil, display question under point. When FOCUS is
non-nil (the default when called interactively), also focus the
-relevant window.
+relevant window.
If WINDOW nil, the window is decided by
`sx-question-mode-display-buffer-function'."
@@ -255,13 +273,13 @@ If SILENT is nil, message the user about this limit."
(defun sx--get-post (type site id)
"Find in the database a post identified by TYPE, SITE and ID.
-TYPE is `question' or `answer'.
+TYPE is `question' or `answer'.
SITE is a string.
ID is an integer."
(let ((db (cons sx-question-mode--data
sx-question-list--dataset)))
(setq db
- (cond
+ (cond
((string= type "question") db)
((string= type "answer")
(apply #'cl-map 'list #'identity
@@ -327,6 +345,7 @@ from context at point."
(sx-site-get-api-tokens) nil t nil nil
default)))
+;;;###autoload
(defun sx-ask (site)
"Start composing a question for SITE.
SITE is a string, indicating where the question will be posted."