With the warning that I am no emacs expert, based on the post you linked to, the following works for me (I've bound it to C-^, which is undefined as far as I can see, as are C-|, and C-~, otherwise, but obviously the binding is a matter of taste):
(defun LaTeX-insert-hat ()
"Insert \\hat{} and position point between the braces."
(interactive)
(progn
(insert "\\hat{}")
(backward-char)))
(eval-after-load 'latex
'(define-key LaTeX-mode-map (kbd "C-^") 'LaTeX-insert-hat))
The lisp of course goes in your .emacs
. It's reasonably obvious what you have to change for any other operator.
If you want to bind the function to an apostrophe sequence available when LaTeX-math-mode is enabled (which is a minor mode on top of AUCTeX) then instead of the keybinding sequence above (for instance, your comments suggested M-^) try
(eval-after-load 'latex
'(define-key LaTeX-math-mode-map (kbd "` M-^") 'LaTeX-insert-hat))
Personally I think I'd rather bind to M-6 than M-^, since having to press backtick then shift-meta-6 is a bit of a stretch. The trick is to make sure that the keybinding is "free". Open up a latex file, place yourself in LaTeX math mode (C-c ~) and then C-h k. The minibuffer will ask you to enter the key you want to have described, and enter your preferred keysequence. If that comes up as "undefined" you are good to go! If it comes up with anything else, then you need to find a different sequence.
Or you could look at yasnippet
, of course; or redefine LaTeX-math-hat, which is the AUCTeX function bound to [backtick]-^
(which doesn't in my version add braces).
(I should also have added: have you considered electric-pair-mode
: in that minor mode, if you type one delimiter {
, you will have a second one inserted automatically and the cursor placed between them. Some people hate it: but it's a more general solution to your issue, since it works for any commands, and although it costs you one extra keystroke, it still saves you one too, and makes sure you don't end up with unbalanced braces.)