From: Miles Bader <miles@gnu.org>
To: "Drew Adams" <drew.adams@oracle.com>
Cc: 'Stefan Monnier' <monnier@iro.umontreal.ca>, emacs-devel@gnu.org
Subject: Re: face-remap.el patch to resize window
Date: Mon, 10 Aug 2009 14:04:30 +0900 [thread overview]
Message-ID: <871vnkfee9.fsf@catnip.gol.com> (raw)
In-Reply-To: <2DD5D9B518394F17A3AA77158B671255@us.oracle.com> (Drew Adams's message of "Sun, 9 Aug 2009 20:27:49 -0700")
[-- Attachment #1: Type: text/plain, Size: 335 bytes --]
What do you think of the following patch, which is an alternative
approach based on hooks?
Basically to get the behavior you want, you can do:
(add-hook 'text-scale-mode-hook 'text-scale-mode-adjust-window-size)
-Miles
--
Corporation, n. An ingenious device for obtaining individual profit without
individual responsibility.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: text-scale-mode-hooks-20090810-0.patch --]
[-- Type: text/x-diff, Size: 3367 bytes --]
diff --git a/lisp/face-remap.el b/lisp/face-remap.el
index c899a8d..53e99ec 100644
--- a/lisp/face-remap.el
+++ b/lisp/face-remap.el
@@ -203,6 +203,19 @@ Each positive or negative step scales the default face height by this amount."
(defvar text-scale-mode-amount 0)
(make-variable-buffer-local 'text-scale-mode-amount)
+(defvar text-scale-mode-old-scale-factor nil
+ "Previously active scale factor for default face :height
+attribute when `text-scale-mode-hook' is called, or nil if
+text-scale-mode was not previously active (meaning the old scale
+factor was 1.0).")
+(make-variable-buffer-local 'text-scale-mode-old-scale-factor)
+
+(defvar text-scale-mode-scale-factor nil
+ "Scale factor for default face :height attribute when
+`text-scale-mode-hook' is called, or nil if text-scale-mode will
+be deactivated (meaning the scale factor is 1.0).")
+(make-variable-buffer-local 'text-scale-mode-scale-factor)
+
(define-minor-mode text-scale-mode
"Minor mode for displaying buffer text in a larger/smaller font than usual.
@@ -221,14 +234,55 @@ disable `text-scale-mode' as necessary)."
(setq text-scale-mode-lighter
(format (if (>= text-scale-mode-amount 0) "+%d" "%d")
text-scale-mode-amount))
+ (setq text-scale-mode-old-scale-factor
+ (nth 2 text-scale-mode-remapping))
+ (setq text-scale-mode-scale-factor
+ (and text-scale-mode
+ (expt text-scale-mode-step text-scale-mode-amount)))
(setq text-scale-mode-remapping
(and text-scale-mode
(face-remap-add-relative 'default
- :height
- (expt text-scale-mode-step
- text-scale-mode-amount))))
+ :height text-scale-mode-scale-factor)))
(force-window-update (current-buffer)))
+(defun text-scale-mode-adjust-window-horizontal-size ()
+ "Change the horizontal size of the current window corresponding to ratio
+`text-scale-mode-scale-factor / text-scale-mode-old-scale-factor'.
+
+This function is intended to be used as a hook for `text-scale-mode-hook'."
+ (let* ((edges (window-edges))
+ (owidth (- (nth 2 edges) (nth 0 edges)))
+ (scale-factor
+ (/ (or text-scale-mode-scale-factor 1.0)
+ (or text-scale-mode-old-scale-factor 1.0))))
+ (condition-case nil
+ (enlarge-window-horizontally
+ (round (- (* owidth scale-factor) owidth)))
+ (error nil))))
+
+(defun text-scale-mode-adjust-window-vertical-size ()
+ "Change the vertical size of the current window corresponding to ratio
+`text-scale-mode-scale-factor / text-scale-mode-old-scale-factor'.
+
+This function is intended to be used as a hook for `text-scale-mode-hook'."
+ (let* ((edges (window-edges))
+ (oheight (- (nth 3 edges) (nth 1 edges)))
+ (scale-factor
+ (/ (or text-scale-mode-scale-factor 1.0)
+ (or text-scale-mode-old-scale-factor 1.0))))
+ (condition-case nil
+ (enlarge-window
+ (round (- (* oheight scale-factor) oheight)))
+ (error nil))))
+
+(defun text-scale-mode-adjust-window-size ()
+ "Change the size of the current window corresponding to ratio
+`text-scale-mode-scale-factor / text-scale-mode-old-scale-factor'.
+
+This function is intended to be used as a hook for `text-scale-mode-hook'."
+ (text-scale-mode-adjust-window-vertical-size)
+ (text-scale-mode-adjust-window-horizontal-size))
+
;;;###autoload
(defun text-scale-set (level)
"Set the scale factor of the default face in the current buffer to LEVEL.
next prev parent reply other threads:[~2009-08-10 5:04 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-08-10 1:04 face-remap.el patch to resize window Drew Adams
2009-08-10 3:00 ` Stefan Monnier
2009-08-10 3:27 ` Drew Adams
2009-08-10 5:04 ` Miles Bader [this message]
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
-- strict thread matches above, loose matches on Subject: below --
2009-06-29 22:10 Drew Adams
2009-06-22 20:40 Drew Adams
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=871vnkfee9.fsf@catnip.gol.com \
--to=miles@gnu.org \
--cc=drew.adams@oracle.com \
--cc=emacs-devel@gnu.org \
--cc=monnier@iro.umontreal.ca \
/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.