Updating Doom Emacs.

This commit is contained in:
Derek Taylor
2020-06-19 22:43:40 -05:00
parent 0f664d532a
commit a5c86c514a
453 changed files with 13527 additions and 12455 deletions

View File

@@ -288,16 +288,27 @@ shadow the default snippet)."
;;;###autoload
(defun +snippets-expand-on-region-a (orig-fn &optional no-condition)
"Fix off-by-one issue with expanding snippets on an evil visual region, and
switches to insert mode.
"Fix off-by-one when expanding snippets on an evil visual region.
If evil-local-mode isn't enabled, run ORIG-FN as is."
Also strips whitespace out of selection. Also switches to insert mode. If
`evil-local-mode' isn't enabled, or we're not in visual mode, run ORIG-FN as
is."
(if (not (and (bound-and-true-p evil-local-mode)
(evil-visual-state-p)))
(funcall orig-fn no-condition)
(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)))
;; Trim whitespace in selected region, so as not to introduce extra
;; whitespace into `yas-selected-text'.
(evil-visual-select (save-excursion
(goto-char evil-visual-beginning)
(skip-chars-forward " \t")
(point))
(save-excursion
(goto-char evil-visual-end)
(skip-chars-backward " \t")
(point))
'inclusive)
(letf! ((defun region-beginning () evil-visual-beginning)
(defun region-end () evil-visual-end))
(funcall orig-fn no-condition)))
(when (and (bound-and-true-p evil-local-mode)
(yas-active-snippets))

View File

@@ -5,9 +5,10 @@
;;
;; Packages
;;; Packages
(use-package! yasnippet
:defer-incrementally eldoc easymenu help-mode
:commands (yas-minor-mode-on
yas-expand
yas-expand-snippet
@@ -19,9 +20,11 @@
;; Remove default ~/.emacs.d/snippets
(defvar yas-snippet-dirs nil)
;; 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))
(unless (daemonp)
;; 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-hook
prog-mode-hook
@@ -30,24 +33,26 @@
#'yas-minor-mode-on)
:config
(setq yas-verbosity (if doom-debug-mode 3 0)
yas-also-auto-indent-first-line t)
(add-to-list 'load-path +snippets-dir)
;; default snippets library, if available
(require 'doom-snippets nil t)
;; Allow private snippets in DOOMDIR/snippets
(add-to-list 'yas-snippet-dirs '+snippets-dir)
;; In case `+snippets-dir' and `doom-snippets-dir' are the same
;; Reduce verbosity. 3 is too chatty about initializing yasnippet. 2 is just
;; right (only shows errors).
(setq yas-verbosity (if doom-debug-p 3 0))
;; default snippets library, if available
(add-to-list 'load-path +snippets-dir)
(require 'doom-snippets nil t)
;; HACK In case `+snippets-dir' and `doom-snippets-dir' are the same, or
;; duplicates exist in `yas-snippet-dirs'.
(advice-add #'yas-snippet-dirs :filter-return #'delete-dups)
;; Remove GUI dropdown prompt (prefer ivy/helm)
(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)
(add-to-list 'yas-prompt-functions #'+snippets-prompt-private)
;; Register `def-project-mode!' modes with yasnippet. This enables project
;; specific snippet libraries (e.g. for Laravel, React or Jekyll projects).
@@ -60,22 +65,14 @@
;; tell smartparens overlays not to interfere with yasnippet keybinds
(advice-add #'yas-expand :before #'sp-remove-active-pair-overlay))
;; Enable `read-only-mode' for built-in snippets (in `doom-local-dir')
(add-hook 'snippet-mode-hook #'+snippets-read-only-maybe-h)
;; (Evil only) fix off-by-one issue with line-wise visual selections in
;; `yas-insert-snippet', and switches to insert mode afterwards.
(advice-add #'yas-insert-snippet :around #'+snippets-expand-on-region-a)
(define-key! snippet-mode-map
"C-c C-k" #'+snippet--abort
"C-c C-e" #'+snippet--edit)
;; Show keybind hints in snippet header-line
(add-hook 'snippet-mode-hook #'+snippets-show-hints-in-header-line-h)
;; Replace commands with superior alternatives
(define-key! yas-minor-mode-map
[remap yas-new-snippet] #'+snippets/new
[remap yas-visit-snippet-file] #'+snippets/edit)
;; Enable `read-only-mode' for built-in snippets (in `doom-local-dir')
(add-hook 'snippet-mode-hook #'+snippets-read-only-maybe-h)
(map! :map yas-keymap
"C-e" #'+snippets/goto-end-of-field
@@ -84,7 +81,20 @@
[M-left] #'+snippets/goto-start-of-field
[M-backspace] #'+snippets/delete-to-start-of-field
[backspace] #'+snippets/delete-backward-char
[delete] #'+snippets/delete-forward-char-or-field))
[delete] #'+snippets/delete-forward-char-or-field
;; Replace commands with superior alternatives
:map yas-minor-mode-map
[remap yas-new-snippet] #'+snippets/new
[remap yas-visit-snippet-file] #'+snippets/edit)
;; REVIEW Fix #2639: For some reason `yas--all-templates' returns duplicates
;; of some templates. Until I figure out the real cause this fixes it.
(defadvice! +snippets--remove-duplicates-a (templates)
:filter-return #'yas--all-templates
(cl-delete-duplicates templates :test #'equal))
;; If in a daemon session, front-load this expensive work:
(if (daemonp) (yas-reload-all)))
(use-package! auto-yasnippet
@@ -96,6 +106,6 @@
us who use yas-minor-mode and enable yasnippet more selectively. This advice
swaps `yas-global-mode' with `yas-minor-mode'."
:around '(aya-expand aya-open-line)
(cl-letf (((symbol-function #'yas-global-mode) #'yas-minor-mode)
(yas-global-mode yas-minor-mode))
(letf! ((#'yas-global-mode #'yas-minor-mode)
(yas-global-mode yas-minor-mode))
(apply orig-fn args))))

View File

@@ -1,10 +1,10 @@
;; -*- no-byte-compile: t; -*-
;;; editor/snippets/packages.el
(package! yasnippet)
(package! auto-yasnippet)
(package! yasnippet :pin "5b1217ab085fab4abeb1118dccb260691b446703")
(package! auto-yasnippet :pin "db9e0dd4335b2202cd5dac95bbbc87a1032d9bbe")
(package! doom-snippets
:recipe (:host github
:repo "hlissner/doom-snippets"
:files ("*.el" "*")))
:files ("*.el" "*"))
:pin "422f683adfbec1b01fe00524690b64dc9e702ae0")