diff options
author | Artur Malabarba <bruce.connor.am@gmail.com> | 2014-12-16 21:20:31 -0200 |
---|---|---|
committer | Artur Malabarba <bruce.connor.am@gmail.com> | 2014-12-22 10:46:41 -0200 |
commit | 9907fb614e0a687a5823519aaa2ae06df12d3dfe (patch) | |
tree | 939c46efa0ca0e545073dc539f8418b2e51edcc0 | |
parent | ff0ee3f39c8801023a838838bac36836d871f4e7 (diff) |
Make entire code-block a single button
This fixes a bug we had. Hitting TAB on a codeblock would move us to the
next line on the code block, instead of going to another button. Now the
entire code block is a single button, so that is fixed.
-rw-r--r-- | sx-babel.el | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/sx-babel.el b/sx-babel.el index b4ff306..24e56c2 100644 --- a/sx-babel.el +++ b/sx-babel.el @@ -51,31 +51,31 @@ on a match.") (defun sx-babel--make-pre-button (beg end) "Turn the region between BEG and END into a button." (let ((text (buffer-substring-no-properties beg end)) - indent) + indent mode copy) (with-temp-buffer (insert text) (setq indent (sx-babel--unindent-buffer)) (goto-char (point-min)) - (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)))) + (setq mode (sx-babel--determine-major-mode)) + (setq copy (string-trim-right (buffer-string))) + (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))) (while (not (eobp)) - (insert space) + (insert-and-inherit space) (forward-line 1))) (setq text (buffer-string))) (goto-char beg) (delete-region beg end) - (insert text))) + (insert-text-button + text + 'sx-button-copy copy + ;; 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))) (defun sx-babel--determine-major-mode () "Return the major-mode most suitable for the current buffer." |