ºìÁªLinuxÃÅ»§
Linux°ïÖú

VIµÄ¾ºÕù¶ÔÊÖEmacs ¿ìËÙÈëÃÅ

·¢²¼Ê±¼ä:2006-03-14 11:21:55À´Ô´:ºìÁª×÷Õß:LinuxÅàѵ²¿³¤
¡¡¡¡Emacs Æô¶¯:
Ö±½Ó´òemacs, Èç¹ûÓÐX-windows¾Í»á¿ªÊÓ´°. Èç¹û²»ÏëÓÃX µÄ°æ±¾, ¾ÍÓà emacs -nw¡¡¡¡¡¡(No windows)Æð¶¯.

·ûºÅ˵Ã÷
C-X ±íʾ°´×¡CTRL¼ü, È»ºó°´X, ÔÙ°ÑCTRL, XÒ»Æð·Å¿ª.
M-X¡¡¡¡¡¡¡¡ META¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ META

ÔÚûÓÐMETA¼üµÄµçÄÔÉÏ, M-X µÈÓÚÏÈ°´ ESC¼ü, ½ÓÖø°´ X¼ü.
SunÉÏÃæMETA¼ü¾ÍÊÇÁâÐεÄÄǸö¼ü.
ÓÐЩϵͳMETA¼ü¾ÍÊÇALT¼ü.(»òÕßijһ±ßµÄALT¼ü)

C-X»ò M-XµÄXûÓдóСд·Ö±ð.

Emacs°´¼üÃüÁî»ù±¾ÉÏÊÇÒ»´®C-ºÍM-×é³ÉµÄ.
³¬¹ýÁ½¸öÒÔÉϵİ´¼üÃüÁî, Emacs»áÔÚÓ©Ä»×îÏÂÃæÒ»ÐÐÏÔʾÄã°´¹ýʲô.
ÕâÒ»ÐнÐ×÷mini buffer

½áÊøEmacs°´ C-x C-c

È¡ÏûÖ´ÐÐ C-g
ÓÐЩEmacsÃüÁî»áÅܾܺÃ, ¿ÉÒÔÓÃC-gÖжÏÖ®. °´´í¼üÒ²¿ÉÒÔ°´C-gÈ¡Ïû.

ÉÏÏÂÒƶ¯¡¡ C-p ÏòÉÏ (previous line) C-n ÏòÏÂ(next line)
×óÓÒÒƶ¯¡¡ C-f ÏòÓÒ (forward)¡¡¡¡¡¡ C-b Ïò×ó (backward)

ÆäʵEmacsÄÚ²¿Ã»ÓÐÐеĸÅÄî, °ÑһƪÎÄÕ·ÅÔÚÒ»¸ö´óbuffer
ÀïÃæ, ËùÒÔC-f (forward)¾ÍÊÇÏòµµÎ²Òƶ¯, C-b (backward)
ÊÇÒÆ»ØÈ¥µÄÒâ˼, Ò»´ÎÒ»¸ö×Ö.

·­Ò³¡¡ÏÂÒ»Ò³ C-v (view next screen)
ÉÏÒ»Ò³ M-v

·­Ò³Ê±,ÉÏһҳĩβ»áÁôÒ»µãÔÚÓ©Ä»×îÉÏÃæ,ÒÔά³ÖÁ¬ÐøÐÔ.

EmacsÔÚÓαê½Ó½üÓ©Ä»×îÏ·½Ê±»á×Ô¶¯Ìø°ëÒ³, °Ñµµ°¸ÍùǰŲһµã, ·½±ãÔĶÁ.

ÖØ»­Ó©Ä» C-L

EmacsÀïÃæÓαêµÄרÓÐÃû´Ê½Ðpoint. point == ÓαêÄ¿Ç°µÄ µã ÓαêÒ»´ÎÌøÒ»¸ö×Ö(word) M-f¡¡ÍùºóÌø M-b

×¢Òâ C-f Óë M-f, C-b Óë M-bµÄ¶Ô³ÆÐÔ.

ÒƵ½ÐÐÍ· C-a¡¡ÐÐβ C-e
ÒƵ½¾äÊ× M-a¡¡µ½¾äβ M-e
(M-a µ½ÉÏÒ»¸ö¾äµãºóÃæ,Ò»¸ö¾ä×ÓµÄÆðÍ·.
M-e µ½¾äµãºóÃæ)

ÒƵ½µµÍ· M-< µµÎ² M->

ɾ³ýÓαêÄ¿Ç°Ö¸µÄ/ºóÃæµÄ×Ö C-d
Ç°ÃæµÄ×Ö DEL¡¡(Delete¼ü)
DELµÄÕýÃû½ÐRubout (Rub out)

M-DEL Íù»Øɾһ¸ö×Ö(word)
M-d¡¡ Íùǰɾ (ÓαêºóÃæ)
C-k¡¡ ɾÖÁÐÐβ (kill)
M-k¡¡ ɾµ½Ò»¾ä×Ó½áβ(ɾµ½¾äµã) (kill)

×¢ÒâBackspace = C-h ÔÚEmacsÏÂÊÇhelpµÄÒâ˼
ºóÃæÓÐ(kill)µÄ, ±íʾ´Ëɾ³ýµÄ¶¯×÷ÊÇkill, ²»Ì«µÈÓÚdelete.
emacs»á°ÑkillµôµÄ¶«Î÷·Åµ½kill ringÈ¥, ËãÊÇÒ»ÖÖÔÝ´æµÄµØ·½, ÒÔºó¿ÉÒԽгöÀ´.¼û yank˵Ã÷.

Undo: C-x u
C-_ µÈÓÚ C-x u¡¡¡¡ÓÐЩDECÖն˻ú, C-/¾ÍÊÇC-_
ÓÐʱµÈÓÚC-Shift- -
Öظ´Ö´ÐÐ

