Browse Source

New command `org-capture-string'

* org-capture.el (org-capture-string): New command to prompt
for the interactive text interactively.  This can also be used
in Elisp programs to use ̀org-capture' with some initial text.
(org-capture-initial): New variable to store the initial text.
(org-capture): Use `org-capture-initial'.
Bastien Guerry 7 years ago
parent
commit
1737d3c4ee
1 changed files with 13 additions and 3 deletions
  1. 13 3
      lisp/org-capture.el

+ 13 - 3
lisp/org-capture.el

@@ -431,6 +431,14 @@ for a capture buffer.")
 ;;; The main commands
 
 ;;;###autoload
+(defvar org-capture-initial nil)
+(defun org-capture-string (string &optional keys)
+  (interactive "sInitial text: \n")
+  (let ((org-capture-initial string)
+	(entry (org-capture-select-template keys)))
+    (org-capture)))
+
+;;;###autoload
 (defun org-capture (&optional goto keys)
   "Capture something.
 \\<org-capture-mode-map>
@@ -462,9 +470,11 @@ bypassed."
 				org-capture-link-is-already-stored)
 			   (plist-get org-store-link-plist :annotation)
 			 (ignore-errors (org-store-link nil))))
-	   (initial (and (org-region-active-p)
-			 (buffer-substring (point) (mark))))
-	   (entry (org-capture-select-template keys)))
+	   (entry (or entry (org-capture-select-template keys)))
+	   initial)
+      (setq initial (or org-capture-initial
+			(and (org-region-active-p)
+			     (buffer-substring (point) (mark)))))
       (when (stringp initial)
 	(remove-text-properties 0 (length initial) '(read-only t) initial))
       (when (stringp annotation)