From 85601f50f236686da662b1b00e01df0a0abe761b Mon Sep 17 00:00:00 2001 From: Simeon Simeonov Date: Wed, 22 Jul 2026 11:10:34 +0200 Subject: Update markdown-mode, rust-mode and yaml-mode. Remove unused snippets --- .emacs.d/lisp/markdown-mode.el | 63 ++++++++++++++++-------- .emacs.d/lisp/rust-compile.el | 7 +-- .emacs.d/lisp/rust-mode-tests.el | 62 ++++++++++++++++++++++- .emacs.d/lisp/rust-prog-mode.el | 9 ++++ .emacs.d/lisp/rust-utils.el | 35 ++++++++++--- .emacs.d/lisp/yaml-mode.el | 3 +- .emacs.d/snippets/python-mode.statnett/from | 6 --- .emacs.d/snippets/python-mode.statnett/try | 8 --- .emacs.d/snippets/python-mode.statnett/with-open | 6 --- .emacs.d/snippets/python-mode/from | 6 --- .emacs.d/snippets/python-mode/try | 8 --- .emacs.d/snippets/python-mode/with-open | 6 --- 12 files changed, 147 insertions(+), 72 deletions(-) delete mode 100644 .emacs.d/snippets/python-mode.statnett/from delete mode 100644 .emacs.d/snippets/python-mode.statnett/try delete mode 100644 .emacs.d/snippets/python-mode.statnett/with-open delete mode 100644 .emacs.d/snippets/python-mode/from delete mode 100644 .emacs.d/snippets/python-mode/try delete mode 100644 .emacs.d/snippets/python-mode/with-open diff --git a/.emacs.d/lisp/markdown-mode.el b/.emacs.d/lisp/markdown-mode.el index 160975c..08ed4bb 100644 --- a/.emacs.d/lisp/markdown-mode.el +++ b/.emacs.d/lisp/markdown-mode.el @@ -1,12 +1,12 @@ ;;; markdown-mode.el --- Major mode for Markdown-formatted text -*- lexical-binding: t; -*- -;; Copyright (C) 2007-2023 Jason R. Blevins and markdown-mode +;; Copyright (C) 2007-2026 Jason R. Blevins and markdown-mode ;; contributors (see the commit log for details). ;; Author: Jason R. Blevins ;; Maintainer: Jason R. Blevins ;; Created: May 24, 2007 -;; Version: 2.8-alpha +;; Version: 2.9-alpha ;; Package-Requires: ((emacs "28.1")) ;; Keywords: Markdown, GitHub Flavored Markdown, itex ;; URL: https://jblevins.org/projects/markdown-mode/ @@ -2930,22 +2930,21 @@ This may be useful for tables and Pandoc's line_blocks extension." "Return t if PROP from BEGIN to END is equal to one of the given PROP-VALUES. Also returns t if PROP is a list containing one of the PROP-VALUES. Return nil otherwise." - (let (props) - (catch 'found - (dolist (loc (number-sequence begin end)) - (when (setq props (get-text-property loc prop)) - (cond ((listp props) - ;; props is a list, check for membership - (dolist (val prop-values) - (when (memq val props) (throw 'found loc)))) - (t - ;; props is a scalar, check for equality - (dolist (val prop-values) - (when (eq val props) (throw 'found loc)))))))))) + (catch 'found + (let ((loc begin)) + (while (<= loc end) + (when-let* ((props (get-text-property loc prop))) + (if (listp props) + ;; props is a list, check for membership + (dolist (val prop-values) + (when (memq val props) (throw 'found loc))) + (dolist (val prop-values) + (when (eq val props) (throw 'found loc))))) + (setq loc (next-single-property-change loc prop nil (1+ end))))))) (defun markdown-range-properties-exist (begin end props) (cl-loop - for loc in (number-sequence begin end) + for loc from begin to end with result = nil while (not (setq result @@ -3637,12 +3636,31 @@ SEQ may be an atom or a sequence." (add-text-properties fontified-start fontified-end heading-props))))) t)) +(defun markdown--fontify-table-alignment () + "Visually align cell separators of the table line at point. +Hiding markup makes the displayed content of a table cell +narrower than the buffer text, which breaks the column alignment +of tables that are aligned in the source. Give the whitespace +before each cell separator a space display specification +stretching it to the separator's buffer column, so that +separators are displayed at the same column as in the source +regardless of what is hidden before them." + (beginning-of-line) + (while (re-search-forward "[ \t]+|" (line-end-position) t) + (let ((separator (1- (match-end 0)))) + (unless (markdown-inline-code-at-pos-p separator) + (put-text-property + (match-beginning 0) separator + 'display `(space :align-to ,(1- (current-column)))))))) + (defun markdown-fontify-tables (last) (when (re-search-forward "|" last t) (when (markdown-table-at-point-p) (font-lock-append-text-property (line-beginning-position) (min (1+ (line-end-position)) (point-max)) - 'face 'markdown-table-face)) + 'face 'markdown-table-face) + (when (or markdown-hide-markup markdown-hide-urls) + (markdown--fontify-table-alignment))) (forward-line 1) t)) @@ -7799,9 +7817,11 @@ Return the name of the output buffer used." markdown-command exit-code)))) output-buffer-name)) -(defun markdown-standalone (&optional output-buffer-name) +(defun markdown-standalone (&optional output-buffer-name title) "Special function to provide standalone HTML output. -Insert the output in the buffer named OUTPUT-BUFFER-NAME." +Insert the output in the buffer named OUTPUT-BUFFER-NAME. +Set the HTML title to TITLE if provided, otherwise the name of the +output buffer." (interactive) (setq output-buffer-name (markdown output-buffer-name)) (let ((css-path markdown-css-paths)) @@ -7809,7 +7829,7 @@ Insert the output in the buffer named OUTPUT-BUFFER-NAME." (set-buffer output-buffer-name) (setq-local markdown-css-paths css-path) (unless (markdown-output-standalone-p) - (markdown-add-xhtml-header-and-footer output-buffer-name)) + (markdown-add-xhtml-header-and-footer (or title output-buffer-name))) (goto-char (point-min)) (html-mode))) output-buffer-name) @@ -7890,7 +7910,8 @@ When OUTPUT-BUFFER-NAME is given, insert the output in the buffer with that name." (interactive) (browse-url-of-buffer - (markdown-standalone (or output-buffer-name markdown-output-buffer-name)))) + (markdown-standalone (or output-buffer-name markdown-output-buffer-name) + (buffer-name)))) (defun markdown-export-file-name (&optional extension) "Attempt to generate a filename for Markdown output. @@ -9773,7 +9794,7 @@ This function assumes point is on a table." (setq fmt (car fmtspec) fmtspec (cdr fmtspec)) (setq width (car widths) widths (cdr widths)) (if (equal fmt 'c) - (setq cell (concat (make-string (/ (- width (length cell)) 2) ?\s) cell))) + (setq cell (concat (make-string (/ (- width (markdown--string-width cell)) 2) ?\s) cell))) (unless (equal fmt 'r) (setq width (- width))) (format (format " %%%ds " width) cell)) cells "|"))) diff --git a/.emacs.d/lisp/rust-compile.el b/.emacs.d/lisp/rust-compile.el index cbdf43a..87b8c57 100644 --- a/.emacs.d/lisp/rust-compile.el +++ b/.emacs.d/lisp/rust-compile.el @@ -41,9 +41,10 @@ See `compilation-error-regexp-alist' for help on their format.") See `compilation-error-regexp-alist' for help on their format.") (defvar rustc-panics-compilation-regexps - (let ((re (concat "thread '[^']+' panicked at " rustc-compilation-location))) - (cons re '(2 3 4 nil 1))) - "Specifications for matching panics in rustc invocations. + (let ((re (concat "thread '[^']+'\\(?: ([0-9]+)\\)? panicked at " + rustc-compilation-location))) + (cons re '(2 3 4 nil 1))) + "Specifications for matching panics in rustc invocations. See `compilation-error-regexp-alist' for help on their format.") ;; Match test run failures and panics during compilation as diff --git a/.emacs.d/lisp/rust-mode-tests.el b/.emacs.d/lisp/rust-mode-tests.el index 259afb2..c8e3e9a 100644 --- a/.emacs.d/lisp/rust-mode-tests.el +++ b/.emacs.d/lisp/rust-mode-tests.el @@ -1979,6 +1979,28 @@ this_is_not_a_string();)" "union" font-lock-variable-name-face "bar" font-lock-type-face))) +(ert-deftest rust-test-raw-context-sensitive () + (rust-test-font-lock + "let raw = 7; let foo = &raw const raw; let bar = &raw mut raw;" + '("let" font-lock-keyword-face + ;; The first raw is a variable name. + "raw" font-lock-variable-name-face + "let" font-lock-keyword-face + "foo" font-lock-variable-name-face + "&" rust-ampersand-face + ;; The second raw is a contextual keyword. + "raw" font-lock-keyword-face + "const" font-lock-keyword-face + ;; The third raw is a value. + "let" font-lock-keyword-face + "bar" font-lock-variable-name-face + "&" rust-ampersand-face + ;; The fourth raw is a contextual keyword. + "raw" font-lock-keyword-face + "mut" font-lock-keyword-face + ;; The fifth raw is a value. + ))) + (ert-deftest indent-method-chains-no-align () (let ((rust-indent-method-chain nil)) (test-indent " @@ -3693,6 +3715,7 @@ let b = 1;" (insert "note: `ZZZ` could also refer to the constant imported here -> b\n --> file4.rs:12:34\n\n") (insert " ::: file5.rs:12:34\n\n") (insert "thread 'main' panicked at src/file7.rs:12:34:\n\n") + (insert "thread 'aaa::bbb' (19178688) panicked at crates/a/src/b.rs:13:9:\n\n") (insert "[src/file8.rs:159:5] symbol_value(SOME_VAR) = Some(\n\n") (insert " at file9.rs:12:34\n\n") ;; should not match @@ -3714,7 +3737,8 @@ let b = 1;" (("file5.rs" "12" "34" compilation-info "file5.rs:12:34")) ((like-previous-one "82" back-to-indentation compilation-info "82") (like-previous-one "132" back-to-indentation compilation-info "132")) - (("src/file7.rs" "12" "34" nil "src/file7.rs:12:34")) + (("src/file7.rs" "12" "34" nil "src/file7.rs:12:34") + ("crates/a/src/b.rs" "13" "9" nil "crates/a/src/b.rs:13:9")) (("src/file8.rs" "159" "5" compilation-info "src/file8.rs:159:5")) (("file9.rs" "12" "34" compilation-info "file9.rs:12:34"))) (mapcar #'rust-collect-matches @@ -3809,3 +3833,39 @@ let b = 1;" (string-match "^C-c C" ,match))) t)) (should (< 0 match-count))))) + +;; Toggle mutability tests + +(ert-deftest rust-toggle-mutability-let () + "Test toggling let <-> let mut." + (with-temp-buffer + (rust-mode) + (insert " let x = 5;") + (rust-toggle-mutability) + (should (string= (buffer-string) " let mut x = 5;")) + (rust-toggle-mutability) + (should (string= (buffer-string) " let x = 5;")))) + +(ert-deftest rust-toggle-mutability-ref () + "Test toggling & <-> &mut." + (with-temp-buffer + (rust-mode) + (insert " let y = & x;") + (goto-char (line-end-position)) + (rust-toggle-mutability) + (should (string-match-p "&mut " (buffer-string))) + (goto-char (line-end-position)) + (rust-toggle-mutability) + (should (string-match-p "& x" (buffer-string))))) + +(ert-deftest rust-toggle-mutability-self () + "Test toggling &self <-> &mut self." + (with-temp-buffer + (rust-mode) + (insert " fn foo(&self) {") + (goto-char (line-end-position)) + (rust-toggle-mutability) + (should (string-match-p "&mut self" (buffer-string))) + (goto-char (line-end-position)) + (rust-toggle-mutability) + (should (string-match-p "&self" (buffer-string))))) diff --git a/.emacs.d/lisp/rust-prog-mode.el b/.emacs.d/lisp/rust-prog-mode.el index f2f3f0b..ea6ef82 100644 --- a/.emacs.d/lisp/rust-prog-mode.el +++ b/.emacs.d/lisp/rust-prog-mode.el @@ -112,6 +112,14 @@ to the function arguments. When nil, `->' will be indented one level." (or space line-start) (group symbol-start "union" symbol-end) (+ space) (regexp ,rust-re-ident)))) +(defconst rust-re-raw + (rx-to-string + `(seq + "&" + (zero-or-more space) + (group "raw") + (one-or-more space) + (or "const" "mut")))) (defun rust-re-item-def (itype) (concat (rust-re-word itype) @@ -269,6 +277,7 @@ Does not match type annotations of the form \"foo::<\"." ;; Contextual keywords ("\\_<\\(default\\)[[:space:]]+fn\\_>" 1 font-lock-keyword-face) (,rust-re-union 1 font-lock-keyword-face) + (,rust-re-raw 1 font-lock-keyword-face) ;; Special types (,(regexp-opt rust-special-types 'symbols) . font-lock-type-face) diff --git a/.emacs.d/lisp/rust-utils.el b/.emacs.d/lisp/rust-utils.el index d93bd0a..b0b0ae1 100644 --- a/.emacs.d/lisp/rust-utils.el +++ b/.emacs.d/lisp/rust-utils.el @@ -108,15 +108,38 @@ if not. Move cursor to the end of macro." ) ) +;;;###autoload (defun rust-toggle-mutability () - "Toggles the mutability of the variable defined on the current line" + "Toggle the mutability of the binding or reference near point. +Handles `let' <-> `let mut' and `&' <-> `&mut' (including `&self')." (interactive) (save-excursion - (back-to-indentation) - (forward-word) - (if (string= " mut" (buffer-substring (point) (+ (point) 4))) - (delete-region (point) (+ (point) 4)) - (insert " mut")))) + (let ((line-start (line-beginning-position)) + (line-end (line-end-position))) + (cond + ;; Remove: &mut -> & + ((search-backward "&mut " line-start t) + (forward-char 1) + (delete-region (point) (+ (point) 4))) + ;; Remove: let mut -> let + ((progn (goto-char (line-beginning-position)) + (re-search-forward "\\_" line-end t)) + (replace-match "let")) + ;; Add: & -> &mut + ((progn (goto-char (line-end-position)) + (search-backward "& " line-start t)) + (forward-char 1) + (insert "mut ")) + ;; Add: &self -> &mut self + ((progn (goto-char (line-end-position)) + (search-backward "&self" line-start t)) + (forward-char 1) + (insert "mut ")) + ;; Add: let -> let mut + ((progn (goto-char (line-beginning-position)) + (re-search-forward "\\_" line-end t)) + (insert " mut")) + (t (message "No mutable/immutable binding or reference found on this line")))))) ;;; _ (provide 'rust-utils) ;;; rust-utils.el ends here diff --git a/.emacs.d/lisp/yaml-mode.el b/.emacs.d/lisp/yaml-mode.el index c748b6c..1bfa43b 100644 --- a/.emacs.d/lisp/yaml-mode.el +++ b/.emacs.d/lisp/yaml-mode.el @@ -272,7 +272,8 @@ that key is pressed to begin a block literal." (sps (save-excursion (syntax-ppss (1- pt))))) (when (not (nth 8 sps)) (cond - ((and (char-equal ?' (char-before (1- pt))) + ((and (char-before (1- pt)) + (char-equal ?' (char-before (1- pt))) (char-equal ?' (char-before pt))) (put-text-property (- pt 2) pt 'syntax-table (string-to-syntax "w")) diff --git a/.emacs.d/snippets/python-mode.statnett/from b/.emacs.d/snippets/python-mode.statnett/from deleted file mode 100644 index 3a4acfc..0000000 --- a/.emacs.d/snippets/python-mode.statnett/from +++ /dev/null @@ -1,6 +0,0 @@ -# -*- mode: snippet -*- -# name: from -# key: from -# group : general -# -- -from ${1:lib} import ${2:funs} \ No newline at end of file diff --git a/.emacs.d/snippets/python-mode.statnett/try b/.emacs.d/snippets/python-mode.statnett/try deleted file mode 100644 index 6e68e8d..0000000 --- a/.emacs.d/snippets/python-mode.statnett/try +++ /dev/null @@ -1,8 +0,0 @@ -# -*- mode: snippet -*- -# name: try -# key: try -# -- -try: - $1 -except ${2:Exception} as e: - $0 \ No newline at end of file diff --git a/.emacs.d/snippets/python-mode.statnett/with-open b/.emacs.d/snippets/python-mode.statnett/with-open deleted file mode 100644 index 77c7210..0000000 --- a/.emacs.d/snippets/python-mode.statnett/with-open +++ /dev/null @@ -1,6 +0,0 @@ -# -*- mode: snippet -*- -# name: with-open -# key: wo -# -- -with open(${1:"filename"}${2:, encoding="${3:utf-8}"}${4:, mode="${5:w}"}) as ${6:myfile}: - $0 \ No newline at end of file diff --git a/.emacs.d/snippets/python-mode/from b/.emacs.d/snippets/python-mode/from deleted file mode 100644 index 3a4acfc..0000000 --- a/.emacs.d/snippets/python-mode/from +++ /dev/null @@ -1,6 +0,0 @@ -# -*- mode: snippet -*- -# name: from -# key: from -# group : general -# -- -from ${1:lib} import ${2:funs} \ No newline at end of file diff --git a/.emacs.d/snippets/python-mode/try b/.emacs.d/snippets/python-mode/try deleted file mode 100644 index 6e68e8d..0000000 --- a/.emacs.d/snippets/python-mode/try +++ /dev/null @@ -1,8 +0,0 @@ -# -*- mode: snippet -*- -# name: try -# key: try -# -- -try: - $1 -except ${2:Exception} as e: - $0 \ No newline at end of file diff --git a/.emacs.d/snippets/python-mode/with-open b/.emacs.d/snippets/python-mode/with-open deleted file mode 100644 index 77c7210..0000000 --- a/.emacs.d/snippets/python-mode/with-open +++ /dev/null @@ -1,6 +0,0 @@ -# -*- mode: snippet -*- -# name: with-open -# key: wo -# -- -with open(${1:"filename"}${2:, encoding="${3:utf-8}"}${4:, mode="${5:w}"}) as ${6:myfile}: - $0 \ No newline at end of file -- cgit v1.3