diff --git a/applescript/org-pandoc-new.applescript b/applescript/org-pandoc-new.applescript new file mode 100644 index 0000000..b7ad3a3 --- /dev/null +++ b/applescript/org-pandoc-new.applescript @@ -0,0 +1,7 @@ +tell application id "com.devon-technologies.thinkpro2" + set active_selection to selection + set selection_name to name of item 1 of active_selection + set selection_path to path of item 1 of active_selection + set appname to (path to frontmost application as Unicode text) + do shell script "emacsclient -n -e '(org-pandoc-new nil \"'" & quoted form of appname & "'\")'" +end tell diff --git a/applescript/org-pandoc.applescript b/applescript/org-pandoc-open.applescript similarity index 100% rename from applescript/org-pandoc.applescript rename to applescript/org-pandoc-open.applescript diff --git a/elisp/org-pandoc.el b/elisp/org-pandoc.el index bc0573f..2d10758 100644 --- a/elisp/org-pandoc.el +++ b/elisp/org-pandoc.el @@ -145,21 +145,20 @@ end tell'" app))) (rename-buffer (format "*Pandoc: %s*" name) t) (setq org-pandoc-orig-file (aref record 1)) (org-pandoc-mode 1)) - ;(delete-file outfile) - (message "%s" outfile) - ))) - + (delete-file outfile)))) (set-buffer-modified-p nil)) (defun org-pandoc-commit () (interactive) - (when org-pandoc-orig-app - (org-pandoc-save) - (when org-pandoc-orig-app - (focus-window org-pandoc-orig-app)) - (kill-buffer) - (delete-frame))) + (org-pandoc-save) + (let (buf (current-buffer)) + (if org-pandoc-orig-app + (progn + (focus-window org-pandoc-orig-app) + (kill-buffer buf) + (delete-frame)) + (kill-buffer buf)))) (defun org-pandoc-open (infile &optional inname inapp) @@ -184,6 +183,29 @@ end tell'" app))) (select-frame-set-input-focus (selected-frame)))))) +(defun org-pandoc-new (&optional mode inapp) + (interactive) + (when (null mode) + (setq mode 'org-mode)) + + (let* ((buf-name (loop for n upfrom 0 + for name = (format "*Pandoc: Untitled%s*" + (if (= n 0) "" (format " (%d)" n))) + while (get-buffer name) + finally return name)) + (buf (get-buffer-create buf-name))) + (with-current-buffer buf + (funcall mode) + (org-pandoc-mode 1) + (set (make-local-variable 'org-pandoc-orig-app) inapp)) + (if inapp + (with-selected-frame (make-frame) + (switch-to-buffer buf) + (select-frame-set-input-focus (selected-frame))) + (switch-to-buffer buf)) + buf)) + + (define-minor-mode org-pandoc-mode "Toggle org-pandoc-mode. With no argument, this command toggles the mode.