Endless Parentheses

Ramblings on productivity and technical subjects.

profile for Malabarba on Stack Exchange

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))))
    `(progn
       (defun ,func-name ()
         ,(format "Run the %s executable." exec)
         (interactive)
         (start-process "" nil ,exec))
       #',func-name)))

(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))))
    `(progn
       (defun ,func-name ()
         ,(format "Browse to the url %s." url)
         (interactive)
         (browse-url ,url))
       #',func-name)))

(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"))
comments powered by Disqus