2012-04-13 17 views
10

Generalmente utilizzo la modalità org per tenere traccia di TODO. Ho i file come:Mantenimento del contesto durante l'archiviazione in modalità org Emacs

* Misc. 
** TODO Task 1 
** TODO Task 2 
* Project 1 
** TODO Task 1 
** TODO Task 2 

Mentre l'archiviazione sottostrutture interi come Project 1 funziona come previsto, io non sono a in grado di muoversi Task 1 in Misc. tale che il file di archivio si presenta così (ignorando PROPRIETA 'in questo esempio):

* Misc 
** DONE Task 1 

In altre parole, voglio mantenere tutte le sezioni a cui appartiene un'attività. C'è un modo rapido per farlo?

risposta

14

è probabile che desidera impostare la proprietà :ARCHIVE: sui titoli genitore.

ti permette di titolo specifico org-archive-location impostazioni. (Vedere la manual)

per esempio, se il file di archivio è impostato come %s_archive si vorrebbe il file originale a guardare come questo

* Misc. 
    :PROPERTIES: 
    :ARCHIVE: %s_archive::* Misc 
    :END: 
** TODO Task 1 
** TODO Task 2 
* Project 1 
    :PROPERTIES: 
    :ARCHIVE: %s_archive::* Project 1 
    :END: 
** TODO Task 1 
** TODO Task 2 

Ciò inviato eventuali sottostrutture in * Misc ad un * Misc titolo del file di archivio, e farebbe l'equivalente per le sottostrutture in Project 1 (a meno che non si archivia l'intero albero in un colpo). Archiviazione dell'albero genitore dopo le sottostrutture appare per aggiungerlo come sottotitolo aggiuntivo sotto la destinazione. Non supporta più livelli, quindi dovresti impostare in anticipo i titoli dei file di archivio per assicurarti che vengano pubblicati come desideri se hai bisogno di una configurazione complessa di questo tipo.

È inoltre possibile utilizzare questa proprietà per archiviare alberi specifici in file separati (per scopi di esportazione/pubblicazione/condivisione).

+0

questa è una soluzione molto bella e pulita. Funziona come previsto.La mia configurazione è abbastanza semplice quindi immagino non avrà problemi con il mancato supporto di più livelli. Grazie! –

4

Non credo che org-mode abbia il supporto per il mirroring diretto del contesto corrente all'interno del file di archivio.

C'è una variabile rilevante, org-archive-location che può essere utilizzata per specificare una singola intestazione per posizionare l'elemento archiviato, ma non sono supportati più livelli all'interno dell'albero. Su this page ci sono due consigli per org-archive-subtree che potrebbe essere sufficiente. Sto replicando il primo qui nel caso in cui il sito va via:

(defadvice org-archive-subtree (around my-org-archive-subtree activate) 
    (let ((org-archive-location 
     (if (save-excursion (org-back-to-heading) 
          (> (org-outline-level) 1)) 
      (concat (car (split-string org-archive-location "::")) 
        "::* " 
        (car (org-get-outline-path))) 
      org-archive-location))) 
    ad-do-it)) 

Il secondo, e uno più complicato conserva anche tag trovato sulle intestazioni di livello superiore.

