Endless Parentheses

Concise ramblings on Emacs productivity.

Keymap for Launching External Applications and Websites

Mnemonic Keymaps post series

The launcher-map wouldn't be half of what it is if not for the run macro. With it, we can easily turn Emacs into a quick 'n dirty app launcher.

(defmacro run (exec)
  "Return a named function that runs EXEC."
  (let ((func-name (intern (concat "endless/run-" exec))))
       (defun ,func-name ()
         ,(format "Run the %s executable." exec)
         (start-process "" nil ,exec))

(define-key launcher-map "m" (run "Mathematica"))
(define-key launcher-map "k" (run "keepass"))
(define-key launcher-map "v" (run "steam")) ; Vapor =P

We could use a lambda instead of the macro, but the macro defines a nicely documented function.

While we're at it, let's do something similar for websites.

(defmacro browse (url)
  "Return a named function that calls `browse-url' on URL."
  (let ((func-name (intern (concat "endless/browse-" url))))
       (defun ,func-name ()
         ,(format "Browse to the url %s." url)
         (browse-url ,url))

(define-key launcher-map "t"
  (browse "http://twitter.com/"))
(define-key launcher-map "?" ;; See also SX.el.
  (browse "http://emacs.stackexchange.com/"))
(define-key launcher-map "r"
  (browse "http://www.reddit.com/r/emacs/"))
(define-key launcher-map "w"
  (browse "http://www.emacswiki.org/"))
(define-key launcher-map "+"
  (browse "https://plus.google.com/communities/114815898697665598016"))

Tags: keymap, intuitive, keybind, init.el, emacs

Say thanks on Gratipay
comments powered by Disqus