浏览代码

Fix bug in mapping entries

Patch by Peter Jones, following a bug report by Xiao-Jong Jin, who wrote:

> If you have the follow org file
>
> * test crypt							      :crypt:
> ** subheading 1
>   text 1
> ** subheading 2
>   text 2
>
> with setup as
>
> (require 'org-crypt)
> (setq org-tags-exclude-from-inheritance '("crypt"))
> (setq org-crypt-key "CBC0714E")              ; my key
>
> On calling org-encrypt-entry on the first head line, only
> subheading 1 get encrypted, subheading 2 remains plain text.
> But, if you add an empty line or some text under the first
> heading, both subheading 1 and 2 are encrypted.
Carsten Dominik 15 年之前
父节点
当前提交
2339c5afa7
共有 2 个文件被更改,包括 27 次插入22 次删除
  1. 4 0
      lisp/ChangeLog
  2. 23 22
      lisp/org-crypt.el

+ 4 - 0
lisp/ChangeLog

@@ -1,3 +1,7 @@
+2010-04-14  Carsten Dominik  <carsten.dominik@gmail.com>
+
+	* org-crypt.el (org-encrypt-entry): Improve mapping behavior.
+
 2010-04-13  Carsten Dominik  <carsten.dominik@gmail.com>
 
 	* org.el (org-align-all-tags): New command.

+ 23 - 22
lisp/org-crypt.el

@@ -105,28 +105,29 @@ heading.  This can also be overridden in the CRYPTKEY property."
   (require 'epg)
   (save-excursion
     (org-back-to-heading t)
-    (forward-line)
-    (when (not (looking-at "-----BEGIN PGP MESSAGE-----"))
-      (let ((folded (org-invisible-p))
-	    (epg-context (epg-make-context nil t t))
-	    (crypt-key (org-crypt-key-for-heading))
-	    (beg (point))
-	    end encrypted-text)
-	(org-end-of-subtree t t)
-	(org-back-over-empty-lines)
-        (setq end (point)
-              encrypted-text
-              (epg-encrypt-string
-               epg-context
-               (buffer-substring-no-properties beg end)
-               (epg-list-keys epg-context crypt-key)))
-        (delete-region beg end)
-        (insert encrypted-text)
-	(when folded
-	  (save-excursion
-	    (org-back-to-heading t)
-	    (hide-subtree)))
-        nil))))
+    (let ((start-heading (point)))
+      (forward-line)
+      (when (not (looking-at "-----BEGIN PGP MESSAGE-----"))
+        (let ((folded (org-invisible-p))
+              (epg-context (epg-make-context nil t t))
+              (crypt-key (org-crypt-key-for-heading))
+              (beg (point))
+              end encrypted-text)
+          (goto-char start-heading)
+          (org-end-of-subtree t t)
+          (org-back-over-empty-lines)
+          (setq end (point)
+                encrypted-text
+                (epg-encrypt-string
+                 epg-context
+                 (buffer-substring-no-properties beg end)
+                 (epg-list-keys epg-context crypt-key)))
+          (delete-region beg end)
+          (insert encrypted-text)
+          (when folded
+            (goto-char start-heading)
+            (hide-subtree))
+          nil)))))
 
 (defun org-decrypt-entry ()
   "Decrypt the content of the current headline."