From 32adaa55b000dd51ec83ad24c6d1fc7158d6f6b4 Mon Sep 17 00:00:00 2001 From: Nicolas Berthier Date: Wed, 5 Jul 2023 18:12:11 +0200 Subject: [PATCH] Simplifiy superbol-mode startups for GNU/Emacs, and add support for Eglot --- .drom | 1 + Makefile | 2 +- README.md | 13 +++++++++++-- emacs/eglot-superbol.el | 42 +++++++++++++++++++++++++++++++++++++++++ emacs/lsp-superbol.el | 37 +++++++++++++++++++++++++++++++++--- emacs/superbol-mode.el | 38 +++++++++++++++---------------------- 6 files changed, 104 insertions(+), 29 deletions(-) create mode 100644 emacs/eglot-superbol.el diff --git a/.drom b/.drom index f184d6eca..0e08f8baf 100644 --- a/.drom +++ b/.drom @@ -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 diff --git a/Makefile b/Makefile index e88fc1d77..ef9ba21a9 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/README.md b/README.md index 5f784f1ba..43cc46e9f 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/emacs/eglot-superbol.el b/emacs/eglot-superbol.el new file mode 100644 index 000000000..ec209a232 --- /dev/null +++ b/emacs/eglot-superbol.el @@ -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 diff --git a/emacs/lsp-superbol.el b/emacs/lsp-superbol.el index 272eed2af..4d5adc6d4 100644 --- a/emacs/lsp-superbol.el +++ b/emacs/lsp-superbol.el @@ -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 ;; @@ -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")) @@ -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) diff --git a/emacs/superbol-mode.el b/emacs/superbol-mode.el index 7981fe6d7..7a9ed430a 100644 --- a/emacs/superbol-mode.el +++ b/emacs/superbol-mode.el @@ -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]\\'" @@ -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)) ;; ---