¾ÙÀý, ÏòÓÒÒÆ 8¸ö×Ö, C-u 8 C-f
C-u ÔÚEmacsÀïÊÇÂùÌرðµÄ,ÓÃÀ´É趨һЩÒýÊý(argument/repeat count)
¸øÆäºóµÄÃüÁî.

C-u 2 0 C-n ÏòÏÂÒÆ 20ÐÐ

ÓÐÒ»¸öÌرðµÄÀýÍâ, C-u 3 C-v ²»ÊÇ·­ÈýÒ³, ¶øÊÇÕû¸öÓ©Ä»ÏòÉÏÒÆÈýÐÐ.
¾Ý˵Õâ±È½ÏÓÐÒâÒå.

C-u 1 0 C-x u¡¡ UNDO 10´Î

¸øC-LÒ»¸öÒýÊý»áÔõôÑù:
C-u 0 C-l »áÖØ»­Ó©Ä»,²¢ÇÒ°ÑÄ¿Ç°µÄÐÐÒƵ½Ó©Ä»µÚÒ»ÐÐ.

ÁíÍâ, C-u 100¡¡ µÈÓÚ M-100
C-u Êý×Ö¡¡µÈÓÚ M-Êý×Ö

X windows ÏÂ,
C-left C-right Ò»´ÎÒÆÒ»¸ö×Ö(word).
C-up C-down Òƶ¯Ò»¶Î (paragraphs/CÓïÑԵĻ°ÊÇblock)
Home = C-a
End = C-e
C-Home = M-<
C-end = M->
PgUp PgDn = M-v C-v
É趨Öظ²´ÎÊý¸ü¼Ó¼òµ¥,
±ÈÈçÒªÏòÓÒÒÆ10¸ö×Ö C-1 C-0 right-arrow
¾ÍÊÇ°´×¡CTRL, È»ºó´ò10¾Í¶ÔÁË, ±È C-u 1 0 ¼òµ¥.

MouseÖмüÓÃÀ´Ñ¡È¡ÓÐhi-lightµÄµØ·½.
ÓÒ¼üÊÇmenu-button

Èç¹û²»Ð¡ÐÄ°´Á½´ÎESC, µÈÓÚ M-ESC,¡¡»áÓÐÒ»¸öѶϢÅܳöÀ´ËµÄã°´µ½Ò»¸ö±»disableµÄÃüÁî. ÕâÊǸ߼¶Ö¸Áî, ×÷ÕßÈÏΪ ³õѧÕßÓò»µÀ,ËùÒÔ»áÎÊÄãÒª²»ÒªÆô¶¯Ëü, Ò»°ã»Ø´ðno.

Èç¹ûijһÐÐÌ«³¤, Ó©Ä»ÏÔʾ²»ÏÂ, Emacs»áÔÚÓ©Ä»×îÓұߴò¸ö$,
±íʾ´ËÐÐδÍê,Óұ߻¹ÓÐ.

°ÑÒ»Ðвð³ÉÁ½ÐÐ: ÔÚÏë²ð´¦°´Enter¼´¿É.
ºÏ²¢Á½ÐÐΪһÐÐ: ÔÚÐÐβ°´C-d (»òÐÐÊ×°´DEL)

Yank: ͳö±»É¾µôµÄ(killed)¶«Î÷.

Ö»ÒªÓÃkill (C-k, M-kµÈ) ɾ³ý, ³¬¹ýÒ»¸ö×ÖµÄ×ÊÁÏ, emacs¾Í»á°ÑËü´æÆðÀ´, È»ºóC-y ¿ÉÒÔ°ÑËü½Ð³öÀ´. ¹¦ÄܸúCut & PasteÒ»Ñù. Kill ºÍdelete²»Ò»Ñù, Ö»Óб» killµôµÄ¶«Î÷²ÅÄÜÓÃyankÍ»ØÀ´.

ÓαêÔÚͬһµØ·½²»¶¯, Á¬ÐøkillµôµÄ×ÊÁϻᱻµ±³ÉÒ»´ÎkillµôµÄ, yankʱ»áÒ»Æð»ØÀ´.

±»KillµôµÄ×ÊÁÏÊÇ·ÅÔÚ³Æ×÷ kill ringµÄ×ÊÁϽṹÉÏÃæ, ring¾ÍÊǸöԲȦ, ±»killµôµÄ¶«Î÷»áÒÀÐò°ÚÔÚԲȦÉÏ. yank »á·Å»Ø×î½üÒ»´ÎkillµôµÄ×ÊÁÏ. Èç¹û²»ÊÇÄãÏëÒªµÄ»°, ÓÃM-y ¿ÉÒÔ»».¡¡(M-y¾ÍÊǸæËßemacs, ²»¶Ô²»¶Ô, ÎÒ²»ÊÇÒªÕâÒ»¸ö,»»Ç°Ò»¸ö¸øÎÒ).

M-y Òª½ô½ÓÔÚC-yÖ®ºó.

¿½±´ÎÄ×ֵķ½·¨== Á¬Ðø C-k ¼¸´Î,¡¡°ÑÒª¿½±´µÄÐÐÈ«²¿É¾µô, È»ºó°´ C-y Ū»ØÀ´. ÔÙµ½Ï븴ÖƵĵط½°´Ò»´ÎC-y, ¾Í³ÉÁË.

°ÑÒª¿½±´µÄ×ÊÁÏkillµôÔÚyank»ØÀ´ºÃÏñºÜ±¿. ÊÇÓбȽÏÎÄÃ÷µÄ ·½·¨, ÄǾÍÊÇM-w, ²»¹ý½ÏÂé·³.

Ê×ÏÈ,ÒªÏÈÉè±ê¼Ç. Mark Óà C-SPC »ò C-@ Éè. È»ºò°ÑÓαêÒƵ½ÁíÒ»¶Ë, °´ M-w ¾Í¿ÉÒÔ°Ñ mark µ½ point¼äµÄ×Ö´æµ½kill ringÉÏ. point ¾ÍÊÇÓαêµÄÒâ˼.

Emacs²»»á°ÑMarkÆðÀ´µÄµØ·½ÓÃhighlight±íʾ, ³ý·ÇÔÚXÏÂ. ÔÚXÏÂ, ¿ÉÒÔÓÃM-w À´¿½±´Óû¬Êó·´°×µÄÎÄ×Ö.

kill & yank ¾ÍÊÇ cut & pasteµÄÒâ˼.

ÒÔÉϴ󲿷ÝÖ¸Áî¶ÔBashµÄÃüÁîÁб༭ҲÓÐЧ

µµ°¸²Ù×÷
¶Áµµ: EmacsÊõÓï½Ð finding a file.
C-x C-f È»ºóÔÚmini-bufferÊäÈëµµÃû. ÊäÈëµµÃûʱ, SPC¼üÓÐauto-completeµÄ¹¦ÄÜ,»òÕß»áÐã³öµ½Ä¿Ç°ÎªÖ¹µµÃûÇ°¼¸¸ö×ÖºÍÊäÈëÒ»ÑùµÄ. (TAB¼üÒ²ÓÐÀàËƹ¦ÄÜ)

C-x C-f ½Ð find-file

C-x C-s ´æµµ (save current file, save current buffer)
C-x s¡¡ ´æËùÓеĵµ

C-x i¡¡ ²åÈëµµ°¸¡¡°ÑÁíÍâµÄµµ°¸µÄÄÚÈݶÁÈëÄ¿Ç°±à¼­ÇøÄÚ

ÊÓ´°

Emacs°Ñµµ°¸¶Á½øÀ´,´æÔÚbufferÖÐ.
ÎÒÃÇ͸¹ýwindowÀ´¿´/±à¼­buffer.

Á½¸öÊÓ´°»á°ÑÓ©Ä»ÇгÉÁ½²¿·Ý, ËûÃÇ¿ÉÒÔͬʱÏÔʾÏàͬµÄ, »ò²»Í¬µÄµµ°¸.

¶Ô³õѧÕ߶øÑÔ, ×îÐèÒªµÄÊǼÇסÔõÑùÈò»ÏëÒªµÄÊÓ´°Ïûʧ:

C-x 0 ¹ØµôÄ¿Ç°µÄÊÓ´°
C-x 1 »áÈÃÄ¿Ç°µÄÊÓ´°Õ¼ÂúÕû¸öÓ©Ä» (One Window), È¡Ïû/¹ØµôÆäËûµÄÊÓ´°.

EmacsÀïÃæÓÐÐí¶à¹¦Äܶ¼»á¿ªÒ»¸öСÊÓ´°À´ºÍʹÓÃÕß¹µÍ¨, ÏÔʾѶϢ.
ÓÐʱºò²»»á×Ô¶¯ÏûʧºÜÌÖÑá, C-x 1 ¾ÍºÜÓÐÓÃ.

ÁíÒ»¸ö¹¦ÄÜÊÇÈçºÎÌøµ½ÁíÒ»¸öÊÓ´°.
C-x o¡¡(other-window)

C-x 2 °ÑÄ¿Ç°µÄÊÓ´°ÇгÉÁ½¸ö (ˮƽ·Ö¸î)
C-x 3¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡(´¹Ö±·Ö¸î)
C-x 4 ÊÇÒ»´®ÓëÊÓ´°ÓйصÄÖ¸Áî.
C-x 5 ÔòÊÇÀ©Õ¹µ½XµÄÊÓ´°, ³ÆΪframe.
C-x 5 2 ¾ÍÊÇÔÙ¿ªÁíÒ»¸öXÊÓ´° (frame).

¶àµµ±à¼­
C-x C-b ¿´Ä¿Ç°ÓÐÄÇЩbuffer (buffer¾ÍÊÇemacs·Å¿ªÆðµÄµµ°¸µÄµØ·½).
C-x b È»ºóÔÚminibufferÊäÈëbufferµÄÃû×Ö,¿ÉÒÔÇл»±à¼­buffer. TAB¼üÒ²ÓÐ×÷ÓÃ. ÓÐЩÄÚ²¿µÄbuffer (¾ÍÊÇûÓеµ°¸µÄbuffer), ÊÇÓÃ*¿ªÍ·ºÍ½áÊø, Õâ¸öÒ²Òª´ò, Èç*scratch*

×îºóÌáÐÑ:
C-x 1 ¿ÉÒ԰ѶàÓàµÄÊÓ´°¹Øµô.

EmacsÀ©³äÖ¸Áî

Ç°Ãæ½éÉܵÄemacs°´¼ü´ó²¿·Ý¶¼ÊÇC- »òÕß M-µÄÐÎʽ.
ÕâÊÇ×î¼òµ¥µÄ°´·¨, ÓÉÒ»¶Ô°´¼ü¹¹³ÉÒ»¸öÖ¸Áî.

EmacsµÄ°´¼ü¿ÉÒÔ³¬¹ý2¸öÒÔÉÏ. Èç C-x 1 »ò C-x C-b.
Ò»°ã³¬¹ýÒ»¸ö°´¼ü×éºÏµÄÃüÁÊÇÓÃC-x ¿ªÍ·.

ÁíÍâÄãÒ²¿ÉÒÔÖ±½ÓÏÂÃüÁî. °´ M-x Ö®ºó¾Í¿ÉÒÔ´òÒ»¸öEmacsÃüÁîÀ´Ö´ÐÐ. Ò»°ãÕâЩÃüÁîÃû×Ö¶¼ºÜ³¤, ²»¹ý¶¼²»³£ÓÃ. µÈһϠÎÒÃÇ»á½éÉÜһЩ. »¹ÓнéÉÜÔõô°ÑÕâЩÃüÁîÉè³É°´¼üÖ¸Áî.

C-x C-c ¾ÍÊǽáÊøEmacs. ²»¹ýÒ»°ãEmacsºÜ±¿ÖØ, Ò»µ©Æ𶯾Ͳ»ÇáÒ×Í˳ö. ËùÒԱȽϳ£ÓõÄÊÇC-z

