.emacs.d/elisp/init-yasnippet.el

67 lines
2.3 KiB
EmacsLisp

;;; init-yasnippet.el --- -*- lexical-binding: t -*-
;;
;; Filename: init-yasnippet.el
;; Description: Initialize YASnippet
;; Author: Mingde (Matthew) Zeng
;; Copyright (C) 2019 Mingde (Matthew) Zeng
;; Created: Tue Apr 23 23:08:17 2019 (-0400)
;; Version: 2.0.0
;; Last-Updated: Sat Dec 14 20:56:21 2019 (-0500)
;; By: Mingde (Matthew) Zeng
;; URL: https://github.com/MatthewZMD/.emacs.d
;; Keywords: M-EMACS .emacs.d yasnippet
;; Compatibility: emacs-version >= 26.1
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;; Commentary:
;;
;; This initializes YASnippet
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or (at
;; your option) any later version.
;;
;; This program is distributed in the hope that it will be useful, but
;; WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;; General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;; Code:
;; YASnippetPac
(use-package yasnippet
:diminish yas-minor-mode
:init
(use-package yasnippet-snippets :after yasnippet)
:hook ((prog-mode LaTeX-mode org-mode) . yas-minor-mode)
:bind
(:map yas-minor-mode-map ("C-c C-n" . yas-expand-from-trigger-key))
(:map yas-keymap
(("TAB" . smarter-yas-expand-next-field)
([(tab)] . smarter-yas-expand-next-field)))
:config
(yas-reload-all)
(defun smarter-yas-expand-next-field ()
"Try to `yas-expand' then `yas-next-field' at current cursor position."
(interactive)
(let ((old-point (point))
(old-tick (buffer-chars-modified-tick)))
(yas-expand)
(when (and (eq old-point (point))
(eq old-tick (buffer-chars-modified-tick)))
(ignore-errors (yas-next-field))))))
;; -YASnippetPac
(provide 'init-yasnippet)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; init-yasnippet.el ends here