aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Allred <code@seanallred.com>2014-12-18 15:27:03 -0500
committerSean Allred <code@seanallred.com>2014-12-18 15:27:03 -0500
commitc1face27a680c9b525af94583b6e5e467116bf2f (patch)
tree10292d3441b074d80d89d5b76cd17df33ca90f71
parent78cac577fc93a6406a7cbfa2b86d33529f4bd6a7 (diff)
parent28bb9c2d582f301bb328c2ca84ad97dcbed87abb (diff)
Merge pull request #160 from vermiculus/better-modes
Better major-modes
-rw-r--r--sx-babel.el24
-rw-r--r--sx-button.el13
-rw-r--r--sx-question-print.el2
3 files changed, 24 insertions, 15 deletions
diff --git a/sx-babel.el b/sx-babel.el
index 5544642..b4ff306 100644
--- a/sx-babel.el
+++ b/sx-babel.el
@@ -56,11 +56,16 @@ on a match.")
(insert text)
(setq indent (sx-babel--unindent-buffer))
(goto-char (point-min))
- (make-text-button
- (point-min) (point-max)
- 'sx-button-copy (buffer-string)
- :type 'sx-question-mode-code-block)
- (sx-babel--determine-and-activate-major-mode)
+ (let ((mode (sx-babel--determine-major-mode)))
+ (make-text-button
+ (point-min) (point-max)
+ 'sx-button-copy (buffer-string)
+ ;; We store the mode here so it can be used if the user wants
+ ;; to edit the code block.
+ 'sx-mode mode
+ :type 'sx-question-mode-code-block)
+ (when mode
+ (delay-mode-hooks (funcall mode))))
(font-lock-fontify-region (point-min) (point-max))
(goto-char (point-min))
(let ((space (make-string indent ?\s)))
@@ -72,17 +77,18 @@ on a match.")
(delete-region beg end)
(insert text)))
-(defun sx-babel--determine-and-activate-major-mode ()
- "Activate the major-mode most suitable for the current buffer."
+(defun sx-babel--determine-major-mode ()
+ "Return the major-mode most suitable for the current buffer."
(let ((alist sx-babel-major-mode-alist)
- cell)
+ cell out)
(while (setq cell (pop alist))
(goto-char (point-min))
(skip-chars-forward "\r\n[:blank:]")
(let ((kar (car cell)))
(when (if (stringp kar) (looking-at kar) (funcall kar))
(setq alist nil)
- (funcall (cadr cell)))))))
+ (setq out (cadr cell)))))
+ out))
(defun sx-babel--unindent-buffer ()
"Remove absolute indentation in current buffer.
diff --git a/sx-button.el b/sx-button.el
index 283fe0d..f166164 100644
--- a/sx-button.el
+++ b/sx-button.el
@@ -77,20 +77,23 @@ 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.
+(defun sx-button-edit-this (text-or-marker &optional major-mode)
+ "Open a temp buffer populated with the string TEXT-OR-MARKER using MAJOR-MODE.
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."
+and the 'sx-mode text-properties under the marker. These are
+usually part of a code-block."
(interactive (list (point-marker)))
;; Buttons receive markers.
(when (markerp text-or-marker)
+ (setq major-mode (get-text-property text-or-marker 'sx-mode))
(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)))
+ (insert text-or-marker)
+ (when major-mode
+ (funcall major-mode))))
(defun sx-button-follow-link (&optional pos)
"Follow link at POS. If POS is nil, use `point'."
diff --git a/sx-question-print.el b/sx-question-print.el
index 0a6c3a8..9f37b10 100644
--- a/sx-question-print.el
+++ b/sx-question-print.el
@@ -344,7 +344,7 @@ E.g.:
"Return TEXT filled according to `markdown-mode'."
(with-temp-buffer
(insert text)
- (markdown-mode)
+ (delay-mode-hooks (markdown-mode))
(font-lock-mode -1)
(when sx-question-mode-bullet-appearance
(font-lock-add-keywords ;; Bullet items.