diff options
author | Sean Whitton <spwhitton@spwhitton.name> | 2021-08-19 16:48:59 -0700 |
---|---|---|
committer | Sean Whitton <spwhitton@spwhitton.name> | 2021-08-19 16:48:59 -0700 |
commit | 07fcbb558d797272b9f43547da60beda485873a3 (patch) | |
tree | 77d5da14e9f9d9d8b1d877c70c01296fd3893796 /lisp/progmodes/ruby-mode.el | |
parent | c9bdeff3e45a7ac84a74a81bb048046f82dddc91 (diff) | |
parent | fb81c8c3adf8633f2f617c82f6019aef630860c7 (diff) | |
download | emacs-07fcbb558d797272b9f43547da60beda485873a3.tar.gz |
Merge remote-tracking branch 'origin/master' into athena/unstable
Diffstat (limited to 'lisp/progmodes/ruby-mode.el')
-rw-r--r-- | lisp/progmodes/ruby-mode.el | 44 |
1 files changed, 27 insertions, 17 deletions
diff --git a/lisp/progmodes/ruby-mode.el b/lisp/progmodes/ruby-mode.el index e7f407b6367..c09f007a5ee 100644 --- a/lisp/progmodes/ruby-mode.el +++ b/lisp/progmodes/ruby-mode.el @@ -291,6 +291,7 @@ Only has effect when `ruby-use-smie' is nil." (defcustom ruby-encoding-map '((us-ascii . nil) ;; Do not put coding: us-ascii + (utf-8 . nil) ;; Default since Ruby 2.0 (shift-jis . cp932) ;; Emacs charset name of Shift_JIS (shift_jis . cp932) ;; MIME charset name of Shift_JIS (japanese-cp932 . cp932)) ;; Emacs charset name of CP932 @@ -331,7 +332,7 @@ It is used when `ruby-encoding-magic-comment-style' is set to `custom'." (require 'smie) ;; Here's a simplified BNF grammar, for reference: -;; http://www.cse.buffalo.edu/~regan/cse305/RubyBNF.pdf +;; https://www.cse.buffalo.edu/~regan/cse305/RubyBNF.pdf (defconst ruby-smie-grammar (smie-prec2->grammar (smie-merge-prec2s @@ -678,7 +679,7 @@ It is used when `ruby-encoding-magic-comment-style' is set to `custom'." (let ((index-alist '()) (case-fold-search nil) name next pos decl sing) (goto-char beg) - (while (re-search-forward "^\\s *\\(\\(class\\s +\\|\\(class\\s *<<\\s *\\)\\|module\\s +\\)\\([^(<\n ]+\\)\\|\\(def\\|alias\\)\\s +\\([^(\n ]+\\)\\)" end t) + (while (re-search-forward "^\\s *\\(\\(class\\s +\\|\\(class\\s *<<\\s *\\)\\|module\\s +\\)\\([^(<\n ]+\\)\\|\\(\\(?:\\(?:private\\|protected\\|public\\) +\\)?def\\|alias\\)\\s +\\([^(\n ]+\\)\\)" end t) (setq sing (match-beginning 3)) (setq decl (match-string 5)) (setq next (match-end 0)) @@ -688,7 +689,7 @@ It is used when `ruby-encoding-magic-comment-style' is set to `custom'." ((string= "alias" decl) (if prefix (setq name (concat prefix name))) (push (cons name pos) index-alist)) - ((string= "def" decl) + ((not (null decl)) (if prefix (setq name (cond @@ -760,7 +761,7 @@ The style of the comment is controlled by `ruby-encoding-magic-comment-style'." (defun ruby--detect-encoding () (if (eq ruby-insert-encoding-magic-comment 'always-utf8) - "utf-8" + 'utf-8 (let ((coding-system (or save-buffer-coding-system buffer-file-coding-system))) @@ -769,12 +770,11 @@ The style of the comment is controlled by `ruby-encoding-magic-comment-style'." (or (coding-system-get coding-system 'mime-charset) (coding-system-change-eol-conversion coding-system nil)))) (if coding-system - (symbol-name - (if ruby-use-encoding-map - (let ((elt (assq coding-system ruby-encoding-map))) - (if elt (cdr elt) coding-system)) - coding-system)) - "ascii-8bit")))) + (if ruby-use-encoding-map + (let ((elt (assq coding-system ruby-encoding-map))) + (if elt (cdr elt) coding-system)) + coding-system) + 'ascii-8bit)))) (defun ruby--encoding-comment-required-p () (or (eq ruby-insert-encoding-magic-comment 'always-utf8) @@ -796,7 +796,7 @@ The style of the comment is controlled by `ruby-encoding-magic-comment-style'." (unless (string= (match-string 2) coding-system) (goto-char (match-beginning 2)) (delete-region (point) (match-end 2)) - (insert coding-system))) + (insert (symbol-name coding-system)))) ((looking-at "\\s *#.*coding\\s *[:=]")) (t (when ruby-insert-encoding-magic-comment (ruby--insert-coding-comment coding-system)))) @@ -1788,8 +1788,8 @@ If the result is do-end block, it will always be multiline." (buffer-substring-no-properties (1+ min) (1- max)))) (setq content (if (equal string-quote "'") - (replace-regexp-in-string "\\\\\"" "\"" (replace-regexp-in-string "\\(\\`\\|[^\\]\\)'" "\\1\\\\'" content)) - (replace-regexp-in-string "\\\\'" "'" (replace-regexp-in-string "\\(\\`\\|[^\\]\\)\"" "\\1\\\\\"" content)))) + (string-replace "\\\"" "\"" (replace-regexp-in-string "\\(\\`\\|[^\\]\\)'" "\\1\\\\'" content)) + (string-replace "\\'" "'" (replace-regexp-in-string "\\(\\`\\|[^\\]\\)\"" "\\1\\\\\"" content)))) (let ((orig-point (point))) (delete-region min max) (insert @@ -1802,12 +1802,12 @@ FEATURE-NAME is a relative file name, file extension is optional. This commands delegates to `gem which', which searches both installed gems and the standard library. When called interactively, defaults to the feature name in the `require' -statement around point." +or `gem' statement around point." (interactive) (unless feature-name (let ((init (save-excursion (forward-line 0) - (when (looking-at "require [\"']\\(.*\\)[\"']") + (when (looking-at "\\(?:require\\| *gem\\) [\"']\\(.*?\\)[\"']") (match-string 1))))) (setq feature-name (read-string "Feature name: " init)))) (let ((out @@ -2127,11 +2127,9 @@ It will be properly highlighted even when the call omits parens.") "loop" "open" "p" - "print" "printf" "proc" "putc" - "puts" "require" "require_relative" "spawn" @@ -2180,9 +2178,11 @@ It will be properly highlighted even when the call omits parens.") "fork" "global_variables" "local_variables" + "print" "private" "protected" "public" + "puts" "raise" "rand" "readline" @@ -2421,6 +2421,15 @@ If there is no Rubocop config file, Rubocop will be passed a flag report-fn args)) +(defconst ruby--prettify-symbols-alist + '(("<=" . ?≤) + (">=" . ?≥) + ("->" . ?→) + ("=>" . ?⇒) + ("::" . ?∷) + ("lambda" . ?λ)) + "Value for `prettify-symbols-alist' in `ruby-mode'.") + ;;;###autoload (define-derived-mode ruby-mode prog-mode "Ruby" "Major mode for editing Ruby code." @@ -2437,6 +2446,7 @@ If there is no Rubocop config file, Rubocop will be passed a flag (setq-local font-lock-defaults '((ruby-font-lock-keywords) nil nil ((?_ . "w")))) + (setq-local prettify-symbols-alist ruby--prettify-symbols-alist) (setq-local syntax-propertize-function #'ruby-syntax-propertize)) |