From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id YIgDHoVhnmHWMQEAgWs5BA (envelope-from ) for ; Wed, 24 Nov 2021 17:00:05 +0100 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id CDenGYVhnmEzcgAA1q6Kng (envelope-from ) for ; Wed, 24 Nov 2021 16:00:05 +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 EF40127C8D for ; Wed, 24 Nov 2021 17:00:04 +0100 (CET) Received: from localhost ([::1]:38292 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mpugl-0004MQ-EK for larch@yhetil.org; Wed, 24 Nov 2021 11:00:03 -0500 Received: from eggs.gnu.org ([209.51.188.92]:34136) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mpugN-0004Lg-1V for emacs-orgmode@gnu.org; Wed, 24 Nov 2021 10:59:39 -0500 Received: from [2607:f8b0:4864:20::632] (port=47090 helo=mail-pl1-x632.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mpug9-0002Di-R9 for emacs-orgmode@gnu.org; Wed, 24 Nov 2021 10:59:38 -0500 Received: by mail-pl1-x632.google.com with SMTP id p18so2185260plf.13 for ; Wed, 24 Nov 2021 07:59:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:in-reply-to:references:date:message-id :mime-version; bh=nVwJT5HWkwm0nf1lIGae4u6Cj5Lzp5+tDqFPJtiuL0Y=; b=gOYh3Z+3HXW+/HXSrZvBio6SQB9P48GgmWraFs+1lFhW0+daA7j+ZXJaBOA5v8nPd/ 0sIGlT53Nw2u5DgJYJQEUigpreygFA5vXkhj0NnKRlZpCpNU1LeyBAsed6TD1WbufeJ6 kZHSbbOOkRKC9Un/GM/b5sdRhuUh/LjrIfl7Ec6ALxpqmByLAYeW1WlK1uojX0cU5IjJ 1rcaQzG0IHnC8aQA6XAm/UPjd5gych473izyCLGUGFGHwqzIcPsDNqcLksdKTOEmYV9P qeQN4aHyT/5N3G9oUHBrPA45RkeoDw0oZ6S3smYXgj4anPss5kY2SKdqHbIHwFmp/bXS 7fkA== 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:subject:in-reply-to:references:date :message-id:mime-version; bh=nVwJT5HWkwm0nf1lIGae4u6Cj5Lzp5+tDqFPJtiuL0Y=; b=3/ld6qniTD2w0jJHKoRgh+AhssoZioa7FTluxWFJiGRn/BhUk4j4YYRPPIasXR70XS TN9zdNQzwxuGR853IkT4FO+aFXEJWqbVK1to34tezzyP3j6/1ApKeHVZwH/rHb4t1jd+ m65dHUZRF53tzs7SbLwd4WbscZwfyuexokewNd6gwLTt2+r2ic8TS6+xunCO7RnbtSm3 07bgPg10ycRDZxgebopKLeWTBXvqKU/jqkxr91esWbyqwu+gUIO6Ytwx0yVRGtIEt8LO hB6GlUvgT9g5cg6RqLPTFM7comNEdQeNaoCJIa2tqk6iqLf65IY93Iouymx7sNa7MGaJ On0A== X-Gm-Message-State: AOAM5312WFn59tCfpD75dXIJEwSmlc6GRuUpb5eMfzzRDL/hbhu4Vpk9 Vglub3mqAxd98dUp947flKjxoAhxVcs= X-Google-Smtp-Source: ABdhPJxrL59toAHAK5/NnuzA6AeAt0wdjPIM83Sjus7zy0sDq1jmFt9BEczOXmanA9IJO7/p5mFsuA== X-Received: by 2002:a17:90b:4f83:: with SMTP id qe3mr17111346pjb.56.1637769563982; Wed, 24 Nov 2021 07:59:23 -0800 (PST) Received: from ryzen3950 (c-208-82-98-189.rev.sailinternet.net. [208.82.98.189]) by smtp.gmail.com with ESMTPSA id c9sm94601pgq.58.2021.11.24.07.59.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Nov 2021 07:59:22 -0800 (PST) From: Matt Huszagh To: Max Nikulin , emacs-orgmode@gnu.org Subject: Re: [PATCH] Fix regex for determining image width from attribute In-Reply-To: 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> <87k0gzpb5s.fsf@gmail.com> <87h7c2pb6w.fsf@gmail.com> Date: Wed, 24 Nov 2021 07:59:20 -0800 Message-ID: <87ee75pmsn.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::632 (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::632; envelope-from=huszaghmatt@gmail.com; helo=mail-pl1-x632.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, 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: , 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=1637769605; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to: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=nVwJT5HWkwm0nf1lIGae4u6Cj5Lzp5+tDqFPJtiuL0Y=; b=lbuGHdJMwuEuYugh9j42V+oevA1eRqZgSqAtXE33KyeMuK03TWPmADINaeIaQQsuAPkT35 1NOeTpz2CFc9y/gUKKvVb5iINzyzsUryxoMWoXA0tcpYNk2PZPROUyh2+2ggDOd2BvKYxj C1Tj3ipTM6VLz5ShvwMkS2tjXFKjoN8jox6VG7wqDaf41XYHo+bT9ZyOdL3itBgLXAaVs3 PkwMcIEtvzyHK+627BTpOvDQm2/3OnOQDeZhIiRk7J8umLAhaZp/H8227eEWTAyM/pjAFB uHjygu05xz30aTVTgxGjHa6mLCveYYxlQvJEbNCE0iih7fWiv5ic2J7PJorOhA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1637769605; a=rsa-sha256; cv=none; b=ZBh5mTYhaW83kZstlPOX23fUdRd1cTCdalQBfkIXwbvjrzu83YsXGcx2UOYpZjvZpoQfbR 7bJiYOKcIEbZECsbTsfe3gzW/De2dH0ZVsFkLqBXDPMKGEp0wd6i9aA96vXmUVpXnrUWHa f7o8xya9rCCz8VlAVlqeqpdVdLg/M2maSPyjy/JzRxwoacJmAu09mKu362Nnxsk1ZgWHAb 1W3za1n4KzjErPPhYUM4MWF83aUiesmWc1CtFC0aHjTOfEAXsb6x5+ZJPEn2EWzy/Vhn+c 9JuuuZG/ky5udFA7eChSmwamkTZcg7UDYjzgT46nxK6sJn/JKgFELNyk5R/Skg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20210112 header.b=gOYh3Z+3; 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.79 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20210112 header.b=gOYh3Z+3; 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: EF40127C8D X-Spam-Score: -1.79 X-Migadu-Scanner: scn0.migadu.com X-TUID: tJeAE7rr46uw --=-=-= Content-Type: text/plain Max Nikulin writes: > This is related solely to docscring. > >> +that is not found, use the first #+ATTR_.*:width specification. > > I am unsure how to make this phrase more clear, maybe something like > "use :width value from the first #+ATTR_,*" or even "#+ATTR_xxx" to > avoid ".*". > >> + (re-search-forward (funcall attr-re "[a-z]*?") >> + par-end t)))) > > https://orgmode.org/worg/dev/org-syntax.html#Keywords > has no requirement that it may be letter only. I expect it to be more > coherent with > http://git.savannah.gnu.org/cgit/emacs/org-mode.git/tree/lisp/org-element.el#n2387 > that uses "\\S-" non-space character. Better? Matt --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=attr_org.patch >From 73f6d6d0c16d9b3312737463361cefe08b01d35c 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..3718d3118 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 "\\S-+?") + par-end t)))) (match-string 1))) (width (cond -- 2.31.1 >From 76e92428716f2dcde0fbd281f71739c44a9be9d3 Mon Sep 17 00:00:00 2001 From: Matt Huszagh Date: Mon, 22 Nov 2021 23:30:11 -0800 Subject: [PATCH 2/2] 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 3718d3118..b050cb0dd 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_xxx :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 --=-=-=--