aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArtur Malabarba <bruce.connor.am@gmail.com>2014-11-26 12:51:51 +0000
committerArtur Malabarba <bruce.connor.am@gmail.com>2014-11-26 12:52:13 +0000
commit8f4caddf383196c23e8131c4baa0b42d5e06e7dd (patch)
tree6708e14ac03c360447d2a0295c57140bc8b30a68
parente9f03bfb583d514ff9c930c551f8e0760f29a598 (diff)
Don't fill link labels or headers
Fixes #97
-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 70b8866..36d0090 100644
--- a/sx-question-mode.el
+++ b/sx-question-mode.el
@@ -385,12 +385,27 @@ 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)))
+(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 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 "]")))) "]"
@@ -445,6 +460,13 @@ URL is used as 'help-echo and 'url properties."
(or (get-text-property (or pos (point)) 'url)
(user-error "No url under point: %s" (or pos (point))))))
+(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-find-reference (id &optional fallback-id)
"Find url identified by reference ID in current buffer.
If ID is nil, use FALLBACK-ID instead."
@@ -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)))))