From a51c29b315cee12e980f4cdc3bd76e2ed40b2e0b Mon Sep 17 00:00:00 2001 From: malc Date: Sat, 5 Feb 2022 16:56:26 +0300 Subject: [PATCH] Replace %p with a page number when invoking path launcher for details see: https://github.com/moosotc/llpp/issues/45#issuecomment-1028683741 --- help.ml | 2 +- main.ml | 16 +++++++++++++--- utils.ml | 3 ++- utils.mli | 3 ++- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/help.ml b/help.ml index 93cd219..b21ae27 100644 --- a/help.ml +++ b/help.ml @@ -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 diff --git a/main.ml b/main.ml index 0618ad0..aacff4c 100644 --- a/main.ml +++ b/main.ml @@ -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") diff --git a/utils.ml b/utils.ml index 9035a3a..80eccde 100644 --- a/utils.ml +++ b/utils.ml @@ -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 diff --git a/utils.mli b/utils.mli index 24671aa..eddc006 100644 --- a/utils.mli +++ b/utils.mli @@ -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 -- 2.11.4.GIT