aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoland Winkler2013-04-03 21:12:25 -0500
committerRoland Winkler2013-04-03 21:12:25 -0500
commitf3d3eaf070d28678d0f094316658037ee411068b (patch)
tree149372d0422f5681a3df3dd85f4e12c0d419833f
parent2575da508408a178f64c9bcdd51e2e0502419a17 (diff)
downloademacs-f3d3eaf070d28678d0f094316658037ee411068b.tar.gz
emacs-f3d3eaf070d28678d0f094316658037ee411068b.zip
lisp/faces.el (read-face-name): Behave as promised by the docstring.
-rw-r--r--lisp/ChangeLog6
-rw-r--r--lisp/faces.el114
2 files changed, 64 insertions, 56 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index d1d4d0d6033..1e50cce354d 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,9 @@
12013-04-04 Roland Winkler <winkler@gnu.org>
2
3 * faces.el (read-face-name): Behave as promised by the docstring.
4 Assume that arg default is a list of faces.
5 (describe-face): Call read-face-name with list of default faces.
6
12013-04-04 Thierry Volpiatto <thierry.volpiatto@gmail.com> 72013-04-04 Thierry Volpiatto <thierry.volpiatto@gmail.com>
2 8
3 * bookmark.el: Fix deletion of bookmarks (bug#13972). 9 * bookmark.el: Fix deletion of bookmarks (bug#13972).
diff --git a/lisp/faces.el b/lisp/faces.el
index 60410733514..400b475429f 100644
--- a/lisp/faces.el
+++ b/lisp/faces.el
@@ -935,80 +935,79 @@ a colon.
935 935
936The optional argument DEFAULT specifies the default face name(s) 936The optional argument DEFAULT specifies the default face name(s)
937to return if the user just types RET. If its value is non-nil, 937to return if the user just types RET. If its value is non-nil,
938it should be a list of face names (symbols); in that case, the 938it should be a list of face names (symbols or strings); in that case,
939default return value is the `car' of DEFAULT (if the argument 939the default return value is the `car' of DEFAULT (if the argument
940MULTIPLE is non-nil), or DEFAULT (if MULTIPLE is nil). See below 940MULTIPLE is non-nil), or DEFAULT (if MULTIPLE is nil). See below
941for the meaning of MULTIPLE. 941for the meaning of MULTIPLE.
942 942
943If DEFAULT is nil, the list of default face names is taken from 943If DEFAULT is nil, the list of default face names is taken from
944the `read-face-name' property of the text at point, or, if that 944the symbol at point and the `read-face-name' property of the text at point,
945is nil, from the `face' property of the text at point. 945or, if that is nil, from the `face' property of the text at point.
946 946
947This function uses `completing-read-multiple' with \",\" as the 947This function uses `completing-read-multiple' with \"[ \\t]*,[ \\t]*\"
948separator character. Thus, the user may enter multiple face 948as the separator regexp. Thus, the user may enter multiple face
949names, separated by commas. The optional argument MULTIPLE 949names, separated by commas. The optional argument MULTIPLE
950specifies the form of the return value. If MULTIPLE is non-nil, 950specifies the form of the return value. If MULTIPLE is non-nil,
951return a list of face names; if the user entered just one face 951return a list of face names; if the user entered just one face
952name, the return value would be a list of one face name. 952name, the return value would be a list of one face name.
953Otherwise, return a single face name; if the user entered more 953Otherwise, return a single face name; if the user entered more
954than one face name, return only the first one." 954than one face name, return only the first one."
955 (let ((faceprop (or (get-char-property (point) 'read-face-name) 955 ;; Should we better not generate automagically a value for DEFAULT
956 (get-char-property (point) 'face))) 956 ;; when `read-face-name' was called with DEFAULT being nil?
957 (aliasfaces nil) 957 ;; Such magic is somewhat unusual for a function `read-...'.
958 (nonaliasfaces nil) 958 ;; Also, one cannot skip this magic by means of a suitable
959 faces) 959 ;; value of DEFAULT. It would be cleaner to use
960 ;; Try to get a face name from the buffer. 960 ;; (read-face-name prompt (face-at-point)).
961 (if (memq (intern-soft (thing-at-point 'symbol)) (face-list)) 961 (unless default
962 (setq faces (list (intern-soft (thing-at-point 'symbol))))) 962 ;; Try to get a default face name from the buffer.
963 ;; Add the named faces that the `face' property uses. 963 (let ((thing (intern-soft (thing-at-point 'symbol))))
964 (if (and (listp faceprop) 964 (if (memq thing (face-list))
965 ;; Don't treat an attribute spec as a list of faces. 965 (setq default (list thing))))
966 (not (keywordp (car faceprop))) 966 ;; Add the named faces that the `read-face-name' or `face' property uses.
967 (not (memq (car faceprop) '(foreground-color background-color)))) 967 (let ((faceprop (or (get-char-property (point) 'read-face-name)
968 (dolist (f faceprop) 968 (get-char-property (point) 'face))))
969 (if (symbolp f) 969 (if (and (listp faceprop)
970 (push f faces))) 970 ;; Don't treat an attribute spec as a list of faces.
971 (if (symbolp faceprop) 971 (not (keywordp (car faceprop)))
972 (push faceprop faces))) 972 (not (memq (car faceprop) '(foreground-color background-color))))
973 (delete-dups faces) 973 (dolist (face faceprop)
974 974 (if (symbolp face)
975 ;; Build up the completion tables. 975 (push face default)))
976 (if (symbolp faceprop)
977 (push faceprop default)))
978 (delete-dups default)))
979
980 ;; If we only want one, and the default is more than one,
981 ;; discard the unwanted ones now.
982 (if (and default (not multiple))
983 (setq default (list (car default))))
984
985 (if default
986 (setq default (mapconcat (lambda (f)
987 (if (symbolp f) (symbol-name f) f))
988 default ", ")))
989
990 ;; Build up the completion tables.
991 (let (aliasfaces nonaliasfaces)
976 (mapatoms (lambda (s) 992 (mapatoms (lambda (s)
977 (if (custom-facep s) 993 (if (custom-facep s)
978 (if (get s 'face-alias) 994 (if (get s 'face-alias)
979 (push (symbol-name s) aliasfaces) 995 (push (symbol-name s) aliasfaces)
980 (push (symbol-name s) nonaliasfaces))))) 996 (push (symbol-name s) nonaliasfaces)))))
981 997
982 ;; If we only want one, and the default is more than one, 998 (let ((faces
983 ;; discard the unwanted ones now. 999 ;; Read the faces.
984 (unless multiple 1000 (mapcar 'intern
985 (if faces 1001 (completing-read-multiple
986 (setq faces (list (car faces))))) 1002 (if default
987 (require 'crm) 1003 (format "%s (default `%s'): " prompt default)
988 (let* ((input 1004 (format "%s: " prompt))
989 ;; Read the input. 1005 (completion-table-in-turn nonaliasfaces aliasfaces)
990 (completing-read-multiple 1006 nil t nil 'face-name-history default))))
991 (if (or faces default)
992 (format "%s (default `%s'): " prompt
993 (if faces (mapconcat 'symbol-name faces ",")
994 default))
995 (format "%s: " prompt))
996 (completion-table-in-turn nonaliasfaces aliasfaces)
997 nil t nil 'face-name-history
998 (if faces (mapconcat 'symbol-name faces ","))))
999 ;; Canonicalize the output.
1000 (output
1001 (cond ((or (equal input "") (equal input '("")))
1002 (or faces (unless (stringp default) default)))
1003 ((stringp input)
1004 (mapcar 'intern (split-string input ", *" t)))
1005 ((listp input)
1006 (mapcar 'intern input))
1007 (input))))
1008 ;; Return either a list of faces or just one face. 1007 ;; Return either a list of faces or just one face.
1009 (if multiple 1008 (if multiple
1010 output 1009 faces
1011 (car output))))) 1010 (car faces)))))
1012 1011
1013;; Not defined without X, but behind window-system test. 1012;; Not defined without X, but behind window-system test.
1014(defvar x-bitmap-file-path) 1013(defvar x-bitmap-file-path)
@@ -1363,7 +1362,10 @@ and FRAME defaults to the selected frame.
1363If the optional argument FRAME is given, report on face FACE in that frame. 1362If the optional argument FRAME is given, report on face FACE in that frame.
1364If FRAME is t, report on the defaults for face FACE (for new frames). 1363If FRAME is t, report on the defaults for face FACE (for new frames).
1365If FRAME is omitted or nil, use the selected frame." 1364If FRAME is omitted or nil, use the selected frame."
1366 (interactive (list (read-face-name "Describe face" 'default t))) 1365 (interactive (list (read-face-name "Describe face"
1366 (if (eq 'default (face-at-point))
1367 '(default))
1368 t)))
1367 (let* ((attrs '((:family . "Family") 1369 (let* ((attrs '((:family . "Family")
1368 (:foundry . "Foundry") 1370 (:foundry . "Foundry")
1369 (:width . "Width") 1371 (:width . "Width")