From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Miles Bader Newsgroups: gmane.emacs.devel Subject: Re: face-remap.el patch to resize window Date: Mon, 10 Aug 2009 14:04:30 +0900 Message-ID: <871vnkfee9.fsf@catnip.gol.com> References: <7D6750DD60204DB082A761ECEE706CEA@us.oracle.com> <2DD5D9B518394F17A3AA77158B671255@us.oracle.com> Reply-To: Miles Bader NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1249880697 30356 80.91.229.12 (10 Aug 2009 05:04:57 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 10 Aug 2009 05:04:57 +0000 (UTC) Cc: 'Stefan Monnier' , emacs-devel@gnu.org To: "Drew Adams" Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Aug 10 07:04:50 2009 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 1MaN3x-00084A-Go for ged-emacs-devel@m.gmane.org; Mon, 10 Aug 2009 07:04:49 +0200 Original-Received: from localhost ([127.0.0.1]:33667 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MaN3w-0007c7-NG for ged-emacs-devel@m.gmane.org; Mon, 10 Aug 2009 01:04:48 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MaN3q-0007c2-Sv for emacs-devel@gnu.org; Mon, 10 Aug 2009 01:04:42 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MaN3m-0007be-2K for emacs-devel@gnu.org; Mon, 10 Aug 2009 01:04:42 -0400 Original-Received: from [199.232.76.173] (port=39899 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MaN3l-0007bZ-UW for emacs-devel@gnu.org; Mon, 10 Aug 2009 01:04:37 -0400 Original-Received: from smtp11.dentaku.gol.com ([203.216.5.73]:54335) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1MaN3i-0008Pi-Kg; Mon, 10 Aug 2009 01:04:35 -0400 Original-Received: from 218.231.177.167.eo.eaccess.ne.jp ([218.231.177.167] helo=catnip.gol.com) by smtp11.dentaku.gol.com with esmtpa (Dentaku) id 1MaN3f-0008B3-L8; Mon, 10 Aug 2009 14:04:31 +0900 Original-Received: by catnip.gol.com (Postfix, from userid 1000) id CABD2DF94; Mon, 10 Aug 2009 14:04:30 +0900 (JST) System-Type: x86_64-unknown-linux-gnu In-Reply-To: <2DD5D9B518394F17A3AA77158B671255@us.oracle.com> (Drew Adams's message of "Sun, 9 Aug 2009 20:27:49 -0700") Original-Lines: 16 X-Virus-Scanned: ClamAV GOL (outbound) X-Abuse-Complaints: abuse@gol.com X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 3) 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:113941 Archived-At: --=-=-= 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. --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=text-scale-mode-hooks-20090810-0.patch Content-Description: text-scale-mode-hooks-20090810-0.patch 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. --=-=-=--