Commit graph

204 commits

Author SHA1 Message Date
Stefan Monnier
34d1a1337d Get Ruby's SMIE code to pass the test suite.
* lisp/progmodes/ruby-mode.el (ruby-use-smie): Change default.
(ruby-comment-column): Follow the global default, by default.
(ruby-smie-grammar): Add assignment syntax.
(ruby-smie--implicit-semi-p): No implicit semi-colon after an
open-paren, a comma, or a \.
(ruby-smie--forward-token, ruby-smie--backward-token): Handle heredocs,
and line continuations.
(ruby-smie-rules): Adjust handling of open-paren, now that it's never
followed by implicit semi-colons.  Add rule for string concatenation
and for indentation at BOB.
(ruby-forward-sexp, ruby-backward-sexp): Adjust for when smie is in use.

* lisp/emacs-lisp/smie.el (smie-next-sexp): Don't go back to pos before
calling next-sexp, since next-token may have skipped chars which
next-sexp doesn't know should be skipped!

* test/indent/ruby.rb: Port a few cases from automated/ruby-mode-tests.el.
Adjust indentation of continued line to the new SMIE behavior.
2013-10-05 14:37:08 -04:00
Dmitry Gutov
aa0214dae5 Revert 2013-10-05T02:26:39Z!dgutov@yandex.ru
`last-coding-system-used' is unreliable: it can be modified by other functions
in `after-save-hook'.
2013-10-05 20:21:22 +03:00
Dmitry Gutov
0106e5b399 * lisp/progmodes/ruby-mode.el (ruby-mode): Add `ruby-mode-set-encoding'
to `after-save-hook' instead of `before-save-hook', because then
we know exactly what encoding was used to write the file.
(ruby-mode-set-encoding): Use `last-coding-system-used' instead of
guessing.  Call `basic-save-buffer-1' after modifying the buffer.
2013-10-05 05:26:39 +03:00
Dmitry Gutov
578c21bc03 * lisp/progmodes/ruby-mode.el (ruby-operator-re): Consider line
continuation character an operator, as far as indentation is
concerned.

Fixes: debbugs:15369
2013-09-16 02:42:26 +03:00
Glenn Morris
08d664200f * lisp/progmodes/ruby-mode.el (ruby-syntax-propertize-function): Declare. 2013-09-11 22:43:55 -07:00
Glenn Morris
2a08047aed Improve previous interpreter-mode-alist change
* lisp/files.el (interpreter-mode-alist): Remove \\` \\' parts.
(set-auto-mode): Don't regexp-quote elements.

* lisp/progmodes/python.el (interpreter-mode-alist): Remove \\` \\'.

* lisp/progmodes/cc-mode.el (interpreter-mode-alist):
* lisp/progmodes/ruby-mode.el (interpreter-mode-alist):
Revert previous change.

* etc/NEWS: Update.
2013-09-10 23:44:35 -07:00
Glenn Morris
1af4c2203c Treat interpreter-mode-alist as alist of regexps, not literals
Cf http://lists.gnu.org/archive/html/emacs-devel/2005-08/msg00472.html

* lisp/files.el (interpreter-mode-alist): Convert to regexps.
(set-auto-mode): Adapt for this. 

* lisp/progmodes/cperl-mode.el (cperl-clobber-mode-lists):
Comment out unused variable.

* lisp/progmodes/cc-mode.el (interpreter-mode-alist):
* lisp/progmodes/python.el (interpreter-mode-alist):
* lisp/progmodes/ruby-mode.el (interpreter-mode-alist): Convert to regexps.

* lisp/progmodes/sh-script.el (sh-set-shell):
No longer use interpreter-mode-alist to get list of shells.

* etc/NEWS: Mention this.

Fixes: debbugs:15306
2013-09-10 16:38:52 -04:00
Dmitry Gutov
1f896cb7ed * lisp/progmodes/ruby-mode.el (ruby-font-lock-keywords): Move "Perl-ish
keywords" below "here-doc beginnings".

