diff --git a/matlab-scan.el b/matlab-scan.el index 6472d29..51b02dc 100644 --- a/matlab-scan.el +++ b/matlab-scan.el @@ -1019,8 +1019,13 @@ Assume basic keyword checks have already been done." (or (string= (nth 1 parent) "function") ;; If not a function, it might be an and, but that end will need to be ;; reverse tracked to see if it belongs to valid argument block. - (string= (nth 1 parent) "end") - ;; TODO: be more rigid in this detection. + (and (string= (nth 1 parent) "end") + (save-excursion + (goto-char (nth 2 parent)) + (matlab--scan-block-backward) + (let ((prevblock (matlab--mk-keyword-node))) + (string= (nth 1 prevblock) "arguments"))) + ) )) )))) @@ -1200,7 +1205,10 @@ then skip and keep searching." ;; Check for simple cases that are invalid for keywords ;; for strings, comments, and lists, skip to the end of them ;; to not waste time searching for keywords inside. - (cond ((matlab-end-of-string-or-comment t) + (cond ((matlab-end-of-string-or-comment) + ;; Test is only IF in a comment. Also skip other comments + ;; once we know we were in a comment. + (matlab-end-of-string-or-comment t) (setq ans nil)) ((matlab-in-list-p) (condition-case nil @@ -1228,7 +1236,8 @@ then skip and keep searching." ;; Check for simple cases that are invalid for keywords ;; for strings, comments, and lists, skip to the end of them ;; to not waste time searching for keywords inside. - (cond ((matlab-beginning-of-string-or-comment t) + (cond ((matlab-beginning-of-string-or-comment) + (matlab-beginning-of-string-or-comment t) (setq ans nil)) ((matlab-beginning-of-outer-list) (setq ans nil)) diff --git a/matlab-syntax.el b/matlab-syntax.el index f285969..f22b6d8 100644 --- a/matlab-syntax.el +++ b/matlab-syntax.el @@ -446,11 +446,12 @@ bounds of the string or comment the cursor is in" (defsubst matlab-beginning-of-string-or-comment (&optional all-comments) "If the cursor is in a string or comment, move to the beginning. -Returns non-nil if the cursor moved." +Returns non-nil if the cursor is in a comment." (let* ((pps (syntax-ppss (point)))) (prog1 (when (nth 8 pps) (goto-char (nth 8 pps)) + t) (when all-comments (forward-comment -100000))))) @@ -476,9 +477,9 @@ Returns non-nil if the cursor moved." (error "Error navitaging syntax.")) t) ;; else not in comment, but still skip 'all-comments' if requested. - (not (eq (point) - (progn (when all-comments (forward-comment 100000)) - (point)))) + (when (and all-comments (looking-at "\\s-*\\s<")) + (forward-comment 100000) + t) ))) ;;; Navigating Lists diff --git a/matlab.el b/matlab.el index f5f7e34..7c88cef 100644 --- a/matlab.el +++ b/matlab.el @@ -287,12 +287,16 @@ If the value is t, then return that." (goto-char (point-min)) (matlab-find-code-line) (let ((matlab-functions-have-end t)) ;; pretend we have ends - (beginning-of-line) - (condition-case nil - ;; Try to navigate. If success, then t - (progn (matlab-forward-sexp) t) - ;; On failure, then no ends. - (error nil)) + (back-to-indentation) + (if (eq (matlab-on-keyword-p) 'decl) + ;; If block scaning returns state, then that means + ;; there is a missing end, so value is nil. + ;; If it returns empty, then there is a matching end. + (if (matlab--scan-block-forward) + nil + t) + ;; Not on a decl, therefore just say nil, since block scanning would fail. + nil) )))) ) ;; Else, just return the default.