Browse Source

ASCII export: Hide output buffer and dump exported text to kill ring

Carsten Dominik 16 years ago
parent
commit
b681a86075
2 changed files with 24 additions and 11 deletions
  1. 6 0
      lisp/ChangeLog
  2. 18 11
      lisp/org-ascii.el

+ 6 - 0
lisp/ChangeLog

@@ -1,3 +1,9 @@
+2009-05-19  Carsten Dominik  <carsten.dominik@gmail.com>
+
+	* org-ascii.el (org-export-ascii-copy-to-kill): New option.
+	(org-export-as-ascii): Hide export buffer, and copy exported ASCII
+	to kill ring.
+
 2009-05-17  Carsten Dominik  <carsten.dominik@gmail.com>
 2009-05-17  Carsten Dominik  <carsten.dominik@gmail.com>
 
 
 	* org-ascii.el (org-export-as-ascii): Fix bug with match string in
 	* org-ascii.el (org-export-as-ascii): Fix bug with match string in

+ 18 - 11
lisp/org-ascii.el

@@ -33,6 +33,12 @@
   :tag "Org Export ASCII"
   :tag "Org Export ASCII"
   :group 'org-export)
   :group 'org-export)
 
 
+(defcustom org-export-ascii-copy-to-kill t
+  "Non-nil means, copy ASCII export aways to kill ring.
+This makes it easy to generate ASCII and then paste it."
+  :group 'org-export-ascii
+  :type 'boolean)
+
 (defcustom org-export-ascii-underline '(?\$ ?\# ?^ ?\~ ?\= ?\-)
 (defcustom org-export-ascii-underline '(?\$ ?\# ?^ ?\~ ?\= ?\-)
   "Characters for underlining headings in ASCII export.
   "Characters for underlining headings in ASCII export.
 In the given sequence, these characters will be used for level 1, 2, ..."
 In the given sequence, these characters will be used for level 1, 2, ..."
@@ -56,7 +62,6 @@ in this way, it will be wrapped."
   :group 'org-export-ascii
   :group 'org-export-ascii
   :type 'boolean)
   :type 'boolean)
 
 
-
 ;;; ASCII export
 ;;; ASCII export
 
 
 (defvar org-ascii-current-indentation nil) ; For communication
 (defvar org-ascii-current-indentation nil) ; For communication
@@ -245,12 +250,9 @@ publishing directory."
     (setq org-min-level (org-get-min-level lines level-offset))
     (setq org-min-level (org-get-min-level lines level-offset))
     (setq org-last-level org-min-level)
     (setq org-last-level org-min-level)
     (org-init-section-numbers)
     (org-init-section-numbers)
-
-    (switch-to-buffer buffer)
-
     (setq lang-words (or (assoc language org-export-language-setup)
     (setq lang-words (or (assoc language org-export-language-setup)
 			 (assoc "en" org-export-language-setup)))
 			 (assoc "en" org-export-language-setup)))
-    (switch-to-buffer-other-window buffer)
+    (set-buffer buffer)
     (erase-buffer)
     (erase-buffer)
     (fundamental-mode)
     (fundamental-mode)
     ;; create local variables for all options, to make sure all called
     ;; create local variables for all options, to make sure all called
@@ -456,12 +458,17 @@ publishing directory."
 	(goto-char beg)))
 	(goto-char beg)))
     (or to-buffer (save-buffer))
     (or to-buffer (save-buffer))
     (goto-char (point-min))
     (goto-char (point-min))
-    (prog1 (if (eq to-buffer 'string)
-	       (prog1 (buffer-substring (point-min) (point-max))
-		 (kill-buffer (current-buffer)))
-	     (current-buffer))
-      (when hidden
-	(delete-window)))))
+    (when org-export-ascii-copy-to-kill
+      (kill-new (buffer-string))
+      (when (fboundp 'x-set-selection)
+	(x-set-selection 'PRIMARY (buffer-string))
+	(x-set-selection 'CLIPBOARD (buffer-string)))
+      (message "Exported ASCII pushed to kill ring and clipboard"))
+    ;; Return the buffer or a string, according to how this function was called
+    (if (eq to-buffer 'string)
+	(prog1 (buffer-substring (point-min) (point-max))
+	  (kill-buffer (current-buffer)))
+      (current-buffer))))
 
 
 (defun org-export-ascii-preprocess (parameters)
 (defun org-export-ascii-preprocess (parameters)
   "Do extra work for ASCII export"
   "Do extra work for ASCII export"