Skip to content

Instantly share code, notes, and snippets.

@krisfoster
Created April 23, 2014 16:16
Show Gist options
  • Save krisfoster/11221905 to your computer and use it in GitHub Desktop.
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
;;;
;;;
;;;
(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