Commit graph

152647 commits

Author SHA1 Message Date
Stefan Monnier
d7ccd3dcc2 Merge remote-tracking branch 'origin/scratch/oclosure' into fcr 2022-01-01 16:41:53 -05:00
Stefan Monnier
2a34e414a1 FCR: Rename to OClosure 2021-12-31 15:39:51 -05:00
Stefan Monnier
de320e2003 Arrange to load nadvice later in loadup.el
This is done simply so as to avoid scattering nadvice's code into
`simple.el` and `cl-print.el`.

* lisp/loadup.el ("emacs-lisp/nadvice"): Move down after "simple".

* lisp/help.el (help-command-error-confusable-suggestions): Make it
call `command-error-default`.
(command-error-function): Replace the top-level call to `add-function`
with a simple `setq` since `add-function` is not available at this
stage any more.

* lisp/emacs-lisp/nadvice.el (interactive-form) <advice>:
(cl-print-object) <advice>: Rename from `advice--get-interactive-form`
and `advice--cl-print-object`.

* lisp/emacs-lisp/cl-print.el (cl-print-object) <advice>:
* lisp/simple.el (interactive-form) <advice>: Move to `nadvice.el`.
(pre-redisplay-function): Replace the top-level call to `add-function`
with a simple `setq` since `add-function` is not available at this
stage any more.

* lisp/emacs-lisp/cl-generic.el: Use `oclosure-object` instead of `advice`
as representative of the OClosure specializers to prefill the dispatcher table.
2021-12-31 01:53:11 -05:00
Stefan Monnier
162a69669f Arrange to load nadvice later in loadup.el
This is done simply so as to avoid scattering nadvice's code into
`simple.el` and `cl-print.el`.

* lisp/loadup.el ("emacs-lisp/nadvice"): Move down after "simple".

* lisp/help.el (help-command-error-confusable-suggestions): Make it
call `command-error-default`.
(command-error-function): Replace the top-level call to `add-function`
with a simple `setq` since `add-function` is not available at this
stage any more.

* lisp/emacs-lisp/nadvice.el (interactive-form) <advice>:
(cl-print-object) <advice>: Rename from `advice--get-interactive-form`
and `advice--cl-print-object`.

* lisp/emacs-lisp/cl-print.el (cl-print-object) <advice>:
* lisp/simple.el (interactive-form) <advice>: Move to `nadvice.el`.
(pre-redisplay-function): Replace the top-level call to `add-function`
with a simple `setq` since `add-function` is not available at this
stage any more.

* lisp/emacs-lisp/cl-generic.el: Use `fcr-object` instead of `advice`
as representative of the FCR specializers to prefill the dispatcher table.
2021-12-31 01:53:11 -05:00
Stefan Monnier
3aa60102b9 kmacro.el: Unify the lambda and the list representations
Kmacros used to be represented as a triplet (MAC COUNTER FORMAT),
and then wrapped into a lambda to turn them into commands.
Replace the triplet with an OClosure so it's directly executable.
Take advantage of the change to promote the key-description
format where applicable.

* lisp/kmacro.el (kmacro): New OClosure type, to replace both `kmacro-function`
and the (MAC COUNTER FORMAT) representation of kmacros.
(kmacro-p): Adjust.
(kmacro-ring-head): Use `kmacro` constructor.
(kmacro-push-ring): Add backward compatibility code for old
list representation.
(kmacro-view-ring-2nd, kmacro-start-macro, kmacro-view-macro):
(kmacro-split-ring-element): Adjust to new representation.
(kmacro-exec-ring-item): Redefine as obsolete alias.
(kmacro-call-ring-2nd, kmacro-end-or-call-macro): Simplify accordingly.
(kmacro-function): Delete OClosure type.
(kmacro): Rename from `kmacro-lambda-form` and streamline
calling convention.  Use `execute-kbd-macro` rather than
`kmacro-exec-ring-item`.
(kmacro-lambda-form, kmacro-extract-lambda): Rewrite and mark as obsolete.
(cl-print-object): Use the key-description format and skip the
counter and format parts if they're trivial.
(kmacro-bind-to-key, kmacro-name-last-macro): Simplify.

* test/lisp/kmacro-tests.el (kmacro-tests-kmacro-bind-to-single-key):
Suppress obsoletion warning.
(kmacro-tests-name-last-macro-bind-and-rebind): Tighten the check
a tiny bit.
(kmacro-tests--cl-print): Adjust to the new key-description output.

* lisp/macros.el (macro--string-to-vector): New function.
(insert-kbd-macro): Use it, and change the generated code to use
`kmacro` and the key-description format.

* lisp/edmacro.el (edit-kbd-macro): Adjust to new representation.
(edmacro-finish-edit): Use `kmacro` constructor.
2021-12-28 12:03:44 -05:00
Stefan Monnier
a69d03779c kmacro.el: Unify the lambda and the list representations
Kmacros used to be represented as a triplet (MAC COUNTER FORMAT),
and then wrapped into a lambda to turn them into commands.
Replace the triplet with an FCR so it's directly executable.
Take advantage of the change to promote the key-description
format where applicable.

* lisp/kmacro.el (kmacro): New FCR type, to replace both `kmacro-function`
and the (MAC COUNTER FORMAT) representation of kmacros.
(kmacro-p): Adjust.
(kmacro-ring-head): Use `kmacro` constructor.
(kmacro-push-ring): Add backward compatibility code for old
list representation.
(kmacro-view-ring-2nd, kmacro-start-macro, kmacro-view-macro):
(kmacro-split-ring-element): Adjust to new representation.
(kmacro-exec-ring-item): Redefine as obsolete alias.
(kmacro-call-ring-2nd, kmacro-end-or-call-macro): Simplify accordingly.
(kmacro-function): Delete FCR type.
(kmacro): Rename from `kmacro-lambda-form` and streamline
calling convention.  Use `execute-kbd-macro` rather than
`kmacro-exec-ring-item`.
(kmacro-lambda-form, kmacro-extract-lambda): Rewrite and mark as obsolete.
(cl-print-object): Use the key-description format and skip the
counter and format parts if they're trivial.
(kmacro-bind-to-key, kmacro-name-last-macro): Simplify.

* test/lisp/kmacro-tests.el (kmacro-tests-kmacro-bind-to-single-key):
Suppress obsoletion warning.
(kmacro-tests-name-last-macro-bind-and-rebind): Tighten the check
a tiny bit.
(kmacro-tests--cl-print): Adjust to the new key-description output.

* lisp/macros.el (macro--string-to-vector): New function.
(insert-kbd-macro): Use it, and change the generated code to use
`kmacro` and the key-description format.

* lisp/edmacro.el (edit-kbd-macro): Adjust to new representation.
(edmacro-finish-edit): Use `kmacro` constructor.
2021-12-28 12:03:44 -05:00
Stefan Monnier
44dbab47f7 * lisp/emacs-lisp/oclosure.el: Remove obsolete comment 2021-12-27 20:22:30 -05:00
Stefan Monnier
9f33a163d3 * lisp/emacs-lisp/fcr.el: Remove obsolete comment 2021-12-27 20:22:30 -05:00
Stefan Monnier
1ace4acd54 Replace uniquify.el's advice with direct calls
* src/buffer.c (Frename_buffer): Call `uniquify--rename-buffer-advice`.
* lisp/files.el (create-file-buffer):
Call`uniquify--create-file-buffer-advice`.

* lisp/uniquify.el (uniquify--rename-buffer-advice)
(uniquify--create-file-buffer-advice): Don't add them as advice any more.
Adjust their calling convention accordingly.
2021-12-27 19:47:23 -05:00
Stefan Monnier
b3f407a2f9 Replace uniquify.el's advice with direct calls
* src/buffer.c (Frename_buffer): Call `uniquify--rename-buffer-advice`.
* lisp/files.el (create-file-buffer):
Call`uniquify--create-file-buffer-advice`.

* lisp/uniquify.el (uniquify--rename-buffer-advice)
(uniquify--create-file-buffer-advice): Don't add them as advice any more.
Adjust their calling convention accordingly.
2021-12-27 19:47:23 -05:00
Stefan Monnier
bc1d94a0d8 * lisp/emacs-lisp/oclosure.el (Commentary:): Add a few notes 2021-12-27 15:30:07 -05:00
Stefan Monnier
35c4ee4782 * lisp/emacs-lisp/fcr.el (Commentary:): Add a few notes 2021-12-27 15:30:07 -05:00
Stefan Monnier
55a8e92413 oclosure.el: Add support for mutable slots
* lisp/emacs-lisp/oclosure.el (oclosure--defstruct-make-copiers): Adjust for the
case of mutable slots.  Optimize the mandatory arg case.
Don't mark the copiers as inlinable.
(oclosure-define): Allow `:type` and `:mutable` properties on slots.
(oclosure--lambda): Add `mutables` arg.
(oclosure-lambda): Pass it.
(oclosure--copy): Add `mutlist` arg.
(oclosure--get): Add `mutable` arg.
(oclosure--set): New function.
(oclosure--mut-getter-prototype, oclosure--mut-setter-prototype):
New prototype functions.

* test/lisp/emacs-lisp/oclosure-tests.el (oclosure-test, oclosure-tests):
Add test for copier with mandatory arg.
(oclosure-test-mut, oclosure-test--mutate): New test.

* lisp/emacs-lisp/nadvice.el (advice): Use separate copiers
for the two use-cases, to avoid relying on CL keywords, since they're
not optimized away via inlining any more.
(advice--make, advice--tweak): Adjust accordingly.
2021-12-27 00:52:05 -05:00
Stefan Monnier
6850f89831 fcr.el: Add support for mutable slots
* lisp/emacs-lisp/fcr.el (fcr--defstruct-make-copiers): Adjust for the
case of mutable slots.  Optimize the mandatory arg case.
Don't mark the copiers as inlinable.
(fcr-defstruct): Allow `:type` and `:mutable` properties on slots.
(fcr--lambda): Add `mutables` arg.
(fcr-lambda): Pass it.
(fcr--copy): Add `mutlist` arg.
(fcr--get): Add `mutable` arg.
(fcr--set): New function.
(fcr--mut-getter-prototype, fcr--mut-setter-prototype):
New prototype functions.

* test/lisp/emacs-lisp/fcr-tests.el (fcr-test, fcr-tests):
Add test for copier with mandatory arg.
(fcr-test-mut, fcr-test--mutate): New test.

* lisp/emacs-lisp/nadvice.el (advice): Use separate copiers
for the two use-cases, to avoid relying on CL keywords, since they're
not optimized away via inlining any more.
(advice--make, advice--tweak): Adjust accordingly.
2021-12-27 00:52:05 -05:00
Stefan Monnier
fe5457ff75 oclosure.el (oclosure-lambda): Change calling convention
* lisp/emacs-lisp/oclosure.el (oclosure-lambda): Change calling convention.
* lisp/emacs-lisp/nadvice.el (advice--where-alist):
* lisp/emacs-lisp/cl-generic.el (cl-generic-call-method):
* lisp/kmacro.el (kmacro-lambda-form): Adjust accordingly.
2021-12-24 23:50:31 -05:00
Stefan Monnier
f21b0935a0 fcr.el (fcr-lambda): Change calling convention
* lisp/emacs-lisp/fcr.el (fcr-lambda): Change calling convention.
* lisp/emacs-lisp/nadvice.el (advice--where-alist):
* lisp/emacs-lisp/cl-generic.el (cl-generic-call-method):
* lisp/kmacro.el (kmacro-lambda-form): Adjust accordingly.
2021-12-24 23:50:31 -05:00
Stefan Monnier
01002ebba0 oclosure.el (oclosure-define): Use oclosure--copy to define accessors
* lisp/emacs-lisp/oclosure.el (oclosure-define): Use `oclosure--copy` to
define accessors.  Fix call to `oclosure--defstruct-make-copiers`.
(oclosure--lambda): New macro extracted from `oclosure-lambda`.
(oclosure-lambda): Use it.
(oclosure--accessor-prototype): New constant.
(oclosure-accessor): New type.
2021-12-22 10:52:21 -05:00
Stefan Monnier
eed3450af0 fcr.el (fcr-defstruct): Use fcr--copy to define accessors
* lisp/emacs-lisp/fcr.el (fcr-defstruct): Use `fcr--copy` to
define accessors.  Fix call to `fcr--defstruct-make-copiers`.
(fcr--lambda): New macro extracted from `fcr-lambda`.
(fcr-lambda): Use it.
(fcr--accessor-prototype): New constant.
(fcr-accessor): New type.
2021-12-22 10:52:21 -05:00
Stefan Monnier
f44ee8cd53 oclosure.el (accessor): New type
* lisp/emacs-lisp/oclosure.el (accessor): New (OClosure) type.
(oclosure-define): Mark the accessor functions
as being of type `accessor`.
(oclosure--accessor-cl-print, oclosure--accessor-docstring): New functions.

