Revision: miles@gnu.org--gnu-2005/emacs--unicode--0--patch-71
[bpt/emacs.git] / lisp / faces.el
index 36f207b..733d7ca 100644 (file)
@@ -1,6 +1,6 @@
 ;;; faces.el --- Lisp faces
 
-;; Copyright (C) 1992,1993,1994,1995,1996,1998,1999,2000,2001,2002,2004
+;; Copyright (C) 1992,1993,1994,1995,1996,1998,1999,2000,2001,2002,2004,2005
 ;;   Free Software Foundation, Inc.
 
 ;; Maintainer: FSF
@@ -20,8 +20,8 @@
 
 ;; You should have received a copy of the GNU General Public License
 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
-;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
 
 ;;; Commentary:
 
@@ -183,10 +183,7 @@ Return nil if there is no such face.
 If the optional argument FRAME is given, this gets the face NAME for
 that frame; otherwise, it uses the selected frame.
 If FRAME is the symbol t, then the global, non-frame face is returned.
-If NAME is already a face, it is simply returned.
-
-This function is defined for compatibility with Emacs 20.2.  It
-should not be used anymore."
+If NAME is already a face, it is simply returned."
   (facep name))
 (make-obsolete 'internal-find-face 'facep "21.1")
 
@@ -207,7 +204,10 @@ If NAME is already a face, it is simply returned."
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
 (defun facep (face)
-  "Return non-nil if FACE is a face name."
+  "Return non-nil if FACE is a face name or internal face object.
+Return nil otherwise.  A face name can be a string or a symbol.
+An internal face object is a vector of the kind used internally
+to record face data."
   (internal-lisp-face-p face))
 
 
