2009-03-03 13 views
1

一些lanaguages,如Perl文本,支持打印預格式化代碼:Emacs的功能來包裝與printfs輸出

print <<EOL 
    a line 
    another line 
    and another. 
EOL 

有些語言沒有。

對於不感興趣,我希望能寫我的文字,然後將其轉化爲一串用printfs的:

 
printf "a line\n"; 
printf "another line\n"; 
printf "and another\n"; 

怎樣做這種轉換的好方法? (最好在Emacs)

回答

2
(defun my-add-printf (b e) 
    "Add printf's to region" 
    (interactive "r") 
    (let ((comment-start "\tprintf \"") 
     (comment-end "\\n\";")) 
    (comment-region b e))) 
+0

(評論區域評論結束)? – gone 2009-03-03 19:20:10

1

除非我不得不每天做很多次,我可能只是做交互:

M-x query-replace-regexp RET .* RET printf "\&\\n"; RET
1

只是覺得建議另兩種方式,確保CUA模式啓用,那麼你在開始時做C-enter,按下直到你到達最後一行(同一列)並鍵入'printf''

另一個是製作一個宏,輸入如下:

C-x ( 
printf " 
C-e 
"; 
C-a 
C-n 
C-x) 
C-x e 
e e e e e e e e ....