Fixes: debbugs:15270
2013-09-05 16:05:01 +03:00
Dmitry Gutov
88527bc0a2 * lisp/progmodes/ruby-mode.el (ruby-calculate-indent): Consider
two-character operators and whether the character preceding them
changes their meaning.

Fixes: debbugs:15208
2013-09-03 03:29:10 +03:00
Stefan Monnier
f069bba87c * lisp/progmodes/ruby-mode.el (ruby-smie-grammar): Add rule for formal
params of lambda expressions.
(ruby-smie--implicit-semi-p): Refine rule.
(ruby-smie--opening-pipe-p): New function.
(ruby-smie--forward-token, ruby-smie--backward-token): Handle Ruby
symbols and matched |...| for formal params.
(ruby-smie-rules): Don't let the formal params of a "do" prevent it
from being treated as hanging.  Handle "rescue".

Fixes: debbugs:15208
2013-08-29 14:06:46 -04:00
Dmitry Gutov
ac72c08d12 * lisp/progmodes/ruby-mode.el (ruby-block-beg-keywords): Inline.
(ruby-font-lock-keyword-beg-re): Extract from
`ruby-font-lock-keywords'.
2013-07-16 23:16:51 +04:00
Dmitry Gutov
77aea2fbb3 * lisp/progmodes/ruby-mode.el (ruby-font-lock-keywords): Do not
highlight question marks in the method names as strings.
2013-07-16 18:47:23 +04:00
Dmitry Gutov
2ce3c56586 * lisp/progmodes/ruby-mode.el (ruby-font-lock-keywords): Highlight
conversion methods on Kernel.
2013-07-13 23:10:19 +04:00
Dmitry Gutov
481861772a * progmodes/ruby-mode.el (ruby-font-lock-keywords): Simplify the last
change.
2013-07-13 03:36:14 +04:00
Dmitry Gutov
0880a9520e * lisp/progmodes/ruby-mode.el (ruby-percent-literals-beg-re):
(ruby-syntax-expansion-allowed-p): Support array of symbols, for
Ruby 2.0.
(ruby-font-lock-keywords): Distinguish calls to functions with
module-like names from module references.  Highlight character
literals.
2013-07-13 00:28:53 +04:00
Dmitry Gutov
70c46b2816 * lisp/progmodes/ruby-mode.el (ruby-font-lock-keywords): Remove extra
"autoload".  Remove "warn lower camel case" section, previously
commented out.  Highlight negation char.  Do not highlight the
target in singleton method definitions.
2013-07-09 05:17:48 +04:00
Dmitry Gutov
56f75efcbc * lisp/progmodes/ruby-mode.el (ruby-font-lock-keywords): Highlight more
keywords and built-ins.
2013-07-03 19:46:45 +04:00
Dmitry Gutov
3086ca2e2c * lisp/progmodes/ruby-mode.el (ruby-move-to-block): When we're at a
middle of block statement initially, lower the depth.  Remove
FIXME comment, not longer valid.  Remove middle of block statement
detection, no need to do that anymore since we've been using
`ruby-parse-region' here.
2013-07-03 05:02:18 +04:00
Dmitry Gutov
6dbafa3000 * lisp/progmodes/ruby-mode.el (ruby-syntax-propertize-function): Don't
start heredoc inside a string or comment.
2013-06-30 06:23:10 +04:00
Dmitry Gutov
12adebe94e * lisp/progmodes/ruby-mode.el (ruby-font-lock-keywords): Move `catch',
add some more keyword-like methods.
http://lists.gnu.org/archive/html/emacs-devel/2013-06/msg00911.html
2013-06-22 17:25:43 +04:00
Dmitry Gutov
f72e2fdb68 * lisp/progmodes/ruby-mode.el (auto-mode-alist): Do not use
`regexp-opt', it breaks the build during dumping.
2013-06-22 04:11:24 +04:00
Dmitry Gutov
7bcf66280c * progmodes/ruby-mode.el (auto-mode-alist): Forgot "Guardfile". 2013-06-22 03:20:54 +04:00
Dmitry Gutov
5cf8176d55 * lisp/progmodes/ruby-mode.el (auto-mode-alist): Consolidate different
entries into one regexp and add more *file-s.
2013-06-22 03:14:38 +04:00
Dmitry Gutov
73eab938a0 * lisp/progmodes/ruby-mode.el (ruby-font-lock-keywords): Highlight
keyword-like methods on Kernel and Module with
font-lock-builtin-face.
2013-06-22 03:07:49 +04:00
Dmitry Gutov
d1bbba4fa5 * lisp/progmodes/ruby-mode.el (ruby-syntax-before-regexp-re):
Distinguish ternary operator tokens from slash symbol and slash
char literal.
2013-06-19 02:17:56 +04:00
Dmitry Gutov
973d1e126c * lisp/progmodes/ruby-mode.el (ruby-syntax-expansion-allowed-p):
Highlight expansions inside regexp literals.
2013-05-31 20:55:03 +04:00
Dmitry Gutov
19bb8e6293 * lisp/progmodes/ruby-mode.el (ruby-syntax-expansion-allowed-p): New
function, checks if expression expansion is allowed in given parse
state.
(ruby-syntax-propertize-expansion): Use it.
(ruby-syntax-propertize-function): Bind `case-fold-search' to nil
around the body.

* test/automated/ruby-mode-tests.el: New tests, for percent literals
and expression expansion.
2013-05-31 10:04:33 +04:00
Glenn Morris
dab49a3b21 * progmodes/ruby-mode.el (ruby-syntax-propertize-expansion): Declare. 2013-05-23 20:49:52 -07:00
Dmitry Gutov
462388b673 * lisp/progmodes/ruby-mode.el (ruby-syntax-propertize-heredoc): Leave
point at bol following the heredoc openers.
(ruby-syntax-propertize-expansions): Remove.
2013-05-19 10:52:22 +04:00
Dmitry Gutov
1a0a0a8a6a * lisp/progmodes/ruby-mode.el (ruby-expression-expansion-re): Allow to
start at point, so that expansion starting right after opening
slash in a regexp is recognized.
(ruby-syntax-before-regexp-re): New defvar, extracted from
ruby-syntax-propertize-function.  Since the value of this regexp
is looked up at runtime now, we should be able to turn
`ruby-syntax-methods-before-regexp' into a defcustom later.
(ruby-syntax-propertize-function): Split regexp matching into two
parts, for opening and closing slashes.  That allows us to skip
over string interpolations and support multiline regexps.
Don't call `ruby-syntax-propertize-expansions', instead use another rule
for them, which calls `ruby-syntax-propertize-expansion'.
(ruby-syntax-propertize-expansions): Move `remove-text-properties'
call to `ruby-syntax-propertize-function'.
(ruby-syntax-propertize-expansion): Extracted from
`ruby-syntax-propertize-expansions'.  Handles one expansion.
(ruby-syntax-propertize-heredoc): Explicitly call
`ruby-syntax-propertize-expansions'.
(ruby-syntax-propertize-percent-literal): Leave point right after
the percent symbol, so that the expression expansion rule can
propertize the contents.

* test/automated/ruby-mode-tests.el (ruby-heredoc-highlights-interpolations)
(ruby-regexp-skips-over-interpolation)
(ruby-regexp-continues-till-end-when-unclosed)
(ruby-regexp-can-be-multiline)
(ruby-interpolation-inside-percent-literal): New tests.

* test/indent/ruby.rb: Add multiline regexp example.
2013-05-19 10:01:23 +04:00
Stefan Monnier
a9e4425bc9 * lisp/progmodes/ruby-mode.el: First cut at SMIE support.
(ruby-use-smie): New var.
(ruby-smie-grammar): New constant.
(ruby-smie--bosp, ruby-smie--implicit-semi-p)
(ruby-smie--forward-token, ruby-smie--backward-token)
(ruby-smie-rules): New functions.
(ruby-mode-variables): Setup SMIE if applicable.
* test/indent/ruby.rb: Fix indentation after =; add more cases.
2013-05-08 16:25:57 -04:00
Dmitry Gutov
fb549d640a * lisp/progmodes/ruby-mode.el (ruby-beginning-of-defun)
(ruby-end-of-defun, ruby-move-to-block): Bind `case-fold-search'
to nil.
(ruby-end-of-defun): Remove the unused arg, change the docstring
to reflect that this function is only used as the value of
`end-of-defun-function'.
(ruby-beginning-of-defun): Remove "top-level" from the docstring,
to reflect an earlier change that beginning/end-of-defun functions
jump between methods in a class definition, as well as top-level
functions.
2013-04-16 03:07:14 +04:00
Dmitry Gutov
ab89e9f9a5 * lisp/progmodes/ruby-mode.el (ruby-syntax-propertize-function): Only
propertize regexp when not inside a string.

Fixes: debbugs:13885
2013-03-06 22:56:29 +04:00
Dmitry Gutov
71a048c16b (ruby-add-log-current-method): Improve performance at the expense
of accuracy.  `ruby-block-contains-point' is relatively slow, so
only use it for method and singleton class blocks.