C-z °ÑEmacsÔÝÍ£, »Øµ½ÃüÁîÁÐ. µ±ÄãÏ´ÎÔÙÐèÒª±à¼­Ê±,´òfg %emacs»òÕßfg¾Í¿ÉÒÔ°ÑEmacs»½ÐÑ.

ÔÚXÏÂ, C-z»á°ÑemacsËõ³Éicon

mode line

emacs±à¼­»­ÃæÓÉ ±à¼­Çø(buffer) ״̬ÁÐ (modeline) ºÍ¶Ô»°Çø (minibuffer)¹¹³É. ÕâÀï½âÊÍ modeline ÏÔʾµÄѶϢ.

ÒÔÏÂÊǸö·¶Àý:

--**-XEmacs: xemacs.qs¡¡¡¡¡¡(Fundamental)----74%-------

ÓɺóÃæÍùÇ°½âÊÍ, 74% ±íʾÓαêµÄλÖÃ.

(Fundamental)±íʾ±à¼­Ä£Ê½.ÕâÊÇ×îԭʼµÄģʽ. ±à¼­²»Í¬ÖÖÀàµÄÎÄÕ¿ÉÄÜÏ£ÍûÓò»Í¬µÄģʽ, ±ÈÈç˵C-mode, lisp-mode, tex-mode, text-modeµÈµÈ. ÔÚ²»Í¬Ä£Ê½Ï¿ÉÄܶàһЩ°´¼ü³öÀ´. ¾ÙÀýtext-mode.
M-x text-mode
¿ÉÒÔÇÐÈëtext-mode, ÕâÊÇÒ»°ãÈ˱༭ÎÄ×ÖʹÓõÄģʽ. ºÍFundamental modeûʲô²îÒì. ²»¹ýÓαêÒƶ¯Ê±, Emacs¶ÔÒ»¸ö×ֵĶ¨Òå¾ÍÓÐËù²»Í¬, Òò¶øM-f M-b µÈÒƶ¯Ò»¸ö×Ö, Ò»¸ö¶ÎÂäµÄÖ¸Áî¾Í¿ÉÄÜ»áÍ£ÔÚ±êµã·ûºÅµÄÇ°Ãæ. ´Ëʱ״̬ÁбäΪ... (Text)----70%---

ÒÔÉÏ˵µÄÊÇMajor mode. ÁíÍ⻹ÓÐminor mode, Æäʵ¾ÍÊÇһЩ¶îÍâµÄ¹¦ÄÜ.
±ÈÈç˵, M-x auto-fill-mode Ôò״̬ÁÐÏÔʾ (Text Fill).
auto-fill¾ÍÊÇ×Ô¶¯¶ÏÐÐ, ÈÃÎÄÕÂÿÐй̶¨ÓÐ70¸ö×Ö.

M-X fundamental-mode ¿ÉÒÔ±ä»ØÀ´.

ÕâÀïҪ˵Ã÷Ò»ÏÂ, emacsÔÚ minibufferÏÂÓÐauto-completionµÄ¹¦ÄÜ,Ò²¾ÍÊÇ´òM-x fund È»ºó°´ SPC, Ëü»á×Ô¶¯²¹È« fundamental-mode,²»ÓÃÈ«´ò. Èç¹ûÓÐÁ½¸öÒÔÉϵÄÑ¡Ôñ, Ëü»á¸æËßÄã. Õâ¸ö¹¦ÄܶÔfind-file (C-x C-f)µÈµÈµµ°¸±à¼­¹¦ÄÜÒ²ÓÐЧ. Ç°ÃæÌá¹ý.ÁíÍâ, minibufferÏÂÃæM-nºÍ M-p ¿ÉÒÔÈ¡»ØÉϴκô½ÐµÄÃüÁî.

×îºó½âÊÍÁ½¸ö**ºÅ. ÓұߵÄ*±íʾÎÄÕ±»Ð޸ĹýÁË.
×ó±ßµÄ* ±íʾÕâ¸ö±à¼­Çø(buffer)¿ÉÒÔÐÞ¸Ä.
ÓÐһЩemacsµÄbufferÊÇread-only buffer, ¾Í»á±ê³É%%%±íʾµµ°¸ÊÇread-only.

C-x C-q ¿ÉÒԽ⿪read-onlyµÄËø¶¨, ÎÞÂÛÈçºÎÄãÒª¸ÄÕâ¸ö±à¼­Çø.ÕâÊǸötoggleÖ¸Áî, Èç¹ûÔ­À´ÊÇ¿ÉÒÔÐ޸ĵÄ, C-x C-q»á°ÑËüÇгÉread-only.

Search

ûÓÐSearch ¹¦Äܵı༭Æ÷¼òÖ±¾ÍÊÇСÅóÓѵÄÍæ¾ß. SearchÊÇÒ»ÏîºÜÖØÒªµÄ¹¦ÄÜ, ËùÒÔemacsÒ²ÌṩµÄºÜÍêÉÆ.
C-s
C-r
M-x re-search-forward
M-x re-search-backward
M-x search-forward
M-x search-backward

