Skip to content

Instantly share code, notes, and snippets.

@lynaghk
Last active November 12, 2024 21:00
Show Gist options
  • Save lynaghk/613465c834a826a5344b99b5b10e7c45 to your computer and use it in GitHub Desktop.
Save lynaghk/613465c834a826a5344b99b5b10e7c45 to your computer and use it in GitHub Desktop.

Revisions

  1. lynaghk revised this gist May 31, 2024. 1 changed file with 10 additions and 11 deletions.
    21 changes: 10 additions & 11 deletions elisp.el
    Original file line number Diff line number Diff line change
    @@ -1,14 +1,13 @@
    (defun formatted-copy ()
    (defun formatted-copy (start end)
    "Export region to HTML, and copy it to the clipboard."
    (interactive)
    (save-window-excursion
    (let* ((buf (org-export-to-buffer 'html "*Formatted Copy*" nil nil t t))
    (html (with-current-buffer buf (buffer-string))))
    (with-current-buffer buf
    (shell-command-on-region
    (point-min)
    (point-max)
    "pandoc -f gfm -t html5 | pbcopy_html"))
    (kill-buffer buf))))
    (interactive "r")
    (let* ((region-string (buffer-substring-no-properties start end))
    (shell-command "pandoc -f gfm -t html5 | pbcopy_html")
    (output-buffer (generate-new-buffer "*Shell Command Output*")))
    (with-current-buffer output-buffer
    (erase-buffer)
    (insert region-string)
    (shell-command-on-region (point-min) (point-max) shell-command t t))
    (kill-buffer output-buffer)))

    (global-set-key (kbd "C-M-c") 'formatted-copy)
  2. lynaghk created this gist Mar 29, 2024.
    14 changes: 14 additions & 0 deletions elisp.el
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    (defun formatted-copy ()
    "Export region to HTML, and copy it to the clipboard."
    (interactive)
    (save-window-excursion
    (let* ((buf (org-export-to-buffer 'html "*Formatted Copy*" nil nil t t))
    (html (with-current-buffer buf (buffer-string))))
    (with-current-buffer buf
    (shell-command-on-region
    (point-min)
    (point-max)
    "pandoc -f gfm -t html5 | pbcopy_html"))
    (kill-buffer buf))))

    (global-set-key (kbd "C-M-c") 'formatted-copy)
    13 changes: 13 additions & 0 deletions pbcopy_html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    #!/usr/bin/env swift

    import Cocoa
    import Darwin

    let pasteboard = NSPasteboard.general

    guard let data = try? FileHandle.standardInput.readToEnd() else {
    exit(1)
    }

    pasteboard.clearContents()
    pasteboard.setData(data, forType: .html)