diff options
| author | Simeon Simeonov | 2016-02-17 07:39:51 +0100 |
|---|---|---|
| committer | Simeon Simeonov | 2016-02-17 07:39:51 +0100 |
| commit | 481decd28b7940d1dae11fd0ff2dc06143c46ee8 (patch) | |
| tree | fca07ee06cf69f62776d74cc03087f8c71401ad5 /.emacs.d/lisp/yasnippet.el | |
| parent | 905ddda312c1535909c64bb261d4cf2a3edcb8ae (diff) | |
Add java-mode snippets. Upgrade yasnippet and yaml-mode
Diffstat (limited to '.emacs.d/lisp/yasnippet.el')
| -rw-r--r-- | .emacs.d/lisp/yasnippet.el | 180 |
1 files changed, 89 insertions, 91 deletions
diff --git a/.emacs.d/lisp/yasnippet.el b/.emacs.d/lisp/yasnippet.el index f13dc4f..69d6b26 100644 --- a/.emacs.d/lisp/yasnippet.el +++ b/.emacs.d/lisp/yasnippet.el | |||
| @@ -1,8 +1,8 @@ | |||
| 1 | ;;; yasnippet.el --- Yet another snippet extension for Emacs. | 1 | ;;; yasnippet.el --- Yet another snippet extension for Emacs. |
| 2 | 2 | ||
| 3 | ;; Copyright (C) 2008-2013, 2015 Free Software Foundation, Inc. | 3 | ;; Copyright (C) 2008-2013, 2015 Free Software Foundation, Inc. |
| 4 | ;; Authors: pluskid <pluskid@gmail.com>, João Távora <joaotavora@gmail.com> | 4 | ;; Authors: pluskid <pluskid@gmail.com>, João Távora <joaotavora@gmail.com>, Noam Postavsky <npostavs@gmail.com> |
| 5 | ;; Maintainer: João Távora <joaotavora@gmail.com> | 5 | ;; Maintainer: Noam Postavsky <npostavs@gmail.com> |
| 6 | ;; Version: 0.8.1 | 6 | ;; Version: 0.8.1 |
| 7 | ;; Package-version: 0.8.0 | 7 | ;; Package-version: 0.8.0 |
| 8 | ;; X-URL: http://github.com/capitaomorte/yasnippet | 8 | ;; X-URL: http://github.com/capitaomorte/yasnippet |
| @@ -156,8 +156,11 @@ | |||
| 156 | (when load-file-name | 156 | (when load-file-name |
| 157 | (concat (file-name-directory load-file-name) "snippets"))) | 157 | (concat (file-name-directory load-file-name) "snippets"))) |
| 158 | 158 | ||
| 159 | (defconst yas--default-user-snippets-dir | ||
| 160 | (concat user-emacs-directory "snippets")) | ||
| 161 | |||
| 159 | (defcustom yas-snippet-dirs (remove nil | 162 | (defcustom yas-snippet-dirs (remove nil |
| 160 | (list "~/.emacs.d/snippets" | 163 | (list yas--default-user-snippets-dir |
| 161 | 'yas-installed-snippets-dir)) | 164 | 'yas-installed-snippets-dir)) |
| 162 | "List of top-level snippet directories. | 165 | "List of top-level snippet directories. |
| 163 | 166 | ||
| @@ -199,10 +202,9 @@ created with `yas-new-snippet'. " | |||
| 199 | (defvaralias 'yas/root-directory 'yas-snippet-dirs) | 202 | (defvaralias 'yas/root-directory 'yas-snippet-dirs) |
| 200 | 203 | ||
| 201 | (defcustom yas-new-snippet-default "\ | 204 | (defcustom yas-new-snippet-default "\ |
| 202 | # -*- mode: snippet; require-final-newline: nil -*- | 205 | # -*- mode: snippet -*- |
| 203 | # name: $1 | 206 | # name: $1 |
| 204 | # key: ${2:${1:$(yas--key-from-desc yas-text)}}${3: | 207 | # key: ${2:${1:$(yas--key-from-desc yas-text)}} |
| 205 | # binding: ${4:direct-keybinding}} | ||
| 206 | # -- | 208 | # -- |
| 207 | $0" | 209 | $0" |
| 208 | "Default snippet to use when creating a new snippet. | 210 | "Default snippet to use when creating a new snippet. |
| @@ -210,10 +212,9 @@ If nil, don't use any snippet." | |||
| 210 | :type 'string | 212 | :type 'string |
| 211 | :group 'yasnippet) | 213 | :group 'yasnippet) |
| 212 | 214 | ||
| 213 | (defcustom yas-prompt-functions '(yas-x-prompt | 215 | (defcustom yas-prompt-functions '(yas-dropdown-prompt |
| 214 | yas-dropdown-prompt | ||
| 215 | yas-completing-prompt | 216 | yas-completing-prompt |
| 216 | yas-ido-prompt | 217 | yas-maybe-ido-prompt |
| 217 | yas-no-prompt) | 218 | yas-no-prompt) |
| 218 | "Functions to prompt for keys, templates, etc interactively. | 219 | "Functions to prompt for keys, templates, etc interactively. |
| 219 | 220 | ||
| @@ -459,10 +460,10 @@ Attention: These hooks are not run when exiting nested/stacked snippet expansion | |||
| 459 | "Hooks to run just before expanding a snippet.") | 460 | "Hooks to run just before expanding a snippet.") |
| 460 | 461 | ||
| 461 | (defvar yas-buffer-local-condition | 462 | (defvar yas-buffer-local-condition |
| 462 | '(if (and (or (fourth (syntax-ppss)) | 463 | '(if (and (let ((ppss (syntax-ppss))) |
| 463 | (fifth (syntax-ppss))) | 464 | (or (nth 3 ppss) (nth 4 ppss))) |
| 464 | this-command | 465 | (memq this-command '(yas-expand yas-expand-from-trigger-key |
| 465 | (eq this-command 'yas-expand-from-trigger-key)) | 466 | yas-expand-from-keymap))) |
| 466 | '(require-snippet-condition . force-in-comment) | 467 | '(require-snippet-condition . force-in-comment) |
| 467 | t) | 468 | t) |
| 468 | "Snippet expanding condition. | 469 | "Snippet expanding condition. |
| @@ -728,22 +729,21 @@ defined direct keybindings to the command | |||
| 728 | (defun yas--modes-to-activate (&optional mode) | 729 | (defun yas--modes-to-activate (&optional mode) |
| 729 | "Compute list of mode symbols that are active for `yas-expand' | 730 | "Compute list of mode symbols that are active for `yas-expand' |
| 730 | and friends." | 731 | and friends." |
| 731 | (let (dfs explored) | 732 | (let* ((explored (if mode (list mode) ; Building up list in reverse. |
| 732 | (setq dfs (lambda (mode) | 733 | (cons major-mode (reverse yas--extra-modes)))) |
| 733 | (unless (memq mode explored) | 734 | (dfs |
| 734 | (push mode explored) | 735 | (lambda (mode) |
| 735 | (loop for neighbour | 736 | (cl-loop for neighbour |
| 736 | in (cl-list* (get mode 'derived-mode-parent) | 737 | in (cl-list* (get mode 'derived-mode-parent) |
| 737 | (ignore-errors (symbol-function mode)) | 738 | (ignore-errors (symbol-function mode)) |
| 738 | (gethash mode yas--parents)) | 739 | (gethash mode yas--parents)) |
| 739 | when (and neighbour | 740 | when (and neighbour |
| 740 | (not (memq neighbour explored)) | 741 | (not (memq neighbour explored)) |
| 741 | (symbolp neighbour)) | 742 | (symbolp neighbour)) |
| 742 | do (funcall dfs neighbour))))) | 743 | do (push neighbour explored) |
| 743 | (if mode | 744 | (funcall dfs neighbour))))) |
| 744 | (funcall dfs mode) | 745 | (mapcar dfs explored) |
| 745 | (mapcar dfs (cons major-mode yas--extra-modes))) | 746 | (nreverse explored))) |
| 746 | explored)) | ||
| 747 | 747 | ||
| 748 | (defvar yas-minor-mode-hook nil | 748 | (defvar yas-minor-mode-hook nil |
| 749 | "Hook run when `yas-minor-mode' is turned on.") | 749 | "Hook run when `yas-minor-mode' is turned on.") |
| @@ -1388,16 +1388,6 @@ them all in `yas--menu-table'" | |||
| 1388 | :visible (yas--show-menu-p ',mode))) | 1388 | :visible (yas--show-menu-p ',mode))) |
| 1389 | menu-keymap)) | 1389 | menu-keymap)) |
| 1390 | 1390 | ||
| 1391 | |||
| 1392 | (defmacro yas--called-interactively-p (&optional kind) | ||
| 1393 | "A backward-compatible version of `called-interactively-p'. | ||
| 1394 | |||
| 1395 | Optional KIND is as documented at `called-interactively-p' | ||
| 1396 | in GNU Emacs 24.1 or higher." | ||
| 1397 | (if (string< emacs-version "24.1") | ||
| 1398 | '(called-interactively-p) | ||
| 1399 | `(called-interactively-p ,kind))) | ||
| 1400 | |||
| 1401 | 1391 | ||
| 1402 | ;;; Template-related and snippet loading functions | 1392 | ;;; Template-related and snippet loading functions |
| 1403 | 1393 | ||
| @@ -1449,7 +1439,7 @@ Here's a list of currently recognized directives: | |||
| 1449 | (point-max))) | 1439 | (point-max))) |
| 1450 | (setq bound (point)) | 1440 | (setq bound (point)) |
| 1451 | (goto-char (point-min)) | 1441 | (goto-char (point-min)) |
| 1452 | (while (re-search-forward "^# *\\([^ ]+?\\) *: *\\(.*\\)$" bound t) | 1442 | (while (re-search-forward "^# *\\([^ ]+?\\) *: *\\(.*?\\)[[:space:]]*$" bound t) |
| 1453 | (when (string= "uuid" (match-string-no-properties 1)) | 1443 | (when (string= "uuid" (match-string-no-properties 1)) |
| 1454 | (setq uuid (match-string-no-properties 2))) | 1444 | (setq uuid (match-string-no-properties 2))) |
| 1455 | (when (string= "type" (match-string-no-properties 1)) | 1445 | (when (string= "type" (match-string-no-properties 1)) |
| @@ -1593,11 +1583,13 @@ Optional PROMPT sets the prompt to use." | |||
| 1593 | (if display-fn (mapcar display-fn choices) choices))))) | 1583 | (if display-fn (mapcar display-fn choices) choices))))) |
| 1594 | (keyboard-quit)))) | 1584 | (keyboard-quit)))) |
| 1595 | 1585 | ||
| 1586 | (defun yas-maybe-ido-prompt (prompt choices &optional display-fn) | ||
| 1587 | (when (bound-and-true-p ido-mode) | ||
| 1588 | (yas-ido-prompt prompt choices display-fn))) | ||
| 1589 | |||
| 1596 | (defun yas-ido-prompt (prompt choices &optional display-fn) | 1590 | (defun yas-ido-prompt (prompt choices &optional display-fn) |
| 1597 | (when (and (fboundp 'ido-completing-read) | 1591 | (require 'ido) |
| 1598 | (or (>= emacs-major-version 24) | 1592 | (yas-completing-prompt prompt choices display-fn #'ido-completing-read)) |
| 1599 | ido-mode)) | ||
| 1600 | (yas-completing-prompt prompt choices display-fn #'ido-completing-read))) | ||
| 1601 | 1593 | ||
| 1602 | (defun yas-dropdown-prompt (_prompt choices &optional display-fn) | 1594 | (defun yas-dropdown-prompt (_prompt choices &optional display-fn) |
| 1603 | (when (fboundp 'dropdown-list) | 1595 | (when (fboundp 'dropdown-list) |
| @@ -1751,8 +1743,8 @@ With prefix argument USE-JIT do jit-loading of snippets." | |||
| 1751 | (funcall fun))) | 1743 | (funcall fun))) |
| 1752 | ;; Look for buffers that are already in `mode-sym', and so | 1744 | ;; Look for buffers that are already in `mode-sym', and so |
| 1753 | ;; need the new snippets immediately... | 1745 | ;; need the new snippets immediately... |
| 1754 | ;; | 1746 | ;; |
| 1755 | (when use-jit | 1747 | (when use-jit |
| 1756 | (cl-loop for buffer in (buffer-list) | 1748 | (cl-loop for buffer in (buffer-list) |
| 1757 | do (with-current-buffer buffer | 1749 | do (with-current-buffer buffer |
| 1758 | (when (eq major-mode mode-sym) | 1750 | (when (eq major-mode mode-sym) |
| @@ -1760,7 +1752,7 @@ With prefix argument USE-JIT do jit-loading of snippets." | |||
| 1760 | (push buffer impatient-buffers))))))) | 1752 | (push buffer impatient-buffers))))))) |
| 1761 | ;; ...after TOP-LEVEL-DIR has been completely loaded, call | 1753 | ;; ...after TOP-LEVEL-DIR has been completely loaded, call |
| 1762 | ;; `yas--load-pending-jits' in these impatient buffers. | 1754 | ;; `yas--load-pending-jits' in these impatient buffers. |
| 1763 | ;; | 1755 | ;; |
| 1764 | (cl-loop for buffer in impatient-buffers | 1756 | (cl-loop for buffer in impatient-buffers |
| 1765 | do (with-current-buffer buffer (yas--load-pending-jits)))) | 1757 | do (with-current-buffer buffer (yas--load-pending-jits)))) |
| 1766 | (when interactive | 1758 | (when interactive |
| @@ -1779,9 +1771,9 @@ With prefix argument USE-JIT do jit-loading of snippets." | |||
| 1779 | (current-time-string))))) | 1771 | (current-time-string))))) |
| 1780 | ;; Normal case. | 1772 | ;; Normal case. |
| 1781 | (unless (file-exists-p (concat directory "/" ".yas-skip")) | 1773 | (unless (file-exists-p (concat directory "/" ".yas-skip")) |
| 1782 | (if (and (progn (yas--message 2 "Loading compiled snippets from %s" directory) t) | 1774 | (unless (and (load (expand-file-name ".yas-compiled-snippets" directory) 'noerror (<= yas-verbosity 3)) |
| 1783 | (load (expand-file-name ".yas-compiled-snippets" directory) 'noerror (<= yas-verbosity 3))) | 1775 | (progn (yas--message 2 "Loaded compiled snippets from %s" directory) t)) |
| 1784 | (yas--message 2 "Loading snippet files from %s" directory) | 1776 | (yas--message 2 "Loading snippet files from %s" directory) |
| 1785 | (yas--load-directory-2 directory mode-sym))))) | 1777 | (yas--load-directory-2 directory mode-sym))))) |
| 1786 | 1778 | ||
| 1787 | (defun yas--load-directory-2 (directory mode-sym) | 1779 | (defun yas--load-directory-2 (directory mode-sym) |
| @@ -1811,16 +1803,18 @@ With prefix argument USE-JIT do jit-loading of snippets." | |||
| 1811 | "Reload the directories listed in `yas-snippet-dirs' or | 1803 | "Reload the directories listed in `yas-snippet-dirs' or |
| 1812 | prompt the user to select one." | 1804 | prompt the user to select one." |
| 1813 | (let (errors) | 1805 | (let (errors) |
| 1814 | (if yas-snippet-dirs | 1806 | (if (null yas-snippet-dirs) |
| 1815 | (dolist (directory (reverse (yas-snippet-dirs))) | 1807 | (call-interactively 'yas-load-directory) |
| 1816 | (cond ((file-directory-p directory) | 1808 | (when (member yas--default-user-snippets-dir yas-snippet-dirs) |
| 1817 | (yas-load-directory directory (not nojit)) | 1809 | (make-directory yas--default-user-snippets-dir t)) |
| 1818 | (if nojit | 1810 | (dolist (directory (reverse (yas-snippet-dirs))) |
| 1819 | (yas--message 3 "Loaded %s" directory) | 1811 | (cond ((file-directory-p directory) |
| 1820 | (yas--message 3 "Prepared just-in-time loading for %s" directory))) | 1812 | (yas-load-directory directory (not nojit)) |
| 1821 | (t | 1813 | (if nojit |
| 1822 | (push (yas--message 0 "Check your `yas-snippet-dirs': %s is not a directory" directory) errors)))) | 1814 | (yas--message 3 "Loaded %s" directory) |
| 1823 | (call-interactively 'yas-load-directory)) | 1815 | (yas--message 3 "Prepared just-in-time loading for %s" directory))) |
| 1816 | (t | ||
| 1817 | (push (yas--message 0 "Check your `yas-snippet-dirs': %s is not a directory" directory) errors))))) | ||
| 1824 | errors)) | 1818 | errors)) |
| 1825 | 1819 | ||
| 1826 | (defun yas-reload-all (&optional no-jit interactive) | 1820 | (defun yas-reload-all (&optional no-jit interactive) |
| @@ -1946,7 +1940,7 @@ This works by stubbing a few functions, then calling | |||
| 1946 | (interactive) | 1940 | (interactive) |
| 1947 | (message (concat "yasnippet (version " | 1941 | (message (concat "yasnippet (version " |
| 1948 | yas--version | 1942 | yas--version |
| 1949 | ") -- pluskid <pluskid@gmail.com>/joaotavora <joaotavora@gmail.com>"))) | 1943 | ") -- pluskid/joaotavora/npostavs"))) |
| 1950 | 1944 | ||
| 1951 | 1945 | ||
| 1952 | ;;; Apropos snippet menu: | 1946 | ;;; Apropos snippet menu: |
| @@ -2226,12 +2220,12 @@ Common gateway for `yas-expand-from-trigger-key' and | |||
| 2226 | ;; loops when other extensions use mechanisms similar | 2220 | ;; loops when other extensions use mechanisms similar |
| 2227 | ;; to `yas--keybinding-beyond-yasnippet'. (github #525 | 2221 | ;; to `yas--keybinding-beyond-yasnippet'. (github #525 |
| 2228 | ;; and #526) | 2222 | ;; and #526) |
| 2229 | ;; | 2223 | ;; |
| 2230 | (yas-minor-mode nil) | 2224 | (yas-minor-mode nil) |
| 2231 | (beyond-yasnippet (yas--keybinding-beyond-yasnippet))) | 2225 | (beyond-yasnippet (yas--keybinding-beyond-yasnippet))) |
| 2232 | (yas--message 4 "Falling back to %s" beyond-yasnippet) | 2226 | (yas--message 4 "Falling back to %s" beyond-yasnippet) |
| 2233 | (assert (or (null beyond-yasnippet) (commandp beyond-yasnippet))) | 2227 | (assert (or (null beyond-yasnippet) (commandp beyond-yasnippet))) |
| 2234 | (setq this-original-command beyond-yasnippet) | 2228 | (setq this-command beyond-yasnippet) |
| 2235 | (when beyond-yasnippet | 2229 | (when beyond-yasnippet |
| 2236 | (call-interactively beyond-yasnippet)))) | 2230 | (call-interactively beyond-yasnippet)))) |
| 2237 | ((and (listp yas-fallback-behavior) | 2231 | ((and (listp yas-fallback-behavior) |
| @@ -2359,7 +2353,6 @@ visited file in `snippet-mode'." | |||
| 2359 | (interactive) | 2353 | (interactive) |
| 2360 | (let* ((yas-buffer-local-condition 'always) | 2354 | (let* ((yas-buffer-local-condition 'always) |
| 2361 | (templates (yas--all-templates (yas--get-snippet-tables))) | 2355 | (templates (yas--all-templates (yas--get-snippet-tables))) |
| 2362 | (yas-prompt-functions '(yas-ido-prompt yas-completing-prompt)) | ||
| 2363 | (template (and templates | 2356 | (template (and templates |
| 2364 | (or (yas--prompt-for-template templates | 2357 | (or (yas--prompt-for-template templates |
| 2365 | "Choose a snippet template to edit: ") | 2358 | "Choose a snippet template to edit: ") |
| @@ -2417,7 +2410,7 @@ where snippets of table might exist." | |||
| 2417 | (let ((main-dir (replace-regexp-in-string | 2410 | (let ((main-dir (replace-regexp-in-string |
| 2418 | "/+$" "" | 2411 | "/+$" "" |
| 2419 | (or (first (or (yas-snippet-dirs) | 2412 | (or (first (or (yas-snippet-dirs) |
| 2420 | (setq yas-snippet-dirs '("~/.emacs.d/snippets"))))))) | 2413 | (setq yas-snippet-dirs (list yas--default-user-snippets-dir))))))) |
| 2421 | (tables (or (and table | 2414 | (tables (or (and table |
| 2422 | (list table)) | 2415 | (list table)) |
| 2423 | (yas--get-snippet-tables)))) | 2416 | (yas--get-snippet-tables)))) |
| @@ -3042,11 +3035,11 @@ through the field's start point" | |||
| 3042 | 3035 | ||
| 3043 | The most recently-inserted snippets are returned first." | 3036 | The most recently-inserted snippets are returned first." |
| 3044 | (sort | 3037 | (sort |
| 3045 | (remove nil (remove-duplicates (mapcar #'(lambda (ov) | 3038 | (delq nil (delete-dups |
| 3046 | (overlay-get ov 'yas--snippet)) | 3039 | (mapcar (lambda (ov) (overlay-get ov 'yas--snippet)) |
| 3047 | (if all-snippets | 3040 | (if all-snippets (overlays-in (point-min) (point-max)) |
| 3048 | (overlays-in (point-min) (point-max)) | 3041 | (nconc (overlays-at (point)) |
| 3049 | (nconc (overlays-at (point)) (overlays-at (1- (point)))))))) | 3042 | (overlays-at (1- (point)))))))) |
| 3050 | #'(lambda (s1 s2) | 3043 | #'(lambda (s1 s2) |
| 3051 | (<= (yas--snippet-id s2) (yas--snippet-id s1))))) | 3044 | (<= (yas--snippet-id s2) (yas--snippet-id s1))))) |
| 3052 | 3045 | ||
| @@ -3159,12 +3152,6 @@ Also create some protection overlays" | |||
| 3159 | (defvar yas--inhibit-overlay-hooks nil | 3152 | (defvar yas--inhibit-overlay-hooks nil |
| 3160 | "Bind this temporarily to non-nil to prevent running `yas--on-*-modification'.") | 3153 | "Bind this temporarily to non-nil to prevent running `yas--on-*-modification'.") |
| 3161 | 3154 | ||
| 3162 | (defmacro yas--inhibit-overlay-hooks (&rest body) | ||
| 3163 | "Run BODY with `yas--inhibit-overlay-hooks' set to t." | ||
| 3164 | (declare (indent 0)) | ||
| 3165 | `(let ((yas--inhibit-overlay-hooks t)) | ||
| 3166 | ,@body)) | ||
| 3167 | |||
| 3168 | (defvar yas-snippet-beg nil "Beginning position of the last snippet committed.") | 3155 | (defvar yas-snippet-beg nil "Beginning position of the last snippet committed.") |
| 3169 | (defvar yas-snippet-end nil "End position of the last snippet committed.") | 3156 | (defvar yas-snippet-end nil "End position of the last snippet committed.") |
| 3170 | 3157 | ||
| @@ -3184,7 +3171,7 @@ This renders the snippet as ordinary text." | |||
| 3184 | (setq yas-snippet-end (overlay-end control-overlay)) | 3171 | (setq yas-snippet-end (overlay-end control-overlay)) |
| 3185 | (delete-overlay control-overlay)) | 3172 | (delete-overlay control-overlay)) |
| 3186 | 3173 | ||
| 3187 | (yas--inhibit-overlay-hooks | 3174 | (let ((yas--inhibit-overlay-hooks t)) |
| 3188 | (when yas--active-field-overlay | 3175 | (when yas--active-field-overlay |
| 3189 | (delete-overlay yas--active-field-overlay)) | 3176 | (delete-overlay yas--active-field-overlay)) |
| 3190 | (when yas--field-protection-overlays | 3177 | (when yas--field-protection-overlays |
| @@ -3396,13 +3383,28 @@ Move the overlay, or create it if it does not exit." | |||
| 3396 | (overlay-put yas--active-field-overlay 'insert-behind-hooks | 3383 | (overlay-put yas--active-field-overlay 'insert-behind-hooks |
| 3397 | '(yas--on-field-overlay-modification)))) | 3384 | '(yas--on-field-overlay-modification)))) |
| 3398 | 3385 | ||
| 3399 | (defun yas--on-field-overlay-modification (overlay after? _beg _end &optional _length) | 3386 | (defun yas--skip-and-clear-field-p (field _beg _end &optional _length) |
| 3387 | "Tell if newly modified FIELD should be cleared and skipped. | ||
| 3388 | BEG, END and LENGTH like overlay modification hooks." | ||
| 3389 | (and (not (yas--field-modified-p field)) | ||
| 3390 | (= (point) (yas--field-start field)) | ||
| 3391 | (require 'delsel) | ||
| 3392 | ;; `yank' sets `this-command' to t during execution. | ||
| 3393 | (let ((clearp (get (if (commandp this-command) this-command | ||
| 3394 | this-original-command) | ||
| 3395 | 'delete-selection))) | ||
| 3396 | (when (and (not (memq clearp '(yank supersede kill))) | ||
| 3397 | (functionp clearp)) | ||
| 3398 | (setq clearp (funcall clearp))) | ||
| 3399 | clearp))) | ||
| 3400 | |||
| 3401 | (defun yas--on-field-overlay-modification (overlay after? beg end &optional length) | ||
| 3400 | "Clears the field and updates mirrors, conditionally. | 3402 | "Clears the field and updates mirrors, conditionally. |
| 3401 | 3403 | ||
| 3402 | Only clears the field if it hasn't been modified and it point it | 3404 | Only clears the field if it hasn't been modified and point is at |
| 3403 | at field start. This hook doesn't do anything if an undo is in | 3405 | field start. This hook does nothing if an undo is in progress." |
| 3404 | progress." | ||
| 3405 | (unless (or yas--inhibit-overlay-hooks | 3406 | (unless (or yas--inhibit-overlay-hooks |
| 3407 | (not (overlayp yas--active-field-overlay)) ; Avoid Emacs bug #21824. | ||
| 3406 | (yas--undo-in-progress)) | 3408 | (yas--undo-in-progress)) |
| 3407 | (let* ((field (overlay-get overlay 'yas--field)) | 3409 | (let* ((field (overlay-get overlay 'yas--field)) |
| 3408 | (snippet (overlay-get yas--active-field-overlay 'yas--snippet))) | 3410 | (snippet (overlay-get yas--active-field-overlay 'yas--snippet))) |
| @@ -3412,11 +3414,7 @@ progress." | |||
| 3412 | (yas--field-update-display field)) | 3414 | (yas--field-update-display field)) |
| 3413 | (yas--update-mirrors snippet)) | 3415 | (yas--update-mirrors snippet)) |
| 3414 | (field | 3416 | (field |
| 3415 | (when (and (not after?) | 3417 | (when (yas--skip-and-clear-field-p field beg end) |
| 3416 | (not (yas--field-modified-p field)) | ||
| 3417 | (eq (point) (if (markerp (yas--field-start field)) | ||
| 3418 | (marker-position (yas--field-start field)) | ||
| 3419 | (yas--field-start field)))) | ||
| 3420 | (yas--skip-and-clear field)) | 3418 | (yas--skip-and-clear field)) |
| 3421 | (setf (yas--field-modified-p field) t)))))) | 3419 | (setf (yas--field-modified-p field) t)))))) |
| 3422 | 3420 | ||
| @@ -3429,7 +3427,7 @@ progress." | |||
| 3429 | ;; As of github #537 this no longer inhibits the command by issuing an | 3427 | ;; As of github #537 this no longer inhibits the command by issuing an |
| 3430 | ;; error: all the snippets at point, including nested snippets, are | 3428 | ;; error: all the snippets at point, including nested snippets, are |
| 3431 | ;; automatically commited and the current command can proceed. | 3429 | ;; automatically commited and the current command can proceed. |
| 3432 | ;; | 3430 | ;; |
| 3433 | (defun yas--make-move-field-protection-overlays (snippet field) | 3431 | (defun yas--make-move-field-protection-overlays (snippet field) |
| 3434 | "Place protection overlays surrounding SNIPPET's FIELD. | 3432 | "Place protection overlays surrounding SNIPPET's FIELD. |
| 3435 | 3433 | ||
| @@ -3443,7 +3441,7 @@ Move the overlays, or create them if they do not exit." | |||
| 3443 | ;; | 3441 | ;; |
| 3444 | (when (< (buffer-size) end) | 3442 | (when (< (buffer-size) end) |
| 3445 | (save-excursion | 3443 | (save-excursion |
| 3446 | (yas--inhibit-overlay-hooks | 3444 | (let ((yas--inhibit-overlay-hooks t)) |
| 3447 | (goto-char (point-max)) | 3445 | (goto-char (point-max)) |
| 3448 | (newline)))) | 3446 | (newline)))) |
| 3449 | ;; go on to normal overlay creation/moving | 3447 | ;; go on to normal overlay creation/moving |
| @@ -3559,7 +3557,7 @@ considered when expanding the snippet." | |||
| 3559 | ;; them mostly to make the undo information | 3557 | ;; them mostly to make the undo information |
| 3560 | ;; | 3558 | ;; |
| 3561 | (setq yas--start-column (current-column)) | 3559 | (setq yas--start-column (current-column)) |
| 3562 | (yas--inhibit-overlay-hooks | 3560 | (let ((yas--inhibit-overlay-hooks t)) |
| 3563 | (setq snippet | 3561 | (setq snippet |
| 3564 | (if expand-env | 3562 | (if expand-env |
| 3565 | (eval `(let* ,expand-env | 3563 | (eval `(let* ,expand-env |
| @@ -4241,7 +4239,7 @@ When multiple expressions are found, only the last one counts." | |||
| 4241 | (not (string= reflection (buffer-substring-no-properties (yas--mirror-start mirror) | 4239 | (not (string= reflection (buffer-substring-no-properties (yas--mirror-start mirror) |
| 4242 | (yas--mirror-end mirror))))) | 4240 | (yas--mirror-end mirror))))) |
| 4243 | (goto-char (yas--mirror-start mirror)) | 4241 | (goto-char (yas--mirror-start mirror)) |
| 4244 | (yas--inhibit-overlay-hooks | 4242 | (let ((yas--inhibit-overlay-hooks t)) |
| 4245 | (insert reflection)) | 4243 | (insert reflection)) |
| 4246 | (if (> (yas--mirror-end mirror) (point)) | 4244 | (if (> (yas--mirror-end mirror) (point)) |
| 4247 | (delete-region (point) (yas--mirror-end mirror)) | 4245 | (delete-region (point) (yas--mirror-end mirror)) |
| @@ -4260,7 +4258,7 @@ When multiple expressions are found, only the last one counts." | |||
| 4260 | (yas--field-end field))))) | 4258 | (yas--field-end field))))) |
| 4261 | (setf (yas--field-modified-p field) t) | 4259 | (setf (yas--field-modified-p field) t) |
| 4262 | (goto-char (yas--field-start field)) | 4260 | (goto-char (yas--field-start field)) |
| 4263 | (yas--inhibit-overlay-hooks | 4261 | (let ((yas--inhibit-overlay-hooks t)) |
| 4264 | (insert transformed) | 4262 | (insert transformed) |
| 4265 | (if (> (yas--field-end field) (point)) | 4263 | (if (> (yas--field-end field) (point)) |
| 4266 | (delete-region (point) (yas--field-end field)) | 4264 | (delete-region (point) (yas--field-end field)) |
