@marjoleink asked on identi.ca [1]1, if it is possible to use emacs org-mode for showing scaled screenshots inline while writing. Since I thought I’d enjoy some hacking, I decided to take the challenge.
It does not do auto-scaling of embedded images, as far as I know, but the use case of screenshots can be done with a simple function (add this to your ~/.emacs or ~/.emacs.d/init.el):
(defun org-insert-scaled-screenshot () "Insert a scaled screenshot for inline display into your org-mode buffer." (interactive) (let ((filename (concat "screenshot-" (substring (shell-command-to-string "date +%Y%m%d%H%M%S") 0 -1 ) ".png"))) (let ((scaledname (concat filename "-width300.png")))
(shell-command (concat "import -window root " filename)) (shell-command (concat "convert -adaptive-resize 300 " filename " " scaledname)) (insert (concat "[[./" scaledname "]]")))))
Now just call M-x org-redisplay-inline-images
to see the screenshot (or add it to the function).
In action:
Have fun with Emacs - and happy hacking!
PS: In case it’s not obvious: The screenshot shows emacs just as the screenshot is being shot - with the method shown here ☺)
Matthew Gregg: @marjoleink "way of life" thing again, but if you can invest some time, org-mode is a really powerful note keeping environment. → Marjolein Katsma: @mcg I'm sure it is - but seriously: can you embed a diagram2 or screenshot, scale it, and link it to itself? ↩
For diagrams, you can just insert a link to the image file without description, then org-mode can show it inline. To get an even nicer user-experience (plain text diagrams or ascii-art), you can use inline code via org-babel [2] using graphviz (dot) or ditaa - the latter is used for the diagrams in my complete Mercurial branching strategy [3]. ↩
Anhang | Größe |
---|---|
screenshot-20121122101933-width300.png [4] | 108.08 KB |
screenshot-20121122101933-width600.png [5] | 272.2 KB |
Links:
[1] http://identi.ca/conversation/97136907#notice-98020110
[2] http://orgmode.org/worg/org-contrib/babel/
[3] https://www.draketo.de/light/english/mercurial/complete-branching-strategy
[4] https://www.draketo.de/files/screenshot-20121122101933-width300.png
[5] https://www.draketo.de/files/screenshot-20121122101933-width600.png