config

Personal configuration.
git clone git://code.dwrz.net/config
Log | Files | Refs

pdf-dev.el (3008B)


      1 ;;; pdf-dev.el --- Mother's little development helper  -*- lexical-binding: t; -*-
      2 
      3 ;; Copyright (C) 2015  Andreas Politz
      4 
      5 ;; Author: Andreas Politz <politza@hochschule-trier.de>
      6 ;; Keywords:
      7 
      8 ;; This program is free software; you can redistribute it and/or modify
      9 ;; it under the terms of the GNU General Public License as published by
     10 ;; the Free Software Foundation, either version 3 of the License, or
     11 ;; (at your option) any later version.
     12 
     13 ;; This program is distributed in the hope that it will be useful,
     14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
     15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16 ;; GNU General Public License for more details.
     17 
     18 ;; You should have received a copy of the GNU General Public License
     19 ;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
     20 
     21 ;;; Commentary:
     22 ;;
     23 ;; This file is only meant for developers.  The entry point is
     24 ;; pdf-dev-minor-mode, which see.
     25 
     26 ;;; Code:
     27 
     28 (defvar pdf-dev-root-directory
     29   (file-name-directory
     30    (directory-file-name
     31     (file-name-directory load-file-name))))
     32 
     33 (defun pdf-dev-reload ()
     34   "Reload Lisp files from source."
     35   (interactive)
     36   (let ((default-directory (expand-file-name
     37                             "lisp"
     38                             pdf-dev-root-directory))
     39         loaded)
     40     (dolist (file (directory-files default-directory nil "\\`pdf-\\w*\\.el\\'"))
     41       (push file loaded)
     42       (load-file file))
     43     (message "Loaded %s" (mapconcat 'identity loaded " "))))
     44 
     45 (define-minor-mode pdf-dev-minor-mode
     46   "Make developing pdf-tools easier.
     47 
     48 It does the following:
     49 
     50 Quits the server and sets `pdf-info-epdfinfo-program' to
     51 ../server/epdfinfo.
     52 
     53 Installs a `compilation-finish-functions' which will restart
     54 epdfinfo after a successful recompilation.
     55 
     56 Sets up `load-path' and reloads all PDF Tools Lisp files."
     57   :group 'pdf-dev
     58   (let ((lisp-dir (expand-file-name "lisp" pdf-dev-root-directory)))
     59     (setq load-path (remove lisp-dir load-path))
     60     (cond
     61      (pdf-dev-minor-mode
     62       (add-hook 'compilation-finish-functions 'pdf-dev-compilation-finished)
     63       (add-to-list 'load-path lisp-dir)
     64       (setq pdf-info-epdfinfo-program
     65             (expand-file-name
     66              "epdfinfo"
     67              (expand-file-name "server" pdf-dev-root-directory)))
     68       (pdf-info-quit)
     69       (pdf-dev-reload))
     70      (t
     71       (remove-hook 'compilation-finish-functions 'pdf-dev-compilation-finished)))))
     72 
     73 (defun pdf-dev-compilation-finished (buffer status)
     74   "Restart the epdfinfo server.
     75 
     76 BUFFER is the PDF buffer and STATUS is the compilation status of
     77 building epdfinfo."
     78   (with-current-buffer buffer
     79     (when (and (equal status "finished\n")
     80                (file-equal-p
     81                 (expand-file-name "server" pdf-dev-root-directory)
     82                 default-directory))
     83       (message "Restarting epdfinfo server")
     84       (pdf-info-quit)
     85       (let ((pdf-info-restart-process-p t))
     86         (pdf-info-process-assert-running)))))
     87 
     88 (provide 'pdf-dev)
     89 ;;; pdf-dev.el ends here