mirror of
https://github.com/godotengine/emacs-gdscript-mode.git
synced 2026-01-03 10:09:25 +03:00
Add basic auto-completion support
This adds support for all the keywords found in the data/* directory using Emacs's built-in completion system.
This commit is contained in:
49
gdscript-completion.el
Normal file
49
gdscript-completion.el
Normal file
@@ -0,0 +1,49 @@
|
||||
;;; gdscript-completion.el --- Autocompletion for GDScript. -*- lexical-binding: t -*-
|
||||
|
||||
;; Copyright (C) 2020 GDQuest, Free Software Foundation, Inc.
|
||||
|
||||
;; Author: Nathan Lovato <nathan@gdquest.com>, Fabián E. Gallina <fgallina@gnu.org>
|
||||
;; URL: https://github.com/GDQuest/emacs-gdscript-mode/
|
||||
;; Version: 0.1.0
|
||||
;; Package-Requires: ((emacs "26.0"))
|
||||
;; Maintainer: nathan@gdquest.com
|
||||
;; Created: Feb 2020
|
||||
;; Keywords: languages
|
||||
|
||||
;; This file is not part of GNU Emacs
|
||||
|
||||
;; This file is free software; you can redistribute it and/or modify
|
||||
;; it under the terms of the GNU General Public License as published by
|
||||
;; the Free Software Foundation; either version 3, or (at your option)
|
||||
;; any later version.
|
||||
|
||||
;; This program is distributed in the hope that it will be useful,
|
||||
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
;; GNU General Public License for more details.
|
||||
|
||||
;; For a full copy of the GNU General Public License
|
||||
;; see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
;;; Commentary:
|
||||
|
||||
;; Provides keywords for 'completion-at-point'.
|
||||
|
||||
;;; Code:
|
||||
|
||||
(require 'gdscript-syntax)
|
||||
|
||||
(defvar-local gdscript--completion-keywords (append gdscript-keywords gdscript-built-in-classes gdscript-built-in-constants gdscript-built-in-functions gdscript-built-in-types))
|
||||
|
||||
(defun gdscript-completion-at-point ()
|
||||
"This is the function to be used for the hook `completion-at-point-functions'."
|
||||
(interactive)
|
||||
(let* ((bounds (bounds-of-thing-at-point 'symbol))
|
||||
(start (car bounds))
|
||||
(end (cdr bounds)))
|
||||
(list start end gdscript--completion-keywords . nil)))
|
||||
|
||||
(provide 'gdscript-completion)
|
||||
|
||||
;;; gdscript-completion.el ends here
|
||||
@@ -1,4 +1,5 @@
|
||||
;;; gdscript-mode.el --- Major mode to add support for Godot's GDScript programming language. -*- lexical-binding: t; -*-
|
||||
;;; gdscript-mode.el --- Major mode to add support for Godot's GDScript
|
||||
;;; programming language. -*- lexical-binding: t; -*-
|
||||
|
||||
;; Copyright (C) 2020 GDQuest, Free Software Foundation, Inc.
|
||||
|
||||
@@ -34,6 +35,8 @@
|
||||
(require 'gdscript-indent-and-nav)
|
||||
(require 'gdscript-imenu)
|
||||
(require 'gdscript-fill-paragraph)
|
||||
(require 'gdscript-completion)
|
||||
|
||||
;; gdscript-rx is a copy of Emacs 27's rx module, to ensure compatibility with
|
||||
;; Emacs 26
|
||||
(if (version< emacs-version "27")
|
||||
@@ -95,8 +98,7 @@ This variant of `rx' supports common Gdscript named REGEXPS."
|
||||
(* ?\\ ?\\) (any ?\' ?\")))
|
||||
(* ?\\ ?\\)
|
||||
;; Match single or triple quotes of any kind.
|
||||
(group (or "\"\"\"" "\"" "'''" "'"))))
|
||||
)
|
||||
(group (or "\"\"\"" "\"" "'''" "'")))))
|
||||
(rx ,@regexps)))
|
||||
|
||||
(defun gdscript-hideshow-forward-sexp-function (_arg)
|
||||
@@ -106,32 +108,21 @@ Argument ARG is ignored."
|
||||
(unless (gdscript-info-current-line-empty-p)
|
||||
(backward-char)))
|
||||
|
||||
|
||||
;; Abbreviations
|
||||
(define-abbrev-table 'gdscript-abbrev-table
|
||||
'(
|
||||
("p" "func _process(delta):\n" )
|
||||
("pp" "func _physics_process(delta):\n" )
|
||||
)
|
||||
"Table of abbreviations to use with abbrev-mode for `gdscript'"
|
||||
)
|
||||
(abbrev-table-put gdscript-abbrev-table :regexp "\\([_-*0-9A-Za-z]+\\)")
|
||||
(abbrev-table-put gdscript-abbrev-table :case-fixed t)
|
||||
(abbrev-table-put gdscript-abbrev-table :system t)
|
||||
|
||||
|
||||
(defun gdscript-electric-pair-string-delimiter ()
|
||||
"GDScript-specific string delimiter detection for 'electric-pair-mode'.
|
||||
Return a doubled string character for 'electric-pair-mode', if
|
||||
the last command event was a string delimiter."
|
||||
(when (and electric-pair-mode
|
||||
(memq last-command-event '(?\" ?\'))
|
||||
(memq last-command-event
|
||||
'(?\" ?\') )
|
||||
(let ((count 0))
|
||||
(while (eq (char-before (- (point) count)) last-command-event)
|
||||
(while (eq (char-before (- (point)
|
||||
count)) last-command-event)
|
||||
(cl-incf count))
|
||||
(= count 3))
|
||||
(eq (char-after) last-command-event))
|
||||
(save-excursion (insert (make-string 2 last-command-event)))))
|
||||
|
||||
(defvar electric-indent-inhibit)
|
||||
(defvar prettify-symbols-alist)
|
||||
(save-excursion
|
||||
(insert (make-string 2 last-command-event)))))
|
||||
|
||||
(define-derived-mode gdscript-mode prog-mode "gdscript"
|
||||
"Major mode for editing Godot GDScript files."
|
||||
@@ -217,5 +208,4 @@ Argument ARG is ignored."
|
||||
(gdscript-indent-guess-indent-offset)))
|
||||
|
||||
(provide 'gdscript-mode)
|
||||
|
||||
;;; gdscript-mode.el ends here
|
||||
|
||||
Reference in New Issue
Block a user