diff options
Diffstat (limited to '.emacs.d/lisp')
| -rw-r--r-- | .emacs.d/lisp/php-mode.el | 25 | ||||
| -rw-r--r-- | .emacs.d/lisp/yasnippet.el | 621 |
2 files changed, 330 insertions, 316 deletions
diff --git a/.emacs.d/lisp/php-mode.el b/.emacs.d/lisp/php-mode.el index 9aae782..89fc073 100644 --- a/.emacs.d/lisp/php-mode.el +++ b/.emacs.d/lisp/php-mode.el | |||
| @@ -12,7 +12,7 @@ | |||
| 12 | (defconst php-mode-version-number "1.17.0" | 12 | (defconst php-mode-version-number "1.17.0" |
| 13 | "PHP Mode version number.") | 13 | "PHP Mode version number.") |
| 14 | 14 | ||
| 15 | (defconst php-mode-modified "2016-03-06" | 15 | (defconst php-mode-modified "2016-08-22" |
| 16 | "PHP Mode build date.") | 16 | "PHP Mode build date.") |
| 17 | 17 | ||
| 18 | ;;; License | 18 | ;;; License |
| @@ -93,11 +93,29 @@ | |||
| 93 | (if (and (= emacs-major-version 24) (>= emacs-minor-version 4)) | 93 | (if (and (= emacs-major-version 24) (>= emacs-minor-version 4)) |
| 94 | (require 'cl))) | 94 | (require 'cl))) |
| 95 | 95 | ||
| 96 | ;; Work around https://github.com/ejmr/php-mode/issues/310. | ||
| 97 | ;; | ||
| 98 | ;; In emacs 24.4 and 24.5, lines after functions with a return type | ||
| 99 | ;; are incorrectly analyzed as member-init-cont. | ||
| 100 | ;; | ||
| 101 | ;; Before emacs 24.4, c member initializers are not supported this | ||
| 102 | ;; way. Starting from emacs 25.1, cc-mode only detects member | ||
| 103 | ;; initializers when the major mode is c++-mode. | ||
| 104 | (eval-and-compile | ||
| 105 | (if (and (= emacs-major-version 24) (or (= emacs-minor-version 4) | ||
| 106 | (= emacs-minor-version 5))) | ||
| 107 | (defun c-back-over-member-initializers () | ||
| 108 | ;; Override of cc-engine.el, cc-mode in emacs 24.4 and 24.5 are too | ||
| 109 | ;; optimistic in recognizing c member initializers. Since we don't | ||
| 110 | ;; need it in php-mode, just return nil. | ||
| 111 | nil))) | ||
| 112 | |||
| 96 | 113 | ||
| 97 | ;; Local variables | 114 | ;; Local variables |
| 98 | ;;;###autoload | 115 | ;;;###autoload |
| 99 | (defgroup php nil | 116 | (defgroup php nil |
| 100 | "Major mode `php-mode' for editing PHP code." | 117 | "Major mode `php-mode' for editing PHP code." |
| 118 | :tag "PHP" | ||
| 101 | :prefix "php-" | 119 | :prefix "php-" |
| 102 | :group 'languages | 120 | :group 'languages |
| 103 | :link '(url-link :tag "Official Site" "https://github.com/ejmr/php-mode") | 121 | :link '(url-link :tag "Official Site" "https://github.com/ejmr/php-mode") |
| @@ -512,6 +530,8 @@ PHP does not have an \"enum\"-like keyword." | |||
| 512 | "and" | 530 | "and" |
| 513 | "array" | 531 | "array" |
| 514 | "callable" | 532 | "callable" |
| 533 | "iterable" | ||
| 534 | "void" | ||
| 515 | "as" | 535 | "as" |
| 516 | "break" | 536 | "break" |
| 517 | "catch all" | 537 | "catch all" |
| @@ -1062,7 +1082,8 @@ PHP heredoc." | |||
| 1062 | 1082 | ||
| 1063 | (when (>= emacs-major-version 25) | 1083 | (when (>= emacs-major-version 25) |
| 1064 | (with-silent-modifications | 1084 | (with-silent-modifications |
| 1065 | (php-syntax-propertize-function (point-min) (point-max))))) | 1085 | (save-excursion |
| 1086 | (php-syntax-propertize-function (point-min) (point-max)))))) | ||
| 1066 | 1087 | ||
| 1067 | 1088 | ||
| 1068 | ;; Define function name completion function | 1089 | ;; Define function name completion function |
diff --git a/.emacs.d/lisp/yasnippet.el b/.emacs.d/lisp/yasnippet.el index 5164754..250f957 100644 --- a/.emacs.d/lisp/yasnippet.el +++ b/.emacs.d/lisp/yasnippet.el | |||
| @@ -131,7 +131,6 @@ | |||
| 131 | 131 | ||
| 132 | ;;; Code: | 132 | ;;; Code: |
| 133 | 133 | ||
| 134 | (require 'cl) | ||
| 135 | (require 'cl-lib) | 134 | (require 'cl-lib) |
| 136 | (require 'easymenu) | 135 | (require 'easymenu) |
| 137 | (require 'help-mode) | 136 | (require 'help-mode) |
| @@ -178,8 +177,6 @@ created with `yas-new-snippet'. " | |||
| 178 | :type '(choice (directory :tag "Single directory") | 177 | :type '(choice (directory :tag "Single directory") |
| 179 | (repeat :tag "List of directories" | 178 | (repeat :tag "List of directories" |
| 180 | (choice (directory) (variable)))) | 179 | (choice (directory) (variable)))) |
| 181 | :group 'yasnippet | ||
| 182 | :require 'yasnippet | ||
| 183 | :set #'(lambda (symbol new) | 180 | :set #'(lambda (symbol new) |
| 184 | (let ((old (and (boundp symbol) | 181 | (let ((old (and (boundp symbol) |
| 185 | (symbol-value symbol)))) | 182 | (symbol-value symbol)))) |
| @@ -207,11 +204,10 @@ created with `yas-new-snippet'. " | |||
| 207 | # name: $1 | 204 | # name: $1 |
| 208 | # key: ${2:${1:$(yas--key-from-desc yas-text)}} | 205 | # key: ${2:${1:$(yas--key-from-desc yas-text)}} |
| 209 | # -- | 206 | # -- |
| 210 | $0`yas-selected-text`" | 207 | $0`(yas-escape-text yas-selected-text)`" |
| 211 | "Default snippet to use when creating a new snippet. | 208 | "Default snippet to use when creating a new snippet. |
| 212 | If nil, don't use any snippet." | 209 | If nil, don't use any snippet." |
| 213 | :type 'string | 210 | :type 'string) |
| 214 | :group 'yasnippet) | ||
| 215 | 211 | ||
| 216 | (defcustom yas-prompt-functions '(yas-dropdown-prompt | 212 | (defcustom yas-prompt-functions '(yas-dropdown-prompt |
| 217 | yas-completing-prompt | 213 | yas-completing-prompt |
| @@ -239,9 +235,8 @@ nil. | |||
| 239 | - To signal that the user quit the prompting process, you can | 235 | - To signal that the user quit the prompting process, you can |
| 240 | signal `quit' with | 236 | signal `quit' with |
| 241 | 237 | ||
| 242 | (signal 'quit \"user quit!\")." | 238 | (signal \\='quit \"user quit!\")." |
| 243 | :type '(repeat function) | 239 | :type '(repeat function)) |
| 244 | :group 'yasnippet) | ||
| 245 | 240 | ||
| 246 | (defcustom yas-indent-line 'auto | 241 | (defcustom yas-indent-line 'auto |
| 247 | "Controls indenting applied to a recent snippet expansion. | 242 | "Controls indenting applied to a recent snippet expansion. |
| @@ -257,28 +252,24 @@ after expansion (the manual per-line \"$>\" indentation still | |||
| 257 | applies)." | 252 | applies)." |
| 258 | :type '(choice (const :tag "Nothing" nothing) | 253 | :type '(choice (const :tag "Nothing" nothing) |
| 259 | (const :tag "Fixed" fixed) | 254 | (const :tag "Fixed" fixed) |
| 260 | (const :tag "Auto" auto)) | 255 | (const :tag "Auto" auto))) |
| 261 | :group 'yasnippet) | ||
| 262 | 256 | ||
| 263 | (defcustom yas-also-auto-indent-first-line nil | 257 | (defcustom yas-also-auto-indent-first-line nil |
| 264 | "Non-nil means also auto indent first line according to mode. | 258 | "Non-nil means also auto indent first line according to mode. |
| 265 | 259 | ||
| 266 | Naturally this is only valid when `yas-indent-line' is `auto'" | 260 | Naturally this is only valid when `yas-indent-line' is `auto'" |
| 267 | :type 'boolean | 261 | :type 'boolean) |
| 268 | :group 'yasnippet) | ||
| 269 | 262 | ||
| 270 | (defcustom yas-snippet-revival t | 263 | (defcustom yas-snippet-revival t |
| 271 | "Non-nil means re-activate snippet fields after undo/redo." | 264 | "Non-nil means re-activate snippet fields after undo/redo." |
| 272 | :type 'boolean | 265 | :type 'boolean) |
| 273 | :group 'yasnippet) | ||
| 274 | 266 | ||
| 275 | (defcustom yas-triggers-in-field nil | 267 | (defcustom yas-triggers-in-field nil |
| 276 | "If non-nil, allow stacked expansions (snippets inside snippets). | 268 | "If non-nil, allow stacked expansions (snippets inside snippets). |
| 277 | 269 | ||
| 278 | Otherwise `yas-next-field-or-maybe-expand' just moves on to the | 270 | Otherwise `yas-next-field-or-maybe-expand' just moves on to the |
| 279 | next field" | 271 | next field" |
| 280 | :type 'boolean | 272 | :type 'boolean) |
| 281 | :group 'yasnippet) | ||
| 282 | 273 | ||
| 283 | (defcustom yas-fallback-behavior 'call-other-command | 274 | (defcustom yas-fallback-behavior 'call-other-command |
| 284 | "How to act when `yas-expand' does *not* expand a snippet. | 275 | "How to act when `yas-expand' does *not* expand a snippet. |
| @@ -294,8 +285,7 @@ next field" | |||
| 294 | COMMAND. If ARGS is non-nil, call COMMAND non-interactively | 285 | COMMAND. If ARGS is non-nil, call COMMAND non-interactively |
| 295 | with ARGS as arguments." | 286 | with ARGS as arguments." |
| 296 | :type '(choice (const :tag "Call previous command" call-other-command) | 287 | :type '(choice (const :tag "Call previous command" call-other-command) |
| 297 | (const :tag "Do nothing" return-nil)) | 288 | (const :tag "Do nothing" return-nil))) |
| 298 | :group 'yasnippet) | ||
| 299 | 289 | ||
| 300 | (defcustom yas-choose-keys-first nil | 290 | (defcustom yas-choose-keys-first nil |
| 301 | "If non-nil, prompt for snippet key first, then for template. | 291 | "If non-nil, prompt for snippet key first, then for template. |
| @@ -303,8 +293,7 @@ next field" | |||
| 303 | Otherwise prompts for all possible snippet names. | 293 | Otherwise prompts for all possible snippet names. |
| 304 | 294 | ||
| 305 | This affects `yas-insert-snippet' and `yas-visit-snippet-file'." | 295 | This affects `yas-insert-snippet' and `yas-visit-snippet-file'." |
| 306 | :type 'boolean | 296 | :type 'boolean) |
| 307 | :group 'yasnippet) | ||
| 308 | 297 | ||
| 309 | (defcustom yas-choose-tables-first nil | 298 | (defcustom yas-choose-tables-first nil |
| 310 | "If non-nil, and multiple eligible snippet tables, prompts user for tables first. | 299 | "If non-nil, and multiple eligible snippet tables, prompts user for tables first. |
| @@ -313,8 +302,7 @@ Otherwise, user chooses between the merging together of all | |||
| 313 | eligible tables. | 302 | eligible tables. |
| 314 | 303 | ||
| 315 | This affects `yas-insert-snippet', `yas-visit-snippet-file'" | 304 | This affects `yas-insert-snippet', `yas-visit-snippet-file'" |
| 316 | :type 'boolean | 305 | :type 'boolean) |
| 317 | :group 'yasnippet) | ||
| 318 | 306 | ||
| 319 | (defcustom yas-use-menu 'abbreviate | 307 | (defcustom yas-use-menu 'abbreviate |
| 320 | "Display a YASnippet menu in the menu bar. | 308 | "Display a YASnippet menu in the menu bar. |
| @@ -327,21 +315,19 @@ menu and the modes set in `yas--extra-modes' are listed. | |||
| 327 | 315 | ||
| 328 | - If set to `full', every submenu is listed | 316 | - If set to `full', every submenu is listed |
| 329 | 317 | ||
| 330 | - If set to `nil', hide the menu. | 318 | - If set to nil, hide the menu. |
| 331 | 319 | ||
| 332 | Any other non-nil value, every submenu is listed." | 320 | Any other non-nil value, every submenu is listed." |
| 333 | :type '(choice (const :tag "Full" full) | 321 | :type '(choice (const :tag "Full" full) |
| 334 | (const :tag "Abbreviate" abbreviate) | 322 | (const :tag "Abbreviate" abbreviate) |
| 335 | (const :tag "No menu" nil)) | 323 | (const :tag "No menu" nil))) |
| 336 | :group 'yasnippet) | ||
| 337 | 324 | ||
| 338 | (defcustom yas-trigger-symbol (or (and (eq window-system 'mac) | 325 | (defcustom yas-trigger-symbol (or (and (eq window-system 'mac) |
| 339 | (ignore-errors | 326 | (ignore-errors |
| 340 | (char-to-string ?\x21E5))) ;; little ->| sign | 327 | (char-to-string ?\x21E5))) ;; little ->| sign |
| 341 | " =>") | 328 | " =>") |
| 342 | "The text that will be used in menu to represent the trigger." | 329 | "The text that will be used in menu to represent the trigger." |
| 343 | :type 'string | 330 | :type 'string) |
| 344 | :group 'yasnippet) | ||
| 345 | 331 | ||
| 346 | (defcustom yas-wrap-around-region nil | 332 | (defcustom yas-wrap-around-region nil |
| 347 | "What to insert for snippet's $0 field. | 333 | "What to insert for snippet's $0 field. |
| @@ -353,22 +339,19 @@ per-snippet basis. A value of `cua' is considered equivalent to | |||
| 353 | :type '(choice (character :tag "Insert from register") | 339 | :type '(choice (character :tag "Insert from register") |
| 354 | (const t :tag "Insert region contents") | 340 | (const t :tag "Insert region contents") |
| 355 | (const nil :tag "Don't insert anything") | 341 | (const nil :tag "Don't insert anything") |
| 356 | (const cua)) ; backwards compat | 342 | (const cua))) ; backwards compat |
| 357 | :group 'yasnippet) | ||
| 358 | 343 | ||
| 359 | (defcustom yas-good-grace t | 344 | (defcustom yas-good-grace t |
| 360 | "If non-nil, don't raise errors in inline elisp evaluation. | 345 | "If non-nil, don't raise errors in inline elisp evaluation. |
| 361 | 346 | ||
| 362 | An error string \"[yas] error\" is returned instead." | 347 | An error string \"[yas] error\" is returned instead." |
| 363 | :type 'boolean | 348 | :type 'boolean) |
| 364 | :group 'yasnippet) | ||
| 365 | 349 | ||
| 366 | (defcustom yas-visit-from-menu nil | 350 | (defcustom yas-visit-from-menu nil |
| 367 | "If non-nil visit snippets's files from menu, instead of expanding them. | 351 | "If non-nil visit snippets's files from menu, instead of expanding them. |
| 368 | 352 | ||
| 369 | This can only work when snippets are loaded from files." | 353 | This can only work when snippets are loaded from files." |
| 370 | :type 'boolean | 354 | :type 'boolean) |
| 371 | :group 'yasnippet) | ||
| 372 | 355 | ||
| 373 | (defcustom yas-expand-only-for-last-commands nil | 356 | (defcustom yas-expand-only-for-last-commands nil |
| 374 | "List of `last-command' values to restrict tab-triggering to, or nil. | 357 | "List of `last-command' values to restrict tab-triggering to, or nil. |
| @@ -377,12 +360,11 @@ Leave this set at nil (the default) to be able to trigger an | |||
| 377 | expansion simply by placing the cursor after a valid tab trigger, | 360 | expansion simply by placing the cursor after a valid tab trigger, |
| 378 | using whichever commands. | 361 | using whichever commands. |
| 379 | 362 | ||
| 380 | Optionally, set this to something like '(self-insert-command) if | 363 | Optionally, set this to something like (self-insert-command) if |
| 381 | you to wish restrict expansion to only happen when the last | 364 | you to wish restrict expansion to only happen when the last |
| 382 | letter of the snippet tab trigger was typed immediately before | 365 | letter of the snippet tab trigger was typed immediately before |
| 383 | the trigger key itself." | 366 | the trigger key itself." |
| 384 | :type '(repeat function) | 367 | :type '(repeat function)) |
| 385 | :group 'yasnippet) | ||
| 386 | 368 | ||
| 387 | (defcustom yas-alias-to-yas/prefix-p t | 369 | (defcustom yas-alias-to-yas/prefix-p t |
| 388 | "If non-nil make aliases for the old style yas/ prefixed symbols. | 370 | "If non-nil make aliases for the old style yas/ prefixed symbols. |
| @@ -394,13 +376,11 @@ It must be set to nil before loading yasnippet to take effect." | |||
| 394 | ;; | 376 | ;; |
| 395 | (defface yas-field-highlight-face | 377 | (defface yas-field-highlight-face |
| 396 | '((t (:inherit 'region))) | 378 | '((t (:inherit 'region))) |
| 397 | "The face used to highlight the currently active field of a snippet" | 379 | "The face used to highlight the currently active field of a snippet") |
| 398 | :group 'yasnippet) | ||
| 399 | 380 | ||
| 400 | (defface yas--field-debug-face | 381 | (defface yas--field-debug-face |
| 401 | '() | 382 | '() |
| 402 | "The face used for debugging some overlays normally hidden" | 383 | "The face used for debugging some overlays normally hidden") |
| 403 | :group 'yasnippet) | ||
| 404 | 384 | ||
| 405 | 385 | ||
| 406 | ;;; User-visible variables | 386 | ;;; User-visible variables |
| @@ -437,7 +417,7 @@ is tried, unless a function element returned the symbol `again', | |||
| 437 | in which case it is called again from the previous position and | 417 | in which case it is called again from the previous position and |
| 438 | may once more reposition point. | 418 | may once more reposition point. |
| 439 | 419 | ||
| 440 | For example, if `yas-key-syntaxes'' value is '(\"w\" \"w_\"), | 420 | For example, if `yas-key-syntaxes' has the value (\"w\" \"w_\"), |
| 441 | trigger keys composed exclusively of \"word\"-syntax characters | 421 | trigger keys composed exclusively of \"word\"-syntax characters |
| 442 | are looked for first. Failing that, longer keys composed of | 422 | are looked for first. Failing that, longer keys composed of |
| 443 | \"word\" or \"symbol\" syntax are looked for. Therefore, | 423 | \"word\" or \"symbol\" syntax are looked for. Therefore, |
| @@ -504,7 +484,7 @@ snippet expansion is attempted: | |||
| 504 | 484 | ||
| 505 | * Otherwise, the snippet is not considered. | 485 | * Otherwise, the snippet is not considered. |
| 506 | 486 | ||
| 507 | * If it evaluates to the symbol 'always, all snippets are | 487 | * If it evaluates to the symbol `always', all snippets are |
| 508 | considered for expansion, regardless of any conditions. | 488 | considered for expansion, regardless of any conditions. |
| 509 | 489 | ||
| 510 | * If it evaluates to t or some other non-nil value | 490 | * If it evaluates to t or some other non-nil value |
| @@ -516,14 +496,14 @@ snippet expansion is attempted: | |||
| 516 | 496 | ||
| 517 | Here's an example preventing snippets from being expanded from | 497 | Here's an example preventing snippets from being expanded from |
| 518 | inside comments, in `python-mode' only, with the exception of | 498 | inside comments, in `python-mode' only, with the exception of |
| 519 | snippets returning the symbol 'force-in-comment in their | 499 | snippets returning the symbol `force-in-comment' in their |
| 520 | conditions. | 500 | conditions. |
| 521 | 501 | ||
| 522 | (add-hook 'python-mode-hook | 502 | (add-hook \\='python-mode-hook |
| 523 | (lambda () | 503 | (lambda () |
| 524 | (setq yas-buffer-local-condition | 504 | (setq yas-buffer-local-condition |
| 525 | '(if (python-in-string/comment) | 505 | \\='(if (python-syntax-comment-or-string-p) |
| 526 | '(require-snippet-condition . force-in-comment) | 506 | \\='(require-snippet-condition . force-in-comment) |
| 527 | t)))) | 507 | t)))) |
| 528 | 508 | ||
| 529 | The default value is similar, it filters out potential snippet | 509 | The default value is similar, it filters out potential snippet |
| @@ -553,7 +533,7 @@ snippet itself contains a condition that returns the symbol | |||
| 553 | 533 | ||
| 554 | (defconst yas--backquote-lisp-expression-regexp | 534 | (defconst yas--backquote-lisp-expression-regexp |
| 555 | "`\\([^`]*\\)`" | 535 | "`\\([^`]*\\)`" |
| 556 | "A regexp to recognize a \"`lisp-expression`\" expression." ) | 536 | "A regexp to recognize a \"\\=`lisp-expression\\=`\" expression." ) |
| 557 | 537 | ||
| 558 | (defconst yas--transform-mirror-regexp | 538 | (defconst yas--transform-mirror-regexp |
| 559 | "${\\(?:\\([0-9]+\\):\\)?$\\([ \t\n]*([^}]*\\)" | 539 | "${\\(?:\\([0-9]+\\):\\)?$\\([ \t\n]*([^}]*\\)" |
| @@ -637,33 +617,33 @@ snippet itself contains a condition that returns the symbol | |||
| 637 | ) | 617 | ) |
| 638 | ("Prompting method" | 618 | ("Prompting method" |
| 639 | ["System X-widget" (setq yas-prompt-functions | 619 | ["System X-widget" (setq yas-prompt-functions |
| 640 | (cons 'yas-x-prompt | 620 | (cons #'yas-x-prompt |
| 641 | (remove 'yas-x-prompt | 621 | (remove #'yas-x-prompt |
| 642 | yas-prompt-functions))) | 622 | yas-prompt-functions))) |
| 643 | :help "Use your windowing system's (gtk, mac, windows, etc...) default menu" | 623 | :help "Use your windowing system's (gtk, mac, windows, etc...) default menu" |
| 644 | :active t :style radio :selected (eq (car yas-prompt-functions) | 624 | :active t :style radio :selected (eq (car yas-prompt-functions) |
| 645 | 'yas-x-prompt)] | 625 | #'yas-x-prompt)] |
| 646 | ["Dropdown-list" (setq yas-prompt-functions | 626 | ["Dropdown-list" (setq yas-prompt-functions |
| 647 | (cons 'yas-dropdown-prompt | 627 | (cons #'yas-dropdown-prompt |
| 648 | (remove 'yas-dropdown-prompt | 628 | (remove #'yas-dropdown-prompt |
| 649 | yas-prompt-functions))) | 629 | yas-prompt-functions))) |
| 650 | :help "Use a special dropdown list" | 630 | :help "Use a special dropdown list" |
| 651 | :active t :style radio :selected (eq (car yas-prompt-functions) | 631 | :active t :style radio :selected (eq (car yas-prompt-functions) |
| 652 | 'yas-dropdown-prompt)] | 632 | #'yas-dropdown-prompt)] |
| 653 | ["Ido" (setq yas-prompt-functions | 633 | ["Ido" (setq yas-prompt-functions |
| 654 | (cons 'yas-ido-prompt | 634 | (cons #'yas-ido-prompt |
| 655 | (remove 'yas-ido-prompt | 635 | (remove #'yas-ido-prompt |
| 656 | yas-prompt-functions))) | 636 | yas-prompt-functions))) |
| 657 | :help "Use an ido-style minibuffer prompt" | 637 | :help "Use an ido-style minibuffer prompt" |
| 658 | :active t :style radio :selected (eq (car yas-prompt-functions) | 638 | :active t :style radio :selected (eq (car yas-prompt-functions) |
| 659 | 'yas-ido-prompt)] | 639 | #'yas-ido-prompt)] |
| 660 | ["Completing read" (setq yas-prompt-functions | 640 | ["Completing read" (setq yas-prompt-functions |
| 661 | (cons 'yas-completing-prompt | 641 | (cons #'yas-completing-prompt |
| 662 | (remove 'yas-completing-prompt | 642 | (remove #'yas-completing-prompt |
| 663 | yas-prompt-functions))) | 643 | yas-prompt-functions))) |
| 664 | :help "Use a normal minibuffer prompt" | 644 | :help "Use a normal minibuffer prompt" |
| 665 | :active t :style radio :selected (eq (car yas-prompt-functions) | 645 | :active t :style radio :selected (eq (car yas-prompt-functions) |
| 666 | 'yas-completing-prompt)] | 646 | #'yas-completing-prompt)] |
| 667 | ) | 647 | ) |
| 668 | ("Misc" | 648 | ("Misc" |
| 669 | ["Wrap region in exit marker" | 649 | ["Wrap region in exit marker" |
| @@ -776,10 +756,7 @@ Negative prefix argument turns off the mode. | |||
| 776 | 756 | ||
| 777 | Key bindings: | 757 | Key bindings: |
| 778 | \\{yas-minor-mode-map}" | 758 | \\{yas-minor-mode-map}" |
| 779 | nil | 759 | :lighter " yas" ;; The indicator for the mode line. |
| 780 | ;; The indicator for the mode line. | ||
| 781 | " yas" | ||
| 782 | :group 'yasnippet | ||
| 783 | (cond ((and yas-minor-mode (featurep 'yasnippet)) | 760 | (cond ((and yas-minor-mode (featurep 'yasnippet)) |
| 784 | ;; Install the direct keymaps in `emulation-mode-map-alists' | 761 | ;; Install the direct keymaps in `emulation-mode-map-alists' |
| 785 | ;; (we use `add-hook' even though it's not technically a hook, | 762 | ;; (we use `add-hook' even though it's not technically a hook, |
| @@ -872,9 +849,7 @@ Honour `yas-dont-activate-functions', which see." | |||
| 872 | (yas-minor-mode 1))) | 849 | (yas-minor-mode 1))) |
| 873 | 850 | ||
| 874 | ;;;###autoload | 851 | ;;;###autoload |
| 875 | (define-globalized-minor-mode yas-global-mode yas-minor-mode yas-minor-mode-on | 852 | (define-globalized-minor-mode yas-global-mode yas-minor-mode yas-minor-mode-on) |
| 876 | :group 'yasnippet | ||
| 877 | :require 'yasnippet) | ||
| 878 | 853 | ||
| 879 | (defun yas--global-mode-reload-with-jit-maybe () | 854 | (defun yas--global-mode-reload-with-jit-maybe () |
| 880 | "Run `yas-reload-all' when `yas-global-mode' is on." | 855 | "Run `yas-reload-all' when `yas-global-mode' is on." |
| @@ -896,10 +871,10 @@ Honour `yas-dont-activate-functions', which see." | |||
| 896 | ;; They're "compiled", so extract the source. | 871 | ;; They're "compiled", so extract the source. |
| 897 | (cadr font-lock-keywords) | 872 | (cadr font-lock-keywords) |
| 898 | font-lock-keywords)) | 873 | font-lock-keywords)) |
| 899 | '(("$\\([0-9]+\\)" | 874 | '(("\\$\\([0-9]+\\)" |
| 900 | (0 font-lock-keyword-face) | 875 | (0 font-lock-keyword-face) |
| 901 | (1 font-lock-string-face t)) | 876 | (1 font-lock-string-face t)) |
| 902 | ("${\\([0-9]+\\):?" | 877 | ("\\${\\([0-9]+\\):?" |
| 903 | (0 font-lock-keyword-face) | 878 | (0 font-lock-keyword-face) |
| 904 | (1 font-lock-warning-face t)) | 879 | (1 font-lock-warning-face t)) |
| 905 | ("\\(\\$(\\)" 1 font-lock-preprocessor-face) | 880 | ("\\(\\$(\\)" 1 font-lock-preprocessor-face) |
| @@ -913,9 +888,9 @@ Honour `yas-dont-activate-functions', which see." | |||
| 913 | "Menu used when snippet-mode is active." | 888 | "Menu used when snippet-mode is active." |
| 914 | (cons "Snippet" | 889 | (cons "Snippet" |
| 915 | (mapcar #'(lambda (ent) | 890 | (mapcar #'(lambda (ent) |
| 916 | (when (third ent) | 891 | (when (nth 2 ent) |
| 917 | (define-key map (third ent) (second ent))) | 892 | (define-key map (nth 2 ent) (nth 1 ent))) |
| 918 | (vector (first ent) (second ent) t)) | 893 | (vector (nth 0 ent) (nth 1 ent) t)) |
| 919 | '(("Load this snippet" yas-load-snippet-buffer "\C-c\C-l") | 894 | '(("Load this snippet" yas-load-snippet-buffer "\C-c\C-l") |
| 920 | ("Load and quit window" yas-load-snippet-buffer-and-close "\C-c\C-c") | 895 | ("Load and quit window" yas-load-snippet-buffer-and-close "\C-c\C-c") |
| 921 | ("Try out this snippet" yas-tryout-snippet "\C-c\C-t"))))) | 896 | ("Try out this snippet" yas-tryout-snippet "\C-c\C-t"))))) |
| @@ -929,7 +904,8 @@ Honour `yas-dont-activate-functions', which see." | |||
| 929 | (setq font-lock-defaults '(yas--font-lock-keywords)) | 904 | (setq font-lock-defaults '(yas--font-lock-keywords)) |
| 930 | (set (make-local-variable 'require-final-newline) nil) | 905 | (set (make-local-variable 'require-final-newline) nil) |
| 931 | (set (make-local-variable 'comment-start) "#") | 906 | (set (make-local-variable 'comment-start) "#") |
| 932 | (set (make-local-variable 'comment-start-skip) "#+[\t ]*")) | 907 | (set (make-local-variable 'comment-start-skip) "#+[\t ]*") |
| 908 | (add-hook 'after-save-hook #'yas-maybe-load-snippet-buffer nil t)) | ||
| 933 | 909 | ||
| 934 | 910 | ||
| 935 | 911 | ||
| @@ -976,7 +952,7 @@ Honour `yas-dont-activate-functions', which see." | |||
| 976 | table | 952 | table |
| 977 | ) | 953 | ) |
| 978 | 954 | ||
| 979 | (defstruct (yas--table (:constructor yas--make-snippet-table (name))) | 955 | (cl-defstruct (yas--table (:constructor yas--make-snippet-table (name))) |
| 980 | "A table to store snippets for a particular mode. | 956 | "A table to store snippets for a particular mode. |
| 981 | 957 | ||
| 982 | Has the following fields: | 958 | Has the following fields: |
| @@ -1083,7 +1059,7 @@ Has the following fields: | |||
| 1083 | (maphash #'(lambda (k v) | 1059 | (maphash #'(lambda (k v) |
| 1084 | (let ((template (gethash name v))) | 1060 | (let ((template (gethash name v))) |
| 1085 | (when (and template | 1061 | (when (and template |
| 1086 | (eq uuid (yas--template-uuid template))) | 1062 | (equal uuid (yas--template-uuid template))) |
| 1087 | (remhash name v) | 1063 | (remhash name v) |
| 1088 | (when (zerop (hash-table-count v)) | 1064 | (when (zerop (hash-table-count v)) |
| 1089 | (push k empty-keys))))) | 1065 | (push k empty-keys))))) |
| @@ -1151,9 +1127,9 @@ Return TEMPLATE." | |||
| 1151 | (unless (eq (cdr menu-binding-pair) :none) | 1127 | (unless (eq (cdr menu-binding-pair) :none) |
| 1152 | ;; the menu item name | 1128 | ;; the menu item name |
| 1153 | ;; | 1129 | ;; |
| 1154 | (setf (cadar menu-binding-pair) (yas--template-name template)) | 1130 | (setf (cl-cadar menu-binding-pair) (yas--template-name template)) |
| 1155 | ;; the :keys information (also visible to the user) | 1131 | ;; the :keys information (also visible to the user) |
| 1156 | (setf (getf (cdr (car menu-binding-pair)) :keys) | 1132 | (setf (cl-getf (cdr (car menu-binding-pair)) :keys) |
| 1157 | (or (and keybinding (key-description keybinding)) | 1133 | (or (and keybinding (key-description keybinding)) |
| 1158 | (and key (concat key yas-trigger-symbol)))))) | 1134 | (and key (concat key yas-trigger-symbol)))))) |
| 1159 | (unless (yas--template-menu-managed-by-yas-define-menu template) | 1135 | (unless (yas--template-menu-managed-by-yas-define-menu template) |
| @@ -1164,7 +1140,7 @@ Return TEMPLATE." | |||
| 1164 | (group (yas--template-group template))) | 1140 | (group (yas--template-group template))) |
| 1165 | ;; Remove from menu keymap | 1141 | ;; Remove from menu keymap |
| 1166 | ;; | 1142 | ;; |
| 1167 | (assert menu-keymap) | 1143 | (cl-assert menu-keymap) |
| 1168 | (yas--delete-from-keymap menu-keymap (yas--template-uuid template)) | 1144 | (yas--delete-from-keymap menu-keymap (yas--template-uuid template)) |
| 1169 | 1145 | ||
| 1170 | ;; Add necessary subgroups as necessary. | 1146 | ;; Add necessary subgroups as necessary. |
| @@ -1227,10 +1203,10 @@ This function implements the rules described in | |||
| 1227 | (let ((requirement (yas--require-template-specific-condition-p))) | 1203 | (let ((requirement (yas--require-template-specific-condition-p))) |
| 1228 | (if (eq requirement 'always) | 1204 | (if (eq requirement 'always) |
| 1229 | templates | 1205 | templates |
| 1230 | (remove-if-not #'(lambda (pair) | 1206 | (cl-remove-if-not (lambda (pair) |
| 1231 | (yas--template-can-expand-p | 1207 | (yas--template-can-expand-p |
| 1232 | (yas--template-condition (cdr pair)) requirement)) | 1208 | (yas--template-condition (cdr pair)) requirement)) |
| 1233 | templates)))) | 1209 | templates)))) |
| 1234 | 1210 | ||
| 1235 | (defun yas--require-template-specific-condition-p () | 1211 | (defun yas--require-template-specific-condition-p () |
| 1236 | "Decide if this buffer requests/requires snippet-specific | 1212 | "Decide if this buffer requests/requires snippet-specific |
| @@ -1299,9 +1275,9 @@ Returns (TEMPLATES START END). This function respects | |||
| 1299 | (save-excursion | 1275 | (save-excursion |
| 1300 | (goto-char original) | 1276 | (goto-char original) |
| 1301 | (setq templates | 1277 | (setq templates |
| 1302 | (mapcan #'(lambda (table) | 1278 | (cl-mapcan (lambda (table) |
| 1303 | (yas--fetch table possible-key)) | 1279 | (yas--fetch table possible-key)) |
| 1304 | (yas--get-snippet-tables)))))) | 1280 | (yas--get-snippet-tables)))))) |
| 1305 | (when templates | 1281 | (when templates |
| 1306 | (list templates (point) original))))) | 1282 | (list templates (point) original))))) |
| 1307 | 1283 | ||
| @@ -1555,31 +1531,31 @@ Optional PROMPT sets the prompt to use." | |||
| 1555 | (sort templates #'(lambda (t1 t2) | 1531 | (sort templates #'(lambda (t1 t2) |
| 1556 | (< (length (yas--template-name t1)) | 1532 | (< (length (yas--template-name t1)) |
| 1557 | (length (yas--template-name t2)))))) | 1533 | (length (yas--template-name t2)))))) |
| 1558 | (some #'(lambda (fn) | 1534 | (cl-some (lambda (fn) |
| 1559 | (funcall fn (or prompt "Choose a snippet: ") | 1535 | (funcall fn (or prompt "Choose a snippet: ") |
| 1560 | templates | 1536 | templates |
| 1561 | #'yas--template-name)) | 1537 | #'yas--template-name)) |
| 1562 | yas-prompt-functions))) | 1538 | yas-prompt-functions))) |
| 1563 | 1539 | ||
| 1564 | (defun yas--prompt-for-keys (keys &optional prompt) | 1540 | (defun yas--prompt-for-keys (keys &optional prompt) |
| 1565 | "Interactively choose a template key from the list KEYS. | 1541 | "Interactively choose a template key from the list KEYS. |
| 1566 | 1542 | ||
| 1567 | Optional PROMPT sets the prompt to use." | 1543 | Optional PROMPT sets the prompt to use." |
| 1568 | (when keys | 1544 | (when keys |
| 1569 | (some #'(lambda (fn) | 1545 | (cl-some (lambda (fn) |
| 1570 | (funcall fn (or prompt "Choose a snippet key: ") keys)) | 1546 | (funcall fn (or prompt "Choose a snippet key: ") keys)) |
| 1571 | yas-prompt-functions))) | 1547 | yas-prompt-functions))) |
| 1572 | 1548 | ||
| 1573 | (defun yas--prompt-for-table (tables &optional prompt) | 1549 | (defun yas--prompt-for-table (tables &optional prompt) |
| 1574 | "Interactively choose a table from the list TABLES. | 1550 | "Interactively choose a table from the list TABLES. |
| 1575 | 1551 | ||
| 1576 | Optional PROMPT sets the prompt to use." | 1552 | Optional PROMPT sets the prompt to use." |
| 1577 | (when tables | 1553 | (when tables |
| 1578 | (some #'(lambda (fn) | 1554 | (cl-some (lambda (fn) |
| 1579 | (funcall fn (or prompt "Choose a snippet table: ") | 1555 | (funcall fn (or prompt "Choose a snippet table: ") |
| 1580 | tables | 1556 | tables |
| 1581 | #'yas--table-name)) | 1557 | #'yas--table-name)) |
| 1582 | yas-prompt-functions))) | 1558 | yas-prompt-functions))) |
| 1583 | 1559 | ||
| 1584 | (defun yas-x-prompt (prompt choices &optional display-fn) | 1560 | (defun yas-x-prompt (prompt choices &optional display-fn) |
| 1585 | "Display choices in a x-window prompt." | 1561 | "Display choices in a x-window prompt." |
| @@ -1596,9 +1572,10 @@ Optional PROMPT sets the prompt to use." | |||
| 1596 | (selected-window))) | 1572 | (selected-window))) |
| 1597 | t) | 1573 | t) |
| 1598 | `(,prompt ("title" | 1574 | `(,prompt ("title" |
| 1599 | ,@(mapcar* (lambda (c d) `(,(concat " " d) . ,c)) | 1575 | ,@(cl-mapcar (lambda (c d) `(,(concat " " d) . ,c)) |
| 1600 | choices | 1576 | choices |
| 1601 | (if display-fn (mapcar display-fn choices) choices))))) | 1577 | (if display-fn (mapcar display-fn choices) |
| 1578 | choices))))) | ||
| 1602 | (keyboard-quit)))) | 1579 | (keyboard-quit)))) |
| 1603 | 1580 | ||
| 1604 | (defun yas-maybe-ido-prompt (prompt choices &optional display-fn) | 1581 | (defun yas-maybe-ido-prompt (prompt choices &optional display-fn) |
| @@ -1625,11 +1602,11 @@ Optional PROMPT sets the prompt to use." | |||
| 1625 | nil 'require-match nil nil))) | 1602 | nil 'require-match nil nil))) |
| 1626 | (if (eq choices formatted-choices) | 1603 | (if (eq choices formatted-choices) |
| 1627 | chosen | 1604 | chosen |
| 1628 | (nth (or (position chosen formatted-choices :test #'string=) 0) | 1605 | (nth (or (cl-position chosen formatted-choices :test #'string=) 0) |
| 1629 | choices)))) | 1606 | choices)))) |
| 1630 | 1607 | ||
| 1631 | (defun yas-no-prompt (_prompt choices &optional _display-fn) | 1608 | (defun yas-no-prompt (_prompt choices &optional _display-fn) |
| 1632 | (first choices)) | 1609 | (cl-first choices)) |
| 1633 | 1610 | ||
| 1634 | 1611 | ||
| 1635 | ;;; Defining snippets | 1612 | ;;; Defining snippets |
| @@ -1719,7 +1696,7 @@ the current buffers contents." | |||
| 1719 | 1696 | ||
| 1720 | (defun yas--define-parents (mode parents) | 1697 | (defun yas--define-parents (mode parents) |
| 1721 | "Add PARENTS to the list of MODE's parents." | 1698 | "Add PARENTS to the list of MODE's parents." |
| 1722 | (puthash mode (remove-duplicates | 1699 | (puthash mode (cl-remove-duplicates |
| 1723 | (append parents | 1700 | (append parents |
| 1724 | (gethash mode yas--parents))) | 1701 | (gethash mode yas--parents))) |
| 1725 | yas--parents)) | 1702 | yas--parents)) |
| @@ -1835,7 +1812,7 @@ prompt the user to select one." | |||
| 1835 | (yas--message 4 "Loaded %s" directory) | 1812 | (yas--message 4 "Loaded %s" directory) |
| 1836 | (yas--message 4 "Prepared just-in-time loading for %s" directory))) | 1813 | (yas--message 4 "Prepared just-in-time loading for %s" directory))) |
| 1837 | (t | 1814 | (t |
| 1838 | (push (yas--message 0 "Check your `yas-snippet-dirs': %s is not a directory" directory) errors))))) | 1815 | (push (yas--message 1 "Check your `yas-snippet-dirs': %s is not a directory" directory) errors))))) |
| 1839 | errors)) | 1816 | errors)) |
| 1840 | 1817 | ||
| 1841 | (defun yas-reload-all (&optional no-jit interactive) | 1818 | (defun yas-reload-all (&optional no-jit interactive) |
| @@ -1851,9 +1828,10 @@ prefix argument." | |||
| 1851 | (catch 'abort | 1828 | (catch 'abort |
| 1852 | (let ((errors) | 1829 | (let ((errors) |
| 1853 | (snippet-editing-buffers | 1830 | (snippet-editing-buffers |
| 1854 | (remove-if-not #'(lambda (buffer) | 1831 | (cl-remove-if-not (lambda (buffer) |
| 1855 | (with-current-buffer buffer yas--editing-template)) | 1832 | (with-current-buffer buffer |
| 1856 | (buffer-list)))) | 1833 | yas--editing-template)) |
| 1834 | (buffer-list)))) | ||
| 1857 | ;; Warn if there are buffers visiting snippets, since reloading will break | 1835 | ;; Warn if there are buffers visiting snippets, since reloading will break |
| 1858 | ;; any on-line editing of those buffers. | 1836 | ;; any on-line editing of those buffers. |
| 1859 | ;; | 1837 | ;; |
| @@ -1914,18 +1892,11 @@ prefix argument." | |||
| 1914 | (funcall fun)) | 1892 | (funcall fun)) |
| 1915 | (remhash mode yas--scheduled-jit-loads)))) | 1893 | (remhash mode yas--scheduled-jit-loads)))) |
| 1916 | 1894 | ||
| 1917 | ;; (when (<= emacs-major-version 22) | 1895 | (defun yas-escape-text (text) |
| 1918 | ;; (add-hook 'after-change-major-mode-hook 'yas--load-pending-jits)) | 1896 | "Escape TEXT for snippet." |
| 1897 | (when text | ||
| 1898 | (replace-regexp-in-string "[\\$]" "\\\\\\&" text))) | ||
| 1919 | 1899 | ||
| 1920 | (defun yas--quote-string (string) | ||
| 1921 | "Escape and quote STRING. | ||
| 1922 | foo\"bar\\! -> \"foo\\\"bar\\\\!\"" | ||
| 1923 | (concat "\"" | ||
| 1924 | (replace-regexp-in-string "[\\\"]" | ||
| 1925 | "\\\\\\&" | ||
| 1926 | string | ||
| 1927 | t) | ||
| 1928 | "\"")) | ||
| 1929 | 1900 | ||
| 1930 | ;;; Snippet compilation function | 1901 | ;;; Snippet compilation function |
| 1931 | 1902 | ||
| @@ -2017,10 +1988,9 @@ static in the menu." | |||
| 2017 | 1988 | ||
| 2018 | (defun yas--show-menu-p (mode) | 1989 | (defun yas--show-menu-p (mode) |
| 2019 | (cond ((eq yas-use-menu 'abbreviate) | 1990 | (cond ((eq yas-use-menu 'abbreviate) |
| 2020 | (find mode | 1991 | (cl-find mode |
| 2021 | (mapcar #'(lambda (table) | 1992 | (mapcar #'yas--table-mode |
| 2022 | (yas--table-mode table)) | 1993 | (yas--get-snippet-tables)))) |
| 2023 | (yas--get-snippet-tables)))) | ||
| 2024 | (yas-use-menu t))) | 1994 | (yas-use-menu t))) |
| 2025 | 1995 | ||
| 2026 | (defun yas--delete-from-keymap (keymap uuid) | 1996 | (defun yas--delete-from-keymap (keymap uuid) |
| @@ -2034,19 +2004,19 @@ static in the menu." | |||
| 2034 | ;; | 2004 | ;; |
| 2035 | (mapc #'(lambda (item) | 2005 | (mapc #'(lambda (item) |
| 2036 | (when (and (listp (cdr item)) | 2006 | (when (and (listp (cdr item)) |
| 2037 | (keymapp (third (cdr item)))) | 2007 | (keymapp (nth 2 (cdr item)))) |
| 2038 | (yas--delete-from-keymap (third (cdr item)) uuid))) | 2008 | (yas--delete-from-keymap (nth 2 (cdr item)) uuid))) |
| 2039 | (rest keymap)) | 2009 | (cdr keymap)) |
| 2040 | ;; Set the uuid entry to nil | 2010 | ;; Set the uuid entry to nil |
| 2041 | ;; | 2011 | ;; |
| 2042 | (define-key keymap (vector (make-symbol uuid)) nil) | 2012 | (define-key keymap (vector (make-symbol uuid)) nil) |
| 2043 | ;; Destructively modify keymap | 2013 | ;; Destructively modify keymap |
| 2044 | ;; | 2014 | ;; |
| 2045 | (setcdr keymap (delete-if #'(lambda (item) | 2015 | (setcdr keymap (cl-delete-if (lambda (item) |
| 2046 | (or (null (cdr item)) | 2016 | (or (null (cdr item)) |
| 2047 | (and (keymapp (third (cdr item))) | 2017 | (and (keymapp (nth 2 (cdr item))) |
| 2048 | (null (cdr (third (cdr item))))))) | 2018 | (null (cdr (nth 2 (cdr item))))))) |
| 2049 | (rest keymap)))) | 2019 | (cdr keymap)))) |
| 2050 | 2020 | ||
| 2051 | (defun yas-define-menu (mode menu &optional omit-items) | 2021 | (defun yas-define-menu (mode menu &optional omit-items) |
| 2052 | "Define a snippet menu for MODE according to MENU, omitting OMIT-ITEMS. | 2022 | "Define a snippet menu for MODE according to MENU, omitting OMIT-ITEMS. |
| @@ -2063,7 +2033,7 @@ MENU is a list, its elements can be: | |||
| 2063 | SUBMENU has the same form as MENU. NAME is also added to the | 2033 | SUBMENU has the same form as MENU. NAME is also added to the |
| 2064 | list of groups of the snippets defined thereafter. | 2034 | list of groups of the snippets defined thereafter. |
| 2065 | 2035 | ||
| 2066 | OMIT-ITEMS is a list of snippet uuid's that will always be | 2036 | OMIT-ITEMS is a list of snippet uuids that will always be |
| 2067 | omitted from MODE's menu, even if they're manually loaded." | 2037 | omitted from MODE's menu, even if they're manually loaded." |
| 2068 | (let* ((table (yas--table-get-create mode)) | 2038 | (let* ((table (yas--table-get-create mode)) |
| 2069 | (hash (yas--table-uuidhash table))) | 2039 | (hash (yas--table-uuidhash table))) |
| @@ -2081,31 +2051,37 @@ omitted from MODE's menu, even if they're manually loaded." | |||
| 2081 | 2051 | ||
| 2082 | (defun yas--define-menu-1 (table menu-keymap menu uuidhash &optional group-list) | 2052 | (defun yas--define-menu-1 (table menu-keymap menu uuidhash &optional group-list) |
| 2083 | "Helper for `yas-define-menu'." | 2053 | "Helper for `yas-define-menu'." |
| 2084 | (dolist (e (reverse menu)) | 2054 | (cl-loop |
| 2085 | (cond ((eq (first e) 'yas-item) | 2055 | for (type name submenu) in (reverse menu) |
| 2086 | (let ((template (or (gethash (second e) uuidhash) | 2056 | if (or (eq type 'yas-item) |
| 2087 | (puthash (second e) | 2057 | (and yas-alias-to-yas/prefix-p |
| 2088 | (yas--make-template | 2058 | (eq type 'yas/item))) |
| 2089 | :table table | 2059 | do (let ((template (or (gethash name uuidhash) |
| 2090 | :perm-group group-list | 2060 | (puthash name |
| 2091 | :uuid (second e)) | 2061 | (yas--make-template |
| 2092 | uuidhash)))) | 2062 | :table table |
| 2093 | (define-key menu-keymap (vector (gensym)) | 2063 | :perm-group group-list |
| 2094 | (car (yas--template-menu-binding-pair-get-create template :stay))))) | 2064 | :uuid name) |
| 2095 | ((eq (first e) 'yas-submenu) | 2065 | uuidhash)))) |
| 2096 | (let ((subkeymap (make-sparse-keymap))) | 2066 | (define-key menu-keymap (vector (cl-gensym)) |
| 2097 | (define-key menu-keymap (vector (gensym)) | 2067 | (car (yas--template-menu-binding-pair-get-create template :stay)))) |
| 2098 | `(menu-item ,(second e) ,subkeymap)) | 2068 | else if (or (eq type 'yas-submenu) |
| 2099 | (yas--define-menu-1 table | 2069 | (and yas-alias-to-yas/prefix-p |
| 2100 | subkeymap | 2070 | (eq type 'yas/submenu))) |
| 2101 | (third e) | 2071 | do (let ((subkeymap (make-sparse-keymap))) |
| 2102 | uuidhash | 2072 | (define-key menu-keymap (vector (cl-gensym)) |
| 2103 | (append group-list (list (second e)))))) | 2073 | `(menu-item ,name ,subkeymap)) |
| 2104 | ((eq (first e) 'yas-separator) | 2074 | (yas--define-menu-1 table |
| 2105 | (define-key menu-keymap (vector (gensym)) | 2075 | subkeymap |
| 2106 | '(menu-item "----"))) | 2076 | submenu |
| 2107 | (t | 2077 | uuidhash |
| 2108 | (yas--message 1 "Don't know anything about menu entry %s" (first e)))))) | 2078 | (append group-list (list name)))) |
| 2079 | else if (or (eq type 'yas-separator) | ||
| 2080 | (and yas-alias-to-yas/prefix-p | ||
| 2081 | (eq type 'yas/separator))) | ||
| 2082 | do (define-key menu-keymap (vector (cl-gensym)) | ||
| 2083 | '(menu-item "----")) | ||
| 2084 | else do (yas--message 1 "Don't know anything about menu entry %s" type))) | ||
| 2109 | 2085 | ||
| 2110 | (defun yas--define (mode key template &optional name condition group) | 2086 | (defun yas--define (mode key template &optional name condition group) |
| 2111 | "Define a snippet. Expanding KEY into TEMPLATE. | 2087 | "Define a snippet. Expanding KEY into TEMPLATE. |
| @@ -2194,12 +2170,13 @@ object satisfying `yas--field-p' to restrict the expansion to." | |||
| 2194 | If expansion fails, execute the previous binding for this key" | 2170 | If expansion fails, execute the previous binding for this key" |
| 2195 | (interactive) | 2171 | (interactive) |
| 2196 | (setq yas--condition-cache-timestamp (current-time)) | 2172 | (setq yas--condition-cache-timestamp (current-time)) |
| 2197 | (let* ((vec (subseq (this-command-keys-vector) (if current-prefix-arg | 2173 | (let* ((vec (cl-subseq (this-command-keys-vector) |
| 2198 | (length (this-command-keys)) | 2174 | (if current-prefix-arg |
| 2199 | 0))) | 2175 | (length (this-command-keys)) |
| 2200 | (templates (mapcan #'(lambda (table) | 2176 | 0))) |
| 2201 | (yas--fetch table vec)) | 2177 | (templates (cl-mapcan (lambda (table) |
| 2202 | (yas--get-snippet-tables)))) | 2178 | (yas--fetch table vec)) |
| 2179 | (yas--get-snippet-tables)))) | ||
| 2203 | (if templates | 2180 | (if templates |
| 2204 | (yas--expand-or-prompt-for-template templates) | 2181 | (yas--expand-or-prompt-for-template templates) |
| 2205 | (let ((yas-fallback-behavior 'call-other-command)) | 2182 | (let ((yas-fallback-behavior 'call-other-command)) |
| @@ -2211,7 +2188,7 @@ If expansion fails, execute the previous binding for this key" | |||
| 2211 | Prompt the user if TEMPLATES has more than one element, else | 2188 | Prompt the user if TEMPLATES has more than one element, else |
| 2212 | expand immediately. Common gateway for | 2189 | expand immediately. Common gateway for |
| 2213 | `yas-expand-from-trigger-key' and `yas-expand-from-keymap'." | 2190 | `yas-expand-from-trigger-key' and `yas-expand-from-keymap'." |
| 2214 | (let ((yas--current-template (or (and (rest templates) ;; more than one | 2191 | (let ((yas--current-template (or (and (cl-rest templates) ;; more than one |
| 2215 | (yas--prompt-for-template (mapcar #'cdr templates))) | 2192 | (yas--prompt-for-template (mapcar #'cdr templates))) |
| 2216 | (cdar templates)))) | 2193 | (cdar templates)))) |
| 2217 | (when yas--current-template | 2194 | (when yas--current-template |
| @@ -2249,7 +2226,7 @@ Common gateway for `yas-expand-from-trigger-key' and | |||
| 2249 | (yas-minor-mode nil) | 2226 | (yas-minor-mode nil) |
| 2250 | (beyond-yasnippet (yas--keybinding-beyond-yasnippet))) | 2227 | (beyond-yasnippet (yas--keybinding-beyond-yasnippet))) |
| 2251 | (yas--message 4 "Falling back to %s" beyond-yasnippet) | 2228 | (yas--message 4 "Falling back to %s" beyond-yasnippet) |
| 2252 | (assert (or (null beyond-yasnippet) (commandp beyond-yasnippet))) | 2229 | (cl-assert (or (null beyond-yasnippet) (commandp beyond-yasnippet))) |
| 2253 | (setq this-command beyond-yasnippet) | 2230 | (setq this-command beyond-yasnippet) |
| 2254 | (when beyond-yasnippet | 2231 | (when beyond-yasnippet |
| 2255 | (call-interactively beyond-yasnippet)))) | 2232 | (call-interactively beyond-yasnippet)))) |
| @@ -2314,13 +2291,13 @@ Honours `yas-choose-tables-first', `yas-choose-keys-first' and | |||
| 2314 | (mapcar #'cdr | 2291 | (mapcar #'cdr |
| 2315 | (if yas-choose-keys-first | 2292 | (if yas-choose-keys-first |
| 2316 | (let ((key (yas--prompt-for-keys | 2293 | (let ((key (yas--prompt-for-keys |
| 2317 | (mapcan #'yas--table-all-keys tables)))) | 2294 | (cl-mapcan #'yas--table-all-keys tables)))) |
| 2318 | (when key | 2295 | (when key |
| 2319 | (mapcan #'(lambda (table) | 2296 | (cl-mapcan (lambda (table) |
| 2320 | (yas--fetch table key)) | 2297 | (yas--fetch table key)) |
| 2321 | tables))) | 2298 | tables))) |
| 2322 | (remove-duplicates (mapcan #'yas--table-templates tables) | 2299 | (cl-remove-duplicates (cl-mapcan #'yas--table-templates tables) |
| 2323 | :test #'equal)))) | 2300 | :test #'equal)))) |
| 2324 | 2301 | ||
| 2325 | (defun yas--lookup-snippet-1 (name mode) | 2302 | (defun yas--lookup-snippet-1 (name mode) |
| 2326 | "Get the snippet called NAME in MODE's tables." | 2303 | "Get the snippet called NAME in MODE's tables." |
| @@ -2357,7 +2334,7 @@ by condition." | |||
| 2357 | yas-buffer-local-condition)) | 2334 | yas-buffer-local-condition)) |
| 2358 | (templates (yas--all-templates (yas--get-snippet-tables))) | 2335 | (templates (yas--all-templates (yas--get-snippet-tables))) |
| 2359 | (yas--current-template (and templates | 2336 | (yas--current-template (and templates |
| 2360 | (or (and (rest templates) ;; more than one template for same key | 2337 | (or (and (cl-rest templates) ;; more than one template for same key |
| 2361 | (yas--prompt-for-template templates)) | 2338 | (yas--prompt-for-template templates)) |
| 2362 | (car templates)))) | 2339 | (car templates)))) |
| 2363 | (where (if (region-active-p) | 2340 | (where (if (region-active-p) |
| @@ -2415,15 +2392,15 @@ visited file in `snippet-mode'." | |||
| 2415 | (pp-to-string (yas--template-content template)) | 2392 | (pp-to-string (yas--template-content template)) |
| 2416 | (yas--template-content template)))) | 2393 | (yas--template-content template)))) |
| 2417 | (snippet-mode) | 2394 | (snippet-mode) |
| 2418 | (set (make-local-variable 'yas--editing-template) template))))) | 2395 | (set (make-local-variable 'yas--editing-template) template) |
| 2396 | (set (make-local-variable 'default-directory) | ||
| 2397 | (car (cdr (car (yas--guess-snippet-directories (yas--template-table template)))))))))) | ||
| 2419 | 2398 | ||
| 2420 | (defun yas--guess-snippet-directories-1 (table) | 2399 | (defun yas--guess-snippet-directories-1 (table) |
| 2421 | "Guess possible snippet subdirectories for TABLE." | 2400 | "Guess possible snippet subdirectories for TABLE." |
| 2422 | (cons (yas--table-name table) | 2401 | (cons (file-name-as-directory (yas--table-name table)) |
| 2423 | (mapcan #'(lambda (parent) | 2402 | (cl-mapcan #'yas--guess-snippet-directories-1 |
| 2424 | (yas--guess-snippet-directories-1 | 2403 | (yas--table-parents table)))) |
| 2425 | parent)) | ||
| 2426 | (yas--table-parents table)))) | ||
| 2427 | 2404 | ||
| 2428 | (defun yas--guess-snippet-directories (&optional table) | 2405 | (defun yas--guess-snippet-directories (&optional table) |
| 2429 | "Try to guess suitable directories based on the current active | 2406 | "Try to guess suitable directories based on the current active |
| @@ -2452,8 +2429,9 @@ where snippets of table might exist." | |||
| 2452 | 2429 | ||
| 2453 | (defun yas--make-directory-maybe (table-and-dirs &optional main-table-string) | 2430 | (defun yas--make-directory-maybe (table-and-dirs &optional main-table-string) |
| 2454 | "Return a dir inside TABLE-AND-DIRS, prompts for creation if none exists." | 2431 | "Return a dir inside TABLE-AND-DIRS, prompts for creation if none exists." |
| 2455 | (or (some #'(lambda (dir) (when (file-directory-p dir) dir)) (cdr table-and-dirs)) | 2432 | (or (cl-some (lambda (dir) (when (file-directory-p dir) dir)) |
| 2456 | (let ((candidate (first (cdr table-and-dirs)))) | 2433 | (cdr table-and-dirs)) |
| 2434 | (let ((candidate (cl-first (cdr table-and-dirs)))) | ||
| 2457 | (unless (file-writable-p (file-name-directory candidate)) | 2435 | (unless (file-writable-p (file-name-directory candidate)) |
| 2458 | (error (yas--format "%s is not writable." candidate))) | 2436 | (error (yas--format "%s is not writable." candidate))) |
| 2459 | (if (y-or-n-p (format "Guessed directory (%s) for%s%s table \"%s\" does not exist! Create? " | 2437 | (if (y-or-n-p (format "Guessed directory (%s) for%s%s table \"%s\" does not exist! Create? " |
| @@ -2487,9 +2465,11 @@ NO-TEMPLATE is non-nil." | |||
| 2487 | (kill-all-local-variables) | 2465 | (kill-all-local-variables) |
| 2488 | (snippet-mode) | 2466 | (snippet-mode) |
| 2489 | (yas-minor-mode 1) | 2467 | (yas-minor-mode 1) |
| 2490 | (set (make-local-variable 'yas--guessed-modes) (mapcar #'(lambda (d) | 2468 | (set (make-local-variable 'yas--guessed-modes) |
| 2491 | (yas--table-mode (car d))) | 2469 | (mapcar (lambda (d) (yas--table-mode (car d))) |
| 2492 | guessed-directories)) | 2470 | guessed-directories)) |
| 2471 | (set (make-local-variable 'default-directory) | ||
| 2472 | (car (cdr (car guessed-directories)))) | ||
| 2493 | (if (and (not no-template) yas-new-snippet-default) | 2473 | (if (and (not no-template) yas-new-snippet-default) |
| 2494 | (yas-expand-snippet yas-new-snippet-default)))) | 2474 | (yas-expand-snippet yas-new-snippet-default)))) |
| 2495 | 2475 | ||
| @@ -2502,12 +2482,13 @@ representing one or more of the mode's parents. | |||
| 2502 | Note that MODE-SYM need not be the symbol of a real major mode, | 2482 | Note that MODE-SYM need not be the symbol of a real major mode, |
| 2503 | neither do the elements of PARENTS." | 2483 | neither do the elements of PARENTS." |
| 2504 | (let* ((file-dir (and file | 2484 | (let* ((file-dir (and file |
| 2505 | (directory-file-name (or (some #'(lambda (special) | 2485 | (directory-file-name |
| 2506 | (locate-dominating-file file special)) | 2486 | (or (cl-some (lambda (special) |
| 2507 | '(".yas-setup.el" | 2487 | (locate-dominating-file file special)) |
| 2508 | ".yas-make-groups" | 2488 | '(".yas-setup.el" |
| 2509 | ".yas-parents")) | 2489 | ".yas-make-groups" |
| 2510 | (directory-file-name (file-name-directory file)))))) | 2490 | ".yas-parents")) |
| 2491 | (directory-file-name (file-name-directory file)))))) | ||
| 2511 | (parents-file-name (concat file-dir "/.yas-parents")) | 2492 | (parents-file-name (concat file-dir "/.yas-parents")) |
| 2512 | (major-mode-name (and file-dir | 2493 | (major-mode-name (and file-dir |
| 2513 | (file-name-nondirectory file-dir))) | 2494 | (file-name-nondirectory file-dir))) |
| @@ -2543,20 +2524,21 @@ neither do the elements of PARENTS." | |||
| 2543 | (intern | 2524 | (intern |
| 2544 | (funcall prompt (format "Choose or enter a table (yas guesses %s): " | 2525 | (funcall prompt (format "Choose or enter a table (yas guesses %s): " |
| 2545 | (if yas--guessed-modes | 2526 | (if yas--guessed-modes |
| 2546 | (first yas--guessed-modes) | 2527 | (cl-first yas--guessed-modes) |
| 2547 | "nothing")) | 2528 | "nothing")) |
| 2548 | (mapcar #'symbol-name yas--guessed-modes) | 2529 | (mapcar #'symbol-name yas--guessed-modes) |
| 2549 | nil | 2530 | nil |
| 2550 | nil | 2531 | nil |
| 2551 | nil | 2532 | nil |
| 2552 | nil | 2533 | nil |
| 2553 | (if (first yas--guessed-modes) | 2534 | (if (cl-first yas--guessed-modes) |
| 2554 | (symbol-name (first yas--guessed-modes))))))) | 2535 | (symbol-name (cl-first yas--guessed-modes))))))) |
| 2555 | 2536 | ||
| 2556 | (defun yas-load-snippet-buffer (table &optional interactive) | 2537 | (defun yas-load-snippet-buffer (table &optional interactive) |
| 2557 | "Parse and load current buffer's snippet definition into TABLE. | 2538 | "Parse and load current buffer's snippet definition into TABLE. |
| 2558 | TABLE is a symbol name passed to `yas--table-get-create'. When | 2539 | TABLE is a symbol name passed to `yas--table-get-create'. When |
| 2559 | called interactively, prompt for the table name." | 2540 | called interactively, prompt for the table name. |
| 2541 | Return the `yas--template' object created" | ||
| 2560 | (interactive (list (yas--read-table) t)) | 2542 | (interactive (list (yas--read-table) t)) |
| 2561 | (cond | 2543 | (cond |
| 2562 | ;; We have `yas--editing-template', this buffer's content comes from a | 2544 | ;; We have `yas--editing-template', this buffer's content comes from a |
| @@ -2578,7 +2560,23 @@ called interactively, prompt for the table name." | |||
| 2578 | (when interactive | 2560 | (when interactive |
| 2579 | (yas--message 3 "Snippet \"%s\" loaded for %s." | 2561 | (yas--message 3 "Snippet \"%s\" loaded for %s." |
| 2580 | (yas--template-name yas--editing-template) | 2562 | (yas--template-name yas--editing-template) |
| 2581 | (yas--table-name (yas--template-table yas--editing-template))))) | 2563 | (yas--table-name (yas--template-table yas--editing-template)))) |
| 2564 | yas--editing-template) | ||
| 2565 | |||
| 2566 | (defun yas-maybe-load-snippet-buffer () | ||
| 2567 | "Added to `after-save-hook' in `snippet-mode'." | ||
| 2568 | (let* ((mode (intern (file-name-sans-extension | ||
| 2569 | (file-name-nondirectory | ||
| 2570 | (directory-file-name default-directory))))) | ||
| 2571 | (current-snippet | ||
| 2572 | (apply #'yas--define-snippets-2 (yas--table-get-create mode) | ||
| 2573 | (yas--parse-template buffer-file-name))) | ||
| 2574 | (uuid (yas--template-uuid current-snippet))) | ||
| 2575 | (unless (equal current-snippet | ||
| 2576 | (if uuid (yas--get-template-by-uuid mode uuid) | ||
| 2577 | (yas--lookup-snippet-1 | ||
| 2578 | (yas--template-name current-snippet) mode))) | ||
| 2579 | (yas-load-snippet-buffer mode t)))) | ||
| 2582 | 2580 | ||
| 2583 | (defun yas-load-snippet-buffer-and-close (table &optional kill) | 2581 | (defun yas-load-snippet-buffer-and-close (table &optional kill) |
| 2584 | "Load and save the snippet, then `quit-window' if saved. | 2582 | "Load and save the snippet, then `quit-window' if saved. |
| @@ -2591,31 +2589,19 @@ The prefix argument KILL is passed to `quit-window'. | |||
| 2591 | Don't use this from a Lisp program, call `yas-load-snippet-buffer' | 2589 | Don't use this from a Lisp program, call `yas-load-snippet-buffer' |
| 2592 | and `kill-buffer' instead." | 2590 | and `kill-buffer' instead." |
| 2593 | (interactive (list (yas--read-table) current-prefix-arg)) | 2591 | (interactive (list (yas--read-table) current-prefix-arg)) |
| 2594 | (yas-load-snippet-buffer table t) | 2592 | (let ((template (yas-load-snippet-buffer table t))) |
| 2595 | (let ((file (yas--template-get-file yas--editing-template))) | 2593 | (when (and (buffer-modified-p) |
| 2596 | (when (and (or | 2594 | (y-or-n-p |
| 2597 | ;; Only offer to save this if it looks like a library or new | 2595 | (format "[yas] Loaded for %s. Also save snippet buffer?" |
| 2598 | ;; snippet (loaded from elisp, from a dir in `yas-snippet-dirs' | 2596 | (yas--table-name (yas--template-table template))))) |
| 2599 | ;; which is not the first, or from an unwritable file) | 2597 | (let ((default-directory (car (cdr (car (yas--guess-snippet-directories |
| 2600 | ;; | 2598 | (yas--template-table template)))))) |
| 2601 | (not file) | 2599 | (default-file-name (yas--template-name template))) |
| 2602 | (not (file-writable-p file)) | 2600 | (unless (or buffer-file-name (not default-file-name)) |
| 2603 | (and (cdr-safe yas-snippet-dirs) | 2601 | (setq buffer-file-name |
| 2604 | (not (string-prefix-p (expand-file-name (car yas-snippet-dirs)) file)))) | 2602 | (read-file-name "File to save snippet in: " |
| 2605 | (y-or-n-p (yas--format "Looks like a library or new snippet. Save to new file? "))) | 2603 | nil nil nil default-file-name ))) |
| 2606 | (let* ((option (first (yas--guess-snippet-directories (yas--template-table yas--editing-template)))) | 2604 | (save-buffer))) |
| 2607 | (chosen (and option | ||
| 2608 | (yas--make-directory-maybe option)))) | ||
| 2609 | (when chosen | ||
| 2610 | (let ((default-file-name (or (and file (file-name-nondirectory file)) | ||
| 2611 | (yas--template-name yas--editing-template)))) | ||
| 2612 | (write-file (expand-file-name | ||
| 2613 | (read-file-name (format "File name to create in %s? " chosen) | ||
| 2614 | chosen default-file-name) | ||
| 2615 | chosen)) | ||
| 2616 | (setf (yas--template-load-file yas--editing-template) buffer-file-name)))))) | ||
| 2617 | (when buffer-file-name | ||
| 2618 | (save-buffer) | ||
| 2619 | (quit-window kill))) | 2605 | (quit-window kill))) |
| 2620 | 2606 | ||
| 2621 | (defun yas-tryout-snippet (&optional debug) | 2607 | (defun yas-tryout-snippet (&optional debug) |
| @@ -2626,7 +2612,7 @@ and `kill-buffer' instead." | |||
| 2626 | (test-mode (or (and (car major-mode-and-parent) | 2612 | (test-mode (or (and (car major-mode-and-parent) |
| 2627 | (fboundp (car major-mode-and-parent)) | 2613 | (fboundp (car major-mode-and-parent)) |
| 2628 | (car major-mode-and-parent)) | 2614 | (car major-mode-and-parent)) |
| 2629 | (first yas--guessed-modes) | 2615 | (cl-first yas--guessed-modes) |
| 2630 | (intern (read-from-minibuffer (yas--format "Please input a mode: "))))) | 2616 | (intern (read-from-minibuffer (yas--format "Please input a mode: "))))) |
| 2631 | (yas--current-template | 2617 | (yas--current-template |
| 2632 | (and parsed | 2618 | (and parsed |
| @@ -2649,15 +2635,17 @@ and `kill-buffer' instead." | |||
| 2649 | (point-max) | 2635 | (point-max) |
| 2650 | (yas--template-expand-env yas--current-template)) | 2636 | (yas--template-expand-env yas--current-template)) |
| 2651 | (when (and debug | 2637 | (when (and debug |
| 2652 | (require 'yasnippet-debug nil t)) | 2638 | (require 'yasnippet-debug nil t) |
| 2653 | (add-hook 'post-command-hook 'yas-debug-snippet-vars nil t)))) | 2639 | (fboundp 'yas-debug-snippet-vars)) |
| 2640 | (add-hook 'post-command-hook #'yas-debug-snippet-vars nil t)))) | ||
| 2654 | (t | 2641 | (t |
| 2655 | (yas--message 1 "Cannot test snippet for unknown major mode"))))) | 2642 | (yas--message 1 "Cannot test snippet for unknown major mode"))))) |
| 2656 | 2643 | ||
| 2657 | (defun yas-active-keys () | 2644 | (defun yas-active-keys () |
| 2658 | "Return all active trigger keys for current buffer and point." | 2645 | "Return all active trigger keys for current buffer and point." |
| 2659 | (remove-duplicates | 2646 | (cl-remove-duplicates |
| 2660 | (remove-if-not #'stringp (mapcan #'yas--table-all-keys (yas--get-snippet-tables))) | 2647 | (cl-remove-if-not #'stringp (cl-mapcan #'yas--table-all-keys |
| 2648 | (yas--get-snippet-tables))) | ||
| 2661 | :test #'string=)) | 2649 | :test #'string=)) |
| 2662 | 2650 | ||
| 2663 | (defun yas--template-fine-group (template) | 2651 | (defun yas--template-fine-group (template) |
| @@ -2822,16 +2810,16 @@ The last element of POSSIBILITIES may be a list of strings." | |||
| 2822 | (when (listp last-elem) | 2810 | (when (listp last-elem) |
| 2823 | (setcar last-link (car last-elem)) | 2811 | (setcar last-link (car last-elem)) |
| 2824 | (setcdr last-link (cdr last-elem)))) | 2812 | (setcdr last-link (cdr last-elem)))) |
| 2825 | (some #'(lambda (fn) | 2813 | (cl-some (lambda (fn) |
| 2826 | (funcall fn "Choose: " possibilities)) | 2814 | (funcall fn "Choose: " possibilities)) |
| 2827 | yas-prompt-functions))) | 2815 | yas-prompt-functions))) |
| 2828 | 2816 | ||
| 2829 | (defun yas-key-to-value (alist) | 2817 | (defun yas-key-to-value (alist) |
| 2830 | (unless (or yas-moving-away-p | 2818 | (unless (or yas-moving-away-p |
| 2831 | yas-modified-p) | 2819 | yas-modified-p) |
| 2832 | (let ((key (read-key-sequence ""))) | 2820 | (let ((key (read-key-sequence ""))) |
| 2833 | (when (stringp key) | 2821 | (when (stringp key) |
| 2834 | (or (cdr (find key alist :key #'car :test #'string=)) | 2822 | (or (cdr (cl-find key alist :key #'car :test #'string=)) |
| 2835 | key))))) | 2823 | key))))) |
| 2836 | 2824 | ||
| 2837 | (defun yas-throw (text) | 2825 | (defun yas-throw (text) |
| @@ -2842,7 +2830,8 @@ The last element of POSSIBILITIES may be a list of strings." | |||
| 2842 | "Verify that the current field value is in POSSIBILITIES. | 2830 | "Verify that the current field value is in POSSIBILITIES. |
| 2843 | 2831 | ||
| 2844 | Otherwise throw exception." | 2832 | Otherwise throw exception." |
| 2845 | (when (and yas-moving-away-p (notany #'(lambda (pos) (string= pos yas-text)) possibilities)) | 2833 | (when (and yas-moving-away-p |
| 2834 | (cl-notany (lambda (pos) (string= pos yas-text)) possibilities)) | ||
| 2846 | (yas-throw (yas--format "Field only allows %s" possibilities)))) | 2835 | (yas-throw (yas--format "Field only allows %s" possibilities)))) |
| 2847 | 2836 | ||
| 2848 | (defun yas-field-value (number) | 2837 | (defun yas-field-value (number) |
| @@ -2909,7 +2898,7 @@ Use this in primary and mirror transformations to tget." | |||
| 2909 | (put 'yas--active-field-overlay 'permanent-local t) | 2898 | (put 'yas--active-field-overlay 'permanent-local t) |
| 2910 | (put 'yas--field-protection-overlays 'permanent-local t) | 2899 | (put 'yas--field-protection-overlays 'permanent-local t) |
| 2911 | 2900 | ||
| 2912 | (defstruct (yas--snippet (:constructor yas--make-snippet ())) | 2901 | (cl-defstruct (yas--snippet (:constructor yas--make-snippet ())) |
| 2913 | "A snippet. | 2902 | "A snippet. |
| 2914 | 2903 | ||
| 2915 | ..." | 2904 | ..." |
| @@ -2923,7 +2912,7 @@ Use this in primary and mirror transformations to tget." | |||
| 2923 | previous-active-field | 2912 | previous-active-field |
| 2924 | force-exit) | 2913 | force-exit) |
| 2925 | 2914 | ||
| 2926 | (defstruct (yas--field (:constructor yas--make-field (number start end parent-field))) | 2915 | (cl-defstruct (yas--field (:constructor yas--make-field (number start end parent-field))) |
| 2927 | "A field. | 2916 | "A field. |
| 2928 | 2917 | ||
| 2929 | NUMBER is the field number. | 2918 | NUMBER is the field number. |
| @@ -2943,7 +2932,7 @@ NEXT is another `yas--field' or `yas--mirror' or `yas--exit'. | |||
| 2943 | next) | 2932 | next) |
| 2944 | 2933 | ||
| 2945 | 2934 | ||
| 2946 | (defstruct (yas--mirror (:constructor yas--make-mirror (start end transform))) | 2935 | (cl-defstruct (yas--mirror (:constructor yas--make-mirror (start end transform))) |
| 2947 | "A mirror. | 2936 | "A mirror. |
| 2948 | 2937 | ||
| 2949 | START and END are mostly buffer markers, but see \"apropos markers-to-points\". | 2938 | START and END are mostly buffer markers, but see \"apropos markers-to-points\". |
| @@ -2957,7 +2946,7 @@ DEPTH is a count of how many nested mirrors can affect this mirror" | |||
| 2957 | next | 2946 | next |
| 2958 | depth) | 2947 | depth) |
| 2959 | 2948 | ||
| 2960 | (defstruct (yas--exit (:constructor yas--make-exit (marker))) | 2949 | (cl-defstruct (yas--exit (:constructor yas--make-exit (marker))) |
| 2961 | marker | 2950 | marker |
| 2962 | next) | 2951 | next) |
| 2963 | 2952 | ||
| @@ -2994,9 +2983,9 @@ With optional string TEXT do it in that string." | |||
| 2994 | (replace-match to t t text)))) | 2983 | (replace-match to t t text)))) |
| 2995 | 2984 | ||
| 2996 | (defun yas--snippet-find-field (snippet number) | 2985 | (defun yas--snippet-find-field (snippet number) |
| 2997 | (find-if #'(lambda (field) | 2986 | (cl-find-if (lambda (field) |
| 2998 | (eq number (yas--field-number field))) | 2987 | (eq number (yas--field-number field))) |
| 2999 | (yas--snippet-fields snippet))) | 2988 | (yas--snippet-fields snippet))) |
| 3000 | 2989 | ||
| 3001 | (defun yas--snippet-sort-fields (snippet) | 2990 | (defun yas--snippet-sort-fields (snippet) |
| 3002 | "Sort the fields of SNIPPET in navigation order." | 2991 | "Sort the fields of SNIPPET in navigation order." |
| @@ -3086,8 +3075,7 @@ Otherwise delegate to `yas-next-field'." | |||
| 3086 | (and (not (eq field active)) | 3075 | (and (not (eq field active)) |
| 3087 | (yas--field-probably-deleted-p snippet field))) | 3076 | (yas--field-probably-deleted-p snippet field))) |
| 3088 | (yas--snippet-fields snippet)))) | 3077 | (yas--snippet-fields snippet)))) |
| 3089 | (if (>= n 0) (nth n (memq active live-fields)) | 3078 | (nth (abs n) (memq active (if (>= n 0) live-fields (reverse live-fields)))))) |
| 3090 | (car (last (memq active (reverse live-fields)) (- n)))))) | ||
| 3091 | 3079 | ||
| 3092 | (defun yas-next-field (&optional arg) | 3080 | (defun yas-next-field (&optional arg) |
| 3093 | "Navigate to the ARGth next field. | 3081 | "Navigate to the ARGth next field. |
| @@ -3150,7 +3138,7 @@ Also create some protection overlays" | |||
| 3150 | 3138 | ||
| 3151 | (defun yas-exit-snippet (snippet) | 3139 | (defun yas-exit-snippet (snippet) |
| 3152 | "Goto exit-marker of SNIPPET." | 3140 | "Goto exit-marker of SNIPPET." |
| 3153 | (interactive (list (first (yas--snippets-at-point)))) | 3141 | (interactive (list (cl-first (yas--snippets-at-point)))) |
| 3154 | (when snippet | 3142 | (when snippet |
| 3155 | (setf (yas--snippet-force-exit snippet) t) | 3143 | (setf (yas--snippet-force-exit snippet) t) |
| 3156 | (goto-char (if (yas--snippet-exit snippet) | 3144 | (goto-char (if (yas--snippet-exit snippet) |
| @@ -3217,7 +3205,7 @@ This renders the snippet as ordinary text." | |||
| 3217 | ;; again from `yas--take-care-of-redo'.... | 3205 | ;; again from `yas--take-care-of-redo'.... |
| 3218 | (setf (yas--snippet-fields snippet) nil))) | 3206 | (setf (yas--snippet-fields snippet) nil))) |
| 3219 | 3207 | ||
| 3220 | (yas--message 3 "Snippet %s exited." (yas--snippet-id snippet))) | 3208 | (yas--message 4 "Snippet %s exited." (yas--snippet-id snippet))) |
| 3221 | 3209 | ||
| 3222 | (defun yas--safely-run-hooks (hook-var) | 3210 | (defun yas--safely-run-hooks (hook-var) |
| 3223 | (condition-case error | 3211 | (condition-case error |
| @@ -3423,14 +3411,15 @@ field start. This hook does nothing if an undo is in progress." | |||
| 3423 | (let* ((inhibit-modification-hooks t) | 3411 | (let* ((inhibit-modification-hooks t) |
| 3424 | (field (overlay-get overlay 'yas--field)) | 3412 | (field (overlay-get overlay 'yas--field)) |
| 3425 | (snippet (overlay-get yas--active-field-overlay 'yas--snippet))) | 3413 | (snippet (overlay-get yas--active-field-overlay 'yas--snippet))) |
| 3426 | (when (yas--skip-and-clear-field-p field beg end length) | 3414 | (save-match-data |
| 3427 | ;; We delete text starting from the END of insertion. | 3415 | (when (yas--skip-and-clear-field-p field beg end length) |
| 3428 | (yas--skip-and-clear field end)) | 3416 | ;; We delete text starting from the END of insertion. |
| 3429 | (setf (yas--field-modified-p field) t) | 3417 | (yas--skip-and-clear field end)) |
| 3430 | (yas--advance-end-maybe field (overlay-end overlay)) | 3418 | (setf (yas--field-modified-p field) t) |
| 3431 | (save-excursion | 3419 | (yas--advance-end-maybe field (overlay-end overlay)) |
| 3432 | (yas--field-update-display field)) | 3420 | (save-excursion |
| 3433 | (yas--update-mirrors snippet)))) | 3421 | (yas--field-update-display field)) |
| 3422 | (yas--update-mirrors snippet))))) | ||
| 3434 | 3423 | ||
| 3435 | ;;; Apropos protection overlays: | 3424 | ;;; Apropos protection overlays: |
| 3436 | ;; | 3425 | ;; |
| @@ -3461,9 +3450,10 @@ Move the overlays, or create them if they do not exit." | |||
| 3461 | ;; go on to normal overlay creation/moving | 3450 | ;; go on to normal overlay creation/moving |
| 3462 | ;; | 3451 | ;; |
| 3463 | (cond ((and yas--field-protection-overlays | 3452 | (cond ((and yas--field-protection-overlays |
| 3464 | (every #'overlay-buffer yas--field-protection-overlays)) | 3453 | (cl-every #'overlay-buffer yas--field-protection-overlays)) |
| 3465 | (move-overlay (first yas--field-protection-overlays) (1- start) start) | 3454 | (move-overlay (nth 0 yas--field-protection-overlays) |
| 3466 | (move-overlay (second yas--field-protection-overlays) end (1+ end))) | 3455 | (1- start) start) |
| 3456 | (move-overlay (nth 1 yas--field-protection-overlays) end (1+ end))) | ||
| 3467 | (t | 3457 | (t |
| 3468 | (setq yas--field-protection-overlays | 3458 | (setq yas--field-protection-overlays |
| 3469 | (list (make-overlay (1- start) start nil t nil) | 3459 | (list (make-overlay (1- start) start nil t nil) |
| @@ -3765,7 +3755,7 @@ has to be called before the $-constructs are deleted." | |||
| 3765 | (setq soup | 3755 | (setq soup |
| 3766 | (sort soup compare-fom-begs)) | 3756 | (sort soup compare-fom-begs)) |
| 3767 | (when soup | 3757 | (when soup |
| 3768 | (reduce link-foms soup))))) | 3758 | (cl-reduce link-foms soup))))) |
| 3769 | 3759 | ||
| 3770 | (defun yas--calculate-mirrors-in-fields (snippet mirror) | 3760 | (defun yas--calculate-mirrors-in-fields (snippet mirror) |
| 3771 | "Attempt to assign a parent field of SNIPPET to the mirror MIRROR. | 3761 | "Attempt to assign a parent field of SNIPPET to the mirror MIRROR. |
| @@ -3855,7 +3845,7 @@ Meant to be called in a narrowed buffer, does various passes" | |||
| 3855 | (yas--protect-escapes) | 3845 | (yas--protect-escapes) |
| 3856 | ;; Parse indent markers: `$>'. | 3846 | ;; Parse indent markers: `$>'. |
| 3857 | (goto-char parse-start) | 3847 | (goto-char parse-start) |
| 3858 | (yas--indent-parse-create snippet) | 3848 | (yas--indent-parse-create) |
| 3859 | ;; parse fields with {} | 3849 | ;; parse fields with {} |
| 3860 | ;; | 3850 | ;; |
| 3861 | (goto-char parse-start) | 3851 | (goto-char parse-start) |
| @@ -3961,12 +3951,11 @@ The SNIPPET's markers are preserved." | |||
| 3961 | (zerop (current-column))) | 3951 | (zerop (current-column))) |
| 3962 | (indent-to-column yas--indent-original-column))) | 3952 | (indent-to-column yas--indent-original-column))) |
| 3963 | ((eq yas-indent-line 'auto) | 3953 | ((eq yas-indent-line 'auto) |
| 3964 | (let ((end (set-marker (make-marker) (point-max)))) | 3954 | (unless yas-also-auto-indent-first-line |
| 3965 | (unless yas-also-auto-indent-first-line | 3955 | (forward-line 1)) |
| 3966 | (forward-line 1)) | 3956 | (yas--indent-region (line-beginning-position) |
| 3967 | (yas--indent-region (line-beginning-position) | 3957 | (point-max) |
| 3968 | (point-max) | 3958 | snippet))))) |
| 3969 | snippet)))))) | ||
| 3970 | 3959 | ||
| 3971 | (defun yas--collect-snippet-markers (snippet) | 3960 | (defun yas--collect-snippet-markers (snippet) |
| 3972 | "Make a list of all the markers used by SNIPPET." | 3961 | "Make a list of all the markers used by SNIPPET." |
| @@ -4015,36 +4004,39 @@ With optional string TEXT do it in string instead of the buffer." | |||
| 4015 | changed-text)) | 4004 | changed-text)) |
| 4016 | 4005 | ||
| 4017 | (defun yas--save-backquotes () | 4006 | (defun yas--save-backquotes () |
| 4018 | "Save all the \"`(lisp-expression)`\"-style expressions | 4007 | "Save all the \"\\=`(lisp-expression)\\=`\"-style expressions |
| 4019 | with their evaluated value into `yas--backquote-markers-and-strings'." | 4008 | with their evaluated value into `yas--backquote-markers-and-strings'." |
| 4020 | ;; Gather `(lisp-expression)`s. | 4009 | (let* ((yas--snippet-buffer (current-buffer)) |
| 4021 | (let ((end (point-max))) | 4010 | (yas--change-detected nil) |
| 4022 | (save-restriction | 4011 | (detect-change (lambda (_beg _end) |
| 4023 | (widen) | 4012 | (when (eq (current-buffer) yas--snippet-buffer) |
| 4024 | (while (re-search-forward yas--backquote-lisp-expression-regexp end t) | 4013 | (setq yas--change-detected t))))) |
| 4025 | (let ((expr (yas--read-lisp (yas--restore-escapes | 4014 | (while (re-search-forward yas--backquote-lisp-expression-regexp nil t) |
| 4026 | (match-string-no-properties 1)))) | 4015 | (let ((current-string (match-string-no-properties 1)) transformed) |
| 4027 | (marker (make-marker))) | ||
| 4028 | (delete-region (match-beginning 0) (match-end 0)) | ||
| 4029 | (insert "Y") ;; quite horrendous, I love it :) | ||
| 4030 | (set-marker marker (point)) | ||
| 4031 | (insert "Y") | ||
| 4032 | (push (cons marker expr) yas--backquote-markers-and-strings))))) | ||
| 4033 | ;; Evaluate them. | ||
| 4034 | (dolist (m-e yas--backquote-markers-and-strings) | ||
| 4035 | (let* ((marker (car m-e)) | ||
| 4036 | (expr (cdr m-e)) | ||
| 4037 | (result (save-excursion | ||
| 4038 | (goto-char marker) | ||
| 4039 | (yas--eval-lisp expr)))) | ||
| 4040 | (setcdr m-e result) | ||
| 4041 | (unless result | ||
| 4042 | (save-restriction (widen) | 4016 | (save-restriction (widen) |
| 4043 | (delete-region (1- marker) (1+ marker))) | 4017 | (delete-region (match-beginning 0) (match-end 0))) |
| 4044 | (set-marker marker nil)))) | 4018 | (let ((before-change-functions |
| 4045 | ;; Drop the nil results. | 4019 | (cons detect-change before-change-functions))) |
| 4046 | (setq yas--backquote-markers-and-strings | 4020 | (setq transformed (yas--eval-lisp (yas--read-lisp |
| 4047 | (cl-delete-if-not #'cdr yas--backquote-markers-and-strings))) | 4021 | (yas--restore-escapes |
| 4022 | current-string '(?`)))))) | ||
| 4023 | (goto-char (match-beginning 0)) | ||
| 4024 | (when transformed | ||
| 4025 | (let ((marker (make-marker)) | ||
| 4026 | (before-change-functions (cdr before-change-functions))) | ||
| 4027 | (save-restriction | ||
| 4028 | (widen) | ||
| 4029 | (insert "Y") ;; quite horrendous, I love it :) | ||
| 4030 | (set-marker marker (point)) | ||
| 4031 | (insert "Y")) | ||
| 4032 | (push (cons marker transformed) yas--backquote-markers-and-strings))))) | ||
| 4033 | (when yas--change-detected | ||
| 4034 | (lwarn '(yasnippet backquote-change) :warning | ||
| 4035 | "`%s' modified buffer in a backquote expression. | ||
| 4036 | To hide this warning, add (yasnippet backquote-change) to `warning-suppress-types'." | ||
| 4037 | (if yas--current-template | ||
| 4038 | (yas--template-name yas--current-template) | ||
| 4039 | "Snippet"))))) | ||
| 4048 | 4040 | ||
| 4049 | (defun yas--restore-backquotes () | 4041 | (defun yas--restore-backquotes () |
| 4050 | "Replace markers in `yas--backquote-markers-and-strings' with their values." | 4042 | "Replace markers in `yas--backquote-markers-and-strings' with their values." |
| @@ -4073,8 +4065,8 @@ with their evaluated value into `yas--backquote-markers-and-strings'." | |||
| 4073 | (set-marker-insertion-type marker nil) | 4065 | (set-marker-insertion-type marker nil) |
| 4074 | marker)) | 4066 | marker)) |
| 4075 | 4067 | ||
| 4076 | (defun yas--indent-parse-create (snippet) | 4068 | (defun yas--indent-parse-create () |
| 4077 | "Parse the \"$>\" indentation markers in SNIPPET." | 4069 | "Parse the \"$>\" indentation markers just inserted." |
| 4078 | (setq yas--indent-markers ()) | 4070 | (setq yas--indent-markers ()) |
| 4079 | (while (search-forward "$>" nil t) | 4071 | (while (search-forward "$>" nil t) |
| 4080 | (delete-region (match-beginning 0) (match-end 0)) | 4072 | (delete-region (match-beginning 0) (match-end 0)) |
| @@ -4221,19 +4213,15 @@ When multiple expressions are found, only the last one counts." | |||
| 4221 | (yas--field-mirrors parent)))) | 4213 | (yas--field-mirrors parent)))) |
| 4222 | (or (yas--mirror-depth mirror) | 4214 | (or (yas--mirror-depth mirror) |
| 4223 | (setf (yas--mirror-depth mirror) | 4215 | (setf (yas--mirror-depth mirror) |
| 4224 | (cond ((memq mirror traversed) | 4216 | (cond ((memq mirror traversed) 0) |
| 4225 | 0) | ||
| 4226 | ((and parent parents-mirrors) | 4217 | ((and parent parents-mirrors) |
| 4227 | (1+ (reduce #'max | 4218 | (1+ (cl-reduce |
| 4228 | (mapcar #'(lambda (m) | 4219 | #'max parents-mirrors |
| 4229 | (yas--calculate-mirror-depth m | 4220 | :key (lambda (m) |
| 4230 | (cons mirror | 4221 | (yas--calculate-mirror-depth |
| 4231 | traversed))) | 4222 | m (cons mirror traversed)))))) |
| 4232 | parents-mirrors)))) | 4223 | (parent 1) |
| 4233 | (parent | 4224 | (t 0)))))) |
| 4234 | 1) | ||
| 4235 | (t | ||
| 4236 | 0)))))) | ||
| 4237 | 4225 | ||
| 4238 | (defun yas--update-mirrors (snippet) | 4226 | (defun yas--update-mirrors (snippet) |
| 4239 | "Update all the mirrors of SNIPPET." | 4227 | "Update all the mirrors of SNIPPET." |
| @@ -4248,7 +4236,11 @@ When multiple expressions are found, only the last one counts." | |||
| 4248 | (cl-mapcan #'(lambda (field) | 4236 | (cl-mapcan #'(lambda (field) |
| 4249 | (mapcar #'(lambda (mirror) | 4237 | (mapcar #'(lambda (mirror) |
| 4250 | (cons field mirror)) | 4238 | (cons field mirror)) |
| 4251 | (yas--field-mirrors field))) | 4239 | (cl-sort |
| 4240 | (cl-copy-list | ||
| 4241 | (yas--field-mirrors field)) | ||
| 4242 | #'< | ||
| 4243 | :key #'yas--mirror-start))) | ||
| 4252 | (yas--snippet-fields snippet)) | 4244 | (yas--snippet-fields snippet)) |
| 4253 | ;; then sort this list so that entries with mirrors with parent | 4245 | ;; then sort this list so that entries with mirrors with parent |
| 4254 | ;; fields appear before. This was important for fixing #290, and | 4246 | ;; fields appear before. This was important for fixing #290, and |
| @@ -4329,12 +4321,14 @@ When multiple expressions are found, only the last one counts." | |||
| 4329 | ;; restored correctly, this condition handles that | 4321 | ;; restored correctly, this condition handles that |
| 4330 | ;; | 4322 | ;; |
| 4331 | (let* ((snippet (car (yas--snippets-at-point))) | 4323 | (let* ((snippet (car (yas--snippets-at-point))) |
| 4332 | (target-field (and snippet | 4324 | (target-field |
| 4333 | (find-if-not #'(lambda (field) | 4325 | (and snippet |
| 4334 | (yas--field-probably-deleted-p snippet field)) | 4326 | (cl-find-if-not |
| 4335 | (remove nil | 4327 | (lambda (field) |
| 4336 | (cons (yas--snippet-active-field snippet) | 4328 | (yas--field-probably-deleted-p snippet field)) |
| 4337 | (yas--snippet-fields snippet))))))) | 4329 | (remq nil |
| 4330 | (cons (yas--snippet-active-field snippet) | ||
| 4331 | (yas--snippet-fields snippet))))))) | ||
| 4338 | (when target-field | 4332 | (when target-field |
| 4339 | (yas--move-to-field snippet target-field)))) | 4333 | (yas--move-to-field snippet target-field)))) |
| 4340 | ((not (yas--undo-in-progress)) | 4334 | ((not (yas--undo-in-progress)) |
| @@ -4376,9 +4370,9 @@ object satisfying `yas--field-p' to restrict the expansion to."))) | |||
| 4376 | (concat "Expand/run snippets from keymaps, possibly falling back to original binding.\n" | 4370 | (concat "Expand/run snippets from keymaps, possibly falling back to original binding.\n" |
| 4377 | (when (and context (eq this-command 'describe-key)) | 4371 | (when (and context (eq this-command 'describe-key)) |
| 4378 | (let* ((vec (this-single-command-keys)) | 4372 | (let* ((vec (this-single-command-keys)) |
| 4379 | (templates (mapcan #'(lambda (table) | 4373 | (templates (cl-mapcan (lambda (table) |
| 4380 | (yas--fetch table vec)) | 4374 | (yas--fetch table vec)) |
| 4381 | (yas--get-snippet-tables))) | 4375 | (yas--get-snippet-tables))) |
| 4382 | (yas--direct-keymaps nil) | 4376 | (yas--direct-keymaps nil) |
| 4383 | (fallback (key-binding vec))) | 4377 | (fallback (key-binding vec))) |
| 4384 | (concat "In this case, " | 4378 | (concat "In this case, " |
| @@ -4427,8 +4421,8 @@ object satisfying `yas--field-p' to restrict the expansion to."))) | |||
| 4427 | "Log level for `yas--message' 4 means trace most anything, 0 means nothing.") | 4421 | "Log level for `yas--message' 4 means trace most anything, 0 means nothing.") |
| 4428 | 4422 | ||
| 4429 | (defun yas--message (level message &rest args) | 4423 | (defun yas--message (level message &rest args) |
| 4430 | "When LEVEL is above `yas-verbosity-level', log MESSAGE and ARGS." | 4424 | "When LEVEL is at or below `yas-verbosity-level', log MESSAGE and ARGS." |
| 4431 | (when (> yas-verbosity level) | 4425 | (when (>= yas-verbosity level) |
| 4432 | (message "%s" (apply #'yas--format message args)))) | 4426 | (message "%s" (apply #'yas--format message args)))) |
| 4433 | 4427 | ||
| 4434 | (defun yas--warning (format-control &rest format-args) | 4428 | (defun yas--warning (format-control &rest format-args) |
| @@ -4647,6 +4641,5 @@ can more or less safely rely upon them.") | |||
| 4647 | ;; Local Variables: | 4641 | ;; Local Variables: |
| 4648 | ;; coding: utf-8 | 4642 | ;; coding: utf-8 |
| 4649 | ;; indent-tabs-mode: nil | 4643 | ;; indent-tabs-mode: nil |
| 4650 | ;; byte-compile-warnings: (not cl-functions) | ||
| 4651 | ;; End: | 4644 | ;; End: |
| 4652 | ;;; yasnippet.el ends here | 4645 | ;;; yasnippet.el ends here |
