From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Psionic K Newsgroups: gmane.emacs.help Subject: Varying line spacing with font-locking in org Date: Fri, 26 Jan 2024 21:17:52 +0900 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="4280"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Ihor Radchenko To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Fri Jan 26 13:19:02 2024 Return-path: Envelope-to: geh-help-gnu-emacs@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 1rTLAk-0000ri-BA for geh-help-gnu-emacs@m.gmane-mx.org; Fri, 26 Jan 2024 13:19:02 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rTLAF-0006BI-8H; Fri, 26 Jan 2024 07:18:31 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rTL9w-0005xs-0H for help-gnu-emacs@gnu.org; Fri, 26 Jan 2024 07:18:13 -0500 Original-Received: from mail-yw1-x112a.google.com ([2607:f8b0:4864:20::112a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rTL9r-0005Cq-6A for help-gnu-emacs@gnu.org; Fri, 26 Jan 2024 07:18:11 -0500 Original-Received: by mail-yw1-x112a.google.com with SMTP id 00721157ae682-6002a655d77so2326087b3.2 for ; Fri, 26 Jan 2024 04:18:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=positron.solutions; s=google; t=1706271483; x=1706876283; darn=gnu.org; h=cc:to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=X0wmDuQ0nI9d3lMIpBjYggBD03SqOX5CaPKc1qFjjv4=; b=bFQLYhI7Y24dUGraXAvE4o+Q6NJ81Wwv8tywXYUAcaX+bMlK0rnPWGvLuId5f5JWaw I9tJwntBF0UE5Zl9dxFzBbbXI5Uv6PRbAYU3+b9p6Tz9zY71QXdDO9F2s1qxTC5PSixZ 0L7nlHyEKTRcg8m9CgeksCFZE8aB+s+gq3VE4/dekDitriQib9ekOLqt1/UmO5649eg/ E4D8OFx//nq4MeeLvE7OF89g14RofzXc+jkUWXeihhCk/BZBHTM2AoYeWATHsMA0crna FGw/MV1geIMFQagDHRfZW4ljvxgu9Du2Y9b6E8gFc4QAcRT95qg1/y59XDfQVii0MJyO WjZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706271483; x=1706876283; h=cc:to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=X0wmDuQ0nI9d3lMIpBjYggBD03SqOX5CaPKc1qFjjv4=; b=u421GZVKuDYIZ+sjkoMNh5ghWlWuU9CvG9bznzdhVDjSGqlqVdvlM+fQV59Csb1EmN 6fcUtrBaDUNXgTGtkOWVs8zoHhJwdYXk0mZWyBCIVLj5tF5sMdV+gnW+EptB5ULP9A59 wSwt6bLyAQ0M/VqaBFMf+nv42L35d8JGlNAMCSc/IHXo44eR8AZvNdMHmcb24Zhi/mrX yzMHPueu52wne4zf2113VgNfeKjw2xbw/L1mF36ME1Na30RXL42t1llyceF9PhNRuNJ5 k9VNlJygQ5r6bvGmZoVMCrkNvLkaFgwggwZ50Wbza6iyeYn94naqAylLf+VEhgvVWliP VAJw== X-Gm-Message-State: AOJu0YydhCyYsefkMsKgHXVNMGlQXo9AtBgr9IGT81JE+WeS7w7UJumE /DE0ExYoiyYpEs7RVLe9QyTVHxenWgjgbJqosLk+/KdPo4edZtrX3MwV9kIfVrVzqYMTGnz5EAH mLgdeXCSzYSHiRmDsAYQYxmaKVcOt41A0pBOegZWIyOXN9GdDrno= X-Google-Smtp-Source: AGHT+IHlfhMxOB7qu3ZabDgEO55DnflwmEWSNanIglbgGxvyDyv2gOqGHEvVMRR2XHS7f6/wrD9IppLw4n0eXDlTxU8= X-Received: by 2002:a81:ce05:0:b0:602:c59e:bcba with SMTP id t5-20020a81ce05000000b00602c59ebcbamr809967ywi.27.1706271483549; Fri, 26 Jan 2024 04:18:03 -0800 (PST) Received-SPF: pass client-ip=2607:f8b0:4864:20::112a; envelope-from=exec@positron.solutions; helo=mail-yw1-x112a.google.com 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, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.help:145807 Archived-At: I implemented element by element line spacing in org using font locking. Here's a description of my method and some findings. For unmatched elements, I started with setting a `default-text-property' for line-spacing and line-height. This was necessary because the buffer-wide value for line-spacing doesn't seem to interact; I can add spacing, but I can't take it away with explicitly added properties. If there is a way to add default font-locking rules, maybe that would be preferred. >From there, I needed to make some elements have no spacing (source blocks) or more spacing (headings, which I use a larger face height for). I made some font-locking rules that I added by extending org-modern-mode. Here is an example (not ready for PR): (when (or org-modern-block-line-height org-modern-block-line-spacing) (let ((line-height-rule `(0 '(face nil line-height ,org-modern-block-line-height) append)) (line-spacing-rule `(0 '(face nil line-spacing ,org-modern-block-line-spacing) append))) `(("^[ \t]*#\\+\\(?:begin\\|BEGIN\\)_\\S-\\([^z-a]*\\)#\\+\\(?:end\\|END\\)_\\S-+\n" ,line-height-rule ,line-spacing-rule)))) I needed to add line-height and line-spacing to the `font-lock-extra-managed-props`, which is normal. The result is mostly satisfactory. Two issues I ran into so far: 1. Org mode folding creates a situation where a different newline becomes the one considered for spacing and height. This can likely be fixed by folding the trailing newline rather than the heading's newline (notified Org maintainer) 2. Visual line mode sometimes might only add spacing to the last line of a paragraph while typing. This seems to have been due to one instance of a buffer and dirty state. I can't reproduce it so far. I think I will go ahead and submit changes to org-modern soon. I'm expecting it will take a while to merge in order to compress the new font lock rules with existing ones and prevent conflicts. If this approach seems to have missed an implementation possibility that I should consider, let me know.