matlab-scan.el:

(matlab--valid-arguments-keyword-point):
If previous code is 'end', make sure it matches a valid arguments block.
(matlab-re-search-keyword-forward,matlab-re-search-keyword-backward):
When checking if in string/comment, don't pass in 'all comments' as t.
Do that only if in a comment.

matlab-syntax.el:
(matlab-beginning-of-string-or-comment):
Make doc accurate.
(matlab-end-of-string-or-comment):
Fix logic for case when not in a comment to only skip all comments if
looking at a comment.  Avoid moving pt if just looking at whitespace.

matlab.el:
(matlab-do-functions-have-end-p):
Improve scanning for end to not do condition-case.
This was hiding an error that was causing incorrect answer.
This commit is contained in:
Eric Ludlam 2021-04-11 15:35:26 -04:00
parent bda0b63da3
commit 4611551deb
3 changed files with 28 additions and 14 deletions

View File

@ -1019,8 +1019,13 @@ Assume basic keyword checks have already been done."
(or (string= (nth 1 parent) "function") (or (string= (nth 1 parent) "function")
;; If not a function, it might be an and, but that end will need to be ;; 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. ;; reverse tracked to see if it belongs to valid argument block.
(string= (nth 1 parent) "end") (and (string= (nth 1 parent) "end")
;; TODO: be more rigid in this detection. (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 ;; Check for simple cases that are invalid for keywords
;; for strings, comments, and lists, skip to the end of them ;; for strings, comments, and lists, skip to the end of them
;; to not waste time searching for keywords inside. ;; 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)) (setq ans nil))
((matlab-in-list-p) ((matlab-in-list-p)
(condition-case nil (condition-case nil
@ -1228,7 +1236,8 @@ then skip and keep searching."
;; Check for simple cases that are invalid for keywords ;; Check for simple cases that are invalid for keywords
;; for strings, comments, and lists, skip to the end of them ;; for strings, comments, and lists, skip to the end of them
;; to not waste time searching for keywords inside. ;; 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)) (setq ans nil))
((matlab-beginning-of-outer-list) ((matlab-beginning-of-outer-list)
(setq ans nil)) (setq ans nil))

View File

@ -446,11 +446,12 @@ bounds of the string or comment the cursor is in"
(defsubst matlab-beginning-of-string-or-comment (&optional all-comments) (defsubst matlab-beginning-of-string-or-comment (&optional all-comments)
"If the cursor is in a string or comment, move to the beginning. "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)))) (let* ((pps (syntax-ppss (point))))
(prog1 (prog1
(when (nth 8 pps) (when (nth 8 pps)
(goto-char (nth 8 pps)) (goto-char (nth 8 pps))
t) t)
(when all-comments (forward-comment -100000))))) (when all-comments (forward-comment -100000)))))
@ -476,9 +477,9 @@ Returns non-nil if the cursor moved."
(error "Error navitaging syntax.")) (error "Error navitaging syntax."))
t) t)
;; else not in comment, but still skip 'all-comments' if requested. ;; else not in comment, but still skip 'all-comments' if requested.
(not (eq (point) (when (and all-comments (looking-at "\\s-*\\s<"))
(progn (when all-comments (forward-comment 100000)) (forward-comment 100000)
(point)))) t)
))) )))
;;; Navigating Lists ;;; Navigating Lists

View File

@ -287,12 +287,16 @@ If the value is t, then return that."
(goto-char (point-min)) (goto-char (point-min))
(matlab-find-code-line) (matlab-find-code-line)
(let ((matlab-functions-have-end t)) ;; pretend we have ends (let ((matlab-functions-have-end t)) ;; pretend we have ends
(beginning-of-line) (back-to-indentation)
(condition-case nil (if (eq (matlab-on-keyword-p) 'decl)
;; Try to navigate. If success, then t ;; If block scaning returns state, then that means
(progn (matlab-forward-sexp) t) ;; there is a missing end, so value is nil.
;; On failure, then no ends. ;; If it returns empty, then there is a matching end.
(error nil)) (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. ;; Else, just return the default.