reddit / emacs

qpdf.el: A transient Emacs wrapper for qpdf

orgtre · 2022-08-15 10:17
[https://github.com/orgtre/qpdf.el](https://github.com/orgtre/qpdf.el) Hi, this is my first Emacs package! It provides a transient wrapper for the [qpdf](https://github.com/qpdf/qpdf) command-line tool aimed especially at users of [pdf-tools](https://github.com/vedang/pdf-tools) or at least DocView. With it one can, for example, remove/reorder/split/rotate pages of a pdf file, merge pdf files, remove annotations, and apply a range of transformations to a pdf file. See the [qpdf documentation](https://qpdf.readthedocs.io/en/stable/cli.html). I used this package to learn transient, so it may also be helpful for people looking to do the same. Comments and suggestions are most welcome. For example, I wonder if I should and how I could define custom [suffix classes](https://magit.vc/manual/transient.html#Suffix-Classes) for better handling qpdf arguments like `--collate[=n]` which are a switch but also optionally take a value, or complex ones like `--overlay file [options] --`?
nv-elisp · 2022-08-15 18:22
> For example, I wonder if I should and how I could define custom suffix classes for better handling qpdf arguments like --collate[=n] which are a switch but also optionally take a value, or complex ones like --overlay file [options] --? If you haven't already, I would take a look at magit's source to see how it handles those types of options. magit-log for example has a few such options.
xenodium · 2022-08-15 18:32
Nice to see more command-line integrations. I did a small [qpdf one recently](https://xenodium.com/emacs-password-protect-current-pdf-revisited/) via [dwim-shell-command](https://github.com/xenodium/dwim-shell-command) (disclosure: I'm author). Not sure if keen on the dwim-shell-command dependency, but it may reduce some buffer management, boilerplate, adds async, and can enforce operating on pdf files in either current buffer or dired selection.
orgtre · 2022-08-16 08:22
This is interesting, I will try it out. I already experimented a bit with async-shell-command but it doesn’t result in a nice experience when one wants the pdf output to pop up. I’d be keen on a smooth way to get pdfs selected in dired into qpdf’s —pages argument while also allowing for the possibility to specify page ranges individually for each pdf. But one would probably need to look at the pdfs for selecting page ranges anyway. Currently this is possible since the qpdf transient persists while the —pages prompt is active, so one can just switch between pdf buffers and scroll through them or look at their outline while deciding on page ranges. Is there a better way?
orgtre · 2022-08-16 10:49
Hm, while `git log` has some arguments which can be used as a switch but also optionally take a value, e.g. `--branches[=<pattern>]`, I don't see any of these implemented in magit. I found some for `git diff` though: `--stat[=<width>[,<name-width>[,<count>]]]` and `git diff --ignore-submodules[=<when>]`. For the former magit ignores the options and implements it as class transient-switch, while for the latter it ignores that values are optional and implements it as class transient-option, forcing users to choose a value. I'm not sure how I could do this in an other way.
xenodium · 2022-08-16 20:38
>This is interesting, I will try it out. I already experimented a bit with async-shell-command but it doesn’t result in a nice experience when one wants the pdf output to pop up. You can use `:on-completion` (see dwim-shell-commands.el as example) to use a custom handler (and open resulting file?). Otherwise you get default behaviour to jump to resulting file (via `dired-dump`). >Is there a better way? Not too sure. Not done much work with pdf manipulation other than the password-protection I mentioned.