Skip to content

Instantly share code, notes, and snippets.

@olmstadfm
Last active July 19, 2016 08:35
Show Gist options
  • Save olmstadfm/96f2b4e54a2aa52ba554 to your computer and use it in GitHub Desktop.
Save olmstadfm/96f2b4e54a2aa52ba554 to your computer and use it in GitHub Desktop.
Emacs polymode for LaTex with erb-chunks

Emacs polymode for LaTex with erb-chunks

Коллега генерировал pdf c помощью latex, а для подстановки переменных в шаблон использовал erb. Ну и огорчался конечно, что ни подсветка синтаксиса не работает, ни автодополнение. И тут мне стало интересно. Поэтому с помощью библиотеки Polymode был изготовлен режим для emacs, который внутри erb-блоков включал ruby-mode со всеми плюшками, а на всем остальном тексте работал как latex-mode.

(require 'polymode)
(if window-system (require 'font-latex))
(defcustom pm-host/latex
(pm-bchunkmode "latex" :mode 'latex-mode)
"Latex host chunkmode"
:group 'hostmodes
:type 'object)
(defcustom pm-inner/nolatex
(pm-hbtchunkmode "nolatex"
:head-reg "\<\%[-=]?"
:tail-reg "\%\>")
"No latex chunk."
:group 'innermodes
:type 'object)
(defcustom pm-inner/erb
(clone pm-inner/nolatex :mode 'ruby-mode)
"Notex innermode for ruby"
:group 'innermodes
:type 'object)
(defcustom pm-poly/latex+erb
(pm-polymode-one "awesome"
:hostmode 'pm-host/latex
:innermode 'pm-inner/erb)
"Awesome polymode."
:group 'polymodes
:type 'object)
(define-polymode poly-latex+erb-mode pm-poly/latex+erb)
(add-to-list 'auto-mode-alist '("\\.pdf.erb" . poly-latex+erb-mode))
;; * supress colors in dired
;; defaults are too bright
;; * turn on max decoration in latex
;; for some reason syntax highlight is turned off in latex-mode
(setq font-lock-maximum-decoration (quote (
(latex-mode . t)
(dired-mode . nil)
)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment