4646
4747(defvar mldoc-default-eldoc-propertizers
4848 '((:function . ((face . font-lock-function-name-face )))
49+ (:constant . ((face . font-lock-constant-face )))
4950 (:return-type . ((face . font-lock-type-face )))
5051 (:type . ((face . font-lock-type-face )))
5152 (:warning . ((face . font-lock-warning-face ))))
6263(defvar-local mldoc-propertizer* nil
6364 " Dynamic bound list of propertizers." )
6465
65- ; ; Utility functions
66+ ; ; Utility functions for users
6667(defsubst mldoc-in-string ()
6768 " Return non-nil if inside a string.
6869it is the character that will terminate the string, or t if the string should be terminated by a generic string delimiter."
@@ -88,32 +89,34 @@ The definition is (lambda ARGLIST [DOCSTRING] BODY...)."
8889 (mapconcat #'identity (apply #'mldoc--build-list doc) " " )
8990 doc))))
9091
91- (defun mldoc--propertize-arg (arg is-current-arg arg-spec )
92- " Propertize ARG by IS-CURRENT-ARG and ARG-SPEC."
93- (cl-loop
94- for spec in arg-spec
95- collect
96- (if (stringp spec)
97- spec
98- (let ((v (plist-get arg spec)))
99- (if (null v)
100- " "
101- (if (and is-current-arg (eq :name spec))
102- (propertize v 'face '(:weight bold ))
103- (mldoc--propertize-keyword arg spec)))))))
104-
105- (defun mldoc--propertize-args (args current-arg arg-separator &optional arg-spec )
106- " Return propertized string by ARGS list, CURRENT-ARG, ARG-SEPARATOR and ARG-SPEC."
92+ (defun mldoc--propertize-param (param is-current-param doc-form )
93+ " Propertize PARAM by IS-CURRENT-PARAM and DOC-FORM."
10794 (mapconcat
108- #'append
109- (cl-loop for arg in args
110- for n = 0 then (1+ n)
111- append
112- (mldoc--propertize-arg
113- (if (stringp arg) (list :name arg) arg)
114- (eq current-arg n)
115- (or arg-spec (list :name ))))
116- (or arg-separator " , " )))
95+ (lambda (spec )
96+ (if (stringp spec)
97+ spec
98+ (let ((v (plist-get param spec)))
99+ (if (null v)
100+ " "
101+ (if (and is-current-param (eq :name spec))
102+ (propertize v 'face '(:weight bold ))
103+ (mldoc--propertize-keyword param spec))))))
104+ doc-form
105+ " " ))
106+
107+ (defun mldoc--propertize-params (params current-param param-separator &optional doc-form )
108+ " Return propertized string by PARAMS list, CURRENT-PARAM, PARAM-SEPARATOR and DOC-FORM."
109+ (let ((n 0 ))
110+ (mapconcat
111+ (lambda (param )
112+ (prog1
113+ (mldoc--propertize-param
114+ (if (stringp param) (list :name param) param)
115+ (eq current-param n)
116+ (or doc-form (list :name )))
117+ (setq n (1+ n))))
118+ params
119+ (or param-separator " , " ))))
117120
118121(defun mldoc--propertizers-to-list (propertizer )
119122 " Return list for function `propertize' by PROPERTIZER alist."
@@ -127,47 +130,44 @@ The definition is (lambda ARGLIST [DOCSTRING] BODY...)."
127130 (funcall val)
128131 val))
129132 (prop (cdr-safe (assq key mldoc-propertizer*))))
130- (if (null prop)
133+ (if (not ( and prop str) )
131134 (or str " " )
132135 (apply #'propertize str (mldoc--propertizers-to-list prop)))))
133136
134- (cl-defmacro mldoc-list (spec &key function propertizers args current-arg values )
137+ (cl-defmacro mldoc-list (form &key propertizers params current-param values )
135138 " Build a list acceptable by MLDoc."
136- `(list , spec
137- :function , function
139+ `(list , form
138140 :propertizers , propertizers
139- :args , args
140- :current-arg , current-arg
141+ :params , params
142+ :current-param , current-param
141143 :values , values ))
142144
143- (cl-defun mldoc--build-list (spec &key function propertizers args current-arg values )
145+ (cl-defun mldoc--build-list (spec &key propertizers params current-param values )
144146 " Return a list of propertized string for ElDoc.
145147
146- integer `:current-arg '
148+ integer `:current-param '
147149 0-origin offset to current position of arguments.
148150plist `values'
149151 Property list of (:name value)
150152"
151- (setq values (plist-put values :function function))
152- (setq values (plist-put values :args args))
153+ (setq values (plist-put values :params params))
153154 (let ((mldoc-propertizer*
154155 (append propertizers mldoc-default-eldoc-propertizers)))
155156 (cl-loop
156157 for s in spec collect
157158 (cond
159+ ((null s) nil )
158160 ((stringp s) s)
159- ((symbolp s)
160- (if (not (keywordp s))
161- (symbol-value s)
162- (mldoc--propertize-keyword values s)))
163- ((listp s) (mldoc--evalute-spec s args current-arg))))))
164-
165- (defun mldoc--evalute-spec (spec args current-arg )
166- " Evalute ARGS and embedded element of SPEC."
161+ ((keywordp s) (mldoc--propertize-keyword values s))
162+ ((symbolp s) (symbol-value s))
163+ ((listp s) (mldoc--evalute-spec s params current-param))))))
164+
165+ (defun mldoc--evalute-spec (spec params current-param )
166+ " Evalute PARAMS and embedded element of SPEC."
167167 (let ((f (car spec))
168168 (rest (cdr spec)))
169169 (cl-case f
170- (args (mldoc--propertize-args args current-arg (car rest) (cdr rest)))
170+ (params (mldoc--propertize-params params current-param (car rest) (cdr rest)))
171171 (if (if (eval (car rest)) (eval (nth 1 rest)) (eval (cons 'progn (cddr rest)))))
172172 (when (when (eval (car rest)) (eval (cons 'progn (cdr rest)))))
173173 (unless (unless (eval (car rest)) (eval (cons 'progn (cdr rest)))))
0 commit comments