在 Emacs 中,如何定义键盘快捷键以快速用 和 括住突出显示的文本,<tag>
并</tag>
选择性地提示输入标签名称tag
?
答案1
(defun my-tagger (tag)
(interactive "sTag: ")
(if (not (use-region-p))
(error "no region is highlighted")
(let ((text (buffer-substring (region-beginning) (region-end))))
(delete-region (region-beginning) (region-end))
(insert (format "<%s>%s</%s>" tag text tag)))))
(global-set-key (kbd "<f7>") 'my-tagger)