summaryrefslogblamecommitdiff
path: root/emacs/elisp/my-web.el
blob: 75951f49b0b3b18d786c897842b93c30fcf56865 (plain) (tree)
1
2
3
4
5
6
7





                                                       
                              











                                                               










                                                    

                       
;;; my-web.el --- Functions related to web interactions
;;; Commentary:
;;; Code:

(require 'my-strings)

(defun my/get-page-title (url)
  "Make URL into an 'org-mode' link."
  (let ((title))
    (with-current-buffer (url-retrieve-synchronously url)
      (goto-char (point-min))
      (re-search-forward "<title>\\([^<]*\\)</title>" nil t 1)
      (setq title (match-string 1))
      (goto-char (point-min))
      (re-search-forward "charset=\\([-0-9a-zA-Z]*\\)" nil t 1)
      (my/string-replace "&nbsp;" " "
                         (decode-coding-string title 'utf-8))
      (concat "[[" url "][" title "]]"))))

(defun my/github-code-search ()
  "Search code on github for a given language."
  (interactive)
  (let ((language (completing-read
                   "Language: "
                   '("Emacs Lisp" "Python"  "Go")))
        (code (read-string "Code: ")))
    (browse-url
     (concat "https://github.com/search?l=" language
             "&type=code&q=" code))))

(provide 'my-web)
;;; my-web.el ends here