From 58c3a9c3a85920dfcaccea63b347f98b945e409f Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sat, 29 Nov 2014 22:05:00 +0000 Subject: Add sx--unindent-text function Used to extract the code contained in code-blocks --- sx.el | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'sx.el') 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 -- cgit v1.2.3