Skip to content

Commit

Permalink
Simplifiy superbol-mode startups for GNU/Emacs, and add support for E…
Browse files Browse the repository at this point in the history
…glot
  • Loading branch information
nberth committed Jul 5, 2023
1 parent 49cd5e5 commit 32adaa5
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 29 deletions.
1 change: 1 addition & 0 deletions .drom
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ d00f73c835ae4a1589d55ebda4ab381b:CHANGES.md
# begin context for Makefile
# file Makefile
7b235cd906ac2e7c97c9d3254b9b3eef:Makefile
d768fb221fd49646ac83e91c15640e63:Makefile
# end context for Makefile

# begin context for README.md
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
.PHONY: all build build-deps fmt fmt-check install dev-deps test
.PHONY: clean distclean

DEV_DEPS := merlin ocamlformat odoc
DEV_DEPS := merlin ocamlformat odoc ppx_expect ppx_inline_test


SPHINX_TARGET:=_drom/docs/sphinx
Expand Down
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,20 @@ You can check the documentation on using the extension on [this page](https://oc
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
# Launch an Emacs with an lsp-mode LSP for superbol-mode, triggered for some default COBOL file extensions
\emacs -L emacs --load lsp-superbol --eval "(custom-set-variables '(lsp-superbol-path \"$SUPERBOL_DIR\"))" --funcall superbol-mode-enable-for-default-extensions
# Then visit a COBOL file and have fun
```

* An alternative experimental mode for GNU/Emacs, based on [eglot](https://elpa.gnu.org/packages/eglot.html), is provided. Test it via the following commands:

```shell
# Setup path to superbol directory, where the "padbol" executable can be found
export SUPERBOL_DIR="$HOME/work/repos/superbol";
# Launch an Emacs with eglot-based LSP for superbol-mode, triggered for some default COBOL file extensions
\emacs -L emacs --load eglot-superbol --eval "(add-to-list 'exec-path \"$SUPERBOL_DIR\")" --funcall superbol-mode-enable-for-default-extensions
```

## Resources

* Website: https://ocamlpro.github.io/superbol-vscode-platform
Expand Down
42 changes: 42 additions & 0 deletions emacs/eglot-superbol.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
;;; lsp-superbol.el --- Eglot 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:

;; Eglot LSP client for Superbol COBOL

;;; Code:

(unless (fboundp 'eglot)
(load "eglot-autoloads"))

(require 'eglot)
(require 'superbol-mode)

(defun eglot-superbol--start ()
"Superbol LSP startup function for Eglot"

;; Actually the LSP server
(eglot-ensure)

;; Turn on fontification (even if minimal)
(funcall font-lock-fontify-buffer-function))

(add-to-list 'eglot-server-programs '(superbol-mode . ("padbol" "lsp")))
(add-to-list 'eglot-server-programs '(cobol-mode . ("padbol" "lsp")))

;; Autostart the LSP when entering superbol-mode
(add-hook 'superbol-mode-hook #'eglot-superbol--start)

;; Also load on cobol-mode
(with-eval-after-load 'cobol-mode
(add-hook 'cobol-mode-hook #'eglot-superbol--start))

(provide 'eglot-superbol)

;;; eglot-superbol.el ends here
37 changes: 34 additions & 3 deletions emacs/lsp-superbol.el
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
;;; lsp-superbol.el --- LSP client for Superbol COBOL -*- lexical-binding: t; -*-
;;; lsp-superbol.el --- lsp-mode LSP client for Superbol COBOL -*- lexical-binding: t; -*-
;;
;; Copyright (c) 2023 OCamlPro SAS
;;
Expand All @@ -8,16 +8,20 @@

;;; Commentary:

;; LSP client for Superbol COBOL
;; lsp-mode.el LSP client for Superbol COBOL

;;; Code:

(unless (fboundp 'lsp-mode)
(load "lsp-mode-autoloads"))

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

;; ---

(defgroup lsp-superbol nil
"Settings for the Superbol Language Server for COBOL."
"Settings for the Superbol Language Server for COBOL (lsp-mode)."
:group 'lsp-mode
:link '(url-link "https://github.com/OCamlPro/superbol-vscode-extension")
:package-version '(lsp-mode . "8.0.1"))
Expand Down Expand Up @@ -46,6 +50,33 @@

;; ---

;; (with-eval-after-load 'superbol-mode
(add-to-list 'lsp-language-id-configuration '(superbol-mode . "cobol"))
(add-to-list 'lsp-language-id-configuration '(cobol-mode . "cobol"))

(defun lsp-superbol--start ()
"Superbol LSP startup function for lsp-mode"

;; Enable semantic tokens
(set (make-local-variable 'lsp-semantic-tokens-enable) t)

;; Actually the LSP server
(lsp)

;; (lsp-semantic-tokens-mode 1)

;; Turn on fontification
(funcall font-lock-fontify-buffer-function))

;; Autostart the LSP when entering superbol-mode
(add-hook 'superbol-mode-hook #'lsp-superbol--start)

;; Also load on cobol-mode
(with-eval-after-load 'cobol-mode
(add-hook 'cobol-mode-hook #'lsp-superbol--start))

;; ---

(lsp-consistency-check lsp-superbol)

(provide 'lsp-superbol)
Expand Down
38 changes: 15 additions & 23 deletions emacs/superbol-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,8 @@

;;; 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 ()
(defun superbol-mode-enable-for-default-extensions ()
"Automatically associate `superbol-mode` with a few common COBOL file
extensions."
(dolist (regex '("\\.[cC][oO][bB]\\'"
Expand All @@ -28,22 +22,20 @@ extensions."
(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) "")

;; Forbid tabs in indentation (for now, that's a limitation of Superbol)
(set (make-local-variable 'indent-tabs-mode) nil)

;; Start the LSP client
(lsp))
(define-derived-mode superbol-mode prog-mode
"Superbol"
"SUPERBOL mode is a major mode for handling COBOL files. It is mostly intended
to be backed by an LSP."
;; 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) "")

;; Forbid tabs in indentation (for now, that's a limitation of Superbol)
(set (make-local-variable 'indent-tabs-mode) nil))

;; ---

Expand Down

0 comments on commit 32adaa5

Please sign in to comment.