From 952692774707d7730eb1501d6e62cedf42572d77 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Wed, 3 Dec 2014 20:53:02 +0000 Subject: Highlight names with .-_ --- sx-question-print.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sx-question-print.el b/sx-question-print.el index eb79a7a..87255d7 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+ (or (syntax word) (syntax symbol) (any ".-_"))))) symbol-end) 1 font-lock-builtin-face))) ;; Everything. -- cgit v1.2.3 From 36e2c98f7c4b325ec5a4108b907f14ca77685fea Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Wed, 3 Dec 2014 23:51:15 +0000 Subject: Take any non-space --- sx-question-print.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sx-question-print.el b/sx-question-print.el index 87255d7..11a3e11 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) (any ".-_"))))) + (group-n 1 (and "@" (1+ (not space)))) symbol-end) 1 font-lock-builtin-face))) ;; Everything. -- cgit v1.2.3 From 847e0a0b1c177d311f54905115bc77aa73c0adf0 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Thu, 4 Dec 2014 13:39:17 +0000 Subject: Understand non-ascii when handling @name --- sx.el | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/sx.el b/sx.el index 431643c..1c0ae9f 100644 --- a/sx.el +++ b/sx.el @@ -251,14 +251,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 -- cgit v1.2.3 From 2651764450b76bd6573cfea2b98f54beeae4f0f1 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Thu, 4 Dec 2014 13:39:37 +0000 Subject: Define test for sx--user-@name Source of the replacements: http://stackapps.com/a/5022/3776 --- test/tests.el | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/tests.el b/test/tests.el index 75238fe..56a5501 100644 --- a/test/tests.el +++ b/test/tests.el @@ -133,3 +133,14 @@ (macroexpand '(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"))) -- cgit v1.2.3