* src/doc.c (store_function_docstring): Improve message and fix check.
* lisp/simple.el (function-docstring) <accessor>: New method.
* lisp/emacs-lisp/cl-print.el (cl-print-object) <accessor>: New method.
2021-12-22 10:06:17 -05:00
Stefan Monnier
59f542ef4f fcr.el (accessor): New type
* lisp/emacs-lisp/fcr.el (accessor): New (FCR) type.
(fcr-defstruct): Mark the accessor functions
as being of type `accessor`.
(fcr--accessor-cl-print, fcr--accessor-docstring): New functions.

* src/doc.c (store_function_docstring): Improve message and fix check.
* lisp/simple.el (function-docstring) <accessor>: New method.
* lisp/emacs-lisp/cl-print.el (cl-print-object) <accessor>: New method.
2021-12-22 10:06:17 -05:00
Stefan Monnier
230617c90c lisp/emacs-lisp/oclosure.el: Signal errors for invalid code
* test/lisp/emacs-lisp/oclosure-tests.el (oclosure-tests): Remove left-over
debugging messages.
(oclosure-tests--limits): New test.

* lisp/emacs-lisp/oclosure.el (oclosure-define): Fill the `index-table` and
signal an error in case of duplicate slot names.
(oclosure-lambda): Change use of `oclosure--fix-type` so `cconv-convert` can use
it to detect store-converted slots.  Tweak generated code to avoid
a warning.
(oclosure--fix-type): Adjust accordingly.

* lisp/emacs-lisp/cconv.el (cconv-convert): Signal an error if we
store-convert a OClosure slot.
2021-12-21 09:57:34 -05:00
Stefan Monnier
0d45186882 lisp/emacs-lisp/fcr.el: Signal errors for invalid code
* test/lisp/emacs-lisp/fcr-tests.el (fcr-tests): Remove left-over
debugging messages.
(fcr-tests--limits): New test.

* lisp/emacs-lisp/fcr.el (fcr-defstruct): Fill the `index-table` and
signal an error in case of duplicate slot names.
(fcr-lambda): Change use of `fcr--fix-type` so `cconv-convert` can use
it to detect store-converted slots.  Tweak generated code to avoid
a warning.
(fcr--fix-type): Adjust accordingly.

* lisp/emacs-lisp/cconv.el (cconv-convert): Signal an error if we
store-convert a FCR slot.
2021-12-21 09:57:34 -05:00
Stefan Monnier
e9cfab679d lisp/emacs-lisp/cl-macs.el: Align with master 2021-12-20 23:14:03 -05:00
Stefan Monnier
98a518b532 lisp/emacs-lisp/cl-macs.el: Align with master 2021-12-20 23:14:03 -05:00
Stefan Monnier
3c9d64b602 cl-macs.el (cl--transform-lambda): Fix last change
* lisp/simple.el (interactive-form): Minor simplification.
* lisp/emacs-lisp/cl-macs.el (cl--transform-lambda): Fix last change.
2021-12-20 15:28:51 -05:00
Stefan Monnier
4f603d49b1 cl-macs.el (cl--transform-lambda): Fix last change
* lisp/simple.el (interactive-form): Minor simplification.
* lisp/emacs-lisp/cl-macs.el (cl--transform-lambda): Fix last change.
2021-12-20 15:28:51 -05:00
Stefan Monnier
20e5cd82ae Fix bug#28557
* test/lisp/emacs-lisp/cconv-tests.el: Remove `:expected-result :failed`
from the bug#28557 tests.
(cconv-tests-cl-function-:documentation): Account for the presence of
the arglist (aka "usage") in the docstring.

* lisp/emacs-lisp/cl-macs.el (cl--transform-lambda):
* lisp/emacs-lisp/cl-generic.el (cl-defgeneric):
Handle non-constant `:documentation`.

* lisp/emacs-lisp/generator.el (iter-lambda):
* lisp/emacs-lisp/oclosure.el (oclosure-lambda):
* lisp/emacs-lisp/cconv.el (cconv--convert-funcbody):
Use `macroexp-parse-body`.

* lisp/calendar/icalendar.el (icalendar--decode-isodatetime):
Fix misuse of `cl-lib` without requiring it.
2021-12-20 11:04:37 -05:00
Stefan Monnier
734e1bcc16 Fix bug#28557
* test/lisp/emacs-lisp/cconv-tests.el: Remove `:expected-result :failed`
from the bug#28557 tests.
(cconv-tests-cl-function-:documentation): Account for the presence of
the arglist (aka "usage") in the docstring.

