├── .gitignore
├── Eldev
├── LICENSE
├── README.org
├── lister-mode.el
├── lister-tests.el
└── lister.el
/.gitignore:
--------------------------------------------------------------------------------
1 | /konzeptblatt.org
2 | /*.elc
3 | /konzeptblatt.org_archive
4 | /lister-interactive-playground.el
5 | /.dir-locals.el
6 | /.eldev
7 | /Eldev-local
8 | /archive/
9 |
--------------------------------------------------------------------------------
/Eldev:
--------------------------------------------------------------------------------
1 | ; -*- mode: emacs-lisp; lexical-binding: t; -*-
2 | ;;
3 | ;; This file currently does nothing. It's only there to be detected
4 | ;; projectile.
5 | ;;
6 |
--------------------------------------------------------------------------------
/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.org:
--------------------------------------------------------------------------------
1 | * Lister - Yet another List Printer
2 |
3 | [[https://melpa.org/#/lister][file:https://melpa.org/packages/lister-badge.svg]]
4 |
5 | # NOTE: Do not forget to update the release in PROJECT STATUS and
6 | # CHANGELOG!
7 | This is the documentation for =Lister= version =0.9.6=
8 |
9 | Lister= is a library for creating interactive lists of any kind. In
10 | contrast to similar packages like =hierarchy.el= or =tablist.el=, it aims
11 | at /not/ simply mapping a data structure to a navigatable list. Rather,
12 | it treats the list buffer like Emacs treats text buffers: It is an
13 | empty space to which you successively add stuff. So =Lister= should
14 | actually be called =Listed=.
15 |
16 | One advantage of this approach is that you don't have to know in
17 | advance the structure of your data. You just "insert" a new slice on
18 | the fly when you need it. Another advantage is that you do not need to
19 | keep a separate copy of the list and worry about syncing: The buffer
20 | is the whole source of truth. Thus =Lister= recommends itself in all
21 | cases where it makes sense to collect, modify, thin out, graft, sort
22 | or otherwise edit lists from various sources.
23 |
24 | * Contents :noexport:
25 | :PROPERTIES:
26 | :TOC: :include siblings
27 | :END:
28 |
29 | :CONTENTS:
30 | - [[#project-status][Project status]]
31 | - [[#feature-overview][Feature overview]]
32 | - [[#example][Example]]
33 | - [[#design-principle][Design principle]]
34 | - [[#what-does-lister-offer][What does Lister offer?]]
35 | - [[#some-core-concepts][Some core concepts:]]
36 | - [[#bumps-and-wrinkles][Bumps and Wrinkles]]
37 | - [[#api][API]]
38 | - [[#setting-up-the-buffer][Setting up the buffer]]
39 | - [[#the-mapper-function][The mapper function]]
40 | - [[#lister-mode-minor-mode][Lister Mode (minor mode)]]
41 | - [[#inserting-adding-deleting-or-replacing-single-items][Inserting, adding, deleting or replacing single items]]
42 | - [[#inserting-adding-deleting-or-replacing-lists-of-items][Inserting, adding, deleting or replacing lists of items]]
43 | - [[#getting-the-list-data][Getting the list data]]
44 | - [[#normalizing-boundaries][Normalizing boundaries]]
45 | - [[#basic-sublist-handling][Basic sublist handling]]
46 | - [[#marking][Marking]]
47 | - [[#sorting][Sorting]]
48 | - [[#filter][Filter]]
49 | - [[#outline][Outline]]
50 | - [[#finding-nodes][Finding nodes]]
51 | - [[#looping][Looping]]
52 | - [[#interactive-editing][Interactive editing]]
53 | - [[#modified-flag][Modified flag]]
54 | - [[#miscellaneous][Miscellaneous]]
55 | - [[#changelog][Changelog]]
56 | - [[#current][Current]]
57 | - [[#094][0.9.4]]
58 | - [[#093][0.9.3.]]
59 | - [[#092][0.9.2]]
60 | - [[#091][0.9.1]]
61 | - [[#09][0.9]]
62 | :END:
63 |
64 | * Project status
65 |
66 | Current release is =0.9.6=
67 |
68 | * Feature overview
69 |
70 | This is an overview of features done or planned. A feature is
71 | considered =stable= if it is used and tested by the auther. If it is
72 | rarely used, but seems to work, it just =works=.
73 |
74 | | Feature | State | Automated tests? |
75 | |--------------------------------------+-----------------+------------------|
76 | | build simple or large lists | stable | yes |
77 | | build nested lists | stable | yes |
78 | | retrieve data, with hierarchies | stable | yes |
79 | | loop over the list | stable | yes |
80 | | marking or unmarking items | stable | yes |
81 | | filter items | stable | yes |
82 | | hide and show sublists outline-style | partially buggy | not enough |
83 | | move items and sublists | works | yes |
84 | | navigate within the hierarchy | works | yes |
85 | |--------------------------------------+-----------------+------------------|
86 |
87 | * Example
88 |
89 | This piece of code creates a new buffer which displays lists of
90 | strings.
91 |
92 | #+begin_src emacs-lisp
93 | (let ((ewoc (lister-setup "BUFFERNAME" #'list)))
94 | ;; insert 4 items:
95 | (lister-set-list ewoc '("ITEM1" "ITEM2" "ITEM3" "ITEM4"))
96 | ;; add further items:
97 | (lister-add-list ewoc '("ITEM5" "ITEM6"))
98 | ;; add sublist:
99 | (lister-insert-sublist-below ewoc :first '("SUBITEM1" "SUBITEM2"))
100 | ;; move point:
101 | (lister-goto ewoc :first)
102 | (lister-goto ewoc :next)
103 | ;; get item data:
104 | (lister-get-data-at ewoc :point) ;; => "SUBITEM1"
105 | ;; get sublist at point:
106 | (lister-get-sublist-at ewoc :point) ;; => ("SUBITEM1" "SUBITEM2")
107 | ;; prepend "X" to each item:
108 | (lister-dolist (ewoc data :first :last node)
109 | (lister-replace-at ewoc node (concat "X" data)))
110 | ;; alternative, more functional way:
111 | (lister-update-list ewoc (lambda (data) (concat "X" data)))
112 | ;; filter every item containing the digit 1:
113 | (let ((filter (apply-partially #'string-match "1")))
114 | (lister-set-filter ewoc filter))
115 | ;; only get visible items:
116 | (lister-get-visible-list ewoc)
117 | ;; => (("XXSUBITEM2") "XXITEM2" "XXITEM3" "XXITEM4" "XXITEM5" "XXITEM6")
118 | ;; remove filter:
119 | (lister-set-filter ewoc nil)
120 | ;; collect the list values as a flat list:
121 | (lister-collect-list ewoc)
122 | ;; => ("XXITEM1" "XXSUBITEM1" "XXSUBITEM2" "XXITEM2"....)
123 | ;; get the data as a nested list:
124 | (lister-get-list ewoc)) ;; => ("XXITEM1" ("XXSUBITEM1" "XXSUBITEM2") "XXITEM2" ....)
125 | #+end_src
126 |
127 | * Design principle
128 |
129 | =Lister= is based on the internal library =Ewoc.el=. Have a look at its
130 | info pages. The core idea is that we keep a double linked list which
131 | is "viewed" in the buffer, so that each change in the list will be
132 | reflected in the buffer using a function which pretty prints the data
133 | (model-view-controller pattern). =Lister= provides convenience functions
134 | on top of this core principle of =Ewoc.el= (and also corrects some of
135 | its bugs). A list item thus is basically a data item which is turned
136 | into a printable representation with a /mapper function/.
137 |
138 | ** What does Lister offer?
139 |
140 | - Structured API to add, insert, delete or replace lists or list
141 | items. All positions can be indicated by passing either the
142 | containing =Ewoc= node, a zero-counting index position, or one of the
143 | symbols =:first=, =:last=, =:next=, =:prev=, =:point=.
144 | - Functions to return the next list item matching a predicate.
145 | - Macros to loop over the lists, or a part of it, and to deal safely
146 | with parts of the list ("regions"). The looping macros mimic the
147 | =cl-dolist= syntax; e.g. you can use =(lister-dolist (data :first
148 | :last) ..BODY..)= to loop over the whole list.
149 | - Functions to collect data which matches a predicate; and functions
150 | which can be used to do something with items ("updating" them).
151 | - Sublist handling: Recognize, insert, delete, replace, reverse or
152 | sort a sublist.
153 | - Visually filter items according to a predicate; offer some of the
154 | functionality above limited to visible items only.
155 | - Built-in functionality to mark items.
156 |
157 | ** Some core concepts:
158 |
159 | - *Mapper function*: A buffer local function which turns a data item (a
160 | non-list lisp object) into a list of strings which will then be
161 | inserted in the buffer as its representation.
162 | - *Hierarchy by indentation*: Nested list hierarchies are built by
163 | visually indenting list items. Each item with the same indentation
164 | level belongs to the same nesting level. A sublist is thus defined
165 | by having an item with an indentation level greater than the one of
166 | its predecessor.
167 | - *Data items cannot be lists*: Since nested lists are recognized by
168 | simply being lists (=consp=), it is /not possible to store lists as
169 | data items/! If you need to store more complex data, use a vector or
170 | a =defstruct= instead.
171 | - *No major mode*: To use a buffer with lister, call =lister-setup=
172 | first. It prepares the buffer by setting some variables and erasing
173 | its content. It does not, however, set a specific major mode.
174 | - *Keep common navigation keys*: Each item is printed with the text
175 | property =intangible= set so that the user can only move point to the
176 | very first character of the printed item. You can thus use all
177 | basic navigation commands without any further ado, including
178 | =isearch=. You do not need to define any navigation commands.
179 | - *Data, items and nodes*: What is visually presented as a list item
180 | has three levels of structure: The =Ewoc= node, the =Lister= specific
181 | =lister--item= and the actual list data. This might cause some
182 | confusion, so here's a short explanation: First, each visual list
183 | item corresponds to an =Ewoc= node. This node becomes relevant for
184 | all generic list functions, such as "looping over the list" or
185 | "deleting a specific region". Secondly, each node contains a
186 | structure called =lister--item=. That structure keeps track of list
187 | specific information such as the indentation level or whether the
188 | item is visible. Finally, there is the actual data which is mapped
189 | and printed. This data is also a part of that =Lister= item structure
190 | which is stored in each node, but is treated distinctly since
191 | accessing it is the purpose of the whole library. To avoid semantic
192 | confusion, all functions applying to the node have a "node"
193 | somewhere in their function name. All other public functions
194 | usually refer to the data. To access the =lister--item=, you can use
195 | =(ewoc-data node)=.
196 |
197 | ** Bumps and Wrinkles
198 |
199 | - =Lister= operations become slower when the list grows above a
200 | thousand items. I would love to optimize it more for bigger lists
201 | once this becomes a real need.
202 |
203 | * Navigation and Marking with Lister Mode (minor mode)
204 |
205 | There is a minor mode shipped with the package which provides some
206 | basic keybindings. Here's the keymap:
207 |
208 | | Key | Function |
209 | |---------------------+-----------------------------------------------------------------------|
210 | | m | Mark item at point, or active region, or sublist if prefixed |
211 | | u | Unmark item at point, or active region, or sublist if prefixed |
212 | | U | Unmark all items in the buffer |
213 | | M-up, M-down | Move item at point one up, or down (prefix lifts level restriction) |
214 | | M-left, M-right | Indent or unindent the item at point (prefix lifts level restriction) |
215 | | S-M-up, S-M-down | Move sublist at point one up, down |
216 | | S-M-right, S-M-left | Indent or unindent sublist at point |
217 | | | Cycle outline visibility of sublist below point |
218 | | C-c C-b / C-c C-f | Move forward or backward to next node with same level |
219 | | C-c C-u | Move to the next parent node |
220 | | M-< / M-> | Move to the beginning or end of the current sublist or list. |
221 | | C-c | Move up to the next child node |
222 | | C-c | Move down to the next child node |
223 | |---------------------+-----------------------------------------------------------------------|
224 |
225 | The commands to mark and unmark also recognize the region. So you can
226 | mark the whole list by pressing =C-x h m=.
227 |
228 | All navigation commands push point on mark if they jump more than one
229 | step.
230 |
231 | If the keys =M-<= and =M->= are pressed repeatedly, move out of the
232 | sublist to the next outer level list and finally to the top or bottom
233 | item.
234 |
235 | * API
236 | ** Setting up the buffer
237 |
238 | #+begin_src emacs-lisp
239 | (lister-setup buf-or-name mapper &optional header footer)
240 | #+end_src
241 |
242 | You have to initialize a buffer in order to use it with =Lister=. The
243 | function =lister-setup= will either create a buffer with the given name,
244 | or erase the contents of an existing buffer. It then prepares the
245 | buffer by adding some text properties and setting some buffer local
246 | variables.
247 |
248 | In addition to defining the buffer and the mapper function, you can
249 | optionally define a =header= or a =footer=. That can be either a string,
250 | or a list of strings, or a zero-argument function which, called in the
251 | Ewoc buffer, returns a string or a list of strings. The strings will
252 | be inserted before or after the actual list.
253 |
254 | Use =lister-set-{header/footer}= to change the header or the footer.
255 | Pass the value =nil= to delete them. If the header or footer is defined
256 | by a function, use =lister-refresh-header-footer= to force a redisplay.
257 | To access the currently installed =header= or =footer=, use the =Ewoc=
258 | function =ewoc-get-hf=.
259 |
260 | =Lister-setup= returns an ewoc object, which is then used as the basic
261 | reference for all =Lister= operations. The ewoc object is also stored in
262 | the buffer local variable =lister-local-ewoc=, which can be retreived
263 | with =lister-get-ewoc=.
264 |
265 | The buffer local variable can be used to access the ewoc in an
266 | interactive function, like this:
267 |
268 | #+begin_src emacs-lisp
269 | (defun do-something (ewoc pos)
270 | "Do something at point."
271 | (interactive (list lister-local-ewoc :point))
272 | (when-let ((node (lister-get-node-at ewoc pos)))
273 | (message "You want to do something with %s."
274 | (lister-node-get-data node))))
275 | #+end_src
276 |
277 | See also =lister-mode.el= for some exemplary interactive functions and
278 | for a macro which helps to define them.
279 |
280 | ** The mapper function
281 | The mapper function is called for each item. It must return a list of
282 | strings representing the item.
283 |
284 | Per default, the strings are inserted with the property =intangible=. If
285 | you want to insert special fields which can also do something, e.g.
286 | editable fields, you can set the =field= property to =t=. The region
287 | marked by this continuous property will /not/ be intangible, that is,
288 | the cursor can move to it. Since one very likely use case of that
289 | feature is to insert =buttons=, the same rule applies to all characters
290 | which are marked with the property =button=.
291 |
292 | Example:
293 |
294 | #+begin_src emacs-lisp
295 | (defun my-get-button (label &rest properties)
296 | "Make a button LABEL in a temporary buffer and return it as a string.
297 | Pass PROPERTIES to `insert-text-button', which creates the
298 | button."
299 | (with-temp-buffer
300 | (apply #'insert-text-button label properties)
301 | (buffer-string)))
302 |
303 | (defun my-action (_)
304 | (message "I have been clicked!"))
305 |
306 | (let ((ewoc (lister-setup "NEW "#'list)))
307 | (lister-set-list ewoc (list "Intangible item"
308 | "Intangible item"
309 | (my-get-button "Click me!"
310 | 'action 'my-action)))
311 | (switch-to-buffer (ewoc-buffer ewoc)))
312 | #+end_src
313 |
314 | ** Inserting, adding, deleting or replacing single items
315 |
316 | #+begin_src emacs-lisp
317 | ;; Insert a single item at POS:
318 | (lister-insert-at ewoc pos data &optional level insert-after)
319 | ;; Add to the end of the list:
320 | (lister-add ewoc data &optional level)
321 | ;; Replace the item at POS:
322 | (lister-replace-at ewoc pos data)
323 | ;; Delete the item at POS:
324 | (lister-delete-at ewoc pos)
325 | #+end_src
326 |
327 | Per default, all =insert= operations insert /at/ the position indicated,
328 | moving the previous content down. This might result in unintuitive
329 | results, e.g. (=lister-insert-at ewoc :last data)= adds the item at the
330 | second last position. Set =insert-after= to a non-nil value to insert
331 | /after/ the position indicated (or use =lister-add=).
332 |
333 | The same principle applies to interactive function which insert lists.
334 | If the cursor is at the bottom of the list, the intended meaning of
335 | "insert at point" is actually "add to the end of list". The end of
336 | list can be recognized with the function =(lister-eolp)=, so that the
337 | following code works:
338 |
339 | #+begin_src emacs-lisp
340 | (defun insert-something-at-point ()
341 | (interactive)
342 | (lister-insert-at lister-local-ewoc
343 | :point
344 | some-data
345 | nil
346 | ;; t means: add, don't insert!
347 | (lister-eolp)))
348 | #+end_src
349 |
350 | Argument =POS= can be either an =Ewoc= node, an integer position, or one
351 | of the symbols =:first=, =:last=, =:next=, =:prev=, or =:point=.
352 |
353 | The integer argument =level= determines the indentation level and can be
354 | used to begin a new sublist. Note that =Lister= automatically corrects
355 | too big values in order to ensure that every new level is just one
356 | level away from the item at =POS=. Thus you can safely use
357 | =(lister-insert-at ewoc pos data 999)= in order to begin a new sublist.
358 |
359 | ** Inserting, adding, deleting or replacing lists of items
360 |
361 | #+begin_src emacs-lisp
362 | ;; Erase all previous content and set a new list:
363 | (lister-set-list ewoc data-list)
364 | ;; Insert a list at POS:
365 | (lister-insert-list ewoc pos data-list &optional level insert-after)
366 | ;; Add a list to the end of the EWOC:
367 | (lister-add-list ewoc data-list &optional level)
368 | ;; Replace the items from BEG to END with a new (possibly longer or shorter) list:
369 | (lister-replace-list ewoc data-list beg end &optional level)
370 | ;; Delete all items from BEG to END:
371 | (lister-delete-list ewoc beg end)
372 | (lister-delete-all ewoc)
373 | #+end_src
374 |
375 | Argument =POS= can be either an =Ewoc= node, an integer position, or one
376 | of the symbols =:first=, =:last=, =:next=, =:prev=, or =:point=.
377 |
378 | The integer argument =level= determines the indentation level and can be
379 | used to begin a new sublist. Note that =Lister= automatically corrects
380 | too big values in order to ensure that every new level is just one
381 | level away from the item at =POS=. Thus you can safely use
382 | =(lister-insert-list ewoc pos data-list 999)= in order to insert a whole
383 | sublist.
384 |
385 | ** Getting the list data
386 |
387 | #+begin_src emacs-lisp
388 | ;; Return the data of a single item:
389 | (lister-get-data-at ewoc pos)
390 | ;; Return the data as a list (with sublists as nested lists):
391 | (lister-get-list ewoc &optional beg end start-level pred)
392 | ;; Get the sublist at or below POS:
393 | (lister-get-sublist-at ewoc pos)
394 | (lister-get-sublist-below ewoc pos)
395 | ;; Map the data of a list (as a tree):
396 | ;; Node that PRED-FN and FN applies to the item data
397 | (lister-map ewoc fn &optional pred-fn beg end start-level))
398 | #+end_src
399 |
400 | All functions (except =lister-get-data=, of course) return a list of
401 | data. Per default, they return the whole list. If there is a sublist
402 | in the specified region, return it as a nested list, e.g. =("A" ("SUB1"
403 | "SUB2") "B"))=. Multiple levels of indentation lead to multiply nested
404 | lists: =("A" (("SUBSUB1" "SUBSUB2")) "B")=.
405 |
406 | Arguments =POS=, =BEG= and =END= can be either an =Ewoc= node, an integer
407 | position, or one of the symbols =:first=, =:last=, =:next=, =:prev=, or
408 | =:point=.
409 |
410 | All of these functions ignore any active filter.
411 |
412 | ** Normalizing boundaries
413 |
414 | Since it is often necessary to operate on a sublist or the whole list,
415 | we have a macro to normalize these boundaries:
416 |
417 | #+begin_src emacs-lisp
418 | (lister-with-boundaries ewoc beg-var end-var
419 | ...BODY..)
420 | #+end_src
421 |
422 | This macro binds BEG-VAR and END-VAR according to the following
423 | scheme:
424 |
425 | If the variables are already bound, use its value to determine the
426 | position. Then these variables are interpreted as a normal position.
427 | Allowed values are an =Ewoc= node, an integer position, or one of the
428 | symbols =:first=, =:last=, =:point=, =:next= or =:prev=. If the variables are
429 | undefined, bind them to the first and the last node of the list,
430 | respectively.
431 |
432 | In short, if you use this macro in a function with the arguments =BEG=
433 | and =END=, and you can profit from automatic parsing these arguments and
434 | also be sure that while in =BODY=, =BEG= and =END= always have a valid
435 | value:
436 |
437 | #+begin_src emacs-lisp
438 | (defun a-function (ewoc beg end)
439 | "Do something within BEG and END. Both arguments can be a node,
440 | an integer position, or one of the symbols `:point', `:first',
441 | `:last', `:next' or `:prev'."
442 | (lister-with-boundaries ewoc beg end
443 | (do-something-with-node beg)))
444 | #+end_src
445 |
446 | All looping macros also normalize the region in the same way (see
447 | below).
448 |
449 | ** Basic sublist handling
450 |
451 | #+begin_src emacs-lisp
452 | ;; Doing something with a sublist below POS:
453 | (lister-insert-sublist-below ewoc pos l)
454 | (lister-delete-sublist-below ewoc pos l)
455 | (lister-replace-sublist-below ewoc pos l)
456 | ;; Doing something with the sublist at POS:
457 | (lister-delete-sublist-at ewoc pos l)
458 | (lister-replace-sublist-at ewoc pos l)
459 | ;; Check if there is a sublist:
460 | (lister-sublist-below-p ewoc pos)
461 | (lister-sublist-at-p ewoc pos)
462 | ;;; Helpful macros:
463 | ;;
464 | ;; Execute BODY with the symbols BEG-SYM and END-SYM bound to the
465 | ;; boundaries of the sublist at POS. Do nothing if there is no
466 | ;; sublist.
467 | (lister-with-sublist-at ewoc pos beg-sym end-sym
468 | ....BODY...)
469 | ;; same as above, but looking for a sublist below POS:
470 | (lister-with-sublist-below ewoc pos beg-sym end-sym
471 | ....BODY...)
472 | #+end_src
473 |
474 | Argument =POS= can be either an =Ewoc= node, an integer position, or one
475 | of the symbols =:first=, =:last=, =:next=, =:prev=, or =:point=.
476 |
477 | ** Marking
478 |
479 | #+begin_src emacs-lisp
480 | ;; All marked items are highlighted by addding the value of that variable:
481 | lister-mark-face-or-property
482 | ;; Check if there are marked items:
483 | (lister-marked-at-p ewoc pos)
484 | (lister-items-marked-p ewoc &optional beg end)
485 | (lister-count-marked-items ewoc &optional beg end)
486 | ;; Mark or unmark the item at POS:
487 | (lister-mark-unmark-at ewoc pos state)
488 | ;; Set a limiting predicate:
489 | (lister-set-marking-predicate ewoc pred)
490 | ;; Mark or unmark a whole list:
491 | (lister-mark-unmark-list ewoc beg end state)
492 | (lister-mark-unmark-sublist-at ewoc pos state)
493 | (lister-mark-unmark-sublist-below ewoc pos state)
494 | ;; Get data of only the marked items:
495 | (lister-get-marked-list ewoc &optional beg end pred-fn flatten?)
496 | ;; Do something with all marked nodes or items:
497 | (lister-walk-marked-nodes ewoc action-fn &optional beg end marker-pred-fn)
498 | (lister-walk-marked-list ewoc action-fn &optional beg end marker-pred-fn)
499 | #+end_src
500 |
501 | If =STATE= is nil, mark the item or the specified list items; else
502 | unmark them. Optionally set a buffer-local marking predicate using
503 | =lister-set-marking-predicate=. If this predicate is set, only mark
504 | items which satisfy it. Setting a new predicate will unmark alreay
505 | marked items which will not match it.
506 |
507 | Note that in the case of walking nodes, =ACTION-FN= requires /two/
508 | arguments: the ewoc object and the node. The reason behind this is
509 | that if you choose do to something with the node rather with the data,
510 | it is very likely you will need the ewoc object.
511 |
512 | Arguments =POS=, =BEG= and =END= can be either an =Ewoc= node, an integer
513 | position, or one of the symbols =:first=, =:last=, =:next=, =:prev=, or
514 | =:point=.
515 |
516 | ** Sorting
517 |
518 | #+begin_src emacs-lisp
519 | ;; Reverse the list items between BEG and END, or the whole list:
520 | (lister-reverse-list ewoc &optional beg end)
521 | ;; Sort the list according to sorting predicate PRED:
522 | (lister-sort-list ewoc pred &optional beg end)
523 | ;; Sort the list according to mulitple predicates in a row:
524 | (lister-sort-list ewoc (list #'comp1 #'comp2) &optional beg end)
525 | ;; The same with sublists:
526 | (lister-sort-sublist-at ewoc pos pred)
527 | (lister-sort-sublist-below ewoc pos pred)
528 | ;; Reorder sublists using any kind of predicate:
529 | (lister-reorder-sublist-at ewoc pos)
530 | (lister-reorder-sublist-below ewoc pos)
531 | ;; Note that "reordering" uses a more complicate predicate function
532 | ;; than simple sorting. See the documentation of
533 | ;; `lister--reorder-wrapped-list' for a more detailed explanation.
534 | #+end_src
535 |
536 | Sorting or reversing a list keeps the individual mark state. Arguments
537 | =POS=, =BEG= and =END= can be either an =Ewoc= node, an integer position, or
538 | one of the symbols =:first=, =:last=, =:next=, =:prev=, or =:point=.
539 |
540 | You can either pass a single comparator to the sorting function (such
541 | as =string>= or a list of comparators, which then will be applied
542 | successively (reduction). This is useful for sorting according to
543 | multiple criteria (e.g. first the name, then within the same name,
544 | ranking by the income, etc.).
545 |
546 | A comparator function has direct access to the list data. So if you
547 | use a more complex data structure, do not forget to operate on the
548 | actual criteria and not on the containing object. E.g.:
549 |
550 | #+begin_src emacs-lisp
551 | (defstruct list-data name income)
552 | (defun sort-it (ewoc)
553 | (cl-labels ((name> (a b) (string> (list-data-name a)
554 | (list-data-name b)))
555 | (income> (a b) (> (list-data-income a)
556 | (list-data-income b))))
557 | (lister-sort-list ewoc (list #'name> #'income>))))
558 | ;; if you use the library dash.el:
559 | (defun sort-it (ewoc)
560 | (lister-sort-list ewoc (list (-on #'string> #'list-data-name)
561 | (-on #'> #'list-data-income))))
562 | #+end_src
563 |
564 | ** Filter
565 |
566 | #+begin_src emacs-lisp
567 | ;; Set and activate a filter predicate:
568 | (lister-set-filter ewoc pred)
569 | ;; Check if filter is active:
570 | (lister-filter-active-p ewoc)
571 | ;; Predicates:
572 | (lister-node-visible-p)
573 | (lister-node-marked-and-visible-p)
574 | ;; Return the filtered ('visible') list:
575 | (lister-get-visible-list ewoc &optional beg end start-level)
576 | ;; Find 'visible' nodes matching a predicate:
577 | (lister-next-visible-matching ewoc pos pred)
578 | (lister-prev-visible-matching ewoc pos pred)
579 | ;; Return only data currently visible:
580 | (lister-get-visible-list ewoc &optional beg end start-level)
581 | #+end_src
582 |
583 | The filter predicate =PRED= is a function which receives the list item's
584 | data as its sole argument. The item is hidden if =PRED= returns a
585 | non-nil value (if it "matches" =PRED=).
586 |
587 | Arguments =POS=, =BEG= and =END= can be either an =Ewoc= node, an integer
588 | position, or one of the symbols =:first=, =:last=, =:next=, =:prev=, or
589 | =:point=.
590 |
591 | ** Outline
592 |
593 | You can hide or show sublists as an outline:
594 |
595 | #+begin_src emacs-lisp
596 | ;; Hide the sublist below POS as an outline:
597 | (lister-outline-hide-sublist-below ewoc pos)
598 | ;; Show it:
599 | (lister-outline-show-sublist-below ewoc pos)
600 | ;; Cycle it:
601 | (lister-outline-cycle-sublist-below ewoc pos)
602 | ;; Show all hidden outlines:
603 | (lister-outline-show-all ewoc)
604 | #+end_src
605 |
606 | Arguments =POS=, =BEG= and =END= can be either an =Ewoc= node, an integer
607 | position, or one of the symbols =:first=, =:last=, =:next=, =:prev=, or
608 | =:point=.
609 |
610 | ** Finding nodes
611 |
612 | #+begin_src emacs-lisp
613 | ;; From POS, find the next or prev node where the data matches PRED:
614 | (lister-next-matching ewoc pos pred &optional limit)
615 | (lister-prev-matching ewoc pos pred &optional limit)
616 | ;; same as above, but only consider visible items:
617 | (lister-next-visible-matching pos pred &optional limit)
618 | (lister-prev-visible-matching pos pred &optional limit)
619 | ;; Find the first or last node of the sublist around POS:
620 | (lister-top-sublist-node ewoc pos)
621 | (lister-bottom-sublist-node ewoc pos)
622 | ;; Find the parent of the sublist around POS:
623 | (lister-parent-node ewoc pos)
624 | ;; Find the first sublist node looking in DIRECTION from POS:
625 | (lister-first-sublist-node ewoc pos direction)
626 | #+end_src
627 |
628 | Argument =POS= can be either an =Ewoc= node, an integer position, or one
629 | of the symbols =:first=, =:last=, =:next=, =:prev=, or =:point=.
630 |
631 | Argument =limit= is a position (a node, an index value or one of the
632 | symbols =:first=, =:last=, =:point=, =:next= or =:prev=, which limits the search. The
633 | search stops when reaching the limit and returns nil, even if the node
634 | at =limit= matches =pred-fn=.
635 |
636 | Note that the generic searching functions (which require a predicate
637 | function) ignore visibility status, whereas the sublist functions
638 | listed in this section don't return invisible items. Other sublist
639 | functions, however, might not check for visibility.
640 |
641 | ** Looping
642 |
643 | Most generally, you can access nodes or data items within the body of
644 | a looping macro or using a function. Most looping facilities come in
645 | two flavors, marked by the last word of the function name. Functions
646 | ending with =-list= loop over the item data (that which is printed);
647 | functions ending with =-nodes= loop over the item node (the =lister--item=
648 | structure in which the data is stored). As a rule of thumb, you should
649 | use =-list= functions if you are just concerned with the data, and
650 | =-nodes= functions if you need to explicitly know if a node is marked or
651 | invisible.
652 |
653 | Basic macros, imperative style:
654 |
655 | #+begin_src emacs-lisp
656 | ;; Basic macro to loop over NODES (not items!)
657 | (lister-dolist-nodes (ewoc var-name &optional beg end))
658 | ;; same with items:
659 | (lister-dolist (ewoc var-name &optional beg end node-var-name))
660 | ;;; Examples:
661 | ;; Delete the whole list:
662 | (lister-dolist-nodes (ewoc node :first :last)
663 | (lister-delete-at ewoc node))
664 | ;; Return t if one list item matches X:
665 | (lister-dolist (ewoc data)
666 | (when (equal data x)
667 | (cl-return t)))
668 | #+end_src
669 |
670 | The body of the loop macros are all wrappend in an implicit =cl-block=.
671 | To quit the loop immediately, use =(cl-return)=.
672 |
673 | More specific functions, more functional style:
674 |
675 | #+begin_src emacs-lisp
676 | ;; Collect and maybe map all items between BEG and END:
677 | (lister-collect-list ewoc &optional beg end pred-fn map-fn)
678 | ;; same with nodes:
679 | (lister-collect-nodes ewoc &optional beg end pred-fn map-fn)
680 | ;; Modifiy the data and redisplay it:
681 | (lister-update-list ewoc action-fn &optional beg end pred-fn)
682 | ;; Do something with each node (not item):
683 | (lister-walk-nodes ewoc action-fn &optional beg end pred-fn)
684 | ;; see also (documented somewhere else in that file):
685 | ;; - lister-walk-marked-{list/nodes} for looping over all marked items
686 | ;; - lister-map for mapping
687 | #+end_src
688 |
689 | All functions operate on the items specified by =BEG= and =END= or on the
690 | whole list. Optionally operation can be restricted to those items
691 | matching =PRED-FN=.
692 |
693 | Note that in the case of =lister-collect-list= and =lister-update-list=,
694 | =PRED-FN= is called with the item's data (that which is printed), while
695 | =lister-collect-nodes= and =lister-walk-nodes= operate on the /complete
696 | node/. In the latter case, =PRED-FN= is called with the complete
697 | =lister--item= object, the printed data being only one slot of that
698 | encompassing structure.
699 |
700 | When collecting stuff, =map-fn= can be used to further transform the
701 | data item.
702 |
703 | When updating a list, =action-fn= receives a data object. If it returns
704 | =nil=, it leaves the corresponding item unchanged, else it updates its
705 | value with the new value and redisplays the node.
706 |
707 | Note that in the case of walking nodes, =ACTION-FN= requires /two/
708 | arguments: the ewoc object and the node. The reason behind this is
709 | that if you choose do to something with the node rather with the data,
710 | it is very likely you will need the ewoc object.
711 |
712 | Arguments =BEG= and =END= can be either an =Ewoc= node, an integer position,
713 | or one of the symbols =:first=, =:last=, =:next=, =:prev=, or =:point=.
714 |
715 | ** Interactive editing
716 |
717 | #+begin_src emacs-lisp
718 | ;; Move items vertically. Per default, only move to
719 | ;; items with the same indentation level:
720 | (lister-move-item-up ewoc pos &optional ignore-level)
721 | (lister-move-item-down ewoc pos &optional ignore-level)
722 | ;; Move items horizontally:
723 | (lister-move-item-right ewoc pos)
724 | (lister-move-item-left ewoc pos)
725 | ;; Move sublists:
726 | (lister-move-sublist-up ewoc pos)
727 | (lister-move-sublist-down ewoc pos)
728 | #+end_src
729 |
730 | Argument =POS= can be either an =Ewoc= node, an integer position, or one
731 | of the symbols =:first=, =:last=, =:next=, =:prev=, or =:point=.
732 |
733 | ** Modified flag
734 | Since =Lister= is intended to offer editing facilities, there's also a
735 | modified flag. It is stored in the buffer local variable
736 | =lister-local-modified=.
737 |
738 | The modified flag will be set to =t= each time an item is deleted,
739 | inserted, or its content is changed. Since moving also internally
740 | works with deleting and inserting, it will also trigger the modified
741 | flag.
742 |
743 | #+begin_src emacs-lisp
744 | ;; Buffer local modified flag
745 | lister-local-modified
746 | ;; Get the value of the modified flag
747 | (lister-modified-p ewoc)
748 | ;; Set the value
749 | (lister-set-modified-p ewoc &optional flag)
750 | #+end_src
751 |
752 | It is recommended to add a variable watcher to display the modified
753 | flag (e.g. in the header of the list or in the modeline).
754 |
755 | ** Miscellaneous
756 |
757 | #+begin_src emacs-lisp
758 | ;; Check if the list is empty:
759 | (lister-empty-p ewoc)
760 | ;; Check if a node is part of the list from beg to end:
761 | (lister-node-in-region-p node beg end)
762 | ;; Move point:
763 | (lister-goto ewoc pos)
764 | ;; Manually re-set the level of an item:
765 | (lister-set-level-at ewoc pos)
766 | (lister-get-level-at ewoc pos)
767 | ;; Redisplay an item (e.g. if its data has changed):
768 | (lister-refresh-at ewoc pos)
769 | (lister-refresh-list ewoc beg end)
770 | ;; Retain position when updating display: Execute BODY, then return
771 | ;; to the node at point before BODY. Useful when updating the
772 | ;; display, and the items change (because this moves the cursor)
773 | (lister-save-current-node BODY)
774 | #+end_src
775 |
776 | Arguments =POS=, =BEG= and =END= can be either an =Ewoc= node, an integer
777 | position, or one of the symbols =:first=, =:last=, =:next=, =:prev=, or
778 | =:point=.
779 |
780 | Padding and indentation of the levels is regulated by the following
781 | variables:
782 | #+begin_src emacs-lisp
783 | ;; integer: add so many whitespaces in front of each item
784 | lister-local-left-margin
785 | ;; string: add this string in front of each item according to the item's level
786 | ;; level 0 means no padding; level 1 means one time; 2 means 2 time, etc.
787 | lister-local-padding-string
788 | #+end_src
789 | * Known Bugs and Limitations
790 |
791 | ** Outline Visibility Cycling
792 |
793 | Current visibility cycling uses the =invisibility-spec= and is not
794 | recognized internally by the =lister= commands. So while hiding an item
795 | using the filter function is mostly taken care of, hiding items using
796 | =invisibility-spec= might lead to inconsistent behavior when jumping
797 | around the list, or when adding or removing items.
798 |
799 | * Changelog
800 |
801 | ** 0.9.6
802 | - Fix bug in lister--outline-invisible-p
803 | ** 0.9.5
804 | - =lister-mode=: Silently exit =view-mode= on entering =lister-mode=, if necessary.
805 | - Add option "LIMIT" to =lister-next-matching= and
806 | =lister-next-visible-matching=
807 | - Add hierarchical navigation keys to =lister-mode= (move to parent,
808 | move forward or backward same level, move to beginning or end of
809 | the sublist), fixing Issue #3
810 | ** 0.9.4
811 |
812 | - Add sorting with multiple predicates / criteria.
813 |
814 | ** 0.9.3.
815 | - Add "modified" flag.
816 |
817 | ** 0.9.2
818 |
819 | - Add =lister-save-current-node=
820 | - Add marking predicate (thanks to Nathanael kinfe)
821 | - Add function to get the buffer local ewoc (thanks to Nathanael kinfe)
822 | - Add convenience functions to 'reorder' sublists (thanks to
823 | Nathanael kinfe)
824 | - Add mapping function
825 | - New feature: header or footer can now also be a function.
826 | - New feature: item strings with fields =button= or =field= set will not be
827 | intangible and can be reached with normal cursor motion, while the
828 | rest of the item remains inaccessible.
829 | - Add new public functions =lister-items-marked-p=, =lister-eolp=.
830 | - Bugfixes, internal refactoring.
831 |
832 | ** 0.9.1
833 | - Some bugfixes; add more tests.
834 | - Added minor-mode.
835 | - Added functions to move items and sublists.
836 | - Added outline style hiding of sublists.
837 |
838 | ** 0.9
839 |
840 | - Rewrite the whole package basing it now on =Ewoc=.
841 |
842 |
--------------------------------------------------------------------------------
/lister-mode.el:
--------------------------------------------------------------------------------
1 | ;;; lister-mode.el --- Key definitions for Lister buffers -*- lexical-binding: t; -*-
2 |
3 | ;; Copyright (C) 2021, 2023
4 |
5 | ;; Author:
6 | ;; URL: https://github.com/publicimageltd/lister
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 | ;; This minor mode adds some keymaps for lister buffers.
24 |
25 | ;;; Code:
26 | (require 'lister)
27 | (require 'view)
28 |
29 | ;; Silence compiler warnings
30 | (defvar lister-local-ewoc)
31 |
32 | ;; Convenience macro for defining interactive keys
33 | (cl-defmacro lister-defkey
34 | (fn-name (ewoc-var pos-var prefix-var node-var)
35 | docstring
36 | &rest body)
37 | "Define interactive function FN-NAME with presets for `lister-mode'.
38 | Define a function using FN-NAME and DOCSTRING. When executing
39 | BODY, let EWOC-VAR be bound to the buffer local ewoc object,
40 | POS-VAR to the symbol `:point', PREFIX-VAR to the current prefix
41 | arg and NODE-VAR to the node referred to by POS-VAR."
42 | (declare (indent 2)
43 | (debug (&define name (symbolp symbolp symbolp symbolp)
44 | stringp def-body))
45 | (doc-string 3))
46 | `(defun ,fn-name (,ewoc-var ,pos-var &optional ,prefix-var)
47 | ,(concat docstring
48 | (apply #'format
49 | "\n\nIf called interactively and called in a buffer with
50 | `lister-mode' set, pre-bind %s to the buffer local ewoc object,
51 | %s to the symbol `:point' and %s to the current prefix argument."
52 | (mapcar (lambda (sym) (upcase (symbol-name sym)))
53 | (list ewoc-var pos-var prefix-var))))
54 | (interactive (list
55 | (or lister-local-ewoc (error "Key only works in a lister buffer"))
56 | :point
57 | current-prefix-arg))
58 | (ignore ,prefix-var ,pos-var ,ewoc-var)
59 | (let ((,node-var (lister--parse-position ewoc pos)))
60 | (if (not ,node-var)
61 | (error "No item at indicated position")
62 | ,@body))))
63 |
64 | (defun lister-mode--push-goto (ewoc pos)
65 | "If point is not at POS, maybe push mark and move point.
66 | Push mark only if POS is not an immediate visible neighbour of
67 | the current node. EWOC is a Lister Ewoc Object."
68 | (lister-with-node ewoc pos node
69 | (let ((current (lister--parse-position ewoc :point)))
70 | (unless (eq node current)
71 | (unless (or (eq node (lister--next-node-matching ewoc current #'lister-node-visible-p #'ewoc-next))
72 | (eq node (lister--next-node-matching ewoc current #'lister-node-visible-p #'ewoc-prev)))
73 | (push-mark))
74 | (lister-goto ewoc node)))))
75 |
76 | ;;; * Key Definitions
77 |
78 | ;; Mark or unmark the item at point
79 |
80 | (defun lister-mode--generic-mark (ewoc pos prefix state)
81 | "Mark or unmark item or sublist.
82 | In EWOC, mark or unmark the item at POS according to STATE and
83 | move forward one item. If PREFIX is '(4), mark the sublist at
84 | POS. If PREFIX is '(16), mark the sublist below POS."
85 | (pcase prefix
86 | (`(4) (lister-mark-unmark-sublist-at ewoc pos state))
87 | (`(16) (lister-mark-unmark-sublist-below ewoc pos state))
88 | ('nil (progn
89 | (lister-mark-unmark-at ewoc pos state)
90 | (lister-goto ewoc :next)))))
91 |
92 | (defun lister-mode--mark-unmark-region (ewoc from to state)
93 | "Mark region from buffer positions FROM and TO according to STATE.
94 | EWOC is a lister ewoc object."
95 | (with-current-buffer (ewoc-buffer ewoc)
96 | (let* ((beg (ewoc-locate ewoc from))
97 | (end (ewoc-locate ewoc to)))
98 | (when (= (ewoc-location end) to)
99 | (setq end (ewoc-prev ewoc end)))
100 | (lister-dolist-nodes (ewoc node beg end)
101 | (lister-mark-unmark-at ewoc node state)))))
102 |
103 | (lister-defkey lister-mode-mark (ewoc pos prefix node)
104 | "Mark the item or sublist at point or the items in the region.
105 | Use EWOC and POS to determine the item to be marked. If PREFIX
106 | is non-nil, mark the sublist at POS. If the region is active,
107 | unmark all items in the region and ignore PREFIX."
108 | (if (and (use-region-p)
109 | (not (region-noncontiguous-p)))
110 | (lister-mode--mark-unmark-region ewoc
111 | (region-beginning)
112 | (region-end) t)
113 | (lister-mode--generic-mark ewoc pos prefix t)))
114 |
115 | (lister-defkey lister-mode-unmark (ewoc pos prefix node)
116 | "Unmark the item or sublist at point or the items in the region.
117 | Use EWOC and POS to determine the item to be marked. If PREFIX
118 | is non-nil, unmark the sublist at POS. If the region is active,
119 | unmark all items in the region and ignore PREFIX."
120 | (if (and (use-region-p)
121 | (not (region-noncontiguous-p)))
122 | (lister-mode--mark-unmark-region ewoc
123 | (region-beginning)
124 | (region-end)
125 | nil)
126 | (lister-mode--generic-mark ewoc pos prefix nil)))
127 |
128 | (defun lister-mode-unmark-all ()
129 | "Unmark all items in the current Lister buffer."
130 | (interactive)
131 | (unless lister-local-ewoc
132 | (error "Functions needs to be called in a Lister buffer with an Ewoc object"))
133 | (lister-walk-marked-nodes lister-local-ewoc
134 | (lambda (ewoc node)
135 | (lister-mark-unmark-at ewoc node nil))))
136 |
137 | ;; Cycle subtree visibility
138 |
139 | (lister-defkey lister-mode-cycle-sublist (ewoc pos prefix node)
140 | "Cycle the visibility of the sublist below point.
141 | Use EWOC and POS to determine the sublist to be marked. If
142 | PREFIX is non-nil, show all sublists."
143 | (if prefix
144 | (lister-outline-show-all ewoc)
145 | (lister-outline-cycle-sublist-below ewoc pos)))
146 |
147 | ;; Move items up or down
148 |
149 | (lister-defkey lister-mode-up (ewoc pos prefix node)
150 | "Move the item at point one up.
151 | Only move within the same level unless PREFIX is set."
152 | (lister-move-item-up ewoc pos prefix))
153 |
154 | (lister-defkey lister-mode-down (ewoc pos prefix node)
155 | "Move the item at point one down.
156 | Only move within the same level unless PREFIX is set."
157 | (lister-move-item-down ewoc pos prefix))
158 |
159 | (lister-defkey lister-mode-right (ewoc pos prefix node)
160 | "Move the item at point to the right."
161 | (lister-move-item-right ewoc pos))
162 |
163 | (lister-defkey lister-mode-left (ewoc pos prefix node)
164 | "Move the item at point to the left."
165 | (lister-move-item-left ewoc pos))
166 |
167 | ;; Move sublists up or down
168 |
169 | (lister-defkey lister-mode-sublist-up (ewoc pos prefix node)
170 | "Move the sublist at point one up."
171 | (lister-move-sublist-up ewoc pos))
172 |
173 | (lister-defkey lister-mode-sublist-down (ewoc pos prefix node)
174 | "Move the sublist at point one down."
175 | (lister-move-sublist-down ewoc pos))
176 |
177 | (lister-defkey lister-mode-sublist-right (ewoc pos prefix node)
178 | "Move the sublist at point to the right."
179 | (lister-move-sublist-right ewoc pos))
180 |
181 | (lister-defkey lister-mode-sublist-left (ewoc pos prefix node)
182 | "Move the sublist at point to the left."
183 | (lister-move-sublist-left ewoc pos))
184 |
185 | ;; Move within the hierarchy
186 |
187 | (defun lister-mode--next-visible-node-same-level (ewoc node move-fn)
188 | "Find the next visible node with the same level as NODE.
189 | EWOC is a Lister Ewoc Object. MOVE-FN must be either `ewoc-next'
190 | or `ewoc-prev'."
191 | (let* ((ref-level (lister-node-get-level node)))
192 | (lister--next-node-matching ewoc node
193 | (lambda (n)
194 | (and (lister-node-visible-p n)
195 | (= ref-level (lister-node-get-level n))))
196 | move-fn)))
197 |
198 | (lister-defkey lister-mode-backward-same-level (ewoc pos prefix node)
199 | "Move backward to the next item with the same level."
200 | (if-let ((next (lister-mode--next-visible-node-same-level ewoc node #'ewoc-next)))
201 | (lister-mode--push-goto ewoc next)
202 | (user-error "No further item with the same level")))
203 |
204 | (lister-defkey lister-mode-forward-same-level (ewoc pos prefix node)
205 | "Move forward to the next item with the same level."
206 | (if-let ((next (lister-mode--next-visible-node-same-level ewoc node #'ewoc-prev)))
207 | (lister-mode--push-goto ewoc next)
208 | (user-error "No further item with the same level")))
209 |
210 | (lister-defkey lister-mode-up-parent (ewoc pos prefix node)
211 | "Move up to the parent node."
212 | (if-let ((parent (lister-parent-node ewoc pos)))
213 | (lister-mode--push-goto ewoc parent)
214 | (user-error "No parent found")))
215 |
216 | (defun lister-mode--outer-top-sublist-node (ewoc pos)
217 | "In EWOC, find the outer top sublist node above POS.
218 | Return the node or nil if no such node is available."
219 | (when-let ((parent (lister-parent-node ewoc pos)))
220 | (lister-top-sublist-node ewoc parent)))
221 |
222 | (defun lister-mode--outer-bottom-sublist-node (ewoc pos)
223 | "In EWOC, find the outer bottom sublistnode below POS.
224 | Return the node or nil if no such node is available."
225 | (lister-with-sublist-at ewoc pos beg end
226 | (when-let* ((outer-first (ewoc-next ewoc end))
227 | (outer-bounds (lister--locate-sublist ewoc outer-first t)))
228 | (nth 1 outer-bounds))))
229 |
230 | (lister-defkey lister-mode-goto-beginning (ewoc pos prefix node)
231 | "Move up to the beginning of the sublist or list.
232 | Call this function several times to move out of nested sublists."
233 | (let ((top (lister-top-sublist-node ewoc pos)))
234 | (when (eq node top)
235 | (setq top (lister-mode--outer-top-sublist-node ewoc top)))
236 | (if top
237 | (lister-mode--push-goto ewoc top)
238 | (if-let ((first (lister--next-or-this-node-matching ewoc (lister-get-node-at ewoc :first)
239 | #'lister-node-visible-p
240 | #'ewoc-next
241 | node)))
242 | (lister-mode--push-goto ewoc first)
243 | (user-error "Beginning of list")))))
244 |
245 | (lister-defkey lister-mode-goto-end (ewoc pos prefix node)
246 | "Move down to the end of the sublist or list.
247 | Call this function several times to move out of nested sublists."
248 | (let ((bottom (lister-bottom-sublist-node ewoc pos)))
249 | (when (eq node bottom)
250 | (setq bottom (lister-mode--outer-bottom-sublist-node ewoc bottom)))
251 | (if bottom
252 | (lister-mode--push-goto ewoc bottom)
253 | (if-let ((last (lister--next-or-this-node-matching ewoc (lister-get-node-at ewoc :last)
254 | #'lister-node-visible-p
255 | #'ewoc-prev
256 | node)))
257 | (lister-mode--push-goto ewoc last)
258 | (user-error "End of list")))))
259 |
260 | (lister-defkey lister-mode-next-child-forward (ewoc pos prefix node)
261 | "Move to the next child looking up from point."
262 | (if-let ((next (lister-first-sublist-node ewoc pos 'up)))
263 | (lister-mode--push-goto ewoc next)
264 | (user-error "No child found above point")))
265 |
266 | (lister-defkey lister-mode-next-child-backward (ewoc pos prefix node)
267 | "Move to the next child looking down from point."
268 | (if-let ((next (lister-first-sublist-node ewoc pos 'down)))
269 | (lister-mode--push-goto ewoc next)
270 | (user-error "No child found below point")))
271 |
272 | ;; * The Keymap
273 | (defvar lister-mode-map
274 | (let ((map (make-sparse-keymap)))
275 | (define-key map "m" 'lister-mode-mark)
276 | (define-key map "u" 'lister-mode-unmark)
277 | (define-key map "U" 'lister-mode-unmark-all)
278 | (define-key map "\t" 'lister-mode-cycle-sublist)
279 | (define-key map (kbd "") 'lister-mode-up)
280 | (define-key map (kbd "") 'lister-mode-down)
281 | (define-key map (kbd "") 'lister-mode-right)
282 | (define-key map (kbd "") 'lister-mode-left)
283 | (define-key map (kbd "") 'lister-mode-sublist-up)
284 | (define-key map (kbd "") 'lister-mode-sublist-down)
285 | (define-key map (kbd "") 'lister-mode-sublist-right)
286 | (define-key map (kbd "") 'lister-mode-sublist-left)
287 | ;;
288 | (define-key map [remap beginning-of-buffer] 'lister-mode-goto-beginning)
289 | (define-key map [remap end-of-buffer] 'lister-mode-goto-end)
290 | (define-key map (kbd "C-c C-u") 'lister-mode-up-parent)
291 | (define-key map (kbd "C-c C-f") 'lister-mode-forward-same-level)
292 | (define-key map (kbd "C-c C-b") 'lister-mode-backward-same-level)
293 | (define-key map (kbd "C-c ") 'lister-mode-next-child-forward)
294 | (define-key map (kbd "C-c ") 'lister-mode-next-child-backward)
295 | map)
296 | "Key map for `lister-mode'.")
297 |
298 | (define-minor-mode lister-mode
299 | "Bind some keys for basic operations in a lister buffer."
300 | :lighter "lister "
301 | :group 'lister
302 | :keymap lister-mode-map
303 | (when (and lister-mode view-mode)
304 | (view-mode-exit t)))
305 |
306 | (provide 'lister-mode)
307 | ;;; lister-mode.el ends here
308 |
--------------------------------------------------------------------------------
/lister-tests.el:
--------------------------------------------------------------------------------
1 | ;;; lister-tests.el --- testsuite for lister.el -*- lexical-binding: t; -*-
2 |
3 | ;; Copyright (C) 2020-2021, 2023
4 |
5 | ;; Author:
6 |
7 | ;; This program is free software; you can redistribute it and/or modify
8 | ;; it under the terms of the GNU General Public License as published by
9 | ;; the Free Software Foundation, either version 3 of the License, or
10 | ;; (at your option) any later version.
11 |
12 | ;; This program is distributed in the hope that it will be useful,
13 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | ;; GNU General Public License for more details.
16 |
17 | ;; You should have received a copy of the GNU General Public License
18 | ;; along with this program. If not, see .
19 |
20 | ;;; Commentary:
21 |
22 | ;; Buttercup tests for lister
23 |
24 | ;;; Code:
25 |
26 | (require 'lister "lister.el")
27 | (require 'lister-mode "lister-mode.el")
28 | (require 'buttercup)
29 | (require 'seq)
30 | (require 'cl-lib)
31 | (require 'cl-extra)
32 | (require 'rx)
33 |
34 | ;; TODO Implement custom-matcher "to-return-no-node", checking for nil
35 | ;; and giving more useful feedback if a node has been returned
36 |
37 |
38 | ;; (message "Testing lister version %s on Emacs %s" lister-version emacs-version)
39 |
40 | ;; (setq buttercup-stack-frame-style 'pretty)
41 |
42 | (defvar lister-local-left-margin)
43 |
44 | (defun lister-test-setup-minimal-buffer ()
45 | "Set up a minimal buffer, with no margins and a simple list mapper.
46 | Return the ewoc object"
47 | (let ((ewoc (lister-setup "*LISTER*" #'list)))
48 | (with-current-buffer (ewoc-buffer ewoc)
49 | (setq-local lister-local-left-margin 0))
50 | ewoc))
51 |
52 | (defun lister-test-get-data-at-point (ewoc)
53 | "Return the data of the item at point in EWOC.
54 | This is functionally equivalent to `lister-get-data-at', but uses
55 | low-lewel ewoc functions instead of `lister--parse-position'."
56 | (lister-node-get-data (with-current-buffer (ewoc-buffer ewoc)
57 | (ewoc-locate ewoc))))
58 |
59 | (defun lister-test-node-data-pred (value)
60 | "Build function matching a lister node's data having VALUE."
61 | (lambda (n) (equal (lister-node-get-data n)
62 | value)))
63 |
64 | (defun lister-test-data-pred (value)
65 | "Build function matching item having VALUE."
66 | (lambda (item) (equal value item)))
67 |
68 | (defun lister-test-only-visible-content (buf)
69 | "Return only content from BUF which is not marked as invisible."
70 | (with-current-buffer buf
71 | (goto-char (point-min))
72 | (let (acc)
73 | (while (not (eobp))
74 | (let* ((invisible (get-text-property (point) 'invisible))
75 | (next-change
76 | (or (next-single-property-change (point) 'invisible)
77 | (point-max))))
78 | (unless invisible
79 | (setq acc
80 | (concat acc (buffer-substring-no-properties (point) next-change))))
81 | (goto-char next-change)))
82 | (or acc ""))))
83 |
84 | ;;; * Custom Matchers
85 |
86 | ;; to match nodes by data:
87 | (buttercup-define-matcher :to-be-node-with-data (node1 node2)
88 | (let* ((n1 (funcall node1))
89 | (n1-data (lister-node-get-data n1))
90 | (n2-data (funcall node2)))
91 | (buttercup--test-expectation
92 | (equal n1-data n2-data)
93 | :expect-match-phrase
94 | (format "Expected node data to be %s, but instead it was %s"
95 | n2-data (if n1 n1-data "no node at all"))
96 | :expect-mismatch-phrase
97 | (format "Expected node data not to be '%s', but instead it was"
98 | n2-data))))
99 |
100 | ;; to match nodes:
101 | (buttercup-define-matcher :to-be-node (node1 node2)
102 | (let* ((n1 (funcall node1))
103 | (n2 (funcall node2))
104 | (n1-data (when n1 (lister-node-get-data n1)))
105 | (n2-data (when n2 (lister-node-get-data n2))))
106 | (buttercup--test-expectation
107 | (equal n1 n2)
108 | :expect-match-phrase
109 | (format "Expected node to be %s, but instead it was %s"
110 | n2-data (if n1 n1-data "no node at all"))
111 | :expect-mismatch-phrase
112 | (format "Expected node not to be '%s', but instead it was"
113 | n2-data))))
114 |
115 | (defun lister-test--map-nodes (n)
116 | "Get the data/content of the nodes in list N."
117 | (mapcar #'lister-node-get-data n))
118 |
119 | (buttercup-define-matcher :to-be-nodes (a b)
120 | (cl-destructuring-bind
121 | ((a-expr . a) (b-expr . b))
122 | (mapcar #'buttercup--expr-and-value (list a b))
123 | (let* ((a-uniques (cl-set-difference a b :test #'equal))
124 | (b-uniques (cl-set-difference b a :test #'equal))
125 | (spec (format-spec-make
126 | ?A (format "%S" a-expr)
127 | ?a (format "%S" (lister-test--map-nodes a))
128 | ?B (format "%S" b-expr)
129 | ?b (format "%S" (lister-test--map-nodes b))
130 | ?m (format "%S" (lister-test--map-nodes b-uniques))
131 | ?p (format "%S" (lister-test--map-nodes a-uniques)))))
132 | (cond
133 | ((and a-uniques b-uniques)
134 | (cons nil (buttercup-format-spec
135 | "Expected `%A' to contain the same nodes as `%b', but `%m' are missing and `%p' are present unexpectedly in `%a'."
136 | spec)))
137 | (a-uniques
138 | (cons nil (buttercup-format-spec
139 | "Expected `%A' to contain the same nodes as `%b', but `%p' are present unexpectedly in `%a'."
140 | spec)))
141 | (b-uniques
142 | (cons nil (buttercup-format-spec
143 | "Expected `%A' to contain the same nodes as `%b', but `%m' are missing in `%a'."
144 | spec)))
145 | (t
146 | (cons t (buttercup-format-spec
147 | "Expected `%A' not to have same nodes as `%b'"
148 | spec)))))))
149 |
150 | ;; to match position of point in list:
151 | (buttercup-define-matcher :to-have-point-at-item (ewoc data)
152 | (let* ((ewoc-value (funcall ewoc))
153 | (data-value (funcall data))
154 | (ewoc-data (lister-test-get-data-at-point ewoc-value)))
155 | (buttercup--test-expectation
156 | (equal ewoc-data data-value)
157 | :expect-match-phrase (format "Expected point to be at item `%s', but it was at `%s'"
158 | data-value ewoc-data)
159 | :expect-mismatch-phrase (format "Expected point not to be at item `%s', but it was."
160 | ewoc-data))))
161 |
162 |
163 | ;; to match buffer contents:
164 | (buttercup-define-matcher :to-have-as-content (buf content-to-be)
165 | (let* ((content (with-current-buffer (funcall buf)
166 | (buffer-substring-no-properties
167 | (point-min) (point-max))))
168 | (expected-content (funcall content-to-be)))
169 | (buttercup--test-expectation
170 | (equal content expected-content)
171 | :expect-match-phrase
172 | (format "Expected buffer content to be '%s', but instead it was '%s'"
173 | expected-content content)
174 | :expect-mismatch-phrase
175 | (format "Expected buffer content not to be '%s', but it was."
176 | expected-content))))
177 |
178 | ;; to match only visible buffer contents:
179 | (buttercup-define-matcher :to-have-as-visible-content (buf content-to-be)
180 | (let* ((content (lister-test-only-visible-content (funcall buf)))
181 | (expected-content (funcall content-to-be)))
182 | (buttercup--test-expectation
183 | (equal content expected-content)
184 | :expect-match-phrase
185 | (format "Expected buffer content to be '%s', but instead it was '%s'"
186 | expected-content content)
187 | :expect-mismatch-phrase
188 | (format "Expected buffer content not to be '%s', but it was."
189 | expected-content))))
190 |
191 | ;; -----------------------------------------------------------
192 | ;; * Tests for lister.el
193 |
194 | ;;; * Set up
195 | (describe "Set up:"
196 | (describe "lister-setup"
197 | (it "returns an ewoc object"
198 | (let* ((ewoc (lister-setup "TEST" #'list)))
199 | (expect (ewoc-p ewoc)
200 | :to-be-truthy)))
201 | (it "creates a new buffer by name"
202 | (let* ((ewoc (lister-setup "TEST" #'list)))
203 | (expect (buffer-name (ewoc-buffer ewoc))
204 | :to-equal
205 | "TEST")))
206 | (it "does not change the major mode of an existing buffer"
207 | (let* ((buf (generate-new-buffer "TEST"))
208 | (mode (with-current-buffer buf major-mode))
209 | (ewoc (lister-setup "TEST" #'list)))
210 | (expect (with-current-buffer (ewoc-buffer ewoc) major-mode)
211 | :to-be
212 | mode)))
213 | (it "stores the mapper locally in the buffer"
214 | (let* ((ewoc (lister-setup "TEST" 'list)))
215 | (expect (buffer-local-value 'lister-local-mapper
216 | (ewoc-buffer ewoc))
217 | :to-equal
218 | 'list)))))
219 |
220 | (describe "Basic level list handling:"
221 | :var (ewoc l item)
222 | (before-each
223 | (setq ewoc (lister-test-setup-minimal-buffer))
224 | (setq l '("A" "B" "C" "D" "E" "F"))
225 | (setq item "ITEM"))
226 | (after-each
227 | (kill-buffer (ewoc-buffer ewoc)))
228 |
229 | (describe "lister-empty-p:"
230 | (it "returns t when list is empty:"
231 | (expect (lister-empty-p ewoc)
232 | :to-be-truthy))
233 | (it "returns nil if list has an item:"
234 | (ewoc-enter-first ewoc (lister--item-create :data "TEST"))
235 | (expect (lister-empty-p ewoc)
236 | :not :to-be-truthy)))
237 |
238 | (describe "lister-set-list/lister-get-list:"
239 | (it "setting and getting returns an unchanged flat list:"
240 | (lister-set-list ewoc l)
241 | (expect (lister-get-list ewoc) :to-equal l))
242 |
243 | (it "setting and getting returns an unchanged nested list:"
244 | (let ((the-list (list "TOP" l "SECOND" l "THIRD" '("1" "2" ("3")) "FOURTH" "FIFTH")))
245 | (lister-set-list ewoc the-list)
246 | (expect (lister-get-list ewoc)
247 | :to-equal the-list))))
248 |
249 | (describe "lister--determine-level"
250 | (it "always returns 0 if called with with prev-level nil:"
251 | (expect (lister--determine-level nil 12)
252 | :to-equal 0)
253 | (expect (lister--determine-level nil 0)
254 | :to-equal 0)
255 | (expect (lister--determine-level nil 123214)
256 | :to-equal 0))
257 | (it "always returns prev-level+1 if called with a bigger value:"
258 | (expect (lister--determine-level 0 12)
259 | :to-be 1)
260 | (expect (lister--determine-level 0 1)
261 | :to-be 1)
262 | (expect (lister--determine-level 0 2)
263 | :to-be 1))
264 | (it "it always returns the new level if called with smaller value:"
265 | (expect (lister--determine-level 2 1)
266 | :to-be 1)
267 | (expect (lister--determine-level 2 0)
268 | :to-be 0)))
269 |
270 | (describe "lister-set-list:"
271 | (it "nil clears the current list:"
272 | (lister-set-list ewoc l)
273 | (lister-set-list ewoc nil)
274 | (expect (lister-empty-p ewoc)
275 | :to-be-truthy)
276 | (expect (lister-get-list ewoc)
277 | :to-be nil)))
278 |
279 | (describe "lister-get-list:"
280 | (it "returns a slice when called with integer arguments:"
281 | (lister-set-list ewoc l)
282 | (expect (lister-get-list ewoc 0 1)
283 | :to-equal '("A" "B"))
284 | (expect (lister-get-list ewoc 1 2)
285 | :to-equal '("B" "C"))
286 | (expect (lister-get-list ewoc 4 5)
287 | :to-equal '("E" "F")))
288 | (it "returns the tail of the list:"
289 | (lister-set-list ewoc l)
290 | (expect (lister-get-list ewoc 3)
291 | :to-equal '("D" "E" "F")))
292 | (it "returns the head of the list:"
293 | (lister-set-list ewoc l)
294 | (expect (lister-get-list ewoc nil 3)
295 | :to-equal '("A" "B" "C" "D")))
296 | (it "combines node and integer positions as arguments:"
297 | (lister-set-list ewoc l)
298 | (let ((beg (ewoc-nth ewoc 0))
299 | (end 3))
300 | (expect (lister-get-list ewoc beg end)
301 | :to-equal '("A" "B" "C" "D")))
302 | (let ((beg 0)
303 | (end (ewoc-nth ewoc 3)))
304 | (expect (lister-get-list ewoc beg end)
305 | :to-equal '("A" "B" "C" "D")))))
306 |
307 | (describe "lister-map"
308 | (it "maps a flat list"
309 | (lister-set-list ewoc l)
310 | (cl-labels ((map-fn (s)
311 | (concat "MAPPED" s)))
312 | (expect (lister-map ewoc #'map-fn)
313 | :to-equal (mapcar #'map-fn l))))
314 | (it "maps a flat list with predicate"
315 | (lister-set-list ewoc l)
316 | (cl-labels ((map-fn (s)
317 | (concat "MAPPED" s))
318 | (pred-fn (s)
319 | (string= "A" s)))
320 | (expect (lister-map ewoc #'map-fn #'pred-fn)
321 | :to-equal '("MAPPEDA"))))
322 |
323 | (it "maps a hierarchical list"
324 | (let ((l '("A" "B" "C" ("D" "E" "F"))))
325 | (lister-set-list ewoc l)
326 | (cl-labels ((map-fn (s)
327 | (concat "MAPPED" s)))
328 | (expect (lister-map ewoc #'map-fn)
329 | :to-equal '("MAPPEDA" "MAPPEDB" "MAPPEDC"
330 | ("MAPPEDD" "MAPPEDE" "MAPPEDF")))))))
331 |
332 | (describe "lister-add"
333 | (it "adds a single item to an empty list:"
334 | (lister-add ewoc item)
335 | (expect (lister-get-list ewoc)
336 | :to-equal (list item)))
337 | (it "always adds item at the end of the list:"
338 | (dolist (item l)
339 | (lister-add ewoc item))
340 | (expect (lister-get-list ewoc)
341 | :to-equal l)))
342 |
343 | (describe "lister-add-list:"
344 | (it "adds a flat list to an empty list:"
345 | (lister-add-list ewoc l)
346 | (expect (lister-get-list ewoc)
347 | :to-equal l))
348 | (it "adds a flat-list to a non-empty list:"
349 | (lister-add ewoc item)
350 | (lister-add-list ewoc l)
351 | (expect (lister-get-list ewoc)
352 | :to-equal (append (list item) l)))
353 | (it "adds a nested list to an empty list:"
354 | (let ((nested '("1" "2" ("3" "4") "5" "6")))
355 | (lister-add-list ewoc nested)
356 | (expect (lister-get-list ewoc)
357 | :to-equal nested))))
358 |
359 | (describe "lister-insert:"
360 | (it "adds a single item in an empty list:"
361 | (lister-insert ewoc :first item)
362 | (expect (lister-get-list ewoc)
363 | :to-equal (list item)))
364 | (it "inserts an item at the top of an existing list:"
365 | (lister-set-list ewoc l)
366 | (lister-insert ewoc :first item)
367 | (expect (lister-get-list ewoc)
368 | :to-equal (append (list item) l)))
369 | (it "inserts an item at the end of an existing list:"
370 | (lister-set-list ewoc l)
371 | (lister-insert ewoc :last item nil t)
372 | (expect (lister-get-list ewoc)
373 | :to-equal (append l (list item))))
374 | (it "throws an error if position does not exist:"
375 | (lister-set-list ewoc l)
376 | (expect (lister-insert ewoc 10 item)
377 | :to-throw))
378 | (it "inserts an item before the last item:"
379 | (lister-set-list ewoc l)
380 | (lister-insert ewoc :last item)))
381 |
382 | (describe "lister-replace-at"
383 | (it "replaces an item in an existing list:"
384 | (lister-set-list ewoc l)
385 | (lister-replace-at ewoc :first item)
386 | (expect (lister-get-list ewoc)
387 | :to-equal (append (list item)
388 | (cdr l)))))
389 | (describe "lister-delete-at:"
390 | (it "deletes the first item of a list:"
391 | (lister-set-list ewoc l)
392 | (lister-delete-at ewoc :first)
393 | (expect (lister-get-list ewoc)
394 | :to-equal (cdr l)))
395 | (it "deletes the last item of a list:"
396 | (lister-set-list ewoc l)
397 | (lister-delete-at ewoc :last)
398 | (expect (lister-get-list ewoc)
399 | :to-equal (reverse (cdr (reverse l)))))
400 | (it "deletes the only item of a list:"
401 | (lister-set-list ewoc (list item))
402 | (lister-delete-at ewoc :first)
403 | (expect (lister-empty-p ewoc)
404 | :to-be-truthy))
405 | (it "throws an error if node does not exist:"
406 | (expect (lister-delete-at ewoc :first)
407 | :to-throw))
408 | (it "throws an error if index is out of range:"
409 | (lister-set-list ewoc l)
410 | (expect (lister-delete-at ewoc 10)
411 | :to-throw)))
412 |
413 | (describe "lister-replace-list"
414 | (it "replaces a list from node to node:"
415 | (lister-set-list ewoc l)
416 | (let ((first (ewoc-nth ewoc 1)) ;; "B"
417 | (second (ewoc-nth ewoc 4)) ;; "E"
418 | (new '("1" "2" "3" "4" "5" "6" "7")))
419 | (lister-replace-list ewoc new first second)
420 | (expect (lister-get-list ewoc)
421 | :to-equal (append (list "A") new (list "F")))))
422 | (it "replaces a list with index positions:"
423 | (lister-set-list ewoc l)
424 | (let* ((new '("1" "2" "3" "4" "5" "6" "7"))
425 | (expected (append (list "A") new (list "F"))))
426 | (lister-replace-list ewoc new 1 4)
427 | (expect (lister-get-list ewoc)
428 | :to-equal expected)))
429 | (it "completely replaces a list with :first :last"
430 | (lister-set-list ewoc l)
431 | (let ((new '("1" "2")))
432 | (lister-replace-list ewoc new :first :last)
433 | (expect (lister-get-list ewoc) :to-equal new)))
434 | (it "completely replaces a list with nil nil:"
435 | (lister-set-list ewoc l)
436 | (let ((new '("1" "2")))
437 | (lister-replace-list ewoc new nil nil)
438 | (expect (lister-get-list ewoc) :to-equal new)))
439 | (it "replaces the list from ... up to end:"
440 | (lister-set-list ewoc l)
441 | (let ((new '("1" "2")))
442 | (lister-replace-list ewoc new 2 nil)
443 | (expect (lister-get-list ewoc)
444 | :to-equal '("A" "B" "1" "2"))))
445 | (it "replaces the existing list with an empty list:"
446 | (lister-set-list ewoc l)
447 | (lister-replace-list ewoc nil nil nil)
448 | (expect (lister-empty-p ewoc) :to-be-truthy))
449 | (it "replaces an empty list with a new list:"
450 | (lister-replace-list ewoc '("1" "2") nil nil)
451 | (expect (lister-get-list ewoc) :to-equal '("1" "2"))))
452 |
453 |
454 | ;; TODO Add tests for -update; -delete-marked
455 | (describe "modified flag:"
456 | (describe "lister-setup"
457 | (it "returns buffer with modified set to nil"
458 | (expect (lister-modified-p ewoc) :not :to-be-truthy)))
459 | (describe "lister-insert"
460 | (it "sets modified flag"
461 | (lister-insert ewoc :first "TEST")
462 | (expect (lister-modified-p ewoc) :to-be-truthy)))
463 | (describe "lister-replace-at"
464 | (it "sets modified flag"
465 | (lister-insert ewoc :first "TEST")
466 | (lister-set-modified-p ewoc nil)
467 | (expect (lister-modified-p ewoc) :not :to-be-truthy)
468 | (lister-replace-at ewoc :first "NEW ITEM")
469 | (expect (lister-modified-p ewoc) :to-be-truthy)))
470 | (describe "lister-delete-at"
471 | (it "sets modified flag"
472 | (lister-insert ewoc :first "TEST")
473 | (lister-set-modified-p ewoc nil)
474 | (expect (lister-modified-p ewoc) :not :to-be-truthy)
475 | (lister-delete-at ewoc :first)
476 | (expect (lister-modified-p ewoc) :to-be-truthy)))
477 | (describe "lister-delete-list"
478 | (it "sets modified flag"
479 | (lister-insert-list ewoc :first '("A" "B" "C"))
480 | (lister-set-modified-p ewoc nil)
481 | (expect (lister-modified-p ewoc) :not :to-be-truthy)
482 | (lister-delete-list ewoc :first :last)
483 | (expect (lister-modified-p ewoc) :to-be-truthy)))
484 | (describe "lister-delete-all"
485 | (it "sets modified flag"
486 | (lister-insert-list ewoc :first '("A" "B" "C"))
487 | (lister-set-modified-p ewoc nil)
488 | (expect (lister-modified-p ewoc) :not :to-be-truthy)
489 | (lister-delete-all ewoc)
490 | (expect (lister-modified-p ewoc) :to-be-truthy)))))
491 |
492 | ;;; * Setting and removing header/footer
493 |
494 | (describe "Header/Footer:"
495 | :var (ewoc l)
496 | (before-each
497 | (setq ewoc (lister-test-setup-minimal-buffer))
498 | (setq l '("1" "2" "3")))
499 | (after-each
500 | (kill-buffer (ewoc-buffer ewoc)))
501 |
502 | (describe "lister-set-header:"
503 | (it "sets header in an empty list:"
504 | (lister-set-header ewoc "TEST")
505 | (expect (ewoc-buffer ewoc)
506 | :to-have-as-content "TEST\n"))
507 | (it "removes header when called with nil:"
508 | (lister-set-header ewoc "TEST")
509 | (lister-set-header ewoc nil)
510 | (expect (ewoc-buffer ewoc)
511 | :to-have-as-content ""))
512 | (it "accepts a list of strings:"
513 | (lister-set-header ewoc '("TEST" "TEST"))
514 | (expect (ewoc-buffer ewoc)
515 | :to-have-as-content "TEST\nTEST\n"))
516 | (it "adds header before a list:"
517 | (lister-set-list ewoc l)
518 | (lister-set-header ewoc "TEST")
519 | (expect (ewoc-buffer ewoc)
520 | :to-have-as-content
521 | (concat "TEST\n"
522 | (string-join l "\n")
523 | "\n")))))
524 |
525 | (describe "lister--parse-position"
526 | :var (ewoc l)
527 | (before-each
528 | (setq l '(:node-1 :node-2 (:nested-node 1 :nested-node-2) :node-3))
529 | (setq ewoc (lister-setup "*LISTER*" (lambda (x) (format "%S" x))))
530 | (with-current-buffer (ewoc-buffer ewoc)
531 | (setq-local lister-local-left-margin 0))
532 | (lister-insert-list ewoc :first l))
533 | (after-each
534 | (kill-buffer (ewoc-buffer ewoc)))
535 |
536 | (it "finds nodes by integer"
537 | (let ((l-flattened (flatten-tree l)))
538 | (expect (lister-node-get-data (lister--parse-position ewoc 0)) :to-be (nth 0 l-flattened))
539 | (expect (lister-node-get-data (lister--parse-position ewoc 1)) :to-be (nth 1 l-flattened))
540 | (expect (lister-node-get-data (lister--parse-position ewoc 2)) :to-be (nth 2 l-flattened))
541 | (expect (lister-node-get-data (lister--parse-position ewoc 3)) :to-be (nth 3 l-flattened))))
542 | (it "finds hidden outline nodes"
543 | (let ((l-flattened (flatten-tree l)))
544 | (lister-outline-hide-sublist-below ewoc 1)
545 | (expect (lister-node-get-data (lister--parse-position ewoc 0)) :to-be (nth 0 l-flattened))
546 | (expect (lister-node-get-data (lister--parse-position ewoc 1)) :to-be (nth 1 l-flattened))
547 | (expect (lister-node-get-data (lister--parse-position ewoc 2)) :to-be (nth 2 l-flattened))
548 | (expect (lister-node-get-data (lister--parse-position ewoc 3)) :to-be (nth 3 l-flattened)))))
549 |
550 |
551 | (describe "lister--outline-invisible-p"
552 | :var (ewoc l)
553 | (before-each
554 | (setq l '(:node-1 :node-2 (:nested-node-1 :nested-node-2) :node-3))
555 | (setq ewoc (lister-setup "*LISTER*" (lambda (x) (format "%S" x))))
556 | (with-current-buffer (ewoc-buffer ewoc)
557 | (setq-local lister-local-left-margin 0))
558 | (lister-insert-list ewoc :first l))
559 | (after-each
560 | (kill-buffer (ewoc-buffer ewoc)))
561 |
562 | (it "yields correct values for non-hidden lists"
563 | (expect (mapcar (lambda (n)
564 | (lister--outline-invisible-p ewoc n))
565 | '(0 1 2 3 4))
566 | :to-equal '(nil nil nil nil nil)))
567 | (it "yields correct values for hidden sublist"
568 | (lister-outline-hide-sublist-below ewoc 1)
569 | (expect (mapcar (lambda (n)
570 | (lister--outline-invisible-p ewoc n))
571 | '(0 1 2 3 4))
572 | :to-equal '(nil nil t t nil))))
573 |
574 | ;;; * Diverse API
575 |
576 | (describe "Diverse API"
577 | :var (ewoc l)
578 | (before-each
579 | (setq ewoc (lister-test-setup-minimal-buffer))
580 | (setq l '("A" "B" "C" "D" "E" "F")))
581 | (after-each
582 | (kill-buffer (ewoc-buffer ewoc)))
583 |
584 | (describe "lister-with-boundaries"
585 | (xit "throws an error if not called with symbols"
586 | ;; This test does not fail, but causes annoying "eager macro
587 | ;; expansion" error; so we x it
588 | (expect (lister-with-boundaries ewoc 1 0
589 | (ignore))
590 | :to-throw)
591 | (expect (lister-with-boundaries ewoc :first :last
592 | (ignore))
593 | :to-throw))
594 | (it "passes through nodes"
595 | (lister-set-list ewoc l)
596 | (let ((first (ewoc-nth ewoc 0))
597 | (second (ewoc-nth ewoc 1)))
598 | (expect (lister-with-boundaries ewoc first second
599 | first)
600 | :to-be-node first)))
601 | (it "accepts :first, :last as values"
602 | (lister-set-list ewoc l)
603 | (let ((first :first)
604 | (second :last))
605 | (expect (lister-with-boundaries ewoc first second
606 | first)
607 | :to-be-node (ewoc-nth ewoc 0))
608 | (expect (lister-with-boundaries ewoc first second
609 | second)
610 | :to-be-node (ewoc-nth ewoc -1))))
611 | (it "accepts indices as values"
612 | (lister-set-list ewoc l)
613 | (let ((first 0)
614 | (second (1- (length l))))
615 | (expect (lister-with-boundaries ewoc first second
616 | first)
617 | :to-be-node (ewoc-nth ewoc 0))
618 | (expect (lister-with-boundaries ewoc first second
619 | second)
620 | :to-be-node (ewoc-nth ewoc -1))))
621 | (it "accepts nil as values"
622 | (lister-set-list ewoc l)
623 | (let ((first nil)
624 | (second nil))
625 | (expect (lister-with-boundaries ewoc first second
626 | first)
627 | :to-be-node (ewoc-nth ewoc 0))
628 | (expect (lister-with-boundaries ewoc first second
629 | second)
630 | :to-be-node (ewoc-nth ewoc -1))))))
631 |
632 | ;;; * Looping
633 |
634 | (describe "Loops:"
635 | :var (ewoc l)
636 | (before-each
637 | (setq ewoc (lister-test-setup-minimal-buffer))
638 | (setq l '("A" "B" "C" "D" "E" "F")))
639 | (after-each
640 | (kill-buffer (ewoc-buffer ewoc)))
641 |
642 | (describe "lister-dolist-nodes"
643 | (it "loops over the complete list of nodes with explicit boundaries:"
644 | (lister-set-list ewoc l)
645 | (let (acc)
646 | (lister-dolist-nodes (ewoc node :first :last)
647 | (push (lister--item-data (ewoc-data node)) acc))
648 | (expect acc :to-equal (reverse l))))
649 | (it "loops over the complete list of nodes with implicit boundaries:"
650 | (lister-set-list ewoc l)
651 | (let (acc)
652 | (lister-dolist-nodes (ewoc node)
653 | (push (lister--item-data (ewoc-data node)) acc))
654 | (expect acc :to-equal (reverse l))))
655 | (it "can deal with BODY which deletes the node:"
656 | (lister-set-list ewoc l)
657 | (lister-dolist-nodes (ewoc node)
658 | (let ((inhibit-read-only t))
659 | (ewoc-delete ewoc node)))
660 | (expect (lister-empty-p ewoc) :to-be-truthy))
661 | (it "breaks out of the loop with a cl-return:"
662 | (lister-set-list ewoc l)
663 | (let ((target-node (ewoc-nth ewoc 2))
664 | acc)
665 | (lister-dolist-nodes (ewoc node)
666 | (push (lister--item-data (ewoc-data node)) acc)
667 | (when (eq target-node node)
668 | (cl-return)))
669 | (expect (nreverse acc) :to-equal '("A" "B" "C")))))
670 |
671 | (describe "lister-dolist:"
672 | (it "loops over the data items:"
673 | (lister-set-list ewoc l)
674 | (let (acc)
675 | (lister-dolist (ewoc data :first :last)
676 | (push data acc))
677 | (expect acc :to-equal (reverse l))))
678 | (it "gives access to the data's node:"
679 | (lister-set-list ewoc l)
680 | (let (acc)
681 | (lister-dolist (ewoc data :first :last node)
682 | (push (lister--item-data (ewoc-data node)) acc))
683 | (expect acc :to-equal (reverse l)))))
684 |
685 | (describe "lister-collect-list"
686 | (it "collects a flat list:"
687 | (lister-set-list ewoc l)
688 | (expect (lister-collect-list ewoc)
689 | :to-equal l))
690 | (it "transforms the collected data:"
691 | (lister-set-list ewoc l)
692 | (let ((transformer-fn (apply-partially #'concat " ")))
693 | (expect (lister-collect-list ewoc :first :last
694 | nil
695 | transformer-fn)
696 | :to-equal
697 | (mapcar transformer-fn l))))
698 | (it "only returns matching data items:"
699 | (lister-set-list ewoc l)
700 | (let ((predicate-fn (apply-partially #'string-match-p (rx string-start (or "A" "B" "C")))))
701 | (expect (lister-collect-list ewoc :first :last
702 | predicate-fn)
703 | :to-equal '("A" "B" "C"))))
704 | (it "combines pred and transformer functions:"
705 | (lister-set-list ewoc l)
706 | (let ((predicate-fn (apply-partially #'string-match-p (rx string-start (or "A" "B" "C"))))
707 | (transformer-fn (apply-partially #'concat " ")))
708 | (expect (lister-collect-list ewoc :first :last
709 | predicate-fn
710 | transformer-fn)
711 | :to-equal (mapcar transformer-fn '("A" "B" "C"))))))
712 |
713 | (describe "lister-update-list"
714 | (it "updates the whole list:"
715 | (lister-set-list ewoc l)
716 | (let ((action-fn (apply-partially #'concat "X")))
717 | (lister-update-list ewoc action-fn)
718 | (expect (lister-get-list ewoc)
719 | :to-equal (mapcar action-fn l))))
720 | (it "updates only those items matching pred-fn:"
721 | (lister-set-list ewoc l)
722 | (let ((action-fn (apply-partially #'concat "X"))
723 | (pred-fn (apply-partially #'string-match "B")))
724 | (lister-update-list ewoc action-fn)
725 | (lister-update-list ewoc action-fn :first :last pred-fn)
726 | (expect (lister-get-list ewoc)
727 | :to-equal (mapcar (lambda (s)
728 | (if (funcall pred-fn s)
729 | (funcall action-fn s)
730 | s))
731 | (mapcar action-fn l)))))))
732 |
733 | ;;; * Sublists
734 |
735 | (describe "Sublists:"
736 | :var (ewoc l)
737 | (before-each
738 | (setq ewoc (lister-test-setup-minimal-buffer))
739 | (setq l '("A" "B" "C" "D"))
740 | (setq sub-l '("1" "2" "3")))
741 | (after-each
742 | (kill-buffer (ewoc-buffer ewoc)))
743 |
744 | (describe "insert-sublist-below:"
745 | (it "inserts sublist below position"
746 | (lister-set-list ewoc l)
747 | (lister-insert-sublist-below ewoc :first sub-l)
748 | (expect (lister-get-list ewoc)
749 | :to-equal (list "A"
750 | sub-l
751 | "B" "C" "D")))
752 | (it "inserts sublist as normal list on top:"
753 | (lister-insert-sublist-below ewoc :first sub-l)
754 | (expect (lister-get-list ewoc)
755 | :to-equal sub-l))
756 | (it "produces a nested list if called within a sublist:"
757 | (lister-set-list ewoc sub-l)
758 | (lister-insert-sublist-below ewoc 0 sub-l)
759 | (lister-insert-sublist-below ewoc 1 sub-l)
760 | (lister-insert-sublist-below ewoc 2 sub-l)
761 | (expect (lister-get-list ewoc)
762 | :to-equal
763 | '("1"
764 | ("1"
765 | ("1"
766 | ("1" "2" "3")
767 | "2"
768 | "3")
769 | "2"
770 | "3")
771 | "2"
772 | "3"))))
773 |
774 | (describe "lister--locate-sublist:"
775 | :var (ewoc l)
776 | (before-each
777 | (setq ewoc (lister-test-setup-minimal-buffer))
778 | (setq l '("1" "2" "3" "4")))
779 | (after-each
780 | (kill-buffer (ewoc-buffer ewoc)))
781 |
782 | (it "returns the whole list boundaries if there is no sublist"
783 | (lister-set-list ewoc '("0" "1" "2" "3" "4" "5" "6"))
784 | (let ((expected-bounds (list (lister--parse-position ewoc :first)
785 | (lister--parse-position ewoc :last))))
786 | (expect (lister--locate-sublist ewoc 2)
787 | :to-be-nodes expected-bounds)))
788 | (it "returns nil if there are no list items"
789 | (lister-delete-all ewoc)
790 | (expect (lister--locate-sublist ewoc :first)
791 | :to-be nil))
792 | (it "throws an error if POS is out of bounds"
793 | (lister-set-list ewoc '("0" "1"))
794 | (expect (lister--locate-sublist ewoc 2)
795 | :to-throw))
796 | (it "identifies a surrounded sublist:"
797 | (lister-set-list ewoc '("0" "1" ("2" "3" "4" "5") "4" "5"))
798 | (let ((expected-bounds (list (ewoc-nth ewoc 2)
799 | (ewoc-nth ewoc 5))))
800 | (expect (lister--locate-sublist ewoc 2)
801 | :to-be-nodes expected-bounds)
802 | (expect (lister--locate-sublist ewoc 3)
803 | :to-be-nodes expected-bounds)
804 | (expect (lister--locate-sublist ewoc 4)
805 | :to-be-nodes expected-bounds)
806 | (expect (lister--locate-sublist ewoc 5)
807 | :to-be-nodes expected-bounds)))
808 | (it "identifies a sublist with 'open end':"
809 | (lister-set-list ewoc '("0" "1"
810 | ("2" "3" "4" "5")))
811 | (let ((expected-bounds (list (ewoc-nth ewoc 2)
812 | (ewoc-nth ewoc 5))))
813 | (expect (lister--locate-sublist ewoc 2)
814 | :to-be-nodes expected-bounds)
815 | (expect (lister--locate-sublist ewoc 3)
816 | :to-be-nodes expected-bounds)
817 | (expect (lister--locate-sublist ewoc 4)
818 | :to-be-nodes expected-bounds)
819 | (expect (lister--locate-sublist ewoc 5)
820 | :to-be-nodes expected-bounds)))
821 | (it "identifies a surrounded nested sublist:"
822 | (lister-set-list ewoc '("0" ("1" ("2" "3") "4" "5")))
823 | (let ((expected-bounds (list (ewoc-nth ewoc 2)
824 | (ewoc-nth ewoc 3))))
825 | (expect (lister--locate-sublist ewoc 2)
826 | :to-be-nodes expected-bounds)
827 | (expect (lister--locate-sublist ewoc 3)
828 | :to-be-nodes expected-bounds)))
829 | (it "skips filtered items if asked for"
830 | (lister-set-list ewoc '("0" ("A" "A" "3" "4") "5"))
831 | (lister-set-filter ewoc (lambda (s) (equal s "A")))
832 | (let ((expected-bounds (list (ewoc-nth ewoc 3)
833 | (ewoc-nth ewoc 4))))
834 | (expect (lister--locate-sublist ewoc 2 :only-visible)
835 | :to-be-nodes expected-bounds)))
836 | (it "returns the only visible item if the rest of the sublist is filtered"
837 | (lister-set-list ewoc '("0" ("A" "A" "3" "A") "5"))
838 | (lister-set-filter ewoc (lambda (s) (equal s "A")))
839 | (let ((expected-bounds (list (ewoc-nth ewoc 3)
840 | (ewoc-nth ewoc 3))))
841 | (expect (lister--locate-sublist ewoc 2 :only-visible)
842 | :to-be-nodes expected-bounds)))
843 | (it "returns nil if the complete list is invisible"
844 | (lister-set-list ewoc '("A" ("A" "A" "A" "A") "A"))
845 | (lister-set-filter ewoc (lambda (s) (equal s "A")))
846 | (expect (lister--locate-sublist ewoc 2 :only-visible)
847 | :to-be nil))
848 | (it "returns first and last if all sublist items are filtered"
849 | (lister-set-list ewoc '("0" ("A" "A" "A" "A") "5"))
850 | (lister-set-filter ewoc (lambda (s) (equal s "A")))
851 | (let ((expected-bounds (list (ewoc-nth ewoc 0)
852 | (ewoc-nth ewoc 5))))
853 | (expect (lister--locate-sublist ewoc 2 :only-visible)
854 | :to-be-nodes expected-bounds))))
855 |
856 | (describe "lister-get-sublist-at:"
857 | (it "returns a sublist:"
858 | (lister-set-list ewoc '("0" ("1" "2" "3") "4"))
859 | (expect (lister-get-sublist-at ewoc 1)
860 | :to-equal '("1" "2" "3")))
861 | (it "returns the whole list if called with :first"
862 | (lister-set-list ewoc '("0" ("1" "2" "3") "4"))
863 | (expect (lister-get-sublist-at ewoc :first)
864 | :to-equal '("0" ("1" "2" "3") "4"))))
865 |
866 | (describe "lister-get-sublist-below:"
867 | (it "returns a sublist:"
868 | (lister-set-list ewoc '("0" ("1" "2" "3") "4"))
869 | (expect (lister-get-sublist-below ewoc 0)
870 | :to-equal '("1" "2" "3")))
871 | (it "returns nil if there is no sublist below:"
872 | (lister-set-list ewoc '("0" "1" "2" "3" "4"))
873 | (expect (lister-get-sublist-below ewoc 0)
874 | :to-be nil)))
875 |
876 | (describe "lister-delete-sublist-at"
877 | (it "deletes a sublist:"
878 | (lister-set-list ewoc '("0" ("1" "2" "3") "4"))
879 | (lister-delete-sublist-at ewoc 1)
880 | (expect (lister-get-list ewoc)
881 | :to-equal '("0" "4")))
882 | (it "deletes the whole list if called with a level 0 item:"
883 | (lister-set-list ewoc '("0" ("1" ("2" "3")) "4" "5"))
884 | (lister-delete-sublist-at ewoc 0)
885 | (expect (lister-empty-p ewoc)
886 | :to-be-truthy)
887 | (expect (lister-get-list ewoc)
888 | :to-be nil)))
889 |
890 | (describe "lister-delete-sublist-below"
891 | (it "deletes a sublist below POS:"
892 | (lister-set-list ewoc l)
893 | (lister-insert-sublist-below ewoc 0 sub-l)
894 | (expect (lister-get-list ewoc)
895 | :to-equal '("A" ("1" "2" "3") "B" "C" "D"))
896 | (lister-delete-sublist-below ewoc 0)
897 | (expect (lister-get-list ewoc) :to-equal l))
898 | (it "does nothing if there is no sublist at POS:"
899 | (lister-set-list ewoc l)
900 | (lister-delete-sublist-below ewoc 0)
901 | (expect (lister-get-list ewoc) :to-equal l)))
902 | (describe "lister-replace-sublist-below"
903 | (it "replaces a sublist below POS:"
904 | (lister-set-list ewoc l)
905 | (lister-insert-sublist-below ewoc 0 sub-l)
906 | (lister-replace-sublist-below ewoc 0 '("A"))
907 | (expect (lister-get-list ewoc)
908 | :to-equal '("A" ("A") "B" "C" "D")))
909 | (it "deletes sublist if called with empty new list:"
910 | (lister-set-list ewoc l)
911 | (lister-insert-sublist-below ewoc 0 sub-l)
912 | (lister-replace-sublist-below ewoc 0 nil)
913 | (expect (lister-get-list ewoc) :to-equal l)))
914 | (describe "lister-replace-sublist-at"))
915 |
916 |
917 | ;;; * Movement / Navigation
918 |
919 | (describe "Movement ('Finding') and Navigation:"
920 | :var (ewoc l)
921 | (before-each
922 | (setq ewoc (lister-test-setup-minimal-buffer))
923 | (setq l '("0" "1" "2" "3" "4" "5"))
924 | (lister-set-list ewoc l))
925 | (after-each
926 | (kill-buffer (ewoc-buffer ewoc)))
927 |
928 | (describe "lister--next-node-matching"
929 | (it "returns the node matching PRED-FN looking down"
930 | (expect (lister--next-node-matching ewoc (ewoc-nth ewoc 0)
931 | (lister-test-node-data-pred "4")
932 | #'ewoc-next)
933 | :to-be-node (lister-get-node-at ewoc 4)))
934 | (it "returns the node matching PRED-FN looking up"
935 | (expect (lister--next-node-matching ewoc (ewoc-nth ewoc -1)
936 | (lister-test-node-data-pred "1")
937 | #'ewoc-prev)
938 | :to-be-node (lister-get-node-at ewoc 1)))
939 | (it "returns nil if no matching node is found looking down"
940 | (expect (lister--next-node-matching ewoc (ewoc-nth ewoc 0)
941 | #'ignore
942 | #'ewoc-next)
943 | :to-be nil))
944 | (it "returns nil if no matching node is found looking up"
945 | (expect (lister--next-node-matching ewoc (ewoc-nth ewoc -1)
946 | #'ignore
947 | #'ewoc-prev)
948 | :to-be nil))
949 | (it "ignores the starting node matching PRED-FN"
950 | (expect (lister--next-node-matching ewoc (ewoc-nth ewoc 0)
951 | (lister-test-node-data-pred "0")
952 | #'ewoc-next)
953 | :to-be nil))
954 | (it "stops searching when node LIMIT is reached"
955 | (expect (lister--next-node-matching ewoc (ewoc-nth ewoc 0)
956 | (lister-test-node-data-pred "3")
957 | #'ewoc-next
958 | (lister-get-node-at ewoc 2))
959 | :to-be nil))
960 | (it "cancels searching even if LIMIT matches PRED-FN"
961 | (expect (lister--next-node-matching ewoc (ewoc-nth ewoc 0)
962 | (lister-test-node-data-pred "3")
963 | #'ewoc-next
964 | (lister-get-node-at ewoc 3))
965 | :to-be nil)))
966 |
967 | (describe "lister--next-or-this-node-matching"
968 | (it "returns the node matching PRED-FN looking down"
969 | (expect (lister--next-or-this-node-matching ewoc (ewoc-nth ewoc 0)
970 | (lister-test-node-data-pred "3")
971 | #'ewoc-next)
972 | :to-be-node (lister-get-node-at ewoc 3)))
973 | (it "returns the node matching PRED-FN looking up"
974 | (expect (lister--next-or-this-node-matching ewoc (ewoc-nth ewoc -1)
975 | (lister-test-node-data-pred "2")
976 | #'ewoc-prev)
977 | :to-be-node (lister-get-node-at ewoc 2)))
978 | (it "returns the starting node matching PRED-FN looking down"
979 | (expect (lister--next-or-this-node-matching ewoc (ewoc-nth ewoc 0)
980 | (lister-test-node-data-pred "0")
981 | #'ewoc-next)
982 | :to-be-node (lister-get-node-at ewoc 0)))
983 | (it "returns the starting node matching PRED-FN looking up"
984 | (expect (lister--next-or-this-node-matching ewoc (ewoc-nth ewoc -1)
985 | (lister-test-node-data-pred "5")
986 | #'ewoc-prev)))
987 | (it "stops searching before reaching LIMIT"
988 | (expect (lister--next-or-this-node-matching ewoc (ewoc-nth ewoc 0)
989 | (lister-test-node-data-pred "4")
990 | #'ewoc-next
991 | (lister-get-node-at ewoc 3))
992 | :to-be nil))
993 | (it "stops searching at LIMIT matching PRED-FN"
994 | (expect (lister--next-or-this-node-matching ewoc (ewoc-nth ewoc 0)
995 | (lister-test-node-data-pred "3")
996 | #'ewoc-next
997 | (lister-get-node-at ewoc 3))
998 | :to-be nil)))
999 |
1000 | (describe "lister-goto:"
1001 | (it "moves point to the first item of the list:"
1002 | (lister-goto ewoc :first)
1003 | (expect ewoc :to-have-point-at-item "0"))
1004 | (it "moves point to the last item of the list:"
1005 | (lister-goto ewoc :last)
1006 | (expect ewoc :to-have-point-at-item "5"))
1007 | (it "moves point to the next item:"
1008 | (lister-goto ewoc :first)
1009 | (lister-goto ewoc :next)
1010 | (expect ewoc :to-have-point-at-item "1"))
1011 | (it "moves point to the prev item:"
1012 | (lister-goto ewoc :last)
1013 | (lister-goto ewoc :prev)
1014 | (expect ewoc :to-have-point-at-item "4"))
1015 | (it "moves point to an index position:"
1016 | (lister-goto ewoc 4)
1017 | (expect ewoc :to-have-point-at-item "4"))
1018 | (it "throws an error if index is out of bounds:"
1019 | (expect (lister-goto ewoc 8)
1020 | :to-throw)))
1021 |
1022 | (describe "lister-top-sublist-node"
1023 | (it "finds the first sublist node"
1024 | (lister-set-list ewoc '("A" "B" ("AA" "BB" "CC" "DD") "C" ))
1025 | (expect (lister-top-sublist-node ewoc 5)
1026 | :to-be-node-with-data "AA"))
1027 | (it "moves to the top node if there is no sublist"
1028 | (expect (lister-top-sublist-node ewoc 4)
1029 | :to-be-node-with-data "0"))
1030 | (it "does nothing if there is no list"
1031 | (lister-set-list ewoc nil)
1032 | (expect (lister-top-sublist-node ewoc :point) :to-be nil)))
1033 |
1034 | (describe "lister-bottom-sublist-node"
1035 | (it "moves to the last sublist node"
1036 | (lister-set-list ewoc '("A" "B" ("AA" "BB" "CC" "DD") "C"))
1037 | (expect (lister-bottom-sublist-node ewoc 5) :to-be-node-with-data "DD"))
1038 | (it "does nothing if there is no list"
1039 | (lister-set-list ewoc nil)
1040 | (expect (lister-bottom-sublist-node ewoc :point) :to-be nil))
1041 | (it "moves to the last node if there is no sublist"
1042 | (expect (lister-bottom-sublist-node ewoc 3) :to-be-node-with-data "5")))
1043 |
1044 | (describe "lister-parent-node"
1045 | (before-each
1046 | ;; 0 1 2 3 4 5 6 7
1047 | (lister-set-list ewoc '("A" "B" ("AA" "BB" "CC" ("AAA" "BBB") "DD") "C" "D"))
1048 | (lister-set-filter ewoc nil))
1049 | (it "finds the parent node"
1050 | (expect (lister-parent-node ewoc 4) :to-be-node-with-data "B"))
1051 | (it "finds the parent node in a nested list"
1052 | (expect (lister-parent-node ewoc 6) :to-be-node-with-data "CC"))
1053 | (it "moves to the top node when called on a 0 level node"
1054 | (expect (lister-parent-node ewoc 1) :to-be-node-with-data "A"))
1055 | (it "moves to the top node when called from below a sublist"
1056 | (expect (lister-parent-node ewoc 8) :to-be-node-with-data "A"))
1057 | (it "skips real parent node since it is invisible"
1058 | (lister-set-filter ewoc (lambda (s) (equal s "B")))
1059 | (expect (lister-parent-node ewoc 3) :to-be-node-with-data "A"))
1060 | (it "throws an error if all parent nodes are invisible"
1061 | (lister-set-filter ewoc (lambda (s) (or (equal s "A")
1062 | (equal s "B"))))
1063 | (expect (lister-parent-node ewoc 2) :to-be nil))
1064 | (it "moves to the first sublist node if all parent nodes are invisible"
1065 | (lister-set-filter ewoc (lambda (s) (or (equal s "A")
1066 | (equal s "B"))))
1067 | (expect (lister-parent-node ewoc 3) :to-be-node-with-data "AA")))
1068 |
1069 | (describe "lister-first-sublist-node"
1070 | (before-each
1071 | ;; 0 1 2 3 4 5 6 7
1072 | (lister-set-list ewoc '("A" "B" ("AA" "BB" "CC" ("AAA" "BBB") "DD") "C" "D")))
1073 | (it "returns nilif no sublist item is available"
1074 | (expect (lister-first-sublist-node ewoc 5 'down) :to-be nil)
1075 | (expect (lister-first-sublist-node ewoc 5 'up) :to-be nil))
1076 | (it "moves to first sublist item"
1077 | (expect (lister-first-sublist-node ewoc :first 'down) :to-be-node-with-data "AA")
1078 | (expect (lister-first-sublist-node ewoc :last 'up) :to-be-node-with-data "DD"))
1079 | (it "moves to nested sublist item"
1080 | (expect (lister-first-sublist-node ewoc (lister-first-sublist-node ewoc :first 'down) 'down) :to-be-node-with-data "AAA")
1081 | (expect (lister-first-sublist-node ewoc (lister-first-sublist-node ewoc :last 'up) 'up) :to-be-node-with-data "BBB"))))
1082 |
1083 | ;;; * Filter
1084 |
1085 | (describe "Filter:"
1086 | :var (ewoc l pred-fn
1087 | filter-a filter-non-a
1088 | filter-b
1089 | filter-i filter-non-i
1090 | filter-2nd
1091 | filter-*)
1092 | (before-each
1093 | (setq ewoc (lister-test-setup-minimal-buffer))
1094 | (setq l '("AZ" "BAZ" "DAZ" "MAZ"
1095 | ("ITEM4" "ITEM5" "ITEM6")
1096 | "HEY" "THEY" "OBEY"))
1097 | (lister-set-list ewoc l)
1098 | (setq filter-a (apply-partially #'string-match "A")
1099 | filter-2nd (apply-partially #'string-match-p "BAZ")
1100 | filter-non-a (lambda (s) (not (string-match "A" s)))
1101 | filter-b (apply-partially #'string-match "Y")
1102 | filter-i (apply-partially #'string-match "ITEM")
1103 | filter-non-i (lambda (s) (not (funcall filter-i s)))
1104 | filter-* (apply-partially #'string-match ".*")))
1105 | (after-each
1106 | (kill-buffer (ewoc-buffer ewoc)))
1107 |
1108 | (describe "Finding nodes while filter is OFF:"
1109 | (describe "lister--next-visible-node:"
1110 | (it "moves to the next node:"
1111 | (expect (lister--next-visible-node ewoc (ewoc-nth ewoc 0))
1112 | :to-be-node (ewoc-nth ewoc 1)))
1113 | (it "moves to prev node:"
1114 | (expect (lister--next-visible-node ewoc (ewoc-nth ewoc -1) #'ewoc-prev)
1115 | :to-be-node (ewoc-nth ewoc -2)))
1116 | (it "returns nil if already at last node:"
1117 | (expect (lister--next-visible-node ewoc (ewoc-nth ewoc -1))
1118 | :to-be nil))
1119 | (it "returns nil if already at first node:"
1120 | (expect (lister--next-visible-node ewoc (ewoc-nth ewoc 0) #'ewoc-prev)
1121 | :to-be nil)))
1122 | (describe "lister--first-visible-node:"
1123 | (it "returns first node:"
1124 | (expect (lister--first-visible-node ewoc)
1125 | :to-be-node (ewoc-nth ewoc 0))))
1126 | (describe "lister--last-visible-node:"
1127 | (it "returns last node:"
1128 | (expect (lister--last-visible-node ewoc)
1129 | :to-be-node (ewoc-nth ewoc -1))))
1130 | (describe "lister-next-matching"
1131 | (it "finds next node matching a data predicate:"
1132 | (expect (lister-next-matching ewoc :first
1133 | (lister-test-data-pred "ITEM4"))
1134 | :to-be-node (ewoc-nth ewoc 4)))
1135 | (it "stops when reaching LIMIT"
1136 | (expect (lister-next-matching ewoc :first
1137 | (lister-test-data-pred "ITEM5")
1138 | 3)
1139 | :to-be nil))
1140 | (it "ignores LIMIT even if it matches PRED-FN"
1141 | (expect (lister-next-matching ewoc :first
1142 | (lister-test-data-pred "ITEM5")
1143 | 5)
1144 | :to-be nil)))
1145 | (describe "lister-prev-matching"
1146 | (it "finds prev node matching a data predicate:"
1147 | (expect (lister-prev-matching ewoc :last
1148 | (lister-test-data-pred "ITEM4"))
1149 | :to-be-node (ewoc-nth ewoc 4))))
1150 | (describe "Hide visible items:"
1151 | (describe "lister-set-filter:"
1152 | (it "hides all items:"
1153 | (lister-set-list ewoc l)
1154 | (lister-set-filter ewoc filter-*)
1155 | (expect (ewoc-buffer ewoc)
1156 | :to-have-as-visible-content "")))))
1157 |
1158 | (describe "Finding nodes while filter is ON:"
1159 | (describe "lister--first-visible-node:"
1160 | (it "finds the first visible node with filter-a:"
1161 | (lister-set-list ewoc l)
1162 | (lister-set-filter ewoc filter-a)
1163 | (expect (lister--first-visible-node ewoc)
1164 | :to-be-node (ewoc-nth ewoc 4)))
1165 | (it "finds the first visible node with filter-b:"
1166 | (lister-set-list ewoc l)
1167 | (lister-set-filter ewoc filter-b)
1168 | (expect (lister--first-visible-node ewoc)
1169 | :to-be-node (ewoc-nth ewoc 0)))
1170 | (it "returns nil if everything is hidden:"
1171 | (lister-set-list ewoc l)
1172 | (lister-set-filter ewoc filter-*)
1173 | (expect (lister--first-visible-node ewoc)
1174 | :to-be nil)))
1175 | (describe "lister--last-visible-node:"
1176 | (it "finds the last visible node with filter-a:"
1177 | (lister-set-list ewoc l)
1178 | (lister-set-filter ewoc filter-a)
1179 | (expect (lister--last-visible-node ewoc)
1180 | :to-be-node (ewoc-nth ewoc -1)))
1181 | (it "finds the last visible node with filter-b:"
1182 | (lister-set-list ewoc l)
1183 | (lister-set-filter ewoc filter-b)
1184 | (expect (lister--last-visible-node ewoc)
1185 | :to-be-node (ewoc-nth ewoc 6)))
1186 | (it "returns nil if everyhing is hidden:"
1187 | (lister-set-list ewoc l)
1188 | (lister-set-filter ewoc filter-*)
1189 | (expect (lister--last-visible-node ewoc)
1190 | :to-be nil)))
1191 | (describe "lister-next-visible-matching:"
1192 | (it "skips hidden nodes when searching for an item:"
1193 | (lister-set-list ewoc l)
1194 | (lister-set-filter ewoc filter-2nd)
1195 | (let ((pred (lambda (s) (string-match-p "AZ" s))))
1196 | (expect (lister-next-visible-matching ewoc :first pred)
1197 | :to-be-node (ewoc-nth ewoc 2))))
1198 | (it "returns nil when searching for an hidden item:"
1199 | (lister-set-list ewoc l)
1200 | (lister-set-filter ewoc filter-i)
1201 | (let ((pred (lambda (s) (string-match-p "ITEM4" s))))
1202 | (expect (lister-next-visible-matching ewoc :first pred)
1203 | :to-be nil))))
1204 | (describe "lister-prev-visible-matching"
1205 | (it "skips hidden nodes when searching for an item:"
1206 | (lister-set-list ewoc l)
1207 | (lister-set-filter ewoc filter-2nd)
1208 | (let ((pred (lambda (s) (string-match-p "AZ" s))))
1209 | (expect (lister-prev-visible-matching ewoc 2 pred)
1210 | :to-be-node (ewoc-nth ewoc 0))))
1211 | (it "returns nil when searching for a hiden item:"
1212 | (lister-set-list ewoc l)
1213 | (lister-set-filter ewoc filter-i)
1214 | (let ((pred (lambda (s) (string-match-p "ITEM4" s))))
1215 | (expect (lister-prev-visible-matching ewoc :last pred)
1216 | :to-be nil)))))
1217 | (describe "retreiving lists with filter ON:"
1218 | (describe "lister-get-list:"
1219 | (it "returns complete list if everything is hidden:"
1220 | (lister-set-list ewoc l)
1221 | (lister-set-filter ewoc filter-*)
1222 | (expect (lister-get-list ewoc)
1223 | :to-equal l)))
1224 | (describe"lister-get-visible-list:"
1225 | (it "returns empty list if everything is hidden:"
1226 | (lister-set-list ewoc l)
1227 | (lister-set-filter ewoc filter-*)
1228 | (expect (lister-get-visible-list ewoc)
1229 | :to-be nil))
1230 | (it "returns a flat filtered list:"
1231 | (lister-set-list ewoc l)
1232 | (lister-set-filter ewoc filter-non-a)
1233 | (expect (lister-get-visible-list ewoc)
1234 | :to-equal '("AZ" "BAZ" "DAZ" "MAZ")))
1235 | (it "returns a sublist:"
1236 | (lister-set-list ewoc l)
1237 | (lister-set-filter ewoc filter-non-i)
1238 | (expect (lister-get-visible-list ewoc)
1239 | ;; NOTE Indented list!
1240 | :to-equal '(("ITEM4" "ITEM5" "ITEM6"))))))
1241 |
1242 | (describe "filter new items:"
1243 | (describe "lister-insert:"
1244 | (it "inserts and hide items which match current filter:"
1245 | (lister-set-list ewoc l)
1246 | (lister-set-filter ewoc filter-*)
1247 | (lister-add ewoc "NEU")
1248 | (expect (let ((lister-ignore-filter t))
1249 | (lister-get-list ewoc))
1250 | :to-equal (append l (list "NEU")))
1251 | (expect (let ((lister-ignore-filter t))
1252 | (lister-get-data-at ewoc :last)
1253 | :to-equal "NEU"))
1254 | (expect (let ((lister-ignore-filter t))
1255 | (lister--item-visible (ewoc-data
1256 | (lister-get-node-at ewoc :last))))
1257 | :not :to-be-truthy))
1258 | (it "inserts and does not hide non-matching item:"
1259 | (lister-set-list ewoc l)
1260 | (lister-set-filter ewoc filter-a)
1261 | (lister-add ewoc "BBB")
1262 | (expect (lister-get-data-at ewoc :last)
1263 | :to-equal "BBB")
1264 | (expect (lister--item-visible (ewoc-data
1265 | (lister-get-node-at ewoc :last)))
1266 | :to-be-truthy)))))
1267 |
1268 | ;; * Sorting
1269 |
1270 | (describe "Sorting:"
1271 | :var (ewoc)
1272 | (before-each
1273 | (setq ewoc (lister-test-setup-minimal-buffer)))
1274 | (after-each
1275 | (kill-buffer (ewoc-buffer ewoc)))
1276 |
1277 | (describe "lister--wrap-list"
1278 | (it "wraps a flat list in lists"
1279 | (let ((the-list '(a b c d)))
1280 | (expect (lister--wrap-list the-list)
1281 | :to-equal
1282 | (mapcar #'list the-list))))
1283 | (it "wraps a sublist in the item before it begins"
1284 | (let ((the-list '(a b top (sub-1 sub-2 sub-3))))
1285 | (expect (lister--wrap-list the-list)
1286 | :to-equal
1287 | '((a) (b) (top (sub-1) (sub-2) (sub-3))))))
1288 | (it "wraps a cascade of sublists"
1289 | (let ((the-list '(top1 (top2 (top3 (top4 (s1 s2 s3)))))))
1290 | (expect (lister--wrap-list the-list)
1291 | :to-equal
1292 | '((top1 (top2 (top3 (top4 (s1) (s2) (s3))))))))))
1293 |
1294 | (describe "lister--reorder-wrapped-list"
1295 | (it "sorts a flat list"
1296 | (let ((the-list '((7) (5) (1) (8) (3) (2)))
1297 | (the-fn (apply-partially #'seq-sort-by #'car #'<)))
1298 | ;; (apply-partially #'seq-sort #'<)))
1299 | (expect (lister--reorder-wrapped-list the-list the-fn)
1300 | :to-equal
1301 | '(1 2 3 5 7 8))))
1302 | (it "sorts wrapped nested lists"
1303 | (let ((the-list '((8) (6) (4
1304 | (43
1305 | (40
1306 | (401)
1307 | (402)
1308 | (408)
1309 | (405))
1310 | (48)))
1311 | (1) (9) (7) (3)))
1312 | (the-fn (apply-partially #'seq-sort-by #'car #'<)))
1313 | (expect (lister--reorder-wrapped-list
1314 | the-list
1315 | the-fn)
1316 | :to-equal
1317 | '(1 3 4 (43 (40 (401 402 405 408) 48)) 6 7 8 9)))))
1318 |
1319 | (describe "lister-reverse-list"
1320 | (it "reverses the whole list:"
1321 | (let ((l '("1" "2" "3")))
1322 | (lister-set-list ewoc l)
1323 | (lister-reverse-list ewoc)
1324 | (expect (lister-get-list ewoc) :to-equal (reverse l))))
1325 | (it "keeps marking state of items:"
1326 | (let ((l '("1" "2" "3")))
1327 | (lister-set-list ewoc l)
1328 | (lister-mark-unmark-at ewoc 0 t)
1329 | (lister-reverse-list ewoc)
1330 | (let ((last-node (lister-get-node-at ewoc :last)))
1331 | (expect (lister-node-marked-p last-node)
1332 | :to-be-truthy)))))
1333 |
1334 | (describe "lister-sort-list"
1335 | (it "sorts a flat list:"
1336 | (let ((l '("a" "b" "d" "f" "c")))
1337 | (lister-set-list ewoc l)
1338 | (lister-sort-list ewoc #'string>)
1339 | (expect (lister-get-list ewoc)
1340 | :to-equal (seq-sort #'string> l))))
1341 | (it "sorts a flat list using two comparators"
1342 | (let ((l '([1 "c"] [2 "a"] [3 "b"]
1343 | [1 "a"] [2 "b"] [3 "a"]
1344 | [1 "b"] [2 "c"] [3 "c"])))
1345 | (cl-labels ((my-num< (a b) (< (aref a 0) (aref b 0)))
1346 | (my-string< (a b) (string< (aref a 1) (aref b 1))))
1347 | (setq ewoc (lister-setup "*LISTER*" (apply-partially #'format "%s")))
1348 | (lister-set-list ewoc l)
1349 | (lister-sort-list ewoc (list #'my-num< #'my-string<)))
1350 | (expect (lister-get-list ewoc)
1351 | :to-equal
1352 | '([1 "a"] [1 "b"] [1 "c"]
1353 | [2 "a"] [2 "b"] [2 "c"]
1354 | [3 "a"] [3 "b"] [3 "c"]))))
1355 | (it "keeps marking state of items:"
1356 | (let ((l '("a" "b" "d" "f" "c")))
1357 | (lister-set-list ewoc l)
1358 | (lister-mark-unmark-at ewoc :first t)
1359 | (lister-sort-list ewoc #'string>)
1360 | (let ((last-node (lister-get-node-at ewoc :last)))
1361 | (expect (lister-node-marked-p last-node)
1362 | :to-be-truthy)))))
1363 |
1364 | (describe "lister-sort-sublist-at"
1365 | (it "sorts a sublist:"
1366 | (let ((l '("b" "a" ("bb" "ba" "bc") "c")))
1367 | (lister-set-list ewoc l)
1368 | (lister-sort-sublist-at ewoc 2 #'string>)
1369 | (expect (lister-get-list ewoc)
1370 | :to-equal '("b" "a" ("bc" "bb" "ba") "c")))))
1371 | (describe "lister-sort-sublist-below"
1372 | (it "sorts a sublist:"
1373 | (let ((l '("b" "a" ("bb" "ba" "bc") "c")))
1374 | (lister-set-list ewoc l)
1375 | (lister-sort-sublist-below ewoc 1 #'string>)
1376 | (expect (lister-get-list ewoc)
1377 | :to-equal '("b" "a" ("bc" "bb" "ba") "c"))))))
1378 |
1379 | ;; * Update
1380 |
1381 | (describe "Update:"
1382 | :var (ewoc l)
1383 | (before-each
1384 | (setq ewoc (lister-test-setup-minimal-buffer))
1385 | (setq l '("A" "B" "C" "D")))
1386 | (after-each
1387 | (kill-buffer (ewoc-buffer ewoc)))
1388 |
1389 | (describe "lister-refresh-at:"
1390 | (it "redraws a changed item:"
1391 | (lister-set-list ewoc l)
1392 | (let ((item (ewoc-data (ewoc-nth ewoc 0))))
1393 | (setf (lister--item-data item) "NEW")
1394 | (lister-refresh-at ewoc :first)
1395 | (expect (ewoc-buffer ewoc)
1396 | :to-have-as-content
1397 | (concat (string-join '("NEW" "B" "C" "D")
1398 | "\n")
1399 | "\n")))))
1400 | (describe "lister-refresh-list"
1401 | (it "redraws a list:"
1402 | (lister-set-list ewoc l)
1403 | (let ((n 0))
1404 | (lister-dolist-nodes (ewoc node)
1405 | (setf (lister--item-data (ewoc-data node)) (number-to-string n))
1406 | (setq n (1+ n)))
1407 | (lister-refresh-list ewoc :first :last)
1408 | (expect (ewoc-buffer ewoc)
1409 | :to-have-as-content
1410 | (concat (string-join '("0" "1" "2" "3") "\n")
1411 | "\n"))))))
1412 |
1413 |
1414 | ;;; * Marking / Unmarking items
1415 |
1416 | (describe "Marking:"
1417 | :var (ewoc l)
1418 | (before-each
1419 | (setq ewoc (lister-test-setup-minimal-buffer))
1420 | (setq l (mapcar #'number-to-string
1421 | (number-sequence 0 10))))
1422 | (after-each
1423 | (kill-buffer (ewoc-buffer ewoc)))
1424 |
1425 | (describe "lister--update-mark-state"
1426 | (it "adds face property for marked items"
1427 | (lister-set-list ewoc l)
1428 | (let* ((item (ewoc-data (ewoc-nth ewoc 0)))
1429 | (pos (lister--item-beg item)))
1430 | (setf (lister--item-marked item) t)
1431 | (with-current-buffer (ewoc-buffer ewoc)
1432 | (lister--update-mark-state item)
1433 | (expect (get-text-property pos 'face)
1434 | :to-equal lister-mark-face-or-property))))
1435 | (it "removes face property for unmarked items"
1436 | (lister-set-list ewoc l)
1437 | (let* ((item (ewoc-data (ewoc-nth ewoc 0)))
1438 | (pos (lister--item-beg item)))
1439 | (setf (lister--item-marked item) t)
1440 | (with-current-buffer (ewoc-buffer ewoc)
1441 | (lister--update-mark-state item)
1442 | (setf (lister--item-marked item) nil)
1443 | (lister--update-mark-state item)
1444 | (expect (get-text-property pos 'face)
1445 | :to-be nil)))))
1446 |
1447 | (describe "lister-mark-unmark-at"
1448 | (it "marks a single item:"
1449 | (lister-set-list ewoc l)
1450 | (lister-mark-unmark-at ewoc :first t)
1451 | (let* ((node (lister-get-node-at ewoc :first))
1452 | (pos (lister--item-beg (ewoc-data node))))
1453 | (expect (get-text-property pos 'face (ewoc-buffer ewoc))
1454 | :to-be lister-mark-face-or-property)))
1455 | (it "umarks a single item:"
1456 | (lister-set-list ewoc l)
1457 | (lister-mark-unmark-at ewoc :first t)
1458 | (lister-mark-unmark-at ewoc :first nil)
1459 | (let* ((node (lister-get-node-at ewoc :first))
1460 | (pos (lister--item-beg (ewoc-data node))))
1461 | (expect (get-text-property pos 'face (ewoc-buffer ewoc))
1462 | :to-be nil)))
1463 | (it "does nothing if unmarking an unmarked item:"
1464 | (lister-set-list ewoc l)
1465 | (lister-mark-unmark-at ewoc :first nil)
1466 | (let* ((node (lister-get-node-at ewoc :first))
1467 | (pos (lister--item-beg (ewoc-data node))))
1468 | (expect (get-text-property pos 'face (ewoc-buffer ewoc))
1469 | :to-be nil))))
1470 |
1471 | (describe "lister-mark-unmark-list"
1472 | (it "marks the whole list:"
1473 | (lister-set-list ewoc l)
1474 | (lister-mark-unmark-list ewoc :first :last t)
1475 | (let ((marked? t))
1476 | (lister-dolist-nodes (ewoc node)
1477 | (setq marked? (and marked?
1478 | (lister-node-marked-p node))))
1479 | (expect marked? :to-be-truthy))))
1480 |
1481 | (describe "lister-get-marked-list"
1482 | (it "returns nil if there is no marked item:"
1483 | (lister-set-list ewoc l)
1484 | (expect (lister-get-marked-list ewoc)
1485 | :to-be nil))
1486 | (it "returns a list of all marked items:"
1487 | (lister-set-list ewoc l)
1488 | (let ((mark? t)
1489 | (acc nil))
1490 | (lister-dolist (ewoc data :first :last node)
1491 | (when mark?
1492 | (push data acc)
1493 | (lister-mark-unmark-at ewoc node t))
1494 | (setq mark? (not mark?)))
1495 | (expect (lister-get-marked-list ewoc)
1496 | :to-equal (nreverse acc))))
1497 | (it "only returns items marked and visible"
1498 | (lister-set-list ewoc l)
1499 | (lister-mark-unmark-list ewoc :first :last t)
1500 | (let ((filter (lambda (s)
1501 | (not (string-match-p "8" s)))))
1502 | (lister-set-filter ewoc filter)
1503 | (expect (lister-get-marked-list ewoc)
1504 | :to-equal '("8"))))
1505 | (it "per default ignores indentation:"
1506 | (lister-set-list ewoc l)
1507 | (lister-insert-sublist-below ewoc 1 '("SUB1" "SUB2"))
1508 | (lister-mark-unmark-sublist-below ewoc 1 t)
1509 | (lister-mark-unmark-at ewoc 0 t)
1510 | (expect (lister-get-marked-list ewoc)
1511 | :to-equal '("0" "SUB1" "SUB2")))
1512 | (it "optionally returns a not-flattened list:"
1513 | (lister-set-list ewoc l)
1514 | (lister-insert-sublist-below ewoc 1 '("SUB1" "SUB2"))
1515 | (lister-mark-unmark-sublist-below ewoc 1 t)
1516 | (lister-mark-unmark-at ewoc 0 t)
1517 | (expect (lister-get-marked-list ewoc :first :last nil t)
1518 | :to-equal '("0" ("SUB1" "SUB2")))))
1519 |
1520 | (describe "lister-walk-marked-nodes"
1521 | (it "does nothing if nothing is marked:"
1522 | (lister-set-list ewoc l)
1523 | (let (acc)
1524 | (let ((action-fn (lambda (ewoc node)
1525 | (push (lister-node-get-data node) acc))))
1526 | (lister-walk-marked-nodes ewoc action-fn))
1527 | (expect acc :to-be nil)))
1528 | (it "walks the marked nodes:"
1529 | (lister-set-list ewoc l)
1530 | (lister-mark-unmark-at ewoc 0 t)
1531 | (lister-mark-unmark-at ewoc 1 t)
1532 | (lister-mark-unmark-at ewoc 3 t)
1533 | (let (acc)
1534 | (let ((action-fn (lambda (ewoc node)
1535 | (push (lister-node-get-data node) acc))))
1536 | (lister-walk-marked-nodes ewoc action-fn))
1537 | (expect acc :to-equal '("3" "1" "0"))))
1538 | (it "counts the marked nodes:"
1539 | (lister-set-list ewoc l)
1540 | (lister-mark-unmark-at ewoc 0 t)
1541 | (lister-mark-unmark-at ewoc 1 t)
1542 | (lister-mark-unmark-at ewoc 2 t)
1543 | (expect (lister-walk-marked-nodes ewoc #'ignore) :to-be 3))
1544 | (it "returns 0 if there is nothing to walk:"
1545 | (lister-set-list ewoc l)
1546 | (expect (lister-walk-marked-nodes ewoc #'ignore) :to-be 0)))
1547 |
1548 | (describe "lister-delete-marked-list"
1549 | (it "does nothing if nothing is marked:"
1550 | (lister-set-list ewoc l)
1551 | (lister-delete-marked-list ewoc)
1552 | (expect (lister-get-list ewoc)
1553 | :to-equal l))
1554 | (it "deletes marked items:"
1555 | (lister-set-list ewoc l)
1556 | (lister-mark-unmark-at ewoc 0 t)
1557 | (lister-mark-unmark-at ewoc 2 t)
1558 | (lister-mark-unmark-at ewoc 4 t)
1559 | (lister-delete-marked-list ewoc)
1560 | (expect (lister-get-list ewoc)
1561 | :to-equal '("1" "3" "5" "6" "7" "8" "9" "10"))))
1562 |
1563 | (describe "lister-set-marking-predicate"
1564 | (it "sets the buffer local predicate"
1565 | (lister-set-list ewoc l)
1566 | (lister-set-marking-predicate ewoc #'identity)
1567 | (expect (with-current-buffer (ewoc-buffer ewoc)
1568 | lister-local-marking-predicate)
1569 | :to-equal #'identity))
1570 | (it "keeps all previous marks if set to nil"
1571 | (lister-set-list ewoc l)
1572 | (lister-dolist-nodes (ewoc node)
1573 | (lister-mark-unmark-at ewoc node t))
1574 | (lister-set-marking-predicate ewoc nil)
1575 | (expect (lister-get-marked-list ewoc)
1576 | :to-equal l))
1577 | (it "keeps marks which match the new predicate"
1578 | (lister-set-list ewoc l)
1579 | (lister-dolist-nodes (ewoc node)
1580 | (lister-mark-unmark-at ewoc node t))
1581 | (let ((pred (lambda (data)
1582 | (cl-evenp (string-to-number data)))))
1583 | (lister-set-marking-predicate ewoc pred)
1584 | (expect (lister-get-marked-list ewoc)
1585 | :to-equal (seq-filter pred l)))))
1586 |
1587 | (describe "lister-mark-unmark-at with marking predicate"
1588 | (it "only allows marking of matching items"
1589 | (lister-set-list ewoc l)
1590 | (let ((pred (lambda (data)
1591 | (cl-evenp (string-to-number data)))))
1592 | (lister-set-marking-predicate ewoc pred)
1593 | (lister-dolist-nodes (ewoc node)
1594 | (lister-mark-unmark-at ewoc node t))
1595 | (expect (lister-get-marked-list ewoc)
1596 | :to-equal (seq-filter pred l))))))
1597 |
1598 | (describe "Interactive Editing"
1599 | :var (ewoc l)
1600 | (before-each
1601 | (setq ewoc (lister-test-setup-minimal-buffer))
1602 | (setq l '("0" "1" "2" ("3" "4" "5") "6" "7" "8")))
1603 | (after-each
1604 | (kill-buffer (ewoc-buffer ewoc)))
1605 |
1606 | (describe "lister-save-current-node"
1607 | (it "leaves point at node when other nodes are changed:"
1608 | (lister-set-list ewoc '("0" "1" "2"))
1609 | (with-current-buffer (ewoc-buffer ewoc)
1610 | (let* ((node (lister-get-node-at ewoc 2))
1611 | (_ (lister-goto ewoc node))
1612 | (p (marker-position (lister--item-beg (ewoc-data node)))))
1613 | (lister-save-current-node ewoc
1614 | (lister-delete-at ewoc 1)
1615 | (lister-insert-at ewoc 1 "1"))
1616 | (expect (point) :to-equal p))))
1617 | (it "follows NODE when it moves:"
1618 | (lister-set-list ewoc '("0" "1" "2"))
1619 | (with-current-buffer (ewoc-buffer ewoc)
1620 | (let* ((node (lister-get-node-at ewoc 2)))
1621 | (lister-goto ewoc node)
1622 | (lister-save-current-node ewoc
1623 | (lister-insert-list ewoc 2 '("NEU" "NEW" "NEUF")))
1624 | (expect (point) :to-equal (marker-position (lister--item-beg (ewoc-data node)))))))
1625 | (it "leaves point untouched when item is gone:"
1626 | (lister-set-list ewoc '("0" "1" "2" "3" "4" "5"))
1627 | (lister-goto ewoc :first)
1628 | (with-current-buffer (ewoc-buffer ewoc)
1629 | (let* ((node (lister-get-node-at ewoc 2))
1630 | (_ (lister-goto ewoc node))
1631 | (p (point)))
1632 | (lister-save-current-node ewoc
1633 | (lister-delete-at ewoc node))
1634 | (expect (point) :to-be p))))
1635 | (it "keeps point at footer:"
1636 | (lister-set-list ewoc '("0" "1" "2" "3" "4"))
1637 | (lister-set-footer ewoc "FOOTER")
1638 | (with-current-buffer (ewoc-buffer ewoc)
1639 | (ewoc-goto-node ewoc (ewoc--footer ewoc))
1640 | (lister-save-current-node ewoc
1641 | (lister-set-list ewoc '("NEW" "StuFF")))
1642 | (expect (lister-eolp) :to-be-truthy)
1643 | (expect (with-current-buffer (ewoc-buffer ewoc)
1644 | (eobp)) :not :to-be-truthy)))
1645 | (it "keeps point at eob:"
1646 | (lister-set-list ewoc '("0" "1" "2" "3" "4"))
1647 | (lister-set-footer ewoc "FOOTER")
1648 | (with-current-buffer (ewoc-buffer ewoc)
1649 | (goto-char (point-max)))
1650 | (lister-save-current-node ewoc
1651 | (lister-set-list ewoc '("NEW" "StuFF")))
1652 | (expect (lister-eolp) :to-be-truthy)
1653 | (expect (with-current-buffer (ewoc-buffer ewoc)
1654 | (eobp)) :to-be-truthy)))
1655 |
1656 | (describe "lister--next-node-same-level"
1657 | (it "finds the next node with the same level:"
1658 | (lister-set-list ewoc '("0" ("1") "2"))
1659 | (let ((expected (lister-get-node-at ewoc 2)))
1660 | (expect (lister--next-node-same-level ewoc 0 #'ewoc-next)
1661 | :to-be-node expected)))
1662 | (it "finds the prev node with the same level:"
1663 | (lister-set-list ewoc '("0" ("1") "2"))
1664 | (let ((expected (lister-get-node-at ewoc 0)))
1665 | (expect (lister--next-node-same-level ewoc 2 #'ewoc-prev)
1666 | :to-be-node expected)))
1667 | (it "finds the next node within a sublist:"
1668 | (lister-set-list ewoc '("0" ("1" "2" "3")))
1669 | (let ((expected (lister-get-node-at ewoc 3)))
1670 | (expect (lister--next-node-same-level ewoc 2 #'ewoc-next)
1671 | :to-be-node expected)))
1672 | (it "finds the prev node within a sublist:"
1673 | (lister-set-list ewoc '("0" ("1" "2" "3")))
1674 | (let ((expected (lister-get-node-at ewoc 1)))
1675 | (expect (lister--next-node-same-level ewoc 2 #'ewoc-prev)
1676 | :to-be-node expected)))
1677 | (it "find no node:"
1678 | (lister-set-list ewoc '("0" ("1") "2"))
1679 | (expect (lister--next-node-same-level ewoc 1 #'ewoc-next)
1680 | :to-be nil)))
1681 |
1682 | (describe "lister--move-item"
1683 | (it "throws an error if no movement is possible - down:"
1684 | (lister-set-list ewoc '("0"))
1685 | (expect (lister--move-item ewoc 0 #'ewoc-next nil nil)
1686 | :to-throw))
1687 | (it "throws an error if no movement is possible - up:"
1688 | (lister-set-list ewoc '("0"))
1689 | (expect (lister--move-item ewoc 0 #'ewoc-prev t nil)
1690 | :to-throw))
1691 | (it "moves item up:"
1692 | (lister-set-list ewoc '("0" ("1") "2"))
1693 | (lister--move-item ewoc 2 #'ewoc-prev t nil)
1694 | (expect (lister-get-list ewoc)
1695 | :to-equal '("0" "2" ("1"))))
1696 | (it "moves item down:"
1697 | (lister-set-list ewoc '("0" ("1") "2"))
1698 | (lister--move-item ewoc 1 #'ewoc-next nil nil)
1699 | (expect (lister-get-list ewoc)
1700 | :to-equal '("0" "2" ("1"))))
1701 | (it "preserves mark when moving down:"
1702 | (lister-set-list ewoc '("0" ("1") "2"))
1703 | (lister-mark-unmark-at ewoc 1 t)
1704 | (lister--move-item ewoc 1 #'ewoc-next nil nil)
1705 | (expect (lister-node-marked-p (lister-get-node-at ewoc 2))
1706 | :to-be-truthy))
1707 | (it "preserves mark when moving up:"
1708 | (lister-set-list ewoc '("0" ("1") "2"))
1709 | (lister-mark-unmark-at ewoc 2 t)
1710 | (lister--move-item ewoc 2 #'ewoc-prev t nil)
1711 | (expect (lister-node-marked-p (lister-get-node-at ewoc 1))
1712 | :to-be-truthy))
1713 | (it "skips sublists when moving up:"
1714 | (lister-set-list ewoc '("0" ("1" "2") "3"))
1715 | (lister--move-item ewoc 3 #'ewoc-prev t t)
1716 | (expect (lister-get-list ewoc)
1717 | :to-equal '("0" "3" ("1" "2"))))
1718 | (it "skips sublists when moving down:"
1719 | (lister-set-list ewoc '("0" ("1" "2") "3"))
1720 | (lister--move-item ewoc 0 #'ewoc-next nil t)
1721 | (expect (lister-get-list ewoc)
1722 | :to-equal '(("1" "2") "0" "3")))
1723 | (it "skips filtered items:"
1724 | (lister-set-list ewoc '("0" "1" "2" "A" "4" "5"))
1725 | (lister-set-filter ewoc (apply-partially #'string-match-p "A"))
1726 | (lister--move-item ewoc 4 #'lister--prev-visible-node t nil)
1727 | (expect (lister-get-list ewoc)
1728 | :to-equal '("0" "1" "4" "A" "2" "5"))))
1729 |
1730 | (describe "lister-move-item-up"
1731 | (it "throws an error if no movement is possible:"
1732 | (lister-set-list ewoc '("0"))
1733 | (expect (lister-move-item-up ewoc 0)
1734 | :to-throw))
1735 | (it "moves within same level per default:"
1736 | (lister-set-list ewoc '("0" ("1" "1" "1") "2"))
1737 | (lister-move-item-up ewoc :last)
1738 | (expect (lister-get-list ewoc)
1739 | :to-equal '("0" "2" ("1" "1" "1"))))
1740 | (it "optionally ignores level when moving:"
1741 | (lister-set-list ewoc '("0" ("1" "1" "1") "2"))
1742 | (lister-move-item-up ewoc :last t)
1743 | (expect (lister-get-list ewoc)
1744 | :to-equal '("0" ("1" "1") "2" ("1")))))
1745 |
1746 | (describe "lister-move-item-down"
1747 | (it "throws an error if no movement is possible:"
1748 | (lister-set-list ewoc '("0"))
1749 | (expect (lister-move-item-down ewoc 0)
1750 | :to-throw))
1751 | (it "moves within same level per default:"
1752 | (lister-set-list ewoc '("0" ("1" "1" "1") "2"))
1753 | (lister-move-item-down ewoc :first)
1754 | (expect (lister-get-list ewoc)
1755 | :to-equal '(("1" "1" "1") "0" "2")))
1756 | (it "optionally ignores level when moving:"
1757 | (lister-set-list ewoc '("0" ("1" "1" "1") "2"))
1758 | (lister-move-item-down ewoc :first t)
1759 | (expect (lister-get-list ewoc)
1760 | :to-equal '(("1") "0" ("1" "1") "2"))))
1761 |
1762 | (describe "lister-move-item-right"
1763 | (it "indents item by one:"
1764 | (lister-set-list ewoc '("0"))
1765 | (lister-move-item-right ewoc :first)
1766 | (expect (lister-get-level-at ewoc :first)
1767 | :to-be 1))
1768 | (it "indents level by two if called two times:"
1769 | (lister-set-list ewoc '("0"))
1770 | (lister-move-item-right ewoc :first)
1771 | (lister-move-item-right ewoc :first)
1772 | (expect (lister-get-level-at ewoc :first)
1773 | :to-be 2)))
1774 |
1775 | (describe "lister-move-item-left"
1776 | (it "dedents item by one:"
1777 | (lister-set-list ewoc '(("0")))
1778 | (lister-move-item-left ewoc :first)
1779 | (expect (lister-get-level-at ewoc :first)
1780 | :to-be 0))
1781 | (it "dedents level by two if called two times:"
1782 | (lister-set-list ewoc '((("0"))))
1783 | (lister-move-item-left ewoc :first)
1784 | (lister-move-item-left ewoc :first)
1785 | (expect (lister-get-level-at ewoc :first)
1786 | :to-be 0)))
1787 |
1788 | (describe "lister-move-sublist-up"
1789 | (it "throws an error if no movement is possible:"
1790 | (lister-set-list ewoc '("0" ("A" "B")))
1791 | (expect (lister-move-sublist-up ewoc 2)
1792 | :to-throw))
1793 | (it "moves sublist up:"
1794 | (lister-set-list ewoc '("0" "1" ("A" "B")))
1795 | (lister-move-sublist-up ewoc 2)
1796 | (expect (lister-get-list ewoc)
1797 | :to-equal '("0" ("A" "B") "1")))
1798 | (it "preserves marking state:"
1799 | (lister-set-list ewoc '("0" "1" ("A" "B")))
1800 | (lister-mark-unmark-sublist-at ewoc 2 t)
1801 | (lister-move-sublist-up ewoc 2)
1802 | (let ((n1 (lister-get-node-at ewoc 1)) ;; "A"
1803 | (n2 (lister-get-node-at ewoc 2))) ;; "B"
1804 | (expect (lister-node-marked-p n1) :to-be-truthy)
1805 | (expect (lister-node-marked-p n2) :to-be-truthy))))
1806 |
1807 | (describe "lister-move-sublist-down"
1808 | (it "throws an error if no movement is possible:"
1809 | (lister-set-list ewoc '("0" ("A" "B")))
1810 | (expect (lister-move-sublist-down ewoc 2)
1811 | :to-throw))
1812 | (it "moves sublist down:"
1813 | (lister-set-list ewoc '("0" ("A" "B") "1"))
1814 | (lister-move-sublist-down ewoc 2)
1815 | (expect (lister-get-list ewoc)
1816 | :to-equal '("0" "1" ("A" "B"))))
1817 | (it "preserves marking state:"
1818 | (lister-set-list ewoc '("0" ("A" "B") "1"))
1819 | (lister-mark-unmark-sublist-at ewoc 2 t)
1820 | (lister-move-sublist-down ewoc 2)
1821 | (let ((n1 (lister-get-node-at ewoc 2)) ;; "A"
1822 | (n2 (lister-get-node-at ewoc 3))) ;; "B"
1823 | (expect (lister-node-marked-p n1) :to-be-truthy)
1824 | (expect (lister-node-marked-p n2) :to-be-truthy))))
1825 |
1826 | (describe "lister-move-sublist-left"
1827 | (it "throws an error if no movement is possible:"
1828 | (lister-set-list ewoc '("0" "A" "B"))
1829 | (expect (lister-move-sublist-left ewoc 1)
1830 | :to-throw))
1831 | (it "moves sublist left:"
1832 | (lister-set-list ewoc '("0" ("A" "B")))
1833 | (lister-move-sublist-left ewoc 1)
1834 | (expect (lister-get-list ewoc)
1835 | :to-equal '("0" "A" "B"))))
1836 |
1837 | (describe "lister-move-sublist-right"
1838 | (it "moves sublist right:"
1839 | (lister-set-list ewoc '("0" ("A" "B")))
1840 | (lister-move-sublist-right ewoc 1)
1841 | (expect (lister-get-list ewoc)
1842 | :to-equal '("0" (("A" "B")))))))
1843 |
1844 | ;; -----------------------------------------------------------
1845 | ;; * Tests for Lister Mode
1846 | ;; -----------------------------------------------------------
1847 |
1848 | (describe "Lister mode"
1849 | (it "disables view mode if `view-read-only' is set"
1850 | (let* ((view-read-only t)
1851 | (ewoc (lister-test-setup-minimal-buffer))
1852 | (buf (ewoc-buffer ewoc)))
1853 | (with-current-buffer buf
1854 | (lister-mode +1)
1855 | (expect lister-mode :to-be-truthy)
1856 | (expect view-mode :not :to-be-truthy))
1857 | (kill-buffer buf))))
1858 |
1859 |
1860 | (provide 'lister-tests)
1861 | ;;; lister-tests.el ends here
1862 |
1863 | ;; Local Variables:
1864 | ;; eval: (flycheck-mode -1)
1865 | ;; End:
1866 |
--------------------------------------------------------------------------------