aboutsummaryrefslogtreecommitdiff
path: root/sx.el
diff options
context:
space:
mode:
authorSean Allred <code@seanallred.com>2014-12-03 17:55:52 -0500
committerSean Allred <code@seanallred.com>2014-12-03 17:55:52 -0500
commit67b60ea558f0386a1ea3dadcf3a9c4d22d398620 (patch)
tree8695418c51779333101b45aad180e6979a6e2ad0 /sx.el
parent48314a1227cca288731a48a7f07558654a953d9d (diff)
parent90d3a20ee3ac0a98e8d26cd9cf203e113acdbdce (diff)
Merge pull request #129 from vermiculus/answering
Implement asking, answering, and editing.
Diffstat (limited to 'sx.el')
-rw-r--r--sx.el18
1 files changed, 12 insertions, 6 deletions
diff --git a/sx.el b/sx.el
index f1d3634..431643c 100644
--- a/sx.el
+++ b/sx.el
@@ -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)))
@@ -262,11 +269,10 @@ with a `link' property).
DATA can also be the link itself."
(let ((link (if (stringp data) data
(cdr (assoc 'link data)))))
- (unless (stringp link)
- (error "Data has no link property"))
- (replace-regexp-in-string
- "^https?://\\(?:\\(?1:[^/]+\\)\\.stackexchange\\|\\(?2:[^/]+\\)\\)\\.[^.]+/.*$"
- "\\1\\2" link)))
+ (when (stringp link)
+ (replace-regexp-in-string
+ "^https?://\\(?:\\(?1:[^/]+\\)\\.stackexchange\\|\\(?2:[^/]+\\)\\)\\.[^.]+/.*$"
+ "\\1\\2" link))))
(defun sx--deep-dot-search (data)
"Find symbols somewhere inside DATA which start with a `.'.