[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/pulsar ac3d050113 08/15: Merge pull request #25 from sh
From: |
ELPA Syncer |
Subject: |
[elpa] externals/pulsar ac3d050113 08/15: Merge pull request #25 from shipmints/region-window-change-redux |
Date: |
Tue, 26 Nov 2024 03:58:51 -0500 (EST) |
branch: externals/pulsar
commit ac3d050113033af9f8ccd148c8bb2058845ac228
Merge: e231995122 d9eb079dda
Author: Protesilaos Stavrou <info@protesilaos.com>
Commit: GitHub <noreply@github.com>
Merge pull request #25 from shipmints/region-window-change-redux
Region window change redux
---
pulsar.el | 124 +++++++++++++++++++++++++++++++++++++++++++++++++++-----------
1 file changed, 103 insertions(+), 21 deletions(-)
diff --git a/pulsar.el b/pulsar.el
index 59d0152f8c..6014b73e02 100644
--- a/pulsar.el
+++ b/pulsar.el
@@ -133,14 +133,29 @@ This only takes effect when `pulsar-mode' (buffer-local)
or
(defcustom pulsar-pulse-region-functions
'(yank
kill-region
+ kill-line
kill-ring-save
append-next-kill
+ kill-whole-line
+ kill-visual-line
+ kill-word backward-kill-word
+ kill-sentence backward-kill-sentence
+ kill-paragraph backward-kill-paragraph
+ kill-sexp backward-kill-sexp
+ kill-rectangle
+ yank-rectangle
+ open-rectangle
undo)
"Functions that highlight the affected region after invocation.
-This only takes effect when `pulsar-mode' (buffer-local) or
-`pulsar-global-mode' is enabled."
+This only takes effect when `pulsar-mode' is enabled."
:type '(repeat function)
- :package-version '(pulsar . "1.3.0")
+ :package-version '(pulsar . "1.2.0")
+ :group 'pulsar)
+
+(defcustom pulsar-pulse-region nil
+ "When non-nil, highlight the affected region after invocation."
+ :type 'boolean
+ :package-version '(pulsar . "1.2.0")
:group 'pulsar)
(defcustom pulsar-resolve-pulse-function-aliases t
@@ -164,7 +179,7 @@ pulsing makes sense."
:group 'pulsar)
(defcustom pulsar-pulse-on-window-change t
- "When non-nil enable pulsing on every window change.
+ "When non-nil, enable pulsing on every window change.
This covers all commands or functions that affect the current
window. Users who prefer to trigger a pulse only after select
functions (e.g. only after `other-window') are advised to set
@@ -206,7 +221,35 @@ background attribute."
:group 'pulsar)
(defcustom pulsar-region-face 'pulsar-face
- "Face used in `pulsar-pulse-region'."
+ "Face to indicate non-destructive region changes."
+ :type '(choice (variable pulsar-face)
+ (radio (face :tag "Generic pulse.el face" pulsar-generic)
+ (face :tag "Red style" pulsar-red)
+ (face :tag "Green style" pulsar-green)
+ (face :tag "Yellow style" pulsar-yellow)
+ (face :tag "Blue style" pulsar-blue)
+ (face :tag "Magenta style" pulsar-magenta)
+ (face :tag "Cyan style" pulsar-cyan)
+ (face :tag "Other face (must have a background)")))
+ :package-version '(pulsar . "1.2.0")
+ :group 'pulsar)
+
+(defcustom pulsar-region-change-face 'pulsar-face
+ "Face to indicate destructive region changes."
+ :type '(choice (variable pulsar-face)
+ (radio (face :tag "Generic pulse.el face" pulsar-generic)
+ (face :tag "Red style" pulsar-red)
+ (face :tag "Green style" pulsar-green)
+ (face :tag "Yellow style" pulsar-yellow)
+ (face :tag "Blue style" pulsar-blue)
+ (face :tag "Magenta style" pulsar-magenta)
+ (face :tag "Cyan style" pulsar-cyan)
+ (face :tag "Other face (must have a background)")))
+ :package-version '(pulsar . "1.2.0")
+ :group 'pulsar)
+
+(defcustom pulsar-window-change-face 'pulsar-face
+ "Face to indicate the current position on window changes."
:type '(choice (variable pulsar-face)
(radio (face :tag "Generic pulse.el face" pulsar-generic)
(face :tag "Red style" pulsar-red)
@@ -338,6 +381,8 @@ With optional FACE, use it instead of `pulsar-face'.
With optional START and END, highlight the region in-between
instead of the current line."
+ (when (and (numberp start) (numberp end) (= start end)) ; pulse the whole
line if start=end
+ (setq start nil end nil))
(let* ((pulse-flag (if no-pulse nil pulsar-pulse))
(pulse-delay pulsar-delay)
(pulse-iterations pulsar-iterations)
@@ -384,10 +429,7 @@ pulse effect."
;; end (progn (move-to-column endcol) (point))))
;; (pulsar--pulse nil nil beg end)))
(pulsar--pulse nil pulsar-region-face beg end))
- (when (mark)
- (let ((beg (mark))
- (end (point)))
- (pulsar--pulse nil pulsar-region-face beg end)))))
+ (pulsar--pulse nil pulsar-region-face)))
;;;###autoload
(defun pulsar-highlight-line ()
@@ -477,7 +519,7 @@ For lines, do the same as `pulsar-highlight-line'."
(cond
((bound-and-true-p rectangle-mark-mode)
(pulsar--highlight-rectangle))
- ((use-region-p)
+ ((region-active-p)
(pulsar--pulse :no-pulse pulsar-highlight-face (region-beginning)
(region-end)))
(t
(pulsar--pulse :no-pulse pulsar-highlight-face))))
@@ -495,10 +537,15 @@ Also check `pulsar-global-mode'."
(when pulsar-resolve-pulse-function-aliases
(pulsar-resolve-function-aliases))
(add-hook 'post-command-hook #'pulsar--post-command-pulse nil 'local)
+ (when pulsar-pulse-region
+ (add-hook 'after-change-functions #'pulsar--after-change-function
nil 'local))
(when pulsar-pulse-on-window-change
- (add-hook 'window-state-change-functions
#'pulsar--pulse-on-window-change nil 'local)))
+ (add-hook 'window-buffer-change-functions
#'pulsar--pulse-on-window-change nil 'local)
+ (add-hook 'window-selection-change-functions
#'pulsar--pulse-on-window-change nil 'local)))
(remove-hook 'post-command-hook #'pulsar--post-command-pulse 'local)
- (remove-hook 'window-state-change-functions
#'pulsar--pulse-on-window-change 'local)))
+ (remove-hook 'after-change-functions #'pulsar--after-change-function
'local)
+ (remove-hook 'window-buffer-change-functions
#'pulsar--pulse-on-window-change 'local)
+ (remove-hook 'window-selection-change-functions
#'pulsar--pulse-on-window-change 'local)))
(defun pulsar--on ()
"Enable `pulsar-mode'."
@@ -511,22 +558,57 @@ Also check `pulsar-global-mode'."
;;;###autoload
(define-globalized-minor-mode pulsar-global-mode pulsar-mode pulsar--on)
-(defun pulsar--pulse-on-window-change (&rest _)
- "Run `pulsar-pulse-line' on window change."
- (when (and pulsar-pulse-on-window-change
+(defun pulsar--pulse-on-window-change (window)
+ "Run `pulsar-pulse-line' on WINDOW change."
+ (when (and pulsar-mode
+ pulsar-pulse-on-window-change
+ (eq (frame-selected-window) window)
(not (minibufferp))
- (or pulsar-mode pulsar-global-mode))
- (pulsar-pulse-line)))
+ ;; Avoid double pulsing when both
+ ;; pulsar-pulse-on-window-change and
+ ;; pulsar-pulse-functions are in effect.
+ (not (memq this-command pulsar-pulse-functions))
+ (not (memq real-this-command pulsar-pulse-functions)))
+ (pulsar--pulse nil pulsar-window-change-face)))
+
+(defvar-local pulsar--pulse-region-changes nil)
+
+;; This feature is heavily inspired by @minad's `goggles' package.
+(defun pulsar--after-change-function (beg end len)
+ "`after-change-functions' hook to accumulate buffer edits.
+Changes are defined by BEG, END, LEN."
+ (when (or (memq this-command pulsar-pulse-region-functions)
+ (memq real-this-command pulsar-pulse-region-functions))
+ ;; beg and end mark the range of changed text
+ ;; len is zero for insertions
+ ;; len is change extent for deletions and beg==end
+ (when (and (zerop len) (= beg end)) ; In case of a deletion
+ (when (> beg (buffer-size))
+ (setq beg (1- beg)))
+ (setq end (1+ beg)))
+ (push (cons (copy-marker beg) (copy-marker end))
pulsar--pulse-region-changes)))
(defun pulsar--post-command-pulse ()
- "Run `pulsar-pulse-line' or pulse the region for registered functions."
- (when (or pulsar-mode pulsar-global-mode)
+ "Pulse current line, accumulated edits, or selected region."
+ (when pulsar-mode
(cond
((or (memq this-command pulsar-pulse-functions)
(memq real-this-command pulsar-pulse-functions))
(pulsar-pulse-line))
- ((or (memq this-command pulsar-pulse-region-functions)
- (memq real-this-command pulsar-pulse-region-functions))
+ ;; Extract the outer limits of the affected region from
+ ;; accumulated changes. NOTE: Non-contiguous regions such as
+ ;; rectangles will pulse their contiguous bounds.
+ ((and pulsar-pulse-region
+ pulsar--pulse-region-changes)
+ (let ((beg (apply #'min (mapcar #'car pulsar--pulse-region-changes)))
+ (end (apply #'max (mapcar #'cdr pulsar--pulse-region-changes))))
+ (setq pulsar--pulse-region-changes nil)
+ (pulsar--pulse nil pulsar-region-change-face beg end)))
+ ;; Pulse the selected region for commands that did not cause
+ ;; buffer changes; e.g., kill-ring-save.
+ ((and pulsar-pulse-region
+ (or (memq this-command pulsar-pulse-region-functions)
+ (memq real-this-command pulsar-pulse-functions)))
(pulsar-pulse-region)))))
(make-obsolete 'pulsar-setup nil "0.3.0")
- [elpa] externals/pulsar updated (e231995122 -> c48b6abcdc), ELPA Syncer, 2024/11/26
- [elpa] externals/pulsar 1a547adcb7 02/15: Refined pulsar-pulse-on-window-change, ELPA Syncer, 2024/11/26
- [elpa] externals/pulsar 0786efd0d3 06/15: Add pulsar-window-change-face pulsar-region-change-face misc items, ELPA Syncer, 2024/11/26
- [elpa] externals/pulsar e35f9d7677 01/15: Avoid double pulse in pulsar--pulse-on-window-change. Refine pulsar-pulse-region., ELPA Syncer, 2024/11/26
- [elpa] externals/pulsar c93f6a3fb1 04/15: Continued...now includes after-change-functions and refined pulsing., ELPA Syncer, 2024/11/26
- [elpa] externals/pulsar ac3d050113 08/15: Merge pull request #25 from shipmints/region-window-change-redux,
ELPA Syncer <=
- [elpa] externals/pulsar d9eb079dda 07/15: Add kill-visual-line to pulsar-pulse-region-functions, ELPA Syncer, 2024/11/26
- [elpa] externals/pulsar 7263aaf819 09/15: Update acknowledgements to mention Abdelhak Bougouffa, ELPA Syncer, 2024/11/26
- [elpa] externals/pulsar 3b7ecc74ff 10/15: Avoid repetition in the user options for faces, ELPA Syncer, 2024/11/26
- [elpa] externals/pulsar 67422e8d32 11/15: Make pulsar-window-change-face do the same as in commit 3b7ecc7, ELPA Syncer, 2024/11/26
- [elpa] externals/pulsar b6bbe57d06 14/15: Tweak the doc strings of the functions that deal with aliases, ELPA Syncer, 2024/11/26
- [elpa] externals/pulsar e81d0e26cd 12/15: Tweak a comment about the goggles package, ELPA Syncer, 2024/11/26
- [elpa] externals/pulsar 07122a68a2 13/15: Tweak the doc string of pulsar--after-change-function, ELPA Syncer, 2024/11/26
- [elpa] externals/pulsar 8d24da2421 03/15: Further refine region pulse and window change pulse., ELPA Syncer, 2024/11/26
- [elpa] externals/pulsar c5d528dc91 05/15: Put back the line pulse this helps for backward-kill-word, for example., ELPA Syncer, 2024/11/26
- [elpa] externals/pulsar c48b6abcdc 15/15: Refactor pulsar-resolve-function-aliases to be easier to read, ELPA Syncer, 2024/11/26