From 73b302f9122f86d24d360dc185366c82d5906fb6 Mon Sep 17 00:00:00 2001 From: Jimmy Aguilar Mena Date: Fri, 3 May 2019 19:27:59 +0200 Subject: ;Corrected display-fill-column-indicator mode. Small corrections in the documentation and code format to merge into master. --- doc/emacs/display.texi | 7 +-- etc/NEWS | 25 +--------- lisp/cus-start.el | 11 +++-- lisp/display-fill-column-indicator.el | 10 ++-- lisp/faces.el | 10 ++-- src/xdisp.c | 93 ++++++++++++++++++----------------- 6 files changed, 69 insertions(+), 87 deletions(-) diff --git a/doc/emacs/display.texi b/doc/emacs/display.texi index e1467a3e0be..34215699b42 100644 --- a/doc/emacs/display.texi +++ b/doc/emacs/display.texi @@ -1181,10 +1181,11 @@ When the mode is enabled through the functions @code{display-fill-column-indicator-mode} or @code{global-display-fill-column-indicator-mode}, the initialization functions check if this variable is @code{non-nil}, otherwise the -initialization tries to set it to U+2502 or '|'. +initialization tries to set it to U+2502 or @sampl{|}. -@item fill-column-face -Specifies the face used to display the indicator it inherits its +@item fill-column-indicator +@vindex fill-column-indicator +Specifies the face used to display the indicator. It inherits its default values from shadow and the default face. @end table diff --git a/etc/NEWS b/etc/NEWS index 80d7f4f24c8..6fcf5187e9a 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -340,7 +340,7 @@ longer. ** Multicolor fonts such as "Noto Color Emoji" can be displayed on Emacs configured with Cairo drawing and linked with cairo >= 1.16.0. ---- ++++ ** Emacs now optionally displays a fill column indicator. This is similar to what 'fill-column-indicator' package provides, but @@ -354,28 +354,7 @@ The indicator is not displayed at all in minibuffer windows and in tooltips, as it is not useful there. There are 2 new buffer local variables and 1 face to customize this -mode: - -*** 'display-fill-column-indicator-column' is the column where the - indicator should be set. It can take positive numerical values for - the column or the special value t. Any other value disables the - indicator. The default value is t. - - When the value is t it means that the variable 'fill-column' will - be used. - -*** 'display-fill-column-indicator-char' is the character used for the - indicator. This character can be any valid char including unicode - ones if the user's font supports them. - - When the mode is enabled throw the functions - 'display-fill-column-indicator-mode' and - 'global-display-fill-column-indicator-mode', they check if there - is a value non-nil for this variable, otherwise the initialization - tries to set it to U+2502 or '|'. - -*** 'fill-column-face' is the face used to display the indicator it - inherits it default values from shadow and the default faces. +mode they are described in the manual "(emacs) Display". * Editing Changes in Emacs 27.1 diff --git a/lisp/cus-start.el b/lisp/cus-start.el index b935776a2df..4c4d5ebb16d 100644 --- a/lisp/cus-start.el +++ b/lisp/cus-start.el @@ -650,11 +650,14 @@ since it could result in memory overflow and make Emacs crash." "26.1") (display-fill-column-indicator display-fill-column-indicator - (choice - (const :tag "Off (nil)" :value nil) - (const :tag "On (t)" :value t)) - "27.1") + boolean "27.1") (display-fill-column-indicator-column display-fill-column-indicator + (choice + (const :tag "Use fill-column variable" + :value t) + (const :tag "Fixed column number" + :value 70 + :format "%v")) integer "27.1") (display-fill-column-indicator-character display-fill-column-indicator character "27.1") diff --git a/lisp/display-fill-column-indicator.el b/lisp/display-fill-column-indicator.el index f6b7352c21b..6d5f5a9f894 100644 --- a/lisp/display-fill-column-indicator.el +++ b/lisp/display-fill-column-indicator.el @@ -1,6 +1,6 @@ ;;; display-fill-column-indicator.el --- interface for display-fill-column-indicator -*- lexical-binding: t -*- -;; Copyright (C) 2017-2019 Free Software Foundation, Inc. +;; Copyright (C) 2019 Free Software Foundation, Inc. ;; Maintainer: emacs-devel@gnu.org ;; Keywords: convenience @@ -37,18 +37,18 @@ ;;; Code: (defgroup display-fill-column-indicator nil - "Display a fill column indicator in th buffer." + "Display a fill column indicator in the buffer." :group 'convenience :group 'display) ;;;###autoload (define-minor-mode display-fill-column-indicator-mode - "Toggle display fill column indicator. + "Toggle display of fill-column indicator. This uses `display-fill-column-indicator' internally. -To change the position of the column displayed by default, -customize `display-fill-column-indicator-column' you can change the +To change the position of the column displayed by default +customize `display-fill-column-indicator-column'. You can change the character for the indicator setting `display-fill-column-indicator-character'." :lighter nil (if display-fill-column-indicator-mode diff --git a/lisp/faces.el b/lisp/faces.el index 121cf7ef1d2..b9332790642 100644 --- a/lisp/faces.el +++ b/lisp/faces.el @@ -2501,15 +2501,11 @@ unwanted effects." :group 'display-line-numbers) ;; Definition stolen from display-line-numbers. -(defface fill-column-face +(defface fill-column-indicator '((t :inherit (shadow default))) - "Face for displaying fill column indicator line. + "Face for displaying fill column indicator. This face is used when `display-fill-column-indicator-mode' is -non-nil. - -If you customize the font of this face, make sure it is a -monospaced font, otherwise the line's characters will not line -up horizontally." +non-nil." :version "27.1" :group 'basic-faces :group 'display-fill-column-indicator) diff --git a/src/xdisp.c b/src/xdisp.c index 080c40c3f38..17827481447 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -379,11 +379,14 @@ static Lisp_Object list_of_error; || *BYTE_POS_ADDR (IT_BYTEPOS (*it)) == '\t')))) \ /* Test all the conditions needed to print the fill column indicator. */ -#define FILL_COLUMN_INDICATOR_NEEDED(it) \ - !NILP (Vdisplay_fill_column_indicator) \ - && (it->continuation_lines_width == 0) \ - && (!NILP (Vdisplay_fill_column_indicator_column)) \ - && FIXNATP (Vdisplay_fill_column_indicator_character) +#define FILL_COLUMN_INDICATOR_NEEDED(it) \ + Vdisplay_fill_column_indicator \ + && (it->continuation_lines_width == 0) \ + && (!NILP (Vdisplay_fill_column_indicator_column)) \ + && FIXNATP (Vdisplay_fill_column_indicator_character) \ + && ((EQ (Vdisplay_fill_column_indicator_column, Qt) \ + && FIXNATP (BVAR (current_buffer, fill_column))) \ + || (FIXNATP (Vdisplay_fill_column_indicator_column))) /* True means print newline to stdout before next mini-buffer message. */ @@ -20168,17 +20171,16 @@ append_space_for_newline (struct it *it, bool default_face_p) /* Corner case for when display-fill-column-indicator-mode is active and the extra character should be added in the - same place than the line */ + same place than the line. */ if ((it->w->pseudo_window_p == 0) && FILL_COLUMN_INDICATOR_NEEDED(it)) { int fill_column_indicator_column = -1; - if (EQ (Vdisplay_fill_column_indicator_column, Qt) - && FIXNATP (BVAR (current_buffer, fill_column))) + if (EQ (Vdisplay_fill_column_indicator_column, Qt)) fill_column_indicator_column = XFIXNAT (BVAR (current_buffer, fill_column)); - else if (FIXNATP (Vdisplay_fill_column_indicator_column)) + else fill_column_indicator_column = XFIXNAT (Vdisplay_fill_column_indicator_column); @@ -20198,7 +20200,7 @@ append_space_for_newline (struct it *it, bool default_face_p) it->c = it->char_to_display = XFIXNAT (Vdisplay_fill_column_indicator_character); it->face_id = - merge_faces (it->w, Qfill_column_face, + merge_faces (it->w, Qfill_column_indicator, 0, DEFAULT_FACE_ID); face = FACE_FROM_ID(it->f, it->face_id); goto produce_glyphs; @@ -20221,8 +20223,8 @@ append_space_for_newline (struct it *it, bool default_face_p) set. */ if (it->glyph_row->reversed_p /* But if the appended newline glyph goes all the way to - the end of the row, there will be no stretch glyph, - so leave the box flag set. */ + the end of the row, there will be no stretch glyph, + so leave the box flag set. */ && saved_x + FRAME_COLUMN_WIDTH (it->f) < it->last_visible_x) it->end_of_box_run_p = false; @@ -20376,7 +20378,7 @@ extend_face_to_end_of_line (struct it *it) && !face->stipple #endif && !it->glyph_row->reversed_p - && NILP (Vdisplay_fill_column_indicator)) + && !Vdisplay_fill_column_indicator) return; /* Set the glyph row flag indicating that the face of the last glyph @@ -20431,17 +20433,16 @@ extend_face_to_end_of_line (struct it *it) /* Display fill column indicator if not in modeline or toolbar and display fill column indicator mode is - active */ + active. */ if ((it->w->pseudo_window_p == 0) && FILL_COLUMN_INDICATOR_NEEDED(it)) { int fill_column_indicator_column = -1; - if (EQ (Vdisplay_fill_column_indicator_column, Qt) - && FIXNATP (BVAR (current_buffer, fill_column))) + if (EQ (Vdisplay_fill_column_indicator_column, Qt)) fill_column_indicator_column = XFIXNAT (BVAR (current_buffer, fill_column)); - else if (FIXNATP (Vdisplay_fill_column_indicator_column)) + else fill_column_indicator_column = XFIXNAT (Vdisplay_fill_column_indicator_column); @@ -20466,7 +20467,7 @@ extend_face_to_end_of_line (struct it *it) Lisp_Object save_object = it->object; /* The stretch width needs to considet the latter - added glyph */ + added glyph. */ const int stretch_width = column_x - it->current_x - char_width; @@ -20474,34 +20475,35 @@ extend_face_to_end_of_line (struct it *it) it->avoid_cursor_p = true; it->object = Qnil; - /* Only generate a stretch glysph if there is distance - between current_x and and the indicator position */ + /* Only generate a stretch glyph if there is distance + between current_x and and the indicator position. */ if (stretch_width > 0) { - int stretch_ascent = (((it->ascent + it->descent) + int stretch_ascent = (((it->ascent + it->descent) * FONT_BASE (font)) / FONT_HEIGHT (font)); append_stretch_glyph (it, Qnil, stretch_width, it->ascent + it->descent, stretch_ascent); } - /* Generate the glysph indicator only if - append_space_for_newline didn't already. */ + /* Generate the glyph indicator only if + append_space_for_newline didn't already. */ if (it->current_x < column_x) { it->char_to_display = XFIXNAT (Vdisplay_fill_column_indicator_character); it->face_id = - merge_faces (it->w, Qfill_column_face, + merge_faces (it->w, Qfill_column_indicator, 0, DEFAULT_FACE_ID); PRODUCE_GLYPHS (it); } - /* Restore the face after the indicator was generated */ + /* Restore the face after the indicator was generated. */ it->face_id = saved_face_id; /* If there is space after the indicator generate an - extra empty glysph to restore the face. */ + extra empty glyph to restore the face. Issue was + observed in X systems. */ it->char_to_display = ' '; PRODUCE_GLYPHS (it); @@ -20514,14 +20516,13 @@ extend_face_to_end_of_line (struct it *it) } } #ifdef HAVE_WINDOW_SYSTEM - if (it->glyph_row->reversed_p) { /* Prepend a stretch glyph to the row, such that the rightmost glyph will be drawn flushed all the way to the right margin of the window. The stretch glyph that will occupy the empty space, if any, to the left of the - glyphs. */ + glyph. */ struct font *font = face->font ? face->font : FRAME_FONT (f); struct glyph *row_start = it->glyph_row->glyphs[TEXT_AREA]; struct glyph *row_end = row_start + it->glyph_row->used[TEXT_AREA]; @@ -20635,18 +20636,19 @@ extend_face_to_end_of_line (struct it *it) else it->face_id = face->id; - /* Display fill-column-line if needed. */ + /* Display fill-column indicator if needed. */ if (FILL_COLUMN_INDICATOR_NEEDED(it)) { int fill_column_indicator_column = -1; /* Vdisplay_fill_column_indicator_column accepts the special - value t to use the default fill-column variable. */ - if (EQ (Vdisplay_fill_column_indicator_column, Qt) - && FIXNATP (BVAR (current_buffer, fill_column))) + value t to use the default fill-column variable. The + conditions are all defined in the macro + FILL_COLUMN_INDICATOR_NEEDED. */ + if (EQ (Vdisplay_fill_column_indicator_column, Qt)) fill_column_indicator_column = XFIXNAT (BVAR (current_buffer, fill_column)) + it->lnum_pixel_width; - else if (FIXNATP (Vdisplay_fill_column_indicator_column)) + else fill_column_indicator_column = XFIXNAT (Vdisplay_fill_column_indicator_column) + it->lnum_pixel_width; @@ -20656,7 +20658,7 @@ extend_face_to_end_of_line (struct it *it) { const int saved_face = it->face_id; it->face_id = - merge_faces (it->w, Qfill_column_face, 0, DEFAULT_FACE_ID); + merge_faces (it->w, Qfill_column_indicator, 0, DEFAULT_FACE_ID); it->c = it->char_to_display = XFIXNAT (Vdisplay_fill_column_indicator_character); PRODUCE_GLYPHS (it); @@ -32839,8 +32841,8 @@ be let-bound around code that needs to disable messages temporarily. */); /* Name of a text property which disables line-number display. */ DEFSYM (Qdisplay_line_numbers_disable, "display-line-numbers-disable"); - /* Names of the face used to display fill column indicator character. */ - DEFSYM (Qfill_column_face, "fill-column-face"); + /* Name of the face used to display fill column indicator character. */ + DEFSYM (Qfill_column_indicator, "fill-column-indicator"); /* Name and number of the face used to highlight escape glyphs. */ DEFSYM (Qescape_glyph, "escape-glyph"); @@ -33414,25 +33416,26 @@ either `relative' or `visual'. */); DEFSYM (Qdisplay_line_numbers_widen, "display-line-numbers-widen"); Fmake_variable_buffer_local (Qdisplay_line_numbers_widen); - DEFVAR_LISP ("display-fill-column-indicator", Vdisplay_fill_column_indicator, + DEFVAR_BOOL ("display-fill-column-indicator", Vdisplay_fill_column_indicator, doc: /* Non-nil means display the fill column indicator. */); - Vdisplay_fill_column_indicator = Qnil; + Vdisplay_fill_column_indicator = false; DEFSYM (Qdisplay_fill_column_indicator, "display-fill-column-indicator"); Fmake_variable_buffer_local (Qdisplay_fill_column_indicator); DEFVAR_LISP ("display-fill-column-indicator-column", Vdisplay_fill_column_indicator_column, - doc: /* Column for indicator when `display-fill-column-indicator' is non-nil. -The default value is t which means that the indicator will use the `fill-column' variable. -If a numeric value is set, the indicator will be drawn in that column -independently of the `fill-column' value. */); + doc: /* Column for indicator when `display-fill-column-indicator' +is non-nil. The default value is t which means that the indicator +will use the `fill-column' variable. If it is set to an integer the +indicator will be drawn in that column. */); Vdisplay_fill_column_indicator_column = Qt; DEFSYM (Qdisplay_fill_column_indicator_column, "display-fill-column-indicator-column"); Fmake_variable_buffer_local (Qdisplay_fill_column_indicator_column); DEFVAR_LISP ("display-fill-column-indicator-character", Vdisplay_fill_column_indicator_character, - doc: /* Character to draw the indicator when `display-fill-column-indicator' is non-nil. -The default is U+2502 but a good alternative is (ascii 124) if -the font in fill-column-face does not support Unicode characters. */); + doc: /* Character to draw the indicator when +`display-fill-column-indicator' is non-nil. The default is U+2502 but +a good alternative is (ascii 124) if the font in fill-column-indicator +face does not support Unicode characters. */); Vdisplay_fill_column_indicator_character = Qnil; DEFSYM (Qdisplay_fill_column_indicator_character, "display-fill-column-indicator-character"); Fmake_variable_buffer_local (Qdisplay_fill_column_indicator_character); -- cgit v1.2.1