From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id W5svHrUF7WA2RAEAgWs5BA (envelope-from ) for ; Tue, 13 Jul 2021 05:17:09 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id IINwGbUF7WDzfwAAB5/wlQ (envelope-from ) for ; Tue, 13 Jul 2021 03:17:09 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 9F9E41D354 for ; Tue, 13 Jul 2021 05:17:08 +0200 (CEST) Received: from localhost ([::1]:49356 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m38uw-0006X7-Vq for larch@yhetil.org; Mon, 12 Jul 2021 23:17:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50952) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m38uH-0006Mq-08; Mon, 12 Jul 2021 23:16:25 -0400 Received: from sewerrat.beakstar.com ([173.15.87.25]:42257) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m38uE-0006r8-6z; Mon, 12 Jul 2021 23:16:24 -0400 Received: from localhost (localhost [127.0.0.1]) by tbird.beakstar.com (Postfix) with ESMTP id 6AB2315323A; Mon, 12 Jul 2021 22:16:23 -0500 (CDT) DomainKey-Signature: a=rsa-sha1; s=dk; d=beakstar.com; c=simple; q=dns; b=JLtIkAF+l+cGwmKrKoxjeod0aZGggqlchey1+MNcaXPRLESA9F+8821Ctpf1LShy0 6prNgWWcIat8y6fgj7bZ0W25+ghA6icIMd2CSQD0REL1Ub0FuTSh6EpnFyeQJmWBCgl 6NNa58hCCiqgmODYncp5bF+8V+79sEpcrCSNoPE= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=beakstar.com; h= user-agent:message-id:references:in-reply-to:subject:subject :from:from:date:date:content-type:content-type:mime-version :received:received; s=dkim; t=1626146182; x=1627960583; bh=X/vmp xmBRmCeu/+oTjcsS5q1eZPKqgMV2/CEP8UwnOY=; b=GQqo7WV3mNqIYeRNgCe2B zNE2j+tYIFOpg/UQy/w3dXdeg9wM+XC5F+PcDSmuSX2LWtWms7T6JdHXMsQ1TSXW q1et3yAtjIhrUqeuG+HAz5a7w3vIaQaJfeBUPk6xe55HSQFKw4GNmpfBbLES5jXo 9Erex94TAD6ZgLVPllfMw8= Received: from sewerrat.beakstar.com ([127.0.0.1]) by localhost (tbird.beakstar.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id TvXE9hzV0VHM; Mon, 12 Jul 2021 22:16:22 -0500 (CDT) Received: from mail.beakstar.com (localhost [127.0.0.1]) by tbird.beakstar.com (Postfix) with ESMTPSA id 28103153234; Mon, 12 Jul 2021 22:16:22 -0500 (CDT) MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="=_6dc0ae90bfaab39c267527734417d6f9" Date: Mon, 12 Jul 2021 22:16:21 -0500 From: Matthew Twomey To: emacs-orgmode@gnu.org Cc: Emacs-orgmode Subject: Re: Ability to hide / collapse in-buffer =?UTF-8?Q?settings=3F?= In-Reply-To: References: Message-ID: X-Sender: mtwomey@beakstar.com User-Agent: Roundcube Webmail/1.0-rc Received-SPF: pass client-ip=173.15.87.25; envelope-from=mtwomey@beakstar.com; helo=sewerrat.beakstar.com X-Spam_score_int: -6 X-Spam_score: -0.7 X-Spam_bar: / X-Spam_report: (-0.7 / 5.0 requ) BAYES_05=-0.5, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HTML_MESSAGE=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1626146229; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=yf3gFCznP4y7qNK5kuoc9QVERIIRXGyTimhtk/92hlg=; b=qelJQ43svzIW/dISXvVos/zitzzf6OJ2mrwnOBctr4Ewcu5KCd7wDEExx1ATaRH4r0q4w0 Z5/TO+rz0sa+Q/wOhNxU2HwGREwBE16ZiCqFjReOQ6hu1Vd4K45o2Y2vIqe4RWGC4aU0uJ peXhFm0Wc7sj7xeVFg/lwdpGNx1585lqdcnHXJAeA1149lmG/lwsnvwe1e1MZE0plNXBL0 YyzPbTcuxw5JWLxI2aE+nplBlHbAqWkN7gnf+IMGyiDLjTzQRswBIvNZNRbSdvFfoZxhPf mxVxKe6/aPOI8+MaVR56xOd5cC2k6H2RFw8UmuomHvjMeC7gOQ3ytAo/CblHfQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1626146229; a=rsa-sha256; cv=none; b=ZhOV9B7I7Z3z3ESLlSI4vLgo5okGZpIsRfEH0TzP+D0ZqKTE+9uFfbkSpJKV4JCSKdfgQt JFq5rfdrIYmDT06MJxm2iCPVquG8ZfMM2MZqDfMH43I0+sh6Q6vUdU0GHKGom7IQbE8aq6 XJKfEJCIKLPVjeRXWTZpY/A9KJDXAVoP0XWcupkbIWWKVCD+iYpooQi376rnITz1nWQS5g 6UlfDYIHUoz9DYaDaDC5LHMivngwKLtUUQ3KgPV1Q2fAL1nh/ceLTp3FxBPwCLscLMsGot xD9anMvNdySElVeA8dHO9KEGfy4jJ++tfQ65w38MUlP0EPNmdnhwxf1s1w3mIQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=beakstar.com header.s=dkim header.b=GQqo7WV3; dmarc=pass (policy=reject) header.from=beakstar.com; spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Migadu-Spam-Score: -0.90 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=beakstar.com header.s=dkim header.b=GQqo7WV3; dmarc=pass (policy=reject) header.from=beakstar.com; spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Migadu-Queue-Id: 9F9E41D354 X-Spam-Score: -0.90 X-Migadu-Scanner: scn0.migadu.com X-TUID: 24I46uHi1s1R --=_6dc0ae90bfaab39c267527734417d6f9 Content-Transfer-Encoding: 7bit Content-Type: text/plain 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 --=_6dc0ae90bfaab39c267527734417d6f9 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8

Just closing the loop on this for anyone that follows in the future. I w= orked out a solution for this, which allows me to keep these setting in dra= wers, but temporarily "unpacks" the draws to just their contents before pai= nting 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)
                                'drawer
                              (lambda (el)
                                (when (string=3D drawer-name (org-element-p=
roperty :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 :content=
s-begin drawer)
                                             (- (org-element-property :cont=
ents-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-buff=
er)
                               'paragraph
                             (lambda (el)
                               (when (string=3D "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-beg=
in paragraph) 1))
                   (concat ":" drawer-name ":\n"
                           (buffer-substring (+ (length save-string) (org-e=
lement-property :begin paragraph))
                                             (- (org-element-property :cont=
ents-begin paragraph) 1))
                           "\n:END:")))))


(defun apply-with-image-drawers-unpacked (f &rest r)
  "Replace drawers named \"IMAGE_INFO\" with their contents, run the functi=
on,
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)<=
/pre>

 

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: :wi= dth 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 s= ettings in a drawer, but that make it invisible to the link element. I've b= een 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

 

 

 
--=_6dc0ae90bfaab39c267527734417d6f9--