From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.bugs Subject: bug#37858: 27.0.50; Ensure a minimum width for `space` display prop Date: Mon, 21 Oct 2019 16:03:58 -0400 Message-ID: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="263559"; mail-complaints-to="usenet@blaine.gmane.org" To: 37858@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Oct 21 22:05:15 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1iMdvU-0016Ov-8l for geb-bug-gnu-emacs@m.gmane.org; Mon, 21 Oct 2019 22:05:12 +0200 Original-Received: from localhost ([::1]:47424 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iMdvS-0001A8-DO for geb-bug-gnu-emacs@m.gmane.org; Mon, 21 Oct 2019 16:05:10 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:37080) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iMdvM-0001A2-1m for bug-gnu-emacs@gnu.org; Mon, 21 Oct 2019 16:05:05 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iMdvK-0005eD-O1 for bug-gnu-emacs@gnu.org; Mon, 21 Oct 2019 16:05:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:49063) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iMdvK-0005du-LE for bug-gnu-emacs@gnu.org; Mon, 21 Oct 2019 16:05:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1iMdvK-00060f-8l for bug-gnu-emacs@gnu.org; Mon, 21 Oct 2019 16:05:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 21 Oct 2019 20:05:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 37858 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.157168825823042 (code B ref -1); Mon, 21 Oct 2019 20:05:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 21 Oct 2019 20:04:18 +0000 Original-Received: from localhost ([127.0.0.1]:57884 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iMduc-0005zZ-7t for submit@debbugs.gnu.org; Mon, 21 Oct 2019 16:04:18 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:60737) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iMdua-0005zQ-6s for submit@debbugs.gnu.org; Mon, 21 Oct 2019 16:04:16 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:37056) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iMduY-000174-Ro for bug-gnu-emacs@gnu.org; Mon, 21 Oct 2019 16:04:16 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iMduW-0005Cm-Mh for bug-gnu-emacs@gnu.org; Mon, 21 Oct 2019 16:04:13 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:57577) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iMduW-0005CO-FY for bug-gnu-emacs@gnu.org; Mon, 21 Oct 2019 16:04:12 -0400 Original-Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 5DDC810079A for ; Mon, 21 Oct 2019 16:04:11 -0400 (EDT) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 08B561002CF for ; Mon, 21 Oct 2019 16:04:10 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1571688250; bh=18B0FzfBdQEix8NasBq59NxnRvs8kFgaxy8JvGReXYk=; h=From:To:Subject:Date:From; b=kSOesySqmhZ2bsGDQluP9lyrLvG6B00UZu2+b1LuMIOit8UHVKYxEYuOuz0BZg2w8 CsSdxNTkuFOx+N2a2LymWWP2e39Y60KGxgCYYiIbKNpvsYZdf5iffSM9WXjrFb+wv9 FOiiKuWIJrLPS5dq0ayQVJGByn527AjafIuu0YsDhnX4V5YYy3fZcCd6YnDJFDDDST xjAy/2Nq0K0r5hECFdV0uhTVvMcro8EAne4kVWIrW2pmrpqvdmma2xaq6XqHDbV2LJ gIlc+XwdzbpOQEQkvzxoLRqd9CJSorNTM1sO1YQju1IQKO7fAJW/rZEXQY4zkIGbqt 9Kun+lAGjrPUg== Original-Received: from alfajor (unknown [216.154.30.71]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id A00CF120BB5 for ; Mon, 21 Oct 2019 16:04:09 -0400 (EDT) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:169943 Archived-At: Package: Emacs Version: 27.0.50 For text displayed in columns, alignment is generally obtained with a `display` text-property of the form (space :align-to FOO) This works great when the previous text ends before FOO, but when we mis-calculate (or didn't calculate at all) and the previous text already extends further than the desired alignment of the following text, such space is reduced down to 0 pixels which is often not what we want. Sometimes one can workaround this by placing 2 spaces in the buffer: one with the :align-to and another fixed size space. But it can be cumbersome to do that and it leads to undesirable artifacts (e.g. the cursor can be placed between the two space). So, I'd like to extend our `space` specifications so as to be able to specify a minimum width. I came up with the patch below which lets you write: (space :align-to FOO :min-width BAR) which seems to work fine, but while trying to update the Elisp doc for it I realized that maybe a better option is to extend the acceptable forms for FOO so it can be of the form: (space :align-to (max FOO (+ BAR current-x))) WDYT? Stefan diff --git a/src/xdisp.c b/src/xdisp.c index be1c209553..fd825d2dfe 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -29218,6 +29218,28 @@ append_stretch_glyph (struct it *it, Lisp_Object object, #endif /* HAVE_WINDOW_SYSTEM */ +static int +compute_relative_width (struct it *it, Lisp_Object prop) +{ + struct it it2; + unsigned char *p = BYTE_POS_ADDR (IT_BYTEPOS (*it)); + + it2 = *it; + if (it->multibyte_p) + it2.c = it2.char_to_display = STRING_CHAR_AND_LENGTH (p, it2.len); + else + { + it2.c = it2.char_to_display = *p, it2.len = 1; + if (! ASCII_CHAR_P (it2.c)) + it2.char_to_display = BYTE8_TO_CHAR (it2.c); + } + + it2.glyph_row = NULL; + it2.what = IT_CHARACTER; + PRODUCE_GLYPHS (&it2); + return NUMVAL (prop) * it2.pixel_width; +} + /* Produce a stretch glyph for iterator IT. IT->object is the value of the glyph property displayed. The value must be a list `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs @@ -29288,23 +29310,7 @@ produce_stretch_glyph (struct it *it) /* Relative width `:relative-width FACTOR' specified and valid. Compute the width of the characters having the `glyph' property. */ - struct it it2; - unsigned char *p = BYTE_POS_ADDR (IT_BYTEPOS (*it)); - - it2 = *it; - if (it->multibyte_p) - it2.c = it2.char_to_display = STRING_CHAR_AND_LENGTH (p, it2.len); - else - { - it2.c = it2.char_to_display = *p, it2.len = 1; - if (! ASCII_CHAR_P (it2.c)) - it2.char_to_display = BYTE8_TO_CHAR (it2.c); - } - - it2.glyph_row = NULL; - it2.what = IT_CHARACTER; - PRODUCE_GLYPHS (&it2); - width = NUMVAL (prop) * it2.pixel_width; + width = compute_relative_width (it, prop); } else if ((prop = Fplist_get (plist, QCalign_to), !NILP (prop)) && calc_pixel_width_or_height (&tem, it, prop, font, true, @@ -29323,6 +29329,21 @@ produce_stretch_glyph (struct it *it) /* Nothing specified -> width defaults to canonical char width. */ width = FRAME_COLUMN_WIDTH (it->f); + if ((prop = Fplist_get (plist, QCmin_width), !NILP (prop)) + && calc_pixel_width_or_height (&tem, it, prop, font, true, 0)) + { + /* Absolute minimum width `:min-width WIDTH' specified and valid. */ + if (width < tem) + width = tem; + } + else if (prop = Fplist_get (plist, QCmin_relative_width), NUMVAL (prop) > 0) + { + /* Relative width `:min-relative-width FACTOR' specified and valid. */ + int tem = compute_relative_width (it, prop); + if (width < tem) + width = tem; + } + if (width <= 0 && (width < 0 || !zero_width_ok_p)) width = 1; @@ -34275,6 +34296,8 @@ syms_of_xdisp (void) DEFSYM (QCalign_to, ":align-to"); DEFSYM (QCrelative_width, ":relative-width"); DEFSYM (QCrelative_height, ":relative-height"); + DEFSYM (QCmin_relative_width, ":min-relative-width"); + DEFSYM (QCmin_width, ":min-width"); DEFSYM (QCeval, ":eval"); DEFSYM (QCpropertize, ":propertize"); DEFSYM (QCfile, ":file");