在 Emacs 中使用 sdcv

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

(global-set-key (kbd "C-c d1") '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-sentinel
       process
       (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 "d2") 'kid-sdcv-to-buffer)
             (local-set-key (kbd "q3") (lambda ()
                                        (interactive)
                                        (bury-buffer)
                                        (unless (null (cdr (window-list))) ; only one window
                                          (delete-window)))))
           (goto-char (point-min)))))))) 	  

1

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

2

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

3

在 *sdcv* 里面按 d 查询当前单词