From: Eli Zaretskii Date: Sat, 24 Jun 2017 13:58:01 +0000 (+0300) Subject: Allow Lisp program to disable line-number display for specific lines X-Git-Tag: emacs-26.0.90~518^2~156^2~26 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=6e18841b17c9b7ca9f38b923db4195cade05da2e;p=emacs.git Allow Lisp program to disable line-number display for specific lines * etc/NEWS: Update the documentation. * src/xdisp.c (syms_of_xdisp) : New symbol. (should_produce_line_number): New function. (display_line): Use should_produce_line_number to determine whether a line number should be produced for each glyph row. --- diff --git a/etc/NEWS b/etc/NEWS index 03204beb9ee..b125b89370f 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -386,7 +386,10 @@ before the line. If set to 'relative', Emacs will display the line number relative to the line showing point. The default is nil, which doesn't display the line numbers. -The new face 'line-number' is used to display the line numbers. +The new face 'line-number' is used to display the line numbers. The +new face 'line-number-current-line' can be customized to display the +current line's number differently from all the other line numbers; by +default these two faces are identical. You can also customize the new variable 'display-line-number-width' to specify a fixed minimal with of the area allocated to line-number @@ -396,6 +399,10 @@ non-negative integer specifies that as the minimal width; selecting a value that is large enough to display all line numbers in a buffer will keep the line-number display area of constant width. +Lisp programs can disable line-number display for a particular screen +line by putting the 'display-line-numbers-disable' text property or +overlay property on the first character of that screen line. + Linum mode and all similar packages are henceforth becoming obsolete. Users and developers are encouraged to switch to this new feature instead. diff --git a/src/xdisp.c b/src/xdisp.c index cf396de203e..d35170ed43e 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -20887,6 +20887,32 @@ maybe_produce_line_number (struct it *it) bidi_unshelve_cache (itdata, false); } +/* Return true if this glyph row needs a line number to be produced + for it. */ +static bool +should_produce_line_number (struct it *it) +{ + if (NILP (Vdisplay_line_numbers)) + return false; + + /* Don't display line numbers in minibuffer windows. */ + if (MINI_WINDOW_P (it->w)) + return false; + +#ifdef HAVE_WINDOW_SYSTEM + /* Don't display line number in tooltip frames. */ + if (FRAMEP (tip_frame) && EQ (WINDOW_FRAME (it->w), tip_frame)) + return false; +#endif + + /* If the character at current position has a non-nil special + property, disable line numbers for this row. */ + Lisp_Object val = Fget_char_property (make_number (IT_CHARPOS (*it)), + Qdisplay_line_numbers_disable, + it->window); + return NILP (val) ? true : false; +} + /* Return true if ROW has no glyphs except those inserted by the display engine. This is needed for indicate-empty-lines and similar features when the glyph row starts with glyphs which didn't @@ -20984,6 +21010,8 @@ display_line (struct it *it, int cursor_vpos) (window_hscroll_limited (it->w, it->f) - it->w->min_hscroll) * FRAME_COLUMN_WIDTH (it->f); + bool line_number_needed = should_produce_line_number (it); + /* Move over display elements that are not visible because we are hscrolled. This may stop at an x-position < first_visible_x if the first glyph is partially visible or if we hit a line end. */ @@ -21021,23 +21049,13 @@ display_line (struct it *it, int cursor_vpos) min_bpos = BYTEPOS (this_line_min_pos); /* Produce line number, if needed. */ - if (!NILP (Vdisplay_line_numbers) -#ifdef HAVE_WINDOW_SYSTEM - && !(FRAMEP (tip_frame) - && EQ (WINDOW_FRAME (it->w), tip_frame)) -#endif - && (!MINI_WINDOW_P (it->w))) + if (line_number_needed) maybe_produce_line_number (it); } else if (it->area == TEXT_AREA) { /* Line numbers should precede the line-prefix or wrap-prefix. */ - if (!NILP (Vdisplay_line_numbers) -#ifdef HAVE_WINDOW_SYSTEM - && !(FRAMEP (tip_frame) - && EQ (WINDOW_FRAME (it->w), tip_frame)) -#endif - && (!MINI_WINDOW_P (it->w))) + if (line_number_needed) maybe_produce_line_number (it); /* We only do this when not calling move_it_in_display_line_to @@ -21203,13 +21221,7 @@ display_line (struct it *it, int cursor_vpos) if (it->area == TEXT_AREA && pending_handle_line_prefix) { /* Line numbers should precede the line-prefix or wrap-prefix. */ - if (!NILP (Vdisplay_line_numbers) -#ifdef HAVE_WINDOW_SYSTEM - && !(FRAMEP (tip_frame) - && EQ (WINDOW_FRAME (it->w), tip_frame)) -#endif - && (!MINI_WINDOW_P (it->w) - || (minibuf_level && EQ (it->window, minibuf_window)))) + if (line_number_needed) maybe_produce_line_number (it); pending_handle_line_prefix = false; @@ -31905,6 +31917,8 @@ They are still logged to the *Messages* buffer. */); /* Names of the faces used to display line numbers. */ DEFSYM (Qline_number, "line-number"); DEFSYM (Qline_number_current_line, "line-number-current-line"); + /* Name of a text property which disables line-number display. */ + DEFSYM (Qdisplay_line_numbers_disable, "display-line-numbers-disable"); /* Name and number of the face used to highlight escape glyphs. */ DEFSYM (Qescape_glyph, "escape-glyph");