* lisp/emacs-lisp/cl-macs.el (cl--transform-lambda):
* lisp/emacs-lisp/cl-generic.el (cl-defgeneric):
Handle non-constant `:documentation`.

* lisp/emacs-lisp/generator.el (iter-lambda):
* lisp/emacs-lisp/fcr.el (fcr-lambda):
* lisp/emacs-lisp/cconv.el (cconv--convert-funcbody):
Use `macroexp-parse-body`.

* lisp/calendar/icalendar.el (icalendar--decode-isodatetime):
Fix misuse of `cl-lib` without requiring it.
2021-12-20 11:04:37 -05:00
Stefan Monnier
e65e2bd0aa * lisp/emacs-lisp/cl-generic.el (cl-generic--oclosure-generalizer): Fix precedence 2021-12-18 23:05:26 -05:00
Stefan Monnier
3e055d5f58 * lisp/emacs-lisp/cl-generic.el (cl-generic--fcr-generalizer): Fix precedence 2021-12-18 23:05:26 -05:00
Stefan Monnier
afa68def26 cl-print.el: Dispatch on advice type
* test/lisp/emacs-lisp/nadvice-tests.el (advice-test-print): New test.

* src/doc.c (store_function_docstring): Don't overwrite an OClosure type.

* lisp/simple.el (function-docstring): Don't return OClosures's type.

* lisp/emacs-lisp/nadvice.el (advice--cl-print-object): New function,
extracted from `cl-print-object`.

* lisp/emacs-lisp/cl-print.el (cl-print-object) <advice>: Use the
`advice` type for the dispatch.  Use `advice--cl-print-object`.
2021-12-18 19:20:25 -05:00
Stefan Monnier
cf3e2fb8af cl-print.el: Dispatch on advice type
* test/lisp/emacs-lisp/nadvice-tests.el (advice-test-print): New test.

* src/doc.c (store_function_docstring): Don't overwrite an FCR type.

* lisp/simple.el (function-docstring): Don't return FCRs's type.

* lisp/emacs-lisp/nadvice.el (advice--cl-print-object): New function,
extracted from `cl-print-object`.

* lisp/emacs-lisp/cl-print.el (cl-print-object) <advice>: Use the
`advice` type for the dispatch.  Use `advice--cl-print-object`.
2021-12-18 19:20:25 -05:00
Stefan Monnier
9465a7e59e nadvice.el: Restore interactive-form handling
* test/lisp/emacs-lisp/nadvice-tests.el
(advice-test-call-interactively): Prefer a locally scoped function.

* lisp/simple.el (interactive-form): Don't skip the method dispatch
when recursing.
(interactive-form) <advice>: New method.

* lisp/emacs-lisp/nadvice.el (advice--where-alist): Fix typo.
(advice--get-interactive-form): New function.

* lisp/emacs-lisp/oclosure.el (oclosure-lambda): Fix thinko.

* lisp/emacs-lisp/cl-generic.el: Prefill with an OClosure dispatcher.
2021-12-18 17:25:50 -05:00
Stefan Monnier
5837f75e0f nadvice.el: Restore interactive-form handling
* test/lisp/emacs-lisp/nadvice-tests.el
(advice-test-call-interactively): Prefer a locally scoped function.

* lisp/simple.el (interactive-form): Don't skip the method dispatch
when recursing.
(interactive-form) <advice>: New method.

* lisp/emacs-lisp/nadvice.el (advice--where-alist): Fix typo.
(advice--get-interactive-form): New function.

* lisp/emacs-lisp/fcr.el (fcr-lambda): Fix thinko.

* lisp/emacs-lisp/cl-generic.el: Prefill with an FCR dispatcher.
2021-12-18 17:25:50 -05:00
Stefan Monnier
5574871ec7 nadvice.el: Use OClosures rather than handmade bytecodes
* lisp/emacs-lisp/nadvice.el (advice): New OClosure type.
(advice--where-alist): Use OClosures.
(advice--car, advice--cdr, advice--props, advice--where):
Delete functions, now defined for us by `oclosure-define`.
(advice--p): Rewrite.
(advice--make-1): Delete function.
(advice--make, advice--tweak): Use `advice--copy` instead.

* lisp/emacs-lisp/oclosure.el (oclosure--fix-type): Don't use `documentation` to
avoid bootstrap problems.
(oclosure-type): Return nil on non-function objects.

