aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArtur Malabarba <bruce.connor.am@gmail.com>2014-12-16 20:52:23 -0200
committerArtur Malabarba <bruce.connor.am@gmail.com>2014-12-22 10:46:41 -0200
commite355e9571b749311e7d3fb7fbd54ac5246ec3c25 (patch)
tree2a22423e7c567a283fc8768b6d858a8d170f60a3
parentff7bf723a10352d0a69078e4d0645d078aa143df (diff)
delay-mode-hooks on code blocks
-rw-r--r--sx-babel.el24
1 files changed, 15 insertions, 9 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.