Jak zautomatyzować refil org dla wielu czynności do wykonania


1

Chcę zautomatyzować ponowne organizowanie org, aby znalazł wszystkie dopasowania i ponownie zarchiwizował je w określonej lokalizacji (ale nie w archiwum). Znalazłem w pełni zautomatyzowaną metodę archiwizacji wielu todo i mam nadzieję znaleźć lub stworzyć (z pewną pomocą) coś podobnego do tej niesamowitej funkcji (ale dla innej pozycji / lokalizacji innej niż archiwizacja): https://github.com /tonyday567/jwiegley-dot-emacs/blob/master/dot-org.el

(defun org-archive-done-tasks ()
  (interactive)
  (save-excursion
    (goto-char (point-min))
    (while (re-search-forward "\* \\(None\\|Someday\\) " nil t)
      (if (save-restriction
            (save-excursion
              (org-narrow-to-subtree)
              (search-forward ":LOGBOOK:" nil t)))
          (forward-line)
        (org-archive-subtree)
        (goto-char (line-beginning-position))))))

Znalazłem również (napisany przez aculich), co jest krokiem we właściwym kierunku, ale nadal wymaga ręcznego powtarzania funkcji: https://stackoverflow.com/questions/7509463/how-to-move-a-subtree-to- another-subtree-in-org-mode-emacs

;; I also wanted a way for org-refile to refile easily to a subtree, so I wrote some code and generalized it so that it will set an arbitrary immediate target anywhere (not just in the same file).

;; Basic usage is to move somewhere in Tree B and type C-c C-x C-m to mark the target for refiling, then move to the entry in Tree A that you want to refile and type C-c C-w which will immediately refile into the target location you set in Tree B without prompting you, unless you called org-refile-immediate-target with a prefix arg C-u C-c C-x C-m.

;; Note that if you press C-c C-w in rapid succession to refile multiple entries it will preserve the order of your entries even if org-reverse-note-order is set to t, but you can turn it off to respect the setting of org-reverse-note-order with a double prefix arg C-u C-u C-c C-x C-m.


(defvar org-refile-immediate nil
  "Refile immediately using `org-refile-immediate-target' instead of prompting.")
