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
Added Context Action Patterns. #1643
base: master
Are you sure you want to change the base?
Conversation
It is now possible to use patterns to specify the context action command to be executed if the user selects "Context Action" from the context menu. The patterns can be configured in the filetypes configuration files. Each action pattern entry needs to have a key of the form "context_action_pattern" followed by a number from 1 to 99 (e.g. "context_action_pattern1", "context_action_pattern2"). The value assigned must be a ';' separated string list with two entries. First, the pattern to match and then the command to execute. So a complete entry looks like this: context_action_pattern1=pattern;command; Loading of the patterns stops after the 99th entry or if no more entries are found. A gap in the entries numeration would lead to early abort of loading. To find the corresponding action command for the current word/selection the following procedure is performed: 1. Try to match the current selection/word against a pattern. If there is a match then the corresponding command is returned. Patterns are matched in the order in which they are specified in the filetype config file. The pattern matching uses the flag "G_REGEX_MATCH_ANCHORED" which means the pattern needs to match the word from the start. This is equal to using "^" at the start of the pattern. 2. If there is no match return the "context_action_cmd" for the filetype. 3. If that is empty use the context action from the global "Tools" preferences
Just added the documentation of the feature to the manual. |
Seems really useful, will give it a test. |
Well, honestly I did not plan one cause I thought it would be quite an effort to implement the UI fields for a varying number of values. |
@LarsGit223 I havn't had a chance to look at this in detail, but is it only per-filetype, or do you have a set that is filetype independent? Or are filetype independent context actions still limited to one puny no pattern command? AFAIK nothing in the filetype files has a GUI, so its probably ok to leave those without (well except for The filetype independent probably needs a GUI since its tricky to edit |
No, it only works per filetype.
The context action can be configured in the tools section of the configuration preferences. But that is a global fallback value, not per filetype. You can also check the manual section that I wrote but at a quick glance it works like this:
So it works on top of the old mechanism and uses the old mechanism as a fallback. |
@kugel-: did you have time to give it a test? Any feedback would be appreciated. |
It is now possible to use patterns to specify the context action command to be executed
if the user selects "Context Action" from the context menu. The patterns can be configured
in the filetypes configuration files.
Each action pattern entry needs to have a key of the form "context_action_pattern" followed by
a number from 1 to 99 (e.g. "context_action_pattern1", "context_action_pattern2"). The value
assigned must be a ';' separated string list with two entries. First, the pattern to match and
then the command to execute. So a complete entry looks like this:
context_action_pattern1=pattern;command;
Loading of the patterns stops after the 99th entry or if no more entries are found.
A gap in the entries numeration would lead to early abort of loading.
To find the corresponding action command for the current word/selection the following
procedure is performed:
If there is a match then the corresponding command is returned.
Patterns are matched in the order in which they are specified in the filetype config file.
The pattern matching uses the flag "G_REGEX_MATCH_ANCHORED" which means the pattern
needs to match the word from the start. This is equal to using "^" at the start
of the pattern.
Here is an example config for
filetype.c
to try out the feature:This config will open/search the cplusplus website if there is no match in the patterns. If the current word/selection starts with
g_
then it searches the gnome API. If the current word/selection starts withxml
then it searches the Libxml2 website.