aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sx-question-print.el2
-rw-r--r--sx.el38
-rw-r--r--test/tests.el11
3 files changed, 48 insertions, 3 deletions
diff --git a/sx-question-print.el b/sx-question-print.el
index 2a0a035..c32c3eb 100644
--- a/sx-question-print.el
+++ b/sx-question-print.el
@@ -352,7 +352,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.
diff --git a/sx.el b/sx.el
index 8e3e5d3..0bacad2 100644
--- a/sx.el
+++ b/sx.el
@@ -264,14 +264,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