From 7bfbd1929d6e122ee609d7df006e57b351755c74 Mon Sep 17 00:00:00 2001 From: TatriX Date: Wed, 26 Feb 2020 15:18:07 +0100 Subject: [PATCH] scel: Add support for completion-at-point-functions and company-mode --- CHANGELOG.md | 14 ++++++++++++++ el/sclang-language.el | 18 ++++++++++++++++++ el/sclang-mode.el | 18 +++++++++++++++--- 3 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..f08e7a5 --- /dev/null +++ b/CHANGELOG.md @@ -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-` or `C-M-i` is no longer bound to `sclang-complete-symbol` + to make builtin completion work as expected. diff --git a/el/sclang-language.el b/el/sclang-language.el index 40f2bbb..4239355 100644 --- a/el/sclang-language.el +++ b/el/sclang-language.el @@ -453,6 +453,24 @@ are considered." (insert " \n")))) (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 ;; ===================================================================== diff --git a/el/sclang-mode.el b/el/sclang-mode.el index 2c15218..83ce830 100644 --- a/el/sclang-mode.el +++ b/el/sclang-mode.el @@ -15,8 +15,15 @@ ;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 ;; USA +;;; Code: + (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 (require 'font-lock) (require 'sclang-util)) @@ -125,7 +132,6 @@ (define-key map "\C-c\C-f" 'sclang-eval-document) ;; language information (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-references) (define-key map "\C-c}" 'sclang-pop-definition-mark) @@ -667,8 +673,7 @@ Returns the column to indent to." (defun sclang-mode () "Major mode for editing SuperCollider language code. -\\{sclang-mode-map} -" +\\{sclang-mode-map}" (interactive) (kill-all-local-variables) (set-syntax-table sclang-mode-syntax-table) @@ -679,6 +684,13 @@ Returns the column to indent to." (sclang-set-font-lock-keywords) (sclang-init-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)) ;; =====================================================================