changeset 96042:dfc9ab5fbea5

Add buffer-face-mode Revision: emacs@sv.gnu.org/emacs--devo--0--patch-1251
author Miles Bader <miles@gnu.org>
date Tue, 17 Jun 2008 11:27:51 +0000
parents c89004e8d9a9
children a678c02d0c40
files lisp/ChangeLog lisp/face-remap.el
diffstat 2 files changed, 83 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/ChangeLog	Tue Jun 17 11:27:36 2008 +0000
+++ b/lisp/ChangeLog	Tue Jun 17 11:27:51 2008 +0000
@@ -1,5 +1,12 @@
 2008-06-17  Miles Bader  <miles@gnu.org>
 
+	* face-remap.el (buffer-face-mode-face)
+	(buffer-face-mode-remapping): New variables.
+	(buffer-face-mode, buffer-face-set, buffer-face-toggle)
+	(buffer-face-mode-invoke): New functions.
+	(variable-pitch-mode-remapping): Variable removed.
+	(variable-pitch-mode): Rewrite as an interface to `buffer-face-mode'.
+
 	* face-remap.el (internal-lisp-face-attributes): New variable.
 	(face-attrs-more-relative-p, face-remap-order): New functions.
 	(face-remap-add-relative): Use `face-remap-order'.
--- a/lisp/face-remap.el	Tue Jun 17 11:27:36 2008 +0000
+++ b/lisp/face-remap.el	Tue Jun 17 11:27:51 2008 +0000
@@ -297,26 +297,87 @@
 
 
 ;; ----------------------------------------------------------------
-;; variable-pitch-mode
+;; buffer-face-mode
 
-;; suggested key binding: (global-set-key "\C-cv" 'variable-pitch-mode)
+(defcustom buffer-face-mode-face 'variable-pitch
+  "The face specification used by `buffer-face-mode'.
+It may contain any value suitable for a `face' text property,
+including a face name, a list of face names, a face-attribute
+plist, etc."
+  :group 'display)
+
+;; current remapping cookie for  buffer-face-mode
+(defvar buffer-face-mode-remapping nil)
+(make-variable-buffer-local 'buffer-face-mode-remapping)
 
-;; current remapping cookie for  variable-pitch-mode
-(defvar variable-pitch-mode-remapping nil)
-(make-variable-buffer-local 'variable-pitch-mode-remapping)
+;;;###autoload
+(define-minor-mode buffer-face-mode
+  "Minor mode for a buffer-specific default face.
+When enabled, the face specified by the variable
+`buffer-face-mode-face' is used to display the buffer text."
+  :lighter " BufFace"
+  (when buffer-face-mode-remapping
+    (face-remap-remove-relative buffer-face-mode-remapping))
+  (setq buffer-face-mode-remapping
+	(and buffer-face-mode
+	     (face-remap-add-relative 'default buffer-face-mode-face)))
+  (force-window-update (current-buffer)))
+
+;;;###autoload
+(defun buffer-face-set (face)
+  "Enable `buffer-face-mode', using the face FACE.
+If FACE is nil, then `buffer-face-mode' is disabled.  This
+function will make the variable `buffer-face-mode-face' buffer
+local, and set it to FACE."
+  (interactive (list (read-face-name "Set buffer face")))
+  (if (null face)
+      (buffer-face-mode 0)
+    (set (make-local-variable 'buffer-face-mode-face) face)
+    (buffer-face-mode t)))
 
 ;;;###autoload
-(define-minor-mode variable-pitch-mode
+(defun buffer-face-toggle (face)
+  "Toggle `buffer-face-mode', using the face FACE.
+
+If `buffer-face-mode' is already enabled, and is currently using
+the face FACE, then it is disabled; if buffer-face-mode is
+disabled, or is enabled and currently displaying some other face,
+then is left enabled, but the face changed to FACE.  This
+function will make the variable `buffer-face-mode-face' buffer
+local, and set it to FACE."
+  (interactive (list buffer-face-mode-face))
+  (if (or (null face)
+	  (and buffer-face-mode (equal buffer-face-mode-face face)))
+      (buffer-face-mode 0)
+    (set (make-local-variable 'buffer-face-mode-face) face)
+    (buffer-face-mode t)))
+
+(defun buffer-face-mode-invoke (face arg &optional interactive)
+  "Enable or disable `buffer-face-mode' using the face FACE, and argument ARG.
+ARG is interpreted in the usual manner for minor-mode commands.
+Besides the choice of face, this is the same as the `buffer-face-mode' command.
+If INTERACTIVE is non-nil, a message will be displayed describing the result."
+  (let ((last-message (current-message)))
+    (if (or (eq arg 'toggle) (not arg))
+	(buffer-face-toggle face)
+      (buffer-face-set (and (> (prefix-numeric-value arg) 0) face)))
+    (when interactive
+      (unless (and (current-message)
+		   (not (equal last-message (current-message))))
+	(message "Buffer-Face mode %sabled"
+		 (if buffer-face-mode "en" "dis"))))))
+
+
+;; ----------------------------------------------------------------
+;; variable-pitch-mode
+
+;;;###autoload
+(defun variable-pitch-mode (&optional arg)
   "Variable-pitch default-face mode.
-When active, causes the buffer text to be displayed using
-the `variable-pitch' face."
-  :lighter " VarPitch"
-  (when variable-pitch-mode-remapping
-    (face-remap-remove-relative variable-pitch-mode-remapping))
-  (setq variable-pitch-mode-remapping
-	(and variable-pitch-mode
-	     (face-remap-add-relative 'default 'variable-pitch)))
-  (force-window-update (current-buffer)))
+An interface to `buffer-face-mode' which uses the `variable-pitch' face.
+Besides the choice of face, it is the same as `buffer-face-mode'."
+  (interactive (list (or current-prefix-arg 'toggle)))
+  (buffer-face-mode-invoke 'variable-pitch arg (interactive-p)))
 
 
 (provide 'face-remap)