Forum moved here!

Home / Is ‘%~dp’ supported in ‘Set inverse search command line’?



I created a portable Emacs + LaTeX setup which can be used with flash drive. I keep the SumatraPDF folder under the same folder as Emacs folder. Since this setup is portable, I tried to specify the inverse search setting without an absolute path.

"%~dp0..\emacs_root\bin\emacsclientw.exe" -n +%l "%f"

is what I used but it didn’t work. Basically what I want was passing where current SumatraPDF folder is and based on that set a relative path specifying where emacs binary is.

So my question is: Is there a way to use auto expansion in inverse search setting based on where current SumatraPDF folder is?


Update: grammar. fixed a typo


If I’ve got this correct, your folder structure is:

parent folder
L sumatra folder
L emacs folder

Did you try to specify the path relative to sumatrapdf.exe as just “…\emacs_root” without the “%~dp0”?


@SumatraPeter Thanks for your suggestion. Yes, I did that before I posted my question. Unfortunately it didn’t work. Your understanding of the folder structure is correct.


need to prove that
+%L "%f"
is what you intended eg check via a bat file what does +%L translate to
echo +%l
echo "%f"


Thanks. Can you expand your suggestion a little bit?

"%~dp0..\emacs_root\bin\emacsclientw.exe" -n +%l "%f"

This line goes to the setting file of SumatraPDF, i.e., SumatraPDF-settings.txt, it is not part of a batch file. How can I view the cmd output?

And as soon as I replace %~dp0.. with an absolute path like

"d:\portable_setup\emacs_root\bin\emacsclientw.exe" -n +%l "%f"

Things start to work but what I needed was a relative path in the setting that can auto expand.


ok understand better that the call is from sumatrapdf’s location thus the default relative route might not be what one may expect. Im old school and would make a “runme.bat” or runme.cmd that has the lines I suggested

so the settings .txt would include

runme.cmd -n +%1 “%f”

the runme.cmd file (a simple textual file in the SumatraPDF folder) would be something like

echo “%~dp0…\emacs…” expect that to confirm d:\portable_etc (this is the one that’s likely at fault)
echo %1 expect that to give you a response of -n on second line
echo %2 expect that to confirm the value desired
echo %3 should be the filename
pause so you can see results above


Update2: Wrote a new launch batch file for emacs. Working now.

Update: It didn’t work. I mistook another version of SumatraPDF in system path as the one on my USB drive. Still looking for a solution.

I fixed the problem by using a completely different approach.

It seems that inverse search setting argument is always valid for files in current folder, i.e., SumatraPDF root. So I created a shortcut to where emacsclientw.exe is then it worked.

By this observation. For inverse search, I only have to use

"emacsclientw.exe" -n +%l "%f

in SumatraPDF inverse settings. Note that emacsclientw.exe refers to actually a shortcut *.lnk file with the same name in SumatraPDF root.

Next, I created a launch bat for emacs which at start up, it checks if there is a shortcut to emacsclientw.exe in SumatraPDF root. If not, it will create one. Essentially, this approach bypasses the parsing problem of auto expansion. It is portable and it works well.

The emacs launcher I created is available on github.