-
-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use completion-at-point and abbrev-mode for LaTeX substitution #100
Conversation
@tpapp I was going to push an additional commit that also overrides TAB to dynamically do I would prefer to keep the concept of completion and abbrevs separate conceptually and possibly bind some other easily accessible key combination to |
Sorry for not getting back to you on this yet, I will need some time to review it but may not get to it until the middle of this week. I will think about this question too. |
Thanks for doing this, and in such a clean way. I like the code. I would like to merge this in some form, but I am wondering what the best interface is (or if people prefer various versions, how to support them all) so I am inviting people to comment on how they use completion. Personally, I would prefer the following: a single TAB
The motivation for the above is that trying to enter a I don't know enough about |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a huge improvement -- nice work!
first tries to indent. if it did, then it is done. if the indentation was unchanged, then:
This is the configuration I prefer as well, but it should all conform to the emacs conventions set with tab-always-indent
, in that case, using complete
.
whenever the point is in or immediately after a complete LaTeX abbreviation, it is replaced by the relevant abbrev, eg \sqrt is replaced by √,
I don't think converting \sqrt
to √
without further input is a good solution, cause you might still be planning to write something else -- the julia REPL doesn't do this either (at least not in my version).
I do think it would be an improvement to convert the abbrevs when the next input is a symbol, howerver, eg. \alpha*
=> α*
. In the sqrt case, it would be nice to expand if the next input was a number, perhaps, but sadly numbers have word syntax - so some other workaround would be required probably.
Last time I looked into it, abbrevs were expanded after word syntax at the C level (meaning if the last user input was a '\sqrt5', only an abbrev matching that would expand - and expansion isn't attempted if the last input is non-word syntax, eg '*'), but customization could be added in a post-self-insert-hook
(I left one that works for symbols in the review).
The only thing I would change is giving the latex abbrev table a non-default name, so that user defined abbrevs still work (eg. they aren't also required to have the special expansion regexp requirement). An alternative could be to add the latex abbrev table as a parent of the julia-mode-abbrev-table
.
enables `abbrev-mode' so that inserting a space character will replace | ||
a LaTeX string with a unicode symbol." | ||
:type 'boolean) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want to expand-abbrevs
after any punctuation, eg. \alpha* => {laxex alpha}*, you could add
a local post-self-insert-hook
along the lines of
(defun julia-abbrev-expand-after-symbols-hook ()
(and (memq (car (syntax-after (1- (point)))) '(0 3))
(setq this-command 'julia-abbrev-expand-after-symbols)
(expand-abbrev)))
which I use in, eg. elisp, where I want my abbrevs to expand after I enter a ')' for example.
It could be another user choice to consider. IIRC I needed to add this as a post-self-insert
command because abbrev expansion after word syntax was hard-coded in C, but the implementation may have changed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem with this is all of the LaTeX codes that include punctuation (or even parentheses). Some examples: \^)
, \_=
, \:soccer:
, \^+
. I guess in practice, as long as none of the LaTeX codes that include symbols have other LaTeX codes that are superstrings of them cut off at the symbol it could be fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think converting \sqrt to √ without further input is a good solution, cause you might still be planning to write something else
Then this may just be my personal preference --- if I want to choose between \sqrt
and \sqrtbottom
, I would complete on \sqr
and pick from the popup. If feasible, keeping this modular and customizable would be nice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some examples: ^), _=, ⚽, ^+
Good point -- the above is too simple for this case
I suppose you could make it more complicated and check that the prefix so far isn't a prefix of other latex symbols in your table -- but then I think that would be pushing the amount of computation you would want to do in a post-self-insert-hook
I also really like the completion working in the middle of symbols, as it does in elisp. |
Agreed, I think intertwining them is likely to break stuff. Abbrevs have been around forever, having their own distinct behaviour. Also, as with everything, the more modular the better - you would want to allow people to opt out of abbrevs, but use completion, and vice versa IMHO. |
It would be a bit hacky, but I can build that interface on top of capf and abbrev, which would still allow people to customize a variable to use capf and abbrev in the emacs default manner. As mentioned above, doing so would not be my preference, but I can certainly implement that if it's the consensus. |
Could you expand on what you mean by here? Specifically "default name" isn't clear to me, nor is it clear how this interferes with regexps for user-defined abbrevs. And what latex abbrev table are you recommending we inherit from? Keep in mind this PR is my first time dipping my toes in the waters of |
Call it |
I've rebased on master and pushed a commit fixing the issue with the regex clobbering user abbrevs noted by @nverno. Now just awaiting feedback/decision on integrating LaTeX substitution/expansion. |
Can you briefly summarize that the alternatives are, and the trade-offs (if any?) |
Sure. Trying to be as brief as possible:
There may be other options and advantages/disadvantages I've missed, but those are the ones that have been bouncing around in my head. |
Sorry for being dense, but I am somewhat confused. I have re-read the history, and found that the original motivation of this string of PRs, starting with #80, was that
I am generally in favor of doing these things, but from various experiments it appears to be difficult to do this in a way that preserves the single-keystroke behavior we have currently. Given that we have a working solution, should we switch to one of the backends at this cost, just to be a better Emacs citizen? Note that I like the current setup, so it is possible that I am missing something that someone else's workflow/setup requires. I am happy to accommodate that, but I am a bit lost why this is needed. That said, this PR has a lot of code improvements which should be incorporated. |
I'm afraid my phrasing in #80 reflects my poor understanding (at the time) of how completion works in Emacs. Sorry about the confusion caused. The real benefit here is that by tying into |
JuliaEditorSupport/julia-emacs#100 changes LaTeX completion in julia-mode to work by a combination of completion-at-point-function and abbrev-mode. This is the necessary change to give full-featured LaTeX completion with emacs-jupyter julia buffers with the PR in its current form.
@tpapp what's the path forward here given the deafening silence of user-input on desired behavior? |
Apologies for the lack of feedback. This is something I want to think about a bit and experiment with, but I am overwhelmed with other stuff at the moment. I understand that putting in the work and not getting it merged can be frustrating, but I ask for your further patience. |
No problem. And no pressure from me with respect to getting this or any pull-request i make merged (and definitely no frustration). I am already happily using all changes I've proposed on my own machines. Just wanted to make sure you weren't waiting on some other input or change from me. :) |
JuliaEditorSupport/julia-emacs#100 changes LaTeX completion in julia-mode to work by a combination of completion-at-point-function and abbrev-mode. This is the necessary change to give full-featured LaTeX completion with emacs-jupyter julia buffers with the PR in its current form.
JuliaEditorSupport/julia-emacs#100 changes LaTeX completion in julia-mode to work by a combination of completion-at-point-function and abbrev-mode. This is the necessary change to give full-featured LaTeX completion with emacs-jupyter julia buffers with the PR in its current form.
JuliaEditorSupport/julia-emacs#100 changes LaTeX completion in julia-mode to work by a combination of completion-at-point-function and abbrev-mode. This is the necessary change to give full-featured LaTeX completion with emacs-jupyter julia buffers with the PR in its current form.
JuliaEditorSupport/julia-emacs#100 changes LaTeX completion in julia-mode to work by a combination of completion-at-point-function and abbrev-mode. This is the necessary change to give full-featured LaTeX completion with emacs-jupyter julia buffers with the PR in its current form.
@tpapp you had time to look at this yet? I understand if not, but I thought I'd ask since rebasing my personal I thought I should also explain a bit better my objection to our current approach: it breaks composibility (and doesn't offer real completion). Emacs has builtin facilities for both "completion" ( |
Thanks. Can the warning
be somehow suppressed? FWIW, I am always happy to drop support for old Emacs versions. |
This follows the pattern for conditional integration code from "net/tramp-integration.el".
I'm not seeing byte-compilation errors locally after the last commit. |
@tpapp Friendly ping. Are you ready to merge this? Should I push an additional commit changing minimum emacs version and test targets and a changelog update? |
@non-Jedi: sorry I was sick for 2 weeks and I am still catching up. I promise that I will merge this PR once I had a chance to evaluate it. The problem is that my emacs config contains a lot of idiosyncratic cruft that interferes with completion. I need to bisect and clean it up. I realize thay you did a lot of work on this and it is frustrating to wait for one person. So if anyone else wants to merge this, feel free to do so In the meantime, please understand that additional work you do on this will not be wasted and this will definitely get merged. |
@tpapp I hope you're feeling better! It always stinks being sick over the holidays. No pressure on getting this merged; just let me know if I can help any more with making this play nicely with your config (I had hoped the recent company-specific commits would have fixed most issues, but no dice, huh). I appreciate you doing the thankless work of maintaining this and reviewing PRs. |
@non-Jedi: thanks for your patience. I have cleaned up my Emacs config and it works fine (I think it was some interaction with some ido thing, but I did not track it down). I have now switched to corfu. I have been testing it for a week and it is superb. I am now happy to merge this, I think it has been reviewed quite thoroughly so I will not ask for another round of reviews. I will wait until Monday for comments though. |
NOTE after merging,
|
I have an issue with this PR, I wonder if anyone can replicate: in the buffer I have α\hat_mean with the cursor on the α̂ ie the |
Can confirm locally. I'll take a look. Seems to be an issue with my code as it happens with both emacs-native completion and corfu. |
@non-Jedi: I have been studying your code, the Emacs completion system (of which I am completely ignorant), and thinking about the design of my ideal completion system. It is clear that completion should always start on the I am wondering if more effort could be spent on finding the end though. Specifically, from the
would complete on
would complete on Then, given this, we could offer a pre-filtered table from the |
Have you seen https://github.com/ymarco/auto-activating-snippets ? |
@tecosaur: thanks, I was not aware of it. I would prefer to keep the completion depend only on the contents of the buffer and the location of the point. |
Sure, but it's doing exactly what you talked about regarding an efficient (tree) representation of valid next chars. |
@tpapp the problem is that trying smartly decide where the entity you're completing from the middle of results in ambiguity. Let's take One hacky solution I could try would be to create a series of ~10 |
EDIT: I pushed a commit that fixed this issue without any compromises. Leaving the original text as-is for the explanation of the bug. See f359fd0 for the solution.
I figured out what's going on here, but I'm not sure what the best way to fix it is. Here's
Here's roughly what we'd like to happen instead which is what does happen if
Right now, I only see a few options for fixing this:
|
This predicate ensures that the symbol you're trying to complete is a substring of the completion candidates. With "before" completion this isn't necessary since there isn't potential for the symbol you're trying to complete containing text that isn't intended to be completed. This commit also includes some refactors for clarity and DRY.
At this point I have nothing against pre-filtering, but I realized that I cannot spare the effort of reading the whole Completion chapter in the manual and then looking at what other language modes do. As typical for Emacs, there are a few hundred different ways of doing what we want, we should opt for the one that meshes the best with the completion frameworks people introduced recently. But I have no detailed knowledge of how these work. Also, I am happy to get rid of "around" completion if we need to, or severely restrict it (eg only works on full escapes, or whatever we need). |
The latest commit does not fix the disappearing suffix issue for me. However, I am now warming to the idea of removing "around" completion. I previously thought that it is a nifty feature, but now I do not think it is so important. The main purpose of this feature is input of UTF-8 characters, ie you input them and you are done. Typing But I would like to make this mode comfortable for all users if feasible, so please comment. @adam-higuera (cf #70)? |
@non-Jedi: I brute-forced end lookup with a hash table, please take a look at non-Jedi#1, a PR against your branch. Personally I find it performant. |
I have been testing it the above modification two days and find it nice, does exactly what I want. Is anyone else testing this PR in practice? Please try out non-Jedi#1 and let me know how it goes, especially wrt to performance and corner cases. Now that tree-sitter is on the horizon I would like to merge this in a couple of weeks. |
JuliaEditorSupport/julia-emacs#100 changes LaTeX completion in julia-mode to work by a combination of completion-at-point-function and abbrev-mode. This is the necessary change to give full-featured LaTeX completion with emacs-jupyter julia buffers with the PR in its current form.
Disclaimer
Additional commits have been pushed to this branch since this original post was written. This PR now implements immediate substitution of the Unicode symbol for the TeX string upon completion instead of requiring entering a space or symbol or manually triggering
expand-abbrev
which is shown and described here. This comment is my most up to date summary of the pros and cons of this change.Original Post
I think this is a more sane version of #82. When
|
represents the cursor, all of\l|am
,\lam|
, and\lam|someothertext
will complete as expected. The latex backslash-string won't be automatically substituted for the unicode symbol unless the user inserts a whitespace or callsexpand-abbrev
C-x a e. Ping @nverno as being similar to your personal setup.Summarizing this PR:
julia-mode
completion-at-point
will now complete LaTeX symbols to their full text for both the case of cursor in the middle of the symbol and cursor at the end (\la|m
->\lambda
and\lam|othertext
to\lambdaothertext
).julia-mode
now first tries to indent the line, and if already indented usescompletion-at-point
to complete LaTeX strings.expand-abbrev
(C-x a e) or entering a non-word-syntax character after a LaTeX string will now replace the LaTeX string with its unicode character.As with #82, I've tried to break this up into conceptually cohesive commits that can be reviewed independently.
Demonstration gif: