diff options
| -rw-r--r-- | .emacs.d/lisp/php-mode.el | 142 | ||||
| -rw-r--r-- | .emacs.d/lisp/yaml-mode.el | 4 | ||||
| -rw-r--r-- | .emacs.d/lisp/yasnippet.el | 558 |
3 files changed, 348 insertions, 356 deletions
diff --git a/.emacs.d/lisp/php-mode.el b/.emacs.d/lisp/php-mode.el index 6979e8c..a7c1985 100644 --- a/.emacs.d/lisp/php-mode.el +++ b/.emacs.d/lisp/php-mode.el | |||
| @@ -2,16 +2,17 @@ | |||
| 2 | 2 | ||
| 3 | ;; Copyright (C) 1999, 2000, 2001, 2003, 2004 Turadg Aleahmad | 3 | ;; Copyright (C) 1999, 2000, 2001, 2003, 2004 Turadg Aleahmad |
| 4 | ;; 2008 Aaron S. Hawley | 4 | ;; 2008 Aaron S. Hawley |
| 5 | ;; 2011, 2012, 2013, 2014, 2015 Eric James Michael Ritz | 5 | ;; 2011, 2012, 2013, 2014, 2015, 2016 Eric James Michael Ritz |
| 6 | 6 | ||
| 7 | ;;; Author: Eric James Michael Ritz | 7 | ;; Author: Eric James Michael Ritz |
| 8 | ;;; URL: https://github.com/ejmr/php-mode | 8 | ;; URL: https://github.com/ejmr/php-mode |
| 9 | ;;; Version: 1.17.0 | 9 | ;; Version: 1.17.0 |
| 10 | ;; Package-Requires: ((emacs "24") (cl-lib "0.5")) | ||
| 10 | 11 | ||
| 11 | (defconst php-mode-version-number "1.17.0" | 12 | (defconst php-mode-version-number "1.17.0" |
| 12 | "PHP Mode version number.") | 13 | "PHP Mode version number.") |
| 13 | 14 | ||
| 14 | (defconst php-mode-modified "2015-10-02" | 15 | (defconst php-mode-modified "2016-03-06" |
| 15 | "PHP Mode build date.") | 16 | "PHP Mode build date.") |
| 16 | 17 | ||
| 17 | ;;; License | 18 | ;;; License |
| @@ -78,9 +79,10 @@ | |||
| 78 | (require 'flymake) | 79 | (require 'flymake) |
| 79 | (require 'etags) | 80 | (require 'etags) |
| 80 | (require 'speedbar) | 81 | (require 'speedbar) |
| 82 | |||
| 83 | (require 'cl-lib) | ||
| 84 | |||
| 81 | (eval-when-compile | 85 | (eval-when-compile |
| 82 | (unless (require 'cl-lib nil t) | ||
| 83 | (require 'cl)) | ||
| 84 | (require 'regexp-opt) | 86 | (require 'regexp-opt) |
| 85 | (defvar c-vsemi-status-unknown-p) | 87 | (defvar c-vsemi-status-unknown-p) |
| 86 | (defvar syntax-propertize-via-font-lock)) | 88 | (defvar syntax-propertize-via-font-lock)) |
| @@ -91,12 +93,6 @@ | |||
| 91 | (if (and (= emacs-major-version 24) (>= emacs-minor-version 4)) | 93 | (if (and (= emacs-major-version 24) (>= emacs-minor-version 4)) |
| 92 | (require 'cl))) | 94 | (require 'cl))) |
| 93 | 95 | ||
| 94 | ;; Use the recommended cl functions in php-mode but alias them to the | ||
| 95 | ;; old names when we detect emacs < 24.3 | ||
| 96 | (if (and (= emacs-major-version 24) (< emacs-minor-version 3)) | ||
| 97 | (unless (fboundp 'cl-set-difference) | ||
| 98 | (defalias 'cl-set-difference 'set-difference))) | ||
| 99 | |||
| 100 | 96 | ||
| 101 | ;; Local variables | 97 | ;; Local variables |
| 102 | ;;;###autoload | 98 | ;;;###autoload |
| @@ -110,13 +106,11 @@ | |||
| 110 | (defcustom php-executable (or (executable-find "php") | 106 | (defcustom php-executable (or (executable-find "php") |
| 111 | "/usr/bin/php") | 107 | "/usr/bin/php") |
| 112 | "The location of the PHP executable." | 108 | "The location of the PHP executable." |
| 113 | :type 'string | 109 | :type 'string) |
| 114 | :group 'php) | ||
| 115 | 110 | ||
| 116 | (defcustom php-default-face 'default | 111 | (defcustom php-default-face 'default |
| 117 | "Default face in `php-mode' buffers." | 112 | "Default face in `php-mode' buffers." |
| 118 | :type 'face | 113 | :type 'face) |
| 119 | :group 'php) | ||
| 120 | 114 | ||
| 121 | (defcustom php-speedbar-config t | 115 | (defcustom php-speedbar-config t |
| 122 | "When set to true automatically configures Speedbar to observe PHP files. | 116 | "When set to true automatically configures Speedbar to observe PHP files. |
| @@ -126,8 +120,7 @@ Ignores php-file patterns option; fixed to expression \"\\.\\(inc\\|php[s345]?\\ | |||
| 126 | (set-default sym val) | 120 | (set-default sym val) |
| 127 | (when val | 121 | (when val |
| 128 | (speedbar-add-supported-extension | 122 | (speedbar-add-supported-extension |
| 129 | "\\.\\(inc\\|php[s345]?\\|phtml\\)"))) | 123 | "\\.\\(inc\\|php[s345]?\\|phtml\\)")))) |
| 130 | :group 'php) | ||
| 131 | 124 | ||
| 132 | (defcustom php-mode-speedbar-open nil | 125 | (defcustom php-mode-speedbar-open nil |
| 133 | "Normally `php-mode' starts with the speedbar closed. | 126 | "Normally `php-mode' starts with the speedbar closed. |
| @@ -136,13 +129,20 @@ Turning this on will open it whenever `php-mode' is loaded." | |||
| 136 | :set (lambda (sym val) | 129 | :set (lambda (sym val) |
| 137 | (set-default sym val) | 130 | (set-default sym val) |
| 138 | (when val | 131 | (when val |
| 139 | (speedbar 1))) | 132 | (speedbar 1)))) |
| 140 | :group 'php) | ||
| 141 | 133 | ||
| 142 | (defcustom php-template-compatibility t | 134 | (defcustom php-template-compatibility t |
| 143 | "Should detect presence of html tags." | 135 | "Should detect presence of html tags." |
| 144 | :type 'boolean | 136 | :type 'boolean) |
| 145 | :group 'php) | 137 | |
| 138 | (defsubst php-in-string-p () | ||
| 139 | (nth 3 (syntax-ppss))) | ||
| 140 | |||
| 141 | (defsubst php-in-comment-p () | ||
| 142 | (nth 4 (syntax-ppss))) | ||
| 143 | |||
| 144 | (defsubst php-in-string-or-comment-p () | ||
| 145 | (nth 8 (syntax-ppss))) | ||
| 146 | 146 | ||
| 147 | (defun php-mode-extra-constants-create-regexp(kwds) | 147 | (defun php-mode-extra-constants-create-regexp(kwds) |
| 148 | "Create regexp for the list of extra constant keywords KWDS." | 148 | "Create regexp for the list of extra constant keywords KWDS." |
| @@ -170,15 +170,13 @@ of constants when set." | |||
| 170 | 170 | ||
| 171 | (defcustom php-lineup-cascaded-calls nil | 171 | (defcustom php-lineup-cascaded-calls nil |
| 172 | "Indent chained method calls to the previous line" | 172 | "Indent chained method calls to the previous line" |
| 173 | :type 'boolean | 173 | :type 'boolean) |
| 174 | :group 'php) | ||
| 175 | 174 | ||
| 176 | ;;;###autoload | 175 | ;;;###autoload |
| 177 | (defcustom php-extra-constants '() | 176 | (defcustom php-extra-constants '() |
| 178 | "A list of additional strings to treat as PHP constants." | 177 | "A list of additional strings to treat as PHP constants." |
| 179 | :type 'list | 178 | :type 'list |
| 180 | :set 'php-mode-extra-constants-set | 179 | :set 'php-mode-extra-constants-set) |
| 181 | :group 'php) | ||
| 182 | 180 | ||
| 183 | (defun php-create-regexp-for-method (visibility) | 181 | (defun php-create-regexp-for-method (visibility) |
| 184 | "Make a regular expression for methods with the given VISIBILITY. | 182 | "Make a regular expression for methods with the given VISIBILITY. |
| @@ -244,70 +242,58 @@ can be used to match against definitions for that classlike." | |||
| 244 | (defcustom php-manual-url "http://www.php.net/manual/en/" | 242 | (defcustom php-manual-url "http://www.php.net/manual/en/" |
| 245 | "URL at which to find PHP manual. | 243 | "URL at which to find PHP manual. |
| 246 | You can replace \"en\" with your ISO language code." | 244 | You can replace \"en\" with your ISO language code." |
| 247 | :type 'string | 245 | :type 'string) |
| 248 | :group 'php) | ||
| 249 | 246 | ||
| 250 | (defcustom php-search-url "http://www.php.net/" | 247 | (defcustom php-search-url "http://www.php.net/" |
| 251 | "URL at which to search for documentation on a word." | 248 | "URL at which to search for documentation on a word." |
| 252 | :type 'string | 249 | :type 'string) |
| 253 | :group 'php) | ||
| 254 | 250 | ||
| 255 | (defcustom php-completion-file "" | 251 | (defcustom php-completion-file "" |
| 256 | "Path to the file which contains the function names known to PHP." | 252 | "Path to the file which contains the function names known to PHP." |
| 257 | :type 'string | 253 | :type 'string) |
| 258 | :group 'php) | ||
| 259 | 254 | ||
| 260 | (defcustom php-manual-path "" | 255 | (defcustom php-manual-path "" |
| 261 | "Path to the directory which contains the PHP manual." | 256 | "Path to the directory which contains the PHP manual." |
| 262 | :type 'string | 257 | :type 'string) |
| 263 | :group 'php) | ||
| 264 | 258 | ||
| 265 | ;;;###autoload | 259 | ;;;###autoload |
| 266 | (add-to-list 'interpreter-mode-alist (cons "php" 'php-mode)) | 260 | (add-to-list 'interpreter-mode-alist (cons "php" 'php-mode)) |
| 267 | 261 | ||
| 268 | (defcustom php-mode-hook nil | 262 | (defcustom php-mode-hook nil |
| 269 | "List of functions to be executed on entry to `php-mode'." | 263 | "List of functions to be executed on entry to `php-mode'." |
| 270 | :type 'hook | 264 | :type 'hook) |
| 271 | :group 'php) | ||
| 272 | 265 | ||
| 273 | (defcustom php-mode-pear-hook nil | 266 | (defcustom php-mode-pear-hook nil |
| 274 | "Hook called when a PHP PEAR file is opened with `php-mode'." | 267 | "Hook called when a PHP PEAR file is opened with `php-mode'." |
| 275 | :type 'hook | 268 | :type 'hook) |
| 276 | :group 'php) | ||
| 277 | 269 | ||
| 278 | (defcustom php-mode-drupal-hook nil | 270 | (defcustom php-mode-drupal-hook nil |
| 279 | "Hook called when a Drupal file is opened with `php-mode'." | 271 | "Hook called when a Drupal file is opened with `php-mode'." |
| 280 | :type 'hook | 272 | :type 'hook) |
| 281 | :group 'php) | ||
| 282 | 273 | ||
| 283 | (defcustom php-mode-wordpress-hook nil | 274 | (defcustom php-mode-wordpress-hook nil |
| 284 | "Hook called when a WordPress file is opened with `php-mode'." | 275 | "Hook called when a WordPress file is opened with `php-mode'." |
| 285 | :type 'hook | 276 | :type 'hook) |
| 286 | :group 'php) | ||
| 287 | 277 | ||
| 288 | (defcustom php-mode-symfony2-hook nil | 278 | (defcustom php-mode-symfony2-hook nil |
| 289 | "Hook called when a Symfony2 file is opened with `php-mode'." | 279 | "Hook called when a Symfony2 file is opened with `php-mode'." |
| 290 | :type 'hook | 280 | :type 'hook) |
| 291 | :group 'php) | ||
| 292 | 281 | ||
| 293 | (defcustom php-mode-psr2-hook nil | 282 | (defcustom php-mode-psr2-hook nil |
| 294 | "Hook called when a PSR-2 file is opened with `php-mode'." | 283 | "Hook called when a PSR-2 file is opened with `php-mode'." |
| 295 | :type 'hook | 284 | :type 'hook) |
| 296 | :group 'php) | ||
| 297 | 285 | ||
| 298 | (defcustom php-mode-force-pear nil | 286 | (defcustom php-mode-force-pear nil |
| 299 | "Normally PEAR coding rules are enforced only when the filename contains \"PEAR.\" | 287 | "Normally PEAR coding rules are enforced only when the filename contains \"PEAR.\" |
| 300 | Turning this on will force PEAR rules on all PHP files." | 288 | Turning this on will force PEAR rules on all PHP files." |
| 301 | :type 'boolean | 289 | :type 'boolean) |
| 302 | :group 'php) | ||
| 303 | 290 | ||
| 304 | (defcustom php-mode-warn-if-mumamo-off t | 291 | (defcustom php-mode-warn-if-mumamo-off t |
| 305 | "Warn once per buffer if you try to indent a buffer without | 292 | "Warn once per buffer if you try to indent a buffer without |
| 306 | mumamo-mode turned on. Detects if there are any HTML tags in the | 293 | mumamo-mode turned on. Detects if there are any HTML tags in the |
| 307 | buffer before warning, but this is is not very smart; e.g. if you | 294 | buffer before warning, but this is is not very smart; e.g. if you |
| 308 | have any tags inside a PHP string, it will be fooled." | 295 | have any tags inside a PHP string, it will be fooled." |
| 309 | :type '(choice (const :tag "Warg" t) (const "Don't warn" nil)) | 296 | :type '(choice (const :tag "Warg" t) (const "Don't warn" nil))) |
| 310 | :group 'php) | ||
| 311 | 297 | ||
| 312 | (defcustom php-mode-coding-style 'pear | 298 | (defcustom php-mode-coding-style 'pear |
| 313 | "Select default coding style to use with php-mode. | 299 | "Select default coding style to use with php-mode. |
| @@ -330,7 +316,6 @@ This variable can take one of the following symbol values: | |||
| 330 | (const :tag "WordPress" wordpress) | 316 | (const :tag "WordPress" wordpress) |
| 331 | (const :tag "Symfony2" symfony2) | 317 | (const :tag "Symfony2" symfony2) |
| 332 | (const :tag "PSR-2" psr2)) | 318 | (const :tag "PSR-2" psr2)) |
| 333 | :group 'php | ||
| 334 | :set 'php-mode-custom-coding-style-set | 319 | :set 'php-mode-custom-coding-style-set |
| 335 | :initialize 'custom-initialize-default) | 320 | :initialize 'custom-initialize-default) |
| 336 | 321 | ||
| @@ -808,7 +793,7 @@ example `html-mode'. Known such libraries are:\n\t" | |||
| 808 | '(available-names . 1) | 793 | '(available-names . 1) |
| 809 | ))) | 794 | ))) |
| 810 | (mode (when name | 795 | (mode (when name |
| 811 | (caddr (assoc name available-multi-libs))))) | 796 | (cl-caddr (assoc name available-multi-libs))))) |
| 812 | (when mode | 797 | (when mode |
| 813 | ;; Minibuffer window is more than one line, fix that first: | 798 | ;; Minibuffer window is more than one line, fix that first: |
| 814 | (message "") | 799 | (message "") |
| @@ -874,15 +859,6 @@ This is was done due to the problem reported here: | |||
| 874 | "See `php-c-at-vsemi-p'." | 859 | "See `php-c-at-vsemi-p'." |
| 875 | ) | 860 | ) |
| 876 | 861 | ||
| 877 | (defsubst php-in-string-p () | ||
| 878 | (nth 3 (syntax-ppss))) | ||
| 879 | |||
| 880 | (defsubst php-in-comment-p () | ||
| 881 | (nth 4 (syntax-ppss))) | ||
| 882 | |||
| 883 | (defsubst php-in-string-or-comment-p () | ||
| 884 | (nth 8 (syntax-ppss))) | ||
| 885 | |||
| 886 | (defun php-lineup-string-cont (langelem) | 862 | (defun php-lineup-string-cont (langelem) |
| 887 | "Line up string toward equal sign or dot | 863 | "Line up string toward equal sign or dot |
| 888 | e.g. | 864 | e.g. |
| @@ -908,12 +884,12 @@ this ^ lineup" | |||
| 908 | (goto-char (cdr langelem)) | 884 | (goto-char (cdr langelem)) |
| 909 | (vector (current-column)))) | 885 | (vector (current-column)))) |
| 910 | 886 | ||
| 911 | (defun php-lineup-arglist (langelem) | 887 | (defun php-lineup-arglist (_langelem) |
| 912 | (save-excursion | 888 | (save-excursion |
| 913 | (beginning-of-line) | 889 | (beginning-of-line) |
| 914 | (if (looking-at-p "\\s-*->") '+ 0))) | 890 | (if (looking-at-p "\\s-*->") '+ 0))) |
| 915 | 891 | ||
| 916 | (defun php-lineup-hanging-semicolon (langelem) | 892 | (defun php-lineup-hanging-semicolon (_langelem) |
| 917 | (save-excursion | 893 | (save-excursion |
| 918 | (beginning-of-line) | 894 | (beginning-of-line) |
| 919 | (if (looking-at-p "\\s-*;\\s-*$") 0 '+))) | 895 | (if (looking-at-p "\\s-*;\\s-*$") 0 '+))) |
| @@ -999,11 +975,10 @@ PHP heredoc." | |||
| 999 | '(("\\(\"\\)\\(\\\\.\\|[^\"\n\\]\\)*\\(\"\\)" (1 "\"") (3 "\"")) | 975 | '(("\\(\"\\)\\(\\\\.\\|[^\"\n\\]\\)*\\(\"\\)" (1 "\"") (3 "\"")) |
| 1000 | ("\\(\'\\)\\(\\\\.\\|[^\'\n\\]\\)*\\(\'\\)" (1 "\"") (3 "\"")))) | 976 | ("\\(\'\\)\\(\\\\.\\|[^\'\n\\]\\)*\\(\'\\)" (1 "\"") (3 "\"")))) |
| 1001 | 977 | ||
| 1002 | (when (boundp 'syntax-propertize-function) | 978 | (add-to-list (make-local-variable 'syntax-propertize-extend-region-functions) |
| 1003 | (add-to-list (make-local-variable 'syntax-propertize-extend-region-functions) | 979 | #'php-syntax-propertize-extend-region) |
| 1004 | #'php-syntax-propertize-extend-region) | 980 | (set (make-local-variable 'syntax-propertize-function) |
| 1005 | (set (make-local-variable 'syntax-propertize-function) | 981 | #'php-syntax-propertize-function) |
| 1006 | #'php-syntax-propertize-function)) | ||
| 1007 | 982 | ||
| 1008 | (setq imenu-generic-expression php-imenu-generic-expression) | 983 | (setq imenu-generic-expression php-imenu-generic-expression) |
| 1009 | 984 | ||
| @@ -1083,7 +1058,11 @@ PHP heredoc." | |||
| 1083 | (set (make-local-variable 'defun-prompt-regexp) | 1058 | (set (make-local-variable 'defun-prompt-regexp) |
| 1084 | "^\\s-*function\\s-+&?\\s-*\\(\\(\\sw\\|\\s_\\)+\\)\\s-*") | 1059 | "^\\s-*function\\s-+&?\\s-*\\(\\(\\sw\\|\\s_\\)+\\)\\s-*") |
| 1085 | (set (make-local-variable 'add-log-current-defun-header-regexp) | 1060 | (set (make-local-variable 'add-log-current-defun-header-regexp) |
| 1086 | php-beginning-of-defun-regexp)) | 1061 | php-beginning-of-defun-regexp) |
| 1062 | |||
| 1063 | (when (>= emacs-major-version 25) | ||
| 1064 | (php-syntax-propertize-function (point-min) (point-max)))) | ||
| 1065 | |||
| 1087 | 1066 | ||
| 1088 | ;; Define function name completion function | 1067 | ;; Define function name completion function |
| 1089 | (defvar php-completion-table nil | 1068 | (defvar php-completion-table nil |
| @@ -1219,8 +1198,7 @@ current `tags-file-name'." | |||
| 1219 | If non-nil, this shadows the value of `browse-url-browser-function' when | 1198 | If non-nil, this shadows the value of `browse-url-browser-function' when |
| 1220 | calling `php-search-documentation' or `php-search-local-documentation'." | 1199 | calling `php-search-documentation' or `php-search-local-documentation'." |
| 1221 | :type '(choice (const :tag "default" nil) function) | 1200 | :type '(choice (const :tag "default" nil) function) |
| 1222 | :link '(variable-link browse-url-browser-function) | 1201 | :link '(variable-link browse-url-browser-function)) |
| 1223 | :group 'php) | ||
| 1224 | 1202 | ||
| 1225 | (defun php-browse-documentation-url (url) | 1203 | (defun php-browse-documentation-url (url) |
| 1226 | "Browse a documentation URL using the configured browser function. | 1204 | "Browse a documentation URL using the configured browser function. |
| @@ -1289,14 +1267,14 @@ exists, and nil otherwise. | |||
| 1289 | With a prefix argument, prompt (with completion) for a word to search for." | 1267 | With a prefix argument, prompt (with completion) for a word to search for." |
| 1290 | (interactive (php--search-documentation-read-arg)) | 1268 | (interactive (php--search-documentation-read-arg)) |
| 1291 | (let ((file (catch 'found | 1269 | (let ((file (catch 'found |
| 1292 | (loop for type in php-search-local-documentation-types do | 1270 | (cl-loop for type in php-search-local-documentation-types do |
| 1293 | (let* ((doc-html (format "%s.%s.html" | 1271 | (let* ((doc-html (format "%s.%s.html" |
| 1294 | type | 1272 | type |
| 1295 | (replace-regexp-in-string | 1273 | (replace-regexp-in-string |
| 1296 | "_" "-" (downcase word)))) | 1274 | "_" "-" (downcase word)))) |
| 1297 | (file (expand-file-name doc-html php-manual-path))) | 1275 | (file (expand-file-name doc-html php-manual-path))) |
| 1298 | (when (file-exists-p file) | 1276 | (when (file-exists-p file) |
| 1299 | (throw 'found file))))))) | 1277 | (throw 'found file))))))) |
| 1300 | (when file | 1278 | (when file |
| 1301 | (let ((file-url (if (string-prefix-p "file://" file) | 1279 | (let ((file-url (if (string-prefix-p "file://" file) |
| 1302 | file | 1280 | file |
| @@ -1462,7 +1440,7 @@ The output will appear in the buffer *PHP*." | |||
| 1462 | (defface php-annotations-annotation-face '((t . (:inherit font-lock-constant-face))) | 1440 | (defface php-annotations-annotation-face '((t . (:inherit font-lock-constant-face))) |
| 1463 | "Face used to highlight annotations.") | 1441 | "Face used to highlight annotations.") |
| 1464 | 1442 | ||
| 1465 | (defconst php-annotations-re "\\(\\s-\\|{\\)\\(@[[:alpha:]]+\\)") | 1443 | (defconst php-annotations-re "\\(\\s-\\|{\\)\\(@[-\\[:alpha:]]+\\)") |
| 1466 | 1444 | ||
| 1467 | (defmacro php-annotations-inside-comment-p (pos) | 1445 | (defmacro php-annotations-inside-comment-p (pos) |
| 1468 | "Return non-nil if POS is inside a comment." | 1446 | "Return non-nil if POS is inside a comment." |
| @@ -1535,7 +1513,7 @@ The output will appear in the buffer *PHP*." | |||
| 1535 | 1513 | ||
| 1536 | 1514 | ||
| 1537 | ;;;###autoload | 1515 | ;;;###autoload |
| 1538 | (dolist (pattern '("\\.php[s345t]?\\'" "\\.phtml\\'" "Amkfile" "\\.amk$")) | 1516 | (dolist (pattern '("\\.php[s345t]?\\'" "\\.phtml\\'" "/Amkfile\\'" "\\.amk\\'")) |
| 1539 | (add-to-list 'auto-mode-alist `(,pattern . php-mode) t)) | 1517 | (add-to-list 'auto-mode-alist `(,pattern . php-mode) t)) |
| 1540 | 1518 | ||
| 1541 | (provide 'php-mode) | 1519 | (provide 'php-mode) |
diff --git a/.emacs.d/lisp/yaml-mode.el b/.emacs.d/lisp/yaml-mode.el index 39c0e57..b8c1ddb 100644 --- a/.emacs.d/lisp/yaml-mode.el +++ b/.emacs.d/lisp/yaml-mode.el | |||
| @@ -41,7 +41,7 @@ | |||
| 41 | ;; handle files ending in '.yml', add something like: | 41 | ;; handle files ending in '.yml', add something like: |
| 42 | ;; | 42 | ;; |
| 43 | ;; (require 'yaml-mode) | 43 | ;; (require 'yaml-mode) |
| 44 | ;; (add-to-list 'auto-mode-alist '("\\.yml$" . yaml-mode)) | 44 | ;; (add-to-list 'auto-mode-alist '("\\.yml\\'" . yaml-mode)) |
| 45 | ;; | 45 | ;; |
| 46 | ;; to your .emacs file. | 46 | ;; to your .emacs file. |
| 47 | ;; | 47 | ;; |
| @@ -431,7 +431,7 @@ cross boundaries of block literals." | |||
| 431 | yaml-mode-version) | 431 | yaml-mode-version) |
| 432 | 432 | ||
| 433 | ;;;###autoload | 433 | ;;;###autoload |
| 434 | (add-to-list 'auto-mode-alist '("\\.e?ya?ml$" . yaml-mode)) | 434 | (add-to-list 'auto-mode-alist '("\\.e?ya?ml\\'" . yaml-mode)) |
| 435 | 435 | ||
| 436 | (provide 'yaml-mode) | 436 | (provide 'yaml-mode) |
| 437 | 437 | ||
diff --git a/.emacs.d/lisp/yasnippet.el b/.emacs.d/lisp/yasnippet.el index b68389f..3446060 100644 --- a/.emacs.d/lisp/yasnippet.el +++ b/.emacs.d/lisp/yasnippet.el | |||
| @@ -1,13 +1,15 @@ | |||
| 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-2016 Free Software Foundation, Inc. |
| 4 | ;; Authors: pluskid <pluskid@gmail.com>, João Távora <joaotavora@gmail.com>, Noam Postavsky <npostavs@gmail.com> | 4 | ;; Authors: pluskid <pluskid@gmail.com>, |
| 5 | ;; João Távora <joaotavora@gmail.com>, | ||
| 6 | ;; Noam Postavsky <npostavs@gmail.com> | ||
| 5 | ;; Maintainer: Noam Postavsky <npostavs@gmail.com> | 7 | ;; Maintainer: Noam Postavsky <npostavs@gmail.com> |
| 6 | ;; Version: 0.8.1 | 8 | ;; Version: 0.9.1 |
| 7 | ;; Package-version: 0.8.0 | ||
| 8 | ;; X-URL: http://github.com/capitaomorte/yasnippet | 9 | ;; X-URL: http://github.com/capitaomorte/yasnippet |
| 9 | ;; Keywords: convenience, emulation | 10 | ;; Keywords: convenience, emulation |
| 10 | ;; URL: http://github.com/capitaomorte/yasnippet | 11 | ;; URL: http://github.com/capitaomorte/yasnippet |
| 12 | ;; Package-Requires: ((cl-lib "0.5")) | ||
| 11 | ;; EmacsWiki: YaSnippetMode | 13 | ;; EmacsWiki: YaSnippetMode |
| 12 | 14 | ||
| 13 | ;; This program is free software: you can redistribute it and/or modify | 15 | ;; This program is free software: you can redistribute it and/or modify |
| @@ -154,10 +156,10 @@ | |||
| 154 | (defvar yas-installed-snippets-dir nil) | 156 | (defvar yas-installed-snippets-dir nil) |
| 155 | (setq yas-installed-snippets-dir | 157 | (setq yas-installed-snippets-dir |
| 156 | (when load-file-name | 158 | (when load-file-name |
| 157 | (concat (file-name-directory load-file-name) "snippets"))) | 159 | (expand-file-name "snippets" (file-name-directory load-file-name)))) |
| 158 | 160 | ||
| 159 | (defconst yas--default-user-snippets-dir | 161 | (defconst yas--default-user-snippets-dir |
| 160 | (concat user-emacs-directory "snippets")) | 162 | (expand-file-name "snippets" user-emacs-directory)) |
| 161 | 163 | ||
| 162 | (defcustom yas-snippet-dirs (remove nil | 164 | (defcustom yas-snippet-dirs (remove nil |
| 163 | (list yas--default-user-snippets-dir | 165 | (list yas--default-user-snippets-dir |
| @@ -173,8 +175,9 @@ snippets. | |||
| 173 | 175 | ||
| 174 | The first directory is taken as the default for storing snippet's | 176 | The first directory is taken as the default for storing snippet's |
| 175 | created with `yas-new-snippet'. " | 177 | created with `yas-new-snippet'. " |
| 176 | :type '(choice (string :tag "Single directory (string)") | 178 | :type '(choice (directory :tag "Single directory") |
| 177 | (repeat :args (string) :tag "List of directories (strings)")) | 179 | (repeat :tag "List of directories" |
| 180 | (choice (directory) (variable)))) | ||
| 178 | :group 'yasnippet | 181 | :group 'yasnippet |
| 179 | :require 'yasnippet | 182 | :require 'yasnippet |
| 180 | :set #'(lambda (symbol new) | 183 | :set #'(lambda (symbol new) |
| @@ -343,11 +346,16 @@ Any other non-nil value, every submenu is listed." | |||
| 343 | :group 'yasnippet) | 346 | :group 'yasnippet) |
| 344 | 347 | ||
| 345 | (defcustom yas-wrap-around-region nil | 348 | (defcustom yas-wrap-around-region nil |
| 346 | "If non-nil, snippet expansion wraps around selected region. | 349 | "What to insert for snippet's $0 field. |
| 347 | 350 | ||
| 348 | The wrapping occurs just before the snippet's exit marker. This | 351 | If set to a character, insert contents of corresponding register. |
| 349 | can be overridden on a per-snippet basis." | 352 | If non-nil insert region contents. This can be overridden on a |
| 350 | :type 'boolean | 353 | per-snippet basis. A value of `cua' is considered equivalent to |
| 354 | `?0' for backwards compatibility." | ||
| 355 | :type '(choice (character :tag "Insert from register") | ||
| 356 | (const t :tag "Insert region contents") | ||
| 357 | (const nil :tag "Don't insert anything") | ||
| 358 | (const cua)) ; backwards compat | ||
| 351 | :group 'yasnippet) | 359 | :group 'yasnippet) |
| 352 | 360 | ||
| 353 | (defcustom yas-good-grace t | 361 | (defcustom yas-good-grace t |
| @@ -508,7 +516,7 @@ snippets returning the symbol 'force-in-comment in their | |||
| 508 | conditions. | 516 | conditions. |
| 509 | 517 | ||
| 510 | (add-hook 'python-mode-hook | 518 | (add-hook 'python-mode-hook |
| 511 | '(lambda () | 519 | (lambda () |
| 512 | (setq yas-buffer-local-condition | 520 | (setq yas-buffer-local-condition |
| 513 | '(if (python-in-string/comment) | 521 | '(if (python-in-string/comment) |
| 514 | '(require-snippet-condition . force-in-comment) | 522 | '(require-snippet-condition . force-in-comment) |
| @@ -522,7 +530,7 @@ snippet itself contains a condition that returns the symbol | |||
| 522 | 530 | ||
| 523 | ;;; Internal variables | 531 | ;;; Internal variables |
| 524 | 532 | ||
| 525 | (defvar yas--version "0.8.0beta") | 533 | (defvar yas--version "0.9.1") |
| 526 | 534 | ||
| 527 | (defvar yas--menu-table (make-hash-table) | 535 | (defvar yas--menu-table (make-hash-table) |
| 528 | "A hash table of MAJOR-MODE symbols to menu keymaps.") | 536 | "A hash table of MAJOR-MODE symbols to menu keymaps.") |
| @@ -688,7 +696,7 @@ snippet itself contains a condition that returns the symbol | |||
| 688 | 696 | ||
| 689 | This variable probably makes more sense as buffer-local, so | 697 | This variable probably makes more sense as buffer-local, so |
| 690 | ensure your use `make-local-variable' when you set it.") | 698 | ensure your use `make-local-variable' when you set it.") |
| 691 | (define-obsolete-variable-alias 'yas-extra-modes 'yas--extra-modes "0.8.1") | 699 | (define-obsolete-variable-alias 'yas-extra-modes 'yas--extra-modes "0.9.1") |
| 692 | 700 | ||
| 693 | (defvar yas--tables (make-hash-table) | 701 | (defvar yas--tables (make-hash-table) |
| 694 | "A hash table of mode symbols to `yas--table' objects.") | 702 | "A hash table of mode symbols to `yas--table' objects.") |
| @@ -727,22 +735,24 @@ defined direct keybindings to the command | |||
| 727 | yas--tables)) | 735 | yas--tables)) |
| 728 | 736 | ||
| 729 | (defun yas--modes-to-activate (&optional mode) | 737 | (defun yas--modes-to-activate (&optional mode) |
| 730 | "Compute list of mode symbols that are active for `yas-expand' | 738 | "Compute list of mode symbols that are active for `yas-expand' and friends." |
| 731 | and friends." | 739 | (defvar yas--dfs) ;We rely on dynbind. We could use `letrec' instead! |
| 732 | (let* ((explored (if mode (list mode) ; Building up list in reverse. | 740 | (let* ((explored (if mode (list mode) ; Building up list in reverse. |
| 733 | (cons major-mode (reverse yas--extra-modes)))) | 741 | (cons major-mode (reverse yas--extra-modes)))) |
| 734 | (dfs | 742 | (yas--dfs |
| 735 | (lambda (mode) | 743 | (lambda (mode) |
| 736 | (cl-loop for neighbour | 744 | (cl-loop for neighbour |
| 737 | in (cl-list* (get mode 'derived-mode-parent) | 745 | in (cl-list* (get mode 'derived-mode-parent) |
| 738 | (ignore-errors (symbol-function mode)) | 746 | ;; NOTE: `fboundp' check is redundant |
| 747 | ;; since Emacs 24.4. | ||
| 748 | (and (fboundp mode) (symbol-function mode)) | ||
| 739 | (gethash mode yas--parents)) | 749 | (gethash mode yas--parents)) |
| 740 | when (and neighbour | 750 | when (and neighbour |
| 741 | (not (memq neighbour explored)) | 751 | (not (memq neighbour explored)) |
| 742 | (symbolp neighbour)) | 752 | (symbolp neighbour)) |
| 743 | do (push neighbour explored) | 753 | do (push neighbour explored) |
| 744 | (funcall dfs neighbour))))) | 754 | (funcall yas--dfs neighbour))))) |
| 745 | (mapcar dfs explored) | 755 | (mapc yas--dfs explored) |
| 746 | (nreverse explored))) | 756 | (nreverse explored))) |
| 747 | 757 | ||
| 748 | (defvar yas-minor-mode-hook nil | 758 | (defvar yas-minor-mode-hook nil |
| @@ -774,8 +784,8 @@ Key bindings: | |||
| 774 | ;; | 784 | ;; |
| 775 | ;; Also install the post-command-hook. | 785 | ;; Also install the post-command-hook. |
| 776 | ;; | 786 | ;; |
| 777 | (add-hook 'emulation-mode-map-alists 'yas--direct-keymaps) | 787 | (cl-pushnew 'yas--direct-keymaps emulation-mode-map-alists) |
| 778 | (add-hook 'post-command-hook 'yas--post-command-handler nil t) | 788 | (add-hook 'post-command-hook #'yas--post-command-handler nil t) |
| 779 | ;; Set the `yas--direct-%s' vars for direct keymap expansion | 789 | ;; Set the `yas--direct-%s' vars for direct keymap expansion |
| 780 | ;; | 790 | ;; |
| 781 | (dolist (mode (yas--modes-to-activate)) | 791 | (dolist (mode (yas--modes-to-activate)) |
| @@ -788,8 +798,9 @@ Key bindings: | |||
| 788 | (t | 798 | (t |
| 789 | ;; Uninstall the direct keymaps and the post-command hook | 799 | ;; Uninstall the direct keymaps and the post-command hook |
| 790 | ;; | 800 | ;; |
| 791 | (remove-hook 'post-command-hook 'yas--post-command-handler t) | 801 | (remove-hook 'post-command-hook #'yas--post-command-handler t) |
| 792 | (remove-hook 'emulation-mode-map-alists 'yas--direct-keymaps)))) | 802 | (setq emulation-mode-map-alists |
| 803 | (remove 'yas--direct-keymaps emulation-mode-map-alists))))) | ||
| 793 | 804 | ||
| 794 | (defun yas-activate-extra-mode (mode) | 805 | (defun yas-activate-extra-mode (mode) |
| 795 | "Activates the snippets for the given `mode' in the buffer. | 806 | "Activates the snippets for the given `mode' in the buffer. |
| @@ -821,21 +832,20 @@ activate snippets associated with that mode." | |||
| 821 | (remove mode | 832 | (remove mode |
| 822 | yas--extra-modes))) | 833 | yas--extra-modes))) |
| 823 | 834 | ||
| 824 | (defvar yas-dont-activate '(minibufferp) | 835 | (define-obsolete-variable-alias 'yas-dont-activate |
| 825 | "If non-nil don't let `yas-global-mode' affect some buffers. | 836 | 'yas-dont-activate-functions "0.9.2") |
| 826 | 837 | (defvar yas-dont-activate-functions (list #'minibufferp) | |
| 827 | If a function of zero arguments, then its result is used. | 838 | "Special hook to control which buffers `yas-global-mode' affects. |
| 828 | 839 | Functions are called with no argument, and should return non-nil to prevent | |
| 829 | If a list of functions, then all functions must return nil to | 840 | `yas-global-mode' from enabling yasnippet in this buffer. |
| 830 | activate yas for this buffer. | ||
| 831 | 841 | ||
| 832 | In Emacsen <= 23, this variable is buffer-local. Because | 842 | In Emacsen < 24, this variable is buffer-local. Because |
| 833 | `yas-minor-mode-on' is called by `yas-global-mode' after | 843 | `yas-minor-mode-on' is called by `yas-global-mode' after |
| 834 | executing the buffer's major mode hook, setting this variable | 844 | executing the buffer's major mode hook, setting this variable |
| 835 | there is an effective way to define exceptions to the \"global\" | 845 | there is an effective way to define exceptions to the \"global\" |
| 836 | activation behaviour. | 846 | activation behaviour. |
| 837 | 847 | ||
| 838 | In Emacsen > 23, only the global value is used. To define | 848 | In Emacsen >= 24, only the global value is used. To define |
| 839 | per-mode exceptions to the \"global\" activation behaviour, call | 849 | per-mode exceptions to the \"global\" activation behaviour, call |
| 840 | `yas-minor-mode' with a negative argument directily in the major | 850 | `yas-minor-mode' with a negative argument directily in the major |
| 841 | mode's hook.") | 851 | mode's hook.") |
| @@ -847,14 +857,14 @@ mode's hook.") | |||
| 847 | (defun yas-minor-mode-on () | 857 | (defun yas-minor-mode-on () |
| 848 | "Turn on YASnippet minor mode. | 858 | "Turn on YASnippet minor mode. |
| 849 | 859 | ||
| 850 | Honour `yas-dont-activate', which see." | 860 | Honour `yas-dont-activate-functions', which see." |
| 851 | (interactive) | 861 | (interactive) |
| 852 | ;; Check `yas-dont-activate' | 862 | (unless (or |
| 853 | (unless (cond ((functionp yas-dont-activate) | 863 | ;; The old behavior used for Emacs<24 was to set |
| 854 | (funcall yas-dont-activate)) | 864 | ;; `yas-dont-activate-functions' to t buffer-locally. |
| 855 | ((consp yas-dont-activate) | 865 | (not (or (listp yas-dont-activate-functions) |
| 856 | (some #'funcall yas-dont-activate)) | 866 | (functionp yas-dont-activate-functions))) |
| 857 | (yas-dont-activate)) | 867 | (run-hook-with-args-until-success 'yas-dont-activate-functions)) |
| 858 | (yas-minor-mode 1))) | 868 | (yas-minor-mode 1))) |
| 859 | 869 | ||
| 860 | ;;;###autoload | 870 | ;;;###autoload |
| @@ -866,22 +876,26 @@ Honour `yas-dont-activate', which see." | |||
| 866 | "Run `yas-reload-all' when `yas-global-mode' is on." | 876 | "Run `yas-reload-all' when `yas-global-mode' is on." |
| 867 | (when yas-global-mode (yas-reload-all))) | 877 | (when yas-global-mode (yas-reload-all))) |
| 868 | 878 | ||
| 869 | (add-hook 'yas-global-mode-hook 'yas--global-mode-reload-with-jit-maybe) | 879 | (add-hook 'yas-global-mode-hook #'yas--global-mode-reload-with-jit-maybe) |
| 870 | 880 | ||
| 871 | 881 | ||
| 872 | ;;; Major mode stuff | 882 | ;;; Major mode stuff |
| 873 | 883 | ||
| 874 | (defvar yas--font-lock-keywords | 884 | (defvar yas--font-lock-keywords |
| 875 | (append '(("^#.*$" . font-lock-comment-face)) | 885 | (append '(("^#.*$" . font-lock-comment-face)) |
| 876 | lisp-font-lock-keywords-2 | 886 | (with-temp-buffer |
| 887 | (ignore-errors (emacs-lisp-mode)) | ||
| 888 | (font-lock-set-defaults) | ||
| 889 | (if (eq t (car-safe font-lock-keywords)) | ||
| 890 | ;; They're "compiled", so extract the source. | ||
| 891 | (cadr font-lock-keywords) | ||
| 892 | font-lock-keywords)) | ||
| 877 | '(("$\\([0-9]+\\)" | 893 | '(("$\\([0-9]+\\)" |
| 878 | (0 font-lock-keyword-face) | 894 | (0 font-lock-keyword-face) |
| 879 | (1 font-lock-string-face t)) | 895 | (1 font-lock-string-face t)) |
| 880 | ("${\\([0-9]+\\):?" | 896 | ("${\\([0-9]+\\):?" |
| 881 | (0 font-lock-keyword-face) | 897 | (0 font-lock-keyword-face) |
| 882 | (1 font-lock-warning-face t)) | 898 | (1 font-lock-warning-face t)) |
| 883 | ("${" . font-lock-keyword-face) | ||
| 884 | ("$[0-9]+?" . font-lock-preprocessor-face) | ||
| 885 | ("\\(\\$(\\)" 1 font-lock-preprocessor-face) | 899 | ("\\(\\$(\\)" 1 font-lock-preprocessor-face) |
| 886 | ("}" | 900 | ("}" |
| 887 | (0 font-lock-keyword-face))))) | 901 | (0 font-lock-keyword-face))))) |
| @@ -903,6 +917,7 @@ Honour `yas-dont-activate', which see." | |||
| 903 | "The keymap used when `snippet-mode' is active.") | 917 | "The keymap used when `snippet-mode' is active.") |
| 904 | 918 | ||
| 905 | 919 | ||
| 920 | ;;;###autoload | ||
| 906 | (define-derived-mode snippet-mode text-mode "Snippet" | 921 | (define-derived-mode snippet-mode text-mode "Snippet" |
| 907 | "A mode for editing yasnippets" | 922 | "A mode for editing yasnippets" |
| 908 | (setq font-lock-defaults '(yas--font-lock-keywords)) | 923 | (setq font-lock-defaults '(yas--font-lock-keywords)) |
| @@ -1474,10 +1489,7 @@ Here's a list of currently recognized directives: | |||
| 1474 | (let* ((dominating-dir (locate-dominating-file file | 1489 | (let* ((dominating-dir (locate-dominating-file file |
| 1475 | ".yas-make-groups")) | 1490 | ".yas-make-groups")) |
| 1476 | (extra-path (and dominating-dir | 1491 | (extra-path (and dominating-dir |
| 1477 | (replace-regexp-in-string (concat "^" | 1492 | (file-relative-name file dominating-dir))) |
| 1478 | (expand-file-name dominating-dir)) | ||
| 1479 | "" | ||
| 1480 | (expand-file-name file)))) | ||
| 1481 | (extra-dir (and extra-path | 1493 | (extra-dir (and extra-path |
| 1482 | (file-name-directory extra-path))) | 1494 | (file-name-directory extra-path))) |
| 1483 | (group (and extra-dir | 1495 | (group (and extra-dir |
| @@ -1488,17 +1500,17 @@ Here's a list of currently recognized directives: | |||
| 1488 | 1500 | ||
| 1489 | (defun yas--subdirs (directory &optional filep) | 1501 | (defun yas--subdirs (directory &optional filep) |
| 1490 | "Return subdirs or files of DIRECTORY according to FILEP." | 1502 | "Return subdirs or files of DIRECTORY according to FILEP." |
| 1491 | (remove-if (lambda (file) | 1503 | (cl-remove-if (lambda (file) |
| 1492 | (or (string-match "^\\." | 1504 | (or (string-match "\\`\\." |
| 1493 | (file-name-nondirectory file)) | 1505 | (file-name-nondirectory file)) |
| 1494 | (string-match "^#.*#$" | 1506 | (string-match "\\`#.*#\\'" |
| 1495 | (file-name-nondirectory file)) | 1507 | (file-name-nondirectory file)) |
| 1496 | (string-match "~$" | 1508 | (string-match "~\\'" |
| 1497 | (file-name-nondirectory file)) | 1509 | (file-name-nondirectory file)) |
| 1498 | (if filep | 1510 | (if filep |
| 1499 | (file-directory-p file) | 1511 | (file-directory-p file) |
| 1500 | (not (file-directory-p file))))) | 1512 | (not (file-directory-p file))))) |
| 1501 | (directory-files directory t))) | 1513 | (directory-files directory t))) |
| 1502 | 1514 | ||
| 1503 | (defun yas--make-menu-binding (template) | 1515 | (defun yas--make-menu-binding (template) |
| 1504 | (let ((mode (yas--table-mode (yas--template-table template)))) | 1516 | (let ((mode (yas--table-mode (yas--template-table template)))) |
| @@ -1770,7 +1782,7 @@ With prefix argument USE-JIT do jit-loading of snippets." | |||
| 1770 | (insert (format ";;; Do not edit! File generated at %s\n" | 1782 | (insert (format ";;; Do not edit! File generated at %s\n" |
| 1771 | (current-time-string))))) | 1783 | (current-time-string))))) |
| 1772 | ;; Normal case. | 1784 | ;; Normal case. |
| 1773 | (unless (file-exists-p (concat directory "/" ".yas-skip")) | 1785 | (unless (file-exists-p (expand-file-name ".yas-skip" directory)) |
| 1774 | (unless (and (load (expand-file-name ".yas-compiled-snippets" directory) 'noerror (<= yas-verbosity 3)) | 1786 | (unless (and (load (expand-file-name ".yas-compiled-snippets" directory) 'noerror (<= yas-verbosity 3)) |
| 1775 | (progn (yas--message 2 "Loaded compiled snippets from %s" directory) t)) | 1787 | (progn (yas--message 2 "Loaded compiled snippets from %s" directory) t)) |
| 1776 | (yas--message 2 "Loading snippet files from %s" directory) | 1788 | (yas--message 2 "Loading snippet files from %s" directory) |
| @@ -1945,7 +1957,7 @@ This works by stubbing a few functions, then calling | |||
| 1945 | 1957 | ||
| 1946 | ;;; Apropos snippet menu: | 1958 | ;;; Apropos snippet menu: |
| 1947 | ;; | 1959 | ;; |
| 1948 | ;; The snippet menu keymaps are store by mode in hash table called | 1960 | ;; The snippet menu keymaps are stored by mode in hash table called |
| 1949 | ;; `yas--menu-table'. They are linked to the main menu in | 1961 | ;; `yas--menu-table'. They are linked to the main menu in |
| 1950 | ;; `yas--menu-keymap-get-create' and are initially created empty, | 1962 | ;; `yas--menu-keymap-get-create' and are initially created empty, |
| 1951 | ;; reflecting the table hierarchy. | 1963 | ;; reflecting the table hierarchy. |
| @@ -1967,9 +1979,9 @@ This works by stubbing a few functions, then calling | |||
| 1967 | ;; duplicate entries. The `yas--template' objects are created in | 1979 | ;; duplicate entries. The `yas--template' objects are created in |
| 1968 | ;; `yas-define-menu', holding nothing but the menu entry, | 1980 | ;; `yas-define-menu', holding nothing but the menu entry, |
| 1969 | ;; represented by a pair of ((menu-item NAME :keys KEYS) TYPE) and | 1981 | ;; represented by a pair of ((menu-item NAME :keys KEYS) TYPE) and |
| 1970 | ;; stored in `yas--template-menu-binding-pair'. The (menu-item ...) | 1982 | ;; stored in `yas--template-menu-binding-pair'. The (menu-item ...) |
| 1971 | ;; part is then stored in the menu keymap itself which make the item | 1983 | ;; part is then stored in the menu keymap itself which make the item |
| 1972 | ;; appear to the user. These limitations could probably be revised. | 1984 | ;; appear to the user. These limitations could probably be revised. |
| 1973 | ;; | 1985 | ;; |
| 1974 | ;; * The `yas--template-perm-group' slot is only used in | 1986 | ;; * The `yas--template-perm-group' slot is only used in |
| 1975 | ;; `yas-describe-tables'. | 1987 | ;; `yas-describe-tables'. |
| @@ -2158,9 +2170,13 @@ object satisfying `yas--field-p' to restrict the expansion to." | |||
| 2158 | (yas--templates-for-key-at-point)) | 2170 | (yas--templates-for-key-at-point)) |
| 2159 | (yas--templates-for-key-at-point)))) | 2171 | (yas--templates-for-key-at-point)))) |
| 2160 | (if templates-and-pos | 2172 | (if templates-and-pos |
| 2161 | (yas--expand-or-prompt-for-template (first templates-and-pos) | 2173 | (yas--expand-or-prompt-for-template |
| 2162 | (second templates-and-pos) | 2174 | (nth 0 templates-and-pos) |
| 2163 | (third templates-and-pos)) | 2175 | ;; Delete snippet key and active region when expanding. |
| 2176 | (min (if (use-region-p) (region-beginning) most-positive-fixnum) | ||
| 2177 | (nth 1 templates-and-pos)) | ||
| 2178 | (max (if (use-region-p) (region-end) most-negative-fixnum) | ||
| 2179 | (nth 2 templates-and-pos))) | ||
| 2164 | (yas--fallback)))) | 2180 | (yas--fallback)))) |
| 2165 | 2181 | ||
| 2166 | (defun yas-expand-from-keymap () | 2182 | (defun yas-expand-from-keymap () |
| @@ -2407,13 +2423,11 @@ tables (or optional TABLE). | |||
| 2407 | Returns a list of elements (TABLE . DIRS) where TABLE is a | 2423 | Returns a list of elements (TABLE . DIRS) where TABLE is a |
| 2408 | `yas--table' object and DIRS is a list of all possible directories | 2424 | `yas--table' object and DIRS is a list of all possible directories |
| 2409 | where snippets of table might exist." | 2425 | where snippets of table might exist." |
| 2410 | (let ((main-dir (replace-regexp-in-string | 2426 | (let ((main-dir (car (or (yas-snippet-dirs) |
| 2411 | "/+$" "" | 2427 | (setq yas-snippet-dirs |
| 2412 | (or (first (or (yas-snippet-dirs) | 2428 | (list yas--default-user-snippets-dir))))) |
| 2413 | (setq yas-snippet-dirs (list yas--default-user-snippets-dir))))))) | 2429 | (tables (if table (list table) |
| 2414 | (tables (or (and table | 2430 | (yas--get-snippet-tables)))) |
| 2415 | (list table)) | ||
| 2416 | (yas--get-snippet-tables)))) | ||
| 2417 | ;; HACK! the snippet table created here is actually registered! | 2431 | ;; HACK! the snippet table created here is actually registered! |
| 2418 | ;; | 2432 | ;; |
| 2419 | (unless (or table (gethash major-mode yas--tables)) | 2433 | (unless (or table (gethash major-mode yas--tables)) |
| @@ -2423,7 +2437,7 @@ where snippets of table might exist." | |||
| 2423 | (mapcar #'(lambda (table) | 2437 | (mapcar #'(lambda (table) |
| 2424 | (cons table | 2438 | (cons table |
| 2425 | (mapcar #'(lambda (subdir) | 2439 | (mapcar #'(lambda (subdir) |
| 2426 | (concat main-dir "/" subdir)) | 2440 | (expand-file-name subdir main-dir)) |
| 2427 | (yas--guess-snippet-directories-1 table)))) | 2441 | (yas--guess-snippet-directories-1 table)))) |
| 2428 | tables))) | 2442 | tables))) |
| 2429 | 2443 | ||
| @@ -2585,9 +2599,10 @@ and `kill-buffer' instead." | |||
| 2585 | (when chosen | 2599 | (when chosen |
| 2586 | (let ((default-file-name (or (and file (file-name-nondirectory file)) | 2600 | (let ((default-file-name (or (and file (file-name-nondirectory file)) |
| 2587 | (yas--template-name yas--editing-template)))) | 2601 | (yas--template-name yas--editing-template)))) |
| 2588 | (write-file (concat chosen "/" | 2602 | (write-file (expand-file-name |
| 2589 | (read-from-minibuffer (format "File name to create in %s? " chosen) | 2603 | (read-file-name (format "File name to create in %s? " chosen) |
| 2590 | default-file-name))) | 2604 | chosen default-file-name) |
| 2605 | chosen)) | ||
| 2591 | (setf (yas--template-load-file yas--editing-template) buffer-file-name)))))) | 2606 | (setf (yas--template-load-file yas--editing-template) buffer-file-name)))))) |
| 2592 | (when buffer-file-name | 2607 | (when buffer-file-name |
| 2593 | (save-buffer) | 2608 | (save-buffer) |
| @@ -2607,10 +2622,10 @@ and `kill-buffer' instead." | |||
| 2607 | (and parsed | 2622 | (and parsed |
| 2608 | (fboundp test-mode) | 2623 | (fboundp test-mode) |
| 2609 | (yas--make-template :table nil ;; no tables for ephemeral snippets | 2624 | (yas--make-template :table nil ;; no tables for ephemeral snippets |
| 2610 | :key (first parsed) | 2625 | :key (nth 0 parsed) |
| 2611 | :content (second parsed) | 2626 | :content (nth 1 parsed) |
| 2612 | :name (third parsed) | 2627 | :name (nth 2 parsed) |
| 2613 | :expand-env (sixth parsed))))) | 2628 | :expand-env (nth 5 parsed))))) |
| 2614 | (cond (yas--current-template | 2629 | (cond (yas--current-template |
| 2615 | (let ((buffer-name (format "*testing snippet: %s*" (yas--template-name yas--current-template)))) | 2630 | (let ((buffer-name (format "*testing snippet: %s*" (yas--template-name yas--current-template)))) |
| 2616 | (kill-buffer (get-buffer-create buffer-name)) | 2631 | (kill-buffer (get-buffer-create buffer-name)) |
| @@ -2660,7 +2675,7 @@ and `kill-buffer' instead." | |||
| 2660 | (setq buffer-read-only nil) | 2675 | (setq buffer-read-only nil) |
| 2661 | (erase-buffer) | 2676 | (erase-buffer) |
| 2662 | (cond ((not by-name-hash) | 2677 | (cond ((not by-name-hash) |
| 2663 | (insert "YASnippet tables: \n") | 2678 | (insert "YASnippet tables:\n") |
| 2664 | (while (and table-lists | 2679 | (while (and table-lists |
| 2665 | continue) | 2680 | continue) |
| 2666 | (dolist (table (car table-lists)) | 2681 | (dolist (table (car table-lists)) |
| @@ -2716,31 +2731,32 @@ and `kill-buffer' instead." | |||
| 2716 | (setq group (truncate-string-to-width group 25 0 ? "...")) | 2731 | (setq group (truncate-string-to-width group 25 0 ? "...")) |
| 2717 | (insert (make-string 100 ?-) "\n") | 2732 | (insert (make-string 100 ?-) "\n") |
| 2718 | (dolist (p templates) | 2733 | (dolist (p templates) |
| 2719 | (let ((name (truncate-string-to-width (propertize (format "\\\\snippet `%s'" (yas--template-name p)) | 2734 | (let* ((name (truncate-string-to-width (propertize (format "\\\\snippet `%s'" (yas--template-name p)) |
| 2720 | 'yasnippet p) | 2735 | 'yasnippet p) |
| 2721 | 50 0 ? "...")) | 2736 | 50 0 ? "...")) |
| 2722 | (group (prog1 group | 2737 | (group (prog1 group |
| 2723 | (setq group (make-string (length group) ? )))) | 2738 | (setq group (make-string (length group) ? )))) |
| 2724 | (condition-string (let ((condition (yas--template-condition p))) | 2739 | (condition-string (let ((condition (yas--template-condition p))) |
| 2725 | (if (and condition | 2740 | (if (and condition |
| 2726 | original-buffer) | 2741 | original-buffer) |
| 2727 | (with-current-buffer original-buffer | 2742 | (with-current-buffer original-buffer |
| 2728 | (if (yas--eval-condition condition) | 2743 | (if (yas--eval-condition condition) |
| 2729 | "(y)" | 2744 | "(y)" |
| 2730 | "(s)")) | 2745 | "(s)")) |
| 2731 | "(a)")))) | 2746 | "(a)"))) |
| 2732 | (insert group " ") | 2747 | (key-description-string (key-description (yas--template-keybinding p))) |
| 2733 | (insert condition-string " ") | 2748 | (template-key-padding (if (string= key-description-string "") nil ? ))) |
| 2734 | (insert name | 2749 | (insert group " " |
| 2735 | (if (string-match "\\.\\.\\.$" name) | 2750 | condition-string " " |
| 2736 | "'" | 2751 | name (if (string-match "\\.\\.\\.$" name) |
| 2737 | " ") | 2752 | "'" " ") |
| 2738 | " ") | 2753 | " " |
| 2739 | (insert (truncate-string-to-width (or (yas--template-key p) "") | 2754 | (truncate-string-to-width (or (yas--template-key p) "") |
| 2740 | 15 0 ? "...") " ") | 2755 | 15 0 template-key-padding "...") |
| 2741 | (insert (truncate-string-to-width (key-description (yas--template-keybinding p)) | 2756 | (or template-key-padding "") |
| 2742 | 15 0 ? "...") " ") | 2757 | (truncate-string-to-width key-description-string |
| 2743 | (insert "\n")))) | 2758 | 15 0 nil "...") |
| 2759 | "\n")))) | ||
| 2744 | groups-hash))) | 2760 | groups-hash))) |
| 2745 | 2761 | ||
| 2746 | 2762 | ||
| @@ -3056,38 +3072,43 @@ Otherwise delegate to `yas-next-field'." | |||
| 3056 | (yas-next-field)))) | 3072 | (yas-next-field)))) |
| 3057 | (yas-next-field))) | 3073 | (yas-next-field))) |
| 3058 | 3074 | ||
| 3075 | (defun yas-next-field-will-exit-p (&optional arg) | ||
| 3076 | "Return non-nil if (yas-next-field ARG) would exit the current snippet." | ||
| 3077 | (let ((snippet (car (yas--snippets-at-point))) | ||
| 3078 | (active (overlay-get yas--active-field-overlay 'yas--field))) | ||
| 3079 | (when snippet | ||
| 3080 | (not (yas--find-next-field arg snippet active))))) | ||
| 3081 | |||
| 3082 | (defun yas--find-next-field (n snippet active) | ||
| 3083 | "Return the Nth field after the ACTIVE one in SNIPPET." | ||
| 3084 | (let ((live-fields (cl-remove-if | ||
| 3085 | (lambda (field) | ||
| 3086 | (and (not (eq field active)) | ||
| 3087 | (yas--field-probably-deleted-p snippet field))) | ||
| 3088 | (yas--snippet-fields snippet)))) | ||
| 3089 | (if (>= n 0) (nth n (memq active live-fields)) | ||
| 3090 | (car (last (memq active (reverse live-fields)) (- n)))))) | ||
| 3091 | |||
| 3059 | (defun yas-next-field (&optional arg) | 3092 | (defun yas-next-field (&optional arg) |
| 3060 | "Navigate to the ARGth next field. | 3093 | "Navigate to the ARGth next field. |
| 3061 | 3094 | ||
| 3062 | If there's none, exit the snippet." | 3095 | If there's none, exit the snippet." |
| 3063 | (interactive) | 3096 | (interactive) |
| 3064 | (let* ((arg (or arg | 3097 | (unless arg (setq arg 1)) |
| 3065 | 1)) | 3098 | (let* ((snippet (car (yas--snippets-at-point))) |
| 3066 | (snippet (first (yas--snippets-at-point))) | ||
| 3067 | (active-field (overlay-get yas--active-field-overlay 'yas--field)) | 3099 | (active-field (overlay-get yas--active-field-overlay 'yas--field)) |
| 3068 | (live-fields (remove-if #'(lambda (field) | 3100 | (target-field (yas--find-next-field arg snippet active-field))) |
| 3069 | (and (not (eq field active-field)) | 3101 | ;; First check if we're moving out of a field with a transform. |
| 3070 | (yas--field-probably-deleted-p snippet field))) | 3102 | (when (and active-field (yas--field-transform active-field)) |
| 3071 | (yas--snippet-fields snippet))) | ||
| 3072 | (active-field-pos (position active-field live-fields)) | ||
| 3073 | (target-pos (and active-field-pos (+ arg active-field-pos))) | ||
| 3074 | (target-field (and target-pos (nth target-pos live-fields)))) | ||
| 3075 | ;; First check if we're moving out of a field with a transform | ||
| 3076 | ;; | ||
| 3077 | (when (and active-field | ||
| 3078 | (yas--field-transform active-field)) | ||
| 3079 | (let* ((yas-moving-away-p t) | 3103 | (let* ((yas-moving-away-p t) |
| 3080 | (yas-text (yas--field-text-for-display active-field)) | 3104 | (yas-text (yas--field-text-for-display active-field)) |
| 3081 | (yas-modified-p (yas--field-modified-p active-field))) | 3105 | (yas-modified-p (yas--field-modified-p active-field))) |
| 3082 | ;; primary field transform: exit call to field-transform | 3106 | ;; primary field transform: exit call to field-transform |
| 3083 | (yas--eval-lisp (yas--field-transform active-field)))) | 3107 | (yas--eval-lisp (yas--field-transform active-field)))) |
| 3084 | ;; Now actually move... | 3108 | ;; Now actually move... |
| 3085 | (cond ((and target-pos (>= target-pos (length live-fields))) | 3109 | (if target-field |
| 3086 | (yas-exit-snippet snippet)) | 3110 | (yas--move-to-field snippet target-field) |
| 3087 | (target-field | 3111 | (yas-exit-snippet snippet)))) |
| 3088 | (yas--move-to-field snippet target-field)) | ||
| 3089 | (t | ||
| 3090 | nil)))) | ||
| 3091 | 3112 | ||
| 3092 | (defun yas--place-overlays (snippet field) | 3113 | (defun yas--place-overlays (snippet field) |
| 3093 | "Correctly place overlays for SNIPPET's FIELD." | 3114 | "Correctly place overlays for SNIPPET's FIELD." |
| @@ -3341,15 +3362,17 @@ Otherwise deletes a character normally by calling `delete-char'." | |||
| 3341 | (t | 3362 | (t |
| 3342 | (call-interactively 'delete-char))))) | 3363 | (call-interactively 'delete-char))))) |
| 3343 | 3364 | ||
| 3344 | (defun yas--skip-and-clear (field) | 3365 | (defun yas--skip-and-clear (field &optional from) |
| 3345 | "Deletes the region of FIELD and sets it's modified state to t." | 3366 | "Deletes the region of FIELD and sets it's modified state to t. |
| 3367 | If given, FROM indicates position to start at instead of FIELD's beginning." | ||
| 3346 | ;; Just before skipping-and-clearing the field, mark its children | 3368 | ;; Just before skipping-and-clearing the field, mark its children |
| 3347 | ;; fields as modified, too. If the children have mirrors-in-fields | 3369 | ;; fields as modified, too. If the children have mirrors-in-fields |
| 3348 | ;; this prevents them from updating erroneously (we're skipping and | 3370 | ;; this prevents them from updating erroneously (we're skipping and |
| 3349 | ;; deleting!). | 3371 | ;; deleting!). |
| 3350 | ;; | 3372 | ;; |
| 3351 | (yas--mark-this-and-children-modified field) | 3373 | (yas--mark-this-and-children-modified field) |
| 3352 | (delete-region (yas--field-start field) (yas--field-end field))) | 3374 | (unless (= (yas--field-start field) (yas--field-end field)) |
| 3375 | (delete-region (or from (yas--field-start field)) (yas--field-end field)))) | ||
| 3353 | 3376 | ||
| 3354 | (defun yas--mark-this-and-children-modified (field) | 3377 | (defun yas--mark-this-and-children-modified (field) |
| 3355 | (setf (yas--field-modified-p field) t) | 3378 | (setf (yas--field-modified-p field) t) |
| @@ -3383,40 +3406,33 @@ Move the overlay, or create it if it does not exit." | |||
| 3383 | (overlay-put yas--active-field-overlay 'insert-behind-hooks | 3406 | (overlay-put yas--active-field-overlay 'insert-behind-hooks |
| 3384 | '(yas--on-field-overlay-modification)))) | 3407 | '(yas--on-field-overlay-modification)))) |
| 3385 | 3408 | ||
| 3386 | (defun yas--skip-and-clear-field-p (field _beg _end &optional _length) | 3409 | (defun yas--skip-and-clear-field-p (field beg _end length) |
| 3387 | "Tell if newly modified FIELD should be cleared and skipped. | 3410 | "Tell if newly modified FIELD should be cleared and skipped. |
| 3388 | BEG, END and LENGTH like overlay modification hooks." | 3411 | BEG, END and LENGTH like overlay modification hooks." |
| 3389 | (and (not (yas--field-modified-p field)) | 3412 | (and (= length 0) ; A 0 pre-change length indicates insertion. |
| 3390 | (= (point) (yas--field-start field)) | 3413 | (= beg (yas--field-start field)) ; Insertion at field start? |
| 3391 | (require 'delsel) | 3414 | (not (yas--field-modified-p field)))) |
| 3392 | ;; `yank' sets `this-command' to t during execution. | ||
| 3393 | (let* ((command (if (commandp this-command) this-command | ||
| 3394 | this-original-command)) | ||
| 3395 | (clearp (if (symbolp command) (get command 'delete-selection)))) | ||
| 3396 | (when (and (not (memq clearp '(yank supersede kill))) | ||
| 3397 | (functionp clearp)) | ||
| 3398 | (setq clearp (funcall clearp))) | ||
| 3399 | clearp))) | ||
| 3400 | 3415 | ||
| 3401 | (defun yas--on-field-overlay-modification (overlay after? beg end &optional length) | 3416 | (defun yas--on-field-overlay-modification (overlay after? beg end &optional length) |
| 3402 | "Clears the field and updates mirrors, conditionally. | 3417 | "Clears the field and updates mirrors, conditionally. |
| 3403 | 3418 | ||
| 3404 | Only clears the field if it hasn't been modified and point is at | 3419 | Only clears the field if it hasn't been modified and point is at |
| 3405 | field start. This hook does nothing if an undo is in progress." | 3420 | field start. This hook does nothing if an undo is in progress." |
| 3406 | (unless (or yas--inhibit-overlay-hooks | 3421 | (unless (or (not after?) |
| 3422 | yas--inhibit-overlay-hooks | ||
| 3407 | (not (overlayp yas--active-field-overlay)) ; Avoid Emacs bug #21824. | 3423 | (not (overlayp yas--active-field-overlay)) ; Avoid Emacs bug #21824. |
| 3408 | (yas--undo-in-progress)) | 3424 | (yas--undo-in-progress)) |
| 3409 | (let* ((field (overlay-get overlay 'yas--field)) | 3425 | (let* ((inhibit-modification-hooks t) |
| 3426 | (field (overlay-get overlay 'yas--field)) | ||
| 3410 | (snippet (overlay-get yas--active-field-overlay 'yas--snippet))) | 3427 | (snippet (overlay-get yas--active-field-overlay 'yas--snippet))) |
| 3411 | (cond (after? | 3428 | (when (yas--skip-and-clear-field-p field beg end length) |
| 3412 | (yas--advance-end-maybe field (overlay-end overlay)) | 3429 | ;; We delete text starting from the END of insertion. |
| 3413 | (save-excursion | 3430 | (yas--skip-and-clear field end)) |
| 3414 | (yas--field-update-display field)) | 3431 | (setf (yas--field-modified-p field) t) |
| 3415 | (yas--update-mirrors snippet)) | 3432 | (yas--advance-end-maybe field (overlay-end overlay)) |
| 3416 | (field | 3433 | (save-excursion |
| 3417 | (when (yas--skip-and-clear-field-p field beg end) | 3434 | (yas--field-update-display field)) |
| 3418 | (yas--skip-and-clear field)) | 3435 | (yas--update-mirrors snippet)))) |
| 3419 | (setf (yas--field-modified-p field) t)))))) | ||
| 3420 | 3436 | ||
| 3421 | ;;; Apropos protection overlays: | 3437 | ;;; Apropos protection overlays: |
| 3422 | ;; | 3438 | ;; |
| @@ -3460,12 +3476,11 @@ Move the overlays, or create them if they do not exit." | |||
| 3460 | ;; (overlay-put ov 'evaporate t) | 3476 | ;; (overlay-put ov 'evaporate t) |
| 3461 | (overlay-put ov 'modification-hooks '(yas--on-protection-overlay-modification))))))) | 3477 | (overlay-put ov 'modification-hooks '(yas--on-protection-overlay-modification))))))) |
| 3462 | 3478 | ||
| 3463 | (defun yas--on-protection-overlay-modification (_overlay after? _beg _end &optional _length) | 3479 | (defun yas--on-protection-overlay-modification (_overlay after? beg end &optional length) |
| 3464 | "Signals a snippet violation, then issues error. | 3480 | "Commit the snippet if the protection overlay is being killed." |
| 3465 | |||
| 3466 | The error should be ignored in `debug-ignored-errors'" | ||
| 3467 | (unless (or yas--inhibit-overlay-hooks | 3481 | (unless (or yas--inhibit-overlay-hooks |
| 3468 | after? | 3482 | (not after?) |
| 3483 | (= length (- end beg)) ; deletion or insertion | ||
| 3469 | (yas--undo-in-progress)) | 3484 | (yas--undo-in-progress)) |
| 3470 | (let ((snippets (yas--snippets-at-point))) | 3485 | (let ((snippets (yas--snippets-at-point))) |
| 3471 | (yas--message 3 "Comitting snippets. Action would destroy a protection overlay.") | 3486 | (yas--message 3 "Comitting snippets. Action would destroy a protection overlay.") |
| @@ -3847,7 +3862,22 @@ Meant to be called in a narrowed buffer, does various passes" | |||
| 3847 | (yas--calculate-adjacencies snippet) | 3862 | (yas--calculate-adjacencies snippet) |
| 3848 | ;; Delete $-constructs | 3863 | ;; Delete $-constructs |
| 3849 | ;; | 3864 | ;; |
| 3850 | (save-restriction (widen) (yas--delete-regions yas--dollar-regions)) | 3865 | (save-restriction |
| 3866 | (widen) | ||
| 3867 | (yas--delete-regions yas--dollar-regions)) | ||
| 3868 | ;; Make sure to do this insertion *after* deleting the dollar | ||
| 3869 | ;; regions, otherwise we invalidate the calculated positions of | ||
| 3870 | ;; all the fields following $0. | ||
| 3871 | (let ((exit (yas--snippet-exit snippet))) | ||
| 3872 | (goto-char (if exit (yas--exit-marker exit) (point-max)))) | ||
| 3873 | (when (eq yas-wrap-around-region 'cua) | ||
| 3874 | (setq yas-wrap-around-region ?0)) | ||
| 3875 | (cond ((and yas-wrap-around-region yas-selected-text) | ||
| 3876 | (insert yas-selected-text)) | ||
| 3877 | ((and (characterp yas-wrap-around-region) | ||
| 3878 | (get-register yas-wrap-around-region)) | ||
| 3879 | (insert (prog1 (get-register yas-wrap-around-region) | ||
| 3880 | (set-register yas-wrap-around-region nil))))) | ||
| 3851 | ;; restore backquoted expression values | 3881 | ;; restore backquoted expression values |
| 3852 | ;; | 3882 | ;; |
| 3853 | (yas--restore-backquotes) | 3883 | (yas--restore-backquotes) |
| @@ -3863,8 +3893,9 @@ Meant to be called in a narrowed buffer, does various passes" | |||
| 3863 | (goto-char parse-start) | 3893 | (goto-char parse-start) |
| 3864 | (yas--indent snippet))) | 3894 | (yas--indent snippet))) |
| 3865 | 3895 | ||
| 3866 | (defun yas--indent-according-to-mode (snippet-markers) | 3896 | (defun yas--indent-region (from to snippet) |
| 3867 | "Indent current line according to mode, preserving SNIPPET-MARKERS." | 3897 | "Indent the lines between FROM and TO with `indent-according-to-mode'. |
| 3898 | The SNIPPET's markers are preserved." | ||
| 3868 | ;;; Apropos indenting problems.... | 3899 | ;;; Apropos indenting problems.... |
| 3869 | ;; | 3900 | ;; |
| 3870 | ;; `indent-according-to-mode' uses whatever `indent-line-function' | 3901 | ;; `indent-according-to-mode' uses whatever `indent-line-function' |
| @@ -3877,54 +3908,50 @@ Meant to be called in a narrowed buffer, does various passes" | |||
| 3877 | ;; `front-advance' property set to nil. | 3908 | ;; `front-advance' property set to nil. |
| 3878 | ;; | 3909 | ;; |
| 3879 | ;; This is why I have these `trouble-markers', they are the ones at | 3910 | ;; This is why I have these `trouble-markers', they are the ones at |
| 3880 | ;; they are the ones at the first non-whitespace char at the line | 3911 | ;; the first non-whitespace char at the line. After indentation |
| 3881 | ;; (i.e. at `yas--real-line-beginning'. After indentation takes place | 3912 | ;; takes place we should be at the correct to restore them. All |
| 3882 | ;; we should be at the correct to restore them to. All other | 3913 | ;; other non-trouble-markers should have been *pushed* and don't |
| 3883 | ;; non-trouble-markers have been *pushed* and don't need special | 3914 | ;; need special attention. |
| 3884 | ;; attention. | 3915 | (let* ((snippet-markers (yas--collect-snippet-markers snippet)) |
| 3885 | ;; | 3916 | (to (set-marker (make-marker) to))) |
| 3886 | (goto-char (yas--real-line-beginning)) | 3917 | (save-excursion |
| 3887 | (let ((trouble-markers (remove-if-not #'(lambda (marker) | 3918 | (goto-char from) |
| 3888 | (= marker (point))) | 3919 | (save-restriction |
| 3889 | snippet-markers))) | 3920 | (widen) |
| 3890 | (save-restriction | 3921 | (cl-loop do |
| 3891 | (widen) | 3922 | (back-to-indentation) |
| 3892 | (condition-case _ | 3923 | (let ((trouble-markers ; The markers at (point). |
| 3893 | (indent-according-to-mode) | 3924 | (cl-remove (point) snippet-markers :test #'/=))) |
| 3894 | (error (yas--message 3 "Warning: `yas--indent-according-to-mode' having problems running %s" indent-line-function) | 3925 | (unwind-protect |
| 3895 | nil))) | 3926 | (indent-according-to-mode) |
| 3896 | (mapc #'(lambda (marker) | 3927 | (dolist (marker trouble-markers) |
| 3897 | (set-marker marker (point))) | 3928 | (set-marker marker (point))))) |
| 3898 | trouble-markers))) | 3929 | while (and (zerop (forward-line 1)) |
| 3930 | (< (point) to))))))) | ||
| 3899 | 3931 | ||
| 3900 | (defvar yas--indent-original-column nil) | 3932 | (defvar yas--indent-original-column nil) |
| 3901 | (defun yas--indent (snippet) | 3933 | (defun yas--indent (snippet) |
| 3902 | (let ((snippet-markers (yas--collect-snippet-markers snippet))) | 3934 | ;; Look for those `$>'. |
| 3903 | ;; Look for those $> | 3935 | (save-excursion |
| 3904 | (save-excursion | 3936 | (while (re-search-forward "$>" nil t) |
| 3905 | (while (re-search-forward "$>" nil t) | 3937 | (delete-region (match-beginning 0) (match-end 0)) |
| 3906 | (delete-region (match-beginning 0) (match-end 0)) | 3938 | (unless (eq yas-indent-line 'auto) |
| 3907 | (when (not (eq yas-indent-line 'auto)) | 3939 | (yas--indent-region (line-beginning-position) |
| 3908 | (yas--indent-according-to-mode snippet-markers)))) | 3940 | (line-end-position) |
| 3909 | ;; Now do stuff for 'fixed and 'auto | 3941 | snippet)))) |
| 3910 | (save-excursion | 3942 | ;; Now do stuff for `fixed' and `auto'. |
| 3911 | (cond ((eq yas-indent-line 'fixed) | 3943 | (save-excursion |
| 3912 | (while (and (zerop (forward-line)) | 3944 | (cond ((eq yas-indent-line 'fixed) |
| 3913 | (zerop (current-column))) | 3945 | (while (and (zerop (forward-line)) |
| 3914 | (indent-to-column yas--indent-original-column))) | 3946 | (zerop (current-column))) |
| 3915 | ((eq yas-indent-line 'auto) | 3947 | (indent-to-column yas--indent-original-column))) |
| 3916 | (let ((end (set-marker (make-marker) (point-max))) | 3948 | ((eq yas-indent-line 'auto) |
| 3917 | (indent-first-line-p yas-also-auto-indent-first-line)) | 3949 | (let ((end (set-marker (make-marker) (point-max)))) |
| 3918 | (while (and (zerop (if indent-first-line-p | 3950 | (unless yas-also-auto-indent-first-line |
| 3919 | (prog1 | 3951 | (forward-line 1)) |
| 3920 | (forward-line 0) | 3952 | (yas--indent-region (line-beginning-position) |
| 3921 | (setq indent-first-line-p nil)) | 3953 | (point-max) |
| 3922 | (forward-line 1))) | 3954 | snippet)))))) |
| 3923 | (not (eobp)) | ||
| 3924 | (<= (point) end)) | ||
| 3925 | (yas--indent-according-to-mode snippet-markers)))) | ||
| 3926 | (t | ||
| 3927 | nil))))) | ||
| 3928 | 3955 | ||
| 3929 | (defun yas--collect-snippet-markers (snippet) | 3956 | (defun yas--collect-snippet-markers (snippet) |
| 3930 | "Make a list of all the markers used by SNIPPET." | 3957 | "Make a list of all the markers used by SNIPPET." |
| @@ -3941,15 +3968,6 @@ Meant to be called in a narrowed buffer, does various passes" | |||
| 3941 | (push (yas--exit-marker snippet-exit) markers))) | 3968 | (push (yas--exit-marker snippet-exit) markers))) |
| 3942 | markers)) | 3969 | markers)) |
| 3943 | 3970 | ||
| 3944 | (defun yas--real-line-beginning () | ||
| 3945 | (let ((c (char-after (line-beginning-position))) | ||
| 3946 | (n (line-beginning-position))) | ||
| 3947 | (while (or (eql c ?\ ) | ||
| 3948 | (eql c ?\t)) | ||
| 3949 | (cl-incf n) | ||
| 3950 | (setq c (char-after n))) | ||
| 3951 | n)) | ||
| 3952 | |||
| 3953 | (defun yas--escape-string (escaped) | 3971 | (defun yas--escape-string (escaped) |
| 3954 | (concat "YASESCAPE" (format "%d" escaped) "PROTECTGUARD")) | 3972 | (concat "YASESCAPE" (format "%d" escaped) "PROTECTGUARD")) |
| 3955 | 3973 | ||
| @@ -4128,21 +4146,10 @@ When multiple expressions are found, only the last one counts." | |||
| 4128 | (while (re-search-forward yas--simple-mirror-regexp nil t) | 4146 | (while (re-search-forward yas--simple-mirror-regexp nil t) |
| 4129 | (let ((number (string-to-number (match-string-no-properties 1)))) | 4147 | (let ((number (string-to-number (match-string-no-properties 1)))) |
| 4130 | (cond ((zerop number) | 4148 | (cond ((zerop number) |
| 4131 | |||
| 4132 | (setf (yas--snippet-exit snippet) | 4149 | (setf (yas--snippet-exit snippet) |
| 4133 | (yas--make-exit (yas--make-marker (match-end 0)))) | 4150 | (yas--make-exit (yas--make-marker (match-end 0)))) |
| 4134 | (save-excursion | 4151 | (push (cons (match-beginning 0) (yas--exit-marker (yas--snippet-exit snippet))) |
| 4135 | (goto-char (match-beginning 0)) | 4152 | yas--dollar-regions)) |
| 4136 | (when yas-wrap-around-region | ||
| 4137 | (cond (yas-selected-text | ||
| 4138 | (insert yas-selected-text)) | ||
| 4139 | ((and (eq yas-wrap-around-region 'cua) | ||
| 4140 | cua-mode | ||
| 4141 | (get-register ?0)) | ||
| 4142 | (insert (prog1 (get-register ?0) | ||
| 4143 | (set-register ?0 nil)))))) | ||
| 4144 | (push (cons (point) (yas--exit-marker (yas--snippet-exit snippet))) | ||
| 4145 | yas--dollar-regions))) | ||
| 4146 | (t | 4153 | (t |
| 4147 | (let ((field (yas--snippet-find-field snippet number))) | 4154 | (let ((field (yas--snippet-find-field snippet number))) |
| 4148 | (if field | 4155 | (if field |
| @@ -4191,43 +4198,45 @@ When multiple expressions are found, only the last one counts." | |||
| 4191 | 4198 | ||
| 4192 | (defun yas--update-mirrors (snippet) | 4199 | (defun yas--update-mirrors (snippet) |
| 4193 | "Update all the mirrors of SNIPPET." | 4200 | "Update all the mirrors of SNIPPET." |
| 4194 | (save-excursion | 4201 | (save-restriction |
| 4195 | (dolist (field-and-mirror (sort | 4202 | (widen) |
| 4196 | ;; make a list of ((F1 . M1) (F1 . M2) (F2 . M3) (F2 . M4) ...) | 4203 | (save-excursion |
| 4197 | ;; where F is the field that M is mirroring | 4204 | (dolist (field-and-mirror |
| 4198 | ;; | 4205 | (sort |
| 4199 | (mapcan #'(lambda (field) | 4206 | ;; make a list of ((F1 . M1) (F1 . M2) (F2 . M3) (F2 . M4) ...) |
| 4200 | (mapcar #'(lambda (mirror) | 4207 | ;; where F is the field that M is mirroring |
| 4201 | (cons field mirror)) | 4208 | ;; |
| 4202 | (yas--field-mirrors field))) | 4209 | (cl-mapcan #'(lambda (field) |
| 4203 | (yas--snippet-fields snippet)) | 4210 | (mapcar #'(lambda (mirror) |
| 4204 | ;; then sort this list so that entries with mirrors with parent | 4211 | (cons field mirror)) |
| 4205 | ;; fields appear before. This was important for fixing #290, and | 4212 | (yas--field-mirrors field))) |
| 4206 | ;; luckily also handles the case where a mirror in a field causes | 4213 | (yas--snippet-fields snippet)) |
| 4207 | ;; another mirror to need reupdating | 4214 | ;; then sort this list so that entries with mirrors with parent |
| 4208 | ;; | 4215 | ;; fields appear before. This was important for fixing #290, and |
| 4209 | #'(lambda (field-and-mirror1 field-and-mirror2) | 4216 | ;; luckily also handles the case where a mirror in a field causes |
| 4210 | (> (yas--calculate-mirror-depth (cdr field-and-mirror1)) | 4217 | ;; another mirror to need reupdating |
| 4211 | (yas--calculate-mirror-depth (cdr field-and-mirror2)))))) | 4218 | ;; |
| 4212 | (let* ((field (car field-and-mirror)) | 4219 | #'(lambda (field-and-mirror1 field-and-mirror2) |
| 4213 | (mirror (cdr field-and-mirror)) | 4220 | (> (yas--calculate-mirror-depth (cdr field-and-mirror1)) |
| 4214 | (parent-field (yas--mirror-parent-field mirror))) | 4221 | (yas--calculate-mirror-depth (cdr field-and-mirror2)))))) |
| 4215 | ;; before updating a mirror with a parent-field, maybe advance | 4222 | (let* ((field (car field-and-mirror)) |
| 4216 | ;; its start (#290) | 4223 | (mirror (cdr field-and-mirror)) |
| 4217 | ;; | 4224 | (parent-field (yas--mirror-parent-field mirror))) |
| 4218 | (when parent-field | 4225 | ;; before updating a mirror with a parent-field, maybe advance |
| 4219 | (yas--advance-start-maybe mirror (yas--fom-start parent-field))) | 4226 | ;; its start (#290) |
| 4220 | ;; update this mirror | 4227 | ;; |
| 4221 | ;; | 4228 | (when parent-field |
| 4222 | (yas--mirror-update-display mirror field) | 4229 | (yas--advance-start-maybe mirror (yas--fom-start parent-field))) |
| 4223 | ;; `yas--place-overlays' is needed if the active field and | 4230 | ;; update this mirror |
| 4224 | ;; protected overlays have been changed because of insertions | 4231 | ;; |
| 4225 | ;; in `yas--mirror-update-display' | 4232 | (yas--mirror-update-display mirror field snippet) |
| 4226 | ;; | 4233 | ;; `yas--place-overlays' is needed since the active field and |
| 4227 | (when (eq field (yas--snippet-active-field snippet)) | 4234 | ;; protected overlays might have been changed because of insertions |
| 4228 | (yas--place-overlays snippet field)))))) | 4235 | ;; in `yas--mirror-update-display'. |
| 4236 | (let ((active-field (yas--snippet-active-field snippet))) | ||
| 4237 | (when active-field (yas--place-overlays snippet active-field)))))))) | ||
| 4229 | 4238 | ||
| 4230 | (defun yas--mirror-update-display (mirror field) | 4239 | (defun yas--mirror-update-display (mirror field snippet) |
| 4231 | "Update MIRROR according to FIELD (and mirror transform)." | 4240 | "Update MIRROR according to FIELD (and mirror transform)." |
| 4232 | 4241 | ||
| 4233 | (let* ((mirror-parent-field (yas--mirror-parent-field mirror)) | 4242 | (let* ((mirror-parent-field (yas--mirror-parent-field mirror)) |
| @@ -4246,7 +4255,11 @@ When multiple expressions are found, only the last one counts." | |||
| 4246 | (set-marker (yas--mirror-end mirror) (point)) | 4255 | (set-marker (yas--mirror-end mirror) (point)) |
| 4247 | (yas--advance-start-maybe (yas--mirror-next mirror) (point)) | 4256 | (yas--advance-start-maybe (yas--mirror-next mirror) (point)) |
| 4248 | ;; super-special advance | 4257 | ;; super-special advance |
| 4249 | (yas--advance-end-of-parents-maybe mirror-parent-field (point)))))) | 4258 | (yas--advance-end-of-parents-maybe mirror-parent-field (point))) |
| 4259 | (let ((yas--inhibit-overlay-hooks t)) | ||
| 4260 | (yas--indent-region (yas--mirror-start mirror) | ||
| 4261 | (yas--mirror-end mirror) | ||
| 4262 | snippet))))) | ||
| 4250 | 4263 | ||
| 4251 | (defun yas--field-update-display (field) | 4264 | (defun yas--field-update-display (field) |
| 4252 | "Much like `yas--mirror-update-display', but for fields." | 4265 | "Much like `yas--mirror-update-display', but for fields." |
| @@ -4320,7 +4333,7 @@ object satisfying `yas--field-p' to restrict the expansion to."))) | |||
| 4320 | '(yas--expand-from-keymap-doc t)) | 4333 | '(yas--expand-from-keymap-doc t)) |
| 4321 | (defun yas--expand-from-keymap-doc (context) | 4334 | (defun yas--expand-from-keymap-doc (context) |
| 4322 | "A doc synthesizer for `yas--expand-from-keymap-doc'." | 4335 | "A doc synthesizer for `yas--expand-from-keymap-doc'." |
| 4323 | (add-hook 'temp-buffer-show-hook 'yas--snippet-description-finish-runonce) | 4336 | (add-hook 'temp-buffer-show-hook #'yas--snippet-description-finish-runonce) |
| 4324 | (concat "Expand/run snippets from keymaps, possibly falling back to original binding.\n" | 4337 | (concat "Expand/run snippets from keymaps, possibly falling back to original binding.\n" |
| 4325 | (when (and context (eq this-command 'describe-key)) | 4338 | (when (and context (eq this-command 'describe-key)) |
| 4326 | (let* ((vec (this-single-command-keys)) | 4339 | (let* ((vec (this-single-command-keys)) |
| @@ -4355,7 +4368,8 @@ object satisfying `yas--field-p' to restrict the expansion to."))) | |||
| 4355 | (defun yas--snippet-description-finish-runonce () | 4368 | (defun yas--snippet-description-finish-runonce () |
| 4356 | "Final adjustments for the help buffer when snippets are concerned." | 4369 | "Final adjustments for the help buffer when snippets are concerned." |
| 4357 | (yas--create-snippet-xrefs) | 4370 | (yas--create-snippet-xrefs) |
| 4358 | (remove-hook 'temp-buffer-show-hook 'yas--snippet-description-finish-runonce)) | 4371 | (remove-hook 'temp-buffer-show-hook |
| 4372 | #'yas--snippet-description-finish-runonce)) | ||
| 4359 | 4373 | ||
| 4360 | (defun yas--create-snippet-xrefs () | 4374 | (defun yas--create-snippet-xrefs () |
| 4361 | (save-excursion | 4375 | (save-excursion |
| @@ -4365,8 +4379,8 @@ object satisfying `yas--field-p' to restrict the expansion to."))) | |||
| 4365 | 'yasnippet))) | 4379 | 'yasnippet))) |
| 4366 | (when template | 4380 | (when template |
| 4367 | (help-xref-button 1 'help-snippet-def template) | 4381 | (help-xref-button 1 'help-snippet-def template) |
| 4368 | (kill-region (match-end 1) (match-end 0)) | 4382 | (delete-region (match-end 1) (match-end 0)) |
| 4369 | (kill-region (match-beginning 0) (match-beginning 1))))))) | 4383 | (delete-region (match-beginning 0) (match-beginning 1))))))) |
| 4370 | 4384 | ||
| 4371 | ;;; Utils | 4385 | ;;; Utils |
| 4372 | 4386 | ||
| @@ -4562,7 +4576,7 @@ and return the directory. Return nil if not found." | |||
| 4562 | They are mapped to \"yas/*\" variants.") | 4576 | They are mapped to \"yas/*\" variants.") |
| 4563 | 4577 | ||
| 4564 | (dolist (sym yas--backported-syms) | 4578 | (dolist (sym yas--backported-syms) |
| 4565 | (let ((backported (intern (replace-regexp-in-string "^yas-" "yas/" (symbol-name sym))))) | 4579 | (let ((backported (intern (replace-regexp-in-string "\\`yas-" "yas/" (symbol-name sym))))) |
| 4566 | (when (boundp sym) | 4580 | (when (boundp sym) |
| 4567 | (make-obsolete-variable backported sym "yasnippet 0.8") | 4581 | (make-obsolete-variable backported sym "yasnippet 0.8") |
| 4568 | (defvaralias backported sym)) | 4582 | (defvaralias backported sym)) |
| @@ -4577,7 +4591,7 @@ They are mapped to \"yas/*\" variants.") | |||
| 4577 | (not (get atom 'byte-obsolete-variable))) | 4591 | (not (get atom 'byte-obsolete-variable))) |
| 4578 | (and (fboundp atom) | 4592 | (and (fboundp atom) |
| 4579 | (not (get atom 'byte-obsolete-info)))) | 4593 | (not (get atom 'byte-obsolete-info)))) |
| 4580 | (string-match-p "^yas-[^-]" (symbol-name atom))) | 4594 | (string-match-p "\\`yas-[^-]" (symbol-name atom))) |
| 4581 | (push atom exported)))) | 4595 | (push atom exported)))) |
| 4582 | exported) | 4596 | exported) |
| 4583 | "Exported yasnippet symbols. | 4597 | "Exported yasnippet symbols. |
