programming (and other) musings
29 Nov 2014

emacs tip: tweeting from emacs-w3m

To follow twitter, i connect to a local Bitlbee server via emacs, using the Circe IRC client, and i browse the web using emacs-w3m.

I needed a command to automatically tweet about the page i am visiting. This being the emacs environment, i just wrote it in elisp.

The command will check if there's a region selected in the buffer using use-region-p, in which case its contents is used as the tweet body, falling back to the page's title. The only user-specific bit in the code below is the name that Bitlbee gives to the buffer of my twitter account, #twitter_jaotwits.

(defun jao-w3m-tweet (&optional from to)
  (interactive (when (use-region-p) (list (region-beginning) (region-end))))
  (let ((url (or w3m-current-url (error "No URL to tweet!")))
        (txt (if (and from to)
                 (buffer-substring from to)
               (w3m-current-title))))
    (switch-to-buffer "#twitter_jaotwits")
    (goto-char (point-max))
    (insert "'" txt "' -- " url)))

As you see, the command switches to the Bitlbee buffer and writes the contents of the tweet, but falls short of sending it, letting me to review the text before pushing return.

Tags: emacs
Creative Commons License
jao.io by jao is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.