· KLDP.org · KLDP.net · KLDP Wiki · KLDP BBS ·
Emacs Ruby Mode

Emacs Ruby-Mode

±è¿ë¿í(CN)

ÀÌ ¹®¼­´Â Emacs¿¡¼­ Ruby ÇÁ·Î±×·¡¹ÖÀ» Æí¸®ÇÏ°Ô Çϱâ À§ÇØ È¯°æ ¼³Á¤ÇÏ´Â ¹æ¹ý°ú °£´ÜÇÑ »ç¿ë¹ýÀ» ´Ù·ç°í ÀÖ´Ù.


1. Emacs Ruby ExtensionÀÇ ¼³Ä¡


Emacs ¿¡µðÅÍ¿Í Emacs Ruby Extension(@EmacsRubyExtension.zip (39.53 KB) )ÀÌ ÇÊ¿äÇÏ´Ù. (µ¿ºÀµÈ ¾ÐÃàÆÄÀÏ¿¡´Â ¼³Ä¡¿¡ ºÒÇÊ¿äÇÑ ÆÄÀÏÀ» etc·Î À̵¿ÇÏ¿´´Ù.)

Ruby ¾ð¾î´Â ÇʼöÀûÀ¸·Î ¼³Ä¡ÇÒ ÇÊ¿ä´Â ¾øÀ¸³ª ¼³Ä¡ÇÏÁö ¾ÊÀ¸¸é Ruby ÇÁ·Î±×·¡¹ÖÀº ºÒ°¡´ÉÇÏ´Ù.

1.1. ¼³Ä¡ °æ·Î ã±â

Emacs Ruby ExtensionÀ» ¼³Ä¡ÇÒ °æ·Î¸¦ ã¾Æ¾ß ÇÑ´Ù.

emacs.PNG
[PNG image (13.62 KB)]

À§ÀÇ È­¸éÀº Emacs¸¦ ½ÇÇà½ÃÅ°¸é óÀ½ ³ª¿À´Â È­¸éÀÌ´Ù. ÇÏ´Ü¿¡ *scratch*¶ó°í Ç¥½ÃµÇ¾î Àִµ¥ *scratch* ¹öÆÛ¶ó´Â ÀǹÌÀÌ´Ù. Emacs´Â ÇϳªÀÇ ÆíÁý ´ÜÀ§¸¦ ¹öÆÛ¶ó°í ºÎ¸¥´Ù. Emacs´Â load-Path º¯¼ö¿¡ µî·ÏµÈ ÁÖ¼Ò¿¡¼­ È®Àå ÆÄÀÏÀ» Àоî¿Â´Ù. Emacs Ruby ExtensionÀÇ ¼³Ä¡¸¦ À§ÇØ Load-Path¸¦ »ìÆ캸ÀÚ.

load-path[*]

[1]°¡ Ä¿¼­¶ó¸é ±× À§Ä¡¿¡¼­ Ctrl Å°¿Í X¸¦ ´©¸£°í (ÀÌÇÏ C-X) Ctrl Å°¿Í E¸¦ ´©¸¥´Ù. (ÀÌÇÏ C-E) ÀÌÁ¦ºÎÅÍ C-X, C-E¿Í °°Àº ÇüÅ·Π°£·«È÷ ºÎ¸¦ °ÍÀÌ´Ù. ½ÇÇà °á°ú´Â ¾Æ·¡¿Í °°ÀÌ È­¸é ÇÏ´Ü¿¡ Ç¥½ÃµÈ´Ù.

load-path.PNG
[PNG image (17.88 KB)]

¿î¿µÃ¼Á¦³ª ¼¼Æÿ¡ µû¶ó Á¶±Ý¾¿ ´Ù¸£°Ô ³ªÅ¸³ª´Âµ¥ ÀÌ ¹®¼­¿¡¼­´Â "c:/Program Files/Emacs/emacs/site-lisp"¿¡ ¼³Ä¡ÇÒ °ÍÀÌ´Ù. ¾î¶² Æú´õ³ª ¼³Ä¡Çصµ »ó°ü¾øÁö¸¸ load-path º¯¼ö¿¡ Æ÷ÇÔµÈ °æ·ÎÀ̾î¾ß ÇÑ´Ù.

´Ù¸¥ °æ·Î¿¡ ¼³Ä¡¸¦ ¿øÇÏ´Â µ¶ÀÚ´Â EmacsInstallScript¸¦ ÂüÁ¶Ç϶ó.

