在 Emacs 中使用 sdcv
优质
小牛编辑
142浏览
2023-12-01
在 Emacs 配置文件中加入以下代码
(global-set-key (kbd "C-c d") 'kid-sdcv-to-buffer) (defun kid-sdcv-to-buffer () (interactive) (let ((word (if mark-active (buffer-substring-no-properties (region-beginning) (region-end)) (current-word nil t))))(setq word (read-string (format "Search the dictionary for (default %s): " word) nil nil word))(set-buffer (get-buffer-create "*sdcv*"))(buffer-disable-undo)(erase-buffer)(let ((process (start-process-shell-command "sdcv" "*sdcv*" "sdcv" "-n" word)))(set-process-sentinelprocess(lambda (process signal) (when (memq (process-status process) '(exit signal)) (unless (string= (buffer-name) "*sdcv*")(setq kid-sdcv-window-configuration (current-window-configuration))(switch-to-buffer-other-window "*sdcv*") (local-set-key (kbd "d") 'kid-sdcv-to-buffer)(local-set-key (kbd "q") (lambda () (interactive) (bury-buffer) (unless (null (cdr (window-list))) ; only one window (delete-window))))) (goto-char (point-min))))))))
|
如果选中区域则查询区域内容,否则查询当前光标所在单词。查询结果显示在一个叫做 *sdcv* 的缓冲区 |
|
在 *sdcv* 里面按 q,将它隐藏到缓冲区列表的结尾 |
|
在 *sdcv* 里面按 d 查询当前单词 |