配置如下,保存文件的时候会用astyle格式化,但是问题是格式化完了以后会自动跳到第一行。 请问有没有办法格式化完了以后回到保存时的行数?
(defvar astyle-command "F:\\astyle\\bin\\AStyle.exe -n -c -j -Z")
(defun astyle-region (start end)
"Run astyle on region, formatting it in a pleasant way."
(interactive "r")
(save-excursion
(shell-command-on-region start end astyle-command nil t (get-buffer-create "*Astyle Errors*") nil)
)
)
(defun astyle-buffer ()
"Run astyle on whole buffer, formatting it in a pleasant way."
(interactive)
(save-excursion
(astyle-region (point-min) (point-max))))
(add-hook 'c-mode-common-hook
'(lambda ()
(define-key c-mode-map "\C-cr" 'astyle-region)
(define-key c-mode-map "\C-cb" 'astyle-buffer)
(define-key c++-mode-map "\C-cr" 'astyle-region)
(define-key c++-mode-map "\C-cb" 'astyle-buffer)))
(add-hook 'before-save-hook
'(lambda ()
(if (file-exists-p (buffer-file-name))
(if (member (file-name-extension (buffer-name))
'("cpp" "h" "c"))
(astyle-buffer))
)))