]> code.delx.au - gnu-emacs-elpa/blob - doc/ivy-ox.el
Bump version to 0.8.0
[gnu-emacs-elpa] / doc / ivy-ox.el
1 ;;; ivy-ox.el --- org-export settings for Ivy
2
3 ;; Copyright (C) 2015 Free Software Foundation, Inc.
4
5 ;; Author: Oleh Krehel
6
7 ;; This file is part of GNU Emacs.
8
9 ;; This file is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 3, or (at your option)
12 ;; any later version.
13
14 ;; This program is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
18
19 ;; For a full copy of the GNU General Public License
20 ;; see <http://www.gnu.org/licenses/>.
21
22 ;;* ox-texinfo
23 (require 'ox-texinfo)
24 (org-export-define-backend 'texinfo
25 '((bold . org-texinfo-bold)
26 (center-block . org-texinfo-center-block)
27 (clock . org-texinfo-clock)
28 (code . org-texinfo-kbd)
29 (drawer . org-texinfo-drawer)
30 (dynamic-block . org-texinfo-dynamic-block)
31 (entity . org-texinfo-entity)
32 (example-block . org-texinfo-example-block)
33 (export-block . org-texinfo-export-block)
34 (export-snippet . org-texinfo-export-snippet)
35 (fixed-width . org-texinfo-fixed-width)
36 (footnote-definition . org-texinfo-footnote-definition)
37 (footnote-reference . org-texinfo-footnote-reference)
38 (headline . org-texinfo-headline)
39 (inline-src-block . org-texinfo-inline-src-block)
40 (inlinetask . org-texinfo-inlinetask)
41 (italic . org-texinfo-italic)
42 (item . org-texinfo-item)
43 (keyword . org-texinfo-keyword)
44 (line-break . org-texinfo-line-break)
45 (link . org-texinfo-link)
46 (node-property . org-texinfo-node-property)
47 (paragraph . org-texinfo-paragraph)
48 (plain-list . org-texinfo-plain-list)
49 (plain-text . org-texinfo-plain-text)
50 (planning . org-texinfo-planning)
51 (property-drawer . org-texinfo-property-drawer)
52 (quote-block . org-texinfo-quote-block)
53 (radio-target . org-texinfo-radio-target)
54 (section . org-texinfo-section)
55 (special-block . org-texinfo-special-block)
56 (src-block . org-texinfo-src-block)
57 (statistics-cookie . org-texinfo-statistics-cookie)
58 (subscript . org-texinfo-subscript)
59 (superscript . org-texinfo-superscript)
60 (table . org-texinfo-table)
61 (table-cell . org-texinfo-table-cell)
62 (table-row . org-texinfo-table-row)
63 (target . org-texinfo-target)
64 (template . org-texinfo-template)
65 (timestamp . org-texinfo-timestamp)
66 (verbatim . org-texinfo-code)
67 (verse-block . org-texinfo-verse-block))
68 :filters-alist
69 '((:filter-headline . org-texinfo--filter-section-blank-lines)
70 (:filter-parse-tree . org-texinfo--normalize-headlines)
71 (:filter-section . org-texinfo--filter-section-blank-lines))
72 :menu-entry
73 '(?i "Export to Texinfo"
74 ((?t "As TEXI file" org-texinfo-export-to-texinfo)
75 (?i "As INFO file" org-texinfo-export-to-info)
76 (?o "As INFO file and open"
77 (lambda (a s v b)
78 (if a (org-texinfo-export-to-info t s v b)
79 (org-open-file (org-texinfo-export-to-info nil s v b)))))))
80 :options-alist
81 '((:texinfo-filename "TEXINFO_FILENAME" nil nil t)
82 (:texinfo-class "TEXINFO_CLASS" nil org-texinfo-default-class t)
83 (:texinfo-header "TEXINFO_HEADER" nil nil newline)
84 (:texinfo-post-header "TEXINFO_POST_HEADER" nil nil newline)
85 (:subtitle "SUBTITLE" nil nil parse)
86 (:subauthor "SUBAUTHOR" nil nil newline)
87 (:texinfo-dircat "TEXINFO_DIR_CATEGORY" nil nil t)
88 (:texinfo-dirtitle "TEXINFO_DIR_TITLE" nil nil t)
89 (:texinfo-dirdesc "TEXINFO_DIR_DESC" nil nil t)
90 (:texinfo-printed-title "TEXINFO_PRINTED_TITLE" nil nil t)
91 ;; Other variables.
92 (:texinfo-classes nil nil org-texinfo-classes)
93 (:texinfo-format-headline-function nil nil org-texinfo-format-headline-function)
94 (:texinfo-node-description-column nil nil org-texinfo-node-description-column)
95 (:texinfo-active-timestamp-format nil nil org-texinfo-active-timestamp-format)
96 (:texinfo-inactive-timestamp-format nil nil org-texinfo-inactive-timestamp-format)
97 (:texinfo-diary-timestamp-format nil nil org-texinfo-diary-timestamp-format)
98 (:texinfo-link-with-unknown-path-format nil nil org-texinfo-link-with-unknown-path-format)
99 (:texinfo-tables-verbatim nil nil org-texinfo-tables-verbatim)
100 (:texinfo-table-scientific-notation nil nil org-texinfo-table-scientific-notation)
101 (:texinfo-def-table-markup nil nil org-texinfo-def-table-markup)
102 (:texinfo-text-markup-alist nil nil org-texinfo-text-markup-alist)
103 (:texinfo-format-drawer-function nil nil org-texinfo-format-drawer-function)
104 (:texinfo-format-inlinetask-function nil nil org-texinfo-format-inlinetask-function)))
105
106 (defun org-texinfo-kbd (code _contents _info)
107 "Transcode a CODE object from Org to Texinfo."
108 (format "@kbd{%s}" (org-element-property :value code)))
109
110 (defun org-texinfo-plain-list (plain-list contents info)
111 "Transcode a PLAIN-LIST element from Org to Texinfo.
112 CONTENTS is the contents of the list. INFO is a plist holding
113 contextual information."
114 (let* ((attr (org-export-read-attribute :attr_texinfo plain-list))
115 (indic (or (plist-get attr :indic)
116 (plist-get info :texinfo-def-table-markup)))
117 (table-type (plist-get attr :table-type))
118 (type (org-element-property :type plain-list))
119 (list-type (cond
120 ((eq type 'ordered) "enumerate")
121 ((eq type 'unordered) "itemize")
122 ((member table-type '("ftable" "vtable")) table-type)
123 (t "table"))))
124 (if (equal list-type "table")
125 (mapconcat (lambda (s)
126 (cond ((string-match "\\`User Option @code{\\(.*\\)}$" s)
127 (format "@defopt %s\n%s\n@end defopt\n"
128 (match-string-no-properties 1 s)
129 (string-trim
130 (substring s (1+ (match-end 1))))))
131 ((string-match "\\(.*\\)$" s)
132 (let* ((line (match-string 1 s))
133 (body (string-trim
134 (substring s (1+ (match-end 1)))))
135 (symbol-index
136 (if (string-match "@code{\\(\\(?:ivy\\|swiper\\|counsel\\)-[^}]+\\)}" line)
137 (format "@vindex %s\n" (match-string 1 line))
138 ""))
139 (key-index
140 (apply #'concat
141 (mapcar
142 (lambda (s)
143 (format "@kindex %s\n" s))
144 (iox-extract-kbd line)))))
145 (format "@subsubheading %s\n%s@indentedblock\n%s\n@end indentedblock"
146 line
147 (concat symbol-index
148 key-index)
149 body)))
150 (t
151 (concat "@subsubheading " s))))
152 (split-string (substring-no-properties contents) "^@item " t)
153 "\n")
154 (format "@%s\n%s@end %s"
155 (if (eq type 'descriptive) (concat list-type " " indic) list-type)
156 contents
157 list-type))))
158
159 (defun iox-extract-kbd (str)
160 (let ((start 0)
161 res)
162 (while (string-match "@kbd{\\([^}]+\\)}" str start)
163 (setq start (match-end 0))
164 (push (match-string 1 str) res))
165 (nreverse res)))
166
167 ;;* ox-html
168 (require 'ox-html)
169 (setq org-html-validation-link nil)
170 (setq org-html-postamble nil)
171 (setq org-html-text-markup-alist
172 '((bold . "<b>%s</b>")
173 (code . "<kbd>%s</kbd>")
174 (italic . "<i>%s</i>")
175 (strike-through . "<del>%s</del>")
176 (underline . "<span class=\"underline\">%s</span>")
177 (verbatim . "<code>%s</code>")))
178 (setq org-html-style-default nil)
179
180 (defvar ivy-info-dir (file-name-directory
181 (or load-file-name
182 (buffer-file-name))))
183
184 (defun info-ivy ()
185 (interactive)
186 (let ((buf (get-buffer "*info*")))
187 (when buf
188 (kill-buffer buf)))
189 (Info-find-node
190 (expand-file-name "ivy.info" ivy-info-dir)
191 "Top"))
192
193 (provide 'ivy-ox)