diff --git a/docs/modules.org b/docs/modules.org index f2f4471d5..477b2e5ae 100644 --- a/docs/modules.org +++ b/docs/modules.org @@ -115,7 +115,7 @@ Modules that bring support for a language or group of languages to Emacs. + [[file:../modules/lang/javascript/README.org][javascript]] =+lsp= - JavaScript, TypeScript, and CoffeeScript support + julia - TODO + kotlin =+lsp+= - TODO -+ [[file:../modules/lang/latex/README.org][latex]] =+latexmk +cdlatex= - TODO ++ [[file:../modules/lang/latex/README.org][latex]] =+latexmk +cdlatex +fold= - TODO + lean - TODO + [[file:../modules/lang/ledger/README.org][ledger]] - TODO + lua =+moonscript= - TODO diff --git a/modules/lang/latex/README.org b/modules/lang/latex/README.org index 34ce6b12c..d0e8d5788 100644 --- a/modules/lang/latex/README.org +++ b/modules/lang/latex/README.org @@ -33,6 +33,8 @@ Provide a helping hand when working with LaTeX documents. ** Module Flags + =+latexmk= Use LatexMk instead of LaTeX to compile documents. + =+cdlatex= Enable [[https://github.com/cdominik/cdlatex][cdlatex]] for fast math insertion. ++ =+fold= Use TeX-fold (from auctex) to fold LaTeX macros to unicode, and make + folding hook-based and less manual. ** Plugins + [[http://www.gnu.org/software/auctex/][auctex]] diff --git a/modules/lang/latex/autoload.el b/modules/lang/latex/autoload.el index d7176754e..cb570e2eb 100644 --- a/modules/lang/latex/autoload.el +++ b/modules/lang/latex/autoload.el @@ -39,6 +39,18 @@ Continuation lines are indented either twice `LaTeX-indent-level', or (+ offset indent)) ((+ contin indent)))))) +;;;###autoload +(defun +latex-fold-last-macro-a (&rest _) + "Advice to auto-fold LaTeX macros after functions that +typically insert macros." + ;; A simpler approach would be to just fold the whole line, but if point was + ;; inside a macro that would would kick it out. So instead we fold the last + ;; macro before point, hoping its the one newly inserted. + (TeX-fold-region (save-excursion + (search-backward "\\" (line-beginning-position) t) + (point)) + (1+ (point)))) + ;;;###autoload (defun +latex-symbols-company-backend (command &optional arg &rest _ignored) "A wrapper backend for `company-mode' that either uses diff --git a/modules/lang/latex/config.el b/modules/lang/latex/config.el index 3ee39af54..8d8f4e16b 100644 --- a/modules/lang/latex/config.el +++ b/modules/lang/latex/config.el @@ -53,8 +53,6 @@ If no viewers are found, `latex-preview-pane' is used.") fill-nobreak-predicate (cons #'texmathp fill-nobreak-predicate)) ;; Enable word wrapping (add-hook 'TeX-mode-hook #'visual-line-mode) - ;; Fold TeX macros - (add-hook 'TeX-mode-hook #'TeX-fold-mode) ;; Enable rainbow mode after applying styles to the buffer (add-hook 'TeX-update-style-hook #'rainbow-delimiters-mode) ;; display output of latex commands in popup @@ -75,6 +73,45 @@ If no viewers are found, `latex-preview-pane' is used.") (sp-local-pair modes "``" nil :unless '(:add sp-in-math-p))))) +(use-package! tex-fold + :when (featurep! +fold) + :hook (TeX-mode . TeX-fold-buffer) + :hook (TeX-mode . TeX-fold-mode) + + :config + ;; Fold after all auctex macro insertions + (advice-add #'TeX-insert-macro :after #'+latex-fold-last-macro-a) + ;; Fold after cdlatex macro insertions + (advice-add #'cdlatex-math-symbol :after #'+latex-fold-last-macro-a) + (advice-add #'cdlatex-math-modify :after #'+latex-fold-last-macro-a) + ;; Fold after snippets + (when (featurep! :editor snippets) + (add-hook 'TeX-fold-mode-hook + (defun +latex-fold-set-yas-hook-h () + "Set a local after-snippet-hook to fold the snippet contents." + (add-hook! 'yas-after-exit-snippet-hook :local + (TeX-fold-region yas-snippet-beg yas-snippet-end))))) + + (add-hook 'mixed-pitch-mode-hook + (defun +latex-fold-set-variable-pitch-h () + "Fix folded things invariably getting fixed pitch when using mixed-pitch. +Math faces should stay fixed by the mixed-pitch blacklist, this +is mostly for \\section etc." + (when mixed-pitch-mode + ;; Adding to this list makes mixed-pitch clean the face remaps after us + (add-to-list 'mixed-pitch-fixed-cookie + (face-remap-add-relative + 'TeX-fold-folded-face + :family (face-attribute 'variable-pitch :family) + :height (face-attribute 'variable-pitch :height)))))) + + (map! :map TeX-fold-mode-map + :localleader + :desc "Fold paragraph" "f" #'TeX-fold-paragraph + :desc "Unfold paragraph" "F" #'TeX-fold-clearout-paragraph + :desc "Unfold buffer" "C-f" #'TeX-fold-clearout-buffer)) + + (after! latex (setq LaTeX-section-hook ; Add the toc entry to the sectioning hooks. '(LaTeX-section-heading