aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Allred <code@seanallred.com>2014-11-14 00:38:33 -0500
committerSean Allred <code@seanallred.com>2014-11-14 00:38:33 -0500
commit5058ab5ba14220615c6a01911898b2c8ded987e4 (patch)
tree364b99967b6a481e26c0fffaa9a87094a8002c62
parentd511ee92d4779cf272a0fb9e215c514eb3cc1165 (diff)
Clean content at the request level
-rw-r--r--sx-encoding.el32
-rw-r--r--sx-question-list.el2
-rw-r--r--sx-question-mode.el6
-rw-r--r--sx-request.el2
4 files changed, 37 insertions, 5 deletions
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