Fix `org-image-actual-width' behaviour

* lisp/org.el (org-image-actual-width): Improve docstring.
(org-display-inline-images): Ignore case when looking for ATTR
keywords.  Refactor code.

Reported-by: 'Ihor Radchenko' <yantar92@gmail.com>
<http://lists.gnu.org/r/emacs-orgmode/2019-06/msg00030.html>
This commit is contained in:
Nicolas Goaziou 2019-06-05 18:31:35 +02:00
parent a41e9950ae
commit 5832c8fc93
1 changed files with 16 additions and 23 deletions

View File

@ -15451,12 +15451,10 @@ If there is already a time stamp at the cursor position, update it."
(encode-time 0 0 0 (nth 1 cal-date) (car cal-date) (nth 2 cal-date)))))) (encode-time 0 0 0 (nth 1 cal-date) (car cal-date) (nth 2 cal-date))))))
(defcustom org-image-actual-width t (defcustom org-image-actual-width t
"Should we use the actual width of images when inlining them? "When non-nil, use the actual width of images when inlining them.
When set to t, always use the image width. When set to a number, use imagemagick (when available) to set the
image's width to this value.
When set to a number, use imagemagick (when available) to set
the image's width to this value.
When set to a number in a list, try to get the width from any When set to a number in a list, try to get the width from any
#+ATTR.* keyword if it matches a width specification like #+ATTR.* keyword if it matches a width specification like
@ -15468,7 +15466,9 @@ and fall back on that number if none is found.
When set to nil, try to get the width from an #+ATTR.* keyword When set to nil, try to get the width from an #+ATTR.* keyword
and fall back on the original width if none is found. and fall back on the original width if none is found.
This requires Emacs >= 24.1, build with imagemagick support." When set to any other non-nil value, always use the image width.
This requires Emacs >= 24.1, built with imagemagick support."
:group 'org-appearance :group 'org-appearance
:version "24.4" :version "24.4"
:package-version '(Org . "8.0") :package-version '(Org . "8.0")
@ -16683,23 +16683,16 @@ boundaries."
;; First try to find a width among ;; First try to find a width among
;; attributes associated to the paragraph ;; attributes associated to the paragraph
;; containing link. ;; containing link.
(let ((paragraph (pcase (org-element-lineage link '(paragraph))
(let ((e link)) (`nil nil)
(while (and (setq e (org-element-property (p
:parent e)) (let* ((case-fold-search t)
(not (eq (org-element-type e) (end (org-element-property :post-affiliated p))
'paragraph)))) (re "^[ \t]*#\\+attr_.*?: +.*?:width +\\(\\S-+\\)"))
e))) (when (org-with-point-at
(when paragraph (org-element-property :begin p)
(save-excursion (re-search-forward re end t))
(goto-char (org-element-property :begin paragraph)) (string-to-number (match-string 1))))))
(when
(re-search-forward
"^[ \t]*#\\+attr_.*?: +.*?:width +\\(\\S-+\\)"
(org-element-property
:post-affiliated paragraph)
t)
(string-to-number (match-string 1))))))
;; Otherwise, fall-back to provided number. ;; Otherwise, fall-back to provided number.
(car org-image-actual-width))) (car org-image-actual-width)))
((numberp org-image-actual-width) ((numberp org-image-actual-width)