@@ -1153,12 +1153,97 @@ Also handles C++ lambda capture by reference."
1153
1153
1154
1154
1155
1155
1156
- ; ;; Other major mode tweaks
1156
+ ; ;; Ruby mode
1157
+
1158
+ (defun electric-operator-ruby-mode- | ()
1159
+ (cond
1160
+ ; ; Start of block params
1161
+ ; ; arr.map { |a| a }
1162
+ ; ; ^^
1163
+ ; ; arr.map do |a| a end
1164
+ ; ; ^^
1165
+ ((electric-operator-looking-back-locally (rx (or " do" " {" ) (* whitespace)))
1166
+ " |" )
1167
+ ; ; End of block params
1168
+ ; ; arr.map { |a| a }
1169
+ ; ; ^^
1170
+ ; ; arr.map do |a| a end
1171
+ ; ; ^^
1172
+ ((electric-operator-looking-back-locally (rx (or " do" " {" ) (* whitespace) " |" (* (not (any " |" " \n " )))))
1173
+ " | " )
1174
+ ; ; Regular operator
1175
+ ; ; 3 | 4
1176
+ ; ; ^^^
1177
+ (t
1178
+ " | " )))
1179
+ (defun electric-operator-ruby-mode-* ()
1180
+ (cond
1181
+ ; ; splat
1182
+ ((electric-operator-probably-unary-operator?) nil )
1183
+ ((electric-operator-just-inside-bracket) " *" )
1184
+ ; ; binary operator
1185
+ (t " * " )))
1186
+ (defun electric-operator-ruby-mode-** ()
1187
+ (cond
1188
+ ; ; keyword argument splat
1189
+ ((electric-operator-probably-unary-operator?) nil )
1190
+ ((electric-operator-just-inside-bracket) " **" )
1191
+ ; ; binary operator
1192
+ (t " ** " )))
1193
+ (defun electric-operator-ruby-mode-% ()
1194
+ (cond
1195
+ ; ; e.g. %w(a b c)
1196
+ ((electric-operator-probably-unary-operator?) nil )
1197
+ ((electric-operator-just-inside-bracket) " %" )
1198
+ ; ; binary operator
1199
+ (t " % " )))
1200
+ (defun electric-operator-ruby-mode-<<- ()
1201
+ ; ; heredoc
1202
+ (cond
1203
+ ((electric-operator-just-inside-bracket) " <<-" )
1204
+ (t " <<-" )))
1205
+ (defun electric-operator-ruby-mode-<<~ ()
1206
+ ; ; heredoc
1207
+ (cond
1208
+ ((electric-operator-just-inside-bracket) " <<~" )
1209
+ (t " <<~" )))
1157
1210
1158
1211
(apply #'electric-operator-add-rules-for-mode 'ruby-mode (electric-operator-get-rules-for-mode 'prog-mode ))
1159
1212
(electric-operator-add-rules-for-mode 'ruby-mode
1160
- (cons " =~" " =~ " ) ; regex equality
1161
- )
1213
+ (cons " |" #'electric-operator-ruby-mode- |)
1214
+ (cons " *" #'electric-operator-ruby-mode-* )
1215
+ (cons " **" #'electric-operator-ruby-mode-** )
1216
+ (cons " %" #'electric-operator-ruby-mode-% )
1217
+ (cons " <<-" #'electric-operator-ruby-mode-<<- )
1218
+ (cons " <<~" #'electric-operator-ruby-mode-<<~ )
1219
+ (cons " &" nil ) ; complicated by &. &: &block
1220
+ (cons " ?" nil ) ; can be boolean_method?() or ternary
1221
+ (cons " /" nil ) ; complicated by regexes
1222
+ (cons " =>" " => " ) ; in hashes
1223
+ (cons " ->(" " ->(" ) ; stabby lambda with arguments
1224
+ (cons " ->" " -> " ) ; stabby lambda (without arguments)
1225
+ (cons " ;" " ; " ) ; statement separator
1226
+ (cons " <<" " << " )
1227
+ (cons " >>" " >> " )
1228
+ (cons " ===" " === " ) ; case equality operator
1229
+ (cons " =~" " =~ " ) ; regex equality
1230
+ (cons " !~" " !~ " ) ; regex inequality
1231
+ (cons " <=>" " <=> " ) ; spaceship operator (comparison)
1232
+ (cons " **=" " **= " )
1233
+ (cons " %=" " %= " )
1234
+ (cons " <<=" " <<= " )
1235
+ (cons " >>=" " >>= " )
1236
+ (cons " &&=" " &&= " )
1237
+ (cons " &=" " &= " )
1238
+ (cons " ||=" " ||= " )
1239
+ (cons " |=" " |= " )
1240
+ (cons " ^=" " ^= " )
1241
+ )
1242
+
1243
+
1244
+
1245
+ ; ;; Other major mode tweaks
1246
+
1162
1247
1163
1248
; ; This is based on a syntax guide and hasn't been tested.
1164
1249
(apply #'electric-operator-add-rules-for-mode 'java-mode (electric-operator-get-rules-for-mode 'prog-mode ))
0 commit comments