Browse Source

New hook `org-src-mode-hook'.

This commit adds a new hook `org-src-mode-hook'.

The Hook  run after Org switched a source code snippet to
its Emacs mode.  This hook will run

- when editing a source code snippet with \"C-c '\".
- When formatting a source code snippet for export with htmlize.

You may want to use this hook for example to turn off `outline-minor-mode'
or similar things which you want to have when editing a source code file,
but which mess up the display of a snippet in Org exported files.
Carsten Dominik 16 years ago
parent
commit
5f3b2c275c
3 changed files with 22 additions and 1 deletions
  1. 8 0
      lisp/ChangeLog
  2. 1 0
      lisp/org-exp.el
  3. 13 1
      lisp/org-src.el

+ 8 - 0
lisp/ChangeLog

@@ -1,3 +1,11 @@
+2009-06-08  Carsten Dominik  <carsten.dominik@gmail.com>
+
+	* org-exp.el (org-export-format-source-code-or-example): Run
+	`org-src-mode-hook'.
+
+	* org-src.el (org-src-mode-hook): New variable.
+	(org-edit-src-code): Run `org-src-mode-hook'.
+
 2009-06-07  Carsten Dominik  <carsten.dominik@gmail.com>
 2009-06-07  Carsten Dominik  <carsten.dominik@gmail.com>
 
 
 	* org.el (org-indent-line-function): Fix indentation of +#end lines.
 	* org.el (org-indent-line-function): Fix indentation of +#end lines.

+ 1 - 0
lisp/org-exp.el

@@ -2219,6 +2219,7 @@ INDENT was the original indentation of the block."
 				(funcall mode)
 				(funcall mode)
 			      (fundamental-mode))
 			      (fundamental-mode))
 			    (font-lock-fontify-buffer)
 			    (font-lock-fontify-buffer)
+			    (run-hooks 'org-src-mode-hook)
 			    (set-buffer-modified-p nil)
 			    (set-buffer-modified-p nil)
 			    (org-export-htmlize-region-for-paste
 			    (org-export-htmlize-region-for-paste
 			     (point-min) (point-max))))
 			     (point-min) (point-max))))

+ 13 - 1
lisp/org-src.el

@@ -89,6 +89,17 @@ When nil, the message will only be shown intermittently in the echo area."
   :type 'boolean)
   :type 'boolean)
 
 
 
 
+(defvar org-src-mode-hook nil
+  "Hook  run after Org switched a source code snippet to its Emacs mode.
+This hook will run
+
+- when editing a source code snippet with \"C-c '\".
+- When formatting a source code snippet for export with htmlize.
+
+You may want to use this hook for example to turn off `outline-minor-mode'
+or similar things which you want to have when editing a source code file,
+but which mess up the display of a snippet in Org exported files.")
+
 (defvar org-protecting-blocks
 (defvar org-protecting-blocks
   '("src" "example" "latex" "ascii" "html" "docbook")
   '("src" "example" "latex" "ascii" "html" "docbook")
   "Blocks that contain text that is quoted, i.e. not processed as Org syntax.
   "Blocks that contain text that is quoted, i.e. not processed as Org syntax.
@@ -167,7 +178,8 @@ the edited version."
 				'(display nil invisible nil intangible nil))
 				'(display nil invisible nil intangible nil))
 	(org-do-remove-indentation)
 	(org-do-remove-indentation)
 	(let ((org-inhibit-startup t))
 	(let ((org-inhibit-startup t))
-	  (funcall lang-f))
+	  (funcall lang-f)
+	  (run-hooks 'org-src-mode-hook))
 	(set (make-local-variable 'org-edit-src-force-single-line) single)
 	(set (make-local-variable 'org-edit-src-force-single-line) single)
 	(set (make-local-variable 'org-edit-src-from-org-mode) org-mode-p)
 	(set (make-local-variable 'org-edit-src-from-org-mode) org-mode-p)
 	(when lfmt
 	(when lfmt