]> git.eshelyaron.com Git - emacs.git/commitdiff
* textmodes/sgml-mode.el (sgml-mode-facemenu-add-face-function):
authorChong Yidong <cyd@stupidchicken.com>
Sat, 31 Oct 2009 21:52:53 +0000 (21:52 +0000)
committerChong Yidong <cyd@stupidchicken.com>
Sat, 31 Oct 2009 21:52:53 +0000 (21:52 +0000)
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
lisp/facemenu.el
lisp/textmodes/sgml-mode.el
lisp/textmodes/tex-mode.el

index 6a4babdd227ad4c1a94e181f26b73ed59d6f1fb3..c250b2ddef4b4205d094ae9516321513cc2dcd20 100644 (file)
@@ -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
index aedb6d355b62d72222575d2c6941c877febc7da6..389fbf804e043760c88eb8b1c0d8063e899d7d88 100644 (file)
@@ -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")))
index 26360df261bcfa6c2ae768d2ff911a9d6c7c6fe2..52d0a70e257b8a4ca7cffe4a2ca5c55043baae4b 100644 (file)
@@ -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 "</" 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.
index db873483579104226b868b57928b41e57646c55d..40d26ee380e006f0e4a735fef5b30311b2107848 100644 (file)
@@ -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)