感謝傑克遜的三分球。我不知道你發佈了一個解決方案,所以我去freenode上的#emacs尋求幫助。經過一番研究,我想出了以下內容:
(defun ess-R-wrap-content-vqn()
"Wrap marked region with a specified PREFIX and closing parentheses."
(interactive)
(set (make-local-variable 'prefix) (read-from-minibuffer "function: "))
(set (make-local-variable 'prefix) (concat prefix "("))
(save-excursion (goto-char (region-beginning)) (insert prefix))
(save-excursion (goto-char (region-end)) (insert ")"))
)
(define-key ess-mode-map "\C-c\M-w" 'ess-R-wrap-content-vqn) ;; w is for wrap
我以爲當解決方案發布時,會通知我stackoverflow。再次,謝謝。從這裏學習一點elisp。
參見:http://xahlee.org/emacs/wrap-url.html – 2009-11-19 10:47:20
另外這款提問/回答:http://stackoverflow.com/questions/1397113/how-to-tag-text -in-emacs/1397134#1397134。 – 2009-11-19 22:19:23
你會如何用yasnippet做這樣的事情?我熟悉: 1.鍵入關鍵字 2.展開 這涉及到在區域的開始和結尾添加文本。我也有興趣聽到這個解決方案。謝謝。 – 2009-11-20 08:34:34