aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuanma Barranquero2019-10-25 15:42:13 +0200
committerJuanma Barranquero2019-10-25 15:42:13 +0200
commit17db4a0a02157457cf0d2a6f6c3afa5184e118be (patch)
treeaf6084c077e067d808bad112879ced3f04360ce7
parent372c4ebf6d3c7d39cc5b1e04e7f228543fec107d (diff)
downloademacs-17db4a0a02157457cf0d2a6f6c3afa5184e118be.tar.gz
emacs-17db4a0a02157457cf0d2a6f6c3afa5184e118be.zip
windmove.el: Mark unused code as obsolete
* lisp/windmove.el (windmove-window-distance-delta) (windmove-coord-add, windmove-constrain-to-range) (windmove-constrain-around-range, windmove-frame-edges) (windmove-constrain-loc-for-movement) (windmove-wrap-loc-for-movement, windmove-reference-loc) (windmove-other-window-loc): Declare obsolete. (windmove-find-other-window, windmove-do-window-select): Doc fixes. * etc/NEWS: Document it.
-rw-r--r--etc/NEWS7
-rw-r--r--lisp/windmove.el184
2 files changed, 34 insertions, 157 deletions
diff --git a/etc/NEWS b/etc/NEWS
index 20967d4d772..56127ba6018 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -750,6 +750,13 @@ that was in the specified direction.
750to the commands that swap the states of the selected window with the 750to the commands that swap the states of the selected window with the
751window in the specified direction. 751window in the specified direction.
752 752
753*** Windmove code no longer used is now obsolete. That includes the
754user option 'windmove-window-distance-delta' and the functions
755'windmove-coord-add', 'windmove-constrain-to-range',
756'windmove-constrain-around-range', 'windmove-frame-edges',
757'windmove-constrain-loc-for-movement', 'windmove-wrap-loc-for-movement',
758'windmove-reference-loc' and 'windmove-other-window-loc'.
759
753** Octave mode 760** Octave mode
754The mode is automatically enabled in files that start with the 761The mode is automatically enabled in files that start with the
755'function' keyword. 762'function' keyword.
diff --git a/lisp/windmove.el b/lisp/windmove.el
index feb269a4074..d5c6e348bef 100644
--- a/lisp/windmove.el
+++ b/lisp/windmove.el
@@ -109,14 +109,6 @@
109;; 109;;
110;; (setq windmove-wrap-around t) 110;; (setq windmove-wrap-around t)
111;; 111;;
112;;
113;; Note: If you have an Emacs that manifests a bug that sometimes
114;; causes the occasional creation of a "lost column" between windows,
115;; so that two adjacent windows do not actually touch, you may want to
116;; increase the value of `windmove-window-distance-delta' to 2 or 3:
117;;
118;; (setq windmove-window-distance-delta 2)
119;;
120 112
121;; Acknowledgments: 113;; Acknowledgments:
122;; 114;;
@@ -167,150 +159,41 @@ to a value larger than 1 may be useful in getting around window-
167placement bugs in old versions of Emacs." 159placement bugs in old versions of Emacs."
168 :type 'number 160 :type 'number
169 :group 'windmove) 161 :group 'windmove)
162(make-obsolete-variable 'windmove-window-distance-delta
163 "no longer used." "27.1")
170 164
171 165
172;; Implementation overview: 166;; Note:
173;;
174;; The conceptual framework behind this code is all fairly simple. We
175;; are on one window; we wish to move to another. The correct window
176;; to move to is determined by the position of point in the current
177;; window as well as the overall window setup.
178;;
179;; Early on, I made the decision to base my implementation around the
180;; built-in function `window-at'. This function takes a frame-based
181;; coordinate, and returns the window that contains it. Using this
182;; function, the job of the various top-level windmove functions can
183;; be decomposed: first, find the current frame-based location of
184;; point; second, manipulate it in some way to give a new location,
185;; that hopefully falls in the window immediately at left (or right,
186;; etc.); third, use `window-at' and `select-window' to select the
187;; window at that new location.
188;;
189;; This is probably not the only possible architecture, and it turns
190;; out to have some inherent cruftiness. (Well, okay, the third step
191;; is pretty clean....) We will consider each step in turn.
192;;
193;; A quick digression about coordinate frames: most of the functions
194;; in the windmove package deal with screen coordinates in one way or
195;; another. These coordinates are always relative to some reference
196;; points. Window-based coordinates have their reference point in the
197;; upper-left-hand corner of whatever window is being talked about;
198;; frame-based coordinates have their reference point in the
199;; upper-left-hand corner of the entire frame (of which the current
200;; window is a component).
201;;
202;; All coordinates are zero-based, which simply means that the
203;; reference point (whatever it is) is assigned the value (x=0, y=0).
204;; X-coordinates grow down the screen, and Y-coordinates grow towards
205;; the right of the screen.
206;; 167;;
207;; Okay, back to work. The first step is to gather information about 168;; The functions that follow were used in the implementation of
208;; the frame-based coordinates of point, or rather, the reference 169;; `windmove-find-other-window', but they are known to be unreliable
209;; location. The reference location can be point, or the upper-left, 170;; after the window and frame rework done in 2013, so they are no
210;; or the lower-right corner of the window; the particular one used is 171;; longer used or maintained; their functionality is subsumed in the
211;; controlled by the prefix argument to `windmove-left' and all the 172;; new function `window-in-direction'. They are kept only for
212;; rest. 173;; compatibility and will be removed in the future. Please consider
213;; 174;; using the new window interfaces documented in "(elisp)Windows".
214;; This work is done by `windmove-reference-loc'. It can figure out
215;; the locations of the corners by calling `window-edges' combined
216;; with the result of `posn-at-point'.
217;;
218;; The second step is more messy. Conceptually, it is fairly simple:
219;; if we know the reference location, and the coordinates of the
220;; current window, we can "throw" our reference point just over the
221;; appropriate edge of the window, and see what other window is
222;; there. More explicitly, consider this example from the user
223;; documentation above.
224;;
225;; -------------
226;; | | A |
227;; | | |
228;; | |-----
229;; | * | | (* is point in the currently
230;; | | B | selected window)
231;; | | |
232;; -------------
233;;
234;; The asterisk marks the reference point; we wish to move right.
235;; Since we are moving horizontally, the Y coordinate of the new
236;; location will be the same. The X coordinate can be such that it is
237;; just past the edge of the present window. Obviously, the new point
238;; will be inside window B. This in itself is fairly simple: using
239;; the result of `windmove-reference-loc' and `window-edges', all the
240;; necessary math can be performed. (Having said that, there is a
241;; good deal of room for off-by-one errors, and Emacs 19.34, at least,
242;; sometimes manifests a bug where two windows don't actually touch,
243;; so a larger skip is required.) The actual math here is done by
244;; `windmove-other-window-loc'.
245;;
246;; But we can't just pass the result of `windmove-other-window-loc' to
247;; `window-at' directly. Why not? Suppose a move would take us off
248;; the edge of the screen, say to the left. We want to give a
249;; descriptive error message to the user. Or, suppose that a move
250;; would place us in the minibuffer. What if the minibuffer is
251;; inactive?
252;;
253;; Actually, the whole subject of the minibuffer edge of the frame is
254;; rather messy. It turns out that with a sufficiently large delta,
255;; we can fly off the bottom edge of the frame and miss the minibuffer
256;; altogether. This, I think, is never right: if there's a minibuffer
257;; and you're not in it, and you move down, the minibuffer should be
258;; in your way.
259;;
260;; (By the way, I'm not totally sure that the code does the right
261;; thing in really weird cases, like a frame with no minibuffer.)
262;;
263;; So, what we need is some ways to do constraining and such. The
264;; early versions of windmove took a fairly simplistic approach to all
265;; this. When I added the wrap-around option, those internals had to
266;; be rewritten. After a *lot* of futzing around, I came up with a
267;; two-step process that I think is general enough to cover the
268;; relevant cases. (I'm not totally happy with having to pass the
269;; window variable as deep as I do, but we can't have everything.)
270;;
271;; In the first phase, we make sure that the new location is sane.
272;; "Sane" means that we can only fall of the edge of the frame in the
273;; direction we're moving in, and that we don't miss the minibuffer if
274;; we're moving down and not already in the minibuffer. The function
275;; `windmove-constrain-loc-for-movement' takes care of all this.
276;;
277;; Then, we handle the wraparound, if it's enabled. The function
278;; `windmove-wrap-loc-for-movement' takes coordinate values (both X
279;; and Y) that fall off the edge of the frame, and replaces them with
280;; values on the other side of the frame. It also has special
281;; minibuffer-handling code again, because we want to wrap through the
282;; minibuffer if it's not enabled.
283;;
284;; So, that's it. Seems to work. All of this work is done by the fun
285;; function `windmove-find-other-window'.
286;;
287;; So, now we have a window to move to (or nil if something's gone
288;; wrong). The function `windmove-do-window-select' is the main
289;; driver function: it actually does the `select-window'. It is
290;; called by four little convenience wrappers, `windmove-left',
291;; `windmove-up', `windmove-right', and `windmove-down', which make
292;; for convenient keybinding.
293
294 175
295;; Quick & dirty utility function to add two (x . y) coords. 176;; Quick & dirty utility function to add two (x . y) coords.
296(defun windmove-coord-add (coord1 coord2) 177(defun windmove-coord-add (coord1 coord2)
297 "Add the two coordinates. 178 "Add the two coordinates.
298Both COORD1 and COORD2 are coordinate cons pairs, (HPOS . VPOS). The 179Both COORD1 and COORD2 are coordinate cons pairs, (HPOS . VPOS). The
299result is another coordinate cons pair." 180result is another coordinate cons pair."
181 (declare (obsolete "no longer used." "27.1"))
300 (cons (+ (car coord1) (car coord2)) 182 (cons (+ (car coord1) (car coord2))
301 (+ (cdr coord1) (cdr coord2)))) 183 (+ (cdr coord1) (cdr coord2))))
302 184
303
304(defun windmove-constrain-to-range (n min-n max-n) 185(defun windmove-constrain-to-range (n min-n max-n)
305 "Ensure that N is between MIN-N and MAX-N inclusive by constraining. 186 "Ensure that N is between MIN-N and MAX-N inclusive by constraining.
306If N is less than MIN-N, return MIN-N; if greater than MAX-N, return 187If N is less than MIN-N, return MIN-N; if greater than MAX-N, return
307MAX-N." 188MAX-N."
189 (declare (obsolete "no longer used." "27.1"))
308 (max min-n (min n max-n))) 190 (max min-n (min n max-n)))
309 191
310(defun windmove-constrain-around-range (n min-n max-n) 192(defun windmove-constrain-around-range (n min-n max-n)
311 "Ensure that N is between MIN-N and MAX-N inclusive by wrapping. 193 "Ensure that N is between MIN-N and MAX-N inclusive by wrapping.
312If N is less than MIN-N, return MAX-N; if greater than MAX-N, return 194If N is less than MIN-N, return MAX-N; if greater than MAX-N, return
313MIN-N." 195MIN-N."
196 (declare (obsolete "no longer used." "27.1"))
314 (cond 197 (cond
315 ((< n min-n) max-n) 198 ((< n min-n) max-n)
316 ((> n max-n) min-n) 199 ((> n max-n) min-n)
@@ -324,18 +207,9 @@ of the frame; (X-MAX, Y-MAX) is the zero-based coordinate of the
324bottom-right corner of the frame. 207bottom-right corner of the frame.
325For example, if a frame has 76 rows and 181 columns, the return value 208For example, if a frame has 76 rows and 181 columns, the return value
326from `windmove-frame-edges' will be the list (0 0 180 75)." 209from `windmove-frame-edges' will be the list (0 0 180 75)."
210 (declare (obsolete "no longer used." "27.1"))
327 (window-edges (frame-root-window window))) 211 (window-edges (frame-root-window window)))
328 212
329;; it turns out that constraining is always a good thing, even when
330;; wrapping is going to happen. this is because:
331;; first, since we disallow exotic diagonal-around-a-corner type
332;; movements, so we can always fix the unimportant direction (the one
333;; we're not moving in).
334;; second, if we're moving down and we're not in the minibuffer, then
335;; constraining the y coordinate to max-y is okay, because if that
336;; falls in the minibuffer and the minibuffer isn't active, that y
337;; coordinate will still be off the bottom of the frame as the
338;; wrapping function sees it and so will get wrapped around anyway.
339(defun windmove-constrain-loc-for-movement (coord window dir) 213(defun windmove-constrain-loc-for-movement (coord window dir)
340 "Constrain COORD so that it is reasonable for the given movement. 214 "Constrain COORD so that it is reasonable for the given movement.
341This involves two things: first, make sure that the \"off\" coordinate 215This involves two things: first, make sure that the \"off\" coordinate
@@ -347,6 +221,7 @@ accidentally. WINDOW is the window that movement is relative to; DIR
347is the direction of the movement, one of `left', `up', `right', 221is the direction of the movement, one of `left', `up', `right',
348or `down'. 222or `down'.
349Returns the constrained coordinate." 223Returns the constrained coordinate."
224 (declare (obsolete "no longer used." "27.1"))
350 (let ((frame-edges (windmove-frame-edges window)) 225 (let ((frame-edges (windmove-frame-edges window))
351 (in-minibuffer (window-minibuffer-p window))) 226 (in-minibuffer (window-minibuffer-p window)))
352 (let ((min-x (nth 0 frame-edges)) 227 (let ((min-x (nth 0 frame-edges))
@@ -368,17 +243,13 @@ Returns the constrained coordinate."
368 (cdr coord)))) 243 (cdr coord))))
369 (cons new-x new-y))))) 244 (cons new-x new-y)))))
370 245
371;; having constrained in the limited sense of windmove-constrain-loc-
372;; for-movement, the wrapping code is actually much simpler than it
373;; otherwise would be. the only complication is that we need to check
374;; if the minibuffer is active, and, if not, pretend that it's not
375;; even part of the frame.
376(defun windmove-wrap-loc-for-movement (coord window) 246(defun windmove-wrap-loc-for-movement (coord window)
377 "Takes the constrained COORD and wraps it around for the movement. 247 "Takes the constrained COORD and wraps it around for the movement.
378This makes an out-of-range x or y coordinate and wraps it around the 248This makes an out-of-range x or y coordinate and wraps it around the
379frame, giving a coordinate (hopefully) in the window on the other edge 249frame, giving a coordinate (hopefully) in the window on the other edge
380of the frame. WINDOW is the window that movement is relative to (nil 250of the frame. WINDOW is the window that movement is relative to (nil
381means the currently selected window). Returns the wrapped coordinate." 251means the currently selected window). Returns the wrapped coordinate."
252 (declare (obsolete "no longer used." "27.1"))
382 (let* ((frame-edges (windmove-frame-edges window)) 253 (let* ((frame-edges (windmove-frame-edges window))
383 (frame-minibuffer (minibuffer-window (if window 254 (frame-minibuffer (minibuffer-window (if window
384 (window-frame window) 255 (window-frame window)
@@ -396,10 +267,6 @@ means the currently selected window). Returns the wrapped coordinate."
396 (windmove-constrain-around-range (car coord) min-x max-x) 267 (windmove-constrain-around-range (car coord) min-x max-x)
397 (windmove-constrain-around-range (cdr coord) min-y max-y))))) 268 (windmove-constrain-around-range (cdr coord) min-y max-y)))))
398 269
399
400;; This calculates the reference location in the current window: the
401;; frame-based (x . y) of either point, the top-left, or the
402;; bottom-right of the window, depending on ARG.
403(defun windmove-reference-loc (&optional arg window) 270(defun windmove-reference-loc (&optional arg window)
404 "Return the reference location for directional window selection. 271 "Return the reference location for directional window selection.
405Return a coordinate (HPOS . VPOS) that is frame-based. If ARG is nil 272Return a coordinate (HPOS . VPOS) that is frame-based. If ARG is nil
@@ -407,6 +274,7 @@ or not supplied, the reference point is the buffer's point in the
407currently-selected window, or WINDOW if supplied; otherwise, it is the 274currently-selected window, or WINDOW if supplied; otherwise, it is the
408top-left or bottom-right corner of the selected window, or WINDOW if 275top-left or bottom-right corner of the selected window, or WINDOW if
409supplied, if ARG is greater or smaller than zero, respectively." 276supplied, if ARG is greater or smaller than zero, respectively."
277 (declare (obsolete "no longer used." "27.1"))
410 (let ((effective-arg (if (null arg) 0 (prefix-numeric-value arg))) 278 (let ((effective-arg (if (null arg) 0 (prefix-numeric-value arg)))
411 (edges (window-inside-edges window))) 279 (edges (window-inside-edges window)))
412 (let ((top-left (cons (nth 0 edges) 280 (let ((top-left (cons (nth 0 edges)
@@ -429,15 +297,13 @@ supplied, if ARG is greater or smaller than zero, respectively."
429 (posn-col-row 297 (posn-col-row
430 (posn-at-point (window-point window) window)))))))) 298 (posn-at-point (window-point window) window))))))))
431 299
432;; This uses the reference location in the current window (calculated
433;; by `windmove-reference-loc' above) to find a reference location
434;; that will hopefully be in the window we want to move to.
435(defun windmove-other-window-loc (dir &optional arg window) 300(defun windmove-other-window-loc (dir &optional arg window)
436 "Return a location in the window to be moved to. 301 "Return a location in the window to be moved to.
437Return value is a frame-based (HPOS . VPOS) value that should be moved 302Return value is a frame-based (HPOS . VPOS) value that should be moved
438to. DIR is one of `left', `up', `right', or `down'; an optional ARG 303to. DIR is one of `left', `up', `right', or `down'; an optional ARG
439is handled as by `windmove-reference-loc'; WINDOW is the window that 304is handled as by `windmove-reference-loc'; WINDOW is the window that
440movement is relative to." 305movement is relative to."
306 (declare (obsolete "no longer used." "27.1"))
441 (let ((edges (window-edges window)) ; edges: (x0, y0, x1, y1) 307 (let ((edges (window-edges window)) ; edges: (x0, y0, x1, y1)
442 (refpoint (windmove-reference-loc arg window))) ; (x . y) 308 (refpoint (windmove-reference-loc arg window))) ; (x . y)
443 (cond 309 (cond
@@ -463,15 +329,19 @@ movement is relative to."
463;; Rewritten on 2013-12-13 using `window-in-direction'. After the 329;; Rewritten on 2013-12-13 using `window-in-direction'. After the
464;; pixelwise change the old approach didn't work any more. martin 330;; pixelwise change the old approach didn't work any more. martin
465(defun windmove-find-other-window (dir &optional arg window) 331(defun windmove-find-other-window (dir &optional arg window)
466 "Return the window object in direction DIR. 332 "Return the window object in direction DIR as seen from WINDOW.
467DIR, ARG, and WINDOW are handled as by `windmove-other-window-loc'." 333DIR is one of `left', `up', `right', or `down'.
334WINDOW must be a live window and defaults to the selected one.
335Optional ARG, if negative, means to use the right or bottom edge of
336WINDOW as reference position, instead of `window-point'; if positive,
337use the left or top edge of WINDOW as reference point."
468 (window-in-direction dir window nil arg windmove-wrap-around t)) 338 (window-in-direction dir window nil arg windmove-wrap-around t))
469 339
470;; Selects the window that's hopefully at the location returned by 340;; Selects the window that's hopefully at the location returned by
471;; `windmove-other-window-loc', or screams if there's no window there. 341;; `windmove-find-other-window', or screams if there's no window there.
472(defun windmove-do-window-select (dir &optional arg window) 342(defun windmove-do-window-select (dir &optional arg window)
473 "Move to the window at direction DIR. 343 "Move to the window at direction DIR as seen from WINDOW.
474DIR, ARG, and WINDOW are handled as by `windmove-other-window-loc'. 344DIR, ARG, and WINDOW are handled as by `windmove-find-other-window'.
475If no window is at direction DIR, an error is signaled. 345If no window is at direction DIR, an error is signaled.
476If `windmove-create-window' is non-nil, try to create a new window 346If `windmove-create-window' is non-nil, try to create a new window
477in direction DIR instead." 347in direction DIR instead."