aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeo Liu2013-06-05 15:40:02 +0800
committerLeo Liu2013-06-05 15:40:02 +0800
commit976cb066286ab3f1ca8356ac850d9a9a34c15406 (patch)
treee64462cfd934711a1cc39d1cccd13ef6f3d1a504
parent208d0342a3bfc4f6bba6c79e43e0dc937b5ca69a (diff)
downloademacs-976cb066286ab3f1ca8356ac850d9a9a34c15406.tar.gz
emacs-976cb066286ab3f1ca8356ac850d9a9a34c15406.zip
Re-implement smie matching block highlight using show-paren-data-function.
* emacs-lisp/smie.el (smie-matching-block-highlight) (smie--highlight-matching-block-overlay) (smie--highlight-matching-block-lastpos) (smie-highlight-matching-block) (smie-highlight-matching-block-mode): Remove. (smie--matching-block-data-cache): New variable. (smie--matching-block-data): New function. (smie-setup): Use smie--matching-block-data for show-paren-data-function. * progmodes/octave.el (octave-mode-menu): Fix. (octave-find-definition): Skip garbage lines. Fixes: debbugs:14395
-rw-r--r--lisp/ChangeLog17
-rw-r--r--lisp/emacs-lisp/smie.el143
-rw-r--r--lisp/progmodes/octave.el16
3 files changed, 87 insertions, 89 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 6d9a21fda9a..753c3af882b 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,20 @@
12013-06-05 Leo Liu <sdl.web@gmail.com>
2
3 Re-implement smie matching block highlight using
4 show-paren-data-function. (Bug#14395)
5 * emacs-lisp/smie.el (smie-matching-block-highlight)
6 (smie--highlight-matching-block-overlay)
7 (smie--highlight-matching-block-lastpos)
8 (smie-highlight-matching-block)
9 (smie-highlight-matching-block-mode): Remove.
10 (smie--matching-block-data-cache): New variable.
11 (smie--matching-block-data): New function.
12 (smie-setup): Use smie--matching-block-data for
13 show-paren-data-function.
14
15 * progmodes/octave.el (octave-mode-menu): Fix.
16 (octave-find-definition): Skip garbage lines.
17
12013-06-05 Stefan Monnier <monnier@iro.umontreal.ca> 182013-06-05 Stefan Monnier <monnier@iro.umontreal.ca>
2 19
3 Fix compilation error with simultaneous dynamic+lexical scoping. 20 Fix compilation error with simultaneous dynamic+lexical scoping.
diff --git a/lisp/emacs-lisp/smie.el b/lisp/emacs-lisp/smie.el
index a88b9d70930..f4eda606ad6 100644
--- a/lisp/emacs-lisp/smie.el
+++ b/lisp/emacs-lisp/smie.el
@@ -1021,87 +1021,63 @@ 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))) 1024(defvar-local smie--matching-block-data-cache nil)
1025 "Face used to highlight matching block." 1025
1026 :group 'smie) 1026(defun smie--matching-block-data (orig &rest args)
1027 1027 "A function suitable for `show-paren-data-function' (which see)."
1028(defvar smie--highlight-matching-block-overlay nil) 1028 (when smie-closer-alist
1029(defvar-local smie--highlight-matching-block-lastpos -1) 1029 (if (eq (point) (car smie--matching-block-data-cache))
1030 1030 (or (cdr smie--matching-block-data-cache)
1031(defun smie-highlight-matching-block () 1031 (apply orig args))
1032 (when (and smie-closer-alist 1032 (setq smie--matching-block-data-cache (list (point)))
1033 (/= (point) smie--highlight-matching-block-lastpos)) 1033 (let* ((beg-of-tok
1034 (unless (overlayp smie--highlight-matching-block-overlay) 1034 (lambda (&optional start)
1035 (setq smie--highlight-matching-block-overlay 1035 "Move to the beginning of current token at START."
1036 (make-overlay (point) (point)))) 1036 (let* ((token)
1037 (setq smie--highlight-matching-block-lastpos (point)) 1037 (start (or start (point)))
1038 (let ((beg-of-tok 1038 (beg (progn
1039 (lambda (&optional start) 1039 (funcall smie-backward-token-function)
1040 "Move to the beginning of current token at START." 1040 (forward-comment (point-max))
1041 (let* ((token) 1041 (point)))
1042 (start (or start (point))) 1042 (end (progn
1043 (beg (progn 1043 (setq token (funcall smie-forward-token-function))
1044 (funcall smie-backward-token-function) 1044 (forward-comment (- (point)))
1045 (forward-comment (point-max)) 1045 (point))))
1046 (point))) 1046 (if (and (<= beg start) (<= start end)
1047 (end (progn 1047 (or (assoc token smie-closer-alist)
1048 (setq token (funcall smie-forward-token-function)) 1048 (rassoc token smie-closer-alist)))
1049 (forward-comment (- (point))) 1049 (progn (goto-char beg) (list token beg end))
1050 (point)))) 1050 (goto-char start)
1051 (if (and (<= beg start) (<= start end) 1051 nil))))
1052 (or (assoc token smie-closer-alist) 1052 (tok-at-pt
1053 (rassoc token smie-closer-alist))) 1053 (lambda ()
1054 (progn (goto-char beg) token) 1054 (or (funcall beg-of-tok)
1055 (goto-char start) 1055 (funcall beg-of-tok
1056 nil)))) 1056 (prog1 (point)
1057 (highlight 1057 (funcall smie-forward-token-function)))))))
1058 (lambda (beg end) 1058 (unless (nth 8 (syntax-ppss))
1059 (move-overlay smie--highlight-matching-block-overlay
1060 beg end (current-buffer))
1061 (overlay-put smie--highlight-matching-block-overlay
1062 'face 'smie-matching-block-highlight))))
1063 (overlay-put smie--highlight-matching-block-overlay 'face nil)
1064 (unless (nth 8 (syntax-ppss))
1065 (save-excursion
1066 (condition-case nil 1059 (condition-case nil
1067 (let ((token 1060 (let ((here (funcall tok-at-pt)))
1068 (or (funcall beg-of-tok) 1061 (when here
1069 (funcall beg-of-tok 1062 (let (pair there)
1070 (prog1 (point) 1063 (cond
1071 (funcall smie-forward-token-function)))))) 1064 ((assoc (car here) smie-closer-alist) ; opener
1072 (cond 1065 (forward-sexp 1)
1073 ((assoc token smie-closer-alist) ; opener 1066 (setq there (funcall tok-at-pt))
1074 (forward-sexp 1) 1067 (setq pair (cons (car here) (car there))))
1075 (let ((end (point)) 1068 ((rassoc (car here) smie-closer-alist) ; closer
1076 (closer (funcall smie-backward-token-function))) 1069 (funcall smie-forward-token-function)
1077 (when (rassoc closer smie-closer-alist) 1070 (forward-sexp -1)
1078 (funcall highlight (point) end)))) 1071 (setq there (funcall tok-at-pt))
1079 ((rassoc token smie-closer-alist) ; closer 1072 (setq pair (cons (car there) (car here)))))
1080 (funcall smie-forward-token-function) 1073 ;; Update the cache
1081 (forward-sexp -1) 1074 (setcdr smie--matching-block-data-cache
1082 (let ((beg (point)) 1075 (list (nth 1 here) (nth 2 here)
1083 (opener (funcall smie-forward-token-function))) 1076 (nth 1 there) (nth 2 there)
1084 (when (assoc opener smie-closer-alist) 1077 (not (member pair smie-closer-alist)))))))
1085 (funcall highlight beg (point))))))) 1078 (scan-error))
1086 (scan-error))))))) 1079 (goto-char (car smie--matching-block-data-cache))))
1087 1080 (apply #'smie--matching-block-data orig args))))
1088(defvar smie--highlight-matching-block-timer nil)
1089
1090;;;###autoload
1091(define-minor-mode smie-highlight-matching-block-mode nil
1092 :global t :group 'smie
1093 (when (timerp smie--highlight-matching-block-timer)
1094 (cancel-timer smie--highlight-matching-block-timer))
1095 (setq smie--highlight-matching-block-timer nil)
1096 (if smie-highlight-matching-block-mode
1097 (progn
1098 (remove-hook 'post-self-insert-hook #'smie-blink-matching-open 'local)
1099 (setq smie--highlight-matching-block-timer
1100 (run-with-idle-timer 0.2 t #'smie-highlight-matching-block)))
1101 (when smie--highlight-matching-block-overlay
1102 (delete-overlay smie--highlight-matching-block-overlay)
1103 (setq smie--highlight-matching-block-overlay nil))
1104 (kill-local-variable 'smie--highlight-matching-block-lastpos)))
1105 1081
1106;;; The indentation engine. 1082;;; The indentation engine.
1107 1083
@@ -1799,9 +1775,10 @@ KEYWORDS are additional arguments, which can use the following keywords:
1799 (setq-local smie-closer-alist ca) 1775 (setq-local smie-closer-alist ca)
1800 ;; Only needed for interactive calls to blink-matching-open. 1776 ;; Only needed for interactive calls to blink-matching-open.
1801 (setq-local blink-matching-check-function #'smie-blink-matching-check) 1777 (setq-local blink-matching-check-function #'smie-blink-matching-check)
1802 (unless smie-highlight-matching-block-mode 1778 (add-hook 'post-self-insert-hook
1803 (add-hook 'post-self-insert-hook 1779 #'smie-blink-matching-open 'append 'local)
1804 #'smie-blink-matching-open 'append 'local)) 1780 (add-function :around (local 'show-paren-data-function)
1781 #'smie--matching-block-data)
1805 ;; Setup smie-blink-matching-triggers. Rather than wait for SPC to 1782 ;; Setup smie-blink-matching-triggers. Rather than wait for SPC to
1806 ;; blink, try to blink as soon as we type the last char of a block ender. 1783 ;; blink, try to blink as soon as we type the last char of a block ender.
1807 (let ((closers (sort (mapcar #'cdr smie-closer-alist) #'string-lessp)) 1784 (let ((closers (sort (mapcar #'cdr smie-closer-alist) #'string-lessp))
diff --git a/lisp/progmodes/octave.el b/lisp/progmodes/octave.el
index c6e19fe3a15..efa735e99b9 100644
--- a/lisp/progmodes/octave.el
+++ b/lisp/progmodes/octave.el
@@ -153,10 +153,10 @@ parenthetical grouping.")
153 'eldoc-mode)) 153 'eldoc-mode))
154 :style toggle :selected (or eldoc-post-insert-mode eldoc-mode) 154 :style toggle :selected (or eldoc-post-insert-mode eldoc-mode)
155 :help "Display function signatures after typing `SPC' or `('"] 155 :help "Display function signatures after typing `SPC' or `('"]
156 ["Delimiter Matching" smie-highlight-matching-block-mode 156 ["Delimiter Matching" show-paren-mode
157 :style toggle :selected smie-highlight-matching-block-mode 157 :style toggle :selected show-paren-mode
158 :help "Highlight matched pairs such as `if ... end'" 158 :help "Highlight matched pairs such as `if ... end'"
159 :visible (fboundp 'smie-highlight-matching-block-mode)] 159 :visible (fboundp 'smie--matching-block-data)]
160 ["Auto Fill" auto-fill-mode 160 ["Auto Fill" auto-fill-mode
161 :style toggle :selected auto-fill-function 161 :style toggle :selected auto-fill-function
162 :help "Automatic line breaking"] 162 :help "Automatic line breaking"]
@@ -1715,9 +1715,13 @@ Functions implemented in C++ can be found if
1715 (list (format "\ 1715 (list (format "\
1716if iskeyword(\"%s\") disp(\"`%s' is a keyword\") else which(\"%s\") endif\n" 1716if iskeyword(\"%s\") disp(\"`%s' is a keyword\") else which(\"%s\") endif\n"
1717 fn fn fn))) 1717 fn fn fn)))
1718 (let* ((line (car inferior-octave-output-list)) 1718 (let (line file)
1719 (file (when (and line (string-match "from the file \\(.*\\)$" line)) 1719 ;; Skip garbage lines such as
1720 (match-string 1 line)))) 1720 ;; warning: fmincg.m: possible Matlab-style ....
1721 (while (and (not file) (consp inferior-octave-output-list))
1722 (setq line (pop inferior-octave-output-list))
1723 (when (string-match "from the file \\(.*\\)$" line)
1724 (setq file (match-string 1 line))))
1721 (if (not file) 1725 (if (not file)
1722 (user-error "%s" (or line (format "`%s' not found" fn))) 1726 (user-error "%s" (or line (format "`%s' not found" fn)))
1723 (require 'etags) 1727 (require 'etags)