From: Eli Zaretskii Date: Sat, 8 Jul 2017 07:49:36 +0000 (+0300) Subject: Support display of line numbers natively X-Git-Tag: emacs-26.0.90~518^2~156 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=5df239fc6ffbbb16ea6e5546fbec1508bf2cb4b7;p=emacs.git Support display of line numbers natively This merges branch 'line-numbers'. * src/buffer.c (disable_line_numbers_overlay_at_eob): New function. * src/lisp.h (disable_line_numbers_overlay_at_eob): Add prototype. * src/dispextern.h (struct it): New members pt_lnum, lnum, lnum_bytepos, lnum_width, and lnum_pixel_width. * src/indent.c (line_number_display_width): New function, refactored from line-number width calculations in vertical-motion. (Fvertical_motion): Call line_number_display_width when the width of line-number display is needed. (Fline_number_display_width): New defun. (syms_of_indent): Defsubr it. * src/indent.c (Fvertical_motion): Help C-n/C-p estimate correctly the width used up by line numbers by looking near the window-start point. If window-start is outside of the accessible portion, temporarily widen the buffer. * src/term.c (produce_glyphs): Adjust tab stops for the horizontal space taken by the line-number display. * src/xdisp.c (display_count_lines_logically) (display_count_lines_visually, maybe_produce_line_number) (should_produce_line_number, row_text_area_empty): New functions. (try_window_reusing_current_matrix): Don't use this method when display-line-numbers is in effect. (try_window_id, try_cursor_movement): Disable these optimizations when the line-number-current-line face is different from line-number face and for relative line numbers. (try_window_id, redisplay_window, try_cursor_movement): For visual line-number display, disable the same redisplay optimizations as for relative. (x_produce_glyphs): Adjust tab stops for the horizontal space taken by the line-number display. (hscroll_window_tree): Adjust hscroll calculations to line-number display. (DISP_INFINITY): Renamed from INFINITY to avoid clashes with math.h; all users changed. (set_cursor_from_row): Fix calculation of cursor X coordinate in R2L rows with display-produced glyphs at the beginning. (display_line): Use should_produce_line_number to determine whether a line number should be produced for each glyph row, and maybe_produce_line_number to produce line numbers. Don't display line numbers in the minibuffer and in tooltip frames. Call row_text_area_empty to verify that a glyph row's text area is devoid of any glyphs that came from a buffer or a string. This fixes a bug with empty-lines indication disappearing when line numbers or line-prefix are displayed. (syms_of_xdisp) : New buffer-local variables. : New variable. * lisp/cus-start.el (standard): Provide customization forms for display-line-numbers and its sub-features. * lisp/faces.el (line-number, line-number-current-line): New faces. * lisp/frame.el: Add display-line-numbers, display-line-numbers-widen, display-line-numbers-current-absolute, and display-line-number-width to the list of variables that should trigger redisplay of the current buffer. * lisp/menu-bar.el (menu-bar-showhide-menu): Add menu-bar item to turn display-line-numbers on and off. (toggle-display-line-numbers): New function. * lisp/simple.el (last--line-number-width): New internal variable. (line-move-visual): Use it to adjust temporary-goal-column when line-number display changes its width. * doc/emacs/basic.texi (Position Info): Add cross-reference to "Display Custom", for line-number display. * doc/emacs/custom.texi (Init Rebinding): * doc/emacs/modes.texi (Minor Modes): Remove references to linum-mode. * doc/emacs/display.texi (Display Custom): Describe the line-number display. * doc/lispref/display.texi (Size of Displayed Text): Document line-number-display-width. * etc/NEWS: Document display-line-numbers and its customizations. --- 5df239fc6ffbbb16ea6e5546fbec1508bf2cb4b7 diff --cc etc/NEWS index 13805ce0da7,79eb3919e6d..15c3009ae10 --- a/etc/NEWS +++ b/etc/NEWS @@@ -405,10 -377,57 +405,60 @@@ display of raw bytes from octal to hex ** You can now provide explicit field numbers in format specifiers. For example, '(format "%2$s %1$s" "X" "Y")' produces "Y X". - +++ +** 'comment-indent-function' values may now return a cons to specify a +range of indentation. + + +++ + ** Emacs now supports optional display of line numbers in the buffer. + This is similar to what linum-mode provides, but much faster and + doesn't usurp the display margin for the line numbers. Customize the + buffer-local variable 'display-line-numbers' to activate this optional + display. If set to t, Emacs will display the number of each line + before the line. If set to 'relative', Emacs will display the line + number relative to the line showing point, with that line's number + displayed as absolute. If set to 'visual', Emacs will display a + relative number for every screen line, i.e. it will count screen lines + rather than buffer lines. The default is nil, which doesn't display + the line numbers. + + In 'relative' and 'visual' modes, the variable + 'display-line-numbers-current-absolute' controls what number is + displayed for the line showing point. By default, this variable's + value is t, which means display the absolute line number for the line + showing point. Customizing this variable to a nil value will cause + Emacs to show zero instead, which preserves horizontal space of the + window in large buffers. + + Line numbers are not displayed at all in minibuffer windows and in + tooltips, as they are not useful there. + + 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 + display. The default is nil, meaning that Emacs will dynamically + calculate the area width, enlarging or shrinking it as needed. + Setting it to a 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 then keep the line-number display area of + constant width at all times, if that is desired. + + 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. This is + intended for add-on packages that need a finer control of the display. + + Lisp programs that need to know how much screen estate is used up for + line-number display in a window can use the new function + 'line-number-display-width'. + + Linum mode and all similar packages are henceforth becoming obsolete. + Users and developers are encouraged to switch to this new feature + instead. + * Editing Changes in Emacs 26.1