diff options
| author | Eli Zaretskii | 2022-08-06 17:58:08 +0300 |
|---|---|---|
| committer | Eli Zaretskii | 2022-08-06 17:58:08 +0300 |
| commit | 315b00ff8d7ece419e6026c7fffa182fd5b83a70 (patch) | |
| tree | f66b17dc659020cfc824fbb5c27d7a2eee5db1f5 /src | |
| parent | bee6ee9de179a412f6c4b1c072408066e7912ff6 (diff) | |
| download | emacs-315b00ff8d7ece419e6026c7fffa182fd5b83a70.tar.gz emacs-315b00ff8d7ece419e6026c7fffa182fd5b83a70.zip | |
New function 'composition-sort-rules'
* src/composite.c (Fcomposition_sort_rules)
(compare_composition_rules): New functions.
Diffstat (limited to 'src')
| -rw-r--r-- | src/composite.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/composite.c b/src/composite.c index a13839939b8..b09b755d346 100644 --- a/src/composite.c +++ b/src/composite.c | |||
| @@ -2054,6 +2054,54 @@ See `find-composition' for more details. */) | |||
| 2054 | return Fcons (make_fixnum (start), Fcons (make_fixnum (end), tail)); | 2054 | return Fcons (make_fixnum (start), Fcons (make_fixnum (end), tail)); |
| 2055 | } | 2055 | } |
| 2056 | 2056 | ||
| 2057 | static int | ||
| 2058 | compare_composition_rules (const void *r1, const void *r2) | ||
| 2059 | { | ||
| 2060 | Lisp_Object vec1 = *(Lisp_Object *)r1, vec2 = *(Lisp_Object *)r2; | ||
| 2061 | |||
| 2062 | return XFIXNAT (AREF (vec2, 1)) - XFIXNAT (AREF (vec1, 1)); | ||
| 2063 | } | ||
| 2064 | |||
| 2065 | DEFUN ("composition-sort-rules", Fcomposition_sort_rules, | ||
| 2066 | Scomposition_sort_rules, 1, 1, 0, | ||
| 2067 | doc: /* Sort composition RULES by their LOOKBACK parameter. | ||
| 2068 | |||
| 2069 | If RULES include just one rule, return RULES. | ||
| 2070 | Otherwise, return a new list of rules where all the rules are | ||
| 2071 | arranged in decreasing order of the LOOKBACK parameter of the | ||
| 2072 | rules (the second element of the rule's vector). This is required | ||
| 2073 | when combining composition rules from different sources, because | ||
| 2074 | of the way buffer text is examined for matching one of the rules. */) | ||
| 2075 | (Lisp_Object rules) | ||
| 2076 | { | ||
| 2077 | ptrdiff_t nrules; | ||
| 2078 | USE_SAFE_ALLOCA; | ||
| 2079 | |||
| 2080 | CHECK_LIST (rules); | ||
| 2081 | nrules = list_length (rules); | ||
| 2082 | if (nrules > 1) | ||
| 2083 | { | ||
| 2084 | ptrdiff_t i; | ||
| 2085 | Lisp_Object *sortvec; | ||
| 2086 | |||
| 2087 | SAFE_NALLOCA (sortvec, 1, nrules); | ||
| 2088 | for (i = 0; i < nrules; i++) | ||
| 2089 | { | ||
| 2090 | Lisp_Object elt = XCAR (rules); | ||
| 2091 | if (VECTORP (elt) && ASIZE (elt) == 3 && FIXNATP (AREF (elt, 1))) | ||
| 2092 | sortvec[i] = elt; | ||
| 2093 | else | ||
| 2094 | error ("Invalid composition rule in RULES argument"); | ||
| 2095 | rules = XCDR (rules); | ||
| 2096 | } | ||
| 2097 | qsort (sortvec, nrules, sizeof (Lisp_Object), compare_composition_rules); | ||
| 2098 | rules = Flist (nrules, sortvec); | ||
| 2099 | } | ||
| 2100 | |||
| 2101 | SAFE_FREE (); | ||
| 2102 | return rules; | ||
| 2103 | } | ||
| 2104 | |||
| 2057 | 2105 | ||
| 2058 | void | 2106 | void |
| 2059 | syms_of_composite (void) | 2107 | syms_of_composite (void) |
| @@ -2185,4 +2233,5 @@ This list is auto-generated, you should not need to modify it. */); | |||
| 2185 | defsubr (&Sfind_composition_internal); | 2233 | defsubr (&Sfind_composition_internal); |
| 2186 | defsubr (&Scomposition_get_gstring); | 2234 | defsubr (&Scomposition_get_gstring); |
| 2187 | defsubr (&Sclear_composition_cache); | 2235 | defsubr (&Sclear_composition_cache); |
| 2236 | defsubr (&Scomposition_sort_rules); | ||
| 2188 | } | 2237 | } |