💥 Remove :feature category
:feature was a "catch-all" category. Many of its modules fit better in other categories, so they've been moved: - feature/debugger -> tools/debugger - feature/evil -> editor/evil - feature/eval -> tools/eval - feature/lookup -> tools/lookup - feature/snippets -> editor/snippets - feature/file-templates -> editor/file-templates - feature/workspaces -> ui/workspaces More potential changes in the future: - A new :term category for terminal emulation modules (eshell, term and vterm). - A new :os category for modules dedicated to os-specific functionality. The :tools macos module would fit here, but so would modules for nixos and arch. - A new :services category for web-service integration, like wakatime, twitter, elfeed, gist and pastebin services.
This commit is contained in:
parent
52eed893fe
commit
77e4cc4d58
193 changed files with 304 additions and 303 deletions
36
modules/editor/snippets/README.org
Normal file
36
modules/editor/snippets/README.org
Normal file
|
@ -0,0 +1,36 @@
|
|||
#+TITLE: editor/snippets
|
||||
#+DATE: February 11, 2017
|
||||
#+SINCE: v2.0
|
||||
#+STARTUP: inlineimages
|
||||
|
||||
* Table of Contents :TOC:
|
||||
- [[Description][Description]]
|
||||
- [[Module Flags][Module Flags]]
|
||||
- [[Plugins][Plugins]]
|
||||
- [[Hacks][Hacks]]
|
||||
- [[Prerequisites][Prerequisites]]
|
||||
- [[Features][Features]]
|
||||
- [[Configuration][Configuration]]
|
||||
- [[Troubleshooting][Troubleshooting]]
|
||||
|
||||
* Description
|
||||
This module adds snippets to Emacs, powered by yasnippet.
|
||||
|
||||
** Module Flags
|
||||
This module exposes no flags.
|
||||
|
||||
** Plugins
|
||||
+ [[https://github.com/joaotavora/yasnippet][yasnippet]]
|
||||
+ [[https://github.com/abo-abo/auto-yasnippet][auto-yasnippet]]
|
||||
+ [[https://github.com/hlissner/emacs-snippets][emacs-snippets]]
|
||||
|
||||
** TODO Hacks
|
||||
|
||||
* Prerequisites
|
||||
This module has no external dependencies.
|
||||
|
||||
* TODO Features
|
||||
|
||||
* TODO Configuration
|
||||
|
||||
* TODO Troubleshooting
|
16
modules/editor/snippets/autoload/evil.el
Normal file
16
modules/editor/snippets/autoload/evil.el
Normal file
|
@ -0,0 +1,16 @@
|
|||
;;; editor/snippets/autoload/evil.el -*- lexical-binding: t; -*-
|
||||
;;;###if (featurep! :editor evil)
|
||||
|
||||
;;;###autoload
|
||||
(defun +snippets/expand-on-region ()
|
||||
"Only use this with `evil-mode'. Expands a snippet around a selected region
|
||||
and switches to insert mode if there are editable fields."
|
||||
(interactive)
|
||||
(when (evil-visual-state-p)
|
||||
(evil-visual-select evil-visual-beginning evil-visual-end 'inclusive))
|
||||
(cl-letf (((symbol-function 'region-beginning) (lambda () evil-visual-beginning))
|
||||
((symbol-function 'region-end) (lambda () evil-visual-end)))
|
||||
(yas-insert-snippet))
|
||||
(when (yas-active-snippets)
|
||||
(evil-insert-state +1)))
|
||||
|
10
modules/editor/snippets/autoload/settings.el
Normal file
10
modules/editor/snippets/autoload/settings.el
Normal file
|
@ -0,0 +1,10 @@
|
|||
;;; editor/snippets/autoload/settings.el -*- lexical-binding: t; -*-
|
||||
|
||||
;;;###autodef
|
||||
(defun set-yas-minor-mode! (modes)
|
||||
"Register minor MODES (one mode symbol or a list of them) with yasnippet so it
|
||||
can have its own snippets category, if the folder exists."
|
||||
(dolist (mode (doom-enlist modes))
|
||||
(let ((fn (intern (format "+snippets|register-%s" mode))))
|
||||
(fset fn (lambda () (yas-activate-extra-mode mode)))
|
||||
(add-hook (intern (format "%s-hook" mode)) fn))))
|
121
modules/editor/snippets/autoload/snippets.el
Normal file
121
modules/editor/snippets/autoload/snippets.el
Normal file
|
@ -0,0 +1,121 @@
|
|||
;;; editor/snippets/autoload/snippets.el -*- lexical-binding: t; -*-
|
||||
|
||||
(defun +snippets--remove-p (x y)
|
||||
(and (equal (yas--template-key x) (yas--template-key y))
|
||||
(file-in-directory-p (yas--template-get-file x) doom-emacs-dir)))
|
||||
|
||||
;;;###autoload
|
||||
(defun +snippets-prompt-private (prompt choices &optional display-fn)
|
||||
"Prioritize private snippets over built-in ones if there are multiple
|
||||
choices.
|
||||
|
||||
There are two groups of snippets in Doom Emacs. The built in ones (under
|
||||
`doom-emacs-dir'; provided by Doom or its plugins) or your private snippets
|
||||
(outside of `doom-eamcs-dir').
|
||||
|
||||
If there are multiple snippets with the same key in either camp (but not both),
|
||||
you will be prompted to select one.
|
||||
|
||||
If there are conflicting keys across the two camps, the built-in ones are
|
||||
ignored. This makes it easy to override built-in snippets with private ones."
|
||||
(when (memq this-command '(yas-expand +snippets/expand-on-region))
|
||||
(let* ((gc-cons-threshold doom-gc-cons-upper-limit)
|
||||
(choices (cl-remove-duplicates choices :test #'+snippets--remove-p)))
|
||||
(if (cdr choices)
|
||||
(cl-loop for fn in (cdr (memq '+snippets-prompt-private yas-prompt-functions))
|
||||
if (funcall fn prompt choices display-fn)
|
||||
return it)
|
||||
(car choices)))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +snippets/goto-start-of-field ()
|
||||
"Go to the beginning of the current field."
|
||||
(interactive)
|
||||
(let* ((snippet (car (yas-active-snippets)))
|
||||
(active-field (yas--snippet-active-field snippet))
|
||||
(position (if (yas--field-p active-field) (yas--field-start active-field) -1)))
|
||||
(if (= (point) position)
|
||||
(move-beginning-of-line 1)
|
||||
(goto-char position))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +snippets/goto-end-of-field ()
|
||||
"Go to the end of the current field."
|
||||
(interactive)
|
||||
(let* ((snippet (car (yas-active-snippets)))
|
||||
(active-field (yas--snippet-active-field snippet))
|
||||
(position (if (yas--field-p active-field) (yas--field-end active-field) -1)))
|
||||
(if (= (point) position)
|
||||
(move-end-of-line 1)
|
||||
(goto-char position))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +snippets/delete-backward-char (&optional field)
|
||||
"Prevents Yas from interfering with backspace deletion."
|
||||
(interactive)
|
||||
(let ((field (or field (and (overlayp yas--active-field-overlay)
|
||||
(overlay-buffer yas--active-field-overlay)
|
||||
(overlay-get yas--active-field-overlay 'yas--field)))))
|
||||
(unless (and (yas--field-p field)
|
||||
(eq (point) (marker-position (yas--field-start field))))
|
||||
(call-interactively #'delete-backward-char))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +snippets/delete-forward-char-or-field (&optional field)
|
||||
"Delete forward, or skip the current field if it's empty. This is to prevent
|
||||
buggy behavior when <delete> is pressed in an empty field."
|
||||
(interactive)
|
||||
(let ((field (or field (and yas--active-field-overlay
|
||||
(overlay-buffer yas--active-field-overlay)
|
||||
(overlay-get yas--active-field-overlay 'yas--field)))))
|
||||
(cond ((not (yas--field-p field))
|
||||
(delete-char 1))
|
||||
((and (not (yas--field-modified-p field))
|
||||
(eq (point) (marker-position (yas--field-start field))))
|
||||
(yas--skip-and-clear field)
|
||||
(yas-next-field 1))
|
||||
((eq (point) (marker-position (yas--field-end field))) nil)
|
||||
((delete-char 1)))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +snippets/delete-to-start-of-field (&optional field)
|
||||
"Delete to start-of-field."
|
||||
(interactive)
|
||||
(unless field
|
||||
(setq field (and (overlayp yas--active-field-overlay)
|
||||
(overlay-buffer yas--active-field-overlay)
|
||||
(overlay-get yas--active-field-overlay 'yas--field))))
|
||||
(when (yas--field-p field)
|
||||
(let ((sof (marker-position (yas--field-start field))))
|
||||
(when (and field (> (point) sof))
|
||||
(delete-region sof (point))))))
|
||||
|
||||
|
||||
;;
|
||||
;; Hooks
|
||||
|
||||
;;;###autoload
|
||||
(defun +snippets|enable-project-modes (mode &rest _)
|
||||
"Automatically enable snippet libraries for project minor modes defined with
|
||||
`def-project-mode!'."
|
||||
(if (symbol-value mode)
|
||||
(yas-activate-extra-mode mode)
|
||||
(yas-deactivate-extra-mode mode)))
|
||||
|
||||
|
||||
;;
|
||||
;; Commands
|
||||
|
||||
;;;###autoload
|
||||
(defun +snippets/browse (_arg)
|
||||
"TODO"
|
||||
(interactive "P")
|
||||
(doom-project-browse +snippets-dir))
|
||||
|
||||
;;;###autoload
|
||||
(defun +snippets/find-file ()
|
||||
"TODO"
|
||||
(interactive)
|
||||
(if (file-directory-p +snippets-dir)
|
||||
(doom-project-find-file +snippets-dir)
|
||||
(yas-visit-snippet-file)))
|
59
modules/editor/snippets/config.el
Normal file
59
modules/editor/snippets/config.el
Normal file
|
@ -0,0 +1,59 @@
|
|||
;;; editor/snippets/config.el -*- lexical-binding: t; -*-
|
||||
|
||||
(defvar +snippets-dir (expand-file-name "snippets/" doom-private-dir)
|
||||
"Directory where `yasnippet' will search for your private snippets.")
|
||||
|
||||
|
||||
;;
|
||||
;; Packages
|
||||
|
||||
(def-package! yasnippet
|
||||
:commands (yas-minor-mode-on yas-expand yas-expand-snippet yas-lookup-snippet
|
||||
yas-insert-snippet yas-new-snippet yas-visit-snippet-file)
|
||||
:init
|
||||
;; Ensure `yas-reload-all' is called as late as possible. Other modules could
|
||||
;; have additional configuration for yasnippet. For example, file-templates.
|
||||
(add-transient-hook! 'yas-minor-mode-hook (yas-reload-all))
|
||||
|
||||
(add-hook! (text-mode prog-mode conf-mode snippet-mode)
|
||||
#'yas-minor-mode-on)
|
||||
|
||||
:config
|
||||
(setq yas-verbosity (if doom-debug-mode 3 0)
|
||||
yas-also-auto-indent-first-line t
|
||||
yas-triggers-in-field t ; Allow nested snippets
|
||||
;; Remove default ~/.emacs.d/snippets
|
||||
yas-snippet-dirs (delete yas--default-user-snippets-dir yas-snippet-dirs))
|
||||
|
||||
;; Allow private snippets in DOOMDIR/snippets
|
||||
(add-to-list 'yas-snippet-dirs '+snippets-dir nil #'eq)
|
||||
|
||||
;; Remove GUI dropdown prompt (prefer ivy/helm)
|
||||
(setq yas-prompt-functions (delq 'yas-dropdown-prompt yas-prompt-functions))
|
||||
;; Prioritize private snippets in `+snippets-dir' over built-in ones if there
|
||||
;; are multiple choices.
|
||||
(add-to-list 'yas-prompt-functions #'+snippets-prompt-private nil #'eq)
|
||||
|
||||
;; Register `def-project-mode!' modes with yasnippet. This enables project
|
||||
;; specific snippet libraries (e.g. for Laravel, React or Jekyll projects).
|
||||
(add-hook 'doom-project-hook #'+snippets|enable-project-modes)
|
||||
|
||||
;; Exit snippets on ESC from normal mode
|
||||
(add-hook 'doom-escape-hook #'yas-abort-snippet)
|
||||
|
||||
(after! smartparens
|
||||
;; tell smartparens overlays not to interfere with yasnippet keybinds
|
||||
(advice-add #'yas-expand :before #'sp-remove-active-pair-overlay))
|
||||
|
||||
(when (featurep! :editor evil)
|
||||
;; evil visual-mode integration for `yas-insert-snippet'
|
||||
(define-key yas-minor-mode-map [remap yas-insert-snippet] #'+snippets/expand-on-region)))
|
||||
|
||||
|
||||
;; `auto-yasnippet'
|
||||
(setq aya-persist-snippets-dir (concat doom-etc-dir "auto-snippets/"))
|
||||
|
||||
|
||||
;; default snippets library
|
||||
(def-package! emacs-snippets
|
||||
:after yasnippet)
|
10
modules/editor/snippets/packages.el
Normal file
10
modules/editor/snippets/packages.el
Normal file
|
@ -0,0 +1,10 @@
|
|||
;; -*- no-byte-compile: t; -*-
|
||||
;;; editor/snippets/packages.el
|
||||
|
||||
(package! yasnippet)
|
||||
(package! auto-yasnippet)
|
||||
|
||||
(package! emacs-snippets
|
||||
:recipe (:fetcher github
|
||||
:repo "hlissner/emacs-snippets"
|
||||
:files ("*")))
|
Loading…
Add table
Add a link
Reference in a new issue