martes, 19 de junio de 2012

erc-oops

Hi again emacsians.
Maybe you're familiar with this IRC log samples.

  15:54 [rgc] xb
  15:54 [rgc] ooops, C-fail

  12:02 [xyz] ls
  12:02 [xyz] oops

  00:21 [foo] cd
  00:22 [foo] wrong buffer :/

To avoid that, some time ago I wrote some elisp to make erc-buffers read-only, but I just came up with a better solution:
(defun rgrau-erc-oops (txt)
  (when (member txt '("ls" "xb" "cd"))
      (setq erc-send-this nil)))

(add-to-list 'erc-send-pre-hook 'rgrau-erc-oops)


It's too simple to make an erc module out of that(isn't it?), so I just put it in this blog entry.

jueves, 7 de junio de 2012

erc-button fun


Erc is one of multiple irc clients bundled with emacs.  It's probably the most complex one, in fact, in #emacs you read that quite a few people left it in favour of simpler clients like rcirc. But I kind of like its complexity :)

One nice thing about erc that's not very known is erc-button.  Yeah, the thing that allows you to click on nicknames and kick them :).

At work, we use github issues to manage our stuff, and we wrote a super simple extension for our bot that whenever it sees #number it just pastes the url of the issue. I tried to use a more silent approach using erc-button, and here's the result.

It just highlights #123 like strings and make them clickable, linking to the appropiate issue in the appropiate repo.

(defvar rgrau-irc-gh-repos '(("#dev" . "3scale/project1")
("#clasker" . "clasker/clasker")))
(defun rgrau-browse-issue (issue-number)
(browse-url (rgrau-gh (cdr (assoc (buffer-name) rgrau-irc-gh-repos))
issue-number)))
(defun rgrau-gh (user/repo arg)
(format "https://github.com/%s/issues/%s" user/repo arg))
(eval-after-load "erc-button"
'(add-to-list 'erc-button-alist '("#\\([0-9]+\\)" 0 t rgrau-browse-issue 1)))

Neat, no?

Well, if you happen to use other sites for your issues, you can work around that github-centric approach with something else, I just hacked an ugly solution on top of the previous one. Not very clean maybe, but working.
(defun rgrau-browse-issue (arg)
(browse-url (format (cdr (assoc (buffer-name) rgrau-irc-gh-repos)) arg)))
(defun rgrau-gh-repo (repo)
(let ((channel (car repo))
(url (cdr repo)))
(cons channel (format "https://github.com/%s/issues/%%s" url))))
(defvar rgrau-irc-gh-repos `(,@(map 'list 'rgrau-gh-repo
'(("#dev" . "3scale/project1")
("#clasker" . "clasker/clasker")))
("#evil-mode" . "https://bitbucket.org/lyro/evil/issue/%s")))
(eval-after-load "erc-button"
'(add-to-list 'erc-button-alist '("#\\([0-9]+\\)" 0 t rgrau-browse-issue 1)))


Probably, the most sensitive solution would be writing the whole urls for each one, but well... :D

The nice point here is the tight relation between emacs and all other tools and use case. In really few lines of code we solved a problem, and we did it flexibly enough to be used in multiple scenarios.

Btw, hi to all planet emacsers, that's my first post here since I signed in. I hope to contribute here some of my emacs tricks. Don't hesitate giving feedback and commenting.

Update: There are gists inlined in the post that aren't visible in planet emacsen.  Will try to change approach for the next one.