“Reverting” the auto-fill in emacs

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

emacs strip blank lines

Spiral-Bound Pad

Spiral-Bound Pad (by incurable_hippie)

Here is a quick way to strip (remove) blank lines from a file with emacs.

  1. position on top of file: M-<
  2. Call a query-regex-replace: M-C-%
  3. input the regex ^ C-q C-j that stand for match all lines that consist in only a carriage return.
  4. RET-RET. The first one confirm the regex and the last one is for “replace with nothing”.
  5. When asked use ! to replace-all.

Summing all commands:

M-< C-M-% ^ C-q C-j RET RET !

here you are 🙂

[emacs] log4j-start-filter

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.

[emacs] save a macro

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