ÒÔÉÏÕâЩָÁîÊÇ»ù±¾µÄsearchÖ¸Áî. C-s, C-rÊÇincreamental search,¾ÍÊÇÄã´ò×ÖµÄͬʱ, emacs¾ÍÖ±½Ó°ïÄãÕÒ. Ò»¸öÊÇforward, Ò»¸öÊÇbackward.ÕÒµ½ÁËÔõô°ì? °´C-g¿ÉÒÔÈ¡ÏûËÑÑ°, Ìø»ØÔ­À´µÄλÖÃ. °´Enter¾ÍÈÃÓαêÍ£ÔÚÕÒµ½µÄµØ·½ -- ´ËʱminibufferÏÔʾ:Mark saved where search startedʲôÒâ˼? ¾ÍÊÇisearch°ïÄãÔÚÔ­À´µÄλÖÃÉèÁËÒ»¸ömark, È»ºó°Ñpoint(cursor) ÒƵ½ÐµÄλÖÃ.
ÏëÌø»ØÈ¥Ô­Ïȵĵط½?
C-x C-x ¾Í¿ÉÒÔÁË.(exchange-point-and-mark)
C-u C-SPC ¿ÉÒÔÒÀÐòÌø»ØÇ°¼¸´ÎÉèmarkµÄµØ·½.
(C-SPCÊÇÉèmark, ¸øËüÒ»¸öargument, ¾ÍÊÇ·´¶¯×÷) (»¹¼Ç²»¼ÇµÃC-u ¿ÉÒÔ¸øºóÃæµÄÖ¸ÁîÉèһЩ²ÎÊý. ÓÐЩָÁîÄÃÕâ¸ö²ÎÊýÀ´µ±×÷repeat count, ÓÐЩָÁî¾ÍÖ»ÄÃÀ´µ±×÷on/off, true/false, set/clear¶øÒÑ)

M-x re-search-forward¿ÉÒÔÈÃÄãÓÃregular expressionËÑÑ°.
M-x search-forwardÔòûÓÐincreamentalµÄ¹¦ÄÜ.

ÁíÍâÒ»¸öÖ¸Áî, ×÷ÓúÍgrepºÜÏñ:
M-x occure

ºÍsearchÏàÌá²¢Â۵ľÍÊÇreplace.

M-x replace È»ºó°´ SPC, ¾ÍÖªµÀÁË.

EmacsµÄÉ趨:

EmacsµÄÉ趨µµÊÇ $HOME/.emacs
ÄãÓ¦¸Ã¶àÉÙÖªµÀ, emacsÊÇÓÃlispд³ÉµÄ±à¼­Æ÷, .emacsµµÒ²¶¼ÊÇÒªÓÃlispµÄÓï·¨É趨. emacsÓõÄlisp³ÆΪelisp, ºÍÒ»°ãµÄlisp²îÒ»µãµã.

ÓÐÒ»¸öinfo page, emacs-lisp-intro, ÉîÈëdz³öµÄ½éÉÜemacs lisp. Èç¹ûÄ㻹²»»á, ²»¶®programming, Ç¿ÁÒ½¨ÒéÄã¿´Õâ·ÝÎļþ. Èç¹ûÄã»átexinfo, Äã¿ÉÒÔ°ÑËüºÜƯÁÁµÄÓ¡³öÀ´. (ÄÚÈÝÒ»µãµã¶øÒÑ, Á½ÈýÌì¾Í¿´ÍêÁË)

Èç¹ûÄã°Ñ.emacs¸ãÔÒÁË, ½øemacsºÜÆæ¹Ö, Ôõô°ì?
1. Óà vi ¸Ä .emacs :>
2. emacs -q ½ø emacs

Major Modes

Ò»°ã³£¼ûµÄemacs major modeÓÐ
fundamental-mode
text-mode
lisp-mode¡¡ ÓÐ×Ô¶¯¶ÔÀ¨ºÅ/ÖØÅÅ, Ö±½ÓÖ´ÐÐlisp code¹¦ÄÜ.
c-mode/cc-mode c-modeÊDZȽϾɵÄc-mode, cc-modeÓ¦¸ÃÊÇĿǰеÄc-mode. ÓÐ×Ô¶¯ÖØÅÅ/¶ÔÀ¨ºÅµÄ¹¦ÄÜ. Ò²¿ÉÒÔÔÚemacsÄÚcompile, Ìøµ½compiler error ÐÞÕý´íÎó. Ö´ÐгÌʽʱdebug. (ÅäºÏdbx/gdb)compileÊÇ͸¹ýMakefile½øÐÐ.
tex-mode¡¡¡¡Tex/Latex±à¼­Ä£Ê¾. ¿ÉÄÜÊÇ´òһЩÆæ¹ÖµÄ±êµã·ûºÅ±È½Ï·½±ã.
-mode ͬlisp/cc-mode. Èç¹ûÊÇinterpreterµÄ»°, emacsͨ³£¶¼¿ÉÒÔÖ±½ÓÖ´ÐÐ/debug.
-mode»¹ÓÐtagsµÄ¹¦ÄÜ, ºóÊö.

html-mode, texinfo-mode, sgml-mode: ±àдhtml, texi, sgmlÖ®ÓÃ.
w3-mode¡¡¡¡ WWW browser. ÔÚx-winÉϲ»ÂúÒâ,µ«¿ÉÒÔ½ÓÊÜ...

Tags

Tags ÊÇÒ»¸öÏÔΪÈËÖªµÄ¹¦ÄÜ? ËùÒÔÎÒÏëÌáÒ»ÏÂ. Õâ²»ÊÇemacs·¢Ã÷µÄ,¶øÊÇvi Ô­±¾µÄÌØÒ칦ÄÜ. emacsÖ»ÊÇ·¢Ñï¹â´ó¶øÒÑ.

¼ÙÉèÄãÓÐÒ»¸öĿ¼, ÀïÃæÊÇÒ»¸ö³ÌʽµÄԭʼÂë, ±ÈÈç˵, tin µÄԭʼÂë,·ÅÔÚ ~/tin-1.3beta ÏÂÃæ. ÄãÏë¿´ËüÃÇ.

Ê×ÏÈ, ½Ðemacs cdµ½¸ÃĿ¼:
M-x cd

È»ºó, ½¨Á¢tag table.
tag table ¾ÍÊÇÒ»ÕŶÔÕÕ±í, ¼Ç¼Äĸö·ûºÅ(variable/function call)¶ÔÓ³µ½Äĸöµµ°¸µÄÄĸöµØ·½. ÓÐÕâÕűí, emacs¿ÉÒÔÈÃÎÒÃÇ¿ìËÙµÄÔÚ³ÌʽÂëÄÚÓÎ×ß. Ò»°ãÕâÕűíÊÇÒ»¸öµµ°¸, ½Ð×÷TAGS (´óд)

