Function: org-agenda-write
org-agenda-write is an interactive and byte-compiled function defined
in org-agenda.el.gz.
Signature
(org-agenda-write FILE &optional OPEN NOSETTINGS AGENDA-BUFNAME)
Documentation
Write the current buffer (an agenda view) as a file.
Depending on the extension of the file name, plain text (.txt), HTML (.html or .htm), PDF (.pdf) or Postscript (.ps) is produced. If the extension is .ics, translate visible agenda into iCalendar format. If the extension is .org, collect all subtrees corresponding to the agenda entries and add them in an .org file.
With prefix argument OPEN, open the new file immediately. If
NOSETTINGS is given, do not scope the settings of
org-agenda-exporter-settings into the export commands. This is
used when the settings have already been scoped and we do not
wish to overrule other, higher priority settings. If
AGENDA-BUFFER-NAME is provided, use this as the buffer name for
the agenda to write.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/org/org-agenda.el.gz
(defun org-agenda-write (file &optional open nosettings agenda-bufname)
"Write the current buffer (an agenda view) as a file.
Depending on the extension of the file name, plain text (.txt),
HTML (.html or .htm), PDF (.pdf) or Postscript (.ps) is produced.
If the extension is .ics, translate visible agenda into iCalendar
format. If the extension is .org, collect all subtrees
corresponding to the agenda entries and add them in an .org file.
With prefix argument OPEN, open the new file immediately. If
NOSETTINGS is given, do not scope the settings of
`org-agenda-exporter-settings' into the export commands. This is
used when the settings have already been scoped and we do not
wish to overrule other, higher priority settings. If
AGENDA-BUFFER-NAME is provided, use this as the buffer name for
the agenda to write."
(interactive "FWrite agenda to file: \nP")
(if (or (not (file-writable-p file))
(and (file-exists-p file)
(if (called-interactively-p 'any)
(not (y-or-n-p (format "Overwrite existing file %s? " file))))))
(user-error "Cannot write agenda to file %s" file))
(cl-progv
(if nosettings nil (mapcar #'car org-agenda-exporter-settings))
(if nosettings nil (mapcar (lambda (binding) (eval (cadr binding) t))
org-agenda-exporter-settings))
(save-excursion
(save-window-excursion
(let ((bs (copy-sequence (buffer-string)))
(extension (file-name-extension file))
(default-directory (file-name-directory file))
) ;; beg content
(with-temp-buffer
(rename-buffer org-agenda-write-buffer-name t)
(set-buffer-modified-p nil)
(insert bs)
(org-agenda-remove-marked-text 'invisible 'org-filtered)
(run-hooks 'org-agenda-before-write-hook)
(cond
((bound-and-true-p org-mobile-creating-agendas)
(org-mobile-write-agenda-for-mobile file))
((string= "org" extension)
(let (content p m message-log-max)
(goto-char (point-min))
(while (setq p (next-single-property-change (point) 'org-hd-marker nil))
(goto-char p)
(setq m (get-text-property (point) 'org-hd-marker))
(when m
(cl-pushnew (with-current-buffer (marker-buffer m)
(goto-char m)
(org-copy-subtree 1 nil t t)
org-subtree-clip)
content
:test #'equal)))
(find-file file)
(erase-buffer)
(dolist (s content) (org-paste-subtree 1 s))
(write-file file)
(kill-buffer (current-buffer))
(message "Org file written to %s" file)))
((member extension '("html" "htm"))
(org-require-package 'htmlize)
(declare-function htmlize-buffer "htmlize" (&optional buffer))
(set-buffer (htmlize-buffer (current-buffer)))
(when org-agenda-export-html-style
;; replace <style> section with org-agenda-export-html-style
(goto-char (point-min))
(kill-region (- (search-forward "<style") 6)
(search-forward "</style>"))
(insert org-agenda-export-html-style))
(write-file file)
(kill-buffer (current-buffer))
(message "HTML written to %s" file))
((string= "ps" extension)
(require 'ps-print)
(ps-print-buffer-with-faces file)
(message "Postscript written to %s" file))
((string= "pdf" extension)
(require 'ps-print)
(ps-print-buffer-with-faces
(concat (file-name-sans-extension file) ".ps"))
(call-process "ps2pdf" nil nil nil
(expand-file-name
(concat (file-name-sans-extension file) ".ps"))
(expand-file-name file))
(delete-file (concat (file-name-sans-extension file) ".ps"))
(message "PDF written to %s" file))
((string= "ics" extension)
(require 'ox-icalendar)
(declare-function org-icalendar-export-current-agenda
"ox-icalendar" (file))
(org-icalendar-export-current-agenda (expand-file-name file)))
(t
(write-region nil nil file)
(message "Plain text written to %s" file)))))))
(set-buffer (or agenda-bufname
;; FIXME: I'm pretty sure called-interactively-p
;; doesn't do what we want here!
(and (called-interactively-p 'any) (buffer-name))
org-agenda-buffer-name)))
(when open (org-open-file file)))