瀏覽代碼

Fix read-only issue with capture

* lisp/org-capture.el (org-capture): Remove read-only text properties
from capture text.
(org-capture-set-target-location): Throw an error if file+headline
target does not point into a file which is in Org mode.

Richard Riley writes:

> If I select a region in, in this case, an erc (emacs irc client)
> buffer in the read only section and then use my global keys to create
> a new item using the following "j" template while the text is still
> selected
>
> ("j" "Journal" entry
>  (file+datetree "journal.org")
>  "* %T %?\n  %i\n  %a")
>
> then I get the following backtrace :-
>
> Debugger entered--Lisp error: (error "Capture abort: (text-read-only)")
>  signal(error ("Capture abort: (text-read-only)"))
>  error("Capture abort: %s" (text-read-only))
>  byte-code("\301\302!\203\n
Carsten Dominik 14 年之前
父節點
當前提交
d8498a40e8
共有 1 個文件被更改,包括 6 次插入0 次删除
  1. 6 0
      lisp/org-capture.el

+ 6 - 0
lisp/org-capture.el

@@ -383,6 +383,10 @@ bypassed."
 	   (initial (and (org-region-active-p)
 			 (buffer-substring (point) (mark))))
 	   (entry (org-capture-select-template keys)))
+      (when initial
+	(remove-text-properties 0 (length initial) '(read-only t) initial))
+      (when annotation
+	(remove-text-properties 0 (length initial) '(read-only t) annotation))
       (cond
        ((equal entry "C")
 	(customize-variable 'org-capture-templates))
@@ -590,6 +594,8 @@ already gone."
 	(set-buffer (org-capture-target-buffer (nth 1 target)))
 	(let ((hd (nth 2 target)))
 	  (goto-char (point-min))
+	  (unless (org-mode-p)
+	    (error "Target buffer for file+headline should be in Org mode"))
 	  (if (re-search-forward
 	       (format org-complex-heading-regexp-format (regexp-quote hd))
 	       nil t)