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.
This commit is contained in:
parent
339258061e
commit
828be28570
|
@ -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
|
||||
|
|
|
@ -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::
|
||||
|
|
10
etc/NEWS
10
etc/NEWS
|
@ -6,6 +6,16 @@ See the end of the file for license conditions.
|
|||
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
|
||||
|
|
Loading…
Reference in New Issue