From mboxrd@z Thu Jan 1 00:00:00 1970 From: Matt Price Subject: Re: using flet to suppress meta generation in html export? Date: Tue, 6 Nov 2018 11:05:40 -0500 Message-ID: References: <87a7mm2p7q.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="00000000000096ecb1057a012a9f" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:51621) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gK3rd-0000RP-Vx for emacs-orgmode@gnu.org; Tue, 06 Nov 2018 11:06:08 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gK3rc-00062L-K2 for emacs-orgmode@gnu.org; Tue, 06 Nov 2018 11:06:01 -0500 Received: from mail-it1-x12a.google.com ([2607:f8b0:4864:20::12a]:52370) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gK3ra-0005M3-Fc for emacs-orgmode@gnu.org; Tue, 06 Nov 2018 11:06:00 -0500 Received: by mail-it1-x12a.google.com with SMTP id t190-v6so12835679itb.2 for ; Tue, 06 Nov 2018 08:05:12 -0800 (PST) In-Reply-To: <87a7mm2p7q.fsf@gmail.com> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: Org Mode --00000000000096ecb1057a012a9f Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 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 th= e > > 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, whe= n > > 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=CA=BCt do. Thi= s in > turn means that it should be a more robust way of accomplishing the > desired outcome.) > > -- > Aaron Ecay > --00000000000096ecb1057a012a9f Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
AH, THISI S SUPER-HELPFUL, aARON. MANY THANK.=C2=A0 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 t= he
> Canvas Learning Management System.=C2=A0 I was trying to strip down th= e exported
> HTML to an absolute minimum and had forgotten about the body-only para= mter
> to org-export-as (!!). So, my solution was to try to rebind
> 'org-html--build-meta-info to always just return "".=C2= =A0 =C2=A0However, I can't
> seem to do it properly and I'm wondering if someone can help me fi= gure out
> what's wrong. It's my first time using cl-flet! And I know the= re are
> various approaches, but I odn't understnad whyt this is notworking= , when
> for instance, this does work for me:
>
> (cl-flet ((+
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (lambda (&rest args) (mes= sage "no plus!"))))
>=C2=A0 =C2=A0(+ "whoops"))
> ;; "no plus!"
>
> Meanwhile, here's my=C2=A0 non-functional code:

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

=C2=A0 =C2=A0 =C2=A0The bindings are lexical in scope.=C2=A0 This means tha= t all references
=C2=A0 =C2=A0 =C2=A0to the named functions must appear physically within FO= RMS.

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

(cl-letf (((symbol-function 'org-html--build-meta-info)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(lambda (&rest args) "&qu= ot;)))
=C2=A0 your-code-here)

You could also do something like:

(let ((my-advice (lambda (&rest _) "")))
=C2=A0 (advice-add 'org-html--build-meta-info :override my-advice)
=C2=A0 (unwind-protect
=C2=A0 =C2=A0 =C2=A0 (progn
=C2=A0 =C2=A0 =C2=A0 =C2=A0 your-code-here)
=C2=A0 =C2=A0 (advice-remove 'org-html--build-meta-info my-advice)))
(Why do I think this is better, despite being more verbose?=C2=A0 Advice-ad= d
is specifically designed to change the binding of functions at runtime,
and so it does some specialized things that cl-letf doesn=CA=BCt do.=C2=A0 = This in
turn means that it should be a more robust way of accomplishing the
desired outcome.)

--
Aaron Ecay
--00000000000096ecb1057a012a9f--