Skip to main content
Add the full export routine
Source Link
stsquad
  • 4.7k
  • 31
  • 45

EDIT TO ADD

The overall export is slightly more complex as it involves parsing and filtering out lines that are no longer relevant. This is done by calling org-export-as with the following code block:

#+name: get-task-list-as-exported-text
#+begin_src emacs-lisp :exports code
  (defun my-filter-out-done-lines (s backend info)
    "Filter out lines ending in :done"
    (apply 'concat
           (--remove (s-matches? (rx ":done" (zero-or-more blank) eol) it)
                     (s-slice-at (rx bol "-") s))))

  ; headline _back-end _info
  (defun my-filter-out-old-completed-todos (s backend info)
    "Filter out DONE items if they where completed over a week ago."
    (let ((date (plist-get info :with-date))
          (todo (plist-get info :with-todo-keywords))
          (todo-type (org-element-property :todo-type s))
          (output s))
      ;; getting there
      (setq my-global-debug-var
            (add-to-list 'my-global-debug-var
                         (list :string s
                               :date date
                               :todo todo
                               :todo-type todo-type)))
      ;; strip ~~~\n lines
      (let ((start (string-match "~+\n" output)))
        (if start
            (concat (substring s 0 start)
                    (substring s (match-end 0)))
          output))))

  (org-export-define-derived-backend 'my-status-report 'ascii
    :options-alist
    '((:with-todo-keywords nil)
      (:num nil))
    :filters-alist
    '((:filter-plain-list . my-filter-out-done-lines)
      (:filter-headline . my-filter-out-old-completed-todos)))


  ;; Snarf the weeks activities
  (save-excursion
    (goto-char (point-min))
    (when (re-search-forward "* Tasks")
      (goto-char (match-beginning 0))
      (org-export-as 'my-status-report t nil t )))
#+end_src

EDIT TO ADD

The overall export is slightly more complex as it involves parsing and filtering out lines that are no longer relevant. This is done by calling org-export-as with the following code block:

#+name: get-task-list-as-exported-text
#+begin_src emacs-lisp :exports code
  (defun my-filter-out-done-lines (s backend info)
    "Filter out lines ending in :done"
    (apply 'concat
           (--remove (s-matches? (rx ":done" (zero-or-more blank) eol) it)
                     (s-slice-at (rx bol "-") s))))

  ; headline _back-end _info
  (defun my-filter-out-old-completed-todos (s backend info)
    "Filter out DONE items if they where completed over a week ago."
    (let ((date (plist-get info :with-date))
          (todo (plist-get info :with-todo-keywords))
          (todo-type (org-element-property :todo-type s))
          (output s))
      ;; getting there
      (setq my-global-debug-var
            (add-to-list 'my-global-debug-var
                         (list :string s
                               :date date
                               :todo todo
                               :todo-type todo-type)))
      ;; strip ~~~\n lines
      (let ((start (string-match "~+\n" output)))
        (if start
            (concat (substring s 0 start)
                    (substring s (match-end 0)))
          output))))

  (org-export-define-derived-backend 'my-status-report 'ascii
    :options-alist
    '((:with-todo-keywords nil)
      (:num nil))
    :filters-alist
    '((:filter-plain-list . my-filter-out-done-lines)
      (:filter-headline . my-filter-out-old-completed-todos)))


  ;; Snarf the weeks activities
  (save-excursion
    (goto-char (point-min))
    (when (re-search-forward "* Tasks")
      (goto-char (match-beginning 0))
      (org-export-as 'my-status-report t nil t )))
#+end_src
fix typos, improve wording
Source Link
stsquad
  • 4.7k
  • 31
  • 45

I use org-export to generate my end of week email reports. OnceOne of the links I have in those reports is for mu4e searches. I have a helper function to translate them into something more useful:

;; Exporting
(defvar my-org-mu4e-index-links
  (rx
   (: (or "query:i:" "msgid:") (group-n 1 (one-or-more any))))
  "A regex to match mu4e links of the form:

    query:i:[email protected]
")

(defun my-org-mu4e-export (path desc format)
  "Format mu4e links for export."
  (when (string-match my-org-mu4e-index-links path)
    (cond
     ((eq format 'html)
      (format "<a href=\"%s%s\">%s</a>"
              "https://www.google.com/search?q="
              (match-string 1 path)
              desc))
     ((eq format 'jira)
      (format "[%s|%s%s]"
              desc
              "https://www.google.com/search?q="
              (match-string 1 path)))
     ((eq format 'ascii)
      (format "%s\nMessage-Id: <%s>" desc (match-string 1 path))))))

(use-package ox
  :config
  (org-link-set-parameters "mu4e" :export 'my-org-mu4e-export))

However what I really want is what happens with other links where the link text is surrounded by [] and the link is displayed at the bottom of the section. e.g.:

Task 1
======

  - posted message [about foo] to mailing list

[foo] Message-Id: <bar>

However I've not been able to work out where in the exporter transcoders and filters this is done. I assume I should be able to set some sort of parameter for mu4e style links to deal do this.

I use org-export to generate my end of week email reports. Once of the links I have in those reports is mu4e. I have a helper function to translate them into something more useful:

;; Exporting
(defvar my-org-mu4e-index-links
  (rx
   (: (or "query:i:" "msgid:") (group-n 1 (one-or-more any))))
  "A regex to match mu4e links of the form:

    query:i:[email protected]
")

(defun my-org-mu4e-export (path desc format)
  "Format mu4e links for export."
  (when (string-match my-org-mu4e-index-links path)
    (cond
     ((eq format 'html)
      (format "<a href=\"%s%s\">%s</a>"
              "https://www.google.com/search?q="
              (match-string 1 path)
              desc))
     ((eq format 'jira)
      (format "[%s|%s%s]"
              desc
              "https://www.google.com/search?q="
              (match-string 1 path)))
     ((eq format 'ascii)
      (format "%s\nMessage-Id: <%s>" desc (match-string 1 path))))))

(use-package ox
  :config
  (org-link-set-parameters "mu4e" :export 'my-org-mu4e-export))

However what I really want is what happens with other links where the link text is surrounded by [] and the link is displayed at the bottom of the section. e.g.:

Task 1
======

  - posted message [about foo] to mailing list

[foo] Message-Id: <bar>

However I've not been able to work out where in the exporter transcoders and filters this is done. I assume I should be able to set some sort of parameter for mu4e style links to deal do this.

I use org-export to generate my end of week email reports. One of the links I have in those reports is for mu4e searches. I have a helper function to translate them into something more useful:

;; Exporting
(defvar my-org-mu4e-index-links
  (rx
   (: (or "query:i:" "msgid:") (group-n 1 (one-or-more any))))
  "A regex to match mu4e links of the form:

    query:i:[email protected]
")

(defun my-org-mu4e-export (path desc format)
  "Format mu4e links for export."
  (when (string-match my-org-mu4e-index-links path)
    (cond
     ((eq format 'html)
      (format "<a href=\"%s%s\">%s</a>"
              "https://www.google.com/search?q="
              (match-string 1 path)
              desc))
     ((eq format 'jira)
      (format "[%s|%s%s]"
              desc
              "https://www.google.com/search?q="
              (match-string 1 path)))
     ((eq format 'ascii)
      (format "%s\nMessage-Id: <%s>" desc (match-string 1 path))))))

(use-package ox
  :config
  (org-link-set-parameters "mu4e" :export 'my-org-mu4e-export))

However what I really want is what happens with other links where the link text is surrounded by [] and the link is displayed at the bottom of the section. e.g.:

Task 1
======

  - posted message [about foo] to mailing list

[foo] Message-Id: <bar>

However I've not been able to work out where in the exporter transcoders and filters this is done. I assume I should be able to set some sort of parameter for mu4e style links to deal do this.

added 3 characters in body; edited title
Source Link
Drew
  • 79.1k
  • 10
  • 123
  • 257

What is the mechanism by which org-export colatescollates links for the summary?

I use org-exportorg-export to generate my end of week email reports. Once of the links I have in those reports is mu4e. I have a helper function to translate them into something more useful:

;; Exporting
(defvar my-org-mu4e-index-links
  (rx
   (: (or "query:i:" "msgid:") (group-n 1 (one-or-more any))))
  "A regex to match mu4e links of the form:

    query:i:[email protected]
")

(defun my-org-mu4e-export (path desc format)
  "Format mu4e links for export."
  (when (string-match my-org-mu4e-index-links path)
    (cond
     ((eq format 'html)
      (format "<a href=\"%s%s\">%s</a>"
              "https://www.google.com/search?q="
              (match-string 1 path)
              desc))
     ((eq format 'jira)
      (format "[%s|%s%s]"
              desc
              "https://www.google.com/search?q="
              (match-string 1 path)))
     ((eq format 'ascii)
      (format "%s\nMessage-Id: <%s>" desc (match-string 1 path))))))
 

(use-package ox
  :config
  (org-link-set-parameters "mu4e" :export 'my-org-mu4e-export))

However what I really want is what happens with other links where the link text is surrounded by []'s[] and the link is displayed at the bottom of the section. e.g.:

Task 1
======

  - posted message [about foo] to mailing list

[foo] Message-Id: <bar>

However I've not been able to work out where in the exporter transcoders and filters this is done. I assume I should be able to set some sort of parameter for mu4e style links to deal do this.

What is the mechanism by which org-export colates links for the summary?

I use org-export to generate my end of week email reports. Once of the links I have in those reports is mu4e. I have a helper function to translate them into something more useful:

;; Exporting
(defvar my-org-mu4e-index-links
  (rx
   (: (or "query:i:" "msgid:") (group-n 1 (one-or-more any))))
  "A regex to match mu4e links of the form:

    query:i:[email protected]
")

(defun my-org-mu4e-export (path desc format)
  "Format mu4e links for export."
  (when (string-match my-org-mu4e-index-links path)
    (cond
     ((eq format 'html)
      (format "<a href=\"%s%s\">%s</a>"
              "https://www.google.com/search?q="
              (match-string 1 path)
              desc))
     ((eq format 'jira)
      (format "[%s|%s%s]"
              desc
              "https://www.google.com/search?q="
              (match-string 1 path)))
     ((eq format 'ascii)
      (format "%s\nMessage-Id: <%s>" desc (match-string 1 path))))))
 

(use-package ox
  :config
  (org-link-set-parameters "mu4e" :export 'my-org-mu4e-export))

However what I really want is what happens with other links where the link text is surrounded by []'s and the link displayed at the bottom of the section. e.g.:

Task 1
======

  - posted message [about foo] to mailing list

[foo] Message-Id: <bar>

However I've not been able to work out where in the exporter transcoders and filters this is done. I assume I should be able to set some sort of parameter for mu4e style links to deal do this.

What is the mechanism by which org-export collates links for the summary?

I use org-export to generate my end of week email reports. Once of the links I have in those reports is mu4e. I have a helper function to translate them into something more useful:

;; Exporting
(defvar my-org-mu4e-index-links
  (rx
   (: (or "query:i:" "msgid:") (group-n 1 (one-or-more any))))
  "A regex to match mu4e links of the form:

    query:i:[email protected]
")

(defun my-org-mu4e-export (path desc format)
  "Format mu4e links for export."
  (when (string-match my-org-mu4e-index-links path)
    (cond
     ((eq format 'html)
      (format "<a href=\"%s%s\">%s</a>"
              "https://www.google.com/search?q="
              (match-string 1 path)
              desc))
     ((eq format 'jira)
      (format "[%s|%s%s]"
              desc
              "https://www.google.com/search?q="
              (match-string 1 path)))
     ((eq format 'ascii)
      (format "%s\nMessage-Id: <%s>" desc (match-string 1 path))))))

(use-package ox
  :config
  (org-link-set-parameters "mu4e" :export 'my-org-mu4e-export))

However what I really want is what happens with other links where the link text is surrounded by [] and the link is displayed at the bottom of the section. e.g.:

Task 1
======

  - posted message [about foo] to mailing list

[foo] Message-Id: <bar>

However I've not been able to work out where in the exporter transcoders and filters this is done. I assume I should be able to set some sort of parameter for mu4e style links to deal do this.

Source Link
stsquad
  • 4.7k
  • 31
  • 45
Loading