Function: c-after-change-unmark-ml-strings

c-after-change-unmark-ml-strings is a byte-compiled function defined in cc-engine.el.gz.

Signature

(c-after-change-unmark-ml-strings BEG END OLD-LEN)

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/cc-engine.el.gz
(defun c-after-change-unmark-ml-strings (beg end old-len)
  ;; This function removes `syntax-table' text properties from any ml strings
  ;; which have been affected by the current change.  These are those which
  ;; have been "stringed out" and from newly formed ml strings, or any
  ;; existing ml string which the new text terminates.  BEG, END, and
  ;; OLD-LEN are the standard arguments supplied to any
  ;; after-change-function.
  ;;
  ;; Point is undefined on both entry and exit, and the return value has no
  ;; significance.
  ;;
  ;; This functions is called as an after-change function by virtue of its
  ;; membership of the mode's value of `c-before-font-lock-functions'.
  ;; (when (< beg end)
  ;;
  ;; Maintainers' note: Be careful with the use of `c-old-beg-ml' and
  ;; `c-old-end-ml'; since text has been inserted or removed, most of the
  ;; components in these variables will no longer be valid.  (caar
  ;; c-old-beg-ml) is normally OK, (cadar c-old-beg-ml) often is, any others
  ;; will need adjstments.
  (c-save-buffer-state (found eoll state opener)
    ;; Has an inserted " swallowed up a R"(, turning it into "...R"(?
    (goto-char end)
    (setq eoll (c-point 'eoll))
    (when (and (null c-old-END-literality)
	       (search-forward-regexp c-ml-string-opener-re eoll t))
      (setq state (c-semi-pp-to-literal end))
      (when (eq (cadr state) 'string)
	(unwind-protect
	    ;; Temporarily insert a closing string delimiter....
	    (progn
	      (goto-char end)
	      (cond
	       ((c-characterp (nth 3 (car state)))
		(insert (nth 3 (car state))))
	       ((eq (nth 3 (car state)) t)
		(insert ?\")
		(c-put-string-fence end)))
	      (c-truncate-lit-pos/state-cache end)
	      ;; ....ensure c-new-END extends right to the end of the about
	      ;; to be un-stringed raw string....
	      (save-excursion
		(goto-char (1+ (match-end 1))) ; Count inserted " too.
		(setq c-new-END
		      (max c-new-END
			   (if (re-search-forward
				(funcall c-make-ml-string-closer-re-function
					 (match-string-no-properties 1))
				nil t)
			       (1- (match-end 1)) ; 1- For the inserted ".
			     eoll))))

	      ;; ...and clear `syntax-table' text properties from the
	      ;; following raw strings.
	      (c-depropertize-ml-strings-in-region (point) (1+ eoll)))
	  ;; Remove the temporary string delimiter.
	  (goto-char end)
	  (delete-char 1)
	  (c-truncate-lit-pos/state-cache end))))

    ;; Have we just created a new starting id?
    (goto-char beg)
    (setq opener
	  (if (eq beg end)
	      (c-ml-string-opener-at-or-around-point end)
	    (c-ml-string-opener-intersects-region beg end)))
    (when
	(and opener (<= (car opener) end)
	     (setq state (c-semi-pp-to-literal (car opener)))
	     (not (cadr state)))
      (setq c-new-BEG (min c-new-BEG (car opener)))
      (goto-char (cadr opener))
      (when (re-search-forward
	     (funcall c-make-ml-string-closer-re-function
		      (buffer-substring-no-properties
		       (car opener) (cadr opener)))
	     nil t)	; No bound
	(setq c-new-END (max c-new-END (match-end 1))))
      (goto-char c-new-BEG)
      (while (c-search-forward-char-property-with-value-on-char
	      'syntax-table '(15) ?\" c-new-END)
	(c-remove-string-fences (1- (point))))
      (c-depropertize-ml-strings-in-region c-new-BEG c-new-END))

    ;; Have we matched up with an existing terminator by typing into or
    ;; deleting from an opening delimiter? ... or by messing up a raw string's
    ;; terminator so that it now matches a later terminator?
    (when
	(cond
	 ((or c-ml-string-end-delim-disrupted
	      (and c-old-beg-ml
		   (eq c-beg-pos 'open-delim)))
	  (goto-char (caar c-old-beg-ml)))
	 ((and (< beg end)
	       (not c-old-beg-ml)
	       c-old-1-beg-ml
	       (save-excursion
		 (goto-char (1- beg))
		 (c-ml-string-back-to-neutral (caar c-old-1-beg-ml))
		 (re-search-forward
		  (funcall c-make-ml-string-closer-re-function
			   (buffer-substring-no-properties
			    (caar c-old-1-beg-ml)
			    (cadar c-old-1-beg-ml)))
		  nil 'bound)
		 (> (point) beg)))
	  (goto-char (caar c-old-1-beg-ml))
	  (setq c-new-BEG (min c-new-BEG (point)))
	  (c-truncate-lit-pos/state-cache (point))))

      (when (looking-at c-ml-string-opener-re)
	(goto-char (match-end 1))
	(when (re-search-forward (funcall c-make-ml-string-closer-re-function
					  (match-string-no-properties 1))
				 nil t)	; No bound
	  ;; If what is to be the new delimiter was previously an unterminated
	  ;; ordinary string, clear the c-fl-syn-tab properties from this old
	  ;; string.
	  (when (c-get-char-property (match-beginning 2) 'c-fl-syn-tab)
	    (c-remove-string-fences (match-beginning 2)))
	  (setq c-new-END (point-max))
	  (c-clear-syntax-table-properties-trim-caches
	   (caar (or c-old-beg-ml c-old-1-beg-ml)) c-new-END))))

    ;; Have we disturbed the innards of an ml string, possibly by deleting "s?
    (when (and
	   c-old-beg-ml
	   (eq c-beg-pos 'string)
	   (eq beg end))
      (goto-char beg)
      (c-ml-string-back-to-neutral (caar c-old-beg-ml))
      (let ((bound (if (cdr c-old-end-ml)
		       (min (+ (- (caddr c-old-end-ml) old-len)
			       c-ml-string-max-closer-len-no-leader)
			    (point-max))
		     (point-max)))
	    (new-END-end-ml-string
	     (if (cdr c-old-end-ml)
		 (- (caddr c-old-end-ml) old-len)
	       (point-max))))
	(when (and
	       (re-search-forward
		(funcall c-make-ml-string-closer-re-function
			 (buffer-substring-no-properties
			  (caar c-old-beg-ml) (cadar c-old-beg-ml)))
		bound 'bound)
	       (< (match-end 1) new-END-end-ml-string))
	    (setq c-new-END (max new-END-end-ml-string c-new-END))
	    (c-clear-syntax-table-properties-trim-caches
	     (caar c-old-beg-ml) c-new-END)
	    (setq c-new-BEG (min (caar c-old-beg-ml) c-new-BEG)))))

    ;; Have we terminated an existing raw string by inserting or removing
    ;; text?
    (when
	(and
	 (< beg end)
	 (eq c-old-END-literality 'string)
	 c-old-beg-ml)
      ;; Have we just made or modified a closing delimiter?
      (goto-char end)
      (c-ml-string-back-to-neutral (caar c-old-beg-ml))
      (while
	  (and
	   (setq found
		 (search-forward-regexp
		  c-ml-string-any-closer-re
		  (+ (c-point 'eol end)
		     (1- c-ml-string-max-closer-len-no-leader))
		  t))
	   (< (match-end 1) beg))
	(goto-char (match-end 1)))
      (when (and found (<= (match-beginning 0) end))
	(let ((opener-re (funcall c-make-ml-string-opener-re-function
				  (match-string 1))))
	  (while
	      (and
	       (setq found (re-search-backward opener-re nil t))
	       (setq state (c-semi-pp-to-literal (point)))
	       (memq (nth 3 (car state)) '(t ?\")))))
	(when found
	  (setq c-new-BEG (min (point) c-new-BEG)
		c-new-END (point-max))
	  (c-clear-syn-tab-properties (point) c-new-END)
	  (c-truncate-lit-pos/state-cache (point)))))

    ;; Are there any raw strings in a newly created macro?
      (goto-char (c-point 'bol beg))
      (while (and (< (point) (c-point 'eol end))
		  (re-search-forward c-anchored-cpp-prefix (c-point 'eol end)
				     'boundt))
	(when (and (<= beg (match-end 1))
		   (>= end (match-beginning 1)))
	  (goto-char (match-beginning 1))
	  (c-end-of-macro)
	  (c-depropertize-ml-strings-in-region
	   (match-beginning 1) (point))))))