* [ELPA] New Package: resize-mode
@ 2015-11-22 3:56 daniel sutton
2015-11-22 4:14 ` Yuri Khan
` (2 more replies)
0 siblings, 3 replies; 9+ messages in thread
From: daniel sutton @ 2015-11-22 3:56 UTC (permalink / raw)
To: emacs-devel
[-- Attachment #1: Type: text/plain, Size: 7993 bytes --]
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 <danielsutton01@gmail.com>
;; Maintainer: Dan Sutton <danielsutton01@gmail.com>
;; 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
;; <http://www.gnu.org/licenses/>.
;;; 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
[-- Attachment #2: Type: text/html, Size: 11264 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [ELPA] New Package: resize-mode
2015-11-22 3:56 [ELPA] New Package: resize-mode daniel sutton
@ 2015-11-22 4:14 ` Yuri Khan
2015-11-22 15:32 ` Eli Zaretskii
2015-11-22 5:19 ` John Wiegley
2015-11-22 12:22 ` Artur Malabarba
2 siblings, 1 reply; 9+ messages in thread
From: Yuri Khan @ 2015-11-22 4:14 UTC (permalink / raw)
To: daniel sutton; +Cc: emacs-devel
On Sun, Nov 22, 2015 at 9:56 AM, daniel sutton <danielsutton01@gmail.com> wrote:
> 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.
This might benefit from also binding [Shift+]arrow keys as well.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [ELPA] New Package: resize-mode
2015-11-22 4:14 ` Yuri Khan
@ 2015-11-22 15:32 ` Eli Zaretskii
2015-11-22 15:52 ` daniel sutton
0 siblings, 1 reply; 9+ messages in thread
From: Eli Zaretskii @ 2015-11-22 15:32 UTC (permalink / raw)
To: Yuri Khan; +Cc: danielsutton01, emacs-devel
> From: Yuri Khan <yuri.v.khan@gmail.com>
> Date: Sun, 22 Nov 2015 10:14:05 +0600
> Cc: emacs-devel <emacs-devel@gnu.org>
>
> This might benefit from also binding [Shift+]arrow keys as well.
Which IMO should allow pixel-granular resizing.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [ELPA] New Package: resize-mode
2015-11-22 15:32 ` Eli Zaretskii
@ 2015-11-22 15:52 ` daniel sutton
2015-11-22 19:38 ` Artur Malabarba
0 siblings, 1 reply; 9+ messages in thread
From: daniel sutton @ 2015-11-22 15:52 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: emacs-devel, Yuri Khan
[-- Attachment #1: Type: text/plain, Size: 1351 bytes --]
> Why is it called `background-face' if it only sets the foreground?
I was following the style of ace-window as I am new to this. I will update
that.
> Really small nitpick, but this would read better as a cond. (And that
> progn is redundant).
Totally agree
> Is there a reason why this is done like this? Why not just set this
> value inside the defvar?
I was adding things to this and defvar only sets it if it is unbound. I
figured since this is so easy to read and simple, people might add their
own and eval the buffer. This makes it trivial to add more options.
> besides, this package is not a mode.
Totally agree. My thinking drastically changed as I went.
Thanks so much for taking the time to look at my code.
In the elpa wiki it mentioned that if you don't have push rights your code
will be added by someone else after two days. I have an account on Savannah
but I'm I never saw if this includes push rights to elpa, although I would
assume not. Does anyone know what further steps I will need to take?
dan
On Sun, Nov 22, 2015 at 9:32 AM, Eli Zaretskii <eliz@gnu.org> wrote:
> > From: Yuri Khan <yuri.v.khan@gmail.com>
> > Date: Sun, 22 Nov 2015 10:14:05 +0600
> > Cc: emacs-devel <emacs-devel@gnu.org>
> >
> > This might benefit from also binding [Shift+]arrow keys as well.
>
> Which IMO should allow pixel-granular resizing.
>
[-- Attachment #2: Type: text/html, Size: 2778 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [ELPA] New Package: resize-mode
2015-11-22 15:52 ` daniel sutton
@ 2015-11-22 19:38 ` Artur Malabarba
2015-11-22 20:14 ` daniel sutton
0 siblings, 1 reply; 9+ messages in thread
From: Artur Malabarba @ 2015-11-22 19:38 UTC (permalink / raw)
To: daniel sutton; +Cc: Eli Zaretskii, Yuri Khan, emacs-devel
[-- Attachment #1: Type: text/plain, Size: 2039 bytes --]
>> Is there a reason why this is done like this? Why not just set this
>> value inside the defvar?
> I was adding things to this and defvar only sets it if it is unbound.
Try reevaluating the defvar with C-M-x
> I
> figured since this is so easy to read and simple, people might add their
own
> and eval the buffer. This makes it trivial to add more options.
It's unusual for people to edit package files directly. They usually add
configurations to their init files. In this case, if your package is loaded
after their init file your setq will override their setq.
> In the elpa wiki it mentioned that if you don't have push rights your code
> will be added by someone else after two days. I have an account on
Savannah
> but I'm I never saw if this includes push rights to elpa, although I would
> assume not. Does anyone know what further steps I will need to take?
You need to sign the copyright assignment, and then I can push it for you
(you're not the first to ask, the readme really should say this).
To get started on that, follow these instructions:
-------
Please email the following information to assign@gnu.org, and we
will send you the assignment form for your past and future changes.
Please use your full legal name (in ASCII characters) as the subject
line of the message.
----------------------------------------------------------------------
REQUEST: SEND FORM FOR PAST AND FUTURE CHANGES
[What is the name of the program or package you're contributing to?]
Emacs
[Did you copy any files or text written by someone else in these changes?
Even if that material is free software, we need to know about it.]
[Do you have an employer who might have a basis to claim to own
your changes? Do you attend a school which might make such a claim?]
[For the copyright registration, what country are you a citizen of?]
[What year were you born?]
[Please write your email address here.]
[Please write your postal address here.]
[Which files have you changed so far, and which new files have you written
so far?]
[-- Attachment #2: Type: text/html, Size: 2553 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [ELPA] New Package: resize-mode
2015-11-22 19:38 ` Artur Malabarba
@ 2015-11-22 20:14 ` daniel sutton
2015-11-22 20:32 ` Artur Malabarba
0 siblings, 1 reply; 9+ messages in thread
From: daniel sutton @ 2015-11-22 20:14 UTC (permalink / raw)
To: Artur Malabarba; +Cc: Eli Zaretskii, Yuri Khan, emacs-devel
[-- Attachment #1: Type: text/plain, Size: 2605 bytes --]
thanks Artur.
Excellent point about the setq. I have made the change. The emacsWiki
article for making packages said that step one (in bold) was to make an
account on Savannah and sign the copyright transfer information. However,
it did not have any apparently obvious information about how to do this.
Thank you so much for providing that information. The email has been sent.
On Sun, Nov 22, 2015 at 1:38 PM, Artur Malabarba <bruce.connor.am@gmail.com>
wrote:
> >> Is there a reason why this is done like this? Why not just set this
> >> value inside the defvar?
> > I was adding things to this and defvar only sets it if it is unbound.
>
> Try reevaluating the defvar with C-M-x
>
> > I
> > figured since this is so easy to read and simple, people might add their
> own
> > and eval the buffer. This makes it trivial to add more options.
>
> It's unusual for people to edit package files directly. They usually add
> configurations to their init files. In this case, if your package is loaded
> after their init file your setq will override their setq.
>
> > In the elpa wiki it mentioned that if you don't have push rights your
> code
> > will be added by someone else after two days. I have an account on
> Savannah
> > but I'm I never saw if this includes push rights to elpa, although I
> would
> > assume not. Does anyone know what further steps I will need to take?
>
> You need to sign the copyright assignment, and then I can push it for you
> (you're not the first to ask, the readme really should say this).
>
> To get started on that, follow these instructions:
>
> -------
>
> Please email the following information to assign@gnu.org, and we
> will send you the assignment form for your past and future changes.
>
> Please use your full legal name (in ASCII characters) as the subject
> line of the message.
> ----------------------------------------------------------------------
> REQUEST: SEND FORM FOR PAST AND FUTURE CHANGES
>
> [What is the name of the program or package you're contributing to?]
> Emacs
>
> [Did you copy any files or text written by someone else in these changes?
> Even if that material is free software, we need to know about it.]
>
> [Do you have an employer who might have a basis to claim to own
> your changes? Do you attend a school which might make such a claim?]
>
> [For the copyright registration, what country are you a citizen of?]
>
> [What year were you born?]
>
> [Please write your email address here.]
>
> [Please write your postal address here.]
>
>
>
> [Which files have you changed so far, and which new files have you written
> so far?]
>
[-- Attachment #2: Type: text/html, Size: 3424 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [ELPA] New Package: resize-mode
2015-11-22 3:56 [ELPA] New Package: resize-mode daniel sutton
2015-11-22 4:14 ` Yuri Khan
@ 2015-11-22 5:19 ` John Wiegley
2015-11-22 12:22 ` Artur Malabarba
2 siblings, 0 replies; 9+ messages in thread
From: John Wiegley @ 2015-11-22 5:19 UTC (permalink / raw)
To: daniel sutton; +Cc: emacs-devel
>>>>> daniel sutton <danielsutton01@gmail.com> writes:
> 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.
It looks like a good addition to ELPA to me.
John
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [ELPA] New Package: resize-mode
2015-11-22 3:56 [ELPA] New Package: resize-mode daniel sutton
2015-11-22 4:14 ` Yuri Khan
2015-11-22 5:19 ` John Wiegley
@ 2015-11-22 12:22 ` Artur Malabarba
2 siblings, 0 replies; 9+ messages in thread
From: Artur Malabarba @ 2015-11-22 12:22 UTC (permalink / raw)
To: daniel sutton; +Cc: emacs-devel
Looks like a fine addition to Gelpa. The only suggestion I would make
before pushing it is that it be renamed to `resize-window'. That's more
descriptive of what it does (resize-mode could mean quite a few things)
and, besides, this package is not a mode. :-)
Below are a few comments the code. These are all just small
improvements which could be addressed before or after pushing.
daniel sutton <danielsutton01@gmail.com> writes:
> (defface rw-background-face
> '((t (:foreground "gray40")))
> "Face for when resizing window.")
Why is it called `background-face' if it only sets the foreground?
Also, the current convention is to not have `-face' at the end of face
names (I know, a lot of built-in faces have this, but they're for
backwards compatibility).
> (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)))
Is there a reason why this is done like this? Why not just set this
value inside the defvar?
> (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
This progn is redundant.
> (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))))))))
Really small nitpick, but this would read better as a cond. (And that
progn is redundant).
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2015-11-22 20:32 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-11-22 3:56 [ELPA] New Package: resize-mode daniel sutton
2015-11-22 4:14 ` Yuri Khan
2015-11-22 15:32 ` Eli Zaretskii
2015-11-22 15:52 ` daniel sutton
2015-11-22 19:38 ` Artur Malabarba
2015-11-22 20:14 ` daniel sutton
2015-11-22 20:32 ` Artur Malabarba
2015-11-22 5:19 ` John Wiegley
2015-11-22 12:22 ` Artur Malabarba
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.