From: Mike Shire Date: 2005-04-20T00:20:41+09:00 Subject: Re: emacs ruby-mode statement modifier indent problem? Mike Shire wrote: > Greetings, > > New to the list, and relatively new to Ruby and loving it. > > After updating ruby-mode (ruby-elisp1.8.2 using Debian apt-get and > emacs21) recently I'm having a problem with emacs indenting > incorrectly with statement modifiers. E.g. > > puts "foo" if foo > puts "next line is indented waaay out here" > > > An hours search revealed this fix from 2002: > http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/32352 > > I changed out the the elisp ruby-expr-beg function and that seemed to > solve that particular problem. However, the function I replaced I am > sure had been updated since this referenced post and I'm sure > replacing it has broken something else (and my elisp knowledge is > practically nil). > > Has anyone encountered this or has this been fixed elsewhere that I > can get it? > > Many thanks. > > mike! > Here is the code substitution that I made to ruby-mode.el that eliminates the statement modifier indentation problem (cut and paste from aforementioned post)... I apologise if this is not the proper place for this but in the hopes that someone with good elisp knowledge would happen to spot something obvious I thought it convenient to simply post them. ;; --- original function with broken statement modifier indent --- ;; (defun ruby-expr-beg (&optional option) ;; (save-excursion ;; (store-match-data nil) ;; (let ((start (point)) ;; (space (skip-chars-backward " \t"))) ;; (cond ;; ((bolp) t) ;; ((progn ;; (forward-char -1) ;; (and (looking-at "\\?") ;; (or (eq (char-syntax (char-before (point))) ?w) ;; (ruby-special-char-p)))) ;; nil) ;; ((or (goto-char start) ;; (looking-at ruby-operator-re) ;; (looking-at "[\\[({,;]") ;; (and (or (not (eq option 'heredoc)) ;; (< space 0)) ;; (looking-at "[!?]") ;; (or (not (eq option 'modifier)) ;; (bolp) ;; (save-excursion (forward-char -1) (looking-at "\\Sw")))) ;; (and (looking-at ruby-symbol-re) ;; (skip-chars-backward ruby-symbol-chars) ;; (cond ;; ((or (looking-at (concat "\\<\\(" ruby-block-beg-re ;; "|" ruby-block-op-re ;; "|" ruby-block-mid-re "\\)\\>"))) ;; (goto-char (match-end 0)) ;; (not (looking-at "\\s_"))) ;; ((eq option 'expr-qstr) ;; (looking-at "[a-zA-Z][a-zA-z0-9_]* +%[^ \t]")) ;; ((eq option 'expr-re) ;; (looking-at "[a-zA-Z][a-zA-z0-9_]* +/[^ \t]")) ;; (t nil))))))))) ;; --- reverted function that works --- (defun ruby-expr-beg (&optional option) (save-excursion (store-match-data nil) (skip-chars-backward " \t") (cond ((bolp) t) ((looking-at "\\?") (or (bolp) (forward-char -1)) (not (looking-at "\\sw"))) (t (forward-char -1) (or (looking-at ruby-operator-re) (looking-at "[\\[({,;]") (and (not (eq option 'modifier)) (looking-at "[!?]")) (and (looking-at ruby-symbol-re) (skip-chars-backward ruby-symbol-chars) (cond ((or (looking-at ruby-block-beg-re) (looking-at ruby-block-op-re) (looking-at ruby-block-mid-re)) (goto-char (match-end 0)) (looking-at "\\>")) ((eq option 'expr-qstr) (looking-at "[a-zA-Z][a-zA-z0-9_]* +%[^ \t]")) ((eq option 'expr-re) (looking-at "[a-zA-Z][a-zA-z0-9_]* +/[^ \t]")) (t nil))))))))