emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Matthew Twomey <mtwomey@beakstar.com>
To: emacs-orgmode@gnu.org
Cc: Emacs-orgmode <emacs-orgmode-bounces+mtwomey=beakstar.com@gnu.org>
Subject: Re: Ability to hide / collapse in-buffer settings?
Date: Mon, 12 Jul 2021 22:16:21 -0500	[thread overview]
Message-ID: <a6bff00ac850b630c6b13174dc147f25@mail.beakstar.com> (raw)
In-Reply-To: <ed766ef0ad45b81a6e54852193580f48@mail.beakstar.com>

[-- Attachment #1: Type: text/plain, Size: 2874 bytes --]

 

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: truen")
 (image-drawers (reverse (org-element-map (org-element-parse-buffer)
 'drawer
 (lambda (el)
 (when (string= drawer-name (org-element-property :drawer-name el))
 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: truen")
 (image-paragraphs (reverse (org-element-map (org-element-parse-buffer)
 'paragraph
 (lambda (el)
 (when (string= "true" (nth 0 (org-element-property :attr_save el)))
 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))
 "n:END:")))))

(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."
 (unpack-image-drawers)
 (apply f r)
 (repack-image-drawers)
 (org-hide-drawer-all))

(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: 

> Greetings, 
> 
> 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
> [[file:homepage.org_imgs/20210706_002617_ok9v4c.png]] 
> 
> 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? 
> 
> Thanks, 
> 
> -Matt

 

[-- Attachment #2: Type: text/html, Size: 3995 bytes --]

      reply	other threads:[~2021-07-13  3:17 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-06 23:25 Ability to hide / collapse in-buffer settings? Matthew Twomey
2021-07-13  3:16 ` Matthew Twomey [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a6bff00ac850b630c6b13174dc147f25@mail.beakstar.com \
    --to=mtwomey@beakstar.com \
    --cc=emacs-orgmode-bounces+mtwomey=beakstar.com@gnu.org \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).