From 9f2c55bcb75a610af733b97ab801bf5a3a8cc7d3 Mon Sep 17 00:00:00 2001 From: Lucas Werkmeister Date: Sat, 13 May 2017 18:32:54 +0200 Subject: [PATCH] Restore point after formatting source code Part of #8. --- ceylon-mode.el | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ceylon-mode.el b/ceylon-mode.el index 2097965..6a9fd5a 100644 --- a/ceylon-mode.el +++ b/ceylon-mode.el @@ -144,7 +144,12 @@ The region must contain code that looks like a compilation unit so that `ceylon.formatter' can parse it, usually one or more complete declarations." (interactive) - (shell-command-on-region (region-beginning) (region-end) "ceylon format --pipe" t t (get-buffer-create "*ceylon-format-errors*") t)) + ;; remember whether point was at beginning or end of region before formatting + (setq point-at-end (eq (point) (region-end))) + ;; pipe region through ceylon.formatter + (shell-command-on-region (region-beginning) (region-end) "ceylon format --pipe" t t (get-buffer-create "*ceylon-format-errors*") t) + ;; shell-command-on-region places point at beginning of region, move to end if it was there before formatting + (if point-at-end (goto-char (region-end)))) (define-key mode-specific-map "\C-f" 'ceylon-format-region)