[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] scratch/line-numbers 6e18841 11/14: Allow Lisp program to
From: |
Eli Zaretskii |
Subject: |
[Emacs-diffs] scratch/line-numbers 6e18841 11/14: Allow Lisp program to disable line-number display for specific lines |
Date: |
Sat, 24 Jun 2017 13:12:53 -0400 (EDT) |
branch: scratch/line-numbers
commit 6e18841b17c9b7ca9f38b923db4195cade05da2e
Author: Eli Zaretskii <address@hidden>
Commit: Eli Zaretskii <address@hidden>
Allow Lisp program to disable line-number display for specific lines
* etc/NEWS: Update the documentation.
* src/xdisp.c (syms_of_xdisp) <display-line-numbers-disable>: 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.
---
etc/NEWS | 9 ++++++++-
src/xdisp.c | 52 +++++++++++++++++++++++++++++++++-------------------
2 files changed, 41 insertions(+), 20 deletions(-)
diff --git a/etc/NEWS b/etc/NEWS
index 03204be..b125b89 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 cf396de..d35170e 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");
- [Emacs-diffs] scratch/line-numbers 9776d7b 05/14: Don't display line numbers in the minibuffer and in tooltip frames., (continued)
- [Emacs-diffs] scratch/line-numbers 9776d7b 05/14: Don't display line numbers in the minibuffer and in tooltip frames., Eli Zaretskii, 2017/06/24
- [Emacs-diffs] scratch/line-numbers ead4ab6 14/14: Improve documentation in NEWS., Eli Zaretskii, 2017/06/24
- [Emacs-diffs] scratch/line-numbers efedb66 08/14: Rename display-line-width, Eli Zaretskii, 2017/06/24
- [Emacs-diffs] scratch/line-numbers 13cc19a 12/14: Partial fix of hscroll of truncated lines with line numbers, Eli Zaretskii, 2017/06/24
- [Emacs-diffs] scratch/line-numbers 7d7602c 06/14: Fix crashes on TTY frames due to negative lnum_width., Eli Zaretskii, 2017/06/24
- [Emacs-diffs] scratch/line-numbers 55a9298 07/14: Fix tab stops when line numbers are displayed, Eli Zaretskii, 2017/06/24
- [Emacs-diffs] scratch/line-numbers 71a7294 10/14: Support a separate face for displaying the current line's number, Eli Zaretskii, 2017/06/24
- [Emacs-diffs] scratch/line-numbers d4eddb0 01/14: Fix display of indicate-empty-lines when line numbers are displayed, Eli Zaretskii, 2017/06/24
- [Emacs-diffs] scratch/line-numbers 0d5c713 13/14: Move additional hscrolling code into a suitable 'if', Eli Zaretskii, 2017/06/24
- [Emacs-diffs] scratch/line-numbers fa5e84c 09/14: Change display of current line in relative mode, Eli Zaretskii, 2017/06/24
- [Emacs-diffs] scratch/line-numbers 6e18841 11/14: Allow Lisp program to disable line-number display for specific lines,
Eli Zaretskii <=