From 673c1168a07b3c26b0d7e01e049f7226fcc91b00 Mon Sep 17 00:00:00 2001 From: Chong Yidong Date: Sat, 31 Oct 2009 21:52:53 +0000 Subject: [PATCH] * textmodes/sgml-mode.el (sgml-mode-facemenu-add-face-function): Support face colors. * textmodes/tex-mode.el (tex-facemenu-add-face-function): New function. Support face colors (Bug#1168). (tex-common-initialization): Use it. * facemenu.el (facemenu-enable-faces-p): Enable facemenu if the mode allows it (Bug#1168). --- lisp/ChangeLog | 12 ++++++++++++ lisp/facemenu.el | 5 ++++- lisp/textmodes/sgml-mode.el | 24 ++++++++++++++++++------ lisp/textmodes/tex-mode.el | 17 ++++++++++++++--- 4 files changed, 48 insertions(+), 10 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 6a4babdd227..c250b2ddef4 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,15 @@ +2009-10-31 Chong Yidong + + * textmodes/sgml-mode.el (sgml-mode-facemenu-add-face-function): + Support face colors. + + * textmodes/tex-mode.el (tex-facemenu-add-face-function): New + function. Support face colors (Bug#1168). + (tex-common-initialization): Use it. + + * facemenu.el (facemenu-enable-faces-p): Enable facemenu if the + mode allows it (Bug#1168). + 2009-10-31 Juri Linkov * facemenu.el (list-colors-display): Don't mark buffer as diff --git a/lisp/facemenu.el b/lisp/facemenu.el index aedb6d355b6..389fbf804e0 100644 --- a/lisp/facemenu.el +++ b/lisp/facemenu.el @@ -187,7 +187,10 @@ it will remove any faces not explicitly in the list." ;;; Condition for enabling menu items that set faces. (defun facemenu-enable-faces-p () - (not (and font-lock-mode font-lock-defaults))) + ;; Enable the facemenu if facemenu-add-face-function is defined + ;; (e.g. in Tex-mode and SGML mode), or if font-lock is off. + (or (not (and font-lock-mode font-lock-defaults)) + facemenu-add-face-function)) (defvar facemenu-special-menu (let ((map (make-sparse-keymap "Special"))) diff --git a/lisp/textmodes/sgml-mode.el b/lisp/textmodes/sgml-mode.el index 26360df261b..52d0a70e257 100644 --- a/lisp/textmodes/sgml-mode.el +++ b/lisp/textmodes/sgml-mode.el @@ -397,12 +397,24 @@ a DOCTYPE or an XML declaration." (comment-indent-new-line soft))) (defun sgml-mode-facemenu-add-face-function (face end) - (if (setq face (cdr (assq face sgml-face-tag-alist))) - (progn - (setq face (funcall skeleton-transformation-function face)) - (setq facemenu-end-add-face (concat "")) - (concat "<" face ">")) - (error "Face not configured for %s mode" (format-mode-line mode-name)))) + (let ((tag-face (cdr (assq face sgml-face-tag-alist)))) + (cond (tag-face + (setq tag-face (funcall skeleton-transformation-function tag-face)) + (setq facemenu-end-add-face (concat "")) + (concat "<" tag-face ">")) + ((and (consp face) + (consp (car face)) + (null (cdr face)) + (memq (caar face) '(:foreground :background))) + (setq facemenu-end-add-face "") + (format "" + (if (eq (caar face) :foreground) + "color" + "background-color") + (cadr (car face)))) + (t + (error "Face not configured for %s mode" + (format-mode-line mode-name)))))) (defun sgml-fill-nobreak () ;; Don't break between a tag name and its first argument. diff --git a/lisp/textmodes/tex-mode.el b/lisp/textmodes/tex-mode.el index db873483579..40d26ee380e 100644 --- a/lisp/textmodes/tex-mode.el +++ b/lisp/textmodes/tex-mode.el @@ -860,6 +860,19 @@ Inherits `shell-mode-map' with a few additions.") ,@tex-face-alist) "Alist of face and LaTeX font name for facemenu.") +(defun tex-facemenu-add-face-function (face end) + (or (cdr (assq face tex-face-alist)) + (or (and (consp face) + (consp (car face)) + (null (cdr face)) + (eq major-mode 'latex-mode) + ;; This actually requires the `color' LaTeX package. + (cond ((eq (caar face) :foreground) + (format "{\\color{%s} " (cadr (car face)))) + ((eq (caar face) :background) + (format "\\colorbox{%s}{" (cadr (car face)))))) + (error "Face %s not configured for %s mode" face mode-name)))) + ;; This would be a lot simpler if we just used a regexp search, ;; but then it would be too slow. (defun tex-guess-mode () @@ -1131,9 +1144,7 @@ Entering SliTeX mode runs the hook `text-mode-hook', then the hook (set (make-local-variable 'compare-windows-whitespace) 'tex-categorize-whitespace) (set (make-local-variable 'facemenu-add-face-function) - (lambda (face end) - (or (cdr (assq face tex-face-alist)) - (error "Face %s not configured for %s mode" face mode-name)))) + 'tex-facemenu-add-face-function) (set (make-local-variable 'facemenu-end-add-face) "}") (set (make-local-variable 'facemenu-remove-face-function) t) (set (make-local-variable 'font-lock-defaults) -- 2.39.5