diff options
| author | Eli Zaretskii | 2014-09-07 20:46:54 +0300 |
|---|---|---|
| committer | Eli Zaretskii | 2014-09-07 20:46:54 +0300 |
| commit | eb71ffc65e57e72798c9e1326a0e804380b94b56 (patch) | |
| tree | 3ec1e93c2d2a3c5ea42a67befac0d2a2c337eb0e /src | |
| parent | a12d75c6e2df82308f86ce2df68fa1422867a27a (diff) | |
| download | emacs-eb71ffc65e57e72798c9e1326a0e804380b94b56.tar.gz emacs-eb71ffc65e57e72798c9e1326a0e804380b94b56.zip | |
Added bidi-resolved-levels, with a bug.
Diffstat (limited to 'src')
| -rw-r--r-- | src/xdisp.c | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/src/xdisp.c b/src/xdisp.c index 39e70717143..7cf1782b83f 100644 --- a/src/xdisp.c +++ b/src/xdisp.c | |||
| @@ -21328,6 +21328,114 @@ Value is the new character position of point. */) | |||
| 21328 | #undef ROW_GLYPH_NEWLINE_P | 21328 | #undef ROW_GLYPH_NEWLINE_P |
| 21329 | } | 21329 | } |
| 21330 | 21330 | ||
| 21331 | DEFUN ("bidi-resolved-levels", Fbidi_resolved_levels, | ||
| 21332 | Sbidi_resolved_levels, 0, 1, 0, | ||
| 21333 | doc: /* Return the resolved bidirectional levels of characters at VPOS. | ||
| 21334 | |||
| 21335 | The resolved levels are produced by the Emacs bidi reordering engine | ||
| 21336 | that implements the UBA, the Unicode Bidirectional Algorithm. Please | ||
| 21337 | read the Unicode Standard Annex 9 (UAX#9) for background information | ||
| 21338 | about these levels. | ||
| 21339 | |||
| 21340 | VPOS is the zero-based number of the current window's screen line | ||
| 21341 | for which to produce the resolved levels. If VPOS is nil or omitted, | ||
| 21342 | it defaults to the screen line of point. If the window displays a | ||
| 21343 | header line, VPOS of zero will report on the header line, and first | ||
| 21344 | line of text in the window will have VPOS of 1. | ||
| 21345 | |||
| 21346 | Value is an array of resolved levels, indexed by glyph number. | ||
| 21347 | Glyphs are numbered from zero starting from the beginning of the | ||
| 21348 | screen line, i.e. the left edge of the window for left-to-right lines | ||
| 21349 | and from the right edge for right-to-left lines. The resolved levels | ||
| 21350 | are produced only for the window's text area; text in display margins | ||
| 21351 | is not included. | ||
| 21352 | |||
| 21353 | If the selected window's display is not up-to-date, or if the specified | ||
| 21354 | screen line does not display text, this function returns nil. It is | ||
| 21355 | highly recommended to bind this function to some simple key, like F8, | ||
| 21356 | in order to avoid these problems. | ||
| 21357 | |||
| 21358 | This function exists mainly for testing the correctness of the | ||
| 21359 | Emacs UBA implementation, in particular with the test suite. */) | ||
| 21360 | (Lisp_Object vpos) | ||
| 21361 | { | ||
| 21362 | struct window *w = XWINDOW (selected_window); | ||
| 21363 | struct buffer *b = XBUFFER (w->contents); | ||
| 21364 | int nrow; | ||
| 21365 | struct glyph_row *row; | ||
| 21366 | |||
| 21367 | if (NILP (vpos)) | ||
| 21368 | { | ||
| 21369 | int d1, d2, d3, d4, d5; | ||
| 21370 | |||
| 21371 | pos_visible_p (w, PT, &d1, &d2, &d3, &d4, &d5, &nrow); | ||
| 21372 | } | ||
| 21373 | else | ||
| 21374 | { | ||
| 21375 | CHECK_NUMBER_COERCE_MARKER (vpos); | ||
| 21376 | nrow = XINT (vpos); | ||
| 21377 | } | ||
| 21378 | |||
| 21379 | /* We require up-to-date glyph matrix for this window. */ | ||
| 21380 | if (w->window_end_valid | ||
| 21381 | && !windows_or_buffers_changed | ||
| 21382 | && b | ||
| 21383 | && !b->clip_changed | ||
| 21384 | && !b->prevent_redisplay_optimizations_p | ||
| 21385 | && !window_outdated (w) | ||
| 21386 | && nrow >= 0 | ||
| 21387 | && nrow < w->current_matrix->nrows | ||
| 21388 | && (row = MATRIX_ROW (w->current_matrix, nrow))->enabled_p | ||
| 21389 | && MATRIX_ROW_DISPLAYS_TEXT_P (row)) | ||
| 21390 | { | ||
| 21391 | struct glyph *g, *e, *g1; | ||
| 21392 | int nglyphs, i; | ||
| 21393 | Lisp_Object levels; | ||
| 21394 | |||
| 21395 | if (!row->reversed_p) /* Left-to-right glyph row. */ | ||
| 21396 | { | ||
| 21397 | g = g1 = row->glyphs[TEXT_AREA]; | ||
| 21398 | e = g + row->used[TEXT_AREA]; | ||
| 21399 | |||
| 21400 | /* Skip over glyphs at the start of the row that was | ||
| 21401 | generated by redisplay for its own needs. */ | ||
| 21402 | while (g < e | ||
| 21403 | && INTEGERP (g->object) | ||
| 21404 | && g->charpos < 0) | ||
| 21405 | g++; | ||
| 21406 | g1 = g; | ||
| 21407 | |||
| 21408 | /* Count the "interesting" glyphs in this row. */ | ||
| 21409 | for (nglyphs = 0; g < e && !INTEGERP (g->object); g++) | ||
| 21410 | nglyphs++; | ||
| 21411 | |||
| 21412 | /* Create and fill the array. */ | ||
| 21413 | levels = make_uninit_vector (nglyphs); | ||
| 21414 | for (i = 0; g1 < g; i++, g1++) | ||
| 21415 | ASET (levels, i, make_number (g1->resolved_level)); | ||
| 21416 | } | ||
| 21417 | else /* Right-to-left glyph row. */ | ||
| 21418 | { | ||
| 21419 | g = row->glyphs[TEXT_AREA] + row->used[TEXT_AREA] - 1; | ||
| 21420 | e = row->glyphs[TEXT_AREA] - 1; | ||
| 21421 | while (g > e | ||
| 21422 | && INTEGERP (g->object) | ||
| 21423 | && g->charpos < 0) | ||
| 21424 | g--; | ||
| 21425 | g1 = g; | ||
| 21426 | for (nglyphs = 0; g > e && !INTEGERP (g->object); g--) | ||
| 21427 | nglyphs++; | ||
| 21428 | levels = make_uninit_vector (nglyphs); | ||
| 21429 | for (i = 0; g1 > g; i++, g1--) | ||
| 21430 | ASET (levels, i, make_number (g1->resolved_level)); | ||
| 21431 | } | ||
| 21432 | return levels; | ||
| 21433 | } | ||
| 21434 | else | ||
| 21435 | return Qnil; | ||
| 21436 | } | ||
| 21437 | |||
| 21438 | |||
| 21331 | 21439 | ||
| 21332 | /*********************************************************************** | 21440 | /*********************************************************************** |
| 21333 | Menu Bar | 21441 | Menu Bar |
| @@ -30293,6 +30401,7 @@ syms_of_xdisp (void) | |||
| 30293 | 30401 | ||
| 30294 | DEFSYM (Qright_to_left, "right-to-left"); | 30402 | DEFSYM (Qright_to_left, "right-to-left"); |
| 30295 | DEFSYM (Qleft_to_right, "left-to-right"); | 30403 | DEFSYM (Qleft_to_right, "left-to-right"); |
| 30404 | defsubr (&Sbidi_resolved_levels); | ||
| 30296 | 30405 | ||
| 30297 | #ifdef HAVE_WINDOW_SYSTEM | 30406 | #ifdef HAVE_WINDOW_SYSTEM |
| 30298 | DEFVAR_BOOL ("x-stretch-cursor", x_stretch_cursor_p, | 30407 | DEFVAR_BOOL ("x-stretch-cursor", x_stretch_cursor_p, |