;;; -*- lexical-binding: t -*- ;;; ohai-splash.el --- Customise the scratch buffer. ;; Copyright (C) 2015 Bodil Stokke ;; Author: Bodil Stokke ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see . ;;; Code: (require 'ohai-package) (require 'ohai-personal-taste) (setq ohai-splash/sources (cond ((equal ohai-personal-taste/splash 'emergency-puppy) '(ohai-splash/emergency-puppy)) ((equal ohai-personal-taste/splash 'daily-otter) '(ohai-splash/daily-otter)))) (package-require 'dash) (package-require 's) (package-require 'web) (require 'dash) (require 's) (require 'web) (defun ohai-splash/load-and-map (url map-fn cb) (web-http-get (lambda (con header data) (funcall cb (funcall map-fn data header))) :url url)) (defun ohai-splash/load-and-match (url regex format-str cb) (ohai-splash/load-and-map url (lambda (data header) (-when-let (m (s-match regex data)) (s-format format-str 'elt m))) cb)) (defun ohai-splash/pick-first (fetchers cb) (-if-let (fetcher (car fetchers)) (if (stringp fetcher) (funcall cb fetcher) (funcall fetcher (lambda (url) (if url (funcall cb url) (ohai-splash/pick-first (cdr fetchers) cb))))) (funcall cb nil))) (defun ohai-splash/load-image (url cb) (web-http-get (lambda (con header data) (funcall cb (create-image (string-to-unibyte data) nil t))) :url url)) (defun ohai-splash/dilbert (cb) (ohai-splash/load-and-match "http://dilbert.com/" "/dyn/str_strip/[0-9/]+\.strip\\(\.sunday\\)?\.gif" "http://dilbert.com$0" cb)) (defun ohai-splash/imgur (search-term) (lambda (cb) (ohai-splash/load-and-match (s-concat "http://imgur.com/search/score/day?q_size_px=med&q_size_mpx=med&q=" (url-hexify-string search-term)) "