Add +latex-symbols-compand-backend delegate #754

If +latex-enable-unicode-math is non-nil, company-math-symbols-unicode
will be used instead of company-math-symbols-latex.
This commit is contained in:
Henrik Lissner 2018-07-29 21:57:56 +02:00
parent 9f4b6869b6
commit c96c2aa7fb
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
2 changed files with 22 additions and 12 deletions

View file

@ -40,4 +40,11 @@
(t (t
(+ contin indent)))))) (+ contin indent))))))
;;;###autoload
(defun +latex-symbols-company-backend (command &optional arg &rest _ignored)
"A wrapper backend for `company-mode' that either uses
`company-math-symbols-unicode' or `company-math-symbols-latex'. If
`+latex-enable-unicode-math' is non-nil use the former, otherwise the latter."
(if +latex-enable-unicode-math
(company-math-symbols-unicode command arg)
(company-math-symbols-latex command arg)))

View file

@ -6,6 +6,15 @@
(defvar +latex-bibtex-file "" (defvar +latex-bibtex-file ""
"File AUCTeX (specifically RefTeX) uses to search for citations.") "File AUCTeX (specifically RefTeX) uses to search for citations.")
(defvar +latex-enable-unicode-math nil
"If non-nil, use `company-math-symbols-unicode' backend in LaTeX-mode,
enabling unicode symbols in math regions. This requires the unicode-math latex
package to be installed.")
;;
(defvar +latex--company-backends nil)
;; ;;
;; Plugins ;; Plugins
;; ;;
@ -64,6 +73,8 @@
LaTeX-section-label) LaTeX-section-label)
LaTeX-fill-break-at-separators nil LaTeX-fill-break-at-separators nil
LaTeX-item-indent 0) LaTeX-item-indent 0)
(when +latex--company-backends
(set-company-backend! 'latex-mode +latex--company-backends))
;; Set custom item indentation ;; Set custom item indentation
(dolist (env '("itemize" "enumerate" "description")) (dolist (env '("itemize" "enumerate" "description"))
(add-to-list 'LaTeX-indent-environment-list `(,env +latex/LaTeX-indent-item)))) (add-to-list 'LaTeX-indent-environment-list `(,env +latex/LaTeX-indent-item))))
@ -76,26 +87,18 @@
preview-scale-function preview-scale-function
(lambda () (* (/ 10.0 (preview-document-pt)) preview-scale)))) (lambda () (* (/ 10.0 (preview-document-pt)) preview-scale))))
(defvar +latex--company-backends nil)
(def-package! company-auctex (def-package! company-auctex
:when (featurep! :completion company) :when (featurep! :completion company)
:defer t :defer t
:init :init
(add-to-list '+latex--company-backends 'company-auctex-environments nil #'eq) (add-to-list '+latex--company-backends #'company-auctex-environments nil #'eq)
(add-to-list '+latex--company-backends 'company-auctex-macros nil #'eq)) (add-to-list '+latex--company-backends #'company-auctex-macros nil #'eq))
(def-package! company-math (def-package! company-math
:when (featurep! :completion company) :when (featurep! :completion company)
:defer t :defer t
:init :init
(add-to-list '+latex--company-backends '+latex-symbols-company-backend nil #'eq)) (add-to-list '+latex--company-backends #'+latex-symbols-company-backend nil #'eq))
(when +latex--company-backends
;; We can't use the `set-company-backend!' because Auctex reports its
;; major-mode as `latex-mode', but uses LaTeX-mode-hook for its mode, which is
;; not something `set-company-backend!' anticipates (and shouldn't have to!)
(add-hook! 'LaTeX-mode-hook (add-to-list (make-local-variable 'company-backends) +latex--company-backends)))
;; Nicely indent lines that have wrapped when visual line mode is activated ;; Nicely indent lines that have wrapped when visual line mode is activated
(def-package! adaptive-wrap (def-package! adaptive-wrap