diff options
author | Artur Malabarba <bruce.connor.am@gmail.com> | 2014-12-03 15:24:15 +0000 |
---|---|---|
committer | Artur Malabarba <bruce.connor.am@gmail.com> | 2014-12-03 15:24:15 +0000 |
commit | 7ecd6404ea465c547f3217016c1940f94682fb96 (patch) | |
tree | 54aeff5ff098975244d26d54a1246add1258958b /sx.el | |
parent | 7373bde63cbb066d9aa4f05d0ac04d7ec2781cba (diff) |
Add comments to sx--unindent-text
Diffstat (limited to 'sx.el')
-rw-r--r-- | sx.el | 9 |
1 files changed, 8 insertions, 1 deletions
@@ -189,24 +189,31 @@ Anything before the (sub)domain is removed." "" url))) (defun sx--unindent-text (text) - "Remove indentation from TEXT." + "Remove indentation from TEXT. +Primarily designed to extract the content of markdown code +blocks." (with-temp-buffer (insert text) (goto-char (point-min)) (let (result) + ;; Get indentation of each non-blank line (while (null (eobp)) (skip-chars-forward "[:blank:]") (unless (looking-at "$") (push (current-column) result)) (forward-line 1)) (when result + ;; Build a regexp with the smallest indentation (let ((rx (format "^ \\{0,%s\\}" (apply #'min result)))) (goto-char (point-min)) + ;; Use this regexp to remove that much indentation + ;; throughout the buffer. (while (and (null (eobp)) (search-forward-regexp rx nil 'noerror)) (replace-match "") (forward-line 1))))) + ;; Return the buffer (buffer-string))) |