all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Drew Adams" <drew.adams@oracle.com>
To: <emacs-devel@gnu.org>
Subject: face-remap.el patch to resize window
Date: Mon, 22 Jun 2009 13:40:15 -0700	[thread overview]
Message-ID: <8F69F432630D4C30875CBF4B117C0BF1@us.oracle.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 1084 bytes --]

Commands `text-scale-decrease', `text-scale-increase', and
`text-scale-adjust' (bound to `C-x C--', `C-x C-+', `C-x C-=',
and `C-x C-0') let you resize the text in the current buffer
by changing its scale factor.

When you shrink or enlarge the apparent text size this way,
however, the window takes no notice of it.  In particular,
although shrinking text can result in extra horizontal
space at the right, window commands do not see this space
as extra (available).

With this patch, user option `text-scale-resize-window' lets
you automatically resize the selected window (horizontally,
vertically, or both) when text is resized, so that the way the
window fits the buffer text remains relatively constant.
Shrinking the text in one window shrinks that window, giving
more space to adjacent windows.

Feel free to change the default value for the option (e.g. to nil, to have no
effect by default). Feel free to accept the patch or ignore it.

[For anyone who might be interested in a version that also resizes a one-window
frame: http://www.emacswiki.org/emacs/face-remap%2b.el.]

[-- Attachment #2: face-remap-2009-06-22.patch --]
[-- Type: application/octet-stream, Size: 3126 bytes --]

diff -c -w face-remap.el face-remap-patched-2009-06-22.el
*** face-remap.el	Mon Jun 22 10:06:24 2009
--- face-remap-patched-2009-06-22.el	Mon Jun 22 11:41:02 2009
***************
*** 191,196 ****
--- 191,207 ----
    :type 'number
    :version "23.1")
  
+ (defcustom text-scale-resize-window t
+   "Non-nil means text scaling resizes the window accordingly.
+ For example, if you use `C-x C--' (`text-scale-decrease')' to make the
+ text smaller, then the window is made smaller by a similar factor."
+   :type '(choice
+           (const :tag "Do not resize window when scale text"  nil)
+           (const :tag "Resize window when scale text"         t)
+           (const :tag "Resize only horizontally"              horizontally)
+           (const :tag "Resize only vertically"                vertically))
+   :group 'display)
+ 
  ;; current remapping cookie for text-scale-mode
  (defvar text-scale-mode-remapping nil)
  (make-variable-buffer-local 'text-scale-mode-remapping)
***************
*** 237,247 ****
  Each step scales the height of the default face by the variable
  `text-scale-mode-step' (a negative number of steps decreases the
  height by the same amount).  As a special case, an argument of 0
! will remove any scaling currently active."
    (interactive "p")
    (setq text-scale-mode-amount
  	(if (= inc 0) 0 (+ (if text-scale-mode text-scale-mode-amount 0) inc)))
!   (text-scale-mode (if (zerop text-scale-mode-amount) -1 1)))
  
  ;;;###autoload
  (defun text-scale-decrease (dec)
--- 248,277 ----
  Each step scales the height of the default face by the variable
  `text-scale-mode-step' (a negative number of steps decreases the
  height by the same amount).  As a special case, an argument of 0
! removes any scaling currently active.
! 
! If option `text-scale-resize-window' is non-nil, then resize the
! selected window accordingly, so as to keep roughly the same text
! visible in the window.  See option `text-scale-resize-window' for the
! possible behaviors."
    (interactive "p")
+   (let* ((oamount       (if text-scale-mode text-scale-mode-amount 0))
+          (scale-factor  (expt text-scale-mode-step (if (= inc 0) (- oamount) inc)))
+          (edges         (window-edges))
+          (owidth        (- (nth 2 edges) (nth 0 edges)))
+          (oheight       (- (nth 3 edges) (nth 1 edges))))
      (setq text-scale-mode-amount
            (if (= inc 0) 0 (+ (if text-scale-mode text-scale-mode-amount 0) inc)))
!     (text-scale-mode (if (zerop text-scale-mode-amount) -1 1))
!     (when text-scale-resize-window
!       (unless (eq text-scale-resize-window 'vertically)
!         (condition-case nil
!             (enlarge-window-horizontally (round (- (* owidth scale-factor) owidth)))
!           (error nil)))
!       (unless (eq text-scale-resize-window 'horizontally)
!         (condition-case nil
!             (enlarge-window (round (- (* oheight scale-factor) oheight)))
!           (error nil))))))
  
  ;;;###autoload
  (defun text-scale-decrease (dec)

Diff finished.  Mon Jun 22 11:42:00 2009

             reply	other threads:[~2009-06-22 20:40 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-22 20:40 Drew Adams [this message]
  -- strict thread matches above, loose matches on Subject: below --
2009-06-29 22:10 face-remap.el patch to resize window Drew Adams
2009-08-10  1:04 Drew Adams
2009-08-10  3:00 ` Stefan Monnier
2009-08-10  3:27   ` Drew Adams
2009-08-10  5:04     ` Miles Bader
2009-08-10 17:00       ` Drew Adams
2009-08-10  3:34   ` Miles Bader
2009-08-10 15:01     ` Stefan Monnier
2009-08-10 16:31     ` Drew Adams
2009-08-10 16:52       ` Miles Bader
2009-08-10 16:59         ` Drew Adams
2009-08-10 17:16         ` Stefan Monnier
2009-08-10 17:00       ` Stefan Monnier
2009-08-10 17:15         ` Drew Adams
2009-08-10 17:37           ` Miles Bader
2009-08-10 21:41             ` Drew Adams
2009-08-10 18:03           ` Stefan Monnier
2009-08-10 21:50             ` Drew Adams
2009-08-11  3:45               ` Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8F69F432630D4C30875CBF4B117C0BF1@us.oracle.com \
    --to=drew.adams@oracle.com \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.