Function: lua-find-regexp

lua-find-regexp is a byte-compiled function defined in lua-mode.el.gz.

Signature

(lua-find-regexp DIRECTION REGEXP &optional LIMIT)

Documentation

Search for a regular expression in the direction specified.

DIRECTION is one of 'forward and 'backward.

Matches in comments and strings are ignored. If the REGEXP is found, returns point position, nil otherwise.

The argument LIMIT is a buffer position that bounds the search.

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/lua-mode.el.gz
(defun lua-find-regexp (direction regexp &optional limit)
  "Search for a regular expression in the direction specified.

DIRECTION is one of \\='forward and \\='backward.

Matches in comments and strings are ignored.  If the REGEXP is found,
returns point position, nil otherwise.

The argument LIMIT is a buffer position that bounds the search."
  (let ((search-func (if (eq direction 'forward)
                         're-search-forward 're-search-backward))
        (case-fold-search nil))
    (cl-loop
     always (or (null limit)
                (lua--ensure-point-within-limit
                 limit (not (eq direction 'forward))))
     always (funcall search-func regexp limit 'noerror)
     for match-beg = (match-beginning 0)
     for match-end = (match-end 0)
     while (or (lua-comment-or-string-p match-beg)
               (lua-comment-or-string-p match-end))
     do (let ((parse-state (syntax-ppss)))
          (cond
           ;; Inside a string
           ((nth 3 parse-state)
            (lua--escape-from-string (not (eq direction 'forward))))
           ;; Inside a comment
           ((nth 4 parse-state)
            (goto-char (nth 8 parse-state))
            (when (eq direction 'forward)
              (forward-comment 1)))))
     finally return (point))))