emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Aaron Ecay <aaronecay@gmail.com>
To: Matt Price <moptop99@gmail.com>, Org Mode <emacs-orgmode@gnu.org>
Subject: Re: using flet to suppress meta generation in html export?
Date: Tue, 06 Nov 2018 15:35:53 +0000	[thread overview]
Message-ID: <87a7mm2p7q.fsf@gmail.com> (raw)
In-Reply-To: <CAN_Dec94zwS-3PunRfkkYMvaCyKf3vzLcvqW_YR9VVmBABZuEw@mail.gmail.com>

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

  reply	other threads:[~2018-11-06 15:36 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-06 14:16 using flet to suppress meta generation in html export? Matt Price
2018-11-06 15:35 ` Aaron Ecay [this message]
2018-11-06 16:05   ` Matt Price

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=87a7mm2p7q.fsf@gmail.com \
    --to=aaronecay@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=moptop99@gmail.com \
    /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).