* test/automated/ruby-mode-tests.el
(ruby-add-log-current-method-after-inner-class): Lower
expectations: move point inside a method, initially.
2013-02-14 09:45:33 +04:00
Dmitry Gutov
53ca88c478 * lisp/progmodes/ruby-mode.el (ruby-parse-partial): Don't increase
depth for unfinished percent literal.  Not using it in the caller.
(ruby-move-to-block): Jump over multiline literals of all types,
ignoring code-looking contents inside them.

* test/automated/ruby-mode-tests.el
(ruby-move-to-block-skips-percent-literal): Add depth-affecting
bits inside the examples.
(ruby-move-to-block-skips-heredoc): New test.
2013-02-14 07:33:55 +04:00
Dmitry Gutov
7132e457ad * lisp/progmodes/ruby-mode.el (ruby-move-to-block): Improve
performance.  Instead of recalculating indentation fully for each
line, sum up indentation depth based only on visited lines.
(ruby-parse-partial): Increase the depth after "do" even when END
is right after it.
(ruby-parse-partial): When END is in the middle of a percent
literal, increase the depth if the delimiter chars belong to the
paren syntax class.

* test/automated/ruby-mode-tests.el
(ruby-move-to-block-skips-percent-literal): New test.
2013-02-13 12:15:05 +04:00
Dmitry Gutov
18d801db79 * progmodes/ruby-mode.el (ruby-font-lock-keywords): Highlight
nested constants, too.  \_< broke that.
2013-01-28 06:07:42 +04:00
Dmitry Gutov
a324b8c791 * progmodes/ruby-mode.el (ruby-move-to-block): Work with (maybe
temporarily) broken indentation.
* automated/ruby-mode-tests.el (ruby-block-test-example):
  Break indentation of the do block opener and add a line inside it.
