From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: daniel sutton Newsgroups: gmane.emacs.devel Subject: [ELPA] New Package: resize-mode Date: Sat, 21 Nov 2015 21:56:26 -0600 Message-ID: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=089e013a0142c541460525191718 X-Trace: ger.gmane.org 1448164614 14781 80.91.229.3 (22 Nov 2015 03:56:54 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 22 Nov 2015 03:56:54 +0000 (UTC) To: emacs-devel Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Nov 22 04:56:48 2015 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1a0Llf-00071i-E4 for ged-emacs-devel@m.gmane.org; Sun, 22 Nov 2015 04:56:47 +0100 Original-Received: from localhost ([::1]:54699 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a0Lle-0001Hb-Uf for ged-emacs-devel@m.gmane.org; Sat, 21 Nov 2015 22:56:46 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:52464) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a0LlN-0001HW-UI for emacs-devel@gnu.org; Sat, 21 Nov 2015 22:56:32 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a0LlL-0002Bo-NU for emacs-devel@gnu.org; Sat, 21 Nov 2015 22:56:29 -0500 Original-Received: from mail-ig0-x22a.google.com ([2607:f8b0:4001:c05::22a]:37768) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a0LlL-0002Bd-Fa for emacs-devel@gnu.org; Sat, 21 Nov 2015 22:56:27 -0500 Original-Received: by igcto18 with SMTP id to18so36999496igc.0 for ; Sat, 21 Nov 2015 19:56:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=TqvV7i6uCB4eSc3A44638IWnKniEoC6AgLGGskBEmb8=; b=bzo90xz5Fe1wri8mjokewkxIlhn5GYs9QNMZQO8DJI5HY2fEhqfunyLK+BjPwRxgsF K/4DqHUnhCr5Wq4eX9QVA/ZEtWBsqP11jOrau0jZAbHGJeWrXcHHalmtvCju+lbDMy9d fKLIDUiUVUaQARLBfAu16QvlPLbO0Jz4F+gdGRwfZnwoznENJd4EVqUIjOsrRHJXxUlA x7HIBXOxO53IOlEoJNJe+RX5CrgJghJKU7wcHubO4dgwZyZYmENhAAHqvJevlzdgyQIQ Emx0V/30o27gpnJeH24cYzTd2O2wb/wg1XboNq9nd4+3fenSgiyUDuZ3H5JTFn3nijr1 bywA== X-Received: by 10.50.73.9 with SMTP id h9mr543929igv.41.1448164586764; Sat, 21 Nov 2015 19:56:26 -0800 (PST) Original-Received: by 10.107.15.229 with HTTP; Sat, 21 Nov 2015 19:56:26 -0800 (PST) X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:4001:c05::22a X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:194978 Archived-At: --089e013a0142c541460525191718 Content-Type: text/plain; charset=UTF-8 I have found that resizing windows is not very easy or quick, especially with repeated calls and prefixes. To this aim, I made a little "mode" here that makes this much easier by allowing to use the standard navigation keys (n,p,f,b) to increase and decrease horizontal and vertical widths. w cycle through windows, r resets back to a standard layout, and ? displays a menu. The navigational keys allow for NPFB to specify coarse movements rather than the fine movements of their lowercase versions. I find it very useful already and I would like to share it on elpa to allow installation to be straightforward. I have it up on https://github.com/dpsutton/resize-mode at the moment but obviously want to add it to the elpa repository. I'll post the code here below and look forward to everyone's thoughts and remarks. dan code below: ;;; package -- Summary -*- lexical-binding: t; -*- ;; Copyright (C) 2015 Free Software Foundation, Inc. ;; Author: Dan Sutton ;; Maintainer: Dan Sutton ;; URL: https://github.com/dpsutton/resize-mode ;; Version: 0.1.0 ;; Package-Requires: () ;; Keywords: window, resize ;; 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 of the License, 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, see ;; . ;;; Commentary: ;; Easily allows you to resize windows. Rather than guessing that you ;; want `C-u 17 C-x {`, you could just press FFff, which enlarges 5 ;; lines, then 5 lines, then one and then one. The idea is that the ;; normal motions n,p,f,b along with r for reset and w for cycling ;; windows allows for super simple resizing of windows. All of this is ;; inside of a while loop so that you don't have to invoke more chords ;; to resize again, but just keep using standard motions until you are ;; happy. ;; All of the work is done inside of resize-window. Its just a while ;; loop that keeps looping over character input until it doesn't ;; recognize an option or an allowable capital. The dispatch alist has ;; a character code to look for, a function to invoke, a string for ;; display and whether to match against capital letters. If so, it is ;; invoked with the default capital argument rather than the default ;; argument. ;;; Code: (defgroup resize-window nil "Quickly resize current window" :group 'convenience :prefix "rw-") (defcustom rw-capital-argument 5 "Set how big a capital letter movement is." :type 'integer) (defcustom rw-default-argument 1 "Set how big the default movement should be." :type 'integer) (defcustom rw-allow-backgrounds t "Allow resize mode to set a background. This is also valuable to see that you are in resize mode." :type 'boolean) (defvar rw-background-overlay () "Holder for background overlay.") (defface rw-background-face '((t (:foreground "gray40"))) "Face for when resizing window.") (defvar rw-dispatch-alist ;; (key function description allow-caps-for-scaled) () "List of actions for `rw-dispatch-default.") (setq rw-dispatch-alist '((?n rw-enlarge-down " Resize - Expand down" t) (?p rw-enlarge-up " Resize - Expand up" t) (?f rw-enlarge-horizontally " Resize - horizontally" t) (?b rw-shrink-horizontally " Resize - shrink horizontally" t) (?r rw-reset-windows " Resize - reset window layour" nil) (?w rw-cycle-window-positive " Resize - cycle window" nil) (?W rw-cycle-window-negative " Resize - cycle window" nil) (?? rw-display-menu " Resize - display menu" nil))) (defun rw-display-choice (choice) "Formats screen message about CHOICE. CHOICE is a (key function description allows-capital." (format "%s: %s " (if (rw-allows-capitals choice) (format "%s|%s" (string (car choice)) (string (- (car choice) 32))) (string (car choice))) (car (cdr (cdr choice))))) (defun rw-get-documentation-strings () "Get all documentation strings for display." (let ((documentation "")) (dolist (choice rw-dispatch-alist) (setq documentation (concat (rw-display-choice choice) "\n" documentation))) documentation)) (defun rw-make-background () "Place a background over the current window." (when rw-allow-backgrounds (let ((ol (make-overlay (point-min) (point-max) (window-buffer)))) (overlay-put ol 'face 'rw-background-face) ol))) (defun rw-execute-action (choice &optional scaled) "Given a CHOICE, grab values out of the alist. If SCALED, then call action with the rw-capital-argument." ;; (char function description) (let ((action (cadr choice)) (description (car (cdr (cdr choice))))) (progn (if scaled (funcall action rw-capital-argument) (funcall action)) (unless (equalp (car choice) ??) (message "%s" description))))) (defun rw-allows-capitals (choice) "To save time typing, we will tell whether we allow capitals for scaling. To do so, we check to see whether CHOICE allows for capitals by checking its last spot in the list for whether it is true or nil." (car (last choice))) ;;;###autoload (defun resize-window () "Resize the window. Press n to enlarge down, p to enlarge up, b to enlarge left and f to enlarge right. Current ARG is not supported." (interactive) (setq rw-background-overlay (rw-make-background)) (message "Resize mode: enter character, ? for help") (let ((reading-characters t) ;; allow mini-buffer to collapse after displaying menu (resize-mini-windows t)) (while reading-characters (let* ((char (read-char-exclusive)) (choice (assoc char rw-dispatch-alist)) (capital (assoc (+ char 32) rw-dispatch-alist))) (if choice (rw-execute-action choice) (if (and capital (rw-allows-capitals capital)) (rw-execute-action capital t) (progn (setq reading-characters nil) (delete-overlay rw-background-overlay)))))))) ;;; Function Handlers (defun rw-enlarge-down (&optional size) "Extend the current window downwards by optional SIZE. If no SIZE is given, extend by `rw-default-argument`" (let ((size (or size rw-default-argument))) (enlarge-window size))) (defun rw-enlarge-up (&optional size) "Bring bottom edge back up by one or optional SIZE." (let ((size (or size rw-default-argument))) (enlarge-window (- size)))) (defun rw-enlarge-horizontally (&optional size) "Enlarge the window horizontally by one or optional SIZE." (let ((size (or size rw-default-argument))) (enlarge-window size t))) (defun rw-shrink-horizontally (&optional size) "Shrink the window horizontally by one or optional SIZE." (let ((size (or size rw-default-argument))) (enlarge-window (- size) t))) (defun rw-reset-windows () "Reset window layout to even spread." (balance-windows)) (defun rw-cycle-window-positive () "Cycle windows." (delete-overlay rw-background-overlay) (other-window 1) (setq rw-background-overlay (rw-make-background))) (defun rw-cycle-window-negative () "Cycle windows negative." (delete-overlay rw-background-overlay) (other-window -1) (setq rw-background-overlay (rw-make-background))) (defun rw-display-menu () "Display menu in minibuffer." (message "%s" (rw-get-documentation-strings))) (provide 'resize-mode) ;;; resize-mode ends here --089e013a0142c541460525191718 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
I have found that resizing windows is not very easy or qui= ck, especially with repeated calls and prefixes. To this aim, I made a litt= le "mode" here that makes this much easier by allowing to use the= standard navigation keys (n,p,f,b) to increase and decrease horizontal and= vertical widths. w cycle through windows, r resets back to a standard layo= ut, and ? displays a menu. The navigational keys allow for NPFB to specify = coarse movements rather than the fine movements of their lowercase versions= .

I find it very useful already and I would like to shar= e it on elpa to allow installation to be straightforward. I have it up on= =C2=A0https://github.co= m/dpsutton/resize-mode at the moment but obviously want to add it to th= e elpa repository.

I'll post the code here bel= ow and look forward to everyone's thoughts and remarks.
dan

code below:

;;; packa= ge -- Summary -*- lexical-binding: t; -*-

;; Copyr= ight (C) 2015 =C2=A0Free Software Foundation, Inc.

;; Author: Dan Sutton =C2=A0<danielsutton01@gmail.com>
;; Maintainer: Dan Sutton =C2= =A0<danielsutton01@gmail.com= >

;;= Version: 0.1.0
;; Package-Requires: ()
;; Keywords: wi= ndow, resize

;; This program is free software: you= can redistribute it and/or modify
;; it under the terms of the G= NU General Public License as published by
;; the Free Software Fo= undation, either version 3 of the License, 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 FITNE= SS FOR A PARTICULAR PURPOSE.=C2=A0 See the
;; GNU General Public = License for more details.

;; You should have recei= ved a copy of the GNU General Public License
;; along with this p= rogram.=C2=A0 If not, see

;;;= Commentary:
;; Easily allows you to resize windows. Rather than = guessing that you
;; want `C-u 17 C-x {`, you could just press FF= ff, which enlarges 5
;; lines, then 5 lines, then one and then on= e. The idea is that the
;; normal motions n,p,f,b along with r fo= r reset and w for cycling
;; windows allows for super simple resi= zing of windows. All of this is
;; inside of a while loop so that= you don't have to invoke more chords
;; to resize again, but= just keep using standard motions until you are
;; happy.

;; All of the work is done inside of resize-window. Its j= ust a while
;; loop that keeps looping over character input until= it doesn't
;; recognize an option or an allowable capital. T= he dispatch alist has
;; a character code to look for, a function= to invoke, a string for
;; display and whether to match against = capital letters. If so, it is
;; invoked with the default capital= argument rather than the default
;; argument.

;;; Code:

(defgroup resize-window nil
=
=C2=A0 "Quickly resize current window"
=C2=A0 :gro= up 'convenience
=C2=A0 :prefix "rw-")
(defcustom rw-capital-argument 5
=C2=A0 "Set how= big a capital letter movement is."
=C2=A0 :type 'intege= r)

(defcustom rw-default-argument 1
=C2= =A0 "Set how big the default movement should be."
=C2= =A0 :type 'integer)

(defcustom rw-allow-backgr= ounds t
=C2=A0 "Allow resize mode to set a background.
=
This is also valuable to see that you are in resize mode."
<= div>=C2=A0 :type 'boolean)

(defvar rw-backgrou= nd-overlay ()
=C2=A0 "Holder for background overlay.")<= /div>

(defface rw-background-face
=C2=A0 '= ((t (:foreground "gray40")))
=C2=A0 "Face for when= resizing window.")

(defvar rw-dispatch-alist=
=C2=A0 ;; (key function description allow-caps-for-scaled)
=
=C2=A0 ()
=C2=A0 "List of actions for `rw-dispatch-defa= ult.")

(setq rw-dispatch-alist
=C2= =A0 =C2=A0 =C2=A0 '((?n rw-enlarge-down =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0" Resize - Expand down" t)
=C2=A0 =C2=A0 =C2=A0 =C2= =A0 (?p rw-enlarge-up =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0" Resiz= e - Expand up" t)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (?f rw-enlarge= -horizontally =C2=A0" Resize - horizontally" t)
=C2=A0 = =C2=A0 =C2=A0 =C2=A0 (?b rw-shrink-horizontally =C2=A0 " Resize - shri= nk horizontally" t)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (?r rw-reset= -windows =C2=A0 =C2=A0 =C2=A0 =C2=A0 " Resize - reset window layour&qu= ot; nil)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (?w rw-cycle-window-positive= " Resize - cycle window" nil)
=C2=A0 =C2=A0 =C2=A0 =C2= =A0 (?W rw-cycle-window-negative " Resize - cycle window" nil)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (?? rw-display-menu =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0" Resize - display menu" nil)))

(defun rw-display-choice (choice)
=C2=A0 "Formats s= creen message about CHOICE.
CHOICE is a (key function description= allows-capital."
=C2=A0 (format "%s: %s " (if (rw= -allows-capitals choice)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (format "%s|%s" (st= ring (car choice)) (string (- (car choice) 32)))
=C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (string (car= choice)))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (car (cdr (cdr choi= ce)))))

(defun rw-get-documentation-strings ()
=C2=A0 "Get all documentation strings for display."
<= div>=C2=A0 (let ((documentation ""))
=C2=A0 =C2=A0 (dol= ist (choice rw-dispatch-alist)
=C2=A0 =C2=A0 =C2=A0 (setq documen= tation
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (concat (rw-disp= lay-choice choice) "\n" documentation)))
=C2=A0 =C2=A0 = documentation))

(defun rw-make-background ()
=
=C2=A0 "Place a background over the current window."
=C2=A0 (when rw-allow-backgrounds
=C2=A0 =C2=A0 (let ((ol (mak= e-overlay
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= (point-min)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0(point-max)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0(window-buffer))))
=C2=A0 =C2=A0 =C2=A0 (overlay-put ol = 9;face 'rw-background-face)
=C2=A0 =C2=A0 =C2=A0 ol)))
<= div>
(defun rw-execute-action (choice &optional scaled)
=C2=A0 "Given a CHOICE, grab values out of the alist.
If SCALED, then call action with the rw-capital-argument."
=C2=A0 ;; (char function description)
=C2=A0 (let ((action (cad= r choice))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (description (car (cdr (cd= r choice)))))
=C2=A0 =C2=A0 (progn
=C2=A0 =C2=A0 =C2=A0= (if scaled
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (funcall action rw= -capital-argument)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (funcall action))<= /div>
=C2=A0 =C2=A0 =C2=A0 (unless (equalp (car choice) ??)
= =C2=A0 =C2=A0 =C2=A0 =C2=A0 (message "%s" description)))))
<= div>
(defun rw-allows-capitals (choice)
=C2=A0 &quo= t;To save time typing, we will tell whether we allow capitals for scaling.<= /div>
To do so, we check to see whether CHOICE allows for capitals by
checking its last spot in the list for whether it is true or
=
nil."
=C2=A0 (car (last choice)))

<= div>;;;###autoload
(defun resize-window ()
=C2=A0 "= ;Resize the window.
Press n to enlarge down, p to enlarge up, b t= o enlarge left and f
to enlarge right.=C2=A0 Current ARG is not s= upported."
=C2=A0 (interactive)
=C2=A0 (setq rw-ba= ckground-overlay (rw-make-background))
=C2=A0 (message "Resi= ze mode: enter character, ? for help")
=C2=A0 (let ((reading= -characters t)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 ;; allow mini-buffer t= o collapse after displaying menu
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (res= ize-mini-windows t))
=C2=A0 =C2=A0 (while reading-characters
=C2=A0 =C2=A0 =C2=A0 (let* ((char (read-char-exclusive))
= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(choice (assoc char rw-disp= atch-alist))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(cap= ital (assoc (+ char 32) rw-dispatch-alist)))
=C2=A0 =C2=A0 =C2=A0= =C2=A0 (if choice
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (rw-= execute-action choice)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (if (an= d capital (rw-allows-capitals capital))
=C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 (rw-execute-action capital t)
=C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (progn
=C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 (setq reading-characters nil)
=C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (delete-overlay rw-background-overla= y))))))))

;;; Function Handlers
(defun r= w-enlarge-down (&optional size)
=C2=A0 "Extend the curre= nt window downwards by optional SIZE.
If no SIZE is given, extend= by `rw-default-argument`"
=C2=A0 (let ((size (or size rw-de= fault-argument)))
=C2=A0 =C2=A0 (enlarge-window size)))

(defun rw-enlarge-up (&optional size)
=C2=A0 = "Bring bottom edge back up by one or optional SIZE."
= =C2=A0 (let ((size (or size rw-default-argument)))
=C2=A0 =C2=A0 = (enlarge-window (- size))))

(defun rw-enlarge-hori= zontally (&optional size)
=C2=A0 "Enlarge the window hor= izontally by one or optional SIZE."
=C2=A0 (let ((size (or s= ize rw-default-argument)))
=C2=A0 =C2=A0 (enlarge-window size t))= )

(defun rw-shrink-horizontally (&optional siz= e)
=C2=A0 "Shrink the window horizontally by one or optional= SIZE."
=C2=A0 (let ((size (or size rw-default-argument)))
=C2=A0 =C2=A0 (enlarge-window (- size) t)))

(defun rw-reset-windows ()
=C2=A0 "Reset window layout to= even spread."
=C2=A0 (balance-windows))

(defun rw-cycle-window-positive ()
=C2=A0 "Cycle windo= ws."
=C2=A0 (delete-overlay rw-background-overlay)
=C2=A0 (other-window 1)
=C2=A0 (setq rw-background-overlay (rw-m= ake-background)))

(defun rw-cycle-window-negative = ()
=C2=A0 "Cycle windows negative."
=C2=A0 (d= elete-overlay rw-background-overlay)
=C2=A0 (other-window -1)
=C2=A0 (setq rw-background-overlay (rw-make-background)))
=
(defun rw-display-menu ()
=C2=A0 "Display men= u in minibuffer."
=C2=A0 (message "%s" (rw-get-doc= umentation-strings)))

(provide 'resize-mode)
;;; resize-mode ends here

--089e013a0142c541460525191718--