[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Question about string-match and match-string
From: |
Rasmus |
Subject: |
Re: Question about string-match and match-string |
Date: |
Sun, 21 Jul 2013 00:25:53 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) |
Julien Cubizolles <j.cubizolles@free.fr> writes:
> Rasmus <rasmus@gmx.us> writes:
>
>> (with-eval-after-load 'ox
>> (defun rasmus/org-latex-ignore-heading (headline backend info)
>> "Strip headline from HEADLINE if it has tag ignoreheading for
>> certain headlines. `info' is ignored"
>> (when (and (org-export-derived-backend-p backend 'latex 'html 'ascii
>> 'odt)
>> (string-match "\\`.*ignoreheading.*\n"
>> (downcase headline)))
>> (replace-match "" nil nil headline)))
>>
>> (add-to-list 'org-export-filter-headline-functions
>> 'rasmus/org-latex-ignore-heading))
>
> It's working, thanks, but it's ignored if you use tags:nil option (which
> is pretty common I guess).
Well. . . If you never want tags perhaps the correct way is to never
have tag export e.g. via a filter or a derived backend.
> If however you use
>
> #+TITLE: Titre
> #+OPTIONS: tags:nil
>
> * First Heading :tag:
> blablabla
> * Second Heading :ignoreheading:
> blablabla
>
> Both the first and second heading are displayed (not what I want).
Try this then. . . It's ugly. Also, you can't easily do this with
html due to divs and tab of contents, manually numbering etc. So
you'd need a derived backend. I don't know about odt.
It's an ugly hack.
(defun rasmus/org-latex-ignore-heading (headline backend info)
"Strip headline from HEADLINE if it has tag ignoreheading."
(let* ((tags (org-element-property :tags
(plist-get
(text-properties-at
(- (string-match "\n" headline) 2)
headline)
:parent))))
(when (and (member-ignore-case "ignoreheading" tags)
(org-export-derived-backend-p backend 'latex 'ascii))
(string-match "\\`.*\n.*\n" headline)
(replace-match "" nil nil headline))))
Alternatively, you can add hook removing lines before parsing which
would give nice results in all backend, but then this won't work:
* h1 :noexport:
* h2 :ignoreheading:
my protected section
If you never have such constructions this is a better solution.
(defun rasmus/remove-ignored-headlines-before-parse (backend)
"Remove headlines with tag \"ignoreheading\" before parsing"
(dolist (x
(org-element-map (org-element-parse-buffer 'headlines)
'headline (lambda (h) (cons (org-element-property :tags h)
(org-element-property :begin h)))))
(save-excursion (when (member-ignore-case "ignoreheading" (car x))
(goto-char (cdr x)) (delete-region
(line-beginning-position) (line-end-position))))))
(add-hook 'org-export-before-parsing-hook
'rasmus/remove-ignored-headlines-before-parse)
> Finally, something weird with the title: if you don't define it with de
> #+TITLE, it's set to name_of_thefile$_{\text{ignoreheading}}$...
I can't reproduce.
–Rasmus
--
A page of history is worth a volume of logic
- Question about string-match and match-string, Suvayu Ali, 2013/07/17
- Re: Question about string-match and match-string, Suvayu Ali, 2013/07/17
- Re: Question about string-match and match-string, Rasmus, 2013/07/17
- Re: Question about string-match and match-string, Suvayu Ali, 2013/07/17
- Re: Question about string-match and match-string, Julien Cubizolles, 2013/07/18
- Re: Question about string-match and match-string, Rasmus, 2013/07/18
- Re: Question about string-match and match-string, Julien Cubizolles, 2013/07/20
- Re: Question about string-match and match-string,
Rasmus <=
- Re: Question about string-match and match-string, Rasmus, 2013/07/20
- Re: Question about string-match and match-string, Julien Cubizolles, 2013/07/21
Re: Question about string-match and match-string, Nicolas Richard, 2013/07/17