* misc/ruby-mode.el (ruby-delimiter): include here document.
* misc/ruby-mode.el (ruby-deep-arglist): skips spaces after parenthesis when 'space. * misc/ruby-mode.el (ruby-imenu-create-index): fix for nested classes. * misc/ruby-mode.el (ruby-accurate-end-of-block): added. scan a block in the order. * misc/ruby-mode.el (ruby-expr-beg): support for here document. * misc/ruby-mode.el (ruby-parse-partial): splitted from ruby-parse-region. * misc/ruby-mode.el (ruby-move-to-block): skips RD style comments. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
5fdec7d96b
commit
abfbbcf8e3
20
ChangeLog
20
ChangeLog
@ -1,3 +1,23 @@
|
|||||||
|
Thu Jul 25 09:05:02 2002 Nobuyoshi Nakada <nobu.nokada@softhome.net>
|
||||||
|
|
||||||
|
* misc/ruby-mode.el (ruby-delimiter): include here document.
|
||||||
|
|
||||||
|
* misc/ruby-mode.el (ruby-deep-arglist): skips spaces after
|
||||||
|
parenthesis when 'space.
|
||||||
|
|
||||||
|
* misc/ruby-mode.el (ruby-imenu-create-index): fix for nested
|
||||||
|
classes.
|
||||||
|
|
||||||
|
* misc/ruby-mode.el (ruby-accurate-end-of-block): added. scan a
|
||||||
|
block in the order.
|
||||||
|
|
||||||
|
* misc/ruby-mode.el (ruby-expr-beg): support for here document.
|
||||||
|
|
||||||
|
* misc/ruby-mode.el (ruby-parse-partial): splitted from
|
||||||
|
ruby-parse-region.
|
||||||
|
|
||||||
|
* misc/ruby-mode.el (ruby-move-to-block): skips RD style comments.
|
||||||
|
|
||||||
Thu Jul 18 11:52:02 2002 Shugo Maeda <shugo@ruby-lang.org>
|
Thu Jul 18 11:52:02 2002 Shugo Maeda <shugo@ruby-lang.org>
|
||||||
|
|
||||||
* lib/net/ftp.rb (set_socket): new method.
|
* lib/net/ftp.rb (set_socket): new method.
|
||||||
|
@ -48,7 +48,7 @@
|
|||||||
(defconst ruby-block-end-re "end")
|
(defconst ruby-block-end-re "end")
|
||||||
|
|
||||||
(defconst ruby-delimiter
|
(defconst ruby-delimiter
|
||||||
(concat "[?$/%(){}#\"'`.:]\\|\\[\\|\\]\\|\\<\\("
|
(concat "[?$/%(){}#\"'`.:]\\|<<\\|\\[\\|\\]\\|\\<\\("
|
||||||
ruby-block-beg-re
|
ruby-block-beg-re
|
||||||
"\\|" ruby-block-end-re
|
"\\|" ruby-block-end-re
|
||||||
"\\)\\>\\|^=begin")
|
"\\)\\>\\|^=begin")
|
||||||
@ -127,33 +127,54 @@
|
|||||||
"*Indentation of ruby statements.")
|
"*Indentation of ruby statements.")
|
||||||
|
|
||||||
(defvar ruby-deep-arglist t
|
(defvar ruby-deep-arglist t
|
||||||
"*Deep indent argument lists when non-nil.")
|
"*Deep indent argument lists when non-nil.
|
||||||
|
Also ignores spaces after parenthesis when 'space.")
|
||||||
|
|
||||||
(eval-when-compile (require 'cl))
|
(eval-when-compile (require 'cl))
|
||||||
(defun ruby-imenu-create-index ()
|
(defun ruby-imenu-create-index-in-block (prefix beg end)
|
||||||
(let ((index-alist '())
|
(let ((index-alist '()) (nest '()) (case-fold-search nil)
|
||||||
class-name class-begin method-name method-begin decl)
|
name next pos decl sing)
|
||||||
(goto-char (point-min))
|
(goto-char beg)
|
||||||
(while (re-search-forward "^\\s *\\(class\\|def\\)\\s *\\([^(\n ]+\\)" nil t)
|
(while (re-search-forward "^\\s *\\(\\(class\\>\\(\\s *<<\\)?\\|module\\>\\)\\s *\\([^\(<\n ]+\\)\\|\\(def\\|alias\\)\\>\\s *\\([^\(\n ]+\\)\\)" end t)
|
||||||
(setq decl (buffer-substring (match-beginning 1) (match-end 1)))
|
(setq sing (match-beginning 3))
|
||||||
|
(setq decl (match-string 5))
|
||||||
|
(setq next (match-end 0))
|
||||||
|
(setq name (or (match-string 4) (match-string 6)))
|
||||||
|
(setq pos (match-beginning 0))
|
||||||
(cond
|
(cond
|
||||||
((string= "class" decl)
|
((string= "alias" decl)
|
||||||
(setq class-begin (match-beginning 2))
|
(if prefix (setq name (concat prefix name)))
|
||||||
(setq class-name (buffer-substring class-begin (match-end 2)))
|
(push (cons name pos) index-alist))
|
||||||
(push (cons class-name (match-beginning 0)) index-alist)
|
|
||||||
(ruby-mark-defun)
|
|
||||||
(save-restriction
|
|
||||||
(narrow-to-region (region-beginning) (region-end))
|
|
||||||
(while (re-search-forward "^\\s *def\\s *\\([^(\n ]+\\)" nil 'move)
|
|
||||||
(setq method-begin (match-beginning 1))
|
|
||||||
(setq method-name (buffer-substring method-begin (match-end 1)))
|
|
||||||
(push (cons (concat class-name "#" method-name) (match-beginning 0)) index-alist))))
|
|
||||||
((string= "def" decl)
|
((string= "def" decl)
|
||||||
(setq method-begin (match-beginning 2))
|
(if prefix
|
||||||
(setq method-name (buffer-substring method-begin (match-end 2)))
|
(setq name
|
||||||
(push (cons method-name (match-beginning 0)) index-alist))))
|
(cond
|
||||||
|
((string-match "^self\." name)
|
||||||
|
(concat (substring prefix 0 -1) (substring name 4)))
|
||||||
|
(t (concat prefix name)))))
|
||||||
|
(push (cons name pos) index-alist)
|
||||||
|
(ruby-accurate-end-of-block))
|
||||||
|
(t
|
||||||
|
(if (string= "self" name)
|
||||||
|
(if prefix (setq name (substring prefix 0 -1)))
|
||||||
|
(if prefix (setq name (concat (substring prefix 0 -1) "::" name)))
|
||||||
|
(push (cons name pos) index-alist))
|
||||||
|
(ruby-accurate-end-of-block)
|
||||||
|
(setq beg (point))
|
||||||
|
(setq index-alist
|
||||||
|
(nconc (ruby-imenu-create-index-in-block
|
||||||
|
(concat name (if sing "." "#"))
|
||||||
|
next beg) index-alist))
|
||||||
|
(goto-char beg))))
|
||||||
index-alist))
|
index-alist))
|
||||||
|
|
||||||
|
(defun ruby-imenu-create-index ()
|
||||||
|
(nreverse (ruby-imenu-create-index-in-block nil (point-min) nil)))
|
||||||
|
|
||||||
|
(defun ruby-accurate-end-of-block ()
|
||||||
|
(let (state)
|
||||||
|
(while (>= (nth 2 (setq state (apply 'ruby-parse-partial end state))) 0))))
|
||||||
|
|
||||||
(defun ruby-mode-variables ()
|
(defun ruby-mode-variables ()
|
||||||
(set-syntax-table ruby-mode-syntax-table)
|
(set-syntax-table ruby-mode-syntax-table)
|
||||||
(setq local-abbrev-table ruby-mode-abbrev-table)
|
(setq local-abbrev-table ruby-mode-abbrev-table)
|
||||||
@ -239,7 +260,7 @@ The variable ruby-indent-level controls the amount of indentation.
|
|||||||
(defun ruby-expr-beg (&optional option)
|
(defun ruby-expr-beg (&optional option)
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(store-match-data nil)
|
(store-match-data nil)
|
||||||
(skip-chars-backward " \t")
|
(let ((space (skip-chars-backward " \t")))
|
||||||
(cond
|
(cond
|
||||||
((bolp) t)
|
((bolp) t)
|
||||||
((looking-at "\\?")
|
((looking-at "\\?")
|
||||||
@ -249,7 +270,9 @@ The variable ruby-indent-level controls the amount of indentation.
|
|||||||
(forward-char -1)
|
(forward-char -1)
|
||||||
(or (looking-at ruby-operator-re)
|
(or (looking-at ruby-operator-re)
|
||||||
(looking-at "[\\[({,;]")
|
(looking-at "[\\[({,;]")
|
||||||
(and (not (eq option 'modifier))
|
(and (or (eq option 'modifier)
|
||||||
|
(not (eq option 'heredoc))
|
||||||
|
(< space 0))
|
||||||
(looking-at "[!?]"))
|
(looking-at "[!?]"))
|
||||||
(and (looking-at ruby-symbol-re)
|
(and (looking-at ruby-symbol-re)
|
||||||
(skip-chars-backward ruby-symbol-chars)
|
(skip-chars-backward ruby-symbol-chars)
|
||||||
@ -263,7 +286,7 @@ The variable ruby-indent-level controls the amount of indentation.
|
|||||||
(looking-at "[a-zA-Z][a-zA-z0-9_]* +%[^ \t]"))
|
(looking-at "[a-zA-Z][a-zA-z0-9_]* +%[^ \t]"))
|
||||||
((eq option 'expr-re)
|
((eq option 'expr-re)
|
||||||
(looking-at "[a-zA-Z][a-zA-z0-9_]* +/[^ \t]"))
|
(looking-at "[a-zA-Z][a-zA-z0-9_]* +/[^ \t]"))
|
||||||
(t nil))))))))
|
(t nil)))))))))
|
||||||
|
|
||||||
(defun ruby-forward-string (term &optional end no-error expand)
|
(defun ruby-forward-string (term &optional end no-error expand)
|
||||||
(let ((n 1) (c (string-to-char term))
|
(let ((n 1) (c (string-to-char term))
|
||||||
@ -280,23 +303,10 @@ The variable ruby-indent-level controls the amount of indentation.
|
|||||||
(no-error nil)
|
(no-error nil)
|
||||||
(error "unterminated string"))))
|
(error "unterminated string"))))
|
||||||
|
|
||||||
(defun ruby-parse-region (start end)
|
(defun ruby-parse-partial (&optional end in-string nest depth pcol indent)
|
||||||
(let ((indent-point end)
|
|
||||||
(indent 0)
|
|
||||||
(in-string nil)
|
|
||||||
(in-paren nil)
|
|
||||||
(depth 0)
|
|
||||||
(nest nil)
|
|
||||||
(pcol nil))
|
|
||||||
(save-excursion
|
|
||||||
(if start
|
|
||||||
(goto-char start)
|
|
||||||
(ruby-beginning-of-indent))
|
|
||||||
(save-restriction
|
|
||||||
(narrow-to-region (point) end)
|
|
||||||
(while (and (> indent-point (point))
|
|
||||||
(re-search-forward ruby-delimiter indent-point t))
|
|
||||||
(or depth (setq depth 0))
|
(or depth (setq depth 0))
|
||||||
|
(or indent (setq indent 0))
|
||||||
|
(when (re-search-forward ruby-delimiter end 'move)
|
||||||
(let ((pnt (point)) w re expand)
|
(let ((pnt (point)) w re expand)
|
||||||
(goto-char (match-beginning 0))
|
(goto-char (match-beginning 0))
|
||||||
(cond
|
(cond
|
||||||
@ -304,26 +314,26 @@ The variable ruby-indent-level controls the amount of indentation.
|
|||||||
(looking-at "`"))
|
(looking-at "`"))
|
||||||
(cond
|
(cond
|
||||||
((and (not (eobp))
|
((and (not (eobp))
|
||||||
(ruby-forward-string (buffer-substring (point) (1+ (point))) indent-point t t))
|
(ruby-forward-string (buffer-substring (point) (1+ (point))) end t t))
|
||||||
nil)
|
nil)
|
||||||
(t
|
(t
|
||||||
(setq in-string (point))
|
(setq in-string (point))
|
||||||
(goto-char indent-point))))
|
(goto-char end))))
|
||||||
((looking-at "'")
|
((looking-at "'")
|
||||||
(cond
|
(cond
|
||||||
((and (not (eobp))
|
((and (not (eobp))
|
||||||
(re-search-forward "[^\\]\\(\\\\\\\\\\)*'" indent-point t))
|
(re-search-forward "[^\\]\\(\\\\\\\\\\)*'" end t))
|
||||||
nil)
|
nil)
|
||||||
(t
|
(t
|
||||||
(setq in-string (point))
|
(setq in-string (point))
|
||||||
(goto-char indent-point))))
|
(goto-char end))))
|
||||||
((looking-at "/")
|
((looking-at "/")
|
||||||
(cond
|
(cond
|
||||||
((and (not (eobp)) (ruby-expr-beg 'expr-re))
|
((and (not (eobp)) (ruby-expr-beg 'expr-re))
|
||||||
(if (ruby-forward-string "/" indent-point t t)
|
(if (ruby-forward-string "/" end t t)
|
||||||
nil
|
nil
|
||||||
(setq in-string (point))
|
(setq in-string (point))
|
||||||
(goto-char indent-point)))
|
(goto-char end)))
|
||||||
(t
|
(t
|
||||||
(goto-char pnt))))
|
(goto-char pnt))))
|
||||||
((looking-at "%")
|
((looking-at "%")
|
||||||
@ -331,34 +341,32 @@ The variable ruby-indent-level controls the amount of indentation.
|
|||||||
((and (not (eobp))
|
((and (not (eobp))
|
||||||
(ruby-expr-beg 'expr-qstr)
|
(ruby-expr-beg 'expr-qstr)
|
||||||
(not (looking-at "%="))
|
(not (looking-at "%="))
|
||||||
(looking-at "%[Qqrxw]?\\(.\\)"))
|
(looking-at "%[QqrxWw]?\\(.\\)"))
|
||||||
(goto-char (match-beginning 1))
|
(goto-char (match-beginning 1))
|
||||||
(setq expand (not (eq (char-before) ?q)))
|
(setq expand (not (memq (char-before) '(?q ?w))))
|
||||||
(setq w (buffer-substring (match-beginning 1)
|
(setq w (match-string 1))
|
||||||
(match-end 1)))
|
|
||||||
(cond
|
(cond
|
||||||
((string= w "[") (setq re "]["))
|
((string= w "[") (setq re "]["))
|
||||||
((string= w "{") (setq re "}{"))
|
((string= w "{") (setq re "}{"))
|
||||||
((string= w "(") (setq re ")("))
|
((string= w "(") (setq re ")("))
|
||||||
((string= w "<") (setq re "><"))
|
((string= w "<") (setq re "><"))
|
||||||
((or (and expand (string= w "\\"))
|
((and expand (string= w "\\"))
|
||||||
(member w '("*" "." "+" "?" "^" "$")))
|
|
||||||
(setq w (concat "\\" w))))
|
(setq w (concat "\\" w))))
|
||||||
(unless (cond (re (ruby-forward-string re indent-point t expand))
|
(unless (cond (re (ruby-forward-string re end t expand))
|
||||||
(expand (ruby-forward-string w indent-point t t))
|
(expand (ruby-forward-string w end t t))
|
||||||
(t (re-search-forward
|
(t (re-search-forward
|
||||||
(if (string= w "\\")
|
(if (string= w "\\")
|
||||||
"\\\\[^\\]*\\\\"
|
"\\\\[^\\]*\\\\"
|
||||||
(concat "[^\\]\\(\\\\\\\\\\)*" w))
|
(concat "[^\\]\\(\\\\\\\\\\)*" w))
|
||||||
indent-point t)))
|
end t)))
|
||||||
(setq in-string (point))
|
(setq in-string (point))
|
||||||
(goto-char indent-point)))
|
(goto-char end)))
|
||||||
(t
|
(t
|
||||||
(goto-char pnt))))
|
(goto-char pnt))))
|
||||||
((looking-at "\\?") ;skip ?char
|
((looking-at "\\?") ;skip ?char
|
||||||
(cond
|
(cond
|
||||||
((ruby-expr-beg)
|
((and (ruby-expr-beg)
|
||||||
(looking-at "?\\(\\\\C-\\|\\\\M-\\)*.")
|
(looking-at "?\\(\\\\C-\\|\\\\M-\\)*."))
|
||||||
(goto-char (match-end 0)))
|
(goto-char (match-end 0)))
|
||||||
(t
|
(t
|
||||||
(goto-char pnt))))
|
(goto-char pnt))))
|
||||||
@ -370,6 +378,8 @@ The variable ruby-indent-level controls the amount of indentation.
|
|||||||
(goto-char (point))
|
(goto-char (point))
|
||||||
)
|
)
|
||||||
((and (looking-at "(") ruby-deep-arglist)
|
((and (looking-at "(") ruby-deep-arglist)
|
||||||
|
(and (eq ruby-deep-arglist 'space) (looking-at ".\\s +")
|
||||||
|
(setq pnt (match-end 0)))
|
||||||
(setq nest (cons (cons (char-after (point)) pnt) nest))
|
(setq nest (cons (cons (char-after (point)) pnt) nest))
|
||||||
(setq pcol (cons (cons pnt depth) pcol))
|
(setq pcol (cons (cons pnt depth) pcol))
|
||||||
(setq depth 0)
|
(setq depth 0)
|
||||||
@ -443,21 +453,52 @@ The variable ruby-indent-level controls the amount of indentation.
|
|||||||
(goto-char pnt))
|
(goto-char pnt))
|
||||||
((looking-at ":\\([a-zA-Z_][a-zA-Z_0-9]*\\)?")
|
((looking-at ":\\([a-zA-Z_][a-zA-Z_0-9]*\\)?")
|
||||||
(goto-char (match-end 0)))
|
(goto-char (match-end 0)))
|
||||||
((or (looking-at "\\.")
|
((or (looking-at "\\.\\.\\.?")
|
||||||
(looking-at "\\.\\.\\.?")
|
|
||||||
(looking-at "\\.[0-9]+")
|
(looking-at "\\.[0-9]+")
|
||||||
(looking-at "\\.[a-zA-Z_0-9]+"))
|
(looking-at "\\.[a-zA-Z_0-9]+")
|
||||||
|
(looking-at "\\."))
|
||||||
(goto-char (match-end 0)))
|
(goto-char (match-end 0)))
|
||||||
((looking-at "^=begin")
|
((looking-at "^=begin")
|
||||||
(if (re-search-forward "^=end" indent-point t)
|
(if (re-search-forward "^=end" end t)
|
||||||
(forward-line 1)
|
(forward-line 1)
|
||||||
(setq in-string (match-end 0))
|
(setq in-string (match-end 0))
|
||||||
(goto-char indent-point)))
|
(goto-char end)))
|
||||||
|
((looking-at "<<")
|
||||||
|
(cond
|
||||||
|
((and (ruby-expr-beg 'heredoc)
|
||||||
|
(looking-at "<<\\(-\\)?\\(\\([\"'`]\\)\\([^\n]+?\\)\\3\\|\\sw+\\)"))
|
||||||
|
(setq re (regexp-quote (or (match-string 4) (match-string 2))))
|
||||||
|
(if (match-beginning 1) (setq re (concat "\\s *" re)))
|
||||||
|
(if (re-search-forward (concat "^" re "$") end 'move)
|
||||||
|
(forward-line 1)
|
||||||
|
(setq in-string (match-end 0))
|
||||||
|
(goto-char end)))
|
||||||
|
(t
|
||||||
|
(goto-char pnt))))
|
||||||
|
((looking-at "^__END__$")
|
||||||
|
(goto-char pnt))
|
||||||
(t
|
(t
|
||||||
(error (format "bad string %s"
|
(error (format "bad string %s"
|
||||||
(buffer-substring (point) pnt)
|
(buffer-substring (point) pnt)
|
||||||
)))))))
|
))))))
|
||||||
(list in-string (car nest) depth (car (car pcol))))))
|
(list in-string nest depth pcol))
|
||||||
|
|
||||||
|
(defun ruby-parse-region (start end)
|
||||||
|
(let (state)
|
||||||
|
(save-excursion
|
||||||
|
(if start
|
||||||
|
(goto-char start)
|
||||||
|
(ruby-beginning-of-indent))
|
||||||
|
(save-restriction
|
||||||
|
(narrow-to-region (point) end)
|
||||||
|
(while (and (> end (point))
|
||||||
|
(setq state (apply 'ruby-parse-partial end state))))))
|
||||||
|
(list (nth 0 state) ; in-string
|
||||||
|
(car (nth 1 state)) ; nest
|
||||||
|
(nth 2 state) ; depth
|
||||||
|
(car (car (nth 3 state))) ; pcol
|
||||||
|
;(car (nth 5 state)) ; indent
|
||||||
|
)))
|
||||||
|
|
||||||
(defun ruby-indent-size (pos nest)
|
(defun ruby-indent-size (pos nest)
|
||||||
(+ pos (* (if nest nest 1) ruby-indent-level)))
|
(+ pos (* (if nest nest 1) ruby-indent-level)))
|
||||||
@ -627,13 +668,16 @@ An end of a defun is found by moving forward from the beginning of one."
|
|||||||
(defun ruby-move-to-block (n)
|
(defun ruby-move-to-block (n)
|
||||||
(let (start pos done down)
|
(let (start pos done down)
|
||||||
(setq start (ruby-calculate-indent))
|
(setq start (ruby-calculate-indent))
|
||||||
(if (eobp)
|
(setq down (looking-at (if (< n 0) ruby-block-end-re ruby-block-beg-re)))
|
||||||
nil
|
(while (and (not done) (not (if (< n 0) (bobp) (eobp))))
|
||||||
(while (and (not (bobp)) (not (eobp)) (not done))
|
|
||||||
(forward-line n)
|
(forward-line n)
|
||||||
(cond
|
(cond
|
||||||
((looking-at "^$"))
|
((looking-at "^\\s *$"))
|
||||||
((looking-at "^\\s *#"))
|
((looking-at "^\\s *#"))
|
||||||
|
((and (> n 0) (looking-at "^=begin\\>"))
|
||||||
|
(re-search-forward "^=end\\>"))
|
||||||
|
((and (< n 0) (looking-at "^=end\\>"))
|
||||||
|
(re-search-backward "^=begin\\>"))
|
||||||
(t
|
(t
|
||||||
(setq pos (current-indentation))
|
(setq pos (current-indentation))
|
||||||
(cond
|
(cond
|
||||||
@ -647,7 +691,7 @@ An end of a defun is found by moving forward from the beginning of one."
|
|||||||
(progn
|
(progn
|
||||||
(back-to-indentation)
|
(back-to-indentation)
|
||||||
(if (looking-at ruby-block-mid-re)
|
(if (looking-at ruby-block-mid-re)
|
||||||
(setq done nil)))))))
|
(setq done nil))))))
|
||||||
(back-to-indentation))
|
(back-to-indentation))
|
||||||
|
|
||||||
(defun ruby-beginning-of-block ()
|
(defun ruby-beginning-of-block ()
|
||||||
@ -706,8 +750,7 @@ An end of a defun is found by moving forward from the beginning of one."
|
|||||||
"\\(" ruby-symbol-re "+\\)")
|
"\\(" ruby-symbol-re "+\\)")
|
||||||
nil t)
|
nil t)
|
||||||
(progn
|
(progn
|
||||||
(setq mlist (list (buffer-substring
|
(setq mlist (list (match-string 2)))
|
||||||
(match-beginning 2) (match-end 2))))
|
|
||||||
(goto-char (match-beginning 1))
|
(goto-char (match-beginning 1))
|
||||||
(setq indent (current-column))
|
(setq indent (current-column))
|
||||||
(beginning-of-line)))
|
(beginning-of-line)))
|
||||||
@ -721,9 +764,7 @@ An end of a defun is found by moving forward from the beginning of one."
|
|||||||
(goto-char (match-beginning 1))
|
(goto-char (match-beginning 1))
|
||||||
(if (< (current-column) indent)
|
(if (< (current-column) indent)
|
||||||
(progn
|
(progn
|
||||||
(setq mlist
|
(setq mlist (cons (match-string 2) mlist))
|
||||||
(cons (buffer-substring
|
|
||||||
(match-beginning 2) (match-end 2)) mlist))
|
|
||||||
(setq indent (current-column))
|
(setq indent (current-column))
|
||||||
(beginning-of-line))))
|
(beginning-of-line))))
|
||||||
;; generate string
|
;; generate string
|
||||||
|
Loading…
x
Reference in New Issue
Block a user