emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/forth-mode cc267b4b85 043/153: Symbol completion. Candidat


From: ELPA Syncer
Subject: [nongnu] elpa/forth-mode cc267b4b85 043/153: Symbol completion. Candidates come from a running Forth.
Date: Sat, 29 Jan 2022 08:02:15 -0500 (EST)

branch: elpa/forth-mode
commit cc267b4b85e89aabbfaf8835c1ea44d7653376b4
Author: Lars Brinkhoff <lars.brinkhoff@delphi.com>
Commit: Lars Brinkhoff <lars.brinkhoff@delphi.com>

    Symbol completion.  Candidates come from a running Forth.
---
 README.md     |  4 +---
 forth-mode.el | 15 +++++++++++++++
 2 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/README.md b/README.md
index 6e014b220f..086635f40a 100644
--- a/README.md
+++ b/README.md
@@ -10,9 +10,6 @@ Features in progress:
   expressions.
 - Display stack comment when moving the cursor over a word.
 - Edit block files.
-
-Planned:
-
 - Tab completion.
 - Query a running Forth about words, search order, etc.
 
@@ -48,3 +45,4 @@ Key bindings:
 - `C-c C-l` - load file.
 - `C-c C-r` - evaluate region.
 - `C-c C-k` - kill interactive Forth.
+- `M-TAB`, `C-M-i` - complete-symbol.
diff --git a/forth-mode.el b/forth-mode.el
index e37d134a5b..222d9b8c7d 100644
--- a/forth-mode.el
+++ b/forth-mode.el
@@ -58,6 +58,20 @@
 (defvar forth-font-lock-keywords
   '((forth-match-definition 3 font-lock-function-name-face)))
 
+(defun forth-symbol-start ()
+  (save-excursion
+    (re-search-backward "[^[:graph:]]")
+    (1+ (point))))
+
+(defun forth-symbol-end ()
+  (save-excursion
+    (re-search-forward "[^[:graph:]]")
+    (1- (point))))
+
+(defun forth-expand-symbol ()
+  ;; Append result from (imenu--make-index-alist t)?
+  (list (forth-symbol-start) (forth-symbol-end) (forth-words)))
+
 (defun forth-block-p ()
   "Guess whether the current buffer is a Forth block file."
   (and (> (point-max) 1)
@@ -76,6 +90,7 @@
   (if (forth-block-p)
       (forth-block-mode))
   (setq font-lock-defaults '(forth-font-lock-keywords))
+  (setq-local completion-at-point-functions '(forth-expand-symbol))
   (setq ;; font-lock-defaults
        comment-start-skip "\\((\\*?\\|\\\\\\) *"
        comment-start "("



reply via email to

[Prev in Thread] Current Thread [Next in Thread]