M-! etags *.[ch]

M-! ÊÇÖ´ÐÐexternal shell commandµÄÒâ˼. etags¾ÍÊÇemacsµÄ½¨±í³Ìʽ.ÄãÖ»Òª¸æËßËüÄãµÄsource codeÔÚÄÇÀï¼´¿É.

viµÄ»°ÊÇʹÓÃctagsÕâ¸ö³Ìʽ, Ëü½¨³öÀ´µÄµµÃû½Ðtags (Сд). ÒòΪÎÒÃǽéÉÜemacs, ËùÒÔ²»¹ÜËü.

È»ºó, Ôõô¿´³Ìʽ? ÄãÖªµÀËùÓеÄC ³Ìʽ¶¼ÊÇÓÉmain()¿ªÊ¼, ËùÒÔÄãÏëÕÒµ½main()ÔÚÄĸöµµ°¸. ÕâʱֻҪ°´¡¡M-. È»ºóemacs»áÎÊÄãtag tableÔÚÄÄÀï. ÒòΪÎÒÃÇÒѾ­cdµ½¸ÃĿ¼, Ö±½Ó°´enter¾ÍºÃÁË. È»ºóÊäÈëmain,emacs¾Í»á°ÑÄã´øµ½main(){ ... }È¥.

Èç¹û Äã¿´µ½Ä³¸ö³ÌʽƬ¶Ïºô½ÐÒ»¸öÄãû¿´¹ýµÄº¯Ê½, Äã¿ÉÒÔ°ÑÓαêÒƵ½¸Ãº¯Ê½µÄÃû×ÖÉÏ, M-. ENTER ¾Í¸ã¶¨ÁË.

Èç¹û emacsÕÒ´íÁË (±ÈÈçÓбäÊýºÍº¯Ê½Í¬Ãû, emacsÌøµ½±äÊýÈ¥),ÄÇÄã¿ÉÒÔÓà C-u M-. ÕÒÏÂÒ»¸ö.

Ôڱ༭³ÌʽÂëµÄʱºò, M-SPC ºÜÓÐÓÃ, Ëü»á°ÑÓα긽½üµÄ¿Õ°×Ëõ³ÉÒ»¸ö.ÔÚÆäËüµØ·½Ò²ÓÐЧ.

EmacsµÄһЩpackage:

M-x dired¡¡(»òC-x d)
ÓÎ×ß/±à¼­ Ŀ¼, ¾ÍÊǵµ°¸×ܹܵÄÒâ˼

M-x man¡¡ ¾ÍÊÇman page
M-x shell ¿ª¸öcommand prompt, ²»¹ý²»ÄÜÅÜvi,elm, tin...
M-x gnus¡¡¶ÁÐÂÎÅ/¶ÁÐÅ
M-x rmail ¶ÁÐÅ
M-x vm¡¡¡¡view mail
M-x mh-rmail ¶ÁÐÅ (package mh-e)
M-x mh-smail ËÍÐÅ (package mh-e)

Ç¿Áн¨Òé¸ÄÓÃemacs¶Ánews/bbs. ÊÀ½ç»á¸üÃÀºÃ!

¶ÁÐŵĻ°¾ÍÒª¿´ÄãµÄ¸Ð¾õ. ÕâЩ¶ÁÐųÌʽ¶¼»á°ÑÐÅ´ÓϵͳµÄmail folder°áµ½×Ô¼ºµÄĿ¼ÏÂ, Õ¼ÓÃquota, ÎÒ²»Ï²»¶¡¡½¨Òéelm»òmutt.
³ý·Ç²Î¼Ómailling listÅäºÏprocmail. ²»È»²»ÊµÓÃ.
ÓÃmh-e ÐëҪװmh Õâ¸öÍⲿ³Ìʽ, ²»Ì«ºÃ. ½¨Òévm »ò gnus.

Èç¹ûÄãµÄ×ÊÁÏÓÃrcs/sccs×÷°æ±¾¹ÜÀí, emacs×Ô¶¯»áÆð¶¯version control(minor mode.), c-x c-q ±ä³Écheck-in/check-out.

ÈçºÎÈ¡µÃ¸ü¶àµÄ×ÊѶ:

EmacsµÄlisp ¾­¹ý¶àÄêµÄ·¢Õ¹,ÒѳÉΪÍêÕûµÄself-documentingϵͳ.
ºÜ¶à¶«Î÷¶¼¿ÉÒÔÏßÉÏÕÒµ½ÄãÒªµÄ×ÊѶ.

Ç°Ãæ˵¹ý,»òÕßÄãÒѾ­²»Ð¡ÐÄ°´backspaceÓöµ½ÁË, C-h (¾ÍÊÇbackspaceµÄasciiÂë) ÔÚemacsÀïÃæÊÇhelpµÄÒâ˼, Ëü¿ÉÒÔ´ø³öÒ»´®Ö¸Áî.³£ÓõÄÓÐ:

