comparison lisp/face-remap.el @ 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 2b046bd8b819
comparison
equal deleted inserted replaced
96041:c89004e8d9a9 96042:dfc9ab5fbea5
295 (setq ev (read-event)))) 295 (setq ev (read-event))))
296 (push ev unread-command-events))) 296 (push ev unread-command-events)))
297 297
298 298
299 ;; ---------------------------------------------------------------- 299 ;; ----------------------------------------------------------------
300 ;; buffer-face-mode
301
302 (defcustom buffer-face-mode-face 'variable-pitch
303 "The face specification used by `buffer-face-mode'.
304 It may contain any value suitable for a `face' text property,
305 including a face name, a list of face names, a face-attribute
306 plist, etc."
307 :group 'display)
308
309 ;; current remapping cookie for buffer-face-mode
310 (defvar buffer-face-mode-remapping nil)
311 (make-variable-buffer-local 'buffer-face-mode-remapping)
312
313 ;;;###autoload
314 (define-minor-mode buffer-face-mode
315 "Minor mode for a buffer-specific default face.
316 When enabled, the face specified by the variable
317 `buffer-face-mode-face' is used to display the buffer text."
318 :lighter " BufFace"
319 (when buffer-face-mode-remapping
320 (face-remap-remove-relative buffer-face-mode-remapping))
321 (setq buffer-face-mode-remapping
322 (and buffer-face-mode
323 (face-remap-add-relative 'default buffer-face-mode-face)))
324 (force-window-update (current-buffer)))
325
326 ;;;###autoload
327 (defun buffer-face-set (face)
328 "Enable `buffer-face-mode', using the face FACE.
329 If FACE is nil, then `buffer-face-mode' is disabled. This
330 function will make the variable `buffer-face-mode-face' buffer
331 local, and set it to FACE."
332 (interactive (list (read-face-name "Set buffer face")))
333 (if (null face)
334 (buffer-face-mode 0)
335 (set (make-local-variable 'buffer-face-mode-face) face)
336 (buffer-face-mode t)))
337
338 ;;;###autoload
339 (defun buffer-face-toggle (face)
340 "Toggle `buffer-face-mode', using the face FACE.
341
342 If `buffer-face-mode' is already enabled, and is currently using
343 the face FACE, then it is disabled; if buffer-face-mode is
344 disabled, or is enabled and currently displaying some other face,
345 then is left enabled, but the face changed to FACE. This
346 function will make the variable `buffer-face-mode-face' buffer
347 local, and set it to FACE."
348 (interactive (list buffer-face-mode-face))
349 (if (or (null face)
350 (and buffer-face-mode (equal buffer-face-mode-face face)))
351 (buffer-face-mode 0)
352 (set (make-local-variable 'buffer-face-mode-face) face)
353 (buffer-face-mode t)))
354
355 (defun buffer-face-mode-invoke (face arg &optional interactive)
356 "Enable or disable `buffer-face-mode' using the face FACE, and argument ARG.
357 ARG is interpreted in the usual manner for minor-mode commands.
358 Besides the choice of face, this is the same as the `buffer-face-mode' command.
359 If INTERACTIVE is non-nil, a message will be displayed describing the result."
360 (let ((last-message (current-message)))
361 (if (or (eq arg 'toggle) (not arg))
362 (buffer-face-toggle face)
363 (buffer-face-set (and (> (prefix-numeric-value arg) 0) face)))
364 (when interactive
365 (unless (and (current-message)
366 (not (equal last-message (current-message))))
367 (message "Buffer-Face mode %sabled"
368 (if buffer-face-mode "en" "dis"))))))
369
370
371 ;; ----------------------------------------------------------------
300 ;; variable-pitch-mode 372 ;; variable-pitch-mode
301 373
302 ;; suggested key binding: (global-set-key "\C-cv" 'variable-pitch-mode) 374 ;;;###autoload
303 375 (defun variable-pitch-mode (&optional arg)
304 ;; current remapping cookie for variable-pitch-mode
305 (defvar variable-pitch-mode-remapping nil)
306 (make-variable-buffer-local 'variable-pitch-mode-remapping)
307
308 ;;;###autoload
309 (define-minor-mode variable-pitch-mode
310 "Variable-pitch default-face mode. 376 "Variable-pitch default-face mode.
311 When active, causes the buffer text to be displayed using 377 An interface to `buffer-face-mode' which uses the `variable-pitch' face.
312 the `variable-pitch' face." 378 Besides the choice of face, it is the same as `buffer-face-mode'."
313 :lighter " VarPitch" 379 (interactive (list (or current-prefix-arg 'toggle)))
314 (when variable-pitch-mode-remapping 380 (buffer-face-mode-invoke 'variable-pitch arg (interactive-p)))
315 (face-remap-remove-relative variable-pitch-mode-remapping))
316 (setq variable-pitch-mode-remapping
317 (and variable-pitch-mode
318 (face-remap-add-relative 'default 'variable-pitch)))
319 (force-window-update (current-buffer)))
320 381
321 382
322 (provide 'face-remap) 383 (provide 'face-remap)
323 384
324 ;; arch-tag: 5c5f034b-8d58-4967-82bd-d61fd364e686 385 ;; arch-tag: 5c5f034b-8d58-4967-82bd-d61fd364e686