summaryrefslogtreecommitdiff
path: root/.emacs.d/lisp/yasnippet.el
diff options
context:
space:
mode:
authorSimeon Simeonov2023-11-01 20:24:03 +0100
committerSimeon Simeonov2023-11-01 20:24:03 +0100
commitf6ecb707b36d71b6a24e224b3635223f7a5b8b33 (patch)
tree30638dd9f373557e61b9ac5c955f213a1fef11fe /.emacs.d/lisp/yasnippet.el
parent415d67fe3ac92dc69b34bfe2b2f4a793d0f83e14 (diff)
Upgrade lua-mode, markdown-mode and yasnippet
Diffstat (limited to '.emacs.d/lisp/yasnippet.el')
-rw-r--r--.emacs.d/lisp/yasnippet.el157
1 files changed, 40 insertions, 117 deletions
diff --git a/.emacs.d/lisp/yasnippet.el b/.emacs.d/lisp/yasnippet.el
index 78ef38a..c4f8ae4 100644
--- a/.emacs.d/lisp/yasnippet.el
+++ b/.emacs.d/lisp/yasnippet.el
@@ -1,6 +1,6 @@
1;;; yasnippet.el --- Yet another snippet extension for Emacs 1;;; yasnippet.el --- Yet another snippet extension for Emacs -*- lexical-binding: t; -*-
2 2
3;; Copyright (C) 2008-2019 Free Software Foundation, Inc. 3;; Copyright (C) 2008-2023 Free Software Foundation, Inc.
4;; Authors: pluskid <pluskid@gmail.com>, 4;; Authors: pluskid <pluskid@gmail.com>,
5;; João Távora <joaotavora@gmail.com>, 5;; João Távora <joaotavora@gmail.com>,
6;; Noam Postavsky <npostavs@gmail.com> 6;; Noam Postavsky <npostavs@gmail.com>
@@ -9,7 +9,7 @@
9;; X-URL: http://github.com/joaotavora/yasnippet 9;; X-URL: http://github.com/joaotavora/yasnippet
10;; Keywords: convenience, emulation 10;; Keywords: convenience, emulation
11;; URL: http://github.com/joaotavora/yasnippet 11;; URL: http://github.com/joaotavora/yasnippet
12;; Package-Requires: ((cl-lib "0.5")) 12;; Package-Requires: ((cl-lib "0.5") (emacs "24.4"))
13;; EmacsWiki: YaSnippetMode 13;; EmacsWiki: YaSnippetMode
14 14
15;; 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
@@ -474,20 +474,20 @@ See also Info node `(elisp) Syntax Descriptors'.")
474 474
475(defvar yas-after-exit-snippet-hook 475(defvar yas-after-exit-snippet-hook
476 '() 476 '()
477 "Hooks to run after a snippet exited. 477 "Hook run after a snippet exited.
478 478
479The hooks will be run in an environment where some variables bound to 479The functions will be run in an environment where some variables bound to
480proper values: 480proper values:
481 481
482`yas-snippet-beg' : The beginning of the region of the snippet. 482`yas-snippet-beg' : The beginning of the region of the snippet.
483 483
484`yas-snippet-end' : Similar to beg. 484`yas-snippet-end' : Similar to beg.
485 485
486Attention: These hooks are not run when exiting nested/stacked snippet expansion!") 486Attention: This hook is not run when exiting nested/stacked snippet expansion!")
487 487
488(defvar yas-before-expand-snippet-hook 488(defvar yas-before-expand-snippet-hook
489 '() 489 '()
490 "Hooks to run just before expanding a snippet.") 490 "Hook run just before expanding a snippet.")
491 491
492(defconst yas-not-string-or-comment-condition 492(defconst yas-not-string-or-comment-condition
493 '(if (let ((ppss (syntax-ppss))) 493 '(if (let ((ppss (syntax-ppss)))
@@ -611,38 +611,6 @@ can be useful."
611(defvar yas--snippet-id-seed 0 611(defvar yas--snippet-id-seed 0
612 "Contains the next id for a snippet.") 612 "Contains the next id for a snippet.")
613 613
614(defvar yas--original-auto-fill-function nil
615 "The original value of `auto-fill-function'.")
616(make-variable-buffer-local 'yas--original-auto-fill-function)
617
618(defvar yas--watch-auto-fill-backtrace nil)
619
620(defun yas--watch-auto-fill (sym newval op _where)
621 (when (and (or (and (eq sym 'yas--original-auto-fill-function)
622 (null newval)
623 (eq auto-fill-function 'yas--auto-fill))
624 (and (eq sym 'auto-fill-function)
625 (eq newval 'yas--auto-fill)
626 (null yas--original-auto-fill-function)))
627 (null yas--watch-auto-fill-backtrace)
628 (fboundp 'backtrace-frames) ; Suppress compiler warning.
629 ;; If we're about to change `auto-fill-function' too,
630 ;; it's okay (probably).
631 (not (and (eq op 'makunbound)
632 (not (eq (default-value 'auto-fill-function) 'yas--auto-fill))
633 (cl-member 'kill-all-local-variables
634 (backtrace-frames 'yas--watch-auto-fill)
635 :key (lambda (frame) (nth 1 frame))))))
636 (setq yas--watch-auto-fill-backtrace
637 (backtrace-frames 'yas--watch-auto-fill))))
638
639;; Try to get more info on #873/919 (this only works for Emacs 26+).
640(when (fboundp 'add-variable-watcher)
641 (add-variable-watcher 'yas--original-auto-fill-function
642 #'yas--watch-auto-fill)
643 (add-variable-watcher 'auto-fill-function
644 #'yas--watch-auto-fill))
645
646(defun yas--snippet-next-id () 614(defun yas--snippet-next-id ()
647 (let ((id yas--snippet-id-seed)) 615 (let ((id yas--snippet-id-seed))
648 (cl-incf yas--snippet-id-seed) 616 (cl-incf yas--snippet-id-seed)
@@ -676,11 +644,16 @@ expanded.")
676 644
677(defvar yas-minor-mode-map 645(defvar yas-minor-mode-map
678 (let ((map (make-sparse-keymap))) 646 (let ((map (make-sparse-keymap)))
679 (define-key map [(tab)] yas-maybe-expand) 647 ;; Modes should always bind to TAB instead of `tab', so as not to override
648 ;; bindings that should take higher precedence but which bind to `TAB`
649 ;; instead (relying on `function-key-map` to remap `tab` to TAB).
650 ;; If this causes problem because of another package that binds to `tab`,
651 ;; complain to that other package!
652 ;;(define-key map [(tab)] yas-maybe-expand)
680 (define-key map (kbd "TAB") yas-maybe-expand) 653 (define-key map (kbd "TAB") yas-maybe-expand)
681 (define-key map "\C-c&\C-s" 'yas-insert-snippet) 654 (define-key map "\C-c&\C-s" #'yas-insert-snippet)
682 (define-key map "\C-c&\C-n" 'yas-new-snippet) 655 (define-key map "\C-c&\C-n" #'yas-new-snippet)
683 (define-key map "\C-c&\C-v" 'yas-visit-snippet-file) 656 (define-key map "\C-c&\C-v" #'yas-visit-snippet-file)
684 map) 657 map)
685 "The keymap used when `yas-minor-mode' is active.") 658 "The keymap used when `yas-minor-mode' is active.")
686 659
@@ -860,10 +833,9 @@ which decides on the snippet to expand.")
860 "Hook run when `yas-minor-mode' is turned on.") 833 "Hook run when `yas-minor-mode' is turned on.")
861 834
862(defun yas--auto-fill-wrapper () 835(defun yas--auto-fill-wrapper ()
863 (when (and auto-fill-function 836 (when auto-fill-function ;Turning the mode ON.
864 (not (eq auto-fill-function #'yas--auto-fill))) 837 ;; (cl-assert (local-variable-p 'auto-fill-function))
865 (setq yas--original-auto-fill-function auto-fill-function) 838 (add-function :around (local 'auto-fill-function) #'yas--auto-fill)))
866 (setq auto-fill-function #'yas--auto-fill)))
867 839
868;;;###autoload 840;;;###autoload
869(define-minor-mode yas-minor-mode 841(define-minor-mode yas-minor-mode
@@ -906,8 +878,8 @@ Key bindings:
906 ;; auto-fill handler. 878 ;; auto-fill handler.
907 (remove-hook 'post-command-hook #'yas--post-command-handler t) 879 (remove-hook 'post-command-hook #'yas--post-command-handler t)
908 (remove-hook 'auto-fill-mode-hook #'yas--auto-fill-wrapper) 880 (remove-hook 'auto-fill-mode-hook #'yas--auto-fill-wrapper)
909 (when (local-variable-p 'yas--original-auto-fill-function) 881 (when (local-variable-p 'auto-fill-function)
910 (setq auto-fill-function yas--original-auto-fill-function)) 882 (remove-function (local 'auto-fill-function) #'yas--auto-fill))
911 (setq emulation-mode-map-alists 883 (setq emulation-mode-map-alists
912 (remove 'yas--direct-keymaps emulation-mode-map-alists))))) 884 (remove 'yas--direct-keymaps emulation-mode-map-alists)))))
913 885
@@ -1344,7 +1316,7 @@ string and TEMPLATE is a `yas--template' structure."
1344 (save-excursion 1316 (save-excursion
1345 (save-restriction 1317 (save-restriction
1346 (save-match-data 1318 (save-match-data
1347 (eval condition)))) 1319 (eval condition t))))
1348 (error (progn 1320 (error (progn
1349 (yas--message 1 "Error in condition evaluation: %s" (error-message-string err)) 1321 (yas--message 1 "Error in condition evaluation: %s" (error-message-string err))
1350 nil)))) 1322 nil))))
@@ -1502,7 +1474,7 @@ Also tries to work around Emacs Bug#30931."
1502 (save-excursion 1474 (save-excursion
1503 (yas--save-restriction-and-widen 1475 (yas--save-restriction-and-widen
1504 (save-match-data 1476 (save-match-data
1505 (let ((result (eval form))) 1477 (let ((result (eval form t)))
1506 (when result 1478 (when result
1507 (format "%s" result)))))) 1479 (format "%s" result))))))
1508 ((debug error) (error-message-string oops))))) 1480 ((debug error) (error-message-string oops)))))
@@ -1518,7 +1490,7 @@ return an expression that when evaluated will issue an error."
1518 (condition-case err 1490 (condition-case err
1519 (read string) 1491 (read string)
1520 (error (and (not nil-on-error) 1492 (error (and (not nil-on-error)
1521 `(error (error-message-string ,err)))))) 1493 `(error (error-message-string ',err))))))
1522 1494
1523(defun yas--read-keybinding (keybinding) 1495(defun yas--read-keybinding (keybinding)
1524 "Read KEYBINDING as a snippet keybinding, return a vector." 1496 "Read KEYBINDING as a snippet keybinding, return a vector."
@@ -1813,7 +1785,8 @@ Optional PROMPT sets the prompt to use."
1813SNIPPETS is a list of snippet definitions, each taking the 1785SNIPPETS is a list of snippet definitions, each taking the
1814following form 1786following form
1815 1787
1816 (KEY TEMPLATE NAME CONDITION GROUP EXPAND-ENV LOAD-FILE KEYBINDING UUID SAVE-FILE) 1788 (KEY TEMPLATE
1789 NAME CONDITION GROUP EXPAND-ENV LOAD-FILE KEYBINDING UUID SAVE-FILE)
1817 1790
1818Within these, only KEY and TEMPLATE are actually mandatory. 1791Within these, only KEY and TEMPLATE are actually mandatory.
1819 1792
@@ -2074,7 +2047,7 @@ prefix argument."
2074 "successfully"))))))) 2047 "successfully")))))))
2075 2048
2076(defvar yas-after-reload-hook nil 2049(defvar yas-after-reload-hook nil
2077 "Hooks run after `yas-reload-all'.") 2050 "Hook run after `yas-reload-all'.")
2078 2051
2079(defun yas--load-pending-jits () 2052(defun yas--load-pending-jits ()
2080 (dolist (mode (yas--modes-to-activate)) 2053 (dolist (mode (yas--modes-to-activate))
@@ -2341,7 +2314,7 @@ value for the first time then always returns a cached value.")
2341 (put ',func 'yas--condition-cache (cons yas--condition-cache-timestamp new-value)) 2314 (put ',func 'yas--condition-cache (cons yas--condition-cache-timestamp new-value))
2342 new-value))))) 2315 new-value)))))
2343 2316
2344(defalias 'yas-expand 'yas-expand-from-trigger-key) 2317(defalias 'yas-expand #'yas-expand-from-trigger-key)
2345(defun yas-expand-from-trigger-key (&optional field) 2318(defun yas-expand-from-trigger-key (&optional field)
2346 "Expand a snippet before point. 2319 "Expand a snippet before point.
2347 2320
@@ -2980,7 +2953,8 @@ marks it as something else (typically comment ender)."
2980 'again)) 2953 'again))
2981 2954
2982(defun yas-longest-key-from-whitespace (start-point) 2955(defun yas-longest-key-from-whitespace (start-point)
2983 "As `yas-key-syntaxes' element, look for longest key between point and whitespace. 2956 "Look for longest key between point and whitespace.
2957For use as `yas-key-syntaxes' element.
2984 2958
2985A newline will be considered whitespace even if the mode syntax 2959A newline will be considered whitespace even if the mode syntax
2986marks it as something else (typically comment ender)." 2960marks it as something else (typically comment ender)."
@@ -3067,8 +3041,7 @@ snippet field. The arguments are the same as `completing-read'.
3067(defun yas-throw (text) 3041(defun yas-throw (text)
3068 "Signal `yas-exception' with TEXT as the reason." 3042 "Signal `yas-exception' with TEXT as the reason."
3069 (signal 'yas-exception (list text))) 3043 (signal 'yas-exception (list text)))
3070(put 'yas-exception 'error-conditions '(error yas-exception)) 3044(define-error 'yas-exception "[yas] Exception")
3071(put 'yas-exception 'error-message "[yas] Exception")
3072 3045
3073(defun yas-verify-value (possibilities) 3046(defun yas-verify-value (possibilities)
3074 "Verify that the current field value is in POSSIBILITIES. 3047 "Verify that the current field value is in POSSIBILITIES.
@@ -3208,7 +3181,7 @@ expression that evaluates to its value."
3208 `(let ((,envvar ,env)) 3181 `(let ((,envvar ,env))
3209 (cl-progv 3182 (cl-progv
3210 (mapcar #'car ,envvar) 3183 (mapcar #'car ,envvar)
3211 (mapcar (lambda (v-f) (eval (cadr v-f))) ,envvar) 3184 (mapcar (lambda (v-f) (eval (cadr v-f) t)) ,envvar)
3212 ,@body)))) 3185 ,@body))))
3213 3186
3214(defun yas--snippet-map-markers (fun snippet) 3187(defun yas--snippet-map-markers (fun snippet)
@@ -3349,7 +3322,7 @@ equivalent to a range covering the whole buffer."
3349 (cl-sort snippets #'>= :key #'yas--snippet-id)))) 3322 (cl-sort snippets #'>= :key #'yas--snippet-id))))
3350 3323
3351(define-obsolete-function-alias 'yas--snippets-at-point 3324(define-obsolete-function-alias 'yas--snippets-at-point
3352 'yas-active-snippets "0.12") 3325 #'yas-active-snippets "0.12")
3353 3326
3354(defun yas-next-field-or-maybe-expand () 3327(defun yas-next-field-or-maybe-expand ()
3355 "Try to expand a snippet at a key before point. 3328 "Try to expand a snippet at a key before point.
@@ -3728,8 +3701,8 @@ Use as a `:filter' argument for a conditional keybinding."
3728 "Clears unmodified field if at field start, skips to next tab. 3701 "Clears unmodified field if at field start, skips to next tab.
3729 3702
3730Otherwise deletes a character normally by calling `delete-char'." 3703Otherwise deletes a character normally by calling `delete-char'."
3731 (interactive)
3732 (declare (obsolete "Bind to `yas-maybe-skip-and-clear-field' instead." "0.13")) 3704 (declare (obsolete "Bind to `yas-maybe-skip-and-clear-field' instead." "0.13"))
3705 (interactive)
3733 (cond ((yas--maybe-clear-field-filter t) 3706 (cond ((yas--maybe-clear-field-filter t)
3734 (yas--skip-and-clear (or field (yas-current-field))) 3707 (yas--skip-and-clear (or field (yas-current-field)))
3735 (yas-next-field 1)) 3708 (yas-next-field 1))
@@ -3880,7 +3853,7 @@ field start. This hook does nothing if an undo is in progress."
3880 snippet (yas--snippet-field-mirrors snippet))) 3853 snippet (yas--snippet-field-mirrors snippet)))
3881 (setq yas--todo-snippet-indent nil)))) 3854 (setq yas--todo-snippet-indent nil))))
3882 3855
3883(defun yas--auto-fill () 3856(defun yas--auto-fill (orig-fun &rest args)
3884 ;; Preserve snippet markers during auto-fill. 3857 ;; Preserve snippet markers during auto-fill.
3885 (let* ((orig-point (point)) 3858 (let* ((orig-point (point))
3886 (end (progn (forward-paragraph) (point))) 3859 (end (progn (forward-paragraph) (point)))
@@ -3897,44 +3870,7 @@ field start. This hook does nothing if an undo is in progress."
3897 reoverlays)) 3870 reoverlays))
3898 (goto-char orig-point) 3871 (goto-char orig-point)
3899 (let ((yas--inhibit-overlay-hooks t)) 3872 (let ((yas--inhibit-overlay-hooks t))
3900 (if yas--original-auto-fill-function 3873 (apply orig-fun args))
3901 (funcall yas--original-auto-fill-function)
3902 ;; Shouldn't happen, gather more info about it (see #873/919).
3903 (let ((yas--fill-fun-values `((t ,(default-value 'yas--original-auto-fill-function))))
3904 (fill-fun-values `((t ,(default-value 'auto-fill-function))))
3905 ;; Listing 2 buffers with the same value is enough
3906 (print-length 3))
3907 (save-current-buffer
3908 (dolist (buf (let ((bufs (buffer-list)))
3909 ;; List the current buffer first.
3910 (setq bufs (cons (current-buffer)
3911 (remq (current-buffer) bufs)))))
3912 (set-buffer buf)
3913 (let* ((yf-cell (assq yas--original-auto-fill-function
3914 yas--fill-fun-values))
3915 (af-cell (assq auto-fill-function fill-fun-values)))
3916 (when (local-variable-p 'yas--original-auto-fill-function)
3917 (if yf-cell (setcdr yf-cell (cons buf (cdr yf-cell)))
3918 (push (list yas--original-auto-fill-function buf) yas--fill-fun-values)))
3919 (when (local-variable-p 'auto-fill-function)
3920 (if af-cell (setcdr af-cell (cons buf (cdr af-cell)))
3921 (push (list auto-fill-function buf) fill-fun-values))))))
3922 (lwarn '(yasnippet auto-fill bug) :error
3923 "`yas--original-auto-fill-function' unexpectedly nil in %S! Disabling auto-fill.
3924 %S
3925 `auto-fill-function': %S\n%s"
3926 (current-buffer) yas--fill-fun-values fill-fun-values
3927 (if (fboundp 'backtrace--print-frame)
3928 (with-output-to-string
3929 (mapc (lambda (frame)
3930 (apply #'backtrace--print-frame frame))
3931 yas--watch-auto-fill-backtrace))
3932 ""))
3933 ;; Try to avoid repeated triggering of this bug.
3934 (auto-fill-mode -1)
3935 ;; Don't pop up more than once in a session (still log though).
3936 (defvar warning-suppress-types) ; `warnings' is autoloaded by `lwarn'.
3937 (add-to-list 'warning-suppress-types '(yasnippet auto-fill bug)))))
3938 (save-excursion 3874 (save-excursion
3939 (setq end (progn (forward-paragraph) (point))) 3875 (setq end (progn (forward-paragraph) (point)))
3940 (setq beg (progn (backward-paragraph) (point)))) 3876 (setq beg (progn (backward-paragraph) (point))))
@@ -4006,8 +3942,6 @@ Move the overlays, or create them if they do not exit."
4006 (cl-loop for snippet in snippets 3942 (cl-loop for snippet in snippets
4007 do (yas--commit-snippet snippet))))) 3943 do (yas--commit-snippet snippet)))))
4008 3944
4009(add-to-list 'debug-ignored-errors "^Exit the snippet first!$")
4010
4011 3945
4012;;; Snippet expansion and "stacked" expansion: 3946;;; Snippet expansion and "stacked" expansion:
4013;; 3947;;
@@ -4739,10 +4673,11 @@ The following count as a field:
4739 4673
4740* \"${n: text}\", for a numbered field with default text, as long as N is not 0; 4674* \"${n: text}\", for a numbered field with default text, as long as N is not 0;
4741 4675
4742* \"${n: text$(expression)}, the same with a Lisp expression; 4676* \"${n: text$(expression)}, the same with a Lisp expression; this is caught
4743 this is caught with the curiously named `yas--multi-dollar-lisp-expression-regexp' 4677 with the curiously named `yas--multi-dollar-lisp-expression-regexp'
4744 4678
4745* the same as above but unnumbered, (no N:) and number is calculated automatically. 4679* the same as above but unnumbered, (no N:) and number is calculated
4680 automatically.
4746 4681
4747When multiple expressions are found, only the last one counts." 4682When multiple expressions are found, only the last one counts."
4748 ;; 4683 ;;
@@ -4988,18 +4923,6 @@ When multiple expressions are found, only the last one counts."
4988;; 4923;;
4989(defun yas--post-command-handler () 4924(defun yas--post-command-handler ()
4990 "Handles various yasnippet conditions after each command." 4925 "Handles various yasnippet conditions after each command."
4991 (when (and yas--watch-auto-fill-backtrace
4992 (fboundp 'backtrace--print-frame)
4993 (null yas--original-auto-fill-function)
4994 (eq auto-fill-function 'yas--auto-fill))
4995 (lwarn '(yasnippet auto-fill bug) :error
4996 "`yas--original-auto-fill-function' unexpectedly nil! Please report this backtrace\n%S"
4997 (with-output-to-string
4998 (mapc #'backtrace--print-frame
4999 yas--watch-auto-fill-backtrace)))
5000 ;; Don't pop up more than once in a session (still log though).
5001 (defvar warning-suppress-types) ; `warnings' is autoloaded by `lwarn'.
5002 (add-to-list 'warning-suppress-types '(yasnippet auto-fill bug)))
5003 (yas--do-todo-snippet-indent) 4926 (yas--do-todo-snippet-indent)
5004 (condition-case err 4927 (condition-case err
5005 (progn (yas--finish-moving-snippets) 4928 (progn (yas--finish-moving-snippets)