L'ultima cosa che può tornare utile è la variabile personalizzata org-archive-save-context-info. Se questo elenco contiene il simbolo 'olpath, la voce archiviata conterrà la proprietà :ARCHIVE_OLPATH:, che è impostata sul percorso del profilo della voce archiviata (ad esempio Projects/Misc. È possibile eseguire qualche post elaborazione sullo org-archive-subtree e riposizionare la voce archiviata nella sua struttura originale percorso utilizzando questo.

3
;; org-archive-subtree-hierarchical.el 
;; modified from https://lists.gnu.org/archive/html/emacs-orgmode/2014-08/msg00109.html 

;; In orgmode 
;; * A 
;; ** AA 
;; *** AAA 
;; ** AB 
;; *** ABA 
;; Archiving AA will remove the subtree from the original file and create 
;; it like that in archive target: 

;; * AA 
;; ** AAA 

;; And this give you 
;; * A 
;; ** AA 
;; *** AAA 


(require 'org-archive) 

(defun org-archive-subtree-hierarchical--line-content-as-string() 
    "Returns the content of the current line as a string" 
    (save-excursion 
    (beginning-of-line) 
    (buffer-substring-no-properties 
    (line-beginning-position) (line-end-position)))) 

(defun org-archive-subtree-hierarchical--org-child-list() 
    "This function returns all children of a heading as a list. " 
    (interactive) 
    (save-excursion 
    ;; this only works with org-version > 8.0, since in previous 
    ;; org-mode versions the function (org-outline-level) returns 
    ;; gargabe when the point is not on a heading. 
    (if (= (org-outline-level) 0) 
     (outline-next-visible-heading 1) 
     (org-goto-first-child)) 
    (let ((child-list (list (org-archive-subtree-hierarchical--line-content-as-string)))) 
     (while (org-goto-sibling) 
     (setq child-list (cons (org-archive-subtree-hierarchical--line-content-as-string) child-list))) 
     child-list))) 

(defun org-archive-subtree-hierarchical--org-struct-subtree() 
    "This function returns the tree structure in which a subtree 
belongs as a list." 
    (interactive) 
    (let ((archive-tree nil)) 
    (save-excursion 
     (while (org-up-heading-safe) 
     (let ((heading 
       (buffer-substring-no-properties 
       (line-beginning-position) (line-end-position)))) 
      (if (eq archive-tree nil) 
       (setq archive-tree (list heading)) 
      (setq archive-tree (cons heading archive-tree)))))) 
    archive-tree)) 

(defun org-archive-subtree-hierarchical() 
    "This function archives a subtree hierarchical" 
    (interactive) 
    (let ((org-tree (org-archive-subtree-hierarchical--org-struct-subtree)) 
     (this-buffer (current-buffer)) 
     (file (abbreviate-file-name 
       (or (buffer-file-name (buffer-base-buffer)) 
        (error "No file associated to buffer"))))) 
    (save-excursion 
     (setq location (org-get-local-archive-location) 
      afile (org-extract-archive-file location) 
      heading (org-extract-archive-heading location) 
      infile-p (equal file (abbreviate-file-name (or afile "")))) 
     (unless afile 
     (error "Invalid `org-archive-location'")) 
     (if (> (length afile) 0) 
      (setq newfile-p (not (file-exists-p afile)) 
       visiting (find-buffer-visiting afile) 
       buffer (or visiting (find-file-noselect afile))) 
     (setq buffer (current-buffer))) 
     (unless buffer 
     (error "Cannot access file \"%s\"" afile)) 
     (org-cut-subtree) 
     (set-buffer buffer) 
     (org-mode) 
     (goto-char (point-min)) 
     (while (not (equal org-tree nil)) 
     (let ((child-list (org-archive-subtree-hierarchical--org-child-list))) 
      (if (member (car org-tree) child-list) 
       (progn 
       (search-forward (car org-tree) nil t) 
       (setq org-tree (cdr org-tree))) 
      (progn 
       (goto-char (point-max)) 
       (newline) 
       (org-insert-struct org-tree) 
       (setq org-tree nil))))) 
     (newline) 
     (org-yank) 
     (when (not (eq this-buffer buffer)) 
     (save-buffer)) 
     (message "Subtree archived %s" 
       (concat "in file: " (abbreviate-file-name afile)))))) 

(defun org-insert-struct (struct) 
    "TODO" 
    (interactive) 
    (when struct 
    (insert (car struct)) 
    (newline) 
    (org-insert-struct (cdr struct)))) 

(defun org-archive-subtree() 
    (org-archive-subtree-hierarchical) 
) 

Questo mod proprio agire come REFILE per il file di archivio con tutto stessa struct genitore, nessun archivio :PROPERTIES: qui.

anche come sostanza qui: https://gist.github.com/CodeFalling/87b116291aa87fde72cb

+0

funziona proprio come previsto, molto bello! –

+0

Incredibile! Grazie mille! – Jeremy

+0

Mi è piaciuto molto. Si combina piacevolmente con una chiave nell'agenda: (define-key org-agenda-mode-map "z" 'org-agenda-archive) – Jeremy

Problemi correlati