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.
This commit is contained in:
Carsten Dominik 2010-04-14 09:42:50 +02:00
parent 9cfebf0842
commit 2339c5afa7
2 changed files with 27 additions and 22 deletions

View File

@ -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> 2010-04-13 Carsten Dominik <carsten.dominik@gmail.com>
* org.el (org-align-all-tags): New command. * org.el (org-align-all-tags): New command.

View File

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