Skip to content

Instantly share code, notes, and snippets.

@mahito1594
Last active April 19, 2019 15:37
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 mahito1594/966aead817a675a51e97e6d4b9ed6c07 to your computer and use it in GitHub Desktop.
Save mahito1594/966aead817a675a51e97e6d4b9ed6c07 to your computer and use it in GitHub Desktop.
My Emacs configure for YaTeX-mode, see http://mtino1594.hatenablog.com/entry/2019/04/07/200000
(require 'package)
(add-to-list 'package-archives
'("melpa" . "https://melpa.org/packages/") t)
(package-initialize)
(unless package-archive-contents (package-refresh-contents))
(unless (package-installed-p 'use-package)
(package-install 'use-package))
(require 'use-package)
(use-package company
:ensure t
:hook (after-init . global-company-mode))
(use-package flycheck
:ensure t
:hook (after-init . global-flycheck-mode)
:config
(flycheck-add-mode 'tex-chktex 'yatex-mode)
(flycheck-add-mode 'tex-lacheck 'yatex-mode))
(use-package yatex
:ensure t
:preface
(defvar my-YaTeX-section-alist
'(("part" . 0)
("chapter" . 1)
("section" . 2)
("subsection" . 3)
("subsubsection" . 4)
("paragraph" . 5)
("subparagraph" . 6)))
(defvar my-YaTeX-metasection-list
'("documentclass"
"begin{document}" "end{document}"
"frontmatter" "mainmatter" "appendix" "backmatter"))
(defvar my-YaTeX-outline-regexp
(concat (regexp-quote "\\")
(regexp-opt (append my-YaTeX-metasection-list
(mapcar #'car my-YaTeX-section-alist))
t)))
(defvar my-YaTeX-outline-promotion-headings
'("\\chapter" "\\section" "\\subsection"
"\\subsubsection" "\\paragraph" "\\subparagraph"))
(defun my-YaTeX-outline-level ()
(if (looking-at my-YaTeX-outline-regexp)
(1+ (or (cdr (assoc (match-string 1) my-YaTeX-section-alist)) -1))
1000))
(defun my-YaTeX-with-outline ()
(outline-minor-mode 1)
(setq-local outline-regexp my-YaTeX-outline-regexp)
(setq-local outline-level #'my-YaTeX-outline-level)
(setq-local outline-promotion-headings my-YaTeX-outline-promotion-headings))
:init
(setq YaTeX-inhibit-prefix-letter t)
:mode (("\\.tex\\'" . yatex-mode)
("\\.sty\\'" . yatex-mode)
("\\.ltx\\'" . yatex-mode))
:hook (yatex-mode . my-YaTeX-with-outline)
:defer t
:config
(setq YaTeX-kanji-code 4) ; 1 => SJIS, 2 => JIS, 3 => EUC, 4 => UTF8
(setq YaTeX-use-AMS-LaTeX t)
(setq tex-command "latexmk"))
(use-package company-math
:ensure t
:demand t
:after (company yatex)
:config
(push 'company-math-symbols-latex company-backends)
(push 'company-latex-commands company-backends))
(use-package reftex
:ensure nil
:hook (yatex-mode . reftex-mode)
:bind (:map reftex-mode-map
("C-c )" . nil)
("C-c (" . reftex-reference))
:defer t
:custom
(reftex-ref-style-default-list '("Cleveref") "Use cref/Cref as default"))
(use-package outline-magic
:ensure t
:preface
(defun my-outline-move-subtree-down (&optional arg)
"Move the currrent subtree down past ARG headlines of the same level.
If the current subtree is folded, call `outline-hide-subtree' after move down."
(interactive "p")
(let* ((headers (or arg 1))
(movfunc (if (> headers 0) 'outline-get-next-sibling
'outline-get-last-sibling))
(ins-point (make-marker))
(cnt (abs headers))
(folded (save-match-data
(outline-end-of-heading)
(outline-invisible-p)))
beg end txt)
;; Select the tree
(outline-back-to-heading)
(setq beg (point))
(outline-end-of-subtree)
(if (= (char-after) ?\n) (forward-char 1))
(setq end (point))
;; Find insertion point, with error handling
(goto-char beg)
(while (> cnt 0)
(or (funcall movfunc)
(progn (goto-char beg)
(error "Cannot move past superior level")))
(setq cnt (1- cnt)))
(if (> headers 0)
;; Moving forward - still need to move over subtree
(progn (outline-end-of-subtree)
(if (= (char-after) ?\n) (forward-char 1))))
(move-marker ins-point (point))
(setq txt (buffer-substring beg end))
(delete-region beg end)
(insert txt)
(goto-char ins-point)
(if folded (outline-hide-subtree))
(move-marker ins-point nil)))
:bind (:map outline-minor-mode-map
("C-<tab>" . outline-cycle)
("M-<left>" . outline-promote)
("M-<right>" . outline-demote)
("M-<up>" . outline-move-subtree-up)
("M-<down>" . outline-move-subtree-down))
:demand t
:after (outline)
:config
(advice-add 'outline-move-down :override #'my-outline-move-subtree-down))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment