I think this might be related. In the following function, point is also not restored: (defun my-java-organize-imports2 () "Sorts import statements" (interactive) (message "Point %d" (point)) (sit-for 3) (save-excursion (let (deactivate-mark) ;; Remove empty lines between imports (replace-regexp "^import \\(.*\\)\n\\(\n\\)*import \\(.*\\)$" "import \\1\nimport \\3" nil (point-min) (point-max)) ;; Sort imports in file (sort-regexp-fields nil "^.*$" "^import .*$" (point-min) (point-max)))) (message "Point %d" (point)) (sit-for 3)) Thanks, Alexander