Function: c-clear-<-pair-props

c-clear-<-pair-props is a byte-compiled function defined in cc-engine.el.gz.

Signature

(c-clear-<-pair-props &optional POS)

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/cc-engine.el.gz
;; Setting and removing syntax properties on < and > in languages (C++
;; and Java) where they can be template/generic delimiters as well as
;; their normal meaning of "less/greater than".

;; Normally, < and > have syntax 'punctuation'.  When they are found to
;; be delimiters, they are marked as such with the category properties
;; c-<-as-paren-syntax, c->-as-paren-syntax respectively.

;; STRATEGY:
;;
;; It is impossible to determine with certainty whether a <..> pair in
;; C++ is two comparison operators or is template delimiters, unless
;; one duplicates a lot of a C++ compiler.  For example, the following
;; code fragment:
;;
;;     foo (a < b, c > d) ;
;;
;; could be a function call with two integer parameters (each a
;; relational expression), or it could be a constructor for class foo
;; taking one parameter d of templated type "a < b, c >".  They are
;; somewhat easier to distinguish in Java.
;;
;; The strategy now (2010-01) adopted is to mark and unmark < and
;; > IN MATCHING PAIRS ONLY.  [Previously, they were marked
;; individually when their context so indicated.  This gave rise to
;; intractable problems when one of a matching pair was deleted, or
;; pulled into a literal.]
;;
;; At each buffer change, the syntax-table properties are removed in a
;; before-change function and reapplied, when needed, in an
;; after-change function.  It is far more important that the
;; properties get removed when they they are spurious than that they
;; be present when wanted.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun c-clear-<-pair-props (&optional pos)
  ;; POS (default point) is at a < character.  If it is marked with
  ;; open paren syntax-table text property, remove the property,
  ;; together with the close paren property on the matching > (if
  ;; any).
  (save-excursion
    (if pos
	(goto-char pos)
      (setq pos (point)))
    (when (equal (c-get-char-property (point) 'syntax-table)
		 c-<-as-paren-syntax)
      (with-syntax-table c-no-parens-syntax-table ; ignore unbalanced [,{,(,..
	(c-go-list-forward))
      (when (equal (c-get-char-property (1- (point)) 'syntax-table)
		   c->-as-paren-syntax) ; should always be true.
	(c-unmark-<->-as-paren (1- (point)))
	(c-truncate-lit-pos-cache (1- (point))))
      (c-unmark-<->-as-paren pos)
      (c-truncate-lit-pos-cache pos))))