From 5ffd8eece138f38613cdcc2a4a447e9bcf070e4c Mon Sep 17 00:00:00 2001 From: Alex Poslavsky Date: Fri, 31 Jan 2014 17:06:45 +0200 Subject: [PATCH] Added promote / demote functionality, instead of only promote from draft to post --- hyde.el | 59 +++++++++++++++++++++++++++++++++------------------------ 1 file changed, 34 insertions(+), 25 deletions(-) diff --git a/hyde.el b/hyde.el index 0eed53b..ddb1b17 100644 --- a/hyde.el +++ b/hyde.el @@ -276,32 +276,41 @@ user" "/" (match-string-no-properties 2)))) assets)))) - -(defun hyde/promote-to-post (pos) - "Promotes the post under the cursor from a draft to a post" + +(defun hyde/prodemote-to-post (pos) + "Move file (& assets) drafts to posts and visa-versa" (interactive "d") (let ( - (post-file-name (nth - 1 - (split-string (strip-string (thing-at-point 'line)) " : "))) - (dir (get-text-property pos 'dir))) - (if (equal dir hyde-drafts-dir) + (post-file-name (nth 1 (split-string (strip-string (thing-at-point 'line)) " : "))) + (dir (get-text-property pos 'dir)) + ) + (cond ((equal dir hyde-drafts-dir) + (setq temp-target-dir hyde-posts-dir)) + ((equal dir hyde-posts-dir) + (setq temp-target-dir hyde-drafts-dir)) + (t (message "You seem to have missed an actual post, aim better, please!") + (setq temp-target-dir nil)) + ) + (when temp-target-dir + + ;; Move over post assets + (dolist (asset (hyde/hyde-get-post-assets (concat dir "/" post-file-name))) (progn - ;; Move over post assets - (dolist (asset (hyde/hyde-get-post-assets (concat dir "/" post-file-name))) - (progn - (message (concat "Asset is : " asset)) - (hyde/hyde-rename-file asset - (format "%s%s" hyde-home - (replace-regexp-in-string "_drafts" "" asset))))) - ;; Move over the actual post - (hyde/hyde-rename-file (concat dir "/" post-file-name) - (concat hyde-posts-dir "/" post-file-name)))) - (hyde/vc-commit hyde-home - '() - (concat "Promoting " post-file-name)) - (hyde/load-posts))) - + (message (concat "Asset is : " asset)) + (hyde/hyde-rename-file asset + (format "%s%s" hyde-home + (replace-regexp-in-string dir "" asset))))) + + ;; Move over the actual post + (hyde/hyde-rename-file (concat dir "/" post-file-name) + (concat temp-target-dir "/" post-file-name)) + + (hyde/vc-commit hyde-home + '() + (concat "Promoting " post-file-name)) + (hyde/load-posts) + ) + )) (defun hyde/open-post-maybe (pos) "Opens the post under cursor in the editor" @@ -357,8 +366,8 @@ user" (define-key hyde-mode-map (kbd "s") 'hyde/serve) (define-key hyde-mode-map (kbd "k") 'hyde/stop-serve) (define-key hyde-mode-map (kbd "d") 'hyde/deploy) - (define-key hyde-mode-map (kbd "p") 'hyde/promote-to-post) - (define-key hyde-mode-map (kbd "q") 'hyde/quit) + (define-key hyde-mode-map (kbd "p") 'hyde/prodemote-to-post) + (define-key hyde-mode-map (kbd "q") 'hyde/quit) (define-key hyde-mode-map (kbd "RET") 'hyde/open-post-maybe) hyde-mode-map) "Keymap for Hyde")