domingo, 14 de abril de 2013

Embedding Lua, embedding Guile

Lately I've spent a quite few hours hacking on Lua. I love its simplicity, and the way it exposes lots of inner aspects of the programming language, that are usually hidden from the user in other programming languages.

One of the cool aspects of lua is the easiness of embedding it into your C app. But let's make it more fun. Embed Guile also inthere.

Lua

The process to embed Lua in a C app is quite easy, and simple (for really simple things), but I guess it gets more cumbersome when the complexity of the embedding system increases. Being a stack based vm makes it non-trivial to write some embedding functions (recursive functions, for example).

Guile.

The way to embed guile into an app is also, really easy. And Powerful. And you're not bound to interact with it using a stack based machine, but you just register your functions, and use the generic SCM type for all inputs and outputs. I find it easier than Lua

The Code

Here's a minimal example that does some trivial calculations and the flux of the code passes from C to guile, guile calls another C function, and after this, we call lua which also calls a function we have defined in C. In the end it's doing something like (n! + 1).

jueves, 11 de abril de 2013

Running a shell command on current file

Before being an emacs evangelist, I was a vim evangelist for a few years (next month sublime text), and one feature that I missed in emacs was having a way to reference the current file when executing a command.

In vim, it's pretty common to run commands like

:!gcc %

It's pretty simple and the syntax is really easy to remember, ":" for command mode, "!" to run something, and in the command "%" will be replaced by your filename.

I haven't found anything similar to "%" for emacs, so let's write some elisp to fix it.


(defun shell-execute ()
  (interactive)
  (let ((file-buffer (or (buffer-file-name) ""))
        (command (read-shell-command "Shell command: " nil nil nil)))
    (shell-command (replace-regexp-in-string "%" file-buffer command))))

(global-set-key (kbd "M-!") 'shell-execute)

domingo, 7 de abril de 2013

Guile's deprecation warnings

I've been hacking a bit of Guile (for embedding purposes), and somehow I got to use some deprecated functions: scm_int2num and scm_num2int. The amazing thing is that along with the result of the program, you get the following warning message:
Some deprecated features have been used.  Set the environment
variable GUILE_WARN_DEPRECATED to "detailed" and rerun the
program to get more information.  Set it to "no" to suppress
this message.
Nice, no? Let's set the variable and rerun.
`scm_int2num' is deprecated. Use scm_from_int instead.
`scm_num2int' is deprecated. Use scm_to_int instead.
These kind of things make usin guile a pleasure. Now back to embedding.

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.