├── .gitignore ├── README.md ├── tests └── dired-preview-test.el ├── doclicense.texi ├── CHANGELOG.org ├── COPYING ├── dired-preview.el └── README.org /.gitignore: -------------------------------------------------------------------------------- 1 | *.elc 2 | *-autoloads.el 3 | *-pkg.el 4 | dired-preview.info 5 | dired-preview.texi 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # dired-preview for Emacs 2 | 3 | This is a simple package to automatically preview in a side window the 4 | file at point in Dired buffers. Preview windows are closed when they 5 | are no longer relevant, while preview buffers are killed if they have 6 | not been used for other purposes beside previewing. The package 7 | provides several customisation options to control its behaviour. 8 | 9 | + Package name (GNU ELPA): `dired-preview` 10 | + Official manual: 11 | + Git repositories: 12 | + GitHub: 13 | + GitLab: 14 | + Backronym: Directories Invariably Render Everything Decently ... 15 | preview; dired ... PDFs Require Extra Viewing Instructions for Emacs 16 | to Work. 17 | -------------------------------------------------------------------------------- /tests/dired-preview-test.el: -------------------------------------------------------------------------------- 1 | ;;; dired-preview-test.el --- Unit tests for Dired preview -*- lexical-binding: t -*- 2 | 3 | ;; Copyright (C) 2023-2025 Free Software Foundation, Inc. 4 | 5 | ;; Author: Protesilaos Stavrou 6 | ;; Maintainer: Protesilaos Stavrou 7 | ;; URL: https://github.com/protesilaos/denote 8 | 9 | ;; This file is NOT part of GNU Emacs. 10 | 11 | ;; This program is free software; you can redistribute it and/or modify 12 | ;; it under the terms of the GNU General Public License as published by 13 | ;; the Free Software Foundation, either version 3 of the License, or 14 | ;; (at your option) any later version. 15 | ;; 16 | ;; This program is distributed in the hope that it will be useful, 17 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | ;; GNU General Public License for more details. 20 | ;; 21 | ;; You should have received a copy of the GNU General Public License 22 | ;; along with this program. If not, see . 23 | 24 | ;;; Commentary: 25 | 26 | ;; Tests for Dired preview. Note that we are using Shorthands in this 27 | ;; file, so the "dpt-" prefix really is "denote-preview-test-". 28 | ;; Evaluate the following to learn more: 29 | ;; 30 | ;; (info "(elisp) Shorthands") 31 | 32 | ;;; Code: 33 | 34 | (require 'ert) 35 | (require 'dired-preview) 36 | 37 | (ert-deftest dpt--dired-preview--file-ignored-p () 38 | "Test that `dired-preview--file-ignored-p' returns non-nil for ignored file names." 39 | (let ((dired-preview-ignored-extensions-regexp 40 | (custom--standard-value 'dired-preview-ignored-extensions-regexp))) 41 | (dolist (ext '("mkv" "webm" "mp4" "mp3" "ogg" "m4a" "flac" "wav" 42 | "gz" "zst" "tar" "xz" "rar" "zip" "iso" "epub" "pdf")) 43 | (should (dired-preview--file-ignored-p (format "example.%s" ext))) 44 | (should-not (dired-preview--file-ignored-p (format "example.%s_" ext))))) 45 | (let ((dired-preview-ignored-extensions-regexp "\\.DS_Store\\'")) 46 | (should (dired-preview--file-ignored-p ".DS_Store")))) 47 | 48 | (ert-deftest dpt--dired-preview--infer-type () 49 | "Test that `dired-preview--infer-type' infers the correct file type." 50 | (let ((dired-preview-ignored-extensions-regexp 51 | (custom--standard-value 'dired-preview-ignored-extensions-regexp))) 52 | (dolist (ext '("mkv" "webm" "mp4" "mp3" "ogg" "m4a" "flac" "wav" 53 | "gz" "zst" "tar" "xz" "rar" "zip" "iso" "epub" "pdf")) 54 | (should (eq 'ignore 55 | (car (dired-preview--infer-type 56 | (format "example.%s" ext))))) 57 | (should-not (eq 'ignore 58 | (car (dired-preview--infer-type 59 | (format "example.%s_" ext))))))) 60 | (let ((dired-preview-ignored-extensions-regexp "\\.DS_Store\\'")) 61 | (should (eq 'ignore 62 | (car (dired-preview--infer-type ".DS_Store")))))) 63 | 64 | (provide 'dired-preview-test) 65 | ;;; dired-preview-test.el ends here 66 | 67 | ;; Local Variables: 68 | ;; read-symbol-shorthands: (("dpt" . "dired-preview-test-")) 69 | ;; End: 70 | -------------------------------------------------------------------------------- /doclicense.texi: -------------------------------------------------------------------------------- 1 | @c The GNU Free Documentation License. 2 | @center Version 1.3, 3 November 2008 3 | 4 | @c This file is intended to be included within another document, 5 | @c hence no sectioning command or @node. 6 | 7 | @display 8 | Copyright @copyright{} 2000, 2001, 2002, 2007, 2008 Free Software Foundation, Inc. 9 | @uref{https://fsf.org/} 10 | 11 | Everyone is permitted to copy and distribute verbatim copies 12 | of this license document, but changing it is not allowed. 13 | @end display 14 | 15 | @enumerate 0 16 | @item 17 | PREAMBLE 18 | 19 | The purpose of this License is to make a manual, textbook, or other 20 | functional and useful document @dfn{free} in the sense of freedom: to 21 | assure everyone the effective freedom to copy and redistribute it, 22 | with or without modifying it, either commercially or noncommercially. 23 | Secondarily, this License preserves for the author and publisher a way 24 | to get credit for their work, while not being considered responsible 25 | for modifications made by others. 26 | 27 | This License is a kind of ``copyleft'', which means that derivative 28 | works of the document must themselves be free in the same sense. It 29 | complements the GNU General Public License, which is a copyleft 30 | license designed for free software. 31 | 32 | We have designed this License in order to use it for manuals for free 33 | software, because free software needs free documentation: a free 34 | program should come with manuals providing the same freedoms that the 35 | software does. But this License is not limited to software manuals; 36 | it can be used for any textual work, regardless of subject matter or 37 | whether it is published as a printed book. We recommend this License 38 | principally for works whose purpose is instruction or reference. 39 | 40 | @item 41 | APPLICABILITY AND DEFINITIONS 42 | 43 | This License applies to any manual or other work, in any medium, that 44 | contains a notice placed by the copyright holder saying it can be 45 | distributed under the terms of this License. Such a notice grants a 46 | world-wide, royalty-free license, unlimited in duration, to use that 47 | work under the conditions stated herein. The ``Document'', below, 48 | refers to any such manual or work. Any member of the public is a 49 | licensee, and is addressed as ``you''. You accept the license if you 50 | copy, modify or distribute the work in a way requiring permission 51 | under copyright law. 52 | 53 | A ``Modified Version'' of the Document means any work containing the 54 | Document or a portion of it, either copied verbatim, or with 55 | modifications and/or translated into another language. 56 | 57 | A ``Secondary Section'' is a named appendix or a front-matter section 58 | of the Document that deals exclusively with the relationship of the 59 | publishers or authors of the Document to the Document's overall 60 | subject (or to related matters) and contains nothing that could fall 61 | directly within that overall subject. (Thus, if the Document is in 62 | part a textbook of mathematics, a Secondary Section may not explain 63 | any mathematics.) The relationship could be a matter of historical 64 | connection with the subject or with related matters, or of legal, 65 | commercial, philosophical, ethical or political position regarding 66 | them. 67 | 68 | The ``Invariant Sections'' are certain Secondary Sections whose titles 69 | are designated, as being those of Invariant Sections, in the notice 70 | that says that the Document is released under this License. If a 71 | section does not fit the above definition of Secondary then it is not 72 | allowed to be designated as Invariant. The Document may contain zero 73 | Invariant Sections. If the Document does not identify any Invariant 74 | Sections then there are none. 75 | 76 | The ``Cover Texts'' are certain short passages of text that are listed, 77 | as Front-Cover Texts or Back-Cover Texts, in the notice that says that 78 | the Document is released under this License. A Front-Cover Text may 79 | be at most 5 words, and a Back-Cover Text may be at most 25 words. 80 | 81 | A ``Transparent'' copy of the Document means a machine-readable copy, 82 | represented in a format whose specification is available to the 83 | general public, that is suitable for revising the document 84 | straightforwardly with generic text editors or (for images composed of 85 | pixels) generic paint programs or (for drawings) some widely available 86 | drawing editor, and that is suitable for input to text formatters or 87 | for automatic translation to a variety of formats suitable for input 88 | to text formatters. A copy made in an otherwise Transparent file 89 | format whose markup, or absence of markup, has been arranged to thwart 90 | or discourage subsequent modification by readers is not Transparent. 91 | An image format is not Transparent if used for any substantial amount 92 | of text. A copy that is not ``Transparent'' is called ``Opaque''. 93 | 94 | Examples of suitable formats for Transparent copies include plain 95 | ASCII without markup, Texinfo input format, La@TeX{} input 96 | format, SGML or XML using a publicly available 97 | DTD, and standard-conforming simple HTML, 98 | PostScript or PDF designed for human modification. Examples 99 | of transparent image formats include PNG, XCF and 100 | JPG@. Opaque formats include proprietary formats that can be 101 | read and edited only by proprietary word processors, SGML or 102 | XML for which the DTD and/or processing tools are 103 | not generally available, and the machine-generated HTML, 104 | PostScript or PDF produced by some word processors for 105 | output purposes only. 106 | 107 | The ``Title Page'' means, for a printed book, the title page itself, 108 | plus such following pages as are needed to hold, legibly, the material 109 | this License requires to appear in the title page. For works in 110 | formats which do not have any title page as such, ``Title Page'' means 111 | the text near the most prominent appearance of the work's title, 112 | preceding the beginning of the body of the text. 113 | 114 | The ``publisher'' means any person or entity that distributes copies 115 | of the Document to the public. 116 | 117 | A section ``Entitled XYZ'' means a named subunit of the Document whose 118 | title either is precisely XYZ or contains XYZ in parentheses following 119 | text that translates XYZ in another language. (Here XYZ stands for a 120 | specific section name mentioned below, such as ``Acknowledgements'', 121 | ``Dedications'', ``Endorsements'', or ``History''.) To ``Preserve the Title'' 122 | of such a section when you modify the Document means that it remains a 123 | section ``Entitled XYZ'' according to this definition. 124 | 125 | The Document may include Warranty Disclaimers next to the notice which 126 | states that this License applies to the Document. These Warranty 127 | Disclaimers are considered to be included by reference in this 128 | License, but only as regards disclaiming warranties: any other 129 | implication that these Warranty Disclaimers may have is void and has 130 | no effect on the meaning of this License. 131 | 132 | @item 133 | VERBATIM COPYING 134 | 135 | You may copy and distribute the Document in any medium, either 136 | commercially or noncommercially, provided that this License, the 137 | copyright notices, and the license notice saying this License applies 138 | to the Document are reproduced in all copies, and that you add no other 139 | conditions whatsoever to those of this License. You may not use 140 | technical measures to obstruct or control the reading or further 141 | copying of the copies you make or distribute. However, you may accept 142 | compensation in exchange for copies. If you distribute a large enough 143 | number of copies you must also follow the conditions in section 3. 144 | 145 | You may also lend copies, under the same conditions stated above, and 146 | you may publicly display copies. 147 | 148 | @item 149 | COPYING IN QUANTITY 150 | 151 | If you publish printed copies (or copies in media that commonly have 152 | printed covers) of the Document, numbering more than 100, and the 153 | Document's license notice requires Cover Texts, you must enclose the 154 | copies in covers that carry, clearly and legibly, all these Cover 155 | Texts: Front-Cover Texts on the front cover, and Back-Cover Texts on 156 | the back cover. Both covers must also clearly and legibly identify 157 | you as the publisher of these copies. The front cover must present 158 | the full title with all words of the title equally prominent and 159 | visible. You may add other material on the covers in addition. 160 | Copying with changes limited to the covers, as long as they preserve 161 | the title of the Document and satisfy these conditions, can be treated 162 | as verbatim copying in other respects. 163 | 164 | If the required texts for either cover are too voluminous to fit 165 | legibly, you should put the first ones listed (as many as fit 166 | reasonably) on the actual cover, and continue the rest onto adjacent 167 | pages. 168 | 169 | If you publish or distribute Opaque copies of the Document numbering 170 | more than 100, you must either include a machine-readable Transparent 171 | copy along with each Opaque copy, or state in or with each Opaque copy 172 | a computer-network location from which the general network-using 173 | public has access to download using public-standard network protocols 174 | a complete Transparent copy of the Document, free of added material. 175 | If you use the latter option, you must take reasonably prudent steps, 176 | when you begin distribution of Opaque copies in quantity, to ensure 177 | that this Transparent copy will remain thus accessible at the stated 178 | location until at least one year after the last time you distribute an 179 | Opaque copy (directly or through your agents or retailers) of that 180 | edition to the public. 181 | 182 | It is requested, but not required, that you contact the authors of the 183 | Document well before redistributing any large number of copies, to give 184 | them a chance to provide you with an updated version of the Document. 185 | 186 | @item 187 | MODIFICATIONS 188 | 189 | You may copy and distribute a Modified Version of the Document under 190 | the conditions of sections 2 and 3 above, provided that you release 191 | the Modified Version under precisely this License, with the Modified 192 | Version filling the role of the Document, thus licensing distribution 193 | and modification of the Modified Version to whoever possesses a copy 194 | of it. In addition, you must do these things in the Modified Version: 195 | 196 | @enumerate A 197 | @item 198 | Use in the Title Page (and on the covers, if any) a title distinct 199 | from that of the Document, and from those of previous versions 200 | (which should, if there were any, be listed in the History section 201 | of the Document). You may use the same title as a previous version 202 | if the original publisher of that version gives permission. 203 | 204 | @item 205 | List on the Title Page, as authors, one or more persons or entities 206 | responsible for authorship of the modifications in the Modified 207 | Version, together with at least five of the principal authors of the 208 | Document (all of its principal authors, if it has fewer than five), 209 | unless they release you from this requirement. 210 | 211 | @item 212 | State on the Title page the name of the publisher of the 213 | Modified Version, as the publisher. 214 | 215 | @item 216 | Preserve all the copyright notices of the Document. 217 | 218 | @item 219 | Add an appropriate copyright notice for your modifications 220 | adjacent to the other copyright notices. 221 | 222 | @item 223 | Include, immediately after the copyright notices, a license notice 224 | giving the public permission to use the Modified Version under the 225 | terms of this License, in the form shown in the Addendum below. 226 | 227 | @item 228 | Preserve in that license notice the full lists of Invariant Sections 229 | and required Cover Texts given in the Document's license notice. 230 | 231 | @item 232 | Include an unaltered copy of this License. 233 | 234 | @item 235 | Preserve the section Entitled ``History'', Preserve its Title, and add 236 | to it an item stating at least the title, year, new authors, and 237 | publisher of the Modified Version as given on the Title Page. If 238 | there is no section Entitled ``History'' in the Document, create one 239 | stating the title, year, authors, and publisher of the Document as 240 | given on its Title Page, then add an item describing the Modified 241 | Version as stated in the previous sentence. 242 | 243 | @item 244 | Preserve the network location, if any, given in the Document for 245 | public access to a Transparent copy of the Document, and likewise 246 | the network locations given in the Document for previous versions 247 | it was based on. These may be placed in the ``History'' section. 248 | You may omit a network location for a work that was published at 249 | least four years before the Document itself, or if the original 250 | publisher of the version it refers to gives permission. 251 | 252 | @item 253 | For any section Entitled ``Acknowledgements'' or ``Dedications'', Preserve 254 | the Title of the section, and preserve in the section all the 255 | substance and tone of each of the contributor acknowledgements and/or 256 | dedications given therein. 257 | 258 | @item 259 | Preserve all the Invariant Sections of the Document, 260 | unaltered in their text and in their titles. Section numbers 261 | or the equivalent are not considered part of the section titles. 262 | 263 | @item 264 | Delete any section Entitled ``Endorsements''. Such a section 265 | may not be included in the Modified Version. 266 | 267 | @item 268 | Do not retitle any existing section to be Entitled ``Endorsements'' or 269 | to conflict in title with any Invariant Section. 270 | 271 | @item 272 | Preserve any Warranty Disclaimers. 273 | @end enumerate 274 | 275 | If the Modified Version includes new front-matter sections or 276 | appendices that qualify as Secondary Sections and contain no material 277 | copied from the Document, you may at your option designate some or all 278 | of these sections as invariant. To do this, add their titles to the 279 | list of Invariant Sections in the Modified Version's license notice. 280 | These titles must be distinct from any other section titles. 281 | 282 | You may add a section Entitled ``Endorsements'', provided it contains 283 | nothing but endorsements of your Modified Version by various 284 | parties---for example, statements of peer review or that the text has 285 | been approved by an organization as the authoritative definition of a 286 | standard. 287 | 288 | You may add a passage of up to five words as a Front-Cover Text, and a 289 | passage of up to 25 words as a Back-Cover Text, to the end of the list 290 | of Cover Texts in the Modified Version. Only one passage of 291 | Front-Cover Text and one of Back-Cover Text may be added by (or 292 | through arrangements made by) any one entity. If the Document already 293 | includes a cover text for the same cover, previously added by you or 294 | by arrangement made by the same entity you are acting on behalf of, 295 | you may not add another; but you may replace the old one, on explicit 296 | permission from the previous publisher that added the old one. 297 | 298 | The author(s) and publisher(s) of the Document do not by this License 299 | give permission to use their names for publicity for or to assert or 300 | imply endorsement of any Modified Version. 301 | 302 | @item 303 | COMBINING DOCUMENTS 304 | 305 | You may combine the Document with other documents released under this 306 | License, under the terms defined in section 4 above for modified 307 | versions, provided that you include in the combination all of the 308 | Invariant Sections of all of the original documents, unmodified, and 309 | list them all as Invariant Sections of your combined work in its 310 | license notice, and that you preserve all their Warranty Disclaimers. 311 | 312 | The combined work need only contain one copy of this License, and 313 | multiple identical Invariant Sections may be replaced with a single 314 | copy. If there are multiple Invariant Sections with the same name but 315 | different contents, make the title of each such section unique by 316 | adding at the end of it, in parentheses, the name of the original 317 | author or publisher of that section if known, or else a unique number. 318 | Make the same adjustment to the section titles in the list of 319 | Invariant Sections in the license notice of the combined work. 320 | 321 | In the combination, you must combine any sections Entitled ``History'' 322 | in the various original documents, forming one section Entitled 323 | ``History''; likewise combine any sections Entitled ``Acknowledgements'', 324 | and any sections Entitled ``Dedications''. You must delete all 325 | sections Entitled ``Endorsements.'' 326 | 327 | @item 328 | COLLECTIONS OF DOCUMENTS 329 | 330 | You may make a collection consisting of the Document and other documents 331 | released under this License, and replace the individual copies of this 332 | License in the various documents with a single copy that is included in 333 | the collection, provided that you follow the rules of this License for 334 | verbatim copying of each of the documents in all other respects. 335 | 336 | You may extract a single document from such a collection, and distribute 337 | it individually under this License, provided you insert a copy of this 338 | License into the extracted document, and follow this License in all 339 | other respects regarding verbatim copying of that document. 340 | 341 | @item 342 | AGGREGATION WITH INDEPENDENT WORKS 343 | 344 | A compilation of the Document or its derivatives with other separate 345 | and independent documents or works, in or on a volume of a storage or 346 | distribution medium, is called an ``aggregate'' if the copyright 347 | resulting from the compilation is not used to limit the legal rights 348 | of the compilation's users beyond what the individual works permit. 349 | When the Document is included in an aggregate, this License does not 350 | apply to the other works in the aggregate which are not themselves 351 | derivative works of the Document. 352 | 353 | If the Cover Text requirement of section 3 is applicable to these 354 | copies of the Document, then if the Document is less than one half of 355 | the entire aggregate, the Document's Cover Texts may be placed on 356 | covers that bracket the Document within the aggregate, or the 357 | electronic equivalent of covers if the Document is in electronic form. 358 | Otherwise they must appear on printed covers that bracket the whole 359 | aggregate. 360 | 361 | @item 362 | TRANSLATION 363 | 364 | Translation is considered a kind of modification, so you may 365 | distribute translations of the Document under the terms of section 4. 366 | Replacing Invariant Sections with translations requires special 367 | permission from their copyright holders, but you may include 368 | translations of some or all Invariant Sections in addition to the 369 | original versions of these Invariant Sections. You may include a 370 | translation of this License, and all the license notices in the 371 | Document, and any Warranty Disclaimers, provided that you also include 372 | the original English version of this License and the original versions 373 | of those notices and disclaimers. In case of a disagreement between 374 | the translation and the original version of this License or a notice 375 | or disclaimer, the original version will prevail. 376 | 377 | If a section in the Document is Entitled ``Acknowledgements'', 378 | ``Dedications'', or ``History'', the requirement (section 4) to Preserve 379 | its Title (section 1) will typically require changing the actual 380 | title. 381 | 382 | @item 383 | TERMINATION 384 | 385 | You may not copy, modify, sublicense, or distribute the Document 386 | except as expressly provided under this License. Any attempt 387 | otherwise to copy, modify, sublicense, or distribute it is void, and 388 | will automatically terminate your rights under this License. 389 | 390 | However, if you cease all violation of this License, then your license 391 | from a particular copyright holder is reinstated (a) provisionally, 392 | unless and until the copyright holder explicitly and finally 393 | terminates your license, and (b) permanently, if the copyright holder 394 | fails to notify you of the violation by some reasonable means prior to 395 | 60 days after the cessation. 396 | 397 | Moreover, your license from a particular copyright holder is 398 | reinstated permanently if the copyright holder notifies you of the 399 | violation by some reasonable means, this is the first time you have 400 | received notice of violation of this License (for any work) from that 401 | copyright holder, and you cure the violation prior to 30 days after 402 | your receipt of the notice. 403 | 404 | Termination of your rights under this section does not terminate the 405 | licenses of parties who have received copies or rights from you under 406 | this License. If your rights have been terminated and not permanently 407 | reinstated, receipt of a copy of some or all of the same material does 408 | not give you any rights to use it. 409 | 410 | @item 411 | FUTURE REVISIONS OF THIS LICENSE 412 | 413 | The Free Software Foundation may publish new, revised versions 414 | of the GNU Free Documentation License from time to time. Such new 415 | versions will be similar in spirit to the present version, but may 416 | differ in detail to address new problems or concerns. See 417 | @uref{https://www.gnu.org/licenses/}. 418 | 419 | Each version of the License is given a distinguishing version number. 420 | If the Document specifies that a particular numbered version of this 421 | License ``or any later version'' applies to it, you have the option of 422 | following the terms and conditions either of that specified version or 423 | of any later version that has been published (not as a draft) by the 424 | Free Software Foundation. If the Document does not specify a version 425 | number of this License, you may choose any version ever published (not 426 | as a draft) by the Free Software Foundation. If the Document 427 | specifies that a proxy can decide which future versions of this 428 | License can be used, that proxy's public statement of acceptance of a 429 | version permanently authorizes you to choose that version for the 430 | Document. 431 | 432 | @item 433 | RELICENSING 434 | 435 | ``Massive Multiauthor Collaboration Site'' (or ``MMC Site'') means any 436 | World Wide Web server that publishes copyrightable works and also 437 | provides prominent facilities for anybody to edit those works. A 438 | public wiki that anybody can edit is an example of such a server. A 439 | ``Massive Multiauthor Collaboration'' (or ``MMC'') contained in the 440 | site means any set of copyrightable works thus published on the MMC 441 | site. 442 | 443 | ``CC-BY-SA'' means the Creative Commons Attribution-Share Alike 3.0 444 | license published by Creative Commons Corporation, a not-for-profit 445 | corporation with a principal place of business in San Francisco, 446 | California, as well as future copyleft versions of that license 447 | published by that same organization. 448 | 449 | ``Incorporate'' means to publish or republish a Document, in whole or 450 | in part, as part of another Document. 451 | 452 | An MMC is ``eligible for relicensing'' if it is licensed under this 453 | License, and if all works that were first published under this License 454 | somewhere other than this MMC, and subsequently incorporated in whole 455 | or in part into the MMC, (1) had no cover texts or invariant sections, 456 | and (2) were thus incorporated prior to November 1, 2008. 457 | 458 | The operator of an MMC Site may republish an MMC contained in the site 459 | under CC-BY-SA on the same site at any time before August 1, 2009, 460 | provided the MMC is eligible for relicensing. 461 | 462 | @end enumerate 463 | 464 | @page 465 | @heading ADDENDUM: How to use this License for your documents 466 | 467 | To use this License in a document you have written, include a copy of 468 | the License in the document and put the following copyright and 469 | license notices just after the title page: 470 | 471 | @smallexample 472 | @group 473 | Copyright (C) @var{year} @var{your name}. 474 | Permission is granted to copy, distribute and/or modify this document 475 | under the terms of the GNU Free Documentation License, Version 1.3 476 | or any later version published by the Free Software Foundation; 477 | with no Invariant Sections, no Front-Cover Texts, and no Back-Cover 478 | Texts. A copy of the license is included in the section entitled ``GNU 479 | Free Documentation License''. 480 | @end group 481 | @end smallexample 482 | 483 | If you have Invariant Sections, Front-Cover Texts and Back-Cover Texts, 484 | replace the ``with@dots{}Texts.''@: line with this: 485 | 486 | @smallexample 487 | @group 488 | with the Invariant Sections being @var{list their titles}, with 489 | the Front-Cover Texts being @var{list}, and with the Back-Cover Texts 490 | being @var{list}. 491 | @end group 492 | @end smallexample 493 | 494 | If you have Invariant Sections without Cover Texts, or some other 495 | combination of the three, merge those two alternatives to suit the 496 | situation. 497 | 498 | If your document contains nontrivial examples of program code, we 499 | recommend releasing these examples in parallel under your choice of 500 | free software license, such as the GNU General Public License, 501 | to permit their use in free software. 502 | 503 | @c Local Variables: 504 | @c ispell-local-pdict: "ispell-dict" 505 | @c End: 506 | -------------------------------------------------------------------------------- /CHANGELOG.org: -------------------------------------------------------------------------------- 1 | #+title: Change log of dired-preview.el 2 | #+author: Protesilaos Stavrou 3 | #+email: info@protesilaos.com 4 | #+options: ':t toc:nil author:t email:t num:t 5 | #+startup: content 6 | 7 | This document contains the release notes for each tagged commit on the 8 | project's main git repository: . 9 | 10 | The newest release is at the top. For further details, please consult 11 | the manual: . 12 | 13 | #+toc: headlines 1 insert TOC here, with one headline level 14 | 15 | * Version 0.6.0 on 2025-07-18 16 | :PROPERTIES: 17 | :CUSTOM_ID: h:cdb4ee0e-5fd3-4958-9655-8b3ee6118755 18 | :END: 19 | 20 | This is a small release that provides quality-of-life refinements. 21 | 22 | ** Optionally do not trigger a preview when entering the directory 23 | :PROPERTIES: 24 | :CUSTOM_ID: h:b6b61050-6827-405b-8fc8-ee0ee51f1418 25 | :END: 26 | 27 | The new user option ~dired-preview-trigger-on-start~ controls whether 28 | a preview is produced automatically when (i) entering a directory 29 | while (ii) the ~dired-preview-mode~ or its global counterpart is 30 | enabled. 31 | 32 | The default value is non-~nil~, which preserves the behaviour we have 33 | always had of previewing outright. When set to ~nil~, the preview does 34 | not happen upon entering a directory and is triggered only after one 35 | of the commands in ~denote-preview-trigger-commands~ is invoked. 36 | 37 | I did this is in response to issue 31 by dasoju: . 38 | 39 | ** Define which commands trigger a preview 40 | :PROPERTIES: 41 | :CUSTOM_ID: h:20db592a-a282-4a63-a0f2-d64a6ded8ac2 42 | :END: 43 | 44 | The ~denote-preview-trigger-commands~ is now declared as a "user 45 | option" rather than a generic variable, meaning that users are 46 | encouraged to customise it (and it technically is available via the 47 | Custom interface and related). Everything should otherwise work the 48 | same as before. 49 | 50 | ** The preview does not interfere with ~dired-dwim-target~ 51 | :PROPERTIES: 52 | :CUSTOM_ID: h:96178e26-80b4-4717-85b8-e51a2f6c17e4 53 | :END: 54 | 55 | Previous versions would make ~dired-dwim-target~ not return the 56 | directory of the other window. Whereas we want the preview to not 57 | influence how Dired behaves when copying or renaming files. 58 | 59 | The bug was addressed in patch release =0.5.2=. 60 | 61 | ** Fixed a temporary bug in ~dired-preview-page-up~ 62 | :PROPERTIES: 63 | :CUSTOM_ID: h:cc578a93-b441-4ddc-9f82-a3b643a80ab1 64 | :END: 65 | 66 | It was missing the macro we define to perform operations in the 67 | preview window. 68 | 69 | Thanks to Alex Popescu for telling me that the command was not 70 | working. This was done in issue 28: . 71 | 72 | The bug was addressed in patch release =0.5.1=. 73 | * Version 0.5.0 on 2025-04-09 74 | :PROPERTIES: 75 | :CUSTOM_ID: h:bbcb8fc7-5738-4761-b0e8-853d74172a5a 76 | :END: 77 | 78 | This version contains a few bug fixes and minor refinements that 79 | should improve the behaviour of the package. 80 | 81 | ** Revised how preview windows are deleted 82 | :PROPERTIES: 83 | :CUSTOM_ID: h:0a4464ac-2f21-4c1e-8202-3bfe0b4eff93 84 | :END: 85 | 86 | In the past, ~dired-preview-mode~ could delete windows that held 87 | another buffer, thus undoing the window layout that was present before 88 | a preview buffer was displayed. Now ~dired-preview-mode~ makes sure to 89 | only delete windows that have not had another buffer shown in them, 90 | i.e. windows that were created just for preview purposes. 91 | 92 | ** Directories no longer get misunderstood as "large files" 93 | :PROPERTIES: 94 | :CUSTOM_ID: h:c5c0206a-57ce-4ad5-a74f-96275b8aaaf2 95 | :END: 96 | 97 | We tweaked how we test the type of the buffer-to-be-preview such that 98 | directories are not mistaken for "large files". This was an issue for 99 | Mac computers that Sean Devlin brought to my attention in issue 27: 100 | . 101 | 102 | ** The ~dired-preview-delay~ has a 0.1 second minimum to avoid instability 103 | :PROPERTIES: 104 | :CUSTOM_ID: h:4dcf8881-9c07-4a8e-93fa-24bedfd61db2 105 | :END: 106 | 107 | A value of 0 could lead to a noticeably degraded experience while 108 | navigating the Dired buffer. Thanks to Yiyu Zhou for reporting the 109 | matter in issue 2 on the GitLab mirror: 110 | . 111 | 112 | ** Files without an extension can also be ignored 113 | :PROPERTIES: 114 | :CUSTOM_ID: h:4d1b5c14-eb7d-473b-955a-3b3068b1a9ed 115 | :END: 116 | 117 | The user option ~dired-preview-ignored-extensions-regexp~ will now 118 | also match files without an extension, such as the =.DS_Store= on Mac 119 | computers. 120 | 121 | Thanks to Sean Devlin for the contribution in pull request 26: 122 | . The change is 123 | within the ~15-line limit, meaning that Sean does not need to assign 124 | copyright to the Free Software Foundation. 125 | 126 | ** The preview buffer is the "other window" for scrolling purposes 127 | :PROPERTIES: 128 | :CUSTOM_ID: h:7eb9ced9-03a7-4436-9392-6352737aee15 129 | :END: 130 | 131 | The commands which scroll the other window, such as 132 | ~scroll-other-window~ now operate on the preview buffer when that is 133 | displayed. Thanks to Karthik Chikmagalur for proposing this in issue 134 | 24: . 135 | 136 | This is in addition to the commands we already provided for scrolling 137 | the preview window, namely, ~dired-preview-page-up~ and ~dired-preview-page-down~. 138 | Do =M-x describe-keymap= and then search for ~dired-preview-mode-map~: 139 | it is in effect when ~dired-preview-mode~ is enabled. 140 | 141 | * Version 0.4.0 on 2025-02-18 142 | :PROPERTIES: 143 | :CUSTOM_ID: h:af454ee4-dcae-4a76-80c7-d4f9be7730c7 144 | :END: 145 | 146 | This version contains several refinements and bug fixes. 147 | 148 | ** Preview buffers have a mode line indicator 149 | :PROPERTIES: 150 | :CUSTOM_ID: h:309a2e0b-866a-45a6-b262-2d9f4c74531a 151 | :END: 152 | 153 | Preview buffers have a prefix to their name to make them stand out. 154 | This is controlled by the user option ~dired-preview-buffer-name-indicator~, 155 | which is a string that defaults to =[P]=. 156 | 157 | ** Control how preview buffers are cleaned up 158 | :PROPERTIES: 159 | :CUSTOM_ID: h:7e173b76-ee7b-4720-8ab3-06664f5decee 160 | :END: 161 | 162 | The way ~dired-preview~ works is to display a buffer and then keep a 163 | list of preview buffers to economise on redisplaying it again. This 164 | list of buffers is relevant for as long as we are in the Dired buffer, 165 | otherwise all buffers therein are killed (buffers that were alive 166 | before being previewed are not touched). 167 | 168 | By default we delete from oldest to newest the accumulated buffers 169 | when they exceed =10= in total. Though users can modify this behaviour 170 | by editing the value of the new user option ~dired-preview-kill-buffers-method~ 171 | (its doc string explains the technicalities). 172 | 173 | Thanks to artelse for discussing this with me in issue 20: 174 | . 175 | 176 | ** The ~dired-preview-display-action-alist~ has a new optional function 177 | :PROPERTIES: 178 | :CUSTOM_ID: h:a51e6649-1f36-4f5b-9525-5541367d7bea 179 | :END: 180 | 181 | The ~dired-preview-display-action-alist~ is the user option which 182 | controls where the preview window is displayed. Its value can either 183 | be the symbol of a function or a ~display-buffer-alist~ entry. 184 | 185 | By default, we have a "do-what-I-mean" function that tries to find a 186 | good placement for the window. The new ~dired-preview-display-action-alist-below~ 187 | function has a straightforward behaviour: it always shows the preview 188 | below the current window and it always makes the preview window 0.3 189 | times the height of the Emacs frame. 190 | 191 | ** Encypted files are no longer previewed 192 | :PROPERTIES: 193 | :CUSTOM_ID: h:e93c9c41-c1ad-4e88-945a-c42962441bbe 194 | :END: 195 | 196 | This is to ensure that potentially sensitive contents are not 197 | displayed by accident, such as during a video call. 198 | 199 | ** We no longer preview the "self" directory 200 | :PROPERTIES: 201 | :CUSTOM_ID: h:ec1bfadc-728e-4605-a8d7-25d1c595f9a1 202 | :END: 203 | 204 | We should not trigger a preview when the cursor is over the implicit 205 | =.= directory, as that causes a recursion that breaks things. Thanks 206 | to Inkbottle007 for reporting the bug in issue 23: 207 | . 208 | 209 | ** Miscellaneous 210 | :PROPERTIES: 211 | :CUSTOM_ID: h:078acf4c-cf38-4053-befd-600476970d1a 212 | :END: 213 | 214 | - Fixed a scenario where we would try to delete the last available 215 | window on the current frame. This should never happen. Thanks to 216 | artelse for reporting a relevant bug in the discussion of issue 22: 217 | . 218 | 219 | - Fixed a case when ~hexl-follow-ascii~ could fail to find an overlay 220 | under certain conditions. This did not create any noticeable 221 | problems, though having an error there would interfere with any 222 | workflow that would rely on ~toggle-debug-on-error~. 223 | 224 | - The preview window will automatically be closed if the user switches 225 | outside the given Dired buffer. We now do not consider a change to 226 | the minibuffer as being "outside" this context. This way, a quick 227 | =M-x= to, say, enable a minor mode does not have any effect on the 228 | window layout. 229 | 230 | - Suppressed the messaging facility of the underlying tracking of 231 | preview buffers. Otherwise, Dired would notify us that the directory 232 | has changed whenever we would preview a new one, which is 233 | superfluous. 234 | 235 | - The body of the ~dired-preview-trigger~ function, which determines 236 | whether a preview will be displayed, is encapsulated in a ~condition-case~. 237 | This helps capture errors and thus have a more predictable behaviour. 238 | 239 | - The ~dired-preview-display-action-alist~ has a more accurate 240 | declaration which allows for its correct customisation inside the 241 | Custom UI interface. In particular, it will behave the same way as 242 | the ~display-buffer-alist~, where relevant. 243 | 244 | * Version 0.3.0 on 2024-09-16 245 | :PROPERTIES: 246 | :CUSTOM_ID: h:d9780c65-4e70-4188-ae17-abdef97f7ea9 247 | :END: 248 | 249 | This version brings some nice new features and makes small refinements 250 | to the code base. 251 | 252 | ** Run commands in the preview window 253 | :PROPERTIES: 254 | :CUSTOM_ID: h:4d4e2b08-df93-4738-936b-70de1a056def 255 | :END: 256 | 257 | The ~dired-preview-mode-map~ is active when ~dired-preview-mode~ is 258 | enabled. Here are all the keys and corresponding commands it provides 259 | right now: 260 | 261 | | Key binding | Command | 262 | |-------------+---------------------------| 263 | | C-c C-c | dired-preview-hexl-toggle | 264 | | C-c C-d | dired-preview-page-down | 265 | | C-c C-f | dired-preview-find-file | 266 | | C-c C-o | dired-preview-open-dwim | 267 | | C-c C-u | dired-preview-page-up | 268 | 269 | With the exception of ~dired-preview-hexl-toggle~, these are all new 270 | commands. 271 | 272 | My most used command among those is ~dired-preview-open-dwim~, which 273 | has a Do-What-I-Mean behaviour: If the file name matches 274 | ~dired-preview-media-extensions-regexp~, 275 | ~dired-preview-ignored-extensions-regexp~, or 276 | ~dired-preview-image-extensions-regexp~, then it opens it externally. 277 | Otherwise, it visits the file in an Emacs buffer. Note that here we 278 | include the ~dired-preview-image-extensions-regexp~ because while 279 | Emacs can visit those in a buffer, it does not offer as much 280 | functionality as other apps that specialise in handling image files. 281 | 282 | [ Emacs uses the system default for those files when opening them externally. ] 283 | 284 | ** Advanced users can rely on the ~dired-preview-with-window~ macro 285 | :PROPERTIES: 286 | :CUSTOM_ID: h:90b9c693-c217-4760-a102-a7e04308bfd9 287 | :END: 288 | 289 | Use this in your custom functions to run some code with the preview 290 | window as the selected window. For example, here is a simple one from 291 | our code base: 292 | 293 | #+begin_src emacs-lisp 294 | (defun dired-preview-page-down () 295 | "Move a page down in the preview window. 296 | This technically runs `scroll-up-command'." 297 | (interactive) 298 | (dired-preview-with-window 299 | (call-interactively 'scroll-up-command))) 300 | #+end_src 301 | 302 | Remember to add them to the ~dired-preview-mode-map~. 303 | 304 | ** Placeholder window prevents preview jumpiness 305 | :PROPERTIES: 306 | :CUSTOM_ID: h:8c0034c1-9770-456f-b8db-40fe1db7754f 307 | :END: 308 | 309 | Wtih ~dired-preview-ignored-extensions-regexp~ we can exclude certain 310 | files from being previewed. This is useful because, for example, Emacs 311 | cannot display those files or do something useful with their contents, 312 | or we just want to hide them (e.g. to omit GPG-encrypted files from 313 | the preview). 314 | 315 | In the past, ~dired-preview-mode~ would pop up a preview window for a 316 | file that could be previewed and would then hide that window for 317 | anything matching ~dired-preview-ignored-extensions-regexp~. As a 318 | result, windows would jump in and out of the frame layout. This could 319 | be disorienting. 320 | 321 | We now provide the user option ~dired-preview-ignored-show-ignored-placeholders~ 322 | which shows a placeholder window when trying to preview an ignored 323 | file. So as we move up and down the Dired buffer, the preview window 324 | stays in place regardless if we are on an ignored file or not. 325 | 326 | The default value of ~dired-preview-ignored-show-ignored-placeholders~ 327 | is ~t~ because I think this is the better behaviour. Though users can 328 | set it to ~nil~ to retain the old functionality. 329 | 330 | Thanks to Álvaro Ramírez (xenodium) for the contribution. This was 331 | done in pull request 15: . 332 | 333 | The change is within the permissible limit of ~15 lines, meaning that 334 | Álvaro does not need to assign copyright to the Free Software 335 | Foundation. 336 | 337 | ** The ~dired-preview-display-action-alist~ replaces ~dired-preview-display-action-alist-function~ 338 | :PROPERTIES: 339 | :CUSTOM_ID: h:250662ef-3fd3-4abe-8cf7-71c72ce4619c 340 | :END: 341 | 342 | The old symbol is an alias for the new one and users will be notified 343 | accordingly while updating. 344 | 345 | This user option is for advanced users who want to customise where and 346 | how ~display-buffer~ places the preview window. Before, we were 347 | accepting only the symbol of a function that would return an 348 | appropriate action alist. Now we accept either a function's symbol or 349 | an action alist directly. 350 | 351 | Examples of both: 352 | 353 | #+begin_src emacs-lisp 354 | ;; Use a function that returns an action alist: 355 | (setq dired-preview-display-action-alist #'dired-preview-display-action-alist-dwim) 356 | 357 | ;; Use an action alist directly: 358 | (setq dired-preview-display-action-alist 359 | '((display-buffer-in-side-window) 360 | (side . bottom) 361 | (window-height . 0.2) 362 | (preserve-size . (t . t)))) 363 | #+end_src 364 | 365 | Check our ~dired-preview-display-action-alist-dwim~ for inspiration if 366 | you want to have a function that returns an action alist based on, 367 | say, the width of the frame. 368 | 369 | ** Preview of the next file works when marking for deletion 370 | :PROPERTIES: 371 | :CUSTOM_ID: h:68fd4a03-7ca9-489c-93bc-efdaf8faaefc 372 | :END: 373 | 374 | When we mark a file for deletion, Dired moves the point to the next 375 | line. Before, this would not trigger a preview of the updated 376 | file-at-point. Now it should work as expected. 377 | 378 | Technically, we check if the last command is among those stored in the 379 | variable ~dired-preview-trigger-commands~. If you think there are 380 | more commands we need to include there, just let me know. 381 | 382 | ** The ~dired-preview-ignored-extensions-regexp~ can be ~nil~ 383 | :PROPERTIES: 384 | :CUSTOM_ID: h:a06e0f9b-02d2-4a77-a259-eadaeff33c9e 385 | :END: 386 | 387 | This was always the intention, but the relevant code was not 388 | accounting for that scenario. It should work now as intended. 389 | 390 | * Version 0.2.0 on 2024-05-07 391 | :PROPERTIES: 392 | :CUSTOM_ID: h:4225d638-f5bb-4855-85c7-972ff40aad6d 393 | :END: 394 | 395 | This release brings many small improvements and fixes some bugs. 396 | 397 | ** The preview shows up right away on new directories 398 | :PROPERTIES: 399 | :CUSTOM_ID: h:e3652b69-aa81-4b71-9887-81052ff7f9f7 400 | :END: 401 | 402 | In the past, entering a new directory would not trigger a preview: it 403 | would wait for some motion before doing so. This could make it seem 404 | that the mode was not enabled in the current buffer. Now, the preview 405 | shows up immediately. 406 | 407 | Thanks to Nofint for the initial contribution in pull request 8: 408 | . The changes are 409 | small and do not require copyright assignment to the Free Software 410 | Foundation. 411 | 412 | ** Directories are previewed as well 413 | :PROPERTIES: 414 | :CUSTOM_ID: h:8dae8cba-3ca7-43be-a4ba-5dd938b37f82 415 | :END: 416 | 417 | The contents are displayed in a Dired buffer, using the current 418 | settings for it. This means that colours are possible icons are shown 419 | too. 420 | 421 | ** Large files are previewed in ~hexl-mode~ 422 | :PROPERTIES: 423 | :CUSTOM_ID: h:b4928def-5392-4e7b-8cb5-ed5c238b1b5e 424 | :END: 425 | 426 | As the documentation of this mode suggests: 427 | 428 | #+begin_quote 429 | A mode for editing binary files in hex dump format. 430 | This is not an ordinary major mode; it alters some aspects 431 | of the current mode’s behavior, but not all; also, you can exit 432 | Hexl mode and return to the previous mode using C-c C-c. 433 | #+end_quote 434 | 435 | The =C-c C-c= key binding toggles the mode, in case you want to see 436 | the raw output. 437 | 438 | Thanks to Karthik Chikmagalur for the contribution. This was done on 439 | the now defunct mailing list: 440 | . 441 | 442 | ** Previews are displayed in a full-featured mode 443 | :PROPERTIES: 444 | :CUSTOM_ID: h:ea324fd1-f808-420f-b019-250e161465ff 445 | :END: 446 | 447 | Before, we would delay the execution of the mode hooks to speed things 448 | up. Though this came at the cost of (i) making the buffer less capable 449 | and (ii) forcing us to handle the execution of those hooks at a later 450 | stage when they would be needed, which proved to be error-prone in a 451 | number of scenaria. 452 | 453 | ** Files without an extension are still previewed 454 | :PROPERTIES: 455 | :CUSTOM_ID: h:a4d6b125-5ef6-409d-aded-e7b1971ac87d 456 | :END: 457 | 458 | This is a bug fix. Before, they would be considered as part of the 459 | files to be ignored, per ~dired-preview-ignored-extensions-regexp~. 460 | 461 | ** Previews are not added to what ~recentf-mode~ tracks 462 | :PROPERTIES: 463 | :CUSTOM_ID: h:67d61ed2-3e16-49a9-bd3a-61950d9ab81b 464 | :END: 465 | 466 | Thanks to Juergen Hoetzel for reporting this issue and for tweaking my 467 | suggested patch for it. This was done in pull request 12: 468 | . The change is 469 | small, so Juergen does not need to assign copyright to the Free 470 | Software Foundation. 471 | 472 | ** A nil value for ~split-width-threshold~ still works 473 | :PROPERTIES: 474 | :CUSTOM_ID: h:493488b1-0f7d-4b44-b96d-4cd9a6bde352 475 | :END: 476 | 477 | We no longer consider this an error and adapt the preview accordingly. 478 | Thanks to Juergen Hoetzel for the contribution. This was done in pull 479 | request 11 and does not require copyright assignment: 480 | . 481 | 482 | ** For developers: previews are done with ~cl-defmethod~ 483 | :PROPERTIES: 484 | :CUSTOM_ID: h:d8c42eea-a540-44fd-91b4-138fdba47288 485 | :END: 486 | 487 | Each file type will thus have its own method on how to display the 488 | contents in a buffer. The idea is to make this easier to extend. The 489 | goal is to have methods that can preview PDFs and images without 490 | blocking Emacs. Other file types can be considered as well, though 491 | those two are the immediate priority. 492 | 493 | * Version 0.1.0 on 2023-07-08 494 | :PROPERTIES: 495 | :CUSTOM_ID: h:99cbb3dd-a0f1-4d2b-a945-58531f4ab189 496 | :END: 497 | 498 | The ~dired-preview~ package was in a public testing phase from 499 | 2023-06-25 until today. In the meantime, lots of changes have been 500 | made in the interest of usability and robustness. 501 | 502 | ** Global and buffer-local modes 503 | :PROPERTIES: 504 | :CUSTOM_ID: h:598de101-5c1f-4fbd-8f27-709375d8950b 505 | :END: 506 | 507 | The ~dired-preview-mode~ is a local minor mode, while 508 | ~dired-preview-global-mode~ is its global counterpart. Both only take 509 | effect in Dired buffers. 510 | 511 | The idea for a global and a local mode is to empower the user to 512 | toggle the functionality on demand, such as when they are in a meeting 513 | and want to disable/enable previews in a given context. 514 | 515 | During the development phase, I had made an error regarding the scope 516 | of what should be a local minor mode. Thanks to Christian Tietze for 517 | pointing it out: . 518 | 519 | ** Preview delay runs on an idle timer 520 | :PROPERTIES: 521 | :CUSTOM_ID: h:b80cc550-24ee-4817-be8c-c24c5e98e4c2 522 | :END: 523 | 524 | Originally, previews would run on a timer that would block Emacs. 525 | Whereas we now arrange to only trigger a preview when Emacs is idle 526 | for a customisable amount of seconds. Refer to the user option 527 | ~dired-preview-delay~. 528 | 529 | ** Trigger a preview in the post-command phase 530 | :PROPERTIES: 531 | :CUSTOM_ID: h:c298121a-5ba4-408b-b063-14022c307c47 532 | :END: 533 | 534 | In the original design, previews were triggered by bespoke 535 | ~dired-preview~ commands that were remapped to =n= and =p= in Dired 536 | buffers. This had several downsides, namely, (i) the other motions 537 | would not pick up the trigger, (ii) we would have to remap all 538 | possible motions, and (iii) the code was needlessly complex. 539 | 540 | Currently, we install a local hook in the post-command phase, which 541 | will trigger a preview if the previous command was a Dired motion. In 542 | future versions, we may expand the list of commands that we check for. 543 | 544 | Thanks to Peter Prevos for reporting this in issue 1 on the GitHub 545 | mirror: . 546 | 547 | Thanks to Christian Tietze and Ed Hamilton for discussing this topic 548 | with me on the mailing list: 549 | . 550 | Commit ae93720 by Christian Tietze is based on this discussion, 551 | although the implementation details have since been redone. 552 | 553 | During the development phase, I had made the mistake of checking the 554 | ~last-command~, whereas I should be testing against the 555 | ~this-command~. Thanks to Karthik Chikmagalur for pointing out my 556 | error: 557 | . 558 | 559 | ** The placement of the preview window is customisable 560 | :PROPERTIES: 561 | :CUSTOM_ID: h:3033401f-878d-4298-9256-228d6c249b3a 562 | :END: 563 | 564 | We arrange to display previews in a side window. Due to the inherent 565 | complexity of the ~display-buffer~ function and its accoutrements, a 566 | user option is necessarily reserved for experienced users. To this 567 | end, we provide the ~dired-preview-display-action-alist-function~. 568 | Refer to the ~dired-preview-display-action-alist-dwim~ function for 569 | the implementation details. 570 | 571 | Thanks to Karthik Chikmagalur for making an initial suggestion about 572 | such a feature: 573 | 574 | 575 | Thanks to Bruno Boal for discussing the user option and concomitant 576 | function with me and for checking the relevant definitions. This was 577 | done via a private channel and the information is shared with 578 | permission. 579 | 580 | ** Window placement and deletion is more robust 581 | :PROPERTIES: 582 | :CUSTOM_ID: h:06e6249d-8755-450e-b65e-b8f999d982a4 583 | :END: 584 | 585 | The idea of "preview" windows is that they are not ordinary windows 586 | that the user can interact with. As such, they are to be deleted when 587 | some non-preview mode of action is taken. 588 | 589 | Testing for such cases was extensive and required lots of changes to 590 | the code base. Thanks to Bruno Boal for performing the tests with me, 591 | for brainstorming possible solutions, and for inspecting the 592 | implementation details. This was done via a private channel and the 593 | information is shared with permission. 594 | 595 | ** We no longer try to preview irregular files 596 | :PROPERTIES: 597 | :CUSTOM_ID: h:a2ee3d09-7356-465c-8627-bdc56e9ec303 598 | :END: 599 | 600 | Before, ~dired-preview~ would attempt to produce a preview of named 601 | pipes and sockets. This was not intended and has since been 602 | addressed. Use 'file-regular-p' instead of 'file-exists-p' 603 | 604 | Thanks to Karthik Chikmagalur for bringing this matter to my attention 605 | and for recommending the use of ~file-regular-p~ instead of 606 | ~file-exists-p~: 607 | . 608 | 609 | ** Preview buffers are killed up to a cumulative size threshold 610 | :PROPERTIES: 611 | :CUSTOM_ID: h:d8ba0949-76b0-4d3a-b0f3-1bfb62280483 612 | :END: 613 | 614 | In the original design, we were killing preview buffers all at once. 615 | This was wasteful because all the work we were doing in the background 616 | to, for example, fetch a large file was discarded even though the user 617 | could theoretically request another preview of it. 618 | 619 | The current approach is to keep around the newer buffers in order to 620 | speed up potential requests for another preview. Older buffers are 621 | discarded starting from the oldest. The clearance of older buffers is 622 | done until we reach a cumulative size of what is specified as the 623 | value of the variable ~dired-preview--buffers-threshold~. 624 | 625 | Note that the symbol includes double dashes, meaning that it is 626 | intended for "private" (internal) purposes. I am mentioning it here, 627 | because this seems like a good candidate for a future user option, 628 | subject to further refinements. 629 | 630 | Thanks to Bruno Boal for suggesting this idea and checking its 631 | implementation with me. This was done via a private channel and the 632 | information is shared with permission. 633 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 2023 Protesilaos Stavrou 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 2023 Protesilaos Stavrou 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /dired-preview.el: -------------------------------------------------------------------------------- 1 | ;;; dired-preview.el --- Automatically preview file at point in Dired -*- lexical-binding: t -*- 2 | 3 | ;; Copyright (C) 2023-2025 Free Software Foundation, Inc. 4 | 5 | ;; Author: Protesilaos Stavrou 6 | ;; Maintainer: Protesilaos Stavrou 7 | ;; URL: https://github.com/protesilaos/dired-preview 8 | ;; Version: 0.6.0 9 | ;; Package-Requires: ((emacs "28.1")) 10 | ;; Keywords: files, convenience 11 | 12 | ;; This file is NOT part of GNU Emacs. 13 | 14 | ;; This program is free software; you can redistribute it and/or modify 15 | ;; it under the terms of the GNU General Public License as published by 16 | ;; the Free Software Foundation, either version 3 of the License, or 17 | ;; (at your option) any later version. 18 | ;; 19 | ;; This program is distributed in the hope that it will be useful, 20 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 | ;; GNU General Public License for more details. 23 | ;; 24 | ;; You should have received a copy of the GNU General Public License 25 | ;; along with this program. If not, see . 26 | 27 | ;;; Commentary: 28 | ;; 29 | ;; This is a simple package to automatically preview in a side window the 30 | ;; file at point in Dired buffers. Preview windows are closed when they 31 | ;; are no longer relevant, while preview buffers are killed if they have 32 | ;; not been used for other purposes beside previewing. 33 | ;; 34 | ;; Enable the `dired-preview-mode' in the current Dired buffer or 35 | ;; `dired-preview-global-mode' for all Dired buffers and then perform 36 | ;; the regular up/down motions. Those will trigger the preview. 37 | ;; 38 | ;; The previewed file is displayed in a side window if its size is below 39 | ;; the number specified in the user option `dired-preview-max-size'. 40 | ;; Previews are shown subject to a small delay, per ther user option 41 | ;; `dired-preview-delay'. 42 | ;; 43 | ;; Files matching the `dired-preview-ignored-extensions-regexp' are 44 | ;; not previewed, though a preview window is still displayed if the 45 | ;; user option `dired-preview-ignored-show-ignored-placeholders' is 46 | ;; non-nil. This is to avoid windows jumping in and out of focus as 47 | ;; the user moves between files. 48 | ;; 49 | ;; [ In the future, we may find ways to quickly preview any file type 50 | ;; without affecting the performance of Emacs.] 51 | ;; 52 | ;; I took inspiration for `dired-preview' from the now unmaintained 53 | ;; `peep-dired' package by Adam Sokolnicki: . 54 | ;; My original plan was to volunteer to maintain `peep-dired` but I 55 | ;; decided to write it my own way: it was easier for me, plus I can 56 | ;; implement only what I consider necessary without upsetting existing 57 | ;; users. 58 | 59 | ;;; Code: 60 | 61 | (require 'dired) 62 | (require 'seq) 63 | (eval-when-compile 64 | (require 'cl-lib) 65 | (require 'subr-x)) 66 | 67 | (defgroup dired-preview nil 68 | "Automatically preview file at point in Dired." 69 | :group 'dired) 70 | 71 | (defcustom dired-preview-ignored-extensions-regexp 72 | (concat "\\." 73 | "\\(mkv\\|webm\\|mp4\\|mp3\\|ogg\\|m4a\\|flac\\|wav" 74 | "\\|gz\\|zst\\|tar\\|xz\\|rar\\|zip" 75 | "\\|iso\\|epub\\|pdf\\)\\'") 76 | "Regular expression of file type extensions to not preview. 77 | When the value is nil, do not ignore any file: preview 78 | everything. 79 | 80 | A placeholder window will be displayed even for files that are ignored, 81 | in order to avoid windows jumping in and out of focus. This behaviour 82 | is controlled by the `dired-preview-ignored-show-ignored-placeholders' 83 | user option." 84 | :group 'dired-preview 85 | :type '(choice (const :tag "Do not ignore any file (preview everything)" nil) 86 | (string :tag "Ignore files matching regular expression"))) 87 | 88 | (defcustom dired-preview-ignored-show-ignored-placeholders t 89 | "When non-nil, show a placeholder preview buffer for ignored files. 90 | Ignored files are controlled by the `dired-preview-ignored-extensions-regexp' 91 | user option." 92 | :type 'boolean 93 | :package-version '(dired-preview . "0.3.0") 94 | :group 'dired-preview) 95 | 96 | (defcustom dired-preview-image-extensions-regexp "\\.\\(png\\|jpg\\|jpeg\\|tiff\\)" 97 | "List of file extensions representing image types." 98 | :group 'dired-preview 99 | :type '(string :tag "Image files matching regular expression")) 100 | 101 | (defcustom dired-preview-max-size (expt 2 20) 102 | "Files larger than this byte limit are not previewed." 103 | :group 'dired-preview 104 | :type 'natnum) 105 | 106 | (defcustom dired-preview-kill-buffers-method (cons 'buffer-number 10) 107 | "Determine whether to periodically kill preview buffers while in Dired. 108 | When the value is nil, do not kill any preview buffer. 109 | 110 | When the value is a cons cell of the form (SYMBOL . NATURAL-NUMBER), 111 | check if symbol is one of the following to derive the meaning of its 112 | NATURAL-NUMBER. 113 | 114 | - `buffer-number' means to kill the number of preview buffers that 115 | exceed the NATURAL-NUMBER. 116 | 117 | - `combined-size' means to kill buffers until their combined size does 118 | not exceed the NATURAL-NUMBER. 119 | 120 | Whatever the SYMBOL, buffers are killed from oldest to newest. 121 | 122 | Buffers are always killed when exiting Dired." 123 | :type '(choice 124 | (cons (choice (const :tag "Maximum number of buffers" buffer-number) 125 | (const :tag "Maximum cumulative buffer size" combined-size)) 126 | natnum) 127 | (const :tag "Do not kill any preview buffers" nil)) 128 | :package-version '(dired-preview . "0.4.0") 129 | :group 'dired-preview) 130 | 131 | (define-obsolete-variable-alias 132 | 'dired-preview-display-action-alist-function 133 | 'dired-preview-display-action-alist 134 | "0.3.0") 135 | 136 | (defcustom dired-preview-display-action-alist #'dired-preview-display-action-alist-dwim 137 | "The `display-buffer' action alist for the preview window. 138 | This is the same data that is passed to `display-buffer-alist'. 139 | Read Info node `(elisp) Displaying Buffers'. As such, it is 140 | meant for experienced users. 141 | 142 | Example of a valid value: 143 | 144 | \\='((display-buffer-in-side-window) 145 | (side . bottom) 146 | (window-height . 0.2) 147 | (preserve-size . (t . t))) 148 | 149 | The value may also be a function, which returns a `display-buffer' 150 | action alist. See `dired-preview-display-action-alist-dwim' (the 151 | default value of this variable) for the implementation details. A 152 | simpler alternative is the function `dired-preview-display-action-alist-below'. 153 | 154 | The `dired-preview-display-action-alist-dwim' will display the preview 155 | window either at the right hand side or the bottom of the frame, 156 | depending on the available space. It will also try to resize the window 157 | accordingly. 158 | 159 | Whereas the `dired-preview-display-action-alist-below' has a more simple 160 | behaviour of always displaying the preview window below the currently 161 | selected window and always setting the preview window's height to 0.3 162 | times the height of the frame." 163 | :group 'dired-preview 164 | :package-version '(dired-preview . "0.4.0") 165 | :type `(choice 166 | (alist :key-type 167 | (choice :tag "Condition" 168 | regexp 169 | (function :tag "Matcher function")) 170 | :value-type ,display-buffer--action-custom-type) 171 | (function :tag "Open to the side or bottom" dired-preview-display-action-alist-dwim) 172 | (function :tag "Open below the selected window" dired-preview-display-action-alist-below) 173 | (function :tag "Custom function like `dired-preview-display-action-alist-dwim'")) 174 | :risky t) 175 | 176 | (defcustom dired-preview-delay 0.7 177 | "Time in seconds to wait before previewing. 178 | If the value is 0, then it is internally understood as 0.1 as no delay 179 | can affect performance." 180 | :group 'dired-preview 181 | :type 'number) 182 | 183 | (defcustom dired-preview-chunk-size 10240 184 | "Size in bytes to read from large files." 185 | :group 'dired-preview 186 | :type 'natnum) 187 | 188 | (defcustom dired-preview-buffer-name-indicator "[P]" 189 | "String to prepend to the name of preview buffers." 190 | :type 'string 191 | :package-version '(dired-preview . "0.4.0") 192 | :group 'dired-preview) 193 | 194 | (defcustom dired-preview-trigger-on-start t 195 | "When non-nil try to trigger a preview when enabling `dired-preview-mode'. 196 | This also means that the preview will be displayed as soon as the Dired 197 | buffer is visited, if `dired-preview-mode' is added to the 198 | `dired-mode-hook' or `dired-preview-global-mode' is enabled. 199 | 200 | If nil, then the preview happens only after one of the commands in 201 | `dired-preview-trigger-commands' is invoked and the mode is enabled." 202 | :type 'boolean 203 | :package-version '(dired-preview . "0.6.0") 204 | :group 'dired-preview) 205 | 206 | (defcustom dired-preview-trigger-commands 207 | '( dired-next-line 208 | dired-previous-line 209 | dired-flag-file-deletion 210 | dired-mark 211 | dired-unmark 212 | dired-unmark-backward 213 | dired-del-marker 214 | dired-goto-file 215 | dired-find-file 216 | scroll-up-command 217 | scroll-down-command) 218 | "List of commands that trigger a preview when `dired-preview-mode' is enabled. 219 | Also see `dired-preview-trigger-on-start'." 220 | :type '(repeat function) 221 | :package-version '(dired-preview . "0.6.0") 222 | :group 'dired-preview) 223 | 224 | (defcustom dired-preview-hook nil 225 | "Normal hook that runs after a preview is displayed. 226 | Functions that need to run in the preview window should wrap their body 227 | in the `dired-preview-with-window' macro." 228 | :type 'hook 229 | :package-version '(dired-preview . "0.7.0") 230 | :group 'dired-preview) 231 | 232 | (defvar dired-preview--buffers nil 233 | "List with buffers of previewed files.") 234 | 235 | (defvar dired-preview--large-files-alist nil 236 | "Alist mapping previewed large files to buffer names.") 237 | 238 | (defun dired-preview--get-buffers () 239 | "Return buffers that show previews." 240 | (seq-filter #'buffer-live-p dired-preview--buffers)) 241 | 242 | (defun dired-preview--get-directories () 243 | "Return directories from preview buffers." 244 | (when-let* ((buffers (dired-preview--get-buffers))) 245 | (delq nil 246 | (mapcar 247 | (lambda (buffer) 248 | (with-current-buffer buffer 249 | (when (derived-mode-p 'dired-mode) 250 | (dired-current-directory)))) 251 | buffers)))) 252 | 253 | (declare-function dired-dwim-target-next "dired-aux" (&optional all-frames)) 254 | 255 | (defun dired-preview-get-future-history () 256 | "Function for `dired-dwim-target' to get directories." 257 | (let ((target-directories (dired-dwim-target-next :all-frames))) 258 | (if-let* ((preview-directories (dired-preview--get-directories))) 259 | (seq-remove 260 | (lambda (file) 261 | (member file preview-directories)) 262 | target-directories) 263 | target-directories))) 264 | 265 | (defun dired-preview--get-buffer-cumulative-size (buffers) 266 | "Return cumulative size of BUFFERS." 267 | (let ((size 0)) 268 | (dolist (buffer buffers) 269 | (setq size (+ (buffer-size buffer) size))) 270 | size)) 271 | 272 | (defun dired-preview--kill-buffers-by-size (buffers max-combined-size) 273 | "Kill BUFFERS to not exceed MAX-COMBINED-SIZE." 274 | (catch 'enough 275 | (dolist (buffer buffers) 276 | (if (>= (dired-preview--get-buffer-cumulative-size buffers) max-combined-size) 277 | (if (eq buffer (current-buffer)) 278 | (setq buffers (delq buffer buffers)) 279 | (ignore-errors (kill-buffer-if-not-modified buffer))) 280 | (throw 'enough t)))) 281 | (setq dired-preview--buffers (delq nil (nreverse buffers)))) 282 | 283 | (defun dired-preview--kill-buffers-by-length (buffers max-length) 284 | "Kill BUFFERS up to MAX-LENGTH." 285 | (let ((length (length buffers))) 286 | (catch 'enough 287 | (dolist (buffer buffers) 288 | (if (>= length max-length) 289 | (progn 290 | (if (eq buffer (current-buffer)) 291 | (setq buffers (delq buffer buffers)) 292 | (ignore-errors (kill-buffer-if-not-modified buffer))) 293 | (setq length (1- length))) 294 | (throw 'enough t))))) 295 | (setq dired-preview--buffers (delq nil (nreverse buffers)))) 296 | 297 | (defun dired-preview--kill-buffers-unconditionally (buffers) 298 | "Kill all BUFFERS except the current one." 299 | (dolist (buffer buffers) 300 | (when (not (eq buffer (current-buffer))) 301 | (ignore-errors (kill-buffer-if-not-modified buffer))) 302 | (setq buffers (delq buffer buffers))) 303 | (setq dired-preview--buffers (delq nil (nreverse buffers)))) 304 | 305 | (defun dired-preview--kill-buffers (&optional kill-all) 306 | "Implement `dired-preview-kill-buffers-method'. 307 | With optional KILL-ALL, kill all buffers regardless of the 308 | aforementioned user option." 309 | (when-let* ((buffers (nreverse (dired-preview--get-buffers)))) 310 | (cond 311 | (kill-all 312 | (dired-preview--kill-buffers-unconditionally buffers)) 313 | (dired-preview-kill-buffers-method 314 | (pcase-let ((`(,method . ,number) dired-preview-kill-buffers-method)) 315 | (pcase method 316 | ('combined-size (dired-preview--kill-buffers-by-size buffers number)) 317 | ('buffer-number (dired-preview--kill-buffers-by-length buffers number)) 318 | (_ (error "The `%s' in `dired-preview-kill-buffers-method' is unknown" method)))))))) 319 | 320 | (defun dired-preview--kill-large-buffers () 321 | "Kill buffers previewing large files." 322 | (dolist (pair dired-preview--large-files-alist) 323 | (let ((buffer (cdr pair))) 324 | (and (bufferp buffer) 325 | (kill-buffer buffer)))) 326 | (setq dired-preview--large-files-alist nil)) 327 | 328 | (defun dired-preview--kill-placeholder-buffers () 329 | "Kill all placeholder preview buffers." 330 | (setq dired-preview--buffers 331 | (seq-remove (lambda (buffer) 332 | (with-current-buffer buffer 333 | (when (and (boundp 'dired-preview--placeholder-buffer-p) 334 | dired-preview--placeholder-buffer-p) 335 | (ignore-errors (kill-buffer buffer)) 336 | t))) 337 | (dired-preview--get-buffers)))) 338 | 339 | (defun dired-preview--window-parameter-p (window) 340 | "Return non-nil if WINDOW has `dired-preview-window' parameter." 341 | (window-parameter window 'dired-preview-window)) 342 | 343 | (defun dired-preview--get-windows () 344 | "Return windows that show previews." 345 | (seq-filter #'dired-preview--window-parameter-p (window-list))) 346 | 347 | (defun dired-preview--delete-windows () 348 | "Delete preview windows or clean them up if they should not be deleted." 349 | (dolist (window (dired-preview--get-windows)) 350 | (if (and (not (one-window-p)) 351 | (window-live-p window) 352 | (not (eq window (minibuffer-window))) 353 | (not (window-prev-buffers window))) 354 | (delete-window window) 355 | (dired-preview--clean-up-window window)))) 356 | 357 | (defun dired-preview--file-ignored-p (file) 358 | "Return non-nil if FILE extension is among the ignored extensions. 359 | See user option `dired-preview-ignored-extensions-regexp'." 360 | (when-let* (((stringp dired-preview-ignored-extensions-regexp)) 361 | ((not (file-directory-p file))) 362 | (file-nondir (file-name-nondirectory file))) 363 | (string-match-p dired-preview-ignored-extensions-regexp file-nondir))) 364 | 365 | (defun dired-preview--file-large-p (file) 366 | "Return non-nil if FILE exceeds `dired-preview-max-size'." 367 | (>= (or (file-attribute-size (file-attributes file)) 368 | 0) 369 | dired-preview-max-size)) 370 | 371 | (defun dired-preview--file-displayed-p (file) 372 | "Return non-nil if FILE is already displayed in a window." 373 | (when-let* ((buffer (get-file-buffer file)) 374 | (window (get-buffer-window buffer))) 375 | (window-live-p window))) 376 | 377 | (defun dired-preview--set-window-parameters (window value) 378 | "Set desired WINDOW parameters to VALUE." 379 | (with-selected-window window 380 | (set-window-parameter window 'dired-preview-window value) 381 | (set-window-parameter window 'dedicated value) 382 | (set-window-parameter window 'no-other-window value))) 383 | 384 | (defun dired-preview--clean-up-window (&optional window) 385 | "Remove preview state from WINDOW or `selected-window'." 386 | (let* ((w (or window (selected-window))) 387 | (buffer (window-buffer w))) 388 | (dired-preview--rename-buffer (window-buffer w) :make-public) 389 | (setq dired-preview--buffers (delq buffer dired-preview--buffers)) 390 | (dired-preview--set-window-parameters w nil) 391 | (remove-hook 'post-command-hook #'dired-preview--clean-up-window :local))) 392 | 393 | ;; TODO 2024-04-22: Add PDF type and concomitant method to display its buffer. 394 | (defun dired-preview--infer-type (file) 395 | "Infer what type FILE is. 396 | Return a cons cell whose `car' is a symbol describing FILE and `cdr' is 397 | FILE." 398 | (let* ((file (expand-file-name file)) 399 | (file-nondir (file-name-nondirectory file))) 400 | (cond 401 | ((and dired-preview-ignored-extensions-regexp 402 | (string-match-p dired-preview-ignored-extensions-regexp file-nondir)) 403 | (cons 'ignore file)) 404 | ((file-directory-p file) 405 | (cons 'directory file)) 406 | ((dired-preview--file-large-p file) 407 | (cons 'large file)) 408 | ((string-match-p dired-preview-image-extensions-regexp file-nondir) 409 | (cons 'image file)) 410 | (t 411 | (cons 'text file))))) 412 | 413 | (defmacro dired-preview-with-file-setup (&rest body) 414 | "Run BODY while setting up the right preview environment." 415 | (declare (indent 0)) 416 | `(cl-letf (((symbol-function 'recentf-track-opened-file) #'ignore)) 417 | (let ((file (cdr file)) 418 | (inhibit-message t) 419 | (enable-dir-local-variables nil) 420 | (enable-local-variables :safe) 421 | (non-essential t)) 422 | ,@body))) 423 | 424 | (cl-defgeneric dired-preview--get-buffer (file) 425 | "Get a buffer for FILE.") 426 | 427 | ;; FIXME 2024-04-22: We have a lot of repetitive code. Can we expand 428 | ;; a macro inside of a `cl-defmethod' or, alternatively, have a macro 429 | ;; that returns the method with its implementation? 430 | (cl-defmethod dired-preview--get-buffer ((file (head text))) 431 | "Get preview buffer for text FILE type." 432 | (dired-preview-with-file-setup 433 | (find-file-noselect file :nowarn))) 434 | 435 | (defun dired-preview--add-truncation-message () 436 | "Add a message indicating that the previewed file is truncated." 437 | (let* ((max (point-max)) 438 | (end-ov (make-overlay (1- max) max))) 439 | (overlay-put 440 | end-ov 'display 441 | (propertize "\n--PREVIEW TRUNCATED--" 'face 'shadow)))) 442 | 443 | ;;;###autoload 444 | (defmacro dired-preview-with-window (&rest body) 445 | "Evaluate BODY with the Dired preview window as selected." 446 | (declare (indent 0)) 447 | `(if-let* ((windows (dired-preview--get-windows))) 448 | (dolist (win windows) 449 | (with-selected-window win 450 | ,@body)) 451 | (user-error "No dired-preview window available"))) 452 | 453 | (defun dired-preview-find-file () 454 | "Visit the currently previewed buffer with `find-file'. 455 | This means that the buffer is no longer among the previews. 456 | 457 | Also see `dired-preview-open-dwim'." 458 | (interactive) 459 | (let (file buffer) 460 | (dired-preview-with-window 461 | (setq file buffer-file-name) 462 | (dired-preview--close-previews-outside-dired) 463 | (setq buffer (find-file-noselect file))) 464 | (pop-to-buffer buffer))) 465 | 466 | (defvar dired-preview-media-extensions-regexp 467 | "\\.\\(mp3\\|m4a\\|flac\\|mp4\\|ogg\\|mpv\\|webm\\|mov\\|wav\\)" 468 | "Regular expression matching media file extensions.") 469 | 470 | (declare-function w32-shell-execute "w32fns.c") 471 | 472 | ;; NOTE 2024-07-29: Adapted from the `dired-do-open' found in Emacs 31.0.50. 473 | (defun dired-preview--open-externally (file) 474 | "Run appropriate command to open FILE externally." 475 | (if-let* ((command (cond 476 | ((executable-find "xdg-open") 477 | "xdg-open") 478 | ((memq system-type '(gnu/linux darwin)) 479 | "open") 480 | ((memq system-type '(windows-nt ms-dos)) 481 | "start") 482 | ((eq system-type 'cygwin) 483 | "cygstart") 484 | ((executable-find "run-mailcap") 485 | "run-mailcap")))) 486 | (cond 487 | ((memq system-type '(gnu/linux)) 488 | (call-process command nil 0 nil file)) 489 | ((memq system-type '(ms-dos)) 490 | (shell-command (concat command " " (shell-quote-argument file)))) 491 | ((memq system-type '(windows-nt)) 492 | (w32-shell-execute command (convert-standard-filename file))) 493 | ((memq system-type '(cygwin)) 494 | (call-process command nil nil nil file)) 495 | ((memq system-type '(darwin)) 496 | (start-process (concat command " " file) nil command file))) 497 | (error "Cannot find a command to open `%s' externally" file))) 498 | 499 | (defun dired-preview-open-dwim () 500 | "Do-What-I-Mean open the currently previewed file. 501 | This means that the buffer is no longer among the previews. 502 | 503 | If the file name matches `dired-preview-media-extensions-regexp', 504 | `dired-preview-ignored-extensions-regexp', or 505 | `dired-preview-image-extensions-regexp', then open it externally. 506 | Otherwise, visit the file in an Emacs buffer. 507 | 508 | Also see `dired-preview-find-file'." 509 | (interactive) 510 | (let ((buffer nil)) 511 | (dired-preview-with-window 512 | (when-let* ((file buffer-file-name)) 513 | (if (or (string-match-p dired-preview-media-extensions-regexp file) 514 | (string-match-p dired-preview-ignored-extensions-regexp file) 515 | (string-match-p dired-preview-image-extensions-regexp file)) 516 | (dired-preview--open-externally file) 517 | (dired-preview--close-previews-outside-dired) 518 | (setq buffer (find-file-noselect file))))) 519 | (when buffer 520 | (pop-to-buffer buffer)))) 521 | 522 | ;; NOTE 2024-07-29: "Scroll up/down" confuses me in this context 523 | ;; because the motion is in the opposite direction. So "page up/down" 524 | ;; is fine, based on what the keys of the same name do. 525 | (defun dired-preview-page-down () 526 | "Move a page down in the preview window. 527 | This technically runs `scroll-up-command'." 528 | (interactive) 529 | (dired-preview-with-window 530 | (call-interactively 531 | (pcase (derived-mode-p major-mode) 532 | ('doc-view-mode 'doc-view-scroll-up-or-next-page) 533 | ('pdf-view-mode 'pdf-view-scroll-up-or-next-page) 534 | (_ 'scroll-up-command))))) 535 | 536 | ;; Same as above for the terminology. 537 | (defun dired-preview-page-up () 538 | "Move a page up in the preview window. 539 | This technically runs `scroll-down-command'." 540 | (interactive) 541 | (dired-preview-with-window 542 | (call-interactively 543 | (pcase (derived-mode-p major-mode) 544 | ('doc-view-mode 'doc-view-scroll-down-or-previous-page) 545 | ('pdf-view-mode 'pdf-view-scroll-down-or-previous-page) 546 | (_ 'scroll-down-command))))) 547 | 548 | (declare-function hexl-mode "hexl") 549 | (declare-function hexl-mode-exit "hexl" (&optional arg)) 550 | (defvar hexl-follow-ascii) 551 | 552 | (defun dired-preview-hexl-toggle () 553 | "Toggle preview between text and `hexl-mode'." 554 | (interactive) 555 | (dired-preview-with-window 556 | (let ((hexl-follow-ascii nil)) 557 | (if (eq major-mode 'hexl-mode) 558 | (hexl-mode-exit) 559 | (hexl-mode 1))) 560 | (dired-preview--add-truncation-message))) 561 | 562 | (cl-defmethod dired-preview--get-buffer ((file (head large))) 563 | "Get preview buffer for large FILE. 564 | The size of the leading chunk is specified by 565 | `dired-preview-chunk-size'." 566 | (dired-preview-with-file-setup 567 | (if-let* ((buffer (or (get-file-buffer file) 568 | (find-buffer-visiting file) 569 | (alist-get file dired-preview--large-files-alist nil nil #'equal)))) 570 | buffer ; Buffer is already being visited, we can reuse it 571 | (with-current-buffer (create-file-buffer file) 572 | ;; We create a buffer with a partial preview 573 | (buffer-disable-undo) 574 | (insert-file-contents file nil 1 dired-preview-chunk-size 'replace) 575 | (when (eq buffer-file-coding-system 'no-conversion) 576 | (let ((hexl-follow-ascii nil)) 577 | (hexl-mode 1))) 578 | (dired-preview--add-truncation-message) 579 | (read-only-mode t) 580 | ;; Because this buffer is not marked as visiting FILE, we need to keep 581 | ;; track of it ourselves. 582 | (setf (alist-get file dired-preview--large-files-alist nil nil 'equal) (current-buffer)))))) 583 | 584 | (cl-defmethod dired-preview--get-buffer ((file (head ignore))) 585 | "Get preview placeholder buffer for an ignored FILE." 586 | (let* ((file (cdr file)) 587 | (buffer-name (format "%s (no preview)" (file-name-nondirectory file)))) 588 | (or (get-buffer buffer-name) 589 | (with-current-buffer (get-buffer-create buffer-name) 590 | (set-visited-file-name file t) 591 | (rename-buffer buffer-name) 592 | (set-buffer-modified-p nil) 593 | (setq-local dired-preview--placeholder-buffer-p t) 594 | (setq buffer-read-only t) 595 | (current-buffer))))) 596 | 597 | (cl-defmethod dired-preview--get-buffer ((file (head directory))) 598 | "Get preview buffer for directory FILE type." 599 | (dired-preview-with-file-setup 600 | (dired-noselect file))) 601 | 602 | ;; FIXME 2024-04-22: Best way to preview images and PDF files? For now 603 | ;; this is the same as the text file type, though we need to refine 604 | ;; it. 605 | (cl-defmethod dired-preview--get-buffer ((file (head image))) 606 | "Get preview buffer for image FILE type." 607 | (dired-preview-with-file-setup 608 | (find-file-noselect file :nowarn))) 609 | 610 | (defun dired-preview--add-to-previews (file) 611 | "Add FILE to `dired-preview--buffers', if not already in a buffer. 612 | Return FILE buffer or nil." 613 | (cl-letf (((symbol-function 'recentf-track-opened-file) #'ignore)) 614 | (let* ((inhibit-message t) 615 | (existing-buffer (or (find-buffer-visiting file) 616 | (and (file-directory-p file) 617 | (car (dired-buffers-for-dir file))))) 618 | (new-buffer (unless existing-buffer 619 | (dired-preview--get-buffer (dired-preview--infer-type file))))) 620 | (dired-preview--kill-buffers) 621 | (when new-buffer 622 | (with-current-buffer new-buffer 623 | (add-hook 'post-command-hook #'dired-preview--clean-up-window nil :local)) 624 | (add-to-list 'dired-preview--buffers new-buffer)) 625 | (or existing-buffer new-buffer)))) 626 | 627 | (defun dired-preview--get-preview-buffer (file) 628 | "Return buffer to preview FILE in." 629 | (dired-preview--add-to-previews file)) 630 | 631 | (defvar dired-preview-buffer-name "*dired-preview*" 632 | "Name of preview buffer.") 633 | 634 | (defun dired-preview-get-window-size (dimension) 635 | "Return window size by checking for DIMENSION. 636 | DIMENSION is either a `:width' or `:height' keyword. It is 637 | checked against `split-width-threshold' or 638 | `split-height-threshold'" 639 | (pcase dimension 640 | (:width (if-let* ((window-width (floor (window-total-width) 2)) 641 | ((>= window-width fill-column))) 642 | window-width 643 | fill-column)) 644 | (:height (floor (window-height) 2)))) 645 | 646 | (defun dired-preview-display-action-side () 647 | "Pick a side window that is appropriate for the given frame." 648 | (if-let* (split-width-threshold 649 | (width (window-body-width)) 650 | ((>= width (window-body-height))) 651 | ((>= width split-width-threshold))) 652 | `(:side right :dimension window-width :size ,(dired-preview-get-window-size :width)) 653 | `(:side bottom :dimension window-height :size ,(dired-preview-get-window-size :height)))) 654 | 655 | (defun dired-preview-display-action-alist-dwim () 656 | "Reference function for `dired-preview-display-action-alist'. 657 | Determine whether to show a preview window on the right side or at the 658 | bottom of the frame, depending on the available space, and set the size 659 | of the window accordingly. 660 | 661 | Return a `display-buffer' action alist, as described in the 662 | aforementioned user option." 663 | (let ((properties (dired-preview-display-action-side))) 664 | `((display-buffer-in-side-window) 665 | (side . ,(plist-get properties :side)) 666 | (,(plist-get properties :dimension) . ,(plist-get properties :size))))) 667 | 668 | (defun dired-preview-display-action-alist-below () 669 | "Reference function for `dired-preview-display-action-alist'. 670 | Always show the preview window below the currently selected window and 671 | always keep the height of the preview window to 0.3 times that of the 672 | total height of the frame. 673 | 674 | Return a `display-buffer' action alist, as described in the 675 | aforementioned user option." 676 | `((display-buffer-below-selected) 677 | (window-height . 0.3) 678 | (dedicated . t) 679 | (preserve-size . (t . t)))) 680 | 681 | (defvar dired-preview--timer nil 682 | "Most recent timer object to display a preview.") 683 | 684 | (defun dired-preview--cancel-timer () 685 | "Cancel `dired-preview--timer' if it is a timer object." 686 | (when (timerp dired-preview--timer) 687 | (cancel-timer dired-preview--timer))) 688 | 689 | (defun dired-preview--close-previews () 690 | "Kill preview buffers and delete their windows." 691 | (dired-preview--cancel-timer) 692 | (dired-preview--delete-windows) 693 | (dired-preview--kill-buffers :kill-all) 694 | (dired-preview--kill-large-buffers) 695 | (dired-preview--kill-placeholder-buffers)) 696 | 697 | (defun dired-preview--close-previews-outside-dired () 698 | "Call `dired-preview--close-previews' if the current buffer is not in Dired mode. 699 | Do not consider the minibuffer as being another mode." 700 | (unless (or (eq major-mode 'dired-mode) (minibufferp)) 701 | (dired-preview--close-previews) 702 | (remove-hook 'window-state-change-hook #'dired-preview--close-previews-outside-dired) 703 | (put 'dired-preview-start 'function-executed nil))) 704 | 705 | (defun dired-preview--display-buffer (buffer) 706 | "Call `display-buffer' for BUFFER. 707 | Only do it with the current major mode is Dired." 708 | (let ((action-alist (cond 709 | ((functionp dired-preview-display-action-alist) 710 | (funcall dired-preview-display-action-alist)) 711 | (dired-preview-display-action-alist)))) 712 | (display-buffer buffer action-alist))) 713 | 714 | (defun dired-preview--remove-preview-indicator (name) 715 | "Remove `dired-preview-buffer-name-indicator' from NAME." 716 | (string-trim 717 | (string-replace dired-preview-buffer-name-indicator "" name) 718 | "[\s\t\n\r]+" nil)) 719 | 720 | (defun dired-preview--rename-buffer (buffer &optional make-public) 721 | "Rename BUFFER to have `dired-preview-buffer-name-indicator'. 722 | With optional MAKE-PUBLIC, remove the indicator." 723 | (let ((name (buffer-name buffer))) 724 | (with-current-buffer buffer 725 | (cond 726 | (make-public 727 | (rename-buffer (dired-preview--remove-preview-indicator name) :make-unique)) 728 | ((and (not (string-match-p (regexp-quote dired-preview-buffer-name-indicator) name)) 729 | (memq buffer dired-preview--buffers)) 730 | (rename-buffer (format "%s %s" dired-preview-buffer-name-indicator name) :make-unique)))))) 731 | 732 | (defun dired-preview-display-file (file) 733 | "Display preview of FILE if appropriate." 734 | (dired-preview--delete-windows) 735 | (when-let* ((buffer (dired-preview--get-preview-buffer file))) 736 | (dired-preview--display-buffer buffer) 737 | (dired-preview--rename-buffer buffer) 738 | (when-let* ((window (get-buffer-window buffer))) 739 | (dired-preview--set-window-parameters window t) 740 | (run-hooks 'dired-preview-hook)))) 741 | 742 | (defvar dired-preview-encryption-file-extensions '(".gpg" ".age") 743 | "List of strings specifying file extensions for encryption.") 744 | 745 | (defun dired-preview--file-encrypted-p (file) 746 | "Return non-nil if FILE is encrypted. 747 | More specifically, test if FILE has an extension among the 748 | `dired-preview-encryption-file-extensions'." 749 | (when-let* ((extension (file-name-extension file :include-period))) 750 | (member extension dired-preview-encryption-file-extensions))) 751 | 752 | (defun dired-preview--preview-p (file) 753 | "Return non-nil if FILE can be previewed." 754 | (and file 755 | (not (string-match-p "/\\./" file)) 756 | (not (dired-preview--file-encrypted-p file)) 757 | (or (file-regular-p file) (file-directory-p file)) 758 | (file-readable-p file) 759 | (not (dired-preview--file-displayed-p file)) 760 | (or dired-preview-ignored-show-ignored-placeholders 761 | (not (dired-preview--file-ignored-p file))))) 762 | 763 | (defun dired-preview-start (file) 764 | "Preview FILE instantly when invoking Dired." 765 | (when dired-preview-trigger-on-start 766 | (unless (get 'dired-preview-start 'function-executed) 767 | (put 'dired-preview-start 'function-executed t) 768 | (dired-preview-display-file file)))) 769 | 770 | (defun dired-preview--start-idle-timer (file) 771 | "Start the idle timer to preview FILE." 772 | (setq dired-preview--timer 773 | (run-with-idle-timer 774 | (if (> dired-preview-delay 0) 775 | dired-preview-delay 776 | 0.1) 777 | nil #'dired-preview-display-file file))) 778 | 779 | (defun dired-preview-trigger (&optional no-delay) 780 | "Trigger display of file at point after `dired-preview-trigger-commands'. 781 | With optional NO-DELAY do not start a timer. Otherwise produce 782 | the preview with `dired-preview-delay' of idleness." 783 | (condition-case nil 784 | (if (eq major-mode 'dired-mode) 785 | (progn 786 | (add-hook 'window-state-change-hook #'dired-preview--close-previews-outside-dired) 787 | (dired-preview--cancel-timer) 788 | (let* ((file (dired-file-name-at-point)) 789 | (preview (dired-preview--preview-p file))) 790 | (cond 791 | ((and preview (memq this-command dired-preview-trigger-commands)) 792 | (if no-delay 793 | (dired-preview-display-file file) 794 | (dired-preview--start-idle-timer file))) 795 | (preview 796 | (dired-preview-start file)) 797 | ((and (not preview) 798 | (memq this-command dired-preview-trigger-commands)) 799 | (dired-preview--delete-windows))))) 800 | (dired-preview--close-previews-outside-dired)) 801 | ((error user-error quit) nil))) 802 | 803 | (defun dired-preview-get-first-window () 804 | "Return a window object for `other-window-scroll-default'." 805 | (car (dired-preview--get-windows))) 806 | 807 | (defun dired-preview-disable-preview () 808 | "Disable Dired preview." 809 | (unless (eq major-mode 'dired-mode) 810 | (user-error "Can only use `dired-preview' in Dired")) 811 | (when (and other-window-scroll-default 812 | (eq other-window-scroll-default #'dired-preview-get-first-window)) 813 | (setq-local other-window-scroll-default nil)) 814 | (setq-local dired-dwim-target nil) 815 | (remove-hook 'post-command-hook #'dired-preview-trigger :local) 816 | (dired-preview--close-previews) 817 | (put 'dired-preview-start 'function-executed nil)) 818 | 819 | (defun dired-preview-enable-preview () 820 | "Enable Dired preview." 821 | (unless (eq major-mode 'dired-mode) 822 | (user-error "Can only use `dired-preview' in Dired")) 823 | (when (>= emacs-major-version 29) 824 | (setq-local other-window-scroll-default #'dired-preview-get-first-window)) 825 | (setq-local dired-dwim-target #'dired-preview-get-future-history) 826 | (add-hook 'post-command-hook #'dired-preview-trigger nil :local) 827 | (dired-preview-trigger :no-delay)) 828 | 829 | (defvar dired-preview-mode-map 830 | (let ((map (make-sparse-keymap))) 831 | (define-key map (kbd "C-c C-x") #'dired-preview-hexl-toggle) 832 | (define-key map (kbd "C-c C-f") #'dired-preview-find-file) 833 | (define-key map (kbd "C-c C-o") #'dired-preview-open-dwim) 834 | (define-key map (kbd "C-c C-u") #'dired-preview-page-up) 835 | (define-key map (kbd "C-c C-d") #'dired-preview-page-down) 836 | map) 837 | "Key map for `dired-preview-mode'.") 838 | 839 | ;;;###autoload 840 | (define-minor-mode dired-preview-mode 841 | "Buffer-local mode to preview file at point in Dired." 842 | :keymap dired-preview-mode-map 843 | :global nil 844 | (if dired-preview-mode 845 | (dired-preview-enable-preview) 846 | (dired-preview-disable-preview))) 847 | 848 | (defun dired-preview--on () 849 | "Enable `dired-preview-mode' in Dired." 850 | (when (eq major-mode 'dired-mode) 851 | (dired-preview-mode 1))) 852 | 853 | ;;;###autoload 854 | (define-globalized-minor-mode dired-preview-global-mode 855 | dired-preview-mode dired-preview--on) 856 | 857 | (provide 'dired-preview) 858 | ;;; dired-preview.el ends here 859 | -------------------------------------------------------------------------------- /README.org: -------------------------------------------------------------------------------- 1 | #+title: dired-preview.el: automatically preview files in Dired 2 | #+author: Protesilaos Stavrou 3 | #+email: info@protesilaos.com 4 | #+language: en 5 | #+options: ':t toc:nil author:t email:t num:t 6 | #+startup: content 7 | #+macro: stable-version 0.6.0 8 | #+macro: release-date 2025-07-18 9 | #+macro: development-version 0.7.0-dev 10 | #+macro: file @@texinfo:@file{@@$1@@texinfo:}@@ 11 | #+macro: space @@texinfo:@: @@ 12 | #+macro: kbd @@texinfo:@kbd{@@$1@@texinfo:}@@ 13 | #+export_file_name: dired-preview.texi 14 | #+texinfo_filename: dired-preview.info 15 | #+texinfo_dir_category: Emacs misc features 16 | #+texinfo_dir_title: Dired-Preview: (dired-preview) 17 | #+texinfo_dir_desc: Automatically preview files in Dired 18 | #+texinfo_header: @set MAINTAINERSITE @uref{https://protesilaos.com,maintainer webpage} 19 | #+texinfo_header: @set MAINTAINER Protesilaos Stavrou 20 | #+texinfo_header: @set MAINTAINEREMAIL @email{info@protesilaos.com} 21 | #+texinfo_header: @set MAINTAINERCONTACT @uref{mailto:info@protesilaos.com,contact the maintainer} 22 | 23 | #+texinfo: @insertcopying 24 | 25 | This manual, written by Protesilaos Stavrou, describes the 26 | functionality and customization options of ~dired-preview~ (or 27 | ~dired-preview.el~) package, and provides every other piece of 28 | information pertinent to it. 29 | 30 | The documentation furnished herein corresponds to stable version 31 | {{{stable-version}}}, released on {{{release-date}}}. Any reference 32 | to a newer feature which does not yet form part of the latest tagged 33 | Git commit, is explicitly marked as such. 34 | 35 | Current development target is {{{development-version}}}. 36 | 37 | + Package name (GNU ELPA): ~dired-preview~ 38 | + Official manual: 39 | + Git repositories: 40 | + GitHub: 41 | + GitLab: 42 | + Backronym: Directories Invariably Render Everything Decently ... 43 | preview; dired ... PDFs Require Extra Viewing Instructions for Emacs 44 | to Work. 45 | 46 | #+toc: headlines 8 insert TOC here, with eight headline levels 47 | 48 | * COPYING 49 | :PROPERTIES: 50 | :COPYING: t 51 | :CUSTOM_ID: h:475b7969-8a84-4ae6-9bf8-3a7cb741cd64 52 | :END: 53 | 54 | Copyright (C) 2023-2025 Free Software Foundation, Inc. 55 | 56 | #+begin_quote 57 | Permission is granted to copy, distribute and/or modify this document 58 | under the terms of the GNU Free Documentation License, Version 1.3 or 59 | any later version published by the Free Software Foundation; with no 60 | Invariant Sections, with the Front-Cover Texts being “A GNU Manual,” and 61 | with the Back-Cover Texts as in (a) below. A copy of the license is 62 | included in the section entitled “GNU Free Documentation License.” 63 | 64 | (a) The FSF’s Back-Cover Text is: “You have the freedom to copy and 65 | modify this GNU manual.” 66 | #+end_quote 67 | 68 | * Overview 69 | :PROPERTIES: 70 | :CUSTOM_ID: h:b518b406-ed29-4739-9b55-fd633e957b22 71 | :END: 72 | 73 | This is a simple and robust package to automatically preview in a side 74 | window the file at point in Dired buffers. Preview windows are closed 75 | when they are no longer relevant, while preview buffers are killed if 76 | they have not been used for other purposes beside previewing. 77 | 78 | #+findex: dired-preview-mode 79 | #+findex: dired-preview-global-mode 80 | Enable the ~dired-preview-mode~ in the current Dired buffer or 81 | ~dired-preview-global-mode~ for all Dired buffers and then perform the 82 | regular up/down motions. Those will trigger the preview. 83 | 84 | #+vindex: dired-preview-max-size 85 | #+vindex: dired-preview-delay 86 | The previewed file is displayed in a side window if its size is below 87 | the number specified in the user option ~dired-preview-max-size~. 88 | Previews are shown subject to a small delay, per ther user option 89 | ~dired-preview-delay~: if the value of the delay is 0, then it is 90 | internally understood as 0.1 as no delay can affect performance. 91 | 92 | #+vindex: dired-preview-trigger-on-start 93 | When entering a directory, a preview is triggered outright if the user 94 | option ~dired-preview-trigger-on-start~ is set to a non-nil value (the 95 | default). 96 | 97 | #+vindex: dired-preview-trigger-commands 98 | Other than entering a directory, a preview happens after one of the 99 | commands in ~dired-preview-trigger-commands~ is invoked. 100 | 101 | #+vindex: dired-preview-ignored-extensions-regexp 102 | #+vindex: dired-preview-ignored-show-ignored-placeholders 103 | Files matching the ~dired-preview-ignored-extensions-regexp~ are not 104 | previewed, though a preview window is still displayed if the user 105 | option ~dired-preview-ignored-show-ignored-placeholders~ is non-nil. 106 | This is to avoid windows jumping in and out of focus as the user moves 107 | between files. 108 | 109 | #+vindex: dired-preview-buffer-name-indicator 110 | Preview buffers have a prefix to their name to make them stand out. 111 | This is controlled by the user option ~dired-preview-buffer-name-indicator~. 112 | 113 | #+vindex: dired-preview-kill-buffers-method 114 | While using Dired, preview buffers are killed according to the user 115 | option ~dired-preview-kill-buffers-method~. The default method is to 116 | kill buffers that exceed a combined size. An alternative is to kill 117 | buffers that exceed a certain number. Else to not kill any buffers. 118 | Buffers are always killed upon exiting Dired. 119 | 120 | [ In the near future, we may find ways to quickly preview any file 121 | type without affecting the performance of Emacs. ] 122 | 123 | Large files are previewed in ~hexl-mode~ mode. The user can disable 124 | this mode by typing =C-c C-c=. 125 | 126 | I took inspiration for ~dired-preview~ from the now unmaintained 127 | ~peep-dired~ package by Adam Sokolnicki: . 128 | My original plan was to volunteer to maintain ~peep-dired~ but I 129 | decided to write it my own way: it was easier for me, plus I can 130 | implement only what I consider necessary without upsetting existing 131 | users. 132 | 133 | ** The commands available in the preview window 134 | :PROPERTIES: 135 | :CUSTOM_ID: h:b63d9f69-d595-415b-b7c8-b24697ea27ce 136 | :END: 137 | 138 | The ~dired-preview-mode~ and its global variant activate the ~dired-preview-mode-map~. 139 | This key map binds the following commands: 140 | 141 | #+findex: dired-preview-find-file 142 | - ~dired-preview-find-file~ :: Visit the currently previewed buffer 143 | with ~find-file~. This means that the buffer is no longer among the 144 | previews. 145 | 146 | #+findex: dired-preview-open-dwim 147 | #+vindex: dired-preview-media-extensions-regexp 148 | #+vindex: dired-preview-image-extensions-regexp 149 | - ~dired-preview-open-dwim~ :: Do-What-I-Mean open the currently 150 | previewed file. This means that the buffer is no longer among the 151 | previews. If the file name matches 152 | ~dired-preview-media-extensions-regexp~, 153 | ~dired-preview-ignored-extensions-regexp~, or 154 | ~dired-preview-image-extensions-regexp~, then open it externally. 155 | Otherwise, visit the file in an Emacs buffer. 156 | 157 | #+findex: dired-preview-page-up 158 | - ~dired-preview-page-up~ :: Perform a "page up" motion in the preview 159 | window. 160 | 161 | #+findex: dired-preview-page-down 162 | - ~dired-preview-page-down~ :: Perform a "page down" motion in the 163 | preview window. 164 | 165 | #+findex: dired-preview-hexl-toggle 166 | - ~dired-preview-hexl-toggle~ :: Toggle preview between text and 167 | ~hexl-mode~. 168 | 169 | ** How to tweak the placement of the preview window 170 | :PROPERTIES: 171 | :CUSTOM_ID: h:25135eb2-04a9-403e-bc3a-8ee287ac36cf 172 | :END: 173 | 174 | #+vindex: dired-preview-display-action-alist 175 | The user option ~dired-preview-display-action-alist~ 176 | speficies a function to handle the display of the preview. The 177 | default value will place the preview either to the right or the 178 | bottom side window, depending on the available width. 179 | 180 | Users can specify their own conditions with something like this: 181 | 182 | #+begin_src emacs-lisp 183 | (defun my-dired-preview-to-the-right () 184 | "My preferred `dired-preview-display-action-alist-function'." 185 | '((display-buffer-in-side-window) 186 | (side . right) 187 | (window-width . 0.3))) 188 | 189 | (setq dired-preview-display-action-alist #'my-dired-preview-to-the-right) 190 | #+end_src 191 | 192 | Note that the ~display-buffer~ mechanism is inherently complex and 193 | powerful. As such, this user option must be treated with care as a 194 | false value will break things. 195 | 196 | We still provide two functions which probably are enough to cover 197 | users' needs: 198 | 199 | #+findex: dired-preview-display-action-alist-dwim 200 | - The function ~dired-preview-display-action-alist-dwim~ is the 201 | default value of ~dired-preview-display-action-alist~. It will 202 | display the preview window either at the right hand side or the 203 | bottom of the frame, depending on the available space. It will also 204 | try to resize the window accordingly. 205 | 206 | #+findex: dired-preview-display-action-alist-below 207 | - Whereas the function ~dired-preview-display-action-alist-below~ has 208 | a more simple behaviour of always displaying the preview window 209 | below the currently selected window and always setting the preview 210 | window's height to 0.3 times the height of the frame. 211 | 212 | * Installation 213 | :PROPERTIES: 214 | :CUSTOM_ID: h:30b9c20c-071d-4943-a9a7-e8d7e7ea33e3 215 | :END: 216 | #+cindex: Installation instructions 217 | 218 | ** GNU ELPA package 219 | :PROPERTIES: 220 | :CUSTOM_ID: h:9dfb9c7c-a57b-472a-bdf6-5fb88f9ebe74 221 | :END: 222 | 223 | The package is available as ~dired-preview~. Simply do: 224 | 225 | : M-x package-refresh-contents 226 | : M-x package-install 227 | 228 | And search for it. 229 | 230 | GNU ELPA provides the latest stable release. Those who prefer to follow 231 | the development process in order to report bugs or suggest changes, can 232 | use the version of the package from the GNU-devel ELPA archive. Read: 233 | https://protesilaos.com/codelog/2022-05-13-emacs-elpa-devel/. 234 | 235 | ** Manual installation 236 | :PROPERTIES: 237 | :CUSTOM_ID: h:53495b27-c15d-4c9a-b6fc-f94a0ee55834 238 | :END: 239 | 240 | Assuming your Emacs files are found in =~/.emacs.d/=, execute the 241 | following commands in a shell prompt: 242 | 243 | #+begin_src sh 244 | cd ~/.emacs.d 245 | 246 | # Create a directory for manually-installed packages 247 | mkdir manual-packages 248 | 249 | # Go to the new directory 250 | cd manual-packages 251 | 252 | # Clone this repo, naming it "dired-preview" 253 | git clone https://github.com/protesilaos/dired-preview dired-preview 254 | #+end_src 255 | 256 | Finally, in your =init.el= (or equivalent) evaluate this: 257 | 258 | #+begin_src emacs-lisp 259 | ;; Make Elisp files in that directory available to the user. 260 | (add-to-list 'load-path "~/.emacs.d/manual-packages/dired-preview") 261 | #+end_src 262 | 263 | Everything is in place to set up the package. 264 | 265 | * Sample configuration 266 | :PROPERTIES: 267 | :CUSTOM_ID: h:088fc7b3-7d7b-434b-80b1-e2ad20bdb4ea 268 | :END: 269 | #+cindex: Package configuration 270 | 271 | Remember to read the doc string of each of these variables or functions. 272 | 273 | #+begin_src emacs-lisp 274 | (require 'dired-preview) 275 | 276 | ;; Default values for demo purposes 277 | (setq dired-preview-delay 0.7) 278 | (setq dired-preview-max-size (expt 2 20)) 279 | (setq dired-preview-ignored-extensions-regexp 280 | (concat "\\." 281 | "\\(gz\\|" 282 | "zst\\|" 283 | "tar\\|" 284 | "xz\\|" 285 | "rar\\|" 286 | "zip\\|" 287 | "iso\\|" 288 | "epub" 289 | "\\)")) 290 | 291 | ;; Enable `dired-preview-mode' in a given Dired buffer or do it 292 | ;; globally: 293 | (dired-preview-global-mode 1) 294 | #+end_src 295 | 296 | * Do-It-Yourself extensions 297 | :PROPERTIES: 298 | :CUSTOM_ID: h:c2a592d0-da08-4737-ad90-e031d7be471d 299 | :END: 300 | 301 | In this section we include sample code to help users further configure 302 | ~dired-preview~ to suit their needs. 303 | 304 | ** The ~dired-preview-with-window~ macro 305 | :PROPERTIES: 306 | :CUSTOM_ID: h:f5a5f8ed-4b03-4afc-96e2-83904be19739 307 | :END: 308 | 309 | #+findex: dired-preview-with-window 310 | The Lisp macro ~dired-preview-with-window~ can be used in custom 311 | functions to evaluate its =BODY= with the Dired Preview window as the 312 | selected one. It is what commands provided by Dired Preview also use 313 | ([[#h:b63d9f69-d595-415b-b7c8-b24697ea27ce][The commands available in the preview window]]). Use this to perform 314 | some action in the preview window's buffer. 315 | 316 | [[#h:1765efb1-f9fe-4379-8ef3-668e573e299b][Combine ~dired-preview~ with ~ready-player~]] 317 | 318 | ** Combine ~dired-preview~ with ~ready-player~ 319 | :PROPERTIES: 320 | :CUSTOM_ID: h:1765efb1-f9fe-4379-8ef3-668e573e299b 321 | :END: 322 | 323 | The ~ready-player~ package by Alvaro Ramirez produces a usable buffer 324 | for multimedia files that are otherwise not readable inside of Emacs. 325 | This buffer includes media controls and shows metadata of the file. 326 | With ~ready-player~, the user can launch an external program to play 327 | the media. It is neat! 328 | 329 | When ~dired-preview~ requests the preview of a multimedia file, it is 330 | displayed using ~ready-player~ under the hood. We can then write our 331 | own commands to call ~ready-player~ functions inside the previewed 332 | buffer ([[#h:f5a5f8ed-4b03-4afc-96e2-83904be19739][The ~dired-preview-with-window~ macro]]). Here is a sample: 333 | 334 | #+begin_src emacs-lisp 335 | (defun prot/ready-player-dired-preview-play-toggle () 336 | "Call `ready-player-toggle-play-stop' on the currently previewed media file." 337 | (interactive) 338 | (dired-preview-with-window 339 | (if-let ((file buffer-file-name) 340 | (media (concat "\\." (regexp-opt ready-player-supported-media t) "\\'")) 341 | (_ (string-match-p media file))) 342 | (call-interactively #'ready-player-toggle-play-stop) 343 | (user-error "Cannot do something useful with `ready-player' here")))) 344 | 345 | (define-key dired-preview-mode-map (kbd "C-c C-p") #'prot/ready-player-dired-preview-play-toggle) 346 | #+end_src 347 | 348 | Same idea, but open the file externally no matter what: 349 | 350 | #+begin_src emacs-lisp 351 | (defun prot/ready-player-dired-preview-open-externally () 352 | "Call `ready-player-open-externally' on the currently previewed media file." 353 | (interactive) 354 | (dired-preview-with-window 355 | (if-let ((file buffer-file-name) 356 | (media (concat "\\." (regexp-opt ready-player-supported-media t) "\\'")) 357 | (_ (string-match-p media file))) 358 | (call-interactively #'ready-player-open-externally) 359 | (user-error "Cannot do something useful with `ready-player' here")))) 360 | #+end_src 361 | 362 | * Acknowledgements 363 | :PROPERTIES: 364 | :CUSTOM_ID: h:72a35028-5b0c-4835-9e3a-8869b9241f1a 365 | :END: 366 | #+cindex: Contributors 367 | 368 | This project is meant to be a collective effort. Every bit of help 369 | matters. 370 | 371 | + Author/maintainer :: Protesilaos Stavrou. 372 | 373 | + Contributions to code or the manual :: Álvaro Ramírez (xenodium), 374 | Bruno Boal, Christian Tietze, Juergen Hoetzel, Karthik Chikmagalur, 375 | Sean Devlin, Stefan Monnier, Philip Kaludercic, Nofint. 376 | 377 | + Ideas and/or user feedback :: Alex Popescu, Bruno Boal, Ed Hamilton, 378 | Karthik Chikmagalur, Peter Prevos, Ramon Diaz-Uriarte, Yiyu Zhou, 379 | artelse, dasoju, fab6, Inkbottle00. 380 | 381 | * GNU Free Documentation License 382 | :PROPERTIES: 383 | :CUSTOM_ID: h:59ce922f-fb7e-4925-8101-a9fef614abb3 384 | :END: 385 | 386 | #+texinfo: @include doclicense.texi 387 | 388 | #+begin_export html 389 |
390 | 
391 |                 GNU Free Documentation License
392 |                  Version 1.3, 3 November 2008
393 | 
394 | 
395 |  Copyright (C) 2000, 2001, 2002, 2007, 2008 Free Software Foundation, Inc.
396 |      
397 |  Everyone is permitted to copy and distribute verbatim copies
398 |  of this license document, but changing it is not allowed.
399 | 
400 | 0. PREAMBLE
401 | 
402 | The purpose of this License is to make a manual, textbook, or other
403 | functional and useful document "free" in the sense of freedom: to
404 | assure everyone the effective freedom to copy and redistribute it,
405 | with or without modifying it, either commercially or noncommercially.
406 | Secondarily, this License preserves for the author and publisher a way
407 | to get credit for their work, while not being considered responsible
408 | for modifications made by others.
409 | 
410 | This License is a kind of "copyleft", which means that derivative
411 | works of the document must themselves be free in the same sense.  It
412 | complements the GNU General Public License, which is a copyleft
413 | license designed for free software.
414 | 
415 | We have designed this License in order to use it for manuals for free
416 | software, because free software needs free documentation: a free
417 | program should come with manuals providing the same freedoms that the
418 | software does.  But this License is not limited to software manuals;
419 | it can be used for any textual work, regardless of subject matter or
420 | whether it is published as a printed book.  We recommend this License
421 | principally for works whose purpose is instruction or reference.
422 | 
423 | 
424 | 1. APPLICABILITY AND DEFINITIONS
425 | 
426 | This License applies to any manual or other work, in any medium, that
427 | contains a notice placed by the copyright holder saying it can be
428 | distributed under the terms of this License.  Such a notice grants a
429 | world-wide, royalty-free license, unlimited in duration, to use that
430 | work under the conditions stated herein.  The "Document", below,
431 | refers to any such manual or work.  Any member of the public is a
432 | licensee, and is addressed as "you".  You accept the license if you
433 | copy, modify or distribute the work in a way requiring permission
434 | under copyright law.
435 | 
436 | A "Modified Version" of the Document means any work containing the
437 | Document or a portion of it, either copied verbatim, or with
438 | modifications and/or translated into another language.
439 | 
440 | A "Secondary Section" is a named appendix or a front-matter section of
441 | the Document that deals exclusively with the relationship of the
442 | publishers or authors of the Document to the Document's overall
443 | subject (or to related matters) and contains nothing that could fall
444 | directly within that overall subject.  (Thus, if the Document is in
445 | part a textbook of mathematics, a Secondary Section may not explain
446 | any mathematics.)  The relationship could be a matter of historical
447 | connection with the subject or with related matters, or of legal,
448 | commercial, philosophical, ethical or political position regarding
449 | them.
450 | 
451 | The "Invariant Sections" are certain Secondary Sections whose titles
452 | are designated, as being those of Invariant Sections, in the notice
453 | that says that the Document is released under this License.  If a
454 | section does not fit the above definition of Secondary then it is not
455 | allowed to be designated as Invariant.  The Document may contain zero
456 | Invariant Sections.  If the Document does not identify any Invariant
457 | Sections then there are none.
458 | 
459 | The "Cover Texts" are certain short passages of text that are listed,
460 | as Front-Cover Texts or Back-Cover Texts, in the notice that says that
461 | the Document is released under this License.  A Front-Cover Text may
462 | be at most 5 words, and a Back-Cover Text may be at most 25 words.
463 | 
464 | A "Transparent" copy of the Document means a machine-readable copy,
465 | represented in a format whose specification is available to the
466 | general public, that is suitable for revising the document
467 | straightforwardly with generic text editors or (for images composed of
468 | pixels) generic paint programs or (for drawings) some widely available
469 | drawing editor, and that is suitable for input to text formatters or
470 | for automatic translation to a variety of formats suitable for input
471 | to text formatters.  A copy made in an otherwise Transparent file
472 | format whose markup, or absence of markup, has been arranged to thwart
473 | or discourage subsequent modification by readers is not Transparent.
474 | An image format is not Transparent if used for any substantial amount
475 | of text.  A copy that is not "Transparent" is called "Opaque".
476 | 
477 | Examples of suitable formats for Transparent copies include plain
478 | ASCII without markup, Texinfo input format, LaTeX input format, SGML
479 | or XML using a publicly available DTD, and standard-conforming simple
480 | HTML, PostScript or PDF designed for human modification.  Examples of
481 | transparent image formats include PNG, XCF and JPG.  Opaque formats
482 | include proprietary formats that can be read and edited only by
483 | proprietary word processors, SGML or XML for which the DTD and/or
484 | processing tools are not generally available, and the
485 | machine-generated HTML, PostScript or PDF produced by some word
486 | processors for output purposes only.
487 | 
488 | The "Title Page" means, for a printed book, the title page itself,
489 | plus such following pages as are needed to hold, legibly, the material
490 | this License requires to appear in the title page.  For works in
491 | formats which do not have any title page as such, "Title Page" means
492 | the text near the most prominent appearance of the work's title,
493 | preceding the beginning of the body of the text.
494 | 
495 | The "publisher" means any person or entity that distributes copies of
496 | the Document to the public.
497 | 
498 | A section "Entitled XYZ" means a named subunit of the Document whose
499 | title either is precisely XYZ or contains XYZ in parentheses following
500 | text that translates XYZ in another language.  (Here XYZ stands for a
501 | specific section name mentioned below, such as "Acknowledgements",
502 | "Dedications", "Endorsements", or "History".)  To "Preserve the Title"
503 | of such a section when you modify the Document means that it remains a
504 | section "Entitled XYZ" according to this definition.
505 | 
506 | The Document may include Warranty Disclaimers next to the notice which
507 | states that this License applies to the Document.  These Warranty
508 | Disclaimers are considered to be included by reference in this
509 | License, but only as regards disclaiming warranties: any other
510 | implication that these Warranty Disclaimers may have is void and has
511 | no effect on the meaning of this License.
512 | 
513 | 2. VERBATIM COPYING
514 | 
515 | You may copy and distribute the Document in any medium, either
516 | commercially or noncommercially, provided that this License, the
517 | copyright notices, and the license notice saying this License applies
518 | to the Document are reproduced in all copies, and that you add no
519 | other conditions whatsoever to those of this License.  You may not use
520 | technical measures to obstruct or control the reading or further
521 | copying of the copies you make or distribute.  However, you may accept
522 | compensation in exchange for copies.  If you distribute a large enough
523 | number of copies you must also follow the conditions in section 3.
524 | 
525 | You may also lend copies, under the same conditions stated above, and
526 | you may publicly display copies.
527 | 
528 | 
529 | 3. COPYING IN QUANTITY
530 | 
531 | If you publish printed copies (or copies in media that commonly have
532 | printed covers) of the Document, numbering more than 100, and the
533 | Document's license notice requires Cover Texts, you must enclose the
534 | copies in covers that carry, clearly and legibly, all these Cover
535 | Texts: Front-Cover Texts on the front cover, and Back-Cover Texts on
536 | the back cover.  Both covers must also clearly and legibly identify
537 | you as the publisher of these copies.  The front cover must present
538 | the full title with all words of the title equally prominent and
539 | visible.  You may add other material on the covers in addition.
540 | Copying with changes limited to the covers, as long as they preserve
541 | the title of the Document and satisfy these conditions, can be treated
542 | as verbatim copying in other respects.
543 | 
544 | If the required texts for either cover are too voluminous to fit
545 | legibly, you should put the first ones listed (as many as fit
546 | reasonably) on the actual cover, and continue the rest onto adjacent
547 | pages.
548 | 
549 | If you publish or distribute Opaque copies of the Document numbering
550 | more than 100, you must either include a machine-readable Transparent
551 | copy along with each Opaque copy, or state in or with each Opaque copy
552 | a computer-network location from which the general network-using
553 | public has access to download using public-standard network protocols
554 | a complete Transparent copy of the Document, free of added material.
555 | If you use the latter option, you must take reasonably prudent steps,
556 | when you begin distribution of Opaque copies in quantity, to ensure
557 | that this Transparent copy will remain thus accessible at the stated
558 | location until at least one year after the last time you distribute an
559 | Opaque copy (directly or through your agents or retailers) of that
560 | edition to the public.
561 | 
562 | It is requested, but not required, that you contact the authors of the
563 | Document well before redistributing any large number of copies, to
564 | give them a chance to provide you with an updated version of the
565 | Document.
566 | 
567 | 
568 | 4. MODIFICATIONS
569 | 
570 | You may copy and distribute a Modified Version of the Document under
571 | the conditions of sections 2 and 3 above, provided that you release
572 | the Modified Version under precisely this License, with the Modified
573 | Version filling the role of the Document, thus licensing distribution
574 | and modification of the Modified Version to whoever possesses a copy
575 | of it.  In addition, you must do these things in the Modified Version:
576 | 
577 | A. Use in the Title Page (and on the covers, if any) a title distinct
578 |    from that of the Document, and from those of previous versions
579 |    (which should, if there were any, be listed in the History section
580 |    of the Document).  You may use the same title as a previous version
581 |    if the original publisher of that version gives permission.
582 | B. List on the Title Page, as authors, one or more persons or entities
583 |    responsible for authorship of the modifications in the Modified
584 |    Version, together with at least five of the principal authors of the
585 |    Document (all of its principal authors, if it has fewer than five),
586 |    unless they release you from this requirement.
587 | C. State on the Title page the name of the publisher of the
588 |    Modified Version, as the publisher.
589 | D. Preserve all the copyright notices of the Document.
590 | E. Add an appropriate copyright notice for your modifications
591 |    adjacent to the other copyright notices.
592 | F. Include, immediately after the copyright notices, a license notice
593 |    giving the public permission to use the Modified Version under the
594 |    terms of this License, in the form shown in the Addendum below.
595 | G. Preserve in that license notice the full lists of Invariant Sections
596 |    and required Cover Texts given in the Document's license notice.
597 | H. Include an unaltered copy of this License.
598 | I. Preserve the section Entitled "History", Preserve its Title, and add
599 |    to it an item stating at least the title, year, new authors, and
600 |    publisher of the Modified Version as given on the Title Page.  If
601 |    there is no section Entitled "History" in the Document, create one
602 |    stating the title, year, authors, and publisher of the Document as
603 |    given on its Title Page, then add an item describing the Modified
604 |    Version as stated in the previous sentence.
605 | J. Preserve the network location, if any, given in the Document for
606 |    public access to a Transparent copy of the Document, and likewise
607 |    the network locations given in the Document for previous versions
608 |    it was based on.  These may be placed in the "History" section.
609 |    You may omit a network location for a work that was published at
610 |    least four years before the Document itself, or if the original
611 |    publisher of the version it refers to gives permission.
612 | K. For any section Entitled "Acknowledgements" or "Dedications",
613 |    Preserve the Title of the section, and preserve in the section all
614 |    the substance and tone of each of the contributor acknowledgements
615 |    and/or dedications given therein.
616 | L. Preserve all the Invariant Sections of the Document,
617 |    unaltered in their text and in their titles.  Section numbers
618 |    or the equivalent are not considered part of the section titles.
619 | M. Delete any section Entitled "Endorsements".  Such a section
620 |    may not be included in the Modified Version.
621 | N. Do not retitle any existing section to be Entitled "Endorsements"
622 |    or to conflict in title with any Invariant Section.
623 | O. Preserve any Warranty Disclaimers.
624 | 
625 | If the Modified Version includes new front-matter sections or
626 | appendices that qualify as Secondary Sections and contain no material
627 | copied from the Document, you may at your option designate some or all
628 | of these sections as invariant.  To do this, add their titles to the
629 | list of Invariant Sections in the Modified Version's license notice.
630 | These titles must be distinct from any other section titles.
631 | 
632 | You may add a section Entitled "Endorsements", provided it contains
633 | nothing but endorsements of your Modified Version by various
634 | parties--for example, statements of peer review or that the text has
635 | been approved by an organization as the authoritative definition of a
636 | standard.
637 | 
638 | You may add a passage of up to five words as a Front-Cover Text, and a
639 | passage of up to 25 words as a Back-Cover Text, to the end of the list
640 | of Cover Texts in the Modified Version.  Only one passage of
641 | Front-Cover Text and one of Back-Cover Text may be added by (or
642 | through arrangements made by) any one entity.  If the Document already
643 | includes a cover text for the same cover, previously added by you or
644 | by arrangement made by the same entity you are acting on behalf of,
645 | you may not add another; but you may replace the old one, on explicit
646 | permission from the previous publisher that added the old one.
647 | 
648 | The author(s) and publisher(s) of the Document do not by this License
649 | give permission to use their names for publicity for or to assert or
650 | imply endorsement of any Modified Version.
651 | 
652 | 
653 | 5. COMBINING DOCUMENTS
654 | 
655 | You may combine the Document with other documents released under this
656 | License, under the terms defined in section 4 above for modified
657 | versions, provided that you include in the combination all of the
658 | Invariant Sections of all of the original documents, unmodified, and
659 | list them all as Invariant Sections of your combined work in its
660 | license notice, and that you preserve all their Warranty Disclaimers.
661 | 
662 | The combined work need only contain one copy of this License, and
663 | multiple identical Invariant Sections may be replaced with a single
664 | copy.  If there are multiple Invariant Sections with the same name but
665 | different contents, make the title of each such section unique by
666 | adding at the end of it, in parentheses, the name of the original
667 | author or publisher of that section if known, or else a unique number.
668 | Make the same adjustment to the section titles in the list of
669 | Invariant Sections in the license notice of the combined work.
670 | 
671 | In the combination, you must combine any sections Entitled "History"
672 | in the various original documents, forming one section Entitled
673 | "History"; likewise combine any sections Entitled "Acknowledgements",
674 | and any sections Entitled "Dedications".  You must delete all sections
675 | Entitled "Endorsements".
676 | 
677 | 
678 | 6. COLLECTIONS OF DOCUMENTS
679 | 
680 | You may make a collection consisting of the Document and other
681 | documents released under this License, and replace the individual
682 | copies of this License in the various documents with a single copy
683 | that is included in the collection, provided that you follow the rules
684 | of this License for verbatim copying of each of the documents in all
685 | other respects.
686 | 
687 | You may extract a single document from such a collection, and
688 | distribute it individually under this License, provided you insert a
689 | copy of this License into the extracted document, and follow this
690 | License in all other respects regarding verbatim copying of that
691 | document.
692 | 
693 | 
694 | 7. AGGREGATION WITH INDEPENDENT WORKS
695 | 
696 | A compilation of the Document or its derivatives with other separate
697 | and independent documents or works, in or on a volume of a storage or
698 | distribution medium, is called an "aggregate" if the copyright
699 | resulting from the compilation is not used to limit the legal rights
700 | of the compilation's users beyond what the individual works permit.
701 | When the Document is included in an aggregate, this License does not
702 | apply to the other works in the aggregate which are not themselves
703 | derivative works of the Document.
704 | 
705 | If the Cover Text requirement of section 3 is applicable to these
706 | copies of the Document, then if the Document is less than one half of
707 | the entire aggregate, the Document's Cover Texts may be placed on
708 | covers that bracket the Document within the aggregate, or the
709 | electronic equivalent of covers if the Document is in electronic form.
710 | Otherwise they must appear on printed covers that bracket the whole
711 | aggregate.
712 | 
713 | 
714 | 8. TRANSLATION
715 | 
716 | Translation is considered a kind of modification, so you may
717 | distribute translations of the Document under the terms of section 4.
718 | Replacing Invariant Sections with translations requires special
719 | permission from their copyright holders, but you may include
720 | translations of some or all Invariant Sections in addition to the
721 | original versions of these Invariant Sections.  You may include a
722 | translation of this License, and all the license notices in the
723 | Document, and any Warranty Disclaimers, provided that you also include
724 | the original English version of this License and the original versions
725 | of those notices and disclaimers.  In case of a disagreement between
726 | the translation and the original version of this License or a notice
727 | or disclaimer, the original version will prevail.
728 | 
729 | If a section in the Document is Entitled "Acknowledgements",
730 | "Dedications", or "History", the requirement (section 4) to Preserve
731 | its Title (section 1) will typically require changing the actual
732 | title.
733 | 
734 | 
735 | 9. TERMINATION
736 | 
737 | You may not copy, modify, sublicense, or distribute the Document
738 | except as expressly provided under this License.  Any attempt
739 | otherwise to copy, modify, sublicense, or distribute it is void, and
740 | will automatically terminate your rights under this License.
741 | 
742 | However, if you cease all violation of this License, then your license
743 | from a particular copyright holder is reinstated (a) provisionally,
744 | unless and until the copyright holder explicitly and finally
745 | terminates your license, and (b) permanently, if the copyright holder
746 | fails to notify you of the violation by some reasonable means prior to
747 | 60 days after the cessation.
748 | 
749 | Moreover, your license from a particular copyright holder is
750 | reinstated permanently if the copyright holder notifies you of the
751 | violation by some reasonable means, this is the first time you have
752 | received notice of violation of this License (for any work) from that
753 | copyright holder, and you cure the violation prior to 30 days after
754 | your receipt of the notice.
755 | 
756 | Termination of your rights under this section does not terminate the
757 | licenses of parties who have received copies or rights from you under
758 | this License.  If your rights have been terminated and not permanently
759 | reinstated, receipt of a copy of some or all of the same material does
760 | not give you any rights to use it.
761 | 
762 | 
763 | 10. FUTURE REVISIONS OF THIS LICENSE
764 | 
765 | The Free Software Foundation may publish new, revised versions of the
766 | GNU Free Documentation License from time to time.  Such new versions
767 | will be similar in spirit to the present version, but may differ in
768 | detail to address new problems or concerns.  See
769 | https://www.gnu.org/licenses/.
770 | 
771 | Each version of the License is given a distinguishing version number.
772 | If the Document specifies that a particular numbered version of this
773 | License "or any later version" applies to it, you have the option of
774 | following the terms and conditions either of that specified version or
775 | of any later version that has been published (not as a draft) by the
776 | Free Software Foundation.  If the Document does not specify a version
777 | number of this License, you may choose any version ever published (not
778 | as a draft) by the Free Software Foundation.  If the Document
779 | specifies that a proxy can decide which future versions of this
780 | License can be used, that proxy's public statement of acceptance of a
781 | version permanently authorizes you to choose that version for the
782 | Document.
783 | 
784 | 11. RELICENSING
785 | 
786 | "Massive Multiauthor Collaboration Site" (or "MMC Site") means any
787 | World Wide Web server that publishes copyrightable works and also
788 | provides prominent facilities for anybody to edit those works.  A
789 | public wiki that anybody can edit is an example of such a server.  A
790 | "Massive Multiauthor Collaboration" (or "MMC") contained in the site
791 | means any set of copyrightable works thus published on the MMC site.
792 | 
793 | "CC-BY-SA" means the Creative Commons Attribution-Share Alike 3.0
794 | license published by Creative Commons Corporation, a not-for-profit
795 | corporation with a principal place of business in San Francisco,
796 | California, as well as future copyleft versions of that license
797 | published by that same organization.
798 | 
799 | "Incorporate" means to publish or republish a Document, in whole or in
800 | part, as part of another Document.
801 | 
802 | An MMC is "eligible for relicensing" if it is licensed under this
803 | License, and if all works that were first published under this License
804 | somewhere other than this MMC, and subsequently incorporated in whole or
805 | in part into the MMC, (1) had no cover texts or invariant sections, and
806 | (2) were thus incorporated prior to November 1, 2008.
807 | 
808 | The operator of an MMC Site may republish an MMC contained in the site
809 | under CC-BY-SA on the same site at any time before August 1, 2009,
810 | provided the MMC is eligible for relicensing.
811 | 
812 | 
813 | ADDENDUM: How to use this License for your documents
814 | 
815 | To use this License in a document you have written, include a copy of
816 | the License in the document and put the following copyright and
817 | license notices just after the title page:
818 | 
819 |     Copyright (c)  YEAR  YOUR NAME.
820 |     Permission is granted to copy, distribute and/or modify this document
821 |     under the terms of the GNU Free Documentation License, Version 1.3
822 |     or any later version published by the Free Software Foundation;
823 |     with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
824 |     A copy of the license is included in the section entitled "GNU
825 |     Free Documentation License".
826 | 
827 | If you have Invariant Sections, Front-Cover Texts and Back-Cover Texts,
828 | replace the "with...Texts." line with this:
829 | 
830 |     with the Invariant Sections being LIST THEIR TITLES, with the
831 |     Front-Cover Texts being LIST, and with the Back-Cover Texts being LIST.
832 | 
833 | If you have Invariant Sections without Cover Texts, or some other
834 | combination of the three, merge those two alternatives to suit the
835 | situation.
836 | 
837 | If your document contains nontrivial examples of program code, we
838 | recommend releasing these examples in parallel under your choice of
839 | free software license, such as the GNU General Public License,
840 | to permit their use in free software.
841 | 
842 | #+end_export 843 | 844 | #+html: 873 | --------------------------------------------------------------------------------