|
1 | 1 | * MLDoc - Multi ElDoc integration |
| 2 | +*MLDoc* extends ElDoc and makes function definition very easy. |
| 3 | +** What is ElDoc? |
| 4 | +[[https://www.emacswiki.org/emacs/ElDoc][ElDoc]] is a minor mode to show documentation in echo area. |
| 5 | +ElDoc function is implemented for several languages besides Emacs Lisp. |
| 6 | +** Why MLDoc? |
| 7 | +MLDoc solves ElDoc problem. |
| 8 | +- ElDoc can usually only register one or two functions. |
| 9 | +- ElDoc implementations are difficult to understand and tends to be untestable. |
| 10 | +MLDoc has APIs for end users and Lisp package developers. |
| 11 | +** API for users |
| 12 | +*Note*: no end-user MLDoc implementation yet. |
| 13 | +#+BEGIN_SRC emacs-lisp |
| 14 | +(defun my-foo-mode-setup () |
| 15 | + "Setup function for `foo-mode'." |
| 16 | + (mldoc-mode 1) |
| 17 | + (setq mldoc-documentation-functions '(mldoc-foo mldoc-html))) |
| 18 | + |
| 19 | +(with-eval-after-load "foo-mode" |
| 20 | + (add-hook 'foo-mode-hook 'my-foo-mode-setup)) |
| 21 | +#+END_SRC |
| 22 | +** API for developers |
| 23 | +*** MLDoc DSL |
| 24 | +**** Example |
| 25 | +#+BEGIN_SRC emacs-lisp |
| 26 | +(defcustom mldoc-foo-function-spec |
| 27 | + '(return-type " " function "(" (args ", " type " " name) ")") |
| 28 | + "MLDoc display spec for Foo function call." |
| 29 | + :group 'mldoc-foo |
| 30 | + :type 'sexp) |
| 31 | + |
| 32 | +(define-mldoc mldoc-foo |
| 33 | + "MLDoc function for Foo language." |
| 34 | + ;; This function is extremely simplified, but represents the specification of |
| 35 | + ;; the value that an actual implementation should return. |
| 36 | + (mldoc-list mldoc-foo-function-spec :function "print" |
| 37 | + :args '((:type "string" :name "message")) |
| 38 | + :current-arg 0)) |
| 39 | +#+END_SRC |
| 40 | +**** Format |
| 41 | +Actually the DSL is just a list. Its structure is =(cons spec plist)=. |
| 42 | +***** spec |
| 43 | +*spec* is a notation for converting a list to a string. |
| 44 | +- ="string"=: Just combined with that value. |
| 45 | +- =:keyword=: The value passed as a keyword in =plist=. |
| 46 | +- =symbol=: Symbol is evaluated as a variable name. |
| 47 | +- =(args separator &optional argspec)=: This looks like a function, but combines =:args= with =separator=. |
| 48 | + - *separator*: In languages similar to C, =", "= is assumed. |
| 49 | + - *argspec*: spec for arguments. |
| 50 | +***** plist |
| 51 | +It is an [[https://www.gnu.org/software/emacs/manual/html_node/elisp/Property-Lists.html#Property-Lists][Property List]] with the following keys. |
| 52 | +- =:args=: List of =string= or =plist=. |
| 53 | +- =:current-arg=: 0-origin current position of argument list. |
| 54 | +*** macro =(define-mldoc name docstring &rest body)= |
| 55 | +This macro is very similar to defun. |
| 56 | +It's actually just a defun wrapper, but it is responsible for converting between MLDoc DSL and ElDoc output formats. |
0 commit comments