@@ -225,7 +225,8 @@ Value is FACE."
 
 (defun face-id (face &optional frame)
   "Return the internal ID of face with name FACE.
-If optional argument FRAME is nil or omitted, use the selected frame."
+The optional argument FRAME is ignored, since the internal face ID
+of a face name is the same for all frames."
   (check-face face)
   (get face 'face))
 
@@ -233,8 +234,8 @@ If optional argument FRAME is nil or omitted, use the selected frame."
 (defun face-equal (face1 face2 &optional frame)
   "Non-nil if faces FACE1 and FACE2 are equal.
 Faces are considered equal if all their attributes are equal.
-If the optional argument FRAME is given, report on face FACE in that frame.
-If FRAME is t, report on the defaults for face FACE (for new frames).
+If the optional argument FRAME is given, report on FACE1 and FACE2 in that frame.
+If FRAME is t, report on the defaults for FACE1 and FACE2 (for new frames).
 If FRAME is omitted or nil, use the selected frame."
   (internal-lisp-face-equal-p face1 face2 frame))
 
@@ -384,7 +385,7 @@ completely specified)."
 (defun face-attribute-merged-with (attribute value faces &optional frame)
   "Merges ATTRIBUTE, initially VALUE, with faces from FACES until absolute.
 FACES may be either a single face or a list of faces.
-\[This is an internal function]"
+\[This is an internal function.]"
   (cond ((not (face-attribute-relative-p attribute value))
         value)
        ((null faces)
@@ -515,8 +516,17 @@ Use `face-attribute' for finer control."
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
 (defun face-documentation (face)
-  "Get the documentation string for FACE."
-  (get face 'face-documentation))
+  "Get the documentation string for FACE.
+If FACE is a face-alias, get the documentation for the target face."
+  (let ((alias (get face 'face-alias))
+        doc)
+    (if alias
+        (progn
+          (setq doc (get alias 'face-documentation))
+          (format "%s is an alias for the face `%s'.%s" face alias
+                  (if doc (format "\n%s" doc)
+                    "")))
+      (get face 'face-documentation))))
 
 
 (defun set-face-documentation (face string)
@@ -663,7 +673,7 @@ like an underlying face would be, with higher priority than underlying faces."
     (setq args (purecopy args))
     ;; If we set the new-frame defaults, this face is modified outside Custom.
     (if (memq where '(0 t))
-       (put face 'face-modified t))
+       (put (or (get face 'face-alias) face) 'face-modified t))
     (while args
       (internal-set-lisp-face-attribute face (car args)
                                        (purecopy (cadr args))
@@ -856,8 +866,13 @@ If MULTIPLE is non-nil, return a list of faces (possibly only one).
 Otherwise, return a single face."
   (let ((faceprop (or (get-char-property (point) 'read-face-name)
                      (get-char-property (point) 'face)))
+        (aliasfaces nil)
+        (nonaliasfaces nil)
        faces)
-    ;; Make a list of the named faces that the `face' property uses.
+    ;; Try to get a face name from the buffer.
+    (if (memq (intern-soft (thing-at-point 'symbol)) (face-list))
+       (setq faces (list (intern-soft (thing-at-point 'symbol)))))
+    ;; Add the named faces that the `face' property uses.
     (if (and (listp faceprop)
             ;; Don't treat an attribute spec as a list of faces.
             (not (keywordp (car faceprop)))
@@ -867,32 +882,40 @@ Otherwise, return a single face."
              (push f faces)))
       (if (symbolp faceprop)
          (push faceprop faces)))
-    ;; If there are none, try to get a face name from the buffer.
-    (if (and (null faces)
-            (memq (intern-soft (thing-at-point 'symbol)) (face-list)))
-       (setq faces (list (intern-soft (thing-at-point 'symbol)))))
+
+    ;; Build up the completion tables.
+    (mapatoms (lambda (s)
+                (if (custom-facep s)
+                    (if (get s 'face-alias)
+                        (push (symbol-name s) aliasfaces)
+                      (push (symbol-name s) nonaliasfaces)))))
 
     ;; If we only want one, and the default is more than one,
     ;; discard the unwanted ones now.
     (unless multiple
       (if faces
          (setq faces (list (car faces)))))
+    (require 'crm)
     (let* ((input
            ;; Read the input.
-           (completing-read
+           (completing-read-multiple
             (if (or faces string-describing-default)
                 (format "%s (default %s): " prompt
-                        (if faces (mapconcat 'symbol-name faces ", ")
+                        (if faces (mapconcat 'symbol-name faces ",")
                           string-describing-default))
               (format "%s: " prompt))
-            obarray 'custom-facep t))
+            (complete-in-turn nonaliasfaces aliasfaces)
+            nil t nil nil
+            (if faces (mapconcat 'symbol-name faces ","))))
           ;; Canonicalize the output.
           (output
-           (if (equal input "")
-               faces
-             (if (stringp input)
-                 (list (intern input))
-               input))))
+           (cond ((or (equal input "") (equal input '("")))
+                  faces)
+                 ((stringp input)
+                  (mapcar 'intern (split-string input ", *" t)))
+                 ((listp input)
+                  (mapcar 'intern input))
+                 (input))))
       ;; Return either a list of faces or just one face.
       (if multiple
          output
@@ -1013,7 +1036,7 @@ name of the attribute for prompting.  Value is the new attribute value."
          ((member new-value '("unspecified-fg" "unspecified-bg"))
           new-value)
          (t
-          (string-to-int new-value)))))
+          (string-to-number new-value)))))
 
 
 (defun read-face-attribute (face attribute &optional frame)
@@ -1072,7 +1095,7 @@ of a global face.  Value is the new attribute value."
 
 (defun read-face-font (face &optional frame)
   "Read the name of a font for FACE on FRAME.
-If optional argument FRAME Is nil or omitted, use the selected frame."
+If optional argument FRAME is nil or omitted, use the selected frame."
   (let ((completion-ignore-case t))
     (completing-read (format "Set font attributes of face `%s' from font: " face)
                     (append (fontset-list) (x-list-fonts "*" nil frame)))))
@@ -1080,7 +1103,7 @@ If optional argument FRAME Is nil or omitted, use the selected frame."
 
 (defun read-all-face-attributes (face &optional frame)
   "Interactively read all attributes for FACE.
-If optional argument FRAME Is nil or omitted, use the selected frame.
+If optional argument FRAME is nil or omitted, use the selected frame.
 Value is a property list of attribute names and new values."
   (let (result)
     (dolist (attribute face-attribute-name-alist result)
@@ -1094,7 +1117,7 @@ Value is a property list of attribute names and new values."
 If optional argument FRAME is nil or omitted, modify the face used
 for newly created frame, i.e. the global face.
 For non-interactive use, `set-face-attribute' is preferred.
-When called from elisp, if FACE is nil, all arguments but FRAME are ignored
+When called from Lisp, if FACE is nil, all arguments but FRAME are ignored
 and the face and its settings are obtained by querying the user."
   (interactive)
   (if face
@@ -1153,16 +1176,24 @@ this regular expression.  When called interactively with a prefix
 arg, prompt for a regular expression."
   (interactive (list (and current-prefix-arg
                           (read-string "List faces matching regexp: "))))
-  (let ((faces (sort (face-list) #'string-lessp))
+  (let ((all-faces (zerop (length regexp)))
        (frame (selected-frame))
+       (max-length 0)
+       faces line-format
        disp-frame window face-name)
-    (when (> (length regexp) 0)
-      (setq faces
-            (delq nil
-                  (mapcar (lambda (f)
-                            (when (string-match regexp (symbol-name f))
-                              f))
-                          faces))))
+    ;; We filter and take the max length in one pass
+    (setq faces
+         (delq nil
+               (mapcar (lambda (f)
+                         (let ((s (symbol-name f)))
+                           (when (or all-faces (string-match regexp s))
+                             (setq max-length (max (length s) max-length))
+                             f)))
+                       (sort (face-list) #'string-lessp))))
+    (unless faces
+      (error "No faces matching \"%s\"" regexp))
+    (setq max-length (1+ max-length)
+         line-format (format "%%-%ds" max-length))
     (with-output-to-temp-buffer "*Faces*"
       (save-excursion
        (set-buffer standard-output)
@@ -1177,12 +1208,13 @@ arg, prompt for a regular expression."
        (setq help-xref-stack nil)
        (dolist (face faces)
          (setq face-name (symbol-name face))
-         (insert (format "%25s " face-name))
+         (insert (format line-format face-name))
          ;; Hyperlink to a customization buffer for the face.  Using
          ;; the help xref mechanism may not be the best way.
          (save-excursion
            (save-match-data
              (search-backward face-name)
+             (setq help-xref-stack-item `(list-faces-display ,regexp))
              (help-xref-button 0 'help-customize-face face)))
          (let ((beg (point))
                (line-beg (line-beginning-position)))
@@ -1201,7 +1233,7 @@ arg, prompt for a regular expression."
            (goto-char beg)
            (forward-line 1)
            (while (not (eobp))
-             (insert "                          ")
+             (insert-char ?\s max-length)
              (forward-line 1))))
        (goto-char (point-min)))
       (print-help-return-message))
@@ -1257,20 +1289,35 @@ If FRAME is omitted or nil, use the selected frame."
          (insert "Face: " (symbol-name f))
          (if (not (facep f))
              (insert "   undefined face.\n")
-           (let ((customize-label "customize this face"))
+           (let ((customize-label "customize this face")
+                 file-name)
              (princ (concat " (" customize-label ")\n"))
              (insert "Documentation: "
                      (or (face-documentation f)
                          "Not documented as a face.")
-                     "\n\n")
+                     "\n")
              (with-current-buffer standard-output
                (save-excursion
                  (re-search-backward
                   (concat "\\(" customize-label "\\)") nil t)
                  (help-xref-button 1 'help-customize-face f)))
+             ;; The next 4 sexps are copied from describe-function-1
+             ;; and simplified.
+             (setq file-name (symbol-file f 'defface))
+             (when file-name
+               (princ "Defined in `")
+               (princ file-name)
+               (princ "'")
+               ;; Make a hyperlink to the library.
+               (save-excursion
+                 (re-search-backward "`\\([^`']+\\)'" nil t)
+                 (help-xref-button 1 'help-face-def f file-name))
+               (princ ".")
+               (terpri)
+               (terpri))
              (dolist (a attrs)
                (let ((attr (face-attribute f (car a) frame)))
-                 (insert (make-string (- max-width (length (cdr a))) ?\ )
+                 (insert (make-string (- max-width (length (cdr a))) ?\s)
                          (cdr a) ": " (format "%s" attr) "\n")))))
          (terpri)))
       (print-help-return-message))))
@@ -1284,7 +1331,7 @@ If FRAME is omitted or nil, use the selected frame."
 ;; face implementation.
 
 (defun face-attr-construct (face &optional frame)
-  "Return a defface-style attribute list for FACE on FRAME.
+  "Return a `defface'-style attribute list for FACE on FRAME.
 Value is a property list of pairs ATTRIBUTE VALUE for all specified
 face attributes of FACE where ATTRIBUTE is the attribute name and
 VALUE is the specified value of that attribute."
@@ -1413,7 +1460,7 @@ If SPEC is nil, do nothing."
   ;; When we reset the face based on its spec, then it is unmodified
   ;; as far as Custom is concerned.
   (if (null frame)
-      (put face 'face-modified nil)))
+      (put (or (get face 'face-alias) face) 'face-modified nil)))
 
 
 (defun face-attr-match-p (face attrs &optional frame)
@@ -1447,7 +1494,8 @@ If there is no default for FACE, return nil."
 (defsubst face-user-default-spec (face)
   "Return the user's customized face-spec for FACE, or the default if none.
 If there is neither a user setting nor a default for FACE, return nil."
-  (or (get face 'saved-face)
+  (or (get face 'customized-face)
+      (get face 'saved-face)
       (face-default-spec face)))
 
 \f
@@ -1519,9 +1567,9 @@ If omitted or nil, that stands for the selected frame's display."
 
 (defcustom frame-background-mode nil
   "*The brightness of the background.
-Set this to the symbol `dark' if your background color is dark, `light' if
-your background is light, or nil (default) if you want Emacs to
-examine the brightness for you.  Don't set this variable with `setq';
+Set this to the symbol `dark' if your background color is dark,
+`light' if your background is light, or nil (default) if you want Emacs
+to examine the brightness for you.  Don't set this variable with `setq';
 this won't have the expected effect."
   :group 'faces
   :set #'(lambda (var value)
@@ -1532,6 +1580,13 @@ this won't have the expected effect."
                 (choice-item light)
                 (choice-item :tag "default" nil)))
 
+(defvar default-frame-background-mode nil
+  "Internal variable for the default brightness of the background.
+Emacs sets it automatically depending on the terminal type.
+The value `nil' means `dark'.  If Emacs runs in non-windowed
+mode from `xterm' or a similar terminal emulator, the value is
+`light'.  On rxvt terminals, the value depends on the environment
+variable COLORFGBG.")
 
 (defun frame-set-background-mode (frame)
   "Set up display-dependent faces on FRAME.
@@ -1547,13 +1602,13 @@ according to the `background-mode' and `display-type' frame parameters."
                 (intern (downcase bg-resource)))
                ((and (null window-system) (null bg-color))
                 ;; No way to determine this automatically (?).
-                'dark)
+                (or default-frame-background-mode 'dark))
                ;; Unspecified frame background color can only happen
                ;; on tty's.
                ((member bg-color '(unspecified "unspecified-bg"))
-                'dark)
+                (or default-frame-background-mode 'dark))
                ((equal bg-color "unspecified-fg") ; inverted colors
-                'light)
+                (if (eq default-frame-background-mode 'light) 'dark 'light))
                ((>= (apply '+ (x-color-values bg-color frame))
                    ;; Just looking at the screen, colors whose
                    ;; values add up to .6 of the white total
@@ -1781,8 +1836,8 @@ created."
 ;; Update the colors of FACE, after FRAME's own colors have been
 ;; changed.
 
-(defalias 'frame-update-face-colors 'frame-set-background-mode)
-(make-obsolete 'frame-update-face-colors 'frame-set-background-mode "21.1")
+(define-obsolete-function-alias 'frame-update-face-colors
+    'frame-set-background-mode "21.1")
 
 \f
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -1827,9 +1882,27 @@ created."
   :group 'modeline
   :group 'basic-faces)
 
+(defface mode-line-highlight
+  '((((class color) (min-colors 88))
+     :box (:line-width 2 :color "grey40" :style released-button))
+    (t
+     :inherit highlight))
+  "Basic mode line face for highlighting."
+  :version "22.1"
+  :group 'modeline
+  :group 'basic-faces)
+
+(defface vertical-border
+  '((((type tty)) :inherit mode-line-inactive))
+  "Face used for vertical window dividers on ttys."
+  :version "22.1"
+  :group 'modeline
+  :group 'basic-faces)
+
 ;; Make `modeline' an alias for `mode-line', for compatibility.
 (put 'modeline 'face-alias 'mode-line)
 (put 'modeline-inactive 'face-alias 'mode-line-inactive)
+(put 'modeline-highlight 'face-alias 'mode-line-highlight)
 
 (defface header-line
   '((default
@@ -1983,7 +2056,7 @@ Note: Other faces cannot inherit from the cursor face."
      ;; because in some cases the display engine will do it's own
      ;; workaround (to `dim' on ttys)
      :slant italic))
-  "Basic italic font."
+  "Basic italic face."
   :group 'basic-faces)
 
 
@@ -1992,7 +2065,11 @@ Note: Other faces cannot inherit from the cursor face."
   :group 'basic-faces)
 
 
-(defface underline '((t :underline t))
+(defface underline '((((supports :underline t))
+                     :underline t)
+                    (((supports :weight bold))
+                     :weight bold)
+                    (t :underline t))
   "Basic underlined face."
   :group 'basic-faces)
 
@@ -2015,7 +2092,7 @@ Note: Other faces cannot inherit from the cursor face."
 
 (defface secondary-selection
   '((((class color) (min-colors 88) (background light))
-     :background "yellow")
+     :background "yellow1")
     (((class color) (min-colors 88) (background dark))
      :background "SkyBlue4")
     (((class color) (min-colors 16) (background light))
@@ -2041,22 +2118,48 @@ Note: Other faces cannot inherit from the cursor face."
 
 (defface trailing-whitespace
   '((((class color) (background light))
-     :background "red")
+     :background "red1")
     (((class color) (background dark))
-     :background "red")
+     :background "red1")
     (t :inverse-video t))
   "Basic face for highlighting trailing whitespace."
   :version "21.1"
-  :group 'font-lock                    ; like `show-trailing-whitespace'
+  :group 'whitespace           ; like `show-trailing-whitespace'
   :group 'basic-faces)
 
-(defface escape-glyph '((((background dark)) :foreground "cyan")
-                       ;; See the comment in minibuffer-prompt for
-                       ;; the reason not to use blue on MS-DOS.
-                       (((type pc)) :foreground "magenta")
-                       (t :foreground "blue"))
+(defface escape-glyph
+  '((((background dark)) :foreground "cyan")
+    ;; See the comment in minibuffer-prompt for
+    ;; the reason not to use blue on MS-DOS.
+    (((type pc)) :foreground "magenta")
+    ;; red4 is too dark, but some say blue is too loud.
+    ;; brown seems to work ok. -- rms.
+    (t :foreground "brown"))
   "Face for characters displayed as ^-sequences or \-sequences."
-  :group 'basic-faces)
+  :group 'basic-faces
+  :version "22.1")
+
+(defface nobreak-space
+  '((((class color) (min-colors 88)) :inherit escape-glyph :underline t)
+    (((class color) (min-colors 8)) :background "magenta")
+    (t :inverse-video t))
+  "Face for displaying nobreak space."
+  :group 'basic-faces
+  :version "22.1")
+
+(defface shadow
+  '((((class color grayscale) (min-colors 88) (background light))
+     :foreground "grey50")
+    (((class color grayscale) (min-colors 88) (background dark))
+     :foreground "grey70")
+    (((class color) (min-colors 8) (background light))
+     :foreground "green")
+    (((class color) (min-colors 8) (background dark))
+     :foreground "yellow"))
+  "Basic face for shadowed text."
+  :group 'basic-faces
+  :version "22.1")
+
 \f
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;; Manipulating font names.
@@ -2236,5 +2339,5 @@ If that can't be done, return nil."
 
 (provide 'faces)
 
-;;; arch-tag: 19a4759f-2963-445f-b004-425b9aadd7d6
+;; arch-tag: 19a4759f-2963-445f-b004-425b9aadd7d6
 ;;; faces.el ends here