diff options
| author | Simeon Simeonov | 2023-11-01 20:24:03 +0100 |
|---|---|---|
| committer | Simeon Simeonov | 2023-11-01 20:24:03 +0100 |
| commit | f6ecb707b36d71b6a24e224b3635223f7a5b8b33 (patch) | |
| tree | 30638dd9f373557e61b9ac5c955f213a1fef11fe | |
| parent | 415d67fe3ac92dc69b34bfe2b2f4a793d0f83e14 (diff) | |
Upgrade lua-mode, markdown-mode and yasnippet
| -rw-r--r-- | .emacs.d/lisp/lua-mode.el | 23 | ||||
| -rw-r--r-- | .emacs.d/lisp/markdown-mode.el | 78 | ||||
| -rw-r--r-- | .emacs.d/lisp/yasnippet.el | 157 |
3 files changed, 124 insertions, 134 deletions
diff --git a/.emacs.d/lisp/lua-mode.el b/.emacs.d/lisp/lua-mode.el index 6ab4d43..6c524f5 100644 --- a/.emacs.d/lisp/lua-mode.el +++ b/.emacs.d/lisp/lua-mode.el | |||
| @@ -330,8 +330,9 @@ Should be a list of strings." | |||
| 330 | :type 'string | 330 | :type 'string |
| 331 | :group 'lua | 331 | :group 'lua |
| 332 | :set 'lua--customize-set-prefix-key | 332 | :set 'lua--customize-set-prefix-key |
| 333 | :get '(lambda (sym) | 333 | :get (lambda (sym) |
| 334 | (let ((val (eval sym))) (if val (single-key-description (eval sym)) "")))) | 334 | (let ((val (eval sym))) |
| 335 | (if val (single-key-description (eval sym)) "")))) | ||
| 335 | 336 | ||
| 336 | (defvar lua-mode-menu (make-sparse-keymap "Lua") | 337 | (defvar lua-mode-menu (make-sparse-keymap "Lua") |
| 337 | "Keymap for lua-mode's menu.") | 338 | "Keymap for lua-mode's menu.") |
| @@ -994,7 +995,7 @@ placed before the string." | |||
| 994 | (defun lua-find-regexp (direction regexp &optional limit) | 995 | (defun lua-find-regexp (direction regexp &optional limit) |
| 995 | "Searches for a regular expression in the direction specified. | 996 | "Searches for a regular expression in the direction specified. |
| 996 | 997 | ||
| 997 | Direction is one of 'forward and 'backward. | 998 | Direction is one of \\='forward and \\='backward. |
| 998 | 999 | ||
| 999 | Matches in comments and strings are ignored. If the regexp is | 1000 | Matches in comments and strings are ignored. If the regexp is |
| 1000 | found, returns point position, nil otherwise." | 1001 | found, returns point position, nil otherwise." |
| @@ -1097,12 +1098,12 @@ TOKEN-TYPE determines where the token occurs on a statement. open indicates that | |||
| 1097 | "Find matching open- or close-token for TOKEN in DIRECTION. | 1098 | "Find matching open- or close-token for TOKEN in DIRECTION. |
| 1098 | Point has to be exactly at the beginning of TOKEN, e.g. with | being point | 1099 | Point has to be exactly at the beginning of TOKEN, e.g. with | being point |
| 1099 | 1100 | ||
| 1100 | {{ }|} -- (lua-find-matching-token-word \"}\" 'backward) will return | 1101 | {{ }|} -- (lua-find-matching-token-word \"}\" \\='backward) will return |
| 1101 | -- the first { | 1102 | -- the first { |
| 1102 | {{ |}} -- (lua-find-matching-token-word \"}\" 'backward) will find | 1103 | {{ |}} -- (lua-find-matching-token-word \"}\" \\='backward) will find |
| 1103 | -- the second {. | 1104 | -- the second {. |
| 1104 | 1105 | ||
| 1105 | DIRECTION has to be either 'forward or 'backward." | 1106 | DIRECTION has to be either \\='forward or \\='backward." |
| 1106 | (let* ((token-info (lua-get-block-token-info token)) | 1107 | (let* ((token-info (lua-get-block-token-info token)) |
| 1107 | (match-type (lua-get-token-type token-info)) | 1108 | (match-type (lua-get-token-type token-info)) |
| 1108 | ;; If we are on a middle token, go backwards. If it is a middle or open, | 1109 | ;; If we are on a middle token, go backwards. If it is a middle or open, |
| @@ -1177,7 +1178,7 @@ at the current point. Returns the point position of the first character of | |||
| 1177 | the matching token if successful, nil otherwise. | 1178 | the matching token if successful, nil otherwise. |
| 1178 | 1179 | ||
| 1179 | Optional PARSE-START is a position to which the point should be moved first. | 1180 | Optional PARSE-START is a position to which the point should be moved first. |
| 1180 | DIRECTION has to be 'forward or 'backward ('forward by default)." | 1181 | DIRECTION has to be \\='forward or \\='backward (\\='forward by default)." |
| 1181 | (if parse-start (goto-char parse-start)) | 1182 | (if parse-start (goto-char parse-start)) |
| 1182 | (let ((case-fold-search nil)) | 1183 | (let ((case-fold-search nil)) |
| 1183 | (if (looking-at lua-indentation-modifier-regexp) | 1184 | (if (looking-at lua-indentation-modifier-regexp) |
| @@ -1286,7 +1287,7 @@ Returns final value of point as integer or nil if operation failed." | |||
| 1286 | "Regexp that matches the ending of a line that needs continuation. | 1287 | "Regexp that matches the ending of a line that needs continuation. |
| 1287 | 1288 | ||
| 1288 | This regexp starts from eol and looks for a binary operator or an unclosed | 1289 | This regexp starts from eol and looks for a binary operator or an unclosed |
| 1289 | block intro (i.e. 'for' without 'do' or 'if' without 'then') followed by | 1290 | block intro (i.e. `for' without `do' or `if' without `then') followed by |
| 1290 | an optional whitespace till the end of the line.") | 1291 | an optional whitespace till the end of the line.") |
| 1291 | 1292 | ||
| 1292 | (defconst lua-cont-bol-regexp | 1293 | (defconst lua-cont-bol-regexp |
| @@ -1589,7 +1590,7 @@ block opening statement when it is closed. | |||
| 1589 | 1590 | ||
| 1590 | When a replace-matching token is seen, the last recorded info is removed, | 1591 | When a replace-matching token is seen, the last recorded info is removed, |
| 1591 | and the cdr of the replace-matching info is added in its place. This is used | 1592 | and the cdr of the replace-matching info is added in its place. This is used |
| 1592 | when a middle-of the block (the only case is 'else') is seen on the same line | 1593 | when a middle-of the block (the only case is `else') is seen on the same line |
| 1593 | the block is opened." | 1594 | the block is opened." |
| 1594 | (cond | 1595 | (cond |
| 1595 | ( (eq 'multiple (car pair)) | 1596 | ( (eq 'multiple (car pair)) |
| @@ -1755,8 +1756,8 @@ token should be indented relative to left-shifter expression | |||
| 1755 | indentation rather then to block-open token. | 1756 | indentation rather then to block-open token. |
| 1756 | 1757 | ||
| 1757 | For example: | 1758 | For example: |
| 1758 | -- 'local a = ' is a left-shifter expression | 1759 | -- `local a = ' is a left-shifter expression |
| 1759 | -- 'function' is a block-open token | 1760 | -- `function' is a block-open token |
| 1760 | local a = function() | 1761 | local a = function() |
| 1761 | -- block contents is indented relative to left-shifter | 1762 | -- block contents is indented relative to left-shifter |
| 1762 | foobarbaz() | 1763 | foobarbaz() |
diff --git a/.emacs.d/lisp/markdown-mode.el b/.emacs.d/lisp/markdown-mode.el index 3abecce..0771060 100644 --- a/.emacs.d/lisp/markdown-mode.el +++ b/.emacs.d/lisp/markdown-mode.el | |||
| @@ -51,6 +51,13 @@ | |||
| 51 | 51 | ||
| 52 | (declare-function project-roots "project") | 52 | (declare-function project-roots "project") |
| 53 | (declare-function sh-set-shell "sh-script") | 53 | (declare-function sh-set-shell "sh-script") |
| 54 | (declare-function mailcap-file-name-to-mime-type "mailcap") | ||
| 55 | (declare-function dnd-get-local-file-name "dnd") | ||
| 56 | |||
| 57 | ;; for older emacs<29 | ||
| 58 | (declare-function mailcap-mime-type-to-extension "mailcap") | ||
| 59 | (declare-function file-name-with-extension "files") | ||
| 60 | (declare-function yank-media-handler "yank-media") | ||
| 54 | 61 | ||
| 55 | 62 | ||
| 56 | ;;; Constants ================================================================= | 63 | ;;; Constants ================================================================= |
| @@ -73,6 +80,13 @@ | |||
| 73 | (defvar markdown-gfm-language-history nil | 80 | (defvar markdown-gfm-language-history nil |
| 74 | "History list of languages used in the current buffer in GFM code blocks.") | 81 | "History list of languages used in the current buffer in GFM code blocks.") |
| 75 | 82 | ||
| 83 | (defvar markdown-follow-link-functions nil | ||
| 84 | "Functions used to follow a link. | ||
| 85 | Each function is called with one argument, the link's URL. It | ||
| 86 | should return non-nil if it followed the link, or nil if not. | ||
| 87 | Functions are called in order until one of them returns non-nil; | ||
| 88 | otherwise the default link-following function is used.") | ||
| 89 | |||
| 76 | 90 | ||
| 77 | ;;; Customizable Variables ==================================================== | 91 | ;;; Customizable Variables ==================================================== |
| 78 | 92 | ||
| @@ -7923,11 +7937,11 @@ If the link is a complete URL, open in browser with `browse-url'. | |||
| 7923 | Otherwise, open with `find-file' after stripping anchor and/or query string. | 7937 | Otherwise, open with `find-file' after stripping anchor and/or query string. |
| 7924 | Translate filenames using `markdown-filename-translate-function'." | 7938 | Translate filenames using `markdown-filename-translate-function'." |
| 7925 | (interactive (list last-command-event)) | 7939 | (interactive (list last-command-event)) |
| 7926 | (save-excursion | 7940 | (if event (posn-set-point (event-start event))) |
| 7927 | (if event (posn-set-point (event-start event))) | 7941 | (if (markdown-link-p) |
| 7928 | (if (markdown-link-p) | 7942 | (or (run-hook-with-args-until-success 'markdown-follow-link-functions (markdown-link-url)) |
| 7929 | (markdown--browse-url (markdown-link-url)) | 7943 | (markdown--browse-url (markdown-link-url))) |
| 7930 | (user-error "Point is not at a Markdown link or URL")))) | 7944 | (user-error "Point is not at a Markdown link or URL"))) |
| 7931 | 7945 | ||
| 7932 | (defun markdown-fontify-inline-links (last) | 7946 | (defun markdown-fontify-inline-links (last) |
| 7933 | "Add text properties to next inline link from point to LAST." | 7947 | "Add text properties to next inline link from point to LAST." |
| @@ -8337,7 +8351,7 @@ See `markdown-follow-link-at-point' and | |||
| 8337 | `markdown-follow-wiki-link-at-point'." | 8351 | `markdown-follow-wiki-link-at-point'." |
| 8338 | (interactive "P") | 8352 | (interactive "P") |
| 8339 | (cond ((markdown-link-p) | 8353 | (cond ((markdown-link-p) |
| 8340 | (markdown--browse-url (markdown-link-url))) | 8354 | (markdown-follow-link-at-point)) |
| 8341 | ((markdown-wiki-link-p) | 8355 | ((markdown-wiki-link-p) |
| 8342 | (markdown-follow-wiki-link-at-point arg)) | 8356 | (markdown-follow-wiki-link-at-point arg)) |
| 8343 | (t | 8357 | (t |
| @@ -9829,6 +9843,48 @@ rows and columns and the column alignment." | |||
| 9829 | (markdown--substitute-command-keys | 9843 | (markdown--substitute-command-keys |
| 9830 | "\\[markdown-toggle-markup-hiding]")))))) | 9844 | "\\[markdown-toggle-markup-hiding]")))))) |
| 9831 | 9845 | ||
| 9846 | (defun markdown--image-media-handler (mimetype data) | ||
| 9847 | (let* ((ext (symbol-name (mailcap-mime-type-to-extension mimetype))) | ||
| 9848 | (filename (read-string "Insert filename for image: ")) | ||
| 9849 | (link-text (read-string "Link text: ")) | ||
| 9850 | (filepath (file-name-with-extension filename ext)) | ||
| 9851 | (dir (file-name-directory filepath))) | ||
| 9852 | (when (and dir (not (file-directory-p dir))) | ||
| 9853 | (make-directory dir t)) | ||
| 9854 | (with-temp-file filepath | ||
| 9855 | (insert data)) | ||
| 9856 | (when (string-match-p "\\s-" filepath) | ||
| 9857 | (setq filepath (concat "<" filepath ">"))) | ||
| 9858 | (markdown-insert-inline-image link-text filepath))) | ||
| 9859 | |||
| 9860 | (defun markdown--file-media-handler (_mimetype data) | ||
| 9861 | (let* ((data (split-string data "[\0\r\n]" t "^file://")) | ||
| 9862 | (files (cdr data))) | ||
| 9863 | (while (not (null files)) | ||
| 9864 | (let* ((file (url-unhex-string (car files))) | ||
| 9865 | (file (file-relative-name file)) | ||
| 9866 | (prompt (format "Link text(%s): " (file-name-nondirectory file))) | ||
| 9867 | (link-text (read-string prompt))) | ||
| 9868 | (when (string-match-p "\\s-" file) | ||
| 9869 | (setq file (concat "<" file ">"))) | ||
| 9870 | (markdown-insert-inline-image link-text file) | ||
| 9871 | (when (not (null (cdr files))) | ||
| 9872 | (insert " ")) | ||
| 9873 | (setq files (cdr files)))))) | ||
| 9874 | |||
| 9875 | (defun markdown--dnd-local-file-handler (url _action) | ||
| 9876 | (require 'mailcap) | ||
| 9877 | (require 'dnd) | ||
| 9878 | (let* ((filename (dnd-get-local-file-name url)) | ||
| 9879 | (mimetype (mailcap-file-name-to-mime-type filename)) | ||
| 9880 | (file (file-relative-name filename)) | ||
| 9881 | (link-text "link text")) | ||
| 9882 | (when (string-match-p "\\s-" file) | ||
| 9883 | (setq file (concat "<" file ">"))) | ||
| 9884 | (if (string-prefix-p "image/" mimetype) | ||
| 9885 | (markdown-insert-inline-image link-text file) | ||
| 9886 | (markdown-insert-inline-link link-text file)))) | ||
| 9887 | |||
| 9832 | 9888 | ||
| 9833 | ;;; Mode Definition ========================================================== | 9889 | ;;; Mode Definition ========================================================== |
| 9834 | 9890 | ||
| @@ -9957,6 +10013,16 @@ rows and columns and the column alignment." | |||
| 9957 | (add-hook 'electric-quote-inhibit-functions | 10013 | (add-hook 'electric-quote-inhibit-functions |
| 9958 | #'markdown--inhibit-electric-quote nil :local) | 10014 | #'markdown--inhibit-electric-quote nil :local) |
| 9959 | 10015 | ||
| 10016 | ;; drag and drop handler | ||
| 10017 | (setq-local dnd-protocol-alist (cons '("^file:///" . markdown--dnd-local-file-handler) | ||
| 10018 | dnd-protocol-alist)) | ||
| 10019 | |||
| 10020 | ;; media handler | ||
| 10021 | (when (version< "29" emacs-version) | ||
| 10022 | (yank-media-handler "image/.*" #'markdown--image-media-handler) | ||
| 10023 | ;; TODO support other than GNOME, like KDE etc | ||
| 10024 | (yank-media-handler "x-special/gnome-copied-files" #'markdown--file-media-handler)) | ||
| 10025 | |||
| 9960 | ;; Make checkboxes buttons | 10026 | ;; Make checkboxes buttons |
| 9961 | (when markdown-make-gfm-checkboxes-buttons | 10027 | (when markdown-make-gfm-checkboxes-buttons |
| 9962 | (markdown-make-gfm-checkboxes-buttons (point-min) (point-max)) | 10028 | (markdown-make-gfm-checkboxes-buttons (point-min) (point-max)) |
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 | ||
| 479 | The hooks will be run in an environment where some variables bound to | 479 | The functions will be run in an environment where some variables bound to |
| 480 | proper values: | 480 | proper 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 | ||
| 486 | Attention: These hooks are not run when exiting nested/stacked snippet expansion!") | 486 | Attention: 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." | |||
| 1813 | SNIPPETS is a list of snippet definitions, each taking the | 1785 | SNIPPETS is a list of snippet definitions, each taking the |
| 1814 | following form | 1786 | following 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 | ||
| 1818 | Within these, only KEY and TEMPLATE are actually mandatory. | 1791 | Within 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. |
| 2957 | For use as `yas-key-syntaxes' element. | ||
| 2984 | 2958 | ||
| 2985 | A newline will be considered whitespace even if the mode syntax | 2959 | A newline will be considered whitespace even if the mode syntax |
| 2986 | marks it as something else (typically comment ender)." | 2960 | marks 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 | ||
| 3730 | Otherwise deletes a character normally by calling `delete-char'." | 3703 | Otherwise 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 | ||
| 4747 | When multiple expressions are found, only the last one counts." | 4682 | When 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) |
