doomemacs/modules/tools/upload/config.el

53 lines
2.1 KiB
EmacsLisp
Raw Normal View History

;;; tools/upload/config.el -*- lexical-binding: t; -*-
2017-02-19 18:54:32 -05:00
;; Uses `ssh-deploy' to map a local folder to a remote one. Set
;; `ssh-deploy-root-remote' and `ssh-deploy-root-local' in a .dir-locals.el file
;; to establish this mapping.
2017-02-19 18:54:32 -05:00
;;
2017-04-16 16:09:01 -04:00
;; Example:
;; ((nil . ((ssh-deploy-root-local . "/local/path/to/project")
;; (ssh-deploy-root-remote . "/ssh:user@server:/remote/project/")
;; (ssh-deploy-on-explicity-save . t))))
2017-04-16 16:09:01 -04:00
;;
;; Note: `ssh-deploy-root-local' is optional, and will resort to
;; `doom-project-root' if unspecified.
2017-02-19 18:54:32 -05:00
(def-package! ssh-deploy
2017-02-19 18:54:32 -05:00
:commands (ssh-deploy-upload-handler
ssh-deploy-upload-handler-forced
ssh-deploy-diff-handler
ssh-deploy-browse-remote-handler
2017-02-19 18:54:32 -05:00
ssh-deploy-remote-changes-handler)
:init
;; Make these safe as file-local variables
(dolist (sym '((ssh-deploy-root-local . stringp)
(ssh-deploy-root-remote . stringp)
(ssh-deploy-script . functionp)
(ssh-deploy-on-explicitly-save . booleanp)
(ssh-deploy-async . booleanp)
(ssh-deploy-exclude-list . listp)))
(put (car sym) 'safe-local-variable (cdr sym)))
2017-02-19 18:54:32 -05:00
;; Maybe auto-upload on save
(defun +upload|init-after-save ()
2017-04-16 16:09:01 -04:00
(when (and (bound-and-true-p ssh-deploy-root-remote)
ssh-deploy-on-explicit-save)
2017-02-19 18:54:32 -05:00
(ssh-deploy-upload-handler)))
(add-hook 'after-save-hook #'+upload|init-after-save)
2017-02-19 18:54:32 -05:00
2017-04-16 16:09:01 -04:00
;; Enable ssh-deploy if variables are set, and check for changes on open file
;; (if possible)
(defun +upload|init-find-file ()
2017-02-19 18:54:32 -05:00
(when (bound-and-true-p ssh-deploy-root-remote)
2017-04-16 16:09:01 -04:00
(require 'ssh-deploy)
2017-02-19 18:54:32 -05:00
(unless ssh-deploy-root-local
(setq ssh-deploy-root-local (doom-project-root)))
(when ssh-deploy-automatically-detect-remote-changes
(ssh-deploy-remote-changes-handler))))
(add-hook 'find-file-hook #'+upload|init-find-file)
2017-02-19 18:54:32 -05:00
:config
(setq ssh-deploy-revision-folder (concat doom-cache-dir "ssh-revisions/")
ssh-deploy-on-explicit-save t
ssh-deploy-automatically-detect-remote-changes t))