From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Lars Ingebrigtsen Newsgroups: gmane.emacs.devel Subject: Re: Patch to vertically center line content when using line-spacing variable Date: Sun, 25 Apr 2021 21:41:09 +0200 Message-ID: <87sg3ei23u.fsf@gnus.org> References: <1398d749303cdc2a490cd9eb35f88fcf@johnmuhl.me> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="8945"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: jessenzr@gmail.com, emacs-devel@gnu.org To: email@johnmuhl.me Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun Apr 25 21:42:41 2021 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lakeO-0002Di-JA for ged-emacs-devel@m.gmane-mx.org; Sun, 25 Apr 2021 21:42:40 +0200 Original-Received: from localhost ([::1]:39322 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lakeN-0003Lq-Kl for ged-emacs-devel@m.gmane-mx.org; Sun, 25 Apr 2021 15:42:39 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:37568) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lakd8-0002vX-DE for emacs-devel@gnu.org; Sun, 25 Apr 2021 15:41:22 -0400 Original-Received: from quimby.gnus.org ([2a01:4f9:2b:f0f::2]:56358) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lakd5-00065g-6O for emacs-devel@gnu.org; Sun, 25 Apr 2021 15:41:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnus.org; s=20200322; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date: References:Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=Sbsq3mMS6ooRegdL9QQ7JwvEai2AxHgSn1o2XJzDQhU=; b=vU+OshZtQWuVq2AL+9UfeRltds cUZJl9Cdyc5V38ueI4pBvEoBzkr/5d5dLutn9sL88T0NXJwTHQuxrhlK1QfqisgXEhG8L9RLvQqtj 9M0NgyFsAhM3X5RvTFbZGuvDw4hxq8l3hrOsdm/UMSCDP3H9CKVfDli1L7hf4LaZpQRE=; Original-Received: from cm-84.212.220.105.getinternet.no ([84.212.220.105] helo=xo) by quimby.gnus.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lakcw-0001ZV-Bq; Sun, 25 Apr 2021 21:41:16 +0200 X-Now-Playing: The Body's _Remixed and Reinterpreted_: "Ten Times A Day Everyday A Stranger (Remixed by Container)" In-Reply-To: <1398d749303cdc2a490cd9eb35f88fcf@johnmuhl.me> (email@johnmuhl.me's message of "Mon, 12 Apr 2021 20:24:53 +0000") Received-SPF: pass client-ip=2a01:4f9:2b:f0f::2; envelope-from=larsi@gnus.org; helo=quimby.gnus.org X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:268416 Archived-At: --=-=-= Content-Type: text/plain email@johnmuhl.me writes: > 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. I've included the patch below. I've never used the `line-spacing' variable myself (and my guess is that few do, which is probably why your message didn't get any responses), but I did a (setq line-spacing 20) now, and I see that this puts more space at the bottom of the line. The proposed patch allows centring instead, which seems eminently reasonable to me. (Perhaps this should even be the default?) Does anybody have any comments here before I apply the patch? -- (domestic pets only, the antidote for overdose, milk.) bloggy blog: http://lars.ingebrigtsen.no --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=line.patch >From 1302c040a23837b80a53416421914f3fe8ba1926 Mon Sep 17 00:00:00 2001 From: Sungbin Jo Date: Fri, 24 Jan 2020 00:56:38 +0900 Subject: [PATCH] Add new variable for centering lines vertically. Co-authored-by: Jesse Nazario 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. * 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. + * 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) --=-=-=--