File: pdf-dev.el

package info (click to toggle)
emacs-pdf-tools 0.70-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 1,388 kB
  • ctags: 1,623
  • sloc: lisp: 11,589; ansic: 6,932; makefile: 100; cpp: 76; sh: 2
file content (85 lines) | stat: -rw-r--r-- 2,890 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
;;; pdf-dev.el --- Mother's little development helper  -*- lexical-binding: t; -*-

;; Copyright (C) 2015  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:
;; 
;; This file is only ment for developers.  The entry point is
;; pdf-dev-minor-mode, which see.

;;; Code:

(defvar pdf-dev-root-directory
  (file-name-directory
   (directory-file-name
    (file-name-directory load-file-name))))

(defun pdf-dev-reload ()
  "Reload lisp files from source."
  (interactive)
  (let ((default-directory (expand-file-name
                            "lisp"
                            pdf-dev-root-directory))
        loaded)
    (dolist (file (directory-files default-directory nil "\\`pdf-\\w*\\.el\\'"))
      (push file loaded)
      (load-file file))
    (message "Loaded %s" (mapconcat 'identity loaded " "))))
    
(define-minor-mode pdf-dev-minor-mode
  "Make developing pdf-tools easier.

It does the following:

Quits the server and sets `pdf-info-epdfinfo-program' to
../server/epdfinfo.

Installs a `compilation-finish-functions' which will restart
epdfinfo after a succesful recompilation.

Sets up `load-path' and reloads all PDF Tools lisp files."
  nil nil nil
  (let ((lisp-dir (expand-file-name "lisp" pdf-dev-root-directory)))
    (setq load-path (remove lisp-dir load-path))
    (cond
     (pdf-dev-minor-mode
      (add-hook 'compilation-finish-functions 'pdf-dev-compilation-finished)
      (add-to-list 'load-path lisp-dir)
      (setq pdf-info-epdfinfo-program
            (expand-file-name
             "epdfinfo"
             (expand-file-name "server" pdf-dev-root-directory)))
      (pdf-info-quit)
      (pdf-dev-reload))
     (t
      (remove-hook 'compilation-finish-functions 'pdf-dev-compilation-finished)))))

(defun pdf-dev-compilation-finished (buffer status)
  (with-current-buffer buffer
    (when (and (equal status "finished\n")
               (file-equal-p
                (expand-file-name "server" pdf-dev-root-directory)
                default-directory))
      (message "Restarting epdfinfo server")
      (pdf-info-quit)
      (let ((pdf-info-restart-process-p t))
        (pdf-info-process-assert-running)))))

(provide 'pdf-dev)
;;; pdf-dev.el ends here