From 59b6c94d1a15d3ab76dbf5f56f21ed460563a6e8 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Wed, 28 Oct 2015 08:10:47 +0000 Subject: [PATCH] [Fix #21 Fix #17] Add beacon-blink-when-point-moves-horizontally --- beacon.el | 52 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 18 deletions(-) diff --git a/beacon.el b/beacon.el index 616330543..97bef0c1c 100644 --- a/beacon.el +++ b/beacon.el @@ -53,13 +53,20 @@ Otherwise this should be a number, and `beacon' will push the mark whenever point moves more than that many lines." :type '(choice integer (const nil))) -(defcustom beacon-blink-when-point-moves nil - "Should the beacon blink when moving a long distance? -If nil, don't blink due to plain movement. +(defcustom beacon-blink-when-point-moves-vertically nil + "Should the beacon blink when moving a long distance vertically? +If nil, don't blink due to vertical movement. If non-nil, this should be an integer, which is the minimum movement distance (in lines) that triggers a beacon blink." :type '(choice integer (const nil))) +(defcustom beacon-blink-when-point-moves-horizontally nil + "Should the beacon blink when moving a long distance horizontally? +If nil, don't blink due to horizontal movement. +If non-nil, this should be an integer, which is the minimum +movement distance (in columns) that triggers a beacon blink." + :type '(choice integer (const nil))) + (defcustom beacon-blink-when-buffer-changes t "Should the beacon blink when changing buffer?" :type 'boolean) @@ -294,26 +301,34 @@ Only returns `beacon-size' elements." ;;; Movement detection -(defun beacon--movement-> (delta) - "Return non-nil if latest point movement is > DELTA. -If DELTA is nil, return nil." - (and delta +(defun beacon--movement-> (delta-y &optional delta-x) + "Return non-nil if latest vertical movement is > DELTA-Y. +If DELTA-Y is nil, return nil. +The same is true for DELTA-X and horizonta movement." + (and delta-y (markerp beacon--previous-place) (equal (marker-buffer beacon--previous-place) (current-buffer)) ;; Quick check that prevents running the code below in very ;; short movements (like typing). (> (abs (- (point) beacon--previous-place)) - delta) - ;; Check if the movement was >= DELTA lines by moving DELTA - ;; lines. `count-screen-lines' is too slow if the movement had - ;; thousands of lines. - (save-excursion - (let ((p (point))) - (goto-char (min beacon--previous-place p)) - (vertical-motion delta) - (> (max p beacon--previous-place) - (line-beginning-position)))))) + delta-y) + ;; Col movement. + (or (and delta-x + (> (abs (- (current-column) + (save-excursion + (goto-char beacon--previous-place) + (current-column)))) + delta-x)) + ;; Check if the movement was >= DELTA lines by moving DELTA + ;; lines. `count-screen-lines' is too slow if the movement had + ;; thousands of lines. + (save-excursion + (let ((p (point))) + (goto-char (min beacon--previous-place p)) + (vertical-motion delta-y) + (> (max p beacon--previous-place) + (line-beginning-position))))))) (defun beacon--maybe-push-mark () "Push mark if it seems to be safe." @@ -338,7 +353,8 @@ If DELTA is nil, return nil." (equal beacon--window-scrolled (selected-window))) (beacon-blink)) ;; Blink for movement - ((beacon--movement-> beacon-blink-when-point-moves) + ((beacon--movement-> beacon-blink-when-point-moves-vertically + beacon-blink-when-point-moves-horizontally) (beacon-blink)) ;; Even if we don't blink, vanish any previous beacon. (t (beacon--vanish))) -- 2.39.2