From a5cb69f2937500e5c035ff6588c1f25a5a611833 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Wed, 17 Dec 2014 13:23:58 -0200 Subject: Hotfix filling code blocks. Fix #163 When filling a paragraph, narrow to region after point, so we don't affect anything behind point (the code block). --- sx-question-print.el | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/sx-question-print.el b/sx-question-print.el index dc853ba..223049a 100644 --- a/sx-question-print.el +++ b/sx-question-print.el @@ -362,10 +362,11 @@ E.g.: (while (null (eobp)) ;; Don't fill pre blocks. (unless (sx-question-mode--dont-fill-here) - (skip-chars-forward "\r\n[:blank:]") - (fill-paragraph) - (forward-paragraph))) - (buffer-string))) + (let ((beg (point))) + (skip-chars-forward "\r\n[:blank:]") + (forward-paragraph) + (fill-region beg (point))))) + (string-trim-right (buffer-string)))) (defun sx-question-mode--dont-fill-here () "If text shouldn't be filled here, return t and skip over it." @@ -429,18 +430,21 @@ If ID is nil, use FALLBACK-ID instead." "If there's a pre block ahead, handle it, skip it and return t. Handling means to turn it into a button and remove erroneous font-locking." - (let (beg end) - (when (markdown-match-pre-blocks + (let ((before (point)) + beg end) + (if (markdown-match-pre-blocks + (save-excursion + (skip-chars-forward "\r\n[:blank:]") + (setq beg (point)))) + (progn + (setq end (point)) + (sx-babel--make-pre-button (save-excursion - (skip-chars-forward "\r\n[:blank:]") - (setq beg (point)))) - (setq end (point)) - (sx-babel--make-pre-button - (save-excursion - (goto-char beg) - (line-beginning-position)) - end)))) + (goto-char beg) + (line-beginning-position)) + end)) + (goto-char before) + nil))) (provide 'sx-question-print) ;;; sx-question-print.el ends here - -- cgit v1.2.3