From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id iBcFBm+cnGEK/QAAgWs5BA (envelope-from ) for ; Tue, 23 Nov 2021 08:46:55 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id qJPCAW+cnGHEBAAAB5/wlQ (envelope-from ) for ; Tue, 23 Nov 2021 07:46:55 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id AAB753B0AC for ; Tue, 23 Nov 2021 08:46:54 +0100 (CET) Received: from localhost ([::1]:37884 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mpQVw-0001eV-Fh for larch@yhetil.org; Tue, 23 Nov 2021 02:46:52 -0500 Received: from eggs.gnu.org ([209.51.188.92]:47988) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mpQVJ-0001eJ-MB for emacs-orgmode@gnu.org; Tue, 23 Nov 2021 02:46:13 -0500 Received: from [2607:f8b0:4864:20::42e] (port=43658 helo=mail-pf1-x42e.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mpQVH-0002sH-It for emacs-orgmode@gnu.org; Tue, 23 Nov 2021 02:46:13 -0500 Received: by mail-pf1-x42e.google.com with SMTP id n85so18594673pfd.10 for ; Mon, 22 Nov 2021 23:46:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:cc:subject:in-reply-to:references:date:message-id :mime-version; bh=BMi981qlMfZsy1VpKHFYEoupDoQhFeU/cG6oST/wv60=; b=WZzfHGZlm6NA/K7eKASx3gWA7b3c1AW4T3S8RFoHzya01LSV63kcwmGh6xdx180mzj 5pjoA854kxRu5WvuaNsnGWJsS5Mi8HfcbxG6RjaFOPx/v2akreVCtaRg6/bq59pkNmcT l96fqwc5acKFwpIJsAPG2KNSMfZBhNvEnjSTwF4ZGKcUFHJtlY80d15LXzaRkF7ygT0W 4UfNbeSlkVKomQ8hOLwSLSiQZEG6qFZI9JwiMSdQjOrwVEUfYNjAhHRPQ489RdJFKoP+ EjYC+6ugwf2C6ZQpnCFZtVjuur1fwpwWOV3mSVWzAJd2WMCyOQqti/G0l30ZRKT5bkNa CrJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:cc:subject:in-reply-to:references :date:message-id:mime-version; bh=BMi981qlMfZsy1VpKHFYEoupDoQhFeU/cG6oST/wv60=; b=qNasUhnyKzwIkmBkFHlXX9Cf2pfDvajZn/mIDavP8S6vfK7iFHdIG5mU7NbFWxS0WR snkHvj5UwRyKkWQ7I2DGzr16oJ2t3iHswSJ6yDUHjHqF5JauJt6zAo/FMoUSyifNZXqI xtsrpZ4rCYjnVKLlipf2HAttiUSC3NNudqCp65qOyDQ4b92MtygCxwzi74Ba2314cbPk F8QFlYY0e7U3ERNH6etPmtEVmPyUM82k7XsqdM69/r25PF7MI3gmszJt9F/KqFi/pTLq VrviqqAMaYrxu9ACd/kbsdMR0ULX+50K//DRS4O6oleOR9ZK/TQKSQHpfZ5evDDurhXS cg0g== X-Gm-Message-State: AOAM5333L2RRbFGCuO8Hkj+KQUY686D6/FwpUm8U4/LUy8cYS7jApMfu 972Aj3oIkcNg3b9oGAZOJXRg3khx93U= X-Google-Smtp-Source: ABdhPJwneuXYHNJjrjg0mGzTQ1NZP02IYRPGA5FpPXZ87d6oOhBrhZEIGN1cq2CyCyYyT4zih9E3lw== X-Received: by 2002:aa7:9a04:0:b0:4a2:ebcd:89a with SMTP id w4-20020aa79a04000000b004a2ebcd089amr3636169pfj.60.1637653569768; Mon, 22 Nov 2021 23:46:09 -0800 (PST) Received: from ryzen3950 (c-208-82-98-189.rev.sailinternet.net. [208.82.98.189]) by smtp.gmail.com with ESMTPSA id k12sm8002544pgi.23.2021.11.22.23.46.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Nov 2021 23:46:09 -0800 (PST) From: Matt Huszagh To: Timothy Subject: Re: [PATCH] Fix regex for determining image width from attribute In-Reply-To: <871r37l96a.fsf@gmail.com> References: <87czmtuy0p.fsf@gmail.com> <87ilwl71gh.fsf@gmail.com> <87a6hxuw0y.fsf@gmail.com> <877dd07fnb.fsf@gmail.com> <8735noqig0.fsf@gmail.com> <87wnl05ag6.fsf@gmail.com> <87y25fq5d2.fsf@gmail.com> <8735nnlaef.fsf@gmail.com> <87v90jph1w.fsf@gmail.com> <871r37l96a.fsf@gmail.com> Date: Mon, 22 Nov 2021 23:46:07 -0800 Message-ID: <87k0gzpb5s.fsf@gmail.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::42e (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::42e; envelope-from=huszaghmatt@gmail.com; helo=mail-pf1-x42e.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 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, FREEMAIL_FROM=0.001, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: , emacs-orgmode@gnu.org Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1637653614; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=BMi981qlMfZsy1VpKHFYEoupDoQhFeU/cG6oST/wv60=; b=j39tgZiFygFZ6lR5CRbd4ModHomkN8Igm3OVTL56+ClLcU420fve7JlLX3NX1c0vI94jWJ BsUMh2FOYlxH2fPHdGHTqD4GQKz/vEFh16YCzPuwF4gkURY5FquUkzCizXl/LF34OpATqU nc00UKrFqYuEqIYUJJTsQ4BMUGpZJ8vjaMeyfA9PPvs5LzD1ILMBS8jJvjebS8iSx+N9NB qZ4Ylu6qzaxuAmsM38AICZ25eSdnDGbuMh7qGKBGs6z9B9OEPITTQARUBOG9CMG9p5RCZm r7pfYqB/w3GHGOrfOELls1q6H+sZYpJ4OqI6TZpR6ic4WnoJL45W1HZ1CjQaGA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1637653614; a=rsa-sha256; cv=none; b=N2H1OEM0wu+UfPN06omS6toMe6+43ytTR/3vWkALDSZC985dBhyK4Y4WbolsoLnzcflnf/ nzNowcyfGrR3xkXftiY/Yvnz31SY9Kl1d0UNg6ZOI7kfSDyxK33GJ1bR9YM7pM2W/HJ1MD ZaQNGQSdKDQk25tuAuJWXNU0EMpcDsn//RbkUJWUJUYP6yVuz47wEACX1TuLvaYenHIT8j /w6YaPm81VMAl+B+U+W2/4YzaOpfDhet30E7Mydrnl12VpHgzTnxXvQiXy0jFveSkAsbJv v2w7lVVIsmuEsB4ExpJA9nL/+/2xFokyIcKm5siXP16HqYXAEfCsYXDY/DGW/g== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20210112 header.b=WZzfHGZl; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -1.78 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20210112 header.b=WZzfHGZl; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: AAB753B0AC X-Spam-Score: -1.78 X-Migadu-Scanner: scn0.migadu.com X-TUID: BPsXVJubX49J --=-=-= Content-Type: text/plain Here are two patches that prioritize attr_org over other attr_ keywords. I believe this is what you had in mind Timothy. But let me know if not. The second patch (intended to be applied after the first) improves the documentation. It describes behavior that wasn't previously documented and removes redundant documentation between org-image-actual-width and org-display-inline-image--width (now only in org-image-actual-width). Please double check I got everything correct, as I haven't used all this behavior myself. Thanks Matt --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-org.el-Prioritize-attr_org-when-computing-image-widt.patch Content-Description: 1st patch >From 22bbe7d651e1f27398597297c7c35ae4f3253773 Mon Sep 17 00:00:00 2001 From: Matt Huszagh Date: Mon, 22 Nov 2021 23:28:48 -0800 Subject: [PATCH 1/2] org.el: Prioritize attr_org when computing image width * lisp/org.el (org-display-inline-image--width): First look for attr_org: :width and then look for another attr_.* :width when that isn't specified. --- lisp/org.el | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lisp/org.el b/lisp/org.el index 308bb7d51..bf5d08e09 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -16853,13 +16853,20 @@ buffer boundaries with possible narrowing." ((listp org-image-actual-width) (let* ((case-fold-search t) (par (org-element-lineage link '(paragraph))) - (attr-re "^[ \t]*#\\+attr_.*?: +.*?:width +\\(\\S-+\\)") + (attr-re (lambda (backend) + (concat "^[ \t]*#\\+attr_" + backend + ": +.*?:width +\\(\\S-+\\)"))) (par-end (org-element-property :post-affiliated par)) - ;; Try to find an attribute providing a :width. + ;; If an attr_org provides a :width, use that. Otherwise, + ;; use the first attribute that provides it, if any. (attr-width (when (and par (org-with-point-at (org-element-property :begin par) - (re-search-forward attr-re par-end t))) + (or (re-search-forward (funcall attr-re "org") + par-end t) + (re-search-forward (funcall attr-re ".*?") + par-end t)))) (match-string 1))) (width (cond -- 2.31.1 --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-org.el-Clarify-documentation-for-computing-image-wid.patch Content-Description: 2nd patch >From aff581922e8d8bf10f813cdb9bc8adf9c8632683 Mon Sep 17 00:00:00 2001 From: Matt Huszagh Date: Mon, 22 Nov 2021 23:30:11 -0800 Subject: [PATCH] org.el: Clarify documentation for computing image width * lisp/org.el (org-display-inline-image--width) (org-image-actual-width): Specify documentation for computing an inline image width in org-image-actual-width and remove the redundant documentation from org-display-inline-image--width. --- lisp/org.el | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/lisp/org.el b/lisp/org.el index bf5d08e09..c8dc1815f 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -15529,10 +15529,29 @@ When set to a number in a list, try to get the width from any and fall back on that number if none is found. -When set to nil, try to get the width from an #+ATTR.* keyword -and fall back on the original width if none is found. - -When set to any other non-nil value, always use the image width. +When set to nil, first try to get the width from #+ATTR_ORG. If +that is not found, use the first #+ATTR_.*:width specification. +If that is also not found, fall back on the original image width. + +Finally, org is quite flexible in the width specifications it +supports and intelligently interprets width specifications for +other backends when rendering an image in an org buffer. This +behavior is described presently. + +1. A floating point value is interpreted as the percentage of the text + area that should be taken up by the image. +2. A number followed by a percent sign is divided by 100 and then + interpreted as a floating point value. +3. If a number is followed by other text, extract the number and + discard the remaining text. That number is then interpreted as a + floating-point value. For example, + + #+ATTR_LATEX: :width 0.7\\linewidth + + would be interpreted as 70% of the text width. +4. If t is provided the original image width is used. This is useful + when you want to specify a width for a backend, but still want to + use the original image width in the org buffer. This requires Emacs >= 24.1, built with imagemagick support." :group 'org-appearance @@ -16838,16 +16857,7 @@ buffer boundaries with possible narrowing." (defvar visual-fill-column-width) ; Silence compiler warning (defun org-display-inline-image--width (link) "Determine the display width of the image LINK, in pixels. -- When `org-image-actual-width' is t, the image's pixel width is used. -- When `org-image-actual-width' is a number, that value will is used. -- When `org-image-actual-width' is nil or a list, the first :width attribute - set (if it exists) is used to set the image width. A width of X% is - divided by 100. - If no :width attribute is given and `org-image-actual-width' is a list with - a number as the car, then that number is used as the default value. - If the value is a float between 0 and 2, it interpreted as that proportion - of the text width in the buffer." - ;; Apply `org-image-actual-width' specifications. +See `org-image-actual-width' for how the image width is computed." (cond ((eq org-image-actual-width t) nil) ((listp org-image-actual-width) -- 2.31.1 --=-=-=--