How to Interactively Run Gforth Inside Emacs

By Jim Brooks  www.jimbrooks.org/forth/

  1. Download and install Gforth.

  2. Copy gforth.el from the Gforth source tarball to whatever directory you want
    (I chose ~/misc/gforth.el).

  3. Add this emacs LISP code to your ~/.emacs file:
    (substitute /misc/gforth.el with your choice)
     
    (defvar HOME (expand-file-name "~"))
    
    ;; ------
    ;; FORTH
    ;; ------
    (defvar GFORTH_EL (concat HOME "/misc/gforth.el"))
    (cond ((file-readable-p GFORTH_EL)
      (load-library GFORTH_EL)
      (autoload 'forth-mode GFORTH_EL)
      (setq auto-mode-alist (cons '("\\.fs\\'" . forth-mode) auto-mode-alist))
      (autoload 'forth-block-mode GFORTH_EL)
      (setq auto-mode-alist (cons '("\\.fb\\'" . forth-block-mode) auto-mode-alist))
      (add-hook 'forth-mode-hook (function (lambda ()
        (setq forth-indent-level 4)
        (setq forth-minor-indent-level 2)
        (setq forth-hilight-level 3))))
    ))
    

  4. Run Gforth inside emacs:
     
    M-x run-forth
    The emacs window should split with Gforth running in the bottom.

  5. Load your file containing FORTH source code.
    Or, if you want to type FORTH words interactively,
    create a new emacs buffer and change its mode to FORTH by:
     
    M-x forth-mode

  6. Select (highlight/mark) the source code you want to paste into the FORTH interpreter,
    then type (don't switch emacs buffers):
     
    M-x forth-send-region   (or  C-c C-r  which is  Ctrl-c Ctrl-r)
    This should pipe FORTH commands to the Gforth process running in the bottom window.
    index   home