I'm Emacs newbie and for automatic re-formating of my source codes in Emacs I've created simple macro using
indent-region commands, mapped to C-j shortcut:
(fset 'format-document "\C-[xmark-whole-buffer\C-m\C-[xindent-region\C-m") (global-set-key (kbd "C-j") 'format-document)
However, when executed, the original position of cursor is lost and new cursor position is set to the beginning of the buffer. Is there any way how to perform this macro and return the cursor back to its previous position? I'm using GNU/Emacs 24.3 on Ubuntu 14.04.