Screenshots in org-mode
; 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:
- Make sure you have
importfrom the ImageMagick suite, check withwhich import. - Put code in a .el file in your
~/.emacs.d/directory (or anywhere else for that matter) - Evaluate the buffer with
M-x eval-buffer - Move to a org-mode file (or enable it with
M-x org-modein any other buffer) - Go to the position where you want to insert your screenshot and call that function with
M-x my-screenshot. - Your cursor will turn into a crosshair or something, now click on the window you want to capture.
- The image inserted at your cursor positiong
How does it work?
- Generate a filename, within the current working directory (usually the location of the file associated with current buffer)
- Call ImageMagick's
importtool, with that filename - Insert a link at the current cursor position
- Call the
org-display-inline-imagesfunction.
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
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?

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