Skip to content

Commit

Permalink
Option to center lines vertically when using line-spacing
Browse files Browse the repository at this point in the history
  • Loading branch information
sollidsnake committed Aug 31, 2019
1 parent 172b99a commit aff5c59
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/buffer.c
Expand Up @@ -219,6 +219,11 @@ bset_extra_line_spacing (struct buffer *b, Lisp_Object val)
b->extra_line_spacing_ = val;
}
static void
bset_line_spacing_vertical_center (struct buffer *b, Lisp_Object val)
{
b->line_spacing_vertical_center_ = val;
}
static void
bset_file_format (struct buffer *b, Lisp_Object val)
{
b->file_format_ = val;
Expand Down Expand Up @@ -956,6 +961,7 @@ reset_buffer (register struct buffer *b)
(b, BVAR (&buffer_defaults, enable_multibyte_characters));
bset_cursor_type (b, BVAR (&buffer_defaults, cursor_type));
bset_extra_line_spacing (b, BVAR (&buffer_defaults, extra_line_spacing));
bset_line_spacing_vertical_center (b, BVAR (&buffer_defaults, line_spacing_vertical_center));

b->display_error_modiff = 0;
}
Expand Down Expand Up @@ -5190,6 +5196,7 @@ init_buffer_once (void)
XSETFASTINT (BVAR (&buffer_local_flags, header_line_format), idx); ++idx;
XSETFASTINT (BVAR (&buffer_local_flags, cursor_type), idx); ++idx;
XSETFASTINT (BVAR (&buffer_local_flags, extra_line_spacing), idx); ++idx;
XSETFASTINT (BVAR (&buffer_local_flags, line_spacing_vertical_center), idx); ++idx;
XSETFASTINT (BVAR (&buffer_local_flags, cursor_in_non_selected_windows), idx); ++idx;

/* buffer_local_flags contains no pointers, so it's safe to treat it
Expand Down Expand Up @@ -5259,6 +5266,7 @@ init_buffer_once (void)
bset_bidi_paragraph_separate_re (&buffer_defaults, Qnil);
bset_cursor_type (&buffer_defaults, Qt);
bset_extra_line_spacing (&buffer_defaults, Qnil);
bset_line_spacing_vertical_center (&buffer_defaults, Qnil);
bset_cursor_in_non_selected_windows (&buffer_defaults, Qt);

bset_enable_multibyte_characters (&buffer_defaults, Qt);
Expand Down Expand Up @@ -6248,6 +6256,11 @@ see `display-graphic-p'.
If value is a floating point number, it specifies the spacing relative
to the default frame line height. A value of nil means add no extra space. */);

DEFVAR_PER_BUFFER ("line-spacing-vertical-center",
&BVAR (current_buffer, line_spacing_vertical_center), Qnil,
doc: /* Non-nil will center the line content vertically
when using `line-spacing' variable. */);

DEFVAR_PER_BUFFER ("cursor-in-non-selected-windows",
&BVAR (current_buffer, cursor_in_non_selected_windows), Qnil,
doc: /* Non-nil means show a cursor in non-selected windows.
Expand Down
4 changes: 4 additions & 0 deletions src/buffer.h
Expand Up @@ -740,6 +740,10 @@ struct buffer
in the display of this buffer. */
Lisp_Object extra_line_spacing_;

/* When non-nil will center the line content vertically. To be used
along with `line-spacing'. */
Lisp_Object line_spacing_vertical_center_;

/* Cursor type to display in non-selected windows.
t means to use hollow box cursor.
See `cursor-type' for other values. */
Expand Down
8 changes: 7 additions & 1 deletion src/xdisp.c
Expand Up @@ -29294,7 +29294,13 @@ gui_produce_glyphs (struct it *it)

if (extra_line_spacing > 0)
{
it->descent += extra_line_spacing;
if (! BVAR (XBUFFER (it->w->contents), line_spacing_vertical_center)) {
it->descent += extra_line_spacing;
} else {
int spacing = extra_line_spacing / 2;
it->ascent += spacing;
it->descent += spacing;
}
if (extra_line_spacing > it->max_extra_line_spacing)
it->max_extra_line_spacing = extra_line_spacing;
}
Expand Down

0 comments on commit aff5c59

Please sign in to comment.