comparison lisp/faces.el @ 44886:fe167023fdf0

(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.
author Richard M. Stallman <rms@gnu.org>
date Fri, 26 Apr 2002 22:31:16 +0000
parents 59d5728240b3
children 235cc7208807
comparison
equal deleted inserted replaced
44885:467b1524d1cb 44886:fe167023fdf0
844 844
845 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 845 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
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.
851 PROMPT should not end with a blank, since this function appends one. 851 If it has a `read-face-name' property, that overrides the `face' property.
852 Value is a symbol naming a known face." 852 PROMPT 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)) 853 STRING-DESCRIBING-DEFAULT describes what default you will use
854 (face-list))) 854 if this function returns nil.
855 (def (thing-at-point 'symbol)) 855 If MULTIPLE is non-nil, return a list of faces (possibly only one).
856 face) 856 Otherwise, 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)
867 "Return valid values for face attribute ATTRIBUTE. 902 "Return valid values for face attribute ATTRIBUTE.
868 The optional argument FRAME is used to determine available fonts 903 The optional argument FRAME is used to determine available fonts
1135 ;; Hyperlink to a customization buffer for the face. Using 1170 ;; Hyperlink to a customization buffer for the face. Using
1136 ;; the help xref mechanism may not be the best way. 1171 ;; the help xref mechanism may not be the best way.
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
1145 (save-match-data 1181 (save-match-data
1146 (search-backward list-faces-sample-text) 1182 (search-backward list-faces-sample-text)
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)
1153 (while (not (eobp)) 1192 (while (not (eobp))
1154 (insert " ") 1193 (insert " ")
1165 (let ((faces (face-list))) 1204 (let ((faces (face-list)))
1166 (while faces 1205 (while faces
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.
1211 Interactevely, FACE defaults to the faces of the character after point
1212 and FRAME defaults to the selected frame.
1213
1173 If the optional argument FRAME is given, report on face FACE in that frame. 1214 If the optional argument FRAME is given, report on face FACE in that frame.
1174 If FRAME is t, report on the defaults for face FACE (for new frames). 1215 If FRAME is t, report on the defaults for face FACE (for new frames).
1175 If FRAME is omitted or nil, use the selected frame." 1216 If 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")
1180 (:weight . "Weight") 1221 (:weight . "Weight")
1181 (:slant . "Slant") 1222 (:slant . "Slant")
1190 (:font . "Font or fontset") 1231 (:font . "Font or fontset")
1191 (:inherit . "Inherit"))) 1232 (:inherit . "Inherit")))
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
1217 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 1266 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1218 ;;; Face specifications (defface). 1267 ;;; Face specifications (defface).