Skip to content

Instantly share code, notes, and snippets.

@Parik27
Created February 6, 2020 11:30
Show Gist options
  • Save Parik27/864688d55dae27f109f9727a7d3c4c24 to your computer and use it in GitHub Desktop.
Save Parik27/864688d55dae27f109f9727a7d3c4c24 to your computer and use it in GitHub Desktop.
SCM Major Mode for Emacs
;;; scm-mode.el - SCM Mode
;; define the mode hook list
(defvar scm-mode-hook
nil
"A list for storing scm-mode hooks.")
;; set up the syntax highlighting defaults
(defvar scm-mode-font-lock-regexp-keywords
"\\s-\\(if\\|jump_if_false\\|not\\|gosub\\|return\\|end_thread\\)\\s-"
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defvar scm-mode-font-lock-defaults
`(
("//.*" . font-lock-comment-face)
(,scm-mode-font-lock-regexp-keywords . (1 font-lock-keyword-face))
("^:.*\\|\\s-@\\S-*" . font-lock-function-name-face)
("\\(\\S-*@\\)\\(\\s-\\|s\\)" . font-lock-variable-name-face)
("\\s-\\$\\S-*\\|\\s-#\\S-*" . font-lock-constant-face)
("^{.*}" . font-lock-preprocessor-face)
("\\s-\\(\\S-*:\\)" . font-lock-type-face)
)
"The default syntax highlighting rules for scm-mode.")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun scm-mode--get-abs-offset-at-point()
(forward-char)
(let ((current-number (number-at-point)))
(backward-char)
current-number
)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun scm-mode--calculate-offset()
"""Calculates the offset of the current operation.
Requires a main.scm file with file offsets
"""
(interactive)
(save-excursion
(beginning-of-line)
(let ((current-offset (scm-mode--get-abs-offset-at-point)))
(when current-offset
(search-backward-regexp "^:")
(search-forward "_")
(let ((relative-offset (number-at-point)))
(forward-line)
(let ((next-offset (scm-mode--get-abs-offset-at-point)))
(kill-new (number-to-string (+ relative-offset
(- current-offset next-offset))))
)
)
)
)
)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun scm-mode--jump-to-definition ()
(interactive)
(let ((symbol (symbol-at-point)))
(when symbol
(search-forward (concat ":" symbol))
(search-backward (concat ":" symbol))
)
)
)
(defvar scm-mode-hook nil)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define-derived-mode scm-mode fundamental-mode
"SCM"
"Major mode to edit SCM source files."
(setq font-lock-defaults '(scm-mode-font-lock-defaults))
;; comments
(set (make-local-variable 'comment-start) "//")
(set (make-local-variable 'comment-start-skip) "/\\*+ *\\|//+ *")
(set (make-local-variable 'comment-end) ""))
(provide 'scm-mode)
;;; scm-mode.el ends here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment