From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id gA8IO1icnWEavAAAgWs5BA (envelope-from ) for ; Wed, 24 Nov 2021 02:58:48 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id AF+1NlicnWGTQQAA1q6Kng (envelope-from ) for ; Wed, 24 Nov 2021 01:58:48 +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 2AF7D2EA91 for ; Wed, 24 Nov 2021 02:58:48 +0100 (CET) Received: from localhost ([::1]:56570 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mphYc-0005rV-Ky for larch@yhetil.org; Tue, 23 Nov 2021 20:58:46 -0500 Received: from eggs.gnu.org ([209.51.188.92]:38636) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mphXh-0005r8-Gc for emacs-orgmode@gnu.org; Tue, 23 Nov 2021 20:57:49 -0500 Received: from [2607:f8b0:4864:20::1030] (port=50886 helo=mail-pj1-x1030.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mphXf-0007aW-PH for emacs-orgmode@gnu.org; Tue, 23 Nov 2021 20:57:49 -0500 Received: by mail-pj1-x1030.google.com with SMTP id x7so1144060pjn.0 for ; Tue, 23 Nov 2021 17:57:46 -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=HVY03GcJdr14XRDvPi4hdCKmCCam3prpyQWg4Qw1JGM=; b=CU4L9hAbkfmaIjE6bb3rHUbpaKWqhBMKPAINMl+FWe7MrVwoxTgObrviQjuV9O0Zzl MfQ0wegLJTim97e3fdc1JU6vCtUbC7F7AAEIZJF+YnL7/AvifQ698PcBUwg7/S3A6cYK xUyRxh0oITfJQZDNzYWEixdUoROzyOZcOfeM+HdPvoMGYCEKXX681YCxxKMhEyjNXBOo Do0nrlM9yCB5Y8eb/5g3YIbE5HBr+14ISMHy8HGC3X73x4q4OTrhWX7kt3IZW0clHFDm RNS8bWTZfQxJcMi9zkLJ5gvyWsRf4rFsh+33xOVB+HTZh0jRbHDO7mAasGuPtTTy1w9K k/JQ== 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=HVY03GcJdr14XRDvPi4hdCKmCCam3prpyQWg4Qw1JGM=; b=ORHrEXcUkbUU2fTPOXkl4XnPV7mbZL9LR5WrNqTtG4Jgz0tIDJpJvgo3rynal++r3U NHn/R0+RipAOSnSRrqurSt1YuEmZwdLSd0Wq4uapT996tIce1CR+GLxwECBb9DjZZ2rR An0J5eGt9eA5rxXyr/yLhrwMOrBGdcpUiwFG1y/nmI1f5tl4nBpg1z69NbRpRT+Nc+iU WxWiYssIBHgwOiMnRHfnsO/X83QUIZqPmapu4gLSlxSq1EfN09fWcK3xtLZoSNQSzf6b J3AsMhISYabVBDL9E/4BeruNJHLDJxn8ZdxPFAII6kd2aJACWvISnHgwzCUqo8b1mBQy nvpg== X-Gm-Message-State: AOAM530e9FANwIFymLMzWUxOJn2fK69ehE6TIJgBXwnHtcFELRFv3+0P 8Lf2fDfIYwsG0kmPM98fYJHt2LcUVJE= X-Google-Smtp-Source: ABdhPJz/tTsphmcFXrd6Dl7XiWfapHEXc1+dffAGjdw2IC6VwzT7FTdGVeBcsQPpN3QVe8L5qzVLBw== X-Received: by 2002:a17:90b:1c07:: with SMTP id oc7mr3075489pjb.127.1637719065343; Tue, 23 Nov 2021 17:57:45 -0800 (PST) Received: from ryzen3950 (c-208-82-98-189.rev.sailinternet.net. [208.82.98.189]) by smtp.gmail.com with ESMTPSA id l4sm15001248pfc.121.2021.11.23.17.57.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Nov 2021 17:57:44 -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> Date: Tue, 23 Nov 2021 17:57:43 -0800 Message-ID: <87h7c2pb6w.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::1030 (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::1030; envelope-from=huszaghmatt@gmail.com; helo=mail-pj1-x1030.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: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1637719128; 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=HVY03GcJdr14XRDvPi4hdCKmCCam3prpyQWg4Qw1JGM=; b=MCqnFpzngQiQg7qgyDc8gq1zFDpIG1y0Dtu+sjav7P10xTVlo//1LiVd2XIxY1hl9UHGUK CL484ljsrpM6DjqhNef5/jhqh/Ago5XeuvnTd7FgW64bRooYiQxg9IR7arkiSI0LZZ0XS6 zGa3H0o6t0+iBocBxBJK6r//xyS8Bym6oCuGp/GedEnWmGXAjgx4WmtoURKzc44jr1Jz91 G2IBsOcYh8iCwNm835fyTCNphdp6eS1+osSALSz/Wmif8cas83xlGKtTzjj4EdWHJaGFqP HavTyvmN7uX5oK7+CDWIDRi/lLqNubniENh5KYFMK64hwqDWTuUF2xqJU3DhOw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1637719128; a=rsa-sha256; cv=none; b=RngWHnw4QwACePW46k7IJyFX05wMiLrgeSR46P1hPzqGKXoAtelumHFPXSbdY/ZwpWpTLG 60MNAEvPzNJxkkAoXfPhxDkh4S978BX38HBSNRTBNuYC+zXEQ1jbZSDRB2Y3ebKcYpazGy 9gcLW6ElWFmnZtICXg65Vbz+wFdXU/tnxxh6mg1oXS3+TUR0cWVvoWindpGFASLFCBQU/s iWBOKLnyP2d4ESP7yjm3khfYCO0rfhsJ6Qsgvc1DLubtHNJexVjsyKAogE6CP51OrabcSw Vsl6l8ZfapI/zbMSXBDVxtImqpwZOr53u3/5lokpNTTTpnmf/LyYIrMpGpzsNw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20210112 header.b=CU4L9hAb; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@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=CU4L9hAb; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Migadu-Queue-Id: 2AF7D2EA91 X-Spam-Score: -1.79 X-Migadu-Scanner: scn1.migadu.com X-TUID: 1IkzVPi5p3V/ --=-=-= Content-Type: text/plain Max Nikulin writes: > I may be wrong, but it seems both the old and the new regexps match > > #+attr_html : :width 50% > > that is not a keyword due to a space before ":". The dot in the regexp > is too permissive. I agree. > Despite ".*" includes ": " before ":width", I would prefer explicit > space before ":width". Currently we have a space before .*. Would you prefer it after? Anyway, I've also implemented this change. Let me know what you think. Matt --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=attr_org.patch >From 76a0c05cec8e449efd5cbffd8123338912815f17 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..5f9d120a2 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 "[a-z]*?") + par-end t)))) (match-string 1))) (width (cond -- 2.31.1 >From 0bc320b895ffb80a2a3ca8fb494e0aabe76180a3 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 5f9d120a2..37369cdb6 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 --=-=-=--