emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Orgmode] Re: alter all subtrees containing specific tag


From: news
Subject: [Orgmode] Re: alter all subtrees containing specific tag
Date: Mon, 09 Mar 2009 00:56:41 +0000

Carsten Dominik <address@hidden> 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





reply via email to

[Prev in Thread] Current Thread [Next in Thread]