* automated/ruby-mode-tests.el (works-on-do, ok-with-three):
  Adjust line numbers.
2013-01-28 05:20:42 +04:00
Dmitry Gutov
499572e4d5 * progmodes/ruby-mode.el (ruby-font-lock-keywords): Use "\\_<" instead
of "\\b".  Remove some checks made superfluous as a result.
2013-01-28 02:32:11 +04:00
Paul Eggert
0877d0dc24 Merge from emacs-24; up to 2012-12-06T01:39:03Z!monnier@iro.umontreal.ca 2013-01-02 08:13:04 -08:00
Paul Eggert
ab422c4d68 Update copyright notices for 2013. 2013-01-01 09:11:05 +00:00
Glenn Morris
82e2a1f054 Merge from emacs-24; up to 2012-12-03T21:07:47Z!eggert@cs.ucla.edu 2012-12-27 00:21:08 -08:00
Dmitry Gutov
78269b95cf * lisp/progmodes/ruby-mode.el (auto-mode-alist): `purecopy' the
Rakefile regexp.
(auto-mode-alist): Associate .gemspec files with ruby-mode
(https://bugs.ruby-lang.org/issues/5453).
2012-12-26 23:52:56 +04:00
Dmitry Gutov
db590ef6e3 * lisp/progmodes/ruby-mode.el (ruby-indent-beg-re): Only allow "class",
"module" and "def" to have indentation before them.  Regression
  from 2012-09-07T04:15:56Z!dgutov@yandex.ru (see the new test).

* test/automated/ruby-mode-tests.el
  (ruby-indent-after-block-in-continued-expression): New test.
2012-12-26 20:45:19 +04:00
Dmitry Gutov
ea0857a126 * lisp/progmodes/ruby-mode.el: Bump the version to 1.2.
Fixes: debbugs:13200
2012-12-24 11:14:49 +04:00
Paul Eggert
cccaebd24d Spelling fixes.
My favorite was that the word "dictionary" was misspelled.
Also, correct the title in the DeRemer & Pennello 1982 citation,
and add a URL.
2012-12-14 12:05:03 -08:00
Dmitry Gutov
bb808526ae * lisp/progmodes/ruby-mode.el (ruby-syntax-propertize-function):
Extract `ruby-syntax-propertize-expansions'.
(ruby-syntax-propertize-expansions): Only change syntax on
certain string delimiters, to punctuation.  This way the common
functions like forward-word and thing-at-point still work.
(ruby-match-expression-expansion): Improve readability.
(ruby-block-contains-point): New function.
(ruby-add-log-current-method): Handle several edge cases.

