X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/d9b9e93c76c4001bb401be992d8a80b06f7d2fc4..1a27c64e1cf94e374cac95137b438b1651739074:/lisp/windmove.el diff --git a/lisp/windmove.el b/lisp/windmove.el index d6dd84e5b1..7757417b28 100644 --- a/lisp/windmove.el +++ b/lisp/windmove.el @@ -1,6 +1,7 @@ ;;; windmove.el --- directional window-selection routines ;; -;; Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc. +;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, +;; 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. ;; ;; Author: Hovav Shacham (hovav@cs.stanford.edu) ;; Created: 17 October 1998 @@ -8,20 +9,18 @@ ;; ;; This file is part of GNU Emacs. ;; -;; GNU Emacs is free software; you can redistribute it and/or modify +;; GNU Emacs is free software: you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by -;; the Free Software Foundation; either version 2, or (at your option) -;; any later version. -;; +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + ;; GNU Emacs is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. -;; + ;; You should have received a copy of the GNU General Public License -;; along with GNU Emacs; see the file COPYING. If not, write to the -;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, -;; Boston, MA 02111-1307, USA. +;; along with GNU Emacs. If not, see . ;; ;; -------------------------------------------------------------------- @@ -206,11 +205,8 @@ placement bugs in old versions of Emacs." ;; rest. ;; ;; This work is done by `windmove-reference-loc'. It can figure out -;; the locations of the corners by calling `window-edges', but to -;; calculate the frame-based location of point, it calls the workhorse -;; function `windmove-coordinates-of-position', which itself calls the -;; incredibly hairy builtin `compute-motion'. There is a good deal of -;; black magic in getting all the arguments to this function just right. +;; the locations of the corners by calling `window-edges' combined +;; with the result of `posn-at-point'. ;; ;; The second step is more messy. Conceptually, it is fairly simple: ;; if we know the reference location, and the coordinates of the @@ -324,11 +320,11 @@ from `windmove-frame-edges' will be the list (0 0 180 75)." (let* ((frame (if window (window-frame window) (selected-frame))) - (top-left (window-inside-edges (frame-first-window frame))) + (top-left (window-edges (frame-first-window frame))) (x-min (nth 0 top-left)) (y-min (nth 1 top-left)) - (x-max (+ x-min (frame-width frame) -1)) ; 1- for last row & col - (y-max (+ x-max (frame-height frame) -1))) + (x-max (1- (frame-width frame))) ; 1- for last row & col + (y-max (1- (frame-height frame)))) (list x-min y-min x-max y-max))) ;; it turns out that constraining is always a good thing, even when @@ -404,45 +400,6 @@ Returns the wrapped coordinate." (windmove-constrain-around-range (cdr coord) min-y max-y))))) - -;; `windmove-coordinates-of-position' is stolen and modified from the -;; Emacs Lisp Reference Manual, section 27.2.5. It seems to work -;; okay, although I am bothered by the fact that tab-offset (the cdr -;; of the next-to- last argument) is set to 0. On the other hand, I -;; can't find a single usage of `compute-motion' anywhere that doesn't -;; set this component to zero, and I'm too lazy to grovel through the -;; C source to figure out what's happening in the background. there -;; also seems to be a good deal of fun in calculating the correct -;; width of lines for telling `compute-motion' about; in particular, -;; it seems we need to subtract 1 (for the continuation column) from -;; the number that `window-width' gives, or continuation lines aren't -;; counted correctly. I haven't seen anyone doing this before, -;; though. -(defun windmove-coordinates-of-position (pos &optional window) - "Return the coordinates of position POS in window WINDOW. -Return the window-based coodinates in a cons pair: (HPOS . VPOS), -where HPOS and VPOS are the zero-based x and y components of the -screen location of POS. If WINDOW is nil, return the coordinates in -the currently selected window. -As an example, if point is in the top left corner of a window, then -the return value from `windmove-coordinates-of-position' is (0 . 0) -regardless of the where point is in the buffer and where the window -is placed in the frame." - (let* ((wind (if (null window) (selected-window) window)) - (usable-width (1- (window-width wind))) ; 1- for cont. column - (usable-height (1- (window-height wind))) ; 1- for mode line - (big-hairy-result (compute-motion - (window-start) - '(0 . 0) - pos - (cons usable-width usable-height) - usable-width - (cons (window-hscroll) - 0) ; why zero? - wind))) - (cons (nth 1 big-hairy-result) ; hpos, not vpos as documented - (nth 2 big-hairy-result)))) ; vpos, not hpos as documented - ;; This calculates the reference location in the current window: the ;; frame-based (x . y) of either point, the top-left, or the ;; bottom-right of the window, depending on ARG. @@ -469,8 +426,11 @@ supplied, if ARG is greater or smaller than zero, respectively." ((= effective-arg 0) (windmove-coord-add top-left - (windmove-coordinates-of-position (window-point window) - window))))))) + (let ((col-row + (posn-col-row + (posn-at-point (window-point window) window)))) + (cons (- (car col-row) (window-hscroll window)) + (cdr col-row))))))))) ;; This uses the reference location in the current window (calculated ;; by `windmove-reference-loc' above) to find a reference location @@ -493,13 +453,13 @@ movement is relative to." (- (nth 1 edges) windmove-window-distance-delta))) ; (x, y0-d) ((eq dir 'right) - (cons (+ (nth 2 edges) + (cons (+ (1- (nth 2 edges)) ; -1 to get actual max x windmove-window-distance-delta) - (cdr refpoint))) ; (x1+d, y) - ((eq dir 'down) + (cdr refpoint))) ; (x1+d-1, y) + ((eq dir 'down) ; -1 to get actual max y (cons (car refpoint) - (+ (nth 3 edges) - windmove-window-distance-delta))) ; (x, y1+d) + (+ (1- (nth 3 edges)) + windmove-window-distance-delta))) ; (x, y1+d-1) (t (error "Invalid direction of movement: %s" dir))))) (defun windmove-find-other-window (dir &optional arg window) @@ -608,4 +568,5 @@ Default MODIFIER is 'shift." (provide 'windmove) +;; arch-tag: 56267432-bf1a-4296-a9a0-85c6bd9f2375 ;;; windmove.el ends here