Function: cfengine3-format-function-docstring

cfengine3-format-function-docstring is a byte-compiled function defined in cfengine.el.gz.

Signature

(cfengine3-format-function-docstring FDEF)

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/cfengine.el.gz
;; format from "cf-promises -s json", e.g. "sort" function:
;; ((category . "data")
;;  (variadic . :json-false)
;;  (parameters . [((range . "[a-zA-Z0-9_$(){}\\[\\].:]+") (type . "string"))
;;                 ((range . "lex,int,real,IP,ip,MAC,mac") (type . "option"))])
;;  (returnType . "slist")
;;  (status . "normal"))

(defun cfengine3-format-function-docstring (fdef)
  (let* ((f (format "%s" (car-safe fdef)))
         (def (cdr fdef))
         (rtype (cdr (assq 'returnType def)))
         (plist (cdr (assq 'parameters def)))
         (has-some-parameters (> (length plist) 0))
         (variadic (eq t (cdr (assq 'variadic def)))))

    ;; (format "[%S]%s %s(%s%s)" def
    (format "%s %s(%s%s)"
            (if rtype
                (propertize rtype 'face 'font-lock-variable-name-face)
              "???")
            (propertize f 'face 'font-lock-function-name-face)
            (mapconcat (lambda (p)
                         (let* ((type (cdr (assq 'type p)))
                                (description (cdr (assq 'description p)))
                                (desc-string (if (stringp description)
                                                 (concat " /" description "/")
                                               ""))
                               (range (cdr (assq 'range p))))
                           (cond
                            ((not (stringp type)) "???type???")
                            ((not (stringp range)) "???range???")
                            ;; options are lists of possible keywords
                            ((equal type "option")
                             (propertize (concat "[" range "]" desc-string)
                                         'face
                                         'font-lock-keyword-face))
                            ;; anything else is a type name as a variable
                            (t (propertize (concat type desc-string)
                                           'face
                                           'font-lock-variable-name-face)))))
                       plist
                       ", ")
            (if variadic
                (if has-some-parameters ", ..." "...")
              ""))))