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")
;; 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))

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)
"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

View File

@ -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.