Klimi's new dotfiles with stow.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

85 lines
2.8 KiB

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