55
55
" \\ _>" ))
56
56
57
57
(defun rust-looking-back-str (str )
58
- " Like `looking-back' but for fixed strings rather than regexps (so that it's not so slow)"
58
+ " Return non-nil if there's a match on the text before point and STR.
59
+ Like `looking-back' but for fixed strings rather than regexps (so that it's not so slow)."
59
60
(let ((len (length str)))
60
61
(and (> (point ) len)
61
62
(equal str (buffer-substring-no-properties (- (point ) len) (point ))))))
62
63
63
64
(defun rust-looking-back-symbols (SYMS )
64
- " Return non-nil if the point is just after a complete symbol that is a member of the list of strings SYMS"
65
+ " Return non-nil if the point is just after a complete symbol that is a member of the list of strings SYMS. "
65
66
(save-excursion
66
67
(let* ((pt-orig (point ))
67
68
(beg-of-symbol (progn (forward-thing 'symbol -1 ) (point )))
71
72
(member (buffer-substring-no-properties beg-of-symbol pt-orig) SYMS)))))
72
73
73
74
(defun rust-looking-back-ident ()
74
- " Non-nil if we are looking backwards at a valid rust identifier"
75
+ " Non-nil if we are looking backwards at a valid rust identifier. "
75
76
(let ((beg-of-symbol (save-excursion (forward-thing 'symbol -1 ) (point ))))
76
77
(looking-back rust-re-ident beg-of-symbol)))
77
78
116
117
:safe #'integerp )
117
118
118
119
(defcustom rust-indent-method-chain nil
119
- " Indent Rust method chains, aligned by the ' .' operators"
120
+ " Indent Rust method chains, aligned by the ` .' operators. "
120
121
:type 'boolean
121
122
:group 'rust-mode
122
123
:safe #'booleanp )
123
124
124
125
(defcustom rust-indent-where-clause nil
125
- " Indent the line starting with the where keyword following a
126
- function or trait. When nil, where will be aligned with fn or trait."
126
+ " Indent lines starting with the ` where' keyword following a function or trait.
127
+ When nil, ` where' will be aligned with `fn' or ` trait' ."
127
128
:type 'boolean
128
129
:group 'rust-mode
129
130
:safe #'booleanp )
130
131
131
132
(defcustom rust-playpen-url-format " https://play.rust-lang.org/?code=%s"
132
- " Format string to use when submitting code to the playpen"
133
+ " Format string to use when submitting code to the playpen. "
133
134
:type 'string
134
135
:group 'rust-mode )
135
136
(defcustom rust-shortener-url-format " https://is.gd/create.php?format=simple&url=%s"
136
- " Format string to use for creating the shortened link of a playpen submission"
137
+ " Format string to use for creating the shortened link of a playpen submission. "
137
138
:type 'string
138
139
:group 'rust-mode )
139
140
140
141
(defcustom rust-match-angle-brackets t
141
- " Enable angle bracket matching. Attempt to match `<' and `>' where
142
- appropriate."
142
+ " Whether to attempt angle bracket matching (`<' and `>' ) where appropriate."
143
143
:type 'boolean
144
144
:safe #'booleanp
145
145
:group 'rust-mode )
@@ -161,8 +161,7 @@ function or trait. When nil, where will be aligned with fn or trait."
161
161
:group 'rust-mode )
162
162
163
163
(defcustom rust-always-locate-project-on-open nil
164
- " Whether to run `cargo locate-project' every time `rust-mode'
165
- is activated."
164
+ " Whether to run `cargo locate-project' every time `rust-mode' is activated."
166
165
:type 'boolean
167
166
:group 'rust-mode )
168
167
@@ -351,7 +350,7 @@ buffer."
351
350
(rust-rewind-to-beginning-of-current-level-expr)
352
351
(+ (current-column ) rust-indent-offset))))))
353
352
(cond
354
- ; ; Indent inside a non-raw string only if the the previous line
353
+ ; ; Indent inside a non-raw string only if the previous line
355
354
; ; ends with a backslash that is inside the same string
356
355
((nth 3 (syntax-ppss ))
357
356
(let*
@@ -576,8 +575,9 @@ buffer."
576
575
577
576
578
577
(defun rust-path-font-lock-matcher (re-ident )
579
- " Matches names like \" foo::\" or \" Foo::\" (depending on RE-IDENT, which should match
580
- the desired identifiers), but does not match type annotations \" foo::<\" ."
578
+ " Match occurrences of RE-IDENT followed by a double-colon.
579
+ Examples include to match names like \" foo::\" or \" Foo::\" .
580
+ Does not match type annotations of the form \" foo::<\" ."
581
581
`(lambda (limit)
582
582
(catch 'rust-path-font-lock-matcher
583
583
(while t
@@ -593,8 +593,7 @@ the desired identifiers), but does not match type annotations \"foo::<\"."
593
593
(throw 'rust-path-font-lock-matcher match ))))))))
594
594
595
595
(defun rust-next-string-interpolation (limit )
596
- " Search forward from point for next Rust interpolation marker
597
- before LIMIT.
596
+ " Search forward from point for the next Rust interpolation marker before LIMIT.
598
597
Set point to the end of the occurrence found, and return match beginning
599
598
and end."
600
599
(catch 'match
@@ -615,8 +614,8 @@ and end."
615
614
(throw 'match (list start (point )))))))))))
616
615
617
616
(defun rust-string-interpolation-matcher (limit )
618
- " Match next Rust interpolation marker before LIMIT and set
619
- match data if found. Returns nil if not within a Rust string."
617
+ " Match the next Rust interpolation marker before LIMIT; set match data if found.
618
+ Returns nil if the point is not within a Rust string."
620
619
(when (rust-in-str)
621
620
(let ((match (rust-next-string-interpolation limit)))
622
621
(when match
@@ -630,7 +629,7 @@ match data if found. Returns nil if not within a Rust string."
630
629
" format"
631
630
" print"
632
631
" println" )
633
- " List of builtin Rust macros for string formatting used by `rust-mode-font-lock-keywords' . (`write!' is handled separately.) " )
632
+ " List of builtin Rust macros for string formatting used by `rust-mode-font-lock-keywords' (`write!' is handled separately). " )
634
633
635
634
(defvar rust-formatting-macro-opening-re
636
635
" [[:space:]\n ]*[({[][[:space:]\n ]*"
@@ -751,10 +750,11 @@ match data if found. Returns nil if not within a Rust string."
751
750
(goto-char dest))))))
752
751
753
752
(defun rust-rewind-to-decl-name ()
754
- " If we are before an ident that is part of a declaration that
755
- can have a where clause, rewind back to just before the name of
756
- the subject of that where clause and return the new point.
757
- Otherwise return nil"
753
+ " Return the point at the beginning of the name in a declaration.
754
+ I.e. if we are before an ident that is part of a declaration that
755
+ can have a where clause, rewind back to just before the name of
756
+ the subject of that where clause and return the new point.
757
+ Otherwise return nil."
758
758
759
759
(let* ((ident-pos (point ))
760
760
(newpos (save-excursion
@@ -783,13 +783,13 @@ match data if found. Returns nil if not within a Rust string."
783
783
784
784
(defun rust-is-in-expression-context (token )
785
785
" Return t if what comes right after the point is part of an
786
- expression (as opposed to starting a type) by looking at what
787
- comes before. Takes a symbol that roughly indicates what is
788
- after the point.
786
+ expression (as opposed to starting a type) by looking at what
787
+ comes before. Takes a symbol that roughly indicates what is
788
+ after the point.
789
789
790
- This function is used as part of `rust-is-lt-char-operator' as
791
- part of angle bracket matching, and is not intended to be used
792
- outside of this context."
790
+ This function is used as part of `rust-is-lt-char-operator' as
791
+ part of angle bracket matching, and is not intended to be used
792
+ outside of this context."
793
793
794
794
(save-excursion
795
795
(let ((postchar (char-after )))
@@ -970,8 +970,8 @@ match data if found. Returns nil if not within a Rust string."
970
970
))))
971
971
972
972
(defun rust-is-lt-char-operator ()
973
- " Return t if the < sign just after point is an operator rather
974
- than an opening angle bracket, otherwise nil."
973
+ " Return t if the `<' after the point is the less-than operator.
974
+ Otherwise, for instance if it's an opening angle bracket, return nil."
975
975
976
976
(let ((case-fold-search nil ))
977
977
(save-excursion
@@ -1019,9 +1019,8 @@ match data if found. Returns nil if not within a Rust string."
1019
1019
))))
1020
1020
1021
1021
(defun rust-electric-pair-inhibit-predicate-wrap (char )
1022
- " Wraps the default `electric-pair-inhibit-predicate' to prevent
1023
- inserting a \" matching\" > after a < that would be treated as a
1024
- less than sign rather than as an opening angle bracket."
1022
+ " Prevent \" matching\" with a `>' when CHAR is the less-than operator.
1023
+ This wraps the default defined by `electric-pair-inhibit-predicate' ."
1025
1024
(or
1026
1025
(when (= ?< char)
1027
1026
(save-excursion
@@ -1067,7 +1066,7 @@ should be considered a paired angle bracket."
1067
1066
(not (looking-at " <" ))))))))
1068
1067
1069
1068
(defun rust-mode-syntactic-face-function (state )
1070
- " Syntactic face function to distinguish doc comments from other comments ."
1069
+ " Return face which distinguishes doc and normal comments in the given syntax STATE ."
1071
1070
(if (nth 3 state) 'font-lock-string-face
1072
1071
(save-excursion
1073
1072
(goto-char (nth 8 state))
@@ -1097,7 +1096,7 @@ should be considered a paired angle bracket."
1097
1096
1098
1097
If point is already in a raw string, this will apply the
1099
1098
appropriate string syntax to the character up to the end of the
1100
- raw string, or to `end' , whichever comes first."
1099
+ raw string, or to END , whichever comes first."
1101
1100
(let ((str-start (nth 8 (syntax-ppss ))))
1102
1101
(when str-start
1103
1102
(when (save-excursion
@@ -1115,7 +1114,7 @@ raw string, or to `end', whichever comes first."
1115
1114
(goto-char (match-end 0 ))))))))
1116
1115
1117
1116
(defun rust-syntax-propertize (start end )
1118
- " A `syntax-propertize-function' for `rust-mode' ."
1117
+ " A `syntax-propertize-function' to apply properties from START to END ."
1119
1118
(goto-char start)
1120
1119
(rust--syntax-propertize-raw-string end)
1121
1120
(funcall
@@ -1139,7 +1138,7 @@ raw string, or to `end', whichever comes first."
1139
1138
(point ) end))
1140
1139
1141
1140
(defun rust-fill-prefix-for-comment-start (line-start )
1142
- " Determine what to use for `fill-prefix' based on what is at the beginning of a line ."
1141
+ " Determine what to use for `fill-prefix' based on the text at LINE-START ."
1143
1142
(let ((result
1144
1143
; ; Replace /* with same number of spaces
1145
1144
(replace-regexp-in-string
@@ -1304,7 +1303,7 @@ which calls this, does that afterwards."
1304
1303
With argument, do it that many times.
1305
1304
Negative argument -N means move back to Nth preceding end of defun.
1306
1305
1307
- Assume that this is called after beginning-of-defun. So point is
1306
+ Assume that this is called after ` beginning-of-defun' . So point is
1308
1307
at the beginning of the defun body.
1309
1308
1310
1309
This is written mainly to be used as `end-of-defun-function' for Rust."
@@ -1612,10 +1611,10 @@ See `compilation-error-regexp-alist' for help on their format.")
1612
1611
1613
1612
(defun rustc-scroll-down-after-next-error ()
1614
1613
" In the new style error messages, the regular expression
1615
- matches on the file name (which appears after `-->`), but the
1616
- start of the error appears a few lines earlier. This hook runs
1617
- after `M-x next-error` ; it simply scrolls down a few lines in
1618
- the compilation window until the top of the error is visible."
1614
+ matches on the file name (which appears after `-->`), but the
1615
+ start of the error appears a few lines earlier. This hook runs
1616
+ after `next-error' ( \\ [ next-error]) ; it simply scrolls down a few lines in
1617
+ the compilation window until the top of the error is visible."
1619
1618
(save-selected-window
1620
1619
(when (eq major-mode 'rust-mode )
1621
1620
(select-window (get-buffer-window next-error-last-buffer 'visible ))
@@ -1646,8 +1645,7 @@ See `compilation-error-regexp-alist' for help on their format.")
1646
1645
; ;; Functions to submit (parts of) buffers to the rust playpen, for
1647
1646
; ;; sharing.
1648
1647
(defun rust-playpen-region (begin end )
1649
- " Create a sharable URL for the contents of the current region
1650
- on the Rust playpen."
1648
+ " Create a shareable URL for the region from BEGIN to END on the Rust playpen."
1651
1649
(interactive " r" )
1652
1650
(let* ((data (buffer-substring begin end))
1653
1651
(escaped-data (url-hexify-string data))
@@ -1672,8 +1670,7 @@ See `compilation-error-regexp-alist' for help on their format.")
1672
1670
(message " %s " last-line)))))))))
1673
1671
1674
1672
(defun rust-playpen-buffer ()
1675
- " Create a sharable URL for the contents of the current buffer
1676
- on the Rust playpen."
1673
+ " Create a shareable URL for the contents of the buffer on the Rust playpen."
1677
1674
(interactive )
1678
1675
(rust-playpen-region (point-min ) (point-max )))
1679
1676
0 commit comments