Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wip] Open file #32

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft

[wip] Open file #32

wants to merge 7 commits into from

Conversation

erooke
Copy link
Contributor

@erooke erooke commented Jan 26, 2022

This pr aims to address #20. It is currently rather rough and not quite ready, this is just to track process on it / enable feedback.

Specifically it aims to provide a file opening action where if a bibtex entry has a file field following one of the following forms:

  • file = {/path/to/article.pdf}
  • file = {name:/path/to/article.pdf:PDF}
  • file={name:/path/to/article.pdf:PDF;name:/path/to/supplementary_materials.pdf:PDF}

we should be able to open it in a user specified reader.

Currently we only work with the second style of file fields. That is fields of the form name:/path/to/article:ext given a config entry called reader like so:

require('telescope').setup {
  extensions = {
    bibtex = {
      reader = {
        djvu = 'evince',
        pdf  = 'zathura'
      },
    }
  }
}

it will open djvu files in evince and pdf files in zathura. Currently it is rather bodged together and will not work if there is a : in the path anywhere.

Still left to todo:

  • handle file specifications of the form {/path/to/article}
  • handle multiple files (should it spawn another picker to allow you to choose?)
  • properly handle files with : in their paths
  • handle the case where the user has not specified a reader for a filetype

maybe handle remote files? For instance something likefile = {:http\://arxiv.org/pdf/2003.05580v3:PDF}

@noahares
Copy link
Collaborator

Maybe you can use xdg-open to find a default reader? I do not know whether Windows has something similar, but this would be good to have as a fallback. This would also address remote files which would be opened in the browser.

@erooke
Copy link
Contributor Author

erooke commented Jan 27, 2022

Ah yeah, I totally forgot xdg-open existed. That's perfect. I'm thinking we shouldn't really handle remote files differently for the time being. As you pointed out xdg-open will handle them and some readers (evince in particular) will also handle remote files. It doesn't feel worth the extra complexity for now.

This is a real rough first draft at opening files specified in the
bibtex entry. To call it one runs `:Telescope bibtex`. The selected
entry can be opened by using `<c-o>`.
```
require('telescope').setup {
  extensions = {
    bibtex = {
      reader = { 'evince' },
    }
  }
}
```
would open the file in evince
Configuration now looks like
```
require('telescope').setup {
  extensions = {
    bibtex = {
      reader = {
        djvu = 'evince',
        pdf  = 'zathura'
      },
    }
  }
}
```
This would open djvu files in evince and pdf files in zathura
Implemented a basic parser instead of using luas string substitution to
deal with file lists. In theory we can now deal with : and ; being in
file names. It now parses two styles of entries:
- `{/path/to/file}`
- `{name:/path/to/file:ext}`
and can do a list of entires with mixed styles. Currently the first one
is opened instead of actually dealing with the list of entries.
The parser remembered its state between invocations which caused it to
fail to parse a second time. Declared variables as local to fix this
problem.
The parser always appended a single empty item to the end of every
parse. This has been fixed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants