changeset 95527:0f9689c194e6

Add adjust-buffer-face-height command ... and move face-height adjustment bindings into ctl-x-map using it. Revision: emacs@sv.gnu.org/emacs--devo--0--patch-1203
author Miles Bader <miles@gnu.org>
date Wed, 04 Jun 2008 05:38:04 +0000
parents 437d3830a398
children 40ef1e044cad
files doc/emacs/ChangeLog doc/emacs/display.texi lisp/ChangeLog lisp/face-remap.el
diffstat 4 files changed, 103 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/doc/emacs/ChangeLog	Tue Jun 03 22:56:56 2008 +0000
+++ b/doc/emacs/ChangeLog	Wed Jun 04 05:38:04 2008 +0000
@@ -1,3 +1,10 @@
+2008-06-04  Miles Bader  <miles@gnu.org>
+
+	* display.texi (Temporary Face Changes): Add
+	`adjust-buffer-face-height'.  Rewrite description of
+	`increase-buffer-face-height' and `decrease-default-face-height' now
+	that they aren't bound by default.
+
 2008-06-03  Miles Bader  <miles@gnu.org>
 
 	* display.texi (Temporary Face Changes): New node.
--- a/doc/emacs/display.texi	Tue Jun 03 22:56:56 2008 +0000
+++ b/doc/emacs/display.texi	Wed Jun 04 05:38:04 2008 +0000
@@ -1178,24 +1178,48 @@
 These are commands which temporarily change the default face used to
 display text in a buffer.
 
+@cindex adjust buffer face height
+@findex adjust-buffer-face-height
+@kindex C-x C-+
+@kindex C-x C--
+@kindex C-x C-=
+@kindex C-x C-0
+To increase the height of the default face in the current buffer one
+step, type @kbd{C-x C-+} or @kbd{C-x C-=}.  To decrease it one step,
+type @kbd{C-x C--}.  To restore the default (global) face height, type
+@kbd{C-x C-0}.  These keys are all bound to the same command,
+@code{adjust-buffer-face-height}, which looks at the last key typed to
+determine the adjustment to make.
+
+The final key of these commands may be repeated without the leading
+@kbd{C-x} -- for instance, @kbd{C-x C-= C-= C-=} increases the face
+height by three steps.
+
+Each step scales the height of the default face by the value of the
+variable @code{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.
+
+This command is a special-purpose wrapper around the
+@code{increase-buffer-face-height} command which makes repetition
+convenient even when it is bound in a non-top-level keymap.  For
+binding in a top-level keymap, @code{increase-buffer-face-height} or
+@code{decrease-default-face-height} may be more appropriate."
+
 @cindex increase buffer face height
 @findex increase-buffer-face-height
 @cindex decrease buffer face height
 @findex decrease-buffer-face-height
-@findex text-scale-mode
-To increase the size of the font used to display text in the current
-buffer, type @kbd{C-=} or @kbd{C-+}
-(@code{increase-buffer-face-height}).  With a numeric prefix argument,
-the size will be increased by that many steps (the default is 1 step);
-each step scales the font height by the value of the variable
-@code{text-scale-mode-step}.  If repeated, this command has a
+The @code{increase-buffer-face-height} and
+@code{decrease-buffer-face-height} commands increase or decrease the
+height of the default face in the current buffer by one step.  With a
+numeric prefix argument, the size will be increased/decreased by that
+many steps; each step scales the font height by the value of the
+variable @code{text-scale-mode-step}.  If repeated, this command has a
 cumulative effect.  As a special case, a prefix argument of 0 will
 remove any scaling currently active.
 
-To decrease the size of the text, type @kbd{C--}
-(@code{decrease-buffer-face-height}).  The behavior is similar to that
-of @code{increase-buffer-face-height}, but in reverse.
-
+@findex text-scale-mode
 These commands automatically enable or disable the
 @code{text-scale-mode} minor-mode, depending on whether the current
 font scaling is other than 1 or not.
--- a/lisp/ChangeLog	Tue Jun 03 22:56:56 2008 +0000
+++ b/lisp/ChangeLog	Wed Jun 04 05:38:04 2008 +0000
@@ -1,3 +1,10 @@
+2008-06-04  Miles Bader  <miles@gnu.org>
+
+	* face-remap.el (adjust-buffer-face-height): New function.
+	Add autoloaded keybindings in ctl-x-map.
+	(increase-buffer-face-height, decrease-buffer-face-height):
+	Simplify interactive spec to just "p".  Remove autoloaded keybindings.
+
 2008-06-03  Chong Yidong  <cyd@stupidchicken.com>
 
 	* simple.el (line-move-1): If we did not move as far as desired,
--- a/lisp/face-remap.el	Tue Jun 03 22:56:56 2008 +0000
+++ b/lisp/face-remap.el	Wed Jun 04 05:38:04 2008 +0000
@@ -181,8 +181,6 @@
 						text-scale-mode-amount))))
   (force-window-update (current-buffer)))
 
