all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Patch to vertically center line content when using line-spacing variable
@ 2019-08-31 21:53 Jesse Medeiros
  2019-08-31 22:36 ` Stefan Kangas
  0 siblings, 1 reply; 33+ messages in thread
From: Jesse Medeiros @ 2019-08-31 21:53 UTC (permalink / raw)
  To: emacs-devel

When you set the line-spacing variable, Emacs only adds margin to the
bottom of the line, which always annoyed me. So I decided to work on
this and wrote a patch to vertically center the line when setting the
line-spacing variable. I created a new variable called
line-spacing-vertical-center, and the centering will only apply when
this variable is set to non-nil. Could this be merged upstream? Here's
the link for the patch:

https://github.com/sollidsnake/emacs/commit/aff5c59d10001e1161884ef3d0725eda86fa3ea0

This is my first attempt to contribute to Emacs, and I'm not very
familiar neither with C nor with Emacs core, so please let me know if
I'm doing something wrong.


Jesse Medeiros



^ permalink raw reply	[flat|nested] 33+ messages in thread
* Patch to vertically center line content when using line-spacing variable
@ 2020-01-23 16:32 조성빈
  2020-01-23 19:22 ` Eli Zaretskii
  0 siblings, 1 reply; 33+ messages in thread
From: 조성빈 @ 2020-01-23 16:32 UTC (permalink / raw)
  To: emacs-devel; +Cc: jessenzr

