changeset 105821:18698b6aca31

* 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).
author Chong Yidong <cyd@stupidchicken.com>
date Sat, 31 Oct 2009 21:52:53 +0000
parents ea3a6d116908
children 59656f4a5cda
files lisp/ChangeLog lisp/facemenu.el lisp/textmodes/sgml-mode.el lisp/textmodes/tex-mode.el
diffstat 4 files changed, 48 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/ChangeLog	Sat Oct 31 20:16:50 2009 +0000
+++ b/lisp/ChangeLog	Sat Oct 31 21:52:53 2009 +0000
@@ -1,3 +1,15 @@
+2009-10-31  Chong Yidong  <cyd@stupidchicken.com>
+
+	* 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  <juri@jurta.org>
 
 	* facemenu.el (list-colors-display): Don't mark buffer as
--- a/lisp/facemenu.el	Sat Oct 31 20:16:50 2009 +0000
+++ b/lisp/facemenu.el	Sat Oct 31 21:52:53 2009 +0000
@@ -187,7 +187,10 @@
 
 ;;; 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")))
--- a/lisp/textmodes/sgml-mode.el	Sat Oct 31 20:16:50 2009 +0000
+++ b/lisp/textmodes/sgml-mode.el	Sat Oct 31 21:52:53 2009 +0000
@@ -397,12 +397,24 @@
     (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 "</" face ">"))
-	(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 "</" tag-face ">"))
+	   (concat "<" tag-face ">"))
+	  ((and (consp face)
+		(consp (car face))
+		(null  (cdr face))
+		(memq (caar face) '(:foreground :background)))
+	   (setq facemenu-end-add-face "</span>")
+	   (format "<span style=\"%s:%s\">"
+		   (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.
--- a/lisp/textmodes/tex-mode.el	Sat Oct 31 20:16:50 2009 +0000
+++ b/lisp/textmodes/tex-mode.el	Sat Oct 31 21:52:53 2009 +0000
@@ -860,6 +860,19 @@
     ,@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 @@
   (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)