diff options
| author | Simeon Simeonov | 2025-02-05 19:25:11 +0100 |
|---|---|---|
| committer | Simeon Simeonov | 2025-02-05 19:25:11 +0100 |
| commit | f6a91e549fe34f047acdb03e806e0f7dce9ffce1 (patch) | |
| tree | 1459feeefcf4a09b881cad538325f72cc3190eb6 | |
| parent | 4227c712db2a11302ec4eda0c5035fecc4e3e4d2 (diff) | |
Upgrade markdown-mode, rust-prog-mode and yasnippet
| -rw-r--r-- | .emacs.d/lisp/markdown-mode.el | 17 | ||||
| -rw-r--r-- | .emacs.d/lisp/rust-prog-mode.el | 119 | ||||
| -rw-r--r-- | .emacs.d/lisp/yasnippet.el | 42 |
3 files changed, 155 insertions, 23 deletions
diff --git a/.emacs.d/lisp/markdown-mode.el b/.emacs.d/lisp/markdown-mode.el index 89d8962..f99897d 100644 --- a/.emacs.d/lisp/markdown-mode.el +++ b/.emacs.d/lisp/markdown-mode.el | |||
| @@ -287,6 +287,13 @@ cause lag when typing on slower machines." | |||
| 287 | :safe 'booleanp | 287 | :safe 'booleanp |
| 288 | :package-version '(markdown-mode . "2.2")) | 288 | :package-version '(markdown-mode . "2.2")) |
| 289 | 289 | ||
| 290 | (defcustom markdown-wiki-link-retain-case nil | ||
| 291 | "When non-nil, wiki link file names do not have their case changed." | ||
| 292 | :group 'markdown | ||
| 293 | :type 'boolean | ||
| 294 | :safe 'booleanp | ||
| 295 | :package-version '(markdown-mode . "2.7")) | ||
| 296 | |||
| 290 | (defcustom markdown-uri-types | 297 | (defcustom markdown-uri-types |
| 291 | '("acap" "cid" "data" "dav" "fax" "file" "ftp" | 298 | '("acap" "cid" "data" "dav" "fax" "file" "ftp" |
| 292 | "geo" "gopher" "http" "https" "imap" "ldap" "mailto" | 299 | "geo" "gopher" "http" "https" "imap" "ldap" "mailto" |
| @@ -370,6 +377,7 @@ Math support can be enabled, disabled, or toggled later using | |||
| 370 | (defcustom markdown-css-paths nil | 377 | (defcustom markdown-css-paths nil |
| 371 | "List of URLs of CSS files to link to in the output XHTML." | 378 | "List of URLs of CSS files to link to in the output XHTML." |
| 372 | :group 'markdown | 379 | :group 'markdown |
| 380 | :safe (lambda (x) (and (listp x) (cl-every #'stringp x))) | ||
| 373 | :type '(repeat (string :tag "CSS File Path"))) | 381 | :type '(repeat (string :tag "CSS File Path"))) |
| 374 | 382 | ||
| 375 | (defcustom markdown-content-type "text/html" | 383 | (defcustom markdown-content-type "text/html" |
| @@ -5180,6 +5188,7 @@ list simply adds a blank line)." | |||
| 5180 | (markdown-indent-on-enter | 5188 | (markdown-indent-on-enter |
| 5181 | (let (bounds) | 5189 | (let (bounds) |
| 5182 | (if (and (memq markdown-indent-on-enter '(indent-and-new-item)) | 5190 | (if (and (memq markdown-indent-on-enter '(indent-and-new-item)) |
| 5191 | (not (markdown-code-block-at-point-p)) | ||
| 5183 | (setq bounds (markdown-cur-list-item-bounds))) | 5192 | (setq bounds (markdown-cur-list-item-bounds))) |
| 5184 | (let ((beg (cl-first bounds)) | 5193 | (let ((beg (cl-first bounds)) |
| 5185 | (end (cl-second bounds)) | 5194 | (end (cl-second bounds)) |
| @@ -7735,7 +7744,7 @@ Standalone XHTML output is identified by an occurrence of | |||
| 7735 | 7744 | ||
| 7736 | (defun markdown-stylesheet-link-string (stylesheet-path) | 7745 | (defun markdown-stylesheet-link-string (stylesheet-path) |
| 7737 | (concat "<link rel=\"stylesheet\" type=\"text/css\" media=\"all\" href=\"" | 7746 | (concat "<link rel=\"stylesheet\" type=\"text/css\" media=\"all\" href=\"" |
| 7738 | (or (and (string-prefix-p "~" stylesheet-path) | 7747 | (or (and (string-match-p (rx (or "~" "./" "../")) stylesheet-path) |
| 7739 | (expand-file-name stylesheet-path)) | 7748 | (expand-file-name stylesheet-path)) |
| 7740 | stylesheet-path) | 7749 | stylesheet-path) |
| 7741 | "\" />")) | 7750 | "\" />")) |
| @@ -8373,7 +8382,7 @@ in parent directories if | |||
| 8373 | ;; This function must not overwrite match data(PR #590) | 8382 | ;; This function must not overwrite match data(PR #590) |
| 8374 | (let* ((basename (replace-regexp-in-string | 8383 | (let* ((basename (replace-regexp-in-string |
| 8375 | "[[:space:]\n]" markdown-link-space-sub-char name)) | 8384 | "[[:space:]\n]" markdown-link-space-sub-char name)) |
| 8376 | (basename (if (derived-mode-p 'gfm-mode) | 8385 | (basename (if (and (derived-mode-p 'gfm-mode) (not markdown-wiki-link-retain-case)) |
| 8377 | (concat (upcase (substring basename 0 1)) | 8386 | (concat (upcase (substring basename 0 1)) |
| 8378 | (downcase (substring basename 1 nil))) | 8387 | (downcase (substring basename 1 nil))) |
| 8379 | basename)) | 8388 | basename)) |
| @@ -9091,6 +9100,10 @@ LANG is a string, and the returned major mode is a symbol." | |||
| 9091 | (and mode | 9100 | (and mode |
| 9092 | (fboundp mode) | 9101 | (fboundp mode) |
| 9093 | (or | 9102 | (or |
| 9103 | (not (string-match-p "ts-mode\\'" (symbol-name mode))) | ||
| 9104 | ;; Don't load tree-sitter mode if the mode is in neither auto-mode-alist nor major-mode-remap-alist | ||
| 9105 | ;; Because some ts-mode overwrites auto-mode-alist and it might break user configurations | ||
| 9106 | |||
| 9094 | ;; https://github.com/jrblevin/markdown-mode/issues/787 | 9107 | ;; https://github.com/jrblevin/markdown-mode/issues/787 |
| 9095 | ;; major-mode-remap-alist was introduced at Emacs 29.1 | 9108 | ;; major-mode-remap-alist was introduced at Emacs 29.1 |
| 9096 | (cl-loop for pair in (bound-and-true-p major-mode-remap-alist) | 9109 | (cl-loop for pair in (bound-and-true-p major-mode-remap-alist) |
diff --git a/.emacs.d/lisp/rust-prog-mode.el b/.emacs.d/lisp/rust-prog-mode.el index 05bc5e0..6263949 100644 --- a/.emacs.d/lisp/rust-prog-mode.el +++ b/.emacs.d/lisp/rust-prog-mode.el | |||
| @@ -567,7 +567,7 @@ buffer." | |||
| 567 | ;; foo.bar | 567 | ;; foo.bar |
| 568 | (t (funcall skip-dot-identifier))))))) | 568 | (t (funcall skip-dot-identifier))))))) |
| 569 | 569 | ||
| 570 | (defun rust-mode-indent-line () | 570 | (defun rust-mode--indent-line () |
| 571 | (interactive) | 571 | (interactive) |
| 572 | (let ((indent | 572 | (let ((indent |
| 573 | (save-excursion | 573 | (save-excursion |
| @@ -769,6 +769,123 @@ buffer." | |||
| 769 | (save-excursion (= (progn (goto-char pos1) (line-end-position)) | 769 | (save-excursion (= (progn (goto-char pos1) (line-end-position)) |
| 770 | (progn (goto-char pos2) (line-end-position))))) | 770 | (progn (goto-char pos2) (line-end-position))))) |
| 771 | 771 | ||
| 772 | (defun rust-mode-indent-line () | ||
| 773 | "Indent the current line, and indent code examples in comments. | ||
| 774 | |||
| 775 | Indent the current line as `rust-mode-indent-line' does. If | ||
| 776 | point is inside a block comment containing a Markdown code | ||
| 777 | example (delimited by triple backquotes), then also indent the | ||
| 778 | current line within the code example." | ||
| 779 | (interactive) | ||
| 780 | |||
| 781 | ;; First, reindent the current line. | ||
| 782 | (rust-mode--indent-line) | ||
| 783 | |||
| 784 | ;; If point is inside a comment: | ||
| 785 | (let ((ppss (syntax-ppss))) | ||
| 786 | (when (nth 4 ppss) | ||
| 787 | (rust-with-comment-fill-prefix | ||
| 788 | (lambda () | ||
| 789 | (let* ((orig-buf (current-buffer)) | ||
| 790 | (orig-point (point)) | ||
| 791 | (orig-eol (line-end-position)) | ||
| 792 | (orig-bol (line-beginning-position)) | ||
| 793 | (orig-mode major-mode) | ||
| 794 | (com-start (nth 8 ppss)) | ||
| 795 | (com-prefix (replace-regexp-in-string "\\s-*\\'" "" | ||
| 796 | (or fill-prefix ""))) | ||
| 797 | (com-re (regexp-quote com-prefix)) | ||
| 798 | (cb-re (concat "^" com-re "\\(\\s-*\\)```")) | ||
| 799 | cb-start cb-pad cb-hidden-marker indented rel-point) | ||
| 800 | |||
| 801 | ;; If point is within the prefix (not inside the comment | ||
| 802 | ;; body), don't do anything fancy. | ||
| 803 | (when (>= orig-point (+ orig-bol (length com-prefix))) | ||
| 804 | (save-excursion | ||
| 805 | ;; If we're in a // comment block, use the fill prefix to | ||
| 806 | ;; find the start of the block. If we're in a /* | ||
| 807 | ;; comment, the start is determined by ppss. | ||
| 808 | (when (string-match "^\\s-*//" com-prefix) | ||
| 809 | (setq com-start orig-bol) | ||
| 810 | (while (and (= (forward-line -1) 0) | ||
| 811 | (looking-at com-re)) | ||
| 812 | (setq com-start (point)))) | ||
| 813 | |||
| 814 | ;; Search for ``` lines within the comment block, and | ||
| 815 | ;; identify the start of the current code block if any. | ||
| 816 | (goto-char com-start) | ||
| 817 | (while (re-search-forward cb-re orig-bol t) | ||
| 818 | (setq cb-start (unless cb-start (line-end-position)) | ||
| 819 | cb-pad (match-string 1)))) | ||
| 820 | |||
| 821 | (when cb-start | ||
| 822 | ;; We're inside a code block. Copy preceding contents to | ||
| 823 | ;; a temporary buffer. | ||
| 824 | (with-temp-buffer | ||
| 825 | (insert-buffer-substring orig-buf cb-start orig-eol) | ||
| 826 | (forward-char (- orig-point orig-eol)) | ||
| 827 | (save-excursion | ||
| 828 | ;; For each line in the temporary buffer, remove | ||
| 829 | ;; the comment prefix, left padding if present, and | ||
| 830 | ;; hidden-line marker if present. For example, if | ||
| 831 | ;; the code block begins with: | ||
| 832 | ;; | ||
| 833 | ;; ^ /// ```$ | ||
| 834 | ;; | ||
| 835 | ;; then trim lines as follows: | ||
| 836 | ;; | ||
| 837 | ;; ^ ///$ becomes ^$ | ||
| 838 | ;; ^ /// let x = 2;$ becomes ^ let x = 2;$ | ||
| 839 | ;; ^ /// # fn main() {$ becomes ^fn main() {$ | ||
| 840 | ;; | ||
| 841 | ;; If the line we're indenting isn't a hidden line, | ||
| 842 | ;; then remove hidden lines completely - non-hidden | ||
| 843 | ;; lines are indented as if the hidden lines don't | ||
| 844 | ;; exist. | ||
| 845 | (let ((trim-re (concat com-re "\\(?:" cb-pad "\\)?" | ||
| 846 | "\\(\\s-*# \\)?"))) | ||
| 847 | (beginning-of-line) | ||
| 848 | (if (and (looking-at trim-re) (match-beginning 1)) | ||
| 849 | (setq cb-hidden-marker "# ") | ||
| 850 | (setq cb-hidden-marker "" | ||
| 851 | trim-re (concat com-re "\\(?:" cb-pad "\\)?" | ||
| 852 | "\\(\\s-*# .*\\)?"))) | ||
| 853 | |||
| 854 | (goto-char (point-min)) | ||
| 855 | (while (not (eobp)) | ||
| 856 | (when (looking-at trim-re) | ||
| 857 | (delete-region (point) (match-end 0))) | ||
| 858 | (forward-line 1)))) | ||
| 859 | |||
| 860 | ;; Reindent the line. Copy local settings from the | ||
| 861 | ;; parent buffer, but disable indent-tabs-mode unless | ||
| 862 | ;; it is enabled in the parent buffer and the code | ||
| 863 | ;; block is already tab-aligned. | ||
| 864 | (funcall orig-mode) | ||
| 865 | (mapc (lambda (v) | ||
| 866 | (when (custom-variable-p (or (car-safe v) v)) | ||
| 867 | (if (symbolp v) | ||
| 868 | (makunbound (make-local-variable v)) | ||
| 869 | (set (make-local-variable (car v)) (cdr v))))) | ||
| 870 | (buffer-local-variables orig-buf)) | ||
| 871 | (or (string-suffix-p "\t" cb-pad) | ||
| 872 | (= 0 (length com-prefix) (length cb-pad)) | ||
| 873 | (setq-local indent-tabs-mode nil)) | ||
| 874 | (rust-mode--indent-line) | ||
| 875 | |||
| 876 | ;; Extract the indented line and copy back into the | ||
| 877 | ;; original buffer. | ||
| 878 | (setq rel-point (- (point) (point-max))) | ||
| 879 | (beginning-of-line) | ||
| 880 | (setq indented | ||
| 881 | (concat com-prefix cb-pad cb-hidden-marker | ||
| 882 | (buffer-substring (point) (point-max))))) | ||
| 883 | (goto-char orig-eol) | ||
| 884 | (unless (equal indented (buffer-substring orig-bol orig-eol)) | ||
| 885 | (delete-region orig-bol orig-eol) | ||
| 886 | (insert indented)) | ||
| 887 | (forward-char rel-point))))))))) | ||
| 888 | |||
| 772 | ;;; Font-locking definitions and helpers | 889 | ;;; Font-locking definitions and helpers |
| 773 | 890 | ||
| 774 | (defun rust-next-string-interpolation (limit) | 891 | (defun rust-next-string-interpolation (limit) |
diff --git a/.emacs.d/lisp/yasnippet.el b/.emacs.d/lisp/yasnippet.el index 782c440..602e74e 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 -*- lexical-binding: t; -*- | 1 | ;;; yasnippet.el --- Yet another snippet extension for Emacs -*- lexical-binding: t; -*- |
| 2 | 2 | ||
| 3 | ;; Copyright (C) 2008-2024 Free Software Foundation, Inc. | 3 | ;; Copyright (C) 2008-2025 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> |
| @@ -1000,7 +1000,7 @@ Honour `yas-dont-activate-functions', which see." | |||
| 1000 | ;;; Major mode stuff | 1000 | ;;; Major mode stuff |
| 1001 | 1001 | ||
| 1002 | (defvar yas--font-lock-keywords | 1002 | (defvar yas--font-lock-keywords |
| 1003 | (append '(("^#.*$" . font-lock-comment-face)) | 1003 | (append '(("^#.*$" (0 'font-lock-comment-face))) |
| 1004 | (with-temp-buffer | 1004 | (with-temp-buffer |
| 1005 | (let ((prog-mode-hook nil) | 1005 | (let ((prog-mode-hook nil) |
| 1006 | (emacs-lisp-mode-hook nil)) | 1006 | (emacs-lisp-mode-hook nil)) |
| @@ -1011,14 +1011,14 @@ Honour `yas-dont-activate-functions', which see." | |||
| 1011 | (cadr font-lock-keywords) | 1011 | (cadr font-lock-keywords) |
| 1012 | font-lock-keywords)) | 1012 | font-lock-keywords)) |
| 1013 | '(("\\$\\([0-9]+\\)" | 1013 | '(("\\$\\([0-9]+\\)" |
| 1014 | (0 font-lock-keyword-face) | 1014 | (0 'font-lock-keyword-face) |
| 1015 | (1 font-lock-string-face t)) | 1015 | (1 'font-lock-string-face t)) |
| 1016 | ("\\${\\([0-9]+\\):?" | 1016 | ("\\${\\([0-9]+\\):?" |
| 1017 | (0 font-lock-keyword-face) | 1017 | (0 'font-lock-keyword-face) |
| 1018 | (1 font-lock-warning-face t)) | 1018 | (1 'font-lock-warning-face t)) |
| 1019 | ("\\(\\$(\\)" 1 font-lock-preprocessor-face) | 1019 | ("\\(\\$(\\)" 1 'font-lock-preprocessor-face) |
| 1020 | ("}" | 1020 | ("}" |
| 1021 | (0 font-lock-keyword-face))))) | 1021 | (0 'font-lock-keyword-face))))) |
| 1022 | 1022 | ||
| 1023 | (defvar snippet-mode-map | 1023 | (defvar snippet-mode-map |
| 1024 | (let ((map (make-sparse-keymap))) | 1024 | (let ((map (make-sparse-keymap))) |
| @@ -2784,18 +2784,20 @@ Return the `yas--template' object created" | |||
| 2784 | 2784 | ||
| 2785 | (defun yas-maybe-load-snippet-buffer () | 2785 | (defun yas-maybe-load-snippet-buffer () |
| 2786 | "Added to `after-save-hook' in `snippet-mode'." | 2786 | "Added to `after-save-hook' in `snippet-mode'." |
| 2787 | (let* ((mode (intern (file-name-sans-extension | 2787 | (save-excursion ;; Issue #1146. Here or in `yas--parse-template`? |
| 2788 | (file-name-nondirectory | 2788 | (let* ((mode (intern (file-name-sans-extension |
| 2789 | (directory-file-name default-directory))))) | 2789 | (file-name-nondirectory |
| 2790 | (current-snippet | 2790 | (directory-file-name default-directory))))) |
| 2791 | (apply #'yas--define-snippets-2 (yas--table-get-create mode) | 2791 | (current-snippet |
| 2792 | (yas--parse-template buffer-file-name))) | 2792 | (apply #'yas--define-snippets-2 (yas--table-get-create mode) |
| 2793 | (uuid (yas--template-uuid current-snippet))) | 2793 | ;; FIXME: `yas-load-snippet-buffer' will *re*parse! |
| 2794 | (unless (equal current-snippet | 2794 | (yas--parse-template buffer-file-name))) |
| 2795 | (if uuid (yas--get-template-by-uuid mode uuid) | 2795 | (uuid (yas--template-uuid current-snippet))) |
| 2796 | (yas--lookup-snippet-1 | 2796 | (unless (equal current-snippet |
| 2797 | (yas--template-name current-snippet) mode))) | 2797 | (if uuid (yas--get-template-by-uuid mode uuid) |
| 2798 | (yas-load-snippet-buffer mode t)))) | 2798 | (yas--lookup-snippet-1 |
| 2799 | (yas--template-name current-snippet) mode))) | ||
| 2800 | (yas-load-snippet-buffer mode t))))) | ||
| 2799 | 2801 | ||
| 2800 | (defun yas-load-snippet-buffer-and-close (table &optional kill) | 2802 | (defun yas-load-snippet-buffer-and-close (table &optional kill) |
| 2801 | "Load and save the snippet, then `quit-window' if saved. | 2803 | "Load and save the snippet, then `quit-window' if saved. |
