I’m still learning new stuff in Emacs every day. It’s probably one of the main reason why Emacs is my favourite text editor; it’s just plain fun.
I happen to know a little Lisp, which come in handy sometime. Changing or extending the behavíour of a program is seldom easy, fun or even productive. Emacs is of course an exception. Once you know the basics you can do pretty much whatever comes to mind.
Today I made my first attempt at building an “interactive” function. A function that you can run by entering M-x function-name, that is. It’s called facebook-log-fix and I needed it because I really like saving my online conversations. Pidgin does this for me most of the time but when I chat on Facebook I need to save them myself. The problem is that Facebook’s stylesheets takes care of the layout of the chat, so when you simply copy the conversation to a text editor it gets all jumbled up. This simple little function takes care of this for me. Maybe you’ll like it, or just learn something about how to modify Emacs a little. Please tell me if you have got any suggestions for improvements — I’m a pretty big noob when it comes to lisp and Emacs.
Here it goes, just paste it into your .emacs file or whatever.
(defun facebook-log-fix nil
"Make proper adjustments to a cut'n'pasted Facebook chat"
(interactive) ; make the function available to the user
(message "Trying to cleanup Facebook chat")
(save-excursion ; restore stuff (point, mark and current buffer) when done
; Fancy regexp: (name)\n((anything+\n)*?[non-greedy])(time of day)
(replace-regexp "\\(.*?\\)\n\\(\\(?:.*\n\\)*?\\)\\([0-9][0-9]:[0-9][0-9][a|p]m\\)"
"\\3 \\1 \\2\n"
nil 0 (buffer-size))))