È­¸é ÇÏ´Ü¿¡ Ç¥½ÃµÇ¾î load-path º¯¼öÀÇ ³»¿ëÀ» »ìÆ캸±â Èûµé´Ù¸é C-X, B, *m, TAB, ENTER¸¦ ´­·¯¼­ ÀÚ¼¼ÇÏ°Ô È®ÀÎÇØ º¼ ¼ö ÀÖ´Ù. (´Ù½Ã *scratch* ¹öÆÛ·Î À̵¿Çϱâ À§Çؼ­ C-X, B, *s, TAB, ENTER¸¦ »ç¿ëÇÑ´Ù.)

1.2. Emacs Ruby Extension ÆÄÀÏ º¹»çÇϱâ


ÇØ´ç Æú´õ¿¡ Emacs Ruby Extension ÆÄÀϵéÀ» º¹»çÇÑ´Ù. ÀÌ ¹®¼­¿¡¼± "c:/Program Files/Emacs/emacs/site-lisp"¿¡ º¹Á¦Çϴµ¥ ÇØ´ç ÆÄÀÏÀÇ ÆÄÀϸíÀº ´ÙÀ½°ú °°´Ù.
inf-fuby.elc
rubydb.el
rubydb.elc
ruby-electric.el
ruby-electric.elc
ruby-mode.el
ruby-mode.elc

1.3. ȯ°æ ¼³Á¤Çϱâ


