diff options
-rw-r--r-- | sx-load.el | 1 | ||||
-rw-r--r-- | sx-question-list.el | 9 | ||||
-rw-r--r-- | sx-question-mode.el | 5 | ||||
-rw-r--r-- | sx-question-print.el | 2 | ||||
-rw-r--r-- | sx.el | 38 | ||||
-rw-r--r-- | test/tests.el | 11 |
6 files changed, 59 insertions, 7 deletions
@@ -34,7 +34,6 @@ sx-interaction sx-method sx-networks - sx.org sx-question sx-question-list sx-question-mode diff --git a/sx-question-list.el b/sx-question-list.el index c5c32d9..788fc2f 100644 --- a/sx-question-list.el +++ b/sx-question-list.el @@ -286,7 +286,11 @@ into consideration. (mapc (lambda (x) (define-key sx-question-list-mode-map (car x) (cadr x))) - '(("n" sx-question-list-next) + '( + ;; S-down and S-up would collide with `windmove'. + ([down] sx-question-list-view-next) + ([up] sx-question-list-view-previous) + ("n" sx-question-list-next) ("p" sx-question-list-previous) ("j" sx-question-list-view-next) ("k" sx-question-list-view-previous) @@ -303,7 +307,8 @@ into consideration. ("d" sx-toggle-downvote) ("h" sx-question-list-hide) ("m" sx-question-list-mark-read) - ([?\r] sx-display-question))) + ([?\r] sx-display-question) + )) (defun sx-question-list-hide (data) "Hide question under point. diff --git a/sx-question-mode.el b/sx-question-mode.el index ccd9433..19d7d16 100644 --- a/sx-question-mode.el +++ b/sx-question-mode.el @@ -193,7 +193,10 @@ Letters do not insert themselves; instead, they are commands. (mapc (lambda (x) (define-key sx-question-mode-map (car x) (cadr x))) - `(("n" sx-question-mode-next-section) + `( + ([down] sx-question-mode-next-section) + ([up] sx-question-mode-previous-section) + ("n" sx-question-mode-next-section) ("p" sx-question-mode-previous-section) ("g" sx-question-mode-refresh) ("c" sx-comment) diff --git a/sx-question-print.el b/sx-question-print.el index 653ebab..dc853ba 100644 --- a/sx-question-print.el +++ b/sx-question-print.el @@ -350,7 +350,7 @@ E.g.: (font-lock-add-keywords ;; Highlight usernames. nil `((,(rx (or blank line-start) - (group-n 1 (and "@" (1+ (or (syntax word) (syntax symbol))))) + (group-n 1 (and "@" (1+ (not space)))) symbol-end) 1 font-lock-builtin-face))) ;; Everything. @@ -236,14 +236,48 @@ Return the result of BODY." (push ov sx--overlays)) result)) +(defvar sx--ascii-replacement-list + '(("[:space:]" . "") + ("àåáâäãåą" . "a") + ("èéêëę" . "e") + ("ìíîïı" . "i") + ("òóôõöøőð" . "o") + ("ùúûüŭů" . "u") + ("çćčĉ" . "c") + ("żźž" . "z") + ("śşšŝ" . "s") + ("ñń" . "n") + ("ýÿ" . "y") + ("ğĝ" . "g") + ("ř" . "r") + ("ł" . "l") + ("đ" . "d") + ("ß" . "ss") + ("Þ" . "th") + ("ĥ" . "h") + ("ĵ" . "j") + ("^[:ascii:]" . "")) + "List of replacements to use for non-ascii characters +Used to convert user names into @mentions.") + (defun sx--user-@name (user) "Get the `display_name' of USER prepended with @. In order to correctly @mention the user, all whitespace is removed from the display name before it is returned." (sx-assoc-let user (when (stringp .display_name) - (concat "@" (replace-regexp-in-string - "[[:space:]]" "" .display_name))))) + (concat "@" (sx--recursive-replace + sx--ascii-replacement-list .display_name))))) + +(defun sx--recursive-replace (alist string) + "Replace each car of ALIST with its cdr in STRING." + (if alist + (sx--recursive-replace + (cdr alist) + (let ((kar (car alist))) + (replace-regexp-in-string + (format "[%s]" (car kar)) (cdr kar) string))) + string)) ;;; Assoc-let diff --git a/test/tests.el b/test/tests.el index 43531b4..b997c6e 100644 --- a/test/tests.el +++ b/test/tests.el @@ -134,6 +134,17 @@ '(sx-assoc-let data (cons .test-one .test-two)))))) +(ert-deftest sx--user-@name () + "Tests macro expansion for `sx-assoc-let'" + (should + (string= + (sx--user-@name '((display_name . "ĥÞßđłřğĝýÿñńśşšŝżźžçćčĉùúûüŭůòóôõöøőðìíîïıèéêëęàåáâäãåąĵ★"))) + "@hTHssdlrggyynnsssszzzccccuuuuuuooooooooiiiiieeeeeaaaaaaaaj")) + (should + (string= + (sx--user-@name '((display_name . "ĤÞßĐŁŘĞĜÝŸÑŃŚŞŠŜŻŹŽÇĆČĈÙÚÛÜŬŮÒÓÔÕÖØŐÐÌÍÎÏıÈÉÊËĘÀÅÁÂÄÃÅĄĴ"))) + "@HTHssDLRGGYYNNSSSSZZZCCCCUUUUUUOOOOOOOOIIIIiEEEEEAAAAAAAAJ"))) + (ert-deftest thing-as-string () "Tests `sx--thing-as-string'" (should |