From aaac90c9b05e490660176dc6109b9e58c3bbe3c1 Mon Sep 17 00:00:00 2001 From: Simeon Simeonov Date: Sat, 14 Feb 2026 10:44:11 +0100 Subject: Update markdown-mode and rust-mode --- .emacs.d/lisp/markdown-mode.el | 79 +++++++++++++++++++++++++++++---------- .emacs.d/lisp/rust-cargo-tests.el | 16 ++++++++ .emacs.d/lisp/rust-cargo.el | 33 +++++++++++++--- .emacs.d/lisp/rust-prog-mode.el | 3 +- 4 files changed, 105 insertions(+), 26 deletions(-) diff --git a/.emacs.d/lisp/markdown-mode.el b/.emacs.d/lisp/markdown-mode.el index 77f9bf5..ddeaf7b 100644 --- a/.emacs.d/lisp/markdown-mode.el +++ b/.emacs.d/lisp/markdown-mode.el @@ -38,6 +38,7 @@ (require 'thingatpt) (require 'cl-lib) (require 'url-parse) +(require 'url-util) (require 'button) (require 'color) (require 'rx) @@ -2253,6 +2254,9 @@ Depending on your font, some reasonable choices are: (2 'markdown-markup-face) (3 'markdown-metadata-value-face))) (markdown-fontify-hrs) + (,markdown-regex-strike-through . ((3 markdown-markup-properties) + (4 'markdown-strike-through-face) + (5 markdown-markup-properties))) (markdown-match-code . ((1 markdown-markup-properties prepend) (2 'markdown-inline-code-face prepend) (3 markdown-markup-properties prepend))) @@ -2318,9 +2322,6 @@ Depending on your font, some reasonable choices are: (markdown-match-italic . ((1 markdown-markup-properties prepend) (2 'markdown-italic-face append) (3 markdown-markup-properties prepend))) - (,markdown-regex-strike-through . ((3 markdown-markup-properties) - (4 'markdown-strike-through-face) - (5 markdown-markup-properties))) (markdown--match-highlighting . ((3 markdown-markup-properties) (4 'markdown-highlighting-face) (5 markdown-markup-properties))) @@ -3282,11 +3283,18 @@ processed elements." (markdown-end-of-text-block) (point)))) ;; Move over balanced expressions to closing right bracket. - ;; Catch unbalanced expression errors and return nil. + ;; Catch unbalanced expression errors, then try to search right bracket manually. (first-end (condition-case nil (and (goto-char first-begin) (scan-sexps (point) 1)) - (error nil))) + (error + (save-match-data + (let ((last (match-end 4)) + ok end-pos) + (while (and (not ok) (search-forward "]" last t)) + (unless (= (char-before (1- (point))) ?\\) + (setq ok t end-pos (point)))) + end-pos))))) ;; Continue with point at CONT-POINT upon failure. (cont-point (min (1+ first-begin) last)) second-begin second-end url-begin url-end @@ -8160,6 +8168,27 @@ See `markdown-wiki-link-p' for more information." (thing-at-point-looking-at markdown-regex-uri) (thing-at-point-looking-at markdown-regex-angle-uri)))))) +(defun markdown--unhex-url-string (url) + "Unhex control characters and spaces in URL. +This is similar to `url-unhex-string' but this doesn't unhex all percent-encoded +characters." + (let ((str (or url "")) + (tmp "") + (case-fold-search t)) + (while (string-match "%\\([01][0-9a-f]\\|20\\)" str) + (let* ((start (match-beginning 0)) + (ch1 (url-unhex (elt str (+ start 1)))) + (code (+ (* 16 ch1) + (url-unhex (elt str (+ start 2)))))) + (setq tmp (concat + tmp (substring str 0 start) + (cond + ((or (= code ?\n) (= code ?\r)) + " ") + (t (byte-to-string code)))) + str (substring str (match-end 0))))) + (concat tmp str))) + (defun markdown-link-at-pos (pos) "Return properties of link or image at position POS. Value is a list of elements describing the link: @@ -8183,7 +8212,9 @@ Value is a list of elements describing the link: url (match-string-no-properties 6)) ;; consider nested parentheses ;; if link target contains parentheses, (match-end 0) isn't correct end position of the link - (let* ((close-pos (scan-sexps (match-beginning 5) 1)) + (let* ((close-pos (condition-case nil + (scan-sexps (match-beginning 5) 1) + (error (match-end 0)))) (destination-part (string-trim (buffer-substring-no-properties (1+ (match-beginning 5)) (1- close-pos))))) (setq end close-pos) ;; A link can contain spaces if it is wrapped with angle brackets @@ -8193,7 +8224,7 @@ Value is a list of elements describing the link: (setq url (match-string-no-properties 1 destination-part) title (substring (match-string-no-properties 2 destination-part) 1 -1))) (t (setq url destination-part))) - (setq url (url-unhex-string url)))) + (setq url (markdown--unhex-url-string url)))) ;; Reference link at point. ((thing-at-point-looking-at markdown-regex-link-reference) (setq bang (match-string-no-properties 1) @@ -9728,6 +9759,18 @@ This function assumes point is on a table." (cl-loop for c across line always (member c '(?| ?- ?: ?\t ? ))))) +(defun markdown-table-align-raw (cells fmtspec widths) + (let (fmt width) + (mapconcat + (lambda (cell) + (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))) + (unless (equal fmt 'r) (setq width (- width))) + (format (format " %%%ds " width) cell)) + cells "|"))) + (defun markdown-table-align () "Align table at point. This function assumes point is on a table." @@ -9752,8 +9795,6 @@ This function assumes point is on a table." (maxcells (if cells (apply #'max (mapcar #'length cells)) (user-error "Empty table"))) - ;; Empty cells to fill short lines - (emptycells (make-list maxcells "")) maxwidths) ;; Calculate maximum width for each column (dotimes (i maxcells) @@ -9765,20 +9806,20 @@ This function assumes point is on a table." (setq fmtspec (markdown-table-colfmt fmtspec)) ;; Compute formats needed for output of table lines (let ((hfmt (concat indent "|")) - (rfmt (concat indent "|")) - hfmt1 rfmt1 fmt) - (dolist (width maxwidths (setq hfmt (concat (substring hfmt 0 -1) "|"))) - (setq fmt (pop fmtspec)) - (cond ((equal fmt 'l) (setq hfmt1 ":%s-|" rfmt1 " %%-%ds |")) - ((equal fmt 'r) (setq hfmt1 "-%s:|" rfmt1 " %%%ds |")) - ((equal fmt 'c) (setq hfmt1 ":%s:|" rfmt1 " %%-%ds |")) - (t (setq hfmt1 "-%s-|" rfmt1 " %%-%ds |"))) - (setq rfmt (concat rfmt (format rfmt1 width))) + hfmt1 fmt (fmts fmtspec)) + (dolist (width maxwidths) + (setq fmt (car fmts) fmts (cdr fmts)) + (cond ((equal fmt 'l) (setq hfmt1 ":%s-|")) + ((equal fmt 'r) (setq hfmt1 "-%s:|")) + ((equal fmt 'c) (setq hfmt1 ":%s:|")) + (t (setq hfmt1 "-%s-|"))) (setq hfmt (concat hfmt (format hfmt1 (make-string width ?-))))) ;; Replace modified lines only (dolist (line lines) (let ((line (if line - (apply #'format rfmt (append (pop cells) emptycells)) + (concat indent "|" + (markdown-table-align-raw (pop cells) fmtspec maxwidths) + "|") hfmt)) (previous (buffer-substring (point) (line-end-position)))) (if (equal previous line) diff --git a/.emacs.d/lisp/rust-cargo-tests.el b/.emacs.d/lisp/rust-cargo-tests.el index 1b072ee..a029b2a 100644 --- a/.emacs.d/lisp/rust-cargo-tests.el +++ b/.emacs.d/lisp/rust-cargo-tests.el @@ -60,6 +60,22 @@ (rust-test--wait-process-exit) (should (rust-test--find-string "***run interactive: 1234"))))) +(ert-deftest rust-test-test () + (skip-unless (executable-find rust-cargo-bin)) + (setq rust-cargo-default-arguments "") + (rust-test--with-main-file-buffer + (with-current-buffer (rust-test) + (rust-test--wait-process-exit) + (should (rust-test--find-string "running 1 test"))))) + +(ert-deftest rust-test-test-with-arg () + (skip-unless (executable-find rust-cargo-bin)) + (setq rust-cargo-default-arguments "") + (rust-test--with-main-file-buffer + (with-current-buffer (rust-test t t) + (rust-test--wait-process-exit) + (should (rust-test--find-string "***output test"))))) + (ert-deftest rust-test-rustfmt () (skip-unless (executable-find "rustfmt")) (rust-test--with-main-file-buffer diff --git a/.emacs.d/lisp/rust-cargo.el b/.emacs.d/lisp/rust-cargo.el index d323b5d..bb5d2ac 100644 --- a/.emacs.d/lisp/rust-cargo.el +++ b/.emacs.d/lisp/rust-cargo.el @@ -66,7 +66,9 @@ worksapce for commands like `cargo check`." (goto-char 0) (let ((output (let ((json-object-type 'alist)) (json-read)))) - (cdr (assoc-string "root" output))))))) + (concat + (file-remote-p default-directory) + (cdr (assoc-string "root" output)))))))) (defun rust-buffer-crate () "Try to locate Cargo.toml using `locate-dominating-file'." @@ -129,10 +131,29 @@ output buffer will be in comint mode, i.e. interactive." (interactive "P") (rust--compile comint "%s run --release" rust-cargo-bin)) -(defun rust-test () - "Test using `cargo test`" - (interactive) - (rust--compile nil "%s test %s" rust-cargo-bin rust-cargo-default-arguments)) +(defun rust-test (&optional arg is-test) + "Test using `cargo test`. + +If prefixed with `C-u`, pass additional arguments to the command +(from a string read from the minibuffer). + +If optional arg IS-TEST is non-nil, +the argument `-- --show-output' will be automatically +added instead of being read from the minibuffer. + +Note that the IS-TEST arg is not meant for general use, +and only exists for testing the `rust-mode' package. " + (interactive "P") + (let ((test-command + (if arg + (progn + (let ((custom-arg + (if is-test + "-- --show-output" + (string-trim (read-string "Enter Arguments: "))))) + (concat "%s test " custom-arg " %s"))) + "%s test %s"))) + (rust--compile nil test-command rust-cargo-bin rust-cargo-default-arguments))) (defun rust-run-clippy () "Run `cargo clippy'." @@ -140,7 +161,7 @@ output buffer will be in comint mode, i.e. interactive." (when (null rust-buffer-project) (rust-update-buffer-project)) (let* ((args (append (list rust-cargo-bin "clippy" - (concat "--manifest-path=" rust-buffer-project)) + (concat "--manifest-path=" (file-local-name rust-buffer-project))) rust-cargo-clippy-default-arguments)) ;; set `compile-command' temporarily so `compile' doesn't ;; clobber the existing value diff --git a/.emacs.d/lisp/rust-prog-mode.el b/.emacs.d/lisp/rust-prog-mode.el index 6263949..f2f3f0b 100644 --- a/.emacs.d/lisp/rust-prog-mode.el +++ b/.emacs.d/lisp/rust-prog-mode.el @@ -204,7 +204,8 @@ See `prettify-symbols-compose-predicate'." "u64" "i64" "u128" "i128" - "f32" "f64" + "f16" "f32" + "f64" "f128" "isize" "usize" "bool" "str" "char")) -- cgit v1.3