diff options
| author | Simeon Simeonov | 2026-02-14 10:44:11 +0100 |
|---|---|---|
| committer | Simeon Simeonov | 2026-02-14 10:44:11 +0100 |
| commit | aaac90c9b05e490660176dc6109b9e58c3bbe3c1 (patch) | |
| tree | 850d9c131aeaa749d2aaffaac54262b9917140fa | |
| parent | 5c2c9a50da3a3f534842ffe95a49fe990000a072 (diff) | |
Update markdown-mode and rust-mode
| -rw-r--r-- | .emacs.d/lisp/markdown-mode.el | 79 | ||||
| -rw-r--r-- | .emacs.d/lisp/rust-cargo-tests.el | 16 | ||||
| -rw-r--r-- | .emacs.d/lisp/rust-cargo.el | 33 | ||||
| -rw-r--r-- | .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 @@ | |||
| 38 | (require 'thingatpt) | 38 | (require 'thingatpt) |
| 39 | (require 'cl-lib) | 39 | (require 'cl-lib) |
| 40 | (require 'url-parse) | 40 | (require 'url-parse) |
| 41 | (require 'url-util) | ||
| 41 | (require 'button) | 42 | (require 'button) |
| 42 | (require 'color) | 43 | (require 'color) |
| 43 | (require 'rx) | 44 | (require 'rx) |
| @@ -2253,6 +2254,9 @@ Depending on your font, some reasonable choices are: | |||
| 2253 | (2 'markdown-markup-face) | 2254 | (2 'markdown-markup-face) |
| 2254 | (3 'markdown-metadata-value-face))) | 2255 | (3 'markdown-metadata-value-face))) |
| 2255 | (markdown-fontify-hrs) | 2256 | (markdown-fontify-hrs) |
| 2257 | (,markdown-regex-strike-through . ((3 markdown-markup-properties) | ||
| 2258 | (4 'markdown-strike-through-face) | ||
| 2259 | (5 markdown-markup-properties))) | ||
| 2256 | (markdown-match-code . ((1 markdown-markup-properties prepend) | 2260 | (markdown-match-code . ((1 markdown-markup-properties prepend) |
| 2257 | (2 'markdown-inline-code-face prepend) | 2261 | (2 'markdown-inline-code-face prepend) |
| 2258 | (3 markdown-markup-properties prepend))) | 2262 | (3 markdown-markup-properties prepend))) |
| @@ -2318,9 +2322,6 @@ Depending on your font, some reasonable choices are: | |||
| 2318 | (markdown-match-italic . ((1 markdown-markup-properties prepend) | 2322 | (markdown-match-italic . ((1 markdown-markup-properties prepend) |
| 2319 | (2 'markdown-italic-face append) | 2323 | (2 'markdown-italic-face append) |
| 2320 | (3 markdown-markup-properties prepend))) | 2324 | (3 markdown-markup-properties prepend))) |
| 2321 | (,markdown-regex-strike-through . ((3 markdown-markup-properties) | ||
| 2322 | (4 'markdown-strike-through-face) | ||
| 2323 | (5 markdown-markup-properties))) | ||
| 2324 | (markdown--match-highlighting . ((3 markdown-markup-properties) | 2325 | (markdown--match-highlighting . ((3 markdown-markup-properties) |
| 2325 | (4 'markdown-highlighting-face) | 2326 | (4 'markdown-highlighting-face) |
| 2326 | (5 markdown-markup-properties))) | 2327 | (5 markdown-markup-properties))) |
| @@ -3282,11 +3283,18 @@ processed elements." | |||
| 3282 | (markdown-end-of-text-block) | 3283 | (markdown-end-of-text-block) |
| 3283 | (point)))) | 3284 | (point)))) |
| 3284 | ;; Move over balanced expressions to closing right bracket. | 3285 | ;; Move over balanced expressions to closing right bracket. |
| 3285 | ;; Catch unbalanced expression errors and return nil. | 3286 | ;; Catch unbalanced expression errors, then try to search right bracket manually. |
| 3286 | (first-end (condition-case nil | 3287 | (first-end (condition-case nil |
| 3287 | (and (goto-char first-begin) | 3288 | (and (goto-char first-begin) |
| 3288 | (scan-sexps (point) 1)) | 3289 | (scan-sexps (point) 1)) |
| 3289 | (error nil))) | 3290 | (error |
| 3291 | (save-match-data | ||
| 3292 | (let ((last (match-end 4)) | ||
| 3293 | ok end-pos) | ||
| 3294 | (while (and (not ok) (search-forward "]" last t)) | ||
| 3295 | (unless (= (char-before (1- (point))) ?\\) | ||
| 3296 | (setq ok t end-pos (point)))) | ||
| 3297 | end-pos))))) | ||
| 3290 | ;; Continue with point at CONT-POINT upon failure. | 3298 | ;; Continue with point at CONT-POINT upon failure. |
| 3291 | (cont-point (min (1+ first-begin) last)) | 3299 | (cont-point (min (1+ first-begin) last)) |
| 3292 | second-begin second-end url-begin url-end | 3300 | second-begin second-end url-begin url-end |
| @@ -8160,6 +8168,27 @@ See `markdown-wiki-link-p' for more information." | |||
| 8160 | (thing-at-point-looking-at markdown-regex-uri) | 8168 | (thing-at-point-looking-at markdown-regex-uri) |
| 8161 | (thing-at-point-looking-at markdown-regex-angle-uri)))))) | 8169 | (thing-at-point-looking-at markdown-regex-angle-uri)))))) |
| 8162 | 8170 | ||
| 8171 | (defun markdown--unhex-url-string (url) | ||
| 8172 | "Unhex control characters and spaces in URL. | ||
| 8173 | This is similar to `url-unhex-string' but this doesn't unhex all percent-encoded | ||
| 8174 | characters." | ||
| 8175 | (let ((str (or url "")) | ||
| 8176 | (tmp "") | ||
| 8177 | (case-fold-search t)) | ||
| 8178 | (while (string-match "%\\([01][0-9a-f]\\|20\\)" str) | ||
| 8179 | (let* ((start (match-beginning 0)) | ||
| 8180 | (ch1 (url-unhex (elt str (+ start 1)))) | ||
| 8181 | (code (+ (* 16 ch1) | ||
| 8182 | (url-unhex (elt str (+ start 2)))))) | ||
| 8183 | (setq tmp (concat | ||
| 8184 | tmp (substring str 0 start) | ||
| 8185 | (cond | ||
| 8186 | ((or (= code ?\n) (= code ?\r)) | ||
| 8187 | " ") | ||
| 8188 | (t (byte-to-string code)))) | ||
| 8189 | str (substring str (match-end 0))))) | ||
| 8190 | (concat tmp str))) | ||
| 8191 | |||
| 8163 | (defun markdown-link-at-pos (pos) | 8192 | (defun markdown-link-at-pos (pos) |
| 8164 | "Return properties of link or image at position POS. | 8193 | "Return properties of link or image at position POS. |
| 8165 | Value is a list of elements describing the link: | 8194 | Value is a list of elements describing the link: |
| @@ -8183,7 +8212,9 @@ Value is a list of elements describing the link: | |||
| 8183 | url (match-string-no-properties 6)) | 8212 | url (match-string-no-properties 6)) |
| 8184 | ;; consider nested parentheses | 8213 | ;; consider nested parentheses |
| 8185 | ;; if link target contains parentheses, (match-end 0) isn't correct end position of the link | 8214 | ;; if link target contains parentheses, (match-end 0) isn't correct end position of the link |
| 8186 | (let* ((close-pos (scan-sexps (match-beginning 5) 1)) | 8215 | (let* ((close-pos (condition-case nil |
| 8216 | (scan-sexps (match-beginning 5) 1) | ||
| 8217 | (error (match-end 0)))) | ||
| 8187 | (destination-part (string-trim (buffer-substring-no-properties (1+ (match-beginning 5)) (1- close-pos))))) | 8218 | (destination-part (string-trim (buffer-substring-no-properties (1+ (match-beginning 5)) (1- close-pos))))) |
| 8188 | (setq end close-pos) | 8219 | (setq end close-pos) |
| 8189 | ;; A link can contain spaces if it is wrapped with angle brackets | 8220 | ;; 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: | |||
| 8193 | (setq url (match-string-no-properties 1 destination-part) | 8224 | (setq url (match-string-no-properties 1 destination-part) |
| 8194 | title (substring (match-string-no-properties 2 destination-part) 1 -1))) | 8225 | title (substring (match-string-no-properties 2 destination-part) 1 -1))) |
| 8195 | (t (setq url destination-part))) | 8226 | (t (setq url destination-part))) |
| 8196 | (setq url (url-unhex-string url)))) | 8227 | (setq url (markdown--unhex-url-string url)))) |
| 8197 | ;; Reference link at point. | 8228 | ;; Reference link at point. |
| 8198 | ((thing-at-point-looking-at markdown-regex-link-reference) | 8229 | ((thing-at-point-looking-at markdown-regex-link-reference) |
| 8199 | (setq bang (match-string-no-properties 1) | 8230 | (setq bang (match-string-no-properties 1) |
| @@ -9728,6 +9759,18 @@ This function assumes point is on a table." | |||
| 9728 | (cl-loop for c across line | 9759 | (cl-loop for c across line |
| 9729 | always (member c '(?| ?- ?: ?\t ? ))))) | 9760 | always (member c '(?| ?- ?: ?\t ? ))))) |
| 9730 | 9761 | ||
| 9762 | (defun markdown-table-align-raw (cells fmtspec widths) | ||
| 9763 | (let (fmt width) | ||
| 9764 | (mapconcat | ||
| 9765 | (lambda (cell) | ||
| 9766 | (setq fmt (car fmtspec) fmtspec (cdr fmtspec)) | ||
| 9767 | (setq width (car widths) widths (cdr widths)) | ||
| 9768 | (if (equal fmt 'c) | ||
| 9769 | (setq cell (concat (make-string (/ (- width (length cell)) 2) ?\s) cell))) | ||
| 9770 | (unless (equal fmt 'r) (setq width (- width))) | ||
| 9771 | (format (format " %%%ds " width) cell)) | ||
| 9772 | cells "|"))) | ||
| 9773 | |||
| 9731 | (defun markdown-table-align () | 9774 | (defun markdown-table-align () |
| 9732 | "Align table at point. | 9775 | "Align table at point. |
| 9733 | This function assumes point is on a table." | 9776 | This function assumes point is on a table." |
| @@ -9752,8 +9795,6 @@ This function assumes point is on a table." | |||
| 9752 | (maxcells (if cells | 9795 | (maxcells (if cells |
| 9753 | (apply #'max (mapcar #'length cells)) | 9796 | (apply #'max (mapcar #'length cells)) |
| 9754 | (user-error "Empty table"))) | 9797 | (user-error "Empty table"))) |
| 9755 | ;; Empty cells to fill short lines | ||
| 9756 | (emptycells (make-list maxcells "")) | ||
| 9757 | maxwidths) | 9798 | maxwidths) |
| 9758 | ;; Calculate maximum width for each column | 9799 | ;; Calculate maximum width for each column |
| 9759 | (dotimes (i maxcells) | 9800 | (dotimes (i maxcells) |
| @@ -9765,20 +9806,20 @@ This function assumes point is on a table." | |||
| 9765 | (setq fmtspec (markdown-table-colfmt fmtspec)) | 9806 | (setq fmtspec (markdown-table-colfmt fmtspec)) |
| 9766 | ;; Compute formats needed for output of table lines | 9807 | ;; Compute formats needed for output of table lines |
| 9767 | (let ((hfmt (concat indent "|")) | 9808 | (let ((hfmt (concat indent "|")) |
| 9768 | (rfmt (concat indent "|")) | 9809 | hfmt1 fmt (fmts fmtspec)) |
| 9769 | hfmt1 rfmt1 fmt) | 9810 | (dolist (width maxwidths) |
| 9770 | (dolist (width maxwidths (setq hfmt (concat (substring hfmt 0 -1) "|"))) | 9811 | (setq fmt (car fmts) fmts (cdr fmts)) |
| 9771 | (setq fmt (pop fmtspec)) | 9812 | (cond ((equal fmt 'l) (setq hfmt1 ":%s-|")) |
| 9772 | (cond ((equal fmt 'l) (setq hfmt1 ":%s-|" rfmt1 " %%-%ds |")) | 9813 | ((equal fmt 'r) (setq hfmt1 "-%s:|")) |
| 9773 | ((equal fmt 'r) (setq hfmt1 "-%s:|" rfmt1 " %%%ds |")) | 9814 | ((equal fmt 'c) (setq hfmt1 ":%s:|")) |
| 9774 | ((equal fmt 'c) (setq hfmt1 ":%s:|" rfmt1 " %%-%ds |")) | 9815 | (t (setq hfmt1 "-%s-|"))) |
| 9775 | (t (setq hfmt1 "-%s-|" rfmt1 " %%-%ds |"))) | ||
| 9776 | (setq rfmt (concat rfmt (format rfmt1 width))) | ||
| 9777 | (setq hfmt (concat hfmt (format hfmt1 (make-string width ?-))))) | 9816 | (setq hfmt (concat hfmt (format hfmt1 (make-string width ?-))))) |
| 9778 | ;; Replace modified lines only | 9817 | ;; Replace modified lines only |
| 9779 | (dolist (line lines) | 9818 | (dolist (line lines) |
| 9780 | (let ((line (if line | 9819 | (let ((line (if line |
| 9781 | (apply #'format rfmt (append (pop cells) emptycells)) | 9820 | (concat indent "|" |
| 9821 | (markdown-table-align-raw (pop cells) fmtspec maxwidths) | ||
| 9822 | "|") | ||
| 9782 | hfmt)) | 9823 | hfmt)) |
| 9783 | (previous (buffer-substring (point) (line-end-position)))) | 9824 | (previous (buffer-substring (point) (line-end-position)))) |
| 9784 | (if (equal previous line) | 9825 | (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 @@ | |||
| 60 | (rust-test--wait-process-exit) | 60 | (rust-test--wait-process-exit) |
| 61 | (should (rust-test--find-string "***run interactive: 1234"))))) | 61 | (should (rust-test--find-string "***run interactive: 1234"))))) |
| 62 | 62 | ||
| 63 | (ert-deftest rust-test-test () | ||
| 64 | (skip-unless (executable-find rust-cargo-bin)) | ||
| 65 | (setq rust-cargo-default-arguments "") | ||
| 66 | (rust-test--with-main-file-buffer | ||
| 67 | (with-current-buffer (rust-test) | ||
| 68 | (rust-test--wait-process-exit) | ||
| 69 | (should (rust-test--find-string "running 1 test"))))) | ||
| 70 | |||
| 71 | (ert-deftest rust-test-test-with-arg () | ||
| 72 | (skip-unless (executable-find rust-cargo-bin)) | ||
| 73 | (setq rust-cargo-default-arguments "") | ||
| 74 | (rust-test--with-main-file-buffer | ||
| 75 | (with-current-buffer (rust-test t t) | ||
| 76 | (rust-test--wait-process-exit) | ||
| 77 | (should (rust-test--find-string "***output test"))))) | ||
| 78 | |||
| 63 | (ert-deftest rust-test-rustfmt () | 79 | (ert-deftest rust-test-rustfmt () |
| 64 | (skip-unless (executable-find "rustfmt")) | 80 | (skip-unless (executable-find "rustfmt")) |
| 65 | (rust-test--with-main-file-buffer | 81 | (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`." | |||
| 66 | (goto-char 0) | 66 | (goto-char 0) |
| 67 | (let ((output (let ((json-object-type 'alist)) | 67 | (let ((output (let ((json-object-type 'alist)) |
| 68 | (json-read)))) | 68 | (json-read)))) |
| 69 | (cdr (assoc-string "root" output))))))) | 69 | (concat |
| 70 | (file-remote-p default-directory) | ||
| 71 | (cdr (assoc-string "root" output)))))))) | ||
| 70 | 72 | ||
| 71 | (defun rust-buffer-crate () | 73 | (defun rust-buffer-crate () |
| 72 | "Try to locate Cargo.toml using `locate-dominating-file'." | 74 | "Try to locate Cargo.toml using `locate-dominating-file'." |
| @@ -129,10 +131,29 @@ output buffer will be in comint mode, i.e. interactive." | |||
| 129 | (interactive "P") | 131 | (interactive "P") |
| 130 | (rust--compile comint "%s run --release" rust-cargo-bin)) | 132 | (rust--compile comint "%s run --release" rust-cargo-bin)) |
| 131 | 133 | ||
| 132 | (defun rust-test () | 134 | (defun rust-test (&optional arg is-test) |
| 133 | "Test using `cargo test`" | 135 | "Test using `cargo test`. |
| 134 | (interactive) | 136 | |
| 135 | (rust--compile nil "%s test %s" rust-cargo-bin rust-cargo-default-arguments)) | 137 | If prefixed with `C-u`, pass additional arguments to the command |
| 138 | (from a string read from the minibuffer). | ||
| 139 | |||
| 140 | If optional arg IS-TEST is non-nil, | ||
| 141 | the argument `-- --show-output' will be automatically | ||
| 142 | added instead of being read from the minibuffer. | ||
| 143 | |||
| 144 | Note that the IS-TEST arg is not meant for general use, | ||
| 145 | and only exists for testing the `rust-mode' package. " | ||
| 146 | (interactive "P") | ||
| 147 | (let ((test-command | ||
| 148 | (if arg | ||
| 149 | (progn | ||
| 150 | (let ((custom-arg | ||
| 151 | (if is-test | ||
| 152 | "-- --show-output" | ||
| 153 | (string-trim (read-string "Enter Arguments: "))))) | ||
| 154 | (concat "%s test " custom-arg " %s"))) | ||
| 155 | "%s test %s"))) | ||
| 156 | (rust--compile nil test-command rust-cargo-bin rust-cargo-default-arguments))) | ||
| 136 | 157 | ||
| 137 | (defun rust-run-clippy () | 158 | (defun rust-run-clippy () |
| 138 | "Run `cargo clippy'." | 159 | "Run `cargo clippy'." |
| @@ -140,7 +161,7 @@ output buffer will be in comint mode, i.e. interactive." | |||
| 140 | (when (null rust-buffer-project) | 161 | (when (null rust-buffer-project) |
| 141 | (rust-update-buffer-project)) | 162 | (rust-update-buffer-project)) |
| 142 | (let* ((args (append (list rust-cargo-bin "clippy" | 163 | (let* ((args (append (list rust-cargo-bin "clippy" |
| 143 | (concat "--manifest-path=" rust-buffer-project)) | 164 | (concat "--manifest-path=" (file-local-name rust-buffer-project))) |
| 144 | rust-cargo-clippy-default-arguments)) | 165 | rust-cargo-clippy-default-arguments)) |
| 145 | ;; set `compile-command' temporarily so `compile' doesn't | 166 | ;; set `compile-command' temporarily so `compile' doesn't |
| 146 | ;; clobber the existing value | 167 | ;; 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'." | |||
| 204 | "u64" "i64" | 204 | "u64" "i64" |
| 205 | "u128" "i128" | 205 | "u128" "i128" |
| 206 | 206 | ||
| 207 | "f32" "f64" | 207 | "f16" "f32" |
| 208 | "f64" "f128" | ||
| 208 | "isize" "usize" | 209 | "isize" "usize" |
| 209 | "bool" | 210 | "bool" |
| 210 | "str" "char")) | 211 | "str" "char")) |
