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.
You can view, comment on, or merge this pull request online at:

  https://github.com/geany/geany/pull/1643

-- Commit Summary --

  * Added Context Action Patterns.

-- File Changes --

    M src/callbacks.c (7)
    M src/filetypes.c (107)
    M src/filetypes.h (3)

-- Patch Links --

https://github.com/geany/geany/pull/1643.patch
https://github.com/geany/geany/pull/1643.diff

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/geany/geany/pull/1643

Reply via email to