aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArtur Malabarba <bruce.connor.am@gmail.com>2014-11-29 22:05:00 +0000
committerArtur Malabarba <bruce.connor.am@gmail.com>2014-11-29 22:05:00 +0000
commit58c3a9c3a85920dfcaccea63b347f98b945e409f (patch)
tree07c77b43cd222232f0fb0c62e0fe08a50f489d5a
parent7320355e0c746e31aca91051758cc15499624b0c (diff)
Add sx--unindent-text function
Used to extract the code contained in code-blocks
-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