Skip to content

Commit

Permalink
Draft version of basic superbol-mode for GNU/Emacs
Browse files Browse the repository at this point in the history
  • Loading branch information
nberth committed Jul 5, 2023
1 parent 115d4ec commit e7f303c
Show file tree
Hide file tree
Showing 7 changed files with 134 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .drom
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ version:0.9.0

# hash of toml configuration files
# used for generation of all files
7f7003362e5dc1f40e4ead15fe0fc82d:.
b88976ceb8a8ae036de3bd66eb1c3a07:.
# end context for .

# begin context for .github/workflows/workflow.yml
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ _build
/yarn.lock
/package-json
ATTIC
/emacs/lsp-superbol-customs.el
/out
!.vscode/tasks.json
!.vscode/launch.json
Expand Down
16 changes: 16 additions & 0 deletions Makefile.header
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# -*- Makefile -*-
PROJECT=superbol_vscode_extension
SRCDIR=src/superbol-vscode-platform

# Emacs lsp-mode source directory (https://github.com/emacs-lsp/lsp-mode):
# (could be a submodule)
LSP_MODE_SRCDIR ?= ../lsp-mode

compile:
opam exec -- dune build
cp -f _build/default/src/vscode-package-json/main.exe vscode-package-json
Expand All @@ -27,3 +32,14 @@ compile-release:
--sourcemap \
--sources-content=false

# emacs-lsp:
emacs/lsp-superbol-customs.el: $(LSP_MODE_SRCDIR) package.json
emacs --batch > "$@" \
--load "$(LSP_MODE_SRCDIR)/scripts/lsp-generate-settings.el" \
--eval "(dolist (l (lsp-generate-settings \"package.json\")) (print l))" \
&& echo "Generated $@" 1>&2 \
|| rm -f "$@"

# 8.0.1
# --eval "(princ (lsp-generate-settings \"package.json\" 'lsp-superbol))" \
# --eval '(princ "\n")' \
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,20 @@ In the `superbol` field past the path to the `superbol` executable.

You can check the documentation on using the extension on [this page](https://ocamlpro.github.io/superbol-vscode-platform/sphinx).

### GNU/Emacs mode

* An experimental mode for GNU/Emacs, that is based on [lsp-mode](https://github.com/emacs-lsp/lsp-mode), is provided. It can be tested via the following commands:

```shell
# Derive customization variables from "package.json"
make emacs/lsp-superbol-customs.el
# Setup path to superbol directory, where the "padbol" executable can be found
export SUPERBOL_DIR="$HOME/work/repos/superbol";
# Launch an Emacs with LSP-mode autoloads and superbol-mode triggered for default COBOL file extensions
\emacs -q -L emacs --load superbol-mode --load lsp-mode-autoloads --eval "(custom-set-variables '(lsp-superbol-path \"$SUPERBOL_DIR\"))" --funcall superbol-mode-for-default-extensions
# Then visit a COBOL file and have fun
```

## Resources

* Website: https://ocamlpro.github.io/superbol-vscode-platform
Expand Down
1 change: 1 addition & 0 deletions drom.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ ATTIC
!.vscode/tasks.json
!.vscode/launch.json
*.vsix
/emacs/lsp-superbol-customs.el
"""

[[package]]
Expand Down
53 changes: 53 additions & 0 deletions emacs/lsp-superbol.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
;;; lsp-superbol.el --- LSP client for Superbol COBOL -*- lexical-binding: t; -*-
;;
;; Copyright (c) 2023 OCamlPro SAS
;;
;; All rights reserved.
;; This source code is licensed under the MIT license found in the
;; LICENSE.md file in the root directory of this source tree.

;;; Commentary:

;; LSP client for Superbol COBOL

;;; Code:

(require 'lsp-mode)

;; ---

(defgroup lsp-superbol nil
"Settings for the Superbol Language Server for COBOL."
:group 'lsp-mode
:link '(url-link "https://github.com/OCamlPro/superbol-vscode-extension")
:package-version '(lsp-mode . "8.0.1"))

(load (expand-file-name "lsp-superbol-customs.el"
(file-name-directory load-file-name)))

;; ---

(defun lsp-superbol--server-command ()
"Startup command for the Superbol LSP language server."
;; (list (lsp-package-path 'superbol-language-server) "lsp"))
(list (expand-file-name "padbol" lsp-superbol-path) "lsp"))

;; (lsp-dependency 'superbol-language-server
;; `(:system ,(executable-find (lsp-package-path 'superbol-language-server))))
;; '(:system "superbol-language-server"))

(lsp-register-client
(make-lsp-client
:new-connection (lsp-stdio-connection #'lsp-superbol--server-command)
:priority 0
:activation-fn (lsp-activate-on "superbol" "cobol" "COBOL")
:server-id 'superbol-ls
))

;; ---

(lsp-consistency-check lsp-superbol)

(provide 'lsp-superbol)

;;; lsp-superbol.el ends here
48 changes: 48 additions & 0 deletions emacs/superbol-mode.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
;;; superbol-mode.el --- Superbol COBOL major mode -*- lexical-binding: t; -*-
;;
;; Copyright (c) 2023 OCamlPro SAS
;;
;; All rights reserved.
;; This source code is licensed under the MIT license found in the
;; LICENSE.md file in the root directory of this source tree.

;;; Commentary:

;; Major mode for editing COBOL files using Superbol as a LSP server

;;; Code:

(require 'lsp-mode)
(require 'lsp-superbol)

(add-to-list 'lsp-language-id-configuration
'(superbol-mode . "cobol"))

;; CHECKME: Force association right here?
(defun superbol-mode-for-default-extensions ()
"Automatically associate `superbol-mode` with a few common COBOL file
extensions."
(dolist (regex '("\\.[cC][oO][bB]\\'"
"\\.[cC][bB][lL]\\'"
"\\.[cC][pP][yY]\\'"))
(add-to-list 'auto-mode-alist `(,regex . superbol-mode))))

;;;###autoload
(define-derived-mode
superbol-mode prog-mode "Superbol"
"SUPERBOL mode is a major mode for handling COBOL files."
;; XXX: could actually derive from cobol-mode, if available.

;; Straight from cobol-mode
(set (make-local-variable 'comment-start-skip)
"\\(^.\\{6\\}\\*\\|\\*>\\)\\s-* *")
(set (make-local-variable 'comment-start) "*>")
(set (make-local-variable 'comment-end) "")

;; Start the LSP client
(lsp))

;; ---

(provide 'superbol-mode)
;;; superbol-mode.el ends here

0 comments on commit e7f303c

Please sign in to comment.