* lisp/help.el (help--docstring-quote, help-add-fundoc-usage)
(help--make-usage, help--make-usage-docstring): Move to `subr.el`.

* lisp/subr.el (docstring--quote, docstring-add-fundoc-usage)
(docstring--make-usage, docstring--make-usage-docstring): New names for
functions moved from `help.el` for bootstrap reasons.

* lisp/emacs-lisp/cl-macs.el (cl--transform-lambda): Use the new names.
2021-12-18 10:28:57 -05:00
Stefan Monnier
49992d58bd nadvice.el: Use FCRs rather than handmade bytecodes
* lisp/emacs-lisp/nadvice.el (advice): New FCR type.
(advice--where-alist): Use FCRs.
(advice--car, advice--cdr, advice--props, advice--where):
Delete functions, now defined for us by `fcr-defstruct`.
(advice--p): Rewrite.
(advice--make-1): Delete function.
(advice--make, advice--tweak): Use `advice--copy` instead.

* lisp/emacs-lisp/fcr.el (fcr--fix-type): Don't use `documentation` to
avoid bootstrap problems.
(fcr-type): Return nil on non-function objects.

* lisp/help.el (help--docstring-quote, help-add-fundoc-usage)
(help--make-usage, help--make-usage-docstring): Move to `subr.el`.

* lisp/subr.el (docstring--quote, docstring-add-fundoc-usage)
(docstring--make-usage, docstring--make-usage-docstring): New names for
functions moved from `help.el` for bootstrap reasons.

* lisp/emacs-lisp/cl-macs.el (cl--transform-lambda): Use the new names.
2021-12-18 10:28:57 -05:00
Stefan Monnier
a444d85977 Fix bootstrap problems and various misc issues found along the way
* lisp/simple.el (function-docstring): Fix call to `signal`.

* lisp/emacs-lisp/oclosure.el (oclosure--define): Use `cl-deftype-satisfies`.

* lisp/emacs-lisp/cl-generic.el (cl--generic-prefill-dispatchers):
Bind `cl--generic-compiler` around the right part of the function (duh!).
2021-12-17 14:53:03 -05:00
Stefan Monnier
f2d8a24e21 Fix bootstrap problems and various misc issues found along the way
* lisp/simple.el (function-docstring): Fix call to `signal`.

* lisp/emacs-lisp/fcr.el (fcr--define): Use `cl-deftype-satisfies`.

* lisp/emacs-lisp/cl-generic.el (cl--generic-prefill-dispatchers):
Bind `cl--generic-compiler` around the right part of the function (duh!).
2021-12-17 14:53:03 -05:00
Stefan Monnier
3119e59252 lisp/emacs-lisp/oclosure.el: Rename oclosure-make to oclosure-lambda
* lisp/emacs-lisp/oclosure.el (oclosure-lambda): Rename from `oclosure-make`.
* lisp/emacs-lisp/cl-generic.el (cl-generic-call-method):
* test/lisp/emacs-lisp/oclosure-tests.el (oclosure-tests):
* lisp/kmacro.el (kmacro-lambda-form): Adjust accordingly.
2021-12-17 12:45:01 -05:00
Stefan Monnier
a21cbc05f2 lisp/emacs-lisp/fcr.el: Rename fcr-make to fcr-lambda
* lisp/emacs-lisp/fcr.el (fcr-lambda): Rename from `fcr-make`.
* lisp/emacs-lisp/cl-generic.el (cl-generic-call-method):
* test/lisp/emacs-lisp/fcr-tests.el (fcr-tests):
* lisp/kmacro.el (kmacro-lambda-form): Adjust accordingly.
2021-12-17 12:45:01 -05:00
Stefan Monnier
d93b0ad4d4 (interactive-form, function-docstring): New generic functions
Change `interactive-form` to be a generic function, and
change `documentation` to delegate to a new `function-docstring`
generic function so that we can use `cl-defmethod` to construct
the docstrings and interactive forms of OClosures.

* src/eval.c (Fcommandp): Rewrite to delegate to `interactive-form`
when potentially necessary.

* src/doc.c (Fdocumentation): Delegate to `function-docstring` in
most cases.

* src/data.c (Finternal__interactive_form): Rename from
`Finteractive_form` and simplify to only handle the cases we can't (yet)
handle from Lisp.
(syms_of_data): Adjust accordingly.