* test/automated/ruby-mode-tests.el
Rename one interpolation test; add three more.
(ruby-with-temp-buffer): New macro, use it where appropriate.
(ruby-add-log-current-method-examples): Use "_" for target point.
Add four tests for ruby-add-log-current-method.
2012-12-14 10:58:15 +04:00
Dmitry Gutov
dbb530d988 * lisp/progmodes/ruby-mode.el (ruby-syntax-propertize-function):
Extract `ruby-syntax-propertize-expansions'.
(ruby-syntax-propertize-expansions): Only change syntax on
certain string delimiters, to punctuation.  This way the common
functions like forward-word and thing-at-point still work.

* test/automated/ruby-mode-tests.el
Rename one interpolation test; add three more.
2012-12-14 08:55:23 +04:00
Dmitry Gutov
c62792e7df * lisp/progmodes/ruby-mode.el
(ruby-syntax-propertize-function): After everything else, search
for expansions in string literals, mark their insides as
whitespace syntax and save match data for font-lock.
(ruby-font-lock-keywords): Highlight just the 2nd group from
expression expansion matches.
(ruby-match-expression-expansion): Use the match data saved to the
text property in ruby-syntax-propertize-function.

* test/automated/ruby-mode-tests.el
Change direct font-lock face references to var references.
(ruby-interpolation-suppresses-syntax-inside): New test.
(ruby-interpolation-inside-percent-literal-with-paren): New
failing test.
2012-11-14 16:17:21 +04:00
Dmitry Gutov
8619323f69 * lisp/progmodes/ruby-mode.el (ruby-expr-beg): Make heredoc detection
more strict.  Add docstring.

* test/automated/ruby-mode-tests.el (ruby-indent-singleton-class): Pass.
(ruby-indent-inside-heredoc-after-operator)
(ruby-indent-inside-heredoc-after-space): New tests.
2012-11-14 10:34:17 +04:00