From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Goaziou Subject: Re: [patch, ox] Unnumbered headlines Date: Fri, 03 Oct 2014 09:56:55 +0200 Message-ID: <87iok1twl4.fsf@nicolasgoaziou.fr> References: <87lhqzyubg.fsf@gmx.us> <87bnrrp0tb.fsf@nicolasgoaziou.fr> <87r40n6nrg.fsf@gmx.us> <87egwmaxte.fsf@nicolasgoaziou.fr> <87k34y701i.fsf@gmx.us> <87fvfl86ct.fsf@nicolasgoaziou.fr> <87k34xghtt.fsf@gmx.us> <87ppeon4mw.fsf@nicolasgoaziou.fr> <87tx4020lh.fsf@gmx.us> <87vboflkil.fsf@nicolasgoaziou.fr> <87iokfdvi3.fsf@gmx.us> <87d2aiesce.fsf@nicolasgoaziou.fr> <87lhp0iusr.fsf@pank.eu> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:60440) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XZxit-0001BD-Ac for emacs-orgmode@gnu.org; Fri, 03 Oct 2014 03:56:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XZxil-0003xy-8W for emacs-orgmode@gnu.org; Fri, 03 Oct 2014 03:56:19 -0400 Received: from relay3-d.mail.gandi.net ([2001:4b98:c:538::195]:55010) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XZxik-0003xq-RZ for emacs-orgmode@gnu.org; Fri, 03 Oct 2014 03:56:11 -0400 In-Reply-To: <87lhp0iusr.fsf@pank.eu> (rasmus@gmx.us's message of "Wed, 01 Oct 2014 00:54:12 +0200") 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-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Rasmus Cc: emacs-orgmode@gnu.org, alantyree@gmail.com Hello, Rasmus writes: > Alan did some testing on a slightly older version of this patch and he > managed to publish his book without errors and with working links. So > let's give it another shot. > > I briefly tested the output of LaTeX, html, texinfo, odt, md, and > plaintext and made sure links work and that the right text is shown in > the output. Thanks. It looks mostly good. Some minor comments follow. >> I think the following is more in the spirit of the code (you don't >> ignore :custom-id property): >> >> (ids (delq nil >> (list (org-element-property :CUSTOM_ID headline) >> (org-export-get-headline-id headline info) >> (org-element-property :ID headline)))) >> (preferred-id (car ids)) > > But we are not checking that :CUSTOM_ID is unique. This is not our problem, but user's. > In ox-latex you're required to turn on a variable on to get this > behavior (I could be mistaken here). For now I have done as you > suggest. But I don't understand why we are favoring CUSTOM_ID here > over the nice, unique label we've generated? We could do the same as ox-latex, default to generated label, and optionally allow users to use raw custom-id instead (with usual caveat). Meanwhile, I think it is reasonable to stick to the current behaviour. >> Last line: >> >> (list headline (incf num)) > > Oh incf is quite handy. Didn't know that one. > > I leave it as (cons headline (list (incf num))). Why? 'Cause that's > the format used by `org-export--collect-headline-numbering'. While > simpler is nicer, I think it's better not to have to consider > different data structures depending on whether data is from > `org-export--collect-headline-numbering' or > `org-export--collect-unnumbered-headline-id'. I don't get your point. (cons 'a (list 'b)) is equivalent to (list 'a 'b). Why do you think this changes the data structure? >> (unless (org-some >> (lambda (h) (org-not-nil (org-element-property :UNNUMBERED h)= )) >> (org-export-get-genealogy headline)) >> ...) > > Handy. AFAIK BLOB is not a member of (org-export-get-genealogy BLOB) > (or so the output suggests), so (or =C2=B7 =C2=B7) is still needed. I think (org-some (lambda (h) ...) (cons headline (org-export-get-genealogy headline))) is more elegant. > + ;; headline linked via CUSTOM_ID ;; Headline linked via CUSTOM_ID. > + (or (and (string=3D type "custom-id") > + (org-element-property :CUSTOM_ID destination)) > + (org-export-get-headline-id destination info) > + (t (error "Shouldn't reach here")))) > ;; What description to use? > (desc > ;; Case 1: Headline is numbered and LINK has no > @@ -3073,13 +3063,16 @@ holding contextual information." > (let* ((class-num (+ (org-export-get-relative-level parent info) > (1- (plist-get info :html-toplevel-hlevel)))) > (section-number > - (mapconcat > - 'number-to-string > - (org-export-get-headline-number parent info) "-"))) > + (and (org-export-numbered-headline-p parent info) > + (mapconcat > + 'number-to-string Nitpick: #'number-to-string > + ;; Test if destination is a numbered headline Missing full stop. > + (let ((num 0)) > + (org-element-map data 'headline > + (lambda (headline) > + (unless (org-export-numbered-headline-p headline options) > + (cons headline (list (incf num)))))))) See above. > + (unless > + (or (org-element-property :UNNUMBERED headline) > + (org-some (lambda (head) (org-not-nil (org-element-property :UNNUMBER= ED head))) > + (org-export-get-genealogy headline))) > + (let ((sec-num (plist-get info :section-numbers)) > + (level (org-export-get-relative-level headline info))) > + (if (wholenump sec-num) (<=3D level sec-num) sec-num)))) Per above (unless (org-some (lambda (h) (org-not-nil (org-element-property :UNNUMBERED h))) (cons headline (org-export-get-genealogy headline))) ...) > +(ert-deftest test-org-export/org-export-get-headline-id () > + "Test `org-export-get-headline-id' specifications." > + (should > + (equal "sec-1" > + (org-test-with-parsed-data "* Headline" > + (org-export-get-headline-id > + (org-element-map tree 'headline 'identity info t) > + info)))) > + (should > + (equal "unnumbered-1" > + (org-test-with-parsed-data "* Headline\n:PROPERTIES:\n:UNNUMBERED: t\= n:END:" > + (org-export-get-headline-id > + (org-element-map tree 'headline 'identity info t) > + info)))) > + (should > + (equal "unnumbered-1" > + (org-test-with-parsed-data "* Headline\n#+OPTIONS: num:nil" > + (org-export-get-headline-id > + (org-element-map tree 'headline 'identity info t) > + info))))) I suggest to also test tricky inherited UNNUMBERED properties * H :PROPERTIES: :UNNUMBERED: t :END: ** H2 :PROPERTIES: :UNNUMBERED: nil :END: *** H3 Regards, --=20 Nicolas Goaziou