[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 6a4ad31 43/47: Add derived mode support.
From: |
Jackson Ray Hamilton |
Subject: |
[elpa] master 6a4ad31 43/47: Add derived mode support. |
Date: |
Mon, 18 May 2015 09:52:07 +0000 |
branch: master
commit 6a4ad31d4f86e6d1b129c17fb16deca9be148514
Author: Jackson Ray Hamilton <address@hidden>
Commit: Jackson Ray Hamilton <address@hidden>
Add derived mode support.
---
context-coloring.el | 18 +++++++++++----
test/context-coloring-test.el | 49 +++++++++++++++++++++++++++++++----------
2 files changed, 50 insertions(+), 17 deletions(-)
diff --git a/context-coloring.el b/context-coloring.el
index 23af23d..0249a5d 100644
--- a/context-coloring.el
+++ b/context-coloring.el
@@ -841,6 +841,15 @@ Invoke CALLBACK when complete."
(defvar context-coloring-mode-hash-table (make-hash-table :test 'eq)
"Map major mode names to dispatch property lists.")
+(defun context-coloring-get-dispatch-for-mode (mode)
+ "Return the dispatch for MODE (or a derivative mode)."
+ (let ((parent mode)
+ dispatch)
+ (while (and parent
+ (not (setq dispatch (gethash parent
context-coloring-mode-hash-table)))
+ (setq parent (get parent 'derived-mode-parent))))
+ dispatch))
+
(defun context-coloring-define-dispatch (symbol &rest properties)
"Define a new dispatch named SYMBOL with PROPERTIES.
@@ -969,7 +978,7 @@ produces (1 0 0), \"19700101\" produces (19700101), etc."
"Asynchronously invoke CALLBACK with a predicate indicating
whether the current scopifier version satisfies the minimum
version number required for the current major mode."
- (let ((dispatch (gethash major-mode context-coloring-mode-hash-table)))
+ (let ((dispatch (context-coloring-get-dispatch-for-mode major-mode)))
(when dispatch
(let ((version (plist-get dispatch :version))
(command (plist-get dispatch :command)))
@@ -1396,7 +1405,7 @@ the current buffer, then execute it.
Invoke CALLBACK when complete. It is invoked synchronously for
elisp tracks, and asynchronously for shell command tracks."
- (let* ((dispatch (gethash major-mode context-coloring-mode-hash-table))
+ (let* ((dispatch (context-coloring-get-dispatch-for-mode major-mode))
(colorizer (plist-get dispatch :colorizer))
(scopifier (plist-get dispatch :scopifier))
(command (plist-get dispatch :command))
@@ -1427,7 +1436,7 @@ elisp tracks, and asynchronously for shell command
tracks."
nil " Context" nil
(if (not context-coloring-mode)
(progn
- (let ((dispatch (gethash major-mode context-coloring-mode-hash-table)))
+ (let ((dispatch (context-coloring-get-dispatch-for-mode major-mode)))
(when dispatch
(let ((command (plist-get dispatch :command))
(teardown (plist-get dispatch :teardown)))
@@ -1448,8 +1457,7 @@ elisp tracks, and asynchronously for shell command
tracks."
;; Safely change the valye of this function as necessary.
(make-local-variable 'font-lock-syntactic-face-function)
- ;; TODO: Detect derived modes.
- (let ((dispatch (gethash major-mode context-coloring-mode-hash-table)))
+ (let ((dispatch (context-coloring-get-dispatch-for-mode major-mode)))
(if dispatch
(progn
(let ((command (plist-get dispatch :command))
diff --git a/test/context-coloring-test.el b/test/context-coloring-test.el
index 19f844b..e22ee29 100644
--- a/test/context-coloring-test.el
+++ b/test/context-coloring-test.el
@@ -348,8 +348,16 @@ EXPECTED-FACE."
(context-coloring-test-assert-region-face
start end 'font-lock-string-face))
+(defun context-coloring-test-get-last-message ()
+ (let ((messages (split-string
+ (buffer-substring-no-properties
+ (point-min)
+ (point-max))
+ "\n")))
+ (car (nthcdr (- (length messages) 2) messages))))
+
(defun context-coloring-test-assert-message (expected buffer)
- "Assert that message EXPECTED exists in BUFFER."
+ "Assert that message EXPECTED is at the end of BUFFER."
(when (null (get-buffer buffer))
(ert-fail
(format
@@ -358,20 +366,28 @@ EXPECTED-FACE."
"but the buffer did not have any messages.")
buffer expected)))
(with-current-buffer buffer
- (let ((messages (split-string
- (buffer-substring-no-properties
- (point-min)
- (point-max))
- "\n")))
- (let ((message (car (nthcdr (- (length messages) 2) messages))))
- (when (not (equal message expected))
+ (let ((message (context-coloring-test-get-last-message)))
+ (when (not (equal message expected))
+ (ert-fail
+ (format
+ (concat
+ "Expected buffer `%s' to have message \"%s\", "
+ "but instead it was \"%s\"")
+ buffer expected
+ message))))))
+
+(defun context-coloring-test-assert-not-message (expected buffer)
+ "Assert that message EXPECTED is not at the end of BUFFER."
+ (when (get-buffer buffer)
+ (with-current-buffer buffer
+ (let ((message (context-coloring-test-get-last-message)))
+ (when (equal message expected)
(ert-fail
(format
(concat
- "Expected buffer `%s' to have message \"%s\", "
- "but instead it was \"%s\"")
- buffer expected
- message)))))))
+ "Expected buffer `%s' not to have message \"%s\", "
+ "but it did")
+ buffer expected)))))))
(defun context-coloring-test-assert-no-message (buffer)
"Assert that BUFFER has no message."
@@ -506,6 +522,15 @@ FOREGROUND. Apply ARGUMENTS to
"Context coloring is not available for this major mode"
"*Messages*")))
+(ert-deftest context-coloring-test-derived-mode ()
+ (context-coloring-test-with-fixture
+ "./fixtures/empty"
+ (lisp-interaction-mode)
+ (context-coloring-mode)
+ (context-coloring-test-assert-not-message
+ "Context coloring is not available for this major mode"
+ "*Messages*")))
+
(define-derived-mode
context-coloring-test-define-dispatch-error-mode
fundamental-mode
- [elpa] master 5c5b429 32/47: Fix font-lock error., (continued)
- [elpa] master 5c5b429 32/47: Fix font-lock error., Jackson Ray Hamilton, 2015/05/18
- [elpa] master c0a6689 33/47: Only set defaults when the mode is enabled., Jackson Ray Hamilton, 2015/05/18
- [elpa] master 59a6c8e 34/47: Fix timer disposal and timer buffer detection., Jackson Ray Hamilton, 2015/05/18
- [elpa] master 88a921f 35/47: Improve defun regexp., Jackson Ray Hamilton, 2015/05/18
- [elpa] master 438cb33 36/47: Fix incorrect last fontified position., Jackson Ray Hamilton, 2015/05/18
- [elpa] master 1d7761c 37/47: Add constant comment test., Jackson Ray Hamilton, 2015/05/18
- [elpa] master 4ff6e82 39/47: Remove verbose parsing., Jackson Ray Hamilton, 2015/05/18
- [elpa] master 4bbce56 38/47: Add test for interruption., Jackson Ray Hamilton, 2015/05/18
- [elpa] master 6392d1f 40/47: Bind optional parameters earlier., Jackson Ray Hamilton, 2015/05/18
- [elpa] master 5051a70 42/47: Update documentation for emacs lisp., Jackson Ray Hamilton, 2015/05/18
- [elpa] master 6a4ad31 43/47: Add derived mode support.,
Jackson Ray Hamilton <=
- [elpa] master 3b6a391 44/47: Minor cleanup., Jackson Ray Hamilton, 2015/05/18
- [elpa] master 708276e 41/47: Compiler micro-optimizations., Jackson Ray Hamilton, 2015/05/18
- [elpa] master 3bf805d 46/47: Version 6.3.0., Jackson Ray Hamilton, 2015/05/18
- [elpa] master c6e173b 45/47: Merge branch 'elisp', Jackson Ray Hamilton, 2015/05/18
- [elpa] master b525e2d 47/47: Merge commit '3bf805df83fe6f110f3e7e8ce2dc37e0cf6c14cb' from context-coloring, Jackson Ray Hamilton, 2015/05/18