emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/calibre 828be28570 4/9: Allow opening books in an exter


From: ELPA Syncer
Subject: [elpa] externals/calibre 828be28570 4/9: Allow opening books in an external program
Date: Tue, 16 Jan 2024 12:57:40 -0500 (EST)

branch: externals/calibre
commit 828be28570a2e8bb064d0e763b00d66ea3e4c2e6
Author: Kjartan Oli Agustsson <kjartanoli@disroot.org>
Commit: Kjartan Oli Agustsson <kjartanoli@disroot.org>

    Allow opening books in an external program
    
    * calibre-library.el (calibre-external-programs): New user option.
      (calibre-library-open-book-external): New command.
      (calibre-library-open-book): Defer to
      calibre-library-open-book-external if an appropriate entry exists in
      calibre-external-programs.
    
    * doc/calibre.texi (Reading books): Add information about
      calibre-external-programs and calibre-library-open-book-external.
    
    * etc/NEWS: Mention calibre-external-programs and
      calibre-library-open-book-external.
---
 calibre-library.el | 34 +++++++++++++++++++++++++++++++++-
 doc/calibre.texi   | 18 ++++++++++++++----
 etc/NEWS           | 10 ++++++++++
 3 files changed, 57 insertions(+), 5 deletions(-)

diff --git a/calibre-library.el b/calibre-library.el
index 7a62953cd7..8cac3d1017 100644
--- a/calibre-library.el
+++ b/calibre-library.el
@@ -31,6 +31,17 @@
 (require 'calibre-virtual-library)
 (require 'calibre-edit)
 
+(defcustom calibre-external-programs nil
+  "A mapping of formats to external programs used to read them.
+
+This is an alist, where each entry is of the form (FORMAT
+. PROGRAM).  FORMAT is a symbol identifying a book format and
+PROGRAM is a string naming an external program to use when
+opening books in that format."
+  :type '(repeat (cons (symbol :tag "Format") (string :tag "Program")))
+  :group 'calibre
+  :package-version '("calibre" . "1.4.0"))
+
 ;;;###autoload
 (defun calibre-library-add-book (file)
   "Add FILE to the Calibre library."
@@ -107,7 +118,10 @@ If called with a prefix argument prompt the user for the 
format."
   (let ((format (if arg
                     (completing-read "Format: " (calibre-book-formats book) 
nil t)
                   (calibre-book--pick-format book))))
-    (find-file (calibre-book--file book format))))
+    (let ((program (alist-get format calibre-external-programs)))
+      (if program
+          (calibre-library-open-book-external book program)
+        (find-file (calibre-book--file book format))))))
 
 (defun calibre-library-open-book-other-window (book &optional arg)
   "Open BOOK in its preferred format, in another window.
@@ -120,6 +134,24 @@ If called with a prefix argument prompt the user for the 
format."
                   (calibre-book--pick-format book))))
     (find-file-other-window (calibre-book--file book format))))
 
+(defun calibre-library-open-book-external (book &optional command arg)
+  "Open BOOK in an external program.
+If called with a prefix argument prompt the user for the format."
+  (interactive (list (tabulated-list-get-id)
+                     nil
+                     current-prefix-arg)
+               calibre-library-mode)
+  (let* ((format (if arg
+                    (completing-read "Format: " (calibre-book-formats book) 
nil t)
+                  (calibre-book--pick-format book)))
+         (command (if command
+                      command
+                    (read-shell-command "Open with: " (alist-get format 
calibre-external-programs)))))
+    (start-process (format "%s-external" (calibre-book-title book))
+                   nil
+                   command
+                   (calibre-book--file book format))))
+
 (defvar-keymap calibre-library-mode-map
   :doc "Local keymap for Calibre Library buffers."
   :parent tabulated-list-mode-map
diff --git a/doc/calibre.texi b/doc/calibre.texi
index 37fd17a973..4e1ffb66b5 100644
--- a/doc/calibre.texi
+++ b/doc/calibre.texi
@@ -121,10 +121,20 @@ To read a book simply press @kbd{@key{RET}}
 the @file{*Library*} buffer.  This will open a new buffer containing the
 book at point in the current window.  Alternatively you can also press
 @kbd{o} (@code{calibre-library-open-book-other-window}), which will open
-the book in a different window.  To actually read a book Emacs must of
-course be able to display the file format in which the book is stored,
-which may require the presence of additional tools on your system
-@xref{Document View,,,Emacs}.
+the book in a different window.
+
+@findex calibre-library-open-book-external
+@vindex calibre-external-formats
+To actually read a book Emacs must of course be able to display the file
+format in which the book is stored, which may require the presence of
+additional tools on your system @xref{Document View,,,Emacs}.  If Emacs
+is not able to display your chosen format, or you simply prefer using
+another program, you can also open the book in an external program using
+@code{calibre-library-open-book-external} or customize
+@code{calibre-external-formats}.  If an entry for a particular format
+exists en @code{calibre-external-formats}
+@code{calibre-library-open-book} will use the specified program instead
+of opening the file in Emacs.
 
 @menu
 * Choosing formats::
diff --git a/etc/NEWS b/etc/NEWS
index 688b8130a4..228914094e 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -7,6 +7,16 @@ This file is about changes in calibre.el, the Emacs client for
 Calibre.
 
 
+* Changes in calibre.el 1.4.0
+** Allow opening books in external programs
+The new calibre-library-open-book-external command allows opening
+books using an external program.
+
+The new calibre-external-programs user option allows specifying
+external programs to use for specific formats instead of opening the
+file in Emacs.
+
+
 * Changes in calibre.el 1.3.4
 ** Allow searching by title in composite filters
 The filter composition interface lacked the ability to filter by



reply via email to

[Prev in Thread] Current Thread [Next in Thread]