Function: c-literal-limits

c-literal-limits is a byte-compiled function defined in cc-engine.el.gz.

Signature

(c-literal-limits &optional LIM NEAR NOT-IN-DELIMITER)

Documentation

Return a cons of the beginning and end positions of the comment or string surrounding point (including both delimiters), or nil if point isn't in one. If LIM is non-nil, it's used as the "safe" position to start parsing from. If NEAR is non-nil, then the limits of any literal next to point is returned. "Next to" means there's only spaces and tabs between point and the literal. The search for such a literal is done first in forward direction. If NOT-IN-DELIMITER is non-nil, the case when point is inside a starting delimiter won't be recognized. This only has effect for comments which have starting delimiters with more than one character.

Note that this function might do hidden buffer changes. See the comment at the start of cc-engine.el for more info.

Aliases

c-literal-limits-fast

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/cc-engine.el.gz
(defun c-literal-limits (&optional lim near not-in-delimiter)
  "Return a cons of the beginning and end positions of the comment or
string surrounding point (including both delimiters), or nil if point
isn't in one.  If LIM is non-nil, it's used as the \"safe\" position
to start parsing from.  If NEAR is non-nil, then the limits of any
literal next to point is returned.  \"Next to\" means there's only
spaces and tabs between point and the literal.  The search for such a
literal is done first in forward direction.  If NOT-IN-DELIMITER is
non-nil, the case when point is inside a starting delimiter won't be
recognized.  This only has effect for comments which have starting
delimiters with more than one character.

Note that this function might do hidden buffer changes.  See the
comment at the start of cc-engine.el for more info."

  (save-excursion
    (let*
	((pos (point))
	 (lit-limits
	  (if lim
	      (let ((s (parse-partial-sexp lim (point))))
		(when (or (nth 3 s)
			  (and (nth 4 s) (not (eq (nth 7 s) 'syntax-table))))
		  (cons (nth 8 s)
			(progn (parse-partial-sexp (point) (point-max)
						   nil nil
						   s
						   'syntax-table)
			       (point)))))
	    (let* ((pp-to-lit (c-full-pp-to-literal pos not-in-delimiter))
		   (limits (car (cddr pp-to-lit))))
	      (if (and limits (null (cdr limits)))
		  (cons (car limits) (point-max))
		limits)))))
      (cond
       (lit-limits)

       (near
	(goto-char pos)
	;; Search forward for a literal.
	(skip-chars-forward " \t")
	(cond
	 ((looking-at c-string-limit-regexp) ; String.
	  (cons (point) (or (c-safe (c-forward-sexp 1) (point))
			    (point-max))))

	 ((looking-at c-comment-start-regexp) ; Line or block comment.
	  (cons (point) (progn (c-forward-single-comment) (point))))

	 (t
	  ;; Search backward.
	  (skip-chars-backward " \t")

	  (let ((end (point)) beg)
	    (cond
	     ((save-excursion
		(< (skip-syntax-backward c-string-syntax) 0)) ; String.
	      (setq beg (c-safe (c-backward-sexp 1) (point))))

	     ((and (c-safe (forward-char -2) t)
		   (looking-at "\\*/"))
	      ;; Block comment.  Due to the nature of line
	      ;; comments, they will always be covered by the
	      ;; normal case above.
	      (goto-char end)
	      (c-backward-single-comment)
	      ;; If LIM is bogus, beg will be bogus.
	      (setq beg (point))))

	    (if beg (cons beg end))))))
       ))))