gs -o - -sDEVICE=inkcov input.pdf | grep -v "^ 0.00000 0.00000 0.00000" | grep "^ " | wc -l
2012-10-30
Counting Color Pages in PDF Files
Printing books and such in color can be expensive. So here is how to count the color pages using a recent version of GhostScript and a UNIX shell:
2012-10-29
Improved handling of background GNU Global update
Earlier this year I detailed how to run gtags of GNU Global when Emacs is idle. However, this collides with some special Emacs modes, like ediff. That mode makes its own Emacs frame layout, which can be destroyed by the xgtags incremental update buffer. So I conceived a way to disable gtags temporarily as long as ediff is active:
;; This stuff is only needed, if you haven't got xgtags loaded yet
(autoload 'gtags-mode "gtags" "" t)
(require 'xgtags)
(add-hook 'c-mode-common-hook (lambda () (xgtags-mode 1)))
(defun global-update-incrementally () (shell-command "global -u -q" "*Messages*" "*Messages*") )
;; Call gtags update when idle for some time
(defcustom my-gtags-update-idle-time 60
"Number of idle seconds before an incremental gtags update is launched"
:group 'my-group
:type 'integer
)
;; initially allow gtags updates
(setq my-gtags-update-active t)
(run-with-idle-timer my-gtags-update-idle-time t
(lambda ()
(if (and my-gtags-update-active
(not (minibufferp) )
)
(progn
(message "Running gtags...")
(global-update-incrementally)
)
)
)
)
(add-hook 'ediff-quit-hook
(lambda ()
(message "Activating gtags update.")
(setq my-gtags-update-active t)
)
)
(add-hook 'ediff-before-setup-hook
(lambda ()
(message "Deactivating gtags update.")
(setq my-gtags-update-active nil)
)
)
2012-09-28
Encode image sequence to MPEG4 video
Today something very simple: use ffmpeg to encode an image sequence as a MPEG4 video:
ffmpeg -f image2 -i filename-%04d.png -vcodec mpeg4 -b 6000k output.mp4
I often use blender or custom software to render out a bunch of images. Blender usually names output files filename-0000.png, where 0000 is the frame number. So ffmpeg can generate those filenames with the usual printf style format. You can of course tweak ffmpeg's output via a myriad of options. But this here will simply generate a 25fps mpeg4 file, which is easily embedded for example into your Keynote presentation. On OS X you can get ffmpeg for example via MacPorts: sudo port install ffmpeg, and Linux distros usually have a package for ffmpeg as well.
ffmpeg -f image2 -i filename-%04d.png -vcodec mpeg4 -b 6000k output.mp4
I often use blender or custom software to render out a bunch of images. Blender usually names output files filename-0000.png, where 0000 is the frame number. So ffmpeg can generate those filenames with the usual printf style format. You can of course tweak ffmpeg's output via a myriad of options. But this here will simply generate a 25fps mpeg4 file, which is easily embedded for example into your Keynote presentation. On OS X you can get ffmpeg for example via MacPorts: sudo port install ffmpeg, and Linux distros usually have a package for ffmpeg as well.
2012-09-08
Using Ctrl+Arrow keys in the OS X terminal
The key combination Ctrl + left or right arrow key can be used to go a word left or right in many programs such as GNU Emacs or the bash. In the default configuration of the OS X terminal, this is not the case. That's because Terminal.app sends the wrong key codes for bash's default configuration. So you just need to got to the preferences (cmd+,) and set the key codes for Ctrl+left and right to \033b and \033f respectively:
2012-08-31
Java Autocompletion for Emacs
The past few weeks I have been using the great eclim, and the corresponding emacs-eclim package. It allows you to use many of Eclipse's features in your favourite editor. The installation of emacs-eclim is rather easy, and the one for eclim is even easier, since it comes with a simple clickety-click-installer.
I use emacs-eclim for Java development, and it works rather well. I use the two functions ac-complete-emacs-eclim and ac-complete-eclim-c-dot for auto-completion, which is the most important aspect when using such heavily object oriented languages and when developing large projects. Also useful are the functions eclim-java-import-missing, and eclim-java-remove-unused-imports. The current project can be compiled by calling eclim-project-build.
In theory, you can also use eclim with CDT for C++ development and auto-completion, but I rather stick with my earlier clang based solution, which is very fast and accurate.
I use emacs-eclim for Java development, and it works rather well. I use the two functions ac-complete-emacs-eclim and ac-complete-eclim-c-dot for auto-completion, which is the most important aspect when using such heavily object oriented languages and when developing large projects. Also useful are the functions eclim-java-import-missing, and eclim-java-remove-unused-imports. The current project can be compiled by calling eclim-project-build.
In theory, you can also use eclim with CDT for C++ development and auto-completion, but I rather stick with my earlier clang based solution, which is very fast and accurate.
2012-08-09
An argument for Emacs window-local variables
The Emacs developers used argue that window-local variables are not neccessary, since there are indirect buffers, which can do mostly the same thing. In recent Emacs releases, the window state is anyway mostly hidden from Lisp. However, I think sometimes it is useful to have window-local variables, instead of buffer-local variables. Emacs is very buffer-centric, but sometimes the UI and the user's view is rather window-centric. Two use-cases for window-local variables are:
The buffer stack for a navigation history definitely should be window specific. Everything else would be very confusing. If a window is split, the new window will inherit its parents history.
- Window decorations like the tabbar
- A buffer / point stack for going back/forth like in a web browser or Eclipse
The buffer stack for a navigation history definitely should be window specific. Everything else would be very confusing. If a window is split, the new window will inherit its parents history.
2012-08-07
Updating GNU Global GTAGS file when Emacs is idle
GNU Global is a very useful code navigation tool. In order for it to work well, it needs to be run regularly. Until now, I used the after-save-hook, to keep it up to date. However, when using emacs-eclim (also see Eclim), saving becomes so frequent that performance takes a massive hit. So I whipped up this small code snippet to run Global only when Emacs is idle for some number of seconds (default is 10):
(defcustom my-gtags-update-idle-time 10
"Number of idle seconds before an incremental gtags update is launched"
:group 'my-group ;; Put whatever customization group you like here
:type 'integer
)
(run-with-idle-timer my-gtags-update-idle-time t
(lambda ()
(if (not (minibufferp) )
(progn
(message "Running gtags...")
(global-update-incrementally)
)
)
)
)
Subscribe to:
Posts (Atom)