.emacs-my
changeset 1335 c8606339804e
parent 1334 6e334301afb1
child 1336 7c93663d44f3
equal deleted inserted replaced
1334:6e334301afb1 1335:c8606339804e
  1548    org-tags-column 64
  1548    org-tags-column 64
  1549    org-archive-save-context-info '(time file olpath todo itags)
  1549    org-archive-save-context-info '(time file olpath todo itags)
  1550    )
  1550    )
  1551   (setq my-org-agenda-todo-file (concat org-directory "/TODO.org"))
  1551   (setq my-org-agenda-todo-file (concat org-directory "/TODO.org"))
  1552   (setq my-org-agenda-note-file (concat org-directory "/NOTE.org"))
  1552   (setq my-org-agenda-note-file (concat org-directory "/NOTE.org"))
  1553   (setq my-org-agenda-learning-file (concat org-directory "/LEARNING.org"))
  1553   (setq org-agenda-file-regexp "\\`[^.#].*[^_]\\.org\\'"
  1554   (setq org-agenda-files `(,my-org-agenda-todo-file ,my-org-agenda-note-file ,my-org-agenda-learning-file))
  1554         org-agenda-files (list org-directory))
       
  1555   ;; (setq my-org-agenda-learning-file (concat org-directory "/LEARNING.org"))
       
  1556   ;; (setq org-agenda-files `(,my-org-agenda-todo-file ,my-org-agenda-note-file ,my-org-agenda-learning-file))
  1555   (define-key global-map "\C-va" 'org-agenda)
  1557   (define-key global-map "\C-va" 'org-agenda)
  1556   (define-key global-map "\C-ve" (lambda nil (interactive) (find-file my-org-agenda-note-file)))
  1558   (define-key global-map "\C-ve" (lambda nil (interactive) (find-file my-org-agenda-note-file)))
  1557 
  1559 
  1558   (setq org-todo-keywords '("TODO" "DONE"))
  1560   (setq org-todo-keywords '("TODO" "DONE"))
  1559 
  1561 
  1605     (org-remember-insinuate)
  1607     (org-remember-insinuate)
  1606     ))
  1608     ))
  1607 
  1609 
  1608   )
  1610   )
  1609 
  1611 
  1610 
  1612 (defun my/org-archive-location (path)
  1611 (defun my-org-archive-location (org-file)
  1613   "For given PATH make path to archive. Currently add undescore
  1612   (concat (if (string-match "\\(.*\\)\\.org$" org-file)
  1614 before file extention. If file name doesn't match
  1613               (match-string 1 org-file)
  1615 `org-agenda-file-regexp' or have no extention return `nil'."
  1614             org-file)
  1616   (if (and (file-name-extension path)
  1615           "_done.org"))
  1617            (string-match org-agenda-file-regexp (file-name-nondirectory path)))
  1616 
  1618       (concat (file-name-sans-extension path) "_." (file-name-extension path))
  1617 (defun my-org-archive ()
  1619     nil))
  1618   "Move marked by `org-done-keywords' entries to archive file defined by `my-org-archive-location'."
  1620 
  1619   (interactive)
  1621 (defun my/org-archive-file (path)
  1620   (let ( (org-archive (my-org-archive-location (buffer-file-name)))
  1622   "Move marked by `org-done-keywords' entries to archive file.
  1621          (entry-re (concat "^\\* "))
  1623 
  1622          (entry-done-re (concat "^\\* *" (mapconcat 'regexp-quote org-done-keywords "\\|") " "))
  1624 Archive file name constructed by `my/org-archive-location'."
       
  1625   (let ( (archive (my/org-archive-location path))
       
  1626          entry-re entry-done-re
  1623          entry-beg entry-end )
  1627          entry-beg entry-end )
       
  1628     (unless archive
       
  1629       (error "'%s' looks like a non-org file..." path))
  1624     (save-excursion
  1630     (save-excursion
  1625       (show-all)
  1631       (with-current-buffer (find-file-noselect path)
  1626       (kill-new "")
  1632         (org-set-regexps-and-options)
  1627       (goto-char (point-min))
  1633         (setq entry-re "^\\* "
  1628       (while (re-search-forward entry-done-re nil t)
  1634               entry-done-re (concat "^\\* *" (mapconcat 'regexp-quote org-done-keywords "\\|") " "))
  1629         (setq entry-beg (line-beginning-position))
  1635         (kill-new "")
  1630         ()
  1636         (goto-char (point-min))
  1631         (if (re-search-forward entry-re nil t)
  1637         (while (re-search-forward entry-done-re nil t)
  1632             (beginning-of-line)
  1638           (setq entry-beg (line-beginning-position))
  1633           (goto-char (point-max)))
  1639           (if (re-search-forward entry-re nil t)
  1634         (setq entry-end (point))
  1640               (beginning-of-line)
  1635         (let ( (last-command 'kill-region) )
  1641             (goto-char (point-max)))
  1636           (kill-region entry-beg entry-end))
  1642           (setq entry-end (point))
  1637         )
  1643           (let ( (last-command 'kill-region) )
  1638       (find-file org-archive)
  1644             (kill-region entry-beg entry-end))
  1639       (goto-char (point-max))
  1645           )
  1640       (insert ?\n)
  1646         (with-current-buffer (find-file-noselect archive)
  1641       (yank)
  1647           (goto-char (point-max))
  1642       )))
  1648           (insert ?\n)
       
  1649           (yank)
       
  1650           (save-buffer))
       
  1651         (save-buffer) ))))
       
  1652 
       
  1653 (defun my/org-archive (&optional prefix)
       
  1654   "Move all entries marked by `org-done-keywords' to archive
       
  1655 files with name mangled by `my/org-archive-location'.
       
  1656 
       
  1657 Without prefix work on current file. With prefix work on "
       
  1658   (interactive "P")
       
  1659   (loop for file in (if prefix (org-agenda-files) (list (buffer-file-name))) do
       
  1660         (my/org-archive-file file)))
  1643 
  1661 
  1644 (setq org-agenda-include-diary t)
  1662 (setq org-agenda-include-diary t)
  1645 
  1663 
  1646 (defun my-org-kill-by-tag (tag)
  1664 (defun my-org-kill-by-tag (tag)
  1647   "Put all entries that matches TAG from current org-file to `kill-ring'."
  1665   "Put all entries that matches TAG from current org-file to `kill-ring'."