summaryrefslogtreecommitdiffstats
path: root/emacs.d/nxhtml/util/winsize.el
blob: 808daf559f54a8a02cdc9c5e6208996823ccf38f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
;;; winsize.el --- Interactive window structure editing
;;
;; Author: Lennart Borgman <lennart dot borgman at gmail dot com >
;; Maintainer:
;; Created: Wed Dec 07 15:35:09 2005
(defconst winsize:version "0.98") ;;Version: 0.97
;; Lxast-Updated: Sun Nov 18 02:14:52 2007 (3600 +0100)
;; Keywords:
;; Compatibility:
;;
;; Fxeatures that might be required by this library:
;;
;;   None
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;; Commentary:
;;
;; This file contains functions for interactive resizing of Emacs
;; windows.  To use it put it in your `load-path' and add the following
;; to your .emacs:
;;
;;     (require 'winsize)
;;     (global-set-key [(control x) ?+] 'resize-windows)
;;
;; For more information see `resize-windows'.
;;
;; These functions are a slightly rewritten version of the second part
;; of the second part my proposal for a new `balance-windows' function
;; for Emacs 22.  The rewrite is mostly a restructure to more easily
;; add new functions.  All functions and variables have been renamed.
;; The file was originally named bw-interactive.el.
;;
;; New ideas for functionality have been to a large part adopted from
;; the Emacs Devel mailing list.  Probably most of them originated from
;; Drew Adams and Bastien.
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;; Change log:
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; This program 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.
;;
;; This program 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 this program; see the file COPYING.  If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; TODO: Change mouse pointer shape during resizing.
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;; Code:

(eval-when-compile (require 'windmove))
(eval-when-compile (require 'view))
(eval-when-compile (require 'winsav nil t))
(eval-when-compile (require 'ourcomments-widgets))
(eval-when-compile (require 'ring))

;;; Custom variables

(defcustom winsize-juris-way t
  ""
  :type 'boolean
  :group 'winsize)

(defcustom winsize-autoselect-borders t
  "Determines how borders are selected by default.
If nil hever select borders automatically (but keep them on the
same side while changing window).  If 'when-single select border
automatically if there is only one possible choice.  If t alwasy
select borders automatically if they are not selected."
  :type '(choice (const :tag "Always" t)
                 (const :tag "When only one possbility" when-single)
                 (const :tag "Never" nil))
  :group 'winsize)

(defcustom winsize-mode-line-colors (list t (list "green" "green4"))
  "Mode line colors used during resizing."
  :type '(list (boolean :tag "Enable mode line color changes during resizing")
               (list
                (color :tag "- Active window mode line color")
                (color :tag "- Inactive window mode line color")))
  :group 'winsize)

(defcustom winsize-mark-selected-window t
  "Mark selected window if non-nil."
  :type 'boolean
  :group 'winsize)

(defcustom winsize-make-mouse-prominent t
  "Try to make mouse more visible during resizing.
The mouse is positioned next to the borders that you can move.
It can however be hard to see if where it is.  Setting this to on
makes the mouse jump a few times."
  :type 'boolean
  :group 'winsize)

(defvar widget-command-prompt-value-history nil
  "History of input to `widget-function-prompt-value'.")

(defvar winsize-keymap nil
  "Keymap used by `resize-windows'.")

