Function: c-filter-ops

c-filter-ops is a byte-compiled function defined in cc-langs.el.gz.

Signature

(c-filter-ops OPS OPGROUP-FILTER OP-FILTER &optional XLATE)

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/cc-langs.el.gz
(eval-and-compile
  ;; Some helper functions used when building the language constants.

  (defun c-filter-ops (ops opgroup-filter op-filter &optional xlate)
    ;; Extract a subset of the operators in the list OPS in a DWIM:ey
    ;; way.  The return value is a plain list of operators:
    ;;
    ;; OPS either has the structure of `c-operators', is a single
    ;; group in `c-operators', or is a plain list of operators.
    ;;
    ;; OPGROUP-FILTER specifies how to select the operator groups.  It
    ;; can be t to choose all groups, a list of group type symbols
    ;; (such as 'prefix) to accept, or a function which will be called
    ;; with the group symbol for each group and should return non-nil
    ;; if that group is to be included.
    ;;
    ;; OP-FILTER selects the operators.  It is either t to select all
    ;; operators, a string to select all operators for which `string-match'
    ;; matches the operator with the string, or a function which will be
    ;; called with the operator and should return non-nil when the operator
    ;; is to be selected.
    ;;
    ;; If XLATE is given, it's a function which is called for each
    ;; matching operator and its return value is collected instead.
    ;; If it returns a list, the elements are spliced directly into
    ;; the final result, which is returned as a list with duplicates
    ;; removed using `equal'.
    ;;
    ;; `c-mode-syntax-table' for the current mode is in effect during
    ;; the whole procedure.
    (unless (listp (car-safe ops))
      (setq ops (list ops)))
    (cond ((eq opgroup-filter t)
	   (setq opgroup-filter (lambda (_opgroup) t)))
	  ((not (functionp opgroup-filter))
	   (setq opgroup-filter `(lambda (opgroup)
				   (memq opgroup ',opgroup-filter)))))
    (cond ((eq op-filter t)
	   (setq op-filter (lambda (_op) t)))
	  ((stringp op-filter)
	   (setq op-filter `(lambda (op)
			      (string-match ,op-filter op)))))
    (unless xlate
      (setq xlate 'identity))
    (c-with-syntax-table (c-lang-const c-mode-syntax-table)
      (c--delete-duplicates
       (c--mapcan (lambda (opgroup)
		    (when (if (symbolp (car opgroup))
			      (when (funcall opgroup-filter (car opgroup))
				(setq opgroup (cdr opgroup))
				t)
			    t)
		      (c--mapcan (lambda (op)
				   (when (funcall op-filter op)
				     (let ((res (funcall xlate op)))
				       (if (listp res) res (list res)))))
				 opgroup)))
		  ops)
       :test 'equal))))