From 08eea895f1a445156c2e1c382bf167ba6d9d4515 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Wed, 12 Nov 2014 21:19:31 +0000 Subject: Update code to new assoc-let --- sx-request.el | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'sx-request.el') diff --git a/sx-request.el b/sx-request.el index 56362fc..f8feb22 100644 --- a/sx-request.el +++ b/sx-request.el @@ -107,15 +107,16 @@ number of requests left every time it finishes a call.") (error "Response could not be read by `json-read-from-string'")) ;; If we get here, the response is a valid data structure (sx-assoc-let response - (when error_id + (when .error_id (error "Request failed: (%s) [%i %s] %S" - method error_id error_name error_message)) + .method .error_id .error_name .error_message)) (when (< (setq sx-request-remaining-api-requests - quota_remaining) + .quota_remaining) sx-request-remaining-api-requests-message-threshold) (sx-message "%d API requests reamining" sx-request-remaining-api-requests)) - items))))))) + :hi + .items))))))) ;;; Support Functions -- cgit v1.2.3 From 9c2e07f01f41c223b07356c4bd495e6f7edd1d0f Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Wed, 12 Nov 2014 17:56:00 -0500 Subject: Remove spurious line --- sx-request.el | 1 - 1 file changed, 1 deletion(-) (limited to 'sx-request.el') diff --git a/sx-request.el b/sx-request.el index f8feb22..dd98ead 100644 --- a/sx-request.el +++ b/sx-request.el @@ -115,7 +115,6 @@ number of requests left every time it finishes a call.") sx-request-remaining-api-requests-message-threshold) (sx-message "%d API requests reamining" sx-request-remaining-api-requests)) - :hi .items))))))) -- cgit v1.2.3 From 5058ab5ba14220615c6a01911898b2c8ded987e4 Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Fri, 14 Nov 2014 00:38:33 -0500 Subject: Clean content at the request level --- sx-encoding.el | 32 ++++++++++++++++++++++++++++++++ sx-question-list.el | 2 +- sx-question-mode.el | 6 +++--- sx-request.el | 2 +- 4 files changed, 37 insertions(+), 5 deletions(-) (limited to 'sx-request.el') diff --git a/sx-encoding.el b/sx-encoding.el index 58bbd80..7f4765a 100644 --- a/sx-encoding.el +++ b/sx-encoding.el @@ -23,6 +23,8 @@ ;;; Code: +(require 'cl-lib) + (defcustom sx-encoding-html-entities-plist '(Aacute "Á" aacute "á" Acirc "Â" acirc "â" acute "´" AElig "Æ" aelig "æ" Agrave "À" agrave "à" alefsym "ℵ" Alpha "Α" alpha "α" amp "&" and "∧" @@ -86,6 +88,36 @@ Applies `sx-encoding-normalize-line-endings' and (sx-encoding-normalize-line-endings string))) +;;; @TODO: This is a pretty ugly implementation. It can likely be +;;; simplified and it should be improved. +(defun sx-encoding-clean-content-deep (data) + "Clean DATA recursively where necessary. + +See `sx-encoding-clean-content'." + (cond + ;; If we're looking at an atom, clean it if it's a string. + ;; Otherwise, just return it. + ((atom data) + (if (stringp data) (sx-encoding-clean-content data) data)) + ;; Looking at a vector? Recurse by mapping. + ((vectorp data) + (cl-map #'vector #'sx-encoding-clean-content-deep data)) + ;; Is our cdr a vector? Map again, but reconstruct the cons cell. + ((vectorp (cdr data)) + (cons (car data) (cl-map #'vector + #'sx-encoding-clean-content-deep + (cdr data)))) + ;; Is our cdr just a string? Clean and return it, reconstructing. + ((stringp (cdr data)) + (cons (car data) (sx-encoding-clean-content (cdr data)))) + ;; Is this a cons cell where the other part is an atom? Return the + ;; atom. If we got here, it wasn't a string. + ((and (consp data) (atom (cdr data))) data) + ;; If it's a list, map. + ((listp data) (mapcar #'sx-encoding-clean-content-deep data)) + ;; Default to identity. + (t data))) + (defun sx-encoding-gzipped-p (data) "Checks for magic bytes in DATA. diff --git a/sx-question-list.el b/sx-question-list.el index 8c558e6..ff1bdaa 100644 --- a/sx-question-list.el +++ b/sx-question-list.el @@ -231,7 +231,7 @@ Used in the questions list to indicate a question was updated \"4d ago\"." 'sx-question-list-answers)) (concat (propertize - (sx-encoding-clean-content .title) + .title 'face (if (sx-question--read-p .data) 'sx-question-list-read-question ;; Increment `sx-question-list--unread-count' for the mode-line. diff --git a/sx-question-mode.el b/sx-question-mode.el index c17d55a..4cbdf3a 100644 --- a/sx-question-mode.el +++ b/sx-question-mode.el @@ -200,7 +200,7 @@ DATA can represent a question or an answer." (if .title ;; Questions have title (propertize - (sx-encoding-clean-content .title) + .title 'font-lock-face 'sx-question-mode-title 'sx-question-mode--section 1) ;; Answers don't @@ -237,7 +237,7 @@ DATA can represent a question or an answer." '(face sx-question-mode-content-face) (insert "\n" (sx-question-mode--fill-string - (sx-encoding-clean-content .body_markdown)) + .body_markdown) sx-question-mode-separator))) ;; Comments (when .comments @@ -277,7 +277,7 @@ DATA can represent a question or an answer." (sx-assoc-let data (insert " " - (sx-encoding-clean-content .body_markdown) + .body_markdown " – " (sx-question-mode--propertized-display-name .owner) "\n"))) diff --git a/sx-request.el b/sx-request.el index dd98ead..b16fd9a 100644 --- a/sx-request.el +++ b/sx-request.el @@ -115,7 +115,7 @@ number of requests left every time it finishes a call.") sx-request-remaining-api-requests-message-threshold) (sx-message "%d API requests reamining" sx-request-remaining-api-requests)) - .items))))))) + (sx-encoding-clean-content-deep .items)))))))) ;;; Support Functions -- cgit v1.2.3 From ff9298fdf3f35a6c110375445639f9e7bb41ec7f Mon Sep 17 00:00:00 2001 From: Jonathan Leech-Pepin Date: Fri, 14 Nov 2014 14:49:28 -0500 Subject: Set `sx-request-api-root` to use `https` instead of `http`. This will prevent loss of authentication token when using authentication. --- sx-request.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sx-request.el') diff --git a/sx-request.el b/sx-request.el index b16fd9a..6dc54e7 100644 --- a/sx-request.el +++ b/sx-request.el @@ -41,7 +41,7 @@ "The current version of the API.") (defconst sx-request-api-root - (format "http://api.stackexchange.com/%s/" sx-request-api-version) + (format "https://api.stackexchange.com/%s/" sx-request-api-version) "The base URL to make requests from.") (defcustom sx-request-silent-p -- cgit v1.2.3