diff options
| author | Richard M. Stallman | 1993-06-17 18:17:32 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1993-06-17 18:17:32 +0000 |
| commit | e66feb07ede03b7f6c428ba1eb85347674f2b759 (patch) | |
| tree | 6eeab3fd8a0223c539e0b09b016a595e4770fd08 | |
| parent | 1bf41cb0afa65fd2e39ba07ed5bdb0a08af47dea (diff) | |
| download | emacs-e66feb07ede03b7f6c428ba1eb85347674f2b759.tar.gz emacs-e66feb07ede03b7f6c428ba1eb85347674f2b759.zip | |
(mouse-start-secondary): New function.
(mouse-set-secondary, mouse-drag-secondary): New functions.
(mouse-kill-secondary, mouse-secondary-save-then-kill): New functions.
| -rw-r--r-- | lisp/mouse.el | 104 |
1 files changed, 103 insertions, 1 deletions
diff --git a/lisp/mouse.el b/lisp/mouse.el index 0bf5ae0c230..51f05e31b5d 100644 --- a/lisp/mouse.el +++ b/lisp/mouse.el | |||
| @@ -161,7 +161,7 @@ This must be bound to a button-down mouse event." | |||
| 161 | (push-mark newmark t t) | 161 | (push-mark newmark t t) |
| 162 | ;; Turn off the old mark when we set up an empty region. | 162 | ;; Turn off the old mark when we set up an empty region. |
| 163 | (setq deactivate-mark t)))) | 163 | (setq deactivate-mark t)))) |
| 164 | 164 | ||
| 165 | ;; Subroutine: set the mark where CLICK happened, | 165 | ;; Subroutine: set the mark where CLICK happened, |
| 166 | ;; but don't do anything else. | 166 | ;; but don't do anything else. |
| 167 | (defun mouse-set-mark-fast (click) | 167 | (defun mouse-set-mark-fast (click) |
| @@ -252,7 +252,109 @@ which prepares for a second click to delete the text." | |||
| 252 | (mouse-show-mark) | 252 | (mouse-show-mark) |
| 253 | (setq mouse-save-then-kill-posn | 253 | (setq mouse-save-then-kill-posn |
| 254 | (list (car kill-ring) (point) click-posn))))) | 254 | (list (car kill-ring) (point) click-posn))))) |
| 255 | |||
| 256 | (global-set-key [M-mouse-1] 'mouse-start-secondary) | ||
| 257 | (global-set-key [M-drag-mouse-1] 'mouse-set-secondary) | ||
| 258 | (global-set-key [M-down-mouse-1] 'mouse-drag-secondary) | ||
| 259 | (global-set-key [M-mouse-3] 'mouse-secondary-save-then-kill) | ||
| 260 | (global-set-key [M-mouse-2] 'mouse-kill-secondary) | ||
| 261 | |||
| 262 | ;; An overlay which records the current secondary selection | ||
| 263 | ;; or else is deleted when there is no secondary selection. | ||
| 264 | ;; May be nil. | ||
| 265 | (defvar mouse-secondary-overlay nil) | ||
| 266 | |||
| 267 | ;; A marker which records the specified first end for a secondary selection. | ||
| 268 | ;; May be nil. | ||
| 269 | (defvar mouse-secondary-start nil) | ||
| 270 | |||
| 271 | (defun mouse-start-secondary (click) | ||
| 272 | "Set one end of the secondary selection to the position clicked on. | ||
| 273 | Use \\[mouse-secondary-save-then-kill] to set the other end | ||
| 274 | and complete the secondary selection." | ||
| 275 | (interactive "e") | ||
| 276 | (let ((posn (event-start click))) | ||
| 277 | (select-window (posn-window posn)) | ||
| 278 | ;; Cancel any preexisting secondary selection. | ||
| 279 | (if mouse-secondary-overlay | ||
| 280 | (delete-overlay mouse-secondary-overlay)) | ||
| 281 | (if (numberp (posn-point posn)) | ||
| 282 | (progn | ||
| 283 | (or mouse-secondary-start | ||
| 284 | (setq mouse-secondary-start (make-marker))) | ||
| 285 | (move-marker mouse-secondary-start (posn-point posn)))))) | ||
| 286 | |||
| 287 | (defun mouse-set-secondary (click) | ||
| 288 | "Set the secondary selection to the text that the mouse is dragged over. | ||
| 289 | This must be bound to a mouse drag event." | ||
| 290 | (interactive "e") | ||
| 291 | (let ((posn (event-start click)) | ||
| 292 | beg | ||
| 293 | (end (event-end click))) | ||
| 294 | (select-window (posn-window posn)) | ||
| 295 | (if (numberp (posn-point posn)) | ||
| 296 | (setq beg (posn-point posn))) | ||
| 297 | (if mouse-secondary-overlay | ||
| 298 | (move-overlay mouse-secondary-overlay beg (posn-point end)) | ||
| 299 | (setq mouse-secondary-overlay (make-overlay beg (posn-point end)))) | ||
| 300 | (overlay-put mouse-secondary-overlay 'face 'secondary-selection))) | ||
| 301 | |||
| 302 | (defun mouse-drag-secondary (click) | ||
| 303 | "Set the secondary selection to the text that the mouse is dragged over. | ||
| 304 | This must be bound to a button-down mouse event." | ||
| 305 | (interactive "e") | ||
| 306 | (let ((posn (event-start click))) | ||
| 307 | (select-window (posn-window posn)) | ||
| 308 | ;; Set point temporarily, so user sees where it is. | ||
| 309 | (if (numberp (posn-point posn)) | ||
| 310 | (goto-char (posn-point posn))))) | ||
| 255 | 311 | ||
| 312 | (defun mouse-kill-secondary () | ||
| 313 | "Kill the text in the secondary selection." | ||
| 314 | (interactive "*") | ||
| 315 | (kill-region (overlay-start mouse-secondary-overlay) | ||
| 316 | (overlay-end mouse-secondary-overlay)) | ||
| 317 | (delete-overlay mouse-secondary-overlay) | ||
| 318 | (setq mouse-secondary-overlay nil)) | ||
| 319 | |||
| 320 | (defun mouse-secondary-save-then-kill (click) | ||
| 321 | "Save text to secondary start point in kill ring; if twice, kill it. | ||
| 322 | If the text between secondary start point and the mouse is the same as what's | ||
| 323 | at the front of the kill ring, this deletes the text. | ||
| 324 | Otherwise, it adds the text to the kill ring, like \\[kill-ring-save], | ||
| 325 | which prepares for a second click to delete the text." | ||
| 326 | (interactive "e") | ||
| 327 | (let ((click-posn (posn-point (event-start click))) | ||
| 328 | (start (+ 0 mouse-secondary-start)) | ||
| 329 | ;; Don't let a subsequent kill command append to this one: | ||
| 330 | ;; prevent setting this-command to kill-region. | ||
| 331 | (this-command this-command)) | ||
| 332 | (if (and (eq last-command 'mouse-secondary-save-then-kill) | ||
| 333 | mouse-save-then-kill-posn | ||
| 334 | (eq (car mouse-save-then-kill-posn) (car kill-ring)) | ||
| 335 | (equal (cdr mouse-save-then-kill-posn) | ||
| 336 | (list start click-posn))) | ||
| 337 | ;; If this is the second time we've called | ||
| 338 | ;; mouse-save-then-kill, delete the text from the buffer. | ||
| 339 | (progn | ||
| 340 | (let ((buffer-undo-list t)) | ||
| 341 | (delete-overlay mouse-secondary-overlay) | ||
| 342 | (delete-region start click-posn)) | ||
| 343 | ;; Make the undo list by hand so it is shared. | ||
| 344 | (if (not (eq buffer-undo-list t)) | ||
| 345 | (setq buffer-undo-list | ||
| 346 | (cons (cons (car kill-ring) start) | ||
| 347 | buffer-undo-list)))) | ||
| 348 | ;; Otherwise, save this region. | ||
| 349 | (select-window (posn-window (event-start click))) | ||
| 350 | (kill-ring-save start click-posn) | ||
| 351 | (if mouse-secondary-overlay | ||
| 352 | (move-overlay mouse-secondary-overlay start click-posn) | ||
| 353 | (setq mouse-secondary-overlay (make-overlay start click-posn))) | ||
| 354 | (overlay-put mouse-secondary-overlay 'face 'secondary-selection) | ||
| 355 | (setq mouse-save-then-kill-posn | ||
| 356 | (list (car kill-ring) start click-posn))))) | ||
| 357 | |||
| 256 | (defun mouse-buffer-menu (event) | 358 | (defun mouse-buffer-menu (event) |
| 257 | "Pop up a menu of buffers for selection with the mouse. | 359 | "Pop up a menu of buffers for selection with the mouse. |
| 258 | This switches buffers in the window that you clicked on, | 360 | This switches buffers in the window that you clicked on, |