;;; emacs-wiki-init.el --- configuration file for emacs-wiki

;; This file is part of Michael Olson's Emacs settings.

;; The code in this file may be used, distributed, and modified
;; without restriction.

;; I use initsplit.el to separate customize settings on a per-project
;; basis.

;;; Add to load path
(add-to-list 'load-path "/stuff/proj/emacs/emacs-wiki/mwolson")

;;; Initialize
(require 'emacs-wiki)
(require 'emacs-wiki-menu)
(require 'emacs-wiki-srctag)

;;; Set things up for multiple projects

;; Set projects list
(setq emacs-wiki-projects
      `(("WebWiki" .
         ((emacs-wiki-directories . ("~/proj/notmine/web-copy"))
          (emacs-wiki-project-server-prefix . "/web/")
          (emacs-wiki-publishing-directory
           . "~/proj/notmine/web-out")))
        ("ProjectsWiki" .
         ((emacs-wiki-directories . ("~/proj/notmine/projects-copy"))
          (emacs-wiki-project-server-prefix . "/projects/")
          (emacs-wiki-publishing-directory
           . "~/proj/notmine/project-out")))))

;; Set the menu
(setq emacs-wiki-menu-definition
      '(("About me" "/web/AboutMe.html"
         "About me, contact info.")
        ("Albums" "http://mwolson.risnerolson.org/albums/"
         "Photo albums and the like.")
        ("Blog" "/blog/"
         "My blog.")
        ("Bookmarks" "/bookmarks/"
         "Bookmarks from my web browser.")
        ("Guestbook" "/blog/guestbook.html"
         "Leave comments about me or my site here.")
        ("Projects" "/projects/"
         "Software that I work on, configuration.")
        ("Works" "/web/WorksPage.html"
         "Miscellaneous things I work on.")))

;; Add to interwiki list
(add-to-list 'emacs-wiki-interwiki-names
             '("ArchWiki" .
               (lambda (tag)
                 (concat "http://wiki.gnuarch.org/"
                         (or tag "FrontPage")))))
(add-to-list 'emacs-wiki-interwiki-names
             '("BlogWiki" .
               (lambda (tag)
                 (concat "/blog/"
                         (or tag "index.html")))))
(add-to-list 'emacs-wiki-interwiki-names
             '("PlugWiki" .
               (lambda (tag)
                 (concat "http://plug.student-orgs.purdue.edu/plugwiki/"
                         (or tag "FrontPage")))))

;;; Functions

;; Insert header
(defun my-emacs-wiki-insert-header ()
  (ignore (insert-file-contents
           "/home/mike/personal-site/emacs-wiki/header.html")))

;; Insert footer
(defun my-emacs-wiki-insert-footer ()
  (ignore (insert-file-contents
           "/home/mike/personal-site/emacs-wiki/footer.html")))

;; Get last N ChangeLog entries
(defun my-get-changelog-entries (num-entries)
  "Return the most recent entries from the ChangeLog file.
It will look in the current directory for this file.  The number
of entries is determined by NUM-ENTRIES.

You can put <lisp>(my-get-changelog-entries NUM-ENTRIES)</lisp>
in a Wiki file to make use of this function."
  (interactive)
  (let* ((file "ChangeLog")
         (regexp "^[0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\}")
         beginning end buffer-opened-already buffer str)
    (save-excursion
      (save-match-data
        (setq buffer-opened-already (get-file-buffer file))
        (setq buffer (set-buffer (find-file-noselect file)))
        (goto-char (point-min))
        (when (re-search-forward regexp nil t)
          (setq beginning (match-beginning 0))
          (while (and (> num-entries 0)
                      (re-search-forward regexp
                                         nil 1))
            (setq num-entries (1- num-entries)))
          (beginning-of-line)
          (backward-char)
          (setq end (point)))))
    (and beginning end
         (with-current-buffer buffer
           (setq str (buffer-substring beginning end))))
    (unless buffer-opened-already
      (kill-buffer buffer))
    str))

;; COMPLETELY disable text mode hooks while publishing.  For some
;; reason, a user of an obscure version of (X)Emacs had a problem with
;; my solution, which actually worked, unlike the current version of
;; this in `emacs-wiki-publish.el'.
(defun emacs-wiki-publish (&optional arg)
  "Publish all wikis that need publishing.
If the published wiki already exists, it is only overwritten if
the wiki is newer than the published copy.

When given the optional argument ARG, all wikis are rewritten, no
matter how recent they are.  The index file is rewritten no
matter what."
  (interactive "P")
  ;; prompt to save any emacs-wiki buffers
  (save-some-buffers nil (lambda ()
                           (derived-mode-p 'emacs-wiki-mode)))
  (let ((emacs-wiki-project emacs-wiki-current-project)
        (text-mode-hook nil))
    (emacs-wiki-refresh-file-alist)
    (let* ((names (emacs-wiki-file-alist))
           (files (list t))
           (lfiles files)
           ;; disable hooks
           (emacs-wiki-mode-hook nil))
      (while names
        (setcdr lfiles (cons (cdar names) nil))
        (setq lfiles (cdr lfiles)
              names (cdr names)))
      (if (emacs-wiki-publish-files (cdr files) arg)
          (progn
            (run-hooks 'emacs-wiki-after-wiki-publish-hook)
            (message "All Wiki pages%s have been published."
                     (if emacs-wiki-current-project
                         (concat " for project "
                                 emacs-wiki-current-project)
                       "")))
        (message "No Wiki pages%s need publishing at this time."
                 (if emacs-wiki-current-project
                     (concat " in project "
                             emacs-wiki-current-project)
                   ""))))))

;;; Key customizations

(define-key emacs-wiki-mode-map         ; follow link at point
  "\C-c\r" 'emacs-wiki-follow-name-at-point)

;; See `planner-init.el' for global-level key customizations

;;; Customizations

(custom-set-variables
 '(emacs-wiki-autogen-headings (quote outline))
 '(emacs-wiki-charset-default "utf-8")
 '(emacs-wiki-coding-default (quote utf-8))
 '(emacs-wiki-default-project "WebWiki")
 '(emacs-wiki-ignored-extensions-regexp "\\.\\(muse\\|bz2\\|gz\\|[Zz]\\)\\'")
 '(emacs-wiki-maintainer "MissingPage.html")
 '(emacs-wiki-menu-bottom "
</div><!-- menu ends here -->
")
 '(emacs-wiki-menu-factory (quote emacs-wiki-menu-make-from-list))
 '(emacs-wiki-menu-make-from-list-format "  <div class=\"menuitem\">
    <a title=\"%tooltip%\" href=\"%url%\">%text%</a>
  </div>
")
 '(emacs-wiki-menu-remove-last-word t)
 '(emacs-wiki-menu-top "<div class=\"menu\">
")
 '(emacs-wiki-private-pages (quote ("^[0-9]" "^Course" "^WorkList")))
 '(emacs-wiki-project-remove-last-word t)
 '(emacs-wiki-publishing-footer "/home/mike/personal-site/emacs-wiki/footer.html")
 '(emacs-wiki-publishing-header "/home/mike/personal-site/emacs-wiki/header.html")
 '(emacs-wiki-recurse-directories t)
 '(emacs-wiki-style-sheet "<link rel=\"stylesheet\" type=\"text/css\" charset=\"utf-8\" media=\"all\" href=\"/common.css\" />
<link rel=\"stylesheet\" type=\"text/css\" charset=\"utf-8\" media=\"screen\" href=\"/screen.css\" />
<link rel=\"stylesheet\" type=\"text/css\" charset=\"utf-8\" media=\"print\" href=\"/print.css\" />")
 '(emacs-wiki-use-mode-flags nil))
(custom-set-faces)

;;; emacs-wiki-init.el ends here