diff options
| author | Eli Zaretskii | 2017-06-24 15:45:23 +0300 |
|---|---|---|
| committer | Eli Zaretskii | 2017-06-24 15:45:23 +0300 |
| commit | 71a7294d0a775a8969ec077eb3633da6bdad7c62 (patch) | |
| tree | 7ba8cad1e5ace7421e0412db94e184e82e0bc42b /src | |
| parent | fa5e84cccd31cf94074255180d6ff3a44d4f8f89 (diff) | |
| download | emacs-71a7294d0a775a8969ec077eb3633da6bdad7c62.tar.gz emacs-71a7294d0a775a8969ec077eb3633da6bdad7c62.zip | |
Support a separate face for displaying the current line's number
* lisp/faces.el (line-number-current-line): New face.
* src/xdisp.c (syms_of_xdisp) <line-number-current-line>: New
symbol.
(try_window_id, try_cursor_movement): Disable these optimizations
when the line-number-current-line face is different from
line-number face.
(maybe_produce_line_number): Display the current line in the
line-number-current-line face, if it's different from line-number.
Diffstat (limited to 'src')
| -rw-r--r-- | src/xdisp.c | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/src/xdisp.c b/src/xdisp.c index 8acba259d2f..cf396de203e 100644 --- a/src/xdisp.c +++ b/src/xdisp.c | |||
| @@ -15940,6 +15940,13 @@ try_cursor_movement (Lisp_Object window, struct text_pos startp, | |||
| 15940 | /* When display-line-numbers is in relative mode, moving point | 15940 | /* When display-line-numbers is in relative mode, moving point |
| 15941 | requires to redraw the entire window. */ | 15941 | requires to redraw the entire window. */ |
| 15942 | && !EQ (Vdisplay_line_numbers, Qrelative) | 15942 | && !EQ (Vdisplay_line_numbers, Qrelative) |
| 15943 | /* When the current line number should be displayed in a | ||
| 15944 | distinct face, moving point cannot be handled in optimized | ||
| 15945 | way as below. */ | ||
| 15946 | && !(!NILP (Vdisplay_line_numbers) | ||
| 15947 | && NILP (Finternal_lisp_face_equal_p (Qline_number, | ||
| 15948 | Qline_number_current_line, | ||
| 15949 | w->frame))) | ||
| 15943 | /* This code is not used for mini-buffer for the sake of the case | 15950 | /* This code is not used for mini-buffer for the sake of the case |
| 15944 | of redisplaying to replace an echo area message; since in | 15951 | of redisplaying to replace an echo area message; since in |
| 15945 | that case the mini-buffer contents per se are usually | 15952 | that case the mini-buffer contents per se are usually |
| @@ -18445,8 +18452,13 @@ try_window_id (struct window *w) | |||
| 18445 | if (!NILP (BVAR (XBUFFER (w->contents), extra_line_spacing))) | 18452 | if (!NILP (BVAR (XBUFFER (w->contents), extra_line_spacing))) |
| 18446 | GIVE_UP (23); | 18453 | GIVE_UP (23); |
| 18447 | 18454 | ||
| 18448 | /* Give up if display-line-numbers is in relative mode. */ | 18455 | /* Give up if display-line-numbers is in relative mode, or when the |
| 18449 | if (EQ (Vdisplay_line_numbers, Qrelative)) | 18456 | current line's number needs to be displayed in a distinct face. */ |
| 18457 | if (EQ (Vdisplay_line_numbers, Qrelative) | ||
| 18458 | || (!NILP (Vdisplay_line_numbers) | ||
| 18459 | && NILP (Finternal_lisp_face_equal_p (Qline_number, | ||
| 18460 | Qline_number_current_line, | ||
| 18461 | w->frame)))) | ||
| 18450 | GIVE_UP (24); | 18462 | GIVE_UP (24); |
| 18451 | 18463 | ||
| 18452 | /* Make sure beg_unchanged and end_unchanged are up to date. Do it | 18464 | /* Make sure beg_unchanged and end_unchanged are up to date. Do it |
| @@ -20739,8 +20751,13 @@ maybe_produce_line_number (struct it *it) | |||
| 20739 | char lnum_buf[INT_STRLEN_BOUND (ptrdiff_t) + 1]; | 20751 | char lnum_buf[INT_STRLEN_BOUND (ptrdiff_t) + 1]; |
| 20740 | bool beyond_zv = IT_BYTEPOS (*it) >= ZV_BYTE ? true : false; | 20752 | bool beyond_zv = IT_BYTEPOS (*it) >= ZV_BYTE ? true : false; |
| 20741 | ptrdiff_t lnum_offset = -1; /* to produce 1-based line numbers */ | 20753 | ptrdiff_t lnum_offset = -1; /* to produce 1-based line numbers */ |
| 20754 | int lnum_face_id = merge_faces (it->f, Qline_number, 0, DEFAULT_FACE_ID); | ||
| 20755 | int current_lnum_face_id | ||
| 20756 | = merge_faces (it->f, Qline_number_current_line, 0, DEFAULT_FACE_ID); | ||
| 20742 | /* Compute point's line number if needed. */ | 20757 | /* Compute point's line number if needed. */ |
| 20743 | if (EQ (Vdisplay_line_numbers, Qrelative) && !it->pt_lnum) | 20758 | if ((EQ (Vdisplay_line_numbers, Qrelative) |
| 20759 | || lnum_face_id != current_lnum_face_id) | ||
| 20760 | && !it->pt_lnum) | ||
| 20744 | { | 20761 | { |
| 20745 | ptrdiff_t ignored; | 20762 | ptrdiff_t ignored; |
| 20746 | if (PT_BYTE > it->lnum_bytepos) | 20763 | if (PT_BYTE > it->lnum_bytepos) |
| @@ -20803,7 +20820,6 @@ maybe_produce_line_number (struct it *it) | |||
| 20803 | 20820 | ||
| 20804 | /* Produce glyphs for the line number in a scratch glyph_row. */ | 20821 | /* Produce glyphs for the line number in a scratch glyph_row. */ |
| 20805 | int n_glyphs_before; | 20822 | int n_glyphs_before; |
| 20806 | int lnum_face_id = merge_faces (it->f, Qline_number, 0, DEFAULT_FACE_ID); | ||
| 20807 | for (const char *p = lnum_buf; *p; p++) | 20823 | for (const char *p = lnum_buf; *p; p++) |
| 20808 | { | 20824 | { |
| 20809 | /* For continuation lines and lines after ZV, instead of a line | 20825 | /* For continuation lines and lines after ZV, instead of a line |
| @@ -20811,6 +20827,8 @@ maybe_produce_line_number (struct it *it) | |||
| 20811 | default face for the blank field beyond ZV. */ | 20827 | default face for the blank field beyond ZV. */ |
| 20812 | if (beyond_zv) | 20828 | if (beyond_zv) |
| 20813 | tem_it.face_id = it->base_face_id; | 20829 | tem_it.face_id = it->base_face_id; |
| 20830 | else if (lnum_face_id != current_lnum_face_id && this_line == it->pt_lnum) | ||
| 20831 | tem_it.face_id = current_lnum_face_id; | ||
| 20814 | else | 20832 | else |
| 20815 | tem_it.face_id = lnum_face_id; | 20833 | tem_it.face_id = lnum_face_id; |
| 20816 | if (beyond_zv || it->continuation_lines_width > 0) | 20834 | if (beyond_zv || it->continuation_lines_width > 0) |
| @@ -31884,8 +31902,9 @@ They are still logged to the *Messages* buffer. */); | |||
| 31884 | /* Name of the face used to highlight trailing whitespace. */ | 31902 | /* Name of the face used to highlight trailing whitespace. */ |
| 31885 | DEFSYM (Qtrailing_whitespace, "trailing-whitespace"); | 31903 | DEFSYM (Qtrailing_whitespace, "trailing-whitespace"); |
| 31886 | 31904 | ||
| 31887 | /* Name of the face used to display line numbers. */ | 31905 | /* Names of the faces used to display line numbers. */ |
| 31888 | DEFSYM (Qline_number, "line-number"); | 31906 | DEFSYM (Qline_number, "line-number"); |
| 31907 | DEFSYM (Qline_number_current_line, "line-number-current-line"); | ||
| 31889 | 31908 | ||
| 31890 | /* Name and number of the face used to highlight escape glyphs. */ | 31909 | /* Name and number of the face used to highlight escape glyphs. */ |
| 31891 | DEFSYM (Qescape_glyph, "escape-glyph"); | 31910 | DEFSYM (Qescape_glyph, "escape-glyph"); |