branch: master
commit c68cee0beaeb99c5bd178fab6fec995bce4e501f
Merge: 631e7f1 0cc4df5
Author: Dmitry Gutov <[email protected]>
Commit: GitHub <[email protected]>
Merge pull request #73 from AdamNiederer/master
Mode transition hooks
---
mmm-mode.el | 10 ++++++++++
mmm-region.el | 12 ++++++++----
2 files changed, 18 insertions(+), 4 deletions(-)
diff --git a/mmm-mode.el b/mmm-mode.el
index 9637829..41c6be8 100644
--- a/mmm-mode.el
+++ b/mmm-mode.el
@@ -123,6 +123,16 @@ submode region, the following changes \(are supposed to)
occur:
4. Some local variables of the submode shadow the default mode's.
5. Font-lock fontifies correctly for the submode.
6. Indentation function dispatches to the appropriate submode.
+7. User-specified hooks run when the point enters or exits a submode.
+
+The user may specify a number of hooks which may run when the point
+transitions between submodes, or between the primary mode and a
+submode. When a major mode is entered, the hook mmm-x-enter-hook is
+run, where x is the name of the major mode. When a major mode is
+left, the hook mmm-y-exit-hook is run, where y is the name of the
+major mode. Users may also specify hooks with names of the form
+mmm-x-y-hook which are run when the point leaves a mode named x,
+and enters a mode named y.
For further information, including installation and configuration
instructions, see the Info file mmm.info which is included with the
diff --git a/mmm-region.el b/mmm-region.el
index 547b351..6567b31 100644
--- a/mmm-region.el
+++ b/mmm-region.el
@@ -545,10 +545,14 @@ different keymaps, syntax tables, local variables, etc.
for submodes."
(when (mmm-update-current-submode)
(mmm-save-changed-local-variables mmm-previous-submode
mmm-previous-overlay)
- (let ((mode (or mmm-current-submode mmm-primary-mode)))
- (mmm-update-mode-info mode)
- (mmm-set-local-variables mode mmm-current-overlay)
- (mmm-enable-font-lock mode))
+ (let ((new-mode (or mmm-current-submode mmm-primary-mode))
+ (old-mode (or mmm-previous-submode mmm-primary-mode)))
+ (mmm-run-constructed-hook old-mode new-mode)
+ (mmm-run-constructed-hook old-mode "exit")
+ (mmm-run-constructed-hook new-mode "enter")
+ (mmm-update-mode-info new-mode)
+ (mmm-set-local-variables new-mode mmm-current-overlay)
+ (mmm-enable-font-lock new-mode))
(mmm-set-mode-line)
(dolist (func (if mmm-current-overlay
(overlay-get mmm-current-overlay 'entry-hook)