├── .dir-locals.el
├── .github
├── FUNDING.yml
└── ISSUE_TEMPLATE
│ ├── bug_report.md
│ └── feature_request.md
├── .gitignore
├── CHANGELOG.md
├── Eldev
├── LICENSE
├── README.md
├── doc
└── orb-manual.org
├── img
├── demo-thumbnail.jpg
├── demo.gif
├── logo-p.svg
├── logo-r500.png
└── logo.svg
├── orb-anystyle.el
├── orb-compat.el
├── orb-core.el
├── orb-helm.el
├── orb-ivy.el
├── orb-pdf-scrapper.el
├── orb-pkg.el
├── orb-section.el
├── orb-utils.el
└── org-roam-bibtex.el
/.dir-locals.el:
--------------------------------------------------------------------------------
1 | ;;; Directory Local Variables
2 | ;;; For more information see (info "(emacs) Directory Variables")
3 |
4 | ((nil (sentence-end-double-space . t)
5 | (package-lint-main-file . "orb-pkg.el")))
6 |
--------------------------------------------------------------------------------
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | # These are supported funding model platforms
2 |
3 | github: zaeph # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
4 | patreon: # Replace with a single Patreon username
5 | open_collective: # Replace with a single Open Collective username
6 | ko_fi: # Replace with a single Ko-fi username
7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9 | liberapay: # Replace with a single Liberapay username
10 | issuehunt: # Replace with a single IssueHunt username
11 | otechie: # Replace with a single Otechie username
12 | custom: ["https://www.paypal.me/zaeph", "https://www.buymeacoffee.com/mshevchuk"] # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
13 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/bug_report.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Bug report
3 | about: Create a report to help us improve
4 | title: ''
5 | labels: ''
6 | assignees: ''
7 |
8 | ---
9 |
10 | **Describe the bug**
11 | A clear and concise description of what the bug is.
12 |
13 | **To Reproduce**
14 | Steps to reproduce the behavior:
15 | 1. Run command '...'
16 | 2. '...'
17 |
18 | **Expected behavior**
19 | A clear and concise description of what you expected to happen.
20 |
21 | **ORB configuration**
22 | 1. How the package is loaded.
23 | 2. ORB options set to non-default values (e.g. `orb-templates`)
24 |
25 | **Environment (please complete the following information):**
26 | - ORB commit or MELPA package version
27 | - Org Roam commit or MELPA package version
28 | - Org Mode version
29 | - Emacs framework [e.g. Doom, Spacemacs, Prelude, none]
30 | - Emacs version [e.g. 26.3, 27.1]
31 | - OS: [e.g. Linux, macOS, Windows]
32 |
33 | **Screenshots**
34 | If applicable, add screenshots to help explain your problem.
35 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/feature_request.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Feature request
3 | about: Suggest an idea for this project
4 | title: ''
5 | labels: ''
6 | assignees: ''
7 |
8 | ---
9 |
10 | **Is your feature request related to a problem? Please describe.**
11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...].
12 |
13 | **Describe the solution you'd like**
14 | A clear and concise description of what you want to happen.
15 |
16 | **Describe alternatives you've considered**
17 | A clear and concise description of any alternative solutions or features you've considered.
18 |
19 | **Additional context**
20 | Add any other context or screenshots about the feature request here.
21 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.elc
2 |
3 | # Added automatically by ‘eldev init’.
4 | /.eldev
5 | /Eldev-local
6 |
7 | # autoloads
8 | /*-autoloads.el
9 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Changelog
2 | All notable changes to this project will be documented in this file.
3 |
4 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5 | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6 |
7 | Well, at least we try!
8 |
9 | ## [Unreleased]
10 |
11 | ## [0.6.2] - 2022-01-05
12 |
13 | ### Added
14 | - Support for `s-format` template placeholders in `orb-insert-link-description`
15 | - Support for different citation dialects (Org-ref v2 and v3, Org-cite) in
16 | `orb-insert-link-description`
17 |
18 | ### Changed
19 | - Activating `org-roam-bibtex-mode` adds `orb-get-node-citekey` to
20 | `bibtex-completion-key-at-point-functions`
21 | - Org-ref was removed as a Package-Requires dependency
22 | - Internals of `orb-insert--link`: it now relies on global variables
23 | instead of `orb-plist`, which has now been removed completely
24 | - Commentary section in `org-roam-bibtex.el` was updated
25 | - Copyright year was updated
26 |
27 | ## Fixed
28 | - Variables belonging to external packages are now no longer reset to their
29 | default values when `org-roam-bibtex-mode` is switched off. Instead, their
30 | original, perhaps user-set value is recorded before `org-roam-bibtex-mode` is
31 | switched on and restored when it is switched off.
32 |
33 | ## [0.6.1] - 2021-12-03
34 |
35 | ### Added
36 | - Support for Citar (formerly Bibtex-actions)
37 | - Support for Org-ref v3
38 | - Support Org-cite
39 | - Support for BibDesk attachments
40 |
41 | ### Changed
42 | - Internals of how BibTeX attachments are handled
43 | - Deprecate `orb-process-file-field` in favour of `orb-get-attached-file`
44 | - Deprecate `orb-citekey-format` in favour of `orb-roam-ref-format`
45 | - Deprecate `orb-file-field-extensions` in favour of `orb-attached-file-extensions`
46 |
47 | ## Fixed
48 | - Delayed loading of dependencies (custom setter for `orb-insert-interface`)
49 | - Incompatibilities resulting from Org-roam upstream changes: `:target`
50 | template keyword
51 | - Docs. A little bit.
52 |
53 | ## Thanks
54 |
55 | @klorophatu, @zaeph, @paulhaider, @chuxubank
56 |
57 | ## [0.6.0] - 2021-07-19
58 |
59 | This is the first version of ORB that supports with Org-roam v2.
60 |
61 | ### Changed
62 | - Internal changes to support Org-roam v2. Incompatible with Org-roam v1 and
63 | previous ORB configurations!
64 | - User option `orb-templates` was removed. ORB templates are now stored in
65 | `org-roam-capture-templates` along with other Org-roam templates.
66 | - Remove keybindigns in `org-roam-bibtex-mode-map`.
67 |
68 | ## [0.5.2] - 2021-07-19
69 |
70 | This is the last version of ORB that works with Org-roam v1.
71 |
72 | ### Changed
73 | - Version number
74 | - Updated docs
75 |
76 | ## [0.5.1] - 2021-05-07
77 | ### Added
78 | - Future releases of ORB starting with v0.6 will work only with Org-roam v2 and
79 | will not be backwords compatible with ORB < v0.6. There will be no
80 | deprecation notices on functions and variables!
81 | - Update README with the above notice.
82 | - A basic setup for Eldev was added. No tests yet.
83 |
84 | ### Changed
85 | - Default keybindings for ORB commands were removed from `org-roam-bibtex-map`
86 | because they were non-essential conflicted with some other minor modes.
87 |
88 | ### Fixed
89 | - Added Org-ref to `Package-Requires` declaration.
90 | - Issue a warning in `orb-process-file-field` instead of ignoring errors
91 | silently.
92 |
93 | ## [0.5.0] - 2021-03-17
94 | ### Added
95 | - ORB PDF Scrapper export functionality was completely revisited. It can be
96 | now controlled by the user and allows for export of intermediate text and
97 | BibTeX data in addition to Org data. All the data can be exported into
98 | external files. There is also some preliminary key filtering when exporting
99 | BibTeX data to an existing bib file
100 | - Save progress in ORB PDF Scrapper buffers using `C-x C-s` and `C-x C-w`
101 | - `orb-pdf-scrapper-group-references` user option to control whether the
102 | references extracted by ORB PDF Scrapper should be sorted into different groups
103 | - ORB PDF Scrapper now supports different list styles including numbered lists
104 | for Org output, see `orb-pdf-scrapper-list-style` and
105 | `orb-pdf-scrapper-reference-numbers` for more details
106 | - `orb-pdf-scrapper-prompt-to-generate-keys` allows to suppress any (annoying)
107 | prompts asking to generate citation keys before proceeding to Org mode
108 | - New user option `orb-abbreviate-file-name` to force abbreviated file names
109 | retrieved by `orb-process-file-field`, thanks @emacsbliss
110 | - ORB now automatically selects a template for capture if its the only one on the list.
111 | - New issue and feature request templates for Github
112 | - A link where you can buy me a coffee :)
113 |
114 | Special thanks to @j-steinbach for the ideas of how to improve ORB PDF Scrapper
115 | and fruitful discussions on export, reference grouping and reference numbers!
116 |
117 | ### Changed
118 | - `orb-preformat-keywords` now supports only a list of strings, although cons
119 | cell values are supported for backward compatibility, they do not work as
120 | they used to previously. `orb-bibtex-field-aliases` user option (former
121 | internal `orb--virtual-fields-alist`) now controls the mapping between BibTeX
122 | (virtual) fields and ORB keywords
123 | - `orb-file-field-extensions` now supports only a list of strings
124 | - README.md was split into a short README.md and a longer `orb-manual.org`
125 | - The main README file was revisited to clarify installation instructions
126 | - Error messages in several places were improved
127 | - Old variable names deprecated in v0.2 were removed
128 | - The following symbols were marked as deprecated:
129 |
130 | | old | new |
131 | |----------------------------------------|----------------------------------------|
132 | | `orb-insert-frontend` | `orb-insert-interface` |
133 | | `orb-note-actions-frontend` | `orb-note-actions-interface` |
134 | | `orb-pdf-scrapper-refsection-headings` | `orb-pdf-scrapper-grouped-export` |
135 | | `orb-pdf-scrapper-export-fields` | `orb-pdf-scrapper-table-export-fields` |
136 |
137 | - File layout of `org-roam-bibtex` package: `orb-note-actions.el` was merged
138 | with `org-roam-bibtex.el`, `ivy` and `helm`-related functions were isolated
139 | into separate files
140 | - Updated copyright year to 2021
141 | - Other internal refactoring
142 |
143 | ### Fixed
144 | - Buggy behaviour of `orb-process-file-field`, thanks @PhDyellow
145 | - Performance issue in `ivy-bibtex` and `helm-bibtex` caused by database
146 | queries in `orb-find-note-file`, thanks to @MichielCottaar for pointing this
147 | out. Thanks to @cdlm for fixing another bug in `orb-find-note-file` that was
148 | introduced when the previous bug was fixed
149 | - Buggy behaviour of `orb-edit-notes` in some case due to a typo, thanks
150 | @brabalan
151 | - Consistent formatting between Org headings in ORB PDF Scrapper export
152 | - Maintenance badge in the README, thankgs @cdlm
153 |
154 | ## [0.4.0] - 2020-11-07
155 | ### Added
156 | - `orb-insert` user command to insert links to bibliography notes. If a note does
157 | not exist, create it. Thanks @garrettdreyfus for the idea!
158 |
159 | - user options associated with `orb-insert`: `orb-insert-frontend`,
160 | `orb-insert-follow-link`, `orb-insert-link-description`,
161 | `orb-insert-generic-candidates-format`.
162 |
163 | - user option `orb-use-as-slug` to allow for specifying what should be used to
164 | expand the ${slug} keyword in templates.
165 |
166 | - Default keybindings for `orb-insert`, `orb-insert-non-ref`,
167 | `orb-find-file-non-ref`, `orb-note-actions`.
168 |
169 | ### Changed
170 | - Internals of `orb-edit-notes`. The original function was split into two.
171 | Template pre-selection happens in `orb--edit-notes`, not in `org-capture`,
172 | which obviates the need to pre-format all the templates.
173 |
174 | ### Fixed
175 | - Fix typo in `orb--autokey-format-field` leading to the function's incorrect
176 | behaviour in some cases.
177 | - Fix behaviour `orb-edit-notes` throwing an error when the BibTeX field "file"
178 | was not present.
179 |
180 | ## [0.3.1] - 2020-10-05
181 | ### Added
182 | - Smart ${file} and %^{file} wildcards
183 | If `orb-process-file-keyword` is non nil, process these wildcards with
184 | `orb-process-file-field`. This allows to use `${file}` instead of more
185 | verbose `(orb-process-file-field \"${citekey}\")` in templates
186 |
187 | - Only the files whose extensions match those specified in
188 | `orb-file-field-extensions` will be returned by `orb-process-file-field` or
189 | all if this variable is nil.
190 |
191 | - Functions listed `orb-ignore-bibtex-store-link-functions` will be forced to
192 | return nil during note taking with ORB, e.g. *via* `org-ref` interface. This
193 | has been introduced to achieve a better user experience with `org-ref`, which
194 | causes two functions, native `org-ref-bibtex-store-link` and `ol-bibtex`'
195 | `org-bibtex-store-link` to be defined at runtime. With two functions,
196 | `org-capture` cannot decide which one to use and annoyingly prompts to choose
197 | one every time `org-capture` is initiated from a BibTeX buffer
198 |
199 | ### Changed
200 | - Respect `org-roam-title-to-slug-function`, thanks to @Wetlize
201 | - Remove `org-roam--with-template-error`, which was removed from Org Roam
202 | - Improve ORB PDF Scrapper training session messages
203 |
204 | ### Fixed
205 | - Broken link to Spacemacs instructions
206 | - Ensure Anystyle receives absolute file paths
207 |
208 | ## [0.3.0] - 2020-07-29
209 | ### Added
210 | - Feature: ORB PDF Scrapper
211 |
212 | ORB PDF Scrapper is an Emacs interface to
213 | [`anystyle`](https://github.com/inukshuk/anystyle) reference parser
214 | integrated into ORB. ORB PDF Scrapper interactive process can be
215 | conveniently accessed via ORB Note Actions.
216 |
217 | - Feature: ORB Anystyle
218 |
219 | ORB Anystyle is an Emacs Lisp wrapper for `anystyle` command line program
220 | that allows to conveniently supply arguments and call `anystyle` from Emacs
221 | Lisp programs. Its primary use is within ORB PDF Scrapper but it can be used
222 | freely elsewhere.
223 |
224 | - Feature: ORB Autokey
225 |
226 | ORB Autokey allows to generate citation keys from BibTeX data. Currently,
227 | its primary use is within ORB PDF Scrapper but the functionality is
228 | independent of it and can be used elsewhere.
229 |
230 | - Improved documentation (README)
231 | - Installation instructions for Spacemacs and Doom
232 | - Documentation for Note Actions
233 | - Help me section
234 |
235 | ### Changed
236 | - Internal organization of `org-roam-bibtex` files and file inter-dependencies
237 | towards a more modular approach
238 | - Changes following `org-roam` upstream developments
239 |
240 | ### Fixed
241 | - A couple of minor bugs
242 |
243 | ## [0.2.3] - 2020-05-10
244 | ### Added
245 | - `orb--replace-virtual-fields` and `orb--virtual-fields-alist` for
246 | mapping `bibtex-completion` virtual field names to more conventional
247 | words, namely these:
248 | ``` elisp
249 | ("=type=" . "type")
250 | ("=key=" . "citekey")
251 | ("=has-pdf=" . "pdf?")
252 | ("=has-note=" . "note?")
253 | ```
254 |
255 | From now on, `type`, `citekey`, `pdf?` and `note?` are recognized as
256 | aliases of, respectively, `=type=`, `=key=`, `=has-pdf?` and
257 | `=has-note=` in `orb-preformat-keywords`.
258 | - Throw an error if an `orb-preformat-keywords` element is neither a
259 | string nor a cons cell.
260 | - Github funding badge
261 |
262 | ### Changed
263 | - No more no less: [the upstream URL](https://github.com/org-roam/org-roam-bibtex.git)! We are now a
264 | legit brethren of the Org-Roam family.
265 |
266 | ### Fixed
267 | - `helm-bibtex` not showing the note indicator because
268 | `orb-find-note-file` wasn't adjusted to the upstream changes in
269 | `org-roam--get-ref-path-completions`
270 |
271 | ## [0.2.2] - 2020-05-06
272 | ### Added
273 | - CHANGELOG (this document)
274 | - Video demonstration of how to use org-roam-bibtex!
275 | - Save citekey note action
276 |
277 | ### Fixed
278 | - Bug in hydra frontend for note actions
279 |
280 | ## [0.2.1] - 2014-05-03
281 | ### Changed
282 | - Defaults for `orb-preformat-keywords`
283 |
284 | ### Fixed
285 | - Fixed bugs in note actions
286 | - Fixed other bugs
287 |
288 | ## [0.2.0] - 2020-05-03
289 | ### Added
290 | - New feature: note actions. A single interactive dispatcher command
291 | to perform useful commands in the notes buffer. The command displays
292 | a predefined set of actions using one of: Emacs default
293 | `completing-read`, Emacs built-in `ido`, third-party `helm`, `ivy`
294 | or `hydra` interfaces. User note actions can be installed.
295 |
296 | ### Changed
297 | - The package's namespace `org-roam-bibtex` was abbreviated to
298 | `orb`. The old namespace is retained only for the variables and
299 | functions matching `.+-mode.*` names.
300 |
301 | ### Deprecated
302 | - `org-roam-bibtex` namespace
303 |
304 | ## [0.1.0] - 2020-04-26
305 | ### Added
306 | - And so the journey begins...
307 | - Meaning that it looks like a package, behaves like a package and is
308 | packaged like a package! On [MELPA].
309 | - The package is meant to connect [org-roam] (note management) and
310 | [helm-bibtex/bibtex-completion] (bibtex management).
311 | - Expand org-roam-capture-templates using bibtex-completion as a
312 | backend for retrieving bibliographic information associated with
313 | #+ROAM_KEY:, which is supposed to be a valid citation key in a
314 | bibtex file.
315 | - org-roam-bibtex-mode: a minor mode that performs initial setup
316 | - Filter function for org-roam-find-file to retrieve non-bibliographic
317 | notes (those that do not have #+ROAM_KEY:) and interactive user
318 | functions to use the filter.
319 | - Find note function for bibtex-completion
320 | - Find note function for org-ref
321 | - A few more things
322 | - And an excellent documentation!
323 |
324 | [MELPA]: http://www.melpa.org/#/org-roam-bibtex
325 | [org-roam]: https://github.com/jethrokuan/org-roam
326 | [helm-bibtex/ivy-bibtex/bibtex-completion]: https://github.com/tmalsburg/helm-bibtex
327 | [citar]: https://github.com/bdarcus/citar
328 |
329 | [Unreleased]: https://github.com/org-roam/org-roam-bibtex/compare/v0.6.2...HEAD
330 | [0.6.2]: https://github.com/org-roam/org-roam-bibtex/compare/v0.6.1...v0.6.2
331 | [0.6.1]: https://github.com/org-roam/org-roam-bibtex/compare/v0.6.0...v0.6.1
332 | [0.6.0]: https://github.com/org-roam/org-roam-bibtex/compare/v0.5.2...v0.6.0
333 | [0.5.2]: https://github.com/org-roam/org-roam-bibtex/compare/v0.5.1...v0.5.2
334 | [0.5.1]: https://github.com/org-roam/org-roam-bibtex/compare/v0.5.0...v0.5.1
335 | [0.5.0]: https://github.com/org-roam/org-roam-bibtex/compare/v0.4.0...v0.5.0
336 | [0.4.0]: https://github.com/org-roam/org-roam-bibtex/compare/v0.3.1...v0.4.0
337 | [0.3.1]: https://github.com/org-roam/org-roam-bibtex/compare/v0.3.0...v0.3.1
338 | [0.3.0]: https://github.com/org-roam/org-roam-bibtex/compare/v0.2.3...v0.3.0
339 | [0.2.3]: https://github.com/org-roam/org-roam-bibtex/compare/v0.2.2...v0.2.3
340 | [0.2.2]: https://github.com/org-roam/org-roam-bibtex/compare/v0.2.1...v0.2.2
341 | [0.2.1]: https://github.com/org-roam/org-roam-bibtex/compare/v0.2.0...v0.2.1
342 | [0.2.0]: https://github.com/org-roam/org-roam-bibtex/compare/v0.1.0...v0.2.0
343 | [0.1.0]: https://github.com/org-roam/org-roam-bibtex/releases/tag/v0.1.0
344 |
345 |
--------------------------------------------------------------------------------
/Eldev:
--------------------------------------------------------------------------------
1 | ; -*- mode: emacs-lisp; lexical-binding: t; no-byte-compile: t -*-
2 |
3 | ;; Autodetermined by `eldev init'.
4 | (eldev-use-package-archive 'gnu)
5 | (eldev-use-package-archive 'melpa-unstable)
6 |
7 | (eldev-use-plugin 'autoloads)
8 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [](https://www.gnu.org/licenses/gpl-3.0)
2 | [](https://github.com/org-roam/org-roam-bibtex/graphs/commit-activity)
3 | [](https://github.com/org-roam/org-roam-bibtex/releases/)
4 | [](https://melpa.org/#/org-roam-bibtex)
5 |
6 | org-roam-bibtex
7 | ============
8 |
9 |
10 |
11 | Description
12 | ---------------
13 |
14 | Org Roam BibTeX (ORB) is an Org Roam extension that integrates [Org
15 | Roam](https://github.com/jethrokuan/org-roam) with bibliography/citation
16 | management software: [Org Ref](https://github.com/jkitchin/org-ref), [Helm and
17 | Ivy BibTeX](https://github.com/tmalsburg/helm-bibtex) and
18 | [Citar](https://github.com/bdarcus/citar).
19 |
20 | It allows users to manage their bibliographical notes using Org Roam and access
21 | the notes in `org-roam-directory` via `helm-bibtex`, `ivy-bibtex`,
22 | `citar-open-notes` or by activation Org-ref `cite:` links and Org-cite
23 | citations.
24 |
25 | Quick Demonstration 🎬
26 | ---------------
27 |
28 |
29 | See also [a somewhat outdated video demonstration of Org Roam
30 | v0.2.1](https://www.youtube.com/watch?v=Wy9WvF5gWYg)
31 |
32 | Articles
33 | ---------------
34 | Here is a selection of articles that you may find interesting.
35 |
36 | #### Introduction to Org-roam
37 | - [How To Take Smart Notes With Org-mode](https://blog.jethro.dev/posts/how_to_take_smart_notes_org/) by [@jethrokuan](https://github.com/jethrokuan)
38 |
39 | #### Workflow
40 | - [An Orgmode Note Workflow](https://rgoswami.me/posts/org-note-workflow/) by [@HaoZeke](https://github.com/HaoZeke) (outdated).
41 |
42 | Important news
43 | ---------------------------------
44 |
45 | **Org Roam BibTeX has been upgraded to v0.6, which is compatible with Org-roam
46 | v2. Please read carefully this README file and [the
47 | manual](doc/orb-manual.org) and adjust your configuration files accordingly.
48 | In particular, pay attention that the variable `orb-templates` has been
49 | deprecated in favour of `org-roam-capture-templates`, which in Org-roam v2 has
50 | a different list structure. Consult [the manual](doc/orb-manual.org) for more
51 | details**
52 |
53 | Org Roam BibTeX v0.5.2 is the last version of ORB that works with Org-roam v1.
54 | It can be found on the branch `orb-v0.5`.
55 |
56 | A word of warning 🚧
57 | ---------------
58 |
59 | `org-roam-bibtex` is in **Alpha**.
60 |
61 | This means that a lot of things may change in the future (e.g. renaming
62 | variables, rewriting functions). As a result, the package will be unstable for
63 | a while. This will change when we release v1.0, but for now, you will have to
64 | be on the lookout for a few things:
65 |
66 | 1. If you encounter a problem with the package, start by making sure that you
67 | have the latest version. (cf. [Installation](#installation))
68 | 2. If there is a problem with your configuration, most notably variables which
69 | do not exist anymore or functions which are not called with the right number
70 | of arguments, you will need to check this page to see what has changed.
71 | 3. If neither 1. nor 2. resolved your problem, read the following section on
72 | [how to get help](#orb-help-me).
73 |
74 | Getting help
75 | ---------------
76 |
77 | Please read carefully this section before installing Org Roam BibTeX. We are
78 | glad to help you in case something does not work as expected. However, we
79 | kindly ask you to follow these simple rules when asking for help:
80 |
81 | 1. Read carefully this README file.
82 | 2. Read it once again, please. Consult the [extended manual](doc/orb-manual.org)
83 | 3. Check our [community resources](#community) and describe your problem there.
84 | 4. Open an issue on the bug tracker.
85 | 5. Take your time to describe your problem and we'll take ours to help you solve it.
86 | 6. Describe your problem clearly, in a procedural way: "I run `this command`,
87 | then I run `that command`, and finally `this one`. I expect `this` to happen
88 | but instead happens `that`. Here is my `configuration`."
89 | 7. Thank you!
90 |
91 | Keep in mind that ORB is under active development and the configuration
92 | snippets that you might have found somewhere in the Internet may be outdated
93 | and be the actual cause your errors. It is therefore highly recommended to use
94 | this README file, [the manual](doc/orb-manual.org) and the Emacs built-in
95 | docstrings as primary documentation sources.
96 |
97 | Installation
98 | ---------------
99 |
100 | ### Hard dependencies
101 |
102 | Org Roam BibTeX depends on [Org Roam](https://github.com/org-roam/org-roam) and
103 | [BibTeX Completion](https://github.com/tmalsburg/helm-bibtex). Users cloning
104 | ORB directly from GitHub also need to install the above packages. When
105 | installing ORB with a package manager (MELPA) or from within a configuration
106 | framework (Doom, Spacemacs), no additional steps are required.
107 |
108 | ### Soft dependencies
109 |
110 | Some parts of Org Roam BibTeX will not work without:
111 |
112 | * [Org Ref](https://github.com/jkitchin/org-ref) — namely when Org-ref v2 or v3
113 | citation citation links are used as ROAM_REFS. Org-roam and ORB now support
114 | the built-in Org-cite citation keys (Org mode version 9.5+), so Org-ref is
115 | not a strict requirement anymore.
116 | * [Helm/Ivy-bibtex](https://github.com/tmalsburg/helm-bibtex) — these packages
117 | are required by Org-ref and provide native interfaces for Bibtex-completion,
118 | although the latter can be installed separately without them.
119 | * [Citar](https://github.com/bdarcus/citar) — this package provides an extended
120 | support for Org-cite citations. You will need to install the companion
121 | package [Citar-org-roam](https://github.com/emacs-citar/citar-org-roam), and
122 | configure it as described
123 | [here](https://github.com/emacs-citar/citar/wiki/Notes-configuration#org-roam-bibtex).
124 | * [AnyStyle CLI](https://github.com/inukshuk/anystyle-cli) — ORB PDF Scrapper
125 | requires this external tool, see [Orb Anystyle](#orb-anystyle) for more
126 | details.
127 |
128 | * ORB offers basic completion functions based on Emacs native completion
129 | interfaces, but user experience can be enhanced with Helm, Ivy and Hydra
130 | packages.
131 | * Users of Projectile and Persp-mode will be pleased to learn that ORB can
132 | automatically switch perspective to the Org Roam project when creating a
133 | note.
134 |
135 | ### With Emacs built-in package manager (`package.el`)
136 |
137 | The package is on [MELPA](https://github.com/melpa/melpa).
138 |
139 | 1. Install `org-roam-bibtex`:
140 |
141 | a) using `package.el`:
142 |
143 | ```
144 | M-x package-install RET org-roam-bibtex RET
145 | ```
146 |
147 | b) Alternatively, install it with `M-x package-list-packages`.
148 |
149 | 2. Load and configure the package in your
150 | [init-file](https://www.gnu.org/software/emacs/manual/html_node/emacs/Init-File.html):
151 |
152 | a) with `use-package`:
153 |
154 | ``` emacs-lisp
155 | (use-package org-roam-bibtex
156 | :after org-roam
157 | :config
158 | (require 'org-ref)) ; optional: if using Org-ref v2 or v3 citation links
159 | ```
160 |
161 | b) Alternatively, require the package if you don't use `use-package`:
162 |
163 | ``` emacs-lisp
164 | (require 'org-ref) ; optional: if using Org-ref v2 or v3 citation links
165 | (require 'org-roam-bibtex)
166 | ```
167 |
168 | ### Via cloning
169 |
170 | You can also clone the repository somewhere in your `load-path`. If you would
171 | like to assist with development, this is the way to go.
172 |
173 | To do that:
174 |
175 | 1. Create a directory where you’d like to clone the repository, e.g. `mkdir
176 | ~/projects`.
177 |
178 | 2. `cd ~/projects`
179 |
180 | 3. `git clone https://github.com/org-roam/org-roam-bibtex.git`
181 |
182 | 4. Load and configure the package:
183 |
184 | a) with `use-package`:
185 |
186 | ```emacs-lisp
187 | (use-package org-roam-bibtex
188 | :after org-roam
189 | :load-path "~/projects/org-roam-bibtex/" ; Modify with your own path where you cloned the repository
190 | :config
191 | (require 'org-ref)) ; optional: if using Org-ref v2 or v3 citation links
192 | ```
193 |
194 | b) Alternatively, if you don't use `use-package`:
195 |
196 | ```emacs-lisp
197 | (require 'org-ref) ; optional: if using Org-ref v2 or v3 citation links
198 | (add-to-list 'load-path "~/projects/org-roam-bibtex/") ; Modify with your own path where you cloned the repository
199 | (require 'org-roam-bibtex)
200 | ```
201 |
202 | ### Spacemacs
203 |
204 | If you have a private `org-roam` layer, modify it as follows:
205 |
206 | ``` emacs-lisp
207 | (defconst org-roam-packages
208 | '(org-roam org-roam-bibtex))
209 |
210 | ;; add this after `org-roam/init-org-roam`:
211 |
212 | (defun org-roam/init-org-roam-bibtex ()
213 | (use-package org-roam-bibtex
214 | :after org-roam
215 | :config
216 | (require 'org-ref)) ; optional: if using Org-ref v2 or v3 citation links
217 | ```
218 |
219 | If you don't have a private `org-roam` layer, configure it first, see examples
220 | [here](https://org-roam.discourse.group/t/orb-helm-bibtex-open-notes-wont-create-new-note/690)
221 | and
222 | [here](https://www.reddit.com/r/emacs/comments/f6erh0/total_noob_how_do_i_install_orgroam_in_spacemacs/).
223 |
224 | Recent versions of Spacemacs ship with a built-in `org-roam` support, so you
225 | won't need a private `org-roam` layer. You still need a private layer for
226 | `org-roam-bibtex`. Consult Spacemacs documentation on how to create one, or
227 | use the approach described in the above mentioned resources.
228 |
229 | ### Doom Emacs
230 |
231 | 1. Put this in `$DOOMDIR/packages.el`:
232 |
233 | ``` emacs-lisp
234 | (package! org-roam-bibtex
235 | :recipe (:host github :repo "org-roam/org-roam-bibtex"))
236 |
237 | ;; When using org-roam via the `+roam` flag
238 | (unpin! org-roam)
239 |
240 | ;; When using bibtex-completion via the `biblio` module
241 | (unpin! bibtex-completion helm-bibtex ivy-bibtex)
242 | ```
243 |
244 | 2. Put this in `$DOOMDIR/config.el`:
245 |
246 | ``` emacs-lisp
247 | (use-package! org-roam-bibtex
248 | :after org-roam
249 | :config
250 | (require 'org-ref)) ; optional: if using Org-ref v2 or v3 citation links
251 | ```
252 |
253 | 3. Run `bin/doom sync -u` and restart Emacs.
254 |
255 | Usage
256 | ---------------
257 |
258 | #### `org-roam-bibtex-mode`
259 |
260 | Call interactively `org-roam-bibtex-mode` or arrange your init file to perform
261 | this automatically.
262 |
263 | You can now access your bibliographical notes in `org-roam-directory` with
264 | `helm-bibtex`/`ivy-bibtex` or by opening `org-ref` links. ORB modifies the
265 | behaviour of the above packages to make them use `orb-edit-note` instead of
266 | their default note-management commands. To get their default behaviour back,
267 | disable `org-roam-bibtex-mode`.
268 |
269 | #### `orb-note-actions`
270 |
271 | Type `M-x orb-note-actions` to easily access additional commands useful in
272 | note's context. These commands are run with the note's BibTeX key as an
273 | argument. The key is taken from the `:ROAM_REFS:` file or heading property.
274 |
275 | #### `orb-insert-link`
276 |
277 | Select a bibliography entry and insert a link to a note associated with it. If
278 | the note does not exist yet, create it. Similar to `org-roam-node-insert`, if a
279 | region is selected, it becomes the link description.
280 |
281 | #### `org-roam-buffer` sections
282 |
283 | Three bibliography related `org-roam-buffer` sections are available.
284 | They may be added to the `org-roam-mode-sections` variable. These
285 | are:
286 |
287 | - `orb-section-reference` displays a formatted reference for the
288 | current entry.
289 | - `orb-section-abstract` displays the abstract (if available) of the
290 | current entry.
291 | - `orb-section-file` displays a link to open the attached file, if
292 | such file exists.
293 |
294 | Configuration
295 | ---------------
296 |
297 | See [the Org Roam BibTeX Manual](doc/orb-manual.org) for configuration options and
298 | advanced usage.
299 |
300 | Community
301 | ---------------
302 | For help, support, or if you just want to
303 | hang out with us, you can find us here:
304 |
305 | * **IRC**: channel **#org-roam** on [Libera Chat](https://libera.chat/guides/connect)
306 | * **Slack**: channel **#org-roam-bibtex** on [Org Roam](https://join.slack.com/t/orgroam/shared_invite/zt-deoqamys-043YQ~s5Tay3iJ5QRI~Lxg)
307 | * **Discourse**: [Org Roam Discourse group](https://org-roam.discourse.group)
308 |
309 | Changelog
310 | ---------------
311 | Changelog is being maintained [here](https://github.com/org-roam/org-roam-bibtex/blob/master/CHANGELOG.md).
312 |
313 | License
314 | ---------------
315 | Copyright © 2020-2022 Mykhailo Shevchuk
316 |
317 | Copyright © 2020 Leo Vivier
318 |
319 | And contributros.
320 |
321 | Distributed under the GNU General Public License , see [LICENSE](LICENSE).
322 |
--------------------------------------------------------------------------------
/img/demo-thumbnail.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/org-roam/org-roam-bibtex/b065198f2c3bc2a47ae520acd2b1e00e7b0171e6/img/demo-thumbnail.jpg
--------------------------------------------------------------------------------
/img/demo.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/org-roam/org-roam-bibtex/b065198f2c3bc2a47ae520acd2b1e00e7b0171e6/img/demo.gif
--------------------------------------------------------------------------------
/img/logo-p.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
341 |
--------------------------------------------------------------------------------
/img/logo-r500.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/org-roam/org-roam-bibtex/b065198f2c3bc2a47ae520acd2b1e00e7b0171e6/img/logo-r500.png
--------------------------------------------------------------------------------
/img/logo.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
246 |
--------------------------------------------------------------------------------
/orb-anystyle.el:
--------------------------------------------------------------------------------
1 | ;;; orb-anystyle.el --- Orb Roam BibTeX: Elisp interface to Anystyle -*- lexical-binding: t -*-
2 |
3 | ;; Copyright © 2020-2022 Mykhailo Shevchuk
4 |
5 | ;; Author: Mykhailo Shevchuk
6 | ;; URL: https://github.com/org-roam/org-roam-bibtex
7 |
8 | ;; This file is NOT part of GNU Emacs.
9 |
10 | ;; This program is free software; you can redistribute it and/or modify
11 | ;; it under the terms of the GNU General Public License as published by
12 | ;; the Free Software Foundation; either version 3, or (at your option)
13 | ;; any later version.
14 | ;;
15 | ;; This program is distributed in the hope that it will be useful,
16 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 | ;; GNU General Public License for more details.
19 | ;;
20 | ;; You should have received a copy of the GNU General Public License along with
21 | ;; this program; see the file LICENSE. If not, visit
22 | ;; .
23 |
24 | ;; N.B. This file contains code snippets adopted from other
25 | ;; open-source projects. These snippets are explicitly marked as such
26 | ;; in place. They are not subject to the above copyright and
27 | ;; authorship claims.
28 |
29 | ;;; Commentary:
30 | ;;
31 |
32 | ;;; Code:
33 | ;; * Library requires
34 |
35 | (require 'orb-core)
36 |
37 | (eval-when-compile
38 | (require 'subr-x)
39 | (require 'cl-macs))
40 |
41 | ;; * Customize definitions
42 |
43 | (defcustom orb-anystyle-executable "anystyle"
44 | "Anystyle executable path or program name."
45 | :type '(choice (const "anystyle")
46 | (file :tag "Path to executable" :must-match t))
47 | :group 'orb-anystyle)
48 |
49 | (defcustom orb-anystyle-pdfinfo-executable nil
50 | "Path to pdfinfo executable to be passed to anystyle.
51 | When this is nil, anystyle will look for it in the system path."
52 | :type '(choice
53 | (file :tag "Path to executable")
54 | (const nil))
55 | :group 'orb-anystyle)
56 |
57 | (defcustom orb-anystyle-pdftotext-executable nil
58 | "Path to pdftotext executable to be passed to anystyle.
59 | When this is nil, anystyle will look for it in the system path."
60 | :type '(choice
61 | (file :tag "Path to executable")
62 | (const nil))
63 | :group 'orb-anystyle)
64 |
65 | (defcustom orb-anystyle-parser-model nil
66 | "Path to anystyle custom parser model."
67 | :type '(choice
68 | (file :tag "Path to file" :must-match t)
69 | (const :tag "Built-in" nil))
70 | :group 'orb-anystyle)
71 |
72 | (defcustom orb-anystyle-finder-model nil
73 | "Path to anystyle custom finder model."
74 | :type '(choice
75 | (file :tag "Path to file" :must-match t)
76 | (const :tag "Built-in" nil))
77 | :group 'orb-anystyle)
78 |
79 | ;; --crop is currently broken upstream
80 |
81 | (defcustom orb-anystyle-find-crop nil
82 | "Crop value in pt to be passed to `anystyle find'.
83 | An integer or a conc cell of integers."
84 | :type '(choice (integer :tag "Top and bottom")
85 | (cons :tag "Top, bottom, left and right"
86 | (integer :tag "Top and bottom")
87 | (integer :tag "Left and right"))
88 | (const :tag "Do not crop" nil))
89 | :group 'orb-anystyle)
90 |
91 | (defcustom orb-anystyle-find-solo nil
92 | "Non-nil to pass the `--solo' flag."
93 | :type '(choice (const :tag "Yes" t)
94 | (const :tag "No" nil))
95 | :group 'orb-anystyle)
96 |
97 | (defcustom orb-anystyle-find-layout nil
98 | "Non-nil to pass the `--layout' flag."
99 | :type '(choice (const :tag "Yes" t)
100 | (const :tag "No" nil))
101 | :group 'orb-anystyle)
102 |
103 | (defcustom orb-anystyle-default-buffer "*Orb Anystyle Output*"
104 | "Default buffer name for anystyle output."
105 | :type 'string
106 | :group 'orb-anystyle)
107 |
108 | (defcustom orb-anystyle-user-directory
109 | (concat (file-name-as-directory user-emacs-directory) "anystyle")
110 | "Directory to keep anystyle user files."
111 | :type 'directory
112 | :group 'orb-anystyle)
113 |
114 | (defcustom orb-anystyle-parser-training-set
115 | (concat (file-name-as-directory orb-anystyle-user-directory) "core.xml")
116 | "XML file containing parser training data."
117 | :type '(file :must-match t)
118 | :group 'anystyle)
119 |
120 | (defcustom orb-anystyle-finder-training-set
121 | (f-join (file-name-as-directory orb-anystyle-user-directory) "ttx/")
122 | "Directory containing finder training data (.ttx files)."
123 | :type 'directory
124 | :group 'anystyle)
125 |
126 | ;; * Main functions
127 |
128 | ;;;###autoload
129 | (cl-defun orb-anystyle (command
130 | &key (exec orb-anystyle-executable)
131 | verbose help version adapter
132 | ((:finder-model fmodel) orb-anystyle-finder-model)
133 | ((:parser-model pmodel) orb-anystyle-parser-model)
134 | (pdfinfo orb-anystyle-pdfinfo-executable)
135 | (pdftotext orb-anystyle-pdftotext-executable)
136 | format stdout overwrite
137 | (crop orb-anystyle-find-crop)
138 | (solo orb-anystyle-find-solo)
139 | (layout orb-anystyle-find-layout)
140 | input output
141 | (buffer orb-anystyle-default-buffer))
142 | "Run anystyle COMMAND with `shell-command'.
143 | ARGS is a plist with the following recognized keys:
144 |
145 | Anystyle CLI options
146 | ==========
147 | 1) EXEC :exec => string (valid executable)
148 | - default value can be set through `orb-anystyle-executable'
149 |
150 | 2) COMMAND :command => symbol or string
151 | - valid values: find parse help check license train
152 |
153 | 3) Global options can be passed with the following keys.
154 |
155 | FMODEL :finder-model => string (valid file path)
156 | PMODEL :parser-model => string (valid file path)
157 | PDFINFO :pdfinfo => string (valid executable)
158 | PDFTOTEXT :pdftotext => string (valid executable)
159 | ADAPTER :adapter => anything
160 | STDOUT :stdout => boolean
161 | HELP :help => boolean
162 | VERBOSE :verbose => boolean
163 | VERSION :version => boolean
164 | OVERWRITE :overwrite => boolean
165 | FORMAT :format => string, symbol or list of unquoted symbols
166 |
167 | - FORMAT must be one or more output formats accepted by anystyle commands:
168 | parse => bib csl json ref txt xml
169 | find => bib csl json ref txt ttx xml
170 | - string must be space- or comma-separated, additional spaces are
171 | ignored
172 |
173 | Default values for some of these options can be set globally via
174 | the following variables: `orb-anystyle-finder-model',
175 | `orb-anystyle-parser-model', `orb-anystyle-pdfinfo-executable',
176 | `orb-anystyle-pdftotext-executable'.
177 |
178 | 4) Command options can be passed with the following keys:
179 |
180 | CROP :crop => integer or cons cell of integers
181 | LAYOUT :layout => boolean
182 | SOLO :solo => boolean
183 |
184 | - Command options are ignored for commands other than find
185 | - anystyle help -c flag is not supported
186 |
187 | Default values for these options can be set globally via the
188 | following variables: `orb-anystyle-find-crop',
189 | `orb-anystyle-find-layout', `orb-anystyle-find-solo'.
190 |
191 | 5) INPUT :input => string (file path)
192 |
193 | 6) OUTPUT :output => string (file path)
194 |
195 | `shell-command'-related options
196 | ==========
197 |
198 | 7) BUFFER :buffer => buffer-or-name
199 |
200 | - `shell-command''s OUTPUT-BUFFER
201 | - can be a cons cell (OUTPUT-BUFFER . ERROR-BUFFER)
202 | - when nil, defaults to `orb-anystyle-default-buffer'
203 |
204 | anystyle CLI command synopsis:
205 | anystyle [global options] command [command options] [arguments...].
206 |
207 | Homepage: https://anystyle.io
208 | Github: https://github.com/inukshuk/anystyle-cli
209 | Courtesy of its authors."
210 | (declare (indent 1))
211 | (let* ((commands '(list find parse check train help license))
212 | (exec (executable-find exec))
213 | (buf (if (consp buffer) buffer (list buffer)))
214 | ;; '(a b c) => "a,b,c"
215 | (to-string (lambda (str)
216 | (--reduce-from
217 | (format "%s,%s" acc it)
218 | (car str) (cdr str))))
219 | ;; debug
220 | ;; (anystyle-run (lambda (str)
221 | ;; (message "command: %s \nbuffers: %s and %s" str (car buf) (cdr buf))))
222 | (anystyle-run (lambda (str)
223 | (if (eq command 'train)
224 | ;; train can take minutes, so run it in a sub-process
225 | (start-process-shell-command
226 | "anystyle" (car buf) str)
227 | (shell-command str
228 | (car buf) (cdr buf)))))
229 | global-options command-options anystyle)
230 | ;; executable is a must
231 | (unless exec
232 | (user-error "Anystyle executable not found! \
233 | Install anystyle-cli before running Orb PDF Scrapper"))
234 | ;; we process :version and :help before checking command
235 | ;; since with this global flag command is not required
236 | (cond
237 | ;; help flag takes priority
238 | (help
239 | (setq global-options " --help"
240 | command-options ""
241 | input nil
242 | output nil))
243 | ;; anystyle ignores everything with --version flag except the
244 | ;; --help flag, which we've just resolved above
245 | (version
246 | (setq global-options "--version"
247 | command nil
248 | command-options ""
249 | input nil
250 | output nil))
251 | ;; otherwise command is a must
252 | ((not command)
253 | (user-error "Anystyle command required: \
254 | find, parse, check, train, help or license")))
255 | (when (stringp command)
256 | (setq command (intern command)))
257 | ;; command must be a valid command
258 | (unless (memq command commands)
259 | (user-error "Invalid command %s. Valid commands are \
260 | find, parse, check, train, help and license" command))
261 | ;;
262 | ;; command specific arguments
263 | (cl-case command
264 | ('help
265 | (when (stringp input)
266 | (setq input (intern input)))
267 | (unless (or (and global-options
268 | (string= global-options " --help"))
269 | (memq input commands))
270 | (user-error "Invalid input %s. Valid input for 'anystyle help': \
271 | find, parse, check, train, help or license" input)))
272 | ('license
273 | (setq input nil
274 | output nil
275 | global-options ""
276 | command-options ""))
277 | ('check
278 | (setq output nil))
279 | ('find
280 | ;; pdfinfo and pdftotext must be present in the system
281 | (when (and pdfinfo (not (executable-find pdfinfo)))
282 | (user-error "Executable not found: pdfinfo, %s" pdfinfo))
283 | (when (and pdftotext (not (executable-find pdftotext)))
284 | (user-error "Executable not found: pdftotext, %s" pdftotext))
285 | (setq global-options
286 | (orb-format "%s" global-options
287 | " --pdfinfo=\"%s\"" pdfinfo
288 | " --pdftotext=\"%s\"" pdftotext))
289 | ;; Command options
290 | ;; N.B. Help command accepts a command option -c but it's totally
291 | ;; irrelevant for us:
292 | ;;
293 | ;; [COMMAND OPTIONS]
294 | ;; -c - List commands one per line, to assist with shell completion
295 | ;; so we do not implement it
296 | ;;
297 | ;; :crop value should be integer; if no value was explicitly supplied,
298 | ;; use the default from `orb-anystyle-find-crop'
299 | (when crop
300 | (unless (consp crop)
301 | (setq crop (list crop)))
302 | (let ((x (car crop))
303 | (y (or (cdr crop) 0)))
304 | (unless (and (integerp x)
305 | (integerp y))
306 | (user-error "Invalid value %s,%y. Number expected" x y))
307 | (setq crop (format "%s,%s" x y))))
308 | ;; parse only accepts --[no]-layout, so we ignore the rest
309 | ;; append command options to command
310 | (setq command-options
311 | (orb-format " --crop=%s" crop
312 | " --layout" (cons layout " --no-layout")
313 | " --solo" (cons solo " --no-solo"))))
314 | ('train
315 | (unless output
316 | (setq output
317 | (concat (or (file-name-directory orb-anystyle-parser-training-set)
318 | (file-name-as-directory orb-anystyle-user-directory))
319 | "parser.mod")))))
320 | ;; Arguments relevant for more than one command
321 | ;;
322 | ;; find, parse:
323 | ;; format option should be one of accepted types if present
324 | (when (and (memq command '(find parse))
325 | format)
326 | (when (stringp format)
327 | (setq format
328 | (-map #'intern
329 | (split-string (string-trim format)
330 | "[, ]" t " "))))
331 | (unless (listp format)
332 | (setq format (list format)))
333 | (let ((accepted-formats
334 | (cl-case command
335 | ('find '(bib csl json ref txt ttx xml))
336 | ('parse '(bib csl json ref txt xml)))))
337 | (when (--none? (memq it accepted-formats) format)
338 | (user-error
339 | "Invalid format(s) %s. Valid formats for command %s: %s"
340 | (funcall to-string format)
341 | command
342 | (funcall to-string accepted-formats)))
343 | ;; convert format to a comma-separated string and append
344 | ;; it to global options
345 | (setq global-options
346 | (orb-format "%s" global-options
347 | " -f %s" (funcall to-string format)))))
348 | ;; find, parse, check accept
349 | ;; finder and parser models
350 | (when (memq command '(find parse check))
351 | (when (and fmodel (not (f-exists? fmodel)))
352 | (display-warning 'org-roam-bibtex
353 | "Finder model file not found: %s, \
354 | using the default one" fmodel)
355 | (setq fmodel nil))
356 | (when (and pmodel (not (f-exists? pmodel)))
357 | (display-warning 'org-roam-bibtex
358 | "Finder model file not found: %s, \
359 | using the default one" pmodel)
360 | (setq pmodel nil))
361 | (setq global-options (orb-format "%s" global-options
362 | " -F \"%s\"" fmodel
363 | " -P \"%s\"" pmodel)))
364 | ;; find, train, parse and check:
365 | ;; 1) require input, which should be a valid path
366 | ;; 2) something called ruby adapter, probably a right place here
367 | ;; 3) --verbose, --stdout, --overwrite if non-nil
368 | (when (memq command '(find train parse check))
369 | (unless input
370 | (user-error "Input required for command %s" command))
371 | (unless (and (stringp input) (f-exists? input))
372 | (user-error "Invalid input file or directory %s" input))
373 | (setq global-options
374 | (orb-format
375 | "%s" global-options
376 | " --verbose" (cons verbose " --no-verbose")
377 | ;; this flag does nothing for check
378 | " --stdout" (cons stdout " --no-stdout")
379 | " --adapter=\"%s\"" adapter
380 | " --overwrite" (cons overwrite " --no-overwrite"))))
381 | ;; Set arguments and run the program
382 | ;;
383 | (setq anystyle (orb-format "%s" exec
384 | "%s" global-options
385 | " %s" command
386 | "%s" command-options
387 | " \"%s\"" (when input (file-truename input))
388 | " \"%s\"" (when output (file-truename output))))
389 | (funcall anystyle-run anystyle)))
390 |
391 | (provide 'orb-anystyle)
392 | ;;; orb-anystyle.el ends here
393 | ;; Local Variables:
394 | ;; coding: utf-8
395 | ;; fill-column: 79
396 | ;; End:
397 |
--------------------------------------------------------------------------------
/orb-compat.el:
--------------------------------------------------------------------------------
1 | ;;; org-roam-bibtex-compat.el --- Org Roam BibTeX: obsolete definitions -*- lexical-binding: t -*-
2 |
3 | ;; Copyright © 2020-2022 Mykhailo Shevchuk
4 | ;; Copyright © 2020 Leo Vivier
5 |
6 | ;; Author: Mykhailo Shevchuk
7 | ;; Leo Vivier
8 | ;; URL: https://github.com/org-roam/org-roam-bibtex
9 |
10 | ;; This file is NOT part of GNU Emacs.
11 |
12 | ;; This program is free software; you can redistribute it and/or modify
13 | ;; it under the terms of the GNU General Public License as published by
14 | ;; the Free Software Foundation; either version 3, or (at your option)
15 | ;; any later version.
16 | ;;
17 | ;; This program is distributed in the hope that it will be useful,
18 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | ;; GNU General Public License for more details.
21 | ;;
22 | ;; You should have received a copy of the GNU General Public License along with
23 | ;; this program; see the file LICENSE. If not, visit
24 | ;; .
25 |
26 | ;;; Commentary:
27 | ;;
28 | ;; Obsolete definitions live here. For a while.
29 |
30 | ;;; Code:
31 |
32 | ;; * org-roam-bibtex.el
33 |
34 | (define-obsolete-variable-alias
35 | 'orb-citekey-format 'orb-roam-ref-format "0.6.1")
36 |
37 | (define-obsolete-variable-alias
38 | 'orb-file-field-extensions 'orb-attached-file-extensions "0.6.1")
39 |
40 | (define-obsolete-function-alias
41 | 'orb-process-file-field 'orb-get-attached-file "0.6.1")
42 |
43 | (provide 'orb-compat)
44 | ;;; orb-compat.el ends here
45 | ;; Local Variables:
46 | ;; coding: utf-8
47 | ;; fill-column: 79
48 | ;; End:
49 |
--------------------------------------------------------------------------------
/orb-core.el:
--------------------------------------------------------------------------------
1 | ;;; orb-core.el --- Org Roam BibTeX: core library -*- lexical-binding: t -*-
2 |
3 | ;; Copyright © 2020-2022 Mykhailo Shevchuk
4 | ;; Copyright © 2020 Leo Vivier
5 |
6 | ;; Author: Mykhailo Shevchuk
7 | ;; Leo Vivier
8 | ;; URL: https://github.com/org-roam/org-roam-bibtex
9 |
10 | ;; This file is NOT part of GNU Emacs.
11 |
12 | ;; This program is free software; you can redistribute it and/or modify
13 | ;; it under the terms of the GNU General Public License as published by
14 | ;; the Free Software Foundation; either version 3, or (at your option)
15 | ;; any later version.
16 | ;;
17 | ;; This program is distributed in the hope that it will be useful,
18 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | ;; GNU General Public License for more details.
21 | ;;
22 | ;; You should have received a copy of the GNU General Public License along with
23 | ;; this program; see the file LICENSE. If not, visit
24 | ;; .
25 |
26 | ;;; Commentary:
27 | ;;
28 | ;; This file provides org-roam-bibtex' dependencies and thus should
29 | ;; normally be required by org-roam-bibtex feature libraries. It
30 | ;; defines customize groups and provides general utility functions
31 | ;; that depend on extra features provided through org-roam,
32 | ;; bibtex-completion and their dependencies.
33 |
34 | ;;; Code:
35 |
36 | ;; ============================================================================
37 | ;;; Dependencies
38 | ;; ============================================================================
39 |
40 | (require 'orb-utils)
41 | (require 'orb-compat)
42 |
43 | (eval-when-compile
44 | (require 'cl-macs)
45 | (require 'subr-x)
46 | (require 'rx))
47 |
48 | (declare-function
49 | bibtex-completion-get-entry "bibtex-completion" (entry-key))
50 | (declare-function
51 | bibtex-completion-get-value "bibtex-completion" (field entry &optional default))
52 | (declare-function
53 | bibtex-completion-find-pdf (key-or-entry &optional find-additional))
54 |
55 |
56 | ;; ============================================================================
57 | ;;; Customize groups
58 | ;; ============================================================================
59 | ;;
60 | ;; All modules should put their `defgroup' definitions here
61 | ;; Defcustom definitions should stay in respective files
62 |
63 | (defgroup org-roam-bibtex nil
64 | "Org-roam integration with BibTeX software."
65 | :group 'org-roam
66 | :prefix "orb-")
67 |
68 | (defgroup orb-note-actions nil
69 | "Orb Note Actions - run actions in note's context."
70 | :group 'org-roam-bibtex
71 | :prefix "orb-note-actions-")
72 |
73 | (defgroup orb-pdf-scrapper nil
74 | "Orb PDF Scrapper - retrieve references from PDF."
75 | :group 'org-roam-bibtex
76 | :prefix "orb-pdf-scrapper-")
77 |
78 | (defgroup orb-anystyle nil
79 | "Elisp interface to `anystyle-cli`."
80 | :group 'org-roam-bibtex
81 | :prefix "orb-anystyle-")
82 |
83 | (defgroup orb-autokey nil
84 | "Automatic generation of BibTeX citation keys."
85 | :group 'org-roam-bibtex
86 | :prefix "orb-autokey-")
87 |
88 |
89 | ;; ============================================================================
90 | ;;; BibTeX fields and their special handling
91 | ;; ============================================================================
92 |
93 | (defcustom orb-bibtex-field-aliases
94 | '(("=type=" . "entry-type")
95 | ("=key=" . "citekey")
96 | ("=has-pdf=" . "pdf?")
97 | ("=has-note=" . "note?")
98 | ("citation-number" . "#"))
99 | "Alist of ORB-specific field aliases of the form (FIELD . ALIAS).
100 | The ALIAS can be used instead of the FIELD anywhere in ORB's
101 | configuration. This variable is useful to replace
102 | `bibtex-completion''s internal '='-embraced virtual fields with
103 | more casual alternatives."
104 | :group 'org-roam-bibtex
105 | :type '(repeat
106 | (cons (string :tag "Field name")
107 | (string :tag "Alias name"))))
108 |
109 | (defcustom orb-attached-file-extensions '("pdf")
110 | "When retrieving an attached file, keep files with only these extensions.
111 | This is a list of file extensions without a dot as case-insensitive
112 | strings.
113 |
114 | Set it to nil to keep all file names regardless of their extensions.
115 |
116 | BibTeX entries are searched for attached files according to
117 | `bibtex-completion-pdf-field' (default `file') and in
118 | BibDesk-specific `Bdsk-File-N' fields."
119 | :group 'org-roam-bibtex
120 | :type '(repeat :tag "List of extensions" (string)))
121 |
122 | (defcustom orb-abbreviate-file-name t
123 | "Non-nil to force abbreviation of file names by `orb-get-attached-file'.
124 | When this option is set to a non-nil value, the filename returned
125 | by `orb-get-attached-file' will get the home directory part
126 | abbreviated to `~/'. Symlinked directories will be abbreviated
127 | according to `directory-abbrev-alist', see `abbreviate-file-name'
128 | for details.
129 |
130 | An as-is value will be used otherwise."
131 | :group 'org-roam-bibtex
132 | :type '(choice
133 | (const :tag "Yes" t)
134 | (const :tag "No" nil)))
135 |
136 | (defcustom orb-open-attached-file-as-truename t
137 | "Non-nil to open attached files with their true names.
138 | When this option is set non-nil, `orb-open-attached-file' will
139 | open files using their true names. You may want to set it to nil
140 | if using file symlinks and experiencing problems such as
141 | discussed here:
142 |
143 | https://github.com/org-roam/org-roam-bibtex/issues/259
144 |
145 | An as-is value will be used otherwise."
146 | :group 'org-roam-bibtex
147 | :type '(choice
148 | (const :tag "Yes" t)
149 | (const :tag "No" nil)))
150 |
151 |
152 | (defcustom orb-use-bibdesk-attachments nil
153 | "Whether to look up BibDesk-specific file fields `Bdsk-File'.
154 | If this is non-nil, attachments given in BibDesk-specific file
155 | fields will be considered in addition to those found through the
156 | `bibtex-completion-find-pdf' mechanism when performing a template
157 | expansion, opening an attachment with `orb-note-actions' or
158 | scraping a PDF with `orb-pdf-scrapper'.
159 |
160 | Duplicates will be resolved, but since duplicate comparison is
161 | performed using `file-truename', this will lead to expansion of
162 | symlink paths if such are used in the normal BibTeX `file' field,
163 | for example. See also `orb-abbreviate-file-name' on how to
164 | abbreviate the retrieved filenames.
165 |
166 | Set this to symbol `only' to look up only BibDesk attachments and
167 | do not use `bibtex-completion-find-pdf'."
168 | :group 'org-roam-bibtex
169 | :type '(choice
170 | (const :tag "Yes" t)
171 | (const :tag "BibDesk only" only)
172 | (const :tag "No" nil)))
173 |
174 | (defsubst orb-resolve-field-alias (alias)
175 | "Return ALIAS association from `orb-bibtex-field-aliases'.
176 | Return ALIAS if association was not found."
177 | (or (car (rassoc alias orb-bibtex-field-aliases)) alias))
178 |
179 | (defun orb-get-bibdesk-filenames (entry)
180 | "Return filenames stored in BibDesk file fields \"Bdsk-File-N\".
181 | ENTRY is a BibTeX entry as returned by `bibtex-completion-get-entry'.
182 |
183 | The variable `orb-attached-file-extensions' is respected."
184 | ;; NOTE: Mac-specific, hard-coded
185 | (let* ((bdsk-file-fields
186 | (seq-filter (lambda (cell)
187 | (string-match-p "Bdsk-File" (car cell)))
188 | entry))
189 | (strip-value-rx
190 | (rx (seq (opt (in "\"{"))
191 | (group (* (not (in "\"{}"))))
192 | (opt (in "\"}")))))
193 | (filename-rx
194 | (concat
195 | (rx (seq "Users/" (* anychar)))
196 | (if orb-attached-file-extensions
197 | (regexp-opt orb-attached-file-extensions t)
198 | "pdf")))
199 | (bdsk-files
200 | (mapcar
201 | (lambda (cell)
202 | (let ((val (cdr cell))
203 | file)
204 | (when (string-match strip-value-rx val)
205 | (setq file (base64-decode-string (match-string 1 val)))
206 | (when (string-match filename-rx file)
207 | (concat "/" (match-string 0 file))))))
208 | bdsk-file-fields)))
209 | (seq-filter (lambda (val) val) bdsk-files)))
210 |
211 | ;;;###autoload
212 | (defun orb-get-attached-file (citekey)
213 | "Look up files associated with a BibTeX entry identified by CITEKEY.
214 | Files are searched for using `bibtex-completion-find-pdf',
215 | meaning that Mendeley, Zotero and plain file paths are all
216 | supported, and variables `bibtex-completion-pdf-field' and
217 | `bibtex-completion-library-path' are respected. Additionally,
218 | the BibTeX entry is searched for BibDesk-specific file fields
219 | `Bdsk-File-N'.
220 |
221 | If `orb-attached-file-extensions' is non-nil, return only file paths
222 | matching the respective extensions.
223 |
224 | If `orb-abbreviate-file-name' is non-nil, force an abbreviated
225 | file name.
226 |
227 | Depending on the value of `orb-use-bibdesk-attachments', the
228 | BibDesk-specific file fields `Bdsk-File-N' may or may not be used
229 | for the lookup.
230 |
231 | If multiple files have been found, the user will be prompted to
232 | select one."
233 | (condition-case err
234 | (when-let* ((entry (bibtex-completion-get-entry citekey))
235 | (paths
236 | (--> (pcase orb-use-bibdesk-attachments
237 | (`nil (bibtex-completion-find-pdf
238 | entry bibtex-completion-find-additional-pdfs))
239 | (`only (orb-get-bibdesk-filenames entry))
240 | (_
241 | (-->
242 | (nconc (bibtex-completion-find-pdf entry)
243 | (orb-get-bibdesk-filenames entry))
244 | (-map #'file-truename it)
245 | (-uniq it))))
246 | (if (not orb-attached-file-extensions)
247 | it ; do not filter by extensions
248 | ;; filter by extensions
249 | (--filter
250 | (when-let ((ext (file-name-extension it)))
251 | (member-ignore-case ext orb-attached-file-extensions))
252 | it))))
253 | (path (if (cdr paths)
254 | (completing-read "File to use: " paths)
255 | (car paths))))
256 | (if orb-abbreviate-file-name
257 | (abbreviate-file-name path)
258 | path))
259 | ;; ignore any errors that may be thrown by `bibtex-completion-find-pdf'
260 | ;; don't stop the capture process
261 | (error
262 | (orb-warning
263 | (format "error in `orb-get-attached-file`: %s %s"
264 | (car err) (cdr err))))))
265 |
266 | ;;;###autoload
267 | (defun orb-open-attached-file (citekey)
268 | "Open a file associated with CITEKEY.
269 | CITEKEY must be a list for compatibility with `bibtex-completion'
270 | functions, which also expect a list.
271 |
272 | This is a modified and simplified version of `bibtex-completion-open-pdf',
273 | which uses `orb-get-bibdesk-filenames' under the hood and is therefore
274 | compatible with BibDesk. The file is opened with the function set in
275 | `bibtex-completion-pdf-open-function'.
276 |
277 | The intended primary use is with `orb-note-actions'."
278 | (let* ((key (car citekey))
279 | (attachment (orb-get-attached-file key)))
280 | (if attachment
281 | (funcall bibtex-completion-pdf-open-function
282 | (if orb-open-attached-file-as-truename
283 | (file-truename attachment)
284 | attachment))
285 | (message "No PDF(s) found for this entry: %s" key))))
286 |
287 | ;; ============================================================================
288 | ;;;; Orb autokey
289 | ;; ============================================================================
290 |
291 | (defcustom orb-autokey-format "%a%y%T[4][1]"
292 | "Format string for automatically generated citation keys.
293 |
294 | Supported wildcards:
295 |
296 | Basic
297 | ==========
298 |
299 | %a |author| - first author's (or editor's) last name
300 | %t |title | - first word of title
301 | %f{field} |field | - first word of arbitrary field
302 | %y |year | - year YYYY
303 | %p |page | - first page
304 | %e{(expr)} |elisp | - execute elisp expression
305 |
306 | Extended
307 | ==========
308 |
309 | 1. Capitalized versions:
310 |
311 | %A |author| >
312 | %T |title | > Same as %a,%t,%f{field} but
313 | %F{field} |field | > preserve original capitalization
314 |
315 | 2. Starred versions
316 |
317 | %a*, %A* |author| - include author's (editor's) initials
318 | %t*, %T* |title | - do not ignore words in `orb-autokey-titlewords-ignore'
319 | %y* |year | - year's last two digits __YY
320 | %p* |page | - use \"pagetotal\" field instead of default \"pages\"
321 |
322 | 3. Optional parameters
323 |
324 | %a[N][M][D] |author| >
325 | %t[N][M][D] |title | > include first N words/names
326 | %f{field}[N][M][D] |field | > include at most M first characters of word/name
327 | %p[D] |page | > put delimiter D between words
328 |
329 | N and M should be a single digit 1-9. Putting more digits or any
330 | other symbols will lead to ignoring the optional parameter and
331 | those following it altogether. D should be a single alphanumeric
332 | symbol or one of `-_.:|'.
333 |
334 | Optional parameters work both with capitalized and starred
335 | versions where applicable.
336 |
337 | 4. Elisp expression
338 |
339 | - can be anything
340 | - should return a string or nil
341 | - will be evaluated before expanding other wildcards and therefore
342 | can insert other wildcards
343 | - will have `entry' variable bound to the value of BibTeX entry the key
344 | is being generated for, as returned by `bibtex-completion-get-entry'.
345 | The variable may be safely manipulated in a destructive manner.
346 |
347 | %e{(or (bibtex-completion-get-value \"volume\" entry) \"N/A\")}
348 | %e{(my-function entry)}
349 |
350 | Key generation is performed by `orb-autokey-generate-key'."
351 | :risky t
352 | :type 'string
353 | :group 'org-roam-bibtex)
354 |
355 | (defcustom orb-autokey-titlewords-ignore
356 | '("A" "An" "On" "The" "Eine?" "Der" "Die" "Das"
357 | "[^[:upper:]].*" ".*[^[:upper:][:lower:]0-9].*")
358 | "Patterns from title that will be ignored during key generation.
359 | Every element is a regular expression to match parts of the title
360 | that should be ignored during automatic key generation. Case
361 | sensitive."
362 | ;; Default value was take from `bibtex-autokey-titleword-ignore'.
363 | :type '(repeat :tag "Regular expression" regexp)
364 | :group 'orb-autokey)
365 |
366 | (defcustom orb-autokey-empty-field-token "N/A"
367 | "String to use when BibTeX field is nil or empty."
368 | :type 'string
369 | :group 'orb-autokey)
370 |
371 | (defcustom orb-autokey-invalid-symbols
372 | " \"'()={},~#%\\"
373 | "Characters not allowed in a BibTeX key.
374 | The key will be stripped of these characters."
375 | :type 'string
376 | :group 'orb-autokey)
377 |
378 | (defun orb--autokey-format-field (field &rest specs)
379 | "Return BibTeX FIELD formatted according to plist SPECS.
380 |
381 | Recognized keys:
382 | ==========
383 | :entry - BibTeX entry to use
384 | :value - Value of BibTeX field to use
385 | instead retrieving it from :entry
386 | :capital - capitalized version
387 | :starred - starred version
388 | :words - first optional parameter (number of words)
389 | :characters - second optional parameter (number of characters)
390 | :delimiter - third optional parameter (delimiter)
391 |
392 | All values should be strings, including those representing numbers.
393 |
394 | This function is used internally by `orb-autokey-generate-key'."
395 | (declare (indent 1))
396 | (-let* (((&plist :entry entry
397 | :value value
398 | :capital capital
399 | :starred starred
400 | :words words
401 | :characters chars
402 | :delimiter delim) specs)
403 | ;; field values will be split into a list of words. `separator' is a
404 | ;; regexp for word separators: either a whitespace, one or more
405 | ;; dashes, or en dash, or em dash
406 | (separator "\\([ \n\t]\\|[-]+\\|[—–]\\)")
407 | (invalid-chars-rx
408 | (rx-to-string `(any ,orb-autokey-invalid-symbols) t))
409 | (delim (or delim ""))
410 | result)
411 | ;; 0. virtual field "=name=" is used internally here and in
412 | ;; `orb-autokey-generate-key'; it stands for author or editor
413 | (if (string= field "=name=")
414 | ;; in name fields, logical words are full names consisting of several
415 | ;; words and containing spaces and punctuation, separated by a logical
416 | ;; separator, the word "and"
417 | (setq separator " and "
418 | value (or value
419 | (bibtex-completion-get-value "author" entry)
420 | (bibtex-completion-get-value "editor" entry)))
421 | ;; otherwise proceed with value or get it from entry
422 | (setq value (or value
423 | (bibtex-completion-get-value field entry))))
424 | (if (or (not value)
425 | (string-empty-p value))
426 | (setq result orb-autokey-empty-field-token)
427 | (when (> (length value) 0)
428 | (save-match-data
429 | ;; 1. split field into words
430 | (setq result (split-string value separator t "[ ,.;:-]+"))
431 | ;; 1a) only for title;
432 | ;; STARRED = include words from `orb-autokey-titlewords-ignore
433 | ;; unstarred version filters the keywords, starred ignores this block
434 | (when (and (string= field "title")
435 | (not starred))
436 | (let ((ignore-rx (concat "\\`\\(:?"
437 | (mapconcat #'identity
438 | orb-autokey-titlewords-ignore
439 | "\\|") "\\)\\'"))
440 | (words ()))
441 | (setq result (dolist (word result (nreverse words))
442 | (unless (string-match-p ignore-rx word)
443 | (push word words))))))
444 | ;; 2. take number of words equal to WORDS if that is set
445 | ;; or just the first word; also 0 = 1.
446 | (if words
447 | (setq words (string-to-number words)
448 | result (-take (if (> words (length result))
449 | (length result)
450 | words)
451 | result))
452 | (setq result (list (car result))))
453 | ;; 2a) only for "=name=" field, i.e. author or editor
454 | ;; STARRED = include initials
455 | (when (string= field "=name=")
456 | ;; NOTE: here we expect name field 'Doe, J. B.'
457 | ;; should ideally be able to handle 'Doe, John M. Longname, Jr'
458 | (let ((r-x (if starred
459 | "[ ,.\t\n]"
460 | "\\`\\(.*?\\),.*\\'"))
461 | (rep (if starred "" "\\1"))
462 | (words ()))
463 | (setq result
464 | (dolist (name result (nreverse words))
465 | (push (s-replace-regexp r-x rep name) words)))))
466 | ;; 3. take at most CHARS number of characters from every word
467 | (when chars
468 | (let ((words ()))
469 | (setq chars (string-to-number chars)
470 | result (dolist (word result (nreverse words))
471 | (push
472 | (substring word 0
473 | (if (< chars (length word))
474 | chars
475 | (length word)))
476 | words)))))
477 | ;; 4. almost there: concatenate words, include DELIMiter
478 | (setq result (mapconcat #'identity result delim))
479 | ;; 5. CAPITAL = preserve case
480 | (unless capital
481 | (setq result (downcase result))))))
482 | ;; return result stripped of the invalid characters
483 | (s-replace-regexp invalid-chars-rx "" result t)))
484 |
485 | (defun orb--autokey-evaluate-expression (expr &optional entry)
486 | "Evaluate arbitrary elisp EXPR passed as readable string.
487 | The expression will have value of ENTRY bound to `entry' variable
488 | at its disposal. ENTRY should be a BibTeX entry as returned by
489 | `bibtex-completion-get-entry'. The result returned should be a
490 | string or nil."
491 | (let ((result (eval `(let ((entry (quote ,(copy-tree entry))))
492 | ,(read expr)))))
493 | (unless (or (stringp result)
494 | (not result))
495 | (user-error "Result: %s, invalid type. \
496 | Expression must be string or nil" result))
497 | (or result "")))
498 |
499 | ;;;###autoload
500 | (defun orb-autokey-generate-key (entry &optional control-string)
501 | "Generate citation key from ENTRY according to `orb-autokey-format'.
502 | Return a string. If optional CONTROL-STRING is non-nil, use it
503 | instead of `orb-autokey-format'."
504 | (let* ((case-fold-search nil)
505 | (str (or control-string orb-autokey-format))
506 | ;; star regexp: group 3!
507 | (star '(opt (group-n 3 "*")))
508 | ;; optional parameters: regexp groups 4-6!
509 | (opt1 '(opt (and "[" (opt (group-n 4 digit)) "]")))
510 | (opt2 '(opt (and "[" (opt (group-n 5 digit)) "]")))
511 | (opt3 '(opt (and "[" (opt (group-n 6 (any alnum "_.:|-"))) "]")))
512 | ;; capital letters: regexp group 2!
513 | ;; author wildcard regexp
514 | (a-rx (macroexpand
515 | `(rx (group-n 1 (or "%a" (group-n 2 "%A"))
516 | ,star ,opt1 ,opt2 ,opt3))))
517 | ;; title wildcard regexp
518 | (t-rx (macroexpand
519 | `(rx (group-n 1 (or "%t" (group-n 2 "%T"))
520 | ,star ,opt1 ,opt2 ,opt3))))
521 | ;; any field wildcard regexp
522 | ;; required parameter: group 7!
523 | (f-rx (macroexpand
524 | `(rx (group-n 1 (or "%f" (group-n 2 "%F"))
525 | (and "{" (group-n 7 (1+ letter)) "}")
526 | ,opt1 ,opt2 ,opt3))))
527 | ;; year wildcard regexp
528 | (y-rx (rx (group-n 1 "%y" (opt (group-n 3 "*")))))
529 | ;; page wildcard regexp
530 | (p-rx (macroexpand `(rx (group-n 1 "%p" ,star ,opt3))))
531 | ;; elisp expression wildcard regexp
532 | ;; elisp sexp: group 8!
533 | (e-rx (rx (group-n 1 "%e"
534 | "{" (group-n 8 "(" (1+ ascii) ")") "}"))))
535 | ;; Evaluating elisp expression should go the first because it can produce
536 | ;; additional wildcards
537 | (while (string-match e-rx str)
538 | (setq str (replace-match
539 | (save-match-data
540 | (orb--autokey-evaluate-expression
541 | (match-string 8 str) entry)) t nil str 1)))
542 | ;; Expanding all other wildcards are actually
543 | ;; variations of calls to `orb--autokey-format-field' with many
544 | ;; commonalities, so we wrap it into a macro
545 | (cl-macrolet
546 | ((expand
547 | (wildcard &key field value entry capital
548 | starred words characters delimiter)
549 | (let ((cap (or capital '(match-string 2 str)))
550 | (star (or starred '(match-string 3 str)))
551 | (opt1 (or words '(match-string 4 str)))
552 | (opt2 (or characters '(match-string 5 str)))
553 | (opt3 (or delimiter '(match-string 6 str))))
554 | `(while (string-match ,wildcard str)
555 | (setq str (replace-match
556 | ;; we can safely pass nil values
557 | ;; `orb--autokey-format-field' should
558 | ;; handle them correctly
559 | (orb--autokey-format-field ,field
560 | :entry ,entry :value ,value
561 | :capital ,cap :starred ,star
562 | :words ,opt1 :characters ,opt2 :delimiter ,opt3)
563 | t nil str 1))))))
564 | ;; Handle author wildcards
565 | (expand a-rx
566 | :field "=name="
567 | :value (or (bibtex-completion-get-value "author" entry)
568 | (bibtex-completion-get-value "editor" entry)))
569 | ;; Handle title wildcards
570 | (expand t-rx
571 | :field "title"
572 | :value (or (bibtex-completion-get-value "title" entry) ""))
573 | ;; Handle custom field wildcards
574 | (expand f-rx
575 | :field (match-string 7 str)
576 | :entry entry)
577 | ;; Handle pages wildcards %p*[-]
578 | (expand p-rx
579 | :field (if (match-string 3 str)
580 | "pagetotal" "pages")
581 | :entry entry
582 | :words "1"))
583 | ;; Handle year wildcards
584 | ;; it's simple, so we do not use `orb--autokey-format-field' here
585 | ;; year should be well-formed: YYYY
586 | ;; TODO: put year into cl-macrolet
587 | (let ((year (or (bibtex-completion-get-value "year" entry)
588 | (bibtex-completion-get-value "date" entry))))
589 | (if (or (not year)
590 | (string-empty-p year)
591 | (string= year orb-autokey-empty-field-token))
592 | (while (string-match y-rx str)
593 | (setq str (replace-match orb-autokey-empty-field-token
594 | t nil str 1)))
595 | (while (string-match y-rx str)
596 | (setq year (format "%04d" (string-to-number year))
597 | str (replace-match
598 | (format "%s" (if (match-string 3 str)
599 | (substring year 2 4)
600 | (substring year 0 4)))
601 | t nil str 1)))))
602 | str))
603 |
604 | (provide 'orb-core)
605 | ;;; orb-core.el ends here
606 | ;; Local Variables:
607 | ;; coding: utf-8
608 | ;; fill-column: 79
609 | ;; End:
610 |
--------------------------------------------------------------------------------
/orb-helm.el:
--------------------------------------------------------------------------------
1 | ;;; orb-helm.el --- ORB support form Helm -*- lexical-binding: t -*-
2 |
3 | ;; Copyright © 2020-2022 Mykhailo Shevchuk
4 |
5 | ;; Author: Mykhailo Shevchuk
6 | ;; URL: https://github.com/org-roam/org-roam-bibtex
7 |
8 | ;; Soft dependencies: projectile, persp-mode, helm, ivy, hydra
9 |
10 | ;; This file is NOT part of GNU Emacs.
11 |
12 | ;; This program is free software; you can redistribute it and/or modify
13 | ;; it under the terms of the GNU General Public License as published by
14 | ;; the Free Software Foundation; either version 3, or (at your option)
15 | ;; any later version.
16 | ;;
17 | ;; This program is distributed in the hope that it will be useful,
18 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | ;; GNU General Public License for more details.
21 | ;;
22 | ;; You should have received a copy of the GNU General Public License along with
23 | ;; this program; see the file LICENSE. If not, visit
24 | ;; .
25 |
26 | ;;; Commentary:
27 |
28 | ;;; Code:
29 |
30 | ;; ============================================================================
31 | ;;;; Dependencies
32 | ;; ============================================================================
33 |
34 | (require 'orb-utils)
35 |
36 | (require 'helm-bibtex)
37 | (require 'helm-source)
38 |
39 | (declare-function orb-insert-edit-note "org-roam-bibtex" (citekey))
40 |
41 | (defvar orb-note-actions-default)
42 | (defvar orb-note-actions-extra)
43 | (defvar orb-note-actions-user)
44 |
45 | ;; ============================================================================
46 | ;;;; Note actions
47 | ;; ============================================================================
48 |
49 | (orb-note-actions-defun helm
50 | (helm :sources
51 | `(((name . ,name)
52 | (candidates . ,candidates)
53 | (action . (lambda (f)
54 | (funcall f (list ,citekey))))))))
55 |
56 | ;; ============================================================================
57 | ;;;; Orb insert
58 | ;; ============================================================================
59 |
60 | (defvar helm-source-orb-insert
61 | (helm-build-sync-source "BibTeX entries"
62 | :header-name (lambda (name)
63 | (format "%s: " name))
64 | :candidates 'helm-bibtex-candidates
65 | :filtered-candidate-transformer 'helm-bibtex-candidates-formatter
66 | :action (helm-make-actions
67 | "Edit note & insert a link" 'helm-orb-insert-edit-note
68 | "Open PDF, URL or DOI" 'helm-bibtex-open-any
69 | "Open URL or DOI in browser" 'helm-bibtex-open-url-or-doi
70 | "Insert citation" 'helm-bibtex-insert-citation
71 | "Insert reference" 'helm-bibtex-insert-reference
72 | "Insert BibTeX key" 'helm-bibtex-insert-key
73 | "Insert BibTeX entry" 'helm-bibtex-insert-bibtex
74 | "Attach PDF to email" 'helm-bibtex-add-PDF-attachment
75 | "Show entry" 'helm-bibtex-show-entry
76 | "Add PDF to library" 'helm-bibtex-add-pdf-to-library))
77 | "Helm source to use with `orb-insert'.
78 | A copy of `helm-source-bibtex', in which \"Edit notes\" is made
79 | the first (default) action. This action calls `helm-orb-insert-edit-note'.
80 | Only relevant when `orb-insert-interface' is `helm-bibtex'.")
81 |
82 | (helm-bibtex-helmify-action orb-insert-edit-note helm-orb-insert-edit-note)
83 |
84 | (defun orb-helm-insert (&optional clear-cache)
85 | "Run `helm-bibtex'.
86 | If optional CLEAR-CACHE is non-nil, re-create `bibtex-completion-cache'.
87 |
88 | This is a simple wrapper to be run from `orb-insert'."
89 | (let ((helm-source-bibtex helm-source-orb-insert))
90 | (helm-bibtex clear-cache)))
91 |
92 | (provide 'orb-helm)
93 |
94 | ;;; orb-helm.el ends here
95 | ;; Local Variables:
96 | ;; coding: utf-8
97 | ;; fill-column: 79
98 | ;; End:
99 |
--------------------------------------------------------------------------------
/orb-ivy.el:
--------------------------------------------------------------------------------
1 | ;;; orb-ivy.el --- ORB support for Ivy -*- lexical-binding: t -*-
2 |
3 | ;; Copyright © 2020-2022 Mykhailo Shevchuk
4 |
5 | ;; Author: Mykhailo Shevchuk
6 | ;; URL: https://github.com/org-roam/org-roam-bibtex
7 |
8 | ;; Soft dependencies: projectile, persp-mode, helm, ivy, hydra
9 |
10 | ;; This file is NOT part of GNU Emacs.
11 |
12 | ;; This program is free software; you can redistribute it and/or modify
13 | ;; it under the terms of the GNU General Public License as published by
14 | ;; the Free Software Foundation; either version 3, or (at your option)
15 | ;; any later version.
16 | ;;
17 | ;; This program is distributed in the hope that it will be useful,
18 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | ;; GNU General Public License for more details.
21 | ;;
22 | ;; You should have received a copy of the GNU General Public License along with
23 | ;; this program; see the file LICENSE. If not, visit
24 | ;; .
25 |
26 | ;;; Commentary:
27 |
28 | ;;; Code:
29 |
30 | ;; ============================================================================
31 | ;;;; Dependencies
32 | ;; ============================================================================
33 |
34 | (require 'orb-utils)
35 |
36 | (require 'ivy-bibtex)
37 |
38 | (declare-function orb-insert-edit-note "org-roam-bibtex" (citekey))
39 |
40 | (defvar orb-note-actions-default)
41 | (defvar orb-note-actions-extra)
42 | (defvar orb-note-actions-user)
43 |
44 | ;; ============================================================================
45 | ;;;; Note actions
46 | ;; ============================================================================
47 |
48 | (orb-note-actions-defun ivy
49 | (ivy-read name
50 | candidates
51 | :require-match t
52 | :caller 'orb-note-actions-ivy
53 | :action (lambda (c)
54 | (funcall (cdr c) (list citekey)))))
55 |
56 | ;; ============================================================================
57 | ;;;; Orb insert
58 | ;; ============================================================================
59 |
60 | (defvar orb-insert--ivy-actions
61 | '(("e" ivy-orb-insert-edit-note "Edit note & insert a link")
62 | ("p" ivy-bibtex-open-pdf "Open PDF file (if present)")
63 | ("u" ivy-bibtex-open-url-or-doi "Open URL or DOI in browser")
64 | ("c" ivy-bibtex-insert-citation "Insert citation")
65 | ("r" ivy-bibtex-insert-reference "Insert reference")
66 | ("k" ivy-bibtex-insert-key "Insert BibTeX key")
67 | ("b" ivy-bibtex-insert-bibtex "Insert BibTeX entry")
68 | ("a" ivy-bibtex-add-PDF-attachment "Attach PDF to email")
69 | ("s" ivy-bibtex-show-entry "Show entry")
70 | ("l" ivy-bibtex-add-pdf-to-library "Add PDF to library")
71 | ("f" (lambda (_candidate) (ivy-bibtex-fallback ivy-text)) "Fallback options"))
72 | "Ivy actions to use with `orb-insert'.
73 | A copy of Ivy-bibtex's alist defining Ivy actions, in which
74 | \"Edit note & insert a link\" is made first (default) action.
75 | This action calls `orb-insert-edit-note'. Only relevant when
76 | `orb-insert-interface' is `ivy-bibtex'.")
77 |
78 | (ivy-bibtex-ivify-action orb-insert-edit-note ivy-orb-insert-edit-note)
79 |
80 | (defun orb-ivy-insert (&optional clear-cache)
81 | "Run `ivy-bibtex'.
82 | If optional CLEAR-CACHE is non-nil, re-create `bibtex-completion-cache'.
83 |
84 | This is a simple wrapper to be run from `orb-insert'."
85 | (let* ((ivy-actions (copy-tree ivy--actions-list))
86 | (ivy--actions-list
87 | (plist-put ivy-actions 'ivy-bibtex orb-insert--ivy-actions))
88 | (ivy-bibtex-default-action 'ivy-orb-insert-edit-note))
89 | (ivy-bibtex clear-cache)))
90 |
91 | (provide 'orb-ivy)
92 |
93 | ;;; orb-ivy.el ends here
94 | ;; Local Variables:
95 | ;; coding: utf-8
96 | ;; fill-column: 79
97 | ;; End:
98 |
--------------------------------------------------------------------------------
/orb-pkg.el:
--------------------------------------------------------------------------------
1 | (define-package "orb" "0.6.2"
2 | "Org Roam meets BibTeX"
3 | '((emacs "27.1")
4 | (org-roam "2.2.0")
5 | (bibtex-completion "2.0.0"))
6 | :homepage "https://github.com/org-roam/org-roam-bibtex"
7 | :keywords '("bib" "hypermedia" "outlines" "wp"))
8 |
9 | ;; Local Variables:
10 | ;; flycheck-disabled-checkers: (emacs-list-checkdoc)
11 | ;; package-lint-main-file: nil
12 | ;; End:
13 |
--------------------------------------------------------------------------------
/orb-section.el:
--------------------------------------------------------------------------------
1 | ;;; orb-section.el --- Org Roam BibTeX: Sections for org-roam-mode -*- lexical-binding: t -*-
2 |
3 | ;; Copyright © 2022 Samuel W. Flint
4 |
5 | ;; Author: Samuel W. Flint
6 |
7 | ;; URL: https://github.com/org-roam/org-roam-bibtex
8 |
9 | ;; This file is NOT part of GNU Emacs.
10 |
11 | ;; This program is free software; you can redistribute it and/or modify
12 | ;; it under the terms of the GNU General Public License as published by
13 | ;; the Free Software Foundation; either version 3, or (at your option)
14 | ;; any later version.
15 | ;;
16 | ;; This program is distributed in the hope that it will be useful,
17 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 | ;; GNU General Public License for more details.
20 | ;;
21 | ;; You should have received a copy of the GNU General Public License along with
22 | ;; this program; see the file LICENSE. If not, visit
23 | ;; .
24 |
25 | ;;; Commentary:
26 | ;;
27 | ;; This file provides org-roam-bibtex' dependencies and thus should
28 | ;; normally be required by org-roam-bibtex feature libraries. It
29 | ;; defines customize groups and provides general utility functions
30 | ;; that depend on extra features provided through org-roam,
31 | ;; bibtex-completion and their dependencies.
32 |
33 | ;;; Code:
34 |
35 | ;; ============================================================================
36 | ;;; Dependencies
37 | ;; ============================================================================
38 |
39 | (require 'org-roam-node)
40 | (require 'org-roam-utils)
41 | (require 's)
42 | (require 'magit-section)
43 | (require 'bibtex-completion)
44 |
45 | (require 'orb-utils)
46 | (defvar orb-abbreviate-file-name)
47 |
48 | ;; ============================================================================
49 | ;;; Configuration Variables
50 | ;; ============================================================================
51 |
52 | (defgroup orb-section nil
53 | "Org-roam buffer sections for BibTeX."
54 | :group 'org-roam-bibtex
55 | :prefix "orb-section-")
56 |
57 | (defcustom orb-section-reference-format-method
58 | 'bibtex-completion-apa-format-reference
59 | "How to format the ORB citation.
60 | Either a function taking a bibtex key and returning a string, or
61 | an alist from type to format string. For formatting information,
62 | see `bibtex-completion-display-formats'."
63 | :type '(choice (const :tag "Use BibTeX-Completion APA Format"
64 | 'bibtex-completion-apa-format-reference)
65 | (symbol :tag "Use a function")
66 | (alist :key-type (choice (string :tag "Type Name :")
67 | (const :tag "Default" t))
68 | :value-type (string :tag "Format String:"))))
69 |
70 | (defcustom orb-section-abstract-format-method :org-format
71 | "How to format ORB abstract.
72 | A function taking a key and returning a string, or one of:
73 |
74 | - `:org-format' Assume that the content is org-formatted, and
75 | format accordingly.
76 | - `:pandoc-from-tex' Assume that the content is tex/latex
77 | formatted and use `pandoc' to format accordingly."
78 | :type '(choice (const :tag "Format as Org Text" :org-format)
79 | (const :tag "Format from LaTeX" :pandoc-from-tex)
80 | (symbol :tag "Use function.")))
81 |
82 |
83 | ;; ============================================================================
84 | ;;; Utility functions
85 | ;; ============================================================================
86 |
87 | (defun orb-section-reference-format (key)
88 | "Format reference for KEY according to `orb-section-reference-format-method'."
89 | (if (functionp orb-section-reference-format-method)
90 | (funcall orb-section-reference-format-method key)
91 | (when-let ((entry (bibtex-completion-get-entry key))
92 | (format-string (cdr (or (assoc-string (bibtex-completion-get-value "=type=" entry) orb-section-reference-format-method)
93 | (assoc t orb-section-reference-format-method))))
94 | (formatted-reference (s-format format-string 'bibtex-completion-apa-get-value entry)))
95 | (replace-regexp-in-string "\\([.?!]\\)\\." "\\1" formatted-reference))))
96 |
97 | (defun orb-section-unfill-region (beg end)
98 | "Unfill the region from BEG to END.
99 | Joining text paragraphs into a single logical line.
100 |
101 | Taken from https://www.emacswiki.org/emacs/UnfillRegion"
102 | (interactive "*r")
103 | (let ((fill-column (point-max)))
104 | (fill-region beg end)))
105 |
106 | (defun orb-section-abstract-format (key)
107 | "Format abstract for KEY per `orb-section-abstract-format-method'."
108 | (if (functionp orb-section-abstract-format-method)
109 | (funcall orb-section-abstract-format-method key)
110 | (when-let ((entry (bibtex-completion-get-entry key))
111 | (abstract (bibtex-completion-get-value "abstract" entry)))
112 | (pcase orb-section-abstract-format-method
113 | (:org-format
114 | (org-roam-fontify-like-in-org-mode
115 | (with-temp-buffer
116 | (insert abstract)
117 | (org-mode)
118 | (orb-section-unfill-region (point-min) (point-max))
119 | (save-match-data "\n\n" "\n" (string-trim (buffer-string))))))
120 | (:pandoc-from-tex
121 | (org-roam-fontify-like-in-org-mode
122 | (with-temp-buffer
123 | (insert abstract)
124 | (shell-command-on-region (point-min) (point-max)
125 | "pandoc -f latex -t org" (current-buffer) t)
126 | (org-mode)
127 | (orb-section-unfill-region (point-min) (point-max))
128 | (save-match-data "\n\n" "\n" (string-trim (buffer-string))))))))))
129 |
130 |
131 | ;; ============================================================================
132 | ;;; Section Implementation
133 | ;; ============================================================================
134 |
135 | ;;;###autoload
136 | (defun orb-section-reference (node)
137 | "Show BibTeX reference for NODE if it exists."
138 | (when-let ((cite-key (orb-get-node-citekey node))
139 | (formatted-reference (orb-section-reference-format cite-key)))
140 | (magit-insert-section (orb-section-reference)
141 | (magit-insert-heading "Reference:")
142 | (insert formatted-reference)
143 | (insert "\n\n"))))
144 |
145 | ;;;###autoload
146 | (defun orb-section-abstract (node)
147 | "Show BibTeX entry abstract for NODE if it exists."
148 | (when-let ((cite-key (orb-get-node-citekey node))
149 | (formatted-abstract (orb-section-abstract-format cite-key)))
150 | (magit-insert-section (orb-section-abstract)
151 | (magit-insert-heading "Abstract:")
152 | (insert formatted-abstract)
153 | (insert "\n\n"))))
154 |
155 | ;;;###autoload
156 | (defun orb-section-file (node)
157 | "Show a link to entry file for NODE if it exists."
158 | (when-let ((cite-key (orb-get-node-citekey node))
159 | (file-name (let ((orb-abbreviate-file-name nil))
160 | (orb-get-attached-file cite-key))))
161 | (magit-insert-section (orb-section-file)
162 | (magit-insert-heading "File:")
163 | (insert-text-button (file-name-nondirectory file-name)
164 | 'action (lambda (_button) (orb-open-attached-file cite-key)))
165 | (insert "\n\n"))))
166 |
167 | (provide 'orb-section)
168 | ;;; orb-section.el ends here
169 | ;;
170 | ;; Local Variables:
171 | ;; coding: utf-8
172 | ;; fill-column: 79
173 | ;; End:
174 |
--------------------------------------------------------------------------------
/orb-utils.el:
--------------------------------------------------------------------------------
1 | ;;; orb-utils.el --- Org Roam BibTeX: utility macros and functions -*- lexical-binding: t -*-
2 |
3 | ;; Copyright © 2020-2022 Mykhailo Shevchuk
4 | ;; Copyright © 2020 Leo Vivier
5 |
6 | ;; Author: Mykhailo Shevchuk
7 | ;; Leo Vivier
8 | ;; URL: https://github.com/org-roam/org-roam-bibtex
9 |
10 | ;; This file is NOT part of GNU Emacs.
11 |
12 | ;; This program is free software; you can redistribute it and/or modify
13 | ;; it under the terms of the GNU General Public License as published by
14 | ;; the Free Software Foundation; either version 3, or (at your option)
15 | ;; any later version.
16 | ;;
17 | ;; This program is distributed in the hope that it will be useful,
18 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | ;; GNU General Public License for more details.
21 | ;;
22 | ;; You should have received a copy of the GNU General Public License along with
23 | ;; this program; see the file LICENSE. If not, visit
24 | ;; .
25 |
26 | ;; N.B. This file contains code snippets adopted from other
27 | ;; open-source projects. These snippets are explicitly marked as such
28 | ;; in place. They are not subject to the above copyright and
29 | ;; authorship claims.
30 |
31 | ;;; Commentary:
32 | ;;
33 | ;; This file contains utility macros and helper functions used accross
34 | ;; different org-mode-bibtex modules. This library may be required
35 | ;; directly or through orb-core.el. Definitions in this file should
36 | ;; only depend on built-in Emacs libraries.
37 |
38 | ;;; Code:
39 |
40 | ;; ============================================================================
41 | ;;;; Dependencies
42 | ;; ============================================================================
43 | ;;
44 | ;; org-roam requires org,org-element, dash, f, s, emacsql, emacsql-sqlite,
45 | ;; so all these libraries are always at our disposal
46 |
47 | (require 'org-roam)
48 | (require 'bibtex-completion)
49 |
50 | (require 'warnings)
51 |
52 | (eval-when-compile
53 | (require 'subr-x))
54 |
55 | (defvar org-ref-cite-types)
56 |
57 | ;; Adopted from `org-roam-version'
58 | (defun orb-version (&optional message)
59 | "Return `orb-roam' version.
60 | Interactively, or when MESSAGE is non-nil, show in the echo area."
61 | (interactive)
62 | (let* ((toplib (or load-file-name buffer-file-name))
63 | gitdir topdir version)
64 | (unless (and toplib (equal (file-name-nondirectory toplib) "orb-utils.el"))
65 | (setq toplib (locate-library "orb-utils.el")))
66 | (setq toplib (and toplib (org-roam--straight-chase-links toplib)))
67 | (when toplib
68 | (setq topdir (file-name-directory toplib)
69 | gitdir (expand-file-name ".git" topdir)))
70 | (when (file-exists-p gitdir)
71 | (setq version
72 | (let ((default-directory topdir))
73 | (shell-command-to-string
74 | "git describe --tags --dirty --always"))))
75 | (unless version
76 | (setq version (with-temp-buffer
77 | (insert-file-contents-literally
78 | (locate-library "org-roam-bibtex.el"))
79 | (goto-char (point-min))
80 | (save-match-data
81 | (if (re-search-forward
82 | "\\(?:;; Version: \\([^z-a]*?$\\)\\)" nil nil)
83 | (substring-no-properties (match-string 1))
84 | "N/A")))))
85 | (if (or message (called-interactively-p 'interactive))
86 | (message "%s" version)
87 | version)))
88 |
89 | ;; ============================================================================
90 | ;;;; Macros
91 | ;; ============================================================================
92 |
93 | (defmacro orb--with-message! (message &rest body)
94 | "Put MESSAGE before and after BODY.
95 | Append \"...\" to the first message and \"...done\" to the second.
96 | Return result of evaluating the BODY."
97 | (declare (indent 1) (debug (stringp &rest form)))
98 | (let ((reporter (gensym "orb")))
99 | `(let ((,reporter (make-progress-reporter ,message)))
100 | ,@body
101 | (progress-reporter-done ,reporter))))
102 |
103 | (defmacro orb-note-actions-defun (interface &rest body)
104 | "Return a function definition for INTERFACE.
105 | Function name takes a form of orb-note-actions--INTERFACE. A
106 | simple docstring is constructed and BODY is injected into a `let'
107 | form, which has two variables bound, NAME and CANDIDATES. NAME
108 | is a string formatted with `orb-format-entry' and CANDIDATES
109 | is a cons cell alist constructed from `orb-note-actions-default',
110 | `orb-note-actions-extra', and `orb-note-actions-user'."
111 | (declare (indent 1) (debug (symbolp &rest form)))
112 | (let* ((interface-name (symbol-name interface))
113 | (fun-name (intern (concat "orb-note-actions-" interface-name))))
114 | `(defun ,fun-name (citekey)
115 | ,(format "Provide note actions using %s interface.
116 | CITEKEY is the citekey." (capitalize interface-name))
117 | (let ((name (orb-format-entry citekey)) ;; TODO: make a native format function
118 | (candidates
119 | ,(unless (eq interface 'hydra)
120 | '(append orb-note-actions-default
121 | orb-note-actions-extra
122 | orb-note-actions-user))))
123 | ,@body))))
124 |
125 | ;; ============================================================================
126 | ;;;; General utilities
127 | ;; ============================================================================
128 |
129 | (defun orb-warning (warning &optional citekey)
130 | "Display a WARNING message. Return nil.
131 | Include CITEKEY if it is non-nil."
132 | (display-warning
133 | :warning (concat "ORB: " (when citekey (format "%s :" citekey)) warning))
134 | nil)
135 |
136 | (defun orb-buffer-string (&optional start end)
137 | "Retun buffer (sub)string with no text porperties.
138 | Like `buffer-substring-no-properties' but START and END are
139 | optional and equal to (`point-min') and (`point-max'),
140 | respectively, if nil."
141 | (buffer-substring-no-properties (or start (point-min))
142 | (or end (point-max))))
143 |
144 | (defun orb-format (&rest args)
145 | "Format ARGS conditionally and return a string.
146 | ARGS must be a plist, whose keys are `format' control strings and
147 | values are `format' objects. Thus only one object per control
148 | string is allowed. The result will be concatenated into a single
149 | string.
150 |
151 | In the simplest case, it behaves as a sort of interleaved `format':
152 | ==========
153 |
154 | \(orb-format \"A: %s\" 'hello
155 | \" B: %s\" 'world
156 | \" C: %s\" \"!\")
157 |
158 | => 'A: hello B: world C: !'
159 |
160 | If format object is nil, it will be formatted as empty string:
161 | ==========
162 |
163 | \(orb-format \"A: %s\" 'hello
164 | \" B: %s\" nil
165 | \" C: %s\" \"!\")
166 | => 'A: hello C: !'
167 |
168 | Object can also be a cons cell. If its car is nil then its cdr
169 | will be treated as default value and formatted as \"%s\":
170 | ==========
171 |
172 | \(orb-format \"A: %s\" 'hello
173 | \" B: %s\" '(nil . dworl)
174 | \" C: %s\" \"!\")
175 | => 'A: hellodworl C: !'
176 |
177 | Finally, if the control string is nil, the object will be formatted as \"%s\":
178 | ==========
179 |
180 | \(orb-format \"A: %s\" 'hello
181 | \" B: %s\" '(nil . \" world\")
182 | nil \"!\")
183 | => 'A: hello world!'."
184 | (let ((res ""))
185 | (while args
186 | (let ((str (pop args))
187 | (obj (pop args)))
188 | (unless (consp obj)
189 | (setq obj (cons obj nil)))
190 | (setq res
191 | (concat res
192 | (format (or (and (car obj) str) "%s")
193 | (or (car obj) (cdr obj) ""))))))
194 | res))
195 |
196 | ;; ============================================================================
197 | ;;;; Temporary files
198 | ;; ============================================================================
199 |
200 | ;;;;; Code in this section was adopted from ob-core.el
201 | ;;
202 | ;; Copyright (C) 2009-2020 Free Software Foundation, Inc.
203 | ;;
204 | ;; Authors: Eric Schulte
205 | ;; Dan Davison
206 |
207 | (defvar orb--temp-dir)
208 | (unless (or noninteractive (boundp 'orb--temp-dir))
209 | (defvar orb--temp-dir
210 | (or (and (boundp 'orb--temp-dir)
211 | (file-exists-p orb--temp-dir)
212 | orb--temp-dir)
213 | (make-temp-file "orb-" t))
214 | "Directory to hold temporary files created during reference parsing.
215 | Used by `orb-temp-file'. This directory will be removed on Emacs
216 | shutdown."))
217 |
218 | (defun orb-temp-file (prefix &optional suffix)
219 | "Create a temporary file in the `orb--temp-dir'.
220 | Passes PREFIX and SUFFIX directly to `make-temp-file' with the
221 | value of variable `temporary-file-directory' temporarily set to
222 | the value of `orb--temp-dir'."
223 | (let ((temporary-file-directory
224 | (or (and (boundp 'orb--temp-dir)
225 | (file-exists-p orb--temp-dir)
226 | orb--temp-dir)
227 | temporary-file-directory)))
228 | (make-temp-file prefix nil suffix)))
229 |
230 | (defun orb--remove-temp-dir ()
231 | "Remove `orb--temp-dir' on Emacs shutdown."
232 | (when (and (boundp 'orb--temp-dir)
233 | (file-exists-p orb--temp-dir))
234 | ;; taken from `delete-directory' in files.el
235 | (condition-case nil
236 | (progn
237 | (mapc (lambda (file)
238 | ;; This test is equivalent to
239 | ;; (and (file-directory-p fn) (not (file-symlink-p fn)))
240 | ;; but more efficient
241 | (if (eq t (car (file-attributes file)))
242 | (delete-directory file)
243 | (delete-file file)))
244 | (directory-files orb--temp-dir 'full
245 | directory-files-no-dot-files-regexp))
246 | (delete-directory orb--temp-dir))
247 | (error
248 | (message "Failed to remove temporary Org-roam-bibtex directory %s"
249 | (if (boundp 'orb--temp-dir)
250 | orb--temp-dir
251 | "[directory not defined]"))))))
252 |
253 | (add-hook 'kill-emacs-hook 'orb--remove-temp-dir)
254 |
255 | ;;;;; End of code adopted from ob-core.el
256 |
257 | ;; ============================================================================
258 | ;;;; Document properties
259 | ;; ============================================================================
260 |
261 | (defvar orb-utils-citekey-re
262 | ;; NOTE: Not tested thoroughly
263 | (rx
264 | (or
265 | (seq (group-n 2 (regexp
266 | ;; If Org-ref is available, use its types
267 | ;; default to "cite"
268 | (if (boundp 'org-ref-cite-types)
269 | (regexp-opt
270 | (mapcar
271 | (lambda (el)
272 | ;; Org-ref v3 cite type is a list of strings
273 | ;; Org-ref v2 cite type is a plain string
274 | (or (car-safe el) el))
275 | org-ref-cite-types))
276 | "cite")))
277 | ":"
278 | (or
279 | ;; Org-ref v2 style `cite:links'
280 | (group-n 1 (+ (any "a-zA-Z0-9_:.-")))
281 | ;; Org-ref v3 style `cite:Some&key'
282 | (seq (*? (not "&")) "&"
283 | (group-n 1 (+ (any "!#-+./:<>-@^-`{-~-" word))))))
284 | ;; Org-cite [cite/@citations]
285 | (seq "@" (group-n 1 (+ (any "!#-+./:<>-@^-`{-~-" word))))))
286 | "Universal regexp to match citations in `ROAM_REFS'.
287 | Supports Org-ref v2 and v3 and Org-cite.")
288 |
289 | (defun orb-get-db-cite-refs ()
290 | "Get a list of `cite` refs from Org Roam database."
291 | (let* ((types "cite")
292 | (refs (org-roam-db-query
293 | [:select [ref nodes:file id pos title type]
294 | :from refs
295 | :left-join nodes
296 | :on (= refs:node-id nodes:id)
297 | :where (= type $s1)]
298 | types))
299 | result)
300 | (dolist (ref refs result)
301 | (push (-interleave '(:ref :file :id :pos :title :type) ref) result))))
302 |
303 | (defvar orb-notes-cache nil
304 | "Cache of ORB notes.")
305 |
306 | (defun orb-make-notes-cache ()
307 | "Update ORB notes hash table `orb-notes-cache'."
308 | (let* ((db-entries (orb-get-db-cite-refs))
309 | (size (round (/ (length db-entries) 0.8125))) ;; ht oversize
310 | (ht (make-hash-table :test #'equal :size size)))
311 | (dolist (entry db-entries)
312 | (puthash (plist-get entry :ref)
313 | (org-roam-node-create
314 | :id (plist-get entry :id)
315 | :file (plist-get entry :file)
316 | :title (plist-get entry :title)
317 | :point (plist-get entry :pos))
318 | ht))
319 | (setq orb-notes-cache ht)))
320 |
321 | (defun orb-find-note-file (citekey)
322 | "Find note file associated with CITEKEY.
323 | Returns the path to the note file, or nil if it doesn’t exist."
324 | (when-let ((node (gethash citekey (or orb-notes-cache
325 | (orb-make-notes-cache)))))
326 | (org-roam-node-file node)))
327 |
328 | (defun orb-get-buffer-keyword (keyword &optional buffer)
329 | "Return the value of Org KEYWORD in-buffer directive.
330 | The KEYWORD should be given as a string without \"#+\", e.g. \"title\".
331 |
332 | If optional BUFFER is non-nil, return the value from that buffer
333 | instead of `current-buffer'."
334 | ;; NOTE: does not work with `org-element-multiple-keywords' keywords
335 | ;; if that will somewhen be required, `org-element' should be used.
336 | (with-current-buffer (or buffer (current-buffer))
337 | (let ((case-fold-search t))
338 | (save-excursion
339 | (goto-char (point-min))
340 | (re-search-forward
341 | (format "^[ ]*#\\+%s:[ ]*\\(.*\\)$" keyword) nil t)
342 | (match-string-no-properties 1)))))
343 |
344 | (defun orb-note-exists-p (citekey)
345 | "Check if a note exists whose citekey is CITEKEY.
346 | Return Org Roam node or nil."
347 | ;; NOTE: This function can be made more general.
348 | (gethash citekey (or orb-notes-cache
349 | (orb-make-notes-cache))))
350 |
351 | (defun orb-get-node-citekey (&optional node assert)
352 | "Return citation key associated with NODE.
353 | If optional NODE is nil, return the citekey for node at point.
354 | ASSERT will be passed to `org-roam-node-at-point'. If it is
355 | non-nil, an error will be thrown if there is no node at point."
356 | (when-let ((node (or node
357 | ;; try to get node at point only in Org mode;
358 | ;; can brake other things if not in Org mode, see e.g.
359 | ;; https://github.com/org-roam/org-roam-bibtex/issues/268
360 | (and (derived-mode-p 'org-mode)
361 | (org-roam-node-at-point assert))))
362 | (node-refs (cdr (assoc-string
363 | "ROAM_REFS"
364 | (org-roam-node-properties node) t))))
365 | (let* ((ref-list (split-string-and-unquote node-refs)))
366 | (catch 'found
367 | (dolist (ref ref-list)
368 | (when (string-match orb-utils-citekey-re ref)
369 | (throw 'found (match-string 1 ref))))))))
370 |
371 | (defun orb-format-entry (citekey)
372 | "Format a BibTeX entry for display, whose citation key is CITEKEY.
373 | Uses `bibtex-completion-format-entry' internally and so the
374 | display can be tweaked in the `bibtex-completion-display-formats'
375 | variable."
376 | ;; NOTE: A drop-in replacement for `org-ref-format-entry' which was removed
377 | ;; in Org-ref v3. Still waiting for a native solution.
378 | (bibtex-completion-init)
379 | (bibtex-completion-format-entry
380 | (bibtex-completion-get-entry citekey) (1- (frame-width))))
381 |
382 | (provide 'orb-utils)
383 | ;;; orb-utils.el ends here
384 | ;; Local Variables:
385 | ;; coding: utf-8
386 | ;; fill-column: 79
387 | ;; End:
388 |
--------------------------------------------------------------------------------