Emacs Redux

Return to the Essence of Text Editing

Search Youtube

| Comments

Some time ago I showed you how to do Google queries from Emacs. The approach used in that articles is pretty generic and can be used for the creation of various similar commands. Let’s create a command that searches in YouTube:

1
2
3
4
5
6
7
8
9
(defun youtube ()
  "Search YouTube with a query or region if any."
  (interactive)
  (browse-url
   (concat
    "http://www.youtube.com/results?search_query="
    (url-hexify-string (if mark-active
                           (buffer-substring (region-beginning) (region-end))
                         (read-string "Search YouTube: "))))))

This command will display the query results in your default browser.

I’d suggest binding the command to C-c y if you plan to use it regularly.

1
(global-set-key (kbd "C-c y") 'youtube)

youtube is available in Prelude(but with a prelude- prefix).

Comments