(require 'evil) (require 'pollen-mode) (require 'comint) (defun insert-lozenge () "inserts the lozenge character for use with Pollen" ;; enables function through M-x (interactive) ;; insert the proper character (insert (make-char 'mule-unicode-2500-33ff 34 42))) (defcustom pollen-target-format "pdf" "Options to build pollen document" :type 'string :group 'pollen-mode) (defun pollen-target-file (source) (replace-regexp-in-string "\\.poly\\.pm" (concat "." pollen-target-format) source)) (defun pollen-build () "Build pollen document" (interactive) (let* ((tmp-buf (current-buffer)) (file-name (buffer-file-name)) (cmd (concat "raco pollen render " (pollen-target-file file-name))) (buf-name "*pollen compilation *")) (if (fboundp 'compilation-start) (compilation-start cmd nil #'(lambda (mode-name) buf-name)) (compile-internal cmd "no more errors" buf-name)))) (defun pollen-set-target-format () (interactive) (let ((fmt (read-string "Output format:"))) (if (or (string= fmt "pdf") (string= fmt "html") (string= fmt "txt") (string= fmt "ltx")) (setq pollen-target-format fmt) (message "Unsupported format %s\n" fmt)))) (defun pollen-view () (interactive) (let* ((file-name (concat (pollen-target-file (buffer-file-name)))) (cmd "open") (tmp-buf (current-buffer))) (apply 'make-comint cmd cmd nil (list file-name)) (switch-to-buffer tmp-buf) (switch-to-buffer-other-window (concat "*" cmd "*")))) (defun pollen-reset () (interactive) (let ((cmd "raco") (tmp-buf (current-buffer))) (apply 'make-comint cmd cmd nil (list "pollen" "reset")) (switch-to-buffer tmp-buf) (switch-to-buffer-other-window (concat "*" cmd "*")))) (define-minor-mode evil-pollen-mode "Buffer local minor mode for evil-pollen " :init-value nil :lighter "EvilPollen" :keymap (make-sparse-keymap) :group 'evil-pollen) (mapc #'(lambda (state) (evil-define-key state evil-pollen-mode-map (kbd "M-b") 'pollen-build (kbd "M-f") 'pollen-set-target-format (kbd "M-v") 'pollen-view (kbd "M-c") 'pollen-reset)) '(normal insert)) (global-set-key "\M-\\" 'insert-lozenge) (provide 'evil-pollen)