aboutsummaryrefslogtreecommitdiff
path: root/sx.el
diff options
context:
space:
mode:
Diffstat (limited to 'sx.el')
-rw-r--r--sx.el21
1 files changed, 21 insertions, 0 deletions
diff --git a/sx.el b/sx.el
index 10c0baa..fc58b02 100644
--- a/sx.el
+++ b/sx.el
@@ -188,6 +188,27 @@ Anything before the (sub)domain is removed."
(rx string-start (or (and (0+ word) (optional ":") "//")))
"" url)))
+(defun sx--unindent-text (text)
+ "Remove indentation from TEXT."
+ (with-temp-buffer
+ (insert text)
+ (goto-char (point-min))
+ (let (result)
+ (while (null (eobp))
+ (skip-chars-forward "[:blank:]")
+ (unless (looking-at "$")
+ (push (current-column) result))
+ (forward-line 1))
+ (when result
+ (let ((rx (format "^ \\{0,%s\\}"
+ (apply #'min result))))
+ (goto-char (point-min))
+ (while (and (null (eobp))
+ (search-forward-regexp rx nil 'noerror))
+ (replace-match "")
+ (forward-line 1)))))
+ (buffer-string)))
+
;;; Printing request data
(defvar sx--overlays nil