diff options
-rw-r--r-- | sx-question-mode.el | 43 |
1 files changed, 30 insertions, 13 deletions
diff --git a/sx-question-mode.el b/sx-question-mode.el index 20d3035..4f5116c 100644 --- a/sx-question-mode.el +++ b/sx-question-mode.el @@ -207,12 +207,12 @@ DATA can represent a question or an answer." ;; Questions have title (propertize .title - 'font-lock-face 'sx-question-mode-title + 'face 'sx-question-mode-title 'sx-question-mode--section 1) ;; Answers don't (propertize sx-question-mode-answer-title - 'font-lock-face 'sx-question-mode-title + 'face 'sx-question-mode-title 'sx-question-mode--section 2))) ;; Sections can be hidden with overlays (sx-question-mode--wrap-in-overlay @@ -243,7 +243,7 @@ DATA can represent a question or an answer." (sx-question-mode--wrap-in-overlay '(face sx-question-mode-content-face) (insert "\n" - (sx-question-mode--fill-string + (sx-question-mode--fill-and-fontify .body_markdown) (propertize sx-question-mode-separator 'face 'sx-question-mode-header)))) @@ -253,7 +253,7 @@ DATA can represent a question or an answer." "\n" (propertize sx-question-mode-comments-title - 'font-lock-face 'sx-question-mode-title-comments + 'face 'sx-question-mode-title-comments 'sx-question-mode--section 3)) (sx-question-mode--wrap-in-overlay '(sx-question-mode--section-content t) @@ -262,23 +262,38 @@ DATA can represent a question or an answer." '(face sx-question-mode-content-face) (mapc #'sx-question-mode--print-comment .comments)))))) -(defun sx-question-mode--fill-string (text) +(defun sx-question-mode--fill-and-fontify (text) "Fill TEXT according to `markdown-mode' and return it." (with-temp-buffer (insert text) (markdown-mode) + ;; Highlight usernames. + (font-lock-add-keywords + nil + '(("\\(?: \\|^\\)\\(@\\(?:\\sw\\|\\s_\\)+\\)\\_>" + 1 font-lock-builtin-face))) (goto-char (point-min)) - ;; ;; Do something here - ;; (while (null (eobp)) - ;; (skip-chars-forward "\r\n[:blank:]") - ;; (markdown-pre-region)) + (font-lock-fontify-region (point-min) (point-max)) + ;; Do something here + (while (null (eobp)) + ;; Don't fill pre blocks. + (unless (sx-question-mode--move-over-pre) + (fill-paragraph) + (forward-paragraph))) (buffer-string))) +(defun sx-question-mode--move-over-pre () + "Non-nil if paragraph at point can be filled." + (markdown-match-pre-blocks + (save-excursion + (skip-chars-forward "\r\n[:blank:]") + (point)))) + (defun sx-question-mode--propertized-display-name (author) "Return display_name of AUTHOR with `sx-question-mode-author' face." (sx-assoc-let author (propertize .display_name - 'font-lock-face 'sx-question-mode-author))) + 'face 'sx-question-mode-author))) (defun sx-question-mode--print-comment (data) "Print the comment described by alist DATA." @@ -290,7 +305,7 @@ DATA can represent a question or an answer." (substring ;; We fill with three spaces at the start, so the comment is ;; slightly indented. - (sx-question-mode--fill-string + (sx-question-mode--fill-and-fontify (concat " " .body_markdown)) ;; Then we remove the spaces from the first line, since we'll ;; add the username there anyway. @@ -317,8 +332,8 @@ HEADER is given `sx-question-mode-header' face, and value is given FACE. \(fn header value face [header value face] [header value face] ...)" (while args (insert - (propertize (pop args) 'font-lock-face 'sx-question-mode-header) - (propertize (pop args) 'font-lock-face (pop args))))) + (propertize (pop args) 'face 'sx-question-mode-header) + (propertize (pop args) 'face (pop args))))) ;;; Movement commands @@ -400,6 +415,8 @@ If DIRECTION is negative, move backwards instead." Letters do not insert themselves; instead, they are commands. \\<sx-question-mode> \\{sx-question-mode}" + ;; We call font-lock-region manually. See `sx-question-mode--fill-and-fontify' + (font-lock-mode -1) (remove-hook 'after-change-functions 'markdown-check-change-for-wiki-link t) (remove-hook 'window-configuration-change-hook 'markdown-fontify-buffer-wiki-links t) |