aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorJimmy Aguilar Mena2022-03-13 19:26:23 +0100
committerJimmy Aguilar Mena2022-03-13 19:32:42 +0100
commitfd7bde612ab7a027651ffa29cb390aeb67679d8b (patch)
treefb985bd233c8999d28b0863d1d6ce057f54c7de2 /lisp
parent49d1fe522215d64639f62b4737c3e45f75f94eab (diff)
downloademacs-fd7bde612ab7a027651ffa29cb390aeb67679d8b.tar.gz
emacs-fd7bde612ab7a027651ffa29cb390aeb67679d8b.zip
Add new special text attribute cursor-face
Reuse the functions for highlight region. * lisp/simple.el (redisplay-unhighlight-overlay-function) : (redisplay-highlight-overlay-function) : New functions from previous lambda (redisplay-unhighlight-region-function) : (redisplay-highlight-region-function) : Redefined with the new functions. (redisplay--update-cursor-property-highlight) : New function for pre-redisplay-functions.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/simple.el79
1 files changed, 53 insertions, 26 deletions
diff --git a/lisp/simple.el b/lisp/simple.el
index accc119e2b3..cc356addb97 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -6482,27 +6482,35 @@ An example is a rectangular region handled as a list of
6482separate contiguous regions for each line." 6482separate contiguous regions for each line."
6483 (cdr (region-bounds))) 6483 (cdr (region-bounds)))
6484 6484
6485(defvar redisplay-unhighlight-region-function 6485(defun redisplay-unhighlight-overlay-function (rol)
6486 (lambda (rol) (when (overlayp rol) (delete-overlay rol)))) 6486 "If ROL is an overlay, call ``delete-overlay''."
6487 6487 (when (overlayp rol) (delete-overlay rol)))
6488(defvar redisplay-highlight-region-function 6488
6489 (lambda (start end window rol) 6489(defvar redisplay-unhighlight-region-function #'redisplay-unhighlight-overlay-function
6490 (if (not (overlayp rol)) 6490 "Function to remove the region-highlight overlay.")
6491 (let ((nrol (make-overlay start end))) 6491
6492 (funcall redisplay-unhighlight-region-function rol) 6492(defun redisplay-highlight-overlay-function (start end window rol face)
6493 (overlay-put nrol 'window window) 6493 "Update the overlay ROL in WINDOW with FACE in range START-END."
6494 (overlay-put nrol 'face 'region) 6494 (if (not (overlayp rol))
6495 ;; Normal priority so that a large region doesn't hide all the 6495 (let ((nrol (make-overlay start end)))
6496 ;; overlays within it, but high secondary priority so that if it 6496 (funcall redisplay-unhighlight-region-function rol)
6497 ;; ends/starts in the middle of a small overlay, that small overlay 6497 (overlay-put nrol 'window window)
6498 ;; won't hide the region's boundaries. 6498 (overlay-put nrol 'face face)
6499 (overlay-put nrol 'priority '(nil . 100)) 6499 ;; Normal priority so that a large region doesn't hide all the
6500 nrol) 6500 ;; overlays within it, but high secondary priority so that if it
6501 (unless (and (eq (overlay-buffer rol) (current-buffer)) 6501 ;; ends/starts in the middle of a small overlay, that small overlay
6502 (eq (overlay-start rol) start) 6502 ;; won't hide the region's boundaries.
6503 (eq (overlay-end rol) end)) 6503 (overlay-put nrol 'priority '(nil . 100))
6504 (move-overlay rol start end (current-buffer))) 6504 nrol)
6505 rol)) 6505 (unless (eq (overlay-get rol 'face) face)
6506 (overlay-put rol 'face face))
6507 (unless (and (eq (overlay-buffer rol) (current-buffer))
6508 (eq (overlay-start rol) start)
6509 (eq (overlay-end rol) end))
6510 (move-overlay rol start end (current-buffer)))
6511 rol))
6512
6513(defvar redisplay-highlight-region-function #'redisplay-highlight-overlay-function
6506 "Function to move the region-highlight overlay. 6514 "Function to move the region-highlight overlay.
6507This function is called with four parameters, START, END, WINDOW 6515This function is called with four parameters, START, END, WINDOW
6508and OVERLAY. If OVERLAY is nil, a new overlay is created. In 6516and OVERLAY. If OVERLAY is nil, a new overlay is created. In
@@ -6525,12 +6533,31 @@ The overlay is returned by the function.")
6525 (end (max pt mark)) 6533 (end (max pt mark))
6526 (new 6534 (new
6527 (funcall redisplay-highlight-region-function 6535 (funcall redisplay-highlight-region-function
6528 start end window rol))) 6536 start end window rol 'region)))
6529 (unless (equal new rol) 6537 (unless (equal new rol)
6530 (set-window-parameter window 'internal-region-overlay 6538 (set-window-parameter window 'internal-region-overlay new))))))
6531 new)))))) 6539
6532 6540(defun redisplay--update-cursor-property-highlight (window)
6533(defvar pre-redisplay-functions (list #'redisplay--update-region-highlight) 6541 "This highlights the overlay used to highlight text with cursor-face."
6542 (let ((rol (window-parameter window 'internal-cursor-face-overlay))
6543 (pt) (value) (cursor-face))
6544 (if (and (or (eq window (selected-window))
6545 (and (window-minibuffer-p)
6546 (eq window (minibuffer-selected-window))))
6547 (setq pt (window-point window))
6548 (setq value (get-text-property pt 'cursor-face))
6549 ;; extra code needed here for when passing plists
6550 (setq cursor-face (if (facep value) value)))
6551 (let* ((start (previous-single-property-change (1+ pt) 'cursor-face nil (point-min)))
6552 (end (next-single-property-change pt 'cursor-face nil (point-max)))
6553 (new (redisplay-highlight-overlay-function start end window rol cursor-face)))
6554 (unless (equal new rol)
6555 (set-window-parameter window 'internal-cursor-face-overlay new)))
6556 (if rol
6557 (redisplay-unhighlight-overlay-function rol)))))
6558
6559(defvar pre-redisplay-functions (list #'redisplay--update-cursor-property-highlight
6560 #'redisplay--update-region-highlight)
6534 "Hook run just before redisplay. 6561 "Hook run just before redisplay.
6535It is called in each window that is to be redisplayed. It takes one argument, 6562It is called in each window that is to be redisplayed. It takes one argument,
6536which is the window that will be redisplayed. When run, the `current-buffer' 6563which is the window that will be redisplayed. When run, the `current-buffer'