Project

General

Profile

Feature #464

Emacs UI: split horizontally instead of vertically?

Added by John Abbott about 10 years ago. Updated over 9 years ago.

Status:
Closed
Priority:
Normal
Category:
EmacsUI
Target version:
Start date:
11 Mar 2014
Due date:
% Done:

100%

Estimated time:
10.00 h
Spent time:

Description

The students in Alg Comp would like to be able to have CoCoA source file on the left, and the running interpreter on the right, rather than having one above the other.

This makes sense as screens are now usually much wider than they are high and long lines (in CoCoA source files) are relatively uncommon.

What to do?
(A) we could add a new function which makes a horizontal split
(B) we could modify the existing functions so that they split horizontally


Related issues

Related to CoCoA-5 - Bug #397: EMACS UI: fix windows splittingClosed2013-08-02

History

#1 Updated by John Abbott about 10 years ago

  • Status changed from New to In Progress
  • % Done changed from 0 to 10

Here is a function which works a bit like M-x cocoa5 but makes a horizontal split:

(defun cocoa5-side-by-side ()
  "Place cocoa5 source and shell buffers side by side" 
  (interactive)
  (cocoa5-shell-check-process)
  (cocoa5-shell-check-window)
  (delete-other-windows)
  (split-window-horizontally)
  (switch-to-buffer-other-window "*cocoa5*")
  (other-window 1)
  )

I'm quite sure this can be cleaned up considerably; I just wanted a "proof of concept".

At the moment it is bound to a key sequence (active in a cocoa5 buffer). What key sequence would be best? I had wanted to bind C-c C-| but emacs complained that pipe was not allowed.

#2 Updated by John Abbott about 10 years ago

Here are some other design ideas
  1. make the current functions choose automatically between vert/horiz split (e.g. based on window width)
  2. let the user set/toggle a global variable which says whether to split vert/horiz

I wonder what the KISS design would be...?

JAA comments:
  • would the global variable be remembered between Emacs sessions? If so, how?
  • on the whole I'm sceptical about "automatics" (unless there's an easy override).

#3 Updated by John Abbott about 10 years ago

Here are some emacs fns which might be useful:
window-body-width width of the text area
window-body-height height of the text area

#4 Updated by John Abbott about 10 years ago

I found the following nice Emacs function


(defun rotate-split ()
  (interactive)
  (let ((root (car (window-tree))))
    (if (listp root)
        (let* ((w1 (nth 2 root))
               (w2 (nth 3 root))
               (b1 (window-buffer w1))
               (b2 (window-buffer w2)))
          (cond ((car root)             ; currently vertically split
                 (delete-window w2)
                 (set-window-buffer (split-window-horizontally) b2))
                (t                      ; currently horizontally split
                 (delete-window w1)
                 (set-window-buffer (split-window-vertically) b1))))
      (message "Root window not split")))) 

The URL was http://emacs.1067599.n5.nabble.com/rotate-split-windows-td64770.html

It passed some simple tests in Emacs 23.1; some people reported problems with Emacs 21.3

#5 Updated by Anna Maria Bigatti about 10 years ago

I think the default should be horizontal.
I can make the hor/ver toggle available in the menu.
It can be set for all session using the "CoCoA - Preferences" menu.

Note by JAA it should be easy to modify cocoa5 so that it splits horizontally if given an argument (e.g. C-u M-x cocoa5)

#6 Updated by John Abbott about 10 years ago

I think using the rotate-split function is probably the best solution; it is quite general and might even be useful outside the CoCoA context :-)

I want to check to make sure it doesn't do anything strange if there are more than 2 windows in the frame, and also if the frame is a funny shape (e.g. tall & thin, or short & wide).

Not yet sure what key binding to use (we can define a cocoa5 specific key binding).

#7 Updated by John Abbott about 10 years ago

If we have a global variable, we could make it 3-state: horizontal-split, vertical-split or auto.

If we do this, we must decide what auto means (e.g. if the window is wider than 119 then do vertical-split otherwise horizontal-split). Indeed auto could be indicated by an integer value (to be used instead of the rather arbitrary 119)

What do you think?
[perhaps my idea is not very KISS]

#8 Updated by Anna Maria Bigatti about 10 years ago

  • Target version set to CoCoA-5.1.0 Easter14

#9 Updated by John Abbott about 10 years ago

  • % Done changed from 10 to 30
  • Estimated time set to 10.00 h

#10 Updated by John Abbott about 10 years ago

  • Target version changed from CoCoA-5.1.0 Easter14 to CoCoA-5.1.1 Seoul14

#11 Updated by Anna Maria Bigatti almost 10 years ago

Apparently (on Aquamacs) it splits horizontally or vertically depending on the width of the window. That may be confusing when changing the size of the window after the first split (causes an extra split).
Maybe we should have a user flag in the CoCoA-Menu saying "horizontal/vertical split" to be used independently on the window shape. Default should be "horizontal".

#12 Updated by John Abbott almost 10 years ago

OK for a menu flag which indicates the preferred way of splitting.

Some while ago I added to cocoa5.el the fn cocoa5-rotate-split; it is not perfect (sometimes it leaves the cursor in the wrong place). Someone(Anna?) has added it to cocoa5-mode-map.

#13 Updated by Anna Maria Bigatti almost 10 years ago

  • Status changed from In Progress to Resolved
  • Assignee set to Anna Maria Bigatti
  • % Done changed from 30 to 80

I think I fixed the "random" behaviour for the window splitting.
I added the choice in the CoCoA-5 menu and the flag in the customizable user "Preferences"

#14 Updated by Anna Maria Bigatti almost 10 years ago

I slightly improved the menu so that it indicates which splitting is defined.
(with a tick next to side-by-side or to top-bottom)
I think it is quite nice :-)
just cvs-ed

#15 Updated by Anna Maria Bigatti almost 10 years ago

  • Status changed from Resolved to Feedback
  • % Done changed from 80 to 90

#16 Updated by John Abbott over 9 years ago

  • Status changed from Feedback to Closed
  • % Done changed from 90 to 100

Also available in: Atom PDF