aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman2002-04-26 22:31:16 +0000
committerRichard M. Stallman2002-04-26 22:31:16 +0000
commita482f364557e64a1e864bac5edc657b4308a05b6 (patch)
tree3f26b7f6ae4d640a1db1c20606403cf277138731
parent9e0ad27acdd189ddf1e9c0efda7c6c64856775cc (diff)
downloademacs-a482f364557e64a1e864bac5edc657b4308a05b6.tar.gz
emacs-a482f364557e64a1e864bac5edc657b4308a05b6.zip
(read-face-name): New defaulting features.
New args STRING-DESCRIBING-DEFAULT and MULTIPLE. (list-faces-display): Use the face, not its name string, as arg when running customize-face. Put a `read-face-name' prop on the entire line. (describe-face): Handle multiple faces via read-face-name.
-rw-r--r--lisp/faces.el119
1 files changed, 84 insertions, 35 deletions
diff --git a/lisp/faces.el b/lisp/faces.el
index de049f7f097..0cd6ced20cf 100644
--- a/lisp/faces.el
+++ b/lisp/faces.el
@@ -846,21 +846,56 @@ of the default face. Value is FACE."
846;;; Interactively modifying faces. 846;;; Interactively modifying faces.
847;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 847;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
848 848
849(defun read-face-name (prompt) 849(defun read-face-name (prompt &optional string-describing-default multiple)
850 "Read and return a face symbol, prompting with PROMPT. 850 "Read a face, defaulting to the face or faces on the char after point.
851PROMPT should not end with a blank, since this function appends one. 851If it has a `read-face-name' property, that overrides the `face' property.
852Value is a symbol naming a known face." 852PROMPT describes what you will do with the face (don't end in a space).
853 (let ((face-list (mapcar #'(lambda (x) (cons (symbol-name x) x)) 853STRING-DESCRIBING-DEFAULT describes what default you will use
854 (face-list))) 854if this function returns nil.
855 (def (thing-at-point 'symbol)) 855If MULTIPLE is non-nil, return a list of faces (possibly only one).
856 face) 856Otherwise, return a single face."
857 (cond ((assoc def face-list) 857 (let ((faceprop (or (get-char-property (point) 'read-face-name)
858 (setq prompt (concat prompt " (default " def "): "))) 858 (get-char-property (point) 'face)))
859 (t (setq def nil) 859 faces)
860 (setq prompt (concat prompt ": ")))) 860 ;; Make a list of the named faces that the `face' property uses.
861 (while (equal "" (setq face (completing-read 861 (if (listp faceprop)
862 prompt face-list nil t nil nil def)))) 862 (dolist (f faceprop)
863 (intern face))) 863 (if (symbolp f)
864 (push f faces)))
865 (if (symbolp faceprop)
866 (setq faces (list faceprop))))
867 ;; If there are none, try to get a face name from the buffer.
868 (if (and (null faces)
869 (memq (intern-soft (thing-at-point 'symbol)) (face-list)))
870 (setq faces (list (intern-soft (thing-at-point 'symbol)))))
871
872 ;; If we only want one, and the default is more than one,
873 ;; discard the unwanted ones now.
874 (unless multiple
875 (if faces
876 (setq faces (list (car faces)))))
877 (let* ((input
878 ;; Read the input.
879 (completing-read
880 (if (or faces string-describing-default)
881 (format "%s (default %s): " prompt
882 (if faces (mapconcat 'symbol-name faces ", ")
883 string-describing-default))
884 prompt)
885 obarray 'custom-facep t))
886 ;; Canonicalize the output.
887 (output
888 (if (equal input "")
889 faces
890 (if (stringp input)
891 (list (intern input))
892 input))))
893 ;; Return either a list of faces or just one face.
894 (if multiple
895 output
896 (car output)))))
897
898
864 899
865 900
866(defun face-valid-attribute-values (attribute &optional frame) 901(defun face-valid-attribute-values (attribute &optional frame)
@@ -1137,8 +1172,9 @@ The sample text is a string that comes from the variable
1137 (save-excursion 1172 (save-excursion
1138 (save-match-data 1173 (save-match-data
1139 (search-backward face-name) 1174 (search-backward face-name)
1140 (help-xref-button 0 'help-customize-face face-name))) 1175 (help-xref-button 0 'help-customize-face face)))
1141 (let ((beg (point))) 1176 (let ((beg (point))
1177 (line-beg (line-beginning-position)))
1142 (insert list-faces-sample-text) 1178 (insert list-faces-sample-text)
1143 ;; Hyperlink to a help buffer for the face. 1179 ;; Hyperlink to a help buffer for the face.
1144 (save-excursion 1180 (save-excursion
@@ -1147,6 +1183,9 @@ The sample text is a string that comes from the variable
1147 (help-xref-button 0 'help-face face))) 1183 (help-xref-button 0 'help-face face)))
1148 (insert "\n") 1184 (insert "\n")
1149 (put-text-property beg (1- (point)) 'face face) 1185 (put-text-property beg (1- (point)) 'face face)
1186 ;; Make all face commands default to the proper face
1187 ;; anywhere in the line.
1188 (put-text-property line-beg (1- (point)) 'read-face-name face)
1150 ;; If the sample text has multiple lines, line up all of them. 1189 ;; If the sample text has multiple lines, line up all of them.
1151 (goto-char beg) 1190 (goto-char beg)
1152 (forward-line 1) 1191 (forward-line 1)
@@ -1167,13 +1206,15 @@ The sample text is a string that comes from the variable
1167 (copy-face (car faces) (car faces) frame disp-frame) 1206 (copy-face (car faces) (car faces) frame disp-frame)
1168 (setq faces (cdr faces))))))) 1207 (setq faces (cdr faces)))))))
1169 1208
1170
1171(defun describe-face (face &optional frame) 1209(defun describe-face (face &optional frame)
1172 "Display the properties of face FACE on FRAME. 1210 "Display the properties of face FACE on FRAME.
1211Interactevely, FACE defaults to the faces of the character after point
1212and FRAME defaults to the selected frame.
1213
1173If the optional argument FRAME is given, report on face FACE in that frame. 1214If the optional argument FRAME is given, report on face FACE in that frame.
1174If FRAME is t, report on the defaults for face FACE (for new frames). 1215If FRAME is t, report on the defaults for face FACE (for new frames).
1175If FRAME is omitted or nil, use the selected frame." 1216If FRAME is omitted or nil, use the selected frame."
1176 (interactive (list (read-face-name "Describe face"))) 1217 (interactive (list (read-face-name "Describe face" "= `default' face" t)))
1177 (let* ((attrs '((:family . "Family") 1218 (let* ((attrs '((:family . "Family")
1178 (:width . "Width") 1219 (:width . "Width")
1179 (:height . "Height") 1220 (:height . "Height")
@@ -1192,25 +1233,33 @@ If FRAME is omitted or nil, use the selected frame."
1192 (max-width (apply #'max (mapcar #'(lambda (x) (length (cdr x))) 1233 (max-width (apply #'max (mapcar #'(lambda (x) (length (cdr x)))
1193 attrs)))) 1234 attrs))))
1194 (help-setup-xref (list #'describe-face face) (interactive-p)) 1235 (help-setup-xref (list #'describe-face face) (interactive-p))
1236 (unless face
1237 (setq face 'default))
1238 (if (not (listp face))
1239 (setq face (list face)))
1195 (with-output-to-temp-buffer (help-buffer) 1240 (with-output-to-temp-buffer (help-buffer)
1196 (save-excursion 1241 (save-excursion
1197 (set-buffer standard-output) 1242 (set-buffer standard-output)
1198 (dolist (a attrs) 1243 (dolist (f face)
1199 (let ((attr (face-attribute face (car a) frame))) 1244 (insert "Face: " (symbol-name f))
1200 (insert (make-string (- max-width (length (cdr a))) ?\ ) 1245 (if (not (facep f))
1201 (cdr a) ": " (format "%s" attr) "\n"))) 1246 (insert " undefined face.\n")
1202 (insert "\nDocumentation:\n\n" 1247 (let ((customize-label "customize this face"))
1203 (or (face-documentation face) 1248 (princ (concat " (" customize-label ")\n"))
1204 "not documented as a face.")) 1249 (insert "Documentation: "
1205 (let ((customize-label "customize")) 1250 (or (face-documentation f)
1206 (terpri) 1251 "not documented as a face.")
1207 (terpri) 1252 "\n\n")
1208 (princ (concat "You can " customize-label " this face.")) 1253 (with-current-buffer standard-output
1209 (with-current-buffer standard-output 1254 (save-excursion
1210 (save-excursion 1255 (re-search-backward
1211 (re-search-backward 1256 (concat "\\(" customize-label "\\)") nil t)
1212 (concat "\\(" customize-label "\\)") nil t) 1257 (help-xref-button 1 'help-customize-face f)))
1213 (help-xref-button 1 'help-customize-face face))))) 1258 (dolist (a attrs)
1259 (let ((attr (face-attribute f (car a) frame)))
1260 (insert (make-string (- max-width (length (cdr a))) ?\ )
1261 (cdr a) ": " (format "%s" attr) "\n")))))
1262 (terpri)))
1214 (print-help-return-message)))) 1263 (print-help-return-message))))
1215 1264
1216 1265