diff options
| author | Leo Liu | 2013-05-17 06:58:58 +0800 |
|---|---|---|
| committer | Leo Liu | 2013-05-17 06:58:58 +0800 |
| commit | ebfe68e85acc390a7f1cebed731d362ef54ff001 (patch) | |
| tree | 1fe57d1634afee58318294f03101d0863b94c7d1 | |
| parent | 46cd302842975e63f7ed05c0dc25c92c374f2e79 (diff) | |
| download | emacs-ebfe68e85acc390a7f1cebed731d362ef54ff001.tar.gz emacs-ebfe68e85acc390a7f1cebed731d362ef54ff001.zip | |
* emacs-lisp/smie.el (smie-matching-block-highlight): New face.
(smie--highlight-matching-block-overlay)
(smie--highlight-matching-block-lastpos)
(smie--highlight-matching-block-timer): New variables.
(smie-highlight-matching-block): New function.
(smie-highlight-matching-block-mode): New minor mode.
(smie-setup): Conditionally enable smie-blink-matching-open.
Fixes: debbugs:14395
| -rw-r--r-- | lisp/ChangeLog | 10 | ||||
| -rw-r--r-- | lisp/emacs-lisp/smie.el | 84 |
2 files changed, 92 insertions, 2 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 796652554ff..84e1119bc64 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,13 @@ | |||
| 1 | 2013-05-16 Leo Liu <sdl.web@gmail.com> | ||
| 2 | |||
| 3 | * emacs-lisp/smie.el (smie-matching-block-highlight): New face. | ||
| 4 | (smie--highlight-matching-block-overlay) | ||
| 5 | (smie--highlight-matching-block-lastpos) | ||
| 6 | (smie--highlight-matching-block-timer): New variables. | ||
| 7 | (smie-highlight-matching-block): New function. | ||
| 8 | (smie-highlight-matching-block-mode): New minor mode. (Bug#14395) | ||
| 9 | (smie-setup): Conditionally enable smie-blink-matching-open. | ||
| 10 | |||
| 1 | 2013-05-16 Wilson Snyder <wsnyder@wsnyder.org> | 11 | 2013-05-16 Wilson Snyder <wsnyder@wsnyder.org> |
| 2 | 12 | ||
| 3 | Sync with upstream verilog-mode r840. | 13 | Sync with upstream verilog-mode r840. |
diff --git a/lisp/emacs-lisp/smie.el b/lisp/emacs-lisp/smie.el index c59076974e0..2113457869e 100644 --- a/lisp/emacs-lisp/smie.el +++ b/lisp/emacs-lisp/smie.el | |||
| @@ -1021,6 +1021,85 @@ This uses SMIE's tables and is expected to be placed on `post-self-insert-hook'. | |||
| 1021 | (let ((blink-matching-check-function #'smie-blink-matching-check)) | 1021 | (let ((blink-matching-check-function #'smie-blink-matching-check)) |
| 1022 | (blink-matching-open)))))))) | 1022 | (blink-matching-open)))))))) |
| 1023 | 1023 | ||
| 1024 | (defface smie-matching-block-highlight '((t (:inherit highlight))) | ||
| 1025 | "Face used to highlight matching block." | ||
| 1026 | :group 'smie) | ||
| 1027 | |||
| 1028 | (defvar-local smie--highlight-matching-block-overlay nil) | ||
| 1029 | (defvar-local smie--highlight-matching-block-lastpos -1) | ||
| 1030 | |||
| 1031 | (defun smie-highlight-matching-block () | ||
| 1032 | (when (and smie-closer-alist | ||
| 1033 | (/= (point) smie--highlight-matching-block-lastpos)) | ||
| 1034 | (unless (overlayp smie--highlight-matching-block-overlay) | ||
| 1035 | (setq smie--highlight-matching-block-overlay | ||
| 1036 | (make-overlay (point) (point)))) | ||
| 1037 | (setq smie--highlight-matching-block-lastpos (point)) | ||
| 1038 | (let ((beg-of-tok | ||
| 1039 | (lambda (&optional start) | ||
| 1040 | "Move to the beginning of current token at START." | ||
| 1041 | (let* ((token) | ||
| 1042 | (start (or start (point))) | ||
| 1043 | (beg (progn | ||
| 1044 | (funcall smie-backward-token-function) | ||
| 1045 | (forward-comment (point-max)) | ||
| 1046 | (point))) | ||
| 1047 | (end (progn | ||
| 1048 | (setq token (funcall smie-forward-token-function)) | ||
| 1049 | (forward-comment (- (point))) | ||
| 1050 | (point)))) | ||
| 1051 | (if (and (<= beg start) (<= start end) | ||
| 1052 | (or (assoc token smie-closer-alist) | ||
| 1053 | (rassoc token smie-closer-alist))) | ||
| 1054 | (progn (goto-char beg) token) | ||
| 1055 | (goto-char start) | ||
| 1056 | nil)))) | ||
| 1057 | (highlight | ||
| 1058 | (lambda (beg end) | ||
| 1059 | (move-overlay smie--highlight-matching-block-overlay beg end) | ||
| 1060 | (overlay-put smie--highlight-matching-block-overlay | ||
| 1061 | 'face 'smie-matching-block-highlight)))) | ||
| 1062 | (save-excursion | ||
| 1063 | (condition-case nil | ||
| 1064 | (if (nth 8 (syntax-ppss)) | ||
| 1065 | (overlay-put smie--highlight-matching-block-overlay 'face nil) | ||
| 1066 | (let ((token | ||
| 1067 | (or (funcall beg-of-tok) | ||
| 1068 | (funcall beg-of-tok | ||
| 1069 | (prog1 (point) | ||
| 1070 | (funcall smie-forward-token-function)))))) | ||
| 1071 | (cond | ||
| 1072 | ((assoc token smie-closer-alist) ; opener | ||
| 1073 | (forward-sexp 1) | ||
| 1074 | (let ((end (point)) | ||
| 1075 | (closer (funcall smie-backward-token-function))) | ||
| 1076 | (when (rassoc closer smie-closer-alist) | ||
| 1077 | (funcall highlight (point) end)))) | ||
| 1078 | ((rassoc token smie-closer-alist) ; closer | ||
| 1079 | (funcall smie-forward-token-function) | ||
| 1080 | (forward-sexp -1) | ||
| 1081 | (let ((beg (point)) | ||
| 1082 | (opener (funcall smie-forward-token-function))) | ||
| 1083 | (when (assoc opener smie-closer-alist) | ||
| 1084 | (funcall highlight beg (point))))) | ||
| 1085 | (t (overlay-put smie--highlight-matching-block-overlay | ||
| 1086 | 'face nil))))) | ||
| 1087 | (scan-error | ||
| 1088 | (overlay-put smie--highlight-matching-block-overlay 'face nil))))))) | ||
| 1089 | |||
| 1090 | (defvar smie--highlight-matching-block-timer nil) | ||
| 1091 | |||
| 1092 | ;;;###autoload | ||
| 1093 | (define-minor-mode smie-highlight-matching-block-mode nil | ||
| 1094 | :global t :group 'smie | ||
| 1095 | (when (timerp smie--highlight-matching-block-timer) | ||
| 1096 | (cancel-timer smie--highlight-matching-block-timer)) | ||
| 1097 | (setq smie--highlight-matching-block-timer nil) | ||
| 1098 | (when smie-highlight-matching-block-mode | ||
| 1099 | (remove-hook 'post-self-insert-hook #'smie-blink-matching-open 'local) | ||
| 1100 | (setq smie--highlight-matching-block-timer | ||
| 1101 | (run-with-idle-timer 0.2 t #'smie-highlight-matching-block)))) | ||
| 1102 | |||
| 1024 | ;;; The indentation engine. | 1103 | ;;; The indentation engine. |
| 1025 | 1104 | ||
| 1026 | (defcustom smie-indent-basic 4 | 1105 | (defcustom smie-indent-basic 4 |
| @@ -1701,8 +1780,9 @@ KEYWORDS are additional arguments, which can use the following keywords: | |||
| 1701 | ;; Only needed for interactive calls to blink-matching-open. | 1780 | ;; Only needed for interactive calls to blink-matching-open. |
| 1702 | (set (make-local-variable 'blink-matching-check-function) | 1781 | (set (make-local-variable 'blink-matching-check-function) |
| 1703 | #'smie-blink-matching-check) | 1782 | #'smie-blink-matching-check) |
| 1704 | (add-hook 'post-self-insert-hook | 1783 | (unless smie-highlight-matching-block-mode |
| 1705 | #'smie-blink-matching-open 'append 'local) | 1784 | (add-hook 'post-self-insert-hook |
| 1785 | #'smie-blink-matching-open 'append 'local)) | ||
| 1706 | (set (make-local-variable 'smie-blink-matching-triggers) | 1786 | (set (make-local-variable 'smie-blink-matching-triggers) |
| 1707 | (append smie-blink-matching-triggers | 1787 | (append smie-blink-matching-triggers |
| 1708 | ;; Rather than wait for SPC to blink, try to blink as | 1788 | ;; Rather than wait for SPC to blink, try to blink as |