From e0c28935327051e589556e5943b8e82a70e268fa Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Mon, 3 Nov 2014 13:21:21 +0000 Subject: Define -decode-entities to decode html entities. --- stack-core.el | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) (limited to 'stack-core.el') diff --git a/stack-core.el b/stack-core.el index c2aff15..68d1e07 100644 --- a/stack-core.el +++ b/stack-core.el @@ -273,5 +273,60 @@ context of `stack-cache-directory'." (stack-cache-get-file-name cache)) data) +(defun stack--time-since (time) + "Convert the time interval since TIME (in seconds) to a short string." + (concat + (let ((delay (- (time-to-seconds) time))) + (cond ((> 0 delay) (concat "-" (seconds-to-string (- delay)))) + ((= 0 delay) "0s") + (t (let ((sts seconds-to-string) here) + (while (and (car (setq here (pop sts))) + (<= (car here) delay))) + (concat (format "%.0f" (/ delay (car (cddr here)))) (cadr here)))))) + " ago")) + +(defun stack-core--decode-entities (string) + (let* ((plist '(Aacute "Á" aacute "á" Acirc "Â" acirc "â" acute "´" AElig "Æ" aelig "æ" + Agrave "À" agrave "à" alefsym "ℵ" Alpha "Α" alpha "α" amp "&" and "∧" + ang "∠" apos "'" aring "å" Aring "Å" asymp "≈" atilde "ã" Atilde "Ã" + auml "ä" Auml "Ä" bdquo "„" Beta "Β" beta "β" brvbar "¦" bull "•" + cap "∩" ccedil "ç" Ccedil "Ç" cedil "¸" cent "¢" Chi "Χ" chi "χ" + circ "ˆ" clubs "♣" cong "≅" copy "©" crarr "↵" cup "∪" curren "¤" + Dagger "‡" dagger "†" darr "↓" dArr "⇓" deg "°" Delta "Δ" delta "δ" + diams "♦" divide "÷" eacute "é" Eacute "É" ecirc "ê" Ecirc "Ê" egrave "è" + Egrave "È" empty "∅" emsp " " ensp " " Epsilon "Ε" epsilon "ε" equiv "≡" + Eta "Η" eta "η" eth "ð" ETH "Ð" euml "ë" Euml "Ë" euro "€" + exist "∃" fnof "ƒ" forall "∀" frac12 "½" frac14 "¼" frac34 "¾" frasl "⁄" + Gamma "Γ" gamma "γ" ge "≥" gt ">" harr "↔" hArr "⇔" hearts "♥" + hellip "…" iacute "í" Iacute "Í" icirc "î" Icirc "Î" iexcl "¡" igrave "ì" + Igrave "Ì" image "ℑ" infin "∞" int "∫" Iota "Ι" iota "ι" iquest "¿" + isin "∈" iuml "ï" Iuml "Ï" Kappa "Κ" kappa "κ" Lambda "Λ" lambda "λ" + lang "〈" laquo "«" larr "←" lArr "⇐" lceil "⌈" ldquo "“" le "≤" + lfloor "⌊" lowast "∗" loz "◊" lrm "" lsaquo "‹" lsquo "‘" lt "<" + macr "¯" mdash "—" micro "µ" middot "·" minus "−" Mu "Μ" mu "μ" + nabla "∇" nbsp "" ndash "–" ne "≠" ni "∋" not "¬" notin "∉" + nsub "⊄" ntilde "ñ" Ntilde "Ñ" Nu "Ν" nu "ν" oacute "ó" Oacute "Ó" + ocirc "ô" Ocirc "Ô" OElig "Œ" oelig "œ" ograve "ò" Ograve "Ò" oline "‾" + omega "ω" Omega "Ω" Omicron "Ο" omicron "ο" oplus "⊕" or "∨" ordf "ª" + ordm "º" oslash "ø" Oslash "Ø" otilde "õ" Otilde "Õ" otimes "⊗" ouml "ö" + Ouml "Ö" para "¶" part "∂" permil "‰" perp "⊥" Phi "Φ" phi "φ" + Pi "Π" pi "π" piv "ϖ" plusmn "±" pound "£" Prime "″" prime "′" + prod "∏" prop "∝" Psi "Ψ" psi "ψ" quot "\"" radic "√" rang "〉" + raquo "»" rarr "→" rArr "⇒" rceil "⌉" rdquo "”" real "ℜ" reg "®" + rfloor "⌋" Rho "Ρ" rho "ρ" rlm "" rsaquo "›" rsquo "’" sbquo "‚" + scaron "š" Scaron "Š" sdot "⋅" sect "§" shy "" Sigma "Σ" sigma "σ" + sigmaf "ς" sim "∼" spades "♠" sub "⊂" sube "⊆" sum "∑" sup "⊃" + sup1 "¹" sup2 "²" sup3 "³" supe "⊇" szlig "ß" Tau "Τ" tau "τ" + there4 "∴" Theta "Θ" theta "θ" thetasym "ϑ" thinsp " " thorn "þ" THORN "Þ" + tilde "˜" times "×" trade "™" uacute "ú" Uacute "Ú" uarr "↑" uArr "⇑" + ucirc "û" Ucirc "Û" ugrave "ù" Ugrave "Ù" uml "¨" upsih "ϒ" Upsilon "Υ" + upsilon "υ" uuml "ü" Uuml "Ü" weierp "℘" Xi "Ξ" xi "ξ" yacute "ý" + Yacute "Ý" yen "¥" yuml "ÿ" Yuml "Ÿ" Zeta "Ζ" zeta "ζ" zwj "" zwnj "")) + (get-function (lambda (s) (let ((ss (substring s 1 -1))) + (or (plist-get plist (intern ss)) + (format "%c" (string-to-int + (substring ss 1 nil)))))))) + (replace-regexp-in-string "&[^; ]*;" get-function string))) + (provide 'stack-core) ;;; stack-core.el ends here -- cgit v1.2.3 From 798b2d2e594ba2e3e77b697e37d439925aefb282 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Mon, 3 Nov 2014 14:24:39 +0000 Subject: require time-date --- stack-core.el | 1 + 1 file changed, 1 insertion(+) (limited to 'stack-core.el') diff --git a/stack-core.el b/stack-core.el index 68d1e07..a98770a 100644 --- a/stack-core.el +++ b/stack-core.el @@ -33,6 +33,7 @@ ;;; Requirements (require 'json) (require 'url) +(require 'time-date) ;;; Package Logging -- cgit v1.2.3 From d5ae66d93678ebb8a245221dfeda46c293fb3875 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Mon, 3 Nov 2014 14:48:18 +0000 Subject: Use our own seconds-to-string variable. --- stack-core.el | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) (limited to 'stack-core.el') diff --git a/stack-core.el b/stack-core.el index a98770a..a030525 100644 --- a/stack-core.el +++ b/stack-core.el @@ -274,17 +274,28 @@ context of `stack-cache-directory'." (stack-cache-get-file-name cache)) data) +(defvar stack-core--seconds-to-string + '((1 "ms" 0.001) + (100 "s" 1) + (6000 "m" 60.0) + (108000 "h" 3600.0) + (34560000 "d" 86400.0) + (nil "y" 31557600.0)) + "Auxiliary variable used by `stack--time-since'.") + (defun stack--time-since (time) "Convert the time interval since TIME (in seconds) to a short string." - (concat - (let ((delay (- (time-to-seconds) time))) - (cond ((> 0 delay) (concat "-" (seconds-to-string (- delay)))) - ((= 0 delay) "0s") - (t (let ((sts seconds-to-string) here) - (while (and (car (setq here (pop sts))) - (<= (car here) delay))) - (concat (format "%.0f" (/ delay (car (cddr here)))) (cadr here)))))) - " ago")) + (let ((delay (- (time-to-seconds) time))) + (concat + (if (> 0 delay) "-" "") + (if (= 0 delay) "0s" + (setq delay (abs delay)) + (let ((sts stack-core--seconds-to-string) here) + (while (and (car (setq here (pop sts))) + (<= (car here) delay))) + (concat (format "%.0f" (/ delay (car (cddr here)))) + (cadr here)))) + " ago"))) (defun stack-core--decode-entities (string) (let* ((plist '(Aacute "Á" aacute "á" Acirc "Â" acirc "â" acute "´" AElig "Æ" aelig "æ" -- cgit v1.2.3 From e8e830e91941559b34818dcf04193e956ff8affa Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Tue, 4 Nov 2014 08:49:05 +0000 Subject: Make stack-core--seconds-to-string more descriptive. --- stack-core.el | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'stack-core.el') diff --git a/stack-core.el b/stack-core.el index a030525..7072fd8 100644 --- a/stack-core.el +++ b/stack-core.el @@ -275,12 +275,14 @@ context of `stack-cache-directory'." data) (defvar stack-core--seconds-to-string - '((1 "ms" 0.001) - (100 "s" 1) - (6000 "m" 60.0) - (108000 "h" 3600.0) - (34560000 "d" 86400.0) - (nil "y" 31557600.0)) + ;; (LIMIT NAME VALUE) + ;; We use an entry if the number of seconds in question is less than + ;; LIMIT, but more than the previous entry's LIMIT. + '((100 "s" 1) + (6000 "m" 60.0) + (108000 "h" 3600.0) + (34560000 "d" 86400.0) + (nil "y" 31557600.0)) "Auxiliary variable used by `stack--time-since'.") (defun stack--time-since (time) -- cgit v1.2.3 From a9e7cd8a5bbf4f01375879cc30d756a4cc678f70 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Tue, 4 Nov 2014 08:49:15 +0000 Subject: Make entities plist into a variable. --- stack-core.el | 78 ++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 42 insertions(+), 36 deletions(-) (limited to 'stack-core.el') diff --git a/stack-core.el b/stack-core.el index 7072fd8..df2c8f2 100644 --- a/stack-core.el +++ b/stack-core.el @@ -299,43 +299,49 @@ context of `stack-cache-directory'." (cadr here)))) " ago"))) +(defcustom stack-core-html-entities-plist + '(Aacute "Á" aacute "á" Acirc "Â" acirc "â" acute "´" AElig "Æ" aelig "æ" + Agrave "À" agrave "à" alefsym "ℵ" Alpha "Α" alpha "α" amp "&" and "∧" + ang "∠" apos "'" aring "å" Aring "Å" asymp "≈" atilde "ã" Atilde "Ã" + auml "ä" Auml "Ä" bdquo "„" Beta "Β" beta "β" brvbar "¦" bull "•" + cap "∩" ccedil "ç" Ccedil "Ç" cedil "¸" cent "¢" Chi "Χ" chi "χ" + circ "ˆ" clubs "♣" cong "≅" copy "©" crarr "↵" cup "∪" curren "¤" + Dagger "‡" dagger "†" darr "↓" dArr "⇓" deg "°" Delta "Δ" delta "δ" + diams "♦" divide "÷" eacute "é" Eacute "É" ecirc "ê" Ecirc "Ê" egrave "è" + Egrave "È" empty "∅" emsp " " ensp " " Epsilon "Ε" epsilon "ε" equiv "≡" + Eta "Η" eta "η" eth "ð" ETH "Ð" euml "ë" Euml "Ë" euro "€" + exist "∃" fnof "ƒ" forall "∀" frac12 "½" frac14 "¼" frac34 "¾" frasl "⁄" + Gamma "Γ" gamma "γ" ge "≥" gt ">" harr "↔" hArr "⇔" hearts "♥" + hellip "…" iacute "í" Iacute "Í" icirc "î" Icirc "Î" iexcl "¡" igrave "ì" + Igrave "Ì" image "ℑ" infin "∞" int "∫" Iota "Ι" iota "ι" iquest "¿" + isin "∈" iuml "ï" Iuml "Ï" Kappa "Κ" kappa "κ" Lambda "Λ" lambda "λ" + lang "〈" laquo "«" larr "←" lArr "⇐" lceil "⌈" ldquo "“" le "≤" + lfloor "⌊" lowast "∗" loz "◊" lrm "" lsaquo "‹" lsquo "‘" lt "<" + macr "¯" mdash "—" micro "µ" middot "·" minus "−" Mu "Μ" mu "μ" + nabla "∇" nbsp "" ndash "–" ne "≠" ni "∋" not "¬" notin "∉" + nsub "⊄" ntilde "ñ" Ntilde "Ñ" Nu "Ν" nu "ν" oacute "ó" Oacute "Ó" + ocirc "ô" Ocirc "Ô" OElig "Œ" oelig "œ" ograve "ò" Ograve "Ò" oline "‾" + omega "ω" Omega "Ω" Omicron "Ο" omicron "ο" oplus "⊕" or "∨" ordf "ª" + ordm "º" oslash "ø" Oslash "Ø" otilde "õ" Otilde "Õ" otimes "⊗" ouml "ö" + Ouml "Ö" para "¶" part "∂" permil "‰" perp "⊥" Phi "Φ" phi "φ" + Pi "Π" pi "π" piv "ϖ" plusmn "±" pound "£" Prime "″" prime "′" + prod "∏" prop "∝" Psi "Ψ" psi "ψ" quot "\"" radic "√" rang "〉" + raquo "»" rarr "→" rArr "⇒" rceil "⌉" rdquo "”" real "ℜ" reg "®" + rfloor "⌋" Rho "Ρ" rho "ρ" rlm "" rsaquo "›" rsquo "’" sbquo "‚" + scaron "š" Scaron "Š" sdot "⋅" sect "§" shy "" Sigma "Σ" sigma "σ" + sigmaf "ς" sim "∼" spades "♠" sub "⊂" sube "⊆" sum "∑" sup "⊃" + sup1 "¹" sup2 "²" sup3 "³" supe "⊇" szlig "ß" Tau "Τ" tau "τ" + there4 "∴" Theta "Θ" theta "θ" thetasym "ϑ" thinsp " " thorn "þ" THORN "Þ" + tilde "˜" times "×" trade "™" uacute "ú" Uacute "Ú" uarr "↑" uArr "⇑" + ucirc "û" Ucirc "Û" ugrave "ù" Ugrave "Ù" uml "¨" upsih "ϒ" Upsilon "Υ" + upsilon "υ" uuml "ü" Uuml "Ü" weierp "℘" Xi "Ξ" xi "ξ" yacute "ý" + Yacute "Ý" yen "¥" yuml "ÿ" Yuml "Ÿ" Zeta "Ζ" zeta "ζ" zwj "" zwnj "") + "Plist of html entities to replace when displaying question titles and other text." + :type '(repeat (choice symbol string)) + :group 'stack-core) + (defun stack-core--decode-entities (string) - (let* ((plist '(Aacute "Á" aacute "á" Acirc "Â" acirc "â" acute "´" AElig "Æ" aelig "æ" - Agrave "À" agrave "à" alefsym "ℵ" Alpha "Α" alpha "α" amp "&" and "∧" - ang "∠" apos "'" aring "å" Aring "Å" asymp "≈" atilde "ã" Atilde "Ã" - auml "ä" Auml "Ä" bdquo "„" Beta "Β" beta "β" brvbar "¦" bull "•" - cap "∩" ccedil "ç" Ccedil "Ç" cedil "¸" cent "¢" Chi "Χ" chi "χ" - circ "ˆ" clubs "♣" cong "≅" copy "©" crarr "↵" cup "∪" curren "¤" - Dagger "‡" dagger "†" darr "↓" dArr "⇓" deg "°" Delta "Δ" delta "δ" - diams "♦" divide "÷" eacute "é" Eacute "É" ecirc "ê" Ecirc "Ê" egrave "è" - Egrave "È" empty "∅" emsp " " ensp " " Epsilon "Ε" epsilon "ε" equiv "≡" - Eta "Η" eta "η" eth "ð" ETH "Ð" euml "ë" Euml "Ë" euro "€" - exist "∃" fnof "ƒ" forall "∀" frac12 "½" frac14 "¼" frac34 "¾" frasl "⁄" - Gamma "Γ" gamma "γ" ge "≥" gt ">" harr "↔" hArr "⇔" hearts "♥" - hellip "…" iacute "í" Iacute "Í" icirc "î" Icirc "Î" iexcl "¡" igrave "ì" - Igrave "Ì" image "ℑ" infin "∞" int "∫" Iota "Ι" iota "ι" iquest "¿" - isin "∈" iuml "ï" Iuml "Ï" Kappa "Κ" kappa "κ" Lambda "Λ" lambda "λ" - lang "〈" laquo "«" larr "←" lArr "⇐" lceil "⌈" ldquo "“" le "≤" - lfloor "⌊" lowast "∗" loz "◊" lrm "" lsaquo "‹" lsquo "‘" lt "<" - macr "¯" mdash "—" micro "µ" middot "·" minus "−" Mu "Μ" mu "μ" - nabla "∇" nbsp "" ndash "–" ne "≠" ni "∋" not "¬" notin "∉" - nsub "⊄" ntilde "ñ" Ntilde "Ñ" Nu "Ν" nu "ν" oacute "ó" Oacute "Ó" - ocirc "ô" Ocirc "Ô" OElig "Œ" oelig "œ" ograve "ò" Ograve "Ò" oline "‾" - omega "ω" Omega "Ω" Omicron "Ο" omicron "ο" oplus "⊕" or "∨" ordf "ª" - ordm "º" oslash "ø" Oslash "Ø" otilde "õ" Otilde "Õ" otimes "⊗" ouml "ö" - Ouml "Ö" para "¶" part "∂" permil "‰" perp "⊥" Phi "Φ" phi "φ" - Pi "Π" pi "π" piv "ϖ" plusmn "±" pound "£" Prime "″" prime "′" - prod "∏" prop "∝" Psi "Ψ" psi "ψ" quot "\"" radic "√" rang "〉" - raquo "»" rarr "→" rArr "⇒" rceil "⌉" rdquo "”" real "ℜ" reg "®" - rfloor "⌋" Rho "Ρ" rho "ρ" rlm "" rsaquo "›" rsquo "’" sbquo "‚" - scaron "š" Scaron "Š" sdot "⋅" sect "§" shy "" Sigma "Σ" sigma "σ" - sigmaf "ς" sim "∼" spades "♠" sub "⊂" sube "⊆" sum "∑" sup "⊃" - sup1 "¹" sup2 "²" sup3 "³" supe "⊇" szlig "ß" Tau "Τ" tau "τ" - there4 "∴" Theta "Θ" theta "θ" thetasym "ϑ" thinsp " " thorn "þ" THORN "Þ" - tilde "˜" times "×" trade "™" uacute "ú" Uacute "Ú" uarr "↑" uArr "⇑" - ucirc "û" Ucirc "Û" ugrave "ù" Ugrave "Ù" uml "¨" upsih "ϒ" Upsilon "Υ" - upsilon "υ" uuml "ü" Uuml "Ü" weierp "℘" Xi "Ξ" xi "ξ" yacute "ý" - Yacute "Ý" yen "¥" yuml "ÿ" Yuml "Ÿ" Zeta "Ζ" zeta "ζ" zwj "" zwnj "")) + (let* ((plist stack-core-html-entities-plist) (get-function (lambda (s) (let ((ss (substring s 1 -1))) (or (plist-get plist (intern ss)) (format "%c" (string-to-int -- cgit v1.2.3 From 58bd8f86c5991ad2469da9154865519e06c208d1 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Tue, 4 Nov 2014 08:52:25 +0000 Subject: Trim unnecessary arg --- stack-core.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'stack-core.el') diff --git a/stack-core.el b/stack-core.el index df2c8f2..6830583 100644 --- a/stack-core.el +++ b/stack-core.el @@ -345,7 +345,7 @@ context of `stack-cache-directory'." (get-function (lambda (s) (let ((ss (substring s 1 -1))) (or (plist-get plist (intern ss)) (format "%c" (string-to-int - (substring ss 1 nil)))))))) + (substring ss 1)))))))) (replace-regexp-in-string "&[^; ]*;" get-function string))) (provide 'stack-core) -- cgit v1.2.3 From 4aab65154b3c8f4d58f9e874d8a93eb288432120 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Tue, 4 Nov 2014 08:53:01 +0000 Subject: Move " ago" out of stack--time-since --- stack-core.el | 3 +-- stack-question-list.el | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) (limited to 'stack-core.el') diff --git a/stack-core.el b/stack-core.el index 6830583..5a90cb3 100644 --- a/stack-core.el +++ b/stack-core.el @@ -296,8 +296,7 @@ context of `stack-cache-directory'." (while (and (car (setq here (pop sts))) (<= (car here) delay))) (concat (format "%.0f" (/ delay (car (cddr here)))) - (cadr here)))) - " ago"))) + (cadr here))))))) (defcustom stack-core-html-entities-plist '(Aacute "Á" aacute "á" Acirc "Â" acirc "â" acute "´" AElig "Æ" aelig "æ" diff --git a/stack-question-list.el b/stack-question-list.el index 8f3f722..1a19b44 100644 --- a/stack-question-list.el +++ b/stack-question-list.el @@ -165,7 +165,7 @@ If REDISPLAY is non-nil, also call `tabulated-list-print'." 'stack-question-list-read-question 'stack-question-list-unread-question)) (propertize " " 'display "\n ") - (propertize (stack--time-since (ca 'last_activity_date)) + (propertize (concat (stack--time-since (ca 'last_activity_date)) " ago") 'face 'stack-question-list-date) (propertize (concat " [" (mapconcat #'identity (ca 'tags) "] [") "]") 'face 'stack-question-list-tags) -- cgit v1.2.3 From b26e8bebb1121954e090f350cf8b17e832daccef Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Tue, 4 Nov 2014 09:04:39 +0000 Subject: Descriptive comments to stack-core--decode-entities --- stack-core.el | 2 ++ 1 file changed, 2 insertions(+) (limited to 'stack-core.el') diff --git a/stack-core.el b/stack-core.el index 5a90cb3..c78c316 100644 --- a/stack-core.el +++ b/stack-core.el @@ -342,7 +342,9 @@ context of `stack-cache-directory'." (defun stack-core--decode-entities (string) (let* ((plist stack-core-html-entities-plist) (get-function (lambda (s) (let ((ss (substring s 1 -1))) + ;; Handle things like " (or (plist-get plist (intern ss)) + ;; Handle things like ' (format "%c" (string-to-int (substring ss 1)))))))) (replace-regexp-in-string "&[^; ]*;" get-function string))) -- cgit v1.2.3