As a Geany user, so that I can invoke a web browser in the process of executing 
a build step, I would like to be able to reference the browser command setting.

I noticed in the Geany manual that if the user wants to configure a context 
action that uses a web browser (e.g., use the selected text (via '%s') as a 
parameter to firefox), they're encouraged to specify a command like this:
`firefox "http://www.php.net/%s"`

https://www.geany.org/manual/current/#context-actions

So, I got to thinking that Geany already has the user's browser of choice via 
the preferences mechanism.  Why, then, would Geany need the user to specify a 
browser when it already "knows?"

In the callbacks.c we can see the call to `spawn_async` on the command line 
after the '%s' has been substituted.

https://github.com/geany/geany/blob/master/src/callbacks.c#L1492

Then I thought, what if instead of having the filetype specify the command to 
run, security concerns aside, could we include a pattern that could be replaced 
by the browser specified by the user?

Seeing how the browser command is accessed in utils.c it looks like this could 
be done by replacing the pattern with `tool_prefs.browser_cmd`.

https://github.com/geany/geany/blob/master/src/prefs.c#L681

https://github.com/geany/geany/blob/master/src/utils.c#L85

The user could then specify a context action like this:

`%b "https://www.php.net/%s"`

(where `%b` is the pattern)

The additional stanza would look similar to what's in earlier in callbacks.c

https://github.com/geany/geany/blob/master/src/callbacks.c#L1490

Something like 
```c
utils_str_replace_all(&command_line, "%b", tool_prefs.browser_cmd);
```

Similarly, it would be nice if we could do something similar with the user's 
preferred terminal

```c
utils_str_replace_all(&command_line, "%t", tool_prefs.term_cmd);
```

https://github.com/geany/geany/blob/master/src/prefs.c#L678

It would also be nice if we could do the same with build commands

https://github.com/geany/geany/blob/master/src/build.c#L726

As a use-case, it's handy for me to kick off a web browser to view something 
that results in HTML output.  For example, I have a markdown build command that 
uses 'grep' to convert Markdown to HTML.  From my filetypes.markdown:

```
FT_01_LB=_Convert to HTML
FT_01_CM=docker run -i --rm mbentley/grip - --export - < "%d/%f" > "%d/%e.html"
FT_01_WD=
```
Here, it would be nice if I could append ` && %b %d/%e.html &` to that command.

Please let me know if what I'm describing is viable and useful; if so, I can 
draft something and send along a PR.

Thanks!

-- 
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/issues/2395

Reply via email to