Skip to content

Instantly share code, notes, and snippets.

@mxpiotrowski
Created August 19, 2020 10:25
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 mxpiotrowski/3045be2b9905e5557f0f31e8a76250a8 to your computer and use it in GitHub Desktop.
Save mxpiotrowski/3045be2b9905e5557f0f31e8a76250a8 to your computer and use it in GitHub Desktop.
;;; Markdown
(defun my-markdown-mode-hook ()
(visual-line-mode)
(setq markdown-use-pandoc-style-yaml-metadata t)
(define-key markdown-mode-map [(control c) (?\[)] 'helm-bibtex)
(define-key markdown-mode-map [(control c) (control v)] 'mxp-find-corresponding-pdf)
(when (package-installed-p 'bury-successful-compilation)
(bury-successful-compilation))
;; Set default target for make to a PDF version of the file
(when (or (file-exists-p "GNUmakefile")
(file-exists-p "makefile")
(file-exists-p "Makefile"))
(set (make-local-variable 'compile-command)
(concat "make -k "
;; Don't try to quote or escape anything, it's
;; pointless, and make doesn't really work with
;; filenames with spaces.
(if buffer-file-name
(file-relative-name
(concat (file-name-sans-extension buffer-file-name)
".pdf"))))))
;; Reload PDF after compilation if it's displayed in Emacs
(add-hook 'compilation-finish-functions 'mxp-pandoc-make-refresh-pdf))
(defun mxp-find-corresponding-pdf ()
"Visit PDF file corresponding to the current buffer's file in a new frame.
The PDF file name is generated by replacing the extension of the current buffer file with \".pdf\". Signal an error if the PDF does not exist."
(interactive)
(let ((pdf-file (concat (file-name-sans-extension buffer-file-name)
".pdf")))
(if (file-exists-p pdf-file)
(find-file-other-frame pdf-file)
(error "%s does not exist" pdf-file))))
(defun mxp-pandoc-make-refresh-pdf (buf result)
"Refresh PDF after recompilation if it is open in Emacs.
This function is intended to be called from `compilation-finish-functions'."
(when (string-match "finished" result)
(let ((pdf-file (substring (car compilation-arguments)
(string-match "[^ ]+\\.pdf$"
(car compilation-arguments)))))
(when pdf-file
(if (boundp 'TeX-revert-document-buffer)
(TeX-revert-document-buffer pdf-file)
;; This is exactly what `TeX-revert-document-buffer` does,
;; but it doesn't make sense to require AUCTeX just for this
;; convenience function.
(let ((pdf-buf (find-buffer-visiting pdf-file)))
(when pdf-buf
(with-current-buffer pdf-buf
(revert-buffer nil t t)))))))))
(when (package-installed-p 'markdown-mode)
(setq markdown-command "/opt/pandoc/bin/pandoc -s --filter=pandoc-citeproc "
markdown-command-needs-filename nil)
(add-hook 'markdown-mode-hook 'my-markdown-mode-hook))
(defface pandoc-citation-face
'((t :foreground "dark orange"))
"Face for pandoc citation syntax")
(font-lock-add-keywords
'gfm-mode
;; '(("\\B\\(-?@[[:alnum:]_][-_[:alnum:]:.#$%&+?<>~/]+\\)" . 'pandoc-citation-face)))
;; '(("\\B\\[\\([^][]*\\|@[[:alnum:]_][-_[:alnum:]:.#$%&+?<>~/]+\\)+\\]" . 'pandoc-citation-face)))
'(("\\B\\[[^][]*@[[:alnum:]_]+[^][]*\\]" . 'pandoc-citation-face)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment