diff options
author | Sean Allred <code@seanallred.com> | 2014-11-29 00:18:49 -0500 |
---|---|---|
committer | Sean Allred <code@seanallred.com> | 2014-11-29 00:18:49 -0500 |
commit | 5ededa9ffb7228ee3eef1aaf7b79477cfa635788 (patch) | |
tree | e2a9b6b1afb13e8f27de3187a547df01d5717c98 | |
parent | 891c7eeb070ccde615cd3371bf9136a3b2287b4f (diff) | |
parent | 98478b0bcfdf3c11f2cf30c438843994cc4100c5 (diff) |
Merge branch 'master' into organize
-rw-r--r-- | sx-method.el | 3 | ||||
-rw-r--r-- | sx-question-mode.el | 101 | ||||
-rw-r--r-- | sx-question.el | 29 | ||||
-rw-r--r-- | sx-request.el | 16 | ||||
-rw-r--r-- | sx-tab.el | 7 |
5 files changed, 74 insertions, 82 deletions
diff --git a/sx-method.el b/sx-method.el index 1b20cbf..83455b8 100644 --- a/sx-method.el +++ b/sx-method.el @@ -82,7 +82,8 @@ Return the entire response as a complex alist." (prog1 (format "?site=%s" site) (setq site nil))))) - (call #'sx-request-make)) + (call #'sx-request-make) + parameters) (lwarn "sx-call-method" :debug "A: %S T: %S. M: %S,%s. F: %S" (equal 'warn auth) access-token method-auth full-method filter-auth) (unless access-token diff --git a/sx-question-mode.el b/sx-question-mode.el index ff13ede..fcbd112 100644 --- a/sx-question-mode.el +++ b/sx-question-mode.el @@ -25,6 +25,7 @@ ;;; Code: (require 'markdown-mode) +(require 'button) (eval-when-compile (require 'rx)) @@ -99,12 +100,12 @@ If WINDOW is given, use that to display the buffer." :group 'sx-question-mode-faces) (defface sx-question-mode-title - '((t :height 1.3 :weight bold :inherit default)) + '((t :weight bold :inherit default)) "Face used on the question title in the question buffer." :group 'sx-question-mode-faces) (defface sx-question-mode-title-comments - '((t :height 1.1 :inherit sx-question-mode-title)) + '((t :inherit sx-question-mode-title)) "Face used on the question title in the question buffer." :group 'sx-question-mode-faces) @@ -231,17 +232,15 @@ QUESTION must be a data structure returned by `json-read'." (defvar sx-question-mode--section-help-echo (format - (propertize "%s to hide/display content" 'face 'minibuffer-prompt) - (propertize "RET" 'face 'font-lock-function-name-face)) + (propertize "%s to hide/display content" 'face 'minibuffer-prompt) + (propertize "RET" 'face 'font-lock-function-name-face)) "Help echoed in the minibuffer when point is on a section.") -(defvar sx-question-mode--title-properties - `(face sx-question-mode-title - action sx-question-mode-hide-show-section - help-echo ,sx-question-mode--section-help-echo - button t - follow-link t) - "Title properties.") +(define-button-type 'sx-question-mode-title + 'face 'sx-question-mode-title + 'action #'sx-question-mode-hide-show-section + 'help-echo 'sx-question-mode--section-help-echo + 'follow-link t) (defun sx-question-mode--print-section (data) "Print a section corresponding to DATA. @@ -250,17 +249,13 @@ DATA can represent a question or an answer." (sx-assoc-let data (sx--wrap-in-text-property (list 'sx--data-here data) - (insert sx-question-mode-header-title - (apply - #'propertize - ;; Questions have title - (or .title - ;; Answers don't - sx-question-mode-answer-title) - ;; Section level - 'sx-question-mode--section (if .title 1 2) - ;; face, action and help-echo - sx-question-mode--title-properties)) + (insert sx-question-mode-header-title) + (insert-text-button + ;; Questions have title, Answers don't + (or .title sx-question-mode-answer-title) + ;; Section level + 'sx-question-mode--section (if .title 1 2) + :type 'sx-question-mode-title) ;; Sections can be hidden with overlays (sx--wrap-in-overlay '(sx-question-mode--section-content t) @@ -275,8 +270,8 @@ DATA can represent a question or an answer." (sx-time-seconds-to-date .creation_date) (when .last_edit_date (format sx-question-mode-last-edit-format - (sx-time-since .last_edit_date) - (sx-question-mode--propertize-display-name .last_editor)))) + (sx-time-since .last_edit_date) + (sx-question-mode--propertize-display-name .last_editor)))) 'sx-question-mode-date) (sx-question-mode--insert-header sx-question-mode-header-score @@ -307,12 +302,12 @@ DATA can represent a question or an answer." ;; Comments have their own `sx--data-here' property (so they can ;; be upvoted too). (when .comments - (insert "\n" - (apply #'propertize - sx-question-mode-comments-title - 'face 'sx-question-mode-title-comments - 'sx-question-mode--section 3 - sx-question-mode--title-properties)) + (insert "\n") + (insert-text-button + sx-question-mode-comments-title + 'face 'sx-question-mode-title-comments + 'sx-question-mode--section 3 + :type 'sx-question-mode-title) (sx--wrap-in-overlay '(sx-question-mode--section-content t) (insert "\n") @@ -434,36 +429,30 @@ E.g.: (url (or (match-string-no-properties 2) (sx-question-mode-find-reference (match-string-no-properties 3) - text)))) - (replace-match - (sx-question-mode--propertize-link - (if sx-question-mode-pretty-links - text - (match-string-no-properties 0)) - url) - :fixedcase :literal nil 0))))) - -(defun sx-question-mode--propertize-link (text url) + text))) + (full-text (match-string-no-properties 0))) + (replace-match "") + (sx-question-mode--insert-link + (if sx-question-mode-pretty-links text full-text) + url))))) + +(define-button-type 'sx-question-mode-link + 'follow-link t + 'action #'sx-question-mode-follow-link) + +(defun sx-question-mode--insert-link (text url) "Return a link propertized version of string TEXT. URL is used as 'help-echo and 'url properties." - (propertize + (insert-text-button text ;; Mouse-over - 'help-echo (format - (propertize "URL: %s, %s to visit" 'face 'minibuffer-prompt) - (propertize url 'face 'default) - (propertize "RET" 'face 'font-lock-function-name-face)) - ;; In case we need it. - 'url url - ;; Decoration - 'face 'link - 'mouse-face 'highlight - ;; So RET works - 'button t - ;; So mouse works - 'follow-link t - ;; What RET calls - 'action #'sx-question-mode-follow-link)) + 'help-echo + (format (propertize "URL: %s, %s to visit" 'face 'minibuffer-prompt) + (propertize url 'face 'default) + (propertize "RET" 'face 'font-lock-function-name-face)) + ;; For visiting and stuff. + 'url url + :type 'sx-question-mode-link)) (defun sx-question-mode-follow-link (&optional pos) "Follow link at POS. If POS is nil, use `point'." diff --git a/sx-question.el b/sx-question.el index 680eaaf..7b53e2e 100644 --- a/sx-question.el +++ b/sx-question.el @@ -137,20 +137,21 @@ If no cache exists for it, initialize one with SITE." (defun sx-question--mark-hidden (question) "Mark QUESTION as being hidden." - (let ((site-cell (assoc .site sx-question--user-hidden-list)) - cell) - ;; If question already hidden, do nothing. - (unless (memq .question_id site-cell) - ;; First question from this site. - (push (list .site .question_id) sx-question--user-hidden-list) - ;; Question wasn't present. - ;; Add it in, but make sure it's sorted (just in case we need - ;; it later). - (sx-sorted-insert-skip-first .question_id site-cell >) - ;; This causes a small lag on `j' and `k' as the list gets large. - ;; Should we do this on a timer? - ;; Save the results. - (sx-cache-set 'hidden-questions sx-question--user-hidden-list)))) + (sx-assoc-let question + (let ((site-cell (assoc .site sx-question--user-hidden-list)) + cell) + ;; If question already hidden, do nothing. + (unless (memq .question_id site-cell) + ;; First question from this site. + (push (list .site .question_id) sx-question--user-hidden-list) + ;; Question wasn't present. + ;; Add it in, but make sure it's sorted (just in case we need + ;; it later). + (sx-sorted-insert-skip-first .question_id site-cell >) + ;; This causes a small lag on `j' and `k' as the list gets large. + ;; Should we do this on a timer? + ;; Save the results. + (sx-cache-set 'hidden-questions sx-question--user-hidden-list))))) ;;;; Other data diff --git a/sx-request.el b/sx-request.el index b6c468b..3a8b7a8 100644 --- a/sx-request.el +++ b/sx-request.el @@ -91,9 +91,8 @@ number of requests left every time it finishes a call." ;;; Making Requests -(defun sx-request-make - (method &optional args request-method) - "Make a request to the API, executing METHOD with ARGS. +(defun sx-request-make (method &optional args request-method) + "Make a request to the API, executing METHOD with ARGS. You should almost certainly be using `sx-method-call' instead of this function. REQUEST-METHOD is one of `GET' (default) or `POST'. @@ -116,8 +115,7 @@ then read with `json-read-from-string'. the main content of the response is returned." (let* ((url-automatic-caching t) (url-inhibit-uncompression t) - (url-request-data (sx-request--build-keyword-arguments args - nil)) + (url-request-data (sx-request--build-keyword-arguments args nil)) (request-url (concat sx-request-api-root method)) (url-request-method request-method) (url-request-extra-headers @@ -168,15 +166,11 @@ Currently returns nil." ;;; Support Functions - -(defun sx-request--build-keyword-arguments (alist &optional - kv-sep need-auth) +(defun sx-request--build-keyword-arguments (alist &optional kv-sep) "Format ALIST as a key-value list joined with KV-SEP. If authentication is needed, include it also or error if it is not available. -If NEED-AUTH is non-nil, authentication is required. - Build a \"key=value&key=value&...\"-style string with the elements of ALIST. If any value in the alist is nil, that pair will not be included in the return. If you wish to pass a notion of @@ -185,7 +179,7 @@ false, use the symbol `false'. Each element is processed with ;; Add API key to list of arguments, this allows for increased quota ;; automatically. (let ((api-key (cons "key" sx-request-api-key)) - (auth (car (sx-cache-get 'auth)))) + (auth (car (sx-cache-get 'auth)))) (push api-key alist) (when auth (push auth alist)) @@ -102,6 +102,13 @@ If SITE is nil, use `sx-tab-default-site'." (lambda (page) (sx-question-get-questions sx-question-list--site page))) +;;;###autoload +(autoload 'sx-tab-frontpage + (expand-file-name + "sx-tab" + (when load-file-name + (file-name-directory load-file-name))) + nil t) (provide 'sx-tab) ;;; sx-tab.el ends here |