Skip to main content
deleted 31 characters in body
Source Link

Here is a complete solution based on this discussion:

(require 'company)
(require 'cl-lib)

(defconst sample-completions
  '("procedural" "functional" "high-level" "low-level" "statically-scoped" "dynamically-scoped"))

;; This function is based on http://sixty-north.com/blog/writing-the-simplest-emacs-company-mode-backend
(defun company-sample-backend (command &optional arg &rest ignored)
  (interactive (list 'interactive))
  (let ((my-completions (copy-sequence sample-completions)))
    (cl-case command
      (interactive (company-begin-backend 'company-sample-backend))
      (prefix (and t ;(eq major-mode 'fundamental-mode)
           (company-grab-symbol)))
      (candidates
       (cl-remove-if-not
    (lambda (c) (string-prefix-p arg c))
    my-completions)))))

(define-key company-mode-map (kbd "TAB") 'company-sample-backend)

(setq resize-mini-windows t)

(defun my-minibuffer-mode ()
  (company-mode 1))

We can now perform the input without altering the normal function of the mini-buffer as follows:

(let ((company-backends (copy-sequence company-backends))
      (minibuffer-setup-hook (copy-sequence minibuffer-setup-hook)))
  (add-to-list 'company-backends 'company-sample-backend)
  (add-hook 'minibuffer-setup-hook 'my-minibuffer-mode)
  (read-from-minibuffer "Prompt: "))

Acknowledgement: thank you very much to everyone, especially @Drew and @Dmitry, for their comments.

Here is a complete solution based on this discussion:

(require 'company)
(require 'cl-lib)

(defconst sample-completions
  '("procedural" "functional" "high-level" "low-level" "statically-scoped" "dynamically-scoped"))

;; This function is based on http://sixty-north.com/blog/writing-the-simplest-emacs-company-mode-backend
(defun company-sample-backend (command &optional arg &rest ignored)
  (interactive (list 'interactive))
  (let ((my-completions (copy-sequence sample-completions)))
    (cl-case command
      (interactive (company-begin-backend 'company-sample-backend))
      (prefix (and t ;(eq major-mode 'fundamental-mode)
           (company-grab-symbol)))
      (candidates
       (cl-remove-if-not
    (lambda (c) (string-prefix-p arg c))
    my-completions)))))

(define-key company-mode-map (kbd "TAB") 'company-sample-backend)

(setq resize-mini-windows t)

(defun my-minibuffer-mode ()
  (company-mode 1))

We can now perform the input without altering the normal function of the mini-buffer as follows:

(let ((company-backends (copy-sequence company-backends))
      (minibuffer-setup-hook (copy-sequence minibuffer-setup-hook)))
  (add-to-list 'company-backends 'company-sample-backend)
  (add-hook 'minibuffer-setup-hook 'my-minibuffer-mode)
  (read-from-minibuffer "Prompt: "))

Acknowledgement: thank you very much to everyone, especially @Drew and @Dmitry, for their comments.

Here is a complete solution based on this discussion:

(require 'company)
(require 'cl-lib)

(defconst sample-completions
  '("procedural" "functional" "high-level" "low-level" "statically-scoped" "dynamically-scoped"))

;; This function is based on http://sixty-north.com/blog/writing-the-simplest-emacs-company-mode-backend
(defun company-sample-backend (command &optional arg &rest ignored)
  (interactive (list 'interactive))
  (let ((my-completions (copy-sequence sample-completions)))
    (cl-case command
      (interactive (company-begin-backend 'company-sample-backend))
      (prefix (and t ;(eq major-mode 'fundamental-mode)
           (company-grab-symbol)))
      (candidates
       (cl-remove-if-not
    (lambda (c) (string-prefix-p arg c))
    my-completions)))))

(define-key company-mode-map (kbd "TAB") 'company-sample-backend)

(setq resize-mini-windows t)

(defun my-minibuffer-mode ()
  (company-mode 1))

We can now perform the input without altering the normal function of the mini-buffer as follows:

(let ((company-backends (copy-sequence company-backends))
      (minibuffer-setup-hook (copy-sequence minibuffer-setup-hook)))
  (add-to-list 'company-backends 'company-sample-backend)
  (add-hook 'minibuffer-setup-hook 'my-minibuffer-mode)
  (read-from-minibuffer "Prompt: "))

Acknowledgement: thank you very much to everyone for their comments.

Source Link

Here is a complete solution based on this discussion:

(require 'company)
(require 'cl-lib)

(defconst sample-completions
  '("procedural" "functional" "high-level" "low-level" "statically-scoped" "dynamically-scoped"))

;; This function is based on http://sixty-north.com/blog/writing-the-simplest-emacs-company-mode-backend
(defun company-sample-backend (command &optional arg &rest ignored)
  (interactive (list 'interactive))
  (let ((my-completions (copy-sequence sample-completions)))
    (cl-case command
      (interactive (company-begin-backend 'company-sample-backend))
      (prefix (and t ;(eq major-mode 'fundamental-mode)
           (company-grab-symbol)))
      (candidates
       (cl-remove-if-not
    (lambda (c) (string-prefix-p arg c))
    my-completions)))))

(define-key company-mode-map (kbd "TAB") 'company-sample-backend)

(setq resize-mini-windows t)

(defun my-minibuffer-mode ()
  (company-mode 1))

We can now perform the input without altering the normal function of the mini-buffer as follows:

(let ((company-backends (copy-sequence company-backends))
      (minibuffer-setup-hook (copy-sequence minibuffer-setup-hook)))
  (add-to-list 'company-backends 'company-sample-backend)
  (add-hook 'minibuffer-setup-hook 'my-minibuffer-mode)
  (read-from-minibuffer "Prompt: "))

Acknowledgement: thank you very much to everyone, especially @Drew and @Dmitry, for their comments.