branch: elpa/forth-mode
commit cc267b4b85e89aabbfaf8835c1ea44d7653376b4
Author: Lars Brinkhoff <[email protected]>
Commit: Lars Brinkhoff <[email protected]>
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 "("