(defun muse-index-as-string (&optional as-list exclude-private exclude-current) "Generate an index of all Muse pages. If AS-LIST is non-nil, insert a dash and spaces before each item. If EXCLUDE-PRIVATE is non-nil, exclude files that have private permissions. If EXCLUDE-CURRENT is non-nil, exclude the current file from the output." (let ((files (copy-alist (muse-project-file-alist))) (file-infos nil) (file-info)) (when (and exclude-current (muse-page-name)) (setq files (delete (assoc (muse-page-name) files) files))) (while files (unless (and exclude-private (muse-project-private-p (cdar files))) (setq file-infos (cons (muse-file-info (cdar files)) file-infos))) (setq files (cdr files))) (setq file-infos (sort file-infos (lambda (l r) (not (string< (nth 1 l) (nth 1 r)))))) (with-temp-buffer (while file-infos (setq file-info (car file-infos)) (insert (if as-list " - " "") (nth 1 file-info) " " "[[" (nth 2 file-info) "][" (nth 0 file-info) "]]\n") (setq file-infos (cdr file-infos))) (buffer-string)))) (defun muse-file-info (file) (let ((title (muse-page-name file)) (date nil) (retitle "^\\s-*#title\\s-+\\(\\S-.*\\)\\s-*$") (redate "^\\s-*#date\\s-+\\(\\S-.*\\)\\s-*$")) (muse-with-temp-buffer (muse-insert-file-contents file) (setq title (if (re-search-forward retitle nil t) (match-string 1) title)) (goto-char (point-min)) (setq date (if (re-search-forward redate nil t) (match-string 1) date))) (unless date (setq date (muse-file-mtime file))) (list title date file))) (defun muse-file-mtime (file) (let* ((mtime (nth 5 (file-attributes file))) (dmtime (decode-time mtime)) (fmtime (format "%04d-%02d-%02d-%02d-%02d" (nth 5 dmtime) (nth 4 dmtime) (nth 3 dmtime) (nth 2 dmtime) (nth 1 dmtime)))) fmtime))