summary refs log tree commit diff stats
path: root/lisp/+org.el
blob: b17a1fa9728d3a3f70e504ed90853f3fb568637f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
;;; +org.el --- -*- lexical-binding: t -*-

;;; Copy org trees as HTML

;; Thanks to Oleh Krehel, via [[https://emacs.stackexchange.com/questions/54292/copy-results-of-org-export-directly-to-clipboard][this StackExchange question]].
(defun +org-export-clip-to-html
    (&optional async subtreep visible-only body-only ext-plist post-process)
  "Export region to HTML, and copy it to the clipboard.
Arguments ASYNC, SUBTREEP, VISIBLE-ONLY, BODY-ONLY, EXT-PLIST,
and POST-PROCESS are passed to `org-export-to-file'."
  (interactive) ; XXX: hould this be interactive?
  (message "Exporting Org to HTML...")
  (let ((org-tmp-file "/tmp/org.html"))
    (org-export-to-file 'html org-tmp-file
      async subtreep visible-only body-only ext-plist post-process)
    (start-process "xclip" "*xclip*"
                   "xclip" "-verbose"
                   "-i" org-tmp-file
                   "-t" "text/html"
                   "-selection" "clipboard"))
  (message "Exporting Org to HTML...done."))

;; Specialized functions
(defun +org-export-clip-subtree-to-html ()
  "Export current subtree to HTML."
  (interactive)
  (+org-export-clip-to-html nil :subtree))

;;; Unsmartify quotes and dashes and stuff.

(defun +org-unsmartify ()
  "Replace \"smart\" punctuation with their \"dumb\" counterparts."
  (interactive)
  (save-excursion
    (goto-char (point-min))
    (while (re-search-forward "[“”‘’–—]" nil t)
      (let ((replace (pcase (match-string 0)
                       ((or "“" "”") "\"")
                       ((or "‘" "’") "'")
                       ("–" "--")
                       ("—" "---"))))
        (replace-match replace nil nil)))))

(provide '+org)