From 69b90717fb304958be8aabe6c3d02199293b27b4 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sat, 29 Nov 2014 20:02:14 +0000 Subject: New sx--shorten-url function in sx.el --- sx.el | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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 -- cgit v1.2.3