(make-local-variable 'org-refile-immediate)

(defvar org-refile-immediate-preserve-order t
  "If last command was also `org-refile' then preserve ordering.")
(make-local-variable 'org-refile-immediate-preserve-order)

(defvar org-refile-immediate-target nil)
"Value uses the same format as an item in `org-refile-targets'."
(make-local-variable 'org-refile-immediate-target)

(defadvice org-refile (around org-immediate activate)
  (if (not org-refile-immediate)
      ad-do-it
    ;; if last command was `org-refile' then preserve ordering
    (let ((org-reverse-note-order
           (if (and org-refile-immediate-preserve-order
                    (eq last-command 'org-refile)) nil org-reverse-note-order)))
      (ad-set-arg 2 (assoc org-refile-immediate-target (org-refile-get-targets)))
      (prog1 ad-do-it
        (setq this-command 'org-refile)))))

(defadvice org-refile-cache-clear (after org-refile-history-clear activate)
  (setq org-refile-targets (default-value 'org-refile-targets))
  (setq org-refile-immediate nil)
  (setq org-refile-immediate-target nil)
  (setq org-refile-history nil))

;;;###autoload
(defun org-refile-immediate-target (&optional arg)
  "Set current entry as `org-refile' target.
Non-nil turns off `org-refile-immediate', otherwise `org-refile'
will immediately refile without prompting for target using most
recent entry in `org-refile-targets' that matches
`org-refile-immediate-target' as the default."
  (interactive "P")
  (if (equal arg '(16))
      (progn
        (setq org-refile-immediate-preserve-order
              (not org-refile-immediate-preserve-order))
        (message "Order preserving is turned: %s"
                 (if org-refile-immediate-preserve-order
                     "on" "off")))

    (setq org-refile-immediate (unless arg t))
    (make-local-variable 'org-refile-targets)
    (let* ((components (org-heading-components))
           (level (first components))
           (heading (nth 4 components))
           (string (substring-no-properties heading)))
      (add-to-list 'org-refile-targets
                   (append (list (buffer-file-name))
                           (cons :regexp
                                 (format "^%s %s$"
                                         (make-string level ?*)
                                         string))))
      (setq org-refile-immediate-target heading))))

(define-key org-mode-map "\C-c\C-x\C-m" 'org-refile-immediate-target)

aculichPrzydałoby się, gdyby , lub jakiś inny maven, mógł utworzyć zmienną podobną do, (setq org-archive-location "~/0.todo.org::* Archived Tasks")aby użytkownicy mogli określić plik i nagłówek, który jest już częścią org-archive-subtreefunkcjonalności. Robię wyszukiwanie i zaznaczanie, ponieważ nie mam środków na stworzenie czegoś takiego org-archive-locationdla tej konfiguracji.


EDYCJA: Jeden krok bliżej - prawie bez domu. . .

(defun lawlist-auto-refile ()
    (interactive)
        (beginning-of-buffer)
        (re-search-forward "\* UNDATED")
        (org-refile-immediate-target) ;; cursor must be on a heading to work.
        (save-excursion
            (re-search-backward "\* UNDATED") ;; must be written in such a way so that sub-entries of * UNDATED are not searched; or else infinity loop.
            (while (re-search-backward "\* \\(None\\|Someday\\) " nil t)
                (org-refile)
            )
        )
)

Odpowiedzi:


1

ROZWIĄZANIE # A:

(defun lawlist-auto-refile ()
(interactive)
    (setq org-archive-save-context-info nil)
    (setq org-archive-location "/Users/HOME/.0.data/*TODO*::* UNDATED")
    (beginning-of-buffer)
    (re-search-forward "\* UNDATED")
        (save-excursion
    ;; must be coded in such a way so that sub-entries of * UNDATED are not searched; or else cut-and-paste infinity loop.
            (while (re-search-backward "\* \\(None\\|Someday\\) " nil t)
            (org-archive-subtree)
             )
         )
 )

ROZWIĄZANIE # B:

(defun lawlist-auto-refile-solution-b ()
     (interactive)
         (beginning-of-buffer)
         (re-search-forward "\* UNDATED")
         (org-refile-immediate-target) ;; cursor must be on a heading to work.
         (save-excursion
    ;; must be coded in such a way so that sub-entries of * UNDATED are not searched; or else cut-and-paste infinity loop.
             (while (re-search-backward "\* \\(None\\|Someday\\) " nil t)
             (org-refile)
             )
         )
 )


;; I also wanted a way for org-refile to refile easily to a subtree, so I wrote some code and generalized it so that it will set an arbitrary iate target anywhere (not just in the same file).

;; Basic usage is to move somewhere in Tree B and type C-c C-x C-m to mark the target for refiling, then move to the entry in Tree A that you want to refile and type C-c C-w which will immediately refile into the target location you set in Tree B without prompting you, unless you called org-refile-iate-target with a prefix arg C-u C-c C-x C-m.

;; Note that if you press C-c C-w in rapid succession to refile multiple entries it will preserve the order of your entries even if org-reverse-note- is set to t, but you can turn it off to respect the setting of org-reverse-note-order with a double prefix arg C-u C-u C-c C-x C-m.  

(defvar org-refile-immediate nil
  "Refile immediately using `org-refile-immediate-target' instead of prompting.")
(make-local-variable 'org-refile-immediate) 
(defvar org-refile-immediate-preserve-order t
  "If last command was also `org-refile' then preserve ordering.")
(make-local-variable 'org-refile-immediate-preserve-order) 
(defvar org-refile-immediate-target nil)
"Value uses the same format as an item in `org-refile-targets'."
(make-local-variable 'org-refile-immediate-target) 
(defadvice org-refile (around org-immediate activate)
  (if (not org-refile-immediate)
      ad-do-it
    ;; if last command was `org-refile' then preserve ordering
    (let ((org-reverse-note-order
           (if (and org-refile-immediate-preserve-order
                    (eq last-command 'org-refile)) nil org-reverse-note-order)))
      (ad-set-arg 2 (assoc org-refile-immediate-target (org-refile-get-targets)))
      (prog1 ad-do-it
        (setq this-command 'org-refile))))) 
(defadvice org-refile-cache-clear (after org-refile-history-clear activate)
  (setq org-refile-targets (default-value 'org-refile-targets))
  (setq org-refile-immediate nil)
  (setq org-refile-immediate-target nil)
  (setq org-refile-history nil)) 
;;;###autoload
(defun org-refile-immediate-target (&optional arg)
  "Set current entry as `org-refile' target.
    Non-nil turns off `org-refile-immediate', otherwise `org-refile'
    will immediately refile without prompting for target using most
    recent entry in `org-refile-targets' that matches
    `org-refile-immediate-target' as the default."
   (interactive "P")
   (if (equal arg '(16))
      (progn
        (setq org-refile-immediate-preserve-order
              (not org-refile-immediate-preserve-order))
        (message "Order preserving is turned: %s"
                 (if org-refile-immediate-preserve-order
                     "on" "off"))) 
    (setq org-refile-immediate (unless arg t))
    (make-local-variable 'org-refile-targets)
    (let* ((components (org-heading-components))
           (level (first components))
           (heading (nth 4 components))
           (string (substring-no-properties heading)))
      (add-to-list 'org-refile-targets
                   (append (list (buffer-file-name))
                           (cons :regexp
                                 (format "^%s %s$"
                                         (make-string level ?*)
                                         string))))
      (setq org-refile-immediate-target heading)))) 
(define-key org-mode-map "\C-c\C-x\C-m" 'org-refile-immediate-target) 
Korzystając z naszej strony potwierdzasz, że przeczytałeś(-aś) i rozumiesz nasze zasady używania plików cookie i zasady ochrony prywatności.
Licensed under cc by-sa 3.0 with attribution required.