Skip to content

Instantly share code, notes, and snippets.

@BrianZbr
Created January 15, 2016 16:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BrianZbr/63a7e02f5b1f5f98e884 to your computer and use it in GitHub Desktop.
Save BrianZbr/63a7e02f5b1f5f98e884 to your computer and use it in GitHub Desktop.
elisp function for pasting quotes from pdfs into org-mode documents
(defun my/paste-quote (pages)
"inserts and formats text from the clipboard, formatted for org-mode"
(interactive "sEnter page number\(s\): ")
;;;; convert clipboard to string
(setq quote
(with-temp-buffer
(yank)
(buffer-string)
))
;;;; remove newlines from string
(setq newline "
")
(setq one-space " ")
(setq multiple-space " +")
(setq quote (replace-regexp-in-string newline one-space quote))
(setq quote (replace-regexp-in-string multiple-space one-space quote))
(setq quote (replace-regexp-in-string "\\.- " "" quote))
;;;; insert reformatted quote, saving relevant positions
(insert "#+BEGIN_QUOTE")
(newline)
(setq quote-begin (point))
(insert quote)
(setq quote-end (point))
(insert " ()")
(left-char 1)
(setq page-number-spot (point))
(insert pages)
(end-of-line)
(newline)
(insert "#+END_QUOTE")
;;;; correct spelling in case of bad OCR
(flyspell-region quote-begin quote-end)
(ispell-region quote-begin quote-end)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment