Function: LaTeX-verbatim-macro-boundaries

LaTeX-verbatim-macro-boundaries is a byte-compiled function defined in latex.el.

Signature

(LaTeX-verbatim-macro-boundaries &optional ARG-ONLY)

Documentation

Return boundaries of verbatim macro containing point.

Boundaries are returned as a cons cell where the car is the macro start and the cdr the macro end.

If optional argument ARG-ONLY is non-nil, return the inner region of the macro argument as cons.

Source Code

;; Defined in ~/.emacs.d/elpa/auctex-14.1.2/latex.el
(defun LaTeX-verbatim-macro-boundaries (&optional arg-only)
  "Return boundaries of verbatim macro containing point.
Boundaries are returned as a cons cell where the car is the macro
start and the cdr the macro end.

If optional argument ARG-ONLY is non-nil, return the inner region
of the macro argument as cons."
  (save-excursion
    (let ((orig (point))
          (verbatim-regexp (regexp-opt
                            (append (LaTeX-verbatim-macros-with-delims)
                                    (LaTeX-verbatim-macros-with-braces))
                            t)))
      ;; Search backwards for the macro start, unless we are facing one
      (if (looking-at (concat (regexp-quote TeX-esc) verbatim-regexp))
          (forward-char 1)
        (while (progn
                 (skip-chars-backward (concat "^" (regexp-quote TeX-esc))
                                      (line-beginning-position))
                 (if (or (bolp)
                         (looking-at verbatim-regexp))
                     ;; Terminate the loop.
                     nil
                   (forward-char -1)
                   ;; Continue the loop.
                   t))))
      ;; Search forward for the macro end, unless we failed to find a start
      (unless (bolp)
        (let* ((beg (1- (point)))
               (end (match-end 0))
               ;; XXX: Here we assume we are dealing with \verb which
               ;; expects the delimiter right behind the command.
               ;; However, \lstinline can also cope with whitespace as
               ;; well as an optional argument after the command.
               ;; \Verb (from fancyvrb) also accepts an optional
               ;; argument which we have to encounter.  We assume that
               ;; users don't write something like this '\Verb[foo['
               ;; and again the delimiter is directly after the ]
               ;; closing the optional argument:
               (delimiter (progn
                            (if (= (char-after end) (aref LaTeX-optop 0))
                                ;; Update `end'.
                                (save-excursion (goto-char end)
                                                (forward-list)
                                                (setq end (point))))
                            (string (char-after end)))))
          ;; Heuristic: If an opening brace is encountered, search for
          ;; a closing brace as an end marker.
          ;; Like that the function should work for \verb|...| as well
          ;; as for \url{...}.
          (if (string= delimiter TeX-grop)
              (progn
                (goto-char end)
                ;; Allow one level of nested braces as verb argument.
                (re-search-forward "{[^}{]*\\(?:{[^}{]*}[^}{]*\\)*}"
                                   (line-end-position) t)
                (backward-char))
            (goto-char (1+ end))
            (skip-chars-forward (concat "^" delimiter) (line-end-position)))
          (when (<= orig (point))
            (if arg-only
                (cons (1+ end) (point))
              (cons beg (1+ (point))))))))))