Skip to content

Emacs interface for 'sdcv' (command-line offline dictionary)

License

Notifications You must be signed in to change notification settings

jamescherti/quick-sdcv.el

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

quick-sdcv.el - Emacs interface for the 'sdcv' command-line dictionary

Build Status License

The quick-sdcv package serves as a lightweight Emacs interface for the sdcv command-line interface, which is the console version of the StarDict dictionary application.

This package enables Emacs to function as an offline dictionary.

This integration allows users to access and utilize dictionary functionalities directly within the Emacs environment, leveraging the capabilities of sdcv to look up words and translations from various dictionary files formatted for StarDict.

Here are the main interactive functions:

  • quick-sdcv-search-at-point: Searches the word around the cursor and displays the result in a buffer.
  • quick-sdcv-search-input: Searches the input word and displays the result in a buffer.

Table of Contents

Installation

Prerequisite: The sdcv command. It can usually be installed by installing the sdcv package.

Install using straight

To install quick-sdcv using straight.el:

  1. It if hasn't already been done, add the straight.el bootstrap code to your init file.
  2. Add the following code to the Emacs init file:
(use-package quick-sdcv
  :ensure t
  :straight (quick-sdcv
             :type git
             :host github
             :repo "jamescherti/quick-sdcv.el")
  :custom
  (quick-sdcv-ellipsis ""))

Customizations

To create a unique buffer for each word lookup, set the following:

(setq quick-sdcv-unique-buffers t)

To perform exact word searches (as opposed to fuzzy searches), use:

(setq quick-sdcv-exact-search t)

To change the prefix character used before dictionary names, replacing the default -->, set:

(setq quick-sdcv-dictionary-prefix-symbol "")

To customize the sdcv history size:

(setq quick-sdcv-hist-size 100)

To specify the path to the sdcv executable:

(setq quick-sdcv-program "/path/to/sdcv")

To customize the naming convention of the SDCV buffer:

(setq quick-sdcv-buffer-name-prefix "*sdcv"
      quick-sdcv-buffer-name-separator ":"
      quick-sdcv-buffer-name-suffix "*")

To specify a list of dictionaries:

(setq quick-sdcv-dictionary-complete-list '("stardict-WordNet"
                                            "stardict-Webster"
                                            "stardict-eng_eng_main"))

Improvements Made

  • Streamlined phrasing for clarity.
  • Enhanced the structure to emphasize the purpose of each setting.

Usage

Below are the commands you can use:

Command Description
quick-sdcv-search-at-point Searches the word around the cursor and displays the result in a buffer.
quick-sdcv-search-input Searches the input word and displays the result in a buffer.

If the current mark is active, the quick-sdcv will translate the region string; otherwise, they will translate the word around the cursor.

Frequently asked question

What is the difference between sdcv (MELPA) and quick-sdcv Emacs packages?

The quick-sdcv Emacs package is a fork of sdcv.el version 3.4, which is available on MELPA. The primary differences between the two packages are as follows:

  • Less dependencies: Quick-sdcv does not require any external dependencies; sdcv, on the other hand, installs popup, pos-tip, and showtip.
  • Customize the buffer name:: New variables to customize whether the word is included in the buffer name, as well as the prefix, separator, and suffix of the buffer name (quick-sdcv-unique-buffers, quick-sdcv-buffer-name-prefix, quick-sdcv-buffer-name-separator, and quick-sdcv-buffer-name-suffix). When the buffer is dedicated to a specific word, refresh it only when the buffer is created.
  • Improved Outline Minor Mode: The quick-sdcv package fixes the outline minor mode for dictionary folding, enabling users to collapse all definitions for quicker navigation through dictionaries.
  • Default Language Settings: Various issues have been addressed, including changing the default language setting from Chinese (zh) to nil, providing a more neutral starting point.
  • Buffer Customization: The quick-sdcv package employs display-buffer, allowing users to customize the display of the sdcv buffer and control its placement through display-buffer-alist.
  • Removal of bugs and Warnings: All Emacs warnings have been eliminated and bugs fixed. (e.g., when quick-sdcv-search-at-point cannot locate the word under the cursor)
  • Code Simplification: The code has been simplified by removing unused variables and omitting features like posframe, text-to-speech using the 'say' command, the quick-sdcv-env-lang variable, and functions such as (quick-sdcv-scroll-up-one-line, quick-sdcv-scroll-down-one-line, quick-sdcv-next-line and quick-sdcv-prev-line) which are similar Emacs features. This simplification makes quick-sdcv easier to understand, maintain, and use by focusing solely on dictionary lookup functionality. Features like posframe and text-to-speech, which are not essential to core usage, are better suited as separate packages.
  • Keybindings removal: The default keybindings have been removed from quick-sdcv-mode to prevent conflicts with other modes and keeps the mode lightweight and adaptable for users’ preferences.
  • New options: quick-sdcv-ellipsis, quick-sdcv-hist-size, quick-sdcv-exact-search, quick-sdcv-buffer-name-prefix, quick-sdcv-buffer-name-separator, quick-sdcv-buffer-name-suffix, quick-sdcv-verbose
  • Various improvements: Unset the SDCV_PAGER environment variable, Ensure the buffer and the SDCV output are in UTF-8, Enhance dictionary representation with UTF-8 characters, Implement error handling for cases when the sdcv program is not found.

How to make the sdcv buffer replace the current buffer?

To make the SDCV buffer replace the current buffer, you can utilize the following display-buffer-alist rule:

(add-to-list 'display-buffer-alist '("\\*sdcv"
                                       (display-buffer-same-window)))

How to make links appear as links in an sdcv buffer?

To ensure that links appear as clickable links in the SDCV buffer while using quick-sdcv, add the following hook:

(add-hook 'quick-sdcv-mode-hook #'goto-address-mode)

Links