+ enable lexical-scope everywhere (lexical-binding = t): ~5-10% faster startup; ~5-20% general boost + reduce consing, function calls & garbage collection by preferring cl-loop & dolist over lambda closures (for mapc[ar], add-hook, and various cl-lib filter/map/reduce functions) -- where possible + prefer functions with dedicated opcodes, like assq (see byte-defop's in bytecomp.el for more) + prefer pcase & cond (faster) over cl-case + general refactor for code readability + ensure naming & style conventions are adhered to + appease byte-compiler by marking unused variables with underscore + defer minor mode activation to after-init, emacs-startup or window-setup hooks; a customization opportunity for users + ensures custom functionality won't interfere with startup.
59 lines
2.4 KiB
EmacsLisp
59 lines
2.4 KiB
EmacsLisp
;;; feature/snippets/autoload/snippets.el -*- lexical-binding: t; -*-
|
|
|
|
;;;###autoload
|
|
(defun +snippets/goto-start-of-field ()
|
|
"Go to the beginning of the current field."
|
|
(interactive)
|
|
(let* ((snippet (car (yas-active-snippets)))
|
|
(position (yas--field-start (yas--snippet-active-field snippet))))
|
|
(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)))
|
|
(position (yas--field-end (yas--snippet-active-field snippet))))
|
|
(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 yas--active-field-overlay
|
|
(overlay-buffer yas--active-field-overlay)
|
|
(overlay-get yas--active-field-overlay 'yas--field)))))
|
|
(cond ((eq (point) (marker-position (yas--field-start field))) nil)
|
|
(t (delete-char -1)))))
|
|
|
|
;;;###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 ((and field
|
|
(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)
|
|
(t (delete-char 1)))))
|
|
|
|
;;;###autoload
|
|
(defun +snippets/delete-to-start-of-field (&optional field)
|
|
"Delete to start-of-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))))
|
|
(sof (marker-position (yas--field-start field))))
|
|
(when (and field (> (point) sof))
|
|
(delete-region sof (point)))))
|
|
|