Open timmyjose opened 4 years ago
https://www.emacswiki.org/emacs/Forth-mode works pretty well
Welcome @timmyjose. I also use the Emacs Forth Mode, as I was working with @MitchBradley's source and it just made sense to stick to the same indentation. But I was and keep using it in my unpublished work. I also have some customisations in .emacs
;
(add-to-list 'auto-mode-alist '("\\.fth$" . forth-mode))
(add-to-list 'auto-mode-alist '("\\.bth$" . forth-mode))
(add-hook 'forth-mode-hook (function (lambda ()
(setq forth-indent-level 3)
(setq forth-minor-indent-level 1)
(setq forth-hilight-level 3))))
@MitchBradley @quozl Thank you! I was able to locate it on melpa as well, so it should be easy to set it up.
And @quozl, that snippet will come in very handy indeed. Thanks again!
Cheers.
My set of customizations is a bit more extensive that that of my good friend @quozl . To wit:
(defvar GFORTH_EL (concat HOME "/lisp/gforth.el"))
(cond ((file-readable-p GFORTH_EL)
(load-library GFORTH_EL)
(autoload 'forth-mode GFORTH_EL)
(setq auto-mode-alist (cons '("\\.fth\\'" . forth-mode) auto-mode-alist))
(setq auto-mode-alist (cons '("\\.bth\\'" . 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 3)
(setq forth-minor-indent-level 2)
(setq forth-hilight-level 3)
(setq forth-custom-words
'(
(("label") non-immediate (font-lock-keyword-face . 1)
"[ \t\n]" t name (font-lock-function-name-face . 3))
(("stand-init:") definition-starter (font-lock-function-name-face . 1)
"[\t\n]" nil comment (font-lock-string-face . 1))
(("end-code") definition-ender (font-lock-keyword-face . 1))
(("loopa") compile-only (font-lock-keyword-face . 2))
(("fload" "fl" "in:")
non-immediate (font-lock-keyword-face . 1)
"[\n\t ]" t string (font-lock-string-face . 1))
(("\"") immediate (font-lock-string-face . 1)
"[\"\n]" nil string (font-lock-string-face . 1))
(("purpose:") immediate (font-lock-comment-face . 1)
"[\n]" nil comment (font-lock-comment-face . 1))
(("[ifndef]") immediate (font-lock-keyword-face . 2)
"[ \t\n]" t name (font-lock-function-name-face . 3))
(("/n" "/w" "/c")
non-immediate (font-lock-constant-face . 2))
(("2value" "buffer:")
non-immediate (font-lock-type-face . 2)
"[ \t\n]" t name (font-lock-variable-name-face . 3))
(("end-string-array") non-immediate (font-lock-keyword-face . 2)
"[ \t\n]" t name (font-lock-type-face . 3))
(("string-array") non-immediate (font-lock-keyword-face . 2))
("-?[0-9a-f]+\\(\\.[0-9]*e\\(-?[0-9]+\\)?\\|\\.?[0-9a-f]*\\)\\.?"
immediate (font-lock-constant-face . 3))
))
(setq forth-custom-indent-words
'((("[ifndef]")
(0 . 2) (0 . 2))
(("label")
(0 . 2) (0 . 2) non-immediate)
(("end-code")
(-2 . 0) (0 . -2) non-immediate)
(("c;")
(-2 . 0) (0 . -2) non-immediate)))
(define-key forth-mode-map "\C-h" 'backward-delete-char)
)))))
Some of the keywords mentioned above are specific to Open Firmware source, but you might find a few of interest.
@MitchBradley Wow, that is quite something indeed. I must confess I don't understand most of it, but I can pick and incorporate some useful tidbits from there as I progress in Forth myself. Thank you for sharing the coniguration!
Hello all!
Glad to join the community. Currently learning Forth for good using the gforth manuals. Doing "Starting Forth" in parallel.
Is there any good formatter than you might recommend? I'm having trouble figuring out/conforming to standard Forth guidelines. If relevant, Vim is my preferred editor, but I use Emacs very regularly as well. Ideally, an independent tool would be ideal!
Cheers.