diff options
| author | Eli Zaretskii | 2017-07-08 10:49:36 +0300 |
|---|---|---|
| committer | Eli Zaretskii | 2017-07-08 10:49:36 +0300 |
| commit | 5df239fc6ffbbb16ea6e5546fbec1508bf2cb4b7 (patch) | |
| tree | 9b1b8baff1c3ca9c9c560460b34a7951723f621c /doc | |
| parent | b8ead34f5df92b771520f4d090ff6cde49ca5705 (diff) | |
| parent | 13786d5e7d0aa0a37d7f81d1a1b82eddd3472796 (diff) | |
| download | emacs-5df239fc6ffbbb16ea6e5546fbec1508bf2cb4b7.tar.gz emacs-5df239fc6ffbbb16ea6e5546fbec1508bf2cb4b7.zip | |
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) <display-line-numbers, display-line-numbers-widen>
<display-line-number-width>: New buffer-local variables.
<display-line-numbers-current-absolute>: 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.
Diffstat (limited to 'doc')
| -rw-r--r-- | doc/emacs/basic.texi | 3 | ||||
| -rw-r--r-- | doc/emacs/custom.texi | 1 | ||||
| -rw-r--r-- | doc/emacs/display.texi | 62 | ||||
| -rw-r--r-- | doc/emacs/modes.texi | 5 | ||||
| -rw-r--r-- | doc/lispref/display.texi | 17 |
5 files changed, 80 insertions, 8 deletions
diff --git a/doc/emacs/basic.texi b/doc/emacs/basic.texi index 6b66c18016b..5878e7da256 100644 --- a/doc/emacs/basic.texi +++ b/doc/emacs/basic.texi | |||
| @@ -630,7 +630,8 @@ Display the line number of point. | |||
| 630 | @item M-x line-number-mode | 630 | @item M-x line-number-mode |
| 631 | @itemx M-x column-number-mode | 631 | @itemx M-x column-number-mode |
| 632 | Toggle automatic display of the current line number or column number. | 632 | Toggle automatic display of the current line number or column number. |
| 633 | @xref{Optional Mode Line}. | 633 | @xref{Optional Mode Line}. If you want to have a line number |
| 634 | displayed before each line, see @ref{Display Custom}. | ||
| 634 | 635 | ||
| 635 | @item M-= | 636 | @item M-= |
| 636 | Display the number of lines, words, and characters that are present in | 637 | Display the number of lines, words, and characters that are present in |
diff --git a/doc/emacs/custom.texi b/doc/emacs/custom.texi index c84f4a975d8..a756a89e3f8 100644 --- a/doc/emacs/custom.texi +++ b/doc/emacs/custom.texi | |||
| @@ -1701,7 +1701,6 @@ and mouse events: | |||
| 1701 | (global-set-key (kbd "C-c y") 'clipboard-yank) | 1701 | (global-set-key (kbd "C-c y") 'clipboard-yank) |
| 1702 | (global-set-key (kbd "C-M-q") 'query-replace) | 1702 | (global-set-key (kbd "C-M-q") 'query-replace) |
| 1703 | (global-set-key (kbd "<f5>") 'flyspell-mode) | 1703 | (global-set-key (kbd "<f5>") 'flyspell-mode) |
| 1704 | (global-set-key (kbd "C-<f5>") 'linum-mode) | ||
| 1705 | (global-set-key (kbd "C-<right>") 'forward-sentence) | 1704 | (global-set-key (kbd "C-<right>") 'forward-sentence) |
| 1706 | (global-set-key (kbd "<mouse-2>") 'mouse-save-then-kill) | 1705 | (global-set-key (kbd "<mouse-2>") 'mouse-save-then-kill) |
| 1707 | @end example | 1706 | @end example |
diff --git a/doc/emacs/display.texi b/doc/emacs/display.texi index c4554eb3187..083fcdf97a6 100644 --- a/doc/emacs/display.texi +++ b/doc/emacs/display.texi | |||
| @@ -1333,7 +1333,7 @@ characters in the buffer, which means that @samp{k} for 10^3, @samp{M} | |||
| 1333 | for 10^6, @samp{G} for 10^9, etc., are used to abbreviate. | 1333 | for 10^6, @samp{G} for 10^9, etc., are used to abbreviate. |
| 1334 | 1334 | ||
| 1335 | @cindex line number display | 1335 | @cindex line number display |
| 1336 | @cindex display of line number | 1336 | @cindex display of current line number |
| 1337 | @findex line-number-mode | 1337 | @findex line-number-mode |
| 1338 | The current line number of point appears in the mode line when Line | 1338 | The current line number of point appears in the mode line when Line |
| 1339 | Number mode is enabled. Use the command @kbd{M-x line-number-mode} to | 1339 | Number mode is enabled. Use the command @kbd{M-x line-number-mode} to |
| @@ -1710,6 +1710,66 @@ variable @code{visual-line-fringe-indicators}. | |||
| 1710 | This section describes variables that control miscellaneous aspects | 1710 | This section describes variables that control miscellaneous aspects |
| 1711 | of the appearance of the Emacs screen. Beginning users can skip it. | 1711 | of the appearance of the Emacs screen. Beginning users can skip it. |
| 1712 | 1712 | ||
| 1713 | @vindex display-line-numbers | ||
| 1714 | @cindex number lines in a buffer | ||
| 1715 | @cindex display line numbers | ||
| 1716 | If you want to have Emacs display line numbers for every line in the | ||
| 1717 | buffer, customize the buffer-local variable | ||
| 1718 | @code{display-line-numbers}; it is @code{nil} by default. This | ||
| 1719 | variable can have several different values to support various modes of | ||
| 1720 | line-number display: | ||
| 1721 | |||
| 1722 | @table @asis | ||
| 1723 | @item @code{t} | ||
| 1724 | Display (an absolute) line number before each non-continuation screen | ||
| 1725 | line that displays buffer text. If the line is a continuation line, | ||
| 1726 | or if the entire screen line displays a display or an overlay string, | ||
| 1727 | that line will not be numbered. | ||
| 1728 | |||
| 1729 | @item @code{relative} | ||
| 1730 | Display relative line numbers before non-continuation lines which show | ||
| 1731 | buffer text. The line numbers are relative to the line showing point, | ||
| 1732 | so the numbers grow both up and down as lines become farther from the | ||
| 1733 | current line. | ||
| 1734 | |||
| 1735 | @item @code{visual} | ||
| 1736 | This value causes Emacs to count lines visually: only lines actually | ||
| 1737 | shown on the display will be counted (disregarding any lines in | ||
| 1738 | invisible parts of text), and lines which wrap to consume more than | ||
| 1739 | one screen line will be numbered that many times. The displayed | ||
| 1740 | numbers are relative, as with @code{relative} value above. This is | ||
| 1741 | handy in modes that fold text, such as Outline mode (@pxref{Outline | ||
| 1742 | Mode}), and need to move by exact number of screen lines. | ||
| 1743 | |||
| 1744 | @item anything else | ||
| 1745 | Any other non-@code{nil} value is treated as @code{t}. | ||
| 1746 | @end table | ||
| 1747 | |||
| 1748 | @vindex display-line-numbers-current-absolute | ||
| 1749 | When Emacs displays relative line numbers, you can control the number | ||
| 1750 | displayed before the current line, the line showing point. By | ||
| 1751 | default, Emacs displays the absolute number of the current line there, | ||
| 1752 | even though all the other line numbers are relative. If you customize | ||
| 1753 | the variable @code{display-line-numbers-current-absolute} to a | ||
| 1754 | @code{nil} value, the number displayed for the current line will be | ||
| 1755 | zero. This is handy if you don't care about the number of the current | ||
| 1756 | line, and want to leave more horizontal space for text in large | ||
| 1757 | buffers. | ||
| 1758 | |||
| 1759 | @vindex display-line-numbers-widen | ||
| 1760 | In a narrowed buffer (@pxref{Narrowing}) lines are normally numbered | ||
| 1761 | starting at the beginning of the narrowing. However, if you customize | ||
| 1762 | the variable @code{display-line-numbers-widen} to a non-@code{nil} | ||
| 1763 | value, line numbers will disregard any narrowing and will start at the | ||
| 1764 | first character of the buffer. | ||
| 1765 | |||
| 1766 | @cindex line-number face | ||
| 1767 | The line numbers are displayed in a special face @code{line-number}. | ||
| 1768 | The current line number is displayed in a different face, | ||
| 1769 | @code{line-number-current-line}, so you can make the current line's | ||
| 1770 | number have a distinct appearance, which will help locating the line | ||
| 1771 | showing point. | ||
| 1772 | |||
| 1713 | @vindex visible-bell | 1773 | @vindex visible-bell |
| 1714 | If the variable @code{visible-bell} is non-@code{nil}, Emacs attempts | 1774 | If the variable @code{visible-bell} is non-@code{nil}, Emacs attempts |
| 1715 | to make the whole screen blink when it would normally make an audible bell | 1775 | to make the whole screen blink when it would normally make an audible bell |
diff --git a/doc/emacs/modes.texi b/doc/emacs/modes.texi index be893403012..eb0c88b2901 100644 --- a/doc/emacs/modes.texi +++ b/doc/emacs/modes.texi | |||
| @@ -225,11 +225,6 @@ Font-Lock mode automatically highlights certain textual units found in | |||
| 225 | programs. It is enabled globally by default, but you can disable it | 225 | programs. It is enabled globally by default, but you can disable it |
| 226 | in individual buffers. @xref{Faces}. | 226 | in individual buffers. @xref{Faces}. |
| 227 | 227 | ||
| 228 | @findex linum-mode | ||
| 229 | @cindex Linum mode | ||
| 230 | @item | ||
| 231 | Linum mode displays each line's line number in the window's left margin. | ||
| 232 | |||
| 233 | @item | 228 | @item |
| 234 | Outline minor mode provides similar facilities to the major mode | 229 | Outline minor mode provides similar facilities to the major mode |
| 235 | called Outline mode. @xref{Outline Mode}. | 230 | called Outline mode. @xref{Outline Mode}. |
diff --git a/doc/lispref/display.texi b/doc/lispref/display.texi index 2ebe872c362..005d31af05a 100644 --- a/doc/lispref/display.texi +++ b/doc/lispref/display.texi | |||
| @@ -2045,6 +2045,23 @@ selected window. The value includes the line spacing of the line | |||
| 2045 | (@pxref{Line Height}). | 2045 | (@pxref{Line Height}). |
| 2046 | @end defun | 2046 | @end defun |
| 2047 | 2047 | ||
| 2048 | When a buffer is displayed with line numbers (@pxref{Display Custom,,, | ||
| 2049 | emacs, The GNU Emacs Manual}), it is sometimes useful to know the | ||
| 2050 | width taken for displaying the line numbers. The following function | ||
| 2051 | is for Lisp programs which need this information for layout | ||
| 2052 | calculations. | ||
| 2053 | |||
| 2054 | @defun line-number-display-width &optional pixelwise | ||
| 2055 | This function returns the width used for displaying the line numbers | ||
| 2056 | in the selected window. Optional argument @var{pixelwise}, if | ||
| 2057 | non-@code{nil}, means return the value in pixels; otherwise the value | ||
| 2058 | is returned in column units of the font defined for the | ||
| 2059 | @code{line-number} face. If line numbers are not displayed in the | ||
| 2060 | selected window, the value is zero. Use @code{with-selected-window} | ||
| 2061 | (@pxref{Selecting Windows}) if you need this information about another | ||
| 2062 | window. | ||
| 2063 | @end defun | ||
| 2064 | |||
| 2048 | 2065 | ||
| 2049 | @node Line Height | 2066 | @node Line Height |
| 2050 | @section Line Height | 2067 | @section Line Height |