branch: externals/code-cells
commit 67e1479a7518cf1ea82ec6e4d1147c786db49993
Author: Augusto Stoffel <[email protected]>
Commit: Augusto Stoffel <[email protected]>

    Add code-cells-mode-maybe
---
 code-cells.el | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/code-cells.el b/code-cells.el
index d44de426aa..3d982c63da 100644
--- a/code-cells.el
+++ b/code-cells.el
@@ -282,6 +282,15 @@ level."
     (font-lock-remove-keywords nil (code-cells--font-lock-keywords)))
   (font-lock-flush))
 
+;;;###autoload
+(defun code-cells-mode-maybe ()
+  "Turn on `code-cells-mode' if the buffer appears to contain cells.
+This function is useful when added to a major mode hook."
+    (when (save-excursion
+            (goto-char (point-min))
+            (re-search-forward (code-cells-boundary-regexp) 5000 t))
+      (code-cells-mode)))
+
 (let ((map (make-sparse-keymap)))
   (define-key code-cells-mode-map "\C-c%" map)
   (define-key map ";" 'code-cells-comment-or-uncomment)

Reply via email to