Download
(defun emacs-wiki-finddead ()
"Show a buffer with all pages in the current directory that are not
reachable from the current page."
(interactive)
(let ((all-pages (finddead-all-pages))
(current (file-name-nondirectory (buffer-file-name))))
(finddead-display
(finddead-main (delete current all-pages)
(list current)
(finddead-page-links current)))))
(defun finddead-all-pages ()
"Return a list of all pages in the current directory."
(let ((files '()))
(mapc (lambda (file)
(when (not (file-directory-p file))
(setq files (cons file files))))
(directory-files "."))
files))
(defun finddead-display (lis)
"Display the names in LIS in a separate buffer."
(pop-to-buffer (get-buffer-create "*EmacsWikiFinddead*"))
(let ((inhibit-read-only t))
(delete-region (point-min) (point-max))
(mapc (lambda (name)
(insert name "\n"))
(mapcar #'car
(sort (mapcar (lambda (name)
(cons name
(downcase name)))
lis)
(lambda (a b)
(string< (cdr a) (cdr b))))))
(goto-char (point-min)))
(view-mode 1))
(defun finddead-main (all done todo)
"Remove all pages reachable from TODO and move them to DONE."
(while todo
(if (member (car todo) done)
(setq todo (cdr todo))
(setq all (delete (car todo) all)
done (cons (car todo) done)
todo (append (cdr todo)
(finddead-page-links (car todo))))))
all)
(defun finddead-page-links (pagename)
"Return a list of pages that are linked to from PAGENAME in DIR."
(when (file-exists-p pagename)
(with-temp-buffer
(insert-file-contents pagename)
(finddead-buffer-links))))
(defun finddead-buffer-links ()
"Return a list of pages that are linked to from the current buffer."
(let ((links '())
(case-fold-search nil))
(while (re-search-forward emacs-wiki-name-regexp nil t)
(let ((name (replace-regexp-in-string "#.*"
""
(or (match-string 1)
(match-string 0)))))
(setq links (cons name links))))
(reverse links)))
(provide 'emacs-wiki-finddead)