1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-12 09:00:40 -08:00

* 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.
This commit is contained in:
Stefan Monnier 2018-11-02 12:07:12 -04:00
parent 5b218be0c3
commit dc7b10e9c4

View file

@ -217,19 +217,16 @@ This should only be called after matching against `ruby-here-doc-beg-re'."
(defcustom ruby-indent-tabs-mode nil (defcustom ruby-indent-tabs-mode nil
"Indentation can insert tabs in Ruby mode if this is non-nil." "Indentation can insert tabs in Ruby mode if this is non-nil."
:type 'boolean :type 'boolean
:group 'ruby
:safe 'booleanp) :safe 'booleanp)
(defcustom ruby-indent-level 2 (defcustom ruby-indent-level 2
"Indentation of Ruby statements." "Indentation of Ruby statements."
:type 'integer :type 'integer
:group 'ruby
:safe 'integerp) :safe 'integerp)
(defcustom ruby-comment-column (default-value 'comment-column) (defcustom ruby-comment-column (default-value 'comment-column)
"Indentation column of comments." "Indentation column of comments."
:type 'integer :type 'integer
:group 'ruby
:safe 'integerp) :safe 'integerp)
(defconst ruby-alignable-keywords '(if while unless until begin case for def) (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."
(choice ,@(mapcar (choice ,@(mapcar
(lambda (kw) (list 'const kw)) (lambda (kw) (list 'const kw))
ruby-alignable-keywords)))) ruby-alignable-keywords))))
:group 'ruby
:safe 'listp :safe 'listp
:version "24.4") :version "24.4")
@ -277,7 +273,6 @@ of its parent.
Only has effect when `ruby-use-smie' is t." Only has effect when `ruby-use-smie' is t."
:type 'boolean :type 'boolean
:group 'ruby
:safe 'booleanp :safe 'booleanp
:version "24.4") :version "24.4")
@ -286,7 +281,6 @@ Only has effect when `ruby-use-smie' is t."
Also ignores spaces after parenthesis when `space'. Also ignores spaces after parenthesis when `space'.
Only has effect when `ruby-use-smie' is nil." Only has effect when `ruby-use-smie' is nil."
:type 'boolean :type 'boolean
:group 'ruby
:safe 'booleanp) :safe 'booleanp)
;; FIXME Woefully under documented. What is the point of the last t?. ;; 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."
(cons character (choice (const nil) (cons character (choice (const nil)
(const t))) (const t)))
(const t) ; why? (const t) ; why?
))) ))))
:group 'ruby)
(defcustom ruby-deep-indent-paren-style 'space (defcustom ruby-deep-indent-paren-style 'space
"Default deep indent style. "Default deep indent style.
Only has effect when `ruby-use-smie' is nil." Only has effect when `ruby-use-smie' is nil."
:type '(choice (const t) (const nil) (const space)) :type '(choice (const t) (const nil) (const space)))
:group 'ruby)
(defcustom ruby-encoding-map (defcustom ruby-encoding-map
'((us-ascii . nil) ;; Do not put coding: us-ascii '((us-ascii . nil) ;; Do not put coding: us-ascii
@ -318,8 +310,7 @@ Only has effect when `ruby-use-smie' is nil."
"Alist to map encoding name from Emacs to Ruby. "Alist to map encoding name from Emacs to Ruby.
Associating an encoding name with nil means it needs not be Associating an encoding name with nil means it needs not be
explicitly declared in magic comment." explicitly declared in magic comment."
:type '(repeat (cons (symbol :tag "From") (symbol :tag "To"))) :type '(repeat (cons (symbol :tag "From") (symbol :tag "To"))))
:group 'ruby)
(defcustom ruby-insert-encoding-magic-comment t (defcustom ruby-insert-encoding-magic-comment t
"Insert a magic Ruby encoding comment upon save if this is non-nil. "Insert a magic Ruby encoding comment upon save if this is non-nil.
@ -336,14 +327,12 @@ even if it's not required."
(const :tag "Emacs Style" emacs) (const :tag "Emacs Style" emacs)
(const :tag "Ruby Style" ruby) (const :tag "Ruby Style" ruby)
(const :tag "Custom Style" custom)) (const :tag "Custom Style" custom))
:group 'ruby
:version "24.4") :version "24.4")
(defcustom ruby-custom-encoding-magic-comment-template "# encoding: %s" (defcustom ruby-custom-encoding-magic-comment-template "# encoding: %s"
"A custom encoding comment template. "A custom encoding comment template.
It is used when `ruby-encoding-magic-comment-style' is set to `custom'." It is used when `ruby-encoding-magic-comment-style' is set to `custom'."
:type 'string :type 'string
:group 'ruby
:version "24.4") :version "24.4")
(defcustom ruby-use-encoding-map t (defcustom ruby-use-encoding-map t
@ -741,7 +730,7 @@ It is used when `ruby-encoding-magic-comment-style' is set to `custom'."
(back-to-indentation) (back-to-indentation)
(narrow-to-region (point) end) (narrow-to-region (point) end)
(smie-forward-sexp)) (smie-forward-sexp))
(while (and (setq state (apply 'ruby-parse-partial end state)) (while (and (setq state (apply #'ruby-parse-partial end state))
(>= (nth 2 state) 0) (< (point) end)))))) (>= (nth 2 state) 0) (< (point) end))))))
(defun ruby-mode-variables () (defun ruby-mode-variables ()
@ -751,7 +740,7 @@ It is used when `ruby-encoding-magic-comment-style' is set to `custom'."
(smie-setup ruby-smie-grammar #'ruby-smie-rules (smie-setup ruby-smie-grammar #'ruby-smie-rules
:forward-token #'ruby-smie--forward-token :forward-token #'ruby-smie--forward-token
:backward-token #'ruby-smie--backward-token) :backward-token #'ruby-smie--backward-token)
(setq-local indent-line-function 'ruby-indent-line)) (setq-local indent-line-function #'ruby-indent-line))
(setq-local comment-start "# ") (setq-local comment-start "# ")
(setq-local comment-end "") (setq-local comment-end "")
(setq-local comment-column ruby-comment-column) (setq-local comment-column ruby-comment-column)
@ -986,6 +975,7 @@ delimiter."
((eq c ?\( ) ruby-deep-arglist))) ((eq c ?\( ) ruby-deep-arglist)))
(defun ruby-parse-partial (&optional end in-string nest depth pcol indent) (defun ruby-parse-partial (&optional end in-string nest depth pcol indent)
;; FIXME: Document why we can't just use parse-partial-sexp.
"TODO: document throughout function body." "TODO: document throughout function body."
(or depth (setq depth 0)) (or depth (setq depth 0))
(or indent (setq indent 0)) (or indent (setq indent 0))
@ -1160,7 +1150,7 @@ delimiter."
(state (list in-string nest depth pcol indent))) (state (list in-string nest depth pcol indent)))
;; parse the rest of the line ;; parse the rest of the line
(while (and (> line-end-position (point)) (while (and (> line-end-position (point))
(setq state (apply 'ruby-parse-partial (setq state (apply #'ruby-parse-partial
line-end-position state)))) line-end-position state))))
(setq in-string (car state) (setq in-string (car state)
nest (nth 1 state) nest (nth 1 state)
@ -1197,7 +1187,7 @@ delimiter."
(save-restriction (save-restriction
(narrow-to-region (point) end) (narrow-to-region (point) end)
(while (and (> end (point)) (while (and (> end (point))
(setq state (apply 'ruby-parse-partial end state)))))) (setq state (apply #'ruby-parse-partial end state))))))
(list (nth 0 state) ; in-string (list (nth 0 state) ; in-string
(car (nth 1 state)) ; nest (car (nth 1 state)) ; nest
(nth 2 state) ; depth (nth 2 state) ; depth
@ -2034,13 +2024,6 @@ It will be properly highlighted even when the call omits parens.")
context))) context)))
t))) t)))
(defvar ruby-font-lock-syntax-table
(let ((tbl (make-syntax-table ruby-mode-syntax-table)))
(modify-syntax-entry ?_ "w" tbl)
tbl)
"The syntax table to use for fontifying Ruby mode buffers.
See `font-lock-syntax-table'.")
(defconst ruby-font-lock-keyword-beg-re "\\(?:^\\|[^.@$:]\\|\\.\\.\\)") (defconst ruby-font-lock-keyword-beg-re "\\(?:^\\|[^.@$:]\\|\\.\\.\\)")
(defconst ruby-font-lock-keywords (defconst ruby-font-lock-keywords
@ -2219,7 +2202,8 @@ See `font-lock-syntax-table'.")
;; Conversion methods on Kernel. ;; Conversion methods on Kernel.
(,(concat ruby-font-lock-keyword-beg-re (,(concat ruby-font-lock-keyword-beg-re
(regexp-opt '("Array" "Complex" "Float" "Hash" (regexp-opt '("Array" "Complex" "Float" "Hash"
"Integer" "Rational" "String") 'symbols)) "Integer" "Rational" "String")
'symbols))
(1 font-lock-builtin-face)) (1 font-lock-builtin-face))
;; Expression expansion. ;; Expression expansion.
(ruby-match-expression-expansion (ruby-match-expression-expansion
@ -2316,14 +2300,12 @@ See `font-lock-syntax-table'.")
Only takes effect if RuboCop is installed." Only takes effect if RuboCop is installed."
:version "26.1" :version "26.1"
:type 'boolean :type 'boolean
:group 'ruby
:safe 'booleanp) :safe 'booleanp)
(defcustom ruby-rubocop-config ".rubocop.yml" (defcustom ruby-rubocop-config ".rubocop.yml"
"Configuration file for `ruby-flymake-rubocop'." "Configuration file for `ruby-flymake-rubocop'."
:version "26.1" :version "26.1"
:type 'string :type 'string
:group 'ruby
:safe 'stringp) :safe 'stringp)
(defun ruby-flymake-rubocop (report-fn &rest _args) (defun ruby-flymake-rubocop (report-fn &rest _args)
@ -2393,18 +2375,17 @@ Only takes effect if RuboCop is installed."
"Major mode for editing Ruby code." "Major mode for editing Ruby code."
(ruby-mode-variables) (ruby-mode-variables)
(setq-local imenu-create-index-function 'ruby-imenu-create-index) (setq-local imenu-create-index-function #'ruby-imenu-create-index)
(setq-local add-log-current-defun-function 'ruby-add-log-current-method) (setq-local add-log-current-defun-function #'ruby-add-log-current-method)
(setq-local beginning-of-defun-function 'ruby-beginning-of-defun) (setq-local beginning-of-defun-function #'ruby-beginning-of-defun)
(setq-local end-of-defun-function 'ruby-end-of-defun) (setq-local end-of-defun-function #'ruby-end-of-defun)
(add-hook 'after-save-hook 'ruby-mode-set-encoding nil 'local) (add-hook 'after-save-hook #'ruby-mode-set-encoding nil 'local)
(add-hook 'electric-indent-functions 'ruby--electric-indent-p nil 'local) (add-hook 'electric-indent-functions #'ruby--electric-indent-p nil 'local)
(add-hook 'flymake-diagnostic-functions 'ruby-flymake-auto nil 'local) (add-hook 'flymake-diagnostic-functions #'ruby-flymake-auto nil 'local)
(setq-local font-lock-defaults '((ruby-font-lock-keywords) nil nil)) (setq-local font-lock-defaults '((ruby-font-lock-keywords) nil nil
(setq-local font-lock-keywords ruby-font-lock-keywords) ((?_ . "w"))))
(setq-local font-lock-syntax-table ruby-font-lock-syntax-table)
(setq-local syntax-propertize-function #'ruby-syntax-propertize)) (setq-local syntax-propertize-function #'ruby-syntax-propertize))