emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] Fix regex for determining image width from attribute


From: Max Nikulin
Subject: Re: [PATCH] Fix regex for determining image width from attribute
Date: Tue, 23 Nov 2021 23:44:50 +0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0

On 23/11/2021 14:46, Matt Huszagh wrote:
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.

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))))

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.

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.

+that is not found, use the first #+ATTR_.*:width specification.

Despite ".*" includes ": " before ":width", I would prefer explicit space before ":width".





reply via email to

[Prev in Thread] Current Thread [Next in Thread]