-;;=== Validate selection ==================================================
-
-(defun mouse-sel-validate-selection ()
- "Validate selections in mouse-sel-selection-alist.
-For each listed selection, remove the selection overlay if Emacs no longer
-owns the selection."
- (let ((owner-p-function mouse-sel-selection-owner-p-function)
- (alist mouse-sel-selection-alist)
- selection overlay)
- (if owner-p-function
- (while alist
- (setq selection (car (car alist))
- overlay (symbol-value (nth 1 (car alist)))
- alist (cdr alist))
- (or (funcall owner-p-function selection)
- (delete-overlay overlay))))))
-
-(add-hook 'pre-command-hook 'mouse-sel-validate-selection)
+;;=== Handle loss of selections ===========================================
+
+(defun mouse-sel-lost-selection-hook (selection)
+ "Remove the overlay for a lost selection."
+ (let ((overlay (mouse-sel-selection-overlay selection)))
+ (delete-overlay overlay)))
+
+(add-hook 'x-lost-selection-hooks 'mouse-sel-lost-selection-hook)