Sometimes ago I cited a cool mode for emacs: log4j-mode. Since I started useing it just for “syntax hilight”, I’ve discovered a very cool macro: log4j-start-filter.
I had the needs to filter an application log file (30Mb growing) in which many applications is logging. I’ve not decided this, so don’t hang up with me :).
Well just typing M-x log4j-start-filter <my-list-of-keywords-space-separated> RET and automagically the file is showing only what I need. I can’t live without this functionality.
The counterpart of this macro is M-x log4j-stop-filter.
Once you have recorded a macro, you can save it for later usage on a file (or within your .emacs). The steps to follow in order to get this work, is (1) give a name to the macro, (2) insert it into a buffer.
M-x name-last-kbd-macro RET my-cool-macro-name
then (what I usually do), open a buffer for saving it and insert the macro into it
C-x C-f ~/my-buffer.el ;;open a new (or existing one) file.
M-x insert-kbd-macro RET my-cool-macro-name ;;insert the macro into the buffer
C-x C-s ;;save the buffer
Now, it’s time to use the saved macro. If you have saved it in your .emacs you’ll have it ready on every emacs startup, otherwise it’s enough to load the .el file when needed (I prefer this way)
M-x load-file RET ~/my-buffer.el
I will never stop saying how much I love emacs. I have to admit that it’s very difficult to learn how to use it and even after you have learned enough to use it, you will always find something that you didn’t know.
The task for today is simple: sorting the lines in a region. There’s an already existent macro: sort-lines. So first you will have to select the region and the call the macro. In the following example we will sort the lines of the whole document.
C-x h <RET> M-x sort-lines
Again: easy easy and easy 🙂