0

I am using this function interactively, where the string from completing-read is passed to intern to convert it into a symbol suitable for describe-face.

Currently, I want to handle the non-interactive case, where a face is passed directly to the function. The strategy is to add a condition alternative for a face or face name, that I can call describe-face with that face as a single argument.

Perhaps using stringp for face names and facep for faces.

Is this ok, can it be improved?

(defun laxy-descface (facenm)
  "Describe the typeface properties of face name FACENM."
 
  (interactive
   (list
    (let* ( (cseq '("default" "mode-line" "mode-line-inactive"
            "list" "text-property")) )
      (completing-read "Face_property: " cseq nil t "text-property"))))

  (cond
   ((stringp facenm)
 
    (pcase facenm
      ("text-property"
       (describe-face (get-text-property (point) 'face)))
      ("default"
       (describe-face (intern facenm)))
      ("mode-line"
       (describe-face (intern facenm)))
      ("mode-line-inactive"
       (describe-face (intern facenm)))
      ("list"
       (list-faces-display))) )

   ((facep facenm)

    (describe-face facenm))))
11
  • Who is stopping you?
    – NickD
    Aug 11 at 3:03
  • What pcase alternative can I use that handles the non-interactive case, calling the face being passed without use of intern?
    – Ephram
    Aug 11 at 11:51
  • I'm not sure that clarifies the question, but in any case: add your clarifications to the question - do not ask new question or add clarifications in a comment. The question needs to be clear on its own.
    – NickD
    Aug 11 at 13:10
  • I am not sure why you insist on making it a symbol. Why don't you try out the comments here? The first comment says your code was correct, then in a subsequent comment @NickD, explained that describe-face takes a string also. We are happy to answer your questions, but you should at least try out and try to understand our answers... Aug 11 at 19:59
  • Your code in that question will work perfectly fine when called non-interactively. Just remove the quote from the 'face at the end of your example, as was mentioned in the first comment there. But why don't you call describe-face non-interactively directly? Aug 11 at 20:02

1 Answer 1

0

Except for some (subjective) style changes, your code looks fine, and there is not much to be improved. However, your code contains three times (describe-face (intern facenm)). Often, there are ways to reduce repetition of code (but only do them when it improves the code). Here, you can use the pcase pattern (or pattern1 pattern2...)

(defun laxy-describe-face (facename)
  "Describe the typeface properties of face name FACENAME"
  (interactive
   (let ((options '("default"
                    "mode-line"
                    "mode-line-inactive"
                    "list"
                    "text-property")))
     (list (completing-read "Select face or action: " options nil t "text-property"))))
  (cond ((stringp facename)
         (pcase facename
           ("text-property"
            (describe-face (get-text-property (point) 'face)))
           ((or "default" "mode-line" "mode-line-inactive")
            (describe-face (intern facename)))
           ("list"
            (list-faces-display))) )
        ((facep facename)
         (describe-face facename))))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.