├── .gitignore
├── .travis.yml
├── LICENSE
├── Makefile
├── README.md
├── icons
├── close.xpm
├── leaf.xpm
└── open.xpm
├── neotree.el
├── screenshots
└── icons.png
└── test
├── neotree-test.el
├── test-buffer.el
├── test-cmds.el
├── test-utils.el
└── test-vc.el
/.gitignore:
--------------------------------------------------------------------------------
1 | *.elc
2 | ert.el
3 | *.tar.bz2
4 | *.tar
5 | *~
6 | \#*
7 | neotree-autoloads.el
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | # https://github.com/rolandwalker/emacs-travis
2 |
3 | language: emacs-lisp
4 |
5 | env:
6 | matrix:
7 | - EMACS=emacs24
8 | # - EMACS=emacs-snapshot
9 |
10 | install:
11 | - if [ "$EMACS" = "emacs24" ]; then
12 | sudo add-apt-repository -y ppa:cassou/emacs &&
13 | sudo apt-get update -qq &&
14 | sudo apt-get install -qq emacs24 emacs24-el;
15 | fi
16 | - if [ "$EMACS" = "emacs-snapshot" ]; then
17 | sudo add-apt-repository -y ppa:ubuntu-elisp/ppa &&
18 | sudo apt-get update -qq &&
19 | sudo apt-get install -qq emacs-snapshot;
20 | fi
21 |
22 | before_script:
23 | make downloads
24 |
25 | script:
26 | make test-batch EMACS=${EMACS}
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 | {one line to give the program's name and a brief idea of what it does.}
635 | Copyright (C) {year} {name of author}
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | {project} Copyright (C) {year} {fullname}
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | EMACS=emacs
2 | CURL=curl --silent
3 | ERT_URL=http://git.savannah.gnu.org/cgit/emacs.git/plain/lisp/emacs-lisp/ert.el?h=emacs-24.3
4 |
5 | .PHONY: ert test test-batch
6 |
7 | package: *.el
8 | @ver=`grep -o "Version: .*" neotree.el | cut -c 10-`; \
9 | tar cjvf neotree-$$ver.tar.bz2 --mode 644 `git ls-files '*.el' | xargs`
10 |
11 | clean:
12 | @rm -rf neotree-*/ neotree-*.tar neotree-*.tar.bz2 *.elc ert.el
13 |
14 | test: compile
15 | ${EMACS} -Q -nw -L . -L ./test \
16 | -l test/test-utils.el \
17 | -l test/test-cmds.el \
18 | -l test/test-buffer.el \
19 | -l test/test-vc.el \
20 | --eval "(let (pop-up-windows) (ert t))"
21 |
22 | test-batch: compile
23 | ${EMACS} -Q --batch -L . -L ./test \
24 | -l test/test-utils.el \
25 | --eval "(ert-run-tests-batch-and-exit '(not (tag interactive)))"
26 |
27 | downloads:
28 | ${EMACS} -Q --batch -l ert || \
29 | ${CURL} ${ERT_URL} > ert.el
30 |
31 | compile:
32 | ${EMACS} -Q --batch -L . -f batch-byte-compile neotree.el
33 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # emacs-neotree
2 |
3 | A Emacs tree plugin like NerdTree for Vim.
4 |
5 | [](https://travis-ci.org/jaypei/emacs-neotree)
6 | [](http://stable.melpa.org/#/neotree)
7 | [](https://melpa.org/#/neotree)
8 |
9 |
10 | ## Screenshots
11 |
12 | 
13 |
14 | ## Installation
15 |
16 | ### Melpa
17 |
18 | You can install the plugin using the packages on [melpa](http://melpa.org/).
19 |
20 | Make sure you have something like the following in your Emacs startup file (`~/.emacs.d/init.el`, or `~/.emacs`):
21 |
22 | ```elisp
23 | (add-to-list 'package-archives
24 | '("melpa" . "http://melpa.org/packages/"))
25 | ```
26 |
27 | To make that take effect, either evaluate that elisp expression or restart Emacs.
28 |
29 | Then use `M-x package-list-packages`, select `neotree` from
30 | the list by pressing `i`, then press `x` to execute the changes. At
31 | that point, the package will be installed.
32 |
33 |
34 | ### Source
35 |
36 | Clone project:
37 | ```sh
38 | $ cd /some/path
39 | $ git clone https://github.com/jaypei/emacs-neotree.git neotree
40 | $ cd neotree
41 | $ git checkout dev
42 | ```
43 |
44 | Add config to emacs:
45 |
46 | ```elisp
47 | (add-to-list 'load-path "/some/path/neotree")
48 | (require 'neotree)
49 | (global-set-key [f8] 'neotree-toggle)
50 | ```
51 |
52 | Open (toggle) NeoTree:
53 |
54 | ```
55 |
56 | ```
57 |
58 | ## Keybindings
59 |
60 | Only in Neotree Buffer:
61 |
62 | * `n` next line, `p` previous line。
63 | * `SPC` or `RET` or `TAB` Open current item if it is a file. Fold/Unfold current item if it is a directory.
64 | * `U` Go up a directory
65 | * `g` Refresh
66 | * `A` Maximize/Minimize the NeoTree Window
67 | * `H` Toggle display hidden files
68 | * `O` Recursively open a directory
69 | * `C-c C-n` Create a file or create a directory if filename ends with a ‘/’
70 | * `C-c C-d` Delete a file or a directory.
71 | * `C-c C-r` Rename a file or a directory.
72 | * `C-c C-c` Change the root directory.
73 | * `C-c C-p` Copy a file or a directory.
74 |
75 |
76 | ## Configurations
77 |
78 | ### Theme config
79 | NeoTree provides following themes:
80 | - *classic* (default)
81 | - *ascii*
82 | - *arrow*
83 | - *icons*[^1]
84 | - *nerd-icons*[^2]
85 | - *nerd*
86 |
87 | Theme can be configed by setting **neo-theme**. For example, use *icons* for window
88 | system and *arrow* terminal.
89 |
90 | ```elisp
91 | (setq neo-theme (if (display-graphic-p) 'icons 'arrow))
92 | ```
93 |
94 |
95 | * all-the-icons theme screenshots
96 | 
97 |
98 | ## More documentation
99 |
100 | EmacsWiki:
101 | [En](http://www.emacswiki.org/emacs/NeoTree)
102 | [中文版](http://www.emacswiki.org/emacs/NeoTree_%E4%B8%AD%E6%96%87wiki)
103 |
104 |
105 | [^1]: For users who want to use the `icons` theme. Please make sure you have installed the
106 | [all-the-icons](https://github.com/domtronn/all-the-icons.el) package and its
107 | [fonts](https://github.com/domtronn/all-the-icons.el/tree/master/fonts).
108 |
109 | [^2]: For users who want to use the `nerd-icons` theme. Please make sure you have installed the
110 | [nerd-icons](https://github.com/rainstormstudio/nerd-icons.el?tab=readme-ov-file) package and
111 | one of its [fonts](https://www.nerdfonts.com/).
112 |
--------------------------------------------------------------------------------
/icons/close.xpm:
--------------------------------------------------------------------------------
1 | /* XPM */
2 | static char * close_xpm[] = {
3 | "16 22 15 1",
4 | " c None",
5 | ". c #848400",
6 | "+ c #E7E79C",
7 | "@ c #E7E794",
8 | "# c #DEDE8C",
9 | "$ c #ADAD39",
10 | "% c #ADAD42",
11 | "& c #B5B54A",
12 | "* c #B5B552",
13 | "= c #BDBD5A",
14 | "- c #9C9C29",
15 | "; c #A5A531",
16 | "> c #C6C663",
17 | ", c #C6C66B",
18 | "' c #CECE73",
19 | " ",
20 | " ",
21 | " ",
22 | " ",
23 | " ",
24 | " ",
25 | " .... ",
26 | ".+@@#....... ",
27 | ".....$%%&&*=. ",
28 | ".-;;$%%&&*==. ",
29 | ".;;$%%&&*===. ",
30 | ".;$%%&&*===>. ",
31 | ".$%%&&*===>,. ",
32 | ".%%&&*===>,,. ",
33 | ".%&&*===>,,'. ",
34 | "............. ",
35 | " ",
36 | " ",
37 | " ",
38 | " ",
39 | " ",
40 | " "};
41 |
--------------------------------------------------------------------------------
/icons/leaf.xpm:
--------------------------------------------------------------------------------
1 | /* XPM */
2 | static char * leaf_xpm[] = {
3 | "16 22 9 1",
4 | " c None",
5 | ". c #424242",
6 | "+ c #949494",
7 | "@ c #9C9C9C",
8 | "# c #A5A5A5",
9 | "$ c #ADADAD",
10 | "% c #848484",
11 | "& c #B5B5B5",
12 | "* c #BDBDBD",
13 | " ",
14 | " ",
15 | " ",
16 | " ",
17 | " ",
18 | "....... ",
19 | ".++@@#.. ",
20 | ".+@@##.$. ",
21 | ".@@###.... ",
22 | ".@%%%+%$&. ",
23 | ".###$$$&&. ",
24 | ".#%+%%%&*. ",
25 | ".#$$$&&**. ",
26 | ".$%%+%%**. ",
27 | ".$$&&****. ",
28 | ".$&&*****. ",
29 | ".......... ",
30 | " ",
31 | " ",
32 | " ",
33 | " ",
34 | " "};
35 |
--------------------------------------------------------------------------------
/icons/open.xpm:
--------------------------------------------------------------------------------
1 | /* XPM */
2 | static char * open_xpm[] = {
3 | "16 22 14 1",
4 | " c None",
5 | ". c #848400",
6 | "+ c #D6D67B",
7 | "@ c #CECE7B",
8 | "# c #CECE73",
9 | "$ c #C6C66B",
10 | "% c #BDBD5A",
11 | "& c #BDBD52",
12 | "* c #ADAD39",
13 | "= c #ADAD42",
14 | "- c #B5B54A",
15 | "; c #C6C663",
16 | "> c #CECE6B",
17 | ", c #A5A5C6",
18 | " ",
19 | " ",
20 | " ",
21 | " ",
22 | " ",
23 | " ",
24 | " .... ",
25 | ".+@@#..... ",
26 | ".@@##$$%%&. ",
27 | ".@#.......... ",
28 | ".#.*==--&%%;;. ",
29 | ".#.==--&%%;;. ",
30 | "..==--&%%;;$. ",
31 | "..=--&%%;;$. ",
32 | ".=--&%%;;$>. ",
33 | "........... ",
34 | " ",
35 | " ",
36 | " ",
37 | " ",
38 | " ",
39 | " "};
40 |
--------------------------------------------------------------------------------
/neotree.el:
--------------------------------------------------------------------------------
1 | ;;; neotree.el --- A tree plugin like NerdTree for Vim
2 |
3 | ;; Copyright (C) 2014 jaypei
4 |
5 | ;; Author: jaypei
6 | ;; URL: https://github.com/jaypei/emacs-neotree
7 | ;; Version: 0.6.0
8 | ;; Package-Requires: ((cl-lib "0.5"))
9 |
10 | ;; This program is free software; you can redistribute it and/or modify
11 | ;; it under the terms of the GNU General Public License as published by
12 | ;; the Free Software Foundation, either version 3 of the License, or
13 | ;; (at your option) any later version.
14 |
15 | ;; This program is distributed in the hope that it will be useful,
16 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 | ;; GNU General Public License for more details.
19 |
20 | ;; You should have received a copy of the GNU General Public License
21 | ;; along with this program. If not, see .
22 |
23 | ;;; Commentary:
24 |
25 | ;; To use this file, put something like the following in your
26 | ;; ~/.emacs:
27 | ;;
28 | ;; (add-to-list 'load-path "/directory/containing/neotree/")
29 | ;; (require 'neotree)
30 | ;;
31 | ;; Type M-x neotree to start.
32 | ;;
33 | ;; To set options for NeoTree, type M-x customize, then select
34 | ;; Applications, NeoTree.
35 | ;;
36 |
37 | ;;; Code:
38 |
39 | (require 'cl-lib)
40 |
41 | ;;
42 | ;; Constants
43 | ;;
44 |
45 | (defconst neo-buffer-name " *NeoTree*"
46 | "Name of the buffer where neotree shows directory contents.")
47 |
48 | (defconst neo-dir
49 | (expand-file-name (if load-file-name
50 | (file-name-directory load-file-name)
51 | default-directory)))
52 |
53 | (defconst neo-header-height 5)
54 |
55 | (eval-and-compile
56 |
57 | ;; Added in Emacs 24.3
58 | (unless (fboundp 'user-error)
59 | (defalias 'user-error 'error))
60 |
61 | ;; Added in Emacs 24.3 (mirrors/emacs@b335efc3).
62 | (unless (fboundp 'setq-local)
63 | (defmacro setq-local (var val)
64 | "Set variable VAR to value VAL in current buffer."
65 | (list 'set (list 'make-local-variable (list 'quote var)) val)))
66 |
67 | ;; Added in Emacs 24.3 (mirrors/emacs@b335efc3).
68 | (unless (fboundp 'defvar-local)
69 | (defmacro defvar-local (var val &optional docstring)
70 | "Define VAR as a buffer-local variable with default value VAL.
71 | Like `defvar' but additionally marks the variable as being automatically
72 | buffer-local wherever it is set."
73 | (declare (debug defvar) (doc-string 3))
74 | (list 'progn (list 'defvar var val docstring)
75 | (list 'make-variable-buffer-local (list 'quote var))))))
76 |
77 | ;; Add autoload function for vc (#153).
78 | (autoload 'vc-responsible-backend "vc.elc")
79 |
80 | ;;
81 | ;; Macros
82 | ;;
83 |
84 | (defmacro neo-util--to-bool (obj)
85 | "If OBJ is non-nil, return t, else return nil."
86 | `(and ,obj t))
87 |
88 | (defmacro neo-global--with-buffer (&rest body)
89 | "Execute the forms in BODY with global NeoTree buffer."
90 | (declare (indent 0) (debug t))
91 | `(let ((neotree-buffer (neo-global--get-buffer)))
92 | (unless (null neotree-buffer)
93 | (with-current-buffer neotree-buffer
94 | ,@body))))
95 |
96 | (defmacro neo-global--with-window (&rest body)
97 | "Execute the forms in BODY with global NeoTree window."
98 | (declare (indent 0) (debug t))
99 | `(save-selected-window
100 | (neo-global--select-window)
101 | ,@body))
102 |
103 | (defmacro neo-global--when-window (&rest body)
104 | "Execute the forms in BODY when selected window is NeoTree window."
105 | (declare (indent 0) (debug t))
106 | `(when (eq (selected-window) neo-global--window)
107 | ,@body))
108 |
109 | (defmacro neo-global--switch-to-buffer ()
110 | "Switch to NeoTree buffer."
111 | `(let ((neotree-buffer (neo-global--get-buffer)))
112 | (unless (null neotree-buffer)
113 | (switch-to-buffer neotree-buffer))))
114 |
115 | (defmacro neo-buffer--with-editing-buffer (&rest body)
116 | "Execute BODY in neotree buffer without read-only restriction."
117 | `(let (rlt)
118 | (neo-global--with-buffer
119 | (setq buffer-read-only nil)
120 | (setq rlt (progn ,@body))
121 | (setq buffer-read-only t))
122 | rlt))
123 |
124 | (defmacro neo-buffer--with-resizable-window (&rest body)
125 | "Execute BODY in neotree window without `window-size-fixed' restriction."
126 | `(let (rlt)
127 | (neo-global--with-buffer
128 | (neo-buffer--unlock-width))
129 | (setq rlt (progn ,@body))
130 | (neo-global--with-buffer
131 | (neo-buffer--lock-width))
132 | rlt))
133 |
134 | (defmacro neotree-make-executor (&rest fn-form)
135 | "Make an open event handler, FN-FORM is event handler form."
136 | (let* ((get-args-fn
137 | (lambda (sym) (or (plist-get fn-form sym) (lambda (&rest _)))))
138 | (file-fn (funcall get-args-fn :file-fn))
139 | (dir-fn (funcall get-args-fn :dir-fn)))
140 | `(lambda (&optional arg)
141 | (interactive "P")
142 | (neo-global--select-window)
143 | (neo-buffer--execute arg ,file-fn ,dir-fn))))
144 |
145 |
146 | ;;
147 | ;; Customization
148 | ;;
149 |
150 | (defgroup neotree nil
151 | "Options for neotree."
152 | :prefix "neo-"
153 | :group 'files)
154 |
155 | (defgroup neotree-vc-options nil
156 | "Neotree-VC customizations."
157 | :prefix "neo-vc-"
158 | :group 'neotree
159 | :link '(info-link "(neotree)Configuration"))
160 |
161 | (defgroup neotree-confirmations nil
162 | "Neotree confirmation customizations."
163 | :prefix "neo-confirm-"
164 | :group 'neotree)
165 |
166 | (defcustom neo-window-position 'left
167 | "*The position of NeoTree window."
168 | :group 'neotree
169 | :type '(choice (const left)
170 | (const right)))
171 |
172 | (defcustom neo-display-action '(neo-default-display-fn)
173 | "*Action to use for displaying NeoTree window.
174 | If you change the action so it doesn't use
175 | `neo-default-display-fn', then other variables such as
176 | `neo-window-position' won't be respected when opening NeoTree
177 | window."
178 | :type 'sexp
179 | :group 'neotree)
180 |
181 | (defcustom neo-create-file-auto-open nil
182 | "*If non-nil, the file will auto open when created."
183 | :type 'boolean
184 | :group 'neotree)
185 |
186 | (defcustom neo-banner-message nil
187 | "*The banner message of neotree window."
188 | :type 'string
189 | :group 'neotree)
190 |
191 | (defcustom neo-show-updir-line t
192 | "*If non-nil, show the updir line (..)."
193 | :type 'boolean
194 | :group 'neotree)
195 |
196 | (defcustom neo-show-slash-for-folder t
197 | "*If non-nil, show the slash at the end of folder (folder/)"
198 | :type 'boolean
199 | :group 'neotree)
200 |
201 | (defcustom neo-reset-size-on-open nil
202 | "*If non-nil, the width of the noetree window will be reseted every time a file is open."
203 | :type 'boolean
204 | :group 'neotree)
205 |
206 | (defcustom neo-theme 'classic
207 | "*The tree style to display.
208 | `classic' use icon to display, it only it suitable for GUI mode.
209 | `ascii' is the simplest style, it will use +/- to display the fold state,
210 | it suitable for terminal.
211 | `arrow' use unicode arrow.
212 | `nerd' use the nerdtree indentation mode and arrow.
213 | `icons' use icons from `all-the-icons' when installed.
214 | `nerd-icons' use icons from `nerd-icons' when installed."
215 | :group 'neotree
216 | :type '(choice (const classic)
217 | (const ascii)
218 | (const arrow)
219 | (const icons)
220 | (const nerd-icons)
221 | (const nerd)))
222 |
223 | (defcustom neo-mode-line-type 'neotree
224 | "*The mode-line type to display, `default' is a non-modified mode-line, \
225 | `neotree' is a compact mode-line that shows useful information about the
226 | current node like the parent directory and the number of nodes,
227 | `custom' uses the format stored in `neo-mode-line-custom-format',
228 | `none' hide the mode-line."
229 | :group 'neotree
230 | :type '(choice (const default)
231 | (const neotree)
232 | (const custom)
233 | (const none)))
234 |
235 | (defcustom neo-mode-line-custom-format nil
236 | "*If `neo-mode-line-type' is set to `custom', this variable specifiy \
237 | the mode-line format."
238 | :type 'sexp
239 | :group 'neotree)
240 |
241 | (defcustom neo-smart-open nil
242 | "*If non-nil, every time when the neotree window is opened, it will try to find current file and jump to node."
243 | :type 'boolean
244 | :group 'neotree)
245 |
246 | (defcustom neo-show-hidden-files nil
247 | "*If non-nil, the hidden files are shown by default."
248 | :type 'boolean
249 | :group 'neotree)
250 |
251 | (defcustom neo-autorefresh nil
252 | "*If non-nil, the neotree buffer will auto refresh."
253 | :type 'boolean
254 | :group 'neotree)
255 |
256 | (defcustom neo-window-width 25
257 | "*Specifies the width of the NeoTree window."
258 | :type 'integer
259 | :group 'neotree)
260 |
261 | (defcustom neo-window-fixed-size t
262 | "*If the neotree windows is fixed, it won't be resize when rebalance windows."
263 | :type 'boolean
264 | :group 'neotree)
265 |
266 | (defcustom neo-keymap-style 'default
267 | "*The default keybindings for neotree-mode-map."
268 | :group 'neotree
269 | :type '(choice (const default)
270 | (const concise)))
271 |
272 | (defcustom neo-cwd-line-style 'text
273 | "*The default header style."
274 | :group 'neotree
275 | :type '(choice (const text)
276 | (const button)))
277 |
278 | (defcustom neo-help-echo-style 'default
279 | "The message NeoTree displays when the mouse moves onto nodes.
280 | `default' means the node name is displayed if it has a
281 | width (including the indent) larger than `neo-window-width', and
282 | `none' means NeoTree doesn't display any messages."
283 | :group 'neotree
284 | :type '(choice (const default)
285 | (const none)))
286 |
287 | (defcustom neo-click-changes-root nil
288 | "*If non-nil, clicking on a directory will change the current root to the directory."
289 | :type 'boolean
290 | :group 'neotree)
291 |
292 | (defcustom neo-auto-indent-point nil
293 | "*If non-nil the point is autmotically put on the first letter of a node."
294 | :type 'boolean
295 | :group 'neotree)
296 |
297 | (defcustom neo-hidden-regexp-list
298 | '("^\\." "\\.pyc$" "~$" "^#.*#$" "\\.elc$" "\\.o$")
299 | "*The regexp list matching hidden files."
300 | :type '(repeat (choice regexp))
301 | :group 'neotree)
302 |
303 | (defcustom neo-enter-hook nil
304 | "Functions to run if enter node occured."
305 | :type 'hook
306 | :group 'neotree)
307 |
308 | (defcustom neo-after-create-hook nil
309 | "Hooks called after creating the neotree buffer."
310 | :type 'hook
311 | :group 'neotree)
312 |
313 | (defcustom neo-vc-integration nil
314 | "If non-nil, show VC status."
315 | :group 'neotree-vc
316 | :type '(set (const :tag "Use different faces" face)
317 | (const :tag "Use different characters" char)))
318 |
319 | (defcustom neo-vc-state-char-alist
320 | '((up-to-date . ?\s)
321 | (edited . ?E)
322 | (added . ?+)
323 | (removed . ?-)
324 | (missing . ?!)
325 | (needs-merge . ?M)
326 | (conflict . ?!)
327 | (unlocked-changes . ?!)
328 | (needs-update . ?U)
329 | (ignored . ?\s)
330 | (user . ?U)
331 | (unregistered . ?\s)
332 | (nil . ?\s))
333 | "Alist of vc-states to indicator characters.
334 | This variable is used in `neo-vc-for-node' when
335 | `neo-vc-integration' contains `char'."
336 | :group 'neotree-vc
337 | :type '(alist :key-type symbol
338 | :value-type character))
339 |
340 | (defcustom neo-confirm-change-root 'yes-or-no-p
341 | "Confirmation asking for permission to change root if file was not found in root path."
342 | :type '(choice (function-item :tag "Verbose" yes-or-no-p)
343 | (function-item :tag "Succinct" y-or-n-p)
344 | (function-item :tag "Off" off-p))
345 | :group 'neotree-confirmations)
346 |
347 | (defcustom neo-confirm-create-file 'yes-or-no-p
348 | "Confirmation asking whether *NeoTree* should create a file."
349 | :type '(choice (function-item :tag "Verbose" yes-or-no-p)
350 | (function-item :tag "Succinct" y-or-n-p)
351 | (function-item :tag "Off" off-p))
352 | :group 'neotree-confirmations)
353 |
354 | (defcustom neo-confirm-create-directory 'yes-or-no-p
355 | "Confirmation asking whether *NeoTree* should create a directory."
356 | :type '(choice (function-item :tag "Verbose" yes-or-no-p)
357 | (function-item :tag "Succinct" y-or-n-p)
358 | (function-item :tag "Off" off-p))
359 | :group 'neotree-confirmations)
360 |
361 | (defcustom neo-confirm-delete-file 'yes-or-no-p
362 | "Confirmation asking whether *NeoTree* should delete the file."
363 | :type '(choice (function-item :tag "Verbose" yes-or-no-p)
364 | (function-item :tag "Succinct" y-or-n-p)
365 | (function-item :tag "Off" off-p))
366 | :group 'neotree-confirmations)
367 |
368 | (defcustom neo-confirm-delete-directory-recursively 'yes-or-no-p
369 | "Confirmation asking whether the directory should be deleted recursively."
370 | :type '(choice (function-item :tag "Verbose" yes-or-no-p)
371 | (function-item :tag "Succinct" y-or-n-p)
372 | (function-item :tag "Off" off-p))
373 | :group 'neotree-confirmations)
374 |
375 | (defcustom neo-confirm-kill-buffers-for-files-in-directory 'yes-or-no-p
376 | "Confirmation asking whether *NeoTree* should kill buffers for the directory in question."
377 | :type '(choice (function-item :tag "Verbose" yes-or-no-p)
378 | (function-item :tag "Succinct" y-or-n-p)
379 | (function-item :tag "Off" off-p))
380 | :group 'neotree-confirmations)
381 |
382 | (defcustom neo-toggle-window-keep-p nil
383 | "If not nil, not switch to *NeoTree* buffer when executing `neotree-toggle'."
384 | :type 'boolean
385 | :group 'neotree)
386 |
387 | (defcustom neo-force-change-root t
388 | "If not nil, do not prompt when switching root."
389 | :type 'boolean
390 | :group 'neotree)
391 |
392 | (defcustom neo-filepath-sort-function 'string<
393 | "Function to be called when sorting neotree nodes."
394 | :type '(symbol (const :tag "Normal" string<)
395 | (const :tag "Sort Hidden at Bottom" neo-sort-hidden-last)
396 | (function :tag "Other"))
397 | :group 'neotree)
398 |
399 | (defcustom neo-default-system-application "xdg-open"
400 | "*Name of the application that is used to open a file under point.
401 | By default it is xdg-open."
402 | :type 'string
403 | :group 'neotree)
404 |
405 | (defcustom neo-hide-cursor nil
406 | "If not nil, hide cursor in NeoTree buffer and turn on line higlight."
407 | :type 'boolean
408 | :group 'neotree)
409 |
410 | ;;
411 | ;; Faces
412 | ;;
413 |
414 | (defface neo-banner-face
415 | '((((background dark)) (:foreground "lightblue" :weight bold))
416 | (t (:foreground "DarkMagenta")))
417 | "*Face used for the banner in neotree buffer."
418 | :group 'neotree :group 'font-lock-highlighting-faces)
419 | (defvar neo-banner-face 'neo-banner-face)
420 |
421 | (defface neo-header-face
422 | '((((background dark)) (:foreground "White"))
423 | (t (:foreground "DarkMagenta")))
424 | "*Face used for the header in neotree buffer."
425 | :group 'neotree :group 'font-lock-highlighting-faces)
426 | (defvar neo-header-face 'neo-header-face)
427 |
428 | (defface neo-root-dir-face
429 | '((((background dark)) (:foreground "lightblue" :weight bold))
430 | (t (:foreground "DarkMagenta")))
431 | "*Face used for the root dir in neotree buffer."
432 | :group 'neotree :group 'font-lock-highlighting-faces)
433 | (defvar neo-root-dir-face 'neo-root-dir-face)
434 |
435 | (defface neo-dir-link-face
436 | '((((background dark)) (:foreground "DeepSkyBlue"))
437 | (t (:foreground "MediumBlue")))
438 | "*Face used for expand sign [+] in neotree buffer."
439 | :group 'neotree :group 'font-lock-highlighting-faces)
440 | (defvar neo-dir-link-face 'neo-dir-link-face)
441 |
442 | (defface neo-file-link-face
443 | '((((background dark)) (:foreground "White"))
444 | (t (:foreground "Black")))
445 | "*Face used for open file/dir in neotree buffer."
446 | :group 'neotree :group 'font-lock-highlighting-faces)
447 | (defvar neo-file-link-face 'neo-file-link-face)
448 |
449 | (defface neo-button-face
450 | '((t (:underline nil)))
451 | "*Face used for open file/dir in neotree buffer."
452 | :group 'neotree :group 'font-lock-highlighting-faces)
453 | (defvar neo-button-face 'neo-button-face)
454 |
455 | (defface neo-expand-btn-face
456 | '((((background dark)) (:foreground "SkyBlue"))
457 | (t (:foreground "DarkCyan")))
458 | "*Face used for open file/dir in neotree buffer."
459 | :group 'neotree :group 'font-lock-highlighting-faces)
460 | (defvar neo-expand-btn-face 'neo-expand-btn-face)
461 |
462 | (defface neo-vc-default-face
463 | '((((background dark)) (:foreground "White"))
464 | (t (:foreground "Black")))
465 | "*Face used for unknown files in the neotree buffer.
466 | Used only when \(vc-state node\) returns nil."
467 | :group 'neotree-vc :group 'font-lock-highlighting-faces)
468 | (defvar neo-vc-default-face 'neo-vc-default-face)
469 |
470 | (defface neo-vc-user-face
471 | '((t (:foreground "Red" :slant italic)))
472 | "*Face used for user-locked files in the neotree buffer."
473 | :group 'neotree-vc :group 'font-lock-highlighting-faces)
474 | (defvar neo-vc-user-face 'neo-vc-user-face)
475 |
476 | (defface neo-vc-up-to-date-face
477 | '((((background dark)) (:foreground "LightGray"))
478 | (t (:foreground "DarkGray")))
479 | "*Face used for vc-up-to-date files in the neotree buffer."
480 | :group 'neotree-vc :group 'font-lock-highlighting-faces)
481 | (defvar neo-vc-up-to-date-face 'neo-vc-up-to-date-face)
482 |
483 | (defface neo-vc-edited-face
484 | '((((background dark)) (:foreground "Magenta"))
485 | (t (:foreground "DarkMagenta")))
486 | "*Face used for vc-edited files in the neotree buffer."
487 | :group 'neotree-vc :group 'font-lock-highlighting-faces)
488 | (defvar neo-vc-edited-face 'neo-vc-edited-face)
489 |
490 | (defface neo-vc-needs-update-face
491 | '((t (:underline t)))
492 | "*Face used for vc-needs-update files in the neotree buffer."
493 | :group 'neotree-vc :group 'font-lock-highlighting-faces)
494 | (defvar neo-vc-needs-update-face 'neo-vc-needs-update-face)
495 |
496 | (defface neo-vc-needs-merge-face
497 | '((((background dark)) (:foreground "Red1"))
498 | (t (:foreground "Red3")))
499 | "*Face used for vc-needs-merge files in the neotree buffer."
500 | :group 'neotree-vc :group 'font-lock-highlighting-faces)
501 | (defvar neo-vc-needs-merge-face 'neo-vc-needs-merge-face)
502 |
503 | (defface neo-vc-unlocked-changes-face
504 | '((t (:foreground "Red" :background "Blue")))
505 | "*Face used for vc-unlocked-changes files in the neotree buffer."
506 | :group 'neotree-vc :group 'font-lock-highlighting-faces)
507 | (defvar neo-vc-unlocked-changes-face 'neo-vc-unlocked-changes-face)
508 |
509 | (defface neo-vc-added-face
510 | '((((background dark)) (:foreground "LightGreen"))
511 | (t (:foreground "DarkGreen")))
512 | "*Face used for vc-added files in the neotree buffer."
513 | :group 'neotree-vc :group 'font-lock-highlighting-faces)
514 | (defvar neo-vc-added-face 'neo-vc-added-face)
515 |
516 | (defface neo-vc-removed-face
517 | '((t (:strike-through t)))
518 | "*Face used for vc-removed files in the neotree buffer."
519 | :group 'neotree-vc :group 'font-lock-highlighting-faces)
520 | (defvar neo-vc-removed-face 'neo-vc-removed-face)
521 |
522 | (defface neo-vc-conflict-face
523 | '((((background dark)) (:foreground "Red1"))
524 | (t (:foreground "Red3")))
525 | "*Face used for vc-conflict files in the neotree buffer."
526 | :group 'neotree-vc :group 'font-lock-highlighting-faces)
527 | (defvar neo-vc-conflict-face 'neo-vc-conflict-face)
528 |
529 | (defface neo-vc-missing-face
530 | '((((background dark)) (:foreground "Red1"))
531 | (t (:foreground "Red3")))
532 | "*Face used for vc-missing files in the neotree buffer."
533 | :group 'neotree-vc :group 'font-lock-highlighting-faces)
534 | (defvar neo-vc-missing-face 'neo-vc-missing-face)
535 |
536 | (defface neo-vc-ignored-face
537 | '((((background dark)) (:foreground "DarkGrey"))
538 | (t (:foreground "LightGray")))
539 | "*Face used for vc-ignored files in the neotree buffer."
540 | :group 'neotree-vc :group 'font-lock-highlighting-faces)
541 | (defvar neo-vc-ignored-face 'neo-vc-ignored-face)
542 |
543 | (defface neo-vc-unregistered-face
544 | nil
545 | "*Face used for vc-unregistered files in the neotree buffer."
546 | :group 'neotree-vc :group 'font-lock-highlighting-faces)
547 | (defvar neo-vc-unregistered-face 'neo-vc-unregistered-face)
548 |
549 | ;;
550 | ;; Variables
551 | ;;
552 |
553 | (defvar neo-global--buffer nil)
554 |
555 | (defvar neo-global--window nil)
556 |
557 | (defvar neo-global--autorefresh-timer nil)
558 |
559 | (defvar neo-mode-line-format
560 | (list
561 | '(:eval
562 | (let* ((fname (neo-buffer--get-filename-current-line))
563 | (current (if fname fname neo-buffer--start-node))
564 | (parent (if fname (file-name-directory current) current))
565 | (nodes (neo-buffer--get-nodes parent))
566 | (dirs (car nodes))
567 | (files (cdr nodes))
568 | (ndirs (length dirs))
569 | (nfiles (length files))
570 | (index
571 | (when fname
572 | (1+ (if (file-directory-p current)
573 | (neo-buffer--get-node-index current dirs)
574 | (+ ndirs (neo-buffer--get-node-index current files)))))))
575 | (neo-mode-line--compute-format parent index ndirs nfiles))))
576 | "Neotree mode-line displaying information on the current node.
577 | This mode-line format is used if `neo-mode-line-type' is set to `neotree'")
578 |
579 | (defvar-local neo-buffer--start-node nil
580 | "Start node(i.e. directory) for the window.")
581 |
582 | (defvar-local neo-buffer--start-line nil
583 | "Index of the start line of the root.")
584 |
585 | (defvar-local neo-buffer--cursor-pos (cons nil 1)
586 | "To save the cursor position.
587 | The car of the pair will store fullpath, and cdr will store line number.")
588 |
589 | (defvar-local neo-buffer--last-window-pos (cons nil 1)
590 | "To save the scroll position for NeoTree window.")
591 |
592 | (defvar-local neo-buffer--show-hidden-file-p nil
593 | "Show hidden nodes in tree.")
594 |
595 | (defvar-local neo-buffer--expanded-node-list nil
596 | "A list of expanded dir nodes.")
597 |
598 | (defvar-local neo-buffer--node-list nil
599 | "The model of current NeoTree buffer.")
600 |
601 | (defvar-local neo-buffer--node-list-1 nil
602 | "The model of current NeoTree buffer (temp).")
603 |
604 | ;;
605 | ;; Major mode definitions
606 | ;;
607 |
608 | (defvar neotree-file-button-keymap
609 | (let ((map (make-sparse-keymap)))
610 | (define-key map [mouse-2]
611 | (neotree-make-executor
612 | :file-fn 'neo-open-file))
613 | map)
614 | "Keymap for file-node button.")
615 |
616 | (defvar neotree-dir-button-keymap
617 | (let ((map (make-sparse-keymap)))
618 | (define-key map [mouse-2]
619 | (neotree-make-executor :dir-fn 'neo-open-dir))
620 | map)
621 | "Keymap for dir-node button.")
622 |
623 | (defvar neotree-mode-map
624 | (let ((map (make-sparse-keymap)))
625 | (define-key map (kbd "TAB") (neotree-make-executor
626 | :dir-fn 'neo-open-dir))
627 | (define-key map (kbd "RET") (neotree-make-executor
628 | :file-fn 'neo-open-file
629 | :dir-fn 'neo-open-dir))
630 | (define-key map (kbd "|") (neotree-make-executor
631 | :file-fn 'neo-open-file-vertical-split))
632 | (define-key map (kbd "-") (neotree-make-executor
633 | :file-fn 'neo-open-file-horizontal-split))
634 | (define-key map (kbd "a") (neotree-make-executor
635 | :file-fn 'neo-open-file-ace-window))
636 | (define-key map (kbd "d") (neotree-make-executor
637 | :dir-fn 'neo-open-dired))
638 | (define-key map (kbd "O") (neotree-make-executor
639 | :dir-fn 'neo-open-dir-recursive))
640 | (define-key map (kbd "SPC") 'neotree-quick-look)
641 | (define-key map (kbd "g") 'neotree-refresh)
642 | (define-key map (kbd "q") 'neotree-hide)
643 | (define-key map (kbd "p") 'neotree-previous-line)
644 | (define-key map (kbd "C-p") 'neotree-previous-line)
645 | (define-key map (kbd "n") 'neotree-next-line)
646 | (define-key map (kbd "C-n") 'neotree-next-line)
647 | (define-key map (kbd "A") 'neotree-stretch-toggle)
648 | (define-key map (kbd "U") 'neotree-select-up-node)
649 | (define-key map (kbd "D") 'neotree-select-down-node)
650 | (define-key map (kbd "H") 'neotree-hidden-file-toggle)
651 | (define-key map (kbd "S") 'neotree-select-previous-sibling-node)
652 | (define-key map (kbd "s") 'neotree-select-next-sibling-node)
653 | (define-key map (kbd "o") 'neotree-open-file-in-system-application)
654 | (define-key map (kbd "C-x C-f") 'find-file-other-window)
655 | (define-key map (kbd "C-x 1") 'neotree-empty-fn)
656 | (define-key map (kbd "C-x 2") 'neotree-empty-fn)
657 | (define-key map (kbd "C-x 3") 'neotree-empty-fn)
658 | (define-key map (kbd "C-c C-f") 'find-file-other-window)
659 | (define-key map (kbd "C-c C-c") 'neotree-change-root)
660 | (define-key map (kbd "C-c c") 'neotree-dir)
661 | (define-key map (kbd "C-c C-a") 'neotree-collapse-all)
662 | (cond
663 | ((eq neo-keymap-style 'default)
664 | (define-key map (kbd "C-c C-n") 'neotree-create-node)
665 | (define-key map (kbd "C-c C-d") 'neotree-delete-node)
666 | (define-key map (kbd "C-c C-r") 'neotree-rename-node)
667 | (define-key map (kbd "C-c C-p") 'neotree-copy-node))
668 | ((eq neo-keymap-style 'concise)
669 | (define-key map (kbd "C") 'neotree-change-root)
670 | (define-key map (kbd "c") 'neotree-create-node)
671 | (define-key map (kbd "+") 'neotree-create-node)
672 | (define-key map (kbd "d") 'neotree-delete-node)
673 | (define-key map (kbd "r") 'neotree-rename-node)
674 | (define-key map (kbd "e") 'neotree-enter)))
675 | map)
676 | "Keymap for `neotree-mode'.")
677 |
678 | (define-derived-mode neotree-mode special-mode "NeoTree"
679 | "A major mode for displaying the directory tree in text mode."
680 | (setq indent-tabs-mode nil ; only spaces
681 | buffer-read-only t ; read only
682 | truncate-lines -1
683 | neo-buffer--show-hidden-file-p neo-show-hidden-files)
684 | (when neo-hide-cursor
685 | (progn
686 | (setq cursor-type nil)
687 | (hl-line-mode +1)))
688 | (pcase neo-mode-line-type
689 | (`neotree
690 | (setq-local mode-line-format neo-mode-line-format)
691 | (add-hook 'post-command-hook 'force-mode-line-update nil t))
692 | (`none (setq-local mode-line-format nil))
693 | (`custom
694 | (setq-local mode-line-format neo-mode-line-custom-format)
695 | (add-hook 'post-command-hook 'force-mode-line-update nil t))
696 | (_ nil))
697 | ;; fix for electric-indent-mode
698 | ;; for emacs 24.4
699 | (if (fboundp 'electric-indent-local-mode)
700 | (electric-indent-local-mode -1)
701 | ;; for emacs 24.3 or less
702 | (add-hook 'electric-indent-functions
703 | (lambda (arg) 'no-indent) nil 'local))
704 | (when neo-auto-indent-point
705 | (add-hook 'post-command-hook 'neo-hook--node-first-letter nil t)))
706 |
707 | ;;
708 | ;; Global methods
709 | ;;
710 |
711 | (defun neo-global--window-exists-p ()
712 | "Return non-nil if neotree window exists."
713 | (and (not (null (window-buffer neo-global--window)))
714 | (eql (window-buffer neo-global--window) (neo-global--get-buffer))))
715 |
716 | (defun neo-global--select-window ()
717 | "Select the NeoTree window."
718 | (interactive)
719 | (let ((window (neo-global--get-window t)))
720 | (select-window window)))
721 |
722 | (defun neo-global--get-window (&optional auto-create-p)
723 | "Return the neotree window if it exists, else return nil.
724 | But when the neotree window does not exist and AUTO-CREATE-P is non-nil,
725 | it will create the neotree window and return it."
726 | (unless (neo-global--window-exists-p)
727 | (setf neo-global--window nil))
728 | (when (and (null neo-global--window)
729 | auto-create-p)
730 | (setq neo-global--window
731 | (neo-global--create-window)))
732 | neo-global--window)
733 |
734 | (defun neo-default-display-fn (buffer _alist)
735 | "Display BUFFER to the left or right of the root window.
736 | The side is decided according to `neo-window-position'.
737 | The root window is the root window of the selected frame.
738 | _ALIST is ignored."
739 | (let ((window-pos (if (eq neo-window-position 'left) 'left 'right)))
740 | (display-buffer-in-side-window buffer `((side . ,window-pos)))))
741 |
742 | (defun neo-global--create-window ()
743 | "Create global neotree window."
744 | (let ((window nil)
745 | (buffer (neo-global--get-buffer t)))
746 | (setq window
747 | (select-window
748 | (display-buffer buffer neo-display-action)))
749 | (neo-window--init window buffer)
750 | (neo-global--attach)
751 | (neo-global--reset-width)
752 | window))
753 |
754 | (defun neo-global--get-buffer (&optional init-p)
755 | "Return the global neotree buffer if it exists.
756 | If INIT-P is non-nil and global NeoTree buffer not exists, then create it."
757 | (unless (equal (buffer-name neo-global--buffer)
758 | neo-buffer-name)
759 | (setf neo-global--buffer nil))
760 | (when (and init-p
761 | (null neo-global--buffer))
762 | (save-window-excursion
763 | (setq neo-global--buffer
764 | (neo-buffer--create))))
765 | neo-global--buffer)
766 |
767 | (defun neo-global--file-in-root-p (path)
768 | "Return non-nil if PATH in root dir."
769 | (neo-global--with-buffer
770 | (and (not (null neo-buffer--start-node))
771 | (neo-path--file-in-directory-p path neo-buffer--start-node))))
772 |
773 | (defun neo-global--alone-p ()
774 | "Check whether the global neotree window is alone with some other window."
775 | (let ((windows (window-list)))
776 | (and (= (length windows)
777 | 2)
778 | (member neo-global--window windows))))
779 |
780 | (defun neo-global--do-autorefresh ()
781 | "Do auto refresh."
782 | (interactive)
783 | (when (and neo-autorefresh (neo-global--window-exists-p)
784 | (buffer-file-name))
785 | (neotree-refresh t)))
786 |
787 | (defun neo-global--open ()
788 | "Show the NeoTree window."
789 | (let ((valid-start-node-p nil))
790 | (neo-global--with-buffer
791 | (setf valid-start-node-p (neo-buffer--valid-start-node-p)))
792 | (if (not valid-start-node-p)
793 | (neo-global--open-dir (neo-path--get-working-dir))
794 | (neo-global--get-window t))))
795 |
796 | (defun neo-global--open-dir (path)
797 | "Show the NeoTree window, and change root to PATH."
798 | (neo-global--get-window t)
799 | (neo-global--with-buffer
800 | (neo-buffer--change-root path)))
801 |
802 | (defun neo-global--open-and-find (path)
803 | "Quick select node which specified PATH in NeoTree."
804 | (let ((npath path)
805 | root-dir)
806 | (when (null npath)
807 | (throw 'invalid-path "Invalid path to select."))
808 | (setq root-dir (if (file-directory-p npath)
809 | npath (neo-path--updir npath)))
810 | (when (or (not (neo-global--window-exists-p))
811 | (not (neo-global--file-in-root-p npath)))
812 | (neo-global--open-dir root-dir))
813 | (neo-global--with-window
814 | (neo-buffer--select-file-node npath t))))
815 |
816 | (defun neo-global--select-mru-window (arg)
817 | "Create or find a window to select when open a file node.
818 | The description of ARG is in `neotree-enter'."
819 | (when (eq (safe-length (window-list)) 1)
820 | (neo-buffer--with-resizable-window
821 | (split-window-horizontally)))
822 | (when neo-reset-size-on-open
823 | (neo-global--when-window
824 | (neo-window--zoom 'minimize)))
825 | ;; select target window
826 | (cond
827 | ;; select window with winum
828 | ((and (integerp arg)
829 | (bound-and-true-p winum-mode)
830 | (fboundp 'winum-select-window-by-number))
831 | (winum-select-window-by-number arg))
832 | ;; select window with window numbering
833 | ((and (integerp arg)
834 | (boundp 'window-numbering-mode)
835 | (symbol-value window-numbering-mode)
836 | (fboundp 'select-window-by-number))
837 | (select-window-by-number arg))
838 | ;; open node in a new vertically split window
839 | ((and (stringp arg) (string= arg "a")
840 | (fboundp 'ace-select-window))
841 | (ace-select-window))
842 | ((and (stringp arg) (string= arg "|"))
843 | (select-window (get-mru-window))
844 | (split-window-right)
845 | (windmove-right))
846 | ;; open node in a new horizontally split window
847 | ((and (stringp arg) (string= arg "-"))
848 | (select-window (get-mru-window))
849 | (split-window-below)
850 | (windmove-down)))
851 | ;; open node in last active window
852 | (select-window (get-mru-window)))
853 |
854 | (defun neo-global--detach ()
855 | "Detach the global neotree buffer."
856 | (when neo-global--autorefresh-timer
857 | (cancel-timer neo-global--autorefresh-timer))
858 | (neo-global--with-buffer
859 | (neo-buffer--unlock-width))
860 | (setq neo-global--buffer nil)
861 | (setq neo-global--window nil))
862 |
863 | (defun neo-global--attach ()
864 | "Attach the global neotree buffer"
865 | (when neo-global--autorefresh-timer
866 | (cancel-timer neo-global--autorefresh-timer))
867 | (when neo-autorefresh
868 | (setq neo-global--autorefresh-timer
869 | (run-with-idle-timer 2 10 'neo-global--do-autorefresh)))
870 | (setq neo-global--buffer (get-buffer neo-buffer-name))
871 | (setq neo-global--window (get-buffer-window
872 | neo-global--buffer))
873 | (neo-global--with-buffer
874 | (neo-buffer--lock-width))
875 | (run-hook-with-args 'neo-after-create-hook '(window)))
876 |
877 | (defun neo-global--set-window-width (width)
878 | "Set neotree window width to WIDTH."
879 | (neo-global--with-window
880 | (neo-buffer--with-resizable-window
881 | (neo-util--set-window-width (selected-window) width))))
882 |
883 | (defun neo-global--reset-width ()
884 | "Set neotree window width to `neo-window-width'."
885 | (neo-global--set-window-width neo-window-width))
886 |
887 | ;;
888 | ;; Advices
889 | ;;
890 |
891 | (defadvice mouse-drag-vertical-line
892 | (around neotree-drag-vertical-line (start-event) activate)
893 | "Drag and drop is not affected by the lock."
894 | (neo-buffer--with-resizable-window
895 | ad-do-it))
896 |
897 | (defadvice balance-windows
898 | (around neotree-balance-windows activate)
899 | "Fix neotree inhibits balance-windows."
900 | (if (neo-global--window-exists-p)
901 | (let (old-width)
902 | (neo-global--with-window
903 | (setq old-width (window-width)))
904 | (neo-buffer--with-resizable-window
905 | ad-do-it)
906 | (neo-global--with-window
907 | (neo-global--set-window-width old-width)))
908 | ad-do-it))
909 |
910 | (eval-after-load 'popwin
911 | '(progn
912 | (defadvice popwin:create-popup-window
913 | (around neotree/popwin-popup-buffer activate)
914 | (let ((neo-exists-p (neo-global--window-exists-p)))
915 | (when neo-exists-p
916 | (neo-global--detach))
917 | ad-do-it
918 | (when neo-exists-p
919 | (neo-global--attach)
920 | (neo-global--reset-width))))
921 |
922 | (defadvice popwin:close-popup-window
923 | (around neotree/popwin-close-popup-window activate)
924 | (let ((neo-exists-p (neo-global--window-exists-p)))
925 | (when neo-exists-p
926 | (neo-global--detach))
927 | ad-do-it
928 | (when neo-exists-p
929 | (neo-global--attach)
930 | (neo-global--reset-width))))))
931 |
932 | ;;
933 | ;; Hooks
934 | ;;
935 |
936 | (defun neo-hook--node-first-letter ()
937 | "Move point to the first letter of the current node."
938 | (when (or (eq this-command 'next-line)
939 | (eq this-command 'previous-line))
940 | (neo-point-auto-indent)))
941 |
942 | ;;
943 | ;; Util methods
944 | ;;
945 |
946 | (defun neo-util--filter (condp lst)
947 | "Apply CONDP to elements of LST keeping those that return non-nil.
948 |
949 | Example:
950 | (neo-util--filter 'symbolp '(a \"b\" 3 d4))
951 | => (a d4)
952 |
953 | This procedure does not work when CONDP is the `null' function."
954 | (delq nil
955 | (mapcar (lambda (x) (and (funcall condp x) x)) lst)))
956 |
957 | (defun neo-util--find (where which)
958 | "Find element of the list WHERE matching predicate WHICH."
959 | (catch 'found
960 | (dolist (elt where)
961 | (when (funcall which elt)
962 | (throw 'found elt)))
963 | nil))
964 |
965 | (defun neo-util--make-printable-string (string)
966 | "Strip newline character from STRING, like 'Icon\n'."
967 | (replace-regexp-in-string "\n" "" string))
968 |
969 | (defun neo-util--walk-dir (path)
970 | "Return the subdirectories and subfiles of the PATH."
971 | (let* ((full-path (neo-path--file-truename path)))
972 | (condition-case nil
973 | (directory-files
974 | path 'full directory-files-no-dot-files-regexp)
975 | ('file-error
976 | (message "Walk directory %S failed." path)
977 | nil))))
978 |
979 | (defun neo-util--hidden-path-filter (node)
980 | "A filter function, if the NODE can not match each item in \
981 | `neo-hidden-regexp-list', return t."
982 | (if (not neo-buffer--show-hidden-file-p)
983 | (let ((shortname (neo-path--file-short-name node)))
984 | (null (neo-util--filter
985 | (lambda (x) (not (null (string-match-p x shortname))))
986 | neo-hidden-regexp-list)))
987 | node))
988 |
989 | (defun neo-str--trim-left (s)
990 | "Remove whitespace at the beginning of S."
991 | (if (string-match "\\`[ \t\n\r]+" s)
992 | (replace-match "" t t s)
993 | s))
994 |
995 | (defun neo-str--trim-right (s)
996 | "Remove whitespace at the end of S."
997 | (if (string-match "[ \t\n\r]+\\'" s)
998 | (replace-match "" t t s)
999 | s))
1000 |
1001 | (defun neo-str--trim (s)
1002 | "Remove whitespace at the beginning and end of S."
1003 | (neo-str--trim-left (neo-str--trim-right s)))
1004 |
1005 | (defun neo-path--expand-name (path &optional current-dir)
1006 | (expand-file-name (or (if (file-name-absolute-p path) path)
1007 | (let ((r-path path))
1008 | (setq r-path (substitute-in-file-name r-path))
1009 | (setq r-path (expand-file-name r-path current-dir))
1010 | r-path))))
1011 |
1012 | (defun neo-path--shorten (path len)
1013 | "Shorten a given PATH to a specified LEN.
1014 | This is needed for paths, which are to long for the window to display
1015 | completely. The function cuts of the first part of the path to remain
1016 | the last folder (the current one)."
1017 | (let ((result
1018 | (if (> (length path) len)
1019 | (concat "<" (substring path (- (- len 2))))
1020 | path)))
1021 | (when result
1022 | (decode-coding-string result 'utf-8))))
1023 |
1024 | (defun neo-path--insert-chroot-button (label path face)
1025 | (insert-button
1026 | label
1027 | 'action '(lambda (x) (neotree-change-root))
1028 | 'follow-link t
1029 | 'face face
1030 | 'neo-full-path path))
1031 |
1032 | (defun neo-path--insert-header-buttonized (path)
1033 | "Shortens the PATH to (window-body-width) and displays any \
1034 | visible remains as buttons that, when clicked, navigate to that
1035 | parent directory."
1036 | (let* ((dirs (reverse (cl-maplist 'identity (reverse (split-string path "/" :omitnulls)))))
1037 | (last (car-safe (car-safe (last dirs)))))
1038 | (neo-path--insert-chroot-button "/" "/" 'neo-root-dir-face)
1039 | (dolist (dir dirs)
1040 | (if (string= (car dir) last)
1041 | (neo-buffer--insert-with-face last 'neo-root-dir-face)
1042 | (neo-path--insert-chroot-button
1043 | (concat (car dir) "/")
1044 | (apply 'neo-path--join (cons "/" (reverse dir)))
1045 | 'neo-root-dir-face))))
1046 | ;;shorten the line if need be
1047 | (when (> (current-column) (window-body-width))
1048 | (forward-char (- (window-body-width)))
1049 | (delete-region (point-at-bol) (point))
1050 | (let* ((button (button-at (point)))
1051 | (path (if button (overlay-get button 'neo-full-path) "/")))
1052 | (neo-path--insert-chroot-button "<" path 'neo-root-dir-face))
1053 | (end-of-line)))
1054 |
1055 | (defun neo-path--updir (path)
1056 | (let ((r-path (neo-path--expand-name path)))
1057 | (if (and (> (length r-path) 0)
1058 | (equal (substring r-path -1) "/"))
1059 | (setq r-path (substring r-path 0 -1)))
1060 | (if (eq (length r-path) 0)
1061 | (setq r-path "/"))
1062 | (directory-file-name
1063 | (file-name-directory r-path))))
1064 |
1065 | (defun neo-path--join (root &rest dirs)
1066 | "Joins a series of directories together with ROOT and DIRS.
1067 | Like Python's os.path.join,
1068 | (neo-path--join \"/tmp\" \"a\" \"b\" \"c\") => /tmp/a/b/c ."
1069 | (or (if (not dirs) root)
1070 | (let ((tdir (car dirs))
1071 | (epath nil))
1072 | (setq epath
1073 | (or (if (equal tdir ".") root)
1074 | (if (equal tdir "..") (neo-path--updir root))
1075 | (neo-path--expand-name tdir root)))
1076 | (apply 'neo-path--join
1077 | epath
1078 | (cdr dirs)))))
1079 |
1080 | (defun neo-path--file-short-name (file)
1081 | "Base file/directory name by FILE.
1082 | Taken from http://lists.gnu.org/archive/html/emacs-devel/2011-01/msg01238.html"
1083 | (or (if (string= file "/") "/")
1084 | (neo-util--make-printable-string (file-name-nondirectory (directory-file-name file)))))
1085 |
1086 | (defun neo-path--file-truename (path)
1087 | (let ((rlt (file-truename path)))
1088 | (if (not (null rlt))
1089 | (progn
1090 | (if (and (file-directory-p rlt)
1091 | (> (length rlt) 0)
1092 | (not (equal (substring rlt -1) "/")))
1093 | (setq rlt (concat rlt "/")))
1094 | rlt)
1095 | nil)))
1096 |
1097 | (defun neo-path--has-subfile-p (dir)
1098 | "To determine whether a directory(DIR) contain files."
1099 | (and (file-exists-p dir)
1100 | (file-directory-p dir)
1101 | (neo-util--walk-dir dir)
1102 | t))
1103 |
1104 | (defun neo-path--match-path-directory (path)
1105 | (let ((true-path (neo-path--file-truename path))
1106 | (rlt-path nil))
1107 | (setq rlt-path
1108 | (catch 'rlt
1109 | (if (file-directory-p true-path)
1110 | (throw 'rlt true-path))
1111 | (setq true-path
1112 | (file-name-directory true-path))
1113 | (if (file-directory-p true-path)
1114 | (throw 'rlt true-path))))
1115 | (if (not (null rlt-path))
1116 | (setq rlt-path (neo-path--join "." rlt-path "./")))
1117 | rlt-path))
1118 |
1119 | (defun neo-path--get-working-dir ()
1120 | "Return a directory name of the current buffer."
1121 | (file-name-as-directory (file-truename default-directory)))
1122 |
1123 | (defun neo-path--strip (path)
1124 | "Remove whitespace at the end of PATH."
1125 | (let* ((rlt (neo-str--trim path))
1126 | (pos (string-match "[\\\\/]+\\'" rlt)))
1127 | (when pos
1128 | (setq rlt (replace-match "" t t rlt))
1129 | (when (eq (length rlt) 0)
1130 | (setq rlt "/")))
1131 | rlt))
1132 |
1133 | (defun neo-path--path-equal-p (path1 path2)
1134 | "Return non-nil if pathes PATH1 and PATH2 are the same path."
1135 | (string-equal (neo-path--strip path1)
1136 | (neo-path--strip path2)))
1137 |
1138 | (defun neo-path--file-equal-p (file1 file2)
1139 | "Return non-nil if files FILE1 and FILE2 name the same file.
1140 | If FILE1 or FILE2 does not exist, the return value is unspecified."
1141 | (unless (or (null file1)
1142 | (null file2))
1143 | (let ((nfile1 (neo-path--strip file1))
1144 | (nfile2 (neo-path--strip file2)))
1145 | (file-equal-p nfile1 nfile2))))
1146 |
1147 | (defun neo-path--file-in-directory-p (file dir)
1148 | "Return non-nil if FILE is in DIR or a subdirectory of DIR.
1149 | A directory is considered to be \"in\" itself.
1150 | Return nil if DIR is not an existing directory."
1151 | (let ((nfile (neo-path--strip file))
1152 | (ndir (neo-path--strip dir)))
1153 | (setq ndir (concat ndir "/"))
1154 | (file-in-directory-p nfile ndir)))
1155 |
1156 | (defun neo-util--kill-buffers-for-path (path)
1157 | "Kill all buffers for files in PATH."
1158 | (let ((buffer (find-buffer-visiting path)))
1159 | (when buffer
1160 | (kill-buffer buffer)))
1161 | (dolist (filename (directory-files path t directory-files-no-dot-files-regexp))
1162 | (let ((buffer (find-buffer-visiting filename)))
1163 | (when buffer
1164 | (kill-buffer buffer))
1165 | (when (and
1166 | (file-directory-p filename)
1167 | (neo-path--has-subfile-p filename))
1168 | (neo-util--kill-buffers-for-path filename)))))
1169 |
1170 | (defun neo-util--set-window-width (window n)
1171 | "Make WINDOW N columns width."
1172 | (let ((w (max n window-min-width)))
1173 | (unless (null window)
1174 | (if (> (window-width) w)
1175 | (shrink-window-horizontally (- (window-width) w))
1176 | (if (< (window-width) w)
1177 | (enlarge-window-horizontally (- w (window-width))))))))
1178 |
1179 | (defun neo-point-auto-indent ()
1180 | "Put the point on the first letter of the current node."
1181 | (when (neo-buffer--get-filename-current-line)
1182 | (beginning-of-line 1)
1183 | (re-search-forward "[^-\s+]" (line-end-position 1) t)
1184 | (backward-char 1)))
1185 |
1186 | (defun off-p (msg)
1187 | "Returns true regardless of message value in the argument."
1188 | t)
1189 |
1190 | (defun neo-sort-hidden-last (x y)
1191 | "Sort normally but with hidden files last."
1192 | (let ((x-hidden (neo-filepath-hidden-p x))
1193 | (y-hidden (neo-filepath-hidden-p y)))
1194 | (cond
1195 | ((and x-hidden (not y-hidden))
1196 | nil)
1197 | ((and (not x-hidden) y-hidden)
1198 | t)
1199 | (t
1200 | (string< x y)))))
1201 |
1202 | (defun neo-filepath-hidden-p (node)
1203 | "Return whether or not node is a hidden path."
1204 | (let ((shortname (neo-path--file-short-name node)))
1205 | (neo-util--filter
1206 | (lambda (x) (not (null (string-match-p x shortname))))
1207 | neo-hidden-regexp-list)))
1208 |
1209 | (defun neo-get-unsaved-buffers-from-projectile ()
1210 | "Return list of unsaved buffers from projectile buffers."
1211 | (interactive)
1212 | (let ((rlist '())
1213 | (rtag t))
1214 | (condition-case nil
1215 | (projectile-project-buffers)
1216 | (error (setq rtag nil)))
1217 | (when (and rtag (fboundp 'projectile-project-buffers))
1218 | (dolist (buf (projectile-project-buffers))
1219 | (with-current-buffer buf
1220 | (if (and (buffer-modified-p) buffer-file-name)
1221 | (setq rlist (cons (buffer-file-name) rlist))
1222 | ))))
1223 | rlist))
1224 |
1225 | ;;
1226 | ;; Buffer methods
1227 | ;;
1228 |
1229 | (defun neo-buffer--newline-and-begin ()
1230 | "Insert new line."
1231 | (newline)
1232 | (beginning-of-line))
1233 |
1234 | (defun neo-buffer--get-icon (name)
1235 | "Get image by NAME."
1236 | (let ((icon-path (neo-path--join neo-dir "icons"))
1237 | image)
1238 | (setq image (create-image
1239 | (neo-path--join icon-path (concat name ".xpm"))
1240 | 'xpm nil :ascent 'center :mask '(heuristic t)))
1241 | image))
1242 |
1243 | (defun neo--nerd-icons-icon-for-dir-with-chevron (dir &optional chevron padding)
1244 | (let ((icon (nerd-icons-icon-for-dir dir))
1245 | (chevron (if chevron (nerd-icons-octicon (format "nf-oct-chevron_%s" chevron) :height 0.8 :v-adjust -0.1) ""))
1246 | (padding (or padding "\t")))
1247 | (format "%s%s%s%s%s" padding chevron padding icon padding)))
1248 |
1249 | (defun neo-buffer--insert-fold-symbol (name &optional node-name)
1250 | "Write icon by NAME, the icon style affected by neo-theme.
1251 | `open' write opened folder icon.
1252 | `close' write closed folder icon.
1253 | `leaf' write leaf icon.
1254 | Optional NODE-NAME is used for the `icons' theme"
1255 | (let ((n-insert-image (lambda (n)
1256 | (insert-image (neo-buffer--get-icon n))))
1257 | (n-insert-symbol (lambda (n)
1258 | (neo-buffer--insert-with-face
1259 | n 'neo-expand-btn-face))))
1260 | (cond
1261 | ((and (display-graphic-p) (equal neo-theme 'classic))
1262 | (or (and (equal name 'open) (funcall n-insert-image "open"))
1263 | (and (equal name 'close) (funcall n-insert-image "close"))
1264 | (and (equal name 'leaf) (funcall n-insert-image "leaf"))))
1265 | ((equal neo-theme 'arrow)
1266 | (or (and (equal name 'open) (funcall n-insert-symbol "▾"))
1267 | (and (equal name 'close) (funcall n-insert-symbol "▸"))))
1268 | ((equal neo-theme 'nerd)
1269 | (or (and (equal name 'open) (funcall n-insert-symbol "▾ "))
1270 | (and (equal name 'close) (funcall n-insert-symbol "▸ "))
1271 | (and (equal name 'leaf) (funcall n-insert-symbol " "))))
1272 | ((and (display-graphic-p) (equal neo-theme 'icons))
1273 | (unless (require 'all-the-icons nil 'noerror)
1274 | (error "Package `all-the-icons' isn't installed"))
1275 | (setq-local tab-width 1)
1276 | (or (and (equal name 'open) (insert (all-the-icons-icon-for-dir-with-chevron (directory-file-name node-name) "down")))
1277 | (and (equal name 'close) (insert (all-the-icons-icon-for-dir-with-chevron (directory-file-name node-name) "right")))
1278 | (and (equal name 'leaf) (insert (format "\t\t\t%s\t" (all-the-icons-icon-for-file node-name))))))
1279 | ((equal neo-theme 'nerd-icons)
1280 | (unless (require 'nerd-icons nil 'noerror)
1281 | (error "Package `nerd-icons' isn't installed"))
1282 | (setq-local tab-width 1)
1283 | (or (and (equal name 'open) (insert (neo--nerd-icons-icon-for-dir-with-chevron (directory-file-name node-name) "down")))
1284 | (and (equal name 'close) (insert (neo--nerd-icons-icon-for-dir-with-chevron (directory-file-name node-name) "right")))
1285 | (and (equal name 'leaf) (insert (format "\t\t\t%s\t" (nerd-icons-icon-for-file node-name))))))
1286 | (t
1287 | (or (and (equal name 'open) (funcall n-insert-symbol "- "))
1288 | (and (equal name 'close) (funcall n-insert-symbol "+ ")))))))
1289 |
1290 | (defun neo-buffer--save-cursor-pos (&optional node-path line-pos)
1291 | "Save cursor position.
1292 | If NODE-PATH and LINE-POS is nil, it will be save the current line node position."
1293 | (let ((cur-node-path nil)
1294 | (cur-line-pos nil)
1295 | (ws-wind (selected-window))
1296 | (ws-pos (window-start)))
1297 | (setq cur-node-path (if node-path
1298 | node-path
1299 | (neo-buffer--get-filename-current-line)))
1300 | (setq cur-line-pos (if line-pos
1301 | line-pos
1302 | (line-number-at-pos)))
1303 | (setq neo-buffer--cursor-pos (cons cur-node-path cur-line-pos))
1304 | (setq neo-buffer--last-window-pos (cons ws-wind ws-pos))))
1305 |
1306 | (defun neo-buffer--goto-cursor-pos ()
1307 | "Jump to saved cursor position."
1308 | (let ((line-pos nil)
1309 | (node (car neo-buffer--cursor-pos))
1310 | (line-pos (cdr neo-buffer--cursor-pos))
1311 | (ws-wind (car neo-buffer--last-window-pos))
1312 | (ws-pos (cdr neo-buffer--last-window-pos)))
1313 | (catch 'line-pos-founded
1314 | (unless (null node)
1315 | (setq line-pos 0)
1316 | (mapc
1317 | (lambda (x)
1318 | (setq line-pos (1+ line-pos))
1319 | (unless (null x)
1320 | (when (neo-path--path-equal-p x node)
1321 | (throw 'line-pos-founded line-pos))))
1322 | neo-buffer--node-list))
1323 | (setq line-pos (cdr neo-buffer--cursor-pos))
1324 | (throw 'line-pos-founded line-pos))
1325 | ;; goto line
1326 | (goto-char (point-min))
1327 | (neo-buffer--forward-line (1- line-pos))
1328 | ;; scroll window
1329 | (when (equal (selected-window) ws-wind)
1330 | (set-window-start ws-wind ws-pos t))))
1331 |
1332 | (defun neo-buffer--node-list-clear ()
1333 | "Clear node list."
1334 | (setq neo-buffer--node-list nil))
1335 |
1336 | (defun neo-buffer--node-list-set (line-num path)
1337 | "Set value in node list.
1338 | LINE-NUM is the index of node list.
1339 | PATH is value."
1340 | (let ((node-list-length (length neo-buffer--node-list))
1341 | (node-index line-num))
1342 | (when (null node-index)
1343 | (setq node-index (line-number-at-pos)))
1344 | (when (< node-list-length node-index)
1345 | (setq neo-buffer--node-list
1346 | (vconcat neo-buffer--node-list
1347 | (make-vector (- node-index node-list-length) nil))))
1348 | (aset neo-buffer--node-list (1- node-index) path))
1349 | neo-buffer--node-list)
1350 |
1351 | (defun neo-buffer--insert-with-face (content face)
1352 | (let ((pos-start (point)))
1353 | (insert content)
1354 | (set-text-properties pos-start
1355 | (point)
1356 | (list 'face face))))
1357 |
1358 | (defun neo-buffer--valid-start-node-p ()
1359 | (and (not (null neo-buffer--start-node))
1360 | (file-accessible-directory-p neo-buffer--start-node)))
1361 |
1362 | (defun neo-buffer--create ()
1363 | "Create and switch to NeoTree buffer."
1364 | (switch-to-buffer
1365 | (generate-new-buffer-name neo-buffer-name))
1366 | (neotree-mode)
1367 | ;; disable linum-mode
1368 | (when (and (boundp 'linum-mode)
1369 | (not (null linum-mode)))
1370 | (linum-mode -1))
1371 | ;; Use inside helm window in NeoTree
1372 | ;; Refs https://github.com/jaypei/emacs-neotree/issues/226
1373 | (setq-local helm-split-window-inside-p t)
1374 | (current-buffer))
1375 |
1376 | (defun neo-buffer--insert-banner ()
1377 | (unless (null neo-banner-message)
1378 | (let ((start (point)))
1379 | (insert neo-banner-message)
1380 | (set-text-properties start (point) '(face neo-banner-face)))
1381 | (neo-buffer--newline-and-begin)))
1382 |
1383 | (defun neo-buffer--insert-root-entry (node)
1384 | (neo-buffer--node-list-set nil node)
1385 | (cond ((eq neo-cwd-line-style 'button)
1386 | (neo-path--insert-header-buttonized node))
1387 | (t
1388 | (neo-buffer--insert-with-face (neo-path--shorten node (window-body-width))
1389 | 'neo-root-dir-face)))
1390 | (neo-buffer--newline-and-begin)
1391 | (when neo-show-updir-line
1392 | (neo-buffer--insert-fold-symbol 'close node)
1393 | (insert-button ".."
1394 | 'action '(lambda (x) (neotree-change-root))
1395 | 'follow-link t
1396 | 'face neo-dir-link-face
1397 | 'neo-full-path (neo-path--updir node))
1398 | (neo-buffer--newline-and-begin)))
1399 |
1400 | (defun neo-buffer--help-echo-message (node-name)
1401 | (cond
1402 | ((eq neo-help-echo-style 'default)
1403 | (if (<= (+ (current-column) (string-width node-name))
1404 | neo-window-width)
1405 | nil
1406 | node-name))
1407 | (t nil)))
1408 |
1409 | (defun neo-buffer--insert-dir-entry (node depth expanded)
1410 | (let ((node-short-name (neo-path--file-short-name node)))
1411 | (insert-char ?\s (* (- depth 1) 2)) ; indent
1412 | (when (memq 'char neo-vc-integration)
1413 | (insert-char ?\s 2))
1414 | (neo-buffer--insert-fold-symbol
1415 | (if expanded 'open 'close) node)
1416 | (insert-button (if neo-show-slash-for-folder (concat node-short-name "/") node-short-name)
1417 | 'follow-link t
1418 | 'face neo-dir-link-face
1419 | 'neo-full-path node
1420 | 'keymap neotree-dir-button-keymap
1421 | 'help-echo (neo-buffer--help-echo-message node-short-name))
1422 | (neo-buffer--node-list-set nil node)
1423 | (neo-buffer--newline-and-begin)))
1424 |
1425 | (defun neo-buffer--insert-file-entry (node depth)
1426 | (let ((node-short-name (neo-path--file-short-name node))
1427 | (vc (when neo-vc-integration (neo-vc-for-node node))))
1428 | (insert-char ?\s (* (- depth 1) 2)) ; indent
1429 | (when (memq 'char neo-vc-integration)
1430 | (insert-char (car vc))
1431 | (insert-char ?\s))
1432 | (neo-buffer--insert-fold-symbol 'leaf node-short-name)
1433 | (insert-button node-short-name
1434 | 'follow-link t
1435 | 'face (if (memq 'face neo-vc-integration)
1436 | (cdr vc)
1437 | neo-file-link-face)
1438 | 'neo-full-path node
1439 | 'keymap neotree-file-button-keymap
1440 | 'help-echo (neo-buffer--help-echo-message node-short-name))
1441 | (neo-buffer--node-list-set nil node)
1442 | (neo-buffer--newline-and-begin)))
1443 |
1444 | (defun neo-vc-for-node (node)
1445 | (let* ((backend (ignore-errors
1446 | (vc-responsible-backend node)))
1447 | (vc-state (when backend (vc-state node backend))))
1448 | (cons (cdr (assoc vc-state neo-vc-state-char-alist))
1449 | (cl-case vc-state
1450 | (up-to-date neo-vc-up-to-date-face)
1451 | (edited neo-vc-edited-face)
1452 | (needs-update neo-vc-needs-update-face)
1453 | (needs-merge neo-vc-needs-merge-face)
1454 | (unlocked-changes neo-vc-unlocked-changes-face)
1455 | (added neo-vc-added-face)
1456 | (removed neo-vc-removed-face)
1457 | (conflict neo-vc-conflict-face)
1458 | (missing neo-vc-missing-face)
1459 | (ignored neo-vc-ignored-face)
1460 | (unregistered neo-vc-unregistered-face)
1461 | (user neo-vc-user-face)
1462 | (otherwise neo-vc-default-face)))))
1463 |
1464 | (defun neo-buffer--get-nodes (path)
1465 | (let* ((nodes (neo-util--walk-dir path))
1466 | (comp neo-filepath-sort-function)
1467 | (nodes (neo-util--filter 'neo-util--hidden-path-filter nodes)))
1468 | (cons (sort (neo-util--filter 'file-directory-p nodes) comp)
1469 | (sort (neo-util--filter #'(lambda (f) (not (file-directory-p f))) nodes) comp))))
1470 |
1471 | (defun neo-buffer--get-node-index (node nodes)
1472 | "Return the index of NODE in NODES.
1473 |
1474 | NODES can be a list of directory or files.
1475 | Return nil if NODE has not been found in NODES."
1476 | (let ((i 0)
1477 | (l (length nodes))
1478 | (cur (car nodes))
1479 | (rest (cdr nodes)))
1480 | (while (and cur (not (equal cur node)))
1481 | (setq i (1+ i))
1482 | (setq cur (car rest))
1483 | (setq rest (cdr rest)))
1484 | (if (< i l) i)))
1485 |
1486 | (defun neo-buffer--expanded-node-p (node)
1487 | "Return non-nil if NODE is expanded."
1488 | (neo-util--to-bool
1489 | (neo-util--find
1490 | neo-buffer--expanded-node-list
1491 | #'(lambda (x) (equal x node)))))
1492 |
1493 | (defun neo-buffer--set-expand (node do-expand)
1494 | "Set the expanded state of the NODE to DO-EXPAND.
1495 | Return the new expand state for NODE (t for expanded, nil for collapsed)."
1496 | (if (not do-expand)
1497 | (setq neo-buffer--expanded-node-list
1498 | (neo-util--filter
1499 | #'(lambda (x) (not (equal node x)))
1500 | neo-buffer--expanded-node-list))
1501 | (push node neo-buffer--expanded-node-list))
1502 | do-expand)
1503 |
1504 | (defun neo-buffer--toggle-expand (node)
1505 | (neo-buffer--set-expand node (not (neo-buffer--expanded-node-p node))))
1506 |
1507 | (defun neo-buffer--insert-tree (path depth)
1508 | (if (eq depth 1)
1509 | (neo-buffer--insert-root-entry path))
1510 | (let* ((contents (neo-buffer--get-nodes path))
1511 | (nodes (car contents))
1512 | (leafs (cdr contents))
1513 | (default-directory path))
1514 | (dolist (node nodes)
1515 | (let ((expanded (neo-buffer--expanded-node-p node)))
1516 | (neo-buffer--insert-dir-entry
1517 | node depth expanded)
1518 | (if expanded (neo-buffer--insert-tree (concat node "/") (+ depth 1)))))
1519 | (dolist (leaf leafs)
1520 | (neo-buffer--insert-file-entry leaf depth))))
1521 |
1522 | (defun neo-buffer--refresh (save-pos-p &optional non-neotree-buffer)
1523 | "Refresh the NeoTree buffer.
1524 | If SAVE-POS-P is non-nil, it will be auto save current line number."
1525 | (let ((start-node neo-buffer--start-node))
1526 | (unless start-node
1527 | (setq start-node default-directory))
1528 | (neo-buffer--with-editing-buffer
1529 | ;; save context
1530 | (when save-pos-p
1531 | (neo-buffer--save-cursor-pos))
1532 | (when non-neotree-buffer
1533 | (setq neo-buffer--start-node start-node))
1534 | ;; starting refresh
1535 | (erase-buffer)
1536 | (neo-buffer--node-list-clear)
1537 | (neo-buffer--insert-banner)
1538 | (setq neo-buffer--start-line neo-header-height)
1539 | (neo-buffer--insert-tree start-node 1))
1540 | ;; restore context
1541 | (neo-buffer--goto-cursor-pos)))
1542 |
1543 | (defun neo-buffer--post-move ()
1544 | "Reset current directory when position moved."
1545 | (funcall
1546 | (neotree-make-executor
1547 | :file-fn
1548 | '(lambda (path _)
1549 | (setq default-directory (neo-path--updir btn-full-path)))
1550 | :dir-fn
1551 | '(lambda (path _)
1552 | (setq default-directory (file-name-as-directory path))))))
1553 |
1554 | (defun neo-buffer--get-button-current-line ()
1555 | "Return the first button in current line."
1556 | (let* ((btn-position nil)
1557 | (pos-line-start (line-beginning-position))
1558 | (pos-line-end (line-end-position))
1559 | ;; NOTE: cannot find button when the button
1560 | ;; at beginning of the line
1561 | (current-button (or (button-at (point))
1562 | (button-at pos-line-start))))
1563 | (if (null current-button)
1564 | (progn
1565 | (setf btn-position
1566 | (catch 'ret-button
1567 | (let* ((next-button (next-button pos-line-start))
1568 | (pos-btn nil))
1569 | (if (null next-button) (throw 'ret-button nil))
1570 | (setf pos-btn (overlay-start next-button))
1571 | (if (> pos-btn pos-line-end) (throw 'ret-button nil))
1572 | (throw 'ret-button pos-btn))))
1573 | (if (null btn-position)
1574 | nil
1575 | (setf current-button (button-at btn-position)))))
1576 | current-button))
1577 |
1578 | (defun neo-buffer--get-filename-current-line (&optional default)
1579 | "Return filename for first button in current line.
1580 | If there is no button in current line, then return DEFAULT."
1581 | (let ((btn (neo-buffer--get-button-current-line)))
1582 | (if (not (null btn))
1583 | (button-get btn 'neo-full-path)
1584 | default)))
1585 |
1586 | (defun neo-buffer--lock-width ()
1587 | "Lock the width size for NeoTree window."
1588 | (if neo-window-fixed-size
1589 | (setq window-size-fixed 'width)))
1590 |
1591 | (defun neo-buffer--unlock-width ()
1592 | "Unlock the width size for NeoTree window."
1593 | (setq window-size-fixed nil))
1594 |
1595 | (defun neo-buffer--rename-node ()
1596 | "Rename current node as another path."
1597 | (interactive)
1598 | (let* ((current-path (neo-buffer--get-filename-current-line))
1599 | (buffer (find-buffer-visiting current-path))
1600 | to-path
1601 | msg)
1602 | (unless (null current-path)
1603 | (setq msg (format "Rename [%s] to: " (neo-path--file-short-name current-path)))
1604 | (setq to-path (read-file-name msg (file-name-directory current-path)))
1605 | (if buffer
1606 | (with-current-buffer buffer
1607 | (set-visited-file-name to-path nil t)))
1608 | (if (vc-registered current-path)
1609 | (vc-rename-file current-path to-path)
1610 | (rename-file current-path to-path 1))
1611 | (neo-buffer--refresh t)
1612 | (message "Rename successful."))))
1613 |
1614 | (defun neo-buffer--copy-node ()
1615 | "Copies current node as another path."
1616 | (interactive)
1617 | (let* ((current-path (neo-buffer--get-filename-current-line))
1618 | (buffer (find-buffer-visiting current-path))
1619 | to-path
1620 | msg)
1621 | (unless (null current-path)
1622 | (setq msg (format "Copy [%s] to: " (neo-path--file-short-name current-path)))
1623 | (setq to-path (read-file-name msg (file-name-directory current-path)))
1624 | (if (file-directory-p current-path)
1625 | (copy-directory current-path to-path)
1626 | (copy-file current-path to-path))
1627 | (neo-buffer--refresh t)
1628 | (message "Copy successful."))))
1629 |
1630 | (defun neo-buffer--select-file-node (file &optional recursive-p)
1631 | "Select the node that corresponds to the FILE.
1632 | If RECURSIVE-P is non nil, find files will recursively."
1633 | (let ((efile file)
1634 | (iter-curr-dir nil)
1635 | (file-node-find-p nil)
1636 | (file-node-list nil))
1637 | (unless (file-name-absolute-p efile)
1638 | (setq efile (expand-file-name efile)))
1639 | (setq iter-curr-dir efile)
1640 | (catch 'return
1641 | (while t
1642 | (setq iter-curr-dir (neo-path--updir iter-curr-dir))
1643 | (push iter-curr-dir file-node-list)
1644 | (when (neo-path--file-equal-p iter-curr-dir neo-buffer--start-node)
1645 | (setq file-node-find-p t)
1646 | (throw 'return nil))
1647 | (let ((niter-curr-dir (file-remote-p iter-curr-dir 'localname)))
1648 | (unless niter-curr-dir
1649 | (setq niter-curr-dir iter-curr-dir))
1650 | (when (neo-path--file-equal-p niter-curr-dir "/")
1651 | (setq file-node-find-p nil)
1652 | (throw 'return nil)))))
1653 | (when file-node-find-p
1654 | (dolist (p file-node-list)
1655 | (neo-buffer--set-expand p t))
1656 | (neo-buffer--save-cursor-pos file)
1657 | (neo-buffer--refresh nil))))
1658 |
1659 | (defun neo-buffer--change-root (root-dir)
1660 | "Change the tree root to ROOT-DIR."
1661 | (let ((path root-dir)
1662 | start-path)
1663 | (unless (and (file-exists-p path)
1664 | (file-directory-p path))
1665 | (throw 'error "The path is not a valid directory."))
1666 | (setq start-path (expand-file-name (substitute-in-file-name path)))
1667 | (setq neo-buffer--start-node start-path)
1668 | (cd start-path)
1669 | (neo-buffer--save-cursor-pos path nil)
1670 | (neo-buffer--refresh nil)))
1671 |
1672 | (defun neo-buffer--get-nodes-for-select-down-node (path)
1673 | "Return the node list for the down dir selection."
1674 | (if path
1675 | (when (file-name-directory path)
1676 | (if (neo-buffer--expanded-node-p path)
1677 | (neo-buffer--get-nodes path)
1678 | (neo-buffer--get-nodes (file-name-directory path))))
1679 | (neo-buffer--get-nodes (file-name-as-directory neo-buffer--start-node))))
1680 |
1681 | (defun neo-buffer--get-nodes-for-sibling (path)
1682 | "Return the node list for the sibling selection. Return nil of no nodes can
1683 | be found.
1684 | The returned list is a directory list if path is a directory, otherwise it is
1685 | a file list."
1686 | (when path
1687 | (let ((nodes (neo-buffer--get-nodes (file-name-directory path))))
1688 | (if (file-directory-p path)
1689 | (car nodes)
1690 | (cdr nodes)))))
1691 |
1692 | (defun neo-buffer--sibling (path &optional previous)
1693 | "Return the next sibling of node PATH.
1694 | If PREVIOUS is non-nil the previous sibling is returned."
1695 | (let* ((nodes (neo-buffer--get-nodes-for-sibling path)))
1696 | (when nodes
1697 | (let ((i (neo-buffer--get-node-index path nodes))
1698 | (l (length nodes)))
1699 | (if i (nth (mod (+ i (if previous -1 1)) l) nodes))))))
1700 |
1701 | (defun neo-buffer--execute (arg &optional file-fn dir-fn)
1702 | "Define the behaviors for keyboard event.
1703 | ARG is the parameter for command.
1704 | If FILE-FN is non-nil, it will executed when a file node.
1705 | If DIR-FN is non-nil, it will executed when a dir node."
1706 | (interactive "P")
1707 | (let* ((btn-full-path (neo-buffer--get-filename-current-line))
1708 | is-file-p
1709 | enter-fn)
1710 | (unless (null btn-full-path)
1711 | (setq is-file-p (not (file-directory-p btn-full-path))
1712 | enter-fn (if is-file-p file-fn dir-fn))
1713 | (unless (null enter-fn)
1714 | (funcall enter-fn btn-full-path arg)
1715 | (run-hook-with-args
1716 | 'neo-enter-hook
1717 | (if is-file-p 'file 'directory)
1718 | btn-full-path
1719 | arg)))
1720 | btn-full-path))
1721 |
1722 | (defun neo-buffer--set-show-hidden-file-p (show-p)
1723 | "If SHOW-P is non-nil, show hidden nodes in tree."
1724 | (setq neo-buffer--show-hidden-file-p show-p)
1725 | (neo-buffer--refresh t))
1726 |
1727 | (defun neo-buffer--forward-line (n)
1728 | "Move N lines forward in NeoTree buffer."
1729 | (forward-line (or n 1))
1730 | (neo-buffer--post-move))
1731 |
1732 | ;;
1733 | ;; Mode-line methods
1734 | ;;
1735 |
1736 | (defun neo-mode-line--compute-format (parent index ndirs nfiles)
1737 | "Return a formated string to be used in the `neotree' mode-line."
1738 | (let* ((nall (+ ndirs nfiles))
1739 | (has-dirs (> ndirs 0))
1740 | (has-files (> nfiles 0))
1741 | (msg-index (when index (format "[%s/%s] " index nall)))
1742 | (msg-ndirs (when has-dirs (format (if has-files " (D:%s" " (D:%s)") ndirs)))
1743 | (msg-nfiles (when has-files (format (if has-dirs " F:%s)" " (F:%s)") nfiles)))
1744 | (msg-directory (file-name-nondirectory (directory-file-name parent)))
1745 | (msg-directory-max-length (- (window-width)
1746 | (length msg-index)
1747 | (length msg-ndirs)
1748 | (length msg-nfiles))))
1749 | (setq msg-directory (if (<= (length msg-directory) msg-directory-max-length)
1750 | msg-directory
1751 | (concat (substring msg-directory
1752 | 0 (- msg-directory-max-length 3))
1753 | "...")))
1754 | (propertize
1755 | (decode-coding-string (concat msg-index msg-directory msg-ndirs msg-nfiles) 'utf-8)
1756 | 'help-echo (decode-coding-string parent 'utf-8))))
1757 |
1758 | ;;
1759 | ;; Window methods
1760 | ;;
1761 |
1762 | (defun neo-window--init (window buffer)
1763 | "Make WINDOW a NeoTree window.
1764 | NeoTree buffer is BUFFER."
1765 | (neo-buffer--with-resizable-window
1766 | (switch-to-buffer buffer)
1767 | (set-window-parameter window 'no-delete-other-windows t)
1768 | (set-window-dedicated-p window t))
1769 | window)
1770 |
1771 | (defun neo-window--zoom (method)
1772 | "Zoom the NeoTree window, the METHOD should one of these options:
1773 | 'maximize 'minimize 'zoom-in 'zoom-out."
1774 | (neo-buffer--unlock-width)
1775 | (cond
1776 | ((eq method 'maximize)
1777 | (maximize-window))
1778 | ((eq method 'minimize)
1779 | (neo-util--set-window-width (selected-window) neo-window-width))
1780 | ((eq method 'zoom-in)
1781 | (shrink-window-horizontally 2))
1782 | ((eq method 'zoom-out)
1783 | (enlarge-window-horizontally 2)))
1784 | (neo-buffer--lock-width))
1785 |
1786 | (defun neo-window--minimize-p ()
1787 | "Return non-nil when the NeoTree window is minimize."
1788 | (<= (window-width) neo-window-width))
1789 |
1790 | ;;
1791 | ;; Interactive functions
1792 | ;;
1793 |
1794 | (defun neotree-next-line (&optional count)
1795 | "Move next line in NeoTree buffer.
1796 | Optional COUNT argument, moves COUNT lines down."
1797 | (interactive "p")
1798 | (neo-buffer--forward-line (or count 1)))
1799 |
1800 | (defun neotree-previous-line (&optional count)
1801 | "Move previous line in NeoTree buffer.
1802 | Optional COUNT argument, moves COUNT lines up."
1803 | (interactive "p")
1804 | (neo-buffer--forward-line (- (or count 1))))
1805 |
1806 | ;;;###autoload
1807 | (defun neotree-find (&optional path default-path)
1808 | "Quick select node which specified PATH in NeoTree.
1809 | If path is nil and no buffer file name, then use DEFAULT-PATH,"
1810 | (interactive)
1811 | (let* ((ndefault-path (if default-path default-path
1812 | (neo-path--get-working-dir)))
1813 | (npath (if path path
1814 | (or (buffer-file-name) ndefault-path)))
1815 | (do-open-p nil))
1816 | (if (and (not neo-force-change-root)
1817 | (not (neo-global--file-in-root-p npath))
1818 | (neo-global--window-exists-p))
1819 | (setq do-open-p (funcall neo-confirm-change-root "File not found in root path, do you want to change root?"))
1820 | (setq do-open-p t))
1821 | (when do-open-p
1822 | (neo-global--open-and-find npath))
1823 | (when neo-auto-indent-point
1824 | (neo-point-auto-indent)))
1825 | (neo-global--select-window))
1826 |
1827 | (defun neotree-click-changes-root-toggle ()
1828 | "Toggle the variable neo-click-changes-root.
1829 | If true, clicking on a directory will change the current root to
1830 | the directory instead of showing the directory contents."
1831 | (interactive)
1832 | (setq neo-click-changes-root (not neo-click-changes-root)))
1833 |
1834 | (defun neo-open-dir (full-path &optional arg)
1835 | "Toggle fold a directory node.
1836 |
1837 | FULL-PATH is the path of the directory.
1838 | ARG is ignored."
1839 | (if neo-click-changes-root
1840 | (neotree-change-root)
1841 | (progn
1842 | (let ((new-state (neo-buffer--toggle-expand full-path)))
1843 | (neo-buffer--refresh t)
1844 | (when neo-auto-indent-point
1845 | (when new-state (forward-line 1))
1846 | (neo-point-auto-indent))))))
1847 |
1848 |
1849 | (defun neo--expand-recursive (path state)
1850 | "Set the state of children recursively.
1851 |
1852 | The children of PATH will have state STATE."
1853 | (let ((children (car (neo-buffer--get-nodes path) )))
1854 | (dolist (node children)
1855 | (neo-buffer--set-expand node state)
1856 | (neo--expand-recursive node state ))))
1857 |
1858 | (defun neo-open-dir-recursive (full-path &optional arg)
1859 | "Toggle fold a directory node recursively.
1860 |
1861 | The children of the node will also be opened recursively.
1862 | FULL-PATH is the path of the directory.
1863 | ARG is ignored."
1864 | (if neo-click-changes-root
1865 | (neotree-change-root)
1866 | (let ((new-state (neo-buffer--toggle-expand full-path))
1867 | (children (car (neo-buffer--get-nodes full-path))))
1868 | (dolist (node children)
1869 | (neo-buffer--set-expand node new-state)
1870 | (neo--expand-recursive node new-state))
1871 | (neo-buffer--refresh t))))
1872 |
1873 | (defun neo-open-dired (full-path &optional arg)
1874 | "Open file or directory node in `dired-mode'.
1875 |
1876 | FULL-PATH is the path of node.
1877 | ARG is same as `neo-open-file'."
1878 | (neo-global--select-mru-window arg)
1879 | (dired full-path))
1880 |
1881 | (defun neo-open-file (full-path &optional arg)
1882 | "Open a file node.
1883 |
1884 | FULL-PATH is the file path you want to open.
1885 | If ARG is an integer then the node is opened in a window selected via
1886 | `winum' or`window-numbering' (if available) according to the passed number.
1887 | If ARG is `|' then the node is opened in new vertically split window.
1888 | If ARG is `-' then the node is opened in new horizontally split window."
1889 | (neo-global--select-mru-window arg)
1890 | (find-file full-path))
1891 |
1892 | (defun neo-open-file-vertical-split (full-path arg)
1893 | "Open the current node is a vertically split window.
1894 | FULL-PATH and ARG are the same as `neo-open-file'."
1895 | (neo-open-file full-path "|"))
1896 |
1897 | (defun neo-open-file-horizontal-split (full-path arg)
1898 | "Open the current node is horizontally split window.
1899 | FULL-PATH and ARG are the same as `neo-open-file'."
1900 | (neo-open-file full-path "-"))
1901 |
1902 | (defun neo-open-file-ace-window (full-path arg)
1903 | "Open the current node in a window chosen by ace-window.
1904 | FULL-PATH and ARG are the same as `neo-open-file'."
1905 | (neo-open-file full-path "a"))
1906 |
1907 | (defun neotree-open-file-in-system-application ()
1908 | "Open a file under point in the system application."
1909 | (interactive)
1910 | (call-process neo-default-system-application nil 0 nil
1911 | (neo-buffer--get-filename-current-line)))
1912 |
1913 | (defun neotree-change-root ()
1914 | "Change root to current node dir.
1915 | If current node is a file, then it will do nothing.
1916 | If cannot find any node in current line, it equivalent to using `neotree-dir'."
1917 | (interactive)
1918 | (neo-global--select-window)
1919 | (let ((btn-full-path (neo-buffer--get-filename-current-line)))
1920 | (if (null btn-full-path)
1921 | (call-interactively 'neotree-dir)
1922 | (neo-global--open-dir btn-full-path))))
1923 |
1924 | (defun neotree-select-up-node ()
1925 | "Select the parent directory of the current node. Change the root if
1926 | necessary. "
1927 | (interactive)
1928 | (neo-global--select-window)
1929 | (let* ((btn-full-path (neo-buffer--get-filename-current-line))
1930 | (btn-parent-dir (if btn-full-path (file-name-directory btn-full-path)))
1931 | (root-slash (file-name-as-directory neo-buffer--start-node)))
1932 | (cond
1933 | ((equal btn-parent-dir root-slash) (neo-global--open-dir root-slash))
1934 | (btn-parent-dir (neotree-find btn-parent-dir))
1935 | (t (neo-global--open-dir (file-name-directory
1936 | (directory-file-name root-slash)))))))
1937 |
1938 | (defun neotree-select-down-node ()
1939 | "Select an expanded directory or content directory according to the
1940 | current node, in this order:
1941 | - select the first expanded child node if the current node has one
1942 | - select the content of current node if it is expanded
1943 | - select the next expanded sibling if the current node is not expanded."
1944 | (interactive)
1945 | (let* ((btn-full-path (neo-buffer--get-filename-current-line))
1946 | (path (if btn-full-path btn-full-path neo-buffer--start-node))
1947 | (nodes (neo-buffer--get-nodes-for-select-down-node path)))
1948 | (when nodes
1949 | (if (or (equal path neo-buffer--start-node)
1950 | (neo-buffer--expanded-node-p path))
1951 | ;; select the first expanded child node
1952 | (let ((expanded-dir (catch 'break
1953 | (dolist (node (car nodes))
1954 | (if (neo-buffer--expanded-node-p node)
1955 | (throw 'break node)))
1956 | nil)))
1957 | (if expanded-dir
1958 | (neotree-find expanded-dir)
1959 | ;; select the directory content if needed
1960 | (let ((dirs (car nodes))
1961 | (files (cdr nodes)))
1962 | (if (> (length dirs) 0)
1963 | (neotree-find (car dirs))
1964 | (when (> (length files) 0)
1965 | (neotree-find (car files)))))))
1966 | ;; select the next expanded sibling
1967 | (let ((sibling (neo-buffer--sibling path)))
1968 | (while (and (not (neo-buffer--expanded-node-p sibling))
1969 | (not (equal sibling path)))
1970 | (setq sibling (neo-buffer--sibling sibling)))
1971 | (when (not (string< sibling path))
1972 | ;; select next expanded sibling
1973 | (neotree-find sibling)))))))
1974 |
1975 | (defun neotree-select-next-sibling-node ()
1976 | "Select the next sibling of current node.
1977 | If the current node is the last node then the first node is selected."
1978 | (interactive)
1979 | (let ((sibling (neo-buffer--sibling (neo-buffer--get-filename-current-line))))
1980 | (when sibling (neotree-find sibling))))
1981 |
1982 | (defun neotree-select-previous-sibling-node ()
1983 | "Select the previous sibling of current node.
1984 | If the current node is the first node then the last node is selected."
1985 | (interactive)
1986 | (let ((sibling (neo-buffer--sibling (neo-buffer--get-filename-current-line) t)))
1987 | (when sibling (neotree-find sibling))))
1988 |
1989 | (defun neotree-create-node (filename)
1990 | "Create a file or directory use specified FILENAME in current node."
1991 | (interactive
1992 | (let* ((current-dir (neo-buffer--get-filename-current-line neo-buffer--start-node))
1993 | (current-dir (neo-path--match-path-directory current-dir))
1994 | (filename (read-file-name "Filename:" current-dir)))
1995 | (if (file-directory-p filename)
1996 | (setq filename (concat filename "/")))
1997 | (list filename)))
1998 | (catch 'rlt
1999 | (let ((is-file nil))
2000 | (when (= (length filename) 0)
2001 | (throw 'rlt nil))
2002 | (setq is-file (not (equal (substring filename -1) "/")))
2003 | (when (file-exists-p filename)
2004 | (message "File %S already exists." filename)
2005 | (throw 'rlt nil))
2006 | (when (and is-file
2007 | (funcall neo-confirm-create-file (format "Do you want to create file %S ?"
2008 | filename)))
2009 | ;; ensure parent directory exist before saving
2010 | (mkdir (substring filename 0 (+ 1 (cl-position ?/ filename :from-end t))) t)
2011 | ;; NOTE: create a empty file
2012 | (write-region "" nil filename)
2013 | (neo-buffer--save-cursor-pos filename)
2014 | (neo-buffer--refresh nil)
2015 | (if neo-create-file-auto-open
2016 | (find-file-other-window filename)))
2017 | (when (and (not is-file)
2018 | (funcall neo-confirm-create-directory (format "Do you want to create directory %S?"
2019 | filename)))
2020 | (mkdir filename t)
2021 | (neo-buffer--save-cursor-pos filename)
2022 | (neo-buffer--refresh nil)))))
2023 |
2024 | (defun neotree-delete-node ()
2025 | "Delete current node."
2026 | (interactive)
2027 | (let* ((filename (neo-buffer--get-filename-current-line))
2028 | (buffer (find-buffer-visiting filename))
2029 | (deleted-p nil)
2030 | (trash delete-by-moving-to-trash))
2031 | (catch 'end
2032 | (if (null filename) (throw 'end nil))
2033 | (if (not (file-exists-p filename)) (throw 'end nil))
2034 | (if (not (funcall neo-confirm-delete-file (format "Do you really want to delete %S?"
2035 | filename)))
2036 | (throw 'end nil))
2037 | (if (file-directory-p filename)
2038 | ;; delete directory
2039 | (progn
2040 | (unless (neo-path--has-subfile-p filename)
2041 | (delete-directory filename nil trash)
2042 | (setq deleted-p t)
2043 | (throw 'end nil))
2044 | (when (funcall neo-confirm-delete-directory-recursively
2045 | (format "%S is a directory, delete it recursively?"
2046 | filename))
2047 | (when (funcall neo-confirm-kill-buffers-for-files-in-directory
2048 | (format "kill buffers for files in directory %S?"
2049 | filename))
2050 | (neo-util--kill-buffers-for-path filename))
2051 | (delete-directory filename t trash)
2052 | (setq deleted-p t)))
2053 | ;; delete file
2054 | (progn
2055 | (delete-file filename trash)
2056 | (when buffer
2057 | (kill-buffer-ask buffer))
2058 | (setq deleted-p t))))
2059 | (when deleted-p
2060 | (message "%S deleted." filename)
2061 | (neo-buffer--refresh t))
2062 | filename))
2063 |
2064 | (defun neotree-rename-node ()
2065 | "Rename current node."
2066 | (interactive)
2067 | (neo-buffer--rename-node))
2068 |
2069 | (defun neotree-copy-node ()
2070 | "Copy current node."
2071 | (interactive)
2072 | (neo-buffer--copy-node))
2073 |
2074 | (defun neotree-hidden-file-toggle ()
2075 | "Toggle show hidden files."
2076 | (interactive)
2077 | (neo-buffer--set-show-hidden-file-p (not neo-buffer--show-hidden-file-p)))
2078 |
2079 | (defun neotree-empty-fn ()
2080 | "Used to bind the empty function to the shortcut."
2081 | (interactive))
2082 |
2083 | (defun neotree-refresh (&optional is-auto-refresh)
2084 | "Refresh the NeoTree buffer."
2085 | (interactive)
2086 | (if (eq (current-buffer) (neo-global--get-buffer))
2087 | (neo-buffer--refresh t)
2088 | (save-excursion
2089 | (let ((cw (selected-window))) ;; save current window
2090 | (if is-auto-refresh
2091 | (let ((origin-buffer-file-name (buffer-file-name)))
2092 | (when (and (fboundp 'projectile-project-p)
2093 | (projectile-project-p)
2094 | (fboundp 'projectile-project-root))
2095 | (neo-global--open-dir (projectile-project-root))
2096 | (neotree-find (projectile-project-root)))
2097 | (neotree-find origin-buffer-file-name))
2098 | (neo-buffer--refresh t t))
2099 | (recenter)
2100 | (when (or is-auto-refresh neo-toggle-window-keep-p)
2101 | (select-window cw))))))
2102 |
2103 | (defun neotree-stretch-toggle ()
2104 | "Make the NeoTree window toggle maximize/minimize."
2105 | (interactive)
2106 | (neo-global--with-window
2107 | (if (neo-window--minimize-p)
2108 | (neo-window--zoom 'maximize)
2109 | (neo-window--zoom 'minimize))))
2110 |
2111 | (defun neotree-collapse-all ()
2112 | (interactive)
2113 | "Collapse all expanded folders in the neotree buffer"
2114 | (setq list-of-expanded-folders neo-buffer--expanded-node-list)
2115 | (dolist (folder list-of-expanded-folders)
2116 | (neo-buffer--toggle-expand folder)
2117 | (neo-buffer--refresh t)
2118 | )
2119 | )
2120 | ;;;###autoload
2121 | (defun neotree-projectile-action ()
2122 | "Integration with `Projectile'.
2123 |
2124 | Usage:
2125 | (setq projectile-switch-project-action 'neotree-projectile-action).
2126 |
2127 | When running `projectile-switch-project' (C-c p p), `neotree' will change root
2128 | automatically."
2129 | (interactive)
2130 | (cond
2131 | ((fboundp 'projectile-project-root)
2132 | (neotree-dir (projectile-project-root)))
2133 | (t
2134 | (error "Projectile is not available"))))
2135 |
2136 | ;;;###autoload
2137 | (defun neotree-toggle ()
2138 | "Toggle show the NeoTree window."
2139 | (interactive)
2140 | (if (neo-global--window-exists-p)
2141 | (neotree-hide)
2142 | (neotree-show)))
2143 |
2144 | ;;;###autoload
2145 | (defun neotree-show ()
2146 | "Show the NeoTree window."
2147 | (interactive)
2148 | (let ((cw (selected-window))
2149 | (path (buffer-file-name))) ;; save current window and buffer
2150 | (if neo-smart-open
2151 | (progn
2152 | (when (and (fboundp 'projectile-project-p)
2153 | (projectile-project-p)
2154 | (fboundp 'projectile-project-root))
2155 | (neotree-dir (projectile-project-root)))
2156 | (neotree-find path))
2157 | (neo-global--open))
2158 | (neo-global--select-window)
2159 | (when neo-toggle-window-keep-p
2160 | (select-window cw))))
2161 |
2162 | ;;;###autoload
2163 | (defun neotree-hide ()
2164 | "Close the NeoTree window."
2165 | (interactive)
2166 | (if (neo-global--window-exists-p)
2167 | (delete-window neo-global--window)))
2168 |
2169 | ;;;###autoload
2170 | (defun neotree-dir (path)
2171 | "Show the NeoTree window, and change root to PATH."
2172 | (interactive "DDirectory: ")
2173 | (neo-global--open-dir path)
2174 | (neo-global--select-window))
2175 |
2176 | ;;;###autoload
2177 | (defalias 'neotree 'neotree-show "Show the NeoTree window.")
2178 |
2179 | ;;
2180 | ;; backward compatible
2181 | ;;
2182 |
2183 | (defun neo-bc--make-obsolete-message (from to)
2184 | (message "Warning: `%S' is obsolete. Use `%S' instead." from to))
2185 |
2186 | (defun neo-buffer--enter-file (path)
2187 | (neo-bc--make-obsolete-message 'neo-buffer--enter-file 'neo-open-file))
2188 |
2189 | (defun neo-buffer--enter-dir (path)
2190 | (neo-bc--make-obsolete-message 'neo-buffer--enter-dir 'neo-open-dir))
2191 |
2192 | (defun neotree-enter (&optional arg)
2193 | "NeoTree typical open event.
2194 | ARG are the same as `neo-open-file'."
2195 | (interactive "P")
2196 | (neo-buffer--execute arg 'neo-open-file 'neo-open-dir))
2197 |
2198 | (defun neotree-quick-look (&optional arg)
2199 | "Quick Look like NeoTree open event.
2200 | ARG are the same as `neo-open-file'."
2201 | (interactive "P")
2202 | (neotree-enter arg)
2203 | (neo-global--select-window))
2204 |
2205 | (defun neotree-enter-vertical-split ()
2206 | "NeoTree open event, file node will opened in new vertically split window."
2207 | (interactive)
2208 | (neo-buffer--execute nil 'neo-open-file-vertical-split 'neo-open-dir))
2209 |
2210 | (defun neotree-enter-horizontal-split ()
2211 | "NeoTree open event, file node will opened in new horizontally split window."
2212 | (interactive)
2213 | (neo-buffer--execute nil 'neo-open-file-horizontal-split 'neo-open-dir))
2214 |
2215 | (defun neotree-enter-ace-window ()
2216 | "NeoTree open event, file node will be opened in window chosen by ace-window."
2217 | (interactive)
2218 | (neo-buffer--execute nil 'neo-open-file-ace-window 'neo-open-dir))
2219 |
2220 | (defun neotree-copy-filepath-to-yank-ring ()
2221 | "Neotree convenience interactive function: file node path will be added to the kill ring."
2222 | (interactive)
2223 | (kill-new (neo-buffer--get-filename-current-line)))
2224 |
2225 | (defun neotree-split-window-sensibly (&optional window)
2226 | "An neotree-version of split-window-sensibly,
2227 | which is used to fix issue #209.
2228 | (setq split-window-preferred-function 'neotree-split-window-sensibly)"
2229 | (let ((window (or window (selected-window))))
2230 | (or (split-window-sensibly window)
2231 | (and (get-buffer-window neo-buffer-name)
2232 | (not (window-minibuffer-p window))
2233 | ;; If WINDOW is the only window on its frame
2234 | ;; (or only include Neo window) and is not the
2235 | ;; minibuffer window, try to split it vertically disregarding
2236 | ;; the value of `split-height-threshold'.
2237 | (let ((split-height-threshold 0))
2238 | (when (window-splittable-p window)
2239 | (with-selected-window window
2240 | (split-window-below))))))))
2241 |
2242 | (provide 'neotree)
2243 | ;;; neotree.el ends here
2244 |
2245 |
--------------------------------------------------------------------------------
/screenshots/icons.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jaypei/emacs-neotree/4a4cd8576157a39c0fdb478a2887c01ccfe1aec9/screenshots/icons.png
--------------------------------------------------------------------------------
/test/neotree-test.el:
--------------------------------------------------------------------------------
1 | ;;; neotree-test.el --- test utilities
2 |
3 | ;; Copyright (C) 2014 jaypei
4 |
5 | ;; Author: jaypei
6 | ;; URL: https://github.com/jaypei/emacs-neotree
7 |
8 | ;; This program is free software; you can redistribute it and/or modify
9 | ;; it under the terms of the GNU General Public License as published by
10 | ;; the Free Software Foundation, either version 3 of the License, or
11 | ;; (at your option) any later version.
12 |
13 | ;; This program is distributed in the hope that it will be useful,
14 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | ;; GNU General Public License for more details.
17 |
18 | ;; You should have received a copy of the GNU General Public License
19 | ;; along with this program. If not, see .
20 |
21 | ;;; Commentary:
22 |
23 | ;;; Code:
24 |
25 | (defmacro neo-test--with-temp-dir (&rest body)
26 | (declare (indent 0) (debug t))
27 | `(let* ((temp-cwd (file-name-as-directory (make-temp-file "dir" t)))
28 | (temp-pd (neo-path--join temp-cwd "neo-test" "./")))
29 | (mkdir temp-pd)
30 | (unwind-protect
31 | (let ((default-directory temp-cwd)) ,@body)
32 | (delete-directory temp-cwd t))))
33 |
34 | (defun neo-test--with-temp-dir-open ()
35 | (neo-test--with-temp-dir
36 | (write-region "" nil "file-1")
37 | (write-region "hello" nil "file-2")
38 | (neotree-dir temp-cwd)))
39 |
40 | (defmacro neo-test--try-open (name &rest body)
41 | (declare (indent 0) (debug t))
42 | `(ert-deftest ,name ()
43 | ,@body
44 | (neo-test--with-temp-dir-open)))
45 |
46 | (provide 'neotree-test)
47 | ;;; neotree-test.el ends here
48 |
--------------------------------------------------------------------------------
/test/test-buffer.el:
--------------------------------------------------------------------------------
1 | ;;; test-buffer.el --- summary
2 |
3 | ;; Copyright (C) 2014 jaypei
4 |
5 | ;; Author: jaypei
6 | ;; Version: 0
7 |
8 | ;; This program is free software; you can redistribute it and/or modify
9 | ;; it under the terms of the GNU General Public License as published by
10 | ;; the Free Software Foundation, either version 3 of the License, or
11 | ;; (at your option) any later version.
12 |
13 | ;; This program is distributed in the hope that it will be useful,
14 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | ;; GNU General Public License for more details.
17 |
18 | ;; You should have received a copy of the GNU General Public License
19 | ;; along with this program. If not, see .
20 |
21 | ;;; Commentary:
22 |
23 | ;;; Code:
24 |
25 | (require 'neotree)
26 | (require 'neotree-test)
27 |
28 | (ert-deftest neo-test-save-current-pos ()
29 | (neotree)
30 | (neo-global--select-window)
31 | (beginning-of-line)
32 | (condition-case err
33 | (while t
34 | (next-line)
35 | (neo-buffer--save-cursor-pos)
36 | (let ((current-file-path (neo-buffer--get-filename-current-line))
37 | (current-line-number (line-number-at-pos)))
38 | (should (eq (car neo-buffer--cursor-pos) current-file-path))
39 | (should (eq (cdr neo-buffer--cursor-pos) current-line-number))))
40 | (error
41 | (should (equal err '(end-of-buffer)))))
42 | (neo-buffer--save-cursor-pos "/tmp/nbs" 192)
43 | (should (equal neo-buffer--cursor-pos (cons "/tmp/nbs" 192))))
44 |
45 | (ert-deftest neo-test-set-node-list ()
46 | (neotree)
47 | (neo-global--select-window)
48 | (neo-buffer--node-list-clear)
49 | (should (equal neo-buffer--node-list nil))
50 | (neo-buffer--node-list-set 10 "foo")
51 | (should (equal neo-buffer--node-list
52 | [nil nil nil nil nil nil nil nil nil "foo"]))
53 | (neo-buffer--node-list-set 3 "bar")
54 | (neo-buffer--node-list-set 15 "foobar")
55 | (should (equal neo-buffer--node-list
56 | [nil nil "bar" nil nil
57 | nil nil nil nil "foo"
58 | nil nil nil nil "foobar"]))
59 | (neo-buffer--node-list-clear)
60 | (should (equal neo-buffer--node-list nil)))
61 |
62 | (ert-deftest neo-test-set-node-list-current-line-number ()
63 | (neotree)
64 | (neo-global--select-window)
65 | (end-of-line)
66 | (let ((n (line-number-at-pos)))
67 | (neo-buffer--node-list-set nil "DUMMY")
68 | (beginning-of-line)
69 | (should (string= (elt neo-buffer--node-list (1- n)) "DUMMY"))))
70 |
71 |
72 | (provide 'test-buffer)
73 | ;;; test-buffer.el ends here
74 |
--------------------------------------------------------------------------------
/test/test-cmds.el:
--------------------------------------------------------------------------------
1 | ;;; test-cmds.el --- test cases
2 |
3 | ;; Copyright (C) 2014 jaypei
4 |
5 | ;; Author: jaypei
6 | ;; URL: https://github.com/jaypei/emacs-neotree
7 |
8 | ;; This program is free software; you can redistribute it and/or modify
9 | ;; it under the terms of the GNU General Public License as published by
10 | ;; the Free Software Foundation, either version 3 of the License, or
11 | ;; (at your option) any later version.
12 |
13 | ;; This program is distributed in the hope that it will be useful,
14 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | ;; GNU General Public License for more details.
17 |
18 | ;; You should have received a copy of the GNU General Public License
19 | ;; along with this program. If not, see .
20 |
21 | ;;; Commentary:
22 |
23 | ;;; Code:
24 |
25 | (require 'neotree)
26 | (require 'neotree-test)
27 |
28 |
29 | (ert-deftest neo-test-neotree-startup ()
30 | (neotree)
31 | (should (neo-global--window-exists-p)))
32 |
33 | (ert-deftest neo-test-neotree-toggle ()
34 | (neotree-toggle)
35 | (should (neo-global--window-exists-p))
36 | (neotree-show)
37 | (should (neo-global--window-exists-p))
38 | (neotree-toggle)
39 | (should (not (neo-global--window-exists-p)))
40 | (neotree-hide)
41 | (should (not (neo-global--window-exists-p)))
42 | (neotree-show)
43 | (should (neo-global--window-exists-p)))
44 |
45 | (ert-deftest neo-test-neotree-dir ()
46 | (neo-test--with-temp-dir
47 | (neotree-dir temp-cwd)
48 | (neo-global--with-buffer
49 | (should (string-equal neo-buffer--start-node temp-cwd)))
50 | (neotree-toggle)
51 | (neo-global--with-buffer
52 | (should (string-equal neo-buffer--start-node temp-cwd)))
53 | (neotree-toggle)
54 | (neo-global--with-buffer
55 | (should (string-equal neo-buffer--start-node temp-cwd)))))
56 |
57 | ;;; test-cmds.el ends here
58 |
--------------------------------------------------------------------------------
/test/test-utils.el:
--------------------------------------------------------------------------------
1 | ;;; test-utils.el --- test cases
2 |
3 | ;; Copyright (C) 2014 jaypei
4 |
5 | ;; Author: jaypei
6 | ;; URL: https://github.com/jaypei/emacs-neotree
7 |
8 | ;; This program is free software; you can redistribute it and/or modify
9 | ;; it under the terms of the GNU General Public License as published by
10 | ;; the Free Software Foundation, either version 3 of the License, or
11 | ;; (at your option) any later version.
12 |
13 | ;; This program is distributed in the hope that it will be useful,
14 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | ;; GNU General Public License for more details.
17 |
18 | ;; You should have received a copy of the GNU General Public License
19 | ;; along with this program. If not, see .
20 |
21 | ;;; Commentary:
22 |
23 | ;;; Code:
24 |
25 | (require 'neotree)
26 | (require 'neotree-test)
27 |
28 |
29 | (ert-deftest neo-test-filter ()
30 | (let ((should-equal (lambda (condp lst y)
31 | (should (equal (neo-util--filter condp lst) y)))))
32 | (apply should-equal (list (lambda (x) (> x 10))
33 | '(1 2 8 12 30)
34 | '(12 30)))
35 | (apply should-equal (list (lambda (x) nil)
36 | '(1 2 8 12 30)
37 | nil))
38 | (apply should-equal (list (lambda (x) t)
39 | '(1 2 8 12 30)
40 | '(1 2 8 12 30)))
41 | (apply should-equal (list 'integerp
42 | '(1 "foo" 2 8 "bar" 12 30)
43 | '(1 2 8 12 30)))
44 | (apply should-equal (list 'integerp
45 | '(1 "foo" "bar")
46 | '(1)))
47 | (apply should-equal (list 'integerp
48 | '("foo" "bar" 30)
49 | '(30)))
50 | (apply should-equal (list (lambda (x) (and (not (string= x "."))
51 | (not (string= x ".."))))
52 | '("." ".." ".neotree/" "otherfiles")
53 | '(".neotree/" "otherfiles")))))
54 |
55 |
56 | (ert-deftest neo-test-find ()
57 | (let ((should-equal (lambda (where which y)
58 | (should (equal (neo-util--find where which) y)))))
59 | (apply should-equal (list '("hello" 1 "world") 'integerp 1))
60 | (apply should-equal (list '("hello" 1 "world") 'stringp "hello"))
61 | (apply should-equal (list '("hello" "world" 100000) 'integerp 100000))))
62 |
63 |
64 | (ert-deftest neo-test-newline-and-begin ()
65 | (with-temp-buffer
66 | (neo-buffer--newline-and-begin)))
67 |
68 |
69 | (ert-deftest neo-test-file-short-name ()
70 | (let ((should-equal (lambda (x y)
71 | (should (string= (neo-path--file-short-name x) y)))))
72 | (apply should-equal '("~/" "~"))
73 | (apply should-equal '("/" "/"))
74 | (apply should-equal '("~/." "."))
75 | (apply should-equal '("afile" "afile"))
76 | (apply should-equal '("a/" "a"))
77 | (apply should-equal '("" ""))
78 | (apply should-equal '("~/abc.org" "abc.org"))
79 | (apply should-equal '("/home/q/hello/world/" "world"))
80 | (apply should-equal '("/home/q/hello/world/.abc" ".abc"))))
81 |
82 |
83 | (ert-deftest neo-test-insert-with-face ()
84 | (with-temp-buffer
85 | (insert "foo")
86 | (neo-buffer--insert-with-face "ButtonContent" 'default)
87 | (insert "bar")
88 | (goto-char 4)
89 | (should (eq (face-at-point) 'default))
90 | (should (string= (buffer-string) "fooButtonContentbar"))))
91 |
92 | (ert-deftest neo-test-strip-path ()
93 | (setq cases '((" /" . "/")
94 | ("\n/" . "/")
95 | ("\n \t/" . "/")
96 | ("\n \t~/abc.org " . "~/abc.org")))
97 | (mapc
98 | (lambda (x) (should (equal (neo-path--strip (car x))
99 | (cdr x))))
100 | cases))
101 |
102 | (ert-deftest neo-test-file-equal-p ()
103 | (let ((fn 'neo-path--file-equal-p)
104 | (cases '((("/etc/passwd" "/etc/passwd") . t)
105 | (("/tmp/no-exists-file" "/tmp/no-exists-file") . nil)
106 | ((nil "/etc/passwd") . nil)
107 | (("/etc/passwd" nil) . nil))))
108 | (mapcar (lambda (x) (should (eq (apply fn (car x)) (cdr x)))) cases)))
109 |
110 |
111 | ;;; test-utils.el ends here
112 |
--------------------------------------------------------------------------------
/test/test-vc.el:
--------------------------------------------------------------------------------
1 | ;;; test-vc.el --- test cases
2 |
3 | ;; Copyright (C) 2014 jaypei
4 |
5 | ;; Author: jaypei
6 | ;; URL: https://github.com/jaypei/emacs-neotree
7 |
8 | ;; This program is free software; you can redistribute it and/or modify
9 | ;; it under the terms of the GNU General Public License as published by
10 | ;; the Free Software Foundation, either version 3 of the License, or
11 | ;; (at your option) any later version.
12 |
13 | ;; This program is distributed in the hope that it will be useful,
14 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | ;; GNU General Public License for more details.
17 |
18 | ;; You should have received a copy of the GNU General Public License
19 | ;; along with this program. If not, see .
20 |
21 | ;;; Commentary:
22 |
23 | ;;; Code:
24 |
25 | (require 'neotree)
26 | (require 'neotree-test)
27 |
28 | (neo-test--try-open
29 | neo-test-vc-mode-with-face
30 | (shell-command-to-string "git init")
31 | (setq neo-vc-integration '(face)))
32 |
33 | (neo-test--try-open
34 | neo-test-vc-mode-with-char
35 | (shell-command-to-string "git init")
36 | (setq neo-vc-integration '(char)))
37 |
38 | (neo-test--try-open
39 | neo-test-vc-mode-with-char-face
40 | (shell-command-to-string "git init")
41 | (setq neo-vc-integration '(char face)))
42 |
43 |
44 | ;;; test-vc.el ends here
45 |
--------------------------------------------------------------------------------