org-export-generic.el: Small code clean-up

* org-export-generic.el (org-export-generic-preprocess): Use
`delete-backward-char' instead of `backward-delete-char'.
(org-generic-alist, def-org-export-generic-keyword)
(org-export-generic-remember-section, org-export-generic)
(org-export-generic-format, org-export-generic-header)
(org-generic-level-start): Remove dangling parentheses,
fix indentation.
This commit is contained in:
Bastien Guerry 2012-12-23 12:23:02 +01:00
parent 6b9d77eb8c
commit 91056e2a8d

View file

@ -230,10 +230,7 @@ in this way, it will be wrapped."
; print above and below all body parts ; print above and below all body parts
:body-text-prefix "<p>\n" :body-text-prefix "<p>\n"
:body-text-suffix "</p>\n" :body-text-suffix "</p>\n")
)
;; ;;
;; ascii exporter ;; ascii exporter
;; ;;
@ -290,9 +287,8 @@ in this way, it will be wrapped."
; :body-text-suffix "</t>\n" ; :body-text-suffix "</t>\n"
:body-bullet-list-prefix (?* ?+ ?-) :body-bullet-list-prefix (?* ?+ ?-))
; :body-bullet-list-suffix (?* ?+ ?-) ; :body-bullet-list-suffix (?* ?+ ?-)
)
;; ;;
;; wikipedia ;; wikipedia
@ -327,8 +323,7 @@ in this way, it will be wrapped."
:body-list-format "* %s\n" :body-list-format "* %s\n"
:body-number-list-format "# %s\n" :body-number-list-format "# %s\n"
:body-bullet-list-prefix ("* " "** " "*** " "**** " "***** ") :body-bullet-list-prefix ("* " "** " "*** " "**** " "***** "))
)
;; ;;
;; mediawiki ;; mediawiki
;; ;;
@ -370,10 +365,7 @@ in this way, it will be wrapped."
:body-table-cell-start "|" :body-table-cell-start "|"
:body-table-cell-end "\n" :body-table-cell-end "\n"
:body-table-last-cell-end "|-" :body-table-last-cell-end "|-"
:body-table-hline-start "" :body-table-hline-start "")
)
;; ;;
;; internet-draft .xml for xml2rfc exporter ;; internet-draft .xml for xml2rfc exporter
;; ;;
@ -437,9 +429,7 @@ in this way, it will be wrapped."
:body-list-prefix "<list style=\"symbols\">\n" :body-list-prefix "<list style=\"symbols\">\n"
:body-list-suffix "</list>\n" :body-list-suffix "</list>\n"
:body-list-format "<t>%s</t>\n" :body-list-format "<t>%s</t>\n")
)
("trac-wiki" ("trac-wiki"
:file-suffix ".txt" :file-suffix ".txt"
:key-binding ?T :key-binding ?T
@ -474,8 +464,7 @@ in this way, it will be wrapped."
;; :body-list-suffix "LISTEND" ;; :body-list-suffix "LISTEND"
;; this is ignored! [2010/02/02:rpg] ;; this is ignored! [2010/02/02:rpg]
:body-bullet-list-prefix ("* " "** " "*** " "**** " "***** ") :body-bullet-list-prefix ("* " "** " "*** " "**** " "***** "))
)
("tikiwiki" ("tikiwiki"
:file-suffix ".txt" :file-suffix ".txt"
:key-binding ?U :key-binding ?U
@ -517,11 +506,8 @@ in this way, it will be wrapped."
:underline-format "===%s===" :underline-format "===%s==="
:strikethrough-format "--%s--" :strikethrough-format "--%s--"
:code-format "-+%s+-" :code-format "-+%s+-"
:verbatim-format "~pp~%s~/pp~" :verbatim-format "~pp~%s~/pp~"))
) "A assoc list of property lists to specify export definitions")
)
"A assoc list of property lists to specify export definitions"
)
(setq org-generic-export-type "demo") (setq org-generic-export-type "demo")
@ -538,24 +524,23 @@ export definitions."
(defvar org-export-generic-keywords nil) (defvar org-export-generic-keywords nil)
(defmacro* def-org-export-generic-keyword (keyword (defmacro* def-org-export-generic-keyword (keyword
&key documentation &key documentation
type) type)
"Define KEYWORD as a legitimate element for inclusion in "Define KEYWORD as a legitimate element for inclusion in
the body of an org-set-generic-type definition." the body of an org-set-generic-type definition."
;; TODO: push the documentation and type information
;; somewhere where it will do us some good.
`(progn `(progn
(pushnew ,keyword org-export-generic-keywords) (pushnew ,keyword org-export-generic-keywords)))
;; TODO: push the documentation and type information
;; somewhere where it will do us some good.
))
(def-org-export-generic-keyword :body-newline-paragraph (def-org-export-generic-keyword :body-newline-paragraph
:documentation "Bound either to NIL or to a pattern to be :documentation "Bound either to NIL or to a pattern to be
inserted in the output for every blank line in the input. inserted in the output for every blank line in the input.
The intention is to handle formats where text is flowed, and The intention is to handle formats where text is flowed, and
newlines are interpreted as significant \(e.g., as indicating newlines are interpreted as significant \(e.g., as indicating
preformatted text\). A common non-nil value for this keyword preformatted text\). A common non-nil value for this keyword
is \"\\n\". Should typically be combined with a value for is \"\\n\". Should typically be combined with a value for
:body-line-format that does NOT end with a newline." :body-line-format that does NOT end with a newline."
:type string) :type string)
;;; fontification keywords ;;; fontification keywords
(def-org-export-generic-keyword :bold-format) (def-org-export-generic-keyword :bold-format)
@ -565,15 +550,11 @@ is \"\\n\". Should typically be combined with a value for
(def-org-export-generic-keyword :code-format) (def-org-export-generic-keyword :code-format)
(def-org-export-generic-keyword :verbatim-format) (def-org-export-generic-keyword :verbatim-format)
(defun org-export-generic-remember-section (type suffix &optional prefix) (defun org-export-generic-remember-section (type suffix &optional prefix)
(setq org-export-generic-section-type type) (setq org-export-generic-section-type type)
(setq org-export-generic-section-suffix suffix) (setq org-export-generic-section-suffix suffix)
(if prefix (if prefix
(insert prefix)) (insert prefix)))
)
(defun org-export-generic-check-section (type &optional prefix suffix) (defun org-export-generic-check-section (type &optional prefix suffix)
"checks to see if type is already in use, or we're switching parts "checks to see if type is already in use, or we're switching parts
@ -583,7 +564,7 @@ suffix a later change time."
(when (not (equal type org-export-generic-section-type)) (when (not (equal type org-export-generic-section-type))
(if org-export-generic-section-suffix (if org-export-generic-section-suffix
(insert org-export-generic-section-suffix)) (insert org-export-generic-section-suffix))
(setq org-export-generic-section-type type) (setq org-export-generic-section-type type)
(setq org-export-generic-section-suffix suffix) (setq org-export-generic-section-suffix suffix)
(if prefix (if prefix
@ -640,7 +621,7 @@ underlined headlines. The default is 3."
(list (list
(plist-get (cdr x) :key-binding) (plist-get (cdr x) :key-binding)
(car x))) (car x)))
org-generic-alist) org-generic-alist)
(list (list ? "default")))) (list (list ? "default"))))
r1 r2 ass r1 r2 ass
@ -700,7 +681,7 @@ underlined headlines. The default is 3."
(email (plist-get opt-plist :email)) (email (plist-get opt-plist :email))
(language (plist-get opt-plist :language)) (language (plist-get opt-plist :language))
(quote-re0 (concat "^[ \t]*" org-quote-string "\\>")) (quote-re0 (concat "^[ \t]*" org-quote-string "\\>"))
; (quote-re (concat "^\\(\\*+\\)\\([ \t]*" org-quote-string "\\>\\)")) ; (quote-re (concat "^\\(\\*+\\)\\([ \t]*" org-quote-string "\\>\\)"))
(todo nil) (todo nil)
(lang-words nil) (lang-words nil)
(region (region
@ -881,81 +862,80 @@ underlined headlines. The default is 3."
(if tocprefix (if tocprefix
(push tocprefix thetoc)) (push tocprefix thetoc))
(mapc '(lambda (line) (mapc #'(lambda (line)
(if (string-match org-todo-line-regexp line) (if (string-match org-todo-line-regexp line)
;; This is a headline ;; This is a headline
(progn (progn
(setq have-headings t) (setq have-headings t)
(setq level (- (match-end 1) (match-beginning 1) (setq level (- (match-end 1) (match-beginning 1)
level-offset) level-offset)
level (org-tr-level level) level (org-tr-level level)
txt (match-string 3 line) txt (match-string 3 line)
todo todo
(or (and org-export-mark-todo-in-toc (or (and org-export-mark-todo-in-toc
(match-beginning 2) (match-beginning 2)
(not (member (match-string 2 line) (not (member (match-string 2 line)
org-done-keywords))) org-done-keywords)))
; TODO, not DONE ; TODO, not DONE
(and org-export-mark-todo-in-toc (and org-export-mark-todo-in-toc
(= level umax-toc) (= level umax-toc)
(org-search-todo-below (org-search-todo-below
line lines level)))) line lines level))))
(setq txt (org-html-expand-for-generic txt)) (setq txt (org-html-expand-for-generic txt))
(while (string-match org-bracket-link-regexp txt) (while (string-match org-bracket-link-regexp txt)
(setq txt (setq txt
(replace-match (replace-match
(match-string (if (match-end 2) 3 1) txt) (match-string (if (match-end 2) 3 1) txt)
t t txt))) t t txt)))
(if (and (not tagsintoc) (if (and (not tagsintoc)
(string-match
(org-re "[ \t]+:[[:alnum:]_@:]+:[ \t]*$")
txt))
(setq txt (replace-match "" t t txt))
; include tags but formated
(if (string-match
(org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$")
txt)
(progn
(setq
toctags
(org-export-generic-header
(match-string 1 txt)
export-plist :toc-tags-prefix
:toc-tags-format :toc-tags-suffix))
(string-match (string-match
(org-re "[ \t]+:[[:alnum:]_@:]+:[ \t]*$") (org-re "[ \t]+:[[:alnum:]_@:]+:[ \t]*$")
txt)) txt)
(setq txt (replace-match "" t t txt)) (setq txt (replace-match "" t t txt)))
; include tags but formated (setq toctags tocnotagsstr)))
(if (string-match
(org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$")
txt)
(progn
(setq
toctags
(org-export-generic-header
(match-string 1 txt)
export-plist :toc-tags-prefix
:toc-tags-format :toc-tags-suffix))
(string-match
(org-re "[ \t]+:[[:alnum:]_@:]+:[ \t]*$")
txt)
(setq txt (replace-match "" t t txt)))
(setq toctags tocnotagsstr)))
(if (string-match quote-re0 txt) (if (string-match quote-re0 txt)
(setq txt (replace-match "" t t txt))) (setq txt (replace-match "" t t txt)))
(if (<= level umax-toc) (if (<= level umax-toc)
(progn (progn
(push (push
(concat (concat
(make-string (make-string
(* (max 0 (- level org-min-level)) tocdepth) (* (max 0 (- level org-min-level)) tocdepth)
tocindentchar) tocindentchar)
(if tocsecnums (if tocsecnums
(format tocsecnumform (format tocsecnumform
(org-section-number level)) (org-section-number level))
"") "")
(format (format
(if todo tocformtodo tocformat) (if todo tocformtodo tocformat)
txt) txt)
toctags) toctags)
thetoc) thetoc)
(setq org-last-level level)) (setq org-last-level level))))))
))))
lines) lines)
(if tocsuffix (if tocsuffix
(push tocsuffix thetoc)) (push tocsuffix thetoc))
@ -1075,8 +1055,7 @@ underlined headlines. The default is 3."
listcheckdoneend))) listcheckdoneend)))
((string-match "^\\(\\[/\\]\\)[ \t]*" line) ((string-match "^\\(\\[/\\]\\)[ \t]*" line)
(setq line (concat (replace-match listcheckhalf nil nil line) (setq line (concat (replace-match listcheckhalf nil nil line)
listcheckhalfend))) listcheckhalfend))))
)
(insert (format listformat (org-export-generic-fontify line)))) (insert (format listformat (org-export-generic-fontify line))))
((string-match "^\\([ \t]+\\)\\([0-9]+\\.[ \t]*\\)" line) ((string-match "^\\([ \t]+\\)\\([0-9]+\\.[ \t]*\\)" line)
@ -1101,8 +1080,7 @@ underlined headlines. The default is 3."
listcheckdoneend))) listcheckdoneend)))
((string-match "\\(\\[/\\]\\)[ \t]*" line) ((string-match "\\(\\[/\\]\\)[ \t]*" line)
(setq line (concat (replace-match listcheckhalf nil nil line) (setq line (concat (replace-match listcheckhalf nil nil line)
listcheckhalfend))) listcheckhalfend))))
)
(insert (format numlistformat (org-export-generic-fontify line)))) (insert (format numlistformat (org-export-generic-fontify line))))
@ -1221,20 +1199,18 @@ REVERSE means to reverse the list if the plist match is a list
(if (stringp subtype) (if (stringp subtype)
subtype subtype
(concat (make-string len subtype) "\n"))) (concat (make-string len subtype) "\n")))
(t "")) (t ""))))
))
(defun org-export-generic-header (header export-plist (defun org-export-generic-header (header export-plist
prefixprop formatprop postfixprop prefixprop formatprop postfixprop
&optional n reverse) &optional n reverse)
"convert a header to an output string given formatting property names" "convert a header to an output string given formatting property names"
(let* ((formatspec (plist-get export-plist formatprop)) (let* ((formatspec (plist-get export-plist formatprop))
(len (length header))) (len (length header)))
(concat (concat
(org-export-generic-format export-plist prefixprop len n reverse) (org-export-generic-format export-plist prefixprop len n reverse)
(format (or formatspec "%s") header) (format (or formatspec "%s") header)
(org-export-generic-format export-plist postfixprop len n reverse)) (org-export-generic-format export-plist postfixprop len n reverse))))
))
(defun org-export-generic-preprocess (parameters) (defun org-export-generic-preprocess (parameters)
"Do extra work for ASCII export" "Do extra work for ASCII export"
@ -1242,7 +1218,7 @@ REVERSE means to reverse the list if the plist match is a list
(goto-char (point-min)) (goto-char (point-min))
(while (re-search-forward org-verbatim-re nil t) (while (re-search-forward org-verbatim-re nil t)
(goto-char (match-end 2)) (goto-char (match-end 2))
(backward-delete-char 1) (insert "'") (delete-backward-char 1) (insert "'")
(goto-char (match-beginning 2)) (goto-char (match-beginning 2))
(delete-char 1) (insert "`") (delete-char 1) (insert "`")
(goto-char (match-end 2))) (goto-char (match-end 2)))
@ -1269,9 +1245,9 @@ REVERSE means to reverse the list if the plist match is a list
(while (> len where) (while (> len where)
(catch 'found (catch 'found
(loop for i from where downto (/ where 2) do (loop for i from where downto (/ where 2) do
(and (equal (aref line i) ?\ ) (and (equal (aref line i) ?\ )
(setq pos i) (setq pos i)
(throw 'found t)))) (throw 'found t))))
(if pos (if pos
(progn (progn
(setq result (setq result
@ -1323,22 +1299,18 @@ REVERSE means to reverse the list if the plist match is a list
(insert (insert
(org-export-generic-format export-plist :body-section-prefix 0 (org-export-generic-format export-plist :body-section-prefix 0
(+ old-level counter))) (+ old-level counter)))
(setq counter (1+ counter)) (setq counter (1+ counter))))
))
;; going up ;; going up
((< level old-level) ((< level old-level)
(while (> (- old-level counter) (1- level)) (while (> (- old-level counter) (1- level))
(insert (insert
(org-export-generic-format export-plist :body-section-suffix 0 (org-export-generic-format export-plist :body-section-suffix 0
(- old-level counter))) (- old-level counter)))
(setq counter (1+ counter)) (setq counter (1+ counter))))
))
;; same level ;; same level
((= level old-level) ((= level old-level)
(insert (insert
(org-export-generic-format export-plist :body-section-suffix 0 level)) (org-export-generic-format export-plist :body-section-suffix 0 level))))
)
)
(insert (insert
(org-export-generic-format export-plist :body-section-prefix 0 level)) (org-export-generic-format export-plist :body-section-prefix 0 level))
@ -1464,31 +1436,31 @@ conversions.")
(defun org-export-generic-fontify (string) (defun org-export-generic-fontify (string)
"Convert fontification according to generic rules." "Convert fontification according to generic rules."
(if (string-match org-emph-re string) (if (string-match org-emph-re string)
;; The match goes one char after the *string*, except at the end of a line ;; The match goes one char after the *string*, except at the end of a line
(let ((emph (assoc (match-string 3 string) (let ((emph (assoc (match-string 3 string)
org-export-generic-emphasis-alist)) org-export-generic-emphasis-alist))
(beg (match-beginning 0)) (beg (match-beginning 0))
(end (match-end 0))) (end (match-end 0)))
(unless emph (unless emph
(message "`org-export-generic-emphasis-alist' has no entry for formatting triggered by \"%s\"" (message "`org-export-generic-emphasis-alist' has no entry for formatting triggered by \"%s\""
(match-string 3 string))) (match-string 3 string)))
;; now we need to determine whether we have strikethrough or ;; now we need to determine whether we have strikethrough or
;; a list, which is a bit nasty ;; a list, which is a bit nasty
(if (and (equal (match-string 3 string) "+") (if (and (equal (match-string 3 string) "+")
(save-match-data (save-match-data
(string-match "\\`-+\\'" (match-string 4 string)))) (string-match "\\`-+\\'" (match-string 4 string))))
;; a list --- skip this match and recurse on the point after the ;; a list --- skip this match and recurse on the point after the
;; first emph char... ;; first emph char...
(concat (substring string 0 (1+ (match-beginning 3))) (concat (substring string 0 (1+ (match-beginning 3)))
(org-export-generic-fontify (substring string (match-beginning 3)))) (org-export-generic-fontify (substring string (match-beginning 3))))
(concat (substring string 0 beg) ;; part before the match (concat (substring string 0 beg) ;; part before the match
(match-string 1 string) (match-string 1 string)
(org-export-generic-emph-format (second emph) (org-export-generic-emph-format (second emph)
(match-string 4 string) (match-string 4 string)
(third emph)) (third emph))
(or (match-string 5 string) "") (or (match-string 5 string) "")
(org-export-generic-fontify (substring string end))))) (org-export-generic-fontify (substring string end)))))
string)) string))
(defun org-export-generic-emph-format (format-varname string protect) (defun org-export-generic-emph-format (format-varname string protect)
"Return a string that results from applying the markup indicated by "Return a string that results from applying the markup indicated by
@ -1497,10 +1469,10 @@ FORMAT-VARNAME to STRING."
(let ((string-to-emphasize (let ((string-to-emphasize
(if protect (if protect
string string
(org-export-generic-fontify string)))) (org-export-generic-fontify string))))
(if format (if format
(format format string-to-emphasize) (format format string-to-emphasize)
string-to-emphasize)))) string-to-emphasize))))
(provide 'org-generic) (provide 'org-generic)
(provide 'org-export-generic) (provide 'org-export-generic)