branch: elpa/forth-mode
commit 2813a7bf3dbcdf7780834b53385993620c7a9fd5
Author: Helmut Eller <[email protected]>
Commit: Lars Brinkhoff <[email protected]>
Introduce a hook to initialize backends
Run a hook to initialize backends as require only executes the file once.
---
backend/gforth.el | 6 +++++-
backend/swiftforth.el | 13 ++++++-------
forth-interaction-mode.el | 8 +++++++-
3 files changed, 18 insertions(+), 9 deletions(-)
diff --git a/backend/gforth.el b/backend/gforth.el
index 9515268f28..6d5983fec5 100644
--- a/backend/gforth.el
+++ b/backend/gforth.el
@@ -1,5 +1,9 @@
(require 'forth-interaction-mode)
-(forth-interaction-send "' drop is Attr!")
+(defun forth-gforth-init (backend-type process)
+ (when (eq backend-type 'gforth)
+ (forth-interaction-send "' drop is Attr!")))
+
+(add-hook 'forth-interaction-init-backend-hook #'forth-gforth-init)
(provide 'gforth)
diff --git a/backend/swiftforth.el b/backend/swiftforth.el
index 4a91c26a6c..3399225ede 100644
--- a/backend/swiftforth.el
+++ b/backend/swiftforth.el
@@ -1,12 +1,11 @@
(require 'forth-interaction-mode)
-(set-process-coding-system (get-buffer-process forth-interaction-buffer)
- 'raw-text-dos 'raw-text-dos)
-(save-excursion
- (with-current-buffer forth-interaction-buffer
- (goto-char (point-max))
- (insert "\n")))
+(defun forth-swiftforth-init (backend-type process)
+ (when (eq backend-type 'swiftforth)
+ (set-process-coding-system process 'raw-text-dos 'raw-text-dos)
+ (forth-interaction-send (concat "include " forth-backend-dir
+ "/swiftforth.fth"))))
-(forth-interaction-send (concat "include " forth-backend-dir
"/swiftforth.fth"))
+(add-hook 'forth-interaction-init-backend-hook #'forth-swiftforth-init)
(provide 'swiftforth)
diff --git a/forth-interaction-mode.el b/forth-interaction-mode.el
index ef0c9e788d..6273a32df9 100644
--- a/forth-interaction-mode.el
+++ b/forth-interaction-mode.el
@@ -31,13 +31,19 @@
:syntax-table forth-mode-syntax-table
(use-local-map forth-interaction-mode-map))
+(defvar forth-interaction-init-backend-hook '())
+
(defun forth-interaction-preoutput-filter (text)
(unless forth-implementation
(setq forth-banner (concat forth-banner text))
(dolist (x forth-implementation-matches)
(when (string-match (car x) forth-banner)
+ (setq forth-implementation (cdr x))
(let ((load-path (cons forth-backend-dir load-path)))
- (require (setq forth-implementation (cdr x)))))))
+ (require forth-implementation))
+ (run-hook-with-args 'forth-interaction-init-backend-hook
+ forth-implementation
+ (get-buffer-process (current-buffer))))))
(if forth-interaction-callback
(funcall forth-interaction-callback text)
text))