[-- Attachment #1: Type: text/plain, Size: 195 bytes --]

Hello, there was a thread[0,1] before which introduced a patch to  
vertically center line content. I decided to fix the leftover nitpicks. Can  
anybody check this patch and give any feedback?


[-- Attachment #2: 0001-Add-new-variable-for-centering-lines-vertically.patch --]
[-- Type: application/octet-stream, Size: 6219 bytes --]

From 1302c040a23837b80a53416421914f3fe8ba1926 Mon Sep 17 00:00:00 2001
From: Sungbin Jo <pcr910303@icloud.com>
Date: Fri, 24 Jan 2020 00:56:38 +0900
Subject: [PATCH] Add new variable for centering lines vertically.

Co-authored-by: Jesse Nazario <jessenzr@gmail.com>

When using line-spacing, the new variable line-spacing-vertical-center
can be set to non-nil to center the line content vertically.

* src/buffer.h (struct buffer): New member line_spacing_vertical_center.
* src/buffer.c (bset_line_spacing_vertical_center): New setter for
line_spacing_vertical_center.
(reset_buffer): Reset line_spacing_vertical_center.
(init_buffer_once): Initialize line_spacing_vertical_center.
(syms_of_buffer): Declare Lisp variable line-spacing-vertical-center.
* src/xdisp.c (gui_produce_glyphs): Center the text when
line-spacing-vertical-center is non-nil.
* doc/lispref/display.texi (Line Height): Document the new variable.
* etc/NEWS: Announce the new variable.
---
 doc/lispref/display.texi |  5 +++++
 etc/NEWS                 |  4 ++++
 src/buffer.c             | 14 ++++++++++++++
 src/buffer.h             |  4 ++++
 src/xdisp.c              | 10 +++++++++-
 5 files changed, 36 insertions(+), 1 deletion(-)

diff --git a/doc/lispref/display.texi b/doc/lispref/display.texi
index e4980fe4c3..2fa63ddb56 100644
--- a/doc/lispref/display.texi
+++ b/doc/lispref/display.texi
@@ -2231,6 +2231,11 @@ Line Height
 number of pixels put below lines.  A floating-point number specifies
 the spacing relative to the frame's default line height.
 
+  The @code{line-spacing} parameter creates the space by putting some
+margin only below the line.  If you wish to center the line vertically
+instead, you can set the variable @code{line-spacing-vertical-center}
+as non-nil.
+
 @vindex line-spacing
   You can specify the line spacing for all lines in a buffer via the
 buffer-local @code{line-spacing} variable.  An integer specifies
diff --git a/etc/NEWS b/etc/NEWS
index 11ef31b2c8..fb85131f07 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -51,6 +51,10 @@ It was declared obsolete in Emacs 27.1.
 \f
 * Changes in Emacs 28.1
 
+** New variable line-spacing-vertical-center.
+This variable, if non-nil, centers the line content vertically when
+using the 'line-spacing' variable.
+
 \f
 * Editing Changes in Emacs 28.1
 
diff --git a/src/buffer.c b/src/buffer.c
index 5c65d4d4d1..234745a66a 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -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;
@@ -967,6 +972,8 @@ 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;
 }
@@ -5202,6 +5209,7 @@ init_buffer_once (void)
   XSETFASTINT (BVAR (&buffer_local_flags, tab_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
@@ -5272,6 +5280,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);
@@ -6268,6 +6277,11 @@ from (abs POSITION).  If POSITION is positive, point was at the front
 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 means 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.
diff --git a/src/buffer.h b/src/buffer.h
index fd05fdd37d..c15065b599 100644
--- a/src/buffer.h
+++ b/src/buffer.h
@@ -553,6 +553,10 @@ #define BVAR(buf, field) ((buf)->field ## _)
      in the display of this buffer.  */
   Lisp_Object extra_line_spacing_;
 
+  /* Non-nil means 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.  */
diff --git a/src/xdisp.c b/src/xdisp.c
index a5efbb39be..44727cdd64 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -30527,7 +30527,15 @@ gui_produce_glyphs (struct it *it)
 
   if (extra_line_spacing > 0)
     {
-      it->descent += extra_line_spacing;
+      if (NILP (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;
     }
-- 
2.21.1 (Apple Git-122.3)


[-- Attachment #3: Type: text/plain, Size: 148 bytes --]




[0] https://lists.gnu.org/archive/html/emacs-devel/2019-08/msg00659.html
[1] https://lists.gnu.org/archive/html/emacs-devel/2019-09/msg00049.html

^ permalink raw reply related	[flat|nested] 33+ messages in thread
* Patch to vertically center line content when using line-spacing variable
@ 2021-04-12 20:24 email
  2021-04-25 19:41 ` Lars Ingebrigtsen
  0 siblings, 1 reply; 33+ messages in thread
From: email @ 2021-04-12 20:24 UTC (permalink / raw)
  To: emacs-devel; +Cc: jessenzr

I am interested in this landing and contacted (and cc'd) Jesse and the
FSF paperwork was completed around June 2020. Is there anything else
holding this back now?

https://lists.gnu.org/archive/html/emacs-devel/2020-01/msg00721.html
has links to the previous discussion.



^ permalink raw reply	[flat|nested] 33+ messages in thread

end of thread, other threads:[~2021-04-26 20:04 UTC | newest]

Thread overview: 33+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-08-31 21:53 Patch to vertically center line content when using line-spacing variable Jesse Medeiros
2019-08-31 22:36 ` Stefan Kangas
2019-09-01  0:01   ` Jesse Medeiros
2019-09-03  0:01     ` Jesse Medeiros
2019-09-07  9:50     ` Eli Zaretskii
2019-09-08 23:24       ` Jesse Medeiros
2019-09-09  7:39         ` martin rudalics
2019-09-09  8:40         ` Robert Pluim
2019-09-12 12:08           ` Jesse Medeiros
2019-09-12 14:26             ` Robert Pluim
2019-09-12 20:49               ` Jesse Medeiros
2019-09-13  9:35                 ` Robert Pluim
2019-09-29 23:54           ` Jesse Medeiros
2019-09-30  7:07             ` Robert Pluim
  -- strict thread matches above, loose matches on Subject: below --
2020-01-23 16:32 조성빈
2020-01-23 19:22 ` Eli Zaretskii
2020-02-07 17:06   ` Jesse Medeiros
2020-02-07 18:26     ` Eli Zaretskii
2020-04-05 18:55     ` 조성빈 via "Emacs development discussions.
2020-04-06 21:13       ` Jesse Medeiros
2020-04-07 14:17         ` Eli Zaretskii
2021-04-12 20:24 email
2021-04-25 19:41 ` Lars Ingebrigtsen
2021-04-25 20:15   ` john muhl
2021-04-25 20:21   ` Eli Zaretskii
2021-04-25 23:25     ` Fu Yuan
2021-04-25 23:28   ` Stefan Kangas
2021-04-25 23:56     ` Clément Pit-Claudel
2021-04-26  1:00       ` Stefan Kangas
2021-04-26 14:00         ` Clément Pit-Claudel
2021-04-25 23:56   ` Clément Pit-Claudel
2021-04-26 12:35   ` Eli Zaretskii
2021-04-26 20:04     ` Lars Ingebrigtsen

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.