Skip to content

Consistent condition evaluation with multiple prefixes and abbrev support#201

Open
martenlienen wants to merge 3 commits intominad:mainfrom
martenlienen:multi-template-robustness
Open

Consistent condition evaluation with multiple prefixes and abbrev support#201
martenlienen wants to merge 3 commits intominad:mainfrom
martenlienen:multi-template-robustness

Conversation

@martenlienen
Copy link
Copy Markdown

@martenlienen martenlienen commented Mar 13, 2026

This PR supersedes #200.

It solves the problems that the other PR had and makes tempel generally more robust:

  1. There is now a function tempel--prefixes that returns all possible prefixes that could be expanded at point.
  2. tempel--templates exposes the condition of templates, which was necessary to
  3. extend the abbrev integration so that the same key can expand to different templates depending on which conditions are fulfilled. For example, I have two if templates in python which should expand depending on if I am in statement or expression context.
  4. Multiple prefixes and multiple templates with colliding names are handled correctly everywhere by either letting the user choose one or combining them into a joint capf list.
  5. There are now two re-usable functions. tempel--select-template lets the user pick a template with completing-read whenever the current template is not unique. tempel--capf-list constructs a capf list that combines templates together regardless of key clashes or triggering prefixes of different length and is used wherever a capf list is needed. Before, tempel-expand would use a less fully-featured capf list than tempel-complete.
  6. The abbrev integration now also expands templates with special characters in their names and it considers all possible templates when expanding (If we have two templates abc and bc and type abc, now both templates will be offered for expansion for the user to select via tempel--select-template).

This is a good set of templates to try it

python-base-mode
(s "hello")
(<s "world")
(sun "bye")
(surf "python")
(+six "groovy")

This ensures that :when conditions are evaluated at consistent positions between prefix
expansion and template insertion with ~tempel-insert~.
@martenlienen martenlienen force-pushed the multi-template-robustness branch from 483ff18 to d4f65c3 Compare March 27, 2026 11:28
@martenlienen
Copy link
Copy Markdown
Author

@minad I am sorry for sending such a large pull request. Is there anything I can do to help the review? I have been running this for two weeks now without any hiccups. The force-pushes a few minutes ago were just to update the readme and ensure backwards compatibility with sources that directly evaluate to a list of templates. (Because this PR implements the split source -> filter -> maybe select, sources are now expected to return lists ((modes . templates) ...), but if a source just gives a list of templates it gets wrapped as ((fundamental-mode) . templates).

@minad
Copy link
Copy Markdown
Owner

minad commented Mar 27, 2026

Hi Marten, sorry for letting you wait for so long, and thanks for the PRs. You could try to reduce the diff as much as possible, splitting changes in logical commits, which could also be applied separately, but you likely already tried that, I guess? The problem is really that I cannot sink more and more time and effort into my package maintenance without additional appreciation from the community. A lot of time is already taken by answering questions on the bug trackers or discussion boards, fixing obvious bugs, routine maintenance or adapting to Emacs changes. This means I have to prioritize accordingly, and larger work usually happens in bursts. I did some work on Tempel recently and when the time comes where I focus on Tempel again, I will likely look into the prefix problem here. Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants