Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

lpaulsen93
Copy link
Contributor

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

Here is an example config for filetype.c to try out the feature:

# context action command (please see Geany's main documentation for details)
context_action_cmd=firefox --new-tab "http://www.cplusplus.com/search.do?q=%s"
context_action_pattern1=g_.*;firefox --new-tab "https://developer.gnome.org/symbols/search?q=%s";
context_action_pattern2=xml.*;firefox --new-tab "http://xmlsoft.org/search.php?query=%s";

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 with xml then it searches the Libxml2 website.

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
@lpaulsen93
Copy link
Contributor Author

Just added the documentation of the feature to the manual.

@kugel-
Copy link
Member

kugel- commented Nov 10, 2017

Seems really useful, will give it a test.
Maybe there ought to be an UI for configuration?

@lpaulsen93
Copy link
Contributor Author

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.

@elextr
Copy link
Member

elextr commented Nov 10, 2017

@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 Tools->Configuration Files->etc etc editing).

The filetype independent probably needs a GUI since its tricky to edit geany.conf since Geany re-writes it all the time, but agree that GUIs for variable numbers of things is more complex since it has to be generated by code not Glade, see the Set Build Commands dialog. And maybe independent ones should be stored/read from the project file if its open, and project filetype ones ... getting flashbacks of creating the build command system ... so maybe this can be another follow on pull request. 😁

@lpaulsen93
Copy link
Contributor Author

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?

No, it only works per filetype.

AFAIK nothing in the filetype files has a GUI, ...

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:

  • read context action patterns from filetype config
  • on selection of context action context menu:
    • try to match a pattern, use the action if there is a match
    • if not, execute the filetype's context action
    • if not set, execute the global context action (from the tools config preferences)

So it works on top of the old mechanism and uses the old mechanism as a fallback.

@lpaulsen93
Copy link
Contributor Author

@kugel-: did you have time to give it a test? Any feedback would be appreciated.

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

Successfully merging this pull request may close these issues.

None yet

3 participants