diff options
author | Artur Malabarba <bruce.connor.am@gmail.com> | 2014-11-29 22:05:00 +0000 |
---|---|---|
committer | Artur Malabarba <bruce.connor.am@gmail.com> | 2014-11-29 22:05:00 +0000 |
commit | 58c3a9c3a85920dfcaccea63b347f98b945e409f (patch) | |
tree | 07c77b43cd222232f0fb0c62e0fe08a50f489d5a | |
parent | 7320355e0c746e31aca91051758cc15499624b0c (diff) |
Add sx--unindent-text function
Used to extract the code contained in code-blocks
-rw-r--r-- | sx.el | 21 |
1 files changed, 21 insertions, 0 deletions
@@ -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 |