在 Emacs 中使用 sdcv

在 Emacs 配置文件中加入以下代码

  1. (global-set-key (kbd "C-c d") 'kid-sdcv-to-buffer)
  2. (defun kid-sdcv-to-buffer ()
  3. (interactive)
  4. (let ((word (if mark-active
  5. (buffer-substring-no-properties (region-beginning) (region-end))
  6. (current-word nil t))))
  7. (setq word (read-string (format "Search the dictionary for (default %s): " word)
  8. nil nil word))
  9. (set-buffer (get-buffer-create "*sdcv*"))
  10. (buffer-disable-undo)
  11. (erase-buffer)
  12. (let ((process (start-process-shell-command "sdcv" "*sdcv*" "sdcv" "-n" word)))
  13. (set-process-sentinel
  14. process
  15. (lambda (process signal)
  16. (when (memq (process-status process) '(exit signal))
  17. (unless (string= (buffer-name) "*sdcv*")
  18. (setq kid-sdcv-window-configuration (current-window-configuration))
  19. (switch-to-buffer-other-window "*sdcv*")
  20. (local-set-key (kbd "d") 'kid-sdcv-to-buffer)
  21. (local-set-key (kbd "q") (lambda ()
  22. (interactive)
  23. (bury-buffer)
  24. (unless (null (cdr (window-list))) ; only one window
  25. (delete-window)))))
  26. (goto-char (point-min))))))))

1

如果选中区域则查询区域内容,否则查询当前光标所在单词。查询结果显示在一个叫做 sdcv 的缓冲区

2

sdcv 里面按 q,将它隐藏到缓冲区列表的结尾

3

sdcv 里面按 d 查询当前单词