From 6040c744cc481b65254e3ef7c03d71496f9fb5a3 Mon Sep 17 00:00:00 2001 From: Lars Tveito Date: Tue, 12 May 2015 00:57:31 +0200 Subject: [PATCH] Made custom search functions that saves excursion --- focus-mode.el | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/focus-mode.el b/focus-mode.el index 665aaaa..963b6f4 100644 --- a/focus-mode.el +++ b/focus-mode.el @@ -1,6 +1,12 @@ (defvar-local focus-pre-overlay nil) (defvar-local focus-post-overlay nil) +(defun focus-search-backward (regex) + (save-excursion (re-search-backward regex nil t))) + +(defun focus-search-forward (regex) + (save-excursion (re-search-forward regex nil t))) + (defun focus-hexstr-to-int (str) (read (concat "#x" (substring str 1)))) @@ -10,12 +16,10 @@ (format "#%X" avg))) (defun focus-move-focus () - (save-excursion - (let* ((pre (or (re-search-backward "^\n" nil t) 1)) - (post (1- (or (re-search-forward "^\n" nil t 2) - (1+ (point-max)))))) - (move-overlay focus-pre-overlay (point-min) pre) - (move-overlay focus-post-overlay post (point-max))))) + (let* ((pre (or (focus-search-backward "^\n") (point-min))) + (post (or (focus-search-forward "^\n") (point-max)))) + (move-overlay focus-pre-overlay (point-min) pre) + (move-overlay focus-post-overlay post (point-max)))) ;;;###autoload (define-minor-mode focus-mode