summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimeon Simeonov2024-11-09 13:04:13 +0100
committerSimeon Simeonov2024-11-09 13:04:13 +0100
commita773e7ed865a1a7eb5bf00b9f0481e888534831a (patch)
tree9b0014538bb1cdddd41f651eba62a54d5ebca475
parent87d628a4bb80f1253e01e408bb8e02a0840f85b2 (diff)
Upgrade markdown-mode, nginx-mode, rust-mode, yaml-mode and python-mode/property_getter
-rw-r--r--.emacs.d/lisp/markdown-mode.el262
-rw-r--r--.emacs.d/lisp/nginx-mode.el30
-rw-r--r--.emacs.d/lisp/rust-cargo-tests.el53
-rw-r--r--.emacs.d/lisp/rust-cargo.el55
-rw-r--r--.emacs.d/lisp/rust-mode-treesitter.el13
-rw-r--r--.emacs.d/lisp/rust-mode.el10
-rw-r--r--.emacs.d/lisp/rust-prog-mode.el3
-rw-r--r--.emacs.d/lisp/rust-rustfmt.el4
-rw-r--r--.emacs.d/lisp/yaml-mode.el2
-rw-r--r--.emacs.d/snippets/python-mode.statnett/property_getter2
-rw-r--r--.emacs.d/snippets/python-mode.statnett/property_setter4
-rw-r--r--.emacs.d/snippets/python-mode/property_getter2
-rw-r--r--.emacs.d/snippets/python-mode/property_setter4
13 files changed, 267 insertions, 177 deletions
diff --git a/.emacs.d/lisp/markdown-mode.el b/.emacs.d/lisp/markdown-mode.el
index 33f7476..89d8962 100644
--- a/.emacs.d/lisp/markdown-mode.el
+++ b/.emacs.d/lisp/markdown-mode.el
@@ -684,52 +684,36 @@ This may also be a cons cell where the behavior for `C-a' and
684`C-e' is set separately." 684`C-e' is set separately."
685 :group 'markdown 685 :group 'markdown
686 :type '(choice 686 :type '(choice
687 (const :tag "off" nil) 687 (const :tag "off" nil)
688 (const :tag "on: after hashes/bullet and before closing tags first" t) 688 (const :tag "on: after hashes/bullet and before closing tags first" t)
689 (const :tag "reversed: true line boundary first" reversed) 689 (const :tag "reversed: true line boundary first" reversed)
690 (cons :tag "Set C-a and C-e separately" 690 (cons :tag "Set C-a and C-e separately"
691 (choice :tag "Special C-a" 691 (choice :tag "Special C-a"
692 (const :tag "off" nil) 692 (const :tag "off" nil)
693 (const :tag "on: after hashes/bullet first" t) 693 (const :tag "on: after hashes/bullet first" t)
694 (const :tag "reversed: before hashes/bullet first" reversed)) 694 (const :tag "reversed: before hashes/bullet first" reversed))
695 (choice :tag "Special C-e" 695 (choice :tag "Special C-e"
696 (const :tag "off" nil) 696 (const :tag "off" nil)
697 (const :tag "on: before closing tags first" t) 697 (const :tag "on: before closing tags first" t)
698 (const :tag "reversed: after closing tags first" reversed)))) 698 (const :tag "reversed: after closing tags first" reversed))))
699 :package-version '(markdown-mode . "2.7")) 699 :package-version '(markdown-mode . "2.7"))
700 700
701;;; Markdown-Specific `rx' Macro ============================================== 701;;; Markdown-Specific `rx' Macro ==============================================
702 702
703;; Based on python-rx from python.el. 703;; Based on python-rx from python.el.
704(eval-and-compile 704(defmacro markdown-rx (&rest regexps)
705 (defconst markdown-rx-constituents 705 "Markdown mode specialized rx macro.
706 `((newline . ,(rx "\n"))
707 ;; Note: #405 not consider markdown-list-indent-width however this is never used
708 (indent . ,(rx (or (repeat 4 " ") "\t")))
709 (block-end . ,(rx (and (or (one-or-more (zero-or-more blank) "\n") line-end))))
710 (numeral . ,(rx (and (one-or-more (any "0-9#")) ".")))
711 (bullet . ,(rx (any "*+:-")))
712 (list-marker . ,(rx (or (and (one-or-more (any "0-9#")) ".")
713 (any "*+:-"))))
714 (checkbox . ,(rx "[" (any " xX") "]")))
715 "Markdown-specific sexps for `markdown-rx'")
716
717 (defun markdown-rx-to-string (form &optional no-group)
718 "Markdown mode specialized `rx-to-string' function.
719This variant supports named Markdown expressions in FORM.
720NO-GROUP non-nil means don't put shy groups around the result."
721 (let ((rx-constituents (append markdown-rx-constituents rx-constituents)))
722 (rx-to-string form no-group)))
723
724 (defmacro markdown-rx (&rest regexps)
725 "Markdown mode specialized rx macro.
726This variant of `rx' supports common Markdown named REGEXPS." 706This variant of `rx' supports common Markdown named REGEXPS."
727 (cond ((null regexps) 707 `(rx-let ((newline "\n")
728 (error "No regexp")) 708 ;; Note: #405 not consider markdown-list-indent-width however this is never used
729 ((cdr regexps) 709 (indent (or (repeat 4 " ") "\t"))
730 (markdown-rx-to-string `(and ,@regexps) t)) 710 (block-end (and (or (one-or-more (zero-or-more blank) "\n") line-end)))
731 (t 711 (numeral (and (one-or-more (any "0-9#")) "."))
732 (markdown-rx-to-string (car regexps) t))))) 712 (bullet (any "*+:-"))
713 (list-marker (or (and (one-or-more (any "0-9#")) ".")
714 (any "*+:-")))
715 (checkbox (seq "[" (any " xX") "]")))
716 (rx ,@regexps)))
733 717
734 718
735;;; Regular Expressions ======================================================= 719;;; Regular Expressions =======================================================
@@ -1157,7 +1141,8 @@ Group 4 matches the text inside the delimiters.")
1157 "Property list of all Markdown syntactic properties.") 1141 "Property list of all Markdown syntactic properties.")
1158 1142
1159(defvar markdown-literal-faces 1143(defvar markdown-literal-faces
1160 '(markdown-inline-code-face 1144 '(markdown-code-face
1145 markdown-inline-code-face
1161 markdown-pre-face 1146 markdown-pre-face
1162 markdown-math-face 1147 markdown-math-face
1163 markdown-url-face 1148 markdown-url-face
@@ -2804,8 +2789,9 @@ They does not include square brackets)."
2804 uris :test #'equal))) 2789 uris :test #'equal)))
2805 (reverse uris)))) 2790 (reverse uris))))
2806 2791
2807(defun markdown-inline-code-at-pos (pos) 2792(defun markdown-inline-code-at-pos (pos &optional from)
2808 "Return non-nil if there is an inline code fragment at POS. 2793 "Return non-nil if there is an inline code fragment at POS starting at FROM.
2794Uses the beginning of the block if FROM is nil.
2809Return nil otherwise. Set match data according to 2795Return nil otherwise. Set match data according to
2810`markdown-match-code' upon success. 2796`markdown-match-code' upon success.
2811This function searches the block for a code fragment that 2797This function searches the block for a code fragment that
@@ -2822,7 +2808,9 @@ Group 3 matches the closing backquotes."
2822 (let ((old-point (point)) 2808 (let ((old-point (point))
2823 (end-of-block (progn (markdown-end-of-text-block) (point))) 2809 (end-of-block (progn (markdown-end-of-text-block) (point)))
2824 found) 2810 found)
2825 (markdown-beginning-of-text-block) 2811 (if from
2812 (goto-char from)
2813 (markdown-beginning-of-text-block))
2826 (while (and (markdown-match-code end-of-block) 2814 (while (and (markdown-match-code end-of-block)
2827 (setq found t) 2815 (setq found t)
2828 (< (match-end 0) old-point))) 2816 (< (match-end 0) old-point)))
@@ -2970,28 +2958,42 @@ When FACELESS is non-nil, do not return matches where faces have been applied."
2970 2958
2971(defun markdown-match-bold (last) 2959(defun markdown-match-bold (last)
2972 "Match inline bold from the point to LAST." 2960 "Match inline bold from the point to LAST."
2973 (when (markdown-match-inline-generic markdown-regex-bold last) 2961 (let (done
2974 (let ((is-gfm (derived-mode-p 'gfm-mode)) 2962 retval
2975 (begin (match-beginning 2)) 2963 last-inline-code)
2976 (end (match-end 2))) 2964 (while (not done)
2977 (if (or (markdown-inline-code-at-pos-p begin) 2965 (if (markdown-match-inline-generic markdown-regex-bold last)
2978 (markdown-inline-code-at-pos-p end) 2966 (let ((is-gfm (derived-mode-p 'gfm-mode))
2979 (markdown-in-comment-p) 2967 (begin (match-beginning 2))
2980 (markdown-range-property-any 2968 (end (match-end 2)))
2981 begin begin 'face '(markdown-url-face 2969 (if (or
2982 markdown-plain-url-face)) 2970 (and last-inline-code
2983 (markdown-range-property-any 2971 (>= begin (car last-inline-code))
2984 begin end 'face '(markdown-hr-face 2972 (< begin (cdr last-inline-code)))
2985 markdown-math-face)) 2973 (save-match-data
2986 (and is-gfm (not (markdown--gfm-markup-underscore-p begin end)))) 2974 (when (markdown-inline-code-at-pos begin (cdr last-inline-code))
2987 (progn (goto-char (min (1+ begin) last)) 2975 (setq last-inline-code `(,(match-beginning 0) . ,(match-end 0)))))
2988 (when (< (point) last) 2976 (markdown-inline-code-at-pos-p end)
2989 (markdown-match-bold last))) 2977 (markdown-in-comment-p)
2990 (set-match-data (list (match-beginning 2) (match-end 2) 2978 (markdown-range-property-any
2991 (match-beginning 3) (match-end 3) 2979 begin begin 'face '(markdown-url-face
2992 (match-beginning 4) (match-end 4) 2980 markdown-plain-url-face))
2993 (match-beginning 5) (match-end 5))) 2981 (markdown-range-property-any
2994 t)))) 2982 begin end 'face '(markdown-hr-face
2983 markdown-math-face))
2984 (and is-gfm (not (markdown--gfm-markup-underscore-p begin end))))
2985 (progn (goto-char (min (1+ begin) last))
2986 (unless (< (point) last)
2987 (setq
2988 done t)))
2989 (set-match-data (list (match-beginning 2) (match-end 2)
2990 (match-beginning 3) (match-end 3)
2991 (match-beginning 4) (match-end 4)
2992 (match-beginning 5) (match-end 5)))
2993 (setq done t
2994 retval t)))
2995 (setq done t)))
2996 retval))
2995 2997
2996(defun markdown-match-italic (last) 2998(defun markdown-match-italic (last)
2997 "Match inline italics from the point to LAST." 2999 "Match inline italics from the point to LAST."
@@ -2999,37 +3001,51 @@ When FACELESS is non-nil, do not return matches where faces have been applied."
2999 (regex (if is-gfm 3001 (regex (if is-gfm
3000 markdown-regex-gfm-italic 3002 markdown-regex-gfm-italic
3001 markdown-regex-italic))) 3003 markdown-regex-italic)))
3002 (when (and (markdown-match-inline-generic regex last) 3004 (let (done
3003 (not (markdown--face-p 3005 retval
3004 (match-beginning 1) 3006 last-inline-code)
3005 '(markdown-html-attr-name-face markdown-html-attr-value-face)))) 3007 (while (not done)
3006 (let ((begin (match-beginning 1)) 3008 (if (and (markdown-match-inline-generic regex last)
3007 (end (match-end 1)) 3009 (not (markdown--face-p
3008 (close-end (match-end 4))) 3010 (match-beginning 1)
3009 (if (or (eql (char-before begin) (char-after begin)) 3011 '(markdown-html-attr-name-face markdown-html-attr-value-face))))
3010 (markdown-inline-code-at-pos-p begin) 3012 (let ((begin (match-beginning 1))
3011 (markdown-inline-code-at-pos-p (1- end)) 3013 (end (match-end 1))
3012 (markdown-in-comment-p) 3014 (close-end (match-end 4)))
3013 (markdown-range-property-any 3015 (if (or (eql (char-before begin) (char-after begin))
3014 begin begin 'face '(markdown-url-face 3016 (and last-inline-code
3015 markdown-plain-url-face 3017 (>= begin (car last-inline-code))
3016 markdown-markup-face)) 3018 (< begin (cdr last-inline-code)))
3017 (markdown-range-property-any 3019 (save-match-data
3018 begin end 'face '(markdown-bold-face 3020 (when (markdown-inline-code-at-pos begin (cdr last-inline-code))
3019 markdown-list-face 3021 (setq last-inline-code `(,(match-beginning 0) . ,(match-end 0)))))
3020 markdown-hr-face 3022
3021 markdown-math-face)) 3023 (markdown-inline-code-at-pos-p (1- end))
3022 (and is-gfm 3024 (markdown-in-comment-p)
3023 (or (char-equal (char-after begin) (char-after (1+ begin))) ;; check bold case 3025 (markdown-range-property-any
3024 (not (markdown--gfm-markup-underscore-p begin close-end))))) 3026 begin begin 'face '(markdown-url-face
3025 (progn (goto-char (min (1+ begin) last)) 3027 markdown-plain-url-face
3026 (when (< (point) last) 3028 markdown-markup-face))
3027 (markdown-match-italic last))) 3029 (markdown-range-property-any
3028 (set-match-data (list (match-beginning 1) (match-end 1) 3030 begin end 'face '(markdown-bold-face
3029 (match-beginning 2) (match-end 2) 3031 markdown-list-face
3030 (match-beginning 3) (match-end 3) 3032 markdown-hr-face
3031 (match-beginning 4) (match-end 4))) 3033 markdown-math-face))
3032 t))))) 3034 (and is-gfm
3035 (or (char-equal (char-after begin) (char-after (1+ begin))) ;; check bold case
3036 (not (markdown--gfm-markup-underscore-p begin close-end)))))
3037 (progn (goto-char (min (1+ begin) last))
3038 (unless (< (point) last)
3039 (setq
3040 done t)))
3041 (set-match-data (list (match-beginning 1) (match-end 1)
3042 (match-beginning 2) (match-end 2)
3043 (match-beginning 3) (match-end 3)
3044 (match-beginning 4) (match-end 4)))
3045 (setq done t
3046 retval t)))
3047 (setq done t)))
3048 retval)))
3033 3049
3034(defun markdown--match-highlighting (last) 3050(defun markdown--match-highlighting (last)
3035 (when markdown-enable-highlighting-syntax 3051 (when markdown-enable-highlighting-syntax
@@ -3543,30 +3559,25 @@ SEQ may be an atom or a sequence."
3543 (add-text-properties 3559 (add-text-properties
3544 (match-beginning 3) (match-end 3) rule-props))) 3560 (match-beginning 3) (match-end 3) rule-props)))
3545 ;; atx heading 3561 ;; atx heading
3546 (let ((header-end 3562 (let ((fontified-start
3563 (if (or markdown-hide-markup (not markdown-fontify-whole-heading-line))
3564 (match-beginning 5)
3565 (match-beginning 0)))
3566 (fontified-end
3547 (if markdown-fontify-whole-heading-line 3567 (if markdown-fontify-whole-heading-line
3548 (min (point-max) (1+ (match-end 0))) 3568 (min (point-max) (1+ (match-end 0)))
3549 (match-end 0)))) 3569 (match-end 5))))
3550 (add-text-properties 3570 (add-text-properties
3551 (match-beginning 4) (match-end 4) left-markup-props) 3571 (match-beginning 4) (match-end 4) left-markup-props)
3552 3572
3553 ;; If closing tag is present 3573 ;; If closing tag is present
3554 (if (match-end 6) 3574 (if (match-end 6)
3555 (progn 3575 (progn
3556 (if markdown-hide-markup 3576 (add-text-properties fontified-start fontified-end heading-props)
3557 (progn 3577 (when (or markdown-hide-markup (not markdown-fontify-whole-heading-line))
3558 (add-text-properties 3578 (add-text-properties (match-beginning 6) (match-end 6) right-markup-props)))
3559 (match-beginning 5) header-end heading-props)
3560 (add-text-properties
3561 (match-beginning 6) (match-end 6) right-markup-props))
3562 (add-text-properties
3563 (match-beginning 5) (match-end 5) heading-props)
3564 (add-text-properties
3565 (match-beginning 6) header-end right-markup-props)))
3566 ;; If closing tag is not present 3579 ;; If closing tag is not present
3567 (add-text-properties 3580 (add-text-properties fontified-start fontified-end heading-props)))))
3568 (match-beginning 5) header-end heading-props))
3569 )))
3570 t)) 3581 t))
3571 3582
3572(defun markdown-fontify-tables (last) 3583(defun markdown-fontify-tables (last)
@@ -3812,12 +3823,12 @@ prefixed with an integer from 1 to the length of
3812 (when (and beg skip-space) 3823 (when (and beg skip-space)
3813 (save-excursion 3824 (save-excursion
3814 (goto-char beg) 3825 (goto-char beg)
3815 (skip-chars-forward "[ \t]") 3826 (skip-chars-forward " \t")
3816 (setq beg (point)))) 3827 (setq beg (point))))
3817 (when (and end skip-space) 3828 (when (and end skip-space)
3818 (save-excursion 3829 (save-excursion
3819 (goto-char end) 3830 (goto-char end)
3820 (skip-chars-backward "[ \t]") 3831 (skip-chars-backward " \t")
3821 (setq end (point)))) 3832 (setq end (point))))
3822 (markdown-wrap-or-insert start-delim end-delim nil beg end)) 3833 (markdown-wrap-or-insert start-delim end-delim nil beg end))
3823 (if (markdown--face-p (point) (list face)) 3834 (if (markdown--face-p (point) (list face))
@@ -4894,7 +4905,7 @@ footnote text is found, NIL is returned."
4894 (save-excursion 4905 (save-excursion
4895 (goto-char (point-min)) 4906 (goto-char (point-min))
4896 (when (re-search-forward (concat "^ \\{0,3\\}\\[" id "\\]:") nil t) 4907 (when (re-search-forward (concat "^ \\{0,3\\}\\[" id "\\]:") nil t)
4897 (skip-chars-forward "[ \t]") 4908 (skip-chars-forward " \t")
4898 (point)))) 4909 (point))))
4899 4910
4900(defun markdown-footnote-marker-positions () 4911(defun markdown-footnote-marker-positions ()
@@ -7692,12 +7703,14 @@ Return the name of the output buffer used."
7692Insert the output in the buffer named OUTPUT-BUFFER-NAME." 7703Insert the output in the buffer named OUTPUT-BUFFER-NAME."
7693 (interactive) 7704 (interactive)
7694 (setq output-buffer-name (markdown output-buffer-name)) 7705 (setq output-buffer-name (markdown output-buffer-name))
7695 (with-current-buffer output-buffer-name 7706 (let ((css-path markdown-css-paths))
7696 (set-buffer output-buffer-name) 7707 (with-current-buffer output-buffer-name
7697 (unless (markdown-output-standalone-p) 7708 (set-buffer output-buffer-name)
7698 (markdown-add-xhtml-header-and-footer output-buffer-name)) 7709 (setq-local markdown-css-paths css-path)
7699 (goto-char (point-min)) 7710 (unless (markdown-output-standalone-p)
7700 (html-mode)) 7711 (markdown-add-xhtml-header-and-footer output-buffer-name))
7712 (goto-char (point-min))
7713 (html-mode)))
7701 output-buffer-name) 7714 output-buffer-name)
7702 7715
7703(defun markdown-other-window (&optional output-buffer-name) 7716(defun markdown-other-window (&optional output-buffer-name)
@@ -9139,7 +9152,7 @@ position."
9139 (remove-text-properties start end '(face nil)) 9152 (remove-text-properties start end '(face nil))
9140 (with-current-buffer 9153 (with-current-buffer
9141 (get-buffer-create 9154 (get-buffer-create
9142 (concat " markdown-code-fontification:" (symbol-name lang-mode))) 9155 (format " *markdown-code-fontification:%s*" (symbol-name lang-mode)))
9143 ;; Make sure that modification hooks are not inhibited in 9156 ;; Make sure that modification hooks are not inhibited in
9144 ;; the org-src-fontification buffer in case we're called 9157 ;; the org-src-fontification buffer in case we're called
9145 ;; from `jit-lock-function' (Bug#25132). 9158 ;; from `jit-lock-function' (Bug#25132).
@@ -10292,6 +10305,11 @@ rows and columns and the column alignment."
10292 (setq markdown-link-space-sub-char "-") 10305 (setq markdown-link-space-sub-char "-")
10293 (setq markdown-wiki-link-search-subdirectories t) 10306 (setq markdown-wiki-link-search-subdirectories t)
10294 (setq-local markdown-table-at-point-p-function #'gfm--table-at-point-p) 10307 (setq-local markdown-table-at-point-p-function #'gfm--table-at-point-p)
10308 (setq-local paragraph-separate
10309 (concat paragraph-separate
10310 "\\|"
10311 ;; GFM alert syntax
10312 "^>\s-*\\[!\\(?:NOTE\\|TIP\\|IMPORTANT\\|WARNING\\|CAUTION\\)\\]"))
10295 (add-hook 'post-self-insert-hook #'gfm--electric-pair-fence-code-block 'append t) 10313 (add-hook 'post-self-insert-hook #'gfm--electric-pair-fence-code-block 'append t)
10296 (markdown-gfm-parse-buffer-for-languages)) 10314 (markdown-gfm-parse-buffer-for-languages))
10297 10315
diff --git a/.emacs.d/lisp/nginx-mode.el b/.emacs.d/lisp/nginx-mode.el
index b01367c..4a29d1e 100644
--- a/.emacs.d/lisp/nginx-mode.el
+++ b/.emacs.d/lisp/nginx-mode.el
@@ -5,7 +5,7 @@
5;; Author: Andrew J Cosgriff <andrew@cosgriff.name> 5;; Author: Andrew J Cosgriff <andrew@cosgriff.name>
6;; Maintainer: Andrew J Cosgriff <andrew@cosgriff.name> 6;; Maintainer: Andrew J Cosgriff <andrew@cosgriff.name>
7;; Created: 15 Oct 2010 7;; Created: 15 Oct 2010
8;; Version: 1.1.9 8;; Version: 1.1.10
9;; Keywords: languages, nginx 9;; Keywords: languages, nginx
10 10
11;; available from http://github.com/ajc/nginx-mode 11;; available from http://github.com/ajc/nginx-mode
@@ -33,6 +33,10 @@
33 33
34;; Put this file into your load-path and the following into your ~/.emacs: 34;; Put this file into your load-path and the following into your ~/.emacs:
35;; (require 'nginx-mode) 35;; (require 'nginx-mode)
36;;
37;; Now that nginx-mode is available via NonGNU ELPA, you could also:
38;; (use-package nginx-mode
39;; :commands nginx-mode)
36 40
37;;; Code: 41;;; Code:
38 42
@@ -76,24 +80,8 @@
76 "If point is in a block, return the indentation of the first line of that 80 "If point is in a block, return the indentation of the first line of that
77block (the line containing the opening brace). Used to set the indentation 81block (the line containing the opening brace). Used to set the indentation
78of the closing brace of a block." 82of the closing brace of a block."
79 (save-excursion 83 (* (syntax-ppss-depth (syntax-ppss))
80 (save-match-data 84 nginx-indent-level))
81 (let ((opoint (point))
82 (apoint (search-backward "{" nil t)))
83 (when apoint
84 ;; This is a bit of a hack and doesn't allow for strings. We really
85 ;; want to parse by sexps at some point.
86 (let ((close-braces (count-matches "}" apoint opoint))
87 (open-braces 0))
88 (while (and apoint (> close-braces open-braces))
89 (setq apoint (search-backward "{" nil t))
90 (when apoint
91 (setq close-braces (count-matches "}" apoint opoint))
92 (setq open-braces (1+ open-braces)))))
93 (if apoint
94 (current-indentation)
95 nil))))))
96
97 85
98(defun nginx-comment-line-p () 86(defun nginx-comment-line-p ()
99 "Return non-nil iff this line is a comment." 87 "Return non-nil iff this line is a comment."
@@ -112,11 +100,11 @@ of the closing brace of a block."
112 (block-indent (nginx-block-indent)) 100 (block-indent (nginx-block-indent))
113 cur-indent) 101 cur-indent)
114 (cond 102 (cond
115 ((and (looking-at "^\\s-*}\\s-*$") block-indent) 103 ((and (looking-at "^\\s-*}") block-indent)
116 ;; This line contains a closing brace and we're at the inner 104 ;; This line contains a closing brace and we're at the inner
117 ;; block, so we should indent it matching the indentation of 105 ;; block, so we should indent it matching the indentation of
118 ;; the opening brace of the block. 106 ;; the opening brace of the block.
119 (setq cur-indent block-indent)) 107 (setq cur-indent (- block-indent nginx-indent-level)))
120 (t 108 (t
121 ;; Otherwise, we did not start on a block-ending-only line. 109 ;; Otherwise, we did not start on a block-ending-only line.
122 (save-excursion 110 (save-excursion
diff --git a/.emacs.d/lisp/rust-cargo-tests.el b/.emacs.d/lisp/rust-cargo-tests.el
new file mode 100644
index 0000000..f49cba0
--- /dev/null
+++ b/.emacs.d/lisp/rust-cargo-tests.el
@@ -0,0 +1,53 @@
1;;; rust-cargo-tests.el --- ERT tests for rust-cargo.el -*- lexical-binding: t; -*-
2(require 'rust-cargo)
3(require 'ert)
4
5(defun rust-test--wait-process-exit ()
6 "Wait for comint process for current buffer to exit."
7 (let ((proc (get-buffer-process (current-buffer))))
8 (while (not (eq (process-status proc) 'exit))
9 (sit-for 0.2))))
10
11(defun rust-test--send-process-string (string)
12 "Send STRING to comint process for current buffer."
13 (let ((proc (get-buffer-process (current-buffer))))
14 (comint-send-string proc string)))
15
16(defmacro rust-test--with-main-file-buffer (expr)
17 `(let* ((test-dir (expand-file-name "test-project/" default-directory))
18 (main-file (expand-file-name "src/main.rs" test-dir)))
19 (save-current-buffer
20 (find-file main-file)
21 ,expr)))
22
23(defun rust-test--find-string (string)
24 "Find STRING in current buffer."
25 (goto-char (point-min))
26 (not (null (search-forward string nil t))))
27
28
29(ert-deftest rust-test-compile ()
30 (skip-unless (executable-find rust-cargo-bin))
31 (setq rust-cargo-default-arguments "")
32 (rust-test--with-main-file-buffer
33 (with-current-buffer (rust-compile)
34 (rust-test--wait-process-exit)
35 (should (rust-test--find-string "Compilation finished")))))
36
37(ert-deftest rust-test-run ()
38 (skip-unless (executable-find rust-cargo-bin))
39 (setq rust-cargo-default-arguments "")
40 (rust-test--with-main-file-buffer
41 (with-current-buffer (rust-run)
42 (rust-test--wait-process-exit)
43 (should (rust-test--find-string "***run not interactive")))))
44
45(ert-deftest rust-test-run-interactive ()
46 (skip-unless (executable-find rust-cargo-bin))
47 (setq rust-cargo-default-arguments "interactive")
48 (rust-test--with-main-file-buffer
49 ;; '(4) is default value when called interactively with universal argument
50 (with-current-buffer (rust-run '(4))
51 (rust-test--send-process-string "1234\n")
52 (rust-test--wait-process-exit)
53 (should (rust-test--find-string "***run interactive: 1234")))))
diff --git a/.emacs.d/lisp/rust-cargo.el b/.emacs.d/lisp/rust-cargo.el
index bda23d8..d9f1be5 100644
--- a/.emacs.d/lisp/rust-cargo.el
+++ b/.emacs.d/lisp/rust-cargo.el
@@ -19,6 +19,13 @@
19 :type 'boolean 19 :type 'boolean
20 :group 'rust-mode) 20 :group 'rust-mode)
21 21
22(defcustom rust-cargo-locate-default-arguments '("--workspace")
23 "Arguments for `cargo locate-project`. Remove `--workspace` if you
24would prefer to use the local crate Cargo.toml instead of the
25worksapce for commands like `cargo check`."
26 :type '(repeat string)
27 :group 'rust-mode)
28
22(defcustom rust-cargo-default-arguments "" 29(defcustom rust-cargo-default-arguments ""
23 "Default arguments when running common cargo commands." 30 "Default arguments when running common cargo commands."
24 :type 'string 31 :type 'string
@@ -42,7 +49,13 @@
42 (setq-local process-environment env) 49 (setq-local process-environment env)
43 ;; Set PATH so we can find cargo. 50 ;; Set PATH so we can find cargo.
44 (setq-local exec-path path) 51 (setq-local exec-path path)
45 (let ((ret (process-file rust-cargo-bin nil (list (current-buffer) nil) nil "locate-project" "--workspace"))) 52 (let ((ret
53 (let ((args
54 (append
55 (list rust-cargo-bin nil (list (current-buffer) nil) nil
56 "locate-project")
57 rust-cargo-locate-default-arguments)))
58 (apply #'process-file args))))
46 (when (/= ret 0) 59 (when (/= ret 0)
47 (error "`cargo locate-project' returned %s status: %s" ret (buffer-string))) 60 (error "`cargo locate-project' returned %s status: %s" ret (buffer-string)))
48 (goto-char 0) 61 (goto-char 0)
@@ -67,46 +80,54 @@
67 80
68;;; Internal 81;;; Internal
69 82
70(defun rust--compile (format-string &rest args) 83(defun rust--compile (comint format-string &rest args)
71 (when (null rust-buffer-project) 84 (when (null rust-buffer-project)
72 (rust-update-buffer-project)) 85 (rust-update-buffer-project))
73 (let ((default-directory 86 (let ((default-directory
74 (or (and rust-buffer-project 87 (or (and rust-buffer-project
75 (file-name-directory rust-buffer-project)) 88 (file-name-directory rust-buffer-project))
76 default-directory))) 89 default-directory))
77 (compile (apply #'format format-string args)))) 90 ;; make sure comint is a boolean value
91 (comint (not (not comint))))
92 (compile (apply #'format format-string args) comint)))
78 93
79;;; Commands 94;;; Commands
80 95
81(defun rust-check () 96(defun rust-check ()
82 "Compile using `cargo check`" 97 "Compile using `cargo check`"
83 (interactive) 98 (interactive)
84 (rust--compile "%s check %s" rust-cargo-bin rust-cargo-default-arguments)) 99 (rust--compile nil "%s check %s" rust-cargo-bin rust-cargo-default-arguments))
85 100
86(defun rust-compile () 101(defun rust-compile ()
87 "Compile using `cargo build`" 102 "Compile using `cargo build`"
88 (interactive) 103 (interactive)
89 (rust--compile "%s build %s" rust-cargo-bin rust-cargo-default-arguments)) 104 (rust--compile nil "%s build %s" rust-cargo-bin rust-cargo-default-arguments))
90 105
91(defun rust-compile-release () 106(defun rust-compile-release ()
92 "Compile using `cargo build --release`" 107 "Compile using `cargo build --release`"
93 (interactive) 108 (interactive)
94 (rust--compile "%s build --release" rust-cargo-bin)) 109 (rust--compile nil "%s build --release" rust-cargo-bin))
95 110
96(defun rust-run () 111(defun rust-run (&optional comint)
97 "Run using `cargo run`" 112 "Run using `cargo run`
98 (interactive)
99 (rust--compile "%s run %s" rust-cargo-bin rust-cargo-default-arguments))
100 113
101(defun rust-run-release () 114If optional arg COMINT is t or invoked with universal prefix arg,
102 "Run using `cargo run --release`" 115output buffer will be in comint mode, i.e. interactive."
103 (interactive) 116 (interactive "P")
104 (rust--compile "%s run --release" rust-cargo-bin)) 117 (rust--compile comint "%s run %s" rust-cargo-bin rust-cargo-default-arguments))
118
119(defun rust-run-release (&optional comint)
120 "Run using `cargo run --release`
121
122If optional arg COMINT is t or invoked with universal prefix arg,
123output buffer will be in comint mode, i.e. interactive."
124 (interactive "P")
125 (rust--compile comint "%s run --release" rust-cargo-bin))
105 126
106(defun rust-test () 127(defun rust-test ()
107 "Test using `cargo test`" 128 "Test using `cargo test`"
108 (interactive) 129 (interactive)
109 (rust--compile "%s test %s" rust-cargo-bin rust-cargo-default-arguments)) 130 (rust--compile nil "%s test %s" rust-cargo-bin rust-cargo-default-arguments))
110 131
111(defun rust-run-clippy () 132(defun rust-run-clippy ()
112 "Run `cargo clippy'." 133 "Run `cargo clippy'."
@@ -118,7 +139,7 @@
118 ;; set `compile-command' temporarily so `compile' doesn't 139 ;; set `compile-command' temporarily so `compile' doesn't
119 ;; clobber the existing value 140 ;; clobber the existing value
120 (compile-command (mapconcat #'shell-quote-argument args " "))) 141 (compile-command (mapconcat #'shell-quote-argument args " ")))
121 (rust--compile compile-command))) 142 (rust--compile nil compile-command)))
122 143
123;;; _ 144;;; _
124(provide 'rust-cargo) 145(provide 'rust-cargo)
diff --git a/.emacs.d/lisp/rust-mode-treesitter.el b/.emacs.d/lisp/rust-mode-treesitter.el
index 89c7cd4..5f84a00 100644
--- a/.emacs.d/lisp/rust-mode-treesitter.el
+++ b/.emacs.d/lisp/rust-mode-treesitter.el
@@ -5,12 +5,19 @@
5 5
6;;; Code: 6;;; Code:
7 7
8(require 'rust-mode)
9
10;; Do not compile or load on Emacs releases that don't support
11;; this. See https://github.com/rust-lang/rust-mode/issues/520.
8(when (version<= "29.1" emacs-version) 12(when (version<= "29.1" emacs-version)
9 ;; We have the when macro because of
10 ;; https://github.com/rust-lang/rust-mode/issues/520
11 (require 'treesit) 13 (require 'treesit)
12 (require 'rust-ts-mode) 14 (require 'rust-ts-mode)
13 (require 'rust-common) 15
16 ;; HACK: `rust-ts-mode' adds itself to the `auto-mode-alist'
17 ;; after us, so we need to readd `rust-mode' to the front of
18 ;; the list after loading `rust-ts-mode'.
19 (setq auto-mode-alist (delete '("\\.rs\\'" . rust-mode) auto-mode-alist))
20 (add-to-list 'auto-mode-alist '("\\.rs\\'" . rust-mode))
14 21
15 (define-derived-mode rust-mode rust-ts-mode "Rust" 22 (define-derived-mode rust-mode rust-ts-mode "Rust"
16 "Major mode for Rust code. 23 "Major mode for Rust code.
diff --git a/.emacs.d/lisp/rust-mode.el b/.emacs.d/lisp/rust-mode.el
index a0f6542..8d38295 100644
--- a/.emacs.d/lisp/rust-mode.el
+++ b/.emacs.d/lisp/rust-mode.el
@@ -71,10 +71,6 @@ instead of `prog-mode'. This option requires emacs29+."
71 map) 71 map)
72 "Keymap for Rust major mode.") 72 "Keymap for Rust major mode.")
73 73
74(if (and (version<= "29.1" emacs-version) rust-mode-treesitter-derive)
75 (require 'rust-mode-treesitter)
76 (require 'rust-prog-mode))
77
78;;;###autoload 74;;;###autoload
79(autoload 'rust-mode "rust-mode" "Major mode for Rust code." t) 75(autoload 'rust-mode "rust-mode" "Major mode for Rust code." t)
80 76
@@ -82,6 +78,12 @@ instead of `prog-mode'. This option requires emacs29+."
82(add-to-list 'auto-mode-alist '("\\.rs\\'" . rust-mode)) 78(add-to-list 'auto-mode-alist '("\\.rs\\'" . rust-mode))
83 79
84(provide 'rust-mode) 80(provide 'rust-mode)
81
82(if (and rust-mode-treesitter-derive
83 (version<= "29.1" emacs-version))
84 (require 'rust-mode-treesitter)
85 (require 'rust-prog-mode))
86
85(require 'rust-utils) 87(require 'rust-utils)
86 88
87;;; rust-mode.el ends here 89;;; rust-mode.el ends here
diff --git a/.emacs.d/lisp/rust-prog-mode.el b/.emacs.d/lisp/rust-prog-mode.el
index 51e802d..05bc5e0 100644
--- a/.emacs.d/lisp/rust-prog-mode.el
+++ b/.emacs.d/lisp/rust-prog-mode.el
@@ -4,7 +4,8 @@
4;; rust-mode code deriving from prog-mode instead of rust-ts-mode 4;; rust-mode code deriving from prog-mode instead of rust-ts-mode
5 5
6;;; Code: 6;;; Code:
7(require 'rust-common) 7
8(require 'rust-mode)
8 9
9(defvar electric-pair-inhibit-predicate) 10(defvar electric-pair-inhibit-predicate)
10(defvar electric-pair-skip-self) 11(defvar electric-pair-skip-self)
diff --git a/.emacs.d/lisp/rust-rustfmt.el b/.emacs.d/lisp/rust-rustfmt.el
index f609980..cab183c 100644
--- a/.emacs.d/lisp/rust-rustfmt.el
+++ b/.emacs.d/lisp/rust-rustfmt.el
@@ -87,8 +87,8 @@
87 (insert-file-contents tmpf) 87 (insert-file-contents tmpf)
88 (rust--format-fix-rustfmt-buffer (buffer-name buf)) 88 (rust--format-fix-rustfmt-buffer (buffer-name buf))
89 (error "Rustfmt failed, see %s buffer for details" 89 (error "Rustfmt failed, see %s buffer for details"
90 rust-rustfmt-buffername)))) 90 rust-rustfmt-buffername)))
91 (delete-file tmpf)))))) 91 (delete-file tmpf)))))))
92 92
93;; Since we run rustfmt through stdin we get <stdin> markers in the 93;; Since we run rustfmt through stdin we get <stdin> markers in the
94;; output. This replaces them with the buffer name instead. 94;; output. This replaces them with the buffer name instead.
diff --git a/.emacs.d/lisp/yaml-mode.el b/.emacs.d/lisp/yaml-mode.el
index 9706f6b..c748b6c 100644
--- a/.emacs.d/lisp/yaml-mode.el
+++ b/.emacs.d/lisp/yaml-mode.el
@@ -103,7 +103,7 @@ that key is pressed to begin a block literal."
103 103
104(defface yaml-tab-face 104(defface yaml-tab-face
105 '((((class color)) (:background "red" :foreground "red" :bold t)) 105 '((((class color)) (:background "red" :foreground "red" :bold t))
106 (t (:reverse-video t))) 106 (t (:inverse-video t)))
107 "Face to use for highlighting tabs in YAML files." 107 "Face to use for highlighting tabs in YAML files."
108 :group 'faces 108 :group 'faces
109 :group 'yaml) 109 :group 'yaml)
diff --git a/.emacs.d/snippets/python-mode.statnett/property_getter b/.emacs.d/snippets/python-mode.statnett/property_getter
index 408428a..3e528dd 100644
--- a/.emacs.d/snippets/python-mode.statnett/property_getter
+++ b/.emacs.d/snippets/python-mode.statnett/property_getter
@@ -6,5 +6,5 @@
6@property 6@property
7def ${1:name}(self): 7def ${1:name}(self):
8 """$1-property""" 8 """$1-property"""
9 return self.${2:value} 9 return self._${1}
10$0 \ No newline at end of file 10$0 \ No newline at end of file
diff --git a/.emacs.d/snippets/python-mode.statnett/property_setter b/.emacs.d/snippets/python-mode.statnett/property_setter
index aa0288d..d117200 100644
--- a/.emacs.d/snippets/python-mode.statnett/property_setter
+++ b/.emacs.d/snippets/python-mode.statnett/property_setter
@@ -6,10 +6,10 @@
6@property 6@property
7def ${1:name}(self): 7def ${1:name}(self):
8 """$1-property""" 8 """$1-property"""
9 return self.${2:value} 9 return self._${1}
10 10
11@$1.setter 11@$1.setter
12def $1(self, value): 12def $1(self, value):
13 """$1-property setter""" 13 """$1-property setter"""
14 self.$2 = value 14 self._$1 = value
15$0 \ No newline at end of file 15$0 \ No newline at end of file
diff --git a/.emacs.d/snippets/python-mode/property_getter b/.emacs.d/snippets/python-mode/property_getter
index 408428a..3e528dd 100644
--- a/.emacs.d/snippets/python-mode/property_getter
+++ b/.emacs.d/snippets/python-mode/property_getter
@@ -6,5 +6,5 @@
6@property 6@property
7def ${1:name}(self): 7def ${1:name}(self):
8 """$1-property""" 8 """$1-property"""
9 return self.${2:value} 9 return self._${1}
10$0 \ No newline at end of file 10$0 \ No newline at end of file
diff --git a/.emacs.d/snippets/python-mode/property_setter b/.emacs.d/snippets/python-mode/property_setter
index aa0288d..d117200 100644
--- a/.emacs.d/snippets/python-mode/property_setter
+++ b/.emacs.d/snippets/python-mode/property_setter
@@ -6,10 +6,10 @@
6@property 6@property
7def ${1:name}(self): 7def ${1:name}(self):
8 """$1-property""" 8 """$1-property"""
9 return self.${2:value} 9 return self._${1}
10 10
11@$1.setter 11@$1.setter
12def $1(self, value): 12def $1(self, value):
13 """$1-property setter""" 13 """$1-property setter"""
14 self.$2 = value 14 self._$1 = value
15$0 \ No newline at end of file 15$0 \ No newline at end of file