viernes, 22 de marzo de 2013

Keyboardless programming

Emacs + Dragon + Duct Tape.
My impression after seeing this amazing talk from PyCon 2013 by Tavis Rudd was a big "WOW"!
Actually, when you see it, you'll shit bricks.
Can your editor do this?
Sublime, really(?). (pun intended)



miércoles, 20 de marzo de 2013

occur: Poor man's taglist

From time to time I see some vim screencast and think: "oh, taglist, that was nice...", and yeah, in emacsland we have lots of alternatives, like full blown ecb, or imenu, or idomenu, I guess there might even exist something with speedbar...

But none of them really cuts it for me, I'd need the ecb one without all other ecb features. Or something like that

So here's the plain dead simple elisp I'm using lately. Just occur-mode and a keybinding to update the search. For ruby, it can't find all the dinamic shit in there, but you get a nice overview of what's in your file, and if it's properly indented (which should be) you also get the notion of what's public, private, etc...

Surprisingly, I'm using it more and more, and I can have different regexes for different filetypes. (even tune it to look for 'get\\|post' if I'm editing sinatra things.)

Dead simple, but it kind of works.
(defun rgc-show-ruby-tags ()
  (interactive)
  (occur "^\\s-*\\\(class \\\|module \\\|def \\\|[^:]include \\\|private\\b\\\|protected\\b\\\)"))

