From f26a55ce664d1840efef36079ab3634394006c5b Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sat, 29 Nov 2014 00:00:28 +0000 Subject: Fix byte-compile warnings Fixes #115 --- sx-method.el | 3 ++- sx-question.el | 29 +++++++++++++++-------------- 2 files changed, 17 insertions(+), 15 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.el b/sx-question.el index 01ba030..f80a9bd 100644 --- a/sx-question.el +++ b/sx-question.el @@ -134,20 +134,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 -- cgit v1.2.3 From e731fd754cb4d5ef7e0d5d7e094a98b4162cba61 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sat, 29 Nov 2014 00:00:48 +0000 Subject: Remove need-auth from sx-request--build-keyword-arguments --- sx-request.el | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/sx-request.el b/sx-request.el index a98af5a..6be363d 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)) -- cgit v1.2.3 -- cgit v1.2.3 From fafda82d046c3735a5e6d5e188622be40fe707d0 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sat, 29 Nov 2014 00:19:43 +0000 Subject: Autoload sx-tab-frontpage --- sx-tab.el | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sx-tab.el b/sx-tab.el index 154a90f..5b3f3c4 100644 --- a/sx-tab.el +++ b/sx-tab.el @@ -97,6 +97,9 @@ 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 load-file-name) + nil t) (provide 'sx-tab) ;;; sx-tab.el ends here -- cgit v1.2.3 From 73e37ca539fe7b620f066f4dd56ef97f0e4b91c7 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sat, 29 Nov 2014 01:08:30 +0000 Subject: Autoload sx-tab-frontpage correctly --- sx-tab.el | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sx-tab.el b/sx-tab.el index 5b3f3c4..7ccbf18 100644 --- a/sx-tab.el +++ b/sx-tab.el @@ -98,7 +98,11 @@ If SITE is nil, use `sx-tab-default-site'." (sx-question-get-questions sx-question-list--site page))) ;;;###autoload -(autoload 'sx-tab-frontpage (expand-file-name load-file-name) +(autoload 'sx-tab-frontpage + (expand-file-name + "sx-tab" + (when load-file-name + (file-name-directory load-file-name))) nil t) (provide 'sx-tab) -- cgit v1.2.3 From 6a58d6da301540de5a33a05d95eea1d6aed41553 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sat, 29 Nov 2014 02:26:36 +0000 Subject: Turn interactible objects into actual buttons Fixes #96 --- sx-question-mode.el | 97 ++++++++++++++++++++++++----------------------------- 1 file changed, 43 insertions(+), 54 deletions(-) diff --git a/sx-question-mode.el b/sx-question-mode.el index 6dc8395..d58f3d5 100644 --- a/sx-question-mode.el +++ b/sx-question-mode.el @@ -22,6 +22,7 @@ ;;; Code: (require 'markdown-mode) +(require 'button) (eval-when-compile (require 'rx)) @@ -228,17 +229,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. @@ -247,17 +246,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) @@ -272,8 +267,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 @@ -304,12 +299,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") @@ -431,36 +426,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'." -- cgit v1.2.3 From bc3c636962b9be1bed905150cb6161acddfe19e1 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sat, 29 Nov 2014 02:27:42 +0000 Subject: Tweak section header face. --- sx-question-mode.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sx-question-mode.el b/sx-question-mode.el index d58f3d5..21b6d40 100644 --- a/sx-question-mode.el +++ b/sx-question-mode.el @@ -97,12 +97,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) -- cgit v1.2.3