aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sx-button.el20
-rw-r--r--sx-question-print.el40
2 files changed, 52 insertions, 8 deletions
diff --git a/sx-button.el b/sx-button.el
index afc1cf7..af3c7e3 100644
--- a/sx-button.el
+++ b/sx-button.el
@@ -50,6 +50,21 @@ This is usually a link's URL, or the content of a code block."
(point) 'sx-button-copy-type)
content)))))
+(defun sx-button-edit-this (text-or-marker)
+ "Open a temp buffer populated with the string TEXT-OR-MARKER.
+When given a marker (or interactively), use the 'sx-button-copy
+text-property under the marker. This is usually the content of a
+code-block."
+ (interactive (list (point-marker)))
+ ;; Buttons receive markers.
+ (when (markerp text-or-marker)
+ (unless (setq text-or-marker
+ (get-text-property text-or-marker 'sx-button-copy))
+ (sx-message "Nothing of interest here.")))
+ (with-current-buffer (pop-to-buffer (generate-new-buffer
+ "*sx temp buffer*"))
+ (insert text-or-marker)))
+
(defun sx-button-follow-link (&optional pos)
"Follow link at POS. If POS is nil, use `point'."
(interactive)
@@ -89,6 +104,11 @@ This is usually a link's URL, or the content of a code block."
'sx-button-copy-type "Share Link"
:supertype 'sx-button)
+(define-button-type 'sx-question-mode-code-block
+ 'action #'sx-button-edit-this
+ 'face nil
+ :supertype 'sx-button)
+
(define-button-type 'sx-button-link
'action #'sx-button-follow-link
:supertype 'sx-button)
diff --git a/sx-question-print.el b/sx-question-print.el
index ebdba56..fb4d2e1 100644
--- a/sx-question-print.el
+++ b/sx-question-print.el
@@ -352,7 +352,7 @@ E.g.:
(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)
+ (or (sx-question-mode--skip-and-fontify-pre)
;; Skip headers and references
(let ((pos (point)))
(skip-chars-forward "\r\n[:blank:]")
@@ -399,13 +399,37 @@ URL is used as 'help-echo and 'url properties."
(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."
-
-(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))))
+ (save-excursion
+ (save-match-data
+ (goto-char (point-min))
+ (when (search-forward-regexp
+ (format sx-question-mode--reference-regexp
+ (or id fallback-id))
+ nil t)
+ (match-string-no-properties 1)))))
+
+(defun sx-question-mode--skip-and-fontify-pre ()
+ "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 text)
+ (when (markdown-match-pre-blocks
+ (save-excursion
+ (skip-chars-forward "\r\n[:blank:]")
+ (setq beg (point))))
+ (setq end (point))
+ (setq text
+ (sx--unindent-text
+ (buffer-substring
+ (save-excursion
+ (goto-char beg)
+ (line-beginning-position))
+ end)))
+ (make-text-button
+ beg end
+ 'face 'markdown-pre-face
+ 'sx-button-copy text
+ :type 'sx-question-mode-code-block))))
(provide 'sx-question-print)
;;; sx-question-print.el ends here