Function: composition-sort-rules

composition-sort-rules is a function defined in composite.c.

Signature

(composition-sort-rules RULES)

Documentation

Sort composition RULES by their LOOKBACK parameter.

If RULES include just one rule, return RULES. Otherwise, return a new list of rules where all the rules are arranged in decreasing order of the LOOKBACK parameter of the rules (the second element of the rule's vector). This is required when combining composition rules from different sources, because of the way buffer text is examined for matching one of the rules.

Source Code

// Defined in /usr/src/emacs/src/composite.c
{
  ptrdiff_t nrules;
  USE_SAFE_ALLOCA;

  CHECK_LIST (rules);
  nrules = list_length (rules);
  if (nrules > 1)
    {
      ptrdiff_t i;
      Lisp_Object *sortvec;

      SAFE_NALLOCA (sortvec, 1, nrules);
      for (i = 0; i < nrules; i++)
	{
	  Lisp_Object elt = XCAR (rules);
	  if (VECTORP (elt) && ASIZE (elt) == 3 && FIXNATP (AREF (elt, 1)))
	    sortvec[i] = elt;
	  else
	    error ("Invalid composition rule in RULES argument");
	  rules = XCDR (rules);
	}
      qsort (sortvec, nrules, sizeof (Lisp_Object), compare_composition_rules);
      rules = Flist (nrules, sortvec);
      SAFE_FREE ();
    }

  return rules;
}