Created
April 23, 2014 16:16
-
-
Save krisfoster/11221905 to your computer and use it in GitHub Desktop.
Attempt, within emacs, to validate that a URL exists. has issues... creates too many buffers that don't get closed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; | |
;;; | |
;;; | |
(defun string/ends-with (s ending) | |
"return non-nil if string S ends with ENDING." | |
(cond ((>= (length s) (length ending)) | |
(let ((elength (length ending))) | |
(string= (substring s (- 0 elength)) ending))) | |
(t nil))) | |
(defun goto-buffer-and-count (status) | |
(let ((oldbuff (current-buffer))) | |
(with-current-buffer (current-buffer) | |
(save-excursion | |
(save-match-data | |
(goto-char (point-min)) | |
(let (s e line) | |
(setq s (line-beginning-position)) | |
(setq e (line-end-position)) | |
(setq line (buffer-substring-no-properties s e)) | |
(string/ends-with line "200 OK"))))) | |
(kill-buffer oldbuff))) | |
;; test 1 | |
(url-retrieve "http://www.google.com/" | |
(lambda (status) (if (goto-buffer-and-count status) | |
(message "yes") | |
(message "no")))) | |
;; test 2 | |
(url-retrieve "http://www.google.com/kris-this-wont-work" | |
(lambda (status) (if (goto-buffer-and-count status) | |
(message "yes") | |
(message "no")))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment