latex: refactor

- Moved backend determination to `config.el`
- Replaced unnecessary backquote construct with simple quotation
- Replaced `pcase` form with only one-arm with `when` or `unless` form
- Refactored function
This commit is contained in:
Lucius Hu 2021-03-18 00:31:59 -04:00 committed by duianto
parent 4ff5027b80
commit cd0c914ba1
3 changed files with 27 additions and 39 deletions

View file

@ -31,7 +31,7 @@
;; ...but AUCTeX runs LaTeX-mode-hook rather than latex-mode-hook, so:
(add-hook 'LaTeX-mode-hook #'spacemacs//init-jump-handlers-latex-mode)
(defvar latex-backend nil
(defvar latex-backend (if (configuration-layer/layer-used-p 'lsp) 'lsp 'company-auctex)
"The backend to use for IDE features.
Possible values are `lsp' and `company-auctex'.
If `nil' then 'company-auctex` is the default backend unless `lsp' layer is used")

View file

@ -21,50 +21,38 @@
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
(defun spacemacs//latex-backend ()
"Returns selected backend."
(if latex-backend
latex-backend
(cond
((configuration-layer/layer-used-p 'lsp) 'lsp)
(t 'company-auctex))))
(defun spacemacs//latex-setup-company ()
"Conditionally setup company based on backend."
(pcase (spacemacs//latex-backend)
(pcase latex-backend
;; Activate lsp company explicitly to activate
;; standard backends as well
(`lsp (spacemacs|add-company-backends
('lsp (spacemacs|add-company-backends
:backends company-capf
:modes LaTeX-mode))
(_ (when (configuration-layer/package-used-p 'company-auctex)
(if (configuration-layer/package-used-p 'company-math)
(spacemacs|add-company-backends
:backends
company-math-symbols-unicode
company-math-symbols-latex
(company-auctex-macros)
company-auctex-symbols
company-auctex-environments
:modes LaTeX-mode)
(spacemacs|add-company-backends
:backends
(company-auctex-macros)
company-auctex-symbols
company-auctex-environments
:modes LaTeX-mode)))
(when (configuration-layer/package-used-p 'company-reftex)
(spacemacs|add-company-backends
:backends
company-reftex-labels
company-reftex-citations
:modes LaTeX-mode)))))
('company-auctex (when (configuration-layer/package-used-p 'company-auctex)
(spacemacs|add-company-backends
:backends (if (configuration-layer/package-usedp 'company-math)
'(company-math-symbols-unicode
company-math-symbols-latex
(company-auctex-macros)
company-auctex-symbols
company-auctex-environments)
'(company-auctex-macros
company-auctex-symbols
company-auctex-environments))
:modes LaTeX-mode))
(when (configuration-layer/package-used-p 'company-reftex)
(spacemacs|add-company-backends
:backends
company-reftex-labels
company-reftex-citations
:modes LaTeX-mode)))))
(defun spacemacs//latex-setup-backend ()
"Conditionally setup latex backend."
(pcase (spacemacs//latex-backend)
(`lsp (require 'lsp-latex)
(lsp))))
(when (eq latex-backend 'lsp)
(require 'lsp-latex)
(lsp)))
(defun latex/build ()
(interactive)

View file

@ -99,7 +99,7 @@
"xff" 'latex/font-sans-serif
"xfr" 'latex/font-serif)
(spacemacs/declare-prefix-for-mode mode "mxf" "fonts")
(unless (and (eq (spacemacs//latex-backend) 'lsp)
(unless (and (eq latex-backend 'lsp)
(eq mode 'latex-mode))
(spacemacs/declare-prefix-for-mode mode "mh" "help")
(spacemacs/declare-prefix-for-mode mode "mx" "text/fonts")
@ -154,7 +154,7 @@
"xfu" 'latex/font-upright)
;; Rebind latex keys to avoid conflicts with lsp mode
(if (eq (spacemacs//latex-backend) 'lsp)
(if (eq latex-backend 'lsp)
(spacemacs/set-leader-keys-for-major-mode 'latex-mode
"au" 'TeX-command-run-all
"c" 'latex/build
@ -192,7 +192,7 @@
(add-hook 'LaTeX-mode-hook 'turn-on-reftex)
(setq reftex-plug-into-AUCTeX '(nil nil t t t)
reftex-use-fonts t)
(let ((prefix (if (eq (spacemacs//latex-backend) 'lsp) "R" "r")))
(let ((prefix (if (eq latex-backend 'lsp) "R" "r")))
(spacemacs/declare-prefix-for-mode 'latex-mode (concat "m" prefix) "reftex")
(spacemacs/set-leader-keys-for-major-mode 'latex-mode
(concat prefix "c") 'reftex-citation