diff options
author | Artur Malabarba <bruce.connor.am@gmail.com> | 2014-11-26 12:07:59 +0000 |
---|---|---|
committer | Artur Malabarba <bruce.connor.am@gmail.com> | 2014-11-26 12:07:59 +0000 |
commit | e9f03bfb583d514ff9c930c551f8e0760f29a598 (patch) | |
tree | 169d6cf9f60f70089d583edad11ee69a1803537a | |
parent | 0d73114ea7e7a1aa9cf1e391951a9522e129492d (diff) | |
parent | 85835a2031d046e529f39b108b960c993d9bcaab (diff) |
Merge pull request #99 from vermiculus/copy-visit-link
Add ability to copy link instead of visiting it
-rw-r--r-- | sx-interaction.el | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/sx-interaction.el b/sx-interaction.el index de27ca5..e4234b0 100644 --- a/sx-interaction.el +++ b/sx-interaction.el @@ -51,16 +51,25 @@ Only fields contained in TO are copied." (setcar to (car from)) (setcdr to (cdr from))) -(defun sx-visit (data) +(defun sx-visit (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. + +If copy-as-kill is non-nil, do not call `browse-url'. +Instead, copy the link as a new kill with `kill-new'. +Interactively, this is specified with a prefix argument. + If DATA is a question, also mark it as read." - (interactive (list (sx--data-here))) + (interactive (list (sx--data-here) current-prefix-arg)) (sx-assoc-let data - (when (stringp .link) - (browse-url .link)) - (when .title + (let ((link + (when (stringp .link) + (funcall (if copy-as-kill #'kill-new #'browse-url) + .link)))) + (when (and (called-interactively-p 'any) copy-as-kill) + (message "Copied: %S" link))) + (when (and .title (not copy-as-kill)) (sx-question--mark-read data) (sx--maybe-update-display)))) |