(define-key ruby-mode-map (kbd "C-c t") 'rgc-show-ruby-tags)

domingo, 17 de marzo de 2013

Ratpoison and trays

Ratpoison doesn't come with any system tray by default (unlike stumpwm, which has mode-line).

Why you need a f*cking systray? you ask...  Well, in my laptop I need nm-applet to connect to my wifi.

Lately, I found that using stalonetray and nm-applet is the best combination. No need for gnome, or fancy configurations.


That's all it takes to have it working and not bothering you. It's amazing how easy it is, and how long I postponed this migration falling back to gnome.
  unmanage stalonetray
  exec Downloads/stalonetray-0.8.1/src/stalonetray
  exec nm-applet

I just discovered this other systray app. I never tried it, but I think it's worth a try.

viernes, 1 de marzo de 2013

Melpa, erc-tweet and erc-image

This week Sacha published  a post on her blog related to emacs (welcome back to emacs blogsphere!) and Just before a couple of very nice tricks, she says:
"A kid in a candy store – that’s me with M-x list-packages".

Well, I feel exactly the same.  It feels like when I browsed cpan looking for recent updates in packages. Daily.

Yesterday, a couple of packages I developed came to life in melpa.



erc-image

Shows image linked from erc buffers either inlined in the same erc buffer or in a dedicated buffer (and resizes it to a decent size).

erc-tweet

Shows tweets linked from erc buffers either inlined in the same erc buffer.


Both are quite simple packages, but if you find any issues (which I'm sure there are, because they are my first packages that will reach more than 10 machines), please file a bug either in https://github.com/kidd/erc-image.el  or https://github.com/kidd/erc-tweet.el . Or catch me in #emacs as rgrau or rgc.

W00t!


As a funny related addendum, here's a new package that appeared today in melpa:




So, after some months of doing things like '$ vim ~/.emacs' and overcome that, I'll now be able to 'emacsclient ~/.vimrc' .

Great.


domingo, 24 de febrero de 2013

Armagetron advanced, a few years after

Some years ago I got really addicted to armagetron advanced. A Snake-like game where you drive Tron Light cycles.

 It's dead simple, but the simplicity itself is what makes it so awesome. In fact, The only kind of games that trapped me in the last 10 years where playable with 4 buttons max. (sdmkun, elastomania, *cave, and most ABA games).

 So I installed armagetronad again and went to the internetz to play some styball. It's a bummer that there are no styball servers anymore. But thanks to that I fetched the source to see if I could find the styball mode, and.... besides finding it, I also found a branch which embeded lua into armagetronad. Yeah, modding arma in lua will be great.

 I hope I don't get addicted again.

 And, as a gift, here you have an explanation of rubber, a great concept to deal with latency in armagetron. I think it's one of the things that make aa so amazing.

 Ah, and here's a cheatlist for armagetronad. nice to have, eh? :)

 Btw, it's funny that I loved that game before watching the movie, and before knowing that this movie was somehow related to smalltalk. Hey, even in the 'Tron legacy' movie, there's emacs appearing in some occasion :)

lunes, 28 de enero de 2013

a simple pattern to shorten the feedback cycle

Lately I had to do some work on nginx configuration and lua-scripting (here is the detailed info on augmenting an API through nginx and lua). To do so, the development cycle is the following:
  1. edit nginx conf file or lua file called from the nginx conf file.
  2. restart or reload nginx.
  3. check in nginx log file for errors
  4. Try the feature via curl or browser
I 'nulled' the 2nd step via a very simple pattern that I've been using lately. It's dead simple, but involves a few elisp-ities you may or may not know. Anyway, check it out.
The 'trick' is to use buffer local variables to run the appropiate commands in each buffer. So you should set a variable called run-command, to the string that will be executed when saving.
Hint: here's the pattern for the prop-line in case you want emacs to set the variable automatically when you open the file.
# -*- run-command: "/opt/openresty/nginx/sbin/nginx -c /home/rgrau/workspace/nginx-translator/config_nginx.conf -p /tmp/nginx/  -s reload"; -*

For more fancyness, there's also add-file-local-variable-prop-line which can help you.
And the tiny code to hook the command to after-save hook.
(defun rgc/run-command ()
  (interactive)
  (when (boundp 'run-command)
    (shell-command run-command)))

(add-to-list 'after-save-hook 'rgc/run-command)
To speed up the 3rd step, you can play with tailing the log file in a shell-mode buffer, or use auto-reverse-tail-mode. But let's leave it for another post :) Btw, Next weekend I'll be the next FOSDEM. If anyone wants to meet and hack some elisp or discuss vim vs emacs with a beer, ping me (raimonster at gmail dot com)

miércoles, 9 de enero de 2013

Parsing elisp code with elisp

Today, in Reddit there was this guy presenting a utility library for elisp.


In the comments, there was a discussion about generating documentation
from an elisp file. The approach there is fine: parsing the file via
regexen and asking for the documentation to the elisp system itself.

Here's another version I wrote that walks through the code looking for
defuns and defmacros.  The code parses a buffer, and picks the
docstring from the code itself, so it catches it even if the methods
haven't been evaluated.  It's not a real advantage as you won't
probably try to document a code you aren't evaluating, but just for
the sake of the exmple, I think it's a good learning exercice.

So here's the code:

 (defun fetch-defuns (buffer)
   (interactive)
   (save-excursion
     (goto-char (point-min))
     (let (sexp
          (defuns nil)
          (defmacros nil))
       (condition-case nil
          (while t
            (setq sexp (read buffer))
            (when (listp sexp)
              (case (car sexp)
                (defun (push (cons (cadr sexp) (doc-if-any sexp)) defuns))
                (defmacro (push (cons (cadr sexp) (doc-if-any sexp)) defmacros)))))
        (error nil))
       (generate-docs defuns))))
 
 (defun doc-if-any (sexp)
   "search for the doc"
   (when (stringp (cadddr sexp))
     (cadddr sexp)))
 
 (defun generate-docs (defuns)
   "generate a simple org with the docs"
   (mapconcat (lambda (x) (format "* %s
   %s" (car x) (or (cdr x) "-undocumented-"))) defuns "\n\n"))

M-: (fetch-defuns (current-buffer)) will return a minimal org-file skeleton with the function names and their docs.

The cool way to ask for the documentation of a function, however, is just (documentation 'name-of-fun). try it. It's great.

Happy emacs hacking!