Coding assistance for Emacs

T

Tassilo Horn

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
 
A

Alan Chen

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
 
B

Brian Schröder

Tassilo said:
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)))
 
T

Tassilo Horn

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
 
T

Tassilo Horn

Alan Chen said:
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
 
K

Kristof Bastiaensen

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&release_id=927

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
 
T

Tassilo Horn

Hi Kristof,

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
 
K

Kristof Bastiaensen

Hi Kristof,


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...
Thanks and regards,
Tassilo

You're welcome and regards,
Kristof
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top