From da3630f8a9f025b0e3a0d6c3f9c3df8203e4d19d Mon Sep 17 00:00:00 2001 From: Teon Banek Date: Tue, 21 Aug 2018 16:21:30 +0200 Subject: [PATCH] Add lcp-mode for Emacs Reviewers: mtomic, buda Reviewed By: mtomic Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D1549 --- tools/emacs-lcp/README.md | 21 +++++++++++++++++++++ tools/emacs-lcp/lcp-mode.el | 25 +++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 tools/emacs-lcp/README.md create mode 100644 tools/emacs-lcp/lcp-mode.el diff --git a/tools/emacs-lcp/README.md b/tools/emacs-lcp/README.md new file mode 100644 index 000000000..463d7a753 --- /dev/null +++ b/tools/emacs-lcp/README.md @@ -0,0 +1,21 @@ +# lcp-mode + +Emacs major mode for editing LCP files. It relies on `mmm-mode` for +integrating multiple major modes in a single buffer. + +`lcp-mode` is derived from `lisp-mode`, so all your custom bindings for that +mode should work out of the box. Since LCP supports embedding C++ code blocks, +the `lcp-mode` shifts from `lisp-mode` to `c-mode` in such blocks. Therefore, +your `c-mode` bindings should also work. You may wonder why isn't `c++-mode` +used. The reason is that, unfortunately, `c++-mode` has some issues when used +with `mmm-mode`. + +Future improvements to this mode may include fixing issues with `c++-mode`, +adding additional syntax highlighting as well as new editing commands. + +## Installation + +Just put the following somewhere in your Emacs init file. It will +automatically install `mmm-mode` from the ELPA repository if needed. + + (require 'lcp-mode "/tools/emacs-lcp/lcp-mode.el") diff --git a/tools/emacs-lcp/lcp-mode.el b/tools/emacs-lcp/lcp-mode.el new file mode 100644 index 000000000..31e032a0b --- /dev/null +++ b/tools/emacs-lcp/lcp-mode.el @@ -0,0 +1,25 @@ +(defun require-package (package &optional min-version no-refresh) + "Install PACKAGE with optional MIN-VERSION. + If NO-REFRESH is non NIL, the available package list will not be refreshed." + (if (package-installed-p package min-version) + t + (if (or (assoc package package-archive-contents) no-refresh) + (package-install package) + (package-refresh-contents) + (package-install package)))) + +(require-package 'mmm-mode) +(require 'mmm-mode) + +(setq mmm-global-mode 'maybe) + +(define-derived-mode lcp-mode lisp-mode "LCP" "Mode for editing LCP files at Memgraph." + (setq mmm-submode-decoration-level 0)) + +(mmm-add-classes '((lcp-c++ :submode c-mode ; c++-mode is buggy + :front "#>cpp" :back "cpp<#"))) +(mmm-add-mode-ext-class 'lcp-mode nil 'lcp-c++) + +(add-to-list 'auto-mode-alist '("\\.lcp\\'" . lcp-mode)) + +(provide 'lcp-mode)