Function: c-full-pp-to-literal

c-full-pp-to-literal is a byte-compiled function defined in cc-engine.el.gz.

Signature

(c-full-pp-to-literal HERE &optional NOT-IN-DELIMITER)

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/cc-engine.el.gz
(defun c-full-pp-to-literal (here &optional not-in-delimiter)
  ;; This function will supersede c-state-pp-to-literal.
  ;;
  ;; Do a parse-partial-sexp from a position in the buffer before HERE which
  ;; isn't in a literal, and return information about HERE, either:
  ;; (STATE TYPE (BEG . END))   if HERE is in a literal; or
  ;; (STATE)                    otherwise,
  ;; where STATE is the parsing state at HERE, TYPE is the type of the literal
  ;; enclosing HERE, (one of 'string, 'c, 'c++) and (BEG . END) is the
  ;; boundaries of that literal (including the delimiters), with END being nil
  ;; if there is no end delimiter (i.e. the literal ends at EOB).
  ;;
  ;; Unless NOT-IN-DELIMITER is non-nil, when TO is inside a two-character
  ;; comment opener, this is recognized as being in a comment literal.
  ;;
  ;; Only elements 3 (in a string), 4 (in a comment), 5 (following a quote), 7
  ;; (comment type), and 8 (start of comment/string), and possibly 10 (in
  ;; newer Emacsen only, the syntax of a position after a potential first char
  ;; of a two char construct) of STATE are valid.
  (save-excursion
    (save-restriction
      (widen)
      (c-trim-lit-pos-cache)
      (c-full-trim-near-cache)
      (save-match-data
	(let* ((elt (c-full-get-near-cache-entry here))
	       (base (car elt))
	       (near-base base)
	       (s (cadr elt))
	       s1
	       (end (car (cddr elt)))
	       far-base-and-state far-base far-s ty start)
	  (if (or
	       (not base)   ; FIXME!!! Compare base and far-base??
					; (2019-05-21)
	       (not end)
	       (>= here end))
	      (progn
		(setq far-base-and-state (c-parse-ps-state-below here)
		      far-base (car far-base-and-state)
		      far-s (cdr far-base-and-state))
		(when (or (not base) (> far-base base))
		  (setq base far-base
			s far-s
			end nil))))
	  (cond
	   ((or (and (> here base) (null end))
		(null (nth 8 s))
		(and end (>= here end)))
	    (setq s (parse-partial-sexp base here nil nil s)))
	   ((or (and (nth 3 s)		; string
		     (eq (char-before here) ?\\))
		(and (nth 4 s) (not (nth 7 s)) ; block comment
		     (memq (char-before here) c-block-comment-awkward-chars))
		(and (nth 4 s) (nth 7 s) ; line comment
		     (memq (char-before here) '(?\\ ?\n))))
	    (setq s
		  (if (>= here base)
		      (parse-partial-sexp base here nil nil s)
		    (parse-partial-sexp (nth 8 s) here)))))
	  (cond
	   ((or (nth 3 s)
		(and (nth 4 s)
		     (not (eq (nth 7 s) 'syntax-table)))) ; in a string or comment
	    (setq ty (cond
		      ((nth 3 s) 'string)
		      ((nth 7 s) 'c++)
		      (t 'c)))
	    (setq start (nth 8 s))
	    (unless (and end (>= end here))
	      (setq s1 (parse-partial-sexp here (point-max)
					   nil		  ; TARGETDEPTH
					   nil		  ; STOPBEFORE
					   s		  ; OLDSTATE
					   'syntax-table)); stop at EO literal
	      (unless (or (nth 3 s1)			  ; still in a string
			  (and (nth 4 s1)
			       (not (eq (nth 7 s1) 'syntax-table)))) ; still
								     ; in a
								     ; comment
		(setq end (point))))
	    (unless (eq near-base here)
	      (c-full-put-near-cache-entry here s end))
	    (list s ty (cons start end)))

	   ((and (not not-in-delimiter)	; inside a comment starter
		 (not (bobp))
		 (progn (backward-char)
			(and (not (and (memq 'category-properties c-emacs-features)
				       (looking-at "\\s!")))
			     (looking-at c-comment-start-regexp))))
	    (setq ty (if (looking-at c-block-comment-start-regexp) 'c 'c++)
		  start (point))
	    (forward-comment 1)
	    (list s ty (cons start (point))))

	   (t
	    (unless (eq near-base here)
	      (c-full-put-near-cache-entry here s nil))
	    (list s))))))))