From 0f40fe9df27432436636d89aa7aa885c5739b3ea Mon Sep 17 00:00:00 2001 From: Jim Pudar Date: Sun, 26 May 2019 14:01:40 -0700 Subject: [PATCH] Improve point handling in perltidy functions This moves the point and content of the window close to where you were before you ran perltidy. Of course if perltidy adds or removes a significant amount of characters / lines as part of tidying, the point will be moved by that amount. However in practice this I've found this to be close enough. --- CHANGELOG.develop | 4 ++++ layers/+lang/perl5/funcs.el | 16 ++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.develop b/CHANGELOG.develop index 760a036f2..541ef5f8d 100644 --- a/CHANGELOG.develop +++ b/CHANGELOG.develop @@ -2074,6 +2074,10 @@ Other: - Fixed =spacemacs/run-pandoc= not to reset =pandoc--local-settings= (thanks to martian-f) - Added declaration for the ~SPC P~ prefix (thanks to Codruț Constantin Gușoi) +**** Perl5 +- Fixed =spacemacs/perltidy-format-buffer= and + =spacemacs/perltidy-format-function= to move the point and window to their + original locations. **** PHP - Added company-php (thanks to jim and Eivind Fonn) - Fixed php-company autocompletion (thanks to Dela Anthonio) diff --git a/layers/+lang/perl5/funcs.el b/layers/+lang/perl5/funcs.el index 5aa2f43a4..73c0dcb2c 100644 --- a/layers/+lang/perl5/funcs.el +++ b/layers/+lang/perl5/funcs.el @@ -40,11 +40,19 @@ If region is active, operate on it, else operate on line." (defun spacemacs/perltidy-format-buffer () "Format current buffer with perltidy." (interactive) - (mark-whole-buffer) - (spacemacs/perltidy-format)) + (let ((old-point (point)) + (old-window-start (window-start))) + (mark-whole-buffer) + (spacemacs/perltidy-format) + (goto-char old-point) + (set-window-start (selected-window) old-window-start))) (defun spacemacs/perltidy-format-function () "Format current function with perltidy." (interactive) - (mark-defun) - (spacemacs/perltidy-format)) + (let ((old-point (point)) + (old-window-start (window-start))) + (mark-defun) + (spacemacs/perltidy-format) + (goto-char old-point) + (set-window-start (selected-window) old-window-start)))