Conversation
761bbf6 to
143ae8d
Compare
|
String substitution now works as well. Now an |
beb99d2 to
c606236
Compare
dc5f814 to
d3c387c
Compare
raxod502
left a comment
There was a problem hiding this comment.
I made a few small comments, although I didn't look through the whole implementation. If it works, that's the most important thing. I'm happy to advise on more specific parts if there are places you think should be improved.
Side note---we should add el-patch-template.el to the for_compile and for_checkdoc lists in Makefile.
As suggested by @raxod502 Co-authored-by: Radon Rosborough <radon.neon@gmail.com>
|
Thanks @raxod502. I've tested different forms and everything seems to work. Hopefully I didn't miss a use-case. I've tried to follow the documentation standards as you suggested. I added a few questions in the code review that I would appreciate your input on (including a question about how to correctly handle a Also, regarding your suggestions in #50. How about I create two versions:
I don't know if/how I can combine all of these into one version depending on context. |
Yes, two entry points seems right. I gave some thought to how to make the behavior of these functions the least surprising to the user, and came up with this proposal:
Then our two use cases look like this:
Here ya go! (defmacro magic-macro ()
(message "This message gets printed during macroexpansion")
`(progn
(message "This message gets printed at runtime")
,(if (bound-and-true-p byte-compile-current-file)
'(message "The macro was expanded during byte-compilation")
'(message "The macro was expanded at runtime"))))
(magic-macro)And then you can see the results as follows: |
|
OK, I implemented those ideas. I like the interface you suggested, but I find the fact that Instead, I made it so that In addition to PS: Sorry for the notifications! I just learned about drafts in github and converted the request to a draft. |
fa019ba to
6224e89
Compare
6224e89 to
3a0bbbc
Compare
Templates are only defined in compile-time if el-patch-template is loaded.
Oh, no worries, I disable notifications for newly pushed commits in any case :)
Makes sense!
Yeah, that seems pretty reasonable. Maybe could rename to
Yep yep, that makes sense.
Yeah, I think we do need to handle that. It should be fairly straightforward though, I think you just need to autoload any variables that need to be defined for the macroexpansion to execute successfully even if |
* el-patch-template.el (el-patch-define-compiletime-template): Renamed to el-patch-define-and-eval-template * el-patch.el (el-patch-wrap-locator): Kill buffer when done.
9a00153 to
287d746
Compare
|
I've added validation functions for templates (stolen from el-patch) and greatly simplified the implementation to avoid exceeding In my tests, having my templates in my init file did not slow down my startup time significantly (especially when I autoload them).
Hmm... Maybe I am misunderstanding something here. Here's what I am thinking a use-case might be:
In Is this what you also have in mind? |
OK, good to know. I guess most people don't care about having literally the smallest number of milliseconds of startup time, and it's fine to support having the templates expanded during startup, as long as there's also an option to not do that.
Oops, my bad :)
Your use case is the exact same one I have in mind.
That's a fine approach as well. It should have the same practical effect as what I suggested (autoloading the variable definition
By "the autoload file" do you mean the generated file which contains the autoloads of the That said, it is true that if the user is installing and loading Note that the definition of
So, suppose you have this in your init-file: (el-patch-defun company-statistics--load ()
"Restore statistics."
(load company-statistics-file 'noerror
(el-patch-swap nil 'nomessage)
'nosuffix))Then it macroexpands to this (courtesy of https://github.com/joddie/macrostep): (el-patch--definition
(defun company-statistics--load nil "Restore statistics."
(load company-statistics-file 'noerror
(el-patch-swap nil 'nomessage)
'nosuffix)))And then the (progn
(puthash 'defun
'(defun company-statistics--load nil "Restore statistics."
(load company-statistics-file 'noerror
(el-patch-swap nil 'nomessage)
'nosuffix))
(or
(gethash 'company-statistics--load el-patch--patches)
(puthash 'company-statistics--load
(make-hash-table :test
(function equal))
el-patch--patches)))
(el-patch--stealthy-eval
(defun company-statistics--load nil "Restore statistics."
(load company-statistics-file 'noerror 'nomessage 'nosuffix))
"This function was patched by `el-patch'."))Where as you can see there is a then the package manager will copy the following into the autoload file: (defvar el-patch--patches (make-hash-table :test 'equal) "\
Hash table of patches that have been defined.
The keys are symbols naming the objects that have been patched.
The values are hash tables mapping definition types (symbols
`defun', `defmacro', etc.) to patch definitions, which are lists
beginning with `defun', `defmacro', etc.
Note that the symbols are from the versions of patches that have
been resolved in favor of the modified version, when a patch
renames a symbol.")which should be loaded before anything else happens in user configuration, even if Does that answer your question? |
Thanks for taking the time to write that answer. Yes, everything is clear now. I added a section in the README and I think the branch is ready to be merged. Let me know if you think other changes are needed. |
da58a08 to
6bf0483
Compare
…-patch-template
el-patch--match-template-p was allowing partial matching of nested forms. Not anymore.
|
Thank you so much for your great work and patience! 🌹 |
This is an implementation of the ideas in #50. I put it as a pull request to discuss the implementation and how it can be improved/refined.
All the suggested examples by @raxod502 should work. Currently, the only limitation is that
...does not work as expected insideel-patch-concat. In particular, I would expect it to match a substring so that one does not have to write the full string if one wants to replace a single word in a long string. The implementation of such a functionality is not difficult but I wanted to get some feedback before complicating the code further.Also, currently
el-patch-templatesimply returns the patch form rather than yanking it to the kill-ring or executing it. For now, this can be done withrespectively. (In this instance
...should be filled.el-patch-templateis not magic :) )Any feedback on the syntax or my lisp is much appreciated (I am not an expert with lisp).