aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArtur Malabarba <bruce.connor.am@gmail.com>2014-11-29 20:02:14 +0000
committerArtur Malabarba <bruce.connor.am@gmail.com>2014-11-29 20:02:14 +0000
commit69b90717fb304958be8aabe6c3d02199293b27b4 (patch)
treecc707dd328a37c89c8394ba8d97cc04d5554f530
parent9a39c5d985423e3675cfcd56cf951bb3ab283147 (diff)
New sx--shorten-url function in sx.el
-rw-r--r--sx.el15
1 files changed, 15 insertions, 0 deletions
diff --git a/sx.el b/sx.el
index 83278d3..10c0baa 100644
--- a/sx.el
+++ b/sx.el
@@ -173,6 +173,21 @@ would yield
cons-cell))))
data))))
+(defun sx--shorten-url (url)
+ "Shorten URL hiding anything other than the domain.
+Paths after the domain are replaced with \"...\".
+Anything before the (sub)domain is removed."
+ (replace-regexp-in-string
+ ;; Remove anything after domain.
+ (rx (group-n 1 (and (1+ (any word ".")) "/"))
+ (1+ anything) string-end)
+ (eval-when-compile
+ (concat "\\1" (if (char-displayable-p ?…) "…" "...")))
+ ;; Remove anything before subdomain.
+ (replace-regexp-in-string
+ (rx string-start (or (and (0+ word) (optional ":") "//")))
+ "" url)))
+
;;; Printing request data
(defvar sx--overlays nil