diff options
Diffstat (limited to 'sx-button.el')
-rw-r--r-- | sx-button.el | 34 |
1 files changed, 26 insertions, 8 deletions
diff --git a/sx-button.el b/sx-button.el index 5a2f052..d32314d 100644 --- a/sx-button.el +++ b/sx-button.el @@ -77,30 +77,35 @@ This is usually a link's URL, or the content of a code block." (point) 'sx-button-copy-type) content))))) -(defun sx-button-edit-this (text-or-marker &optional major-mode) - "Open a temp buffer populated with the string TEXT-OR-MARKER using MAJOR-MODE. +(defun sx-button-edit-this (text-or-marker &optional majormode) + "Open a temp buffer populated with the string TEXT-OR-MARKER using MAJORMODE. When given a marker (or interactively), use the 'sx-button-copy and the 'sx-mode text-properties under the marker. These are usually part of a code-block." (interactive (list (point-marker))) ;; Buttons receive markers. (when (markerp text-or-marker) - (setq major-mode (get-text-property text-or-marker 'sx-mode)) + (setq majormode (get-text-property text-or-marker 'sx-mode)) (unless (setq text-or-marker (get-text-property text-or-marker 'sx-button-copy)) (sx-message "Nothing of interest here."))) (with-current-buffer (pop-to-buffer (generate-new-buffer "*sx temp buffer*")) (insert text-or-marker) - (when major-mode - (funcall major-mode)))) + (when majormode + (funcall majormode)))) (defun sx-button-follow-link (&optional pos) "Follow link at POS. If POS is nil, use `point'." (interactive) - (browse-url - (or (get-text-property (or pos (point)) 'sx-button-url) - (sx-user-error "No url under point: %s" (or pos (point)))))) + (let ((url (or (get-text-property (or pos (point)) 'sx-button-url) + (sx-user-error "No url under point: %s" (or pos (point)))))) + ;; If we didn't recognize the link, this errors immediately. If + ;; we mistakenly recognize it, it will error when we try to fetch + ;; whatever we thought it was. + (condition-case nil (sx-open-link url) + ;; When it errors, don't blame the user, just visit externally. + (error (sx-visit-externally url))))) ;;; Help-echo definitions @@ -117,6 +122,12 @@ usually part of a code-block." "link") "Help echoed in the minibuffer when point is on a user.") +(defconst sx-button--tag-help-echo + (format sx-button--help-echo + "Tag search" + "tag") + "Help echoed in the minibuffer when point is on a tag.") + (defconst sx-button--question-title-help-echo (format sx-button--help-echo "hide content" @@ -158,6 +169,13 @@ usually part of a code-block." 'face 'sx-user-name :supertype 'sx-button) +(declare-function sx-search-tag-at-point "sx-search") +(define-button-type 'sx-button-tag + 'action #'sx-search-tag-at-point + 'help-echo sx-button--tag-help-echo + 'face 'sx-tag + :supertype 'sx-button) + (define-button-type 'sx-button-comment 'help-echo (concat "mouse-1, RET" (propertize ": write a comment" |