├── LICENSE
├── demos
├── sfs-dired-info-demo.gif
├── sfs-rec-custom-demo.gif
├── sfs-rec-demo.gif
├── sfs-recollect-demo.gif
├── sfs-redir-demo.gif
├── sfs-res-demo.gif
└── sfs-res-record-demo.gif
├── evil-collection-sfs.el
├── readme.org
├── service.py
├── sfs-rec-custom-demo.gif
├── sfs-recoll.el
├── sfs-recollect-demo.gif
├── sfs-redir-demo.gif
├── sfs-reindex.el
├── sfs-res-rec-demo.gif
├── sfs-tag.el
├── sfs-tui.el
└── sfs.el
/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 | {one line to give the program's name and a brief idea of what it does.}
635 | Copyright (C) {year} {name of author}
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 | {project} Copyright (C) {year} {fullname}
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 |
--------------------------------------------------------------------------------
/demos/sfs-dired-info-demo.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Overdr0ne/sfs/9acac15db1497aa3dd0ec40077a695b748d5cd13/demos/sfs-dired-info-demo.gif
--------------------------------------------------------------------------------
/demos/sfs-rec-custom-demo.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Overdr0ne/sfs/9acac15db1497aa3dd0ec40077a695b748d5cd13/demos/sfs-rec-custom-demo.gif
--------------------------------------------------------------------------------
/demos/sfs-rec-demo.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Overdr0ne/sfs/9acac15db1497aa3dd0ec40077a695b748d5cd13/demos/sfs-rec-demo.gif
--------------------------------------------------------------------------------
/demos/sfs-recollect-demo.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Overdr0ne/sfs/9acac15db1497aa3dd0ec40077a695b748d5cd13/demos/sfs-recollect-demo.gif
--------------------------------------------------------------------------------
/demos/sfs-redir-demo.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Overdr0ne/sfs/9acac15db1497aa3dd0ec40077a695b748d5cd13/demos/sfs-redir-demo.gif
--------------------------------------------------------------------------------
/demos/sfs-res-demo.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Overdr0ne/sfs/9acac15db1497aa3dd0ec40077a695b748d5cd13/demos/sfs-res-demo.gif
--------------------------------------------------------------------------------
/demos/sfs-res-record-demo.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Overdr0ne/sfs/9acac15db1497aa3dd0ec40077a695b748d5cd13/demos/sfs-res-record-demo.gif
--------------------------------------------------------------------------------
/evil-collection-sfs.el:
--------------------------------------------------------------------------------
1 | ;;; evil-collection-sfs.el --- Evil bindings and configuration for SFS. -*- lexical-binding: t; -*-
2 |
3 | ;; Copyright (C) 2021 Sam
4 |
5 | ;; Author: Sam
6 | ;; Keywords: tools
7 |
8 | ;; This program is free software; you can redistribute it and/or modify
9 | ;; it under the terms of the GNU General Public License as published by
10 | ;; the Free Software Foundation, either version 3 of the License, or
11 | ;; (at your option) any later version.
12 |
13 | ;; This program is distributed in the hope that it will be useful,
14 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | ;; GNU General Public License for more details.
17 |
18 | ;; You should have received a copy of the GNU General Public License
19 | ;; along with this program. If not, see .
20 |
21 | ;;; Commentary:
22 |
23 | ;;; Code:
24 |
25 | (defun evil-collection-sfs-setup ()
26 | "Sets up keybindings and initial states for SFS."
27 | (interactive)
28 | (evil-set-initial-state 'sfs-research-mode 'insert)
29 |
30 | (evil-collection-define-key '(normal insert) 'sfs-research-mode-map
31 | (kbd "C-q") 'quit-window
32 | (kbd "") 'widget-field-activate
33 | (kbd "C-r") 'sfs--record-query)
34 | (evil-collection-define-key 'normal 'sfs-recollect-mode-map
35 | (kbd "") 'sfs-recollect-at-point
36 | (kbd "q") 'quit-window)
37 | (evil-collection-define-key 'normal 'sfs-represent-mode-map
38 | (kbd "q") 'quit-window)
39 | (evil-collection-define-key 'normal 'sfs-redir-mode-map
40 | (kbd "") 'sfs-represent
41 | (kbd "q") 'quit-window))
42 |
43 | (provide 'evil-collection-sfs)
44 | ;;; evil-collection-sfs.el ends here
45 |
--------------------------------------------------------------------------------
/readme.org:
--------------------------------------------------------------------------------
1 | #+TITLE: SFS (Search File System)
2 | #+OPTIONS: toc:2
3 |
4 | (Just in case anyone is watching this for activity, I have paused direct development here to familiarize myself with guix/nix in an attempt to create a simpler, reproducible installation process for this and other packages with non-trivial external dependencies. However, do feel free to submit any issues you may be having; I continue to use sfs myself, and will try to support anyone wanting to try things out.)
5 |
6 | - [[#introduction][Introduction]]
7 | - [[#installation][Installation]]
8 | - [[#indexing][Indexing]]
9 | - [[#searching][Researching]]
10 | - [[#recollections][Recollections]]
11 | - [[#dired][Dired]]
12 | - [[#sfs-tags][sfs-tags]]
13 |
14 | * Introduction
15 | SFS is a collection of inter-operating emacs tools to make accessing and organizing your data faster and more ergonomic. It is largely powered by the Recoll file-indexing tool.
16 | * Installation
17 | Install the python dependencies:
18 | #+begin_src
19 | sudo pip3 install dbus-python PyGObject
20 | #+end_src
21 | You will also need to install Recoll, go [[https://www.lesbonscomptes.com/recoll/download.html][here]].
22 | Then, I use straight+use-package:
23 | #+begin_src elisp
24 | (use-package sfs
25 | :straight (sfs :type git
26 | :host github
27 | :repo "Overdr0ne/sfs"
28 | :branch "master"
29 | :files ("sfs.el"
30 | "sfs-recoll.el"
31 | "sfs-tui.el"
32 | "sfs-tag.el"
33 | "sfs-reindex.el"
34 | "service.py"
35 | "evil-collection-sfs.el"))
36 | :config
37 | ;; This starts the server responsible for dispatching queries among other things
38 | (global-sfs-mode 1))
39 | #+end_src
40 | * Indexing
41 | You will need to build a Recoll index first, if you’ve already done so, skip this step. Start by configuring what and how you want to index in your recoll.conf, or for convenience:
42 | #+begin_src
43 | sfs-reindex-config
44 | #+end_src
45 | Then, run the indexer, using the *recollindex* command, or within emacs:
46 | #+begin_src
47 | sfs-reindex-build
48 | #+end_src
49 | You may run that [[https://www.lesbonscomptes.com/recoll/usermanual/webhelp/docs/RCL.INDEXING.PERIODIC.html][periodically]], or have recoll index in [[https://www.lesbonscomptes.com/recoll/usermanual/webhelp/docs/RCL.INDEXING.MONITOR.html][real time ]]with the command *recollindex -m*. I just put that command in my .xinitrc, but you could also set it up as a systemd service or something.
50 | Before you can search, you must index your filesystem with the program *recollindex*. There are a number of options here, but basically you can do this [[https://www.lesbonscomptes.com/recoll/usermanual/webhelp/docs/RCL.INDEXING.PERIODIC.html][periodically]], or in [[https://www.lesbonscomptes.com/recoll/usermanual/webhelp/docs/RCL.INDEXING.MONITOR.html][real time]], updating the index every time a file is modified!
51 | * Researching
52 | Research queries are forwarded to the python search service that's started when the package loads, and the results are used to populate a dired buffer.
53 | Queries may be entered in the minibuffer with:
54 | #+begin_src
55 | sfs-recoll
56 | #+end_src
57 | Or, in the full query editor with:
58 | #+begin_src
59 | sfs-research
60 | #+end_src
61 |
62 | [[./demos/sfs-res-demo.gif]]
63 |
64 | The editor provides a number of keybindings to quickly insert any of Recolls metadata tags.
65 |
66 | Recoll search queries are fully documented [[https://www.lesbonscomptes.com/recoll/usermanual/webhelp/docs/RCL.SEARCH.LANG.html][here]]. The syntax is very similar to an internet search engine.
67 |
68 | You can search for keywords individually:
69 | #+begin_src
70 | Query: keywords to look for in the index
71 | #+end_src
72 | Or clustered phrases:
73 | #+begin_src
74 | Query: "keywords to look" for in "the index"
75 | #+end_src
76 | Recoll also recognizes certain field names:
77 | #+begin_src
78 | Query: filename:test OR filename:bla ext:c dir:home -dir:bin size<10000 date:2001-03-01/2021-05-01
79 | #+end_src
80 | So this gives me files with test or bla in the filename, .c files, home somewhere in the path, bin nowhere in the path, files less than 10000 bytes, and dated between 2001-03-01 and 2021-05-01.
81 |
82 | The full list of field names for convenience:
83 | - *title*, *subject* or *caption* are synonyms which specify data to be searched for in the document title or subject.
84 | - *author* or *from* for searching the documents originators.
85 | - *recipient* or *to* for searching the documents recipients.
86 | - *keyword* for searching the document-specified keywords (few documents actually have any).
87 | - *filename* for the document's file name.
88 | - *containerfilename*. This is set for all documents, both top-level and contained sub-documents, and is always the name of the filesystem directory entry which contains the data.
89 | - *ext* specifies the file name extension (Ex: ext:html)
90 | - *dir* for filtering the results on file location
91 | - *size* for filtering the results on file size.
92 | - *date* for searching or filtering on dates.
93 | - *mime* or *format* for specifying the MIME type.
94 | - *type* or *rclcat* for specifying the category (as in text/media/presentation/etc.)
95 |
96 | ** Recording
97 | You can also *record* your queries. When you *record* a query, it can inserted into the *sfs-recs* hierarchy using '.' as a separator like you would a file.at.some.path.
98 |
99 | [[./demos/sfs-res-record-demo.gif]]
100 |
101 | Queries are saved using the customize interface. To make them persistent, you’ll need to call customize-save-customized to permanently add the query to sfs-recs. Personally, I’ved added *customize-save-customized* to the *kill-emacs-hook*:
102 | #+begin_src
103 | (add-hook ’kill-emacs-hook ’customize-save-customized)
104 | #+end_src
105 | This ensures sfs-recs are saved at the end of each emacs session.
106 |
107 | An *sfs-recs* entry can be either a nested alist, or a function that generates such an alist! This is how I generate the recent.day, recent.week and recent.month entries. Those functions are evaluated when *sfs-recollect* is called.
108 |
109 | * Recollections
110 | Recollections are basically just saved queries. They can also be thought of as file directories in that they can composed into hierarchies, but unlike directories they are defined by the semantics of the query language. See what I mean with:
111 | #+begin_src
112 | sfs-recollect
113 | #+end_src
114 |
115 | [[./demos/sfs-recollect-demo.gif]]
116 |
117 | You can then execute the query at a point with , much like you would enter a directory in dired or something. So when I make a recollection called 'recent images', I can actually make sure it contains all and only image files that I saved in the past week or something, which is usually what people want when they define their file hierarchies. The hierarchy here is actually just an alternative representation of queries themselves, in other words, it is the AST representation of recoll search queries. So if you like, you can just write in a query in its hierarchical form and execute it, like so:
118 | #+begin_src
119 | \* OR
120 | \** AND
121 | \*** ext:c
122 | \*** filename:test
123 | \*** size:<1M
124 | \** AND
125 | \*** ext:js
126 | \*** filename:bla
127 | \*** date:2019/
128 | \** inline test query type:text
129 | #+end_src
130 |
131 | [[./demos/sfs-rec-custom-demo.gif]]
132 |
133 | I haven't quite covered the entirety of the query language here, specifically the ',' and '/' operators are not covered. Queries entered here are also not yet saved between sessions.
134 |
135 | * Redir
136 | Because Recoll stores so much metadata to make files searchable, we get these extra file 'properties' for free. *If it is indexed*, in dired you can access these properties for the file at point using
137 | #+begin_src
138 | sfs-represent
139 | #+end_src
140 |
141 | [[./demos/sfs-redir-demo.gif]]
142 |
143 | In my example, because I’ve indexed my entire filesystem, sfs-represent will actually work anywhere.
144 |
145 | This command is bound to in sfs-redir-mode, which is enabled automatically for sfs results. The command should work though in any dired buffer if the file is indexed. (It basically just computes the file md5 hash and uses that to look up the properties for that file, falling back to looking up based on filename in case it doesn't find it. And because recoll does not store the contiguous filename, this may find some other file with the same name but with two parent directories reversed, like /usr/bin/test and /bin/usr/test.)
146 |
147 | * sfs-tags
148 | *unfinished* sfs-tags is a set of utilities for tagging your data, primarily unix files using extended attributes. In a dired directory, tag the file at point with
149 | #+begin_src
150 | sfs-tag-set
151 | #+end_src
152 | and dump the tag info with
153 | #+begin_src
154 | sfs-tag-get
155 | #+end_src
156 |
157 | * TODO [0/7]
158 | - [-] Add a fancy start page with lots of suggested tag buttons, search history, help commands, etc. that can be conveniently added and removed and composed, sorta like a root directory, model it a bit like magit with really short keybindings.
159 | + [-] the researcher still needs search history, suggestions and tags.
160 | + [-] the recollector works like a root directory
161 | - [ ] parse infixed queries from the recollector into their AST representations such that they can be inserted into the recollections.
162 | - [-] Iterative filtering of results so it feels more like you are navigating your file-system, but non-hierarchically!
163 | + [-] I think the query system is fast enough that simply not deleting the query after search is good enough, though it would be nice to eventually make the updating dynamic...
164 | - [ ] completion integration for each tag
165 | - [ ] maybe store queries in their AST form as files such that they can themselves use a derivative of the dired interface. This also provides a flexible, clear solution to persistence, and creates a single source of truth for building multiple perspectives on queries, inside or outside of emacs. I also like how this links query components together as independent nodes, rather than one monolithic structure, so you more conveniently manipulate subtrees without needing the whole tree.
166 | - [ ] Improve help to make the query language more obvious and intuitive
167 | - [-] Cross-platform...
168 | + [-] Linux
169 | + [ ] Mac
170 | + [ ] Windows
171 | - Bugs...
172 | + From Recoll: "mime, rclcat, size and date criteria always affect the whole query (they are applied as a final filter), even if set with other terms inside a parenthese. mime (or the equivalent rclcat) is the only field with an OR default. You do need to use OR with ext terms for example." One consequence is you can't OR dates :(
173 | + results are not chunked, and dired has a hard time managing massive results, so things slow down pretty massively if the number of results is large.
174 | + The query editor is basically a major mode inside another major mode. Emacs does not natively support multiple major modes in a single buffer, so what I have is a big, ugly hack. You can break out of editibility by backspacing the first character, then you're stuck in read-only. ugh...
175 | + Syntax highlighting is very basic, not context aware, and can conflate a date '/' with the or operator
176 |
--------------------------------------------------------------------------------
/service.py:
--------------------------------------------------------------------------------
1 | from gi.repository import GLib
2 |
3 | from recoll import recoll
4 |
5 | import dbus
6 | import dbus.service
7 | import dbus.mainloop.glib
8 |
9 | usage = """Usage:
10 | python service.py &
11 | """
12 |
13 | class DemoException(dbus.DBusException):
14 | _dbus_error_name = 'com.sfs.QueryException'
15 |
16 | class SFS(dbus.service.Object):
17 | @dbus.service.method("com.sfs.SearchInterface",
18 | in_signature='s', out_signature='aa{ss}')
19 | def Query(self, queryStr):
20 | db = recoll.connect()
21 | queryObj = db.query()
22 | nres = queryObj.execute(queryStr)
23 | results = queryObj.fetchmany(500)
24 | rtn = []
25 | for doc in results:
26 | doc.url = str(doc.url).replace('file://','')
27 | dic = {}
28 | for key in doc.keys():
29 | dic[key] = doc[key]
30 | rtn.append(dic)
31 | return rtn
32 |
33 | @dbus.service.method("com.sfs.SearchInterface",
34 | in_signature='', out_signature='')
35 | def RaiseException(self):
36 | raise QueryException('The RaiseException method does what you might '
37 | 'expect')
38 |
39 | @dbus.service.method("com.sfs.SearchInterface",
40 | in_signature='', out_signature='')
41 | def Exit(self):
42 | mainloop.quit()
43 |
44 |
45 | if __name__ == '__main__':
46 | dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
47 |
48 | session_bus = dbus.SessionBus()
49 | name = dbus.service.BusName("com.sfs.SearchService", session_bus)
50 | object = SFS(session_bus, '/SFS')
51 |
52 | mainloop = GLib.MainLoop()
53 | print("Running SFS service.")
54 | print(usage)
55 | mainloop.run()
56 |
--------------------------------------------------------------------------------
/sfs-rec-custom-demo.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Overdr0ne/sfs/9acac15db1497aa3dd0ec40077a695b748d5cd13/sfs-rec-custom-demo.gif
--------------------------------------------------------------------------------
/sfs-recoll.el:
--------------------------------------------------------------------------------
1 | ;;; sfs-recoll --- An sfs interface to recoll.
2 | ;;; sfs-recoll.el -*- lexical-binding: t; -*-
3 | ;;
4 | ;; Copyright (C) 2020
5 | ;;
6 | ;; Author:
7 | ;; Maintainer:
8 | ;; Created: May 23, 2020
9 | ;; Modified: May 24, 2020
10 | ;; Version: 0.0.1
11 | ;; Keywords:
12 | ;; Homepage: https://github.com/Overdr0ne/sfs
13 | ;; Package-Requires: ((emacs 26.3) (cl-lib "0.5"))
14 | ;;
15 | ;; This file is not part of GNU Emacs.
16 | ;;
17 | ;;; Commentary:
18 | ;;
19 | ;;
20 | ;;
21 | ;;; Code:
22 |
23 | (require 'dbus)
24 | (require 'dired)
25 |
26 | (defun sfs--recoll-get-field (field aList)
27 | "Utility function to get FIELD from ALIST."
28 | (cadr (assoc field aList)))
29 |
30 | (defun sfs--recoll-get-fields (fields aList)
31 | "Utility function to get FIELDS from ALIST."
32 | (mapcar #'(lambda (field) (sfs--recoll-get-field field aList))
33 | fields))
34 |
35 | (defun sfs--recoll-collect-fields (fields db)
36 | "Collect data FIELDS from DB."
37 | (mapcar #'(lambda (entry) (car (sfs--recoll-get-fields fields entry)))
38 | db))
39 |
40 | (defun sfs--recoll-property-str (entry)
41 | "Build tooltip string from DBENTRY."
42 | (let (infoStrs)
43 | (setq entry
44 | (remove-if #'(lambda (field) (string-empty-p (cadr field)))
45 | entry))
46 | (setq infoStrs (mapcar
47 | #'(lambda (field)
48 | (concat (car field) ": " (cadr field) "\n"))
49 | entry))
50 | (reduce #'concat infoStrs)))
51 |
52 | (defun sfs--recoll-search-md5 (filename)
53 | (let (buf-str query entry)
54 | (setq buf-str (with-temp-buffer
55 | (insert-file-contents filename)
56 | (buffer-string)))
57 | (setq query (concat "rclmd5:"
58 | (secure-hash 'md5 buf-str)))
59 | (car (sfs--recoll-search query))))
60 |
61 | (defun sfs--recoll-search-filename (filename)
62 | (let (query split dirs name)
63 | (setq split (split-string filename "/"))
64 | (setq split (remove-if #'(lambda (str) (string= str ""))
65 | split))
66 | (setq name (car (last split)))
67 | (setq dirs (butlast split))
68 | (setq query (mapcar #'(lambda (dir) (concat "dir:" dir))
69 | dirs))
70 | (add-to-list 'query (concat "filename:" name))
71 | (setq query (string-join query " AND "))
72 | (car (sfs--recoll-search query))))
73 |
74 | (defun sfs--recoll-file-properties (filename)
75 | "Get recoll properties for FILENAME by looking up its md5 hash or guessing from the filename."
76 | (let (entry)
77 | (setq entry
78 | (-some #'(lambda (x) x)
79 | `(,(sfs--recoll-search-md5 filename)
80 | ,(progn
81 | (message "Couldn't find entry based on it's hash, guessing the entry based on filename...")
82 | (sfs--recoll-search-filename filename)))))))
83 |
84 | (defun sfs--recoll-call (methodStr &rest args)
85 | "Send METHOD to the SFS python server with optional ARGS."
86 | ;; TODO only works with one argument
87 | (dbus-call-method
88 | :session
89 | "com.sfs.SearchService"
90 | "/SFS"
91 | "com.sfs.SearchInterface"
92 | methodStr
93 | (car args)))
94 |
95 | (defun sfs--recoll-search (query-str)
96 | (sfs--recoll-call "Query" query-str))
97 |
98 | (defun sfs--recoll-find-urls (query-str)
99 | "Query the Recoll database and display the results in dired.
100 | QUERYSTR is a search string conforming to the Recoll Query Language."
101 | (if (not (string= query-str ""))
102 | (let ((raw-db (sfs--recoll-search query-str)))
103 | (if raw-db
104 | (let ((db (remove-if-not #'(lambda (entry)
105 | (file-exists-p (sfs--recoll-get-field "url"
106 | entry)))
107 | raw-db)))
108 | (sfs--recoll-collect-fields '("url") db)
109 | )
110 | (message "SFS: Couldn't find any results for your search...")))
111 | (message "SFS: query string empty...")))
112 |
113 | (defun sfs-recoll-exit ()
114 | "Exit SFS Recoll server."
115 | (interactive)
116 | (dbus-call-method
117 | :session
118 | "com.sfs.SearchService"
119 | "/SFS"
120 | "com.sfs.SearchInterface"
121 | "Exit"))
122 |
123 | (provide 'sfs-recoll)
124 | ;;; sfs-recoll.el ends here
125 |
--------------------------------------------------------------------------------
/sfs-recollect-demo.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Overdr0ne/sfs/9acac15db1497aa3dd0ec40077a695b748d5cd13/sfs-recollect-demo.gif
--------------------------------------------------------------------------------
/sfs-redir-demo.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Overdr0ne/sfs/9acac15db1497aa3dd0ec40077a695b748d5cd13/sfs-redir-demo.gif
--------------------------------------------------------------------------------
/sfs-reindex.el:
--------------------------------------------------------------------------------
1 | ;;; sfs-index.el --- description -*- lexical-binding: t; -*-
2 | ;;
3 | ;; Copyright (C) 2020
4 | ;;
5 | ;; Author:
6 | ;; Maintainer:
7 | ;; Created: August 10, 2020
8 | ;; Modified: August 10, 2020
9 | ;; Version: 0.0.1
10 | ;; Keywords:
11 | ;; Homepage: https://github.com/Overdr0ne/sfs
12 | ;; Package-Requires: ((emacs 26.3) (cl-lib "0.5"))
13 | ;;
14 | ;; This file is not part of GNU Emacs.
15 | ;;
16 | ;;; Commentary:
17 | ;;
18 | ;; description
19 | ;;
20 | ;;; Code:
21 |
22 | (defun sfs-reindex-build ()
23 | "Start the recoll indexer."
24 | (interactive)
25 | (async-shell-command (concat "recollindex -c "
26 | (getenv "RECOLL_CONFDIR"))
27 | "*recollindex output*"
28 | "*recollindex error"))
29 |
30 | (defun sfs-reindex-config ()
31 | "Open the recoll configuration file, interactively creating one if necessary."
32 | (interactive)
33 | (when (not (getenv "RECOLL_CONFDIR"))
34 | (progn
35 | (message "RECOLL_CONFDIR not set. Setting it to ~/.recoll.")
36 | (setenv "RECOLL_CONFDIR" (concat (getenv "HOME") "/.recoll"))
37 | (when (not (file-exists-p (getenv "RECOLL_CONFDIR")))
38 | (mkdir (getenv "RECOLL_CONFDIR")))))
39 | (find-file (concat (getenv "RECOLL_CONFDIR") "/recoll.conf")))
40 |
41 | (defun sfs-reindex-monitor ()
42 | "Start the monitoring files for indexing with recoll."
43 | (async-shell-command "recollindex -m"))
44 |
45 | (provide 'sfs-reindex)
46 | ;;; sfs-index.el ends here
47 |
--------------------------------------------------------------------------------
/sfs-res-rec-demo.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Overdr0ne/sfs/9acac15db1497aa3dd0ec40077a695b748d5cd13/sfs-res-rec-demo.gif
--------------------------------------------------------------------------------
/sfs-tag.el:
--------------------------------------------------------------------------------
1 | ;;; sfs-tag.el -*- lexical-binding: t; -*-
2 | ;;
3 | ;; Copyright (C) 2020
4 | ;;
5 | ;; Author:
6 | ;; Maintainer:
7 | ;; Created: June 19, 2020
8 | ;; Modified: June 19, 2020
9 | ;; Version: 0.0.1
10 | ;; Keywords:
11 | ;; Homepage: https://github.com/Overdr0ne/sfs
12 | ;; Package-Requires: ((emacs 26.3) (cl-lib "0.5"))
13 | ;;
14 | ;; This file is not part of GNU Emacs.
15 | ;;
16 | ;;; Commentary:
17 | ;;
18 | ;;
19 | ;;
20 | ;;; Code:
21 |
22 | (require 'dash)
23 |
24 | (defun sfs-tag-collect-tags ()
25 | "Collect existing tags for file at POINT."
26 | (let (attr)
27 | (setq attr (-> (format "getfattr --absolute-names %s"
28 | (shell-quote-argument (dired-get-filename)))
29 | (shell-command-to-string)))
30 | (setq attr (dired-replace-in-string "#.*" "" attr))
31 | (split-string attr)))
32 |
33 | (defun sfs-tag-collect-vals (tag)
34 | (-> (format "getfattr --absolute-names --only-values -n %s %s 2>/dev/null"
35 | tag (shell-quote-argument (dired-get-filename)))
36 | (shell-command-to-string)
37 | (split-string)))
38 |
39 | (defcustom sfs-tag-initial-input "user."
40 | "A list of set recs to be displayed in the SFS collector TUI."
41 | :type 'string
42 | :group 'sfs)
43 |
44 | (defun sfs-tag-set ()
45 | "Interactively tag the file at POINT using extended attributes."
46 | (interactive)
47 | (let* ((tag (completing-read "Tag: " (sfs-tag-collect-tags) nil nil sfs-tag-initial-input))
48 | (value (completing-read "Value: " (sfs-tag-collect-vals tag)))
49 | (filename (dired-get-filename)))
50 | (shell-command-to-string
51 | (format "setfattr -n %s -v %s %s" tag value filename))
52 | (message (format "Set tag %s to %s on %s." tag value filename))))
53 |
54 | (defun sfs-tag-get ()
55 | "Get all tag info for file at POINT using extended attributes."
56 | (interactive)
57 | (let* ((tag (completing-read "Tag: " (sfs-tag-collect-tags)))
58 | (filename (dired-get-filename))
59 | (value (shell-command-to-string
60 | (format "getfattr --absolute-names --only-values -n %s %s" tag filename))))
61 | (message "Tag %s has value %s on %s." tag value filename)))
62 |
63 | (defun sfs-tag-rm ()
64 | "Remove tag from file at POINT."
65 | (interactive)
66 | (let ((tag (completing-read "Remove tag: " (sfs-tag-collect-tags)))
67 | (filename (dired-get-filename)))
68 | (shell-command-to-string
69 | (format "setfattr -x %s %s" tag filename))
70 | (message (format "Removed tag %s from %s." tag filename))))
71 |
72 | (provide 'sfs-tag)
73 | ;;; sfs-tag.el ends here
74 |
--------------------------------------------------------------------------------
/sfs-tui.el:
--------------------------------------------------------------------------------
1 | ;;; sfs-tui.el --- description -*- lexical-binding: t; -*-
2 | ;;
3 | ;; Copyright (C) 2020
4 | ;;
5 | ;; Author:
6 | ;; Maintainer:
7 | ;; Created: July 06, 2020
8 | ;; Modified: July 06, 2020
9 | ;; Version: 0.0.1
10 | ;; Keywords:
11 | ;; Homepage: https://github.com/Overdr0ne/sfs
12 | ;; Package-Requires: ((emacs 26.3) (cl-lib "0.5"))
13 | ;;
14 | ;; This file is not part of GNU Emacs.
15 | ;;
16 | ;;; Commentary:
17 | ;;
18 | ;; description
19 | ;;
20 | ;;; Code:
21 |
22 | (require 'sfs-recoll)
23 | (require 'dash)
24 |
25 | ;;; shared stuff
26 | (defgroup sfs nil
27 | "Customization group for SFS."
28 | :group 'Applications)
29 |
30 | (defcustom sfs-recs `(sfs--rec-recents
31 | sfs--rec-media)
32 | "A list of set recs to be displayed in the SFS collector TUI."
33 | :type 'sexp
34 | :group 'sfs)
35 |
36 | (defconst sfs--researcher-buf "*SFS researcher*")
37 | (defconst sfs--recollector-buf "*SFS recollector*")
38 |
39 | (defun sfs--queries-or (query-list)
40 | "Create ORed query string from QUERY-LIST."
41 | (string-join query-list " OR "))
42 |
43 | (defun sfs--split-and-prefix (prefix query)
44 | "Split the QUERY on space, and prepend the provided PREFIX to each."
45 | (mapcar #'(lambda (str)
46 | (concat prefix ":" str))
47 | (split-string query)))
48 |
49 | (cl-defstruct (sfs-section (:constructor sfs-section-create (top bot))
50 | (:copier nil))
51 | top bot)
52 |
53 | (defface sfs-heading '((t (:bold t :underline t)))
54 | "Face used for displaying underlined bold emphasized text (_*word*_).")
55 |
56 | (defun set-region-read-only (begin end)
57 | "Sets the read-only text property on the marked region.
58 |
59 | Use `set-region-writeable' to remove this property."
60 | ;; See https://stackoverflow.com/questions/7410125
61 | ;; (interactive "r")
62 | (with-silent-modifications
63 | (put-text-property begin end 'read-only t)))
64 |
65 | ;;; Simple Recoll
66 | (defun sfs-recoll (query-str)
67 | "Search QUERYSTR with recoll and display results in dired."
68 | (interactive "sQuery: ")
69 | (if (not (string= query-str ""))
70 | (let ((sfs-dired-buf (dired (sfs--recoll-find-urls query-str))))
71 | (set-buffer sfs-dired-buf)
72 | (rename-buffer (concat "*SFS dired* : " (buffer-name)))
73 | (buffer-name)
74 | (sfs-redir-mode))
75 | (message "SFS: query string empty...")))
76 |
77 | ;;; Representer
78 | (defvar sfs--recoll-fields
79 | '("rcludi"
80 | "fbytes"
81 | "dbytes"
82 | "sig"
83 | "url"
84 | "abstract"
85 | "filename"
86 | "relevancyrating"
87 | "mtype"
88 | "origcharset"
89 | "mtime"
90 | "fmtime"
91 | "pcbytes"))
92 | (defvar sfs-representation-highlights nil "First element for `font-lock-defaults'.")
93 | (dolist (field sfs--recoll-fields)
94 | (add-to-list 'sfs-representation-highlights `(,field . font-lock-keyword-face)))
95 |
96 | (defvar sfs-representation-mode-map
97 | (let ((map (make-sparse-keymap)))
98 | (define-key map (kbd "q") 'quit-window)
99 | map))
100 | (define-derived-mode sfs-represent-mode fundamental-mode "SFS:rep"
101 | "Major mode for SFS interactive query editor.
102 |
103 | The query editor uses the Recoll query language, documented here:
104 | https://www.lesbonscomptes.com/recoll/usermanual/webhelp/docs/RCL.SEARCH.LANG.html"
105 | (hl-line-mode)
106 | (setq font-lock-defaults '(sfs-representation-highlights)))
107 |
108 | (defun sfs-represent ()
109 | "Display a tooltip showing metadata about the file at POINT."
110 | (interactive)
111 | (let ((entry (sfs--recoll-file-properties (dired-get-filename)))
112 | (buffer (get-buffer-create "*SFS represent*"))
113 | (filename (dired-get-filename))
114 | str)
115 | (if entry
116 | (progn
117 | (setq str (sfs--recoll-property-str entry))
118 | (with-current-buffer buffer
119 | (visual-line-mode 1)
120 | ;; (auto-fill-mode 1)
121 | (let ((inhibit-read-only t))
122 | (erase-buffer)
123 | (insert str))
124 | (pop-to-buffer buffer
125 | '((display-buffer-in-side-window)
126 | (side . right)
127 | (slot . 0)))
128 | (fit-window-to-buffer)
129 | (sfs-represent-mode)
130 | (set-window-point (get-buffer-window buffer) 0)))
131 | (message "This file has not been indexed by Recoll..."))))
132 |
133 | ;;; Redirectory
134 | (defvar sfs-redir-mode-map (make-keymap) "SFS redir mode keymap.")
135 | (define-key sfs-redir-mode-map
136 | (kbd "") 'sfs-represent)
137 | (define-minor-mode sfs-redir-mode
138 | "Minor mode for sfs results in dired."
139 | nil
140 | " SFS:red"
141 | :keymap sfs-redir-mode-map)
142 |
143 | (defun sfs-redisplay-info-hook (entry)
144 | (let ((buffer (get-buffer-create " *Minibuf*")) str)
145 | (setq str (sfs-recoll-build-tooltip entry))
146 | (with-current-buffer buffer
147 | (visual-line-mode 1)
148 | (auto-fill-mode 1)
149 | (erase-buffer)
150 | (insert str)
151 | (display-buffer buffer)))
152 | (select-window (get-mru-window)))
153 |
154 | (defmacro minibuffer-quit-and-run (&rest body)
155 | "Quit the minibuffer and run BODY afterwards."
156 | `(progn
157 | (put 'quit 'error-message "")
158 | (run-at-time nil nil
159 | (lambda ()
160 | (put 'quit 'error-message "Quit")
161 | ,@body))
162 | (minibuffer-keyboard-quit)))
163 |
164 | ;; (defun sfs-dired-next-line ()
165 | ;; (interactive)
166 | ;; "Go to next line, and display file info in minibuffer."
167 | ;; (minibuffer-quit-and-run
168 | ;; (dired-next-line 1)
169 | ;; (sfs-display-info)))
170 | ;; ;; (substitute-key-definition 'dired-next-line 'sfs-dired-next-line dired-mode-map)
171 |
172 | ;; (defun sfs-dired-previous-line ()
173 | ;; (interactive)
174 | ;; "Go to previous line, and display file info in minibuffer."
175 | ;; (minibuffer-quit-and-run
176 | ;; (dired-previous-line 1)
177 | ;; (sfs-display-info)))
178 | ;; ;; (substitute-key-definition 'dired-previous-line 'sfs-dired-previous-line dired-mode-map)
179 |
180 | (defun sfs-redired-tooltip ()
181 | "Display a tooltip showing metadata about the file at POINT."
182 | (interactive)
183 | (let ((entry (sfs--recoll-file-properties (dired-get-filename))))
184 | (popup-tip (sfs--recoll-property-str entry) :point (line-beginning-position))))
185 |
186 | (defun sfs-redired-yank ()
187 | "Yank selected metadata for file at POINT."
188 | (interactive)
189 | (let* ((metadata (sfs--recoll-file-properties (dired-get-filename)))
190 | (selection (completing-read "Find Property: " metadata))
191 | (value (cadr (assoc selection metadata))))
192 | (kill-new value)
193 | (message "Yanked \"%s\" to the kill-ring." value)))
194 |
195 | ;;; Researcher
196 | (defvar sfs--query "")
197 |
198 | (defun sfs--fields ()
199 | '("author"
200 | "containerfilename"
201 | "dir"
202 | "ext"
203 | "filename"
204 | "subject"
205 | "keyword"
206 | "recipient"
207 | "rclcat"
208 | "mime"
209 | "size"
210 | "date"))
211 |
212 | (defun sfs--ops ()
213 | '("OR"
214 | "AND"
215 | ","
216 | "/"
217 | "-"))
218 |
219 | (defun sfs--query-highlights ()
220 | (let (highlights)
221 | (dolist (field (sfs--fields))
222 | (push `(,(concat field ":") . font-lock-keyword-face) highlights))
223 | (dolist (op (sfs--ops))
224 | (push `(,op . font-lock-function-name-face) highlights))
225 | highlights))
226 |
227 | ;; I need explicit function names to make help-modes useful(use which-key and edit names?), this macro automatically creates them to keep fields as single source of truth
228 | (defmacro sfs--def-prefix-fun (field)
229 | "Generate a function for inserting FIELD prefix into the researcher."
230 | `(defun ,(intern (concat "sfs--prefix-" field)) ()
231 | ,(concat "Add " field ": prefix in researcher.")
232 | (interactive)
233 | (insert ,(concat field ":"))))
234 | (dolist (field (sfs--fields))
235 | (eval `(sfs--def-prefix-fun ,field)))
236 |
237 | (defvar sfs--editor-widget)
238 |
239 | (defun sfs--id-get (id rec-tree)
240 | (if (and id rec-tree (listp rec-tree))
241 | (if (rest id)
242 | (sfs--id-get (rest id)
243 | (alist-get (car id) rec-tree))
244 | (alist-get (car id) rec-tree))
245 | nil))
246 |
247 | (defun sfs-id-get (id &optional rec-tree)
248 | (let ((path (mapcar #'intern
249 | (split-string id "\\."))))
250 | (when (not rec-tree) (setq rec-tree sfs-recs))
251 | (sfs--id-get path rec-tree)))
252 |
253 | (defun sfs--make-nested-rec (id val)
254 | (if id
255 | (if (rest id)
256 | `((,(car id) . ,(sfs--make-nested-rec (rest id) val)))
257 | `((,(car id) . ,val)))
258 | nil))
259 |
260 | (defun sfs--id-add (id val rec-tree)
261 | (cond ((not val)
262 | (message "SFS: No value provided...")
263 | rec-tree)
264 | ((not id) ;; just add the leaf
265 | (push val rec-tree)
266 | rec-tree)
267 | ((alist-get (car id) rec-tree) ;; add updated descendents
268 | (setf (alist-get (car id) rec-tree)
269 | (sfs--id-add (rest id) val
270 | (alist-get (car id) rec-tree)))
271 | rec-tree)
272 | (t ;; make branch and graft it
273 | (push (first (sfs--make-nested-rec id val)) rec-tree)
274 | rec-tree)))
275 |
276 | (defun sfs-id-add (id val rec-tree)
277 | "Set sfs ID path to VAL."
278 | (let ((path (mapcar #'intern
279 | (split-string id "\\."))))
280 | ;; (when (not rec-tree) (setq rec-tree sfs-recs))
281 | (setf rec-tree (sfs--id-add path `(,val) rec-tree)))
282 | rec-tree)
283 |
284 | (defun sfs--record-query (id)
285 | "Save current query to ID at.some.path."
286 | (interactive "sEnter a path.to.an.id for query: ")
287 | (customize-set-variable 'sfs-recs (sfs-id-add id (string-join (split-string (widget-value sfs--editor-widget)) " ") sfs-recs))
288 | (quit-window))
289 |
290 | (defun sfs--insert-rec (id)
291 | "Insert rec with ID at point."
292 | (interactive "sEnter a path.to.a.rec.id: ")
293 | (insert (sfs-id-get id)))
294 |
295 | (defvar sfs-research-mode-map
296 | (let ((map (copy-keymap widget-field-keymap)))
297 | (define-key map (kbd "") 'widget-field-activate)
298 | (define-key map "\C-q" 'quit-window)
299 | (define-key map "\C-r" 'sfs--record-query)
300 | (define-key map "\C-c\C-a" 'sfs--prefix-author)
301 | (define-key map "\C-c\C-c" 'sfs--prefix-containerfilename)
302 | (define-key map "\C-c\C-d" 'sfs--prefix-dir)
303 | (define-key map "\C-c\C-e" 'sfs--prefix-ext)
304 | (define-key map "\C-c\C-f" 'sfs--prefix-filename)
305 | (define-key map "\C-c\C-i" 'sfs--insert-rec)
306 | (define-key map "\C-c\C-j" 'sfs--prefix-subject)
307 | (define-key map "\C-c\C-k" 'sfs--prefix-keyword)
308 | (define-key map "\C-c\C-l" 'sfs--prefix-rclcat)
309 | (define-key map "\C-c\C-m" 'sfs--prefix-mime)
310 | (define-key map "\C-c\C-p" 'sfs--prefix-recipient)
311 | (define-key map "\C-c\C-t" 'sfs--prefix-date)
312 | (define-key map "\C-c\C-z" 'sfs--prefix-size)
313 | map)
314 | "Local keymap for SFS Research mode buffers.")
315 | (define-derived-mode sfs-research-mode prog-mode "SFS:res"
316 | "Major mode for researching SFS recs.
317 |
318 | The researcher uses the Recoll query language, documented here:
319 | https://www.lesbonscomptes.com/recoll/usermanual/webhelp/docs/RCL.SEARCH.LANG.html"
320 | (add-hook 'post-command-hook (lambda () (fit-window-to-buffer)) 0 t)
321 | (setq font-lock-defaults '(sfs--query-highlights)))
322 |
323 | (defvar sfs--logo-section)
324 | (defun sfs-insert-logo ()
325 | "Make SFS logo in query builder buffer."
326 | ;; (widget-insert (f-read-text "./assets/graffiti.txt"))
327 | (let ((logo "--- S*fs : researcher ---")
328 | top bot)
329 | (setq top (point))
330 | (widget-insert logo)
331 | (setq bot (point))
332 | (widget-insert "\n")
333 | (setq sfs--logo-section (sfs-section-create top bot))))
334 |
335 | (defun sfs--researcher-retrieve (query-str)
336 | "Run query through recoll and display results in a horizontal split."
337 | (quit-window)
338 | (let ((sfs-dired-buf
339 | (dired-noselect (sfs--recoll-find-urls query-str))))
340 | (when (get-buffer sfs-dired-buf)
341 | (pop-to-buffer sfs-dired-buf
342 | '((display-buffer-same-window)))
343 | (set-buffer sfs-dired-buf)
344 | (rename-buffer (concat "*SFS dired : " (buffer-name) "*"))
345 | (buffer-name)
346 | (fit-window-to-buffer)
347 | (sfs-redir-mode))))
348 |
349 | (defvar sfs--researcher-section)
350 | (defun sfs--researcher-make-section ()
351 | "Make the query section in the sfs TUI."
352 | (let (top bot)
353 | (setq top (point))
354 | (setq sfs--editor-widget
355 | (widget-create 'editable-field
356 | :keymap sfs-research-mode-map
357 | :action (lambda (wid &rest ignore)
358 | (sfs--researcher-retrieve (widget-value wid)))
359 | :notify (lambda (wid changed &rest ignore)
360 | (setq sfs--query (widget-value wid)))))
361 | (setq bot (point))
362 | (setq sfs--researcher-section (sfs-section-create top bot))
363 | (widget-create 'push-button
364 | :notify (lambda (&rest ignore)
365 | (sfs--researcher-retrieve (widget-value sfs--editor-widget)))
366 | "(C-RET)rieve")
367 | (widget-insert "\t")
368 | (widget-create 'push-button
369 | :notify (lambda (&rest ignore)
370 | (call-interactively #'sfs--record-query))
371 | "(C-r)ecord")))
372 |
373 | (defun sfs--researcher-make-tui ()
374 | "Write the tui buffer."
375 | (if (not (get-buffer sfs--researcher-buf))
376 | (let ((buffer
377 | (pop-to-buffer sfs--researcher-buf
378 | '((display-buffer-at-bottom)
379 | )
380 | )))
381 | (with-current-buffer buffer
382 | (kill-all-local-variables)
383 | (remove-overlays)
384 | (let ((inhibit-read-only t))
385 | (erase-buffer))
386 | (sfs-insert-logo)
387 | (sfs--researcher-make-section)
388 | (fit-window-to-buffer)
389 | (set-window-point (get-buffer-window sfs--researcher-buf)
390 | (sfs-section-top sfs--researcher-section))
391 | (widget-setup)
392 | (sfs-research-mode)
393 | ;; (set-region-read-only (sfs-section-top sfs--logo-section)
394 | ;; (sfs-section-bot sfs--logo-section))
395 | ))
396 | (progn
397 | (pop-to-buffer sfs--researcher-buf
398 | '((display-buffer-at-bottom)))
399 | (sfs-research-mode)
400 | (fit-window-to-buffer))))
401 |
402 | (defun sfs--tui-run (f)
403 | "Call F in TUI context."
404 | (call-interactively f)
405 | (sfs--researcher-make-tui))
406 |
407 | (defun sfs-research ()
408 | "Open the SFS researcher to recompose and record recollections."
409 | (interactive)
410 | (sfs--researcher-make-tui))
411 |
412 | ;;; Recollect
413 | (defun sfs--rec-recents ()
414 | "Make the rec for recently touched files."
415 | (let ((recent-recollections '())
416 | (recents
417 | `((day . ,(calendar-current-date))
418 | (week . ,(calendar-gregorian-from-absolute
419 | (+ (calendar-absolute-from-gregorian (calendar-current-date)) -7)))
420 | (month . ,(calendar-gregorian-from-absolute
421 | (+ (calendar-absolute-from-gregorian (calendar-current-date)) -30)))
422 | (year . ,(calendar-gregorian-from-absolute
423 | (+ (calendar-absolute-from-gregorian (calendar-current-date)) -365)))))
424 | query-str day month year rtn-date)
425 | (dolist (elmt recents)
426 | (setq rtn-date (cdr elmt))
427 | (setq day (nth 1 rtn-date))
428 | (setq month (nth 0 rtn-date))
429 | (setq year (nth 2 rtn-date))
430 | (setq query-str (format "date:%d-%d-%d/" year month day))
431 | (push `(,(car elmt) . (,query-str)) recent-recollections))
432 |
433 | `(recents . ,recent-recollections)))
434 |
435 | (defun sfs--rec-media ()
436 | "Make the media rec."
437 | `(media .
438 | ((comics . (,(sfs--queries-or (sfs--split-and-prefix "ext" "djvu cbr cbz cb7 cbt cba"))))
439 | (books . (,(sfs--queries-or (sfs--split-and-prefix "ext" "ibooks pdf epub pbd djvu azw azw3 kf8 kfx fb2 mobi opf"))))
440 | (documents . (,(sfs--queries-or (sfs--split-and-prefix "ext" "pdf doc docx txt tex"))))
441 | (music . (,(sfs--queries-or (sfs--split-and-prefix "ext" "mp3 aac"))
442 | (lossless ,(sfs--queries-or (sfs--split-and-prefix "ext" "wav flac aiff")))
443 | (lossy ,(sfs--queries-or (sfs--split-and-prefix "ext" "mp3 aac")))))
444 | (video . ,(sfs--split-and-prefix "ext" "mp4 mov wmv flv avi webm mkv"))
445 | (text . ("mime:text")))))
446 |
447 | (defun sfs--insert-heading (heading depth)
448 | "SFS insert heading at depth."
449 | (dotimes (n depth)
450 | (insert "*"))
451 | (insert (concat " " heading "\n")))
452 |
453 | (defun sfs--insert-rec-section (rec depth)
454 | "Make the section for REC with LABEL in the sfs rec TUI."
455 | (if rec
456 | (cond
457 | ((listp rec)
458 | (sfs--insert-rec-section (first rec) (+ depth 1))
459 | (sfs--insert-rec-section (rest rec) depth))
460 | ((symbolp rec)
461 | (sfs--insert-heading (concat "rec:" (symbol-name rec)) depth))
462 | (t (sfs--insert-heading rec (+ depth 1))))
463 | nil))
464 |
465 | (defvar sfs-recollect-mode-map
466 | (let ((map (make-sparse-keymap)))
467 | (define-key map (kbd "") 'sfs-recollect-at-point)
468 | (define-key map "\C-q" 'quit-window)
469 | (define-key map "\C-r" 'sfs--record-query)
470 | (define-key map "\C-c\C-a" 'sfs--prefix-author)
471 | (define-key map "\C-c\C-c" 'sfs--prefix-containerfilename)
472 | (define-key map "\C-c\C-d" 'sfs--prefix-dir)
473 | (define-key map "\C-c\C-e" 'sfs--prefix-ext)
474 | (define-key map "\C-c\C-f" 'sfs--prefix-filename)
475 | (define-key map "\C-c\C-i" 'sfs--insert-rec)
476 | (define-key map "\C-c\C-j" 'sfs--prefix-subject)
477 | (define-key map "\C-c\C-k" 'sfs--prefix-keyword)
478 | (define-key map "\C-c\C-l" 'sfs--prefix-rclcat)
479 | (define-key map "\C-c\C-m" 'sfs--prefix-mime)
480 | (define-key map "\C-c\C-p" 'sfs--prefix-recipient)
481 | (define-key map "\C-c\C-t" 'sfs--prefix-date)
482 | (define-key map "\C-c\C-z" 'sfs--prefix-size)
483 | map))
484 | (define-derived-mode sfs-recollect-mode org-mode "SFS:rec"
485 | "Mode for SFS interactive recollections interface."
486 | (hide-sublevels 2)
487 | (setq-local fit-window-to-buffer-horizontally t)
488 | ;; (setq-local window-max-width 35)
489 | (add-hook 'post-command-hook
490 | (lambda () (fit-window-to-buffer nil 999 0 35))
491 | 0 t)
492 | (visual-line-mode)
493 | (fit-window-to-buffer nil 999 0 35))
494 |
495 | (defun sfs--recollector-make-tui ()
496 | "Write the tui buffer."
497 | (pop-to-buffer sfs--recollector-buf
498 | '((display-buffer-in-side-window)
499 | (side . left)
500 | (slot . 0)))
501 | (with-current-buffer sfs--recollector-buf
502 | (erase-buffer)
503 | ;; (push-mark)
504 | (dolist (el sfs-recs)
505 | (cond ((listp el)
506 | (sfs--insert-rec-section el 0))
507 | ((symbol-function el)
508 | (sfs--insert-rec-section (funcall el) 0))
509 | (t (sfs--insert-rec-section (symbol-value el) 0))))
510 | ;; (set-region-read-only (mark) (point))
511 | ;;TODO tags section
512 | (insert "* rec:custom")
513 | ;; (push-mark)
514 | (insert "\n")
515 | (set-window-point (get-buffer-window sfs--recollector-buf)
516 | 0)
517 | (sfs-recollect-mode)))
518 |
519 | (defun sfs--heading-depth (heading)
520 | (if (string-equal (substring heading 0 1) "*")
521 | (+ 1 (sfs--heading-depth (substring heading 1)))
522 | 0))
523 |
524 | (defun sfs--headings-first-subtree-list (headings depth)
525 | (if headings
526 | (if (> (sfs--heading-depth (first headings))
527 | depth)
528 | (cons (first headings)
529 | (sfs--headings-first-subtree-list (rest headings)
530 | depth))
531 | nil)
532 | nil))
533 | (defun sfs--headings-first-tree-list (headings)
534 | (if headings
535 | (cons (first headings)
536 | (sfs--headings-first-subtree-list (rest headings)
537 | (sfs--heading-depth (first headings))))
538 | nil))
539 |
540 | (defun sfs--headings-rest-list- (headings depth)
541 | (if headings
542 | (if (= depth (sfs--heading-depth (first headings)))
543 | headings
544 | (sfs--headings-rest-list- (rest headings) depth))
545 | headings))
546 | (defun sfs--headings-rest-list (headings)
547 | (if headings
548 | (sfs--headings-rest-list- (rest headings)
549 | (sfs--heading-depth (first headings)))
550 | nil))
551 |
552 | (defun sfs--get-title (heading)
553 | (string-join (rest (split-string heading " "))
554 | " "))
555 |
556 | (defun sfs--headings-to-tree (headings)
557 | (if headings
558 | ;; cons the first query tree onto the remaining query trees
559 | (cons (cons (sfs--get-title (first headings))
560 | (sfs--headings-to-tree (rest (sfs--headings-first-tree-list headings))))
561 | (sfs--headings-to-tree (sfs--headings-rest-list headings)))
562 | nil))
563 |
564 | (defun sfs--heading-at-point-to-tree ()
565 | (let (headings tree)
566 | (setq headings (buffer-substring-no-properties (point) (point-max)))
567 | (setq headings (split-string headings "\n"))
568 | (setq headings (remove-if (lambda (el) (string= el "")) headings))
569 | (first (sfs--headings-to-tree headings))))
570 |
571 | (defun sfs--tree-to-query (tree)
572 | (let ((root (first tree)))
573 | (cond ((or (string= root "AND")
574 | (string= root "OR"))
575 | (concat "("
576 | (string-join (mapcar #'sfs--tree-to-query (rest tree))
577 | (concat " " root " "))
578 | ")"))
579 | ((string= (first (split-string root ":"))
580 | "rec")
581 | (concat "("
582 | (string-join (mapcar #'sfs--tree-to-query (rest tree))
583 | " OR ")
584 | ")"))
585 | (t root))))
586 |
587 | (defun sfs-recollect-at-point ()
588 | "Fetch the recollection under the heading at point."
589 | (interactive)
590 | (save-excursion
591 | (beginning-of-line)
592 | (let ((buf (dired-noselect
593 | (sfs--recoll-find-urls
594 | (sfs--tree-to-query
595 | (sfs--heading-at-point-to-tree))))))
596 | (quit-window)
597 | (pop-to-buffer buf
598 | '((display-buffer-same-window)))
599 | (sfs-redir-mode))))
600 |
601 | (defun sfs-record-recollection-at-point (id)
602 | "Save the recollection at point to rec ID."
603 | (interactive "sEnter id path: ")
604 | (let ((query-str (sfs-recollect-at-point)))
605 | (if (alist-get id sfs-recs)
606 | (setf (alist-get (intern id) sfs-recs)
607 | `(,query-str))
608 | (push `(,(intern id) ,(widget-value sfs--editor-widget)) sfs-recs))))
609 |
610 | (defun sfs-recollect ()
611 | "Access SFS recollections in an interactive TUI."
612 | (interactive)
613 | (sfs--recollector-make-tui))
614 |
615 | (provide 'sfs-tui)
616 | ;;; sfs-tui.el ends here
617 |
--------------------------------------------------------------------------------
/sfs.el:
--------------------------------------------------------------------------------
1 | ;;; sfs.el --- SFS - Search File-System -*- lexical-binding: t; -*-
2 |
3 | ;; Copyright (C) 2020 Sam
4 |
5 | ;; Author: Sam
6 | ;; Keywords: tools, files
7 |
8 | ;; This program is free software; you can redistribute it and/or modify
9 | ;; it under the terms of the GNU General Public License as published by
10 | ;; the Free Software Foundation, either version 3 of the License, or
11 | ;; (at your option) any later version.
12 |
13 | ;; This program is distributed in the hope that it will be useful,
14 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | ;; GNU General Public License for more details.
17 |
18 | ;; You should have received a copy of the GNU General Public License
19 | ;; along with this program. If not, see .
20 |
21 | ;;; Commentary:
22 |
23 |
24 | ;;; Code:
25 |
26 | (require 'sfs-reindex)
27 | (require 'sfs-recoll)
28 | (require 'sfs-tag)
29 | (require 'sfs-tui)
30 |
31 | (defvar sfs--initialized-p nil)
32 |
33 | (defun sfs--init ()
34 | "Starts the SFS services if necessary."
35 | (when (not sfs--initialized-p)
36 | (let ((service-filename
37 | (concat (file-name-directory (file-name-directory (find-library-name "sfs"))) "service.py")))
38 | (if (file-exists-p service-filename)
39 | (start-process
40 | "recoll-server"
41 | "*recoll-server*"
42 | "python3"
43 | service-filename)
44 | (message "SFS: Couldn't find service.py...")))
45 | (setq sfs--initialized-p t)
46 | (add-hook 'kill-emacs-hook #'sfs--shutdown)))
47 |
48 | (defun sfs--shutdown ()
49 | "Shuts down SFS services when necessary."
50 | (when sfs--initialized-p
51 | (kill-process "recoll-server")
52 | (setq sfs--initialized-p nil)))
53 |
54 | (define-minor-mode global-sfs-mode
55 | "Toggle global SFS minor mode.
56 |
57 | Interactively with no argument, this command toggles the mode.
58 | A positive prefix argument enables the mode, any other prefix
59 | argument disables it. From Lisp, argument omitted or nil enables
60 | the mode, `toggle' toggles the state.
61 |
62 | When enabled, SFS initializes a python server responsible for
63 | dispatching queries from elisp over dbus, and returning search results."
64 | :init-value nil
65 | :lighter " SFS"
66 | :global t
67 | (if global-sfs-mode
68 | (sfs--init)
69 | (sfs--shutdown)))
70 |
71 | (provide 'sfs)
72 | ;;; sfs.el ends here
73 |
--------------------------------------------------------------------------------