org-make.txt 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. %.html: %.org
  2. emacs -batch -l batch-export.el --eval "(batch-org-export-as 'html)" $<
  3. %.pdf: %.tex
  4. latexmk --shell-escape -pdf -xelatex $<
  5. %.tex: %.org
  6. emacs -batch -l batch-export.el --eval "(batch-org-export-as 'latex)" $<
  7. ;;; -*- mode: emacs-lisp -*-
  8. (add-to-list 'load-path (expand-file-name "~/src/emacs/org/org-mode/lisp"))
  9. (add-to-list 'auto-mode-alist '("\\.\\(org\\|org_archive\\|txt\\)$" . org-mode))
  10. (setq org-export-backends '(html latex))
  11. (require 'org-loaddefs)
  12. (defun org-export-file-to (backend src dest)
  13. (with-temp-buffer
  14. (insert-file-contents src)
  15. (org-export-to-file backend dest)))
  16. (setq file-suffixes
  17. '((html . ".html")
  18. (latex . ".tex")
  19. (pdf . ".pdf")))
  20. (defun org-export-dest (backend f)
  21. (concat (file-name-sans-extension f) (cdr (assoc backend file-suffixes))))
  22. (defun batch-org-export-as (backend &optional noforce)
  23. "Run `org-export-as' with the given backend on the files remaining on the command line.
  24. Use this from the command line, with `-batch'; it won't work in
  25. an interactive Emacs. Each file is processed even if an error
  26. occurred previously. For example, invoke \"emacs -batch -f
  27. batch-byte-compile $emacs/ ~/*.el\". If NOFORCE is non-nil,
  28. don't recompile a file that seems to be already up-to-date."
  29. ;; command-line-args-left is what is left of the command line, from
  30. ;; startup.el.
  31. (defvar command-line-args-left) ;Avoid 'free variable' warning
  32. (if (not noninteractive)
  33. (error "`batch-org-export-as' is to be used only with -batch"))
  34. (let ((error nil))
  35. (while command-line-args-left
  36. (if (file-directory-p (expand-file-name (car command-line-args-left)))
  37. ;; Directory as argument.
  38. (let (source dest)
  39. (dolist (file (directory-files (car command-line-args-left)))
  40. (if (and (string-match emacs-lisp-file-regexp file)
  41. (not (auto-save-file-name-p file))
  42. (setq source
  43. (expand-file-name file
  44. (car command-line-args-left)))
  45. (setq dest (org-export-dest backend source))
  46. (file-exists-p dest)
  47. (file-newer-than-file-p source dest))
  48. (if (null (org-export-file-to backend source dest))
  49. (setq error t)))))
  50. ;; Specific file argument
  51. (let* ((source (car command-line-args-left))
  52. (dest (org-export-dest backend source)))
  53. (if (or (not noforce)
  54. (or (not (file-exists-p dest))
  55. (file-newer-than-file-p source dest)))
  56. (if (null (org-export-file-to backend (car command-line-args-left) dest))
  57. (setq error t)))))
  58. (setq command-line-args-left (cdr command-line-args-left)))
  59. (kill-emacs (if error 1 0))))