C-h F¡¡ Emacs FAQ
C-h t¡¡ Emacs Tutorial
C-h n¡¡ Emacs NEWS file, ½éÉÜ×î½ü¸Ä°æµÄй¦ÄÜ
C-h i¡¡ Info system. InfoÊÇgnuÓÃÀ´È¡´úman pageµÄϵͳ, »ù±¾ÉϺÍÎÄ×ÖģʾµÄWWW²î²»¶à. ÓÐÐí¶àÖØÒªµÄ×ÊѶ ¿ÉÒÔÔÚÕâ±ßÕÒµ½. Èç¹ûÄãÊÇÐÂÊÖ, ½¨ÒéÄãÔÚx-winÏ ¿´. ²»È», °´¼ü m (menuitem), SPC next page l (last node: node¾ÍÊÇÕ½ڵÄÒâ˼) u (up node) d (directory, Ë÷Òý). BS (Backspace, back a page). Èç¹ûÈ«²¿Ö»°´SPC, ¾Í¸úman Ò»Ñù.
C-h k¡¡ describe key, ¸æËßÄã°´Õâ¸ö¼üÖ´ÐÐÄǸölisp function.
C-h f¡¡ describe function. ¸æËßÄãfunctionÔÚ×÷ʲô. Èç¹ûÖ»°´SPC, emacs»á¸øÄãËùÓÐlisp º¯ÊýµÄÁбí, ºÍ˵Ã÷.
C-h v¡¡ describe variable ͬfunction.
C-h a¡¡ aproposµÄÒâ˼(approximate).¡¡¸ølisp functionµÄ²¿·Ý ×Ö´®, emacs°ïÄãÕÒ.
C-h b¡¡ ÁгöÄ¿Ç°ËùÓеÄkeybinding
C-h m¡¡ mode help. ÁгöÄ¿Ç°µÄmodeµÄÌØÊâ˵Ã÷.
C-c C-h ÁгöÒÔC-c ¿ªÍ·µÄËùÓÐkey-binding. ËäȻ˵Emacs ¿ÉÒÔ¶¨Òå°´¼ü, ¿ÉÊÇCtrl- ¿ªÍ·µÄËùÓÐ×éºÏ´ó¸Å¶¼ÓùâÁË, Ö»ÓÐC-cËãÊÇ¿ÉÒÔ×Ô¶¨Ö¸Áî. ²»¹ýÓÐЩmodeÒ²ÇÖ·¸Õâ¸ö¿Õ¼ä. Ä¿Ç°µÄconventionÊÇC-c Áô¸øuser, C-c C- Áô¸øpackage.

ÓÐÒÔÉÏÕâЩhelp, ÄãµÄemacs/elisp¹¦Á¦»áËæÖøʱ¼ä³É³¤.

Elisp ¼ò½é:

EmacsÓÐÈý·ÝÊÖ²á.µÚÒ»·ÝÊÇʹÓÃÊÖ²á, µÚ¶þ·ÝÊÇElisp ÊÖ²á, µÚÈý·ÝÊÇElisp ¼ò½é.¡¡µÚÈý·ÝµÄ³Ì¶ÈÊÇÈëÃż¶, ÖµµÃ¿´. ElispÊÖ²áÆäʵҲдµÄºÜ¼òµ¥, »¹½ÌÄãlisp, ²»¹ýÓе㳤, Êʺϲο¼.

ÒòΪÎÒlispûÓÐ×Ðϸѧ¹ý, ËùÒÔ:
ÒÔÏÂËùÑÔ, ÈçÓÐÇɺÏ, ÄDzÅÊÇÕæµÄ.

Basic data type
×Ö´® (string) "Hello, World"
×ÖÔª (char)¡¡?a¡¡¡¡¡¡¡¡¡¡¡¡¡¡ ; ÎʺſªÍ·
atom & list:
(1 2 3 4)¡¡ÊÇÒ»¸ölist, ÓÉ 4¸ö atom ×é³É.
pair:¡¡ÖмäÊǾäµã.
(apple . 2)
alist (associated list)
¾ÍÊÇÒ»¶Ñ pairµÄ¼¯ºÏ,¾ÍÏñperl/tclµÄassociative array.
»òÕß˵ÊÇÒ»¸ö×ÊÁÏ¿â, Ò»¶Ñ (key, value) pair.
'((Apple¡¡¡¡ . 1)
(Orange¡¡¡¡. 2)
(PineApple . 3))
vector (?)
emacs 19ÓÃvector À´±íʾ°´¼ü(key strok sequence)
[f1] [f2] [f1 a]

nil¡¡¾ÍÊÇ¿ÕµÄlist, »òÕß±íʾ false
t¡¡¡¡true
Forms
ÎÒÃÇд³Ìʽ×îºÃÓÐÑù°æÈÃÎÒÃÇÌî¿Õ×î¼òµ¥ÁË.
Form ¾ÍÊÇÑù°æ, ²»¹ýÒâÒ岻̫һÑù.
Form ¾ÍÊÇElisp ¿ÉÒÔ½ÓÊܵľäÐÍ.
lisp ½âÒëÆ÷ Ô¤ÉèÊǶÔlistµÄÿ¸öÔªËØÇóÖµ(evaluate),
³ý·ÇÊÇ special form, ÓÐÌØÊâµÄ¶¨Òå. ±ÈÈç˵

(defun FUNC (ARG-LIST)
BODY ...)

¾ÍÊÇÒ»¸öspecial form, ÓÃÀ´¶¨Ò庯ʽ, ËùÒÔFUNC ²»»á±» ÇóÖµ, ±»µ±³Ésymbol, ...

(quote (LIST))

ÕâÒ²ÊǸöspecial form, ½Ð lisp °Ñ (LIST)µ±×ösymbol¾ÍºÃÁË, ²»Òª evaluate.

quote ºÜ³£ÓÃ, ËùÒÔÓиöËõд:
'(LIST)¡¡µÈÓÚ (quote (LIST))
'Asymbol ¿ÉÒÔ±íʾһ¸öAtom, Ãû³Æ½ÐAsymbol

