In Emacs, is there a way to autocomplete from only one specified buffer?

When using M- /, the text in the current buffer is auto-populated with sentences from all active buffers.

Is there a way to limit sentences to only one specific buffer?

+4
source share
1 answer

Assuming you are talking about dabbrev-expand ( M- / is a normal binding), then there are many options depending on your requirements.

To search for only a specific buffer whitelist, the easiest way is to set the dabbrev-search-these-buffers-only variable:

  "If non-nil, a list of buffers which dabbrev should search. If this variable is non-nil, dabbrev will only look in these buffers. It will not even look in the current buffer if it is not a member of this list." 

Here is an example from my own mode (I am reinstalling M-/ to this function for this mode)

 (defun tks-dabbrev-expand (arg) "Expand either aliases or descriptions, depending on context." (interactive "*P") (let* ((candidates (if (looking-back "^\\S-+") " *tks-aliases*" " *tks-descriptions*")) (dabbrev-search-these-buffers-only (list (get-buffer candidates)))) (dabbrev-expand arg))) 

Note that there are several other ways that you can filter the list of buffers that dabbrev will look for internally. The dabbrev configuration group has detailed information:
Mx customize-group RET dabbrev RET

+5
source

Source: https://habr.com/ru/post/1403885/


All Articles