* misc/ruby-mode.el (ruby-beginning-of-arg): substitute
ruby-backward-arg. * misc/ruby-mode.el (ruby-calculate-indent): fixed wrong indentation in brace block and parentheses. * misc/ruby-mode.el (ruby-forward-sexp, ruby-backward-sexp): support special char literal, and negative arguments. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3674 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
6e4a83c0a3
commit
6cdf714126
11
ChangeLog
11
ChangeLog
@ -1,3 +1,14 @@
|
|||||||
|
Sat Apr 12 20:59:40 2003 Nobuyoshi Nakada <nobu.nokada@softhome.net>
|
||||||
|
|
||||||
|
* misc/ruby-mode.el (ruby-beginning-of-arg): substitute
|
||||||
|
ruby-backward-arg.
|
||||||
|
|
||||||
|
* misc/ruby-mode.el (ruby-calculate-indent): fixed wrong
|
||||||
|
indentation in brace block and parentheses.
|
||||||
|
|
||||||
|
* misc/ruby-mode.el (ruby-forward-sexp, ruby-backward-sexp):
|
||||||
|
support special char literal, and negative arguments.
|
||||||
|
|
||||||
Fri Apr 11 19:00:14 2003 Nobuyoshi Nakada <nobu.nokada@softhome.net>
|
Fri Apr 11 19:00:14 2003 Nobuyoshi Nakada <nobu.nokada@softhome.net>
|
||||||
|
|
||||||
* win32/win32.c (rb_w32_stat): check arguments. [ruby-dev:20007]
|
* win32/win32.c (rb_w32_stat): check arguments. [ruby-dev:20007]
|
||||||
|
@ -283,9 +283,9 @@ The variable ruby-indent-level controls the amount of indentation.
|
|||||||
|
|
||||||
(defun ruby-special-char-p (&optional pnt)
|
(defun ruby-special-char-p (&optional pnt)
|
||||||
(let ((c (char-before pnt)))
|
(let ((c (char-before pnt)))
|
||||||
(cond ((or (eq c ??) (eq c ?$)))
|
(cond ((or (eq c ??) (eq c ?$)))
|
||||||
((eq c ?\\)
|
((eq c ?\\)
|
||||||
(eq (char-before (1- (or pnt (point)))) ??)))))
|
(eq (char-before (1- (or pnt (point)))) ??)))))
|
||||||
|
|
||||||
(defun ruby-expr-beg (&optional option)
|
(defun ruby-expr-beg (&optional option)
|
||||||
(save-excursion
|
(save-excursion
|
||||||
@ -296,8 +296,8 @@ The variable ruby-indent-level controls the amount of indentation.
|
|||||||
((progn
|
((progn
|
||||||
(forward-char -1)
|
(forward-char -1)
|
||||||
(and (looking-at "\\?")
|
(and (looking-at "\\?")
|
||||||
(or (ruby-special-char-p)
|
(or (eq (char-syntax (char-before (point))) ?w)
|
||||||
(eq (char-syntax (char-before (point)) ?w)))))
|
(ruby-special-char-p))))
|
||||||
nil)
|
nil)
|
||||||
((or (looking-at ruby-operator-re)
|
((or (looking-at ruby-operator-re)
|
||||||
(looking-at "[\\[({,;]")
|
(looking-at "[\\[({,;]")
|
||||||
@ -544,36 +544,42 @@ The variable ruby-indent-level controls the amount of indentation.
|
|||||||
(defun ruby-indent-size (pos nest)
|
(defun ruby-indent-size (pos nest)
|
||||||
(+ pos (* (or nest 1) ruby-indent-level)))
|
(+ pos (* (or nest 1) ruby-indent-level)))
|
||||||
|
|
||||||
(defconst ruby-assign-re "\\s *\\(&&\\|||\\|<<\\|>>[-+*/%&|^]\\)?=\\s *")
|
(defconst ruby-assign-re "\\s *\\(&&\\|||\\|<<\\|>>\\|[-+*/%&|^]\\)?=\\s *")
|
||||||
|
|
||||||
(defun ruby-backward-arg (limit depth)
|
(defun ruby-beginning-of-arg (start end)
|
||||||
(let ((indent (ruby-indent-size 0 depth))
|
(save-restriction
|
||||||
beg pnt (last (point)))
|
(narrow-to-region start (1+ end))
|
||||||
(when limit
|
(goto-char start)
|
||||||
(goto-char limit)
|
(let ((beg t) arg)
|
||||||
(ruby-forward-sexp)
|
(while
|
||||||
(setq limit (point)))
|
(progn
|
||||||
(goto-char last)
|
(skip-chars-forward " \t\n")
|
||||||
(setq pnt (point))
|
(and (not (eobp))
|
||||||
(ruby-backward-sexp)
|
(= (ruby-forward-sexp) 0)))
|
||||||
(while (and
|
(skip-syntax-forward " ")
|
||||||
(not (bobp))
|
(cond ((looking-at ",")
|
||||||
(setq beg (point))
|
(forward-char)
|
||||||
(progn
|
(setq arg start beg t))
|
||||||
(ruby-backward-sexp)
|
((ruby-expr-beg) t)
|
||||||
(or (looking-at ruby-block-hanging-re)
|
((looking-at "=>\\s *")
|
||||||
(save-excursion
|
(goto-char (match-end 0))
|
||||||
(ruby-forward-sexp)
|
(setq arg nil beg nil))
|
||||||
(looking-at ruby-assign-re)))))
|
((looking-at ruby-assign-re)
|
||||||
(setq last beg))
|
(goto-char (match-end 0))
|
||||||
(goto-char last)))
|
(if beg (setq beg nil arg (point))))
|
||||||
|
((looking-at ruby-operator-re)
|
||||||
|
(goto-char (match-end 0))
|
||||||
|
(if beg (setq beg nil arg (match-end 0))))
|
||||||
|
((not (eq (char-syntax (char-after)) ?\())
|
||||||
|
(setq start (point)))))
|
||||||
|
(goto-char (or arg start)))))
|
||||||
|
|
||||||
(defun ruby-calculate-indent (&optional parse-start)
|
(defun ruby-calculate-indent (&optional parse-start)
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(beginning-of-line)
|
(beginning-of-line)
|
||||||
(let ((indent-point (point))
|
(let ((indent-point (point))
|
||||||
(case-fold-search nil)
|
(case-fold-search nil)
|
||||||
state bol eol
|
state bol eol begin
|
||||||
(paren (progn (skip-syntax-forward " ")
|
(paren (progn (skip-syntax-forward " ")
|
||||||
(and (char-after) (matching-paren (char-after)))))
|
(and (char-after) (matching-paren (char-after)))))
|
||||||
(indent 0))
|
(indent 0))
|
||||||
@ -587,51 +593,47 @@ The variable ruby-indent-level controls the amount of indentation.
|
|||||||
(cond
|
(cond
|
||||||
((nth 0 state) ; within string
|
((nth 0 state) ; within string
|
||||||
(setq indent nil)) ; do nothing
|
(setq indent nil)) ; do nothing
|
||||||
((and (car (nth 1 state)) ; in paren
|
((car (nth 1 state)) ; in paren
|
||||||
(or (not (eq (car (nth 1 state)) ?\{))
|
(cond
|
||||||
(save-excursion
|
((and (eq (car (nth 1 state)) ?\{) ; brace block
|
||||||
(goto-char (1- (cdr (nth 1 state))))
|
(save-excursion
|
||||||
(or (ruby-expr-beg) (setq paren nil)))))
|
(goto-char (1- (cdr (nth 1 state))))
|
||||||
(goto-char (cdr (nth 1 state)))
|
(not (ruby-expr-beg))))
|
||||||
(if (ruby-deep-indent-paren-p (car (nth 1 state)))
|
(setq paren nil)
|
||||||
(let ((s (ruby-parse-region (point) indent-point)))
|
(back-to-indentation)
|
||||||
(cond
|
(setq indent (ruby-indent-size (current-column) (nth 2 state))))
|
||||||
((and (nth 2 s) (> (nth 2 s) 0))
|
(t
|
||||||
(goto-char (cdr (nth 1 s)))
|
(goto-char (setq begin (cdr (nth 1 state))))
|
||||||
(forward-word -1)
|
(let ((deep (ruby-deep-indent-paren-p (car (nth 1 state)))))
|
||||||
(setq indent (ruby-indent-size (current-column) (nth 2 state))))
|
(if deep
|
||||||
(t
|
(cond ((and (eq deep t) (eq (car (nth 1 state)) paren))
|
||||||
(setq indent (current-column))
|
(skip-syntax-backward " ")
|
||||||
(cond (paren (setq indent (1- indent)))
|
(setq indent (1- (current-column))))
|
||||||
((eq (car (nth 1 state)) ?\())
|
((let ((s (ruby-parse-region (point) indent-point)))
|
||||||
(t (setq indent (ruby-indent-size (1- indent) 1)))))))
|
(and (nth 2 s) (> (nth 2 s) 0)
|
||||||
(cond
|
(or (goto-char (cdr (nth 1 s))) t)))
|
||||||
((nth 3 state)
|
(forward-word -1)
|
||||||
(goto-char (nth 3 state))
|
(setq indent (ruby-indent-size (current-column) (nth 2 state))))
|
||||||
(setq indent (ruby-indent-size (current-column) (nth 2 state))))
|
(t
|
||||||
(t
|
(setq indent (current-column))
|
||||||
(goto-char parse-start)
|
(cond ((eq deep 'space))
|
||||||
(back-to-indentation)
|
(paren (setq indent (1- indent)))
|
||||||
(setq indent (ruby-indent-size (current-column) (nth 2 state)))))
|
(t (setq indent (ruby-indent-size (1- indent) 1))))))
|
||||||
))
|
(if (nth 3 state) (goto-char (nth 3 state))
|
||||||
((and (nth 2 state)(> (nth 2 state) 0)) ; in nest
|
(goto-char parse-start) (back-to-indentation))
|
||||||
|
(setq indent (ruby-indent-size (current-column) (nth 2 state))))))))
|
||||||
|
((and (nth 2 state) (> (nth 2 state) 0)) ; in nest
|
||||||
(if (null (cdr (nth 1 state)))
|
(if (null (cdr (nth 1 state)))
|
||||||
(error "invalid nest"))
|
(error "invalid nest"))
|
||||||
(goto-char (cdr (nth 1 state)))
|
(goto-char (cdr (nth 1 state)))
|
||||||
(forward-word -1) ; skip back a keyword
|
(forward-word -1) ; skip back a keyword
|
||||||
|
(setq begin (point))
|
||||||
(cond
|
(cond
|
||||||
((looking-at "do\\>[^_]") ; iter block is a special case
|
((looking-at "do\\>[^_]") ; iter block is a special case
|
||||||
(cond
|
(if (nth 3 state) (goto-char (nth 3 state))
|
||||||
((nth 3 state)
|
(goto-char parse-start) (back-to-indentation))
|
||||||
(goto-char (nth 3 state))
|
(setq indent (ruby-indent-size (current-column) (nth 2 state))))
|
||||||
(setq indent (ruby-indent-size (current-column) (nth 2 state))))
|
|
||||||
(t
|
|
||||||
(goto-char parse-start)
|
|
||||||
(back-to-indentation)
|
|
||||||
(setq indent (ruby-indent-size (current-column) (nth 2 state))))))
|
|
||||||
(t
|
(t
|
||||||
(goto-char (1- (cdr (nth 1 state))))
|
|
||||||
(ruby-backward-sexp)
|
|
||||||
(setq indent (+ (current-column) ruby-indent-level)))))
|
(setq indent (+ (current-column) ruby-indent-level)))))
|
||||||
|
|
||||||
((and (nth 2 state) (< (nth 2 state) 0)) ; in negative nest
|
((and (nth 2 state) (< (nth 2 state) 0)) ; in negative nest
|
||||||
@ -652,7 +654,8 @@ The variable ruby-indent-level controls the amount of indentation.
|
|||||||
(save-excursion
|
(save-excursion
|
||||||
(beginning-of-line)
|
(beginning-of-line)
|
||||||
(not (bobp)))
|
(not (bobp)))
|
||||||
(null (car (nth 1 state))))
|
(or (ruby-deep-indent-paren-p t)
|
||||||
|
(null (car (nth 1 state)))))
|
||||||
;; goto beginning of non-empty no-comment line
|
;; goto beginning of non-empty no-comment line
|
||||||
(let (end done)
|
(let (end done)
|
||||||
(while (not done)
|
(while (not done)
|
||||||
@ -673,6 +676,7 @@ The variable ruby-indent-level controls the amount of indentation.
|
|||||||
(and
|
(and
|
||||||
(setq state (ruby-parse-region parse-start (point)))
|
(setq state (ruby-parse-region parse-start (point)))
|
||||||
(nth 0 state)
|
(nth 0 state)
|
||||||
|
(setq begin (nth 1 state))
|
||||||
(goto-char pos)))
|
(goto-char pos)))
|
||||||
(or (bobp) (forward-char -1))
|
(or (bobp) (forward-char -1))
|
||||||
(and
|
(and
|
||||||
@ -684,8 +688,7 @@ The variable ruby-indent-level controls the amount of indentation.
|
|||||||
(goto-char (match-end 0))
|
(goto-char (match-end 0))
|
||||||
(not (looking-at "[a-z_]"))))
|
(not (looking-at "[a-z_]"))))
|
||||||
(and (looking-at ruby-operator-re)
|
(and (looking-at ruby-operator-re)
|
||||||
(not (eq (char-after (1- (point))) ??))
|
(not (ruby-special-char-p))
|
||||||
(not (eq (char-after (1- (point))) ?$))
|
|
||||||
(or (not (eq ?/ (char-after (point))))
|
(or (not (eq ?/ (char-after (point))))
|
||||||
(null (nth 0 (ruby-parse-region parse-start (point)))))
|
(null (nth 0 (ruby-parse-region parse-start (point)))))
|
||||||
(or (not (eq ?| (char-after (point))))
|
(or (not (eq ?| (char-after (point))))
|
||||||
@ -706,9 +709,9 @@ The variable ruby-indent-level controls the amount of indentation.
|
|||||||
(cond
|
(cond
|
||||||
((and
|
((and
|
||||||
(not (looking-at ruby-block-hanging-re))
|
(not (looking-at ruby-block-hanging-re))
|
||||||
(ruby-deep-indent-paren-p t)
|
(eq (ruby-deep-indent-paren-p t) 'space)
|
||||||
(not (bobp)))
|
(not (bobp)))
|
||||||
(ruby-backward-arg (cdr (nth 1 state)) (nth 2 state))
|
(ruby-beginning-of-arg (or begin parse-start) (point))
|
||||||
(current-column))
|
(current-column))
|
||||||
(t
|
(t
|
||||||
(+ indent ruby-indent-level))))))))
|
(+ indent ruby-indent-level))))))))
|
||||||
@ -799,64 +802,81 @@ An end of a defun is found by moving forward from the beginning of one."
|
|||||||
(interactive "p")
|
(interactive "p")
|
||||||
(if (and (numberp cnt) (< cnt 0))
|
(if (and (numberp cnt) (< cnt 0))
|
||||||
(ruby-backward-sexp (- cnt))
|
(ruby-backward-sexp (- cnt))
|
||||||
(dotimes (i (or cnt 1))
|
(let ((i (or cnt 1)))
|
||||||
(skip-chars-forward " \t\n,.:;|&^~=!?\\+\\-\\*")
|
(condition-case nil
|
||||||
(cond ((looking-at "\\s(")
|
(while (> i 0)
|
||||||
(goto-char (scan-sexps (point) 1)))
|
(skip-syntax-forward " ")
|
||||||
((looking-at ruby-block-beg-re)
|
(cond ((looking-at "\\?\\(\\\\[CM]-\\)*\\\\?\\S ")
|
||||||
(ruby-end-of-block)
|
(goto-char (match-end 0)))
|
||||||
(forward-word 1))
|
((progn
|
||||||
((looking-at "\\(\\$\\|@@?\\)?\\sw")
|
(skip-chars-forward ",.:;|&^~=!?\\+\\-\\*")
|
||||||
(while (progn
|
(looking-at "\\s("))
|
||||||
(while (progn (forward-word 1) (looking-at "_")))
|
(goto-char (scan-sexps (point) 1)))
|
||||||
(cond ((looking-at "::") (forward-char 2) t)
|
((looking-at ruby-block-beg-re)
|
||||||
((> (skip-chars-forward ".") 0))
|
(ruby-end-of-block)
|
||||||
((looking-at "\\?\\|!\\(=[~=>]\\|[^~=]\\)")
|
(forward-word 1))
|
||||||
(forward-char 1) nil)))))
|
((looking-at "\\(\\$\\|@@?\\)?\\sw")
|
||||||
((let (state expr)
|
(while (progn
|
||||||
(while
|
(while (progn (forward-word 1) (looking-at "_")))
|
||||||
(progn
|
(cond ((looking-at "::") (forward-char 2) t)
|
||||||
(setq expr (or expr (ruby-expr-beg)
|
((> (skip-chars-forward ".") 0))
|
||||||
(looking-at "%\\sw?\\Sw\\|[\"'`/]")))
|
((looking-at "\\?\\|!\\(=[~=>]\\|[^~=]\\)")
|
||||||
(nth 1 (setq state (apply 'ruby-parse-partial nil state))))
|
(forward-char 1) nil)))))
|
||||||
(setq expr t)
|
((let (state expr)
|
||||||
(skip-chars-forward "<"))
|
(while
|
||||||
(not expr)))))))
|
(progn
|
||||||
|
(setq expr (or expr (ruby-expr-beg)
|
||||||
|
(looking-at "%\\sw?\\Sw\\|[\"'`/]")))
|
||||||
|
(nth 1 (setq state (apply 'ruby-parse-partial nil state))))
|
||||||
|
(setq expr t)
|
||||||
|
(skip-chars-forward "<"))
|
||||||
|
(not expr))))
|
||||||
|
(setq i (1- i)))
|
||||||
|
((error) (forward-word)))
|
||||||
|
i)))
|
||||||
|
|
||||||
(defun-region-command ruby-backward-sexp (&optional cnt)
|
(defun-region-command ruby-backward-sexp (&optional cnt)
|
||||||
(interactive "p")
|
(interactive "p")
|
||||||
(dotimes (i (or cnt 1))
|
(if (and (numberp cnt) (< cnt 0))
|
||||||
(skip-chars-backward " \t\n,.:;|&^~=!?\\+\\-\\*")
|
(ruby-forward-sexp (- cnt))
|
||||||
(forward-char -1)
|
(let ((i (or cnt 1)))
|
||||||
(cond ((looking-at "\\s)")
|
(condition-case nil
|
||||||
(goto-char (scan-sexps (1+ (point)) -1))
|
(while (> i 0)
|
||||||
(case (char-before)
|
(skip-chars-backward " \t\n,.:;|&^~=!?\\+\\-\\*")
|
||||||
(?% (forward-char -1))
|
(forward-char -1)
|
||||||
('(?q ?Q ?w ?W ?r ?x)
|
(cond ((looking-at "\\s)")
|
||||||
(if (eq (char-before (1- (point))) ?%) (forward-char -2))))
|
(goto-char (scan-sexps (1+ (point)) -1))
|
||||||
nil)
|
(case (char-before)
|
||||||
((looking-at "\\s\"\\|\\\\\\S_")
|
(?% (forward-char -1))
|
||||||
(let ((c (char-to-string (char-before (match-end 0)))))
|
('(?q ?Q ?w ?W ?r ?x)
|
||||||
(while (and (search-backward c)
|
(if (eq (char-before (1- (point))) ?%) (forward-char -2))))
|
||||||
(oddp (skip-chars-backward "\\")))))
|
nil)
|
||||||
nil)
|
((looking-at "\\s\"\\|\\\\\\S_")
|
||||||
((looking-at "\\s.\\|\\s\\"))
|
(let ((c (char-to-string (char-before (match-end 0)))))
|
||||||
((looking-at "\\s(") nil)
|
(while (and (search-backward c)
|
||||||
(t
|
(oddp (skip-chars-backward "\\")))))
|
||||||
(forward-char 1)
|
nil)
|
||||||
(while (progn (forward-word -1)
|
((looking-at "\\s.\\|\\s\\")
|
||||||
(case (char-before)
|
(if (ruby-special-char-p) (forward-char -1)))
|
||||||
(?_ t)
|
((looking-at "\\s(") nil)
|
||||||
(?. (forward-char -1) t)
|
(t
|
||||||
((?$ ?@)
|
(forward-char 1)
|
||||||
(forward-char -1)
|
(while (progn (forward-word -1)
|
||||||
(and (eq (char-before) (char-after)) (forward-char -1)))
|
(case (char-before)
|
||||||
(?:
|
(?_ t)
|
||||||
(forward-char -1)
|
(?. (forward-char -1) t)
|
||||||
(eq (char-before) :)))))
|
((?$ ?@)
|
||||||
(if (looking-at ruby-block-end-re)
|
(forward-char -1)
|
||||||
(ruby-beginning-of-block))
|
(and (eq (char-before) (char-after)) (forward-char -1)))
|
||||||
nil))))
|
(?:
|
||||||
|
(forward-char -1)
|
||||||
|
(eq (char-before) :)))))
|
||||||
|
(if (looking-at ruby-block-end-re)
|
||||||
|
(ruby-beginning-of-block))
|
||||||
|
nil))
|
||||||
|
(setq i (1- i)))
|
||||||
|
((error)))
|
||||||
|
i)))
|
||||||
|
|
||||||
(defun ruby-reindent-then-newline-and-indent ()
|
(defun ruby-reindent-then-newline-and-indent ()
|
||||||
(interactive "*")
|
(interactive "*")
|
||||||
@ -1097,7 +1117,11 @@ balanced expression is found."
|
|||||||
2 font-lock-reference-face)
|
2 font-lock-reference-face)
|
||||||
;; expression expansion
|
;; expression expansion
|
||||||
'("#\\({[^}\n\\\\]*\\(\\\\.[^}\n\\\\]*\\)*}\\|\\(\\$\\|@\\|@@\\)\\(\\w\\|_\\)+\\)"
|
'("#\\({[^}\n\\\\]*\\(\\\\.[^}\n\\\\]*\\)*}\\|\\(\\$\\|@\\|@@\\)\\(\\w\\|_\\)+\\)"
|
||||||
0 font-lock-variable-name-face t))
|
0 font-lock-variable-name-face t)
|
||||||
|
;; warn lower camel case
|
||||||
|
;'("\\<[a-z]+[a-z0-9]*[A-Z][A-Za-z0-9]*\\([!?]?\\|\\>\\)"
|
||||||
|
; 0 font-lock-warning-face)
|
||||||
|
)
|
||||||
"*Additional expressions to highlight in ruby mode."))
|
"*Additional expressions to highlight in ruby mode."))
|
||||||
|
|
||||||
((featurep 'hilit19)
|
((featurep 'hilit19)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user