-;;;###autoload (global-set-key [(control =)] 'increase-buffer-face-height)
-;;;###autoload (global-set-key [(control +)] 'increase-buffer-face-height)
 ;;;###autoload
 (defun increase-buffer-face-height (&optional inc)
   "Increase the height of the default face in the current buffer by INC steps.
@@ -192,28 +190,69 @@
 `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
-   (list
-    (cond ((eq current-prefix-arg '-) -1)
-	  ((numberp current-prefix-arg) current-prefix-arg)
-	  ((consp current-prefix-arg) -1)
-	  (t 1))))
+  (interactive "p")
   (setq text-scale-mode-amount (if (= inc 0) 0 (+ text-scale-mode-amount inc)))
   (text-scale-mode (if (zerop text-scale-mode-amount) -1 1)))
 
-;;;###autoload (global-set-key [(control -)] 'decrease-buffer-face-height)
 ;;;###autoload
 (defun decrease-buffer-face-height (&optional dec)
   "Decrease the height of the default face in the current buffer by DEC steps.
 See `increase-buffer-face-height' for more details."
-  (interactive
-   (list
-    (cond ((eq current-prefix-arg '-) -1)
-	  ((numberp current-prefix-arg) current-prefix-arg)
-	  ((consp current-prefix-arg) -1)
-	  (t 1))))
+  (interactive "p")
   (increase-buffer-face-height (- dec)))
 
+;;;###autoload (define-key ctl-x-map [(control ?+)] 'adjust-buffer-face-height)
+;;;###autoload (define-key ctl-x-map [(control ?-)] 'adjust-buffer-face-height)
+;;;###autoload (define-key ctl-x-map [(control ?=)] 'adjust-buffer-face-height)
+;;;###autoload (define-key ctl-x-map [(control ?0)] 'adjust-buffer-face-height)
+;;;###autoload
+(defun adjust-buffer-face-height (&optional inc)
+  "Increase or decrease the height of the default face in the current buffer.
+
+The actual adjustment made depends on the final component of the
+key-binding used to invoke the command, with all modifiers
+removed:
+
+   +, =   Increase the default face height by one step
+   -      Decrease the default face height by one step
+   0      Reset the default face height to the global default
+
+Then, continue to read input events and further adjust the face
+height as long as the input event read (with all modifiers
+removed) is one the above.
+
+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.
+
+This command is a special-purpose wrapper around the
+`increase-buffer-face-height' command which makes repetition
+convenient even when it is bound in a non-top-level keymap.  For
+binding in a top-level keymap, `increase-buffer-face-height' or
+`decrease-default-face-height' may be more appropriate."
+  (interactive "p")
+  (let ((first t) 
+	(step t)
+	(ev last-command-event))
+    (while step
+      (let ((base (event-basic-type ev)))
+	(cond ((or (eq base ?+) (eq base ?=))
+	       (setq step inc))
+	      ((eq base ?-)
+	       (setq step (- inc)))
+	      ((eq base ?0)
+	       (setq step 0))
+	      (first 
+	       (setq step inc))
+	      (t
+	       (setq step nil))))
+      (when step
+	(increase-buffer-face-height step)
+	(setq inc 1 first nil)
+	(setq ev (read-event))))
+    (push ev unread-command-events)))
+
 
 ;; ----------------------------------------------------------------
 ;; variable-pitch-mode