aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2018-11-02 12:07:12 -0400
committerStefan Monnier2018-11-02 12:07:12 -0400
commitdc7b10e9c452f56a79eb83cd5347e7436fa77e1f (patch)
treef73aadfad5a24e41a0ec5de2412515130bee7fac
parent5b218be0c362316384f5c9ef57a3bef02f742e94 (diff)
downloademacs-dc7b10e9c452f56a79eb83cd5347e7436fa77e1f.tar.gz
emacs-dc7b10e9c452f56a79eb83cd5347e7436fa77e1f.zip
* lisp/progmodes/ruby-mode.el: Cosmetic changes
Remove redundant :groups. (ruby-font-lock-syntax-table): Delete var. (ruby-mode): Use font-lock-default's syntax-alist instead.
-rw-r--r--lisp/progmodes/ruby-mode.el57
1 files changed, 19 insertions, 38 deletions
diff --git a/lisp/progmodes/ruby-mode.el b/lisp/progmodes/ruby-mode.el
index 32130cee8e1..9256dfc17b5 100644
--- a/lisp/progmodes/ruby-mode.el
+++ b/lisp/progmodes/ruby-mode.el
@@ -217,19 +217,16 @@ This should only be called after matching against `ruby-here-doc-beg-re'."
217(defcustom ruby-indent-tabs-mode nil 217(defcustom ruby-indent-tabs-mode nil
218 "Indentation can insert tabs in Ruby mode if this is non-nil." 218 "Indentation can insert tabs in Ruby mode if this is non-nil."
219 :type 'boolean 219 :type 'boolean
220 :group 'ruby
221 :safe 'booleanp) 220 :safe 'booleanp)
222 221
223(defcustom ruby-indent-level 2 222(defcustom ruby-indent-level 2
224 "Indentation of Ruby statements." 223 "Indentation of Ruby statements."
225 :type 'integer 224 :type 'integer
226 :group 'ruby
227 :safe 'integerp) 225 :safe 'integerp)
228 226
229(defcustom ruby-comment-column (default-value 'comment-column) 227(defcustom ruby-comment-column (default-value 'comment-column)
230 "Indentation column of comments." 228 "Indentation column of comments."
231 :type 'integer 229 :type 'integer
232 :group 'ruby
233 :safe 'integerp) 230 :safe 'integerp)
234 231
235(defconst ruby-alignable-keywords '(if while unless until begin case for def) 232(defconst ruby-alignable-keywords '(if while unless until begin case for def)
@@ -265,7 +262,6 @@ Only has effect when `ruby-use-smie' is t."
265 (choice ,@(mapcar 262 (choice ,@(mapcar
266 (lambda (kw) (list 'const kw)) 263 (lambda (kw) (list 'const kw))
267 ruby-alignable-keywords)))) 264 ruby-alignable-keywords))))
268 :group 'ruby
269 :safe 'listp 265 :safe 'listp
270 :version "24.4") 266 :version "24.4")
271 267
@@ -277,7 +273,6 @@ of its parent.
277 273
278Only has effect when `ruby-use-smie' is t." 274Only has effect when `ruby-use-smie' is t."
279 :type 'boolean 275 :type 'boolean
280 :group 'ruby
281 :safe 'booleanp 276 :safe 'booleanp
282 :version "24.4") 277 :version "24.4")
283 278
@@ -286,7 +281,6 @@ Only has effect when `ruby-use-smie' is t."
286Also ignores spaces after parenthesis when `space'. 281Also ignores spaces after parenthesis when `space'.
287Only has effect when `ruby-use-smie' is nil." 282Only has effect when `ruby-use-smie' is nil."
288 :type 'boolean 283 :type 'boolean
289 :group 'ruby
290 :safe 'booleanp) 284 :safe 'booleanp)
291 285
292;; FIXME Woefully under documented. What is the point of the last t?. 286;; FIXME Woefully under documented. What is the point of the last t?.
@@ -301,14 +295,12 @@ Only has effect when `ruby-use-smie' is nil."
301 (cons character (choice (const nil) 295 (cons character (choice (const nil)
302 (const t))) 296 (const t)))
303 (const t) ; why? 297 (const t) ; why?
304 ))) 298 ))))
305 :group 'ruby)
306 299
307(defcustom ruby-deep-indent-paren-style 'space 300(defcustom ruby-deep-indent-paren-style 'space
308 "Default deep indent style. 301 "Default deep indent style.
309Only has effect when `ruby-use-smie' is nil." 302Only has effect when `ruby-use-smie' is nil."
310 :type '(choice (const t) (const nil) (const space)) 303 :type '(choice (const t) (const nil) (const space)))
311 :group 'ruby)
312 304
313(defcustom ruby-encoding-map 305(defcustom ruby-encoding-map
314 '((us-ascii . nil) ;; Do not put coding: us-ascii 306 '((us-ascii . nil) ;; Do not put coding: us-ascii
@@ -318,8 +310,7 @@ Only has effect when `ruby-use-smie' is nil."
318 "Alist to map encoding name from Emacs to Ruby. 310 "Alist to map encoding name from Emacs to Ruby.
319Associating an encoding name with nil means it needs not be 311Associating an encoding name with nil means it needs not be
320explicitly declared in magic comment." 312explicitly declared in magic comment."
321 :type '(repeat (cons (symbol :tag "From") (symbol :tag "To"))) 313 :type '(repeat (cons (symbol :tag "From") (symbol :tag "To"))))
322 :group 'ruby)
323 314
324(defcustom ruby-insert-encoding-magic-comment t 315(defcustom ruby-insert-encoding-magic-comment t
325 "Insert a magic Ruby encoding comment upon save if this is non-nil. 316 "Insert a magic Ruby encoding comment upon save if this is non-nil.
@@ -336,14 +327,12 @@ even if it's not required."
336 (const :tag "Emacs Style" emacs) 327 (const :tag "Emacs Style" emacs)
337 (const :tag "Ruby Style" ruby) 328 (const :tag "Ruby Style" ruby)
338 (const :tag "Custom Style" custom)) 329 (const :tag "Custom Style" custom))
339 :group 'ruby
340 :version "24.4") 330 :version "24.4")
341 331
342(defcustom ruby-custom-encoding-magic-comment-template "# encoding: %s" 332(defcustom ruby-custom-encoding-magic-comment-template "# encoding: %s"
343 "A custom encoding comment template. 333 "A custom encoding comment template.
344It is used when `ruby-encoding-magic-comment-style' is set to `custom'." 334It is used when `ruby-encoding-magic-comment-style' is set to `custom'."
345 :type 'string 335 :type 'string
346 :group 'ruby
347 :version "24.4") 336 :version "24.4")
348 337
349(defcustom ruby-use-encoding-map t 338(defcustom ruby-use-encoding-map t
@@ -741,7 +730,7 @@ It is used when `ruby-encoding-magic-comment-style' is set to `custom'."
741 (back-to-indentation) 730 (back-to-indentation)
742 (narrow-to-region (point) end) 731 (narrow-to-region (point) end)
743 (smie-forward-sexp)) 732 (smie-forward-sexp))
744 (while (and (setq state (apply 'ruby-parse-partial end state)) 733 (while (and (setq state (apply #'ruby-parse-partial end state))
745 (>= (nth 2 state) 0) (< (point) end)))))) 734 (>= (nth 2 state) 0) (< (point) end))))))
746 735
747(defun ruby-mode-variables () 736(defun ruby-mode-variables ()
@@ -751,7 +740,7 @@ It is used when `ruby-encoding-magic-comment-style' is set to `custom'."
751 (smie-setup ruby-smie-grammar #'ruby-smie-rules 740 (smie-setup ruby-smie-grammar #'ruby-smie-rules
752 :forward-token #'ruby-smie--forward-token 741 :forward-token #'ruby-smie--forward-token
753 :backward-token #'ruby-smie--backward-token) 742 :backward-token #'ruby-smie--backward-token)
754 (setq-local indent-line-function 'ruby-indent-line)) 743 (setq-local indent-line-function #'ruby-indent-line))
755 (setq-local comment-start "# ") 744 (setq-local comment-start "# ")
756 (setq-local comment-end "") 745 (setq-local comment-end "")
757 (setq-local comment-column ruby-comment-column) 746 (setq-local comment-column ruby-comment-column)
@@ -986,6 +975,7 @@ delimiter."
986 ((eq c ?\( ) ruby-deep-arglist))) 975 ((eq c ?\( ) ruby-deep-arglist)))
987 976
988(defun ruby-parse-partial (&optional end in-string nest depth pcol indent) 977(defun ruby-parse-partial (&optional end in-string nest depth pcol indent)
978 ;; FIXME: Document why we can't just use parse-partial-sexp.
989 "TODO: document throughout function body." 979 "TODO: document throughout function body."
990 (or depth (setq depth 0)) 980 (or depth (setq depth 0))
991 (or indent (setq indent 0)) 981 (or indent (setq indent 0))
@@ -1160,7 +1150,7 @@ delimiter."
1160 (state (list in-string nest depth pcol indent))) 1150 (state (list in-string nest depth pcol indent)))
1161 ;; parse the rest of the line 1151 ;; parse the rest of the line
1162 (while (and (> line-end-position (point)) 1152 (while (and (> line-end-position (point))
1163 (setq state (apply 'ruby-parse-partial 1153 (setq state (apply #'ruby-parse-partial
1164 line-end-position state)))) 1154 line-end-position state))))
1165 (setq in-string (car state) 1155 (setq in-string (car state)
1166 nest (nth 1 state) 1156 nest (nth 1 state)
@@ -1197,7 +1187,7 @@ delimiter."
1197 (save-restriction 1187 (save-restriction
1198 (narrow-to-region (point) end) 1188 (narrow-to-region (point) end)
1199 (while (and (> end (point)) 1189 (while (and (> end (point))
1200 (setq state (apply 'ruby-parse-partial end state)))))) 1190 (setq state (apply #'ruby-parse-partial end state))))))
1201 (list (nth 0 state) ; in-string 1191 (list (nth 0 state) ; in-string
1202 (car (nth 1 state)) ; nest 1192 (car (nth 1 state)) ; nest
1203 (nth 2 state) ; depth 1193 (nth 2 state) ; depth
@@ -2034,13 +2024,6 @@ It will be properly highlighted even when the call omits parens.")
2034 context))) 2024 context)))
2035 t))) 2025 t)))
2036 2026
2037(defvar ruby-font-lock-syntax-table
2038 (let ((tbl (make-syntax-table ruby-mode-syntax-table)))
2039 (modify-syntax-entry ?_ "w" tbl)
2040 tbl)
2041 "The syntax table to use for fontifying Ruby mode buffers.
2042See `font-lock-syntax-table'.")
2043
2044(defconst ruby-font-lock-keyword-beg-re "\\(?:^\\|[^.@$:]\\|\\.\\.\\)") 2027(defconst ruby-font-lock-keyword-beg-re "\\(?:^\\|[^.@$:]\\|\\.\\.\\)")
2045 2028
2046(defconst ruby-font-lock-keywords 2029(defconst ruby-font-lock-keywords
@@ -2219,7 +2202,8 @@ See `font-lock-syntax-table'.")
2219 ;; Conversion methods on Kernel. 2202 ;; Conversion methods on Kernel.
2220 (,(concat ruby-font-lock-keyword-beg-re 2203 (,(concat ruby-font-lock-keyword-beg-re
2221 (regexp-opt '("Array" "Complex" "Float" "Hash" 2204 (regexp-opt '("Array" "Complex" "Float" "Hash"
2222 "Integer" "Rational" "String") 'symbols)) 2205 "Integer" "Rational" "String")
2206 'symbols))
2223 (1 font-lock-builtin-face)) 2207 (1 font-lock-builtin-face))
2224 ;; Expression expansion. 2208 ;; Expression expansion.
2225 (ruby-match-expression-expansion 2209 (ruby-match-expression-expansion
@@ -2316,14 +2300,12 @@ See `font-lock-syntax-table'.")
2316Only takes effect if RuboCop is installed." 2300Only takes effect if RuboCop is installed."
2317 :version "26.1" 2301 :version "26.1"
2318 :type 'boolean 2302 :type 'boolean
2319 :group 'ruby
2320 :safe 'booleanp) 2303 :safe 'booleanp)
2321 2304
2322(defcustom ruby-rubocop-config ".rubocop.yml" 2305(defcustom ruby-rubocop-config ".rubocop.yml"
2323 "Configuration file for `ruby-flymake-rubocop'." 2306 "Configuration file for `ruby-flymake-rubocop'."
2324 :version "26.1" 2307 :version "26.1"
2325 :type 'string 2308 :type 'string
2326 :group 'ruby
2327 :safe 'stringp) 2309 :safe 'stringp)
2328 2310
2329(defun ruby-flymake-rubocop (report-fn &rest _args) 2311(defun ruby-flymake-rubocop (report-fn &rest _args)
@@ -2393,18 +2375,17 @@ Only takes effect if RuboCop is installed."
2393 "Major mode for editing Ruby code." 2375 "Major mode for editing Ruby code."
2394 (ruby-mode-variables) 2376 (ruby-mode-variables)
2395 2377
2396 (setq-local imenu-create-index-function 'ruby-imenu-create-index) 2378 (setq-local imenu-create-index-function #'ruby-imenu-create-index)
2397 (setq-local add-log-current-defun-function 'ruby-add-log-current-method) 2379 (setq-local add-log-current-defun-function #'ruby-add-log-current-method)
2398 (setq-local beginning-of-defun-function 'ruby-beginning-of-defun) 2380 (setq-local beginning-of-defun-function #'ruby-beginning-of-defun)
2399 (setq-local end-of-defun-function 'ruby-end-of-defun) 2381 (setq-local end-of-defun-function #'ruby-end-of-defun)
2400 2382
2401 (add-hook 'after-save-hook 'ruby-mode-set-encoding nil 'local) 2383 (add-hook 'after-save-hook #'ruby-mode-set-encoding nil 'local)
2402 (add-hook 'electric-indent-functions 'ruby--electric-indent-p nil 'local) 2384 (add-hook 'electric-indent-functions #'ruby--electric-indent-p nil 'local)
2403 (add-hook 'flymake-diagnostic-functions 'ruby-flymake-auto nil 'local) 2385 (add-hook 'flymake-diagnostic-functions #'ruby-flymake-auto nil 'local)
2404 2386
2405 (setq-local font-lock-defaults '((ruby-font-lock-keywords) nil nil)) 2387 (setq-local font-lock-defaults '((ruby-font-lock-keywords) nil nil
2406 (setq-local font-lock-keywords ruby-font-lock-keywords) 2388 ((?_ . "w"))))
2407 (setq-local font-lock-syntax-table ruby-font-lock-syntax-table)
2408 2389
2409 (setq-local syntax-propertize-function #'ruby-syntax-propertize)) 2390 (setq-local syntax-propertize-function #'ruby-syntax-propertize))
2410 2391