set ¿ÉÒÔ²úÉú/¶¨ÒåеıäÊý.
(set 'hello 1)
; hello = 1
; ×¢ÒâÎÒÃÇÓà 'hello, ËùÒÔlisp²»»áevaluate helloµÄÖµ.

Õâ¼Ò»ïºÜ³£ÓÃ, Ò²Óмòд.
(setq hello 1)
setq ¾ÍÊÇset quote µÄËõд. ÕâÊǸö special form, ²»»á¶Ô µÚ¶þ¸öÔªËØÇóÖµ.

Evaluation

ÔÚEmacsÏÂ, C-x C-e ¿ÉÒÔÖ´ÐÐ(evaluate, ÇóÖµ)Óαê×ó±ßµÄÐðÊö. ½á¹û»á³öÏÖÔÚminibuffer.

lisp-interaction-modeÖÐ C-j ¿ÉÒÔevaluate, ²¢ÇҰѽá¹ûappendµ½ buffer.

lisp ³ÌʽÓÉÒ»¶Ñlist ¹¹³É.³ÆΪexpression.
ÿ¸öexpression ¶¼»Ø´«»ØÒ»¸öÖµ.
ÓÐЩexpressionÓи±×÷ÓÃ, ÈçɾµôÒ»¸ö×Ö.
(Õâ¸úC µÄint delete_char() Òâ˼һÑù, Ëü´«»Øint, ²¢ÇÒɾµôij¸öchar)

¶¨Ò庯ʽ:

(defun NAME (ARGS-LIST)
"×¢½â"¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡; optional
(interactive)¡¡¡¡¡¡¡¡¡¡ ; optional
BODY)

¶¨ÒåÒ»¸ö½ÐNAMEµÄº¯Ê½. BODY ÊÇÒ»¶Ñexpression.
×¢½âÊÇÓÃÀ´¸øC-h fÏÔʾµÄ.
(interactive) ±íʾÕâ¸öº¯Ê¾»áºÍuser/buffer×÷ÓÃ.
(interactive "B") ±íʾִÐд˺¯Ê½ÏÈÎÊuserÒ»¸öbufferµÄÃû×Ö, È»ºóµ±×÷²ÎÊý´«¸øËü. (Èç, µ±user͸¹ýkey-binding »òÕß M-x ºô½Ð´Ëº¯Ê½Ê±)
(interactive "BAppend to buffer: \nr")
ÎÊuser buffer nameʱ, ÌáʾºÅ Append to buffer: ´ËfunctionÓÐÁ½¸öÒýÊý,µÚÒ»¸öÊÇB, ¾ÍÊÇbuffer µÚ¶þ¸öÊÇr, region ÓÃ\n ¸ô¿ª.
(interactive "p") ÓÃC-u ÉèµÄprefix °ÑËüµ±×÷²ÎÊý´«¸øÎÒ.
Ô¤ÉèÖµ==4. C-u C-f ÏòÓÒÒÆËĸö×Ö

һЩlisp º¯Ê½:

(list 1 2 3 4)¡¡ ²úÉú '(1 2 3 4)
(car '(1 2 3 4)¡¡¡¡¡¡ 1
(cdr '(1 2 3 4)¡¡¡¡¡¡ '(2 3 4)
(cons 1 '(2 3 4))¡¡¡¡ '(1 2 3 4)
(cons 1 2)¡¡¡¡¡¡¡¡¡¡¡¡(1 . 2)
(cons 0 (cons 1¡¡(cons 2 nil)))
µÈÓÚ¡¡'(0 1 2)
{list ÊÇÓà pair ´®ÆðÀ´µÄ, ÓÃC ±íʾ:
pair: {Object *first, Object *second};
*(pair[i].first) == i;
pair[i].second == pair[i+1]; }

(cons '(1 2) '(3 4))¡¡'((1 2) 3 4)
(setq a 1)
(1+ a)¡¡¡¡¡¡¡¡; a+1
(+ 2 a)¡¡¡¡¡¡ ; a+2
(* 1 2 3 4)
(current-buffer)¡¡; ´«»ØÄ¿Ç°bufferµÄ×ÊÁÏÎï¼þ
(switch-to-buffer (other-buffer))
(set-buffer)
(buffer-size)
(setq current-pos (point))
(point-min)
(point-max)
(message "Hello")¡¡ ; ÔÚminibufferÏÔʾHello
(if (test)
(then-part)
(else-part))
(cond ((test1) BODY1)
((test2) BODY2)
(t¡¡OTHER-WISE)
(let ((var1 value)¡¡; local variable
var2¡¡¡¡¡¡¡¡¡¡¡¡ ; no value
(var3 value)
...)
BODY ...)
(lambda (ARG-LIST) ...) ͬ defun, µ«ÊÇûÓÐÃû×Ö (anonymous).
¿ÉÒÔ´æµ½±äÊýÈ¥:
(setq hello (lambda () (message "Hello,World")))
(funcall hello)
(goto-char (point-max))
(defvar VAR VALUE "*×¢½â") Èç¹ûVAR ²»´æÔڲŶ¨Òå. ÓÐ×¢½â¿ÉÒÔÓÃC-h v ¿´. ×¢½â´ò*ºÅ±íÊÇʹÓÃÕß¿ÉÒÔÖ±½Ó¸Ä/ Õâ¸ö±äÊý±¾À´¾ÍÊǸøʹÓÃÕßÉ趨ÓõÄ.
¿ÉÒÔÓà M-x edit-options À´ÏßÉÏÉ趨 (emacs½áÊø¾ÍûÓÐÁË, ²»¹ýedit-options¿ÉÒÔ¸øÄãËùÓпÉÐ޸ĵıäÊýµÄÁбí,Äã¿ÉÒÔ ·Åµ½.emacsµµÄÚ.

(directory-files "./" t "\\..*")
return a list of files under directory X
(load "xxxx.el")¡¡Í¬#include
(setq load-path (cons "~/emacs" load-path)) ; loadµÄsearch path.
(autoload ...) ²»Ïñload»áÖ±½Óevaluate Õû¸öµµ°¸, ¶øÊÇÐèҪʱÔÙload.
(local-unset-key [(control c)])
(local-set-key [(control c) a] 'forward-sexp)
sexp ¾ÍÊÇÒ»¸öexpession, n¸öexpressionÈç¹ûÓÃÀ¨ºÅÀ¨ÆðÀ´¾ÍËãÒ»¸ö.(expressionµÄ¶¨ÒåËæÓïÑԵIJ»Í¬¶øÓв»Í¬, ÔÚC, lisp tex, html, fortran ϽÔÓвîÒì)
ÎÄÕÂÆÀÂÛ

¹²ÓÐ 0 ÌõÆÀÂÛ