;;Docbook mode stuff
(setq auto-mode-alist
(append
;; .docbook files get docbook-mode
'(("\\.docbook" . docbook-mode)
("\\.cgi" . cperl-mode)
("\\.pl" . cperl-mode)
("\\.pm" . cperl-mode))
auto-mode-alist))
(add-hook 'docbook-mode-hook
`(lambda ()
(show-paren-mode 1)
(auto-fill-mode 1)
(flyspell-mode 1)
(local-set-key [C-tab] 'docbook-complete)
(local-set-key [tab] 'docbook-force-electric-tab)
(local-set-key "\C-c\C-s" 'docbook-selection-function-dispatch)
(local-set-key "\C-c\C-d" 'docbook-function-dispatch)
(setq indent-line-function 'docbook-force-electric-tab)
))
;; this function takes a single character which tells it which
;; docbook function to call. Bind this to something like ^c^d
;; then all your docbook insertion commands begin with ^c^d
;; followed by the letter indicating the tag. This function is
;; for tag insertion commands
(defun docbook-function-dispatch (which_func)
(interactive "c")
(cond ((eq which_func ?S) (docbook-insert-sect-tag (read-char)))
((eq which_func ?s) (docbook-insert-section-tag))
((eq which_func ?f) (docbook-insert-figure-tag))
((eq which_func ?u) (docbook-insert-unordered-list-tag))
((eq which_func ?o) (docbook-insert-ordered-list-tag))
((eq which_func ?l) (docbook-insert-listitem-tag))
((eq which_func ?p) (docbook-insert-para-tag))
((eq which_func ?n) (docbook-insert-footnote-tag))
((eq which_func ?e) (docbook-insert-emphasis-tag))
((eq which_func ?E) (docbook-insert-emphasis-tag 'strong))
((eq which_func ?x) (docbook-insert-xref-tag))
((eq which_func ?i) (docbook-insert-literal-tag))
((eq which_func ?P) (docbook-insert-programlisting-tag))
((eq which_func ?t) (docbook-insert-userspecified-tag))
(t (beep))))
(defun docbook-insert-sect-tag (p)
;;; needed only if called directly instead of through dispatch
;;; (interactive "c")
(let ((id (read-from-minibuffer "Section ID: ")))
(progn
(setq begin (point))
(insert "\n")
(setq p2 (point-marker))
(insert "\n\n\n\n")
(setq end (point))
(indent-region begin end nil)
(goto-char p2))))
(defun docbook-insert-section-tag ()
;;; needed only if called directly instead of through dispatch
;;; (interactive "c")
(let ((id (read-from-minibuffer "Section ID: ")))
(progn
(setq begin (point))
(insert "\n")
(setq p2 (point-marker))
(insert "\n\n\n\n")
(setq end (point))
(indent-region begin end nil)
(goto-char p2))))
(defun docbook-insert-figure-tag ()
;;; (interactive)
(let ((id (read-from-minibuffer "Mediaobject ID: "))
(title (read-from-minibuffer "Object Title and Caption: "))
(filename (read-from-minibuffer "File Name (without extension): ")))
(progn
(setq begin (point))
(insert "\n")
(insert "" title "\n")
(insert "\n")
(insert "\n\n")
(insert "\n")
(insert "\n\n")
(insert "\n")
(insert "\n")
(insert "\n")
(setq end (point))
(indent-region begin end nil))))
(defun docbook-insert-unordered-list-tag ()
(progn
(setq begin (point))
(insert "\n")
(insert "")
(setq ipoint (point-marker))
(insert "\n\n")
(insert "\n")
(indent-region begin (point) nil)
(goto-char ipoint)))
(defun docbook-insert-ordered-list-tag ()
(progn
(setq begin (point))
(insert "\n")
(insert "")
(setq ipoint (point-marker))
(insert "\n\n")
(insert "\n")
(indent-region begin (point) nil)
(goto-char ipoint)))
(defun docbook-insert-listitem-tag ()
(progn
(setq begin (point))
(insert "")
(setq ipoint (point-marker))
(insert "\n")
(indent-region begin (point) nil)
(goto-char ipoint)))
(defun docbook-insert-para-tag ()
(progn
(setq begin (point))
(insert "")
(setq ipoint (point-marker))
(insert "\n")
(indent-region begin (point) nil)
(goto-char ipoint)))
(defun docbook-insert-footnote-tag ()
(progn
(setq begin (point))
(insert "")
(setq ipoint (point-marker))
(insert "\n")
(indent-region begin (point) nil)
(goto-char ipoint)))
(defun docbook-insert-emphasis-tag (&optional strong)
(progn
(setq begin (point))
(insert "")
(setq ipoint (point-marker))
(insert "")
(indent-region begin (point) nil)
(goto-char ipoint)))
(defun docbook-insert-xref-tag ()
(let ((id (read-from-minibuffer "xref linkend ID: ")))
(insert "")))
(defun docbook-insert-literal-tag ()
(progn
(setq begin (point))
(insert "")
(setq ipoint (point-marker))
(insert "")
(indent-region begin (point) nil)
(goto-char ipoint)))
(defun docbook-insert-programlisting-tag ()
(progn
(setq begin (point))
(insert "\n")
(insert "# ")
(setq ipoint (point-marker))
(insert "\n")
(insert "")
(indent-region begin (point) nil)
(goto-char ipoint)))
(defun docbook-insert-userspecified-tag ()
(let ((tag (completing-read "Insert tag: " docbook-all-elements-alist)))
(progn
(setq begin (point))
(insert "<" tag ">")
(setq ipoint (point-marker))
(insert "\n" tag ">")
(indent-region begin (point) nil)
(goto-char ipoint))))
;; this function takes a single character which tells it which
;; docbook function to call. Bind this to something like ^c^d
;; then all your docbook insertion commands begin with ^c^d
;; followed by the letter indicating the tag. This function is
;; for commands that surround the selected text with tag elements.
;; This is especially useful when docbookizing existing
;; documentation
(defun docbook-selection-function-dispatch (which_func)
(interactive "c")
(cond ((eq which_func ?g) (docbook-glossify-term (region-beginning) (region-end)))
((eq which_func ?p) (docbook-paraify-term (region-beginning) (region-end)))
((eq which_func ?l) (docbook-listitemify-term (region-beginning) (region-end)))
((eq which_func ?e) (docbook-emphasisify-term (region-beginning) (region-end)))
((eq which_func ?E) (docbook-emphasisify-term (region-beginning) (region-end) 'strong))
((eq which_func ?t) (docbook-apply-input-tag (region-beginning) (region-end)))
((eq which_func ?i) (docbook-literalify-term (region-beginning) (region-end)))
((eq which_func ?v) (docbook-varlistentryify-selection ))
(t (beep))))
(defun docbook-glossify-term (begin end)
;; (interactive "r")
(let ((id (read-from-minibuffer "glossary linkend ID: ")))
(progn
(goto-char end)
(insert "")
(goto-char begin)
(insert ""))))
(defun docbook-paraify-term (begin end)
;; (interactive "r")
(progn
(goto-char end)
(insert "\n")
(goto-char begin)
(insert "")
(indent-region begin (+ 5 end) nil)
))
(defun docbook-listitemify-term (begin end)
;; (interactive "r")
(progn
(goto-char end)
(insert "")
(goto-char begin)
(insert "")))
(defun docbook-emphasisify-term (begin end &optional strong)
(progn
(goto-char end)
(insert "")
(goto-char begin)
(insert "")))
(defun docbook-apply-input-tag (begin end )
;; (let ((tag (read-from-minibuffer "Surround selected text with tag: ")))
(let ((tag (completing-read "Surround selected text with tag: " docbook-all-elements-alist)))
(progn
(goto-char end)
(insert "" tag ">")
(goto-char begin)
(insert "<" tag ">"))))
(defun docbook-literalify-term (begin end)
(progn
(goto-char end)
(insert "")
(goto-char begin)
(insert "")))
(defun docbook-varlistentryify-selection ()
(progn
(read-from-minibuffer "Select the term and then press enter..." )
(setq beginterm (region-beginning))
(setq endterm (region-end))
(read-from-minibuffer "Select the def. and then press enter..." )
(setq begindef (region-beginning))
(setq enddef (region-end))
(goto-char beginterm)
(insert "")
(goto-char endterm)
(insert "")
(docbook-listitemify-term begindef enddef)
))
;;;; end docbook functions