Replace %p with a page number when invoking path launcher

for details see:
 https://github.com/moosotc/llpp/issues/45#issuecomment-1028683741
This commit is contained in:
malc 2022-02-05 16:56:26 +03:00
parent e656df13a0
commit a51c29b315
4 changed files with 18 additions and 6 deletions

View File

@ -172,7 +172,7 @@ o Text searching is very naive|}
open Utils
let gotourl launcher url =
let command = Str.global_replace Utils.Re.percent url launcher in
let command = Str.global_replace Utils.Re.percents url launcher in
try ignore @@ spawn command []
with exn -> dolog "failed to execute `%s': %s" command @@ exntos exn

16
main.ml
View File

@ -61,7 +61,17 @@ let launchpath () =
if emptystr conf.pathlauncher
then adderrmsg "path launcher" "command set"
else
let cmd = Str.global_replace Re.percent !S.path conf.pathlauncher in
let n =
match !S.layout with
| l :: _ -> string_of_int l.pageno
| _ -> E.s
in
let cmd = Str.global_replace Re.percents !S.path conf.pathlauncher in
let cmd =
if nonemptystr n
then Str.global_replace Re.percentp n cmd
else cmd
in
match spawn cmd [] with
| exception exn ->
adderrfmt "spawn" "failed to execute `%s': %s" cmd @@ exntos exn
@ -2790,7 +2800,7 @@ let gotounder = function
"don't know where to save attachment"
else
let filename = Ffi.getfileannot opaque slinkindex in
let savecmd = Str.global_replace Re.percent filename conf.savecmd in
let savecmd = Str.global_replace Re.percents filename conf.savecmd in
let path =
getcmdoutput
(adderrfmt savecmd
@ -3118,7 +3128,7 @@ let save () =
then adderrmsg "savepath-command is empty"
"don't know where to save modified document"
else
let savecmd = Str.global_replace Re.percent !S.path conf.savecmd in
let savecmd = Str.global_replace Re.percents !S.path conf.savecmd in
let path =
getcmdoutput
(adderrfmt savecmd "failed to obtain path to the saved copy: %s")

View File

@ -113,7 +113,8 @@ let getenvdef name def =
module Re = struct
let crlf = Str.regexp "[\r\n]"
let percent = Str.regexp "%s"
let percents = Str.regexp "%s"
let percentp = Str.regexp "%p"
let whitespace = Str.regexp "[ \t]"
end

View File

@ -41,7 +41,8 @@ val getenvdef : string -> string -> string
module Re :
sig
val crlf : Str.regexp
val percent : Str.regexp
val percents : Str.regexp
val percentp : Str.regexp
val whitespace : Str.regexp
end
val addchar : string -> char -> string