[Top][All Lists]

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

Re: Ability to hide / collapse in-buffer settings?

From: Matthew Twomey
Subject: Re: Ability to hide / collapse in-buffer settings?
Date: Mon, 12 Jul 2021 22:16:21 -0500
User-agent: Roundcube Webmail/1.0-rc

Just closing the loop on this for anyone that follows in the future. I worked out a solution for this, which allows me to keep these setting in drawers, but temporarily "unpacks" the draws to just their contents before painting images or exporting:


(defun unpack-image-drawers (&rest r)
  "Replace drawers named \"IMAGE_INFO\" with their contents."
  (let* ((drawer-name "IMAGE_INFO")
        (save-string "#+ATTR_SAVE: true\n")
        (image-drawers (reverse (org-element-map (org-element-parse-buffer)
                              (lambda (el)
                                (when (string= drawer-name (org-element-property :drawer-name el))
    (cl-loop for drawer in image-drawers do
             (setf (buffer-substring (org-element-property :begin drawer)
                                     (- (org-element-property :end drawer) 1))
                   (concat save-string
                           (buffer-substring (org-element-property :contents-begin drawer)
                                             (- (org-element-property :contents-end drawer) 1)))))))

(defun repack-image-drawers (&rest r)
  "Restore image drawers replaced using `unpack-image-drawers'."
  (let* ((drawer-name "IMAGE_INFO")
        (save-string "#+ATTR_SAVE: true\n")
        (image-paragraphs (reverse (org-element-map (org-element-parse-buffer)
                             (lambda (el)
                               (when (string= "true" (nth 0 (org-element-property :attr_save el)))
    (cl-loop for paragraph in image-paragraphs do
             (setf (buffer-substring (org-element-property :begin paragraph)
                                     (- (org-element-property :contents-begin paragraph) 1))
                   (concat ":" drawer-name ":\n"
                           (buffer-substring (+ (length save-string) (org-element-property :begin paragraph))
                                             (- (org-element-property :contents-begin paragraph) 1))

(defun apply-with-image-drawers-unpacked (f &rest r)
  "Replace drawers named \"IMAGE_INFO\" with their contents, run the function,
finally restore the drawers as they were. Also collapses all drawers before returning."
  (apply f r)

(advice-add #'org-display-inline-images :around #'apply-with-image-drawers-unpacked)
(add-hook 'org-export-before-processing-hook 'unpack-image-drawers)


On 2021-07-06 18:25, Matthew Twomey wrote:


I'm trying to find a way to visually collapse settings related to images in my org docs. I have many images with a syntax similar to:

#+NAME: fig:figure name
#+CAPTION: figure name
#+ATTR_ORG: :width 200
#+ATTR_LATEX: :width 2.0in
#+ATTR_HTML: :width 200

The setting vary per image and I prefer tailoring each image, but I don't like all the clutter on my screen while editing. I've tried putting the settings in a drawer, but that make it invisible to the link element. I've been digging through source code, thinking maybe I could give advice to some function or find something to hook into, but I'm not getting anywhere. Any thoughts or ideas on this?






reply via email to

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