all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* using flet to suppress meta generation in html export?
@ 2018-11-06 14:16 Matt Price
  2018-11-06 15:35 ` Aaron Ecay
  0 siblings, 1 reply; 3+ messages in thread
From: Matt Price @ 2018-11-06 14:16 UTC (permalink / raw)
  To: Org Mode

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

Hi,

I was writing a function to quickly post the ocntents of subtrees to the
Canvas Learning Management System.  I was trying to strip down the exported
HTML to an absolute minimum and had forgotten about the body-only paramter
to org-export-as (!!). So, my solution was to try to rebind
'org-html--build-meta-info to always just return "".   However, I can't
seem to do it properly and I'm wondering if someone can help me figure out
what's wrong. It's my first time using cl-flet! And I know there are
various approaches, but I odn't understnad whyt this is notworking, when
for instance, this does work for me:

(cl-flet ((+
           (lambda (&rest args) (message "no plus!"))))
  (+ "whoops"))
;; "no plus!"

Meanwhile, here's my  non-functional code:

(defun org-lms-headline-to-announcement (&optional course)
  (interactive)
  (unless course
    (setq course org-lms-course))
  (cl-flet ((org-html--build-meta-info
            (lambda (&rest args) "")))
          ;; (prin1 (symbol-function  'org-html--build-meta-info))
          (let* ((org-export-with-toc nil)
                 (org-export-with-smart-quotes nil)
                 (org-html-postamble nil)
                 (org-html-preamble nil)
                 (org-html-xml-declaration nil)
                 (org-html-head-include-scripts nil)
                 (org-html-head-include-default-style nil)
                 ;;(atext (org-export-as 'html t))
                 (atitle (nth 4 (org-heading-components)))
                 (org-html-klipsify-src nil)
                 (org-export-with-title nil)
                 (courseid (plist-get course :id))
                 (atitle (nth 4 (org-heading-components)))
                 (atext (org-export-as 'html t nil t))
                 )
            ;; (message "BUILDMETA DEFN")
            ;; (prin1 (symbol-function  'org-html--build-meta-info))
            (message "%s" atext)
            (org-lms-canvas-json-request
             (format  "courses/%s/discussion_topics" courseid) "POST"
             `(("title" . ,atitle)
               ("message" . ,atext)
               ("is_published" . t)
               ("is_announcement" . t))))))

(well, I mean, it works now that I am doing body-only! doh!

I appreciate any hints, thank you!
Matt

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: using flet to suppress meta generation in html export?
  2018-11-06 14:16 using flet to suppress meta generation in html export? Matt Price
@ 2018-11-06 15:35 ` Aaron Ecay
  2018-11-06 16:05   ` Matt Price
  0 siblings, 1 reply; 3+ messages in thread
From: Aaron Ecay @ 2018-11-06 15:35 UTC (permalink / raw)
  To: Matt Price, Org Mode

Hi Matt,

2018ko azaroak 6an, Matt Price-ek idatzi zuen:
> 
> Hi,
> 
> I was writing a function to quickly post the ocntents of subtrees to the
> Canvas Learning Management System.  I was trying to strip down the exported
> HTML to an absolute minimum and had forgotten about the body-only paramter
> to org-export-as (!!). So, my solution was to try to rebind
> 'org-html--build-meta-info to always just return "".   However, I can't
> seem to do it properly and I'm wondering if someone can help me figure out
> what's wrong. It's my first time using cl-flet! And I know there are
> various approaches, but I odn't understnad whyt this is notworking, when
> for instance, this does work for me:
> 
> (cl-flet ((+
>            (lambda (&rest args) (message "no plus!"))))
>   (+ "whoops"))
> ;; "no plus!"
> 
> Meanwhile, here's my  non-functional code:

Quoting from the info page (info "(cl) Function Bindings"):

     The bindings are lexical in scope.  This means that all references
     to the named functions must appear physically within FORMS.

I believe that you can accomplish what you are trying to do with:

(cl-letf (((symbol-function 'org-html--build-meta-info)
           (lambda (&rest args) "")))
  your-code-here)

You could also do something like:

(let ((my-advice (lambda (&rest _) "")))
  (advice-add 'org-html--build-meta-info :override my-advice)
  (unwind-protect
      (progn
        your-code-here)
    (advice-remove 'org-html--build-meta-info my-advice)))

(Why do I think this is better, despite being more verbose?  Advice-add
is specifically designed to change the binding of functions at runtime,
and so it does some specialized things that cl-letf doesnʼt do.  This in
turn means that it should be a more robust way of accomplishing the
desired outcome.)

-- 
Aaron Ecay

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: using flet to suppress meta generation in html export?
  2018-11-06 15:35 ` Aaron Ecay
@ 2018-11-06 16:05   ` Matt Price
  0 siblings, 0 replies; 3+ messages in thread
From: Matt Price @ 2018-11-06 16:05 UTC (permalink / raw)
  To: Org Mode

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

AH, THISI S SUPER-HELPFUL, aARON. MANY THANK.  i'M HOPING THAT BY THE TIME
i RETIRE i WILL BEGIN TO UNDERSTAND LEXICAL SCOPING IN LISP...


On Tue, Nov 6, 2018 at 10:35 AM Aaron Ecay <aaronecay@gmail.com> wrote:

> Hi Matt,
>
> 2018ko azaroak 6an, Matt Price-ek idatzi zuen:
> >
> > Hi,
> >
> > I was writing a function to quickly post the ocntents of subtrees to the
> > Canvas Learning Management System.  I was trying to strip down the
> exported
> > HTML to an absolute minimum and had forgotten about the body-only
> paramter
> > to org-export-as (!!). So, my solution was to try to rebind
> > 'org-html--build-meta-info to always just return "".   However, I can't
> > seem to do it properly and I'm wondering if someone can help me figure
> out
> > what's wrong. It's my first time using cl-flet! And I know there are
> > various approaches, but I odn't understnad whyt this is notworking, when
> > for instance, this does work for me:
> >
> > (cl-flet ((+
> >            (lambda (&rest args) (message "no plus!"))))
> >   (+ "whoops"))
> > ;; "no plus!"
> >
> > Meanwhile, here's my  non-functional code:
>
> Quoting from the info page (info "(cl) Function Bindings"):
>
>      The bindings are lexical in scope.  This means that all references
>      to the named functions must appear physically within FORMS.
>
> I believe that you can accomplish what you are trying to do with:
>
> (cl-letf (((symbol-function 'org-html--build-meta-info)
>            (lambda (&rest args) "")))
>   your-code-here)
>
> You could also do something like:
>
> (let ((my-advice (lambda (&rest _) "")))
>   (advice-add 'org-html--build-meta-info :override my-advice)
>   (unwind-protect
>       (progn
>         your-code-here)
>     (advice-remove 'org-html--build-meta-info my-advice)))
>
> (Why do I think this is better, despite being more verbose?  Advice-add
> is specifically designed to change the binding of functions at runtime,
> and so it does some specialized things that cl-letf doesnʼt do.  This in
> turn means that it should be a more robust way of accomplishing the
> desired outcome.)
>
> --
> Aaron Ecay
>

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-11-06 16:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-11-06 14:16 using flet to suppress meta generation in html export? Matt Price
2018-11-06 15:35 ` Aaron Ecay
2018-11-06 16:05   ` Matt Price

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.