diff options
Diffstat (limited to 'lisp/progmodes/ruby-mode.el')
| -rw-r--r-- | lisp/progmodes/ruby-mode.el | 63 |
1 files changed, 56 insertions, 7 deletions
diff --git a/lisp/progmodes/ruby-mode.el b/lisp/progmodes/ruby-mode.el index 449a10dc999..12fb8d2bf72 100644 --- a/lisp/progmodes/ruby-mode.el +++ b/lisp/progmodes/ruby-mode.el | |||
| @@ -226,9 +226,48 @@ This should only be called after matching against `ruby-here-doc-beg-re'." | |||
| 226 | :group 'ruby | 226 | :group 'ruby |
| 227 | :safe 'integerp) | 227 | :safe 'integerp) |
| 228 | 228 | ||
| 229 | (defcustom ruby-align-to-stmt-keywords nil | ||
| 230 | "Keywords to align their expression body to statement. | ||
| 231 | When nil, an expression that begins with one these keywords is | ||
| 232 | indented to the column of the keyword. Example: | ||
| 233 | |||
| 234 | tee = if foo | ||
| 235 | bar | ||
| 236 | else | ||
| 237 | qux | ||
| 238 | end | ||
| 239 | |||
| 240 | If this value is t or contains a symbol with the name of given | ||
| 241 | keyword, the expression is indented to align to the beginning of | ||
| 242 | the statement: | ||
| 243 | |||
| 244 | tee = if foo | ||
| 245 | bar | ||
| 246 | else | ||
| 247 | qux | ||
| 248 | end | ||
| 249 | |||
| 250 | Only has effect when `ruby-use-smie' is t. | ||
| 251 | " | ||
| 252 | :type '(choice | ||
| 253 | (const :tag "None" nil) | ||
| 254 | (const :tag "All" t) | ||
| 255 | (repeat :tag "User defined" | ||
| 256 | (choice (const if) | ||
| 257 | (const while) | ||
| 258 | (const unless) | ||
| 259 | (const until) | ||
| 260 | (const begin) | ||
| 261 | (const case) | ||
| 262 | (const for)))) | ||
| 263 | :group 'ruby | ||
| 264 | :safe 'listp | ||
| 265 | :version "24.4") | ||
| 266 | |||
| 229 | (defcustom ruby-deep-arglist t | 267 | (defcustom ruby-deep-arglist t |
| 230 | "Deep indent lists in parenthesis when non-nil. | 268 | "Deep indent lists in parenthesis when non-nil. |
| 231 | Also ignores spaces after parenthesis when 'space." | 269 | Also ignores spaces after parenthesis when `space'. |
| 270 | Only has effect when `ruby-use-smie' is nil." | ||
| 232 | :type 'boolean | 271 | :type 'boolean |
| 233 | :group 'ruby | 272 | :group 'ruby |
| 234 | :safe 'booleanp) | 273 | :safe 'booleanp) |
| @@ -236,11 +275,13 @@ Also ignores spaces after parenthesis when 'space." | |||
| 236 | (defcustom ruby-deep-indent-paren '(?\( ?\[ ?\] t) | 275 | (defcustom ruby-deep-indent-paren '(?\( ?\[ ?\] t) |
| 237 | "Deep indent lists in parenthesis when non-nil. | 276 | "Deep indent lists in parenthesis when non-nil. |
| 238 | The value t means continuous line. | 277 | The value t means continuous line. |
| 239 | Also ignores spaces after parenthesis when 'space." | 278 | Also ignores spaces after parenthesis when `space'. |
| 279 | Only has effect when `ruby-use-smie' is nil." | ||
| 240 | :group 'ruby) | 280 | :group 'ruby) |
| 241 | 281 | ||
| 242 | (defcustom ruby-deep-indent-paren-style 'space | 282 | (defcustom ruby-deep-indent-paren-style 'space |
| 243 | "Default deep indent style." | 283 | "Default deep indent style. |
| 284 | Only has effect when `ruby-use-smie' is nil." | ||
| 244 | :options '(t nil space) :group 'ruby) | 285 | :options '(t nil space) :group 'ruby) |
| 245 | 286 | ||
| 246 | (defcustom ruby-encoding-map | 287 | (defcustom ruby-encoding-map |
| @@ -520,6 +561,10 @@ It is used when `ruby-encoding-magic-comment-style' is set to `custom'." | |||
| 520 | (smie-backward-sexp ";") | 561 | (smie-backward-sexp ";") |
| 521 | (cons 'column (smie-indent-virtual)))) | 562 | (cons 'column (smie-indent-virtual)))) |
| 522 | 563 | ||
| 564 | (defun ruby-smie--indent-to-stmt-p (keyword) | ||
| 565 | (or (eq t ruby-align-to-stmt-keywords) | ||
| 566 | (memq (intern keyword) ruby-align-to-stmt-keywords))) | ||
| 567 | |||
| 523 | (defun ruby-smie-rules (kind token) | 568 | (defun ruby-smie-rules (kind token) |
| 524 | (pcase (cons kind token) | 569 | (pcase (cons kind token) |
| 525 | (`(:elem . basic) ruby-indent-level) | 570 | (`(:elem . basic) ruby-indent-level) |
| @@ -572,7 +617,9 @@ It is used when `ruby-encoding-magic-comment-style' is set to `custom'." | |||
| 572 | (`(:before . ,(or `"else" `"then" `"elsif" `"rescue" `"ensure")) | 617 | (`(:before . ,(or `"else" `"then" `"elsif" `"rescue" `"ensure")) |
| 573 | (smie-rule-parent)) | 618 | (smie-rule-parent)) |
| 574 | (`(:before . "when") | 619 | (`(:before . "when") |
| 575 | (if (not (smie-rule-sibling-p)) 0)) ;; ruby-indent-level | 620 | ;; Align to the previous `when', but look up the virtual |
| 621 | ;; indentation of `case'. | ||
| 622 | (if (smie-rule-sibling-p) 0 (smie-rule-parent))) | ||
| 576 | (`(:after . ,(or "=" "iuwu-mod" "+" "-" "*" "/" "&&" "||" "%" "**" "^" "&" | 623 | (`(:after . ,(or "=" "iuwu-mod" "+" "-" "*" "/" "&&" "||" "%" "**" "^" "&" |
| 577 | "<=>" ">" "<" ">=" "<=" "==" "===" "!=" "<<" ">>" | 624 | "<=>" ">" "<" ">=" "<=" "==" "===" "!=" "<<" ">>" |
| 578 | "+=" "-=" "*=" "/=" "%=" "**=" "&=" "|=" "^=" "|" | 625 | "+=" "-=" "*=" "/=" "%=" "**=" "&=" "|=" "^=" "|" |
| @@ -581,9 +628,11 @@ It is used when `ruby-encoding-magic-comment-style' is set to `custom'." | |||
| 581 | (smie-indent--hanging-p) | 628 | (smie-indent--hanging-p) |
| 582 | ruby-indent-level)) | 629 | ruby-indent-level)) |
| 583 | (`(:after . ,(or "?" ":")) ruby-indent-level) | 630 | (`(:after . ,(or "?" ":")) ruby-indent-level) |
| 584 | (`(:before . "begin") | 631 | (`(:before . ,(or "if" "while" "unless" "until" "begin" "case" "for")) |
| 585 | (unless (save-excursion (skip-chars-backward " \t") (bolp)) | 632 | (when (not (save-excursion (skip-chars-backward " \t") (bolp))) |
| 586 | (smie-rule-parent))) | 633 | (if (ruby-smie--indent-to-stmt-p token) |
| 634 | (ruby-smie--indent-to-stmt) | ||
| 635 | (cons 'column (current-column))))) | ||
| 587 | )) | 636 | )) |
| 588 | 637 | ||
| 589 | (defun ruby-imenu-create-index-in-block (prefix beg end) | 638 | (defun ruby-imenu-create-index-in-block (prefix beg end) |