* src/callint.c (Fcall_interactively): `interactive-form` is now
defined in Lisp.

* lisp/simple.el: Require `subr-x`.
(function-docstring, interactive-form): New generic functions.

* lisp/loadup.el ("simple"): Postpone loading it after `cl-generic`.

* lisp/emacs-lisp/macroexp.el (internal-macroexpand-for-load):
Don't neuter eager macroexpansion errors.

* lisp/emacs-lisp/cl-generic.el (cl--generic-lambda):
Avoid `interactive-form` to avoid breaking bootstrap since it's now
defined as a generic function.
(cl-defmethod): Simplify.
(cl--generic-compiler): New var.
(cl--generic-get-dispatcher): Use it.
(cl--generic-prefill-dispatchers): Rebind it.
2021-12-16 23:58:17 -05:00
Stefan Monnier
febe7acf5a (interactive-form, function-docstring): New generic functions
Change `interactive-form` to be a generic function, and
change `documentation` to delegate to a new `function-docstring`
generic function so that we can use `cl-defmethod` to construct
the docstrings and interactive forms of FCRs.

* src/eval.c (Fcommandp): Rewrite to delegate to `interactive-form`
when potentially necessary.

* src/doc.c (Fdocumentation): Delegate to `function-docstring` in
most cases.

* src/data.c (Finternal__interactive_form): Rename from
`Finteractive_form` and simplify to only handle the cases we can't (yet)
handle from Lisp.
(syms_of_data): Adjust accordingly.

* src/callint.c (Fcall_interactively): `interactive-form` is now
defined in Lisp.

* lisp/simple.el: Require `subr-x`.
(function-docstring, interactive-form): New generic functions.

* lisp/loadup.el ("simple"): Postpone loading it after `cl-generic`.

* lisp/emacs-lisp/macroexp.el (internal-macroexpand-for-load):
Don't neuter eager macroexpansion errors.

* lisp/emacs-lisp/cl-generic.el (cl--generic-lambda):
Avoid `interactive-form` to avoid breaking bootstrap since it's now
defined as a generic function.
(cl-defmethod): Simplify.
(cl--generic-compiler): New var.
(cl--generic-get-dispatcher): Use it.
(cl--generic-prefill-dispatchers): Rebind it.
2021-12-16 23:58:17 -05:00
Stefan Monnier
ae0bfc4f75 * lisp/loadup.el (oclosure): Load before nadvice
* lisp/loadup.el (oclosure): Load before `nadvice`.

* lisp/emacs-lisp/cl-generic.el (cl--generic-class-parents): Move to
`cl-preloaded.el`.
(cl--generic-struct-specializers, cl-generic--oclosure-specializers)
(cl--generic-specializers-apply-to-type-p): Use its new name.

* lisp/emacs-lisp/cl-preloaded.el (cl--class-allparents): New function
moved from `cl-generic.el`.

* lisp/emacs-lisp/oclosure.el (oclosure-define): Use it.

* lisp/emacs-lisp/cl-macs.el (pcase--mutually-exclusive-p):
Don't advise if `nadvice` has not yet been loaded.
2021-12-13 19:07:32 -05:00
Stefan Monnier
76b27662fd * lisp/loadup.el (fcr): Load before nadvice
* lisp/loadup.el (fcr): Load before `nadvice`.

* lisp/emacs-lisp/cl-generic.el (cl--generic-class-parents): Move to
`cl-preloaded.el`.
(cl--generic-struct-specializers, cl-generic--fcr-specializers)
(cl--generic-specializers-apply-to-type-p): Use its new name.

* lisp/emacs-lisp/cl-preloaded.el (cl--class-allparents): New function
moved from `cl-generic.el`.

* lisp/emacs-lisp/fcr.el (fcr-defstruct): Use it.

* lisp/emacs-lisp/cl-macs.el (pcase--mutually-exclusive-p):
Don't advise if `nadvice` has not yet been loaded.
2021-12-13 19:07:32 -05:00
Stefan Monnier
e052bb2770 * lisp/kmacro.el: Use OClosure instead of messing with internals
* test/lisp/progmodes/elisp-mode-tests.el
(xref-elisp-generic-co-located-default): Silence warnings.

* test/lisp/kmacro-tests.el (kmacro-tests--cl-print): New test.

* lisp/kmacro.el (kmacro-function): New OClosure type.
(kmacro-lambda-form): Use it.
(kmacro-extract-lambda, kmacro-p): Simplify/rewrite accordingly.
(cl-print-object): New method.

