summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Politz <politza@hochschule-trier.de>2018-10-08 21:16:40 +0200
committerAndreas Politz <politza@hochschule-trier.de>2018-10-08 21:16:40 +0200
commitd8dc23f48a44135f48b2bace16a182d501fa9744 (patch)
tree12281662bbe9c9b9210102346bea49cbd25dff82
parent66dd313dbb1d078fa847805b0d7cf9797bec9e4c (diff)
Add a new, faster procedure for loading this package
-rw-r--r--NEWS4
-rw-r--r--README.org11
-rw-r--r--lisp/pdf-loader.el76
3 files changed, 88 insertions, 3 deletions
diff --git a/NEWS b/NEWS
index ed91464..2f4218e 100644
--- a/NEWS
+++ b/NEWS
@@ -8,6 +8,10 @@
pdf-annot-default-markup-annotation-properties. The new variable
let's the user choose default properties, e.g. a color, for all
supported annotations separately.
+** Provide a faster "boot-loader"
+ The autoloaded function `pdf-loader-install' acts as a replacement
+ for ‘pdf-tools-install’ and makes Emacs load and use PDF Tools as soon
+ as a PDF file is opened, but not sooner.
* Version 0.80
** Tablist package
The files tablist.el and tablist-filter.el are no longer part of
diff --git a/README.org b/README.org
index 5158bf5..34791f7 100644
--- a/README.org
+++ b/README.org
@@ -277,9 +277,14 @@
#+begin_src elisp
(pdf-tools-install)
#+end_src
- somewhere in your ~.emacs~. Next you probably want to take a look at
- the various features of what you've just installed. The following
- two commands might be of help for doing so.
+ somewhere in your ~.emacs~. Alternatively, and if you care about
+ start-up time, you may want to use
+#+begin_src elisp
+ (pdf-loader-install)
+#+end_src
+ instead. Next you probably want to take a look at the various
+ features of what you've just installed. The following two commands
+ might be of help for doing so.
#+begin_src elisp
M-x pdf-tools-help RET
M-x pdf-tools-customize RET
diff --git a/lisp/pdf-loader.el b/lisp/pdf-loader.el
new file mode 100644
index 0000000..e303755
--- /dev/null
+++ b/lisp/pdf-loader.el
@@ -0,0 +1,76 @@
+;;; pdf-loader.el --- Minimal PDF Tools loader -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2017 Andreas Politz
+
+;; Author: Andreas Politz <politza@hochschule-trier.de>
+;; Keywords:
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;;
+
+;;; Code:
+
+(defconst pdf-loader--auto-mode-alist-item
+ (copy-sequence "\\.[pP][dD][fF]\\'")
+ "The item used in `auto-mode-alist'.")
+
+(defconst pdf-loader--magic-mode-alist-item
+ (copy-sequence "%PDF")
+ "The item used in`magic-mode-alist'.")
+
+
+;;;###autoload
+(defun pdf-loader-install (&optional no-query-p skip-dependencies-p
+ no-error-p force-dependencies-p)
+ "Prepare Emacs for using PDF Tools.
+
+This function acts as a replacement for `pdf-tools-install' and
+makes Emacs load and use PDF Tools as soon as a PDF file is
+opened, but not sooner.
+
+The arguments are passed verbatim to `pdf-tools-install', which
+see."
+ (let ((args (list no-query-p skip-dependencies-p
+ no-error-p force-dependencies-p)))
+ (if (featurep 'pdf-tools)
+ (apply #'pdf-tools-install args)
+ (pdf-loader--install
+ (apply #'pdf-loader-load args)))))
+
+(defun pdf-loader--load (&rest args)
+ (pdf-loader--uninstall)
+ (save-selected-window
+ (pdf-tools-install args)))
+
+(defun pdf-loader--install (loader)
+ (setf (alist-get pdf-loader--auto-mode-alist-item
+ auto-mode-alist nil nil #'equal)
+ loader)
+ (setf (alist-get pdf-loader--magic-mode-alist-item
+ magic-mode-alist nil nil #'equal)
+ loader))
+
+(defun pdf-loader--uninstall ()
+ (setf (alist-get pdf-loader--auto-mode-alist-item
+ auto-mode-alist nil :remove #'equal)
+ nil)
+ (setf (alist-get pdf-loader--magic-mode-alist-item
+ magic-mode-alist nil :remove #'equal)
+ nil))
+
+(provide 'pdf-loader)
+;;; pdf-loader.el ends here