aboutsummaryrefslogtreecommitdiff
path: root/sx-question-mode.el
diff options
context:
space:
mode:
authorSean Allred <code@seanallred.com>2014-11-27 13:02:42 -0500
committerSean Allred <code@seanallred.com>2014-11-27 13:02:42 -0500
commitde0f242552610ed2dcca537bd9843c4d798bfc8f (patch)
tree28ac46f781632fe8cc3a463d349bb714a37b6e71 /sx-question-mode.el
parent686ff49e2f9ec57e7c5a712f7e934fa9f7099b0d (diff)
parent49b85115b488bd88d706d1630764f25c4e4312a2 (diff)
Merge pull request #105 from vermiculus/issue-97
Don't fill link labels or headers
Diffstat (limited to 'sx-question-mode.el')
-rw-r--r--sx-question-mode.el27
1 files changed, 24 insertions, 3 deletions
diff --git a/sx-question-mode.el b/sx-question-mode.el
index b2f4604..f3ef8e5 100644
--- a/sx-question-mode.el
+++ b/sx-question-mode.el
@@ -385,12 +385,34 @@ where `value' is given `face' as its face.
(goto-char (point-min))
(while (null (eobp))
;; Don't fill pre blocks.
- (unless (sx-question-mode--move-over-pre)
+ (unless (sx-question-mode--dont-fill-here)
(skip-chars-forward "\r\n[:blank:]")
(fill-paragraph)
(forward-paragraph)))
(buffer-string)))
+(defvar sx-question-mode--reference-regexp
+ (rx line-start (0+ blank) "[%s]:" (0+ blank)
+ (group-n 1 (1+ (not blank))))
+ "Regexp used to find the url of labeled links.
+E.g.:
+ [1]: https://...")
+
+(defun sx-question-mode--dont-fill-here ()
+ "If text shouldn't be filled here, return t and skip over it."
+ (or (sx-question-mode--move-over-pre)
+ ;; Skip headers and references
+ (let ((pos (point)))
+ (skip-chars-forward "\r\n[:blank:]")
+ (goto-char (line-beginning-position))
+ (if (or (looking-at-p (format sx-question-mode--reference-regexp ".+"))
+ (looking-at-p "^#"))
+ ;; Returns non-nil
+ (forward-paragraph)
+ ;; Go back and return nil
+ (goto-char pos)
+ nil))))
+
(defvar sx-question-mode--link-regexp
;; Done at compile time.
(rx "[" (group-n 1 (1+ (not (any "]")))) "]"
@@ -452,8 +474,7 @@ If ID is nil, use FALLBACK-ID instead."
(save-match-data
(goto-char (point-min))
(when (search-forward-regexp
- (format (rx line-start (0+ blank) "[%s]:" (0+ blank)
- (group-n 1 (1+ (not blank))))
+ (format sx-question-mode--reference-regexp
(or id fallback-id))
nil t)
(match-string-no-properties 1)))))