From e5b13f21317f6209b515caa8b9c9f22a98000333 Mon Sep 17 00:00:00 2001 From: Simeon Simeonov Date: Sun, 11 May 2025 22:43:09 +0200 Subject: Upgrade markdown-mode and yasnippet --- .emacs.d/lisp/markdown-mode.el | 305 ++++++++++++++++++++++++++++------------- .emacs.d/lisp/yasnippet.el | 73 +++++----- 2 files changed, 242 insertions(+), 136 deletions(-) (limited to '.emacs.d') diff --git a/.emacs.d/lisp/markdown-mode.el b/.emacs.d/lisp/markdown-mode.el index 311050f..671210e 100644 --- a/.emacs.d/lisp/markdown-mode.el +++ b/.emacs.d/lisp/markdown-mode.el @@ -263,11 +263,11 @@ This is the default search behavior of Ikiwiki." :package-version '(markdown-mode . "2.2")) (defcustom markdown-wiki-link-search-type nil - "Searching type for markdown wiki link. + "A list of options for searching for markdown wiki links. -sub-directories: search for wiki link targets in sub directories -parent-directories: search for wiki link targets in parent directories -project: search for wiki link targets under project root" +`sub-directories': search for wiki link targets in sub directories +`parent-directories': search for wiki link targets in parent directories +`project': search for wiki link targets under project root" :group 'markdown :type '(set (const :tag "search wiki link from subdirectories" sub-directories) @@ -278,6 +278,16 @@ project: search for wiki link targets under project root" (make-obsolete-variable 'markdown-wiki-link-search-subdirectories 'markdown-wiki-link-search-type "2.5") (make-obsolete-variable 'markdown-wiki-link-search-parent-directories 'markdown-wiki-link-search-type "2.5") +(make-obsolete 'markdown-match-wiki-link nil "2.8") +(make-obsolete 'markdown-highlight-wiki-link nil "2.8") +(make-obsolete 'markdown-unfontify-region-wiki-links nil "2.8") +(make-obsolete 'markdown-fontify-region-wiki-links nil "2.8") +(make-obsolete 'markdown-extend-changed-region nil "2.8") +(make-obsolete 'markdown-check-change-for-wiki-link nil "2.8") +(make-obsolete 'markdown-check-change-for-wiki-link-after-change nil "2.8") +(make-obsolete 'markdown-fontify-buffer-wiki-links nil "2.8") +(make-obsolete 'markdown-setup-wiki-link-hooks nil "2.8") + (defcustom markdown-wiki-link-fontify-missing nil "When non-nil, change wiki link face according to existence of target files. This is expensive because it requires checking for the file each time the buffer @@ -930,7 +940,6 @@ This matches typical bracketed [[WikiLinks]] as well as \\='aliased wiki links of the form [[PageName|link text]]. The meanings of the first and second components depend on the value of `markdown-wiki-link-alias-first'. - Group 1 matches the entire link. Group 2 matches the opening square brackets. Group 3 matches the first component of the wiki link. @@ -2007,12 +2016,14 @@ inline code fragments and code blocks." (defface markdown-link-face '((t (:inherit link))) - "Face for links." + "Face for link text, ie the alias portion of a link. +If a wiki link does not have an alias portion, use this face +for the entire link." :group 'markdown-faces) (defface markdown-missing-link-face '((t (:inherit font-lock-warning-face))) - "Face for missing links." + "Face for the link text if the link points to a missing file." :group 'markdown-faces) (defface markdown-reference-face @@ -2283,6 +2294,7 @@ Depending on your font, some reasonable choices are: (7 markdown-markup-properties))) (markdown-fontify-inline-links) (markdown-fontify-reference-links) + (markdown-fontify-wiki-links) (,markdown-regex-reference-definition . ((1 'markdown-markup-face) ; [ (2 'markdown-reference-face) ; label (3 'markdown-markup-face) ; ] @@ -2319,8 +2331,7 @@ Depending on your font, some reasonable choices are: (markdown-fontify-sub-superscripts) (markdown-match-inline-attributes . ((0 markdown-markup-properties prepend))) (markdown-match-leanpub-sections . ((0 markdown-markup-properties))) - (markdown-fontify-blockquotes) - (markdown-match-wiki-link . ((0 'markdown-link-face prepend)))) + (markdown-fontify-blockquotes)) "Syntax highlighting for Markdown files.") ;; Footnotes @@ -3422,7 +3433,8 @@ the buffer)." (markdown-code-block-at-pos begin)) (progn (goto-char (min (1+ begin) last)) (when (< (point) last) - (markdown-match-wiki-link last))) + (with-no-warnings + (markdown-match-wiki-link last)))) (set-match-data (list begin end)) t)))) @@ -3709,6 +3721,18 @@ SEQ may be an atom or a sequence." (defvar markdown-mode-syntax-table (let ((tab (make-syntax-table text-mode-syntax-table))) (modify-syntax-entry ?\" "." tab) + (modify-syntax-entry ?$ "." tab) ; Might appear in inline content + (modify-syntax-entry ?% "." tab) ; Could appear in URLs + (modify-syntax-entry ?* "." tab) ; Emphasis (bold/italic) + (modify-syntax-entry ?+ "." tab) ; Used in lists + (modify-syntax-entry ?/ "." tab) ; Might appear in inline content or URLs + (modify-syntax-entry ?< "." tab) ; For autolinks and embedded HTML + (modify-syntax-entry ?= "." tab) ; Underlining in setext headers + (modify-syntax-entry ?> "." tab) ; Blockquotes and HTML + (modify-syntax-entry ?_ "." tab) ; Used for emphasis/bold + (modify-syntax-entry ?| "." tab) ; Used in tables + (modify-syntax-entry ?& "." tab) ; HTML entities + (modify-syntax-entry ?' "." tab) ; Apostrophe as punctuation tab) "Syntax table for `markdown-mode'.") @@ -5254,8 +5278,7 @@ Otherwise, do normal delete by repeating (back-to-indentation) (unless (looking-at-p "[ \t]*$") (setq mincol (min mincol (current-column)))) - (forward-line 1) - )) + (forward-line 1))) mincol)) (defun markdown-indent-region (beg end arg) @@ -5730,7 +5753,39 @@ Assumes match data is available for `markdown-regex-italic'." "Keymap for `gfm-mode'. See also `markdown-mode-map'.") - + +;;; Text Properties =========================================================== + +(defconst markdown--markup-props (list 'invisible 'markdown-markup + 'rear-nonsticky t + 'font-lock-multiline t)) + +(defconst markdown--title-props (list 'invisible 'markdown-markup + 'font-lock-multiline t)) + +(defun markdown--url-props () + (if markdown-mouse-follow-link + (list 'invisible 'markdown-markup + 'keymap markdown-mode-mouse-map + 'mouse-face 'markdown-highlight-face + 'font-lock-multiline t) + (list 'invisible 'markdown-markup + 'keymap markdown-mode-mouse-map + 'font-lock-multiline t))) + +(defun markdown--link-props (url &optional title) + "Return a property list for URL with optional TITLE." + (let ((echo-text (if title (concat title "\n" url) url))) + (if markdown-mouse-follow-link + (list 'keymap markdown-mode-mouse-map + 'mouse-face 'markdown-highlight-face + 'font-lock-multiline t + 'help-echo echo-text) + (list 'keymap markdown-mode-mouse-map + 'font-lock-multiline t + 'help-echo echo-text)))) + + ;;; Menu ====================================================================== (easy-menu-define markdown-mode-menu markdown-mode-map @@ -8208,39 +8263,20 @@ Translate filenames using `markdown-filename-translate-function'." (title-start (match-beginning 7)) (title-end (match-end 7)) (title (match-string-no-properties 7)) - ;; Markup part - (mp (list 'invisible 'markdown-markup - 'rear-nonsticky t - 'font-lock-multiline t)) - ;; Link part (without face) - (lp (list 'keymap markdown-mode-mouse-map - 'font-lock-multiline t - 'help-echo (if title (concat title "\n" url) url))) - ;; URL part - (up (list 'keymap markdown-mode-mouse-map - 'invisible 'markdown-markup - 'font-lock-multiline t)) - ;; URL composition character - (url-char (markdown--first-displayable markdown-url-compose-char)) - ;; Title part - (tp (list 'invisible 'markdown-markup - 'font-lock-multiline t))) - (when markdown-mouse-follow-link - (setq lp (append lp '(mouse-face 'markdown-highlight-face))) - (setq up (append up '(mouse-face 'markdown-highlight-face)))) + (url-char (markdown--first-displayable markdown-url-compose-char))) (dolist (g '(1 2 4 5 8)) (when (match-end g) - (add-text-properties (match-beginning g) (match-end g) mp) + (add-text-properties (match-beginning g) (match-end g) markdown--markup-props) (add-face-text-property (match-beginning g) (match-end g) 'markdown-markup-face))) ;; Preserve existing faces applied to link part (e.g., inline code) (when link-start - (add-text-properties link-start link-end lp) + (add-text-properties link-start link-end (markdown--link-props url title)) (add-face-text-property link-start link-end 'markdown-link-face)) (when url-start - (add-text-properties url-start url-end up) + (add-text-properties url-start url-end (markdown--url-props)) (add-face-text-property url-start url-end 'markdown-url-face)) (when title-start - (add-text-properties url-end title-end tp) + (add-text-properties url-end title-end markdown--title-props) (add-face-text-property url-end title-end 'markdown-link-title-face)) (when (and markdown-hide-urls url-start) (compose-region url-start (or title-end url-end) url-char)) @@ -8253,11 +8289,7 @@ Translate filenames using `markdown-filename-translate-function'." (link-end (match-end 3)) (ref-start (match-beginning 6)) (ref-end (match-end 6)) - ;; Markup part - (mp (list 'invisible 'markdown-markup - 'rear-nonsticky t - 'font-lock-multiline t)) - ;; Link part + ;; Link properties (lp (list 'keymap markdown-mode-mouse-map 'font-lock-multiline t 'help-echo (lambda (_ __ pos) @@ -8268,14 +8300,14 @@ Translate filenames using `markdown-filename-translate-function'." "Undefined reference")))))) ;; URL composition character (url-char (markdown--first-displayable markdown-url-compose-char)) - ;; Reference part + ;; Reference properties (rp (list 'invisible 'markdown-markup 'font-lock-multiline t))) (when markdown-mouse-follow-link (setq lp (append lp '(mouse-face markdown-highlight-face)))) (dolist (g '(1 2 4 5 8)) (when (match-end g) - (add-text-properties (match-beginning g) (match-end g) mp) + (add-text-properties (match-beginning g) (match-end g) markdown--markup-props) (add-face-text-property (match-beginning g) (match-end g) 'markdown-markup-face))) (when link-start (add-text-properties link-start link-end lp) @@ -8287,6 +8319,75 @@ Translate filenames using `markdown-filename-translate-function'." (compose-region ref-start ref-end url-char))) t))) +(defun markdown-fontify-wiki-links (last) + "Add text properties to next wiki link from point to LAST." + (when (and markdown-enable-wiki-links + (markdown-match-inline-generic markdown-regex-wiki-link last)) + (let* ((begin (match-beginning 1)) + (end (match-end 1)) + (beg2 (match-beginning 2)) + (end2 (match-end 2)) + (beg3 (match-beginning 3)) + (end3 (match-end 3)) + (beg4 (match-beginning 4)) + (end4 (match-end 4)) + (beg5 (match-beginning 5)) + (end5 (match-end 5)) + (beg6 (match-beginning 6)) + (end6 (match-end 6)) + (part1 (match-string-no-properties 3)) + (part2 (match-string-no-properties 5)) + (aliasp (string-equal (match-string-no-properties 4) "|")) + (file-name (markdown-convert-wiki-link-to-filename (markdown-wiki-link-link))) + (file-missing-p (not (file-exists-p file-name)))) + (if (or (markdown-in-comment-p begin) + (markdown-in-comment-p end) + (markdown-inline-code-at-pos-p begin) + (markdown-inline-code-at-pos-p end) + (markdown-code-block-at-pos begin)) + (progn (goto-char (min (1+ begin) last)) + (when (< (point) last) + (markdown-fontify-wiki-links last))) + ;; Add text properties for hiding markup + (progn + ;; Propertize opening and closing brackets + (add-text-properties beg2 end2 markdown--markup-props) + (add-face-text-property beg2 end2 'markdown-markup-face) + (add-text-properties beg6 end6 markdown--markup-props) + (add-face-text-property beg6 end6 'markdown-markup-face) + (if aliasp + (progn + ;; Propertize pipe separating URL from link text + (add-text-properties beg4 end4 markdown--markup-props) + (add-face-text-property beg4 end4 'markdown-markup-face) + (if markdown-wiki-link-alias-first + (progn + ;; Properties alias portion of link + (add-text-properties beg3 end3 (markdown--link-props part2)) + (add-face-text-property beg3 end3 'markdown-link-face) + (add-text-properties beg5 end5 (markdown--url-props)) + (add-text-properties beg5 end5 '(invisible markdown-markup)) + (add-face-text-property beg5 end5 'markdown-url-face) + (when (and file-missing-p markdown-wiki-link-fontify-missing) + (put-text-property beg3 end3 'face 'markdown-missing-link-face))) + (progn + ;; Properties URL portion of link + (add-text-properties beg3 end3 (markdown--url-props)) + (add-text-properties beg3 end3 '(invisible markdown-markup)) + (add-face-text-property beg3 end3 'markdown-url-face) + (add-text-properties beg5 end5 (markdown--link-props part1)) + (add-face-text-property beg5 end5 'markdown-link-face) + (when (and file-missing-p markdown-wiki-link-fontify-missing) + (put-text-property beg5 end5 'face 'markdown-missing-link-face))))) + (progn + ;; Properties link as link text + (add-text-properties beg3 end3 (markdown--link-props part1)) + (add-face-text-property beg3 end3 'markdown-link-face) + (when (and file-missing-p markdown-wiki-link-fontify-missing) + (put-text-property beg3 end3 'face 'markdown-missing-link-face))))) + (set-match-data (list begin end)) + t)))) + (defun markdown-fontify-angle-uris (last) "Add text properties to angle URIs from point to LAST." (when (markdown-match-angle-uris last) @@ -8294,15 +8395,11 @@ Translate filenames using `markdown-filename-translate-function'." (url-end (match-end 2))) (unless (or (markdown-in-inline-code-p url-start) (markdown-in-inline-code-p url-end)) - (let* (;; Markup part - (mp (list 'face 'markdown-markup-face - 'invisible 'markdown-markup - 'rear-nonsticky t - 'font-lock-multiline t)) - ;; URI part - (up (list 'keymap markdown-mode-mouse-map - 'face 'markdown-plain-url-face - 'font-lock-multiline t))) + (let ((mp (append '(face markdown-markup-face) (cl-copy-list markdown--markup-props))) + ;; URI part + (up (list 'keymap markdown-mode-mouse-map + 'face 'markdown-plain-url-face + 'font-lock-multiline t))) (when markdown-mouse-follow-link (setq up (append up '(mouse-face markdown-highlight-face)))) (dolist (g '(1 3)) @@ -8372,6 +8469,11 @@ The location of the alias component depends on the value of (or (match-string-no-properties 5) (match-string-no-properties 3)))) (defun markdown--wiki-link-search-types () + "Return a list of the currently selected search types. + +Due to deprecated variables, as of markdown-mode version 2.5, the return value +of this function is the same as the value of the variable +`markdown-wiki-link-search-type'." (let ((ret (and markdown-wiki-link-search-type (cl-copy-list markdown-wiki-link-search-type)))) (when (and markdown-wiki-link-search-subdirectories @@ -8383,6 +8485,7 @@ The location of the alias component depends on the value of ret)) (defun markdown--project-root () + "Try various approaches to find the project root." (or (cl-loop for dir in '(".git" ".hg" ".svn") when (locate-dominating-file default-directory dir) return it) @@ -8397,12 +8500,9 @@ The location of the alias component depends on the value of (defun markdown-convert-wiki-link-to-filename (name) "Generate a filename from the wiki link NAME. Spaces in NAME are replaced with `markdown-link-space-sub-char'. +Search depth is determined by `markdown-wiki-link-search-type'. When in `gfm-mode', follow GitHub's conventions where [[Test Test]] -and [[test test]] both map to Test-test.ext. Look in the current -directory first, then in subdirectories if -`markdown-wiki-link-search-subdirectories' is non-nil, and then -in parent directories if -`markdown-wiki-link-search-parent-directories' is non-nil." +and [[test test]] both map to Test-test.ext." (save-match-data ;; This function must not overwrite match data(PR #590) (let* ((basename (replace-regexp-in-string @@ -8493,11 +8593,12 @@ and highlight accordingly." (file-name (markdown-convert-wiki-link-to-filename (markdown-wiki-link-link)))) - (if (condition-case nil (file-exists-p file-name) (error nil)) + (with-no-warnings + (if (condition-case nil (file-exists-p file-name) (error nil)) + (markdown-highlight-wiki-link + highlight-beginning highlight-end 'markdown-link-face) (markdown-highlight-wiki-link - highlight-beginning highlight-end 'markdown-link-face) - (markdown-highlight-wiki-link - highlight-beginning highlight-end 'markdown-missing-link-face))))))) + highlight-beginning highlight-end 'markdown-missing-link-face)))))))) (defun markdown-extend-changed-region (from to) "Extend region given by FROM and TO so that we can fontify all links. @@ -8533,7 +8634,8 @@ newline after." ;; Extend the region to fontify so that it starts ;; and ends at safe places. (cl-multiple-value-bind (new-from new-to) - (markdown-extend-changed-region from to) + (with-no-warnings + (markdown-extend-changed-region from to)) (goto-char new-from) ;; Only refontify when the range contains text with a ;; wiki link face or if the wiki link regexp matches. @@ -8542,10 +8644,11 @@ newline after." '(markdown-link-face markdown-missing-link-face)) (re-search-forward markdown-regex-wiki-link new-to t)) - ;; Unfontify existing fontification (start from scratch) - (markdown-unfontify-region-wiki-links new-from new-to) - ;; Now do the fontification. - (markdown-fontify-region-wiki-links new-from new-to)))))) + (with-no-warnings + ;; Unfontify existing fontification (start from scratch) + (markdown-unfontify-region-wiki-links new-from new-to) + ;; Now do the fontification. + (markdown-fontify-region-wiki-links new-from new-to))))))) (cursor-intangible-mode -1) (and (not modified) (buffer-modified-p) @@ -8554,12 +8657,14 @@ newline after." (defun markdown-check-change-for-wiki-link-after-change (from to _) "Check region between FROM and TO for wiki links and re-fontify as needed. Designed to be used with the `after-change-functions' hook." - (markdown-check-change-for-wiki-link from to)) + (with-no-warnings + (markdown-check-change-for-wiki-link from to))) (defun markdown-fontify-buffer-wiki-links () "Refontify all wiki links in the buffer." (interactive) - (markdown-check-change-for-wiki-link (point-min) (point-max))) + (with-no-warnings + (markdown-check-change-for-wiki-link (point-min) (point-max)))) (defun markdown-toggle-wiki-links (&optional arg) "Toggle support for wiki links. @@ -8571,33 +8676,36 @@ and disable it otherwise." (not markdown-enable-wiki-links) (> (prefix-numeric-value arg) 0))) (when (called-interactively-p 'interactive) - (message "markdown-mode wiki link support %s" (if markdown-enable-wiki-links "enabled" "disabled"))) + (message "markdown-mode wiki link support %s" + (if markdown-enable-wiki-links "enabled" "disabled"))) (markdown-reload-extensions)) (defun markdown-setup-wiki-link-hooks () "Add or remove hooks for fontifying wiki links. These are only enabled when `markdown-wiki-link-fontify-missing' is non-nil." ;; Anytime text changes make sure it gets fontified correctly - (if (and markdown-enable-wiki-links - markdown-wiki-link-fontify-missing) - (add-hook 'after-change-functions - #'markdown-check-change-for-wiki-link-after-change t t) - (remove-hook 'after-change-functions - #'markdown-check-change-for-wiki-link-after-change t)) - ;; If we left the buffer there is a really good chance we were - ;; creating one of the wiki link documents. Make sure we get - ;; refontified when we come back. - (if (and markdown-enable-wiki-links - markdown-wiki-link-fontify-missing) - (progn - (add-hook 'window-configuration-change-hook - #'markdown-fontify-buffer-wiki-links t t) - (markdown-fontify-buffer-wiki-links)) - (remove-hook 'window-configuration-change-hook - #'markdown-fontify-buffer-wiki-links t) - (markdown-unfontify-region-wiki-links (point-min) (point-max)))) + (with-no-warnings + (if (and markdown-enable-wiki-links + markdown-wiki-link-fontify-missing) + (add-hook 'after-change-functions + #'markdown-check-change-for-wiki-link-after-change t t) + (remove-hook 'after-change-functions + #'markdown-check-change-for-wiki-link-after-change t)) + ;; If we left the buffer there is a really good chance we were + ;; creating one of the wiki link documents. Make sure we get + ;; refontified when we come back. + (if (and markdown-enable-wiki-links + markdown-wiki-link-fontify-missing) + (progn + (add-hook 'window-configuration-change-hook + #'markdown-fontify-buffer-wiki-links t t) + (markdown-fontify-buffer-wiki-links)) + (remove-hook 'window-configuration-change-hook + #'markdown-fontify-buffer-wiki-links t) + (with-no-warnings + (markdown-unfontify-region-wiki-links (point-min) (point-max))))) ) + - ;;; Following & Doing ========================================================= (defun markdown-follow-thing-at-point (arg) @@ -8784,9 +8892,7 @@ or span." (interactive) (when (derived-mode-p 'markdown-mode) ;; Refontify buffer - (font-lock-flush) - ;; Add or remove hooks related to extensions - (markdown-setup-wiki-link-hooks))) + (font-lock-flush))) (defun markdown-handle-local-variables () "Run in `hack-local-variables-hook' to update font lock rules. @@ -10090,6 +10196,19 @@ rows and columns and the column alignment." (propertize link 'face 'markdown-reference-face) (propertize "]" 'face 'markdown-markup-face)) (propertize link 'face 'markdown-url-face))))) + ;; Hidden URL for wiki links + ((and (and markdown-enable-wiki-links + (thing-at-point-looking-at markdown-regex-wiki-link)) + (or markdown-hide-urls markdown-hide-markup)) + (let* ((aliasp (string-equal (match-string-no-properties 4) "|")) + (part1 (match-string-no-properties 3)) + (part2 (match-string-no-properties 5)) + (link (if (and aliasp markdown-wiki-link-alias-first) part2 part1)) + (edit-keys (markdown--substitute-command-keys + "\\[markdown-insert-wiki-link]")) + (edit-str (propertize edit-keys 'face 'font-lock-constant-face))) + (format "Hidden URL (%s to edit): %s" + edit-str (propertize link 'face 'markdown-reference-face)))) ;; Hidden language name for fenced code blocks ((and (markdown-code-block-at-point-p) (not (get-text-property (point) 'markdown-pre)) @@ -10224,8 +10343,6 @@ rows and columns and the column alignment." (if markdown-hide-markup (add-to-invisibility-spec 'markdown-markup) (remove-from-invisibility-spec 'markdown-markup)) - ;; Wiki links - (markdown-setup-wiki-link-hooks) ;; Math mode (when markdown-enable-math (markdown-toggle-math t)) ;; Add a buffer-local hook to reload after file-local variables are read diff --git a/.emacs.d/lisp/yasnippet.el b/.emacs.d/lisp/yasnippet.el index 602e74e..806f2bc 100644 --- a/.emacs.d/lisp/yasnippet.el +++ b/.emacs.d/lisp/yasnippet.el @@ -5,7 +5,7 @@ ;; João Távora , ;; Noam Postavsky ;; Maintainer: Noam Postavsky -;; Version: 0.14.1 +;; Version: 0.14.2 ;; X-URL: http://github.com/joaotavora/yasnippet ;; Keywords: convenience, emulation ;; URL: http://github.com/joaotavora/yasnippet @@ -588,8 +588,6 @@ can be useful." ;;; Internal variables -(defconst yas--version "0.14.0") - (defvar yas--menu-table (make-hash-table) "A hash table of MAJOR-MODE symbols to menu keymaps.") @@ -891,18 +889,10 @@ which decides on the snippet to expand.") ;;;###autoload (define-minor-mode yas-minor-mode - "Toggle YASnippet mode. + "YASnippet minor mode. When YASnippet mode is enabled, `yas-expand', normally bound to -the TAB key, expands snippets of code depending on the major -mode. - -With no argument, this command toggles the mode. -positive prefix argument turns on the mode. -Negative prefix argument turns off the mode. - -Key bindings: -\\{yas-minor-mode-map}" +the TAB key, expands snippets of code depending on the major mode." :lighter " yas" ;; The indicator for the mode line. (cond ((and yas-minor-mode (featurep 'yasnippet)) ;; Install the direct keymaps in `emulation-mode-map-alists' @@ -1463,7 +1453,7 @@ Returns (TEMPLATES START END). This function respects (defun yas--remove-misc-free-from-undo (old-undo-list) "Tries to work around Emacs Bug#30931. Helper function for `yas--save-restriction-and-widen'." - ;; If Bug#30931 is unfixed, we get (# . INTEGER) + ;; If Bug#30931 is unfixed (Emacs<26.2), we get (# . INTEGER) ;; entries in the undo list. If we call `type-of' on the ;; Lisp_Misc_Free object then Emacs aborts, so try to find it by ;; checking that its type is none of the expected ones. @@ -1487,15 +1477,16 @@ Helper function for `yas--save-restriction-and-widen'." (defmacro yas--save-restriction-and-widen (&rest body) "Equivalent to (save-restriction (widen) BODY). -Also tries to work around Emacs Bug#30931." +Also tries to work around Emacs Bug#30931, fixed in Emacs-26.2." (declare (debug (body)) (indent 0)) - ;; Disable garbage collection, since it could cause an abort. - `(let ((gc-cons-threshold most-positive-fixnum) - (old-undo-list buffer-undo-list)) - (prog1 (save-restriction - (widen) - ,@body) - (yas--remove-misc-free-from-undo old-undo-list)))) + (let ((main `(save-restriction (widen) ,@body))) + (if (< emacs-major-version 27) + ;; Disable garbage collection, since it could cause an abort. + `(let ((gc-cons-threshold most-positive-fixnum) + (old-undo-list buffer-undo-list)) + (prog1 ,main + (yas--remove-misc-free-from-undo old-undo-list))) + main))) (defun yas--eval-for-string (form) "Evaluate FORM and convert the result to string." @@ -1679,8 +1670,9 @@ Here's a list of currently recognized directives: (directory-files directory t))) (defun yas--make-menu-binding (template) - (let ((mode (yas--table-mode (yas--template-table template)))) - `(lambda () (interactive) (yas--expand-or-visit-from-menu ',mode ,(yas--template-uuid template))))) + (let ((mode (yas--table-mode (yas--template-table template))) + (uuid (yas--template-uuid template))) + (lambda () (interactive) (yas--expand-or-visit-from-menu mode uuid)))) (defun yas--expand-or-visit-from-menu (mode uuid) (let* ((table (yas--table-get-create mode)) @@ -2127,27 +2119,23 @@ This works by stubbing a few functions, then calling (defun yas-about () (interactive) (message "yasnippet (version %s) -- pluskid/joaotavora/npostavs" - (or (ignore-errors (car (let ((default-directory yas--loaddir)) - (process-lines "git" "describe" - "--tags" "--dirty")))) - (eval-when-compile + (or (eval-when-compile (and (fboundp 'package-get-version) (package-get-version))) - (when (and (featurep 'package) + (when (and (boundp 'package-alist) (fboundp 'package-desc-version) (fboundp 'package-version-join)) - (defvar package-alist) (ignore-errors - (let* ((yas-pkg (cdr (assq 'yasnippet package-alist))) - (version (package-version-join - (package-desc-version (car yas-pkg))))) - ;; Special case for MELPA's bogus version numbers. - (if (string-match "\\`20..[01][0-9][0-3][0-9][.][0-9]\\{3,4\\}\\'" - version) - (concat yas--version "-snapshot" version) - version)))) - yas--version))) - + (let* ((yas-pkg (cdr (assq 'yasnippet package-alist)))) + (when yas-pkg + (package-version-join + (package-desc-version (car yas-pkg))))))) + ;; The Git description can be misleading, for lack of + ;; recent tags, so we prefer package version info. + (ignore-errors (car (let ((default-directory yas--loaddir)) + (process-lines "git" "describe" + "--tags" "--dirty")))) + "unknown"))) ;;; Apropos snippet menu: ;; @@ -4133,7 +4121,7 @@ Returns the newly created snippet." (unwind-protect (let ((buffer-undo-list t)) (goto-char begin) - (if (> emacs-major-version 29) + (if (< emacs-major-version 27) ;; Don't use the workaround for CC-mode's cache, ;; since it was presumably a bug in CC-mode, so either ;; it's fixed already, or it should get fixed. @@ -4161,6 +4149,7 @@ Returns the newly created snippet." (run-hook-with-args 'after-change-functions (point-min) (point-max) (- end begin)))) + ;; FIXME: Use `undo-amalgamate-change-group'? (when (listp buffer-undo-list) (push (cons (point-min) (point-max)) buffer-undo-list))) @@ -5056,7 +5045,7 @@ object satisfying `yas--field-p' to restrict the expansion to."))) (define-button-type 'help-snippet-def :supertype 'help-xref 'help-function (lambda (template) (yas--visit-snippet-file-1 template)) - 'help-echo (purecopy "mouse-2, RET: find snippets's definition")) + 'help-echo "mouse-2, RET: find snippets's definition") (defun yas--snippet-description-finish-runonce () "Final adjustments for the help buffer when snippets are concerned." -- cgit v1.3