branch: externals/matlab-mode commit 62705b7cb1b0759779d48f29d63dad9a6041db23 Author: John Ciolfi <john.ciolfi...@gmail.com> Commit: John Ciolfi <john.ciolfi...@gmail.com>
matlab.el: code cleanup for classdef property comments Incorporate suggestions from Stefan Monnier --- matlab.el | 57 ++++++++++++++++++++++++--------------------------------- 1 file changed, 24 insertions(+), 33 deletions(-) diff --git a/matlab.el b/matlab.el index e3f048780b..f762747368 100644 --- a/matlab.el +++ b/matlab.el @@ -983,15 +983,6 @@ color support." "Clear the end limit for anchored matchers." (setq ml-fl-anchor-limit nil)) -(defun matlab--move-to-next-language-element () - "Move point over comments and whitespace to next language element. -If point is on a language element, e.g. a variable name, no movement -occurs." - (let ((start-point (1- (point)))) - (while (< start-point (point)) - (setq start-point (point)) - (forward-comment 1)))) - (defun matlab-font-lock-anchor-variable-match (limit) "After finding a keyword like PROPERTIES or ARGUMENTS, match vars. LIMIT is the search limit. @@ -1002,32 +993,32 @@ This matcher will handle a range of variable features." '("properties" "events" "arguments")) (let ((start-point (point))) - ;; Skip over comments so that our regex matchers below do not find items in them. - (matlab--move-to-next-language-element) + ;; Skip over comments to next lanugage element so that our regex matchers below do not find + ;; items in them. + (forward-comment (point-max)) (when (< (point) limit) - (let ((match (progn - ;; When we skip over comments, we need to move back to the start of the line - ;; to ensure our "^" in the regex matches when needed. - (goto-char (max start-point (line-beginning-position))) - (re-search-forward "\\(?:^\\|[,;]\\)\\s-*\\(\\(?:\\w+\\|\\.\\)+\\)\\_>" - limit t)))) - (when match - (let* ( - ;; Save this match so we can do a 2nd anchored search for a data type. - (md1 (list (match-beginning 1) (match-end 1))) - (tm (looking-at - "\\(\\(?:\\s-*([^\n)]+)\\s-*\\|\\s-+\\)?\\(?:\\w+\\(?:\\.\\w+\\)*\\)?\\)\\s-*\\($\\|[;%{=]\\)")) - (tm1 (if tm - (list (match-beginning 1) (match-end 1)) - ;; The below is a cheat to not highlight anything but - ;; still supply the match data for this optional piece. - (list (nth 1 md1) (nth 1 md1)))) - (newmdata (append md1 md1 tm1))) - (goto-char (line-end-position)) - (set-match-data newmdata) - ;; return t which tells font-lock we matched - t))))))) + ;; When we skip over comments, we need to move back to the start of the line + ;; to ensure our "^" in the regex matches when needed. + (goto-char (max start-point (line-beginning-position))) + + (when (re-search-forward "\\(?:^\\|[,;]\\)\\s-*\\(\\(?:\\w+\\|\\.\\)+\\)\\_>" + limit t) + (let* ( + ;; Save this match so we can do a 2nd anchored search for a data type. + (md1 (list (match-beginning 1) (match-end 1))) + (tm (looking-at + "\\(\\(?:\\s-*([^\n)]+)\\s-*\\|\\s-+\\)?\\(?:\\w+\\(?:\\.\\w+\\)*\\)?\\)\\s-*\\($\\|[;%{=]\\)")) + (tm1 (if tm + (list (match-beginning 1) (match-end 1)) + ;; The below is a cheat to not highlight anything but + ;; still supply the match data for this optional piece. + (list (nth 1 md1) (nth 1 md1)))) + (newmdata (append md1 md1 tm1))) + (goto-char (line-end-position)) + (set-match-data newmdata) + ;; return t which tells font-lock we matched + t)))))) ;;; Font Lock keyword handling ;;