Here’s another quick one. It could be when formatting pieces of code that you want to remove any space from the beginning of the line. Removing de-facto any indentation.
M-x query-replace-regexp RET
Confirm then one by one with ‘y‘ or replace all of the buffer with ‘!‘.
Most of the time I use emacs with auto-fill mode breaking any line at 70. Sometimes though I’d like a paragraph to be reverted to a single line; for example for copy-pasting into other editors where it could breaks the formatting. Here’s how
M-x set-variable RET fill-column RET 100000
M-q (on the desired paragraphs)
M-x set-variable RET fill-column RET 70
First line set the fill-column to a large amount, the second will re-run the fill-paragraph and the third will reset the fill-column to my usual value
Spiral-Bound Pad (by incurable_hippie)
Here is a quick way to strip (remove) blank lines from a file with emacs.
- position on top of file: M-<
- Call a query-regex-replace: M-C-%
- input the regex ^ C-q C-j that stand for match all lines that consist in only a carriage return.
- RET-RET. The first one confirm the regex and the last one is for “replace with nothing”.
- When asked use ! to replace-all.
Summing all commands:
M-< C-M-% ^ C-q C-j RET RET !
here you are 🙂
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
Another quick post. Having syntax hilight for python in emacs is very simple as usual. Just install the python-mode by copying the relative .el file into your site lisp and edit your .emacs file for loading the required mode.
I’ve updated my .emacs file adding the support for log4j-mode and disabling the font-lock-maximum-size variable.