* alter all subtrees containing specific tag
@ 2009-03-08 4:31 news
2009-03-08 13:29 ` Carsten Dominik
2009-03-08 13:42 ` Ian Barton
0 siblings, 2 replies; 8+ messages in thread
From: news @ 2009-03-08 4:31 UTC (permalink / raw)
To: emacs-orgmode
Hi,
I use pgg to encrypt some org subtrees (e.g. the ones containing
passwords). At the moment I have to encrypt/decrypt them one at a
time by selecting the appropriate region and running
pgg-encrypt-region/pgg-decrypt-region.
I want to make a function that will automatically encrypt/decrypt all
subtrees (in the current buffer) whose headings contain an :ENCRYPT: tag.
I tried using org-map-entries, but it seems to restore the buffer to
its original state after returning.
Is there a quick way to get the start and end points of a subtree, or
place region around it? and a quick way to jump to the next heading
with a given tag?
--
aleblanc
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: alter all subtrees containing specific tag
2009-03-08 4:31 alter all subtrees containing specific tag news
@ 2009-03-08 13:29 ` Carsten Dominik
2009-03-08 18:00 ` news
` (2 more replies)
2009-03-08 13:42 ` Ian Barton
1 sibling, 3 replies; 8+ messages in thread
From: Carsten Dominik @ 2009-03-08 13:29 UTC (permalink / raw)
To: news; +Cc: emacs-orgmode
On Mar 8, 2009, at 5:31 AM, <news@aleblanc.cotse.net> <news@aleblanc.cotse.net
> wrote:
> Hi,
> I use pgg to encrypt some org subtrees (e.g. the ones containing
> passwords). At the moment I have to encrypt/decrypt them one at a
> time by selecting the appropriate region and running
> pgg-encrypt-region/pgg-decrypt-region.
> I want to make a function that will automatically encrypt/decrypt
> all
> subtrees (in the current buffer) whose headings contain
> an :ENCRYPT: tag.
> I tried using org-map-entries, but it seems to restore the buffer to
> its original state after returning.
No, org-map-entries should be perfect for this, and it does not
restore the buffer.
This should really well. The only thing that might happen, by
replacing the
subtree, that it does not know correctly where to continue and
therefore it might do
every tree twice?
> Is there a quick way to get the start and end points of a subtree,
> or
> place region around it? and a quick way to jump to the next heading
> with a given tag?
(org-mark-subtree) ;; this will include the headline
(re-search-forward "^\\*+ .*?:ENCRYPT:" nil t)
- Carsten
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: alter all subtrees containing specific tag
2009-03-08 4:31 alter all subtrees containing specific tag news
2009-03-08 13:29 ` Carsten Dominik
@ 2009-03-08 13:42 ` Ian Barton
2009-03-08 18:01 ` news
1 sibling, 1 reply; 8+ messages in thread
From: Ian Barton @ 2009-03-08 13:42 UTC (permalink / raw)
To: emacs-orgmode
> I use pgg to encrypt some org subtrees (e.g. the ones containing
> passwords). At the moment I have to encrypt/decrypt them one at a
> time by selecting the appropriate region and running
> pgg-encrypt-region/pgg-decrypt-region.
> I want to make a function that will automatically encrypt/decrypt all
> subtrees (in the current buffer) whose headings contain an :ENCRYPT: tag.
> I tried using org-map-entries, but it seems to restore the buffer to
> its original state after returning.
> Is there a quick way to get the start and end points of a subtree, or
> place region around it? and a quick way to jump to the next heading
> with a given tag?
>
Not really an answer, but I use epa and encrypt the whole file, which I
find much fiddly. You can get epa to play nicely with org mode by
putting something like:
-*- mode:org; epa-file-encrypt-to: ("me@mmyemail.com") -*-
at the top of your encrypted file.
Ian.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: alter all subtrees containing specific tag
2009-03-08 13:29 ` Carsten Dominik
@ 2009-03-08 18:00 ` news
2009-03-09 0:56 ` news
2009-03-09 2:32 ` news
2 siblings, 0 replies; 8+ messages in thread
From: news @ 2009-03-08 18:00 UTC (permalink / raw)
To: emacs-orgmode
Carsten Dominik <dominik@science.uva.nl> writes:
>> Hi,
>> I use pgg to encrypt some org subtrees (e.g. the ones containing
>> passwords). At the moment I have to encrypt/decrypt them one at a
>> time by selecting the appropriate region and running
>> pgg-encrypt-region/pgg-decrypt-region.
>> I want to make a function that will automatically encrypt/decrypt
>> all
>> subtrees (in the current buffer) whose headings contain an
>> :ENCRYPT: tag.
>> I tried using org-map-entries, but it seems to restore the buffer to
>> its original state after returning.
I discovered that the problem is with pgg-encrypt not org.
For some reason it only works properly if I call it interactively.
>
> No, org-map-entries should be perfect for this, and it does not
> restore the buffer.
> This should really well. The only thing that might happen, by
> replacing the
> subtree, that it does not know correctly where to continue and
> therefore it might do
> every tree twice?
>
>
>> Is there a quick way to get the start and end points of a subtree,
>> or
>> place region around it? and a quick way to jump to the next heading
>> with a given tag?
>
>
> (org-mark-subtree) ;; this will include the headline
I don't have this function (Org-mode version 6.24).
--
aleblanc
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: alter all subtrees containing specific tag
2009-03-08 13:42 ` Ian Barton
@ 2009-03-08 18:01 ` news
0 siblings, 0 replies; 8+ messages in thread
From: news @ 2009-03-08 18:01 UTC (permalink / raw)
To: emacs-orgmode
Ian Barton <lists@manor-farm.org> writes:
>> I use pgg to encrypt some org subtrees (e.g. the ones containing
>> passwords). At the moment I have to encrypt/decrypt them one at a
>> time by selecting the appropriate region and running
>> pgg-encrypt-region/pgg-decrypt-region. I want to make a
>> function that will automatically encrypt/decrypt all
>> subtrees (in the current buffer) whose headings contain an :ENCRYPT: tag.
>> I tried using org-map-entries, but it seems to restore the buffer to
>> its original state after returning.
>> Is there a quick way to get the start and end points of a subtree, or
>> place region around it? and a quick way to jump to the next heading
>> with a given tag?
>>
> Not really an answer, but I use epa and encrypt the whole file, which
> I find much fiddly. You can get epa to play nicely with org mode by
> putting something like:
>
> -*- mode:org; epa-file-encrypt-to: ("me@mmyemail.com") -*-
>
> at the top of your encrypted file.
>
I can encrypt the whole buffer with pgg-encrypt, but I want to be able
to just encrypt a selection of subtrees.
--
aleblanc
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: alter all subtrees containing specific tag
2009-03-08 13:29 ` Carsten Dominik
2009-03-08 18:00 ` news
@ 2009-03-09 0:56 ` news
2009-03-09 2:32 ` news
2 siblings, 0 replies; 8+ messages in thread
From: news @ 2009-03-09 0:56 UTC (permalink / raw)
To: emacs-orgmode
Carsten Dominik <dominik@science.uva.nl> writes:
>
>> Is there a quick way to get the start and end points of a subtree,
>> or
>> place region around it? and a quick way to jump to the next heading
>> with a given tag?
>
> (org-mark-subtree) ;; this will include the headline
>
> (re-search-forward "^\\*+ .*?:ENCRYPT:" nil t)
>
> - Carsten
Couldn't find the org-mark-subtree function, but the following code
works for me.
It will toggle the encryption of all subtrees in the current buffer that
are tagged with :ENCRYPT:, i.e. if the subtree is encrypted (starting
from the first line after the header, and finishing on the last
non-empty line of the subtree), it will be decrypted, otherwise it will
be encrypted.
You can use either gpg keys or a passphrase to encrypt subtrees. To use
gpg keys, enter the names of the owners of the keys at the prompt,
otherwise just press enter to use a passphrase only.
If the passphrase does not match for any encrypted subtrees they will be
left as is.
Perhaps someone could post this on Worg? (I am lazy).
(defun org-toggle-encryption (rcpts passphrase)
(interactive (list (split-string (read-string "Recipients (default is none): ") "[ \t,]+")
(pgg-read-passphrase "GnuPG passphrase: ")))
(org-map-entries '(let (start end teststring)
(org-show-subtree)
(next-line)
(org-beginning-of-line)
(setq start (point))
(setq teststring (buffer-substring start (+ start 27)))
(condition-case nil
(progn
(outline-forward-same-level 1)
(previous-line))
(error (goto-char (point-max))))
(org-end-of-line)
(setq end (point))
(if (equal teststring "-----BEGIN PGP MESSAGE-----")
(if (pgg-decrypt-region start end passphrase)
(pgg-display-output-buffer start end t)
(message "Can't decrypt region!"))
(if (equal rcpts '(""))
(pgg-encrypt-symmetric-region start end passphrase)
(pgg-encrypt-region start end rcpts nil passphrase))
(pgg-display-output-buffer start end t)))
"+ENCRYPT"))
--
aleblanc
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: alter all subtrees containing specific tag
2009-03-08 13:29 ` Carsten Dominik
2009-03-08 18:00 ` news
2009-03-09 0:56 ` news
@ 2009-03-09 2:32 ` news
2009-03-09 12:28 ` news
2 siblings, 1 reply; 8+ messages in thread
From: news @ 2009-03-09 2:32 UTC (permalink / raw)
To: emacs-orgmode
Carsten Dominik <dominik@science.uva.nl> writes:
>> Is there a quick way to get the start and end points of a subtree,
>> or
>> place region around it? and a quick way to jump to the next heading
>> with a given tag?
>
> (org-mark-subtree) ;; this will include the headline
>
> (re-search-forward "^\\*+ .*?:ENCRYPT:" nil t)
>
> - Carsten
Just discovered a bug in my previously posted function. It doesn't work
too well if you have lower level subtrees tagged for encryption.
Here is the fixed version:
(defun aleblanc-org-toggle-encryption (rcpts passphrase)
(interactive (list (split-string (read-string "Recipients (default is none): ") "[ \t,]+")
(pgg-read-passphrase "GnuPG passphrase: ")))
(show-all)
(org-map-entries '(let (start end teststring)
(org-outline-level)
(next-line)
(org-beginning-of-line)
(setq start (point))
(setq teststring (buffer-substring start (+ start 27)))
(outline-get-next-sibling)
(if (not (equal (point) (point-max)))
(previous-line))
(org-end-of-line)
(setq end (point))
(if (equal teststring "-----BEGIN PGP MESSAGE-----")
(if (pgg-decrypt-region start end passphrase)
(pgg-display-output-buffer start end t)
(message "Can't decrypt region!"))
(if (equal rcpts '(""))
(pgg-encrypt-symmetric-region start end passphrase)
(pgg-encrypt-region start end rcpts nil passphrase))
(pgg-display-output-buffer start end t)))
"+ENCRYPT"))
--
aleblanc
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: alter all subtrees containing specific tag
2009-03-09 2:32 ` news
@ 2009-03-09 12:28 ` news
0 siblings, 0 replies; 8+ messages in thread
From: news @ 2009-03-09 12:28 UTC (permalink / raw)
To: emacs-orgmode
<news@aleblanc.cotse.net> writes:
>
> Just discovered a bug in my previously posted function. It doesn't work
> too well if you have lower level subtrees tagged for encryption.
I also forgot to mention that you need to have pgg pre-loaded.
This will ensure that:
(defun my-func-org-toggle-encryption (rcpts passphrase)
(interactive (list (split-string (read-string "Recipients (default is none): ") "[ \t,]+")
(pgg-read-passphrase "GnuPG passphrase: ")))
(require 'pgg)
(show-all)
(org-map-entries '(let (start end teststring)
(org-outline-level)
(next-line)
(org-beginning-of-line)
(setq start (point))
(setq teststring (buffer-substring start (+ start 27)))
(outline-get-next-sibling)
(if (not (equal (point) (point-max)))
(previous-line))
(org-end-of-line)
(setq end (point))
(if (equal teststring "-----BEGIN PGP MESSAGE-----")
(if (pgg-decrypt-region start end passphrase)
(pgg-display-output-buffer start end t)
(message "Can't decrypt region!"))
(if (equal rcpts '(""))
(pgg-encrypt-symmetric-region start end passphrase)
(pgg-encrypt-region start end rcpts nil passphrase))
(pgg-display-output-buffer start end t)))
"+ENCRYPT"))
--
aleblanc
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2009-03-09 12:28 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-03-08 4:31 alter all subtrees containing specific tag news
2009-03-08 13:29 ` Carsten Dominik
2009-03-08 18:00 ` news
2009-03-09 0:56 ` news
2009-03-09 2:32 ` news
2009-03-09 12:28 ` news
2009-03-08 13:42 ` Ian Barton
2009-03-08 18:01 ` news
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).