+(defconst mouse-sel-bound-events
+ '(;; Primary selection bindings.
+ ;;
+ ;; Bind keys to `ignore' instead of unsetting them because modes may
+ ;; bind `down-mouse-1', for instance, without binding `mouse-1'.
+ ;; If we unset `mouse-1', this leads to a bitch_at_user when the
+ ;; mouse goes up because no matching binding is found for that.
+ ([mouse-1] . ignore)
+ ([drag-mouse-1] . ignore)
+ ([mouse-3] . ignore)
+ ([down-mouse-1] . mouse-select)
+ ([down-mouse-3] . mouse-extend)
+ ([mouse-2] . mouse-insert-selection)
+ ;; Secondary selection bindings.
+ ([M-mouse-1] . ignore)
+ ([M-drag-mouse-1] . ignore)
+ ([M-mouse-3] . ignore)
+ ([M-down-mouse-1] . mouse-select-secondary)
+ ([M-mouse-2] . mouse-insert-secondary)
+ ([M-down-mouse-3] . mouse-extend-secondary))
+ "An alist of events that `mouse-sel-mode' binds.")
+
+;;=== User Command ========================================================
+
+(defvar mouse-sel-has-been-enabled nil
+ "Non-nil if Mouse Sel mode has been enabled at least once.")
+
+(defvar mouse-sel-original-bindings nil)
+(defvar mouse-sel-original-interprogram-cut-function nil)
+(defvar mouse-sel-original-interprogram-paste-function nil)
+
+;;;###autoload
+(define-minor-mode mouse-sel-mode
+ "Toggle Mouse Sel mode.
+With prefix ARG, turn Mouse Sel mode on if and only if ARG is positive.
+Returns the new status of Mouse Sel mode (non-nil means on).
+
+When Mouse Sel mode is enabled, mouse selection is enhanced in various ways:
+
+- Clicking mouse-1 starts (cancels) selection, dragging extends it.
+
+- Clicking or dragging mouse-3 extends the selection as well.
+
+- Double-clicking on word constituents selects words.
+Double-clicking on symbol constituents selects symbols.
+Double-clicking on quotes or parentheses selects sexps.
+Double-clicking on whitespace selects whitespace.
+Triple-clicking selects lines.
+Quad-clicking selects paragraphs.
+
+- Selecting sets the region & X primary selection, but does NOT affect
+the `kill-ring', nor do the kill-ring functions change the X selection.
+Because the mouse handlers set the primary selection directly,
+mouse-sel sets the variables `interprogram-cut-function' and
+`interprogram-paste-function' to nil.
+
+- Clicking mouse-2 inserts the contents of the primary selection at
+the mouse position (or point, if `mouse-yank-at-point' is non-nil).