* Ability to hide / collapse in-buffer settings?
@ 2021-07-06 23:25 Matthew Twomey
2021-07-13 3:16 ` Matthew Twomey
0 siblings, 1 reply; 2+ messages in thread
From: Matthew Twomey @ 2021-07-06 23:25 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 749 bytes --]
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: 985 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Ability to hide / collapse in-buffer settings?
2021-07-06 23:25 Ability to hide / collapse in-buffer settings? Matthew Twomey
@ 2021-07-13 3:16 ` Matthew Twomey
0 siblings, 0 replies; 2+ messages in thread
From: Matthew Twomey @ 2021-07-13 3:16 UTC (permalink / raw)
To: emacs-orgmode; +Cc: Emacs-orgmode
[-- 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 --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-07-13 3:17 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-07-06 23:25 Ability to hide / collapse in-buffer settings? Matthew Twomey
2021-07-13 3:16 ` Matthew Twomey
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).