emacs-orgmode
[Top][All Lists]
Advanced

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

[SOLVED] Re: [QUESTION] How to specific image size attributes under head


From: Christopher M. Miles
Subject: [SOLVED] Re: [QUESTION] How to specific image size attributes under headline scope?
Date: Sun, 11 Sep 2022 10:20:12 +0800
User-agent: mu4e 1.8.9; emacs 29.0.50

"Christopher M. Miles" <numbchild@gmail.com> writes:

> [[PGP Signed Part:Undecided]]
> There is attributes setting above image link to specify image inline preview 
> size. Like this:
>
> #+begin_src org
> ,#+ATTR_ORG: :width 500
> ,#+ATTR_LATEX: :width 5.0in
> ,#+ATTR_HTML: :width 500px
> [[file:kk/88320740_p0.jpg]]
>
> #+end_src
>
> When I put it on beginning of org document, then preview inline images, but 
> those global attributes
> not affected. The inline images still display in actual image size. I want to 
> specify image size
> under headline properties. Is it possible to do this?

I implemented this feature by written a hook. Hope this can be helpful
for someone who also has this needs. Here is the code:

#+begin_src emacs-lisp
;;; auto display inline images under current TAB cycle expanded "visible" 
subtree.
(defun org-display-subtree-with-inline-images (&optional state)
  "Toggle the display of inline images under current expanded visible subtree.
INCLUDE-LINKED is passed to `org-display-inline-images'."
  (interactive)
  ;; (not (memq state '(overview folded contents))) ; global state change
  (let ((display-inline-images-local
         (lambda (beg end)
           (org-display-inline-images t t beg end)
           ;; display number of inline images which is intersection of two 
image overlays lists.
           ;; (message "%d images displayed inline"
           ;;          (length (cl-intersection org-inline-image-overlays 
(overlays-in beg end))))
           ))
        (hide-inline-images-local
         (lambda ()
           (setq org-inline-image-overlays nil) ; (org-remove-inline-images)
           (message "Inline image display turned off")))
        (inline-image-width-override ; get headline property value as inline 
image width.
         (lambda ()
           ;; The property "INLINE-IMAGE-WIDTH" value should be integer.
           (let* ((property-value (ignore-errors 
(org-property-or-variable-value 'INLINE-IMAGE-WIDTH)))
                  (width-integer (or (and property-value
                                          (if (numberp property-value) 
property-value (string-to-number property-value)))
                                     (- (/ (window-width (selected-window) t) 
2) 100))))
             (setq-local org-image-actual-width width-integer)))))
    (pcase state
      ('children
       (save-excursion
         (save-restriction
           (org-narrow-to-subtree)
           ;; If has nested headlines, beg,end only from parent headline
           ;; to first child headline which reference to upper let-binding
           ;; `org-next-visible-heading'.
           (funcall display-inline-images-local (point-min) (progn 
(org-next-visible-heading 1) (point))))))
      ('subtree
       (save-excursion
         (save-restriction
           (org-narrow-to-subtree)
           (funcall inline-image-width-override)
           ;; If has nested headlines, also inline display images under all 
sub-headlines.
           (funcall display-inline-images-local (point-min) (point-max)))))
      ('folded
       (funcall hide-inline-images-local)))))

(add-to-list 'org-default-properties "INLINE-IMAGE-WIDTH")

(add-hook 'org-cycle-hook #'org-display-subtree-with-inline-images)

(define-key org-mode-map (kbd "C-c C-x C-v") 
'org-display-subtree-with-inline-images)
#+end_src

-- 

[ stardiviner ]
I try to make every word tell the meaning that I want to express without 
misunderstanding.

Blog: https://stardiviner.github.io/
IRC(libera.chat, freenode): stardiviner, Matrix: stardiviner
GPG: F09F650D7D674819892591401B5DF1C95AE89AC3

Attachment: signature.asc
Description: PGP signature


reply via email to

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