Log in

No account? Create an account
Overloading the Machine -- Day [entries|friends|calendar]

[ website | wjsullivan.net ]
[ userinfo | livejournal userinfo ]
[ calendar | livejournal calendar ]

Checking Emacs buffers for broken links [13 May 2008|02:23pm]

This was a quick effort to write a command for checking the current buffer for broken links. Thoughts, feelings and improvements welcome.

(defun campaigns/check-buffer-urls ()
  "Checks the current buffer for broken links, skipping those
that match entries in the `no-check' list."
  (let ((matches '())
        (no-check '("mailto"))
        (fails 0))
      (goto-char (point-min))
          (re-search-forward thing-at-point-url-regexp nil t)
        (add-to-list 'matches (match-string-no-properties 0)) t))
    (pop-to-buffer "*Link checking results*")
    (insert "Checking your links...\n\n")
     (lambda (url)
       (let ((parsed (url-generic-parse-url url)))
         (insert (format "* %s ..." url))
         (if (member (elt parsed 0) no-check)
             (insert "SKIPPING\n")
           (condition-case err
               (if (url-http-file-exists-p url)
                   (insert "OK\n")
                 (insert "ERROR!\n")
                 (setq fails (1+ fails)))
             (error (insert "ERROR!\n")
                (setq fails (1+ fails)))))))
    (insert (format "\nFinish checking %d links. There were %d problems.\n"
                    (length matches) fails))))
1 comment|post comment

[ viewing | May 13th, 2008 ]
[ go | previous day|next day ]