ȯ°æ ¼³Á¤Çϱâ À§Çؼ­´Â .emacs ÆÄÀÏÀ» ¼öÁ¤ÇØ¾ß ÇÑ´Ù. C+X, C+F¸¦ ´­·¯ "ÆÄÀÏ ºÒ·¯¿À±â"¸¦ ÇÏÀÚ.
Find file: C:\Documents and Settings\¿ì¸®Áý/[*]
[2]°¡ Ä¿¼­ À§Ä¡¶ó¸é "~/"¸¦ ÀÔ·ÂÇÏ°í
Find file: C:\Documents and Settings\¿ì¸®Áý/~/
TABÀ» ´©¸£ÀÚ.
Find file: ~/
.emacs¸¦ ÀÔ·ÂÇÏ°í
Find file: ~/.emacs
¿£Å͸¦ ´©¸¥´Ù.
(require 'ruby-mode)
(require 'rubydb)
(require 'inf-ruby)
(require 'ruby-electric)
(setq auto-mode-alist (cons '("\.rb$" . ruby-mode) auto-mode-alist))
À§ÀÇ Äڵ带 »ðÀÔÇÑ´Ù. »õ·Î¿î ÆÄÀÏÀ̶ó¸é ±×³É »ðÀÔÇÏ¸é µÇ°í ±âÁ¸ ÆÄÀÏÀÌ ÀÖ´Ù¸é Àû´çÈ÷ Ãß°¡ÇØÁÖÀÚ.

(Á¦ÀÏ µÚ¿¡ Ãß°¡ÇÏ´Â °ÍÀÌ ¹«³­ÇÒ °ÍÀÌ´Ù.) Ãß°¡°¡ ¿Ï·á µÇ¾ú´Ù¸é C-X, C-S·Î ÀúÀåÇ϶ó.

Emacs¸¦ ´Ù½Ã ½ÇÇàÇÏ°í´Â ¿¡·¯°¡ ³ªÁö ¾Ê±æ ±â¿øÇÏÀÚ.

2. ruby-modeÀÇ »ç¿ë

ruby-mode·Î ÀüȯÀº µÎ°¡Áö ¹æ¹ýÀ¸·Î ÇÒ ¼ö ÀÖ´Ù.
  1. .rb È®ÀåÀÚÀÇ ÆÄÀÏ ¿­±â
  2. M-X ruby-mode
ÀüÀÚ´Â C-X, C-F·Î ÆÄÀÏÀ» ¿­¸é µÇ°í ÈÄÀÚ´Â ALT(MÀº ALTÅ°³ª ESC Å°¸¦ ´©¸£¸é µÈ´Ù.) Å°¿Í X¸¦ ´©¸£°í ruby-mode ¿£Å͸¦ ´­·¯¼­ ÀüȯÇÏ°Ô µÈ´Ù. ruby-mode´Â Àüü ŸÀÌÇÎ ÇÒ ÇÊ¿ä¾øÀÌ ruby¸¦ ÀÔ·ÂÇÏ°í tabÀ» ´©¸£¸é ÀÚµ¿¿Ï¼ºµÈ´Ù.

2.1. Hello Man

ÇϳªÀÇ ÇÁ·Î±×·¥À» ¸¸µé¸é¼­ ruby-mode¸¦ Á÷Á¢ »ç¿ëÇØ º¸ÀÚ.

C-X, C-F¸¦ ÀÔ·ÂÇÏÀÚ.
Find file: c:/Documents and Settings/¿ì¸®Áý/Application Data/[*]
/¸¦ ÀÔ·ÂÇÏ°í
Find file: c:/Documents and Settings/¿ì¸®Áý/Application Data//
TABÀ» ´©¸¥´Ù.
Find file: /
Çѹø¿¡ ·çÆ® µð·ºÅ丮·Î À̵¿ÇÏ´Â ¹æ¹ýÀÌ´Ù. ·çÆ® µð·ºÅ丮¿¡ helloMan.rb¶ó´Â ÆÄÀÏÀ» ¸¸µéÀÚ. Á¦´ë·Î ¼º°øÇß´Ù¸é ¾Æ·¡¿Í °°Àº È­¸éÀÌ ¶ã °ÍÀÌ´Ù.

helloMan.PNG
[PNG image (10.99 KB)]

helloMan.rb¶ó´Â ÆÄÀÏ¸í ¿·¿¡ (Ruby)¶ó´Â ±ÛÀÚ°¡ º¸ÀδÙ. ÇöÀç ruby-mode·Î ÀÛµ¿ÇÏ°í ÀÖ´Ù´Â °ÍÀÌ´Ù.

M-;¸¦ ÀÔ·ÂÇÏÀÚ. (À§¿¡ ¼³¸íÇßµí MÀº ALT Å°³ª ESC¸¦ ÀǹÌÇÑ´Ù. ALT¿Í ;¸¦ µ¿½Ã¿¡ ´©¸£¸é µÈ´Ù.) ÀÌ ¸í·ÉÀº ÁÖ¼®À» ÀÔ·ÂÇÏ´Â ¸í·É¾î´Ù.

# ÀÌÈÄ¿¡ ¾Æ·¡ÀÇ ³»¿ëÀ» ÀÔ·ÂÇÏÀÚ. (¾ûÅ͸® ÁÖ¼®À̶ó´Â °ÍÀº ½Å°æ¾²Áö ¸»ÀÚ.)
# Ruby mode: Major mode for edting ruby scripts. TAB properly idents subexpressions of mult-line class, module, def, if, while, for, do, and case statements, taking nesting into account
ÁÖ¼®ÀÇ ±æÀÌ°¡ ³Ê¹« ±æ¾î¼­ º¸±â Èûµé¾î Á³À» °ÍÀÌ´Ù. Àû´çÇÑ À§Ä¡¿¡¼­ M-Q¸¦ ÀÔ·ÂÇÑ´Ù.

comment.PNG
[PNG image (13.34 KB)]

ÀÚµ¿À¸·Î ÁÖ¼®ÀÇ ÇüÅ°¡ ¿©·¯ ÁÙ·Î Á¤¸®µÇ¾î ÀÖ´Ù. ÇÁ·Î±×·¥ ¾Õ ºÎºÐ¿¡ ±ä ÁÖ¼®À» ´Ù´Â °æ¿ì¿¡ ÀÌ·± ¹æ¹ýÀ¸·Î ÁÖ¼®À» ´Þ ¼ö ÀÖ´Ù. ÀÌÁ¦ ±â´Ù·Á¿Ô´ø HelloMan Ŭ·¡½º¸¦ ÀÛ¼ºÇغ¸ÀÚ.
# Ruby mode: Major mode for edting ruby scripts. TAB properly idents subexpressions of mult-line class, module, def, if, while, for, do, and case statements, taking nesting into account

class HelloMan
def sayHello
¿©±â±îÁö ÀÔ·ÂÇغ» µ¶ÀÚ´Â ÀÚµ¿À¸·Î µé¿©¾²±â°¡ ¾ÈµÈ´Ù´Â °ÍÀ» ¹ß°ßÇßÀ» °ÍÀÌ´Ù. (¹°·Ð Ãֽſ¹ ¼öÀÛ¾÷ ¸Ó½ÅÀ¸·Î ÇØ°áÇÑ µ¶ÀÚµµ ÀÖÀ» °ÍÀÌ´Ù.)

³î¶ó°Å³ª ´çȲÇÒ ÇÊ¿ä¾ø´Ù. Ä¿¼­¸¦ ¿Å±âÁö ¸»°í TABÀ» ´©¸£ÀÚ.

Emacs¿¡¼­ TABÀº ÇØ´ç ¶óÀÎÀ» ÀÚµ¿À¸·Î µé¿©¾²±â ÇÏ´Â ¸í·É¾îÀÌ´Ù. (´Ù¸¥ ¿¡µðÅÍ¿¡¼­ÀÇ TABÀÌ 4-8Ä­À» ¶ç¿ì´Â ¹®ÀÚ¸¦ »ðÀÔÇÏ´Â °Í°ú´Â Â÷ÀÌ°¡ ÀÖ´Ù.)
class HelloMan
  def sayHello
¿©±â¿¡¼­ ¿£Å͸¦ Ä¡±âÀü¿¡ »ý°¢Çغ¸ÀÚ. ´Ù½Ã ¿£Å͸¦ ´©¸£°í ´ÙÀ½ ¶óÀο¡¼­ ³ªÁß¿¡ TABÀ» ´­·¯¼­ ÇàÀ» Á¤·ÄÇØ¾ß ÇÒ±î?

¸Å ¶óÀÎ TABÀ» ´­·¯ Á¤·ÄÇÏ´Â °ÍÀº ¾Æ¹«·¡µµ ±ÍÂú´Ù. C-J¸¦ ´©¸£ÀÚ. Àͼ÷ÇÑ µé¿©¾²±â°¡ µÉ°ÍÀÌ´Ù.

C-J´Â ±× ÇàÀ» ÀÚµ¿À¸·Î µé¿©¾²±â ÇÑÈÄ ´ÙÀ½ ÇàÀ¸·Î ¹Ù²Ù°í ´ÙÀ½ ÇàÀÇ µé¿©¾²±â¸¦ ÇØÁÖ´Â ¸í·É¾î´Ù.

¾î·Á¿ö º¸À̸é ÇÑ°¡Áö¸¸ ±â¾ïÇÏÀÚ. ÀÌÁ¦ºÎÅÍ´Â ¿£ÅÍ ´ë½Å¿¡ C-J¸¦ ´©¸£ÀÚ.
class HelloMan
  def sayHello
    "Helo, guy. I love RUBY."
¿©±â±îÁö ÀÔ·ÂÇϸé ÇϳªÀÇ ÇÔ¼ö¸¦ ¿Ï¼ºÇß´Ù. ÀÌ Å¬·¡½º¿¡´Â ÇϳªÀÇ ÇÔ¼ö¸¸ ³ÖÀ» ¿¹Á¤ÀÌ´Ù.

ÇÔ¼ö¿Í Ŭ·¡½º¸¦ ´Ù ´ÝÀÚ. ´ÙÀ½°ú °°ÀÌ ÀÔ·ÂÇ϶ó.
C-J, C-C, C-E, C-J, C-C, C-E
¿©±â¿¡¼­ CTRL Å°´Â ¶ª ÇÊ¿ä¾ø´Ù. CTRLÀ» ´©¸¥ ä·Î ´ÙÀ½°ú °°ÀÌ ÀÔ·ÂÇÏ¸é µÈ´Ù.
JCEJCE
¿©±â±îÁö ¼º°øÇß´Ù¸é ´ÙÀ½°ú °°Àº È­¸éÀ» º¼ ¼ö ÀÖÀ» °ÍÀÌ´Ù.

class.PNG
[PNG image (14.58 KB)]

C-C, C-E´Â end¸¦ ÀÔ·ÂÇÏ´Â ¸í·É¾îÀÌ´Ù. ruby´Â end°¡ ÀÚÁÖ ¾²ÀÌ´Ï ÄÜÆ®·ÑÀ» ´©¸¥ ä·Î JCE¸¦ ´©¸£´Â Å×Å©´ÐÀº ÀÚÁÖ ÀÌ¿ëÇÒ ¼ö ÀÖ´Ù.

To Do ´Ù¸¥ ¸ðµåÀÇ »ç¿ë¹ý°ú ¼³Á¤¹ýÀ» Ãß°¡ÇÏÀÚ -- CN 2006-02-04 13:53:18


ID
Password
Join
Far duller than a serpent's tooth it is to spend a quiet youth.


sponsored by andamiro
sponsored by cdnetworks
sponsored by HP

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2007-04-20 02:09:34
Processing time 0.0143 sec