sensetalk-mode for emacs?

Anybody have a sensetalk-mode.el for emacs?

I don’t even know what language sensetalk is closest to. If I did, I would try to find an xtalk-mode.el, or something, that was close to SenseTalk syntax and see if I can make it work.

Any suggestions?
Thanks!
-edj

1 Like

I’m not aware of anything right now for emacs or any other editors. SenseTalk (like all xTalks) is an unusually context-sensitive language, in which a single word may mean different things depending on where and how it is used. This makes syntax coloring more difficult. Eggplant achieves its syntax coloring by calling the SenseTalk compiler, which isn’t really an option in other environments.

However, although you’re not likely to get full syntax colorization in another editor, it should be possible to create an editing mode that would recognize some key words, and especially structures like handlers, repeat loops, and try/catch blocks. If anyone finds or creates such an editing mode, please let us know.

@edwindjb I knew I wasn’t the only one looking for something like this :wink:

While this post is quite old, I was also looking for a SenseTalk mode for GNU Emacs around 2018. I had a couple false starts on my own mode, and then started up again recently when I saw this post!

The two main references I’m using are Xah Lee’s brief but excellent tutorial and Aemon Cannon’s code for as3-mode.el (ActionScript mode) or a newer one by Austin Haas.

Someone else must have done this by now, but I’ve yet to see it out there on any public SCM’s :slight_smile: If I ever finish even a simple version I’ll post it. But if someone else already completed one I’m game to try it out :wink:

Just from the perspective of getting the shell of the mode started, the below could get an enterprising person started (should be fine for GNU Emacs v27+ but results may vary for previous releases) using the two references above. Additionally, you’ll want to compare how SenseTalk highlighting compares to ActionScript and Objective-C in Emacs; this will make the task of “simulating” Eggplant Functional highlighting a little easier in terms of copying over existing .el features for modification as needed (with appropriate credit, of course, if using a GPL’d major mode file as reference like Cannon’s above).

  1. sensetalk-mode-map: Used (make-sparse-keymap) to create a sparse keymap, which may be more efficient.
  2. Example settings in the sensetalk-mode definition:
  • comment-start: Sets the comment prefix to # .
  • indent-tabs-mode: Disables the use of tabs for indentation.
  • tab-width: Sets the tab width to 2 spaces. Adjust this value as needed.
  1. Placed (run-hooks 'sensetalk-mode-hook) at the end of the sensetalk-mode definition to run any user-defined hooks. You can add custom hooks to this mode if desired.
  2. Placed the (add-to-list 'auto-mode-alist ...) line at the end, after the provide statement, to ensure it is executed after all the necessary functions and variables have been defined.
;;; sensetalk-mode.el --- A mode for editing Eggplant .script SenseTalk files

;; Copyright (C) 2023 Ian "GNUian" Bryant

;; Author: Ian "GNUian" Bryant
;; Keywords: language modes

;; This file is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.

;; This file is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to
;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.

(require 'font-lock)
(eval-when-compile
  (require 'cl)
  (require 'regexp-opt))

(defconst sensetalk-mode-version "0.0.0"
  "SenseTalk Mode version number.")

(defgroup sensetalk nil
  "Major mode for editing Eggplant .script SenseTalk files."
  :group 'languages)

(defvar sensetalk-mode-hook nil)

(defvar sensetalk-mode-map
  (let ((map (make-sparse-keymap)))
    ;; Add custom keybindings here, if needed
    map)
  "Keymap for SenseTalk major mode")

;;;###autoload
(define-derived-mode sensetalk-mode prog-mode "SenseTalk"
  "Major mode for editing SenseTalk scripts."
  :syntax-table sensetalk-mode-syntax-table
  (setq-local font-lock-defaults '(sensetalk-font-lock-keywords))
  ;; Enable some additional features
  (setq-local comment-start "# ")
  (setq-local indent-tabs-mode nil)
  (setq-local tab-width 2)
  ;; Add any other necessary settings

  ;; Run user-defined hooks
  (run-hooks 'sensetalk-mode-hook))

;; Syntax highlighting definitions
(setq sensetalk-font-lock-keywords
      '(
        ;; Add regex patterns for syntax highlighting here
        ;; Example: (("\\<\\(if\\|then\\|else\\)\\>" . font-lock-keyword-face))
        ;; You can define multiple patterns using the same face

        ;; String literals
        ;; Example: ("\"[^\"]+\"" . font-lock-string-face)

        ;; Comment syntax
        ;; Example: ("#.*$" . font-lock-comment-face)
        ))

(defvar sensetalk-mode-syntax-table
  (let ((st (make-syntax-table)))
    ;; Add character syntax definitions here, if needed
    ;; Example: (modify-syntax-entry ?_ "w")
    st))

;;;###autoload
(add-to-list 'auto-mode-alist '("\\.script\\'" . sensetalk-mode))

(provide 'sensetalk-mode)

;;; sensetalk-mode.el ends here

@edwindjb @SenseTalkDoug I completely forgot to add this xTalk Mode code. It was on EmacsWiki some time ago but the original link is now dead. It’s Alex Rice’s mode from 2002-03 so while it’s a closer example than something like ActionScript, this one would need some updating. Nice, though!

Here’s the link to the Internet Archive copy:
https://web.archive.org/web/20051224133948/http://mindlube.com:80/download/files/runrev/xtalk-mode.el