From 64ec09d45675fa8a12594c00b8b4acccf9960fce Mon Sep 17 00:00:00 2001 From: matz Date: Thu, 1 Apr 2004 23:13:39 +0000 Subject: * ext/socket/socket.c (make_hostent): fix memory leak, based on the patch from HORIKAWA Hisashi . git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6065 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- misc/ruby-mode.el | 314 ++++++++++++++++++++++++------------------------------ 1 file changed, 142 insertions(+), 172 deletions(-) (limited to 'misc/ruby-mode.el') diff --git a/misc/ruby-mode.el b/misc/ruby-mode.el index dac90ee1a2..1972003059 100644 --- a/misc/ruby-mode.el +++ b/misc/ruby-mode.el @@ -561,186 +561,156 @@ The variable ruby-indent-level controls the amount of indentation. (defun ruby-indent-size (pos nest) (+ pos (* (or nest 1) ruby-indent-level))) -;;; maybe obsolete -(defconst ruby-assign-re "\\s *\\(&&\\|||\\|<<\\|>>\\|[-+*/%&|^]\\)?=\\s *") - -;;; maybe obsolete -(defun ruby-beginning-of-arg (start end) - (save-restriction - (narrow-to-region start (1+ end)) - (goto-char start) - (let ((beg t) arg) - (while - (progn - (skip-chars-forward " \t\n") - (and (not (eobp)) - (= (ruby-forward-sexp) 0))) - (skip-syntax-forward " ") - (cond ((looking-at ",") - (forward-char) - (setq arg start beg t)) - ((ruby-expr-beg) t) - ((looking-at "=>\\s *") - (goto-char (match-end 0)) - (setq arg nil beg nil)) - ((looking-at ruby-assign-re) - (goto-char (match-end 0)) - (if beg (setq beg nil arg (point)))) - ((looking-at ruby-operator-re) - (goto-char (match-end 0)) - (echo "foo %s %s" arg beg) - (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) (save-excursion (beginning-of-line) (let ((indent-point (point)) - (case-fold-search nil) - state bol eol begin - (paren (progn (skip-syntax-forward " ") - (and (char-after) (matching-paren (char-after))))) - (indent 0)) - (if parse-start - (goto-char parse-start) - (ruby-beginning-of-indent) - (setq parse-start (point))) - (back-to-indentation) - (setq indent (current-column)) - (setq state (ruby-parse-region parse-start indent-point)) - (cond - ((nth 0 state) ; within string - (setq indent nil)) ; do nothing - ((car (nth 1 state)) ; in paren - (goto-char (setq begin (cdr (nth 1 state)))) - (let ((deep (ruby-deep-indent-paren-p (car (nth 1 state))))) - (if deep - (cond ((and (eq deep t) (eq (car (nth 1 state)) paren)) - (skip-syntax-backward " ") - (setq indent (1- (current-column)))) - ((let ((s (ruby-parse-region (point) indent-point))) - (and (nth 2 s) (> (nth 2 s) 0) - (or (goto-char (cdr (nth 1 s))) t))) - (forward-word -1) - (setq indent (ruby-indent-size (current-column) (nth 2 state)))) - (t - (setq indent (current-column)) - (cond ((eq deep 'space)) - (paren (setq indent (1- indent))) - (t (setq indent (ruby-indent-size (1- indent) 1)))))) - (if (nth 3 state) (goto-char (nth 3 state)) - (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))) - (error "invalid nest")) - (goto-char (cdr (nth 1 state))) - (forward-word -1) ; skip back a keyword - (setq begin (point)) - (cond - ((looking-at "do\\>[^_]") ; iter block is a special case + (case-fold-search nil) + state bol eol begin op-end + (paren (progn (skip-syntax-forward " ") + (and (char-after) (matching-paren (char-after))))) + (indent 0)) + (if parse-start + (goto-char parse-start) + (ruby-beginning-of-indent) + (setq parse-start (point))) + (back-to-indentation) + (setq indent (current-column)) + (setq state (ruby-parse-region parse-start indent-point)) + (cond + ((nth 0 state) ; within string + (setq indent nil)) ; do nothing + ((car (nth 1 state)) ; in paren + (goto-char (setq begin (cdr (nth 1 state)))) + (let ((deep (ruby-deep-indent-paren-p (car (nth 1 state))))) + (if deep + (cond ((and (eq deep t) (eq (car (nth 1 state)) paren)) + (skip-syntax-backward " ") + (setq indent (1- (current-column)))) + ((let ((s (ruby-parse-region (point) indent-point))) + (and (nth 2 s) (> (nth 2 s) 0) + (or (goto-char (cdr (nth 1 s))) t))) + (forward-word -1) + (setq indent (ruby-indent-size (current-column) (nth 2 state)))) + (t + (setq indent (current-column)) + (cond ((eq deep 'space)) + (paren (setq indent (1- indent))) + (t (setq indent (ruby-indent-size (1- indent) 1)))))) (if (nth 3 state) (goto-char (nth 3 state)) (goto-char parse-start) (back-to-indentation)) - (setq indent (ruby-indent-size (current-column) (nth 2 state)))) - (t - (setq indent (+ (current-column) ruby-indent-level))))) - - ((and (nth 2 state) (< (nth 2 state) 0)) ; in negative nest - (setq indent (ruby-indent-size (current-column) (nth 2 state))))) - (when indent - (goto-char indent-point) + (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))) + (error "invalid nest")) + (goto-char (cdr (nth 1 state))) + (forward-word -1) ; skip back a keyword + (setq begin (point)) + (cond + ((looking-at "do\\>[^_]") ; iter block is a special case + (if (nth 3 state) (goto-char (nth 3 state)) + (goto-char parse-start) (back-to-indentation)) + (setq indent (ruby-indent-size (current-column) (nth 2 state)))) + (t + (setq indent (+ (current-column) ruby-indent-level))))) + + ((and (nth 2 state) (< (nth 2 state) 0)) ; in negative nest + (setq indent (ruby-indent-size (current-column) (nth 2 state))))) + (when indent + (goto-char indent-point) + (end-of-line) + (setq eol (point)) + (beginning-of-line) + (cond + ((and (not (ruby-deep-indent-paren-p paren)) + (re-search-forward ruby-negative eol t)) + (and (not (eq ?_ (char-after (match-end 0)))) + (setq indent (- indent ruby-indent-level)))) + ((and + (save-excursion + (beginning-of-line) + (not (bobp))) + (or (ruby-deep-indent-paren-p t) + (null (car (nth 1 state))))) + ;; goto beginning of non-empty no-comment line + (let (end done) + (while (not done) + (skip-chars-backward " \t\n") + (setq end (point)) + (beginning-of-line) + (if (re-search-forward "^\\s *#" end t) + (beginning-of-line) + (setq done t)))) + (setq bol (point)) (end-of-line) - (setq eol (point)) - (beginning-of-line) - (cond - ((and (not (ruby-deep-indent-paren-p paren)) - (re-search-forward ruby-negative eol t)) - (and (not (eq ?_ (char-after (match-end 0)))) - (setq indent (- indent ruby-indent-level)))) - ;;operator terminated lines - ((and - (save-excursion - (beginning-of-line) - (not (bobp))) - (or (ruby-deep-indent-paren-p t) - (null (car (nth 1 state))))) - ;; goto beginning of non-empty no-comment line - (let (end done) - (while (not done) - (skip-chars-backward " \t\n") - (setq end (point)) - (beginning-of-line) - (if (re-search-forward "^\\s *#" end t) - (beginning-of-line) - (setq done t)))) - (setq bol (point)) - (end-of-line) + ;; skip the comment at the end + (skip-chars-backward " \t") + (let (end (pos (point))) + (beginning-of-line) + (while (and (re-search-forward "#" pos t) + (setq end (1- (point))) + (or (ruby-special-char-p end) + (and (setq state (ruby-parse-region parse-start end)) + (nth 0 state)))) + (setq end nil)) + (goto-char (or end pos)) (skip-chars-backward " \t") - (let (end (pos (point))) - (beginning-of-line) - (while (and (re-search-forward "#" pos t) - (setq end (1- (point))) - (ruby-special-char-p end)) - (setq end nil)) - (goto-char (or end pos)) - (skip-chars-backward " \t") - (setq state (ruby-parse-region parse-start (point))) - (setq begin (or (nth 0 state) (cdr (nth 1 state)))) - (goto-char pos)) - (or (bobp) (forward-char -1)) - (and - (or (and (looking-at ruby-symbol-re) - (skip-chars-backward ruby-symbol-chars) - (looking-at ruby-block-hanging-re) - (not (eq (point) (nth 3 state))) - (save-excursion - (goto-char (match-end 0)) - (not (looking-at "[a-z_]")))) - (and (looking-at ruby-operator-re) - (not (ruby-special-char-p)) - (let ((c (char-after (point)))) - (and - (or (not (eq ?, c)) - (null begin) - (save-excursion - (goto-char begin) - (skip-chars-forward " \t") - (not (or (eolp) (looking-at "#") - (and (eq (car (nth 1 state)) ?{) - (looking-at "|")))))) - (or (not (eq ?/ c)) - (null (nth 0 (ruby-parse-region (or begin parse-start) (point))))) - (or (not (eq ?| (char-after (point)))) - (save-excursion - (or (eolp) (forward-char -1)) - (cond - ((search-backward "|" nil t) - (skip-chars-backward " \t\n") - (and (not (eolp)) - (progn - (forward-char -1) - (not (looking-at "{"))) - (progn - (forward-word -1) - (not (looking-at "do\\>[^_]"))))) - (t t)))))))) - (setq indent - (cond - ((and - (not (looking-at ruby-block-hanging-re)) - (eq (ruby-deep-indent-paren-p t) 'space) - (not (bobp))) - (save-excursion - (widen) - (goto-char (or begin parse-start)) - (skip-syntax-forward " ") -;; (ruby-beginning-of-arg (or begin parse-start) (point)) - (current-column))) - (t - (+ indent ruby-indent-level)))))))) - indent))) + (setq begin (if (nth 0 state) pos (cdr (nth 1 state)))) + (setq state (ruby-parse-region parse-start (point)))) + (or (bobp) (forward-char -1)) + (and + (or (and (looking-at ruby-symbol-re) + (skip-chars-backward ruby-symbol-chars) + (looking-at ruby-block-hanging-re) + (not (eq (point) (nth 3 state))) + (save-excursion + (goto-char (match-end 0)) + (not (looking-at "[a-z_]")))) + (and (looking-at ruby-operator-re) + (not (ruby-special-char-p)) + ;; operator at the end of line + (let ((c (char-after (point)))) + (and +;; (or (null begin) +;; (save-excursion +;; (goto-char begin) +;; (skip-chars-forward " \t") +;; (not (or (eolp) (looking-at "#") +;; (and (eq (car (nth 1 state)) ?{) +;; (looking-at "|")))))) + (or (not (eq ?/ c)) + (null (nth 0 (ruby-parse-region (or begin parse-start) (point))))) + (or (not (eq ?| (char-after (point)))) + (save-excursion + (or (eolp) (forward-char -1)) + (cond + ((search-backward "|" nil t) + (skip-chars-backward " \t\n") + (and (not (eolp)) + (progn + (forward-char -1) + (not (looking-at "{"))) + (progn + (forward-word -1) + (not (looking-at "do\\>[^_]"))))) + (t t)))) + (not (eq ?, c)) + (setq op-end t))))) + (setq indent + (cond + ((and + (null op-end) + (not (looking-at ruby-block-hanging-re)) + (eq (ruby-deep-indent-paren-p t) 'space) + (not (bobp))) + (save-excursion + (widen) + (goto-char (or begin parse-start)) + (skip-syntax-forward " ") + (current-column))) + (t + (+ indent ruby-indent-level)))))))) + indent))) (defun ruby-electric-brace (arg) (interactive "P") -- cgit v1.2.3