Screenshots in org-mode

Angelegt von niklas Sun, 28 Nov 2010 19:43:00 GMT

A nice feature for emacs org-mode just went over the mailing list:

; Change name to your needs.
(defun my-screenshot ()
"Take a screenshot into a unique-named file in the current buffer file 
directory and insert a link to this file."

  (interactive)
  (setq filename
   (concat
    (make-temp-name
     (file-name-directory (buffer-file-name))
    )
    ".jpg"
   )
  )

  (call-process "import" nil nil nil filename)
  (insert (concat "[[" filename "]]"))
  (org-display-inline-images)
)

This is how you use it:

  1. Make sure you have import from the ImageMagick suite, check with which import.
  2. Put code in a .el file in your ~/.emacs.d/ directory (or anywhere else for that matter)
  3. Evaluate the buffer with M-x eval-buffer
  4. Move to a org-mode file (or enable it with M-x org-mode in any other buffer)
  5. Go to the position where you want to insert your screenshot and call that function with M-x my-screenshot.
  6. Your cursor will turn into a crosshair or something, now click on the window you want to capture.
  7. The image inserted at your cursor positiong

How does it work?

  1. Generate a filename, within the current working directory (usually the location of the file associated with current buffer)
  2. Call ImageMagick's import tool, with that filename
  3. Insert a link at the current cursor position
  4. Call the org-display-inline-images function.
If you want to customize that link, or insert custom links to images, just do M-x org-display-inline-images to turn those into inline images as well. Export to PDF with C-c C-e d and watch the scaled down screenshots.

Preprocessing JavaScript

Angelegt von niklas Thu, 07 Oct 2010 10:16:00 GMT

Just found this page and thought I'd give it a try. What I wanted to have was a less verbose way to define classes.

So here's a macro to conveniently define classes:

#define class(klass, ...) var klass = function(__VA_ARGS__)
Use it like this:
// class definition
class (Foo, bar) { // Foo: name of the class ; bar: first argument of initializer. can take arbitrary args.
  this.bar = bar;
};
// instantiation
var x = new Foo("xyz");
x.bar; //=> "xyz";
When processing that code with CPP (give it all the above code incl. macro as input) ...
/usr/bin/cpp -P -undef -Wundef -std=c99 -nostdinc -Wtrigraphs -fdollars-in-identifiers -C 
... this is what comes out (comments stripped):
var Foo = function(bar) {
  this.bar = bar;
}

var x = new Foo("xyz");
x.bar;

Now this is pretty convenient, but not the whole story. Here's how I'd like to define a method:

class(Foo) {
  def(bar, arg) {
    alert(arg);
  }
}

var x = new Foo();
x.bar("xyz"); // alerts "xyz"
Definitely possible:
#define def(method, ...) this. method = function(__VA_ARGS__)
Almost the same thing as the class. Here's the output:
var Foo = function() {
  this.bar = function(arg) {
    alert(arg);
  }
}

var x = new Foo();
x.bar("xyz");
Pretty rubyish, isn't it?

Well, this is not the end of the story of course, but it's a start. Anyway, I hope this will cause people to take a deeper look at the GNU cpp, which really doesn't deserve it's bad reputation as being dusty and old, and imho should get more attention outside the scope of C in general. Whatever. Use it or ignore it.

Why did they kill the gnu?

Angelegt von andi Tue, 17 Aug 2010 17:40:00 GMT

Why did they kill the gnu?

( Though Maria says it looks quite content there on the wall… )