pax_global_header00006660000000000000000000000064140166755230014523gustar00rootroot0000000000000052 comment=49ddccc917956c15a9b36983cd6a817ba2b3ec3c subed-master/000077500000000000000000000000001401667552300134625ustar00rootroot00000000000000subed-master/LICENSE000066400000000000000000001045151401667552300144750ustar00rootroot00000000000000 GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . subed-master/Makefile000066400000000000000000000033061401667552300151240ustar00rootroot00000000000000clean: find . -name "*.elc" -delete test: emacs -batch -f package-initialize -L . -f buttercup-run-discover emacs --no-init-file --batch \ --eval "(require 'package-lint)" \ --file package-lint-batch-and-exit \ ./subed/subed.el emacs --quick --batch --eval "(checkdoc-file \"subed/subed.el\")" emacs --quick --batch --eval "(checkdoc-file \"subed/subed-config.el\")" emacs --quick --batch --eval "(checkdoc-file \"subed/subed-mpv.el\")" emacs --quick --batch --eval "(checkdoc-file \"subed/subed-srt.el\")" test-compile: emacs --quick --batch --eval "(progn (add-to-list 'load-path (expand-file-name \"subed\" default-directory)) \ (byte-compile-file \"subed/subed.el\"))" emacs --quick --batch --eval "(progn (add-to-list 'load-path (expand-file-name \"subed\" default-directory)) \ (byte-compile-file \"subed/subed-config.el\"))" emacs --quick --batch --eval "(progn (add-to-list 'load-path (expand-file-name \"subed\" default-directory)) \ (byte-compile-file \"subed/subed-common.el\"))" emacs --quick --batch --eval "(progn (add-to-list 'load-path (expand-file-name \"subed\" default-directory)) \ (byte-compile-file \"subed/subed-mpv.el\"))" emacs --quick --batch --eval "(progn (add-to-list 'load-path (expand-file-name \"subed\" default-directory)) \ (byte-compile-file \"subed/subed-srt.el\"))" emacs --quick --batch --eval "(progn (add-to-list 'load-path (expand-file-name \"subed\" default-directory)) \ (byte-compile-file \"subed/subed-debug.el\"))" make clean subed-master/README.org000066400000000000000000000077231401667552300151410ustar00rootroot00000000000000* subed subed is an Emacs major mode for editing subtitles while playing the corresponding video with [[https://mpv.io/][mpv]]. At the moment, the only supported formats are SubRip ( ~.srt~) and WebVTT ( ~.vtt~ ). [[file:https://raw.githubusercontent.com/rndusr/subed/master/screenshot.jpg]] ** Features - Quickly jump to next (~M-n~) and previous (~M-p~) subtitle text. - Quickly jump to the beginning (~C-M-a~) and end (~C-M-e~) of the current subtitle's text. - Insert subtitles evenly spaced throughout the available space (~M-i~) or right next the current subtitle (~C-M-i~). A prefix argument controls how many subtitles to insert and whether they are inserted before or after the current subtitle. - Kill subtitles (~M-k~). - Adjust subtitle start (~M-[~ / ~M-]~) and stop (~M-{~ / ~M-}~) time. A prefix argument sets the number of milliseconds for the current session (e.g. ~C-u 1000 M-[ M-[ M-[~ decreases start time by 3 seconds). - Move the current subtitle or all marked subtitles forward (~C-M-n~) or backward (~C-M-p~) in time without changing subtitle duration. A prefix argument sets the number of milliseconds for the current session (e.g. ~C-u 500 C-M-n C-M-n~ moves the current subtitle 1 second forward). - Shift the current subtitle forward (~C-M-f~) or backward (~C-M-b~) together with all following subtitles. This is basically a convenience shortcut for ~C-SPC M-> C-M-n/p~. - Sort and re-number subtitles and remove any extra spaces and newlines (~M-s~). This is done automatically every time the buffer is saved. *** mpv integration (optional) - Open videos with ~C-c C-v~ or automatically when entering subed-mode if the video file is named like the subtitle file but with a video extension (e.g. ~.mkv~ or ~.avi~). - Subtitles are automatically reloaded in mpv when the buffer is saved. - Cursor and playback position are synchronized: - Playback in mpv seeks to the position of the current subtitle as the cursor moves between subtitles (~C-c ,~). - The cursor is moved to the currently relevant subtitle as the video is playing (~C-c .~). - Copy the current playback position as start (~C-c [~) or stop (~C-c ]~) time of the current subtitle. - Playback is paused or slowed down when a subtitle's text is edited (~C-c C-p~). - Loop over the current subtitle in mpv (~C-c C-l~). - When a subtitle's start or stop time changes, mpv seeks to the subtitle's start time (~C-c C-r~). - Pause video playback without leaving Emacs (~M-SPC~). ** Installation For now, you have to install it manually. For example, copy ~subed/*.el~ to ~$HOME/.emacs.d/elisp/~ and add ~$HOME/.emacs.d/elisp/~ to your ~load-path~. #+BEGIN_SRC elisp (use-package subed ;; Tell emacs where to find subed :load-path "~/.emacs.d/elisp/" :config ;; Disable automatic movement of point by default (add-hook 'subed-mode-hook 'subed-disable-sync-point-to-player) ;; Remember cursor position between sessions (add-hook 'subed-mode-hook 'save-place-local-mode) ;; Break lines automatically while typing (add-hook 'subed-mode-hook 'turn-on-auto-fill) ;; Break lines at 40 characters (add-hook 'subed-mode-hook (lambda () (setq-local fill-column 40)))) #+END_SRC ~C-h f subed-mode~ should get you started. ** License subed is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY; without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%|<]*hkwwUAlT]Z I{F@5#R:z%y;P T(7_}с,P|5A&dRRUz>(((((((((((((((((((((((((((((m&y6}pPPPPPPPPPPPPPPPPPPPPPPPPPPPPPsubed-master/subed/000077500000000000000000000000001401667552300145645ustar00rootroot00000000000000subed-master/subed/subed-common.el000066400000000000000000001347721401667552300175140ustar00rootroot00000000000000;;; subed-common.el --- Subtitle-format agnostic functions -*- lexical-binding: t; -*- ;;; License: ;; ;; This file is not part of GNU Emacs. ;; ;; This is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation; either version 3, or (at your option) ;; any later version. ;; ;; This is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs; see the file COPYING. If not, write to the ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, ;; Boston, MA 02110-1301, USA. ;;; Commentary: ;; ;; The functions in this file do not expect any particular subtitle format. ;; Instead, they expect certain functions to exist that provide navigation and ;; manipulation for whatever format the current buffer contains. ;;; Code: (require 'subed-config) (require 'subed-debug) (require 'subed-mpv) ;;; Utilities (defun subed-msecs-to-timestamp (msecs) "Convert MSECS to human-readable string." ;; We need to wrap format-seconds in save-match-data because it does regexp ;; stuff and we need to preserve our own match-data. (concat (save-match-data (format-seconds "%02h:%02m:%02s" (/ msecs 1000))) "," (format "%03d" (mod msecs 1000)))) (defmacro subed-save-excursion (&rest body) "Restore relative point within current subtitle after executing BODY. This also works if the buffer changes (e.g. when sorting subtitles) as long the subtitle IDs don't change." (save-excursion `(let ((sub-id (subed-subtitle-id)) (sub-pos (subed-subtitle-relative-point))) (progn ,@body) (subed-jump-to-subtitle-id sub-id) ;; Subtitle text may have changed and we may not be able to move to the ;; exact original position (condition-case nil (forward-char sub-pos) ('beginning-of-buffer nil) ('end-of-buffer nil))))) (defmacro subed-for-each-subtitle (beg end reverse &rest body) "Run BODY for each subtitle between the region specified by BEG and END. If END is nil, it defaults to `point-max'. If BEG and END are both nil, run BODY only on the subtitle at point. If REVERSE is non-nil, start on the subtitle at END and move backwards. Before BODY is run, point is placed on the subtitle's ID." (declare (indent defun)) `(atomic-change-group (if (not ,beg) ;; Run body on subtitle at point (save-excursion (subed-jump-to-subtitle-id) ,@body) (let ((begm (make-marker)) (endm (make-marker))) (set-marker begm ,beg) (set-marker endm (or ,end (point-max))) ;; Run body on multiple subtitles (if ,reverse ;; Iterate backwards (save-excursion (goto-char endm) (subed-jump-to-subtitle-id) (catch 'first-subtitle-reached (while t ;; The subtitle includes every character up to the next subtitle's ID (or eob) (let ((sub-end (save-excursion (subed-jump-to-subtitle-end)))) (when (< sub-end begm) (throw 'first-subtitle-reached t))) (progn ,@body) (unless (subed-backward-subtitle-id) (throw 'first-subtitle-reached t))))) ;; Iterate forwards (save-excursion (goto-char begm) (subed-jump-to-subtitle-id) (catch 'last-subtitle-reached (while t (when (> (point) endm) (throw 'last-subtitle-reached t)) (progn ,@body) (unless (subed-forward-subtitle-id) (throw 'last-subtitle-reached t)))))))))) (defmacro subed-with-subtitle-replay-disabled (&rest body) "Run BODY while automatic subtitle replay is disabled." (declare (indent defun)) `(let ((replay-was-enabled-p (subed-replay-adjusted-subtitle-p))) (subed-disable-replay-adjusted-subtitle :quiet) (progn ,@body) (when replay-was-enabled-p (subed-enable-replay-adjusted-subtitle :quiet)))) (defun subed--right-pad (string length fillchar) "Use FILLCHAR to make STRING LENGTH characters long." (concat string (make-string (- length (length string)) fillchar))) ;;; Hooks for point motion and subtitle motion (defvar-local subed--current-point -1) (defvar-local subed--current-subtitle-id -1) (defun subed--post-command-handler () "Detect point motion and user entering text and signal hooks." ;; Check for point motion first to avoid expensive calls to subed-subtitle-id ;; as often as possible. (let ((new-point (point))) (when (and new-point subed--current-point (not (= new-point subed--current-point))) ;; If point is synced to playback position, temporarily disable that so ;; that manual moves aren't cancelled immediately by automated moves. (subed-disable-sync-point-to-player-temporarily) ;; Store new point and fire signal. (setq subed--current-point new-point) (run-hooks 'subed-point-motion-hook) ;; Check if point moved across subtitle boundaries. (let ((new-sub-id (subed-subtitle-id))) (when (and new-sub-id subed--current-subtitle-id (not (funcall (if (stringp subed--current-subtitle-id) 'string= 'equal) new-sub-id subed--current-subtitle-id))) ;; Store new ID and fire signal. (setq subed--current-subtitle-id new-sub-id) (run-hooks 'subed-subtitle-motion-hook)))))) ;;; Adjusting start/stop time individually (defun subed-adjust-subtitle-time-start (msecs &optional ignore-negative-duration ignore-overlap) "Add MSECS milliseconds to start time (use negative value to subtract). Unless either IGNORE-NEGATIVE-DURATION or `subed-enforce-time-boundaries' are non-nil, adjust MSECS so that the stop time isn't smaller than the start time. Zero-length subtitles are always allowed. Unless either IGNORE-OVERLAP or `subed-enforce-time-boundaries' are non-nil, ensure that there are no gaps between subtitles smaller than `subed-subtitle-spacing' milliseconds by adjusting MSECS if necessary. Return the number of milliseconds the start time was adjusted or nil if nothing changed." (subed-disable-sync-point-to-player-temporarily) (let* ((msecs-start (subed-subtitle-msecs-start)) (msecs-new (when msecs-start (+ msecs-start msecs)))) (when msecs-new (if (> msecs 0) ;; Adding to start time (unless (or ignore-negative-duration (not subed-enforce-time-boundaries)) (let ((msecs-stop (subed-subtitle-msecs-stop))) (setq msecs-new (min msecs-new msecs-stop)))) ;; Subtracting from start time (unless (or ignore-overlap (not subed-enforce-time-boundaries)) (let* ((msecs-prev-stop (save-excursion (when (subed-backward-subtitle-id) (subed-subtitle-msecs-stop)))) (msecs-min (if msecs-prev-stop (+ msecs-prev-stop subed-subtitle-spacing) 0))) (when msecs-min (setq msecs-new (max msecs-new msecs-min)))))) ;; MSECS-NEW must be bigger than the current start time if we are adding ;; or smaller if we are subtracting. (when (and (>= msecs-new 0) ;; Ignore negative times (or (and (> msecs 0) (> msecs-new msecs-start)) ;; Adding (and (< msecs 0) (< msecs-new msecs-start)))) ;; Subtracting (subed-set-subtitle-time-start msecs-new) (subed--run-subtitle-time-adjusted-hook) (- msecs-new msecs-start))))) (defun subed-adjust-subtitle-time-stop (msecs &optional ignore-negative-duration ignore-overlap) "Add MSECS milliseconds to stop time (use negative value to subtract). Unless either IGNORE-NEGATIVE-DURATION or `subed-enforce-time-boundaries' are non-nil, adjust MSECS so that the stop time isn't smaller than the start time. Zero-length subtitles are always allowed. Unless either IGNORE-OVERLAP or `subed-enforce-time-boundaries' are non-nil, ensure that there are no gaps between subtitles smaller than `subed-subtitle-spacing' milliseconds by adjusting MSECS if necessary. Return the number of milliseconds the stop time was adjusted or nil if nothing changed." (subed-disable-sync-point-to-player-temporarily) (let* ((msecs-stop (subed-subtitle-msecs-stop)) (msecs-new (when msecs-stop (+ msecs-stop msecs)))) (when msecs-new (if (> msecs 0) ;; Adding to stop time (unless (or ignore-overlap (not subed-enforce-time-boundaries)) (let* ((msecs-next-start (save-excursion (when (subed-forward-subtitle-id) (subed-subtitle-msecs-start)))) (msecs-max (when msecs-next-start (- msecs-next-start subed-subtitle-spacing)))) (when msecs-max (setq msecs-new (min msecs-new msecs-max))))) ;; Subtracting from stop time (unless (or ignore-negative-duration (not subed-enforce-time-boundaries)) (let ((msecs-start (subed-subtitle-msecs-start))) (setq msecs-new (max msecs-new msecs-start))))) ;; MSECS-NEW must be bigger than the current stop time if we are adding or ;; smaller if we are subtracting. (when (and (>= msecs-new 0) ;; Ignore negative times (or (and (> msecs 0) (> msecs-new msecs-stop)) ;; Adding (and (< msecs 0) (< msecs-new msecs-stop)))) ;; Subtracting (subed-set-subtitle-time-stop msecs-new) (subed--run-subtitle-time-adjusted-hook) (- msecs-new msecs-stop))))) (defun subed-increase-start-time (&optional arg) "Add `subed-milliseconds-adjust' milliseconds to start time. Return new start time in milliseconds or nil if it didn't change. If prefix argument ARG is given, it is used to set `subed-milliseconds-adjust' before moving subtitles. If the prefix argument is given but not numerical, `subed-milliseconds-adjust' is reset to its default value. Example usage: \\[universal-argument] 1000 \\[subed-increase-start-time] Increase start time by 1000ms \\[subed-increase-start-time] Increase start time by 1000ms again \\[universal-argument] 500 \\[subed-increase-start-time] Increase start time by 500ms \\[subed-increase-start-time] Increase start time by 500ms again \\[universal-argument] \\[subed-increase-start-time] Increase start time by 100ms (the default) \\[subed-increase-start-time] Increase start time by 100ms (the default) again" (interactive "P") (subed-adjust-subtitle-time-start (subed-get-milliseconds-adjust arg))) (defun subed-decrease-start-time (&optional arg) "Subtract `subed-milliseconds-adjust' milliseconds from start time. Return new start time in milliseconds or nil if it didn't change. See `subed-increase-start-time' about ARG." (interactive "P") (subed-adjust-subtitle-time-start (* -1 (subed-get-milliseconds-adjust arg)))) (defun subed-increase-stop-time (&optional arg) "Add `subed-milliseconds-adjust' milliseconds to stop time. Return new stop time in milliseconds or nil if it didn't change. See `subed-increase-start-time' about ARG." (interactive "P") (subed-adjust-subtitle-time-stop (subed-get-milliseconds-adjust arg))) (defun subed-decrease-stop-time (&optional arg) "Subtract `subed-milliseconds-adjust' milliseconds from stop time. Return new stop time in milliseconds or nil if it didn't change. See `subed-increase-start-time' about ARG." (interactive "P") (subed-adjust-subtitle-time-stop (* -1 (subed-get-milliseconds-adjust arg)))) (defun subed-copy-player-pos-to-start-time () "Replace current subtitle's start time with current playback time." (interactive) (when (and subed-mpv-playback-position (subed-subtitle-msecs-start)) (subed-set-subtitle-time-start subed-mpv-playback-position) (subed--run-subtitle-time-adjusted-hook) subed-mpv-playback-position)) (defun subed-copy-player-pos-to-stop-time () "Replace current subtitle's stop time with current playback time." (interactive) (when (and subed-mpv-playback-position (subed-subtitle-msecs-stop)) (subed-set-subtitle-time-stop subed-mpv-playback-position) (subed--run-subtitle-time-adjusted-hook) subed-mpv-playback-position)) ;;; Moving subtitles ;;; (adjusting start and stop time by the same amount) (defun subed--get-move-subtitle-func (msecs) "Return subtitle moving function. When moving subtitles forward (MSECS > 0), we must adjust the stop time first and adjust the start time by the same amount the stop time was adjusted. This ensures that subtitle length doesn't change if we can't move MSECS milliseconds forward because we'd overlap with the next subtitle. When moving subtitles backward (MSECS < 0), it's the same thing but we move the start time first." (if (> msecs 0) ;; Moving forward (lambda (msecs &optional ignore-overlap) (let ((msecs (subed-adjust-subtitle-time-stop msecs :ignore-negative-duration ignore-overlap))) (when msecs (subed-adjust-subtitle-time-start msecs :ignore-negative-duration ignore-overlap)))) ;; Moving backward (lambda (msecs &optional ignore-overlap) (let ((msecs (subed-adjust-subtitle-time-start msecs :ignore-negative-duration ignore-overlap))) (when msecs (subed-adjust-subtitle-time-stop msecs :ignore-negative-duration ignore-overlap)))))) (defun subed--move-current-subtitle (msecs) "Move subtitle on point by MSECS milliseconds." (unless (= msecs 0) (subed-with-subtitle-replay-disabled (cl-flet ((move-subtitle (subed--get-move-subtitle-func msecs))) (move-subtitle msecs))))) (defun subed--move-subtitles-in-region (msecs beg end) "Move subtitles in region specified by BEG and END by MSECS milliseconds." (unless (= msecs 0) (subed-with-subtitle-replay-disabled (cl-flet ((move-subtitle (subed--get-move-subtitle-func msecs))) ;; When moving subtitles forward, the first step is to move the last ;; subtitle because: ;; a) We need to check if we can move at all and abort if not. ;; b) We may have to reduce MSECS if we can move but not by the full ;; amount. The goal is that all subtitles are moved by the same ;; amount and the spacing between subtitles doesn't change. ;; All other subtitles must be moved without any checks because we only ;; ensure that the active region as a whole can be moved, not it's ;; individual parts, which may be too close together or even overlap. ;; Moving subtitles backward is basically the same thing but vice versa. (catch 'bumped-into-subtitle (if (> msecs 0) (save-excursion ;; Moving forward - Start on last subtitle to see if/how far ;; we can move forward. (goto-char end) (unless (setq msecs (move-subtitle msecs)) (throw 'bumped-into-subtitle t)) (subed-backward-subtitle-id) (subed-for-each-subtitle beg (point) :reverse (move-subtitle msecs :ignore-negative-duration))) ;; Start on first subtitle to see if/how far we can move backward. (save-excursion (goto-char beg) (unless (setq msecs (move-subtitle msecs)) (throw 'bumped-into-subtitle t)) (subed-forward-subtitle-id) (subed-for-each-subtitle (point) end nil (move-subtitle msecs :ignore-negative-duration))))))))) (defun subed-move-subtitles (msecs &optional beg end) "Move subtitles between BEG and END MSECS milliseconds forward. Use a negative MSECS value to move subtitles backward. If END is nil, move all subtitles from BEG to end of buffer. If BEG is nil, move only the current subtitle. After subtitles are moved, replay the first moved subtitle if replaying is enabled." (cond ((and beg end) (subed--move-subtitles-in-region msecs beg end)) (beg (subed--move-subtitles-in-region msecs beg (point-max))) (t (subed--move-current-subtitle msecs))) (when (subed-replay-adjusted-subtitle-p) (save-excursion (when beg (goto-char beg)) (subed-mpv-jump (subed-subtitle-msecs-start))))) (defun subed-move-subtitle-forward (&optional arg) "Move subtitle `subed-milliseconds-adjust' forward. Moving adjusts start and stop time by the same amount, preserving subtitle duration. All subtitles that are fully or partially in the active region are moved. If prefix argument ARG is given, it is used to set `subed-milliseconds-adjust' before moving subtitles. If the prefix argument is given but not numerical, `subed-milliseconds-adjust' is reset to its default value. Example usage: \\[universal-argument] 1000 \\[subed-move-subtitle-forward] Move subtitle 1000ms forward in time \\[subed-move-subtitle-forward] Move subtitle 1000ms forward in time again \\[universal-argument] 500 \\[subed-move-subtitle-forward] Move subtitle 500ms forward in time \\[subed-move-subtitle-forward] Move subtitle 500ms forward in time again \\[universal-argument] \\[subed-move-subtitle-forward] Move subtitle 100ms (the default) forward in time \\[subed-move-subtitle-forward] Move subtitle 100ms (the default) forward in time again" (interactive "P") (let ((deactivate-mark nil) (msecs (subed-get-milliseconds-adjust arg)) (beg (when mark-active (region-beginning))) (end (when mark-active (region-end)))) (subed-move-subtitles msecs beg end))) (defun subed-move-subtitle-backward (&optional arg) "Move subtitle `subed-milliseconds-adjust' backward. See `subed-move-subtitle-forward' about ARG." (interactive "P") (let ((deactivate-mark nil) (msecs (* -1 (subed-get-milliseconds-adjust arg))) (beg (when mark-active (region-beginning))) (end (when mark-active (region-end)))) (subed-move-subtitles msecs beg end))) ;;; Shifting subtitles ;;; (same as moving, but follow-up subtitles are also moved) (defun subed-shift-subtitle-forward (&optional arg) "Shift subtitle `subed-milliseconds-adjust' backward. Shifting is like moving, but it always moves the subtitles between point and the end of the buffer. See `subed-move-subtitle-forward' about ARG." (interactive "P") (let ((deactivate-mark nil) (msecs (subed-get-milliseconds-adjust arg))) (subed-move-subtitles msecs (point)))) (defun subed-shift-subtitle-backward (&optional arg) "Shift subtitle `subed-milliseconds-adjust' backward. Shifting is like moving, but it always moves the subtitles between point and the end of the buffer. See `subed-move-subtitle-forward' about ARG." (interactive "P") (let ((deactivate-mark nil) (msecs (* -1 (subed-get-milliseconds-adjust arg)))) (subed-move-subtitles msecs (point)))) ;;; Inserting (defun subed--insert-subtitle-info (arg) "Provide information for inserting subtitles. ARG is the user-given argument. Return a list of values in the following order: number-of-subs insert-before-current (t or nil) buffer-is-empty msecs-min msecs-max msecs-avail msecs-per-sub msecs-between insert-subtitle-func" (let* ((number-of-subs (cond ((not arg) 1) ;; M-i ((integerp arg) arg) ;; C-u N M-i / C-u - N M-i ;; C-u [C-u ...] M-i / C-u - [C-u ...] M-i ((consp arg) (* (truncate (log (abs (car arg)) 4)) ;; ([-]64) -> 3 (/ (car arg) (abs (car arg))))) ;; Restore sign (t 1))) ;; C-u - M-i (insert-before-current (or (< number-of-subs 0) ;; C-u - N M-i (eq arg '-) ;; C-u - M-i (consp arg))) ;; C-u [C-u ...] M-i ;; Ensure number-of-subs is positive, now that we figured out `insert-before-current' (number-of-subs (abs number-of-subs)) (buffer-is-empty (if (subed-subtitle-id) nil t)) ;; Find out how much time there is available (msecs-min (save-excursion (if insert-before-current (if (subed-backward-subtitle-id) (subed-subtitle-msecs-stop) 0) (subed-subtitle-msecs-stop)))) (msecs-max (save-excursion (if insert-before-current (subed-subtitle-msecs-start) (when (subed-forward-subtitle-id) (subed-subtitle-msecs-start))))) (msecs-avail (cond ((and msecs-min msecs-max) (- msecs-max msecs-min)) (msecs-max msecs-max) (t nil))) ;; Unlimited (msecs-per-sub (if msecs-avail (min subed-default-subtitle-length (max 0 (/ (- msecs-avail (* (1+ number-of-subs) subed-subtitle-spacing)) number-of-subs))) subed-default-subtitle-length)) (msecs-between (if (or (not msecs-avail) (>= msecs-avail (* (1+ number-of-subs) subed-subtitle-spacing))) subed-subtitle-spacing 0)) (insert-subtitle-func (if insert-before-current #'subed-prepend-subtitle #'subed-append-subtitle))) (subed-debug "Inserting %s subtitle(s) %s the current in %sempty buffer" number-of-subs (if insert-before-current "before" "after") (if buffer-is-empty "" "non-")) (subed-debug " Available time: min=%S max=%S avail=%S sublen=%S/%S" msecs-min msecs-max msecs-avail msecs-per-sub subed-default-subtitle-length) (list number-of-subs insert-before-current buffer-is-empty msecs-min msecs-max msecs-avail msecs-per-sub msecs-between insert-subtitle-func))) (defun subed-insert-subtitle (&optional arg) "Insert subtitle(s) evenly spaced. The inserted subtitles are `subed-default-subtitle-length' milliseconds long. Subtitles are spread out evenly over the available time. ARG, usually provided by `universal-argument', is used in the following manner: \\[subed-insert-subtitle] Insert 1 subtitle after the current subtitle \\[universal-argument] \\[subed-insert-subtitle] Insert 1 subtitle before the current subtitle \\[universal-argument] 5 \\[subed-insert-subtitle] Insert 5 subtitles after the current subtitle \\[universal-argument] - 5 \\[subed-insert-subtitle] Insert 5 subtitles before the current subtitle \\[universal-argument] \\[universal-argument] \\[subed-insert-subtitle] Insert 2 subtitles before the current subtitle" (interactive "P") (atomic-change-group (cl-multiple-value-bind (number-of-subs insert-before-current _buffer-is-empty msecs-min msecs-max msecs-avail msecs-per-sub msecs-between insert-subtitle-func) (subed--insert-subtitle-info arg) (dotimes (i number-of-subs) ;; Value constellations: ;; empty buffer, append : min=0 max=nil avail=nil ;; empty buffer, prepend : min=0 max=nil avail=nil ;; non-empty buffer, prepend, betwixt : min=non-nil max=non-nil avail=non-nil ;; non-empty buffer, append, betwixt : min=non-nil max=non-nil avail=non-nil ;; non-empty buffer, prepend to first : min=0 max=non-nil avail=non-nil ;; non-empty buffer, append to last : min=non-nil max=nil avail=nil (let* ((multiplier (if insert-before-current (- number-of-subs i) (1+ i))) (msecs-start (if msecs-avail ;; Inserting anywhere before the last subtitle (+ msecs-min (if (< msecs-per-sub subed-default-subtitle-length) ;; Use all available space between subtitles (+ msecs-between (* (1- multiplier) (+ msecs-between msecs-per-sub))) ;; Leave extra space between subtitles (* multiplier (/ msecs-avail (1+ number-of-subs))))) (if (and msecs-min (not msecs-max)) ;; Appending to last subtitle (+ msecs-min ;; If buffer is empty, start first subtitle at 0 (if (> msecs-min 0) msecs-between 0) (* (1- multiplier) (+ msecs-per-sub msecs-between))) ;; Appending in empty buffer (* i (+ msecs-per-sub msecs-between))))) (msecs-stop (+ msecs-start msecs-per-sub))) (subed-debug " Inserting new subtitle at %S - %S" msecs-start msecs-stop) (funcall insert-subtitle-func nil msecs-start msecs-stop nil))) (unless insert-before-current (dotimes (_ (1- number-of-subs)) (subed-backward-subtitle-text)))) (subed-regenerate-ids-soon)) (point)) (defun subed-insert-subtitle-adjacent (&optional arg) "Insert subtitle(s) close to each other. The inserted subtitles are `subed-default-subtitle-length' milliseconds long. Subtitles are inserted `subed-subtitle-spacing' milliseconds before or after the current subtitle. When inserting multiple subtitles, the gap between them is also `subed-subtitle-spacing' milliseconds long. ARG, usually provided by `universal-argument', is used in the following manner: \\[subed-insert-subtitle] Insert 1 subtitle after the current subtitle \\[universal-argument] \\[subed-insert-subtitle] Insert 1 subtitle before the current subtitle \\[universal-argument] 5 \\[subed-insert-subtitle] Insert 5 subtitles after the current subtitle \\[universal-argument] - 5 \\[subed-insert-subtitle] Insert 5 subtitles before the current subtitle \\[universal-argument] \\[universal-argument] \\[subed-insert-subtitle] Insert 2 subtitles before the current subtitle" (interactive "P") (atomic-change-group (cl-multiple-value-bind (number-of-subs insert-before-current buffer-is-empty msecs-min msecs-max _msecs-avail msecs-per-sub msecs-between insert-subtitle-func) (subed--insert-subtitle-info arg) (dotimes (i number-of-subs) ;; Value constellations: ;; empty buffer, append : min=0 max=nil avail=nil ;; empty buffer, prepend : min=0 max=nil avail=nil ;; non-empty buffer, prepend, betwixt : min=non-nil max=non-nil avail=non-nil ;; non-empty buffer, append, betwixt : min=non-nil max=non-nil avail=non-nil ;; non-empty buffer, prepend to first : min=0 max=non-nil avail=non-nil ;; non-empty buffer, append to last : min=non-nil max=nil avail=nil (let* ((multiplier (if insert-before-current (- number-of-subs i 1) i)) (msecs-start (if buffer-is-empty (* multiplier (+ msecs-between msecs-per-sub)) (if insert-before-current (- msecs-max (* (1+ i) (+ msecs-between msecs-per-sub))) (+ msecs-min msecs-between (* i (+ msecs-per-sub msecs-between)))))) (msecs-stop (+ msecs-start msecs-per-sub))) (subed-debug " Inserting new subtitle at %S - %S" msecs-start msecs-stop) (funcall insert-subtitle-func nil msecs-start msecs-stop nil))) (unless insert-before-current (dotimes (_ (1- number-of-subs)) (subed-backward-subtitle-text)))) (subed-regenerate-ids-soon)) (point)) (defun subed-split-subtitle () "Split current subtitle at point. The subtitle text after point is moved to a new subtitle that is inserted after the current subtitle. If a video is playing, `subed-mpv-playback-position' is used as the new stop time of the current subtitle. Otherwise, the timestamp between the start and stop timestamp of the current subtitle is used. The newly inserted subtitle starts `subed-subtitle-spacing' milliseconds after the current subtitle's new end timestamp. Return point of the new subtitle. " (interactive) (let ((text-beg (save-excursion (subed-jump-to-subtitle-text))) (text-end (save-excursion (or (subed-jump-to-subtitle-end) (point))))) ;; Ensure point is on subtitle text (unless (and text-beg text-end (>= (point) text-beg) (<= (point) text-end)) (subed-jump-to-subtitle-text)) (let* ((split-timestamp (if subed-mpv-playback-position (+ subed-mpv-playback-position subed-subtitle-spacing) (let ((sub-len (- (subed-subtitle-msecs-stop) (subed-subtitle-msecs-start)))) (+ (subed-subtitle-msecs-start) (/ sub-len 2))))) (new-text (string-trim (buffer-substring (point) text-end))) (new-start-timestamp (+ split-timestamp subed-subtitle-spacing)) (new-stop-timestamp (subed-subtitle-msecs-stop))) (when (or (> split-timestamp new-stop-timestamp) (< split-timestamp (subed-subtitle-msecs-start))) (error "Playback position is not at the subtitle on point.")) (subed-set-subtitle-time-stop split-timestamp) (delete-region (point) text-end) (subed-append-subtitle nil new-start-timestamp new-stop-timestamp new-text)) (subed-regenerate-ids-soon) (point))) ;;; Merging (defun subed-merge-with-previous () "Merge the current subtitle with the previous subtitle. Update the end timestamp accordingly." (interactive) (if (subed-backward-subtitle-id) (subed-merge-with-next) (error "No previous subtitle to merge into"))) ;;; Replay time-adjusted subtitle (defun subed-replay-adjusted-subtitle-p () "Whether the player jumps to start time when start or stop time is adjusted." (member #'subed--replay-adjusted-subtitle subed-subtitle-time-adjusted-hook)) (defun subed-enable-replay-adjusted-subtitle (&optional quiet) "Automatically replay a subtitle when its start/stop time is adjusted. If QUIET is non-nil, do not display a message in the minibuffer." (interactive) (unless (subed-replay-adjusted-subtitle-p) (add-hook 'subed-subtitle-time-adjusted-hook #'subed--replay-adjusted-subtitle :append :local) (subed-debug "Enabled replaying adjusted subtitle: %s" subed-subtitle-time-adjusted-hook) (unless quiet (message "Enabled replaying adjusted subtitle")))) (defun subed-disable-replay-adjusted-subtitle (&optional quiet) "Do not replay a subtitle automatically when its start/stop time is adjusted. If QUIET is non-nil, do not display a message in the minibuffer." (interactive) (when (subed-replay-adjusted-subtitle-p) (remove-hook 'subed-subtitle-time-adjusted-hook #'subed--replay-adjusted-subtitle :local) (subed-debug "Disabled replaying adjusted subtitle: %s" subed-subtitle-time-adjusted-hook) (unless quiet (message "Disabled replaying adjusted subtitle")))) (defun subed-toggle-replay-adjusted-subtitle () "Enable/disable subtitle replay when start/stop time is adjusted." (interactive) (if (subed-replay-adjusted-subtitle-p) (subed-disable-replay-adjusted-subtitle) (subed-enable-replay-adjusted-subtitle))) (defun subed--replay-adjusted-subtitle (msecs-start) "Seek player to MSECS-START." (subed-debug "Replaying subtitle at: %s" (subed-msecs-to-timestamp msecs-start)) (subed-mpv-jump msecs-start)) ;;; Sync point-to-player (defun subed-sync-point-to-player-p () "Whether point is automatically moved to currently playing subtitle." (member #'subed--sync-point-to-player subed-mpv-playback-position-hook)) (defun subed-enable-sync-point-to-player (&optional quiet) "Automatically move point to the currently playing subtitle. If QUIET is non-nil, do not display a message in the minibuffer." (interactive) (unless (subed-sync-point-to-player-p) (add-hook 'subed-mpv-playback-position-hook #'subed--sync-point-to-player :append :local) (subed-debug "Enabled syncing point to playback position: %s" subed-mpv-playback-position-hook) (unless quiet (message "Enabled syncing point to playback position")))) (defun subed-disable-sync-point-to-player (&optional quiet) "Do not move point automatically to the currently playing subtitle. If QUIET is non-nil, do not display a message in the minibuffer." (interactive) (when (subed-sync-point-to-player-p) (remove-hook 'subed-mpv-playback-position-hook #'subed--sync-point-to-player :local) (subed-debug "Disabled syncing point to playback position: %s" subed-mpv-playback-position-hook) (unless quiet (message "Disabled syncing point to playback position")))) (defun subed-toggle-sync-point-to-player () "Enable/disable moving point to the currently playing subtitle." (interactive) (if (subed-sync-point-to-player-p) (subed-disable-sync-point-to-player) (subed-enable-sync-point-to-player))) (defun subed--sync-point-to-player (msecs) "Move point to subtitle at MSECS." (when (and (not (use-region-p)) ;; Don't sync with active-mark in transient-mark-mode (subed-jump-to-subtitle-text-at-msecs msecs)) (subed-debug "Synchronized point to playback position: %s -> #%s" (subed-msecs-to-timestamp msecs) (subed-subtitle-id)) ;; post-command-hook is not triggered because we didn't move interactively, ;; but there shouldn't be a difference between automatic movement and manual ;; movement. E.g. the minor mode `hl-line' breaks because its post-command ;; function is not called. ;; But it's also important NOT to call our own post-command function because ;; that causes player-to-point syncing, which would get hairy. (remove-hook 'post-command-hook #'subed--post-command-handler) (run-hooks 'post-command-hook) (add-hook 'post-command-hook #'subed--post-command-handler :append :local))) (defvar-local subed--point-sync-delay-after-motion-timer nil) (defun subed-disable-sync-point-to-player-temporarily () "Temporarily disable syncing point to player. After `subed-point-sync-delay-after-motion' seconds point is re-synced." (if subed--point-sync-delay-after-motion-timer (cancel-timer subed--point-sync-delay-after-motion-timer) (setq subed--point-was-synced (subed-sync-point-to-player-p))) (when subed--point-was-synced (subed-disable-sync-point-to-player :quiet)) (when subed--point-was-synced (setq subed--point-sync-delay-after-motion-timer (run-at-time subed-point-sync-delay-after-motion nil (lambda () (setq subed--point-sync-delay-after-motion-timer nil) (subed-enable-sync-point-to-player :quiet)))))) ;;; Sync player-to-point (defun subed-sync-player-to-point-p () "Whether playback position jumps to subtitle at point." (member #'subed--sync-player-to-point subed-subtitle-motion-hook)) (defun subed-enable-sync-player-to-point (&optional quiet) "Automatically seek player to subtitle at point. If QUIET is non-nil, do not display a message in the minibuffer." (interactive) (unless (subed-sync-player-to-point-p) (subed--sync-player-to-point) (add-hook 'subed-subtitle-motion-hook #'subed--sync-player-to-point :append :local) (subed-debug "Enabled syncing playback position to point: %s" subed-subtitle-motion-hook) (unless quiet (message "Enabled syncing playback position to point")))) (defun subed-disable-sync-player-to-point (&optional quiet) "Do not automatically seek player to subtitle at point. If QUIET is non-nil, do not display a message in the minibuffer." (interactive) (when (subed-sync-player-to-point-p) (remove-hook 'subed-subtitle-motion-hook #'subed--sync-player-to-point :local) (subed-debug "Disabled syncing playback position to point: %s" subed-subtitle-motion-hook) (unless quiet (message "Disabled syncing playback position to point")))) (defun subed-toggle-sync-player-to-point () "Enable or disable automatically seeking player to subtitle at point." (interactive) (if (subed-sync-player-to-point-p) (subed-disable-sync-player-to-point) (subed-enable-sync-player-to-point))) (defun subed--sync-player-to-point () "Seek player to currently focused subtitle." (subed-debug "Seeking player to subtitle at point %s" (point)) (let ((cur-sub-start (subed-subtitle-msecs-start)) (cur-sub-stop (subed-subtitle-msecs-stop))) (when (and subed-mpv-playback-position cur-sub-start cur-sub-stop (or (< subed-mpv-playback-position cur-sub-start) (> subed-mpv-playback-position cur-sub-stop))) (subed-mpv-jump cur-sub-start) (subed-debug "Synchronized playback position to point: #%s -> %s" (subed-subtitle-id) cur-sub-start)))) ;;; Loop over single subtitle (defun subed-loop-over-current-subtitle-p () "Whether the player is looping over the current subtitle." (or subed--subtitle-loop-start subed--subtitle-loop-stop)) (defvar-local subed--enable-point-to-player-sync-after-disabling-loop nil) (defun subed-enable-loop-over-current-subtitle (&optional quiet) "Enable looping over the current subtitle in the player. If enabled, point-to-player synchronization is disabled and re-enabled again when `subed-disable-loop-over-current-subtitle' is called. If QUIET is non-nil, do not display a message in the minibuffer." (interactive) (unless (subed-loop-over-current-subtitle-p) (subed--set-subtitle-loop (subed-subtitle-id)) (add-hook 'subed-mpv-playback-position-hook #'subed--ensure-subtitle-loop :append :local) (add-hook 'subed-subtitle-motion-hook #'subed--set-subtitle-loop :append :local) (subed-debug "Enabling loop: %s - %s" subed--subtitle-loop-start subed--subtitle-loop-stop) (when (subed-sync-point-to-player-p) (subed-disable-sync-point-to-player) (setq subed--enable-point-to-player-sync-after-disabling-loop t)) (unless quiet (message "Enabled looping over current subtitle")))) (defun subed-disable-loop-over-current-subtitle (&optional quiet) "Disable looping over the current subtitle in the player. If QUIET is non-nil, do not display a message in the minibuffer." (interactive) (when (subed-loop-over-current-subtitle-p) (remove-hook 'subed-mpv-playback-position-hook #'subed--ensure-subtitle-loop :local) (remove-hook 'subed-subtitle-motion-hook #'subed--set-subtitle-loop :local) (setq subed--subtitle-loop-start nil subed--subtitle-loop-stop nil) (subed-debug "Disabling loop: %s - %s" subed--subtitle-loop-start subed--subtitle-loop-stop) (when subed--enable-point-to-player-sync-after-disabling-loop (subed-enable-sync-point-to-player) (setq subed--enable-point-to-player-sync-after-disabling-loop nil)) (unless quiet (message "Disabled looping over current subtitle")))) (defun subed-toggle-loop-over-current-subtitle (&optional quiet) "Enable or disable looping over the current subtitle in the player. If QUIET is non-nil, do not display a message in the minibuffer." (interactive) (if (subed-loop-over-current-subtitle-p) (subed-disable-loop-over-current-subtitle quiet) (subed-enable-loop-over-current-subtitle quiet))) (defun subed--set-subtitle-loop (&optional sub-id) "Set loop positions to start/stop time of SUB-ID or current subtitle." (let ((msecs-start (subed-subtitle-msecs-start sub-id)) (msecs-stop (subed-subtitle-msecs-stop sub-id))) (when (and msecs-start msecs-stop) (setq subed--subtitle-loop-start (- msecs-start (* subed-loop-seconds-before 1000)) subed--subtitle-loop-stop (+ msecs-stop (* subed-loop-seconds-after 1000))) (subed-debug "Set loop: %s - %s" (subed-msecs-to-timestamp subed--subtitle-loop-start) (subed-msecs-to-timestamp subed--subtitle-loop-stop)) (message "Looping over %s - %s" (subed-msecs-to-timestamp subed--subtitle-loop-start) (subed-msecs-to-timestamp subed--subtitle-loop-stop))))) (defun subed--ensure-subtitle-loop (cur-msecs) "Jump to current subtitle start time if CUR-MSECS is after stop time." (when (and subed--subtitle-loop-start subed--subtitle-loop-stop subed-mpv-is-playing) (when (or (< cur-msecs subed--subtitle-loop-start) (> cur-msecs subed--subtitle-loop-stop)) (subed-debug "%s -> Looping over %s - %s" (subed-msecs-to-timestamp cur-msecs) (subed-msecs-to-timestamp subed--subtitle-loop-start) (subed-msecs-to-timestamp subed--subtitle-loop-stop)) (subed-mpv-jump subed--subtitle-loop-start)))) ;;; Pause player while the user is editing (defun subed-pause-while-typing-p () "Whether player is automatically paused or slowed down during editing. See `subed-playback-speed-while-typing' and `subed-playback-speed-while-not-typing'." (member #'subed--pause-while-typing after-change-functions)) (defun subed-enable-pause-while-typing (&optional quiet) "Pause player while the user is editing a subtitle. After `subed-unpause-after-typing-delay' seconds, playback is resumed automatically unless the player was paused already. If QUIET is non-nil, do not display a message in the minibuffer." (unless (subed-pause-while-typing-p) (add-hook 'after-change-functions #'subed--pause-while-typing :append :local) (unless quiet (subed-debug "%S" subed-playback-speed-while-typing) (if (<= subed-playback-speed-while-typing 0) (message "Playback will pause while subtitle texts are edited") (message "Playback will slow down by %s while subtitle texts are edited" subed-playback-speed-while-typing))))) (defun subed-disable-pause-while-typing (&optional quiet) "Do not automatically pause player while the user is editing the buffer. If QUIET is non-nil, do not display a message in the minibuffer." (when (subed-pause-while-typing-p) (remove-hook 'after-change-functions #'subed--pause-while-typing :local) (unless quiet (message "Playback speed will not change while subtitle texts are edited")))) (defun subed-toggle-pause-while-typing () "Enable or disable auto-pausing while the user is editing the buffer." (interactive) (if (subed-pause-while-typing-p) (subed-disable-pause-while-typing) (subed-enable-pause-while-typing))) (defvar-local subed--unpause-after-typing-timer nil) (defun subed--pause-while-typing (&rest _args) "Pause or slow down playback for `subed-unpause-after-typing-delay' seconds. This function is meant to be an item in `after-change-functions' and therefore gets ARGS, which is ignored." (when subed--unpause-after-typing-timer (cancel-timer subed--unpause-after-typing-timer)) (when (or subed-mpv-is-playing subed--player-is-auto-paused) (if (<= subed-playback-speed-while-typing 0) ;; Pause playback (progn (subed-mpv-pause) (setq subed--player-is-auto-paused t) (setq subed--unpause-after-typing-timer (run-at-time subed-unpause-after-typing-delay nil (lambda () (setq subed--player-is-auto-paused nil) (subed-mpv-unpause))))) ;; Slow down playback (progn (subed-mpv-playback-speed subed-playback-speed-while-typing) (setq subed--player-is-auto-paused t) (setq subed--unpause-after-typing-timer (run-at-time subed-unpause-after-typing-delay nil (lambda () (setq subed--player-is-auto-paused nil) (subed-mpv-playback-speed subed-playback-speed-while-not-typing)))))))) (defun subed-guess-video-file () "Find video file with same base name as the opened file in the buffer. The file extension of the return value of the function `buffer-file-name' is replaced with each item in `subed-video-extensions' and the first existing file is returned. Language codes are also handled; e.g. \"foo.en.srt\" or \"foo.estonian.srt\" -> \"foo.{mkv,mp4,...}\" (this actually simply removes the extension from the extension-stripped file name). Return nil if function `buffer-file-name' returns nil." (when (buffer-file-name) (catch 'found-videofile (let* ((file-base (file-name-sans-extension (buffer-file-name))) (file-stem (file-name-sans-extension file-base))) (dolist (extension subed-video-extensions) (let ((file-base-video (format "%s.%s" file-base extension)) (file-stem-video (format "%s.%s" file-stem extension))) (when (file-exists-p file-base-video) (throw 'found-videofile file-base-video)) (when (file-exists-p file-stem-video) (throw 'found-videofile file-stem-video)))))))) (provide 'subed-common) ;;; subed-common.el ends here subed-master/subed/subed-config.el000066400000000000000000000157321401667552300174630ustar00rootroot00000000000000;;; subed-config.el --- Customization variables and hooks for subed -*- lexical-binding: t; -*- ;;; License: ;; ;; This file is not part of GNU Emacs. ;; ;; This is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation; either version 3, or (at your option) ;; any later version. ;; ;; This is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs; see the file COPYING. If not, write to the ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, ;; Boston, MA 02110-1301, USA. ;;; Commentary: ;; Customization variables, hooks, keybindings, etc for subed-mode. ;;; Code: (defgroup subed nil "Major mode for editing subtitles." :group 'files :group 'multimedia :prefix "subed-") (defvar-local subed--subtitle-format nil "Short form of the name of the subtitle format in the current buffer (e.g. \"srt\").") ;; This variable is set in subed.el to avoid compiler warnings because it uses ;; functions defined in subed-common.el, and (require 'subed-common) results in ;; recursive requires. (defvar subed-mode-map nil "Keymap for ‘subed-mode’.") ;; Syntax highlighting (defface subed-srt-id-face '((t (:inherit 'font-lock-constant-face))) "Each subtitle's consecutive number") (defface subed-srt-time-face '((t (:inherit 'font-lock-string-face))) "Start and stop times of subtitles") (defface subed-srt-time-separator-face '((t (:inherit 'font-lock-comment-face))) "Separator between the start and stop time (\" --> \")") (defface subed-srt-text-face '((t (:inherit 'default))) "Text of the subtitle") (defface subed-vtt-time-face '((t (:inherit 'font-lock-string-face))) "Start and stop times of subtitles") (defface subed-vtt-time-separator-face '((t (:inherit 'font-lock-comment-face))) "Separator between the start and stop time (\" --> \")") (defface subed-vtt-text-face '((t (:inherit 'default))) "Text of the subtitle") ;; Variables (defvar-local subed-debugging-enabled-p nil "Whether debugging messages are displayed.") (defcustom subed-debug-buffer "*subed-debug*" "Name of the buffer that contains debugging messages." :type 'string :group 'subed) (defcustom subed-mode-hook nil "Functions to call when entering subed mode." :type 'hook :group 'subed) (defcustom subed-video-extensions '("mkv" "mp4" "webm" "avi" "ts" "ogv") "Video file name extensions." :type 'list :group 'subed) (defcustom subed-auto-find-video t "Whether to open the video automatically when opening a subtitle file." :type 'boolean :group 'subed) (defcustom subed-milliseconds-adjust 100 "Milliseconds to add or subtract from start/stop time. This variable is used when adjusting, moving or shifting subtitles without a prefix argument. This variable is set when adjusting, moving or shifting subtitles with a prefix argument. See `subed-increase-start-time' for details. Use `setq-default' to change the default value of this variable." :type 'float :group 'subed) (defun subed-get-milliseconds-adjust (arg) "Set `subed-milliseconds-adjust' to ARG if it's a number. If ARG is non-nil, reset `subed-milliseconds-adjust' to its default. Return new `subed-milliseconds-adjust' value." (cond ((integerp arg) (setq subed-milliseconds-adjust arg)) ;; Custom adjustment (arg (custom-reevaluate-setting 'subed-milliseconds-adjust))) ;; Reset to default subed-milliseconds-adjust) (defcustom subed-playback-speed-while-typing 0 "Video playback speed while the user is editing the buffer. If set to zero or smaller, playback is paused." :type 'float :group 'subed) (defcustom subed-playback-speed-while-not-typing 1.0 "Video playback speed while the user is not editing the buffer." :type 'float :group 'subed) (defcustom subed-unpause-after-typing-delay 1.0 "Number of seconds to wait after typing stopped before unpausing the player." :type 'float :group 'subed) (defvar-local subed--player-is-auto-paused nil "Whether the player was paused by the user or automatically.") (defcustom subed-subtitle-spacing 100 "Minimum time in milliseconds between subtitles when start/stop time is changed." :type 'integer :group 'subed) (defcustom subed-default-subtitle-length 1000 "How long to make inserted subtitles in milliseconds." :type 'float :group 'subed) (defcustom subed-enforce-time-boundaries t "Whether to refuse time adjustments that result in overlapping subtitles or negative duration." :type 'boolean :group 'subed) (defcustom subed-loop-seconds-before 1 "Prelude in seconds when looping over subtitle(s)." :type 'float :group 'subed) (defcustom subed-loop-seconds-after 1 "Addendum in seconds when looping over subtitle(s)." :type 'float :group 'subed) (defvar-local subed--subtitle-loop-start nil "Start position of loop in player in milliseconds.") (defvar-local subed--subtitle-loop-stop nil "Stop position of loop in player in milliseconds.") (defcustom subed-point-sync-delay-after-motion 1.0 "Number of seconds the player can't adjust point after point was moved by the user." :type 'float :group 'subed) (defvar-local subed--point-was-synced nil "When temporarily disabling point-to-player sync, this variable remembers whether it was originally enabled by the user.") (defcustom subed-mpv-socket-dir (concat (temporary-file-directory) "subed-mpv-socket") "Path to Unix IPC socket that is passed to mpv's --input-ipc-server option." :type 'file :group 'subed) (defcustom subed-mpv-executable "mpv" "Path or filename of mpv executable." :type 'file :group 'subed) (defcustom subed-mpv-arguments '("--osd-level=2" "--osd-fractions") "Additional arguments for \"mpv\". The options --input-ipc-server=SRTEDIT-MPV-SOCKET and --idle are hardcoded." :type '(repeat string) :group 'subed) (defun subed--buffer-file-name () "Return base name of buffer file name or a default name." (file-name-nondirectory (or (buffer-file-name) "unnamed"))) ;; Hooks (defvar-local subed-subtitle-time-adjusted-hook () "Functions to call when a subtitle's start or stop time has changed. The functions are called with the subtitle's start time.") (defun subed--run-subtitle-time-adjusted-hook () "Run `subed-subtitle-time-adjusted-hook' functions. The functions are called with the subtitle's start time." (when subed-subtitle-time-adjusted-hook (run-hook-with-args 'subed-subtitle-time-adjusted-hook (subed-subtitle-msecs-start)))) (defvar-local subed-point-motion-hook nil "Functions to call after point changed.") (defvar-local subed-subtitle-motion-hook nil "Functions to call after current subtitle changed.") (provide 'subed-config) ;;; subed-config.el ends here subed-master/subed/subed-debug.el000066400000000000000000000054651401667552300173060ustar00rootroot00000000000000;;; subed-debug.el --- Debugging functions -*- lexical-binding: t; -*- ;;; License: ;; ;; This file is not part of GNU Emacs. ;; ;; This is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation; either version 3, or (at your option) ;; any later version. ;; ;; This is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs; see the file COPYING. If not, write to the ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, ;; Boston, MA 02110-1301, USA. ;;; Commentary: ;; ;; Debugging-related functions. ;;; Code: (require 'subed-config) (defun subed-enable-debugging () "Hide debugging messages and set `debug-on-error' to nil." (interactive) (unless subed-debugging-enabled-p (setq subed-debugging-enabled-p t debug-on-error t) (let ((debug-buffer (get-buffer-create subed-debug-buffer)) (debug-window (or (get-buffer-window subed-debug-buffer) (split-window-horizontally (max 40 (floor (* 0.3 (window-width)))))))) (set-window-buffer debug-window debug-buffer) (with-current-buffer debug-buffer (buffer-disable-undo) (setq-local buffer-read-only t))) (add-hook 'kill-buffer-hook #'subed-disable-debugging :append :local))) (defun subed-disable-debugging () "Display debugging messages in separate window and set `debug-on-error' to t." (interactive) (when subed-debugging-enabled-p (setq subed-debugging-enabled-p nil debug-on-error nil) (let ((debug-window (get-buffer-window subed-debug-buffer))) (when debug-window (delete-window debug-window))) (remove-hook 'kill-buffer-hook #'subed-disable-debugging :local))) (defun subed-toggle-debugging () "Display or hide debugging messages in separate window and set `debug-on-error' to t or nil." (interactive) (if subed-debugging-enabled-p (subed-disable-debugging) (subed-enable-debugging))) (defun subed-debug (msg &rest args) "Pass MSG and ARGS to `format' and show the result in debugging buffer if it exists." (when (get-buffer subed-debug-buffer) (with-current-buffer (get-buffer-create subed-debug-buffer) (setq-local buffer-read-only nil) (insert (apply #'format (concat msg "\n") args)) (setq-local buffer-read-only t) (let ((debug-window (get-buffer-window subed-debug-buffer))) (when debug-window (set-window-point debug-window (goto-char (point-max)))))))) (provide 'subed-debug) ;;; subed-debug.el ends here subed-master/subed/subed-mpv.el000066400000000000000000000365351401667552300170240ustar00rootroot00000000000000;;; subed-mpv.el --- mpv integration for subed -*- lexical-binding: t; -*- ;;; License: ;; ;; This file is not part of GNU Emacs. ;; ;; This is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation; either version 3, or (at your option) ;; any later version. ;; ;; This is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs; see the file COPYING. If not, write to the ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, ;; Boston, MA 02110-1301, USA. ;;; Commentary: ;; ;; Based on: ;; https://github.com/mk-fg/emacs-setup/blob/master/extz/emms-player-mpv.el ;;; Code: (require 'subed-config) (require 'subed-debug) (require 'json) (defvar-local subed-mpv-is-playing nil "Whether mpv is currently playing or paused.") (defvar-local subed-mpv-playback-speed nil "How fast mpv is playing the video. 1.0 is normal speed, 0.5 is half speed, etc.") (defvar-local subed-mpv-playback-position nil "Current playback position in milliseconds.") (defvar-local subed-mpv-playback-position-hook nil "Functions to call when mpv changes playback position.") (defvar-local subed-mpv-file-loaded-hook '(subed-mpv-pause subed-mpv-jump-to-current-subtitle) "Functions to call when mpv has loaded a file and starts playing.") (defvar-local subed-mpv--server-proc nil "Running mpv process.") (defvar-local subed-mpv--client-proc nil "IPC socket process that communicates over `subed-mpv--socket'.") (defconst subed-mpv--client-test-request (json-encode (list :command '(get_property mpv-version))) "Request as a string to send to check whether IPC connection is working.") (defconst subed-mpv--retry-delays ;; Sums up to 5 seconds in total before failing '(0.1 0.1 0.1 0.1 0.2 0.2 0.3 0.4 0.5 0.5 0.5 0.5 0.5 0.5 0.5) "List of delays between attemps to connect to `subed-mpv--socket'.") (defvar-local subed-mpv--client-command-queue nil "Commands to call when connection to `subed-mpv--socket' is established.") ;;; Server (mpv process that provides an IPC socket) (defun subed-mpv--socket () "Path to mpv's RPC socket for a particular buffer. See also `subed-mpv-socket-dir'." (unless (file-exists-p subed-mpv-socket-dir) (condition-case err (make-directory subed-mpv-socket-dir :create-parents) (file-error (error "%s" (mapconcat #'identity (cdr err) ": "))))) (concat (file-name-as-directory subed-mpv-socket-dir) (format "%s:%s" (let ((filename (file-name-sans-extension (subed--buffer-file-name)))) (substring (substring filename 0 (min (length filename) 20)))) (buffer-hash)))) (defun subed-mpv--server-start (&rest args) "Run mpv in JSON IPC mode. Pass ARGS as command line arguments. \"--idle\" and \"--input-ipc-server\" are hardcoded." (subed-mpv--server-stop) (let* ((socket-file (subed-mpv--socket)) (argv (append (list subed-mpv-executable (format "--input-ipc-server=%s" socket-file) "--idle") args))) (when (file-exists-p socket-file) (error "An mpv instance for %s is already running: %s" (subed--buffer-file-name) socket-file)) (subed-debug "Running %s" argv) (condition-case err (setq subed-mpv--server-proc (make-process :command argv :name "subed-mpv-server" :buffer nil :noquery t)) (error (error "%s" (mapconcat #'identity (cdr (cdr err)) ": ")))))) (defun subed-mpv--server-stop () "Kill a running mpv process." (when (and subed-mpv--server-proc (process-live-p subed-mpv--server-proc)) (delete-process subed-mpv--server-proc) (subed-debug "Killed mpv process")) (let ((socket-file (subed-mpv--socket))) (when (file-exists-p socket-file) (subed-debug "Removing IPC socket: %s" socket-file) (ignore-errors (delete-file socket-file)))) (setq subed-mpv--server-proc nil)) (defun subed-mpv--server-started-p () "Whether `subed-mpv--server-proc' is a running process." (if subed-mpv--server-proc t nil)) ;;; Client (elisp process that connects to server's IPC socket) (defun subed-mpv--client-buffer () "Unique name of buffer that store RPC responses." (let ((buffer-name (format "*subed-mpv-buffer:%s-%s*" (file-name-base (or (buffer-file-name) "unnamed")) (buffer-hash)))) (if subed-debugging-enabled-p buffer-name (concat " " buffer-name)))) (defun subed-mpv--client-connect (delays) "Try to connect to `subed-mpv--socket'. If a connection attempt fails, wait (car DELAYS) seconds and try again with (cdr DELAYS) as arguments." (subed-debug "Attempting to connect to IPC socket: %s" (subed-mpv--socket)) (subed-mpv--client-disconnect) ;; NOTE: make-network-process doesn't fail when the socket file doesn't exist (let ((proc (make-network-process :name "subed-mpv-client" :family 'local :service (subed-mpv--socket) :coding '(utf-8 . utf-8) :buffer (subed-mpv--client-buffer) :filter #'subed-mpv--client-filter :noquery t :nowait t))) ;; Test connection by sending a test request (condition-case err (progn (process-send-string proc (concat subed-mpv--client-test-request "\n")) (subed-debug "Connected to %s (%s)" proc (process-status proc)) (setq subed-mpv--client-proc proc)) (error (if delays (progn (subed-debug "Failed to connect (trying again in %s seconds)" (car delays)) (run-at-time (car delays) nil #'subed-mpv--client-connect (cdr delays))) (progn (subed-debug "Connection failed: %s" err)))))) ;; Run commands that were sent while the connection wasn't up yet (when (subed-mpv--client-connected-p) (while subed-mpv--client-command-queue (let ((cmd (pop subed-mpv--client-command-queue))) (subed-debug "Running queued command: %s" cmd) (apply #'subed-mpv--client-send (list cmd)))))) (defun subed-mpv--client-disconnect () "Close connection to mpv process, if there is one." (when (subed-mpv--client-connected-p) (delete-process subed-mpv--client-proc) (subed-debug "Closed connection to mpv process")) (setq subed-mpv--client-proc nil subed-mpv-is-playing nil subed-mpv-playback-position nil)) (defun subed-mpv--client-connected-p () "Whether the server connection has been established and tested successfully." (if subed-mpv--client-proc t nil)) (defun subed-mpv--client-send (cmd) "Send JSON IPC command. If we're not connected yet but the server has been started, add CMD to `subed-mpv--client-command-queue' which is evaluated by `subed-mpv--client-connect' when the connection is up." (if (subed-mpv--client-connected-p) (let ((request-data (concat (json-encode (list :command cmd))))) (subed-debug "Sending request: %s" request-data) (condition-case err (process-send-string subed-mpv--client-proc (concat request-data "\n")) (error (subed-mpv-kill) (error "Unable to send commands via %s: %s" (subed-mpv--socket) (cdr err)))) t) (when (subed-mpv--server-started-p) (subed-debug "Queueing command: %s" cmd) (setq subed-mpv--client-command-queue (append subed-mpv--client-command-queue (list cmd))) t))) (defun subed-mpv--client-filter (proc response) "Handle response from the server. PROC is the mpv process and RESPONSE is the response as a JSON string." ;; JSON-STRING contains zero or more lines with JSON encoded objects, e.g.: ;; {"data":"mpv 0.29.1","error":"success"} ;; {"data":null,"request_id":1,"error":"success"} ;; {"event":"start-file"}{"event":"tracks-changed"} ;; JSON-STRING can also contain incomplete JSON, e.g. `{"error":"succ'. ;; Therefore we maintain a buffer and process only complete lines. (when (buffer-live-p (process-buffer proc)) (let ((orig-buffer (current-buffer))) (with-current-buffer (process-buffer proc) ;; Insert new response where previous response ended (let* ((proc-mark (process-mark proc)) (moving (= (point) proc-mark))) (save-excursion (goto-char proc-mark) (insert response) (set-marker proc-mark (point))) (if moving (goto-char proc-mark))) ;; Process and remove all complete lines of JSON (lines are complete if ;; they end with \n) (let ((p0 (point-min))) (while (progn (goto-char p0) (end-of-line) (equal (following-char) ?\n)) (let* ((p1 (point)) (line (buffer-substring p0 p1))) (delete-region p0 (+ p1 1)) ;; Return context to the subtitle file buffer because we're using ;; buffer-local variables to store player state. (with-current-buffer orig-buffer (subed-mpv--client-handle-json line))))))))) (defun subed-mpv--client-handle-json (json-string) "Process server response JSON-STRING." (let* ((json-data (condition-case nil (json-read-from-string json-string) (error (subed-debug "Unable to parse JSON response:\n%S" json-string) nil))) (event (when json-data (alist-get 'event json-data)))) (when event (subed-mpv--client-handle-event json-data)))) (defun subed-mpv--client-handle-event (json-data) "Handler for relevant mpv events. JSON-DATA is mpv's JSON response in the form of an association list. See \"List of events\" in mpv(1)." (let ((event (alist-get 'event json-data))) (pcase event ("property-change" (when (string= (alist-get 'name json-data) "time-pos") (let ((pos-msecs (* 1000 (or (alist-get 'data json-data) 0)))) (setq subed-mpv-playback-position (round pos-msecs)) (run-hook-with-args 'subed-mpv-playback-position-hook subed-mpv-playback-position)))) ("file-loaded" (setq subed-mpv-is-playing t) ;; TODO: Remove this code. It seems unnecessary now. Not sure why, but ;; I can't reproduce the issue. ;; Because mpv can report the player position AFTER the file was loaded ;; we disable automatic movement of point for a while so that the effect ;; of `subed-mpv-jump-to-current-subtitle' isn't cancelled immediately. ;; (subed-disable-sync-point-to-player-temporarily) (run-hooks 'subed-mpv-file-loaded-hook)) ("unpause" (setq subed-mpv-is-playing t)) ((or "pause" "end-file" "shutdown" "idle") (setq subed-mpv-is-playing nil))))) ;;; High-level functions (defun subed-mpv-pause () "Stop playback." (interactive) (when subed-mpv-is-playing (when (subed-mpv--client-send `(set_property pause yes)) (subed-mpv--client-handle-event '((event . "pause")))))) (defun subed-mpv-unpause () "Start playback." (interactive) (unless subed-mpv-is-playing (when (subed-mpv--client-send `(set_property pause no)) (subed-mpv--client-handle-event '((event . "unpause")))))) (defun subed-mpv-toggle-pause () "Start or stop playback." (interactive) (if subed-mpv-is-playing (subed-mpv-pause) (subed-mpv-unpause))) (defun subed-mpv-playback-speed (factor) "Play video slower (FACTOR < 1) or faster (FACTOR > 1)." (interactive) (unless (eq subed-mpv-playback-speed factor) (when (subed-mpv--client-send `(set_property speed ,factor)) (setq subed-mpv-playback-speed factor)))) (defun subed-mpv-seek (msec) "Move playback position MSEC milliseconds relative to current position." (subed-mpv--client-send `(seek ,(/ msec 1000.0) relative+exact))) (defun subed-mpv-jump (msec) "Move playback position to absolute position MSEC milliseconds." (subed-mpv--client-send `(seek ,(/ msec 1000.0) absolute+exact))) (defun subed-mpv-jump-to-current-subtitle () "Move playback position to start of currently focused subtitle if possible." (let ((cur-sub-start (subed-subtitle-msecs-start))) (when cur-sub-start (subed-debug "Seeking player to focused subtitle: %S" cur-sub-start) (subed-mpv-jump cur-sub-start)))) (defun subed-mpv-add-subtitles (file) "Load FILE as subtitles in mpv." (subed-mpv--client-send `(sub-add ,file select))) (defun subed-mpv-reload-subtitles () "Reload subtitle file from disk." (subed-mpv--client-send '(sub-reload))) (defun subed-mpv--is-video-file-p (filename) "Return whether FILENAME is a video file or directory." (and (not (or (string= filename ".") (string= filename ".."))) (let ((filepath (expand-file-name filename))) (or (file-directory-p filepath) (member (file-name-extension filename) subed-video-extensions))))) (defun subed-mpv--play (video) "Open VIDEO and play it in mpv." (when (subed-mpv--server-started-p) (subed-mpv-kill)) (when (apply #'subed-mpv--server-start subed-mpv-arguments) (subed-debug "Opening video: %s" video) (subed-mpv--client-connect subed-mpv--retry-delays) (subed-mpv--client-send `(loadfile ,video replace)) ;; mpv won't add the subtitles if the file doesn't exist yet, so we add it ;; via after-save-hook. (if (file-exists-p (buffer-file-name)) (subed-mpv-add-subtitles (buffer-file-name)) (add-hook 'after-save-hook #'subed-mpv--add-subtitle-after-first-save :append :local)) (subed-mpv--client-send `(observe_property 1 time-pos)) (subed-mpv-playback-speed subed-playback-speed-while-not-typing))) (defun subed-mpv-play-video-from-url (url) "Open video file from URL in mpv. See the mpv manual for a list of supported URL types. If you have youtube-dl installed, mpv can open videos from a variety of hosting providers." (interactive "MURL: ") (subed-mpv--play url)) (defun subed-mpv-find-video (file) "Open video file FILE in mpv. Video files are expected to have any of the extensions listed in `subed-video-extensions'." (interactive (list (read-file-name "Find video: " nil nil t nil #'subed-mpv--is-video-file-p))) (subed-mpv--play (expand-file-name file))) (defun subed-mpv--add-subtitle-after-first-save () "Tell mpv to load subtitles from function `buffer-file-name'. Don't send the load command to mpv if `subed-subtitle-id' returns nil because that likely means the file is empty or invalid. This function is supposed to be added to `after-save-hook', and it removes itself from it so mpv doesn't add the same file every time the buffer is saved." (when (subed-subtitle-id) (subed-mpv-add-subtitles (buffer-file-name)) (remove-hook 'after-save-hook #'subed-mpv--add-subtitle-after-first-save :local))) (defun subed-mpv-kill () "Close connection to mpv process and kill the process." (subed-mpv--client-disconnect) (subed-mpv--server-stop)) (provide 'subed-mpv) ;;; subed-mpv.el ends here subed-master/subed/subed-srt.el000066400000000000000000000570461401667552300170320ustar00rootroot00000000000000;;; subed-srt.el --- SubRip/srt implementation for subed -*- lexical-binding: t; -*- ;;; License: ;; ;; This file is not part of GNU Emacs. ;; ;; This is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation; either version 3, or (at your option) ;; any later version. ;; ;; This is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs; see the file COPYING. If not, write to the ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, ;; Boston, MA 02110-1301, USA. ;;; Commentary: ;; SubRip/srt implementation for subed-mode. ;;; Code: (require 'subed-config) (require 'subed-debug) (require 'subed-common) ;;; Syntax highlighting (defconst subed-srt-font-lock-keywords (list '("^[0-9]+$" . 'subed-srt-id-face) '("[0-9]+:[0-9]+:[0-9]+,[0-9]+" . 'subed-srt-time-face) '(",[0-9]+ \\(-->\\) [0-9]+:" 1 'subed-srt-time-separator-face t) '("^.*$" . 'subed-srt-text-face)) "Highlighting expressions for `subed-mode'.") ;;; Parsing (defconst subed-srt--regexp-timestamp "\\([0-9]+\\):\\([0-9]+\\):\\([0-9]+\\),\\([0-9]+\\)") (defconst subed-srt--regexp-separator "\\(?:[[:blank:]]*\n\\)+[[:blank:]]*\n") (defun subed-srt--timestamp-to-msecs (time-string) "Find HH:MM:SS,MS pattern in TIME-STRING and convert it to milliseconds. Return nil if TIME-STRING doesn't match the pattern." (save-match-data (when (string-match subed-srt--regexp-timestamp time-string) (let ((hours (string-to-number (match-string 1 time-string))) (mins (string-to-number (match-string 2 time-string))) (secs (string-to-number (match-string 3 time-string))) (msecs (string-to-number (subed--right-pad (match-string 4 time-string) 3 ?0)))) (+ (* (truncate hours) 3600000) (* (truncate mins) 60000) (* (truncate secs) 1000) (truncate msecs)))))) (defun subed-srt--msecs-to-timestamp (msecs) "Convert MSECS to string in the format HH:MM:SS,MS." ;; We need to wrap format-seconds in save-match-data because it does regexp ;; stuff and we need to preserve our own match-data. (concat (save-match-data (format-seconds "%02h:%02m:%02s" (/ msecs 1000))) "," (format "%03d" (mod msecs 1000)))) (defun subed-srt--subtitle-id () "Return the ID of the subtitle at point or nil if there is no ID." (save-excursion (when (subed-srt--jump-to-subtitle-id) (string-to-number (current-word))))) (defun subed-srt--subtitle-id-max () "Return the ID of the last subtitle or nil if there are no subtitles." (save-excursion (goto-char (point-max)) (subed-srt--subtitle-id))) (defun subed-srt--subtitle-id-at-msecs (msecs) "Return the ID of the subtitle at MSECS milliseconds. Return nil if there is no subtitle at MSECS." (save-match-data (save-excursion (goto-char (point-min)) (let* ((secs (/ msecs 1000)) (only-hours (truncate (/ secs 3600))) (only-mins (truncate (/ (- secs (* only-hours 3600)) 60)))) ;; Move to first subtitle in the relevant hour (when (re-search-forward (format "\\(%s\\|\\`\\)[0-9]+\n%02d:" subed-srt--regexp-separator only-hours) nil t) (beginning-of-line) ;; Move to first subtitle in the relevant hour and minute (re-search-forward (format "\\(\n\n\\|\\`\\)[0-9]+\n%02d:%02d" only-hours only-mins) nil t))) ;; Move to first subtitle that starts at or after MSECS (catch 'subtitle-id (while (<= (or (subed-srt--subtitle-msecs-start) -1) msecs) ;; If stop time is >= MSECS, we found a match (let ((cur-sub-end (subed-srt--subtitle-msecs-stop))) (when (and cur-sub-end (>= cur-sub-end msecs)) (throw 'subtitle-id (subed-srt--subtitle-id)))) (unless (subed-srt--forward-subtitle-id) (throw 'subtitle-id nil))))))) (defun subed-srt--subtitle-msecs-start (&optional sub-id) "Subtitle start time in milliseconds or nil if it can't be found. If SUB-ID is not given, use subtitle on point." (let ((timestamp (save-excursion (when (subed-srt--jump-to-subtitle-time-start sub-id) (when (looking-at subed-srt--regexp-timestamp) (match-string 0)))))) (when timestamp (subed-srt--timestamp-to-msecs timestamp)))) (defun subed-srt--subtitle-msecs-stop (&optional sub-id) "Subtitle stop time in milliseconds or nil if it can't be found. If SUB-ID is not given, use subtitle on point." (let ((timestamp (save-excursion (when (subed-srt--jump-to-subtitle-time-stop sub-id) (when (looking-at subed-srt--regexp-timestamp) (match-string 0)))))) (when timestamp (subed-srt--timestamp-to-msecs timestamp)))) (defun subed-srt--subtitle-text (&optional sub-id) "Return subtitle's text or an empty string. If SUB-ID is not given, use subtitle on point." (or (save-excursion (let ((beg (subed-srt--jump-to-subtitle-text sub-id)) (end (subed-srt--jump-to-subtitle-end sub-id))) (when (and beg end) (buffer-substring beg end)))) "")) (defun subed-srt--subtitle-relative-point () "Point relative to subtitle's ID or nil if ID can't be found." (let ((start-point (save-excursion (when (subed-srt--jump-to-subtitle-id) (point))))) (when start-point (- (point) start-point)))) ;;; Traversing (defun subed-srt--jump-to-subtitle-id (&optional sub-id) "Move to the ID of a subtitle and return point. If SUB-ID is not given, focus the current subtitle's ID. Return point or nil if no subtitle ID could be found." (interactive) (save-match-data (if sub-id ;; Look for a line that contains only the ID, preceded by one or more ;; blank lines or the beginning of the buffer. (let* ((orig-point (point)) (regex (format "\\(%s\\|\\`\\)\\(%d\\)$" subed-srt--regexp-separator sub-id)) (match-found (progn (goto-char (point-min)) (re-search-forward regex nil t)))) (if match-found (goto-char (match-beginning 2)) (goto-char orig-point))) ;; Find one or more blank lines. (re-search-forward "\\([[:blank:]]*\n\\)+" nil t) ;; Find two or more blank lines or the beginning of the buffer, followed ;; by line composed of only digits. (let* ((regex (concat "\\(" subed-srt--regexp-separator "\\|\\`\\)\\([0-9]+\\)$")) (match-found (re-search-backward regex nil t))) (when match-found (goto-char (match-beginning 2))))) ;; Make extra sure we're on an ID, return nil if we're not (when (looking-at "^\\([0-9]+\\)$") (point)))) (defun subed-srt--jump-to-subtitle-id-at-msecs (msecs) "Move point to the ID of the subtitle that is playing at MSECS. Return point or nil if point is still on the same subtitle. See also `subed-srt--subtitle-id-at-msecs'." (let ((current-sub-id (subed-srt--subtitle-id)) (target-sub-id (subed-srt--subtitle-id-at-msecs msecs))) (when (and target-sub-id current-sub-id (not (= target-sub-id current-sub-id))) (subed-srt--jump-to-subtitle-id target-sub-id)))) (defun subed-srt--jump-to-subtitle-text-at-msecs (msecs) "Move point to the text of the subtitle that is playing at MSECS. Return point or nil if point is still on the same subtitle. See also `subed-srt--subtitle-id-at-msecs'." (when (subed-srt--jump-to-subtitle-id-at-msecs msecs) (subed-srt--jump-to-subtitle-text))) (defun subed-srt--jump-to-subtitle-time-start (&optional sub-id) "Move point to subtitle's start time. If SUB-ID is not given, use subtitle on point. Return point or nil if no start time could be found." (interactive) (save-match-data (when (subed-srt--jump-to-subtitle-id sub-id) (forward-line) (when (looking-at subed-srt--regexp-timestamp) (point))))) (defun subed-srt--jump-to-subtitle-time-stop (&optional sub-id) "Move point to subtitle's stop time. If SUB-ID is not given, use subtitle on point. Return point or nil if no stop time could be found." (interactive) (save-match-data (when (subed-srt--jump-to-subtitle-id sub-id) (forward-line 1) (re-search-forward " *--> *" (point-at-eol) t) (when (looking-at subed-srt--regexp-timestamp) (point))))) (defun subed-srt--jump-to-subtitle-text (&optional sub-id) "Move point on the first character of subtitle's text. If SUB-ID is not given, use subtitle on point. Return point or nil if a the subtitle's text can't be found." (interactive) (when (subed-srt--jump-to-subtitle-id sub-id) (forward-line 2) (point))) (defun subed-srt--jump-to-subtitle-end (&optional sub-id) "Move point after the last character of the subtitle's text. If SUB-ID is not given, use subtitle on point. Return point or nil if point did not change or if no subtitle end can be found." (interactive) (save-match-data (let ((orig-point (point))) (subed-srt--jump-to-subtitle-text sub-id) ;; Look for next separator or end of buffer. We can't use ;; `subed-srt--regexp-separator' here because if subtitle text is empty, ;; it may be the only empty line in the separator, i.e. there's only one ;; "\n". (let ((regex (concat "\\([[:blank:]]*\n+[0-9]+\n\\|\\([[:blank:]]*\n*\\)\\'\\)"))) (when (re-search-forward regex nil t) (goto-char (match-beginning 0)))) (unless (= (point) orig-point) (point))))) (defun subed-srt--forward-subtitle-id () "Move point to next subtitle's ID. Return point or nil if there is no next subtitle." (interactive) (save-match-data (when (re-search-forward (concat subed-srt--regexp-separator "[0-9]+\n") nil t) (subed-srt--jump-to-subtitle-id)))) (defun subed-srt--backward-subtitle-id () "Move point to previous subtitle's ID. Return point or nil if there is no previous subtitle." (interactive) (let ((orig-point (point))) (when (subed-srt--jump-to-subtitle-id) (if (re-search-backward (concat "\\(" subed-srt--regexp-separator "\\|\\`[[:space:]]*\\)" "\\([0-9]+\\)\n") nil t) (progn (goto-char (match-beginning 2)) (point)) (goto-char orig-point) nil)))) (defun subed-srt--forward-subtitle-text () "Move point to next subtitle's text. Return point or nil if there is no next subtitle." (interactive) (when (subed-srt--forward-subtitle-id) (subed-srt--jump-to-subtitle-text))) (defun subed-srt--backward-subtitle-text () "Move point to previous subtitle's text. Return point or nil if there is no previous subtitle." (interactive) (when (subed-srt--backward-subtitle-id) (subed-srt--jump-to-subtitle-text))) (defun subed-srt--forward-subtitle-end () "Move point to end of next subtitle. Return point or nil if there is no next subtitle." (interactive) (when (subed-srt--forward-subtitle-id) (subed-srt--jump-to-subtitle-end))) (defun subed-srt--backward-subtitle-end () "Move point to end of previous subtitle. Return point or nil if there is no previous subtitle." (interactive) (when (subed-srt--backward-subtitle-id) (subed-srt--jump-to-subtitle-end))) (defun subed-srt--forward-subtitle-time-start () "Move point to next subtitle's start time." (interactive) (when (subed-srt--forward-subtitle-id) (subed-srt--jump-to-subtitle-time-start))) (defun subed-srt--backward-subtitle-time-start () "Move point to previous subtitle's start time." (interactive) (when (subed-srt--backward-subtitle-id) (subed-srt--jump-to-subtitle-time-start))) (defun subed-srt--forward-subtitle-time-stop () "Move point to next subtitle's stop time." (interactive) (when (subed-srt--forward-subtitle-id) (subed-srt--jump-to-subtitle-time-stop))) (defun subed-srt--backward-subtitle-time-stop () "Move point to previous subtitle's stop time." (interactive) (when (subed-srt--backward-subtitle-id) (subed-srt--jump-to-subtitle-time-stop))) ;;; Manipulation (defun subed-srt--set-subtitle-time-start (msecs &optional sub-id) "Set subtitle start time to MSECS milliseconds. If SUB-ID is not given, set the start of the current subtitle. Return the new subtitle start time in milliseconds." (save-excursion (when (or (not sub-id) (and sub-id (subed-srt--jump-to-subtitle-id sub-id))) (subed-srt--jump-to-subtitle-time-start) (when (looking-at subed-srt--regexp-timestamp) (replace-match (subed-srt--msecs-to-timestamp msecs)))))) (defun subed-srt--set-subtitle-time-stop (msecs &optional sub-id) "Set subtitle stop time to MSECS milliseconds. If SUB-ID is not given, set the stop of the current subtitle. Return the new subtitle stop time in milliseconds." (save-excursion (when (or (not sub-id) (and sub-id (subed-srt--jump-to-subtitle-id sub-id))) (subed-srt--jump-to-subtitle-time-stop) (when (looking-at subed-srt--regexp-timestamp) (replace-match (subed-srt--msecs-to-timestamp msecs)))))) (defun subed-srt--make-subtitle (&optional id start stop text) "Generate new subtitle string. ID, START default to 0. STOP defaults to (+ START `subed-subtitle-spacing') TEXT defaults to an empty string. A newline is appended to TEXT, meaning you'll get two trailing newlines if TEXT is nil or empty." (interactive "P") (format "%s\n%s --> %s\n%s\n" (or id 0) (subed-srt--msecs-to-timestamp (or start 0)) (subed-srt--msecs-to-timestamp (or stop (+ (or start 0) subed-default-subtitle-length))) (or text ""))) (defun subed-srt--prepend-subtitle (&optional id start stop text) "Insert new subtitle before the subtitle at point. ID and START default to 0. STOP defaults to (+ START `subed-subtitle-spacing') TEXT defaults to an empty string. Move point to the text of the inserted subtitle. Return new point." (interactive "P") (subed-srt--jump-to-subtitle-id) (insert (subed-srt--make-subtitle id start stop text)) (save-match-data (when (looking-at "\\([[:space:]]*\\|^\\)[0-9]+$") (insert "\n"))) (forward-line -2) (subed-srt--jump-to-subtitle-text)) (defun subed-srt--append-subtitle (&optional id start stop text) "Insert new subtitle after the subtitle at point. ID, START default to 0. STOP defaults to (+ START `subed-subtitle-spacing') TEXT defaults to an empty string. Move point to the text of the inserted subtitle. Return new point." (interactive "P") (unless (subed-srt--forward-subtitle-id) ;; Point is on last subtitle or buffer is empty (subed-srt--jump-to-subtitle-end) ;; Moved point to end of last subtitle; ensure separator exists (while (not (looking-at "\\(\\`\\|[[:blank:]]*\n[[:blank:]]*\n\\)")) (save-excursion (insert ?\n))) ;; Move to end of separator (goto-char (match-end 0))) (insert (subed-srt--make-subtitle id start stop text)) ;; Complete separator with another newline unless we inserted at the end (save-match-data (when (looking-at "\\([[:space:]]*\\|^\\)[0-9]+$") (insert ?\n))) (forward-line -2) (subed-srt--jump-to-subtitle-text)) (defun subed-srt--kill-subtitle () "Remove subtitle at point." (interactive) (let ((beg (save-excursion (subed-srt--jump-to-subtitle-id) (point))) (end (save-excursion (subed-srt--jump-to-subtitle-id) (when (subed-srt--forward-subtitle-id) (point))))) (if (not end) ;; Removing the last subtitle because forward-subtitle-id returned nil (setq beg (save-excursion (goto-char beg) (subed-srt--backward-subtitle-end) (1+ (point))) end (save-excursion (goto-char (point-max))))) (delete-region beg end)) (subed-srt--regenerate-ids-soon)) (defun subed-srt--merge-with-next () "Merge the current subtitle with the next subtitle. Update the end timestamp accordingly." (interactive) (save-excursion (subed-srt--jump-to-subtitle-end) (let ((pos (point)) new-end) (if (subed-srt--forward-subtitle-time-stop) (progn (when (looking-at subed-srt--regexp-timestamp) (setq new-end (subed-srt--timestamp-to-msecs (match-string 0)))) (subed-srt--jump-to-subtitle-text) (delete-region pos (point)) (insert "\n") (subed-srt--set-subtitle-time-stop new-end) (subed-srt--regenerate-ids-soon)) (error "No subtitle to merge into"))))) ;;; Maintenance (defun subed-srt--regenerate-ids () "Ensure consecutive, unduplicated subtitle IDs." (interactive) (atomic-change-group (save-match-data (save-excursion (goto-char (point-min)) (subed-srt--jump-to-subtitle-id) (when (looking-at "^[[:digit:]]+$") (unless (string= (current-word) "1") (delete-region (point) (progn (forward-word 1) (point))) (insert "1"))) (let ((id 2)) (while (subed-srt--forward-subtitle-id) (let ((id-str (number-to-string id))) (unless (string= (current-word) id-str) (delete-region (point) (progn (forward-word 1) (point))) (insert id-str))) (setq id (1+ id)))))))) (defvar-local subed-srt--regenerate-ids-soon-timer nil) (defun subed-srt--regenerate-ids-soon () "Delay regenerating subtitle IDs for a short amount of time. Run `subed-srt--regenerate-ids' in 100ms unless this function is called again within the next 100ms, in which case the previously scheduled call is canceled and another call is scheduled in 100ms." (interactive) (when subed-srt--regenerate-ids-soon-timer (cancel-timer subed-srt--regenerate-ids-soon-timer)) (setq subed-srt--regenerate-ids-soon-timer (run-at-time 0.1 nil (lambda () (setq subed-srt--regenerate-ids-soon-timer nil) (subed-srt--regenerate-ids))))) (defun subed-srt--sanitize () "Remove surplus newlines and whitespace." (interactive) (atomic-change-group (save-match-data (subed-save-excursion ;; Remove trailing whitespace from each line (delete-trailing-whitespace (point-min) (point-max)) ;; Remove leading spaces and tabs from each line (goto-char (point-min)) (while (re-search-forward "^[[:blank:]]+" nil t) (replace-match "")) ;; Remove leading newlines (goto-char (point-min)) (while (looking-at "\\`\n+") (replace-match "")) ;; Replace separators between subtitles with double newlines (goto-char (point-min)) (while (subed-srt--forward-subtitle-id) (let ((prev-sub-end (save-excursion (when (subed-srt--backward-subtitle-end) (point))))) (when (and prev-sub-end (not (string= (buffer-substring prev-sub-end (point)) "\n\n"))) (delete-region prev-sub-end (point)) (insert "\n\n")))) ;; Two trailing newline if last subtitle text is empty, one trailing ;; newline otherwise; do nothing in empty buffer (no graphical ;; characters) (goto-char (point-min)) (when (re-search-forward "[[:graph:]]" nil t) (goto-char (point-max)) (subed-srt--jump-to-subtitle-end) (unless (looking-at "\n\\'") (delete-region (point) (point-max)) (insert "\n"))) ;; One space before and after " --> " (goto-char (point-min)) (while (re-search-forward (format "^%s" subed-srt--regexp-timestamp) nil t) (when (looking-at "[[:blank:]]*-->[[:blank:]]*") (unless (= (length (match-string 0)) 5) (replace-match " --> ")))))))) (defun subed-srt--validate () "Move point to the first invalid subtitle and report an error." (interactive) (when (> (buffer-size) 0) (atomic-change-group (save-match-data (let ((orig-point (point))) (goto-char (point-min)) (while (and (re-search-forward (format "\\(%s\\|\\`\\)" subed-srt--regexp-separator) nil t) (looking-at "[[:alnum:]]")) (unless (looking-at "^[0-9]+$") (error "Found invalid subtitle ID: %S" (substring (or (thing-at-point 'line :no-properties) "\n") 0 -1))) (forward-line) ;; This regex is stricter than `subed-srt--regexp-timestamp' (unless (looking-at "^[0-9]\\{2\\}:[0-9]\\{2\\}:[0-9]\\{2\\},[0-9]\\{,3\\}") (error "Found invalid start time: %S" (substring (or (thing-at-point 'line :no-properties) "\n") 0 -1))) (when (re-search-forward "[[:blank:]]" (point-at-eol) t) (goto-char (match-beginning 0))) (unless (looking-at " --> ") (error "Found invalid separator between start and stop time: %S" (substring (or (thing-at-point 'line :no-properties) "\n") 0 -1))) (condition-case nil (forward-char 5) (error nil)) (unless (looking-at "[0-9]\\{2\\}:[0-9]\\{2\\}:[0-9]\\{2\\},[0-9]\\{,3\\}$") (error "Found invalid stop time: %S" (substring (or (thing-at-point 'line :no-properties) "\n") 0 -1)))) (goto-char orig-point)))))) (defun subed-srt--sort () "Sanitize, then sort subtitles by start time and re-number them." (interactive) (atomic-change-group (subed-srt--sanitize) (subed-srt--validate) (subed-save-excursion (goto-char (point-min)) (sort-subr nil ;; nextrecfun (move to next record/subtitle or to end-of-buffer ;; if there are no more records) (lambda () (unless (subed-srt--forward-subtitle-id) (goto-char (point-max)))) ;; endrecfun (move to end of current record/subtitle) #'subed-srt--jump-to-subtitle-end ;; startkeyfun (return sort value of current record/subtitle) #'subed-srt--subtitle-msecs-start)) (subed-srt--regenerate-ids))) (defun subed-srt--init () "This function is called when subed-mode is entered for a SRT file." (setq-local subed--subtitle-format "srt") (setq-local font-lock-defaults '(subed-srt-font-lock-keywords)) ;; Support for fill-paragraph (M-q) (let ((timestamps-regexp (concat subed-srt--regexp-timestamp " *--> *" subed-srt--regexp-timestamp))) (setq-local paragraph-separate (concat "^\\(" (mapconcat 'identity `("[[:blank:]]*" "[[:digit:]]+" ,timestamps-regexp) "\\|") "\\)$")) (setq-local paragraph-start (concat "\\(" ;; Mulitple speakers in the same ;; subtitle are often distinguished with ;; a "-" at the start of the line. (mapconcat 'identity '("^-" "[[:graph:]]*$") "\\|") "\\)")))) (provide 'subed-srt) ;;; subed-srt.el ends here subed-master/subed/subed-vtt.el000066400000000000000000000545461401667552300170410ustar00rootroot00000000000000;;; subed-vtt.el --- WebVTT implementation for subed -*- lexical-binding: t; -*- ;;; License: ;; ;; This file is not part of GNU Emacs. ;; ;; This is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation; either version 3, or (at your option) ;; any later version. ;; ;; This is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs; see the file COPYING. If not, write to the ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, ;; Boston, MA 02110-1301, USA. ;;; Commentary: ;; WebVTT implementation for subed-mode. ;; Since WebVTT doesn't use IDs, we'll use the starting timestamp. ;;; Code: (require 'subed-config) (require 'subed-debug) (require 'subed-common) ;;; Syntax highlighting (defconst subed-vtt-font-lock-keywords (list '("[0-9]+:[0-9]+:[0-9]+\\.[0-9]+" . 'subed-vtt-time-face) '(",[0-9]+ \\(-->\\) [0-9]+:" 1 'subed-vtt-time-separator-face t) '("^.*$" . 'subed-vtt-text-face)) "Highlighting expressions for `subed-mode'.") ;;; Parsing (defconst subed-vtt--regexp-timestamp "\\([0-9]+\\):\\([0-9]+\\):\\([0-9]+\\)\\.\\([0-9]+\\)") (defconst subed-vtt--regexp-separator "\\(?:[[:blank:]]*\n\\)+[[:blank:]]*\n") (defun subed-vtt--timestamp-to-msecs (time-string) "Find HH:MM:SS.MS pattern in TIME-STRING and convert it to milliseconds. Return nil if TIME-STRING doesn't match the pattern." (save-match-data (when (string-match subed-vtt--regexp-timestamp time-string) (let ((hours (string-to-number (match-string 1 time-string))) (mins (string-to-number (match-string 2 time-string))) (secs (string-to-number (match-string 3 time-string))) (msecs (string-to-number (subed--right-pad (match-string 4 time-string) 3 ?0)))) (+ (* (truncate hours) 3600000) (* (truncate mins) 60000) (* (truncate secs) 1000) (truncate msecs)))))) (defun subed-vtt--msecs-to-timestamp (msecs) "Convert MSECS to string in the format HH:MM:SS,MS." ;; We need to wrap format-seconds in save-match-data because it does regexp ;; stuff and we need to preserve our own match-data. (concat (save-match-data (format-seconds "%02h:%02m:%02s" (/ msecs 1000))) "." (format "%03d" (mod msecs 1000)))) (defun subed-vtt--subtitle-id () "Return the ID of the subtitle at point or nil if there is no ID." (save-excursion (when (subed-vtt--jump-to-subtitle-id) (when (looking-at subed-vtt--regexp-timestamp) (match-string 0))))) (defun subed-vtt--subtitle-id-max () "Return the ID of the last subtitle or nil if there are no subtitles." (save-excursion (goto-char (point-max)) (subed-vtt--subtitle-id))) (defun subed-vtt--subtitle-id-at-msecs (msecs) "Return the ID of the subtitle at MSECS milliseconds. Return nil if there is no subtitle at MSECS." (save-match-data (save-excursion (goto-char (point-min)) (let* ((secs (/ msecs 1000)) (only-hours (truncate (/ secs 3600))) (only-mins (truncate (/ (- secs (* only-hours 3600)) 60)))) ;; Move to first subtitle in the relevant hour (when (re-search-forward (format "\\(%s\\|\\`\\)%02d:" subed-vtt--regexp-separator only-hours) nil t) (beginning-of-line) ;; Move to first subtitle in the relevant hour and minute (re-search-forward (format "\\(\n\n\\|\\`\\)%02d:%02d" only-hours only-mins) nil t))) ;; Move to first subtitle that starts at or after MSECS (catch 'subtitle-id (while (<= (or (subed-vtt--subtitle-msecs-start) -1) msecs) ;; If stop time is >= MSECS, we found a match (let ((cur-sub-end (subed-vtt--subtitle-msecs-stop))) (when (and cur-sub-end (>= cur-sub-end msecs)) (throw 'subtitle-id (subed-vtt--subtitle-id)))) (unless (subed-vtt--forward-subtitle-id) (throw 'subtitle-id nil))))))) (defun subed-vtt--subtitle-msecs-start (&optional sub-id) "Subtitle start time in milliseconds or nil if it can't be found. If SUB-ID is not given, use subtitle on point." (let ((timestamp (save-excursion (when (subed-vtt--jump-to-subtitle-time-start sub-id) (when (looking-at subed-vtt--regexp-timestamp) (match-string 0)))))) (when timestamp (subed-vtt--timestamp-to-msecs timestamp)))) (defun subed-vtt--subtitle-msecs-stop (&optional sub-id) "Subtitle stop time in milliseconds or nil if it can't be found. If SUB-ID is not given, use subtitle on point." (let ((timestamp (save-excursion (when (subed-vtt--jump-to-subtitle-time-stop sub-id) (when (looking-at subed-vtt--regexp-timestamp) (match-string 0)))))) (when timestamp (subed-vtt--timestamp-to-msecs timestamp)))) (defun subed-vtt--subtitle-text (&optional sub-id) "Return subtitle's text or an empty string. If SUB-ID is not given, use subtitle on point." (or (save-excursion (let ((beg (subed-vtt--jump-to-subtitle-text sub-id)) (end (subed-vtt--jump-to-subtitle-end sub-id))) (when (and beg end) (buffer-substring beg end)))) "")) (defun subed-vtt--subtitle-relative-point () "Point relative to subtitle's ID or nil if ID can't be found." (let ((start-point (save-excursion (when (subed-vtt--jump-to-subtitle-id) (point))))) (when start-point (- (point) start-point)))) ;;; Traversing (defun subed-vtt--jump-to-subtitle-id (&optional sub-id) "Move to the ID of a subtitle and return point. If SUB-ID is not given, focus the current subtitle's ID. Return point or nil if no subtitle ID could be found. WebVTT doesn't use IDs, so we use the starting timestamp instead." (interactive) (save-match-data (if (stringp sub-id) ;; Look for a line that contains only the ID, preceded by one or more ;; blank lines or the beginning of the buffer. (let* ((orig-point (point)) (regex (concat "\\(" subed-srt--regexp-separator "\\|\\`\\)\\(" (regexp-quote sub-id) "\\)")) (match-found (progn (goto-char (point-min)) (re-search-forward regex nil t)))) (if match-found (goto-char (match-beginning 2)) (goto-char orig-point))) ;; Find one or more blank lines. (re-search-forward "\\([[:blank:]]*\n\\)+" nil t) ;; Find two or more blank lines or the beginning of the buffer, followed ;; by line starting with a timestamp. (let* ((regex (concat "\\(" subed-srt--regexp-separator "\\|\\`\\)\\(" subed-vtt--regexp-timestamp "\\)")) (match-found (re-search-backward regex nil t))) (when match-found (goto-char (match-beginning 2))))) ;; Make extra sure we're on a timestamp, return nil if we're not (when (looking-at "^\\([0-9]+:[0-9]+:[0-9]+\\.[0-9]+\\)") (point)))) (defun subed-vtt--jump-to-subtitle-id-at-msecs (msecs) "Move point to the ID of the subtitle that is playing at MSECS. Return point or nil if point is still on the same subtitle. See also `subed-vtt--subtitle-id-at-msecs'." (let ((current-sub-id (subed-vtt--subtitle-id)) (target-sub-id (subed-vtt--subtitle-id-at-msecs msecs))) (when (and target-sub-id current-sub-id (not (equal target-sub-id current-sub-id))) (subed-vtt--jump-to-subtitle-id target-sub-id)))) (defun subed-vtt--jump-to-subtitle-text-at-msecs (msecs) "Move point to the text of the subtitle that is playing at MSECS. Return point or nil if point is still on the same subtitle. See also `subed-vtt--subtitle-id-at-msecs'." (when (subed-vtt--jump-to-subtitle-id-at-msecs msecs) (subed-vtt--jump-to-subtitle-text))) (defun subed-vtt--jump-to-subtitle-time-start (&optional sub-id) "Move point to subtitle's start time. If SUB-ID is not given, use subtitle on point. Return point or nil if no start time could be found." (interactive) (save-match-data (when (subed-vtt--jump-to-subtitle-id sub-id) (when (looking-at subed-vtt--regexp-timestamp) (point))))) (defun subed-vtt--jump-to-subtitle-time-stop (&optional sub-id) "Move point to subtitle's stop time. If SUB-ID is not given, use subtitle on point. Return point or nil if no stop time could be found." (interactive) (save-match-data (when (subed-vtt--jump-to-subtitle-id sub-id) (re-search-forward " *--> *" (point-at-eol) t) (when (looking-at subed-vtt--regexp-timestamp) (point))))) (defun subed-vtt--jump-to-subtitle-text (&optional sub-id) "Move point on the first character of subtitle's text. If SUB-ID is not given, use subtitle on point. Return point or nil if a the subtitle's text can't be found." (interactive) (when (subed-vtt--jump-to-subtitle-id sub-id) (forward-line 1) (point))) (defun subed-vtt--jump-to-subtitle-end (&optional sub-id) "Move point after the last character of the subtitle's text. If SUB-ID is not given, use subtitle on point. Return point or nil if point did not change or if no subtitle end can be found." (interactive) (save-match-data (let ((orig-point (point))) (subed-vtt--jump-to-subtitle-text sub-id) ;; Look for next separator or end of buffer. We can't use ;; `subed-vtt--regexp-separator' here because if subtitle text is empty, ;; it may be the only empty line in the separator, i.e. there's only one ;; "\n". (let ((regex (concat "\\([[:blank:]]*\n+" subed-vtt--regexp-timestamp "\\|\\([[:blank:]]*\n*\\)\\'\\)"))) (when (re-search-forward regex nil t) (goto-char (match-beginning 0)))) (unless (= (point) orig-point) (point))))) (defun subed-vtt--forward-subtitle-id () "Move point to next subtitle's ID. Return point or nil if there is no next subtitle." (interactive) (save-match-data (when (re-search-forward (concat subed-vtt--regexp-separator subed-vtt--regexp-timestamp) nil t) (subed-vtt--jump-to-subtitle-id)))) (defun subed-vtt--backward-subtitle-id () "Move point to previous subtitle's ID. Return point or nil if there is no previous subtitle." (interactive) (let ((orig-point (point))) (when (subed-vtt--jump-to-subtitle-id) (if (re-search-backward (concat "\\(" subed-vtt--regexp-separator "\\|\\`[[:space:]]*\\)\\(" subed-vtt--regexp-timestamp "\\)") nil t) (progn (goto-char (match-beginning 2)) (point)) (goto-char orig-point) nil)))) (defun subed-vtt--forward-subtitle-text () "Move point to next subtitle's text. Return point or nil if there is no next subtitle." (interactive) (when (subed-vtt--forward-subtitle-id) (subed-vtt--jump-to-subtitle-text))) (defun subed-vtt--backward-subtitle-text () "Move point to previous subtitle's text. Return point or nil if there is no previous subtitle." (interactive) (when (subed-vtt--backward-subtitle-id) (subed-vtt--jump-to-subtitle-text))) (defun subed-vtt--forward-subtitle-end () "Move point to end of next subtitle. Return point or nil if there is no next subtitle." (interactive) (when (subed-vtt--forward-subtitle-id) (subed-vtt--jump-to-subtitle-end))) (defun subed-vtt--backward-subtitle-end () "Move point to end of previous subtitle. Return point or nil if there is no previous subtitle." (interactive) (when (subed-vtt--backward-subtitle-id) (subed-vtt--jump-to-subtitle-end))) (defun subed-vtt--forward-subtitle-time-start () "Move point to next subtitle's start time." (interactive) (when (subed-vtt--forward-subtitle-id) (subed-vtt--jump-to-subtitle-time-start))) (defun subed-vtt--backward-subtitle-time-start () "Move point to previous subtitle's start time." (interactive) (when (subed-vtt--backward-subtitle-id) (subed-vtt--jump-to-subtitle-time-start))) (defun subed-vtt--forward-subtitle-time-stop () "Move point to next subtitle's stop time." (interactive) (when (subed-vtt--forward-subtitle-id) (subed-vtt--jump-to-subtitle-time-stop))) (defun subed-vtt--backward-subtitle-time-stop () "Move point to previous subtitle's stop time." (interactive) (when (subed-vtt--backward-subtitle-id) (subed-vtt--jump-to-subtitle-time-stop))) ;;; Manipulation (defun subed-vtt--set-subtitle-time-start (msecs &optional sub-id) "Set subtitle start time to MSECS milliseconds. If SUB-ID is not given, set the start of the current subtitle. Return the new subtitle start time in milliseconds." (save-excursion (when (or (not sub-id) (and sub-id (subed-vtt--jump-to-subtitle-id sub-id))) (subed-vtt--jump-to-subtitle-time-start) (when (looking-at subed-vtt--regexp-timestamp) (replace-match (subed-vtt--msecs-to-timestamp msecs)))))) (defun subed-vtt--set-subtitle-time-stop (msecs &optional sub-id) "Set subtitle stop time to MSECS milliseconds. If SUB-ID is not given, set the stop of the current subtitle. Return the new subtitle stop time in milliseconds." (save-excursion (when (or (not sub-id) (and sub-id (subed-vtt--jump-to-subtitle-id sub-id))) (subed-vtt--jump-to-subtitle-time-stop) (when (looking-at subed-vtt--regexp-timestamp) (replace-match (subed-vtt--msecs-to-timestamp msecs)))))) (defun subed-vtt--make-subtitle (&optional id start stop text) "Generate new subtitle string. ID, START default to 0. STOP defaults to (+ START `subed-subtitle-spacing') TEXT defaults to an empty string. A newline is appended to TEXT, meaning you'll get two trailing newlines if TEXT is nil or empty." (interactive "P") (format "%s --> %s\n%s\n" (subed-vtt--msecs-to-timestamp (or start 0)) (subed-vtt--msecs-to-timestamp (or stop (+ (or start 0) subed-default-subtitle-length))) (or text ""))) (defun subed-vtt--prepend-subtitle (&optional id start stop text) "Insert new subtitle before the subtitle at point. ID and START default to 0. STOP defaults to (+ START `subed-subtitle-spacing') TEXT defaults to an empty string. Move point to the text of the inserted subtitle. Return new point." (interactive "P") (subed-vtt--jump-to-subtitle-id) (insert (subed-vtt--make-subtitle id start stop text)) (save-match-data (when (looking-at (concat "\\([[:space:]]*\\|^\\)" subed-vtt--regexp-timestamp)) (insert "\n"))) (forward-line -2) (subed-vtt--jump-to-subtitle-text)) (defun subed-vtt--append-subtitle (&optional id start stop text) "Insert new subtitle after the subtitle at point. ID, START default to 0. STOP defaults to (+ START `subed-subtitle-spacing') TEXT defaults to an empty string. Move point to the text of the inserted subtitle. Return new point." (interactive "P") (unless (subed-vtt--forward-subtitle-id) ;; Point is on last subtitle or buffer is empty (subed-vtt--jump-to-subtitle-end) ;; Moved point to end of last subtitle; ensure separator exists (while (not (looking-at "\\(\\`\\|[[:blank:]]*\n[[:blank:]]*\n\\)")) (save-excursion (insert ?\n))) ;; Move to end of separator (goto-char (match-end 0))) (insert (subed-vtt--make-subtitle id start stop text)) ;; Complete separator with another newline unless we inserted at the end (save-match-data (when (looking-at (concat "\\([[:space:]]*\\|^\\)" subed-vtt--regexp-timestamp)) (insert ?\n))) (forward-line -2) (subed-vtt--jump-to-subtitle-text)) (defun subed-vtt--kill-subtitle () "Remove subtitle at point." (interactive) (let ((beg (save-excursion (subed-vtt--jump-to-subtitle-id) (point))) (end (save-excursion (subed-vtt--jump-to-subtitle-id) (when (subed-vtt--forward-subtitle-id) (point))))) (if (not end) ;; Removing the last subtitle because forward-subtitle-id returned nil (setq beg (save-excursion (goto-char beg) (subed-vtt--backward-subtitle-end) (1+ (point))) end (save-excursion (goto-char (point-max))))) (delete-region beg end))) (defun subed-vtt--merge-with-next () "Merge the current subtitle with the next subtitle. Update the end timestamp accordingly." (interactive) (save-excursion (subed-vtt--jump-to-subtitle-end) (let ((pos (point)) new-end) (if (subed-vtt--forward-subtitle-time-stop) (progn (when (looking-at subed-vtt--regexp-timestamp) (setq new-end (subed-vtt--timestamp-to-msecs (match-string 0)))) (subed-vtt--jump-to-subtitle-text) (delete-region pos (point)) (insert "\n") (subed-vtt--set-subtitle-time-stop new-end)) (error "No subtitle to merge into"))))) ;;; Maintenance (defun subed-vtt--regenerate-ids () "Not applicable to WebVTT." (interactive)) (defvar-local subed-vtt--regenerate-ids-soon-timer nil) (defun subed-vtt--regenerate-ids-soon () "Not applicable to WebVTT." (interactive)) (defun subed-vtt--sanitize () "Remove surplus newlines and whitespace." (interactive) (atomic-change-group (save-match-data (subed-save-excursion ;; Remove trailing whitespace from each line (delete-trailing-whitespace (point-min) (point-max)) ;; Remove leading spaces and tabs from each line (goto-char (point-min)) (while (re-search-forward "^[[:blank:]]+" nil t) (replace-match "")) ;; Remove leading newlines (goto-char (point-min)) (while (looking-at "\\`\n+") (replace-match "")) ;; Replace separators between subtitles with double newlines (goto-char (point-min)) (while (subed-vtt--forward-subtitle-id) (let ((prev-sub-end (save-excursion (when (subed-vtt--backward-subtitle-end) (point))))) (when (and prev-sub-end (not (string= (buffer-substring prev-sub-end (point)) "\n\n"))) (delete-region prev-sub-end (point)) (insert "\n\n")))) ;; Two trailing newline if last subtitle text is empty, one trailing ;; newline otherwise; do nothing in empty buffer (no graphical ;; characters) (goto-char (point-min)) (when (re-search-forward "[[:graph:]]" nil t) (goto-char (point-max)) (subed-vtt--jump-to-subtitle-end) (unless (looking-at "\n\\'") (delete-region (point) (point-max)) (insert "\n"))) ;; One space before and after " --> " (goto-char (point-min)) (while (re-search-forward (format "^%s" subed-vtt--regexp-timestamp) nil t) (when (looking-at "[[:blank:]]*-->[[:blank:]]*") (unless (= (length (match-string 0)) 5) (replace-match " --> ")))))))) (defun subed-vtt--validate () "Move point to the first invalid subtitle and report an error." (interactive) (when (> (buffer-size) 0) (atomic-change-group (save-match-data (let ((orig-point (point))) (goto-char (point-min)) (while (and (re-search-forward (format "^\\(%s\\)" subed-vtt--regexp-timestamp) nil t) (goto-char (match-beginning 1))) ;; This regex is stricter than `subed-vtt--regexp-timestamp' (unless (looking-at "^[0-9]\\{2\\}:[0-9]\\{2\\}:[0-9]\\{2\\}\\(\\.[0-9]\\{0,3\\}\\)") (error "Found invalid start time: %S" (substring (or (thing-at-point 'line :no-properties) "\n") 0 -1))) (when (re-search-forward "[[:blank:]]" (point-at-eol) t) (goto-char (match-beginning 0))) (unless (looking-at " --> ") (error "Found invalid separator between start and stop time: %S" (substring (or (thing-at-point 'line :no-properties) "\n") 0 -1))) (condition-case nil (forward-char 5) (error nil)) (unless (looking-at "[0-9]\\{2\\}:[0-9]\\{2\\}:[0-9]\\{2\\}\\(\\.[0-9]\\{0,3\\}\\)$") (error "Found invalid stop time: %S" (substring (or (thing-at-point 'line :no-properties) "\n") 0 -1)))) (goto-char orig-point)))))) (defun subed-vtt--sort () "Sanitize, then sort subtitles by start time and re-number them." (interactive) (atomic-change-group (subed-vtt--sanitize) (subed-vtt--validate) (subed-save-excursion (goto-char (point-min)) (subed-vtt--forward-subtitle-id) (sort-subr nil ;; nextrecfun (move to next record/subtitle or to end-of-buffer ;; if there are no more records) (lambda () (unless (subed-vtt--forward-subtitle-id) (goto-char (point-max)))) ;; endrecfun (move to end of current record/subtitle) #'subed-vtt--jump-to-subtitle-end ;; startkeyfun (return sort value of current record/subtitle) #'subed-vtt--subtitle-msecs-start)))) (defun subed-vtt--init () "This function is called when subed-mode is entered for a SRT file." (setq-local subed--subtitle-format "vtt") (setq-local font-lock-defaults '(subed-vtt-font-lock-keywords)) ;; Support for fill-paragraph (M-q) (let ((timestamps-regexp (concat subed-vtt--regexp-timestamp " *--> *" subed-vtt--regexp-timestamp))) (setq-local paragraph-separate (concat "^\\(" (mapconcat 'identity `("[[:blank:]]*" "[[:digit:]]+" ,timestamps-regexp) "\\|") "\\)$")) (setq-local paragraph-start (concat "\\(" ;; Mulitple speakers in the same ;; subtitle are often distinguished with ;; a "-" at the start of the line. (mapconcat 'identity '("^-" "[[:graph:]]*$") "\\|") "\\)")))) (provide 'subed-vtt) ;;; subed-vtt.el ends here subed-master/subed/subed.el000066400000000000000000000237611401667552300162210ustar00rootroot00000000000000;;; subed.el --- A major mode for editing subtitles -*- lexical-binding: t; -*- ;; Version: 0.0.1 ;; Keywords: convenience, files, hypermedia, multimedia ;; URL: https://github.com/rndusr/subed ;; Package-Requires: ((emacs "25.1")) ;;; License: ;; ;; This file is not part of GNU Emacs. ;; ;; This is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation; either version 3, or (at your option) ;; any later version. ;; ;; This is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs; see the file COPYING. If not, write to the ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, ;; Boston, MA 02110-1301, USA. ;;; Commentary: ;; ;; subed is a major mode for editing subtitles with Emacs and mpv. See C-h f ;; subed-mode, the README.org file or https://github.com/rndusr/subed for more ;; information. ;;; Code: (require 'subed-config) (require 'subed-debug) (require 'subed-common) (require 'subed-srt) (require 'subed-vtt) (require 'subed-mpv) (setq subed-mode-map (let ((subed-mode-map (make-keymap))) (define-key subed-mode-map (kbd "M-n") #'subed-forward-subtitle-text) (define-key subed-mode-map (kbd "M-p") #'subed-backward-subtitle-text) (define-key subed-mode-map (kbd "C-M-a") #'subed-jump-to-subtitle-text) (define-key subed-mode-map (kbd "C-M-e") #'subed-jump-to-subtitle-end) (define-key subed-mode-map (kbd "M-[") #'subed-decrease-start-time) (define-key subed-mode-map (kbd "M-]") #'subed-increase-start-time) (define-key subed-mode-map (kbd "M-{") #'subed-decrease-stop-time) (define-key subed-mode-map (kbd "M-}") #'subed-increase-stop-time) (define-key subed-mode-map (kbd "C-M-n") #'subed-move-subtitle-forward) (define-key subed-mode-map (kbd "C-M-p") #'subed-move-subtitle-backward) (define-key subed-mode-map (kbd "C-M-f") #'subed-shift-subtitle-forward) (define-key subed-mode-map (kbd "C-M-b") #'subed-shift-subtitle-backward) (define-key subed-mode-map (kbd "M-i") #'subed-insert-subtitle) (define-key subed-mode-map (kbd "C-M-i") #'subed-insert-subtitle-adjacent) (define-key subed-mode-map (kbd "M-k") #'subed-kill-subtitle) (define-key subed-mode-map (kbd "M-m") #'subed-merge-with-next) (define-key subed-mode-map (kbd "M-M") #'subed-merge-with-previous) (define-key subed-mode-map (kbd "M-.") #'subed-split-subtitle) (define-key subed-mode-map (kbd "M-s") #'subed-sort) (define-key subed-mode-map (kbd "M-SPC") #'subed-mpv-toggle-pause) (define-key subed-mode-map (kbd "C-c C-d") #'subed-toggle-debugging) (define-key subed-mode-map (kbd "C-c C-v") #'subed-mpv-find-video) (define-key subed-mode-map (kbd "C-c C-u") #'subed-mpv-play-video-from-url) (define-key subed-mode-map (kbd "C-c C-p") #'subed-toggle-pause-while-typing) (define-key subed-mode-map (kbd "C-c C-l") #'subed-toggle-loop-over-current-subtitle) (define-key subed-mode-map (kbd "C-c C-r") #'subed-toggle-replay-adjusted-subtitle) (define-key subed-mode-map (kbd "C-c [") #'subed-copy-player-pos-to-start-time) (define-key subed-mode-map (kbd "C-c ]") #'subed-copy-player-pos-to-stop-time) (define-key subed-mode-map (kbd "C-c .") #'subed-toggle-sync-point-to-player) (define-key subed-mode-map (kbd "C-c ,") #'subed-toggle-sync-player-to-point) subed-mode-map)) ;;;###autoload (defvar subed--init-alist '(("srt" . subed-srt--init) ("vtt" . subed-vtt--init)) "Alist that maps file extensions to format-specific init functions.") ;;; Abstraction hack to support different subtitle formats ;; ;; We need subtitle format-specific functions for each individual buffer so it ;; is possible to open a .srt and a .sub file in the same Emacs session. ;; Buffer-local functions don't exist in Elisp, but we can store the format in a ;; buffer-local variable. ;; ;; `subed-mode-enable' runs a format-specific init function based on the file ;; extension. The init function sets the buffer-local variable ;; `subed--subtitle-format' which is then used by generic functions to assemble ;; the names of format-specific functions on the fly (e.g. (concat "subed-" ;; subed-subtitle-format "--subtitle-id")). (defvar subed--generic-function-suffixes (list "subtitle-id" "subtitle-id-max" "subtitle-id-at-msecs" "subtitle-msecs-start" "subtitle-msecs-stop" "subtitle-text" "subtitle-relative-point" "jump-to-subtitle-id" "jump-to-subtitle-id-at-msecs" "jump-to-subtitle-time-start" "jump-to-subtitle-time-stop" "jump-to-subtitle-text" "jump-to-subtitle-text-at-msecs" "jump-to-subtitle-end" "forward-subtitle-id" "backward-subtitle-id" "forward-subtitle-text" "backward-subtitle-text" "forward-subtitle-end" "backward-subtitle-end" "forward-subtitle-time-start" "backward-subtitle-time-start" "forward-subtitle-time-stop" "backward-subtitle-time-stop" "set-subtitle-time-start" "set-subtitle-time-stop" "prepend-subtitle" "append-subtitle" "kill-subtitle" "merge-with-next" "regenerate-ids" "regenerate-ids-soon" "sanitize" "validate" "sort")) (defun subed--get-generic-func (func-suffix) "Return the generic/public function for FUNC-SUFFIX." (intern (concat "subed-" func-suffix))) (defun subed--get-specific-func (func-suffix) "Return the format-specific function for the current buffer for FUNC-SUFFIX." (intern (concat "subed-" subed--subtitle-format "--" func-suffix))) (defun subed--init () "Call subtitle format-specific init function and (re-)alias generic functions." ;; Call format-specific init function based on file extension and ;; `subed--init-alist'. (let* ((file-ext (when (buffer-file-name) (file-name-extension (buffer-file-name)))) (init-func (alist-get file-ext subed--init-alist nil nil 'equal))) (if (functionp init-func) (funcall init-func) (error "Missing init function: %S" init-func)) (unless subed--subtitle-format (error "%S failed to set buffer-local variable: subed--subtitle-format" init-func))) ;; Define generic functions like `subed-subtitle-text'. (cl-loop for func-suffix in subed--generic-function-suffixes do (let ((generic-func (subed--get-generic-func func-suffix)) (specific-func (subed--get-specific-func func-suffix))) (unless (functionp specific-func) (error "Missing subtitle format-specific function: %s" specific-func)) (if (functionp specific-func) (let* ((argspec (help-function-arglist specific-func)) (argvars (seq-filter (lambda (argvar) (let ((first-char (substring (symbol-name argvar) 0 1))) (not (equal first-char "&")))) argspec))) (defalias generic-func `(lambda ,argspec ,(interactive-form specific-func) ;; (interactive ...) or nil (let (;; Get the format-specific function for the current ;; buffer. We must do this every time the generic ;; function is called because the result depends on ;; the buffer-local variable `subed--subtitle-format'. (specific-func (subed--get-specific-func ,func-suffix)) ;; Turn the list of variable names into a list of ;; corresponding values. (argvals (mapcar 'eval ',argvars))) (apply specific-func argvals))) (documentation specific-func t))))))) ;;;###autoload (define-derived-mode subed-mode text-mode "subed" "Major mode for editing subtitles. subed uses the following terminology when it comes to changes in subtitles' timestamps: Adjust - Increase or decrease start or stop time of a subtitle Move - Increase or decrease start and stop time of a subtitle by the same amount Shift - Increase or decrease start and stop time of the current and all following subtitles by the same amount Key bindings: \\{subed-mode-map}" :group 'subed (subed--init) (add-hook 'post-command-hook #'subed--post-command-handler :append :local) (add-hook 'before-save-hook #'subed-sort :append :local) (add-hook 'after-save-hook #'subed-mpv-reload-subtitles :append :local) (add-hook 'kill-buffer-hook #'subed-mpv-kill :append :local) (add-hook 'kill-emacs-hook #'subed-mpv-kill :append :local) (when subed-auto-find-video (let ((video-file (subed-guess-video-file))) (when video-file (subed-debug "Auto-discovered video file: %s" video-file) (condition-case err (subed-mpv-find-video video-file) (error (message "%s -- Set subed-auto-find-video to nil to avoid this error." (car (cdr err)))))))) (subed-enable-pause-while-typing :quiet) (subed-enable-sync-point-to-player :quiet) (subed-enable-sync-player-to-point :quiet) (subed-enable-replay-adjusted-subtitle :quiet) (subed-enable-loop-over-current-subtitle :quiet)) ;; Internally, supported formats are listed in `subed--init-alist', which ;; associates file extensions with format-specific init methods (e.g. "srt" -> ;; subed-srt--init). Here we map each file extension as a regexp to ;; `subed-mode-enable', which will call the format-specific init method and do ;; generic init stuff. ;;;###autoload (dolist (item subed--init-alist) (let ((file-ext-regex (car item))) (add-to-list 'auto-mode-alist (cons (concat "\\." file-ext-regex "\\'") 'subed-mode)))) (provide 'subed) ;;; subed.el ends here subed-master/tests/000077500000000000000000000000001401667552300146245ustar00rootroot00000000000000subed-master/tests/test-subed-common.el000066400000000000000000003475101401667552300205250ustar00rootroot00000000000000;; -*- eval: (buttercup-minor-mode) -*- (add-to-list 'load-path "./subed") (require 'subed) (require 'subed-srt) (defvar mock-srt-data "1 00:01:01,000 --> 00:01:05,123 Foo. 2 00:02:02,234 --> 00:02:10,345 Bar. 3 00:03:03,45 --> 00:03:15,5 Baz. ") (defmacro with-temp-srt-buffer (&rest body) "Call `subed-srt--init' in temporary buffer before running BODY." (declare (indent defun)) `(with-temp-buffer ;; subed--init uses file extension to detect format (setq buffer-file-name "test.srt") (subed--init) (progn ,@body))) (describe "Iterating over subtitles" (it "without providing beginning and end." (with-temp-srt-buffer (insert mock-srt-data) (subed-jump-to-subtitle-time-stop 1) (subed-for-each-subtitle nil nil nil (expect (looking-at "^[0-9]$") :to-be t) (forward-line 2) (kill-line) (insert "Hello.")) (expect (subed-subtitle-text 1) :to-equal "Hello.") (expect (subed-subtitle-text 2) :to-equal "Bar.") (expect (subed-subtitle-text 3) :to-equal "Baz.") (expect (point) :to-equal 20) (subed-jump-to-subtitle-time-stop 2) (subed-for-each-subtitle nil nil nil (expect (looking-at "^[0-9]$") :to-be t) (forward-line 2) (kill-line) (insert "HEllo.")) (expect (subed-subtitle-text 1) :to-equal "Hello.") (expect (subed-subtitle-text 2) :to-equal "HEllo.") (expect (subed-subtitle-text 3) :to-equal "Baz.") (expect (point) :to-equal 60) (subed-jump-to-subtitle-time-stop 3) (subed-for-each-subtitle nil nil nil (expect (looking-at "^[0-9]$") :to-be t) (forward-line 2) (kill-line) (insert "HELlo.")) (expect (subed-subtitle-text 1) :to-equal "Hello.") (expect (subed-subtitle-text 2) :to-equal "HEllo.") (expect (subed-subtitle-text 3) :to-equal "HELlo.") (expect (point) :to-equal 99))) (describe "providing only the beginning" (it "forwards." (with-temp-srt-buffer (insert mock-srt-data) (subed-jump-to-subtitle-time-start 1) (expect (point) :to-equal 3) (let ((new-texts (list "A" "B" "C"))) (subed-for-each-subtitle 71 nil nil (expect (looking-at "^[0-9]$") :to-be t) (forward-line 2) (kill-line) (insert (pop new-texts)))) (expect (subed-subtitle-text 1) :to-equal "Foo.") (expect (subed-subtitle-text 2) :to-equal "A") (expect (subed-subtitle-text 3) :to-equal "B") (expect (point) :to-equal 3))) (it "backwards." (with-temp-srt-buffer (insert mock-srt-data) (subed-jump-to-subtitle-time-stop 3) (expect (point) :to-equal 95) (let ((new-texts (list "A" "B" "C"))) (subed-for-each-subtitle 75 nil :reverse (expect (looking-at "^[0-9]$") :to-be t) (forward-line 2) (kill-line) (insert (pop new-texts)))) (expect (subed-subtitle-text 1) :to-equal "Foo.") (expect (subed-subtitle-text 2) :to-equal "B") (expect (subed-subtitle-text 3) :to-equal "A") (expect (point) :to-equal 92))) ) (describe "providing beginning and end," (describe "excluding subtitles above" (it "forwards." (with-temp-srt-buffer (insert mock-srt-data) (subed-jump-to-subtitle-time-stop 1) (expect (point) :to-equal 20) (let ((new-texts (list "A" "B" "C"))) (subed-for-each-subtitle 71 79 nil (expect (looking-at "^[0-9]$") :to-be t) (forward-line 2) (kill-line) (insert (pop new-texts)))) (expect (subed-subtitle-text 1) :to-equal "Foo.") (expect (subed-subtitle-text 2) :to-equal "A") (expect (subed-subtitle-text 3) :to-equal "B") (expect (point) :to-equal 20))) (it "backwards." (with-temp-srt-buffer (insert mock-srt-data) (subed-jump-to-subtitle-time-start 3) (expect (point) :to-equal 79) (let ((new-texts (list "A" "B" "C"))) (subed-for-each-subtitle 39 77 :reverse (expect (looking-at "^[0-9]$") :to-be t) (forward-line 2) (kill-line) (insert (pop new-texts)))) (expect (subed-subtitle-text 1) :to-equal "Foo.") (expect (subed-subtitle-text 2) :to-equal "B") (expect (subed-subtitle-text 3) :to-equal "A") (expect (point) :to-equal 76))) ) (describe "excluding subtitles below" (it "forwards." (with-temp-srt-buffer (insert mock-srt-data) (subed-jump-to-subtitle-text 3) (expect (point) :to-equal 106) (let ((new-texts (list "A" "B" "C"))) (subed-for-each-subtitle 5 76 nil (expect (looking-at "^[0-9]$") :to-be t) (forward-line 2) (kill-line) (insert (pop new-texts)))) (expect (subed-subtitle-text 1) :to-equal "A") (expect (subed-subtitle-text 2) :to-equal "B") (expect (subed-subtitle-text 3) :to-equal "Baz.") (expect (point) :to-equal 100))) (it "backwards." (with-temp-srt-buffer (insert mock-srt-data) (subed-jump-to-subtitle-time-stop 2) (expect (point) :to-equal 58) (let ((new-texts (list "A" "B" "C"))) (subed-for-each-subtitle 20 76 :reverse (expect (looking-at "^[0-9]$") :to-be t) (forward-line 2) (kill-line) (insert (pop new-texts)))) (expect (subed-subtitle-text 1) :to-equal "B") (expect (subed-subtitle-text 2) :to-equal "A") (expect (subed-subtitle-text 3) :to-equal "Baz.") (expect (point) :to-equal 55))) ) ) ) (describe "Adjusting subtitle start/stop time" :var (subed-subtitle-time-adjusted-hook) (it "runs the appropriate hook." (let ((foo (setf (symbol-function 'foo) (lambda (msecs) ())))) (spy-on 'foo) (with-temp-srt-buffer (add-hook 'subed-subtitle-time-adjusted-hook 'foo) (insert mock-srt-data) (subed-jump-to-subtitle-id 1) (expect (subed-adjust-subtitle-time-start 100) :to-equal 100) (expect 'foo :to-have-been-called-with 61100) (expect 'foo :to-have-been-called-times 1) (expect (subed-adjust-subtitle-time-stop 123) :to-equal 123) (expect 'foo :to-have-been-called-with 61100) (expect 'foo :to-have-been-called-times 2) (subed-jump-to-subtitle-id 2) (expect (subed-adjust-subtitle-time-start 6) :to-equal 6) (expect 'foo :to-have-been-called-with 122240) (expect 'foo :to-have-been-called-times 3) (expect (subed-adjust-subtitle-time-stop 123) :to-equal 123) (expect 'foo :to-have-been-called-with 122240) (expect 'foo :to-have-been-called-times 4)))) (it "adjusts the start/stop time." (with-temp-srt-buffer (insert mock-srt-data) (subed-jump-to-subtitle-id 1) (expect (subed-adjust-subtitle-time-start 100) :to-equal 100) (expect (save-excursion (subed-jump-to-subtitle-time-start) (thing-at-point 'line)) :to-equal "00:01:01,100 --> 00:01:05,123\n") (expect (subed-adjust-subtitle-time-start -200) :to-equal -200) (expect (save-excursion (subed-jump-to-subtitle-time-start) (thing-at-point 'line)) :to-equal "00:01:00,900 --> 00:01:05,123\n") (expect (subed-adjust-subtitle-time-stop 200) :to-equal 200) (expect (save-excursion (subed-jump-to-subtitle-time-start) (thing-at-point 'line)) :to-equal "00:01:00,900 --> 00:01:05,323\n") (expect (subed-adjust-subtitle-time-stop -100) :to-equal -100) (expect (save-excursion (subed-jump-to-subtitle-time-start) (thing-at-point 'line)) :to-equal "00:01:00,900 --> 00:01:05,223\n"))) (describe "enforces boundaries" (describe "when decreasing start time" (it "of the first subtitle." (with-temp-srt-buffer (insert (concat "1\n" "00:00:01,000 --> 00:00:02,000\n" "Foo.\n")) (expect (subed-adjust-subtitle-time-start -999) :to-be -999) (expect (subed-subtitle-msecs-start) :to-be 1) (expect (subed-adjust-subtitle-time-start -1) :to-be -1) (expect (subed-subtitle-msecs-start) :to-be 0) (expect (subed-adjust-subtitle-time-start -1) :to-be nil) (expect (subed-subtitle-msecs-start) :to-be 0))) (it "of a non-first subtitle." (with-temp-srt-buffer (insert (concat "1\n" "00:00:01,000 --> 00:00:02,000\n" "Foo.\n\n" "2\n" "00:00:03,000 --> 00:00:04,000\n" "Bar.\n\n")) (subed-jump-to-subtitle-id 2) (expect (subed-adjust-subtitle-time-start -899) :to-be -899) (expect (subed-subtitle-msecs-start) :to-be 2101) (expect (subed-adjust-subtitle-time-start -1) :to-be -1) (expect (subed-subtitle-msecs-start) :to-be 2100) (expect (subed-adjust-subtitle-time-start -1) :to-be nil) (expect (subed-subtitle-msecs-start) :to-be 2100))) ) (it "when increasing start time." (with-temp-srt-buffer (insert (concat "1\n" "00:00:01,000 --> 00:00:02,000\n" "Foo.\n\n" "2\n" "00:00:03,000 --> 00:00:04,000\n" "Bar.\n\n")) (subed-jump-to-subtitle-id 2) (expect (subed-adjust-subtitle-time-start 999) :to-be 999) (expect (subed-subtitle-msecs-start) :to-be 3999) (expect (subed-adjust-subtitle-time-start 1) :to-be 1) (expect (subed-subtitle-msecs-start) :to-be 4000) (expect (subed-adjust-subtitle-time-start 1) :to-be nil) (expect (subed-subtitle-msecs-start) :to-be 4000))) (it "when decreasing stop time." (with-temp-srt-buffer (insert (concat "1\n" "00:00:01,000 --> 00:00:02,000\n" "Foo.\n\n" "2\n" "00:00:03,000 --> 00:00:04,000\n" "Bar.\n\n")) (subed-jump-to-subtitle-id 2) (expect (subed-adjust-subtitle-time-stop -999) :to-be -999) (expect (subed-subtitle-msecs-stop) :to-be 3001) (expect (subed-adjust-subtitle-time-stop -1) :to-be -1) (expect (subed-subtitle-msecs-stop) :to-be 3000) (expect (subed-adjust-subtitle-time-stop -1) :to-be nil) (expect (subed-subtitle-msecs-stop) :to-be 3000))) (describe "when increasing stop time" (it "of the last subtitle." (with-temp-srt-buffer (insert (concat "1\n" "00:00:01,000 --> 00:00:02,000\n" "Foo.\n\n" "2\n" "00:00:03,000 --> 00:00:04,000\n" "Bar.\n\n")) (subed-jump-to-subtitle-id 2) (expect (subed-adjust-subtitle-time-stop 1000000):to-be 1000000) (expect (subed-subtitle-msecs-stop) :to-be 1004000))) (it "of a non-last subtitle." (with-temp-srt-buffer (insert (concat "1\n" "00:00:01,000 --> 00:00:02,000\n" "Foo.\n\n" "2\n" "00:00:03,000 --> 00:00:04,000\n" "Bar.\n\n")) (subed-jump-to-subtitle-id 1) (expect (subed-adjust-subtitle-time-stop 899) :to-be 899) (expect (subed-subtitle-msecs-stop) :to-be 2899) (expect (subed-adjust-subtitle-time-stop 1) :to-be 1) (expect (subed-subtitle-msecs-stop) :to-be 2900) (expect (subed-adjust-subtitle-time-stop 1) :to-be nil) (expect (subed-subtitle-msecs-stop) :to-be 2900))) ) (it "without undershooting the target time." (with-temp-srt-buffer (insert (concat "1\n" "00:00:01,000 --> 00:00:02,000\n" "Foo.\n\n" "2\n" "00:00:02,000 --> 00:00:03,000\n" "Bar.\n")) (subed-jump-to-subtitle-id 1) (expect (subed-adjust-subtitle-time-stop 1) :to-be nil) (expect (subed-subtitle-msecs-stop) :to-equal 2000))) (it "without overshooting the target time." (with-temp-srt-buffer (insert (concat "1\n" "00:00:01,000 --> 00:00:02,000\n" "Foo.\n\n" "2\n" "00:00:02,000 --> 00:00:03,000\n" "Bar.\n")) (subed-jump-to-subtitle-id 2) (expect (subed-adjust-subtitle-time-start -1) :to-be nil) (expect (subed-subtitle-msecs-start) :to-equal 2000))) ) (describe "ignores negative duration if the first argument is truthy" (it "when adjusting start time." (with-temp-srt-buffer (insert (concat "1\n" "00:00:01,000 --> 00:00:02,000\n" "Foo.\n\n")) (expect (subed-adjust-subtitle-time-start 2000 t) :to-be 2000) (expect (subed-subtitle-msecs-start) :to-be 3000) (expect (subed-subtitle-msecs-stop) :to-be 2000) (expect (subed-adjust-subtitle-time-start -500 t) :to-be -500) (expect (subed-subtitle-msecs-start) :to-be 2500) (expect (subed-subtitle-msecs-stop) :to-be 2000))) (it "when adjusting stop time." (with-temp-srt-buffer (insert (concat "1\n" "00:00:01,000 --> 00:00:02,000\n" "Foo.\n\n")) (expect (subed-adjust-subtitle-time-stop -1500 t) :to-be -1500) (expect (subed-subtitle-msecs-stop) :to-be 500) (expect (subed-subtitle-msecs-start) :to-be 1000) (expect (subed-adjust-subtitle-time-stop 200 t) :to-be 200) (expect (subed-subtitle-msecs-stop) :to-be 700) (expect (subed-subtitle-msecs-start) :to-be 1000))) ) (describe "ignores subtitle spacing if the second argument is truthy" (it "when adjusting start time." (with-temp-srt-buffer (insert (concat "1\n" "00:00:01,000 --> 00:00:02,000\n" "Foo.\n\n" "2\n" "00:00:02,200 --> 00:00:03,000\n" "Bar.\n")) (subed-jump-to-subtitle-id 2) (expect (subed-adjust-subtitle-time-start -150 nil t) :to-be -150) (expect (subed-subtitle-msecs-start 2) :to-be 2050) (expect (subed-subtitle-msecs-stop 1) :to-be 2000) (expect (subed-adjust-subtitle-time-start -51 nil t) :to-be -51) (expect (subed-subtitle-msecs-start 2) :to-be 1999) (expect (subed-subtitle-msecs-stop 1) :to-be 2000))) (it "when adjusting stop time." (with-temp-srt-buffer (insert (concat "1\n" "00:00:01,000 --> 00:00:02,000\n" "Foo.\n\n" "2\n" "00:00:02,200 --> 00:00:03,000\n" "Bar.\n")) (subed-jump-to-subtitle-id 1) (expect (subed-adjust-subtitle-time-stop 150 nil t) :to-be 150) (expect (subed-subtitle-msecs-stop 1) :to-be 2150) (expect (subed-subtitle-msecs-start 2) :to-be 2200) (expect (subed-adjust-subtitle-time-stop 51 nil t) :to-be 51) (expect (subed-subtitle-msecs-stop 1) :to-be 2201) (expect (subed-subtitle-msecs-start 2) :to-be 2200))) ) (describe "ignores negative duration if subed-enforce-time-boundaries is falsy" (it "when adjusting start time." (with-temp-srt-buffer (setq-local subed-enforce-time-boundaries nil) (insert (concat "1\n" "00:00:01,000 --> 00:00:02,000\n" "Foo.\n\n")) (expect (subed-adjust-subtitle-time-start 2000) :to-be 2000) (expect (subed-subtitle-msecs-start) :to-be 3000) (expect (subed-subtitle-msecs-stop) :to-be 2000) (expect (subed-adjust-subtitle-time-start -500) :to-be -500) (expect (subed-subtitle-msecs-start) :to-be 2500) (expect (subed-subtitle-msecs-stop) :to-be 2000))) (it "when adjusting stop time." (with-temp-srt-buffer (setq-local subed-enforce-time-boundaries nil) (insert (concat "1\n" "00:00:01,000 --> 00:00:02,000\n" "Foo.\n\n")) (expect (subed-adjust-subtitle-time-stop -1500) :to-be -1500) (expect (subed-subtitle-msecs-stop) :to-be 500) (expect (subed-subtitle-msecs-start) :to-be 1000) (expect (subed-adjust-subtitle-time-stop 200) :to-be 200) (expect (subed-subtitle-msecs-stop) :to-be 700) (expect (subed-subtitle-msecs-start) :to-be 1000))) ) (describe "ignores subtitle spacing if subed-enforce-time-boundaries is falsy" (it "when adjusting start time." (with-temp-srt-buffer (setq-local subed-enforce-time-boundaries nil) (insert (concat "1\n" "00:00:01,000 --> 00:00:02,000\n" "Foo.\n\n" "2\n" "00:00:02,200 --> 00:00:03,000\n" "Bar.\n")) (subed-jump-to-subtitle-id 2) (expect (subed-adjust-subtitle-time-start -150) :to-be -150) (expect (subed-subtitle-msecs-start 2) :to-be 2050) (expect (subed-subtitle-msecs-stop 1) :to-be 2000) (expect (subed-adjust-subtitle-time-start -51) :to-be -51) (expect (subed-subtitle-msecs-start 2) :to-be 1999) (expect (subed-subtitle-msecs-stop 1) :to-be 2000))) (it "when adjusting stop time." (with-temp-srt-buffer (setq-local subed-enforce-time-boundaries nil) (insert (concat "1\n" "00:00:01,000 --> 00:00:02,000\n" "Foo.\n\n" "2\n" "00:00:02,200 --> 00:00:03,000\n" "Bar.\n")) (subed-jump-to-subtitle-id 1) (expect (subed-adjust-subtitle-time-stop 150) :to-be 150) (expect (subed-subtitle-msecs-stop 1) :to-be 2150) (expect (subed-subtitle-msecs-start 2) :to-be 2200) (expect (subed-adjust-subtitle-time-stop 51) :to-be 51) (expect (subed-subtitle-msecs-stop 1) :to-be 2201) (expect (subed-subtitle-msecs-start 2) :to-be 2200))) ) (describe "prevents negative time even if subed-enforce-time-boundaries is falsy" (it "when adjusting start time." (with-temp-srt-buffer (setq-local subed-enforce-time-boundaries nil) (insert (concat "1\n" "00:00:01,000 --> 00:00:02,000\n" "Foo.\n\n")) (expect (subed-adjust-subtitle-time-start -1000) :to-be -1000) (expect (subed-subtitle-msecs-start) :to-be 0) (expect (subed-adjust-subtitle-time-start -1) :to-be nil) (expect (subed-subtitle-msecs-start) :to-be 0))) (it "when adjusting stop time." (with-temp-srt-buffer (setq-local subed-enforce-time-boundaries nil) (insert (concat "1\n" "00:00:01,000 --> 00:00:02,000\n" "Foo.\n\n")) (expect (subed-adjust-subtitle-time-stop -2000) :to-be -2000) (expect (subed-subtitle-msecs-stop) :to-be 0) (expect (subed-adjust-subtitle-time-stop -1) :to-be nil) (expect (subed-subtitle-msecs-stop) :to-be 0))) ) (it "does nothing if no timestamp can be found." (with-temp-srt-buffer (insert "foo") (goto-char (point-min)) (expect (subed-adjust-subtitle-time-start 123) :to-be nil) (expect (buffer-string) :to-equal "foo") (expect (subed-adjust-subtitle-time-start -123) :to-be nil) (expect (buffer-string) :to-equal "foo"))) ) (describe "Copy start/stop time from player" :var (subed-mpv-playback-position) (it "does nothing in an empty buffer." (with-temp-srt-buffer (let ((subed-mpv-playback-position 12345)) (expect (subed-copy-player-pos-to-start-time) :to-be nil) (expect (subed-copy-player-pos-to-stop-time) :to-be nil) (expect (buffer-string) :to-equal "")))) (it "does nothing if player position is unknown." (with-temp-srt-buffer (insert (concat "1\n" "00:00:01,000 --> 00:00:02,000\n" "Foo.\n")) (let ((subed-mpv-playback-position nil)) (expect (subed-copy-player-pos-to-start-time) :to-be nil) (expect (subed-copy-player-pos-to-stop-time) :to-be nil) (expect (buffer-string) :to-equal (concat "1\n" "00:00:01,000 --> 00:00:02,000\n" "Foo.\n"))))) (it "sets start/stop time when possible." (with-temp-srt-buffer (insert (concat "1\n" "00:00:01,000 --> 00:00:02,000\n" "Foo.\n")) (let ((subed-mpv-playback-position (+ 60000 2000 123))) (expect (subed-copy-player-pos-to-start-time) :to-be subed-mpv-playback-position) (expect (buffer-string) :to-equal (concat "1\n" "00:01:02,123 --> 00:00:02,000\n" "Foo.\n"))) (let ((subed-mpv-playback-position (+ 60000 5000 456))) (expect (subed-copy-player-pos-to-stop-time) :to-be subed-mpv-playback-position) (expect (buffer-string) :to-equal (concat "1\n" "00:01:02,123 --> 00:01:05,456\n" "Foo.\n"))))) (it "runs the appropriate hook." (with-temp-srt-buffer (insert (concat "1\n" "00:00:01,000 --> 00:00:02,000\n" "Foo.\n")) (let ((foo (setf (symbol-function 'foo) (lambda (msecs) ())))) (spy-on 'foo) (add-hook 'subed-subtitle-time-adjusted-hook 'foo) (let ((subed-mpv-playback-position (+ 60000 2000 123))) (expect (subed-copy-player-pos-to-start-time) :to-be subed-mpv-playback-position) (expect (buffer-string) :to-equal (concat "1\n" "00:01:02,123 --> 00:00:02,000\n" "Foo.\n")) (expect (spy-calls-args-for 'foo 0) :to-equal `(,(+ 60000 2000 123))) (expect (spy-calls-count 'foo) :to-equal 1))) (let ((subed-mpv-playback-position (+ 60000 5000 456))) (expect (subed-copy-player-pos-to-stop-time) :to-be subed-mpv-playback-position) (expect (buffer-string) :to-equal (concat "1\n" "00:01:02,123 --> 00:01:05,456\n" "Foo.\n")) (expect (spy-calls-args-for 'foo 0) :to-equal `(,(+ 60000 2000 123))) (expect (spy-calls-count 'foo) :to-equal 2))) (remove-hook 'subed-subtitle-time-adjusted-hook 'foo)) ) (describe "Moving" (it "adjusts start and stop time by the same amount." (with-temp-srt-buffer (insert (concat "1\n" "00:00:01,000 --> 00:00:02,000\n" "Foo.\n")) (let ((orig-point (subed-jump-to-subtitle-text 1))) (subed-move-subtitle-forward 100) (expect (subed-subtitle-msecs-start) :to-equal 1100) (expect (subed-subtitle-msecs-stop) :to-equal 2100) (subed-move-subtitle-backward 200) (expect (subed-subtitle-msecs-start) :to-equal 900) (expect (subed-subtitle-msecs-stop) :to-equal 1900) (expect (point) :to-equal orig-point)))) (it "adjusts start and stop time by the same amount when bumping into next subtitle." (with-temp-srt-buffer (insert (concat "1\n" "00:00:01,000 --> 00:00:01,600\n" "Foo.\n\n" "2\n" "00:00:02,000 --> 00:00:03,000\n" "Bar.\n")) (let ((orig-point (subed-jump-to-subtitle-id 1))) (subed-move-subtitle-forward 1000) (expect (subed-subtitle-msecs-start) :to-equal 1300) (expect (subed-subtitle-msecs-stop) :to-equal 1900) (expect (point) :to-equal orig-point)))) (it "adjusts start and stop time by the same amount when bumping into previous subtitle." (with-temp-srt-buffer (insert (concat "1\n" "00:00:01,000 --> 00:00:01,600\n" "Foo.\n\n" "2\n" "00:00:02,000 --> 00:00:03,000\n" "Bar.\n")) (let ((orig-point (subed-jump-to-subtitle-id 2))) (subed-move-subtitle-backward 1000) (expect (subed-subtitle-msecs-start) :to-equal 1700) (expect (subed-subtitle-msecs-stop) :to-equal 2700) (expect (point) :to-equal orig-point)))) (it "does not adjust anything if subtitle cannot be moved forward at all." (with-temp-srt-buffer (insert (concat "1\n" "00:00:01,000 --> 00:00:02,000\n" "Foo.\n\n" "2\n" "00:00:02,000 --> 00:00:03,000\n" "Bar.\n")) (let ((orig-point (subed-jump-to-subtitle-id 1))) (subed-move-subtitle-forward 1) (expect (subed-subtitle-msecs-start 1) :to-equal 1000) (expect (subed-subtitle-msecs-stop 1) :to-equal 2000) (expect (subed-subtitle-msecs-start 2) :to-equal 2000) (expect (subed-subtitle-msecs-stop 2) :to-equal 3000) (expect (point) :to-equal orig-point)))) (it "does not adjust anything if subtitle cannot be moved backward at all." (with-temp-srt-buffer (insert (concat "1\n" "00:00:01,000 --> 00:00:02,000\n" "Foo.\n\n" "2\n" "00:00:02,000 --> 00:00:03,000\n" "Bar.\n")) (let ((orig-point (subed-jump-to-subtitle-id 2))) (subed-move-subtitle-backward 1) (expect (subed-subtitle-msecs-start 1) :to-equal 1000) (expect (subed-subtitle-msecs-stop 1) :to-equal 2000) (expect (subed-subtitle-msecs-start 2) :to-equal 2000) (expect (subed-subtitle-msecs-stop 2) :to-equal 3000) (expect (point) :to-equal orig-point)))) (describe "adjusts subtitles in the active region," (it "excluding the first subtitle." (with-temp-srt-buffer (insert (concat "1\n" "00:00:01,000 --> 00:00:02,000\n" "Foo.\n\n" "2\n" "00:00:03,000 --> 00:00:04,000\n" "Bar.\n\n" "3\n" "00:00:05,000 --> 00:00:06,000\n" "Baz.\n")) (setq mark-active t) (spy-on 'region-beginning :and-return-value (subed-jump-to-subtitle-text 2)) (spy-on 'region-end :and-return-value (subed-jump-to-subtitle-time-start 3)) (let ((orig-point (subed-jump-to-subtitle-text 2))) (subed-move-subtitle-forward 100) (expect (subed-subtitle-msecs-start 1) :to-equal 1000) (expect (subed-subtitle-msecs-stop 1) :to-equal 2000) (expect (subed-subtitle-msecs-start 2) :to-equal 3100) (expect (subed-subtitle-msecs-stop 2) :to-equal 4100) (expect (subed-subtitle-msecs-start 3) :to-equal 5100) (expect (subed-subtitle-msecs-stop 3) :to-equal 6100) (expect (point) :to-equal orig-point) (subed-move-subtitle-backward 200) (expect (subed-subtitle-msecs-start 1) :to-equal 1000) (expect (subed-subtitle-msecs-stop 1) :to-equal 2000) (expect (subed-subtitle-msecs-start 2) :to-equal 2900) (expect (subed-subtitle-msecs-stop 2) :to-equal 3900) (expect (subed-subtitle-msecs-start 3) :to-equal 4900) (expect (subed-subtitle-msecs-stop 3) :to-equal 5900) (expect (point) :to-equal orig-point)))) (it "excluding the last subtitle." (with-temp-srt-buffer (insert (concat "1\n" "00:00:01,000 --> 00:00:02,000\n" "Foo.\n\n" "2\n" "00:00:03,000 --> 00:00:04,000\n" "Bar.\n\n" "3\n" "00:00:05,000 --> 00:00:06,000\n" "Baz.\n")) (setq mark-active t) (spy-on 'region-beginning :and-return-value (subed-jump-to-subtitle-text 1)) (spy-on 'region-end :and-return-value (subed-jump-to-subtitle-time-stop 2)) (let ((orig-point (subed-jump-to-subtitle-time-stop 3))) (subed-move-subtitle-forward 500) (expect (subed-subtitle-msecs-start 1) :to-equal 1500) (expect (subed-subtitle-msecs-stop 1) :to-equal 2500) (expect (subed-subtitle-msecs-start 2) :to-equal 3500) (expect (subed-subtitle-msecs-stop 2) :to-equal 4500) (expect (subed-subtitle-msecs-start 3) :to-equal 5000) (expect (subed-subtitle-msecs-stop 3) :to-equal 6000) (expect (point) :to-equal orig-point) (subed-move-subtitle-backward 300) (expect (subed-subtitle-msecs-start 1) :to-equal 1200) (expect (subed-subtitle-msecs-stop 1) :to-equal 2200) (expect (subed-subtitle-msecs-start 2) :to-equal 3200) (expect (subed-subtitle-msecs-stop 2) :to-equal 4200) (expect (subed-subtitle-msecs-start 3) :to-equal 5000) (expect (subed-subtitle-msecs-stop 3) :to-equal 6000) (expect (point) :to-equal orig-point)))) (describe "not changing spacing between subtitles" (it "when moving forward." (with-temp-srt-buffer (insert (concat "1\n" "00:00:01,000 --> 00:00:02,000\n" "Foo.\n\n" "2\n" "00:00:10,000 --> 00:00:11,000\n" "Bar.\n\n" "3\n" "00:00:12,000 --> 00:00:13,000\n" "Baz.\n")) (setq mark-active t) (spy-on 'region-beginning :and-return-value (subed-jump-to-subtitle-id 1)) (spy-on 'region-end :and-return-value (subed-jump-to-subtitle-text 2)) (let ((orig-point (subed-jump-to-subtitle-time-start 1))) (subed-move-subtitle-forward 2000) (expect (subed-subtitle-msecs-start 1) :to-equal 1900) (expect (subed-subtitle-msecs-stop 1) :to-equal 2900) (expect (subed-subtitle-msecs-start 2) :to-equal 10900) (expect (subed-subtitle-msecs-stop 2) :to-equal 11900) (expect (subed-subtitle-msecs-start 3) :to-equal 12000) (expect (subed-subtitle-msecs-stop 3) :to-equal 13000) (expect (point) :to-equal orig-point)))) (it "when moving backward." (with-temp-srt-buffer (insert (concat "1\n" "00:00:01,000 --> 00:00:02,000\n" "Foo.\n\n" "2\n" "00:00:3,000 --> 00:00:4,000\n" "Bar.\n\n" "3\n" "00:00:10,000 --> 00:00:11,000\n" "Baz.\n")) (setq mark-active t) (spy-on 'region-beginning :and-return-value (subed-jump-to-subtitle-id 2)) (spy-on 'region-end :and-return-value (subed-jump-to-subtitle-text 3)) (let ((orig-point (subed-jump-to-subtitle-time-start 2))) (subed-move-subtitle-backward 10000) (expect (subed-subtitle-msecs-start 1) :to-equal 1000) (expect (subed-subtitle-msecs-stop 1) :to-equal 2000) (expect (subed-subtitle-msecs-start 2) :to-equal 2100) (expect (subed-subtitle-msecs-stop 2) :to-equal 3100) (expect (subed-subtitle-msecs-start 3) :to-equal 9100) (expect (subed-subtitle-msecs-stop 3) :to-equal 10100) (expect (point) :to-equal orig-point)))) ) ) (describe "unless there is no space left" (it "when moving forward." (with-temp-srt-buffer (insert (concat "1\n" "00:00:01,000 --> 00:00:02,000\n" "Foo.\n\n" "2\n" "00:00:10,000 --> 00:00:11,000\n" "Bar.\n\n" "3\n" "00:00:11,000 --> 00:00:12,000\n" "Baz.\n")) (setq mark-active t) (spy-on 'region-beginning :and-return-value (subed-jump-to-subtitle-id 1)) (spy-on 'region-end :and-return-value (subed-jump-to-subtitle-text 2)) (let ((orig-point (subed-jump-to-subtitle-text 1))) (subed-move-subtitle-forward 1) (expect (subed-subtitle-msecs-start 1) :to-equal 1000) (expect (subed-subtitle-msecs-stop 1) :to-equal 2000) (expect (subed-subtitle-msecs-start 2) :to-equal 10000) (expect (subed-subtitle-msecs-stop 2) :to-equal 11000) (expect (subed-subtitle-msecs-start 3) :to-equal 11000) (expect (subed-subtitle-msecs-stop 3) :to-equal 12000) (expect (point) :to-equal orig-point)))) (it "when moving backward." (with-temp-srt-buffer (insert (concat "1\n" "00:00:01,000 --> 00:00:02,000\n" "Foo.\n\n" "2\n" "00:00:02,000 --> 00:00:03,000\n" "Bar.\n\n" "3\n" "00:00:11,000 --> 00:00:12,000\n" "Baz.\n")) (setq mark-active t) (spy-on 'region-beginning :and-return-value (subed-jump-to-subtitle-id 2)) (spy-on 'region-end :and-return-value (subed-jump-to-subtitle-text 3)) (let ((orig-point (subed-jump-to-subtitle-id 3))) (subed-move-subtitle-backward 1) (expect (subed-subtitle-msecs-start 1) :to-equal 1000) (expect (subed-subtitle-msecs-stop 1) :to-equal 2000) (expect (subed-subtitle-msecs-start 2) :to-equal 2000) (expect (subed-subtitle-msecs-stop 2) :to-equal 3000) (expect (subed-subtitle-msecs-start 3) :to-equal 11000) (expect (subed-subtitle-msecs-stop 3) :to-equal 12000) (expect (point) :to-equal orig-point)))) ) (describe "ignoring spacing for non-leading subtitles" (it "when moving forward." (with-temp-srt-buffer (insert (concat "1\n" "00:00:00,000 --> 00:00:01,000\n" "Foo.\n\n" "2\n" "00:00:01,050 --> 00:00:02,000\n" "Bar.\n\n" "3\n" "00:00:05,000 --> 00:00:6,000\n" "Baz.\n")) (setq mark-active t) (spy-on 'region-beginning :and-return-value (subed-jump-to-subtitle-id 1)) (spy-on 'region-end :and-return-value (subed-jump-to-subtitle-text 2)) (let ((orig-point (subed-jump-to-subtitle-time-start 3))) (subed-move-subtitle-forward 1000) (expect (subed-subtitle-msecs-start 1) :to-equal 1000) (expect (subed-subtitle-msecs-stop 1) :to-equal 2000) (expect (subed-subtitle-msecs-start 2) :to-equal 2050) (expect (subed-subtitle-msecs-stop 2) :to-equal 3000) (expect (subed-subtitle-msecs-start 3) :to-equal 5000) (expect (subed-subtitle-msecs-stop 3) :to-equal 6000) (expect (point) :to-equal orig-point)))) (it "when moving backward." (with-temp-srt-buffer (insert (concat "1\n" "00:00:01,000 --> 00:00:02,000\n" "Foo.\n\n" "2\n" "00:00:04,000 --> 00:00:05,000\n" "Bar.\n\n" "3\n" "00:00:05,000 --> 00:00:05,000\n" "Baz.\n")) (setq mark-active t) (spy-on 'region-beginning :and-return-value (subed-jump-to-subtitle-id 2)) (spy-on 'region-end :and-return-value (subed-jump-to-subtitle-text 3)) (let ((orig-point (subed-jump-to-subtitle-time-stop 1))) (subed-move-subtitle-backward 1000) (expect (subed-subtitle-msecs-start 1) :to-equal 1000) (expect (subed-subtitle-msecs-stop 1) :to-equal 2000) (expect (subed-subtitle-msecs-start 2) :to-equal 3000) (expect (subed-subtitle-msecs-stop 2) :to-equal 4000) (expect (subed-subtitle-msecs-start 3) :to-equal 4000) (expect (subed-subtitle-msecs-stop 3) :to-equal 4000) (expect (point) :to-equal orig-point)))) ) (describe "ignoring overlapping subtitles" (it "when moving forward." (with-temp-srt-buffer (insert (concat "1\n" "00:00:01,000 --> 00:00:01,500\n" "Foo.\n\n" "2\n" "00:00:01,300 --> 00:00:02,000\n" "Bar.\n\n" "3\n" "00:00:05,000 --> 00:00:6,000\n" "Baz.\n")) (setq mark-active t) (spy-on 'region-beginning :and-return-value (subed-jump-to-subtitle-id 1)) (spy-on 'region-end :and-return-value (subed-jump-to-subtitle-text 2)) (let ((orig-point (subed-jump-to-subtitle-text 2))) (subed-move-subtitle-forward 1000) (expect (subed-subtitle-msecs-start 1) :to-equal 2000) (expect (subed-subtitle-msecs-stop 1) :to-equal 2500) (expect (subed-subtitle-msecs-start 2) :to-equal 2300) (expect (subed-subtitle-msecs-stop 2) :to-equal 3000) (expect (subed-subtitle-msecs-start 3) :to-equal 5000) (expect (subed-subtitle-msecs-stop 3) :to-equal 6000) (expect (point) :to-equal orig-point)))) (it "when moving backward." (with-temp-srt-buffer (insert (concat "1\n" "00:00:01,000 --> 00:00:02,000\n" "Foo.\n\n" "2\n" "00:00:04,500 --> 00:00:04,000\n" "Bar.\n\n" "3\n" "00:00:04,500 --> 00:00:04,490\n" "Baz.\n")) (setq mark-active t) (spy-on 'region-beginning :and-return-value (subed-jump-to-subtitle-id 2)) (spy-on 'region-end :and-return-value (subed-jump-to-subtitle-text 3)) (let ((orig-point (subed-jump-to-subtitle-text 1))) (subed-move-subtitle-backward 1000) (expect (subed-subtitle-msecs-start 1) :to-equal 1000) (expect (subed-subtitle-msecs-stop 1) :to-equal 2000) (expect (subed-subtitle-msecs-start 2) :to-equal 3500) (expect (subed-subtitle-msecs-stop 2) :to-equal 3000) (expect (subed-subtitle-msecs-start 3) :to-equal 3500) (expect (subed-subtitle-msecs-stop 3) :to-equal 3490) (expect (point) :to-equal orig-point)))) ) (it "ignoring start time being larger than stop time." (with-temp-srt-buffer (insert (concat "1\n" "00:00:01,500 --> 00:00:01,400\n" "Foo.\n\n" "2\n" "00:00:02,500 --> 00:00:02,499\n" "Bar.\n\n" "3\n" "00:00:05,000 --> 00:00:06,000\n" "Bar.\n")) (setq mark-active t) (spy-on 'region-beginning :and-return-value (subed-jump-to-subtitle-text 1)) (spy-on 'region-end :and-return-value (subed-jump-to-subtitle-time-start 2)) (let ((orig-point (subed-jump-to-subtitle-time-stop 1))) (subed-move-subtitle-forward 1000) (expect (subed-subtitle-msecs-start 1) :to-equal 2500) (expect (subed-subtitle-msecs-stop 1) :to-equal 2400) (expect (subed-subtitle-msecs-start 2) :to-equal 3500) (expect (subed-subtitle-msecs-stop 2) :to-equal 3499) (expect (subed-subtitle-msecs-start 3) :to-equal 5000) (expect (subed-subtitle-msecs-stop 3) :to-equal 6000) (expect (point) :to-equal orig-point) (subed-move-subtitle-backward 500) (expect (subed-subtitle-msecs-start 1) :to-equal 2000) (expect (subed-subtitle-msecs-stop 1) :to-equal 1900) (expect (subed-subtitle-msecs-start 2) :to-equal 3000) (expect (subed-subtitle-msecs-stop 2) :to-equal 2999) (expect (subed-subtitle-msecs-start 3) :to-equal 5000) (expect (subed-subtitle-msecs-stop 3) :to-equal 6000) (expect (point) :to-equal orig-point)))) (it "ignoring stop time being smaller than start time." (with-temp-srt-buffer (insert (concat "1\n" "00:00:01,000 --> 00:00:02,000\n" "Foo.\n\n" "2\n" "00:00:04,100 --> 00:00:04,099\n" "Bar.\n\n" "3\n" "00:00:05,500 --> 00:00:05,000\n" "Bar.\n")) (setq mark-active t) (spy-on 'region-beginning :and-return-value (subed-jump-to-subtitle-text 2)) (spy-on 'region-end :and-return-value (subed-jump-to-subtitle-time-start 3)) (let ((orig-point (subed-jump-to-subtitle-text 1))) (subed-move-subtitle-forward 1000) (expect (subed-subtitle-msecs-start 1) :to-equal 1000) (expect (subed-subtitle-msecs-stop 1) :to-equal 2000) (expect (subed-subtitle-msecs-start 2) :to-equal 5100) (expect (subed-subtitle-msecs-stop 2) :to-equal 5099) (expect (subed-subtitle-msecs-start 3) :to-equal 6500) (expect (subed-subtitle-msecs-stop 3) :to-equal 6000) (expect (point) :to-equal orig-point) (subed-move-subtitle-backward 500) (expect (subed-subtitle-msecs-start 1) :to-equal 1000) (expect (subed-subtitle-msecs-stop 1) :to-equal 2000) (expect (subed-subtitle-msecs-start 2) :to-equal 4600) (expect (subed-subtitle-msecs-stop 2) :to-equal 4599) (expect (subed-subtitle-msecs-start 3) :to-equal 6000) (expect (subed-subtitle-msecs-stop 3) :to-equal 5500) (expect (point) :to-equal orig-point)))) (it "disables subtitle replay while moving subtitles." (with-temp-srt-buffer (insert mock-srt-data) (subed-enable-replay-adjusted-subtitle :quiet) (spy-on 'subed-enable-replay-adjusted-subtitle :and-call-through) (spy-on 'subed-disable-replay-adjusted-subtitle :and-call-through) (spy-on 'subed-adjust-subtitle-time-start :and-call-fake (lambda (msecs &optional a b) (expect (subed-replay-adjusted-subtitle-p) :to-be nil))) (spy-on 'subed-adjust-subtitle-stop :and-call-fake (lambda (msecs &optional a b) (expect (subed-replay-adjusted-subtitle-p) :to-be nil))) (subed-move-subtitle-forward 100) (expect 'subed-disable-replay-adjusted-subtitle :to-have-been-called-times 1) (expect 'subed-enable-replay-adjusted-subtitle :to-have-been-called-times 1) (subed-move-subtitle-backward 100) (expect 'subed-disable-replay-adjusted-subtitle :to-have-been-called-times 2) (expect 'subed-enable-replay-adjusted-subtitle :to-have-been-called-times 2))) (it "does not enable subtitle replay afterwards if it is disabled." (with-temp-srt-buffer (insert mock-srt-data) (subed-disable-replay-adjusted-subtitle :quiet) (spy-on 'subed-enable-replay-adjusted-subtitle :and-call-through) (spy-on 'subed-disable-replay-adjusted-subtitle :and-call-through) (spy-on 'subed-adjust-subtitle-time-start :and-call-fake (lambda (msecs &optional a b) (expect (subed-replay-adjusted-subtitle-p) :to-be nil))) (spy-on 'subed-adjust-subtitle-stop :and-call-fake (lambda (msecs &optional a b) (expect (subed-replay-adjusted-subtitle-p) :to-be nil))) (subed-move-subtitle-forward 100) (expect 'subed-disable-replay-adjusted-subtitle :to-have-been-called-times 1) (expect 'subed-enable-replay-adjusted-subtitle :to-have-been-called-times 0) (subed-move-subtitle-backward 100) (expect 'subed-disable-replay-adjusted-subtitle :to-have-been-called-times 2) (expect 'subed-enable-replay-adjusted-subtitle :to-have-been-called-times 0))) (it "seeks player to current subtitle if region is not active." (with-temp-srt-buffer (insert mock-srt-data) (spy-on 'subed-replay-adjusted-subtitle-p :and-return-value t) (spy-on 'subed-mpv-jump) (subed-move-subtitle-forward 100) (expect 'subed-mpv-jump :to-have-been-called-times 1) (expect 'subed-mpv-jump :to-have-been-called-with 183550) (subed-move-subtitle-backward 200) (expect 'subed-mpv-jump :to-have-been-called-times 2) (expect 'subed-mpv-jump :to-have-been-called-with 183350))) (it "seeks player to first subtitle in active region." (with-temp-srt-buffer (insert mock-srt-data) (let ((beg 15) (end (point-max))) (setq mark-active t) (spy-on 'region-beginning :and-return-value beg) (spy-on 'region-end :and-return-value end) (spy-on 'subed-replay-adjusted-subtitle-p :and-return-value t) (spy-on 'subed-mpv-jump) (subed-move-subtitle-forward 100) (expect 'subed-mpv-jump :to-have-been-called-times 1) (expect 'subed-mpv-jump :to-have-been-called-with '61100) (subed-move-subtitle-backward 300) (expect 'subed-mpv-jump :to-have-been-called-times 2) (expect 'subed-mpv-jump :to-have-been-called-with '60800)))) ) (describe "Inserting evenly spaced" (describe "in an empty buffer," (describe "appending" (it "a single subtile." (cl-loop for arg in (list nil 1) do (with-temp-srt-buffer (spy-on 'subed-regenerate-ids-soon) (expect (subed-insert-subtitle arg) :to-equal 33) (expect (buffer-string) :to-equal (concat "0\n" "00:00:00,000 --> 00:00:01,000\n" "\n")) (expect (point) :to-equal 33) (expect 'subed-regenerate-ids-soon :to-have-been-called-times 1) (spy-calls-reset 'subed-regenerate-ids-soon)))) (it "multiple subtiles." (cl-loop for arg in (list 2) do (with-temp-srt-buffer (spy-on 'subed-regenerate-ids-soon) (expect (subed-insert-subtitle arg) :to-equal 33) (expect (buffer-string) :to-equal (concat "0\n" "00:00:00,000 --> 00:00:01,000\n" "\n\n" "0\n" "00:00:01,100 --> 00:00:02,100\n" "\n")) (expect (point) :to-equal 33) (expect 'subed-regenerate-ids-soon :to-have-been-called-times 1) (spy-calls-reset 'subed-regenerate-ids-soon)))) ) (describe "prepending" (it "a single subtile." (cl-loop for arg in (list '- -1 (list 4)) do (with-temp-srt-buffer (spy-on 'subed-regenerate-ids-soon) (expect (subed-insert-subtitle arg) :to-equal 33) (expect (buffer-string) :to-equal (concat "0\n" "00:00:00,000 --> 00:00:01,000\n" "\n")) (expect (point) :to-equal 33) (expect 'subed-regenerate-ids-soon :to-have-been-called-times 1) (spy-calls-reset 'subed-regenerate-ids-soon)))) (it "multiple subtiles." (cl-loop for arg in (list -2 (list -16)) do (with-temp-srt-buffer (spy-on 'subed-regenerate-ids-soon) (expect (subed-insert-subtitle arg) :to-equal 33) (expect (buffer-string) :to-equal (concat "0\n" "00:00:00,000 --> 00:00:01,000\n" "\n\n" "0\n" "00:00:01,100 --> 00:00:02,100\n" "\n")) (expect (point) :to-equal 33) (expect 'subed-regenerate-ids-soon :to-have-been-called-times 1) (spy-calls-reset 'subed-regenerate-ids-soon)))) ) ) (describe "in a non-empty buffer" (describe "prepending between subtitles" (it "a single subtitle." (cl-loop for arg in (list '- -1 (list 4)) do (with-temp-srt-buffer (spy-on 'subed-regenerate-ids-soon) (insert (concat "1\n" "00:00:59,000 --> 00:01:00,000\n" "Foo.\n\n" "2\n" "00:02:00,000 --> 00:02:01,000\n" "Bar.\n")) (subed-jump-to-subtitle-text 2) (expect (subed-insert-subtitle arg) :to-equal 71) (expect (buffer-string) :to-equal (concat "1\n" "00:00:59,000 --> 00:01:00,000\n" "Foo.\n\n" "0\n" "00:01:30,000 --> 00:01:31,000\n" "\n\n" "2\n" "00:02:00,000 --> 00:02:01,000\n" "Bar.\n")) (expect (point) :to-equal 71) (expect 'subed-regenerate-ids-soon :to-have-been-called-times 1) (spy-calls-reset 'subed-regenerate-ids-soon)))) (it "multiple subtitles." (cl-loop for arg in (list -2 (list 16)) do (with-temp-srt-buffer (spy-on 'subed-regenerate-ids-soon) (insert (concat "1\n" "00:00:59,000 --> 00:01:00,000\n" "Foo.\n\n" "2\n" "00:02:00,000 --> 00:02:01,000\n" "Bar.\n")) (subed-jump-to-subtitle-text 2) (expect (subed-insert-subtitle arg) :to-equal 71) (expect (buffer-string) :to-equal (concat "1\n" "00:00:59,000 --> 00:01:00,000\n" "Foo.\n\n" "0\n" "00:01:20,000 --> 00:01:21,000\n" "\n\n" "0\n" "00:01:40,000 --> 00:01:41,000\n" "\n\n" "2\n" "00:02:00,000 --> 00:02:01,000\n" "Bar.\n")) (expect (point) :to-equal 71) (expect 'subed-regenerate-ids-soon :to-have-been-called-times 1) (spy-calls-reset 'subed-regenerate-ids-soon)))) ) (describe "appending between subtitles" (it "a single subtitle." (cl-loop for arg in (list nil 1) do (with-temp-srt-buffer (spy-on 'subed-regenerate-ids-soon) (insert (concat "1\n" "00:00:59,000 --> 00:01:00,000\n" "Foo.\n\n" "2\n" "00:02:00,000 --> 00:02:01,000\n" "Bar.\n")) (subed-jump-to-subtitle-text 1) (expect (subed-insert-subtitle arg) :to-equal 71) (expect (buffer-string) :to-equal (concat "1\n" "00:00:59,000 --> 00:01:00,000\n" "Foo.\n\n" "0\n" "00:01:30,000 --> 00:01:31,000\n" "\n\n" "2\n" "00:02:00,000 --> 00:02:01,000\n" "Bar.\n")) (expect (point) :to-equal 71) (expect 'subed-regenerate-ids-soon :to-have-been-called-times 1) (spy-calls-reset 'subed-regenerate-ids-soon)))) (it "multiple subtitles." (cl-loop for arg in (list 2) do (with-temp-srt-buffer (spy-on 'subed-regenerate-ids-soon) (insert (concat "1\n" "00:00:59,000 --> 00:01:00,000\n" "Foo.\n\n" "2\n" "00:02:00,000 --> 00:02:01,000\n" "Bar.\n")) (subed-jump-to-subtitle-text 1) (expect (subed-insert-subtitle arg) :to-equal 71) (expect (buffer-string) :to-equal (concat "1\n" "00:00:59,000 --> 00:01:00,000\n" "Foo.\n\n" "0\n" "00:01:20,000 --> 00:01:21,000\n" "\n\n" "0\n" "00:01:40,000 --> 00:01:41,000\n" "\n\n" "2\n" "00:02:00,000 --> 00:02:01,000\n" "Bar.\n")) (expect (point) :to-equal 71) (expect 'subed-regenerate-ids-soon :to-have-been-called-times 1) (spy-calls-reset 'subed-regenerate-ids-soon)))) ) (describe "prepending to the first subtitle" (it "a single subtitle." (cl-loop for arg in (list '- -1 (list 4)) do (with-temp-srt-buffer (spy-on 'subed-regenerate-ids-soon) (insert (concat "1\n" "00:01:00,000 --> 00:01:01,000\n" "Foo.\n")) (subed-srt--jump-to-subtitle-text 1) (expect (subed-insert-subtitle arg) :to-equal 33) (expect (buffer-string) :to-equal (concat "0\n" "00:00:30,000 --> 00:00:31,000\n" "\n\n" "1\n" "00:01:00,000 --> 00:01:01,000\n" "Foo.\n")) (expect (point) :to-equal 33) (expect 'subed-regenerate-ids-soon :to-have-been-called-times 1) (spy-calls-reset 'subed-regenerate-ids-soon)))) (it "multiple subtitles." (cl-loop for arg in (list -2 (list 16)) do (with-temp-srt-buffer (spy-on 'subed-regenerate-ids-soon) (insert (concat "1\n" "00:01:00,000 --> 00:01:01,000\n" "Foo.\n")) (subed-srt--jump-to-subtitle-text 1) (expect (subed-insert-subtitle arg) :to-equal 33) (expect (buffer-string) :to-equal (concat "0\n" "00:00:20,000 --> 00:00:21,000\n" "\n\n" "0\n" "00:00:40,000 --> 00:00:41,000\n" "\n\n" "1\n" "00:01:00,000 --> 00:01:01,000\n" "Foo.\n")) (expect (point) :to-equal 33) (expect 'subed-regenerate-ids-soon :to-have-been-called-times 1) (spy-calls-reset 'subed-regenerate-ids-soon)))) ) (describe "appending to the last subtitle" (it "a single subtitle." (cl-loop for arg in (list nil 1) do (with-temp-srt-buffer (spy-on 'subed-regenerate-ids-soon) (insert (concat "1\n" "00:00:59,000 --> 00:01:00,000\n" "Foo.\n")) (subed-srt--jump-to-subtitle-text 1) (expect (subed-insert-subtitle arg) :to-equal 71) (expect (buffer-string) :to-equal (concat "1\n" "00:00:59,000 --> 00:01:00,000\n" "Foo.\n\n" "0\n" "00:01:00,100 --> 00:01:01,100\n" "\n")) (expect (point) :to-equal 71) (expect 'subed-regenerate-ids-soon :to-have-been-called-times 1) (spy-calls-reset 'subed-regenerate-ids-soon)))) (it "multiple subtitles." (cl-loop for arg in (list 2) do (with-temp-srt-buffer (insert (concat "1\n" "00:00:59,000 --> 00:01:00,000\n" "Foo.\n")) (subed-srt--jump-to-subtitle-text 3) (expect (subed-insert-subtitle arg) :to-equal 71) (expect (buffer-string) :to-equal (concat "1\n" "00:00:59,000 --> 00:01:00,000\n" "Foo.\n\n" "0\n" "00:01:00,100 --> 00:01:01,100\n" "\n\n" "0\n" "00:01:01,200 --> 00:01:02,200\n" "\n")) (expect (point) :to-equal 71)))) ) (describe "when there is not enough time for the subtitles" (describe "to append" (it "a single subtitle." (cl-loop for arg in (list nil 1) do (with-temp-srt-buffer (spy-on 'subed-regenerate-ids-soon) (insert (concat "1\n" "00:00:59,000 --> 00:01:00,000\n" "Foo.\n\n" "2\n" "00:01:00,600 --> 00:01:02,000\n" "Foo.\n")) (subed-srt--jump-to-subtitle-text 1) (expect (subed-insert-subtitle arg) :to-equal 71) (expect (buffer-string) :to-equal (concat "1\n" "00:00:59,000 --> 00:01:00,000\n" "Foo.\n\n" "0\n" "00:01:00,100 --> 00:01:00,500\n" "\n\n" "2\n" "00:01:00,600 --> 00:01:02,000\n" "Foo.\n")) (expect (point) :to-equal 71) (expect 'subed-regenerate-ids-soon :to-have-been-called-times 1) (spy-calls-reset 'subed-regenerate-ids-soon)))) (it "multiple subtitles." (cl-loop for arg in (list 2) do (with-temp-srt-buffer (spy-on 'subed-regenerate-ids-soon) (insert (concat "1\n" "00:00:59,000 --> 00:01:00,000\n" "Foo.\n\n" "2\n" "00:01:00,600 --> 00:01:02,000\n" "Foo.\n")) (subed-srt--jump-to-subtitle-text 1) (expect (subed-insert-subtitle arg) :to-equal 71) (expect (buffer-string) :to-equal (concat "1\n" "00:00:59,000 --> 00:01:00,000\n" "Foo.\n\n" "0\n" "00:01:00,100 --> 00:01:00,250\n" "\n\n" "0\n" "00:01:00,350 --> 00:01:00,500\n" "\n\n" "2\n" "00:01:00,600 --> 00:01:02,000\n" "Foo.\n")) (expect (point) :to-equal 71) (expect 'subed-regenerate-ids-soon :to-have-been-called-times 1) (spy-calls-reset 'subed-regenerate-ids-soon)))) ) (describe "to prepend" (describe "between subtitles" (it "a single subtitle." (cl-loop for arg in (list '- -1 (list 4)) do (with-temp-srt-buffer (spy-on 'subed-regenerate-ids-soon) (insert (concat "1\n" "00:00:57,000 --> 00:00:59,100\n" "Foo.\n\n" "2\n" "00:01:00,000 --> 00:01:02,000\n" "Foo.\n")) (subed-srt--jump-to-subtitle-text 2) (expect (subed-insert-subtitle arg) :to-equal 71) (expect (buffer-string) :to-equal (concat "1\n" "00:00:57,000 --> 00:00:59,100\n" "Foo.\n\n" "0\n" "00:00:59,200 --> 00:00:59,900\n" "\n\n" "2\n" "00:01:00,000 --> 00:01:02,000\n" "Foo.\n")) (expect (point) :to-equal 71) (expect 'subed-regenerate-ids-soon :to-have-been-called-times 1) (spy-calls-reset 'subed-regenerate-ids-soon)))) (it "multiple subtitles." (cl-loop for arg in (list -2 (list 16)) do (with-temp-srt-buffer (spy-on 'subed-regenerate-ids-soon) (insert (concat "1\n" "00:00:57,000 --> 00:00:59,100\n" "Foo.\n\n" "2\n" "00:01:00,000 --> 00:01:02,000\n" "Foo.\n")) (subed-srt--jump-to-subtitle-text 2) (expect (subed-insert-subtitle arg) :to-equal 71) (expect (buffer-string) :to-equal (concat "1\n" "00:00:57,000 --> 00:00:59,100\n" "Foo.\n\n" "0\n" "00:00:59,200 --> 00:00:59,500\n" "\n\n" "0\n" "00:00:59,600 --> 00:00:59,900\n" "\n\n" "2\n" "00:01:00,000 --> 00:01:02,000\n" "Foo.\n")) (expect (point) :to-equal 71) (expect 'subed-regenerate-ids-soon :to-have-been-called-times 1) (spy-calls-reset 'subed-regenerate-ids-soon)))) ) (describe "before the first subtitle" (it "a single subtitle." (cl-loop for arg in (list '- -1 (list 4)) do (with-temp-srt-buffer (spy-on 'subed-regenerate-ids-soon) (insert (concat "1\n" "00:00:00,500 --> 00:00:02,000\n" "Foo.\n")) (subed-srt--jump-to-subtitle-text 1) (expect (subed-insert-subtitle arg) :to-equal 33) (expect (buffer-string) :to-equal (concat "0\n" "00:00:00,100 --> 00:00:00,400\n" "\n\n" "1\n" "00:00:00,500 --> 00:00:02,000\n" "Foo.\n")) (expect (point) :to-equal 33) (expect 'subed-regenerate-ids-soon :to-have-been-called-times 1) (spy-calls-reset 'subed-regenerate-ids-soon)))) (it "multiple subtitles." (cl-loop for arg in (list -2 (list 16)) do (with-temp-srt-buffer (spy-on 'subed-regenerate-ids-soon) (insert (concat "1\n" "00:00:00,600 --> 00:00:01,500\n" "Foo.\n")) (subed-srt--jump-to-subtitle-text 1) (expect (subed-insert-subtitle arg) :to-equal 33) (expect (buffer-string) :to-equal (concat "0\n" "00:00:00,100 --> 00:00:00,250\n" "\n\n" "0\n" "00:00:00,350 --> 00:00:00,500\n" "\n\n" "1\n" "00:00:00,600 --> 00:00:01,500\n" "Foo.\n")) (expect (point) :to-equal 33) (expect 'subed-regenerate-ids-soon :to-have-been-called-times 1) (spy-calls-reset 'subed-regenerate-ids-soon)))) ) ) ) (describe "when there is not enough time for spacing" (describe "between subtitles" (describe "when prepending" (it "a single subtitle." (cl-loop for arg in (list '- -1 (list 4)) do (with-temp-srt-buffer (spy-on 'subed-regenerate-ids-soon) (insert (concat "1\n" "00:00:55,000 --> 00:00:59,950\n" "Foo.\n\n" "2\n" "00:01:00,000 --> 00:01:02,000\n" "Bar.\n")) (subed-srt--jump-to-subtitle-text 2) (expect (subed-insert-subtitle arg) :to-equal 71) (expect (buffer-string) :to-equal (concat "1\n" "00:00:55,000 --> 00:00:59,950\n" "Foo.\n\n" "0\n" "00:00:59,950 --> 00:00:59,950\n" "\n\n" "2\n" "00:01:00,000 --> 00:01:02,000\n" "Bar.\n")) (expect (point) :to-equal 71) (expect 'subed-regenerate-ids-soon :to-have-been-called-times 1) (spy-calls-reset 'subed-regenerate-ids-soon)))) (it "multiple subtitles." (cl-loop for arg in (list -2 (list 16)) do (with-temp-srt-buffer (spy-on 'subed-regenerate-ids-soon) (insert (concat "1\n" "00:00:57,000 --> 00:00:59,999\n" "Foo.\n\n" "2\n" "00:01:00,000 --> 00:01:02,000\n" "Bar.\n")) (subed-srt--jump-to-subtitle-text 2) (expect (subed-insert-subtitle arg) :to-equal 71) (expect (buffer-string) :to-equal (concat "1\n" "00:00:57,000 --> 00:00:59,999\n" "Foo.\n\n" "0\n" "00:00:59,999 --> 00:00:59,999\n" "\n\n" "0\n" "00:00:59,999 --> 00:00:59,999\n" "\n\n" "2\n" "00:01:00,000 --> 00:01:02,000\n" "Bar.\n")) (expect (point) :to-equal 71) (expect 'subed-regenerate-ids-soon :to-have-been-called-times 1) (spy-calls-reset 'subed-regenerate-ids-soon)))) ) (describe "when appending" (it "a single subtitle." (cl-loop for arg in (list nil 1) do (with-temp-srt-buffer (spy-on 'subed-regenerate-ids-soon) (insert (concat "1\n" "00:00:59,000 --> 00:01:00,000\n" "Foo.\n\n" "2\n" "00:01:00,010 --> 00:01:02,000\n" "Bar.\n")) (subed-srt--jump-to-subtitle-text 1) (expect (subed-insert-subtitle arg) :to-equal 71) (expect (buffer-string) :to-equal (concat "1\n" "00:00:59,000 --> 00:01:00,000\n" "Foo.\n\n" "0\n" "00:01:00,000 --> 00:01:00,000\n" "\n\n" "2\n" "00:01:00,010 --> 00:01:02,000\n" "Bar.\n")) (expect (point) :to-equal 71) (expect 'subed-regenerate-ids-soon :to-have-been-called-times 1) (spy-calls-reset 'subed-regenerate-ids-soon)))) (it "multiple subtitles." (cl-loop for arg in (list 2) do (with-temp-srt-buffer (spy-on 'subed-regenerate-ids-soon) (insert (concat "1\n" "00:00:59,000 --> 00:01:00,000\n" "Foo.\n\n" "2\n" "00:01:00,100 --> 00:01:02,000\n" "Bar.\n")) (subed-srt--jump-to-subtitle-text 1) (expect (subed-insert-subtitle arg) :to-equal 71) (expect (buffer-string) :to-equal (concat "1\n" "00:00:59,000 --> 00:01:00,000\n" "Foo.\n\n" "0\n" "00:01:00,000 --> 00:01:00,000\n" "\n\n" "0\n" "00:01:00,000 --> 00:01:00,000\n" "\n\n" "2\n" "00:01:00,100 --> 00:01:02,000\n" "Bar.\n")) (expect (point) :to-equal 71) (expect 'subed-regenerate-ids-soon :to-have-been-called-times 1) (spy-calls-reset 'subed-regenerate-ids-soon)))) ) ) (describe "before the first subtitle" (it "a single subtitle." (cl-loop for arg in (list '- -1 (list 4)) do (with-temp-srt-buffer (spy-on 'subed-regenerate-ids-soon) (insert (concat "1\n" "00:00:00,050 --> 00:00:02,000\n" "Foo.\n")) (subed-srt--jump-to-subtitle-text 1) (expect (subed-insert-subtitle arg) :to-equal 33) (expect (buffer-string) :to-equal (concat "0\n" "00:00:00,000 --> 00:00:00,000\n" "\n\n" "1\n" "00:00:00,050 --> 00:00:02,000\n" "Foo.\n")) (expect (point) :to-equal 33) (expect 'subed-regenerate-ids-soon :to-have-been-called-times 1) (spy-calls-reset 'subed-regenerate-ids-soon)))) (it "multiple subtitles." (cl-loop for arg in (list -2 (list 16)) do (with-temp-srt-buffer (spy-on 'subed-regenerate-ids-soon) (insert (concat "1\n" "00:00:00,100 --> 00:00:01,500\n" "Foo.\n")) (subed-srt--jump-to-subtitle-text 1) (expect (subed-insert-subtitle arg) :to-equal 33) (expect (buffer-string) :to-equal (concat "0\n" "00:00:00,000 --> 00:00:00,000\n" "\n\n" "0\n" "00:00:00,000 --> 00:00:00,000\n" "\n\n" "1\n" "00:00:00,100 --> 00:00:01,500\n" "Foo.\n")) (expect (point) :to-equal 33) (expect 'subed-regenerate-ids-soon :to-have-been-called-times 1) (spy-calls-reset 'subed-regenerate-ids-soon)))) ) ) ) ) (describe "Inserting adjacent" (describe "in an empty buffer," (describe "appending" (it "a single subtile." (cl-loop for arg in (list nil 1) do (with-temp-srt-buffer (spy-on 'subed-regenerate-ids-soon) (expect (subed-insert-subtitle-adjacent arg) :to-equal 33) (expect (buffer-string) :to-equal (concat "0\n" "00:00:00,000 --> 00:00:01,000\n" "\n")) (expect (point) :to-equal 33) (expect 'subed-regenerate-ids-soon :to-have-been-called-times 1) (spy-calls-reset 'subed-regenerate-ids-soon)))) (it "multiple subtiles." (cl-loop for arg in (list 2) do (with-temp-srt-buffer (spy-on 'subed-regenerate-ids-soon) (expect (subed-insert-subtitle-adjacent arg) :to-equal 33) (expect (buffer-string) :to-equal (concat "0\n" "00:00:00,000 --> 00:00:01,000\n" "\n\n" "0\n" "00:00:01,100 --> 00:00:02,100\n" "\n")) (expect (point) :to-equal 33) (expect 'subed-regenerate-ids-soon :to-have-been-called-times 1) (spy-calls-reset 'subed-regenerate-ids-soon)))) ) (describe "prepending" (it "a single subtile." (cl-loop for arg in (list '- -1 (list 4)) do (with-temp-srt-buffer (spy-on 'subed-regenerate-ids-soon) (expect (subed-insert-subtitle-adjacent arg) :to-equal 33) (expect (buffer-string) :to-equal (concat "0\n" "00:00:00,000 --> 00:00:01,000\n" "\n")) (expect (point) :to-equal 33) (expect 'subed-regenerate-ids-soon :to-have-been-called-times 1) (spy-calls-reset 'subed-regenerate-ids-soon)))) (it "multiple subtiles." (cl-loop for arg in (list -2 (list -16)) do (with-temp-srt-buffer (spy-on 'subed-regenerate-ids-soon) (expect (subed-insert-subtitle-adjacent arg) :to-equal 33) (expect (buffer-string) :to-equal (concat "0\n" "00:00:00,000 --> 00:00:01,000\n" "\n\n" "0\n" "00:00:01,100 --> 00:00:02,100\n" "\n")) (expect (point) :to-equal 33) (expect 'subed-regenerate-ids-soon :to-have-been-called-times 1) (spy-calls-reset 'subed-regenerate-ids-soon)))) ) ) (describe "in a non-empty buffer" (describe "prepending between subtitles" (it "a single subtitle." (cl-loop for arg in (list '- -1 (list 4)) do (with-temp-srt-buffer (spy-on 'subed-regenerate-ids-soon) (insert (concat "1\n" "00:00:59,000 --> 00:01:00,000\n" "Foo.\n\n" "2\n" "00:02:00,000 --> 00:02:01,000\n" "Bar.\n")) (subed-jump-to-subtitle-text 2) (expect (subed-insert-subtitle-adjacent arg) :to-equal 71) (expect (buffer-string) :to-equal (concat "1\n" "00:00:59,000 --> 00:01:00,000\n" "Foo.\n\n" "0\n" "00:01:58,900 --> 00:01:59,900\n" "\n\n" "2\n" "00:02:00,000 --> 00:02:01,000\n" "Bar.\n")) (expect (point) :to-equal 71) (expect 'subed-regenerate-ids-soon :to-have-been-called-times 1) (spy-calls-reset 'subed-regenerate-ids-soon)))) (it "multiple subtitles." (cl-loop for arg in (list -2 (list 16)) do (with-temp-srt-buffer (spy-on 'subed-regenerate-ids-soon) (insert (concat "1\n" "00:00:59,000 --> 00:01:00,000\n" "Foo.\n\n" "2\n" "00:02:00,000 --> 00:02:01,000\n" "Bar.\n")) (subed-jump-to-subtitle-text 2) (expect (subed-insert-subtitle-adjacent arg) :to-equal 71) (expect (buffer-string) :to-equal (concat "1\n" "00:00:59,000 --> 00:01:00,000\n" "Foo.\n\n" "0\n" "00:01:57,800 --> 00:01:58,800\n" "\n\n" "0\n" "00:01:58,900 --> 00:01:59,900\n" "\n\n" "2\n" "00:02:00,000 --> 00:02:01,000\n" "Bar.\n")) (expect (point) :to-equal 71) (expect 'subed-regenerate-ids-soon :to-have-been-called-times 1) (spy-calls-reset 'subed-regenerate-ids-soon)))) ) (describe "appending between subtitles" (it "a single subtitle." (cl-loop for arg in (list nil 1) do (with-temp-srt-buffer (spy-on 'subed-regenerate-ids-soon) (insert (concat "1\n" "00:00:59,000 --> 00:01:00,000\n" "Foo.\n\n" "2\n" "00:02:00,000 --> 00:02:01,000\n" "Bar.\n")) (subed-jump-to-subtitle-text 1) (expect (subed-insert-subtitle-adjacent arg) :to-equal 71) (expect (buffer-string) :to-equal (concat "1\n" "00:00:59,000 --> 00:01:00,000\n" "Foo.\n\n" "0\n" "00:01:00,100 --> 00:01:01,100\n" "\n\n" "2\n" "00:02:00,000 --> 00:02:01,000\n" "Bar.\n")) (expect (point) :to-equal 71) (expect 'subed-regenerate-ids-soon :to-have-been-called-times 1) (spy-calls-reset 'subed-regenerate-ids-soon)))) (it "multiple subtitles." (cl-loop for arg in (list 2) do (with-temp-srt-buffer (spy-on 'subed-regenerate-ids-soon) (insert (concat "1\n" "00:00:59,000 --> 00:01:00,000\n" "Foo.\n\n" "2\n" "00:02:00,000 --> 00:02:01,000\n" "Bar.\n")) (subed-jump-to-subtitle-text 1) (expect (subed-insert-subtitle-adjacent arg) :to-equal 71) (expect (buffer-string) :to-equal (concat "1\n" "00:00:59,000 --> 00:01:00,000\n" "Foo.\n\n" "0\n" "00:01:00,100 --> 00:01:01,100\n" "\n\n" "0\n" "00:01:01,200 --> 00:01:02,200\n" "\n\n" "2\n" "00:02:00,000 --> 00:02:01,000\n" "Bar.\n")) (expect (point) :to-equal 71) (expect 'subed-regenerate-ids-soon :to-have-been-called-times 1) (spy-calls-reset 'subed-regenerate-ids-soon)))) ) (describe "prepending to the first subtitle" (it "a single subtitle." (cl-loop for arg in (list '- -1 (list 4)) do (with-temp-srt-buffer (spy-on 'subed-regenerate-ids-soon) (insert (concat "1\n" "00:01:00,000 --> 00:01:01,000\n" "Foo.\n")) (subed-srt--jump-to-subtitle-text 1) (expect (subed-insert-subtitle-adjacent arg) :to-equal 33) (expect (buffer-string) :to-equal (concat "0\n" "00:00:58,900 --> 00:00:59,900\n" "\n\n" "1\n" "00:01:00,000 --> 00:01:01,000\n" "Foo.\n")) (expect (point) :to-equal 33) (expect 'subed-regenerate-ids-soon :to-have-been-called-times 1) (spy-calls-reset 'subed-regenerate-ids-soon)))) (it "multiple subtitles." (cl-loop for arg in (list -2 (list 16)) do (with-temp-srt-buffer (spy-on 'subed-regenerate-ids-soon) (insert (concat "1\n" "00:01:00,000 --> 00:01:01,000\n" "Foo.\n")) (subed-srt--jump-to-subtitle-text 1) (expect (subed-insert-subtitle-adjacent arg) :to-equal 33) (expect (buffer-string) :to-equal (concat "0\n" "00:00:57,800 --> 00:00:58,800\n" "\n\n" "0\n" "00:00:58,900 --> 00:00:59,900\n" "\n\n" "1\n" "00:01:00,000 --> 00:01:01,000\n" "Foo.\n")) (expect (point) :to-equal 33) (expect 'subed-regenerate-ids-soon :to-have-been-called-times 1) (spy-calls-reset 'subed-regenerate-ids-soon)))) ) (describe "appending to the last subtitle" (it "a single subtitle." (cl-loop for arg in (list nil 1) do (with-temp-srt-buffer (spy-on 'subed-regenerate-ids-soon) (insert (concat "1\n" "00:00:59,000 --> 00:01:00,000\n" "Foo.\n")) (subed-srt--jump-to-subtitle-text 1) (expect (subed-insert-subtitle-adjacent arg) :to-equal 71) (expect (buffer-string) :to-equal (concat "1\n" "00:00:59,000 --> 00:01:00,000\n" "Foo.\n\n" "0\n" "00:01:00,100 --> 00:01:01,100\n" "\n")) (expect (point) :to-equal 71) (expect 'subed-regenerate-ids-soon :to-have-been-called-times 1) (spy-calls-reset 'subed-regenerate-ids-soon)))) (it "multiple subtitles." (cl-loop for arg in (list 2) do (with-temp-srt-buffer (spy-on 'subed-regenerate-ids-soon) (insert (concat "1\n" "00:00:59,000 --> 00:01:00,000\n" "Foo.\n")) (subed-srt--jump-to-subtitle-text 3) (expect (subed-insert-subtitle-adjacent arg) :to-equal 71) (expect (buffer-string) :to-equal (concat "1\n" "00:00:59,000 --> 00:01:00,000\n" "Foo.\n\n" "0\n" "00:01:00,100 --> 00:01:01,100\n" "\n\n" "0\n" "00:01:01,200 --> 00:01:02,200\n" "\n")) (expect (point) :to-equal 71) (expect 'subed-regenerate-ids-soon :to-have-been-called-times 1) (spy-calls-reset 'subed-regenerate-ids-soon)))) ) (describe "when there is not enough time for the subtitles" (describe "to append" (it "a single subtitle." (cl-loop for arg in (list nil 1) do (with-temp-srt-buffer (spy-on 'subed-regenerate-ids-soon) (insert (concat "1\n" "00:00:59,000 --> 00:01:00,000\n" "Foo.\n\n" "2\n" "00:01:00,500 --> 00:01:05,000\n" "Bar.\n")) (subed-srt--jump-to-subtitle-text 1) (expect (subed-insert-subtitle-adjacent arg) :to-equal 71) (expect (buffer-string) :to-equal (concat "1\n" "00:00:59,000 --> 00:01:00,000\n" "Foo.\n\n" "0\n" "00:01:00,100 --> 00:01:00,400\n" "\n\n" "2\n" "00:01:00,500 --> 00:01:05,000\n" "Bar.\n")) (expect (point) :to-equal 71) (expect 'subed-regenerate-ids-soon :to-have-been-called-times 1) (spy-calls-reset 'subed-regenerate-ids-soon)))) (it "multiple subtitles." (cl-loop for arg in (list 2) do (with-temp-srt-buffer (spy-on 'subed-regenerate-ids-soon) (insert (concat "1\n" "00:00:59,000 --> 00:01:00,000\n" "Foo.\n\n" "2\n" "00:01:00,500 --> 00:01:05,000\n" "Bar.\n")) (subed-srt--jump-to-subtitle-text 1) (expect (subed-insert-subtitle-adjacent arg) :to-equal 71) (expect (buffer-string) :to-equal (concat "1\n" "00:00:59,000 --> 00:01:00,000\n" "Foo.\n\n" "0\n" "00:01:00,100 --> 00:01:00,200\n" "\n\n" "0\n" "00:01:00,300 --> 00:01:00,400\n" "\n\n" "2\n" "00:01:00,500 --> 00:01:05,000\n" "Bar.\n")) (expect (point) :to-equal 71) (expect 'subed-regenerate-ids-soon :to-have-been-called-times 1) (spy-calls-reset 'subed-regenerate-ids-soon)))) ) (describe "to prepend" (describe "between subtitles" (it "a single subtitle." (cl-loop for arg in (list '- -1 (list 4)) do (with-temp-srt-buffer (spy-on 'subed-regenerate-ids-soon) (insert (concat "1\n" "00:00:59,000 --> 00:01:00,000\n" "Foo.\n\n" "2\n" "00:01:00,700 --> 00:01:05,000\n" "Bar.\n")) (subed-srt--jump-to-subtitle-text 2) (expect (subed-insert-subtitle-adjacent arg) :to-equal 71) (expect (buffer-string) :to-equal (concat "1\n" "00:00:59,000 --> 00:01:00,000\n" "Foo.\n\n" "0\n" "00:01:00,100 --> 00:01:00,600\n" "\n\n" "2\n" "00:01:00,700 --> 00:01:05,000\n" "Bar.\n")) (expect (point) :to-equal 71) (expect 'subed-regenerate-ids-soon :to-have-been-called-times 1) (spy-calls-reset 'subed-regenerate-ids-soon)))) (it "multiple subtitles." (cl-loop for arg in (list -2 (list 16)) do (with-temp-srt-buffer (spy-on 'subed-regenerate-ids-soon) (insert (concat "1\n" "00:00:59,000 --> 00:01:00,000\n" "Foo.\n\n" "2\n" "00:01:00,500 --> 00:01:05,000\n" "Bar.\n")) (subed-srt--jump-to-subtitle-text 2) (expect (subed-insert-subtitle-adjacent arg) :to-equal 71) (expect (buffer-string) :to-equal (concat "1\n" "00:00:59,000 --> 00:01:00,000\n" "Foo.\n\n" "0\n" "00:01:00,100 --> 00:01:00,200\n" "\n\n" "0\n" "00:01:00,300 --> 00:01:00,400\n" "\n\n" "2\n" "00:01:00,500 --> 00:01:05,000\n" "Bar.\n")) (expect (point) :to-equal 71) (expect 'subed-regenerate-ids-soon :to-have-been-called-times 1) (spy-calls-reset 'subed-regenerate-ids-soon)))) ) (describe "before the first subtitle" (it "a single subtitle." (cl-loop for arg in (list '- -1 (list 4)) do (with-temp-srt-buffer (spy-on 'subed-regenerate-ids-soon) (insert (concat "1\n" "00:00:01,000 --> 00:00:02,000\n" "Foo.\n")) (subed-srt--jump-to-subtitle-text 1) (expect (subed-insert-subtitle-adjacent arg) :to-equal 33) (expect (buffer-string) :to-equal (concat "0\n" "00:00:00,100 --> 00:00:00,900\n" "\n\n" "1\n" "00:00:01,000 --> 00:00:02,000\n" "Foo.\n")) (expect (point) :to-equal 33) (expect 'subed-regenerate-ids-soon :to-have-been-called-times 1) (spy-calls-reset 'subed-regenerate-ids-soon)))) (it "multiple subtitles." (cl-loop for arg in (list -2 (list 16)) do (with-temp-srt-buffer (spy-on 'subed-regenerate-ids-soon) (insert (concat "1\n" "00:00:00,800 --> 00:00:03,000\n" "Foo.\n")) (subed-srt--jump-to-subtitle-text 2) (expect (subed-insert-subtitle-adjacent arg) :to-equal 33) (expect (buffer-string) :to-equal (concat "0\n" "00:00:00,100 --> 00:00:00,350\n" "\n\n" "0\n" "00:00:00,450 --> 00:00:00,700\n" "\n\n" "1\n" "00:00:00,800 --> 00:00:03,000\n" "Foo.\n")) (expect (point) :to-equal 33) (expect 'subed-regenerate-ids-soon :to-have-been-called-times 1) (spy-calls-reset 'subed-regenerate-ids-soon)))) ) ) ) (describe "when there is not enough time for spacing" (describe "between subtitles" (describe "when prepending" (it "a single subtitle." (cl-loop for arg in (list '- -1 (list 4)) do (with-temp-srt-buffer (spy-on 'subed-regenerate-ids-soon) (insert (concat "1\n" "00:00:59,000 --> 00:01:00,000\n" "Foo.\n\n" "2\n" "00:01:00,005 --> 00:01:05,000\n" "Bar.\n")) (subed-srt--jump-to-subtitle-text 2) (expect (subed-insert-subtitle-adjacent arg) :to-equal 71) (expect (buffer-string) :to-equal (concat "1\n" "00:00:59,000 --> 00:01:00,000\n" "Foo.\n\n" "0\n" "00:01:00,005 --> 00:01:00,005\n" "\n\n" "2\n" "00:01:00,005 --> 00:01:05,000\n" "Bar.\n")) (expect (point) :to-equal 71) (expect 'subed-regenerate-ids-soon :to-have-been-called-times 1) (spy-calls-reset 'subed-regenerate-ids-soon)))) (it "multiple subtitles." (cl-loop for arg in (list -2 (list 16)) do (with-temp-srt-buffer (spy-on 'subed-regenerate-ids-soon) (insert (concat "1\n" "00:00:59,000 --> 00:01:00,000\n" "Foo.\n\n" "2\n" "00:01:00,025 --> 00:01:05,000\n" "Bar.\n")) (subed-srt--jump-to-subtitle-text 2) (expect (subed-insert-subtitle-adjacent arg) :to-equal 71) (expect (buffer-string) :to-equal (concat "1\n" "00:00:59,000 --> 00:01:00,000\n" "Foo.\n\n" "0\n" "00:01:00,025 --> 00:01:00,025\n" "\n\n" "0\n" "00:01:00,025 --> 00:01:00,025\n" "\n\n" "2\n" "00:01:00,025 --> 00:01:05,000\n" "Bar.\n")) (expect (point) :to-equal 71) (expect 'subed-regenerate-ids-soon :to-have-been-called-times 1) (spy-calls-reset 'subed-regenerate-ids-soon)))) ) (describe "when appending" (it "a single subtitle." (cl-loop for arg in (list nil 1) do (with-temp-srt-buffer (spy-on 'subed-regenerate-ids-soon) (insert (concat "1\n" "00:00:59,000 --> 00:01:00,000\n" "Foo.\n\n" "2\n" "00:01:00,099 --> 00:01:05,000\n" "Bar.\n")) (subed-srt--jump-to-subtitle-text 1) (expect (subed-insert-subtitle-adjacent arg) :to-equal 71) (expect (buffer-string) :to-equal (concat "1\n" "00:00:59,000 --> 00:01:00,000\n" "Foo.\n\n" "0\n" "00:01:00,000 --> 00:01:00,000\n" "\n\n" "2\n" "00:01:00,099 --> 00:01:05,000\n" "Bar.\n")) (expect (point) :to-equal 71) (expect 'subed-regenerate-ids-soon :to-have-been-called-times 1) (spy-calls-reset 'subed-regenerate-ids-soon)))) (it "multiple subtitles." (cl-loop for arg in (list 2) do (with-temp-srt-buffer (spy-on 'subed-regenerate-ids-soon) (insert (concat "1\n" "00:00:59,000 --> 00:01:00,000\n" "Foo.\n\n" "2\n" "00:01:00,075 --> 00:01:05,000\n" "Bar.\n")) (subed-srt--jump-to-subtitle-text 1) (expect (subed-insert-subtitle-adjacent arg) :to-equal 71) (expect (buffer-string) :to-equal (concat "1\n" "00:00:59,000 --> 00:01:00,000\n" "Foo.\n\n" "0\n" "00:01:00,000 --> 00:01:00,000\n" "\n\n" "0\n" "00:01:00,000 --> 00:01:00,000\n" "\n\n" "2\n" "00:01:00,075 --> 00:01:05,000\n" "Bar.\n")) (expect (point) :to-equal 71) (expect 'subed-regenerate-ids-soon :to-have-been-called-times 1) (spy-calls-reset 'subed-regenerate-ids-soon)))) ) ) (describe "before the first subtitle" (it "a single subtitle." (cl-loop for arg in (list '- -1 (list 4)) do (with-temp-srt-buffer (spy-on 'subed-regenerate-ids-soon) (insert (concat "1\n" "00:00:00,040 --> 00:00:05,000\n" "Foo.\n")) (subed-srt--jump-to-subtitle-text 1) (expect (subed-insert-subtitle-adjacent arg) :to-equal 33) (expect (buffer-string) :to-equal (concat "0\n" "00:00:00,040 --> 00:00:00,040\n" "\n\n" "1\n" "00:00:00,040 --> 00:00:05,000\n" "Foo.\n")) (expect (point) :to-equal 33) (expect 'subed-regenerate-ids-soon :to-have-been-called-times 1) (spy-calls-reset 'subed-regenerate-ids-soon)))) (it "multiple subtitles." (cl-loop for arg in (list -2 (list 16)) do (with-temp-srt-buffer (spy-on 'subed-regenerate-ids-soon) (insert (concat "1\n" "00:00:00,024 --> 00:00:05,000\n" "Foo.\n")) (subed-srt--jump-to-subtitle-text 1) (expect (subed-insert-subtitle-adjacent arg) :to-equal 33) (expect (buffer-string) :to-equal (concat "0\n" "00:00:00,024 --> 00:00:00,024\n" "\n\n" "0\n" "00:00:00,024 --> 00:00:00,024\n" "\n\n" "1\n" "00:00:00,024 --> 00:00:05,000\n" "Foo.\n")) (expect (point) :to-equal 33) (expect 'subed-regenerate-ids-soon :to-have-been-called-times 1) (spy-calls-reset 'subed-regenerate-ids-soon)))) ) ) ) ) (describe "Syncing player to point" :var (subed-mpv-playback-position) (before-each (setq subed-mpv-playback-position 0) (spy-on 'subed-subtitle-msecs-start :and-return-value 5000) (spy-on 'subed-subtitle-msecs-stop :and-return-value 6500) (spy-on 'subed-mpv-jump)) (it "does not seek player if point is on current subtitle." (setq subed-mpv-playback-position 5000) (subed--sync-player-to-point) (expect 'subed-mpv-jump :not :to-have-been-called) (setq subed-mpv-playback-position 6500) (subed--sync-player-to-point) (expect 'subed-mpv-jump :not :to-have-been-called)) (it "seeks player if point is on future subtitle." (subed-srt--init) (setq subed-mpv-playback-position 6501) (subed--sync-player-to-point) (expect 'subed-mpv-jump :to-have-been-called-with 5000)) (it "seeks player if point is on past subtitle." (subed-srt--init) (setq subed-mpv-playback-position 4999) (subed--sync-player-to-point) (expect 'subed-mpv-jump :to-have-been-called-with 5000)) ) (describe "Temporarily disabling point-to-player syncing" (before-each (spy-on 'subed-disable-sync-point-to-player)) (describe "when point-to-player syncing is disabled" (before-each (spy-on 'subed-sync-point-to-player-p :and-return-value nil) (spy-on 'run-at-time)) (it "does not disable point-to-player syncing." (subed-disable-sync-point-to-player-temporarily) (expect 'subed-disable-sync-point-to-player :not :to-have-been-called)) (it "does not schedule re-enabling of point-to-player syncing." (subed-disable-sync-point-to-player-temporarily) (expect 'run-at-time :not :to-have-been-called) (expect subed--point-sync-delay-after-motion-timer :to-be nil)) ) (describe "when point-to-player syncing is enabled" :var (subed--point-sync-delay-after-motion-timer) (before-each (spy-on 'subed-sync-point-to-player-p :and-return-value t) (spy-on 'run-at-time :and-return-value "mock timer") (spy-on 'cancel-timer) (setq subed--point-sync-delay-after-motion-timer nil)) (it "disables point-to-player syncing." (subed-disable-sync-point-to-player-temporarily) (expect 'subed-disable-sync-point-to-player :to-have-been-called)) (it "schedules re-enabling of point-to-player syncing." (subed-disable-sync-point-to-player-temporarily) (expect 'run-at-time :to-have-been-called-with subed-point-sync-delay-after-motion nil '(closure (t) nil (setq subed--point-sync-delay-after-motion-timer nil) (subed-enable-sync-point-to-player :quiet)))) (it "cancels previously scheduled re-enabling of point-to-player syncing." (subed-disable-sync-point-to-player-temporarily) (expect 'cancel-timer :not :to-have-been-called-with "mock timer") (subed-disable-sync-point-to-player-temporarily) (expect 'cancel-timer :to-have-been-called-with "mock timer") (expect 'cancel-timer :to-have-been-called-times 1) (subed-disable-sync-point-to-player-temporarily) (expect 'cancel-timer :to-have-been-called-with "mock timer") (expect 'cancel-timer :to-have-been-called-times 2)) ) ) subed-master/tests/test-subed-mpv.el000066400000000000000000000144711401667552300200340ustar00rootroot00000000000000;; -*- eval: (buttercup-minor-mode) -*- (add-to-list 'load-path "./subed") (require 'subed) (describe "Starting mpv" (it "passes arguments to make-process." (spy-on 'make-process) (spy-on 'subed-mpv--socket :and-return-value "/mock/path/to/socket") (subed-mpv--server-start "foo" "--bar") (expect 'make-process :to-have-been-called-with :command (list subed-mpv-executable "--input-ipc-server=/mock/path/to/socket" "--idle" "foo" "--bar") :name "subed-mpv-server" :buffer nil :noquery t)) (it "sets subed-mpv--server-proc on success." (spy-on 'make-process :and-return-value "mock process") (subed-mpv--server-start) (expect subed-mpv--server-proc :to-equal "mock process")) (it "signals error on failure." (spy-on 'make-process :and-throw-error 'error) (expect (subed-mpv--server-start) :to-throw 'error)) ) (describe "Stopping mpv" (before-each (setq subed-mpv--server-proc "mock running mpv process") (spy-on 'process-live-p :and-return-value t) (spy-on 'delete-process)) (it "kills the mpv process." (subed-mpv--server-stop) (expect 'delete-process :to-have-been-called-with "mock running mpv process")) (it "resets subed-mpv--server-proc." (expect subed-mpv--server-proc :not :to-be nil) (subed-mpv--server-stop) (expect subed-mpv--server-proc :to-be nil)) ) (describe "Connecting" (before-each (spy-on 'delete-process)) (it "resets global status variables." (spy-on 'subed-mpv--client-connected-p :and-return-value t) (spy-on 'make-network-process :and-return-value "mock client process") (spy-on 'process-send-string) (spy-on 'subed-mpv--client-send) (setq subed-mpv--client-proc "foo" subed-mpv-is-playing "baz" subed-mpv--client-command-queue '(foo bar baz)) (subed-mpv--client-connect '(0 0 0)) (expect subed-mpv--client-proc :to-equal "mock client process") (expect subed-mpv-is-playing :to-be nil) (expect subed-mpv--client-command-queue :to-be nil)) (it "correctly calls make-network-process." (spy-on 'make-network-process) (spy-on 'process-send-string) (spy-on 'subed-mpv--socket :and-return-value "/mock/path/to/socket") (subed-mpv--client-connect '(0 0 0)) (expect 'make-network-process :to-have-been-called-with :name "subed-mpv-client" :family 'local :service (subed-mpv--socket) :coding '(utf-8 . utf-8) :buffer (subed-mpv--client-buffer) :filter #'subed-mpv--client-filter :noquery t :nowait t)) (describe "tests the connection" (it "and sets subed-mpv--client-proc if the test succeeds." (spy-on 'make-network-process :and-return-value "mock client process") (spy-on 'process-send-string) (subed-mpv--client-connect '(0 0 0)) (expect 'process-send-string :to-have-been-called-with "mock client process" (concat subed-mpv--client-test-request "\n")) (expect subed-mpv--client-proc :to-equal "mock client process")) (it "and resets subed-mpv--client-proc if the test fails." (spy-on 'make-network-process :and-return-value "mock client process") (spy-on 'process-send-string :and-throw-error 'error) (setq subed-mpv--client-proc "foo") (subed-mpv--client-connect '(0 0 0)) (expect subed-mpv--client-proc :to-be nil)) (it "and tries again if the test fails." (spy-on 'make-network-process :and-return-value "mock client process") (spy-on 'process-send-string :and-throw-error 'error) (subed-mpv--client-connect '(0 0 0)) ;; FIXME: This seems to be a bug: ;; https://github.com/jorgenschaefer/emacs-buttercup/issues/139 ;; (expect 'process-send-string :to-have-been-called-times 3) (expect subed-mpv--client-proc :to-be nil)) ) (it "sends queued commands and empties the queue." (spy-on 'make-network-process :and-return-value "mock client process") (spy-on 'process-send-string) (spy-on 'subed-mpv--client-send) (setq subed-mpv--client-command-queue '(foo bar baz)) (subed-mpv--client-connect '(0 0 0)) (expect 'subed-mpv--client-send :to-have-been-called-with 'foo) (expect 'subed-mpv--client-send :to-have-been-called-with 'bar) (expect 'subed-mpv--client-send :to-have-been-called-with 'baz) (expect subed-mpv--client-command-queue :to-be nil)) ) (describe "Sending command" (before-each (spy-on 'delete-process) (setq subed-mpv--client-command-queue nil)) (describe "when mpv process is not running" (before-each (spy-on 'subed-mpv--server-started-p :and-return-value nil)) (it "is not queued if not connected." (spy-on 'subed-mpv--client-connected-p :and-return-value nil) (subed-mpv--client-send '(do this thing)) (expect subed-mpv--client-command-queue :to-be nil)) ) (describe "when mpv process is running" (before-each (spy-on 'subed-mpv--server-started-p :and-return-value t)) (it "is queued if not connected." (spy-on 'subed-mpv--client-connected-p :and-return-value nil) (subed-mpv--client-send '(do this thing)) (expect subed-mpv--client-command-queue :to-equal '((do this thing))) (subed-mpv--client-send '(do something else)) (expect subed-mpv--client-command-queue :to-equal '((do this thing) (do something else)))) (it "sends command if connected." (spy-on 'subed-mpv--client-connected-p :and-return-value t) (spy-on 'process-send-string) (setq subed-mpv--client-proc "mock client process") (subed-mpv--client-send '(do this thing)) (expect 'process-send-string :to-have-been-called-with "mock client process" (concat (json-encode (list :command '(do this thing))) "\n")) (expect subed-mpv--client-command-queue :to-equal nil)) (it "disconnects if sending fails even though we're connected." (spy-on 'subed-mpv--client-connected-p :and-return-value t) (spy-on 'subed-mpv--client-disconnect) (spy-on 'process-send-string :and-throw-error 'error) (expect (subed-mpv--client-send '(do this thing)) :to-throw 'error) (expect 'subed-mpv--client-disconnect :to-have-been-called-times 1) (expect subed-mpv--client-command-queue :to-equal nil)) ) ) subed-master/tests/test-subed-srt.el000066400000000000000000002112771401667552300200450ustar00rootroot00000000000000;; -*- eval: (buttercup-minor-mode) -*- (add-to-list 'load-path "./subed") (require 'subed) (defvar mock-srt-data "1 00:01:01,000 --> 00:01:05,123 Foo. 2 00:02:02,234 --> 00:02:10,345 Bar. 3 00:03:03,45 --> 00:03:15,5 Baz. ") (defmacro with-temp-srt-buffer (&rest body) "Call `subed-srt--init' in temporary buffer before running BODY." `(with-temp-buffer (subed-srt--init) (progn ,@body))) (describe "Getting" (describe "the subtitle ID" (it "returns the subtitle ID if it can be found." (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-text 2) (expect (subed-srt--subtitle-id) :to-equal 2))) (it "returns nil if no subtitle ID can be found." (with-temp-srt-buffer (expect (subed-srt--subtitle-id) :to-equal nil))) ) (describe "the subtitle ID at playback time" (it "returns subtitle ID if time is equal to start time." (with-temp-srt-buffer (insert mock-srt-data) (cl-loop for target-id from 1 to 3 do (let ((msecs (subed-srt--subtitle-msecs-start target-id))) (cl-loop for outset-id from 1 to 3 do (progn (subed-srt--jump-to-subtitle-id outset-id) (expect (subed-srt--subtitle-id-at-msecs msecs) :to-equal target-id))))))) (it "returns subtitle ID if time is equal to stop time." (with-temp-srt-buffer (insert mock-srt-data) (cl-loop for target-id from 1 to 3 do (let ((msecs (subed-srt--subtitle-msecs-stop target-id))) (cl-loop for outset-id from 1 to 3 do (progn (subed-srt--jump-to-subtitle-id outset-id) (expect (subed-srt--subtitle-id-at-msecs msecs) :to-equal target-id))))))) (it "returns subtitle ID if time is between start and stop time." (with-temp-srt-buffer (insert mock-srt-data) (cl-loop for target-id from 1 to 3 do (let ((msecs (+ 1 (subed-srt--subtitle-msecs-start target-id)))) (cl-loop for outset-id from 1 to 3 do (progn (subed-srt--jump-to-subtitle-id outset-id) (expect (subed-srt--subtitle-id-at-msecs msecs) :to-equal target-id))))))) (it "returns nil if time is before the first subtitle's start time." (with-temp-srt-buffer (insert mock-srt-data) (let ((msecs (- (save-excursion (goto-char (point-min)) (subed-srt--subtitle-msecs-start)) 1))) (cl-loop for outset-id from 1 to 3 do (progn (subed-srt--jump-to-subtitle-id outset-id) (expect (subed-srt--subtitle-id-at-msecs msecs) :to-equal nil)))))) (it "returns nil if time is after the last subtitle's start time." (with-temp-srt-buffer (insert mock-srt-data) (let ((msecs (+ (save-excursion (goto-char (point-max)) (subed-srt--subtitle-msecs-stop)) 1))) (cl-loop for outset-id from 1 to 3 do (progn (subed-srt--jump-to-subtitle-id outset-id) (expect (subed-srt--subtitle-id-at-msecs msecs) :to-equal nil)))))) (it "returns nil if time is between subtitles." (with-temp-srt-buffer (insert mock-srt-data) (cl-loop for target-id from 1 to 2 do (let ((msecs (+ (subed-srt--subtitle-msecs-stop target-id) 1))) (cl-loop for outset-id from 1 to 3 do (progn (subed-srt--jump-to-subtitle-id outset-id) (expect (subed-srt--subtitle-id-at-msecs msecs) :to-equal nil)))) (let ((msecs (- (subed-srt--subtitle-msecs-start (+ target-id 1)) 1))) (cl-loop for outset-id from 1 to 3 do (progn (subed-srt--jump-to-subtitle-id outset-id) (expect (subed-srt--subtitle-id-at-msecs msecs) :to-equal nil))))))) (it "doesn't fail if start time is invalid." (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-id 2) (let ((msecs (- (subed-srt--subtitle-msecs-start) 1))) (subed-srt--jump-to-subtitle-time-start) (forward-char 8) (delete-char 1) (expect (subed-srt--subtitle-id-at-msecs msecs) :to-equal 2)))) ) (describe "the subtitle start/stop time" (it "returns the time in milliseconds." (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-text 2) (expect (subed-srt--subtitle-msecs-start) :to-equal (+ (* 2 60000) (* 2 1000) 234)) (expect (subed-srt--subtitle-msecs-stop) :to-equal (+ (* 2 60000) (* 10 1000) 345)))) (it "handles lack of digits in milliseconds gracefully." (with-temp-srt-buffer (insert mock-srt-data) (subed-jump-to-subtitle-id 3) (expect (save-excursion (subed-jump-to-subtitle-time-start) (thing-at-point 'line)) :to-equal "00:03:03,45 --> 00:03:15,5\n") (expect (subed-srt--subtitle-msecs-start) :to-equal (+ (* 3 60 1000) (* 3 1000) 450)) (expect (subed-srt--subtitle-msecs-stop) :to-equal (+ (* 3 60 1000) (* 15 1000) 500)))) (it "returns nil if time can't be found." (with-temp-srt-buffer (expect (subed-srt--subtitle-msecs-start) :to-be nil) (expect (subed-srt--subtitle-msecs-stop) :to-be nil))) ) (describe "the subtitle text" (describe "when text is empty" (it "and at the beginning with a trailing newline." (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-text 1) (kill-line) (expect (subed-srt--subtitle-text) :to-equal ""))) (it "and at the beginning without a trailing newline." (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-text 1) (kill-whole-line) (expect (subed-srt--subtitle-text) :to-equal ""))) (it "and in the middle." (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-text 2) (kill-line) (expect (subed-srt--subtitle-text) :to-equal ""))) (it "and at the end with a trailing newline." (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-text 3) (kill-line) (expect (subed-srt--subtitle-text) :to-equal ""))) (it "and at the end without a trailing newline." (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-text 3) (kill-whole-line) (expect (subed-srt--subtitle-text) :to-equal ""))) ) (describe "when text is not empty" (it "and has no linebreaks." (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-text 2) (expect (subed-srt--subtitle-text) :to-equal "Bar."))) (it "and has linebreaks." (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-text 2) (insert "Bar.\n") (expect (subed-srt--subtitle-text) :to-equal "Bar.\nBar."))) ) ) (describe "the point within the subtitle" (it "returns the relative point if we can find an ID." (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-id 2) (expect (subed-srt--subtitle-relative-point) :to-equal 0) (forward-line) (expect (subed-srt--subtitle-relative-point) :to-equal 2) (forward-line) (expect (subed-srt--subtitle-relative-point) :to-equal 32) (forward-char) (expect (subed-srt--subtitle-relative-point) :to-equal 33) (forward-line) (expect (subed-srt--subtitle-relative-point) :to-equal 37) (forward-line) (expect (subed-srt--subtitle-relative-point) :to-equal 0))) (it "returns nil if we can't find an ID." (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-id 1) (insert "foo") (expect (subed-srt--subtitle-relative-point) :to-equal nil))) ) ) (describe "Jumping" (describe "to current subtitle ID" (it "returns ID's point when point is already on the ID." (with-temp-srt-buffer (insert mock-srt-data) (goto-char (point-min)) (expect (thing-at-point 'word) :to-equal "1") (expect (subed-srt--jump-to-subtitle-id) :to-equal 1) (expect (thing-at-point 'word) :to-equal "1"))) (it "returns ID's point when point is on the duration." (with-temp-srt-buffer (insert mock-srt-data) (search-backward ",234") (expect (thing-at-point 'word) :to-equal "02") (expect (subed-srt--jump-to-subtitle-id) :to-equal 39) (expect (thing-at-point 'word) :to-equal "2"))) (it "returns ID's point when point is on the text." (with-temp-srt-buffer (insert mock-srt-data) (search-backward "Baz.") (expect (thing-at-point 'word) :to-equal "Baz") (expect (subed-srt--jump-to-subtitle-id) :to-equal 77) (expect (thing-at-point 'word) :to-equal "3"))) (it "returns ID's point when point is between subtitles." (with-temp-srt-buffer (insert mock-srt-data) (goto-char (point-min)) (search-forward "Bar.\n") (expect (thing-at-point 'line) :to-equal "\n") (expect (subed-srt--jump-to-subtitle-id) :to-equal 39) (expect (thing-at-point 'word) :to-equal "2"))) (it "returns nil if buffer is empty." (with-temp-srt-buffer (expect (buffer-string) :to-equal "") (expect (subed-srt--jump-to-subtitle-id) :to-equal nil))) (it "returns ID's point when buffer starts with blank lines." (with-temp-srt-buffer (insert (concat " \n \t \n" mock-srt-data)) (search-backward "Foo.") (expect (thing-at-point 'line) :to-equal "Foo.\n") (expect (subed-srt--jump-to-subtitle-id) :to-equal 7) (expect (thing-at-point 'word) :to-equal "1"))) (it "returns ID's point when subtitles are separated with blank lines." (with-temp-srt-buffer (insert mock-srt-data) (goto-char (point-min)) (search-forward "Foo.\n") (insert " \n \t \n") (expect (subed-srt--jump-to-subtitle-id) :to-equal 1) (expect (thing-at-point 'word) :to-equal "1"))) ) (describe "to specific subtitle ID" (it "returns ID's point if wanted ID exists." (with-temp-srt-buffer (insert mock-srt-data) (goto-char (point-max)) (expect (subed-srt--jump-to-subtitle-id 2) :to-equal 39) (expect (thing-at-point 'word) :to-equal "2") (expect (subed-srt--jump-to-subtitle-id 1) :to-equal 1) (expect (thing-at-point 'word) :to-equal "1") (expect (subed-srt--jump-to-subtitle-id 3) :to-equal 77) (expect (thing-at-point 'word) :to-equal "3"))) (it "returns nil and does not move if wanted ID does not exists." (with-temp-srt-buffer (insert mock-srt-data) (goto-char (point-min)) (search-forward "Foo") (let ((stored-point (point))) (expect (subed-srt--jump-to-subtitle-id 4) :to-equal nil) (expect stored-point :to-equal (point))))) ) (describe "to subtitle ID at specific time" (it "returns ID's point if point changed." (with-temp-srt-buffer (insert mock-srt-data) (goto-char (point-max)) (spy-on 'subed-srt--subtitle-id-at-msecs :and-return-value (point-min)) (expect (subed-srt--jump-to-subtitle-id-at-msecs 123450) :to-equal (point-min)) (expect (point) :to-equal (point-min)) (expect 'subed-srt--subtitle-id-at-msecs :to-have-been-called-with 123450) (expect 'subed-srt--subtitle-id-at-msecs :to-have-been-called-times 1))) (it "returns nil if point didn't change." (with-temp-srt-buffer (insert mock-srt-data) (goto-char 75) (spy-on 'subed-srt--subtitle-id-at-msecs :and-return-value 75) (expect (subed-srt--jump-to-subtitle-id-at-msecs 123450) :to-equal nil) (expect (point) :to-equal 75) (expect 'subed-srt--subtitle-id-at-msecs :to-have-been-called-with 123450) (expect 'subed-srt--subtitle-id-at-msecs :to-have-been-called-times 1))) ) (describe "to subtitle start time" (it "returns start time's point if movement was successful." (with-temp-srt-buffer (insert mock-srt-data) (goto-char (point-min)) (expect (subed-srt--jump-to-subtitle-time-start) :to-equal 3) (expect (looking-at subed-srt--regexp-timestamp) :to-be t) (expect (match-string 0) :to-equal "00:01:01,000") (re-search-forward "\n\n") (expect (subed-srt--jump-to-subtitle-time-start) :to-equal 41) (expect (looking-at subed-srt--regexp-timestamp) :to-be t) (expect (match-string 0) :to-equal "00:02:02,234") (re-search-forward "\n\n") (expect (subed-srt--jump-to-subtitle-time-start) :to-equal 79) (expect (looking-at subed-srt--regexp-timestamp) :to-be t) (expect (match-string 0) :to-equal "00:03:03,45"))) (it "returns nil if movement failed." (with-temp-srt-buffer (expect (subed-srt--jump-to-subtitle-time-start) :to-equal nil))) ) (describe "to subtitle stop time" (it "returns stop time's point if movement was successful." (with-temp-srt-buffer (insert mock-srt-data) (goto-char (point-min)) (expect (subed-srt--jump-to-subtitle-time-stop) :to-equal 20) (expect (looking-at subed-srt--regexp-timestamp) :to-be t) (expect (match-string 0) :to-equal "00:01:05,123") (re-search-forward "\n\n") (expect (subed-srt--jump-to-subtitle-time-stop) :to-equal 58) (expect (looking-at subed-srt--regexp-timestamp) :to-be t) (expect (match-string 0) :to-equal "00:02:10,345") (re-search-forward "\n\n") (expect (subed-srt--jump-to-subtitle-time-stop) :to-equal 95) (expect (looking-at subed-srt--regexp-timestamp) :to-be t) (expect (match-string 0) :to-equal "00:03:15,5"))) (it "returns nil if movement failed." (with-temp-srt-buffer (expect (subed-srt--jump-to-subtitle-time-stop) :to-equal nil))) ) (describe "to subtitle text" (it "returns subtitle text's point if movement was successful." (with-temp-srt-buffer (insert mock-srt-data) (goto-char (point-min)) (expect (subed-srt--jump-to-subtitle-text) :to-equal 33) (expect (point) :to-equal (save-excursion (goto-char (point-max)) (search-backward "Foo."))) (re-search-forward "\n\n") (expect (subed-srt--jump-to-subtitle-text) :to-equal 71) (expect (point) :to-equal (save-excursion (goto-char (point-max)) (search-backward "Bar."))) (re-search-forward "\n\n") (expect (subed-srt--jump-to-subtitle-text) :to-equal 106) (expect (point) :to-equal (save-excursion (goto-char (point-max)) (search-backward "Baz."))))) (it "returns nil if movement failed." (with-temp-srt-buffer (expect (subed-srt--jump-to-subtitle-time-stop) :to-equal nil))) ) (describe "to end of subtitle text" (it "returns point if subtitle end can be found." (with-temp-srt-buffer (insert mock-srt-data) (goto-char (point-min)) (expect (subed-srt--jump-to-subtitle-end) :to-be 37) (expect (looking-back "^Foo.$") :to-be t) (forward-char 2) (expect (subed-srt--jump-to-subtitle-end) :to-be 75) (expect (looking-back "^Bar.$") :to-be t) (forward-char 2) (expect (subed-srt--jump-to-subtitle-end) :to-be 110) (expect (looking-back "^Baz.$") :to-be t) (goto-char (point-max)) (backward-char 2) (expect (subed-srt--jump-to-subtitle-end) :to-be 110) (expect (looking-back "^Baz.$") :to-be t))) (it "returns nil if subtitle end cannot be found." (with-temp-srt-buffer (expect (subed-srt--jump-to-subtitle-end) :to-be nil))) (it "returns nil if point did not move." (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-text 1) (kill-line) (expect (subed-srt--jump-to-subtitle-end) :to-be nil))) (it "works if text is empty with trailing newline." (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-text 1) (kill-line) (backward-char) (expect (subed-srt--jump-to-subtitle-end) :to-be 33) (expect (looking-at "^$") :to-be t) (subed-srt--jump-to-subtitle-text 2) (kill-line) (backward-char) (expect (subed-srt--jump-to-subtitle-end) :to-be 67) (expect (looking-at "^$") :to-be t) (subed-srt--jump-to-subtitle-text 3) (kill-line) (backward-char) (expect (subed-srt--jump-to-subtitle-end) :to-be 98) (expect (looking-at "^$") :to-be t))) (it "works if text is empty without trailing newline." (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-text 1) (kill-whole-line) (expect (subed-srt--jump-to-subtitle-end) :to-be nil) (expect (looking-at "^$") :to-be t) (goto-char (point-min)) (expect (subed-srt--jump-to-subtitle-end) :to-be 33) (expect (looking-at "^$") :to-be t) (subed-srt--jump-to-subtitle-text 2) (kill-whole-line) (expect (subed-srt--jump-to-subtitle-end) :to-be nil) (expect (looking-at "^$") :to-be t) (backward-char) (expect (subed-srt--jump-to-subtitle-end) :to-be 66) (expect (looking-at "^$") :to-be t) (subed-srt--jump-to-subtitle-text 3) (kill-whole-line) (expect (subed-srt--jump-to-subtitle-end) :to-be nil) (expect (looking-at "^$") :to-be t) (backward-char) (expect (subed-srt--jump-to-subtitle-end) :to-be 96) (expect (looking-at "^$") :to-be t))) ) (describe "to next subtitle ID" (it "returns point when there is a next subtitle." (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-id 1) (expect (thing-at-point 'word) :to-equal "1") (expect (subed-srt--forward-subtitle-id) :to-be 39) (expect (thing-at-point 'word) :to-equal "2") (subed-srt--jump-to-subtitle-time-start 2) (expect (thing-at-point 'word) :to-equal "00") (expect (subed-srt--forward-subtitle-id) :to-be 77) (expect (thing-at-point 'word) :to-equal "3"))) (it "returns nil and doesn't move when there is no next subtitle." (with-temp-srt-buffer (expect (thing-at-point 'word) :to-equal nil) (expect (subed-srt--forward-subtitle-id) :to-be nil)) (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-text 1) (expect (thing-at-point 'word) :to-equal "Foo") (expect (subed-srt--forward-subtitle-id) :to-be 39) (expect (thing-at-point 'word) :to-equal "2") (subed-srt--jump-to-subtitle-time-stop 2) (expect (thing-at-point 'word) :to-equal "00") (expect (subed-srt--forward-subtitle-id) :to-be 77) (expect (thing-at-point 'word) :to-equal "3")) (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-text 3) (expect (thing-at-point 'word) :to-equal "Baz") (expect (subed-srt--forward-subtitle-id) :to-be nil) (expect (thing-at-point 'word) :to-equal "Baz")) (with-temp-srt-buffer (insert (concat mock-srt-data "\n\n")) (subed-srt--jump-to-subtitle-time-stop 3) (expect (thing-at-point 'word) :to-equal "00") (expect (subed-srt--forward-subtitle-id) :to-be nil) (expect (thing-at-point 'word) :to-equal "00"))) ) (describe "to previous subtitle ID" (it "returns point when there is a previous subtitle." (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-text 2) (expect (thing-at-point 'word) :to-equal "Bar") (expect (subed-srt--backward-subtitle-id) :to-be 1) (expect (thing-at-point 'word) :to-equal "1") (subed-srt--jump-to-subtitle-time-stop 3) (expect (thing-at-point 'word) :to-equal "00") (expect (subed-srt--backward-subtitle-id) :to-be 39) (expect (thing-at-point 'word) :to-equal "2"))) (it "returns nil and doesn't move when there is no previous subtitle." (with-temp-srt-buffer (expect (subed-srt--backward-subtitle-id) :to-be nil)) (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-id 1) (expect (thing-at-point 'word) :to-equal "1") (expect (subed-srt--backward-subtitle-id) :to-be nil) (expect (thing-at-point 'word) :to-equal "1")) (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-text 1) (expect (thing-at-point 'word) :to-equal "Foo") (expect (subed-srt--backward-subtitle-id) :to-be nil) (expect (thing-at-point 'word) :to-equal "Foo")) (with-temp-srt-buffer (insert (concat "\n\n\n" mock-srt-data)) (subed-srt--jump-to-subtitle-time-stop 1) (expect (thing-at-point 'word) :to-equal "00") (expect (subed-srt--backward-subtitle-id) :to-be nil) (expect (thing-at-point 'word) :to-equal "00"))) ) (describe "to next subtitle text" (it "returns point when there is a next subtitle." (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-id 1) (expect (thing-at-point 'word) :to-equal "1") (expect (subed-srt--forward-subtitle-text) :to-be 71) (expect (thing-at-point 'word) :to-equal "Bar"))) (it "returns nil and doesn't move when there is no next subtitle." (with-temp-srt-buffer (goto-char (point-max)) (insert (concat mock-srt-data "\n\n")) (subed-srt--jump-to-subtitle-id 3) (expect (thing-at-point 'word) :to-equal "3") (expect (subed-srt--forward-subtitle-text) :to-be nil) (expect (thing-at-point 'word) :to-equal "3"))) ) (describe "to previous subtitle text" (it "returns point when there is a previous subtitle." (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-id 3) (expect (thing-at-point 'word) :to-equal "3") (expect (subed-srt--backward-subtitle-text) :to-be 71) (expect (thing-at-point 'word) :to-equal "Bar"))) (it "returns nil and doesn't move when there is no previous subtitle." (with-temp-srt-buffer (insert mock-srt-data) (goto-char (point-min)) (expect (thing-at-point 'word) :to-equal "1") (expect (subed-srt--backward-subtitle-text) :to-be nil) (expect (thing-at-point 'word) :to-equal "1"))) ) (describe "to next subtitle end" (it "returns point when there is a next subtitle." (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-text 2) (expect (thing-at-point 'word) :to-equal "Bar") (expect (subed-srt--forward-subtitle-end) :to-be 110) (expect (thing-at-point 'word) :to-equal nil))) (it "returns nil and doesn't move when there is no next subtitle." (with-temp-srt-buffer (insert (concat mock-srt-data "\n\n")) (subed-srt--jump-to-subtitle-text 3) (end-of-line) (expect (thing-at-point 'word) :to-equal nil) (expect (subed-srt--forward-subtitle-end) :to-be nil) (expect (thing-at-point 'word) :to-equal nil))) ) (describe "to previous subtitle end" (it "returns point when there is a previous subtitle." (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-id 3) (expect (thing-at-point 'word) :to-equal "3") (expect (subed-srt--backward-subtitle-text) :to-be 71) (expect (thing-at-point 'word) :to-equal "Bar"))) (it "returns nil and doesn't move when there is no previous subtitle." (with-temp-srt-buffer (insert mock-srt-data) (goto-char (point-min)) (expect (thing-at-point 'word) :to-equal "1") (expect (subed-srt--backward-subtitle-text) :to-be nil) (expect (thing-at-point 'word) :to-equal "1"))) ) (describe "to next subtitle start time" (it "returns point when there is a next subtitle." (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-text 1) (expect (thing-at-point 'word) :to-equal "Foo") (expect (subed-srt--forward-subtitle-time-start) :to-be 41) (expect (thing-at-point 'word) :to-equal "00"))) (it "returns nil and doesn't move when there is no next subtitle." (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-id 3) (expect (thing-at-point 'word) :to-equal "3") (expect (subed-srt--forward-subtitle-time-start) :to-be nil) (expect (thing-at-point 'word) :to-equal "3"))) ) (describe "to previous subtitle start time" (it "returns point when there is a previous subtitle." (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-id 2) (expect (thing-at-point 'word) :to-equal "2") (expect (subed-srt--backward-subtitle-time-start) :to-be 3) (expect (thing-at-point 'word) :to-equal "00"))) (it "returns nil and doesn't move when there is no previous subtitle." (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-id 1) (expect (thing-at-point 'word) :to-equal "1") (expect (subed-srt--backward-subtitle-time-start) :to-be nil) (expect (thing-at-point 'word) :to-equal "1"))) ) (describe "to next subtitle stop time" (it "returns point when there is a next subtitle." (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-text 1) (expect (thing-at-point 'word) :to-equal "Foo") (expect (subed-srt--forward-subtitle-time-stop) :to-be 58) (expect (thing-at-point 'word) :to-equal "00"))) (it "returns nil and doesn't move when there is no next subtitle." (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-id 3) (expect (thing-at-point 'word) :to-equal "3") (expect (subed-srt--forward-subtitle-time-stop) :to-be nil) (expect (thing-at-point 'word) :to-equal "3"))) ) (describe "to previous subtitle stop time" (it "returns point when there is a previous subtitle." (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-id 3) (expect (thing-at-point 'word) :to-equal "3") (expect (subed-srt--backward-subtitle-time-stop) :to-be 58) (expect (thing-at-point 'word) :to-equal "00"))) (it "returns nil and doesn't move when there is no previous subtitle." (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-id 1) (expect (thing-at-point 'word) :to-equal "1") (expect (subed-srt--backward-subtitle-time-stop) :to-be nil) (expect (thing-at-point 'word) :to-equal "1"))) ) ) (describe "Setting start/stop time" (it "of current subtitle." (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-end 2) (subed-srt--set-subtitle-time-start (+ (* 1 60 60 1000) (* 2 60 1000) (* 3 1000) 400)) (expect (buffer-string) :to-equal (concat "1\n" "00:01:01,000 --> 00:01:05,123\n" "Foo.\n\n" "2\n" "01:02:03,400 --> 00:02:10,345\n" "Bar.\n\n" "3\n" "00:03:03,45 --> 00:03:15,5\n" "Baz.\n")) (subed-srt--set-subtitle-time-stop (+ (* 5 60 60 1000) (* 6 60 1000) (* 7 1000) 800)) (expect (buffer-string) :to-equal (concat "1\n" "00:01:01,000 --> 00:01:05,123\n" "Foo.\n\n" "2\n" "01:02:03,400 --> 05:06:07,800\n" "Bar.\n\n" "3\n" "00:03:03,45 --> 00:03:15,5\n" "Baz.\n")))) (it "of specific subtitle." (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-time-stop 3) (subed-srt--set-subtitle-time-start (+ (* 2 60 60 1000) (* 4 60 1000) (* 6 1000) 800) 1) (expect (buffer-string) :to-equal (concat "1\n" "02:04:06,800 --> 00:01:05,123\n" "Foo.\n\n" "2\n" "00:02:02,234 --> 00:02:10,345\n" "Bar.\n\n" "3\n" "00:03:03,45 --> 00:03:15,5\n" "Baz.\n")) (subed-srt--jump-to-subtitle-text 1) (subed-srt--set-subtitle-time-stop (+ (* 3 60 60 1000) (* 5 60 1000) (* 7 1000) 900) 3) (expect (buffer-string) :to-equal (concat "1\n" "02:04:06,800 --> 00:01:05,123\n" "Foo.\n\n" "2\n" "00:02:02,234 --> 00:02:10,345\n" "Bar.\n\n" "3\n" "00:03:03,45 --> 03:05:07,900\n" "Baz.\n")))) (it "when milliseconds lack digits." (with-temp-srt-buffer (insert mock-srt-data) (subed-jump-to-subtitle-id 3) (subed-srt--set-subtitle-time-start (+ (* 1 60 60 1000) (* 2 60 1000) (* 3 1000) 4) 3) (expect (save-excursion (subed-jump-to-subtitle-time-start) (thing-at-point 'line)) :to-equal "01:02:03,004 --> 00:03:15,5\n") (subed-srt--set-subtitle-time-stop (+ (* 2 60 60 1000) (* 3 60 1000) (* 4 1000) 60) 3) (expect (save-excursion (subed-jump-to-subtitle-time-start) (thing-at-point 'line)) :to-equal "01:02:03,004 --> 02:03:04,060\n"))) ) (describe "Inserting a subtitle" (describe "in an empty buffer" (describe "before" (it "passing nothing." (with-temp-srt-buffer (expect (subed-srt--prepend-subtitle) :to-equal 33) (expect (buffer-string) :to-equal (concat "0\n" "00:00:00,000 --> 00:00:01,000\n\n")) (expect (point) :to-equal 33))) (it "passing ID." (with-temp-srt-buffer (expect (subed-srt--prepend-subtitle 2) :to-equal 33) (expect (buffer-string) :to-equal (concat "2\n" "00:00:00,000 --> 00:00:01,000\n\n")) (expect (point) :to-equal 33))) (it "passing ID and start time." (with-temp-srt-buffer (expect (subed-srt--prepend-subtitle 3 60000) :to-equal 33) (expect (buffer-string) :to-equal (concat "3\n" "00:01:00,000 --> 00:01:01,000\n\n")) (expect (point) :to-equal 33))) (it "passing ID, start time and stop time." (with-temp-srt-buffer (expect (subed-srt--prepend-subtitle 4 60000 65000) :to-equal 33) (expect (buffer-string) :to-equal (concat "4\n" "00:01:00,000 --> 00:01:05,000\n\n")) (expect (point) :to-equal 33))) (it "passing ID, start time, stop time and text." (with-temp-srt-buffer (expect (subed-srt--prepend-subtitle 5 60000 65000 "Foo, bar\nbaz.") :to-equal 33) (expect (buffer-string) :to-equal (concat "5\n" "00:01:00,000 --> 00:01:05,000\n" "Foo, bar\nbaz.\n")) (expect (point) :to-equal 33))) ) (describe "after" (it "passing nothing." (with-temp-srt-buffer (expect (subed-srt--append-subtitle) :to-equal 33) (expect (buffer-string) :to-equal (concat "0\n" "00:00:00,000 --> 00:00:01,000\n\n")) (expect (point) :to-equal 33))) (it "passing ID." (with-temp-srt-buffer (expect (subed-srt--append-subtitle 2) :to-equal 33) (expect (buffer-string) :to-equal (concat "2\n" "00:00:00,000 --> 00:00:01,000\n\n")) (expect (point) :to-equal 33))) (it "passing ID and start time." (with-temp-srt-buffer (expect (subed-srt--append-subtitle 3 60000) :to-equal 33) (expect (buffer-string) :to-equal (concat "3\n" "00:01:00,000 --> 00:01:01,000\n\n")) (expect (point) :to-equal 33))) (it "passing ID, start time and stop time." (with-temp-srt-buffer (expect (subed-srt--append-subtitle 4 60000 65000) :to-equal 33) (expect (buffer-string) :to-equal (concat "4\n" "00:01:00,000 --> 00:01:05,000\n\n")) (expect (point) :to-equal 33))) (it "passing ID, start time, stop time and text." (with-temp-srt-buffer (expect (subed-srt--append-subtitle 5 60000 65000 "Foo, bar\nbaz.") :to-equal 33) (expect (buffer-string) :to-equal (concat "5\n" "00:01:00,000 --> 00:01:05,000\n" "Foo, bar\nbaz.\n")) (expect (point) :to-equal 33))) ) ) (describe "in a non-empty buffer" (describe "before the current subtitle" (describe "with point on the first subtitle" (it "passing nothing." (with-temp-srt-buffer (insert (concat "1\n" "00:00:05,000 --> 00:00:06,000\n" "Foo.\n")) (subed-srt--jump-to-subtitle-time-stop) (expect (subed-srt--prepend-subtitle) :to-equal 33) (expect (buffer-string) :to-equal (concat "0\n" "00:00:00,000 --> 00:00:01,000\n" "\n\n" "1\n" "00:00:05,000 --> 00:00:06,000\n" "Foo.\n")) (expect (point) :to-equal 33))) (it "passing ID." (with-temp-srt-buffer (insert (concat "1\n" "00:00:05,000 --> 00:00:06,000\n" "Foo.\n")) (subed-srt--jump-to-subtitle-time-stop) (expect (subed-srt--prepend-subtitle 7) :to-equal 33) (expect (buffer-string) :to-equal (concat "7\n" "00:00:00,000 --> 00:00:01,000\n" "\n\n" "1\n" "00:00:05,000 --> 00:00:06,000\n" "Foo.\n")) (expect (point) :to-equal 33))) (it "passing ID and start time." (with-temp-srt-buffer (insert (concat "1\n" "00:00:05,000 --> 00:00:06,000\n" "Foo.\n")) (subed-srt--jump-to-subtitle-time-stop) (expect (subed-srt--prepend-subtitle 6 1500) :to-equal 33) (expect (buffer-string) :to-equal (concat "6\n" "00:00:01,500 --> 00:00:02,500\n" "\n\n" "1\n" "00:00:05,000 --> 00:00:06,000\n" "Foo.\n")) (expect (point) :to-equal 33))) (it "passing ID, start time and stop time." (with-temp-srt-buffer (insert (concat "1\n" "00:00:05,000 --> 00:00:06,000\n" "Foo.\n")) (subed-srt--jump-to-subtitle-time-stop) (expect (subed-srt--prepend-subtitle 5 1500 2000) :to-equal 33) (expect (buffer-string) :to-equal (concat "5\n" "00:00:01,500 --> 00:00:02,000\n" "\n\n" "1\n" "00:00:05,000 --> 00:00:06,000\n" "Foo.\n")) (expect (point) :to-equal 33))) (it "passing ID, start time, stop time and text." (with-temp-srt-buffer (insert (concat "1\n" "00:00:05,000 --> 00:00:06,000\n" "Foo.\n")) (subed-srt--jump-to-subtitle-time-stop) (expect (subed-srt--prepend-subtitle 4 1500 3000 "Bar.") :to-equal 33) (expect (buffer-string) :to-equal (concat "4\n" "00:00:01,500 --> 00:00:03,000\n" "Bar.\n\n" "1\n" "00:00:05,000 --> 00:00:06,000\n" "Foo.\n")) (expect (point) :to-equal 33))) ) (describe "with point on a non-first subtitle" (it "passing nothing." (with-temp-srt-buffer (insert (concat "1\n" "00:00:05,000 --> 00:00:06,000\n" "Foo.\n\n" "2\n" "00:00:10,000 --> 00:00:12,000\n" "Bar.\n")) (subed-srt--jump-to-subtitle-text 2) (expect (subed-srt--prepend-subtitle) :to-equal 71) (expect (buffer-string) :to-equal (concat "1\n" "00:00:05,000 --> 00:00:06,000\n" "Foo.\n\n" "0\n" "00:00:00,000 --> 00:00:01,000\n" "\n\n" "2\n" "00:00:10,000 --> 00:00:12,000\n" "Bar.\n")) (expect (point) :to-equal 71))) (it "passing ID." (with-temp-srt-buffer (insert (concat "1\n" "00:00:05,000 --> 00:00:06,000\n" "Foo.\n\n" "2\n" "00:00:10,000 --> 00:00:12,000\n" "Bar.\n")) (subed-srt--jump-to-subtitle-text 2) (expect (subed-srt--prepend-subtitle 9) :to-equal 71) (expect (buffer-string) :to-equal (concat "1\n" "00:00:05,000 --> 00:00:06,000\n" "Foo.\n\n" "9\n" "00:00:00,000 --> 00:00:01,000\n" "\n\n" "2\n" "00:00:10,000 --> 00:00:12,000\n" "Bar.\n")) (expect (point) :to-equal 71))) (it "passing ID and start time." (with-temp-srt-buffer (insert (concat "1\n" "00:00:05,000 --> 00:00:06,000\n" "Foo.\n\n" "2\n" "00:00:10,000 --> 00:00:12,000\n" "Bar.\n")) (subed-srt--jump-to-subtitle-text 2) (expect (subed-srt--prepend-subtitle 9 7000) :to-equal 71) (expect (buffer-string) :to-equal (concat "1\n" "00:00:05,000 --> 00:00:06,000\n" "Foo.\n\n" "9\n" "00:00:07,000 --> 00:00:08,000\n" "\n\n" "2\n" "00:00:10,000 --> 00:00:12,000\n" "Bar.\n")) (expect (point) :to-equal 71))) (it "passing ID, start time and stop time." (with-temp-srt-buffer (insert (concat "1\n" "00:00:05,000 --> 00:00:06,000\n" "Foo.\n\n" "2\n" "00:00:10,000 --> 00:00:12,000\n" "Bar.\n")) (subed-srt--jump-to-subtitle-text 2) (expect (subed-srt--prepend-subtitle 9 7000 7123) :to-equal 71) (expect (buffer-string) :to-equal (concat "1\n" "00:00:05,000 --> 00:00:06,000\n" "Foo.\n\n" "9\n" "00:00:07,000 --> 00:00:07,123\n" "\n\n" "2\n" "00:00:10,000 --> 00:00:12,000\n" "Bar.\n")) (expect (point) :to-equal 71))) (it "passing ID, start time, stop time and text." (with-temp-srt-buffer (insert (concat "1\n" "00:00:05,000 --> 00:00:06,000\n" "Foo.\n\n" "2\n" "00:00:10,000 --> 00:00:12,000\n" "Bar.\n")) (subed-srt--jump-to-subtitle-text 2) (expect (subed-srt--prepend-subtitle 9 7000 7123 "Baz.") :to-equal 71) (expect (buffer-string) :to-equal (concat "1\n" "00:00:05,000 --> 00:00:06,000\n" "Foo.\n\n" "9\n" "00:00:07,000 --> 00:00:07,123\n" "Baz.\n\n" "2\n" "00:00:10,000 --> 00:00:12,000\n" "Bar.\n")) (expect (point) :to-equal 71))) ) ) (describe "after the current subtitle" (describe "with point on the last subtitle" (it "passing nothing." (with-temp-srt-buffer (insert (concat "1\n" "00:00:05,000 --> 00:00:06,000\n" "Foo.\n")) (subed-srt--jump-to-subtitle-text) (expect (subed-srt--append-subtitle) :to-equal 71) (expect (buffer-string) :to-equal (concat "1\n" "00:00:05,000 --> 00:00:06,000\n" "Foo.\n\n" "0\n" "00:00:00,000 --> 00:00:01,000\n" "\n")) (expect (point) :to-equal 71))) (it "passing ID." (with-temp-srt-buffer (insert (concat "1\n" "00:00:05,000 --> 00:00:06,000\n" "Foo.\n")) (subed-srt--jump-to-subtitle-text) (expect (subed-srt--append-subtitle 5) :to-equal 71) (expect (buffer-string) :to-equal (concat "1\n" "00:00:05,000 --> 00:00:06,000\n" "Foo.\n\n" "5\n" "00:00:00,000 --> 00:00:01,000\n" "\n")) (expect (point) :to-equal 71))) (it "passing ID and start time." (with-temp-srt-buffer (insert (concat "1\n" "00:00:05,000 --> 00:00:06,000\n" "Foo.\n")) (subed-srt--jump-to-subtitle-text) (expect (subed-srt--append-subtitle 5 12345) :to-equal 71) (expect (buffer-string) :to-equal (concat "1\n" "00:00:05,000 --> 00:00:06,000\n" "Foo.\n\n" "5\n" "00:00:12,345 --> 00:00:13,345\n" "\n")) (expect (point) :to-equal 71))) (it "passing ID, start time and stop time." (with-temp-srt-buffer (insert (concat "1\n" "00:00:05,000 --> 00:00:06,000\n" "Foo.\n")) (subed-srt--jump-to-subtitle-text) (expect (subed-srt--append-subtitle 5 12345 15000) :to-equal 71) (expect (buffer-string) :to-equal (concat "1\n" "00:00:05,000 --> 00:00:06,000\n" "Foo.\n\n" "5\n" "00:00:12,345 --> 00:00:15,000\n" "\n")) (expect (point) :to-equal 71))) (it "passing ID, start time, stop time and text." (with-temp-srt-buffer (insert (concat "1\n" "00:00:05,000 --> 00:00:06,000\n" "Foo.\n")) (subed-srt--jump-to-subtitle-text) (expect (subed-srt--append-subtitle 5 12345 15000 "Bar.") :to-equal 71) (expect (buffer-string) :to-equal (concat "1\n" "00:00:05,000 --> 00:00:06,000\n" "Foo.\n\n" "5\n" "00:00:12,345 --> 00:00:15,000\n" "Bar.\n")) (expect (point) :to-equal 71))) ) (describe "with point on a non-last subtitle" (it "passing nothing." (with-temp-srt-buffer (insert (concat "1\n" "00:00:01,000 --> 00:00:02,000\n" "Foo.\n\n" "2\n" "00:00:05,000 --> 00:00:06,000\n" "Bar.\n")) (subed-srt--jump-to-subtitle-time-start 1) (expect (subed-srt--append-subtitle) :to-equal 71) (expect (buffer-string) :to-equal (concat "1\n" "00:00:01,000 --> 00:00:02,000\n" "Foo.\n\n" "0\n" "00:00:00,000 --> 00:00:01,000\n" "\n\n" "2\n" "00:00:05,000 --> 00:00:06,000\n" "Bar.\n")) (expect (point) :to-equal 71))) (it "passing ID." (with-temp-srt-buffer (insert (concat "1\n" "00:00:01,000 --> 00:00:02,000\n" "Foo.\n\n" "2\n" "00:00:05,000 --> 00:00:06,000\n" "Bar.\n")) (subed-srt--jump-to-subtitle-time-start 1) (expect (subed-srt--append-subtitle 7) :to-equal 71) (expect (buffer-string) :to-equal (concat "1\n" "00:00:01,000 --> 00:00:02,000\n" "Foo.\n\n" "7\n" "00:00:00,000 --> 00:00:01,000\n" "\n\n" "2\n" "00:00:05,000 --> 00:00:06,000\n" "Bar.\n")) (expect (point) :to-equal 71))) (it "passing ID and start time." (with-temp-srt-buffer (insert (concat "1\n" "00:00:01,000 --> 00:00:02,000\n" "Foo.\n\n" "2\n" "00:00:05,000 --> 00:00:06,000\n" "Bar.\n")) (subed-srt--jump-to-subtitle-time-start 1) (expect (subed-srt--append-subtitle 7 2500) :to-equal 71) (expect (buffer-string) :to-equal (concat "1\n" "00:00:01,000 --> 00:00:02,000\n" "Foo.\n\n" "7\n" "00:00:02,500 --> 00:00:03,500\n" "\n\n" "2\n" "00:00:05,000 --> 00:00:06,000\n" "Bar.\n")) (expect (point) :to-equal 71))) (it "passing ID, start time and stop time." (with-temp-srt-buffer (insert (concat "1\n" "00:00:01,000 --> 00:00:02,000\n" "Foo.\n\n" "2\n" "00:00:05,000 --> 00:00:06,000\n" "Bar.\n")) (subed-srt--jump-to-subtitle-time-start 1) (expect (subed-srt--append-subtitle 7 2500 4000) :to-equal 71) (expect (buffer-string) :to-equal (concat "1\n" "00:00:01,000 --> 00:00:02,000\n" "Foo.\n\n" "7\n" "00:00:02,500 --> 00:00:04,000\n" "\n\n" "2\n" "00:00:05,000 --> 00:00:06,000\n" "Bar.\n")) (expect (point) :to-equal 71))) (it "passing ID, start time, stop time and text." (with-temp-srt-buffer (insert (concat "1\n" "00:00:01,000 --> 00:00:02,000\n" "Foo.\n\n" "2\n" "00:00:05,000 --> 00:00:06,000\n" "Bar.\n")) (subed-srt--jump-to-subtitle-time-start 1) (expect (subed-srt--append-subtitle 7 2500 4000 "Baz.") :to-equal 71) (expect (buffer-string) :to-equal (concat "1\n" "00:00:01,000 --> 00:00:02,000\n" "Foo.\n\n" "7\n" "00:00:02,500 --> 00:00:04,000\n" "Baz.\n\n" "2\n" "00:00:05,000 --> 00:00:06,000\n" "Bar.\n")) (expect (point) :to-equal 71))) ) ) (it "when point is on empty text." (with-temp-srt-buffer (insert (concat "1\n" "00:00:01,000 --> 00:00:02,000\n" "\n")) (subed-jump-to-subtitle-text) (expect (subed-srt--append-subtitle) :to-equal 67) (expect (buffer-string) :to-equal (concat "1\n" "00:00:01,000 --> 00:00:02,000\n" "\n\n" "0\n" "00:00:00,000 --> 00:00:01,000\n" "\n")) (expect (point) :to-equal 67))) ) ) (describe "Killing a subtitle" (it "removes the first subtitle." (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-text 1) (subed-srt--kill-subtitle) (expect (buffer-string) :to-equal (concat "2\n" "00:02:02,234 --> 00:02:10,345\n" "Bar.\n\n" "3\n" "00:03:03,45 --> 00:03:15,5\n" "Baz.\n")))) (it "removes it in between." (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-text 2) (subed-srt--kill-subtitle) (expect (buffer-string) :to-equal (concat "1\n" "00:01:01,000 --> 00:01:05,123\n" "Foo.\n\n" "3\n" "00:03:03,45 --> 00:03:15,5\n" "Baz.\n")))) (it "removes the last subtitle." (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-text 3) (subed-srt--kill-subtitle) (expect (buffer-string) :to-equal (concat "1\n" "00:01:01,000 --> 00:01:05,123\n" "Foo.\n\n" "2\n" "00:02:02,234 --> 00:02:10,345\n" "Bar.\n")))) (describe "removes the previous subtitle when point is right above the ID" (it "of the last subtitle." (with-temp-srt-buffer (insert mock-srt-data) (subed-jump-to-subtitle-id 3) (backward-char) (expect (looking-at "^\n3\n") :to-be t) (subed-srt--kill-subtitle) (expect (buffer-string) :to-equal (concat "1\n" "00:01:01,000 --> 00:01:05,123\n" "Foo.\n\n" "3\n" "00:03:03,45 --> 00:03:15,5\n" "Baz.\n")))) (it "of a non-last subtitle." (with-temp-srt-buffer (insert mock-srt-data) (subed-jump-to-subtitle-id 2) (backward-char) (expect (looking-at "^\n2\n") :to-be t) (subed-srt--kill-subtitle) (expect (buffer-string) :to-equal (concat "2\n" "00:02:02,234 --> 00:02:10,345\n" "Bar.\n\n" "3\n" "00:03:03,45 --> 00:03:15,5\n" "Baz.\n")))) ) ) (describe "Validating" (it "works in empty buffer." (with-temp-srt-buffer (subed-srt--validate))) (it "works in buffer that contains only newlines." (with-temp-srt-buffer (cl-loop for _ from 1 to 10 do (insert "\n") (subed-srt--validate)))) (it "works in buffer that contains only spaces." (with-temp-srt-buffer (cl-loop for _ from 1 to 10 do (insert " ") (subed-srt--validate)))) (it "works in buffer that contains only spaces and newlines." (with-temp-srt-buffer (cl-loop for _ from 1 to 10 do (if (eq (random 2) 0) (insert " ") (insert "\n")) (subed-srt--validate)))) (it "reports invalid IDs." (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-id 1) (insert "x") (expect (subed-srt--validate) :to-throw 'error '("Found invalid subtitle ID: \"x1\"")) (expect (point) :to-equal 1))) (it "reports invalid start time." (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-time-start 1) (forward-char 5) (delete-char 1) (expect (subed-srt--validate) :to-throw 'error '("Found invalid start time: \"00:0101,000 --> 00:01:05,123\"")) (expect (point) :to-equal 3))) (it "reports invalid stop time." (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-time-stop 1) (forward-char 10) (insert "3") (expect (subed-srt--validate) :to-throw 'error '("Found invalid stop time: \"00:01:01,000 --> 00:01:05,1323\"")) (expect (point) :to-equal 20))) (it "reports invalid time separator." (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-time-stop 1) (delete-char -1) (expect (subed-srt--validate) :to-throw 'error '("Found invalid separator between start and stop time: \"00:01:01,000 -->00:01:05,123\"")) (expect (point) :to-equal 15))) (it "reports invalid start time in later entries." (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-time-start 3) (forward-char 3) (insert "##") (expect (subed-srt--validate) :to-throw 'error '("Found invalid start time: \"00:##03:03,45 --> 00:03:15,5\"")) (expect (point) :to-equal 79))) (it "does not report error when last subtitle text is empty." (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-text 3) (kill-whole-line) (forward-char -2) (subed-srt--validate) (expect (point) :to-equal 104))) (it "preserves point if there is no error." (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-text 2) (forward-char 2) (subed-srt--validate) (expect (point) :to-equal 73))) ) (describe "Sanitizing" (it "removes trailing tabs and spaces from all lines." (with-temp-srt-buffer (insert mock-srt-data) (goto-char (point-min)) (while (re-search-forward "\n" nil t) (replace-match " \n")) (expect (buffer-string) :not :to-equal mock-srt-data) (subed-srt--sanitize) (expect (buffer-string) :to-equal mock-srt-data)) (with-temp-srt-buffer (insert mock-srt-data) (goto-char (point-min)) (while (re-search-forward "\n" nil t) (replace-match "\t\n")) (expect (buffer-string) :not :to-equal mock-srt-data) (subed-srt--sanitize) (expect (buffer-string) :to-equal mock-srt-data))) (it "removes leading tabs and spaces from all lines." (with-temp-srt-buffer (insert mock-srt-data) (goto-char (point-min)) (while (re-search-forward "\n" nil t) (replace-match "\n ")) (expect (buffer-string) :not :to-equal mock-srt-data) (subed-srt--sanitize) (expect (buffer-string) :to-equal mock-srt-data)) (with-temp-srt-buffer (insert mock-srt-data) (goto-char (point-min)) (while (re-search-forward "\n" nil t) (replace-match "\n\t")) (expect (buffer-string) :not :to-equal mock-srt-data) (subed-srt--sanitize) (expect (buffer-string) :to-equal mock-srt-data))) (it "removes excessive empty lines between subtitles." (with-temp-srt-buffer (insert mock-srt-data) (goto-char (point-min)) (while (re-search-forward "\n\n" nil t) (replace-match "\n \n \t \t\t \n\n \t\n")) (expect (buffer-string) :not :to-equal mock-srt-data) (subed-srt--sanitize) (expect (buffer-string) :to-equal mock-srt-data))) (it "ensures double newline between subtitles if text of previous subtitle is empty." (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-text 1) (kill-whole-line) (expect (buffer-string) :to-equal (concat "1\n" "00:01:01,000 --> 00:01:05,123\n" "\n" "2\n" "00:02:02,234 --> 00:02:10,345\n" "Bar.\n\n" "3\n" "00:03:03,45 --> 00:03:15,5\n" "Baz.\n")) (subed-srt--sanitize) (expect (buffer-string) :to-equal (concat "1\n" "00:01:01,000 --> 00:01:05,123\n" "\n\n" "2\n" "00:02:02,234 --> 00:02:10,345\n" "Bar.\n\n" "3\n" "00:03:03,45 --> 00:03:15,5\n" "Baz.\n")))) (it "removes empty lines from beginning of buffer." (with-temp-srt-buffer (insert mock-srt-data) (goto-char (point-min)) (insert " \n\t\n") (expect (buffer-string) :not :to-equal mock-srt-data) (subed-srt--sanitize) (expect (buffer-string) :to-equal mock-srt-data))) (it "removes empty lines from end of buffer." (with-temp-srt-buffer (insert mock-srt-data) (goto-char (point-max)) (insert " \n\t\n\n") (expect (buffer-string) :not :to-equal mock-srt-data) (subed-srt--sanitize) (expect (buffer-string) :to-equal mock-srt-data))) (it "ensures a single newline after the last subtitle." (with-temp-srt-buffer (insert mock-srt-data) (goto-char (point-max)) (while (eq (char-before (point-max)) ?\n) (delete-backward-char 1)) (expect (buffer-string) :not :to-equal mock-srt-data) (subed-srt--sanitize) (expect (buffer-string) :to-equal mock-srt-data))) (it "ensures single newline after last subtitle if text is empty." (with-temp-srt-buffer (insert mock-srt-data) (subed-srt--jump-to-subtitle-text 3) (kill-whole-line) (expect (buffer-string) :to-equal (concat "1\n" "00:01:01,000 --> 00:01:05,123\n" "Foo.\n\n" "2\n" "00:02:02,234 --> 00:02:10,345\n" "Bar.\n\n" "3\n" "00:03:03,45 --> 00:03:15,5\n" "")) (subed-srt--sanitize) (expect (buffer-string) :to-equal (concat "1\n" "00:01:01,000 --> 00:01:05,123\n" "Foo.\n\n" "2\n" "00:02:02,234 --> 00:02:10,345\n" "Bar.\n\n" "3\n" "00:03:03,45 --> 00:03:15,5\n" "\n")))) (it "ensures single space before and after time separators." (with-temp-srt-buffer (insert mock-srt-data) (goto-char (point-min)) (re-search-forward " --> ") (replace-match " --> ") (re-search-forward " --> ") (replace-match " --> ") (re-search-forward " --> ") (replace-match "-->") (expect (buffer-string) :not :to-equal mock-srt-data) (subed-srt--sanitize) (expect (buffer-string) :to-equal mock-srt-data))) (it "does not insert newline in empty buffer." (with-temp-srt-buffer (expect (buffer-string) :to-equal "") (subed-srt--sanitize) (expect (buffer-string) :to-equal ""))) ) (describe "Renumbering" (it "ensures consecutive subtitle IDs." (with-temp-srt-buffer (insert mock-srt-data) (goto-char (point-min)) (while (looking-at "^[0-9]$") (replace-match "123")) (expect (buffer-string) :not :to-equal mock-srt-data) (subed-srt--regenerate-ids) (expect (buffer-string) :to-equal mock-srt-data))) (it "does not modify the kill-ring." (with-temp-srt-buffer (insert mock-srt-data) (kill-new "asdf") (goto-char (point-min)) (while (looking-at "^[0-9]$") (insert "555")) (subed-srt--regenerate-ids) (expect (car kill-ring) :to-equal "asdf"))) (it "does not modify empty buffer." (with-temp-srt-buffer (subed-srt--regenerate-ids) (expect (buffer-string) :to-equal ""))) ) (describe "Sorting" (it "orders subtitles by start time." (with-temp-srt-buffer (insert mock-srt-data) (goto-char (point-min)) (re-search-forward "01:01") (replace-match "12:01") (goto-char (point-min)) (re-search-forward "02:02") (replace-match "10:02") (goto-char (point-min)) (re-search-forward "03:03") (replace-match "11:03") (subed-srt--sort) (expect (buffer-string) :to-equal (concat "1\n" "00:10:02,234 --> 00:02:10,345\n" "Bar.\n" "\n" "2\n" "00:11:03,45 --> 00:03:15,5\n" "Baz.\n" "\n" "3\n" "00:12:01,000 --> 00:01:05,123\n" "Foo.\n")))) (describe "preserves point in the current subtitle" (it "when subtitle text is non-empty." (with-temp-srt-buffer (insert mock-srt-data) (goto-char (point-min)) (re-search-forward "01:01") (replace-match "12:01") (search-forward "\n") (expect (current-word) :to-equal "Foo") (subed-srt--sort) (expect (current-word) :to-equal "Foo"))) (it "when subtitle text is empty." (with-temp-srt-buffer (insert "1\n00:12:01,000 --> 00:01:05,123\n") (goto-char (point-max)) (subed-srt--sort) (expect (point) :to-equal 33))) ) ) subed-master/tests/test-subed-vtt.el000066400000000000000000001563251401667552300200540ustar00rootroot00000000000000;; -*- eval: (buttercup-minor-mode) -*- (add-to-list 'load-path "./subed") (require 'subed) (defvar mock-vtt-data "WEBVTT 00:01:01.000 --> 00:01:05.123 Foo. 00:02:02.234 --> 00:02:10.345 Bar. 00:03:03.45 --> 00:03:15.5 Baz. ") (defmacro with-temp-vtt-buffer (&rest body) "Call `subed-vtt--init' in temporary buffer before running BODY." `(with-temp-buffer (subed-vtt--init) (progn ,@body))) (describe "VTT" (describe "Getting" (describe "the subtitle start/stop time" (it "returns the time in milliseconds." (with-temp-vtt-buffer (insert mock-vtt-data) (subed-vtt--jump-to-subtitle-id "00:02:02.234") (expect (subed-vtt--subtitle-msecs-start) :to-equal (+ (* 2 60000) (* 2 1000) 234)) (expect (subed-vtt--subtitle-msecs-stop) :to-equal (+ (* 2 60000) (* 10 1000) 345)))) (it "handles lack of digits in milliseconds gracefully." (with-temp-vtt-buffer (insert mock-vtt-data) (subed-vtt--jump-to-subtitle-id "00:03:03.45") (expect (save-excursion (subed-jump-to-subtitle-time-start) (thing-at-point 'line)) :to-equal "00:03:03.45 --> 00:03:15.5\n") (expect (subed-vtt--subtitle-msecs-start) :to-equal (+ (* 3 60 1000) (* 3 1000) 450)) (expect (subed-vtt--subtitle-msecs-stop) :to-equal (+ (* 3 60 1000) (* 15 1000) 500)))) (it "returns nil if time can't be found." (with-temp-vtt-buffer (expect (subed-vtt--subtitle-msecs-start) :to-be nil) (expect (subed-vtt--subtitle-msecs-stop) :to-be nil))) ) (describe "the subtitle text" (describe "when text is empty" (it "and at the beginning with a trailing newline." (with-temp-vtt-buffer (insert mock-vtt-data) (subed-vtt--jump-to-subtitle-text "00:01:01.000") (kill-line) (expect (subed-vtt--subtitle-text) :to-equal ""))) (it "and at the beginning without a trailing newline." (with-temp-vtt-buffer (insert mock-vtt-data) (subed-vtt--jump-to-subtitle-text "00:01:01.000") (kill-whole-line) (expect (subed-vtt--subtitle-text) :to-equal ""))) (it "and in the middle." (with-temp-vtt-buffer (insert mock-vtt-data) (subed-vtt--jump-to-subtitle-text "00:02:02.234") (kill-line) (expect (subed-vtt--subtitle-text) :to-equal ""))) (it "and at the end with a trailing newline." (with-temp-vtt-buffer (insert mock-vtt-data) (subed-vtt--jump-to-subtitle-text "00:03:03.45") (kill-line) (expect (subed-vtt--subtitle-text) :to-equal ""))) (it "and at the end without a trailing newline." (with-temp-vtt-buffer (insert mock-vtt-data) (subed-vtt--jump-to-subtitle-text "00:03:03.45") (kill-whole-line) (expect (subed-vtt--subtitle-text) :to-equal ""))) ) (describe "when text is not empty" (it "and has no linebreaks." (with-temp-vtt-buffer (insert mock-vtt-data) (subed-vtt--jump-to-subtitle-text "00:02:02.234") (expect (subed-vtt--subtitle-text) :to-equal "Bar."))) (it "and has linebreaks." (with-temp-vtt-buffer (insert mock-vtt-data) (subed-vtt--jump-to-subtitle-text "00:02:02.234") (insert "Bar.\n") (expect (subed-vtt--subtitle-text) :to-equal "Bar.\nBar."))) ) ) (describe "the point within the subtitle" (it "returns the relative point if we can find an ID." (with-temp-vtt-buffer (insert mock-vtt-data) (subed-vtt--jump-to-subtitle-id "00:02:02.234") (expect (subed-vtt--subtitle-relative-point) :to-equal 0) (forward-line) (expect (subed-vtt--subtitle-relative-point) :to-equal 30) (forward-char) (expect (subed-vtt--subtitle-relative-point) :to-equal 31) (forward-line) (expect (subed-vtt--subtitle-relative-point) :to-equal 35) (forward-line) (expect (subed-vtt--subtitle-relative-point) :to-equal 0))) (it "returns nil if we can't find an ID." (with-temp-vtt-buffer (insert mock-vtt-data) (subed-vtt--jump-to-subtitle-id "00:01:01.000") (insert "foo") (expect (subed-vtt--subtitle-relative-point) :to-equal nil))) ) ) (describe "Jumping" (describe "to current subtitle timestamp" (it "returns timestamp's point when point is already on the timestamp." (with-temp-vtt-buffer (insert mock-vtt-data) (goto-char (point-min)) (subed-vtt--jump-to-subtitle-id "00:01:01.000") (expect (subed-vtt--jump-to-subtitle-time-start) :to-equal (point)) (expect (looking-at subed-vtt--regexp-timestamp) :to-be t) (expect (match-string 0) :to-equal "00:01:01.000"))) (it "returns timestamp's point when point is on the text." (with-temp-vtt-buffer (insert mock-vtt-data) (search-backward "Baz.") (expect (thing-at-point 'word) :to-equal "Baz") (expect (subed-vtt--jump-to-subtitle-time-start) :to-equal 81) (expect (looking-at subed-vtt--regexp-timestamp) :to-be t) (expect (match-string 0) :to-equal "00:03:03.45"))) (it "returns timestamp's point when point is between subtitles." (with-temp-vtt-buffer (insert mock-vtt-data) (goto-char (point-min)) (search-forward "Bar.\n") (expect (thing-at-point 'line) :to-equal "\n") (expect (subed-vtt--jump-to-subtitle-time-start) :to-equal 45) (expect (looking-at subed-vtt--regexp-timestamp) :to-be t) (expect (match-string 0) :to-equal "00:02:02.234"))) (it "returns nil if buffer is empty." (with-temp-vtt-buffer (expect (buffer-string) :to-equal "") (expect (subed-vtt--jump-to-subtitle-time-start) :to-equal nil))) (it "returns timestamp's point when buffer starts with blank lines." (with-temp-vtt-buffer (insert (concat "WEBVTT \n \t \n" (replace-regexp-in-string "WEBVTT" "" mock-vtt-data))) (search-backward "Foo.") (expect (thing-at-point 'line) :to-equal "Foo.\n") (expect (subed-vtt--jump-to-subtitle-time-start) :to-equal 15) (expect (looking-at subed-vtt--regexp-timestamp) :to-be t) (expect (match-string 0) :to-equal "00:01:01.000"))) (it "returns timestamp's point when subtitles are separated with blank lines." (with-temp-vtt-buffer (insert mock-vtt-data) (goto-char (point-min)) (search-forward "Foo.\n") (insert " \n \t \n") (expect (subed-vtt--jump-to-subtitle-time-start) :to-equal 9) (expect (looking-at subed-vtt--regexp-timestamp) :to-be t) (expect (match-string 0) :to-equal "00:01:01.000"))) ) (describe "to specific subtitle by timestamp" (it "returns timestamp's point if wanted time exists." (with-temp-vtt-buffer (insert mock-vtt-data) (goto-char (point-max)) (expect (subed-vtt--jump-to-subtitle-id "00:02:02.234") :to-equal 45) (expect (looking-at (regexp-quote "00:02:02.234")) :to-be t) (expect (subed-vtt--jump-to-subtitle-id "00:01:01.000") :to-equal 9) (expect (looking-at (regexp-quote "00:01:01.000")) :to-be t))) (it "returns nil and does not move if wanted ID does not exists." (with-temp-vtt-buffer (insert mock-vtt-data) (goto-char (point-min)) (search-forward "Foo") (let ((stored-point (point))) (expect (subed-vtt--jump-to-subtitle-id "0:08:00") :to-equal nil) (expect stored-point :to-equal (point))))) ) (describe "to subtitle start time" (it "returns start time's point if movement was successful." (with-temp-vtt-buffer (insert mock-vtt-data) (goto-char (point-min)) (expect (subed-vtt--jump-to-subtitle-time-start) :to-equal 9) (expect (looking-at subed-vtt--regexp-timestamp) :to-be t) (expect (match-string 0) :to-equal "00:01:01.000") (re-search-forward "\n\n") (expect (subed-vtt--jump-to-subtitle-time-start) :to-equal 45) (expect (looking-at subed-vtt--regexp-timestamp) :to-be t) (expect (match-string 0) :to-equal "00:02:02.234") (re-search-forward "\n\n") (expect (subed-vtt--jump-to-subtitle-time-start) :to-equal 81) (expect (looking-at subed-vtt--regexp-timestamp) :to-be t) (expect (match-string 0) :to-equal "00:03:03.45"))) (it "returns nil if movement failed." (with-temp-vtt-buffer (expect (subed-vtt--jump-to-subtitle-time-start) :to-equal nil))) ) (describe "to subtitle stop time" (it "returns stop time's point if movement was successful." (with-temp-vtt-buffer (insert mock-vtt-data) (goto-char (point-min)) (expect (subed-vtt--jump-to-subtitle-time-stop) :to-equal 26) (expect (looking-at subed-vtt--regexp-timestamp) :to-be t) (expect (match-string 0) :to-equal "00:01:05.123") (re-search-forward "\n\n") (expect (subed-vtt--jump-to-subtitle-time-stop) :to-equal 62) (expect (looking-at subed-vtt--regexp-timestamp) :to-be t) (expect (match-string 0) :to-equal "00:02:10.345") (re-search-forward "\n\n") (expect (subed-vtt--jump-to-subtitle-time-stop) :to-equal 97) (expect (looking-at subed-vtt--regexp-timestamp) :to-be t) (expect (match-string 0) :to-equal "00:03:15.5"))) (it "returns nil if movement failed." (with-temp-vtt-buffer (expect (subed-vtt--jump-to-subtitle-time-stop) :to-equal nil))) ) (describe "to subtitle text" (it "returns subtitle text's point if movement was successful." (with-temp-vtt-buffer (insert mock-vtt-data) (goto-char (point-min)) (expect (subed-vtt--jump-to-subtitle-text) :to-equal 39) (expect (point) :to-equal (save-excursion (goto-char (point-max)) (search-backward "Foo."))) (re-search-forward "\n\n") (expect (subed-vtt--jump-to-subtitle-text) :to-equal 75) (expect (point) :to-equal (save-excursion (goto-char (point-max)) (search-backward "Bar."))) (re-search-forward "\n\n") (expect (subed-vtt--jump-to-subtitle-text) :to-equal 108) (expect (point) :to-equal (save-excursion (goto-char (point-max)) (search-backward "Baz."))))) (it "returns nil if movement failed." (with-temp-vtt-buffer (expect (subed-vtt--jump-to-subtitle-time-stop) :to-equal nil))) ) (describe "to end of subtitle text" (it "returns point if subtitle end can be found." (with-temp-vtt-buffer (insert mock-vtt-data) (goto-char (point-min)) (expect (subed-vtt--jump-to-subtitle-end) :to-be 43) (expect (looking-back "^Foo.$") :to-be t) (forward-char 2) (expect (subed-vtt--jump-to-subtitle-end) :to-be 79) (expect (looking-back "^Bar.$") :to-be t) (forward-char 2) (expect (subed-vtt--jump-to-subtitle-end) :to-be 112) (expect (looking-back "^Baz.$") :to-be t) (goto-char (point-max)) (backward-char 2) (expect (subed-vtt--jump-to-subtitle-end) :to-be 112) (expect (looking-back "^Baz.$") :to-be t))) (it "returns nil if subtitle end cannot be found." (with-temp-vtt-buffer (expect (subed-vtt--jump-to-subtitle-end) :to-be nil))) (it "returns nil if point did not move." (with-temp-vtt-buffer (insert mock-vtt-data) (subed-vtt--jump-to-subtitle-text "00:01:01.000") (kill-line) (expect (subed-vtt--jump-to-subtitle-end) :to-be nil))) (it "works if text is empty with trailing newline." (with-temp-vtt-buffer (insert mock-vtt-data) (subed-vtt--jump-to-subtitle-text "00:01:01.000") (kill-line) (backward-char) (expect (subed-vtt--jump-to-subtitle-end) :to-be 39) (expect (looking-at "^$") :to-be t) (subed-vtt--jump-to-subtitle-text "00:02:02.234") (kill-line) (backward-char) (expect (subed-vtt--jump-to-subtitle-end) :to-be 71) (expect (looking-at "^$") :to-be t) (subed-vtt--jump-to-subtitle-text "00:03:03.45") (kill-line) (backward-char) (expect (subed-vtt--jump-to-subtitle-end) :to-be 100) (expect (looking-at "^$") :to-be t))) (it "works if text is empty without trailing newline." (with-temp-vtt-buffer (insert mock-vtt-data) (subed-vtt--jump-to-subtitle-text "00:01:01.000") (kill-whole-line) (expect (subed-vtt--jump-to-subtitle-end) :to-be nil) (expect (looking-at "^$") :to-be t) (goto-char (point-min)) (expect (subed-vtt--jump-to-subtitle-end) :to-be 39) (expect (looking-at "^$") :to-be t) (subed-vtt--jump-to-subtitle-text "00:02:02.234") (kill-whole-line) (expect (subed-vtt--jump-to-subtitle-end) :to-be nil) (expect (looking-at "^$") :to-be t) (backward-char) (expect (subed-vtt--jump-to-subtitle-end) :to-be 70) (expect (looking-at "^$") :to-be t) (subed-vtt--jump-to-subtitle-text "00:03:03.45") (kill-whole-line) (expect (subed-vtt--jump-to-subtitle-end) :to-be nil) (expect (looking-at "^$") :to-be t) (backward-char) (expect (subed-vtt--jump-to-subtitle-end) :to-be 98) (expect (looking-at "^$") :to-be t))) ) (describe "to next subtitle ID" (it "returns point when there is a next subtitle." (with-temp-vtt-buffer (insert mock-vtt-data) (subed-vtt--jump-to-subtitle-id "00:01:01.000") (expect (looking-at (regexp-quote "00:01:01.000")) :to-be t) (expect (subed-vtt--forward-subtitle-id) :to-be 45) (expect (looking-at (regexp-quote "00:02:02.234")) :to-be t) (subed-vtt--jump-to-subtitle-time-start "00:02:02.234") (expect (looking-at (regexp-quote "00:02:02.234")) :to-be t) (expect (subed-vtt--forward-subtitle-id) :to-be 81) (expect (looking-at (regexp-quote "00:03:03.45")) :to-be t))) (it "returns nil and doesn't move when there is no next subtitle." (with-temp-vtt-buffer (expect (thing-at-point 'word) :to-equal nil) (expect (subed-vtt--forward-subtitle-id) :to-be nil)) (with-temp-vtt-buffer (insert mock-vtt-data) (subed-vtt--jump-to-subtitle-text "00:01:01.000") (expect (thing-at-point 'word) :to-equal "Foo") (expect (subed-vtt--forward-subtitle-id) :to-be 45) (expect (looking-at (regexp-quote "00:02:02.234")) :to-be t) (subed-vtt--jump-to-subtitle-time-stop "00:02:02.234") (expect (looking-at (regexp-quote "00:02:10.345")) :to-be t) (expect (subed-vtt--forward-subtitle-id) :to-be 81) (expect (looking-at (regexp-quote "00:03:03.45")) :to-be t)) (with-temp-vtt-buffer (insert mock-vtt-data) (subed-vtt--jump-to-subtitle-text "00:03:03.45") (expect (thing-at-point 'word) :to-equal "Baz") (expect (subed-vtt--forward-subtitle-id) :to-be nil) (expect (thing-at-point 'word) :to-equal "Baz")) (with-temp-vtt-buffer (insert (concat mock-vtt-data "\n\n")) (subed-vtt--jump-to-subtitle-time-stop "00:03:03.45") (expect (thing-at-point 'word) :to-equal "00") (expect (subed-vtt--forward-subtitle-id) :to-be nil) (expect (thing-at-point 'word) :to-equal "00"))) ) (describe "to previous subtitle ID" (it "returns point when there is a previous subtitle." (with-temp-vtt-buffer (insert mock-vtt-data) (subed-vtt--jump-to-subtitle-text "00:02:02.234") (expect (thing-at-point 'word) :to-equal "Bar") (expect (subed-vtt--backward-subtitle-id) :to-be 9) (expect (looking-at (regexp-quote "00:01:01.000")) :to-be t) (subed-vtt--jump-to-subtitle-time-stop "00:03:03.45") (expect (looking-at (regexp-quote "00:03:15.5")) :to-be t) (expect (subed-vtt--backward-subtitle-id) :to-be 45) (expect (looking-at (regexp-quote "00:02:02.234")) :to-be t))) (it "returns nil and doesn't move when there is no previous subtitle." (with-temp-vtt-buffer (expect (subed-vtt--backward-subtitle-id) :to-be nil)) (with-temp-vtt-buffer (insert mock-vtt-data) (subed-vtt--jump-to-subtitle-id "00:01:01.000") (expect (looking-at (regexp-quote "00:01:01.000")) :to-be t) (expect (subed-vtt--backward-subtitle-id) :to-be nil) (expect (looking-at (regexp-quote "00:01:01.000")) :to-be t)) (with-temp-vtt-buffer (insert mock-vtt-data) (subed-vtt--jump-to-subtitle-text "00:01:01.000") (expect (thing-at-point 'word) :to-equal "Foo") (expect (subed-vtt--backward-subtitle-id) :to-be nil) (expect (thing-at-point 'word) :to-equal "Foo")) (with-temp-vtt-buffer (insert (concat "\n\n\n" mock-vtt-data)) (subed-vtt--jump-to-subtitle-time-stop "00:01:01.000") (expect (thing-at-point 'word) :to-equal "00") (expect (subed-vtt--backward-subtitle-id) :to-be nil) (expect (thing-at-point 'word) :to-equal "00"))) ) (describe "to next subtitle text" (it "returns point when there is a next subtitle." (with-temp-vtt-buffer (insert mock-vtt-data) (subed-vtt--jump-to-subtitle-id "00:01:01.000") (expect (looking-at (regexp-quote "00:01:01.000")) :to-be t) (expect (subed-vtt--forward-subtitle-text) :to-be 75) (expect (thing-at-point 'word) :to-equal "Bar"))) (it "returns nil and doesn't move when there is no next subtitle." (with-temp-vtt-buffer (goto-char (point-max)) (insert (concat mock-vtt-data "\n\n")) (subed-vtt--jump-to-subtitle-id "00:03:03.45") (expect (looking-at (regexp-quote "00:03:03.45")) :to-be t) (expect (subed-vtt--forward-subtitle-text) :to-be nil) (expect (looking-at (regexp-quote "00:03:03.45")) :to-be t))) ) (describe "to previous subtitle text" (it "returns point when there is a previous subtitle." (with-temp-vtt-buffer (insert mock-vtt-data) (subed-vtt--jump-to-subtitle-id "00:03:03.45") (expect (looking-at (regexp-quote "00:03:03.45")) :to-be t) (expect (subed-vtt--backward-subtitle-text) :to-be 75) (expect (thing-at-point 'word) :to-equal "Bar"))) (it "returns nil and doesn't move when there is no previous subtitle." (with-temp-vtt-buffer (insert mock-vtt-data) (goto-char (point-min)) (subed-vtt--forward-subtitle-time-start) (expect (looking-at (regexp-quote "00:01:01.000")) :to-be t) (expect (subed-vtt--backward-subtitle-text) :to-be nil) (expect (looking-at (regexp-quote "00:01:01.000")) :to-be t))) ) (describe "to next subtitle end" (it "returns point when there is a next subtitle." (with-temp-vtt-buffer (insert mock-vtt-data) (subed-vtt--jump-to-subtitle-text "00:02:02.234") (expect (thing-at-point 'word) :to-equal "Bar") (expect (subed-vtt--forward-subtitle-end) :to-be 112) (expect (thing-at-point 'word) :to-equal nil))) (it "returns nil and doesn't move when there is no next subtitle." (with-temp-vtt-buffer (insert (concat mock-vtt-data "\n\n")) (subed-vtt--jump-to-subtitle-text "00:03:03.45") (end-of-line) (expect (thing-at-point 'word) :to-equal nil) (expect (subed-vtt--forward-subtitle-end) :to-be nil) (expect (thing-at-point 'word) :to-equal nil))) ) (describe "to previous subtitle end" (it "returns point when there is a previous subtitle." (with-temp-vtt-buffer (insert mock-vtt-data) (subed-vtt--jump-to-subtitle-id "00:03:03.45") (expect (looking-at (regexp-quote "00:03:03.45")) :to-be t) (expect (subed-vtt--backward-subtitle-text) :to-be 75) (expect (thing-at-point 'word) :to-equal "Bar"))) (it "returns nil and doesn't move when there is no previous subtitle." (with-temp-vtt-buffer (insert mock-vtt-data) (goto-char (point-min)) (subed-vtt--forward-subtitle-id) (expect (looking-at (regexp-quote "00:01:01.000")) :to-be t) (expect (subed-vtt--backward-subtitle-text) :to-be nil) (expect (looking-at (regexp-quote "00:01:01.000")) :to-be t))) ) (describe "to next subtitle start time" (it "returns point when there is a next subtitle." (with-temp-vtt-buffer (insert mock-vtt-data) (subed-vtt--jump-to-subtitle-text "00:01:01.000") (expect (thing-at-point 'word) :to-equal "Foo") (expect (subed-vtt--forward-subtitle-time-start) :to-be 45) (expect (looking-at (regexp-quote "00:02:02.234")) :to-be t))) (it "returns nil and doesn't move when there is no next subtitle." (with-temp-vtt-buffer (insert mock-vtt-data) (subed-vtt--jump-to-subtitle-id "00:03:03.45") (expect (looking-at (regexp-quote "00:03:03.45")) :to-be t) (expect (subed-vtt--forward-subtitle-time-start) :to-be nil) (expect (looking-at (regexp-quote "00:03:03.45")) :to-be t))) ) (describe "to previous subtitle start time" (it "returns point when there is a previous subtitle." (with-temp-vtt-buffer (insert mock-vtt-data) (subed-vtt--jump-to-subtitle-id "00:02:02.234") (expect (looking-at (regexp-quote "00:02:02.234")) :to-be t) (expect (subed-vtt--backward-subtitle-time-start) :to-be 9) (expect (looking-at (regexp-quote "00:01:01.000")) :to-be t))) (it "returns nil and doesn't move when there is no previous subtitle." (with-temp-vtt-buffer (insert mock-vtt-data) (subed-vtt--jump-to-subtitle-id "00:01:01.000") (expect (looking-at (regexp-quote "00:01:01.000")) :to-be t) (expect (subed-vtt--backward-subtitle-time-start) :to-be nil) (expect (looking-at (regexp-quote "00:01:01.000")) :to-be t))) ) (describe "to next subtitle stop time" (it "returns point when there is a next subtitle." (with-temp-vtt-buffer (insert mock-vtt-data) (subed-vtt--jump-to-subtitle-text "00:01:01.000") (expect (thing-at-point 'word) :to-equal "Foo") (expect (subed-vtt--forward-subtitle-time-stop) :to-be 62) (expect (looking-at (regexp-quote "00:02:10.345")) :to-be t))) (it "returns nil and doesn't move when there is no next subtitle." (with-temp-vtt-buffer (insert mock-vtt-data) (subed-vtt--jump-to-subtitle-id "00:03:03.45") (expect (looking-at (regexp-quote "00:03:03.45")) :to-be t) (expect (subed-vtt--forward-subtitle-time-stop) :to-be nil) (expect (looking-at (regexp-quote "00:03:03.45")) :to-be t))) ) (describe "to previous subtitle stop time" (it "returns point when there is a previous subtitle." (with-temp-vtt-buffer (insert mock-vtt-data) (subed-vtt--jump-to-subtitle-id "00:03:03.45") (expect (looking-at (regexp-quote "00:03:03.45")) :to-be t) (expect (subed-vtt--backward-subtitle-time-stop) :to-be 62) (expect (looking-at (regexp-quote "00:02:10.345")) :to-be t))) (it "returns nil and doesn't move when there is no previous subtitle." (with-temp-vtt-buffer (insert mock-vtt-data) (subed-vtt--jump-to-subtitle-id "00:01:01.000") (expect (looking-at (regexp-quote "00:01:01.000")) :to-be t) (expect (subed-vtt--backward-subtitle-time-stop) :to-be nil) (expect (looking-at (regexp-quote "00:01:01.000")) :to-be t))) ) ) (describe "Setting start/stop time" (it "of current subtitle." (with-temp-vtt-buffer (insert mock-vtt-data) (subed-vtt--jump-to-subtitle-end "00:02:02.234") (subed-vtt--set-subtitle-time-start (+ (* 1 60 60 1000) (* 2 60 1000) (* 3 1000) 400)) (expect (buffer-string) :to-equal (concat "WEBVTT\n\n" "00:01:01.000 --> 00:01:05.123\n" "Foo.\n\n" "01:02:03.400 --> 00:02:10.345\n" "Bar.\n\n" "00:03:03.45 --> 00:03:15.5\n" "Baz.\n")) (subed-vtt--set-subtitle-time-stop (+ (* 5 60 60 1000) (* 6 60 1000) (* 7 1000) 800)) (expect (buffer-string) :to-equal (concat "WEBVTT\n\n" "00:01:01.000 --> 00:01:05.123\n" "Foo.\n\n" "01:02:03.400 --> 05:06:07.800\n" "Bar.\n\n" "00:03:03.45 --> 00:03:15.5\n" "Baz.\n")))) (it "of specific subtitle." (with-temp-vtt-buffer (insert mock-vtt-data) (subed-vtt--jump-to-subtitle-time-stop "00:01:01.000") (subed-vtt--set-subtitle-time-start (+ (* 2 60 60 1000) (* 4 60 1000) (* 6 1000) 800) 1) (expect (buffer-string) :to-equal (concat "WEBVTT\n\n" "02:04:06.800 --> 00:01:05.123\n" "Foo.\n\n" "00:02:02.234 --> 00:02:10.345\n" "Bar.\n\n" "00:03:03.45 --> 00:03:15.5\n" "Baz.\n")) (subed-vtt--jump-to-subtitle-text "00:03:03.45") (subed-vtt--set-subtitle-time-stop (+ (* 3 60 60 1000) (* 5 60 1000) (* 7 1000) 900) 3) (expect (buffer-string) :to-equal (concat "WEBVTT\n\n" "02:04:06.800 --> 00:01:05.123\n" "Foo.\n\n" "00:02:02.234 --> 00:02:10.345\n" "Bar.\n\n" "00:03:03.45 --> 03:05:07.900\n" "Baz.\n")))) (it "when milliseconds lack digits." (with-temp-vtt-buffer (insert mock-vtt-data) (subed-jump-to-subtitle-id "00:03:03.45") (subed-vtt--set-subtitle-time-start (+ (* 1 60 60 1000) (* 2 60 1000) (* 3 1000) 4) 3) (expect (save-excursion (subed-jump-to-subtitle-time-start) (thing-at-point 'line)) :to-equal "01:02:03.004 --> 00:03:15.5\n") (subed-vtt--set-subtitle-time-stop (+ (* 2 60 60 1000) (* 3 60 1000) (* 4 1000) 60) 3) (expect (save-excursion (subed-jump-to-subtitle-time-start) (thing-at-point 'line)) :to-equal "01:02:03.004 --> 02:03:04.060\n"))) ) (describe "Inserting a subtitle" (describe "in an empty buffer" (describe "before" (it "passing nothing." (with-temp-vtt-buffer (expect (subed-vtt--prepend-subtitle) :to-equal 31) (expect (buffer-string) :to-equal (concat "00:00:00.000 --> 00:00:01.000\n\n")) (expect (point) :to-equal 31))) (it "passing start time." (with-temp-vtt-buffer (expect (subed-vtt--prepend-subtitle nil 60000) :to-equal 31) (expect (buffer-string) :to-equal (concat "00:01:00.000 --> 00:01:01.000\n\n")) (expect (point) :to-equal 31))) (it "passing start time and stop time." (with-temp-vtt-buffer (expect (subed-vtt--prepend-subtitle nil 60000 65000) :to-equal 31) (expect (buffer-string) :to-equal (concat "00:01:00.000 --> 00:01:05.000\n\n")) (expect (point) :to-equal 31))) (it "passing start time, stop time and text." (with-temp-vtt-buffer (expect (subed-vtt--prepend-subtitle nil 60000 65000 "Foo. bar\nbaz.") :to-equal 31) (expect (buffer-string) :to-equal (concat "00:01:00.000 --> 00:01:05.000\n" "Foo. bar\nbaz.\n")) (expect (point) :to-equal 31))) ) (describe "after" (it "passing nothing." (with-temp-vtt-buffer (expect (subed-vtt--append-subtitle) :to-equal 31) (expect (buffer-string) :to-equal (concat "00:00:00.000 --> 00:00:01.000\n\n")) (expect (point) :to-equal 31))) (it "passing start time." (with-temp-vtt-buffer (expect (subed-vtt--append-subtitle nil 60000) :to-equal 31) (expect (buffer-string) :to-equal (concat "00:01:00.000 --> 00:01:01.000\n\n")) (expect (point) :to-equal 31))) (it "passing start time and stop time." (with-temp-vtt-buffer (expect (subed-vtt--append-subtitle nil 60000 65000) :to-equal 31) (expect (buffer-string) :to-equal (concat "00:01:00.000 --> 00:01:05.000\n\n")) (expect (point) :to-equal 31))) (it "passing start time, stop time and text." (with-temp-vtt-buffer (expect (subed-vtt--append-subtitle nil 60000 65000 "Foo, bar\nbaz.") :to-equal 31) (expect (buffer-string) :to-equal (concat "00:01:00.000 --> 00:01:05.000\n" "Foo, bar\nbaz.\n")) (expect (point) :to-equal 31))) ) ) (describe "in a non-empty buffer" (describe "before the current subtitle" (describe "with point on the first subtitle" (it "passing nothing." (with-temp-vtt-buffer (insert (concat "00:00:05.000 --> 00:00:06.000\n" "Foo.\n")) (subed-vtt--jump-to-subtitle-time-stop) (expect (subed-vtt--prepend-subtitle) :to-equal 31) (expect (buffer-string) :to-equal (concat "00:00:00.000 --> 00:00:01.000\n" "\n\n" "00:00:05.000 --> 00:00:06.000\n" "Foo.\n")) (expect (point) :to-equal 31))) (it "passing start time." (with-temp-vtt-buffer (insert (concat "00:00:05.000 --> 00:00:06.000\n" "Foo.\n")) (subed-vtt--jump-to-subtitle-time-stop) (expect (subed-vtt--prepend-subtitle nil 1500) :to-equal 31) (expect (buffer-string) :to-equal (concat "00:00:01.500 --> 00:00:02.500\n" "\n\n" "00:00:05.000 --> 00:00:06.000\n" "Foo.\n")) (expect (point) :to-equal 31))) (it "passing start time and stop time." (with-temp-vtt-buffer (insert (concat "00:00:05.000 --> 00:00:06.000\n" "Foo.\n")) (subed-vtt--jump-to-subtitle-time-stop) (expect (subed-vtt--prepend-subtitle nil 1500 2000) :to-equal 31) (expect (buffer-string) :to-equal (concat "00:00:01.500 --> 00:00:02.000\n" "\n\n" "00:00:05.000 --> 00:00:06.000\n" "Foo.\n")) (expect (point) :to-equal 31))) (it "passing start time, stop time and text." (with-temp-vtt-buffer (insert (concat "00:00:05.000 --> 00:00:06.000\n" "Foo.\n")) (subed-vtt--jump-to-subtitle-time-stop) (expect (subed-vtt--prepend-subtitle nil 1500 3000 "Bar.") :to-equal 31) (expect (buffer-string) :to-equal (concat "00:00:01.500 --> 00:00:03.000\n" "Bar.\n\n" "00:00:05.000 --> 00:00:06.000\n" "Foo.\n")) (expect (point) :to-equal 31))) ) (describe "with point on a non-first subtitle" (it "passing nothing." (with-temp-vtt-buffer (insert (concat "00:00:05.000 --> 00:00:06.000\n" "Foo.\n\n" "00:00:10.000 --> 00:00:12.000\n" "Bar.\n")) (subed-vtt--jump-to-subtitle-text "00:00:10.000") (expect (subed-vtt--prepend-subtitle) :to-equal 67) (expect (buffer-string) :to-equal (concat "00:00:05.000 --> 00:00:06.000\n" "Foo.\n\n" "00:00:00.000 --> 00:00:01.000\n" "\n\n" "00:00:10.000 --> 00:00:12.000\n" "Bar.\n")) (expect (point) :to-equal 67))) (it "passing start time." (with-temp-vtt-buffer (insert (concat "00:00:05.000 --> 00:00:06.000\n" "Foo.\n\n" "00:00:10.000 --> 00:00:12.000\n" "Bar.\n")) (subed-vtt--jump-to-subtitle-text "00:00:10.000") (expect (subed-vtt--prepend-subtitle nil 7000) :to-equal 67) (expect (buffer-string) :to-equal (concat "00:00:05.000 --> 00:00:06.000\n" "Foo.\n\n" "00:00:07.000 --> 00:00:08.000\n" "\n\n" "00:00:10.000 --> 00:00:12.000\n" "Bar.\n")) (expect (point) :to-equal 67))) (it "passing start time and stop time." (with-temp-vtt-buffer (insert (concat "00:00:05.000 --> 00:00:06.000\n" "Foo.\n\n" "00:00:10.000 --> 00:00:12.000\n" "Bar.\n")) (subed-vtt--jump-to-subtitle-text "00:00:10.000") (expect (subed-vtt--prepend-subtitle nil 7000 7123) :to-equal 67) (expect (buffer-string) :to-equal (concat "00:00:05.000 --> 00:00:06.000\n" "Foo.\n\n" "00:00:07.000 --> 00:00:07.123\n" "\n\n" "00:00:10.000 --> 00:00:12.000\n" "Bar.\n")) (expect (point) :to-equal 67))) (it "passing start time, stop time and text." (with-temp-vtt-buffer (insert (concat "00:00:05.000 --> 00:00:06.000\n" "Foo.\n\n" "00:00:10.000 --> 00:00:12.000\n" "Bar.\n")) (subed-vtt--jump-to-subtitle-text "00:00:10.000") (expect (subed-vtt--prepend-subtitle nil 7000 7123 "Baz.") :to-equal 67) (expect (buffer-string) :to-equal (concat "00:00:05.000 --> 00:00:06.000\n" "Foo.\n\n" "00:00:07.000 --> 00:00:07.123\n" "Baz.\n\n" "00:00:10.000 --> 00:00:12.000\n" "Bar.\n")) (expect (point) :to-equal 67))) ) ) (describe "after the current subtitle" (describe "with point on the last subtitle" (it "passing nothing." (with-temp-vtt-buffer (insert (concat "00:00:05.000 --> 00:00:06.000\n" "Foo.\n")) (subed-vtt--jump-to-subtitle-text) (expect (subed-vtt--append-subtitle) :to-equal 67) (expect (buffer-string) :to-equal (concat "00:00:05.000 --> 00:00:06.000\n" "Foo.\n\n" "00:00:00.000 --> 00:00:01.000\n" "\n")) (expect (point) :to-equal 67))) (it "passing start time." (with-temp-vtt-buffer (insert (concat "00:00:05.000 --> 00:00:06.000\n" "Foo.\n")) (subed-vtt--jump-to-subtitle-text) (expect (subed-vtt--append-subtitle nil 12345) :to-equal 67) (expect (buffer-string) :to-equal (concat "00:00:05.000 --> 00:00:06.000\n" "Foo.\n\n" "00:00:12.345 --> 00:00:13.345\n" "\n")) (expect (point) :to-equal 67))) (it "passing start time and stop time." (with-temp-vtt-buffer (insert (concat "00:00:05.000 --> 00:00:06.000\n" "Foo.\n")) (subed-vtt--jump-to-subtitle-text) (expect (subed-vtt--append-subtitle nil 12345 15000) :to-equal 67) (expect (buffer-string) :to-equal (concat "00:00:05.000 --> 00:00:06.000\n" "Foo.\n\n" "00:00:12.345 --> 00:00:15.000\n" "\n")) (expect (point) :to-equal 67))) (it "passing start time, stop time and text." (with-temp-vtt-buffer (insert (concat "00:00:05.000 --> 00:00:06.000\n" "Foo.\n")) (subed-vtt--jump-to-subtitle-text) (expect (subed-vtt--append-subtitle nil 12345 15000 "Bar.") :to-equal 67) (expect (buffer-string) :to-equal (concat "00:00:05.000 --> 00:00:06.000\n" "Foo.\n\n" "00:00:12.345 --> 00:00:15.000\n" "Bar.\n")) (expect (point) :to-equal 67))) ) (describe "with point on a non-last subtitle" (it "passing nothing." (with-temp-vtt-buffer (insert (concat "00:00:01.000 --> 00:00:02.000\n" "Foo.\n\n" "00:00:05.000 --> 00:00:06.000\n" "Bar.\n")) (subed-vtt--jump-to-subtitle-time-start "00:00:01.000") (expect (subed-vtt--append-subtitle) :to-equal 67) (expect (buffer-string) :to-equal (concat "00:00:01.000 --> 00:00:02.000\n" "Foo.\n\n" "00:00:00.000 --> 00:00:01.000\n" "\n\n" "00:00:05.000 --> 00:00:06.000\n" "Bar.\n")) (expect (point) :to-equal 67))) (it "passing start time." (with-temp-vtt-buffer (insert (concat "00:00:01.000 --> 00:00:02.000\n" "Foo.\n\n" "00:00:05.000 --> 00:00:06.000\n" "Bar.\n")) (subed-vtt--jump-to-subtitle-time-start "00:00:01.000") (expect (subed-vtt--append-subtitle nil 2500) :to-equal 67) (expect (buffer-string) :to-equal (concat "00:00:01.000 --> 00:00:02.000\n" "Foo.\n\n" "00:00:02.500 --> 00:00:03.500\n" "\n\n" "00:00:05.000 --> 00:00:06.000\n" "Bar.\n")) (expect (point) :to-equal 67))) (it "passing start time and stop time." (with-temp-vtt-buffer (insert (concat "00:00:01.000 --> 00:00:02.000\n" "Foo.\n\n" "00:00:05.000 --> 00:00:06.000\n" "Bar.\n")) (subed-vtt--jump-to-subtitle-time-start "00:00:01.000") (expect (subed-vtt--append-subtitle nil 2500 4000) :to-equal 67) (expect (buffer-string) :to-equal (concat "00:00:01.000 --> 00:00:02.000\n" "Foo.\n\n" "00:00:02.500 --> 00:00:04.000\n" "\n\n" "00:00:05.000 --> 00:00:06.000\n" "Bar.\n")) (expect (point) :to-equal 67))) (it "passing start time, stop time and text." (with-temp-vtt-buffer (insert (concat "00:00:01.000 --> 00:00:02.000\n" "Foo.\n\n" "00:00:05.000 --> 00:00:06.000\n" "Bar.\n")) (subed-vtt--jump-to-subtitle-time-start "00:00:01.000") (expect (subed-vtt--append-subtitle nil 2500 4000 "Baz.") :to-equal 67) (expect (buffer-string) :to-equal (concat "00:00:01.000 --> 00:00:02.000\n" "Foo.\n\n" "00:00:02.500 --> 00:00:04.000\n" "Baz.\n\n" "00:00:05.000 --> 00:00:06.000\n" "Bar.\n")) (expect (point) :to-equal 67))) ) ) (it "when point is on empty text." (with-temp-vtt-buffer (insert (concat "00:00:01.000 --> 00:00:02.000\n" "\n")) (subed-jump-to-subtitle-text) (expect (subed-vtt--append-subtitle) :to-equal 63) (expect (buffer-string) :to-equal (concat "00:00:01.000 --> 00:00:02.000\n" "\n\n" "00:00:00.000 --> 00:00:01.000\n" "\n")) (expect (point) :to-equal 63))) ) ) (describe "Killing a subtitle" (it "removes the first subtitle." (with-temp-vtt-buffer (insert mock-vtt-data) (subed-vtt--jump-to-subtitle-text "00:01:01.000") (subed-vtt--kill-subtitle) (expect (buffer-string) :to-equal (concat "WEBVTT\n\n" "00:02:02.234 --> 00:02:10.345\n" "Bar.\n\n" "00:03:03.45 --> 00:03:15.5\n" "Baz.\n")))) (it "removes it in between." (with-temp-vtt-buffer (insert mock-vtt-data) (subed-vtt--jump-to-subtitle-text "00:02:02.234") (subed-vtt--kill-subtitle) (expect (buffer-string) :to-equal (concat "WEBVTT\n\n" "00:01:01.000 --> 00:01:05.123\n" "Foo.\n\n" "00:03:03.45 --> 00:03:15.5\n" "Baz.\n")))) (it "removes the last subtitle." (with-temp-vtt-buffer (insert mock-vtt-data) (subed-vtt--jump-to-subtitle-text "00:03:03.45") (subed-vtt--kill-subtitle) (expect (buffer-string) :to-equal (concat "WEBVTT\n\n" "00:01:01.000 --> 00:01:05.123\n" "Foo.\n\n" "00:02:02.234 --> 00:02:10.345\n" "Bar.\n")))) (describe "removes the previous subtitle when point is right above the timestamp" (it "of the last subtitle." (with-temp-vtt-buffer (insert mock-vtt-data) (subed-jump-to-subtitle-id "00:03:03.45") (backward-char) (expect (looking-at "^\n00:03:03.45") :to-be t) (subed-vtt--kill-subtitle) (expect (buffer-string) :to-equal (concat "WEBVTT\n\n" "00:01:01.000 --> 00:01:05.123\n" "Foo.\n\n" "00:03:03.45 --> 00:03:15.5\n" "Baz.\n")))) (it "of a non-last subtitle." (with-temp-vtt-buffer (insert mock-vtt-data) (subed-jump-to-subtitle-id "00:02:02.234") (backward-char) (expect (looking-at "^\n00:02:02.234") :to-be t) (subed-vtt--kill-subtitle) (expect (buffer-string) :to-equal (concat "WEBVTT\n\n" "00:02:02.234 --> 00:02:10.345\n" "Bar.\n\n" "00:03:03.45 --> 00:03:15.5\n" "Baz.\n")))) ) ) (describe "Validating" (it "works in empty buffer." (with-temp-vtt-buffer (subed-vtt--validate))) (it "works in buffer that contains only newlines." (with-temp-vtt-buffer (cl-loop for _ from 1 to 10 do (insert "\n") (subed-vtt--validate)))) (it "works in buffer that contains only spaces." (with-temp-vtt-buffer (cl-loop for _ from 1 to 10 do (insert " ") (subed-vtt--validate)))) (it "works in buffer that contains only spaces and newlines." (with-temp-vtt-buffer (cl-loop for _ from 1 to 10 do (if (eq (random 2) 0) (insert " ") (insert "\n")) (subed-vtt--validate)))) (it "reports invalid stop time." (with-temp-vtt-buffer (insert mock-vtt-data) (subed-vtt--jump-to-subtitle-time-stop "00:01:01.000") (forward-char 10) (insert "3") (expect (subed-vtt--validate) :to-throw 'error '("Found invalid stop time: \"00:01:01.000 --> 00:01:05.1323\"")) (expect (point) :to-equal 26))) (it "reports invalid time separator." (with-temp-vtt-buffer (insert mock-vtt-data) (subed-vtt--jump-to-subtitle-time-stop "00:01:01.000") (delete-char -1) (expect (subed-vtt--validate) :to-throw 'error '("Found invalid separator between start and stop time: \"00:01:01.000 -->00:01:05.123\"")) (expect (point) :to-equal 21))) (it "does not report error when last subtitle text is empty." (with-temp-vtt-buffer (insert mock-vtt-data) (subed-vtt--jump-to-subtitle-text "00:03:03.45") (kill-whole-line) (forward-char -2) (subed-vtt--validate) (expect (point) :to-equal 106))) (it "preserves point if there is no error." (with-temp-vtt-buffer (insert mock-vtt-data) (subed-vtt--jump-to-subtitle-text "00:02:02.234") (forward-char 2) (subed-vtt--validate) (expect (point) :to-equal 77))) ) (describe "Sanitizing" (it "removes trailing tabs and spaces from all lines." (with-temp-vtt-buffer (insert mock-vtt-data) (goto-char (point-min)) (while (re-search-forward "\n" nil t) (replace-match " \n")) (expect (buffer-string) :not :to-equal mock-vtt-data) (subed-vtt--sanitize) (expect (buffer-string) :to-equal mock-vtt-data)) (with-temp-vtt-buffer (insert mock-vtt-data) (goto-char (point-min)) (while (re-search-forward "\n" nil t) (replace-match "\t\n")) (expect (buffer-string) :not :to-equal mock-vtt-data) (subed-vtt--sanitize) (expect (buffer-string) :to-equal mock-vtt-data))) (it "removes leading tabs and spaces from all lines." (with-temp-vtt-buffer (insert mock-vtt-data) (goto-char (point-min)) (while (re-search-forward "\n" nil t) (replace-match "\n ")) (expect (buffer-string) :not :to-equal mock-vtt-data) (subed-vtt--sanitize) (expect (buffer-string) :to-equal mock-vtt-data)) (with-temp-vtt-buffer (insert mock-vtt-data) (goto-char (point-min)) (while (re-search-forward "\n" nil t) (replace-match "\n\t")) (expect (buffer-string) :not :to-equal mock-vtt-data) (subed-vtt--sanitize) (expect (buffer-string) :to-equal mock-vtt-data))) (it "removes excessive empty lines between subtitles." (with-temp-vtt-buffer (insert mock-vtt-data) (goto-char (point-min)) (forward-line 2) (while (re-search-forward "\n\n" nil t) (replace-match "\n \n \t \t\t \n\n \t\n")) (expect (buffer-string) :not :to-equal mock-vtt-data) (subed-vtt--sanitize) (expect (buffer-string) :to-equal mock-vtt-data))) (it "ensures double newline between subtitles if text of previous subtitle is empty." (with-temp-vtt-buffer (insert mock-vtt-data) (subed-vtt--jump-to-subtitle-text "00:01:01.000") (kill-whole-line) (expect (buffer-string) :to-equal (concat "WEBVTT\n\n" "00:01:01.000 --> 00:01:05.123\n" "\n" "00:02:02.234 --> 00:02:10.345\n" "Bar.\n\n" "00:03:03.45 --> 00:03:15.5\n" "Baz.\n")) (subed-vtt--sanitize) (expect (buffer-string) :to-equal (concat "WEBVTT\n\n" "00:01:01.000 --> 00:01:05.123\n" "\n\n" "00:02:02.234 --> 00:02:10.345\n" "Bar.\n\n" "00:03:03.45 --> 00:03:15.5\n" "Baz.\n")))) (it "removes empty lines from end of buffer." (with-temp-vtt-buffer (insert mock-vtt-data) (goto-char (point-max)) (insert " \n\t\n\n") (expect (buffer-string) :not :to-equal mock-vtt-data) (subed-vtt--sanitize) (expect (buffer-string) :to-equal mock-vtt-data))) (it "ensures a single newline after the last subtitle." (with-temp-vtt-buffer (insert mock-vtt-data) (goto-char (point-max)) (while (eq (char-before (point-max)) ?\n) (delete-backward-char 1)) (expect (buffer-string) :not :to-equal mock-vtt-data) (subed-vtt--sanitize) (expect (buffer-string) :to-equal mock-vtt-data))) (it "ensures single newline after last subtitle if text is empty." (with-temp-vtt-buffer (insert mock-vtt-data) (subed-vtt--jump-to-subtitle-text "00:03:03.45") (kill-whole-line) (expect (buffer-string) :to-equal (concat "WEBVTT\n\n" "00:01:01.000 --> 00:01:05.123\n" "Foo.\n\n" "00:02:02.234 --> 00:02:10.345\n" "Bar.\n\n" "00:03:03.45 --> 00:03:15.5\n" "")) (subed-vtt--sanitize) (expect (buffer-string) :to-equal (concat "WEBVTT\n\n" "00:01:01.000 --> 00:01:05.123\n" "Foo.\n\n" "00:02:02.234 --> 00:02:10.345\n" "Bar.\n\n" "00:03:03.45 --> 00:03:15.5\n" "\n")))) (it "ensures single space before and after time separators." (with-temp-vtt-buffer (insert mock-vtt-data) (goto-char (point-min)) (re-search-forward " --> ") (replace-match " --> ") (re-search-forward " --> ") (replace-match " --> ") (re-search-forward " --> ") (replace-match "-->") (expect (buffer-string) :not :to-equal mock-vtt-data) (subed-vtt--sanitize) (expect (buffer-string) :to-equal mock-vtt-data))) (it "does not insert newline in empty buffer." (with-temp-vtt-buffer (expect (buffer-string) :to-equal "") (subed-vtt--sanitize) (expect (buffer-string) :to-equal ""))) ) (describe "Sorting" (it "orders subtitles by start time." (with-temp-vtt-buffer (insert mock-vtt-data) (goto-char (point-min)) (re-search-forward "01:01") (replace-match "12:01") (goto-char (point-min)) (re-search-forward "02:02") (replace-match "10:02") (goto-char (point-min)) (re-search-forward "03:03") (replace-match "11:03") (subed-vtt--sort) (expect (buffer-string) :to-equal (concat "WEBVTT\n" "\n" "00:10:02.234 --> 00:02:10.345\n" "Bar.\n" "\n" "00:11:03.45 --> 00:03:15.5\n" "Baz.\n" "\n" "00:12:01.000 --> 00:01:05.123\n" "Foo.\n")))) (describe "preserves point in the current subtitle" (it "when subtitle text is non-empty." (with-temp-vtt-buffer (insert mock-vtt-data) (goto-char (point-min)) (re-search-forward "01:01") (replace-match "12:01") (search-forward "\n") (expect (current-word) :to-equal "Foo") (subed-vtt--sort) (expect (current-word) :to-equal "Foo"))) (it "when subtitle text is empty." (with-temp-vtt-buffer (insert "WEBVTT\n\n00:12:01.000 --> 00:01:05.123\n") (goto-char (point-max)) (subed-vtt--sort) (expect (point) :to-equal (1- (point-max))))) ) ))