tkbe

March 12, 2009

cool :: AJAX APIs Playgroun

Filed under: google, ajax — tb @ 10:31 pm

I just stumbled upon the AJAX APIs Playground (http://code.google.com/apis/ajax/playground/). It’s a site with only one purpose: interactive examples of how to use Google Ajax APIs. Better, by far, than countless pages of documentation ;-)

March 8, 2009

emacs :: my first emacs-lisp function (!)

Filed under: emacs — tb @ 1:31 am

I've been finding myself in a tricky situation a lot lately: I'm programming along, and suddenly I realize that the thing I'm writing really should be factored out and named with a variable.

PYTHON:
  1. page.calendar.add(Employee.username(...

"whoops, I'm going to refer to this employee again... I should have written:"

PYTHON:
  1. emp = Employee.username(request.user.username)
  2.    page.calendar.add(emp, ...

What to do? Should I finish the line I'm on and then insert a line above (from experience I know my memory is so bad I'm likely to have forgotten by the time I get to the end of the line); or should I navigate up, insert the line and then try to find my way back to where I was.

What I really needed was to be able to press C-return and magically be transported to a fresh, new, blank and properly indented line above my point. Then I could use the standard C-u C-spc to get back to where I started... After a couple of hours of reading the fine manual, here's what I came up with:


(defun insert-and-indent-line-above ()
  (interactive)
  (push-mark)
  (let* ((ipt (progn (back-to-indentation) (point)))
   (bol (progn (move-beginning-of-line 1) (point)))
   (indent (buffer-substring bol ipt)))
    (newline)
    (previous-line)
    (insert indent)))
 
(global-set-key [ (control return) ] 'insert-and-indent-line-above)

it brought me great satisfaction (even though I realize there is probably a much simpler and more elegant way to do this).

Powered by WordPress