+(defun mouse-drag-vertical-line (start-event)
+ "Change the width of a window by dragging on the vertical line."
+ (interactive "e")
+ ;; Give temporary modes such as isearch a chance to turn off.
+ (run-hooks 'mouse-leave-buffer-hook)
+ (let ((done nil)
+ (echo-keystrokes 0)
+ (start-event-frame (window-frame (car (car (cdr start-event)))))
+ (start-event-window (car (car (cdr start-event))))
+ (start-nwindows (count-windows t))
+ (old-selected-window (selected-window))
+ event mouse x left right edges wconfig growth)
+ (if (one-window-p t)
+ (error "Attempt to resize sole ordinary window"))
+ (if (= (nth 2 (window-edges start-event-window))
+ (frame-width start-event-frame))
+ (error "Attempt to drag rightmost scrollbar"))
+ (track-mouse
+ (progn
+ ;; enlarge-window only works on the selected window, so
+ ;; we must select the window where the start event originated.
+ ;; unwind-protect will restore the old selected window later.
+ (select-window start-event-window)
+ ;; loop reading events and sampling the position of
+ ;; the mouse.
+ (while (not done)
+ (setq event (read-event)
+ mouse (mouse-position))
+ ;; do nothing if
+ ;; - there is a switch-frame event.
+ ;; - the mouse isn't in the frame that we started in
+ ;; - the mouse isn't in any Emacs frame
+ ;; drag if
+ ;; - there is a mouse-movement event
+ ;; - there is a scroll-bar-movement event
+ ;; (same as mouse movement for our purposes)
+ ;; quit if
+ ;; - there is a keyboard event or some other unknown event
+ ;; unknown event.
+ (cond ((integerp event)
+ (setq done t))
+ ((eq (car event) 'switch-frame)
+ nil)
+ ((not (memq (car event)
+ '(mouse-movement scroll-bar-movement)))
+ (if (consp event)
+ (setq unread-command-events
+ (cons event unread-command-events)))
+ (setq done t))
+ ((not (eq (car mouse) start-event-frame))
+ nil)
+ ((null (car (cdr mouse)))
+ nil)
+ (t
+ (setq x (car (cdr mouse))
+ edges (window-edges)
+ left (nth 0 edges)
+ right (nth 2 edges))
+ ;; scale back a move that would make the
+ ;; window too thin.
+ (cond ((< (- x left -1) window-min-width)
+ (setq x (+ left window-min-width -1))))
+ ;; compute size change needed
+ (setq growth (- x right -1)
+ wconfig (current-window-configuration))
+ (enlarge-window growth t)
+ ;; if this window's growth caused another
+ ;; window to be deleted because it was too
+ ;; thin, rescind the change.
+ ;;
+ ;; if size change caused space to be stolen
+ ;; from a window to the left of this one,
+ ;; rescind the change.
+ (if (or (/= start-nwindows (count-windows t))
+ (/= left (nth 0 (window-edges))))
+ (set-window-configuration wconfig)))))))))
+\f