324 |
(let* ((frame (if window |
(let* ((frame (if window |
325 |
(window-frame window) |
(window-frame window) |
326 |
(selected-frame))) |
(selected-frame))) |
327 |
(top-left (window-inside-edges (frame-first-window frame))) |
(top-left (window-edges (frame-first-window frame))) |
328 |
(x-min (nth 0 top-left)) |
(x-min (nth 0 top-left)) |
329 |
(y-min (nth 1 top-left)) |
(y-min (nth 1 top-left)) |
330 |
(x-max (+ x-min (frame-width frame) -1)) ; 1- for last row & col |
(x-max (1- (frame-width frame))) ; 1- for last row & col |
331 |
(y-max (+ x-max (frame-height frame) -1))) |
(y-max (1- (frame-height frame)))) |
332 |
(list x-min y-min x-max y-max))) |
(list x-min y-min x-max y-max))) |
333 |
|
|
334 |
;; it turns out that constraining is always a good thing, even when |
;; it turns out that constraining is always a good thing, even when |
406 |
|
|
407 |
|
|
408 |
;; `windmove-coordinates-of-position' is stolen and modified from the |
;; `windmove-coordinates-of-position' is stolen and modified from the |
409 |
;; Emacs Lisp Reference Manual, section 27.2.5. It seems to work |
;; Emacs 20 Lisp Reference Manual, section 27.2.5. It seems to work |
410 |
;; okay, although I am bothered by the fact that tab-offset (the cdr |
;; okay, although I am bothered by the fact that tab-offset (the cdr |
411 |
;; of the next-to- last argument) is set to 0. On the other hand, I |
;; of the next-to- last argument) is set to 0. On the other hand, I |
412 |
;; can't find a single usage of `compute-motion' anywhere that doesn't |
;; can't find a single usage of `compute-motion' anywhere that doesn't |
418 |
;; the number that `window-width' gives, or continuation lines aren't |
;; the number that `window-width' gives, or continuation lines aren't |
419 |
;; counted correctly. I haven't seen anyone doing this before, |
;; counted correctly. I haven't seen anyone doing this before, |
420 |
;; though. |
;; though. |
421 |
(defun windmove-coordinates-of-position (pos &optional window) |
;; |
422 |
"Return the coordinates of position POS in window WINDOW. |
;; Now updated for Emacs 21, based on the Emacs 21 Lisp Reference |
423 |
|
;; Manual, section 30.2.5. It is no longer necessary to subtract |
424 |
|
;; 1 for the usable width of the window. |
425 |
|
;; TODO: also handle minibuffer case, w/ `minibuffer-prompt-width'. |
426 |
|
(defun windmove-coordinates-of-position (pos) |
427 |
|
"Return the coordinates of position POS in the current window. |
428 |
Return the window-based coodinates in a cons pair: (HPOS . VPOS), |
Return the window-based coodinates in a cons pair: (HPOS . VPOS), |
429 |
where HPOS and VPOS are the zero-based x and y components of the |
where HPOS and VPOS are the zero-based x and y components of the |
430 |
screen location of POS. If WINDOW is nil, return the coordinates in |
screen location of POS. |
|
the currently selected window. |
|
431 |
As an example, if point is in the top left corner of a window, then |
As an example, if point is in the top left corner of a window, then |
432 |
the return value from `windmove-coordinates-of-position' is (0 . 0) |
the return value from `windmove-coordinates-of-position' is (0 . 0) |
433 |
regardless of the where point is in the buffer and where the window |
regardless of the where point is in the buffer and where the window |
434 |
is placed in the frame." |
is placed in the frame." |
435 |
(let* ((wind (if (null window) (selected-window) window)) |
(let ((big-hairy-result (compute-motion |
436 |
(big-hairy-result (compute-motion |
(window-start) |
437 |
(window-start) |
'(0 . 0) |
438 |
'(0 . 0) |
pos |
439 |
pos |
nil ; (window-width window-height) |
440 |
nil ; (window-width window-height) |
nil ; window-width |
441 |
nil ; window-width |
(cons (window-hscroll) |
442 |
(cons (window-hscroll) |
0) ; why zero? |
443 |
0) ; why zero? |
(selected-window)))) |
444 |
wind))) |
(cons (nth 1 big-hairy-result) ; hpos, not vpos as documented |
445 |
(cons (nth 1 big-hairy-result) ; hpos, not vpos as documented |
(nth 2 big-hairy-result)))) ; vpos, not hpos as documented |
446 |
(nth 2 big-hairy-result)))) ; vpos, not hpos as documented |
|
447 |
|
(defun windmove-coordinates-of-window-position (pos &optional window) |
448 |
|
"Return the coordinates of position POS in WINDOW. |
449 |
|
Return the window-based coodinates in a cons pair: (HPOS . VPOS), |
450 |
|
where HPOS and VPOS are the zero-based x and y components of the |
451 |
|
screen location of POS. If WINDOW is nil, return the coordinates in |
452 |
|
the currently selected window." |
453 |
|
(if (null window) |
454 |
|
(windmove-coordinates-of-position pos) |
455 |
|
(save-selected-window |
456 |
|
(select-window window) |
457 |
|
(windmove-coordinates-of-position pos)))) |
458 |
|
|
459 |
;; This calculates the reference location in the current window: the |
;; This calculates the reference location in the current window: the |
460 |
;; frame-based (x . y) of either point, the top-left, or the |
;; frame-based (x . y) of either point, the top-left, or the |
482 |
((= effective-arg 0) |
((= effective-arg 0) |
483 |
(windmove-coord-add |
(windmove-coord-add |
484 |
top-left |
top-left |
485 |
(windmove-coordinates-of-position (window-point window) |
(windmove-coordinates-of-window-position |
486 |
window))))))) |
(window-point window) |
487 |
|
window))))))) |
488 |
|
|
489 |
;; This uses the reference location in the current window (calculated |
;; This uses the reference location in the current window (calculated |
490 |
;; by `windmove-reference-loc' above) to find a reference location |
;; by `windmove-reference-loc' above) to find a reference location |
507 |
(- (nth 1 edges) |
(- (nth 1 edges) |
508 |
windmove-window-distance-delta))) ; (x, y0-d) |
windmove-window-distance-delta))) ; (x, y0-d) |
509 |
((eq dir 'right) |
((eq dir 'right) |
510 |
(cons (+ (nth 2 edges) |
(cons (+ (1- (nth 2 edges)) ; -1 to get actual max x |
511 |
windmove-window-distance-delta) |
windmove-window-distance-delta) |
512 |
(cdr refpoint))) ; (x1+d, y) |
(cdr refpoint))) ; (x1+d-1, y) |
513 |
((eq dir 'down) |
((eq dir 'down) ; -1 to get actual max y |
514 |
(cons (car refpoint) |
(cons (car refpoint) |
515 |
(+ (nth 3 edges) |
(+ (1- (nth 3 edges)) |
516 |
windmove-window-distance-delta))) ; (x, y1+d) |
windmove-window-distance-delta))) ; (x, y1+d-1) |
517 |
(t (error "Invalid direction of movement: %s" dir))))) |
(t (error "Invalid direction of movement: %s" dir))))) |
518 |
|
|
519 |
(defun windmove-find-other-window (dir &optional arg window) |
(defun windmove-find-other-window (dir &optional arg window) |