(defun winsize-make-keymap (let-me-use)
  "Build the keymap that should be used by `winsize-keymap'."
  (let ((map (make-sparse-keymap "Window Resizing")))
    (when (featurep 'winsav)
      (define-key map [menu-bar bw rotate]
        '("Rotate window configuration" . winsav-rotate))
      (define-key map [menu-bar bw sep3] '(menu-item "--")))
    (define-key map [menu-bar bw]
      (cons "Resize" (make-sparse-keymap "second")))
    (define-key map [menu-bar bw save-config]
      '("Save window configuration" . winsize-save-window-configuration))
    (define-key map [menu-bar bw next-config]
      '("Next saved window configuration" . winsize-next-window-configuration))
    (define-key map [menu-bar bw prev-config]
      '("Previous saved window configuration" . winsize-previous-window-configuration))
    (define-key map [menu-bar bw sep2] '(menu-item "--"))
    (define-key map [menu-bar bw fit]
      '("Fit Window to Buffer" . fit-window-to-buffer))
    (define-key map [menu-bar bw shrink]
      '("Shrink Window to Buffer" . shrink-window-if-larger-than-buffer))
    (define-key map [menu-bar bw sep1] '(menu-item "--"))
    (define-key map [menu-bar bw siblings]
      '("Balance Window Siblings" . winsize-balance-siblings))
    (define-key map [menu-bar bw balance]
      '("Balance Windows" . balance-windows))

    (when (featurep 'winsav)
      (define-key map [?|] 'winsav-rotate))
    (define-key map [?+] 'balance-windows)
    (define-key map [?.] 'winsize-balance-siblings)
    (define-key map [?=] 'fit-window-to-buffer)
    (define-key map [?-] 'shrink-window-if-larger-than-buffer)

    (define-key map [(up)]    'winsize-move-border-up)
    (define-key map [(down)]  'winsize-move-border-down)
    (define-key map [(left)]  'winsize-move-border-left)
    (define-key map [(right)] 'winsize-move-border-right)

    (define-key map [(shift up)]    'winsize-move-other-border-up)
    (define-key map [(shift down)]  'winsize-move-other-border-down)
    (define-key map [(shift left)]  'winsize-move-other-border-left)
    (define-key map [(shift right)] 'winsize-move-other-border-right)

    (define-key map [(meta left)]   'winsize-to-border-or-window-left)
    (define-key map [(meta up)]     'winsize-to-border-or-window-up)
    (define-key map [(meta right)]  'winsize-to-border-or-window-right)
    (define-key map [(meta down)]   'winsize-to-border-or-window-down)

    (define-key map [?0] 'delete-window)
    (define-key map [?1] 'delete-other-windows)
    (define-key map [?2] 'split-window-vertically)
    (define-key map [?3] 'split-window-horizontally)
    (define-key map [?4] 'other-window)

    (define-key map [?!] 'winsize-save-window-configuration)
    (define-key map [?>] 'winsize-next-window-configuration)
    (define-key map [?<] 'winsize-previous-window-configuration)

    ;; Fix-me: These keys could also be set to nil
    (define-key map [mouse-1]                        'mouse-set-point)
    ;;(define-key map [down-mouse-1]                   'mouse-set-point)
    (define-key map [(mode-line) (down-mouse-1)]     'mouse-drag-mode-line)
    (define-key map [(vertical-line) (down-mouse-1)] 'mouse-drag-vertical-line)
    (define-key map [(vertical-scroll-bar) (mouse-1)] 'scroll-bar-toolkit-scroll)

    (define-key map [??] 'winsize-help)
    (define-key map [(control ?g)]     'winsize-quit)
    (define-key map [(control return)] 'winsize-stop-go-back)
    (define-key map [(return)]         'winsize-stop)
    (define-key map [t]                'winsize-stop-and-execute)

    (dolist (ks let-me-use)
      (if (and (not (vectorp ks))
               (not (stringp ks))
               (commandp ks))
          (let ((ks-list (where-is-internal ks)))
            (dolist (ks ks-list)
              (unless (lookup-key map ks)
                (define-key map ks nil))))
        (unless (lookup-key map ks)
          (define-key map ks nil))))

    (setq winsize-keymap map)))

(defcustom winsize-let-me-use '(next-line ;;[(control ?n)]
                                previous-line ;;[(control ?p)]
                                forward-char ;;[(control ?f)]
                                backward-char ;;[(control ?b)]
                                [(home)]
                                [(end)]
                                ;; Fix-me: replace this with something
                                ;; pulling in help-event-list:
                                [(f1)]
                                execute-extended-command
                                eval-expression)
  "Key sequences or commands that should not be overriden during resize.
The purpose is to make it easier to switch windows.  The functions
`windmove-left' etc depends on the position when chosing the
window to move to."
  :type '(repeat
          (choice
           ;; Note: key-sequence must be before command here, since
           ;; the key sequences seems to match command too.
           key-sequence command))
  :set (lambda (sym val)
         (set-default sym val)
         (winsize-make-keymap val))
  :group 'winsize)

(defcustom winsize-selected-window-face 'winsize-selected-window-face
  "Variable holding face for marking selected window.
This variable may be nil or a face symbol."
  :type '(choice (const :tag "Do not mark selected window" nil)
                 face)
  :group 'winsize)

(defface winsize-selected-window-face
  '((t (:inherit secondary-selection)))
  "Face for marking selected window."
  :group 'winsize)


;;; These variables all holds values to be reset when exiting resizing:

(defvar winsize-old-mode-line-bg nil)
(defvar winsize-old-mode-line-inactive-bg nil)
(defvar winsize-old-overriding-terminal-local-map nil)
(defvar winsize-old-overriding-local-map-menu-flag nil)
(defvar winsize-old-temp-buffer-show-function nil)
(defvar winsize-old-mouse-avoidance-mode nil
  "Hold the value of `mouse-avoidance-mode' at resizing start.")
(defvar winsize-old-view-exit-action nil)
(make-variable-buffer-local 'winsize-old-view-exit-action)

(defvar winsize-message-end nil
  "Marker, maybe at end of message buffer.")

(defvar winsize-resizing nil
  "t during resizing, nil otherwise.")

(defvar winsize-window-config-init nil
  "Hold window configuration from resizing start.")

(defvar winsize-frame nil
  "Frame that `resize-windows' is operating on.")


;;; Borders

(defvar winsize-window-for-side-hor nil
  "Window used internally for resizing in vertical direction.")

(defvar winsize-window-for-side-ver nil
  "Window used internally for resizing in horizontal direction.")

(defvar winsize-border-hor nil
  "Use internally to remember border choice.
This is set by `winsize-pre-command' and checked by
`winsize-post-command', see the latter for more information.

The value should be either nil, 'left or 'right.")

(defvar winsize-border-ver nil
  "Use internally to remember border choice.
This is set by `winsize-pre-command' and checked by
`winsize-post-command', see the latter for more information.

The value should be either nil, 'up or 'down.")

(defvar winsize-window-at-entry nil
  "Window that was selected when `resize-windows' started.")


;;; Keymap, interactive functions etc

(defun winsize-pre-command ()
  "Do this before every command.
Runs this in `pre-command-hook'.

Remember the currently used border sides for resizing. Also
remember position in message buffer to be able to see if next
command outputs some message.

For more information see `winsize-post-command'."
  (setq winsize-message-end (winsize-message-end))
  (setq winsize-border-hor (winsize-border-used-hor))
  (setq winsize-border-ver (winsize-border-used-ver)))

(defun winsize-post-command ()
  "Done after every command.
Run this in `post-command-hook'.

Check the border sides \(left/right, up/down) remembered in
`winsize-pre-command' and use the the same side if possible,
otherwise the opposite side if that is possible. \(This check is
of course not done if the last command changed the border side.)

The reason for selecting borders this way is to try to give the
user a coherent and easy picture of what is going on when
changing window or when window structure is changed.  \(Note that
the commands moving to another window or changing the window
structure does not have to belong to this package. Those commands
can therefore not select the border sides.)

Give the user feedback about selected window and borders.  Also
give a short help message unless last command gave some message."
  (unless winsize-juris-way
    (unless winsize-border-hor
      (winsize-select-initial-border-hor))
    (when winsize-border-hor
      (winsize-set-border winsize-border-hor t))
    (unless winsize-border-ver
     (winsize-select-initial-border-ver))
    (when winsize-border-ver
      (winsize-set-border winsize-border-ver t)))
  (winsize-tell-user))

;;;###autoload
(defun resize-windows ()
  "Start window resizing.
During resizing a window is selected.  You can move its
borders. In the default configuration the arrow keys moves the
right or bottom border if they are there. To move the opposite
border use S-arrowkeys.

You can also do other window operations, like splitting, deleting
and balancing the sizes.  The keybindings below describes the key
bindings during resizing:\\<winsize-keymap>

  `balance-windows'                      \\[balance-windows]
  `winsize-balance-siblings'             \\[winsize-balance-siblings]
  `fit-window-to-buffer'                 \\[fit-window-to-buffer]
  `shrink-window-if-larger-than-buffer'  \\[shrink-window-if-larger-than-buffer]

  `winsav-rotate'                        \\[winsav-rotate]

  `winsize-move-border-up'      \\[winsize-move-border-up]
  `winsize-move-border-down'    \\[winsize-move-border-down]
  `winsize-move-border-left'    \\[winsize-move-border-left]
  `winsize-move-border-right'   \\[winsize-move-border-right]

  `winsize-to-border-or-window-left'    \\[winsize-to-border-or-window-left]
  `winsize-to-border-or-window-up'      \\[winsize-to-border-or-window-up]
  `winsize-to-border-or-window-right'   \\[winsize-to-border-or-window-right]
  `winsize-to-border-or-window-down'    \\[winsize-to-border-or-window-down]

   Note that you can also use your normal keys for
   `forward-char', `backward-char', `next-line', `previous-line'
   and what you have on HOME and END to move in the windows. That
   might sometimes be necessary to directly select a
   window. \(You may however also use `other-window' or click
   with the mouse, see below.)

  `delete-window'                \\[delete-window]
  `delete-other-windows'         \\[delete-other-windows]
  `split-window-vertically'      \\[split-window-vertically]
  `split-window-horizontally'    \\[split-window-horizontally]
  `other-window'                 \\[other-window]

  `winsize-save-window-configuration'       \\[winsize-save-window-configuration]
  `winsize-next-window-configuration'       \\[winsize-next-window-configuration]
  `winsize-previous-window-configuration'   \\[winsize-previous-window-configuration]

  `mouse-set-point'   \\[mouse-set-point]

  `winsize-quit'               \\[winsize-quit]
  `winsize-stop-go-back'       \\[winsize-stop-go-back]
  `winsize-stop'               \\[winsize-stop]
  `winsize-stop-and-execute'   \\[winsize-stop-and-execute]

  `winsize-help'          \\[winsize-help]
  `describe-key'          \\[describe-key]
  `describe-key-briefly'  \\[describe-key-briefly]
  (All the normal help keys work, and at least those above will
  play well with resizing.)

Nearly all other keys exits window resizing and they are also
executed.  However, the key sequences in `winsize-let-me-use' and
dito for commands there are also executed without exiting
resizing.

The colors of the modelines are changed to those given in
`winsize-mode-line-colors' to indicate that you are resizing
windows.  To make this indication more prominent the text in the
selected window is marked with the face hold in the variable
`winsize-selected-window-face'.

The option `winsize-juris-way' decides how the borders to move
are selected. If this option is non-nil then the right or bottom
border are the ones that are moved with the arrow keys and the
opposite border with shift arrow keys.

If `winsize-juris-way' is nil then the following apply:

As you select other borders or move to new a window the mouse
pointer is moved inside the selected window to show which borders
are beeing moved. The mouse jumps a little bit to make its
position more visible. You can turn this off by customizing
`winsize-make-mouse-prominent'.

Which borders initially are choosen are controlled by the
variable `winsize-autoselect-borders'.

** Example: Border selection, movements and windows.

  Suppose you have a frame divided into windows like in the
  figure below.  If window B is selected when you start resizing
  then \(with default settings) the borders marked with 'v' and
  'h' will be the ones that the arrow keys moves. To indicate
  this the mouse pointer is placed in the right lower corner of
  the selected window B.

    +----------+-----------+--------+
    |          |           v        |
    |          |           v        |
    |    A     |    _B_    v        |
    |          |           v        |
    |          |           v        |
    |          |         x v        |
    +hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh+
    |                    |          |
    |                    |          |
    |                    |          |
    |                    |          |
    |                    |          |
    |                    |          |
    +----------+---------+----------+

  Now if you press M-<left> then the picture below shows what has
  happened. Note that the selected vertical border is now the one
  between A and B. The mouse pointer has moved to the
  corresponding corner in the window B, which is still selected.

    +----------+-----------+--------+
    |          v           |        |
    |          v           |        |
    |    A     v    _B_    |        |
    |          v           |        |
    |          v           |        |
    |          v x         |        |
    +hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh+
    |                    |          |
    |                    |          |
    |                    |          |
    |                    |          |
    |                    |          |
    |                    |          |
    +----------+---------+----------+

  Press M-<left> once again. This gives this picture:

    +----------+-----------+--------+
    |          v           |        |
    |          v           |        |
    |   _A_    v     B     |        |
    |          v           |        |
    |          v           |        |
    |        x v           |        |
    +hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh+
    |                    |          |
    |                    |          |
    |                    |          |
    |                    |          |
    |                    |          |
    |                    |          |
    +----------+---------+----------+

  Note that the window A is now selected. However there is no
  border that could be moved to the left of this window \(which
  would otherwise be chosen now) so the border between A and B is
  still the one that <left> and <right> moves. The mouse has
  moved to A.

  If we now delete window A the new situation will look like
  this:

    +----------+-----------+--------+
    |                      |        |
    |                      |        |
    |         _B_          |        |
    |                      |        |
    |                      |        |
    |                    x |        |
    +hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh+
    |                    |          |
    |                    |          |
    |                    |          |
    |                    |          |
    |                    |          |
    |                    |          |
    +----------+---------+----------+



>>>> testing stuff >>>>
`help-mode-hook'
`temp-buffer-show-function'
`view-exit-action'
<<<<<<<<<<<<<<<<<<<<<<<
"
  (interactive)
  (setq winsize-resizing t)
  ;; Save old values:
  (unless winsize-old-mouse-avoidance-mode
    (setq winsize-old-mouse-avoidance-mode mouse-avoidance-mode))
  ;; Setup user feedback things:
  (mouse-avoidance-mode 'none)
  (winsize-set-mode-line-colors t)
  (winsize-create-short-help-message)
  (setq winsize-message-end (winsize-message-end))
  ;; Save config for exiting:
  (setq winsize-window-config-init (current-window-configuration))
  (setq winsize-window-at-entry (selected-window))
  (setq winsize-frame (selected-frame))
  ;; Setup keymap and command hooks etc:
  (winsize-setup-local-map)
  (winsize-add-command-hooks)
  (setq winsize-window-for-side-hor nil)
  (setq winsize-window-for-side-ver nil))


(defun winsize-setup-local-map ()
  "Setup an overriding keymap and use this during resizing.
Save current keymaps."
  ;; Fix-me: use copy-keymap for old?
  (unless winsize-old-overriding-terminal-local-map
    (setq winsize-old-overriding-terminal-local-map overriding-terminal-local-map))
  (setq overriding-terminal-local-map (copy-keymap winsize-keymap))
  (setq winsize-old-overriding-local-map-menu-flag overriding-local-map-menu-flag)
  (setq overriding-local-map-menu-flag t))

(defun winsize-restore-local-map ()
  "Restore keymaps saved by `winsize-setup-local-map'."
  (setq overriding-terminal-local-map winsize-old-overriding-terminal-local-map)
  (setq winsize-old-overriding-terminal-local-map nil)
  (setq overriding-local-map-menu-flag winsize-old-overriding-local-map-menu-flag)
  (setq winsize-old-overriding-local-map-menu-flag nil))


(defvar winsize-window-config-help nil
  "Hold window configuration when help is shown.")

(defvar winsize-window-config-init-help nil
  "Hold window configuration from resizing start during help.")

(defvar winsize-help-frame nil
  "The frame from which help was called.")

(defun winsize-restore-after-help (buffer)
  "Restore window configuration after help.
Raise frame and reactivate resizing."
  (remove-hook 'temp-buffer-setup-hook 'winsize-help-mode-hook-function)
  (setq temp-buffer-show-function winsize-old-temp-buffer-show-function)
  ;; Get rid of the view exit action and the extra text in the help
  ;; buffer:
  (with-current-buffer (help-buffer)
    (setq view-exit-action winsize-old-view-exit-action)
    (setq winsize-old-view-exit-action nil)
    (let ((here (point-marker))
          (inhibit-read-only t))
      (goto-char (point-min))
      (forward-line 2)
      (delete-region (point-min) (point))
      (goto-char (point-max))
      (forward-line -2)
      (delete-region (point) (point-max))
      (goto-char here)))
  ;; Restart resizing, restoring window configurations:
  (when (select-frame winsize-help-frame)
    (raise-frame)
    (set-window-configuration winsize-window-config-help)
    (resize-windows)
    (setq winsize-window-config-init winsize-window-config-init-help)))

(defun winsize-help-mode-hook-function ()
  "Setup temp buffer show function to only run second step.
The first step, `winsize-temp-buffer-show-function', has already been run."
  (setq temp-buffer-show-function 'winsize-temp-buffer-show-function-1))

(defun winsize-temp-buffer-show-function (buffer)
  "First step of setup for showing help during resizing.
This step is run when showing help during resizing.

Save window configuration etc to be able to resume resizing. Stop
resizing. Delete other windows.

Run second step (`winsize-temp-buffer-show-function-1') and
arrange so that second step is run when following help links."
  (setq winsize-window-config-help (current-window-configuration))
  (setq winsize-window-config-init-help winsize-window-config-init)
  (setq winsize-help-frame (selected-frame))
  (winsize-stop)
  (delete-other-windows)
  (winsize-temp-buffer-show-function-1 buffer)
  (add-hook 'temp-buffer-setup-hook 'winsize-help-mode-hook-function))

(defun winsize-temp-buffer-show-function-1 (buffer)
  "Second step of setup for showing help during resizing.
This is run after the first step when accessing help during
resizing. It is also when following help links."
  (with-current-buffer buffer
    (let ((inhibit-read-only t)
          (buffer-read-only t) ;; It is reverted in `help-mode-finish'
          )
      (run-hooks 'temp-buffer-show-hook))
    (let ((here (point-marker))
          (str "*** Type q to return to window resizing ***"))
      (put-text-property 0 (length str) 'face 'highlight str)
      (goto-char (point-min))
      (insert str "\n\n")
      (goto-char (point-max))
      (insert "\n\n" str)
      (goto-char here)
      (setq buffer-read-only t))
    (unless winsize-old-view-exit-action
      (setq winsize-old-view-exit-action view-exit-action)
      (setq view-exit-action 'winsize-restore-after-help)))
  (set-window-buffer (selected-window) buffer)
  (message "Type q to return to window resizing"))

(defun winsize-help ()
  "Give help during resizing.
Save current window configuration and pause resizing."
  (interactive)
  (if pop-up-frames
      (progn
        (winsize-exit-resizing nil)
        (describe-function 'resize-windows))
    ;; Fix-me: move setup of view-exit-action etc here. Or was it
    ;; temp-buffer-show-function?
    ;; Setup help hooks etc:
    (unless (or winsize-old-temp-buffer-show-function
                ;; These things should not happen... :
                (eq temp-buffer-show-function 'winsize-temp-buffer-show-function)
                (eq temp-buffer-show-function 'winsize-temp-buffer-show-function-1))
      (setq winsize-old-temp-buffer-show-function temp-buffer-show-function))
    (setq temp-buffer-show-function 'winsize-temp-buffer-show-function)
    (with-output-to-temp-buffer (help-buffer)
      (with-current-buffer (help-buffer)
        (insert "resize-windows is ")
        (describe-function-1 'resize-windows)))))

(defun winsize-quit ()
  "Quit resing, restore window configuration at start."
  (interactive)
  (set-window-configuration winsize-window-config-init)
  (winsize-exit-resizing nil))

(defun winsize-stop-go-back ()
  "Exit window resizing.  Go back to the window started in."
  (interactive)
  (winsize-exit-resizing nil t))

(defun winsize-stop-and-execute ()
  "Exit window resizing and put last key on the input queue.
Select the window marked during resizing before putting back the
last key."
  ;; Fix-me: maybe replace this with a check of this-command in
  ;; post-command-hook instead?
  (interactive)
  (winsize-exit-resizing t))

(defun winsize-stop ()
  "Exit window resizing.
Select the window marked during resizing."
  (interactive)
  (winsize-exit-resizing nil))

;;;###autoload
(defun winsize-balance-siblings ()
  "Make current window siblings the same height or width.
It works the same way as `balance-windows', but only for the
current window and its siblings."
  (interactive)
  (balance-windows (selected-window)))

(defun winsize-to-border-or-window-left ()
  "Switch to border leftwards, maybe moving to next window.
If already at the left border, then move to left window, the same
way `windmove-left' does."
  (interactive) (winsize-switch-border 'left t))

(defun winsize-to-border-or-window-right ()
  "Switch to border rightwards, maybe moving to next window.
For more information see `winsize-to-border-or-window-left'."
  (interactive) (winsize-switch-border 'right t))

(defun winsize-to-border-or-window-up ()
  "Switch to border upwards, maybe moving to next window.
For more information see `winsize-to-border-or-window-left'."
  (interactive) (winsize-switch-border 'up t))

(defun winsize-to-border-or-window-down ()
  "Switch to border downwards, maybe moving to next window.
For more information see `winsize-to-border-or-window-left'."
  (interactive) (winsize-switch-border 'down t))


(defun winsize-move-border-left ()
  "Move border left, but select border first if not done."
  (interactive) (winsize-resize 'left nil))

(defun winsize-move-border-right ()
  "Move border right, but select border first if not done."
  (interactive) (winsize-resize 'right nil))

(defun winsize-move-border-up ()
  "Move border up, but select border first if not done."
  (interactive) (winsize-resize 'up nil))

(defun winsize-move-border-down ()
  "Move border down, but select border first if not done."
  (interactive) (winsize-resize 'down nil))


(defun winsize-move-other-border-left ()
  "Move border left, but select border first if not done."
  (interactive) (winsize-resize 'left t))

(defun winsize-move-other-border-right ()
  "Move border right, but select border first if not done."
  (interactive) (winsize-resize 'right t))

(defun winsize-move-other-border-up ()
  "Move border up, but select border first if not done."
  (interactive) (winsize-resize 'up t))

(defun winsize-move-other-border-down ()
  "Move border down, but select border first if not done."
  (interactive) (winsize-resize 'down t))


;;; Internals



(defun winsize-exit-resizing (put-back-last-event &optional stay)
  "Stop window resizing.
Put back mode line colors and keymaps that were changed.

Upon exit first select window.  If STAY is non-nil then select
the window which was selected when `resize-windows' was called,
otherwise select the last window used during resizing.  After
that, if PUT-BACK-LAST-EVENT is non-nil, put back the last input
event on the input queue."
  (setq winsize-resizing nil)
  ;; Reset user feedback things:
  (mouse-avoidance-mode winsize-old-mouse-avoidance-mode)
  (setq winsize-old-mouse-avoidance-mode nil)
  (winsize-set-mode-line-colors nil)
  (winsize-mark-selected-window nil)
  ;; Remove all hooks etc for help:
  (if (or (eq winsize-old-temp-buffer-show-function 'winsize-temp-buffer-show-function)
          (eq winsize-old-temp-buffer-show-function 'winsize-temp-buffer-show-function-1))
      (setq temp-buffer-show-function nil)
    (setq temp-buffer-show-function winsize-old-temp-buffer-show-function))
  (setq winsize-old-temp-buffer-show-function nil)
  (remove-hook 'help-mode-hook 'winsize-help-mode-hook-function)
  (remove-hook 'temp-buffer-setup-hook 'winsize-help-mode-hook-function)
  ;; Restore keymap and command hooks:
  (winsize-restore-local-map)
  (winsize-remove-command-hooks)
  ;; Exit:
  (when stay (select-window winsize-window-at-entry))
  (message "Exited window resizing")
  (when (and put-back-last-event)
    ;; Add this to the input queue again:
    (isearch-unread last-command-event)))

(defun winsize-add-command-hooks ()
  (add-hook 'pre-command-hook 'winsize-pre-command)
  (add-hook 'post-command-hook 'winsize-post-command))

(defun winsize-remove-command-hooks ()
  (remove-hook 'pre-command-hook 'winsize-pre-command)
  (remove-hook 'post-command-hook 'winsize-post-command))


;;; Borders

(defun winsize-border-used-hor ()
  "Return the border side used for horizontal resizing."
  (let ((hor (when winsize-window-for-side-hor
               (if (eq (selected-window) winsize-window-for-side-hor)
                   'right
                 'left))))
    hor))

(defun winsize-border-used-ver ()
  "Return the border side used for vertical resizing."
  (let ((ver (when winsize-window-for-side-ver
               (if (eq (selected-window) winsize-window-for-side-ver)
                   'down
                 'up))))
    ver))

(defun winsize-switch-border (dir allow-windmove)
  "Switch border that is beeing resized.
Switch to border in direction DIR.  If ALLOW-WINDMOVE is non-nil
then change window if necessary, otherwise stay and do not change
border."
  (let* ((window-in-that-dir (windmove-find-other-window
                              dir nil (selected-window))))
    (when (window-minibuffer-p window-in-that-dir)
      (setq window-in-that-dir nil))
    (if winsize-juris-way
        (if (not window-in-that-dir)
            (message "No window in that direction")
          (windmove-do-window-select dir nil))
      (if (not window-in-that-dir)
          (message "No window or border in that direction")
        (let* ((is-hor (memq dir '(left right)))
               (border-used (if is-hor
                                (winsize-border-used-hor)
                              (winsize-border-used-ver)))
               (using-dir-border (eq dir border-used)))
          (if using-dir-border
              (when allow-windmove
                (setq winsize-window-for-side-hor nil)
                (setq winsize-window-for-side-ver nil)
                (windmove-do-window-select dir nil)
                (message "Moved to new window"))
            (winsize-select-border dir)
            (message "Switched to border %swards" dir)))))))


(defun winsize-select-initial-border-hor ()
  "Select a default border horizontally."
  (if winsize-juris-way
      (winsize-set-border 'right t)
    (let ((has-left  (winsize-window-beside (selected-window) 'left))
          (has-right (winsize-window-beside (selected-window) 'right)))
      (cond
       ((not winsize-autoselect-borders) t)
       ((eq winsize-autoselect-borders 'when-single)
        (when (= 1 (length (delq nil (list has-left has-right))))
          (winsize-select-border 'right)))
       (t
        (winsize-select-border 'right))))))

(defun winsize-select-initial-border-ver ()
  "Select a default border vertically."
  (if winsize-juris-way
      (winsize-set-border 'up t)
    (let ((has-up  (winsize-window-beside (selected-window) 'up))
          (has-down (winsize-window-beside (selected-window) 'down)))
      (cond
       ((not winsize-autoselect-borders) t)
       ((eq winsize-autoselect-borders 'when-single)
        (when (= 1 (length (delq nil (list has-up has-down))))
          (winsize-select-border 'up)))
       (t
        (winsize-select-border 'up))))))

(defun winsize-select-border (dir)
  "Select border to be set for resizing.
The actually setting is done in `post-command-hook'."
  (cond
   ((memq dir '(left right))
    (setq winsize-border-hor dir))
   ((memq dir '(up down))
    (setq winsize-border-ver dir))
   (t (error "Bad DIR=%s" dir))))

(defun winsize-set-border (dir allow-other-side)
  "Set border for resizing."
  (let ((window-beside (winsize-window-beside (selected-window) dir))
        (horizontal (memq dir '(left right))))
    (unless window-beside
      (when allow-other-side
        (setq dir (winsize-other-side dir))
        (setq window-beside
              (winsize-window-beside (selected-window) dir))))
    (if horizontal
        (progn
          (setq winsize-border-hor nil)
          (setq winsize-window-for-side-hor nil))
      (setq winsize-border-ver nil)
      (setq winsize-window-for-side-ver nil))
    (when window-beside
      (let ((window-for-side (if (memq dir '(right down))
                                 (selected-window)
                               window-beside)))
        (if horizontal
            (setq winsize-window-for-side-hor window-for-side)
          (setq winsize-window-for-side-ver window-for-side))))))

(defun winsize-resize (dir other-side)
  "Choose border to move.  Or if border is chosen move that border.
Used by `winsize-move-border-left' etc."
  (when winsize-juris-way
    (let ((bside (if (memq dir '(left right))
                     (if other-side 'left 'right)
                   (if other-side 'up 'down))))
      (winsize-set-border bside t)))
  (let* ((horizontal (memq dir '(left right)))
         (arg (if (memq dir '(left up)) -1 1))
         (window-for-side (if horizontal 'winsize-window-for-side-hor 'winsize-window-for-side-ver))
         (window-for-side-val (symbol-value window-for-side)))
    (if (not window-for-side-val)
        (winsize-select-border dir)
      (when (and winsize-resizing
                 (not (eq window-for-side-val 'checked)))
        (condition-case err
            (adjust-window-trailing-edge (symbol-value window-for-side) arg horizontal)
          (error (message "%s" (error-message-string err))))))))

(defun winsize-other-side (side)
  "Return other side for 'left etc, ie 'left => 'right."
  (cond
    ((eq side 'left) 'right)
    ((eq side 'right) 'left)
    ((eq side 'up) 'down)
    ((eq side 'down) 'up)
    (t (error "Invalid SIDE=%s" side))))

(defun winsize-window-beside (window side)
  "Return a window directly beside WINDOW at side SIDE.
That means one whose edge on SIDE is touching WINDOW.  SIDE
should be one of 'left, 'up, 'right and 'down."
  (require 'windmove)
  (let* ((windmove-wrap-around nil)
         (win (windmove-find-other-window side nil window)))
    (unless (window-minibuffer-p win)
      win)))


;;; Window configs

(defconst winsize-window-configuration-ring (make-ring 20)
  "Hold window configurations.")

(defun winsize-ring-rotate (ring forward)
  (when (< 1 (ring-length ring))
    (if forward
        (ring-insert ring (ring-remove ring nil))
      (ring-insert-at-beginning ring (ring-remove ring 0)))))

(defun winsize-ring-index (ring elem)
  (let ((memb (member elem (ring-elements ring))))
    (when memb
      (- (ring-length ring)
         (length memb)))))

(defun winsize-previous-window-configuration ()
  (interactive)
  (winsize-goto-window-configuration nil))

(defun winsize-next-window-configuration ()
  (interactive)
  (winsize-goto-window-configuration t))

(defun winsize-goto-window-configuration (forward)
  (let* ((curr-conf (current-window-configuration))
         (ring winsize-window-configuration-ring)
         (idx (winsize-ring-index ring curr-conf)))
    (if idx
        (progn
          (setq idx (if forward (1- idx) (1+ idx)))
          (set-window-configuration (ring-ref ring idx)))
      ;; Unfortunately idx often seems to be nil so we will have to
      ;; rotate the ring (or something similar).
      (winsize-ring-rotate ring forward)
      (set-window-configuration (ring-ref ring 0)))))

;;;###autoload
(defun winsize-save-window-configuration ()
  (interactive)
  (let* ((curr-conf (current-window-configuration))
         (ring winsize-window-configuration-ring))
    (if (winsize-ring-index ring curr-conf)
        (error "Current configuration was already stored")
      (ring-insert ring curr-conf)
      (message "Saved window config, use '<' or '>' to get it back"))))


;;; User feedback

;;;###autoload
(defun winsize-set-mode-line-colors (on)
  "Turn mode line colors on if ON is non-nil, otherwise off."
  (if on
      (progn
        (unless winsize-old-mode-line-inactive-bg
          (setq winsize-old-mode-line-inactive-bg (face-attribute 'mode-line-inactive :background)))
        (unless winsize-old-mode-line-bg
          (setq winsize-old-mode-line-bg (face-attribute 'mode-line :background)))
        (let* ((use-colors (car winsize-mode-line-colors))
               (colors (cadr winsize-mode-line-colors))
               (active-color (elt colors 0))
               (inactive-color (elt colors 1)))
          (when use-colors
            (set-face-attribute 'mode-line-inactive nil :background inactive-color)
            (set-face-attribute 'mode-line nil :background active-color))))
    (when winsize-old-mode-line-inactive-bg
      (set-face-attribute 'mode-line-inactive nil :background winsize-old-mode-line-inactive-bg))
    (setq winsize-old-mode-line-inactive-bg nil)
    (when winsize-old-mode-line-bg
      (set-face-attribute 'mode-line nil :background winsize-old-mode-line-bg))
    (setq winsize-old-mode-line-bg nil)))

(defvar winsize-short-help-message nil
  "Short help message shown in echo area.")

(defun winsize-create-short-help-message ()
  "Create short help message to show in echo area."
  (let ((msg ""))
    (mapc (lambda (rec)
            (let ((fun (elt rec 0))
                  (desc (elt rec 1))
                  (etc (elt rec 2)))
              (when (< 0 (length msg))
                (setq msg (concat msg ", ")))
              (setq msg (concat msg
                                desc
                                ":"
                                (key-description
                                 (where-is-internal fun winsize-keymap t))
                                (if etc " etc" "")))))
          '(
            (balance-windows "balance" nil)
            (winsize-move-border-left "resize" t)
            (winsize-to-border-or-window-left "border" nil)
            ))
    (setq msg (concat msg ", exit:RET, help:?"))
    (setq winsize-short-help-message msg)))

(defun winsize-move-mouse-to-resized ()
  "Move mouse to show which border(s) are beeing moved."
  (let* ((edges (window-edges (selected-window)))
         (L (nth 0 edges))
         (T (nth 1 edges))
         (R (nth 2 edges))
         (B (nth 3 edges))
         (x (/ (+ L R) 2))
         (y (/ (+ T B) 2)))
    (when (and winsize-window-for-side-hor
               (not (eq winsize-window-for-side-hor 'checked)))
      (setq x (if (eq (selected-window) winsize-window-for-side-hor) (- R 6) (+ L 2))))
    (when (and winsize-window-for-side-ver
               (not (eq winsize-window-for-side-ver 'checked)))
      (setq y (if (eq (selected-window) winsize-window-for-side-ver) (- B 2) (+ T 0))))
    (set-mouse-position (selected-frame) x y)))

(defvar winsize-selected-window-overlay nil)

(defun winsize-mark-selected-window (active)
  (when winsize-selected-window-overlay
    (delete-overlay winsize-selected-window-overlay)
    (setq winsize-selected-window-overlay nil))
  (when active
    (with-current-buffer (window-buffer (selected-window))
      (let ((ovl (make-overlay (point-min) (point-max) nil t)))
        (setq winsize-selected-window-overlay ovl)
        (overlay-put ovl 'window (selected-window))
        (overlay-put ovl 'pointer 'arrow)
        (overlay-put ovl 'priority 1000)
        (when winsize-selected-window-face
          (overlay-put ovl 'face winsize-selected-window-face))))))

(defun winsize-message-end ()
  "Return a marker at the end of the message buffer."
  (with-current-buffer (get-buffer-create "*Messages*")
    (point-max-marker)))

(defvar winsize-move-mouse 1)

(defvar winsize-make-mouse-prominent-timer nil)

(defun winsize-move-mouse ()
  ;;(setq winsize-move-mouse (- winsize-move-mouse))
  (save-match-data ;; runs in timer
    (let* ((fxy (mouse-pixel-position))
           (f (car fxy))
           (x (cadr fxy))
           (y (cddr fxy))
           (m (mod winsize-move-mouse 2))
           (d (* (if (= 0 m) 1 -1) 1)))
      (set-mouse-pixel-position f (+ d x) (+ d y))
      (when (< 1 winsize-move-mouse)
        (setq winsize-move-mouse (1- winsize-move-mouse))
        (setq winsize-make-mouse-prominent-timer
              (run-with-timer 0.2 nil 'winsize-move-mouse))))))

(defun winsize-make-mouse-prominent-f (doit)
  (when (and winsize-make-mouse-prominent-timer
             (timerp winsize-make-mouse-prominent-timer))
    (cancel-timer winsize-make-mouse-prominent-timer))
  (when doit
    (setq winsize-move-mouse 3)
    (setq winsize-make-mouse-prominent-timer
          (run-with-idle-timer 0.1 nil 'winsize-move-mouse))))

(defun winsize-tell-user ()
  "Give the user feedback."
  (when winsize-mark-selected-window
    (winsize-mark-selected-window t))
  (unless winsize-juris-way
    (let ((move-mouse (not (member this-command
                                   '(mouse-drag-mode-line
                                     mouse-drag-vertical-line
                                     scroll-bar-toolkit-scroll)))))
      ;;(message "%s, move-mouse=%s" this-command move-mouse);(sit-for 2)
      (when move-mouse
        (winsize-move-mouse-to-resized))
      (when winsize-make-mouse-prominent
        (winsize-make-mouse-prominent-f move-mouse))))
  (when (= winsize-message-end (winsize-message-end))
    (message "%s" winsize-short-help-message)))


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Window rotating and mirroring

;;;###autoload
(defun winsav-rotate (mirror transpose)
  "Rotate window configuration on selected frame.
MIRROR should be either 'mirror-left-right, 'mirror-top-bottom or
nil.  In the first case the window configuration is mirrored
vertically and in the second case horizontally.  If MIRROR is nil
the configuration is not mirrored.

If TRANSPOSE is non-nil then the window structure is transposed
along the diagonal from top left to bottom right (in analogy with
matrix transosition).

If called interactively MIRROR will is 'mirror-left-right by
default, but 'mirror-top-bottom if called with prefix.  TRANSPOSE
is t. This mean that the window configuration will be turned one
quarter clockwise (or counter clockwise with prefix)."
  (interactive (list
                (if current-prefix-arg
                    'mirror-left-right
                  'mirror-top-bottom)
                t))
  (require 'winsav)
  (let* ((wintree (winsav-get-window-tree))
         (tree (cadr wintree))
         (win-config (current-window-configuration)))
    ;;(winsav-log "old-wintree" wintree)
    (winsav-transform-1 tree mirror transpose)
    ;;(winsav-log "new-wintree" wintree)
    ;;
    ;; Fix-me: Stay in corresponding window. How?
    (delete-other-windows)
    (condition-case err
        (winsav-put-window-tree wintree (selected-window))
      (error
       (set-window-configuration win-config)
       (message "Can't rotate: %s" (error-message-string err))))
    ))


(provide 'winsize)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; winsize.el ends here