Aggressively narrow some external functions#298
Aggressively narrow some external functions#298akater wants to merge 2 commits intopolymode:masterfrom
Conversation
vspinu
left a comment
There was a problem hiding this comment.
Thanks!
All compatibility stuff should go into polymode-compat.el as much a possible.
polymode-core.el
Outdated
| ;; Also, smartparens does sp--update-local-pairs | ||
| ;; which might bring smartparens into broken state | ||
| ;; if brackets are unbalanced. | ||
| (advice-add 'sp-wrap--can-wrap-p :around #'always) |
There was a problem hiding this comment.
I don't understand why this should be happening when the mode is installed. It's a global advice, so it could be done just fine like other advices in polymode-compat.el or not?
I would actually very much prefer it to be a well documented stand alone advice and not a programatically installed one somewhere in the core code. This way people could easier find out who is advising and why.
5b22656 to
702f082
Compare
|
I see that you alerady have this mechanism. This begs several questions. In order of decreasing importance,
and initialize an Org buffer with lisp blocks, and with In what case then will This better be in the documentation; I couldn't find the answer. In fact, the whole
which does not help.
|
|
Sorry for late response. I have missed your reply somehow.
I don't use paredit but I think this is not what you want. As the name suggests Paredit's situation might be a bit more complex if it has to parse the entire buffer and does assume homogenuous syntax. If it simply relies on
Because it's a dynamically bound variable available only within the mapping functions. It does't make sense to bind it globally or locally in the buffer. I have clarified the docs of those compact functions.
No one reported a simple and clear reproducible issue. I am not a user of paredit mode so I cannot see the issue by myself either. |
702f082 to
4ac4fbd
Compare
4ac4fbd to
6490c92
Compare
vspinu
left a comment
There was a problem hiding this comment.
I am looking at this again after some years, and it's still not making a lot of sense to me.
I think a much smaller and more readable incision could be done here without these extra constructs. To summarize the comments, I think all what's needed is to:
- Advice whatever functions need to be narrowed with
pm-execute-narrowed-to-span - Advice worker functions to do what's needed conditionally on if it's in a polymode buffer (ex. paredit-override-check-parens-function)
- (most likely unnecessary) Advice mode functions to behave differently in the polymode buffers (conditional on polymode-mode being t)
| ;;; Code: | ||
|
|
||
| (require 'polymode-core) | ||
| (require 'polymode-compat) |
There was a problem hiding this comment.
polymode-compat is very dirty, it should not be included in the core.
| (condition-case-unless-debug err | ||
| ;; !! run-mode-hooks and hack-local-variables run here | ||
| (funcall mode) | ||
| (pm--funcall-mode-with-convenience mode) |
There was a problem hiding this comment.
This just can be done by advising the mode function. I don't see the need for such a hack in the polymode proper.
| ;; This is merely a guess, for example's sake. | ||
| ;; Also, smartparens does sp--update-local-pairs | ||
| ;; which might bring smartparens into broken state | ||
| ;; if brackets are unbalanced. |
There was a problem hiding this comment.
I don't understand all these changes. These are essentially internals of smartparens and paredit. Also the comments do explicitly say it's either "wrong" or "unsure about". So it's clearly not "production" ready.
| (narrow-to-region (nth 1 pm--localizing-span) | ||
| (nth 2 pm--localizing-span)) | ||
| (apply f args)) | ||
| (apply f args))) |
There was a problem hiding this comment.
If narrowing to current span is all what is needed, then one could just do:
(pm-around-advice 'some-function #'pm-execute-narrowed-to-span)
There was a problem hiding this comment.
Thank you. Yes, almost certainly, significant rewrites are needed. I submitted what seemed to be working for me just because it's a better start than an issue without any patch. Hopefully, I'll rewrite it soon.
This is a draft. We aim to
As written, this mitigates #255 w.r.t. paredit for me. We add global advices on loading polymode. How about we provide a custom variable to specify which functions to advice?
I did not research the smartparens part as I don't use it. I'll dig deeper if the overall idea gets approved.