From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Bastien Newsgroups: gmane.emacs.devel Subject: Re: New keybinding suggestion: C-x _ for `shrink-window' Date: Thu, 08 Nov 2007 15:32:12 +0000 Message-ID: <87bqa4bvnn.fsf@bzg.ath.cx> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1194532374 3709 80.91.229.12 (8 Nov 2007 14:32:54 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 8 Nov 2007 14:32:54 +0000 (UTC) Cc: Drew Adams To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Nov 08 15:32:57 2007 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1Iq8Qt-0000Ah-7p for ged-emacs-devel@m.gmane.org; Thu, 08 Nov 2007 15:32:35 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Iq8Qh-0002We-R4 for ged-emacs-devel@m.gmane.org; Thu, 08 Nov 2007 09:32:23 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Iq8Qe-0002WO-Nb for emacs-devel@gnu.org; Thu, 08 Nov 2007 09:32:20 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Iq8Qd-0002W3-9l for emacs-devel@gnu.org; Thu, 08 Nov 2007 09:32:19 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Iq8Qd-0002W0-4c for emacs-devel@gnu.org; Thu, 08 Nov 2007 09:32:19 -0500 Original-Received: from ug-out-1314.google.com ([66.249.92.174]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Iq8Qc-000248-Bi for emacs-devel@gnu.org; Thu, 08 Nov 2007 09:32:18 -0500 Original-Received: by ug-out-1314.google.com with SMTP id a2so369911ugf for ; Thu, 08 Nov 2007 06:32:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=beta; h=domainkey-signature:received:received:received:from:to:cc:subject:in-reply-to:references:user-agent:date:message-id:mime-version:content-type:sender; bh=+FD/TZ3TLxij4gps+XT3RDJWRDm/XsBDLJfntmhvJpg=; b=ie7TucRN+ft9W78L1zxwSQXF2rrl5FhuKFTEPtnsPqsEiUjnBv1hlICbY1xy6b53jE9lnFT6ZX+yx6S5lDayLFLj6IM3ifFEaI05feOPt6rNM5FziO3+sKTstO3b6BzU7qGKJg7Udn600MKloaZI/qOok14uxMSMEv+k+Dikze8= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=beta; h=received:from:to:cc:subject:in-reply-to:references:user-agent:date:message-id:mime-version:content-type:sender; b=AEm4ZgYW2ktRqrHlupz5AG7I+1gGk5S84jat4iIfadFSEynxGlROgwhEqMq3ODAlpWfusnY9Tem4YSqvZGHlJhWUCP1PZIOV31YSRthNuESeoV6PPMZKX8saZgVAf0bcrHAyZxYqXDq8+dDg7GX4ZP6Cax4z0j7QiI5y3y095NU= Original-Received: by 10.67.22.14 with SMTP id z14mr121865ugi.1194532337165; Thu, 08 Nov 2007 06:32:17 -0800 (PST) Original-Received: from bzg.ath.cx ( [81.99.213.34]) by mx.google.com with ESMTPS id x23sm1378480ugc.2007.11.08.06.32.13 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 08 Nov 2007 06:32:15 -0800 (PST) Original-Received: by bzg.ath.cx (Postfix, from userid 1000) id BC9801575BA; Thu, 8 Nov 2007 15:32:12 +0000 (GMT) In-Reply-To: (Drew Adams's message of "Sun, 4 Nov 2007 23:37:20 -0800") User-Agent: Gnus/5.110007 (No Gnus v0.7) Emacs/23.0.0 (gnu/linux) X-detected-kernel: by monty-python.gnu.org: Linux 2.6 (newer, 2) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:82801 Archived-At: --=-=-= Hi, I attach window-edit.el at the end of this email. window-edit.el contains only one function: M-x window-edit. I tried to implement Drew suggestions into one single function. See my comments below. Any feedback is very welcome. "Drew Adams" writes: > Some quick minor feedback: > > * Use `case' (compile-time require cl) to simplify code. I didn't use it yet. > * Why is WCF an arg? (You immediately set it.) Fixed. > * Bind `echo-keystrokes' to 0. Done. > * Let `0' delete the selected window. Done. > * Not sure `1' is a good idea (especially if no undo). Yes, right, fixed. > * Maybe `r' instead of `_'? Yes. Window configurations are now stored into a ring, so pressing `r' twice will call back wcf2 then wcf1 if wcf1 and wcf2 were stored. The first config in this ring is the initial one. > * When window reaches a minimum, trying to reduce it > more either moves it instead or deletes it instead. > Maybe do something different (e.g. nothing?). Fixed. Hence the ugly part of the defun. I couldn't figure out how to factorize all this a bit yet. Suggestions welcome. > * +/- is only for vertical resizing. Why not horizontal > also? Maybe let arrows do this also, with another key > toggling the mode (move border vs increase/decrease > size). SPC will toggle the mode. See the docstring. > * Maybe let Shift always navigate - up/down/left/right, > and use something else (`+' and `-'?) to > increment/decrement ARG. Right. S- now navigates through windows direction-wise. > * Maybe negate (toggle sign of) ARG with a keystroke > (e.g. `~'), instead of holding Meta down. (Modal.) Done. > * And maybe let C-N (N an integer) set ARG absolutely? Done. > * Maybe let mouse-1 select a window also. Done. > * Maybe use mouse wheel also (if direction is known)? Not done yet. Don't know if this is really useful. > * The prompt doesn't express much of what is possible. > In particular, if `one-window-p', the prompt makes > no sense (but `2' and `3' still make sense). Fixed, even though there is room for improvement. > * Let `?' provide more help. Done. > * Give confirmation message when save & restore. > When save, it should mention `_' (or `r') to restore. Done. > * Is it normal that the window is scrolled (perhaps to > keep point in view)? Maybe not scrolling should be > an option? Fixed, but it's not an option. > * Maybe let unrecognized events (keys, at least) quit > instead of being ignored. And then perhaps be > applied? So, e.g., `RET' would quit (and insert a > newline?). Not done. Will work on this later. Depends on feedback about this defun. > * Rename? `window-edit'? Good suggestion, done. > * Maybe bind it to `C-x w'. Or maybe have that be a > prefix for several window commands and bind this one > to `C-x w e' (for edit)? I let this to the user. Thanks again for the detailed suggestions. That was very helpful. I hope this function is closer that one might expect from window-edit. --=-=-= Content-Type: application/emacs-lisp Content-Disposition: attachment; filename=window-edit.el Content-Transfer-Encoding: 8bit ;;; window-edit.el --- edit windows interactively ;; ;; Copyright 2007 Bastien Guerry ;; ;; Author: Bastien Guerry ;; Version: 0.1 ;; Keywords: window ;; URL: not distributed yet ;; ;; 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 3, 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; if not, write to the Free Software ;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ;; ;;; Commentary: ;; ;; See `window-edit' docstring. ;; ;;; History: ;; ;; This was largely inspired by Hirose Yuuji and Bob Wiener original ;; `resize-window' as posted on the emacs-devel mailing list by Juanma. ;; This was also inspired by Lennart Borgman's bw-interactive.el. See ;; related discussions on the emacs-devel mailing list. ;; ;; Also check http://www.emacswiki.org/cgi-bin/wiki/WindowResize for ;; general hints on window resizing. ;; ;; My main goal was to deal with window resizing in one single defun. ;; ;; Put this file into your load-path and the following into your ;; ~/.emacs: (require 'window-edit) ;; ;;; Code: (provide 'window-edit) ;; TODO use / to enlarge vertically and horizontally? (defun window-edit (&optional arg) "Edit windows interactively. ARG is the number of lines by which the window should be resized. If this command is invoked in a single-window frame, only propose to split the window. Otherwise propose to move the borders with the arrow keys. Hitting SPC will switch from this move-borders mode to the resize-windows mode, where arrows keys don't point to direction but rather increase or decrease the window size. SPC: switch move-borders/resize-windows mode arrows: move borders direction-wise or resize windows S-arrows: jump to other window direction-wise +/-: increase/decrease line units s: store current window configuration in a ring r: restore window configurations q: quit window editing 0: delete other windows 2: split window vertically 3: split window horizontally ~: negate argument =: balance windows o: jump to other window ?: show this help buffer" (interactive "p") (require 'windmove) (unless arg (setq arg 1)) (let ((wcfs nil) (move-borders-p t) msg arg0) (push (current-window-configuration) wcfs) (run-at-time 15 10 '(lambda () (setq msg ""))) (catch 'done (while t (add-text-properties 0 (length msg) '(face bold) msg) (cond ((one-window-p) (message "Use 2 or 3 to split the window vertically or horizontally%s" (or msg ""))) (move-borders-p (message "Use arrow keys to move borders by %d line units%s" arg (or msg ""))) (t (message "Use arrow keys to resize windows by %d line units%s" arg (or msg "")))) (ignore-errors (let ((window-size-fixed nil) (echo-keystrokes 0) (bottom (string-match "Minibuf" (buffer-name (window-buffer (windmove-find-other-window 'down))))) (e (read-event))) (when (eq e ?~) (setq arg (- arg))) (when (memq e '(left right up down)) (if move-borders-p (cond ((eq e 'left) (if (windmove-find-other-window 'left) (progn (windmove-left) (if (> (- (window-width) arg) window-min-width) (shrink-window-horizontally arg) (setq msg " [can't move left]")) (windmove-right)) (if (> (- (window-width) arg) window-min-width) (shrink-window-horizontally arg) (setq msg " [can't move left]")))) ((eq e 'right) (if (windmove-find-other-window 'right) (progn (windmove-right) (if (> (- (window-width) arg) window-min-width) (progn (windmove-left) (enlarge-window-horizontally arg)) (progn (windmove-left) (setq msg " [can't move right]")))) (if (> (- (window-width) arg) window-min-width) (shrink-window-horizontally arg) (setq msg " [can't move right]")))) ((eq e 'up) (if (windmove-find-other-window 'up) (progn (windmove-up) (if (> (- (window-height) arg) window-min-height) (shrink-window arg) (setq msg " [can't move up]")) (windmove-down)) (if (not (or bottom (< (- (window-height) arg) window-min-height))) (shrink-window arg) (setq msg " [can't move up]")))) ((eq e 'down) (cond ((and bottom (windmove-find-other-window 'up)) (if (> (- (window-height) arg) window-min-height) (shrink-window arg) (setq msg " [can't move down]"))) ((windmove-find-other-window 'down) (progn (windmove-down) (if (> (- (window-height) arg) window-min-height) (progn (windmove-up) (enlarge-window arg)) (progn (windmove-up) (setq msg " [can't move down]"))))) (t (if (> (- (window-height) arg) window-min-height) (shrink-window arg) (setq msg " [can't move down]")))))) (cond ((eq e 'left) (and (> (- (window-width) arg) window-min-width) (shrink-window-horizontally arg))) ((eq e 'right) (enlarge-window-horizontally arg)) ((eq e 'up) (enlarge-window arg)) ((eq e 'down) (and (> (- (window-height) arg) window-min-height) (shrink-window arg)))))) (cond ((eq e ?0) (delete-other-windows)) ((eq e ?2) (split-window)) ((eq e ?3) (split-window-horizontally)) ((eq e ?o) (other-window 1)) ((eq e ?s) (push (current-window-configuration) wcfs) (setq msg " [Window configuration stored -- `r' to restore]")) ((eq e ?r) (setq msg " [Window configuration restored]") (let ((wcf (pop wcfs))) (set-window-configuration wcf) (add-to-list 'wcfs wcf t))) ((eq e 'S-left) (if (windmove-find-other-window 'left) (windmove-left) (setq msg " [No window left]"))) ((eq e 'S-right) (if (windmove-find-other-window 'right) (windmove-right) (setq msg " [No window right]"))) ((eq e 'S-down) (if bottom (setq msg " [No window down]") (windmove-down))) ((eq e 'S-up) (if (windmove-find-other-window 'up) (windmove-up) (setq msg " [No window up]"))) ((and (listp e) (eq (car e) 'down-mouse-1)) (select-window (caadr e))) ((setq arg0 (memq e '(?\^1 ?\^2 ?\^3 ?\^4 ?\^5 ?\^6 ?\^7 ?\^8 ?\^9))) (setq arg (- 10 (length arg0)))) ((equal e 32) (if (one-window-p) (setq msg " [can't switch mode in a single window]") (setq move-borders-p (null move-borders-p)))) ((memq e '(?h ??)) (let ((wcf0 (current-window-configuration)) (cursor-type nil)) (delete-other-windows) (switch-to-buffer-other-window (get-buffer-create "*window-edit help*")) (insert " SPC: switch move-borders/resize-windows mode 0: delete other windows arrows: move borders direction-wise or resize windows 2: split window vertically S-arrows: jump to other window direction-wise 3: split window horizontally +/-: increase/decrease line units ~: negate argument s: store current window configuration in a ring =: balance windows r: restore window configurations o: jump to other window q: quit window editing ?: show this help buffer") (shrink-window-if-larger-than-buffer) (goto-char (point-min)) (while (re-search-forward "^\\(.*\\):.*\\([023~=o]\\):" nil t) (add-text-properties (match-beginning 1) (match-end 1) '(face bold)) (add-text-properties (match-beginning 2) (match-end 2) '(face bold))) (when (read-event) (kill-buffer (current-buffer)) (set-window-configuration wcf0)))) ((eq e ?=) (balance-windows)) ((eq e ?+) (setq arg (1+ arg))) ((eq e ?-) (setq arg (1- arg))) ((eq e ?\^G) (keyboard-quit)) ((eq e ?q) (throw 'done t)))))))) (message "Window editing done")) ;;;;########################################################################## ;;;; User Options, Variables ;;;;########################################################################## ;;; window-edit.el ends here --=-=-= -- Bastien --=-=-= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Emacs-devel mailing list Emacs-devel@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-devel --=-=-=--