Fix byte-compile warnings

- use `with-current-buffer` instead `save-excursion` + `set-buffer`
- use `called-interactively-p` instead of `interactive-p`
- fix position of global variable declaration