* lisp/emacs-lisp/oclosure.el (oclosure-make): Keep interactive specs before the
function's code.

* lisp/edmacro.el (edmacro-finish-edit): Prefer `kmacro-p`.
2021-12-13 16:43:58 -05:00
Stefan Monnier
463e621c29 * lisp/kmacro.el: Use FCR instead of messing with internals
* test/lisp/progmodes/elisp-mode-tests.el
(xref-elisp-generic-co-located-default): Silence warnings.

* test/lisp/kmacro-tests.el (kmacro-tests--cl-print): New test.

* lisp/kmacro.el (kmacro-function): New FCR type.
(kmacro-lambda-form): Use it.
(kmacro-extract-lambda, kmacro-p): Simplify/rewrite accordingly.
(cl-print-object): New method.

* lisp/emacs-lisp/fcr.el (fcr-make): Keep interactive specs before the
function's code.

* lisp/edmacro.el (edmacro-finish-edit): Prefer `kmacro-p`.
2021-12-13 16:43:58 -05:00
Stefan Monnier
f11349ed20 * lisp/emacs-lisp/cl-generic.el: Use OClosure for cl-next-method-p
* lisp/emacs-lisp/oclosure.el (oclosure--define): Avoid `cl-lib` at run-time.
(oclosure--type-sym): Delete variable.  Use an interned symbol instead,
so the closures stand a chance of being printable readably.
(oclosure--fix-type, oclosure--copy, oclosure-get, oclosure-type): Adjust accordingly.

* lisp/emacs-lisp/cl-generic.el (cl--generic-nnm): New OClosure type.
(cl--generic-no-next-method-function): Delete function.
(cl-generic-call-method): Use it for the default no-next-method case.
(cl--generic-nnm-sample, cl--generic-cnm-sample): Delete vars.
(cl--generic-isnot-nnm-p): Use `oclosure-type`.
2021-12-13 11:33:49 -05:00
Stefan Monnier
a3640a88f0 * lisp/emacs-lisp/cl-generic.el: Use FCR for cl-next-method-p
* lisp/emacs-lisp/fcr.el (fcr--define): Avoid `cl-lib` at run-time.
(fcr--type-sym): Delete variable.  Use an interned symbol instead,
so the closures stand a chance of being printable readably.
(fcr--fix-type, fcr--copy, fcr-get, fcr-type): Adjust accordingly.

* lisp/emacs-lisp/cl-generic.el (cl--generic-nnm): New FCR type.
(cl--generic-no-next-method-function): Delete function.
(cl-generic-call-method): Use it for the default no-next-method case.
(cl--generic-nnm-sample, cl--generic-cnm-sample): Delete vars.
(cl--generic-isnot-nnm-p): Use `fcr-type`.
2021-12-13 11:33:49 -05:00
Stefan Monnier
263172dbfb lisp/emacs-lisp/oclosure.el: Make it available to cl-generic
* lisp/loadup.el: Load `oclosure`.

* lisp/emacs-lisp/oclosure.el: Don't use `cl-lib` at runtime.
(oclosure--copy): Use `named-let` instead of `cl-mapcar`.
(oclosure--struct-tag, oclosure--struct-specializers, oclosure--struct-generalizer)
(cl-generic-generalizers): Move cl-generic support to cl-generic.

* lisp/emacs-lisp/cl-generic.el (cl--generic-oclosure-tag)
(cl-generic--oclosure-specializers, cl-generic--oclosure-generalizer)
(cl-generic-generalizers): Move OClosure support from `oclosure.el`.
2021-12-13 11:00:04 -05:00
Stefan Monnier
2554d029f6 lisp/emacs-lisp/fcr.el: Make it available to cl-generic
* lisp/loadup.el: Load `fcr`.

* lisp/emacs-lisp/fcr.el: Don't use `cl-lib` at runtime.
(fcr--copy): Use `named-let` instead of `cl-mapcar`.
(fcr--struct-tag, fcr--struct-specializers, fcr--struct-generalizer)
(cl-generic-generalizers): Move cl-generic support to cl-generic.

* lisp/emacs-lisp/cl-generic.el (cl--generic-fcr-tag)
(cl-generic--fcr-specializers, cl-generic--fcr-generalizer)
(cl-generic-generalizers): Move FCR support from `fcr.el`.
2021-12-13 11:00:04 -05:00