[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Coding assistance for Emacs

Tassilo Horn

10/4/2004 10:01:00 AM

Hi,

I'm doing my first stept with Ruby now. I really enjoy it. But I'm
missing some editor assistance.

I use Ruby 1.8.2 preview2, Emacs, ruby-mode.el 1.74, inf-ruby.el.

How can I get code completion and other fancy things making coding
faster?

On ruby-lang.org I've found rtags which perhaps could be something I'm
looking for. Is it included in the current CVS Ruby or do I have to get
it elsewhere?

And is there any documentation for inf-ruby/ruby-mode beside the
sources?

Much thanks in advance,

Tassilo
--
If riding in an airplane is flying, then riding in a boat is swimming.
If you want to experience the element, then get out of the vehicle
- SKYDIVE! <http://www.fsc...
7 Answers

Alan Chen

10/4/2004 8:58:00 PM

0

One useful key combo is M-/ (i think that's the default mapping). It
maps to dabbrev-expand. This is just a built in to emacs and just
searches your open buffers for sane expansions. The algorithm ends up
selecting the correct expansion. Hitting it repeatedly goes through
multiple options.

To search the TAG file you hit M-. (find-tag). I've never tried rtag (I
have used exuberant ctags to generate ruby and other language tag
files)

More instructions are available for a specific command if you hit M-h k
(describe-key) then the key sequence you want help on.

Cheers,
-alan

Brian Schröder

10/4/2004 9:10:00 PM

0

Tassilo Horn wrote:
> Hi,
>
> I'm doing my first stept with Ruby now. I really enjoy it. But I'm
> missing some editor assistance.
>
> I use Ruby 1.8.2 preview2, Emacs, ruby-mode.el 1.74, inf-ruby.el.
>
> How can I get code completion and other fancy things making coding
> faster?
>
> On ruby-lang.org I've found rtags which perhaps could be something I'm
> looking for. Is it included in the current CVS Ruby or do I have to get
> it elsewhere?
>
> And is there any documentation for inf-ruby/ruby-mode beside the
> sources?
>
> Much thanks in advance,
>
> Tassilo

My ruby xemacs setup. Has hide-show of functions [f4,f5,f6,f7]
automatically chmod +x, ruby-xmp [m-f10], ri lookup of keyword at point
[f1]. And some more.

Regards,

Brian


(require 'ruby-mode)
;;; Execute Ruby Command with f3
(define-key ruby-mode-map [f3] 'ruby-load-file)

(defun ruby-xmp-region (reg-start reg-end)
"Pipe the region through Ruby's xmp utility and replace the region
with the result."
(interactive "r")
(shell-command-on-region reg-start reg-end
"ruby -r xmp -n -e 'xmp($_, \"%l\t\t# %r\n\")'" t))

(global-set-key [(meta f10)] 'ruby-xmp-region)


(defun ruby-custom-setup ()
(add-to-list 'hs-special-modes-alist
'(ruby-mode
"\\(def\\|do\\)"
"end"
"#"
(lambda (arg) (ruby-end-of-block))
nil
))
(hs-minor-mode t)
)

(add-hook 'ruby-mode-hook
'(lambda ()
(define-key ruby-mode-map "\M-q" 'jw-rb-fill-comment-region) ))

(add-hook 'ruby-mode-hook 'ruby-custom-setup)

; Chmod of scripts to u+x
(add-hook 'after-save-hook
'(lambda ()
(progn
(and (save-excursion
(save-restriction
(widen)
(goto-char (point-min))
(save-match-data
(looking-at "^#!"))))
(shell-command (concat "chmod u+x " buffer-file-name))
(message (concat "Saved as script: " buffer-file-name))
))))

;JeffreyRadcliffe -- Here is a method which calls the interpreter on the
entire buffer, putting the output in another window:
(defun ruby-eval-buffer () (interactive)
"Evaluate the buffer with ruby."
(shell-command-on-region (point-min) (point-max) "ruby"))

(defun ruby-xmp-region (reg-start reg-end)
"Pipe the region through Ruby's xmp utility and replace
the region with the result."
;PragDave -- This li'l beaut runs Gotoken's xmp processor on a region.
This adds the results of evaluating each line to the end of that line.
It's how I add values to code examples in my e-mail. Here it's bound to
M-F10
(interactive "r")
(shell-command-on-region reg-start reg-end
"ruby -r xmp -n -e 'xmp($_, \"%l\t\t# %r\n\")'" t))

(global-set-key [(control f10)] 'ruby-xmp-region)

(global-set-key [dead-tilde] "~")

(setq ri-ruby-script "/home/bschroed/.xemacs/ri-emacs.rb")
(autoload 'ri "/home/bschroed/.xemacs/ri-ruby.el" nil t)
;;
;; You may want to bind the ri command to a key.
;; For example to bind it to F1 in ruby-mode:
;;
(add-hook 'ruby-mode-hook (lambda () (local-set-key 'f1 'ri)))

--
Brian Schröder
http://ruby.brian-sch...


Tassilo Horn

10/5/2004 7:25:00 AM

0

Hi Brian,

I think I'll adopt a lot of your stuff. Especially looking up a keyword
at point is very useful to me.

Thanks a lot,
Tassilo
--
"There are two major products that come out of Berkeley: LSD and UNIX.
We don't believe this to be a coincidence." Jeremy S. Anderson

Tassilo Horn

10/5/2004 7:45:00 AM

0

"Alan Chen" <aero6dof@yahoo.com> writes:

> One useful key combo is M-/ (i think that's the default mapping). It
> maps to dabbrev-expand.

Yes, this is indeed very useful. But M-/ is nearly unpressable with a
german keyboard layout. I'll bind it to another key.

> To search the TAG file you hit M-. (find-tag). I've never tried rtag
> (I have used exuberant ctags to generate ruby and other language tag
> files)

Ok, I will investigate on ctags.

> More instructions are available for a specific command if you hit M-h
> k (describe-key) then the key sequence you want help on.

I think you mean C-h k. ;-)

> Cheers,
> -alan

Thanks a lot for your help,
Tassilo
--
Q: What's the difference between a golfer and a skydiver?
A: A golfer goes "[WHACK] ... Oh shit!". /---------------\
A skydiver goes "Oh shit! ... [WHACK]" | www.fscnrw.de |
\---------------/

Kristof Bastiaensen

10/5/2004 11:29:00 AM

0

On Tue, 05 Oct 2004 09:25:27 +0200, Tassilo Horn wrote:

> Hi Brian,
>
> I think I'll adopt a lot of your stuff. Especially looking up a keyword at
> point is very useful to me.

Thanks! Download the latest version at
http://rubyforge.org/frs/?group_id=317&rele...

Are you using MS-Windows? Unfortunately it doesn't work for some emacs
versions under windows :( This is probably a bug in the windows-versions,
but I hope they will solve it.

Here is an extract of my init.el file (for XEmacs):

(add-hook 'ruby-mode-hook
(lambda ()
(setq ruby-indent-level 3)
(local-set-key 'f1 'ri)
(local-set-key '(return) 'ruby-reindent-then-newline-and-indent)
(local-set-key '(meta control h) 'ruby-mark-defun)))

;change the colors used in the ri-help buffer
(if (device-on-window-system-p)
(setq ansi-color-names-vector
["black" "red3" "darkgreen" "yellow3"
"blue1" "darkmagenta" "darkcyan" "white"]))

(autoload 'ri "~/.xemacs/ri-ruby.el" "get information on ruby methods and
classes" t)

;freeze and colorize the prompt in comint-modes (i.e.: Inferior Ruby)
(let ((prompt-face (make-face 'comint-prompt-face
"the face used for the prompt in comint-mode")))
(set-face-foreground 'comint-prompt-face
(if (device-on-window-system-p)
"brown4"
"red")))

(defun comint-freeze-prompt (&optional string)
(save-excursion
(goto-char (process-mark (get-buffer-process (current-buffer))))
(if (re-search-backward comint-prompt-regexp (point-at-bol) t)
(let ((extent (make-extent (match-beginning 0) (match-end 0))))
(set-extent-face extent (or (find-face 'comint-prompt-face)
(find-face 'default)))
(set-extent-property extent 'read-only t)))))

(add-hook 'comint-load-hook (lambda ()
(setq comint-output-filter-functions
(append '(comint-freeze-prompt
comint-strip-ctrl-m)
comint-output-filter-functions))))
Regards,
KB

Tassilo Horn

10/5/2004 4:11:00 PM

0

Kristof Bastiaensen <kristof@vleeuwen.org> writes:

Hi Kristof,

> Thanks! Download the latest version at
> http://rubyforge.org/frs/?group_id=317&rele...

Ah. I've searched the web but didn't find ri-emacs.

> Are you using MS-Windows? Unfortunately it doesn't work for some emacs
> versions under windows :( This is probably a bug in the windows-versions,
> but I hope they will solve it.

No, Linux and GNU Emacs.

> Here is an extract of my init.el file (for XEmacs):

Great, thanks.

> [snipped]
> (if (device-on-window-system-p)
^^^^^^^^^^^^^^^^^^^^^^^^^
Thats the XEmacs equivalent of window-system, right?

,----[ C-h v window-system RET ]
| window-system's value is x
|
| Name of window system that Emacs is displaying through.
| The value is a symbol--for instance, `x' for X windows.
| The value is nil if Emacs is using a text-only terminal.
`----

> Regards,
> KB

Thanks and regards,
Tassilo
--
"It may just be paranoia, but I think Gnus reads my mail."
Bruce Stephens <bruce@cenderis.demon.co.uk>

Kristof Bastiaensen

10/5/2004 6:08:00 PM

0

On Tue, 05 Oct 2004 18:11:15 +0200, Tassilo Horn wrote:

> Hi Kristof,
>
>> Are you using MS-Windows? Unfortunately it doesn't work for some emacs
>> versions under windows :( This is probably a bug in the
>> windows-versions, but I hope they will solve it.
>
> No, Linux and GNU Emacs.

Good, it should work then :)

>
>> Here is an extract of my init.el file (for XEmacs):
>
> Great, thanks.
>
>> [snipped]
>> (if (device-on-window-system-p)
> ^^^^^^^^^^^^^^^^^^^^^^^^^
> Thats the XEmacs equivalent of window-system, right?
>
> ,----[ C-h v window-system RET ]
> | window-system's value is x
> |
> | Name of window system that Emacs is displaying through. The value is a
> | symbol--for instance, `x' for X windows. The value is nil if Emacs is
> | using a text-only terminal.
> `----
Yes, that should do it. It's only necessary if you want to change the
colors. It is possible that the colors don't work yet on emacs. I'll
have to find out why...
>
>> Regards,
>> KB
>
> Thanks and regards,
> Tassilo

You're welcome and regards,
Kristof