scel: Add support for completion-at-point-functions and company-mode
This commit is contained in:
parent
7b5d954003
commit
7bfbd1929d
3 changed files with 47 additions and 3 deletions
14
CHANGELOG.md
Normal file
14
CHANGELOG.md
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
# Changelog
|
||||||
|
All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||||
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
|
## [Unreleased]
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- Support for `completion-at-point-functions` and `company` via `company-capf`
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- `M-<tab>` or `C-M-i` is no longer bound to `sclang-complete-symbol`
|
||||||
|
to make builtin completion work as expected.
|
|
@ -453,6 +453,24 @@ are considered."
|
||||||
(insert " \n"))))
|
(insert " \n"))))
|
||||||
(sclang-message "Making completion list...%s" "done")))))
|
(sclang-message "Making completion list...%s" "done")))))
|
||||||
|
|
||||||
|
(defun sclang-completion-at-point ()
|
||||||
|
"Function used for `completion-at-point-functions' in `sclang-mode'."
|
||||||
|
(let* ((end (point))
|
||||||
|
(beg (save-excursion
|
||||||
|
(backward-sexp 1)
|
||||||
|
(skip-syntax-forward "'")
|
||||||
|
(point)))
|
||||||
|
(pattern (buffer-substring-no-properties beg end))
|
||||||
|
(case-fold-search nil)
|
||||||
|
(predicate (if (sclang-class-name-p pattern)
|
||||||
|
#'sclang-class-name-p
|
||||||
|
#'sclang-method-name-p)))
|
||||||
|
(list beg
|
||||||
|
end
|
||||||
|
(all-completions pattern sclang-symbol-table predicate)
|
||||||
|
:exclusive 'no
|
||||||
|
:company-docsig #'identity)))
|
||||||
|
|
||||||
;; =====================================================================
|
;; =====================================================================
|
||||||
;; introspection
|
;; introspection
|
||||||
;; =====================================================================
|
;; =====================================================================
|
||||||
|
|
|
@ -15,8 +15,15 @@
|
||||||
;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||||
;; USA
|
;; USA
|
||||||
|
|
||||||
|
;;; Code:
|
||||||
|
|
||||||
(require 'cl-lib)
|
(require 'cl-lib)
|
||||||
|
|
||||||
|
;; Make byte-compiler happy by declaring external functions and
|
||||||
|
;; variables.
|
||||||
|
(declare-function company-mode "ext:company")
|
||||||
|
(defvar company-backends)
|
||||||
|
|
||||||
(eval-when-compile
|
(eval-when-compile
|
||||||
(require 'font-lock)
|
(require 'font-lock)
|
||||||
(require 'sclang-util))
|
(require 'sclang-util))
|
||||||
|
@ -125,7 +132,6 @@
|
||||||
(define-key map "\C-c\C-f" 'sclang-eval-document)
|
(define-key map "\C-c\C-f" 'sclang-eval-document)
|
||||||
;; language information
|
;; language information
|
||||||
(define-key map "\C-c\C-n" 'sclang-complete-symbol)
|
(define-key map "\C-c\C-n" 'sclang-complete-symbol)
|
||||||
(define-key map "\M-\t" 'sclang-complete-symbol)
|
|
||||||
(define-key map "\C-c:" 'sclang-find-definitions)
|
(define-key map "\C-c:" 'sclang-find-definitions)
|
||||||
(define-key map "\C-c;" 'sclang-find-references)
|
(define-key map "\C-c;" 'sclang-find-references)
|
||||||
(define-key map "\C-c}" 'sclang-pop-definition-mark)
|
(define-key map "\C-c}" 'sclang-pop-definition-mark)
|
||||||
|
@ -667,8 +673,7 @@ Returns the column to indent to."
|
||||||
|
|
||||||
(defun sclang-mode ()
|
(defun sclang-mode ()
|
||||||
"Major mode for editing SuperCollider language code.
|
"Major mode for editing SuperCollider language code.
|
||||||
\\{sclang-mode-map}
|
\\{sclang-mode-map}"
|
||||||
"
|
|
||||||
(interactive)
|
(interactive)
|
||||||
(kill-all-local-variables)
|
(kill-all-local-variables)
|
||||||
(set-syntax-table sclang-mode-syntax-table)
|
(set-syntax-table sclang-mode-syntax-table)
|
||||||
|
@ -679,6 +684,13 @@ Returns the column to indent to."
|
||||||
(sclang-set-font-lock-keywords)
|
(sclang-set-font-lock-keywords)
|
||||||
(sclang-init-document)
|
(sclang-init-document)
|
||||||
(sclang-make-document)
|
(sclang-make-document)
|
||||||
|
|
||||||
|
;; Setup completion
|
||||||
|
(add-hook 'completion-at-point-functions
|
||||||
|
#'sclang-completion-at-point nil 'local)
|
||||||
|
(when (fboundp 'company-mode)
|
||||||
|
(add-to-list 'company-backends 'company-capf))
|
||||||
|
|
||||||
(run-hooks 'sclang-mode-hook))
|
(run-hooks 'sclang-mode-hook))
|
||||||
|
|
||||||
;; =====================================================================
|
;; =====================================================================
|
||||||
|
|
Loading…
Reference in a new issue