(defvar emacs-wiki-code-path "~/cfiles/")
(defvar emacs-wiki-code-exclude-regexp
"[voidnt]+ main()\\|else if[ ]*()\\|if[ ]*()\\|for[ ]*()\\|while[ ]*()\\|switch[ ]*()")
(defun clean (reg str)
(replace-regexp-in-string reg "" str))
(defun emacs-wiki-code-htmlify (code-path h-mode fname)
"Create HTML markup for C,C++,Assembly and Elisp files"
(let (buffer-read-only)
(with-current-buffer
(set-buffer (generate-new-buffer "*CodeHTML*"))
(insert "#style ../style.css\n"
"#head headerarch.wiki\n"
"#foot footerarch.wiki\n\n"
"<fontlock mode=\""
h-mode "\">\n")
(setq temppoint (point))
(insert-file-contents (concat code-path fname))
(goto-char (point-max))
(insert "\n<" "/fontlock" ">")
(emacs-wiki-replace-markup fname)
(goto-char (point-min))
(let ((backup-inhibited t))
(write-file
(expand-file-name (concat fname ".html")
(concat emacs-wiki-publishing-directory
"/code"))))
(kill-buffer (current-buffer))
)))
(defun emacs-wiki-code-generate (&optional code-path
code-highlight-mode createhtml)
"Generate a numbered list of C,C++,Assembly or Elisp files chosen
using code-highlight-mode in code-path with details and
function list.If createhtml is set uses emacs-wiki-code-htmlify to create
html version of all code files."
(if code-path (setq emacs-wiki-code-path code-path))
(let ((h-mode "c-mode") (filecounter 0) (resfunc " ")
(filefilter "^[^.].*\\.cpp$\\|^[^.].*\\.c$\\|^[^.].*\\.cc$\\|^[^.].*\\.h$"))
(if code-highlight-mode (setq h-mode code-highlight-mode))
(if (string= h-mode "asm-mode") (setq filefilter "^[^.].*\\.asm$"))
(if (string= h-mode "emacs-lisp-mode") (setq filefilter "^[^.].*\\.el$"))
(mapconcat
(lambda (file)
(let (
(header
(with-temp-buffer
(insert-file (concat emacs-wiki-code-path file))
(delete-non-matching-lines
(concat "^[\\*/; ]* " file " --\\(-\\)? "))
(replace-regexp-in-string
(concat "^[\\*/; ]* " file " --- \\(.*\\)$") "\\1"
(buffer-string))))
(functions
(with-temp-buffer
(insert-file (concat emacs-wiki-code-path file))
(if (not (string= h-mode "c-mode")) (setq resfunc nil)
(delete-non-matching-lines
"^[a-zA-Z \\*]+ [A-Za-z_0-9 \\*]+(.*)[ ]*$")
(let ((acc (mapconcat
'identity
(split-string
(replace-regexp-in-string
"\\(^[a-zA-Z \\*]+ [A-Za-z_0-9 \\*]+\\)(.*)[ ]*$"
"\\1()"
(buffer-string)) " ") " ")))
(setq acc (clean emacs-wiki-code-exclude-regexp acc))
(setq acc
(replace-regexp-in-string "[\n][\n]+" "\n"
(clean "[ ][ ]+" acc)))
(setq acc (clean "^\n" acc))
(if (or (string= acc "") (< (length acc) 3))
(setq resfunc nil)
(setq resfunc acc)))) (if (not (string= h-mode "emacs-lisp-mode")) resfunc
(delete-non-matching-lines "^ *(defun [^ ]+ ")
(let ((acc (mapconcat
'identity
(split-string
(replace-regexp-in-string
"^.*(defun \\([^ ]+\\) .*$"
"(defun \\1)"
(buffer-string)) " ") " ")))
(if (string= acc "")
(setq resfunc nil)
(setq resfunc acc))
)) )))
(if createhtml
(emacs-wiki-code-htmlify emacs-wiki-code-path h-mode file))
(concat ani-wiki-begin-frame-code
(int-to-string (setq filecounter (+ filecounter 1))) ". " file " "
(if createhtml
(concat "<a href=\"code/" file ".html\">View</a>")
"<code> [Not yet ready for publication] </code>")
(if (> (length header) 0)
(concat "<br /><strong>Details:</strong> " header)
"")
"<br />"
(format "<strong>Size:</strong> %s bytes "
(nth 7 (file-attributes (file-truename
(concat emacs-wiki-code-path file)))))
(format "<strong>Last modified:</strong> %s <br />"
(format-time-string "%B %e, %Y %l:%M %p"
(nth 5 (file-attributes (file-truename
(concat emacs-wiki-code-path file))))))
(if functions
(concat "<strong>Functions:</strong><br />\n"
"<fontlock mode=\"" h-mode "\">\n"
functions "<" "/fontlock" ">")
"")
ani-wiki-end-frame-code "\n<br />")))
(remove-if-not
(lambda (file) (string-match filefilter file))
(sort (directory-files emacs-wiki-code-path) 'string<)) "\n")))
(defun emacs-wiki-codearchive-tag (beg end attrs)
(let ((c-path emacs-wiki-code-path) (fontlockmode "c-mode"))
(if (cdr (assoc "path" attrs))
(setq c-path (cdr (assoc "path" attrs))))
(if (cdr (assoc "mode" attrs))
(setq fontlockmode (cdr (assoc "mode" attrs))))
(save-excursion)
(if (cdr (assoc "publish" attrs))
(insert (emacs-wiki-code-generate c-path fontlockmode t))
(insert (emacs-wiki-code-generate c-path fontlockmode)))
(goto-char end)))
(push '("codearchive" nil t nil emacs-wiki-codearchive-tag) emacs-wiki-markup-tags)