From 2deca009c82fc5c57f71ca7c3734cc6eb5db238d Mon Sep 17 00:00:00 2001 From: Michal Sojka Date: Wed, 30 Jul 2014 00:48:18 +0200 Subject: [PATCH] Add experimental version of omk-mode for Emacs --- contrib/omk-mode.el | 90 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 contrib/omk-mode.el diff --git a/contrib/omk-mode.el b/contrib/omk-mode.el new file mode 100644 index 0000000..54ba2b1 --- /dev/null +++ b/contrib/omk-mode.el @@ -0,0 +1,90 @@ +;;; omk-mode.el --- Major mode for editing OMK makefiles + +;; Copyright (C) 2014 Michal Sojka + +;; Author: Michal Sojka +;; Keywords: convenience, files, extensions + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see . + +;;; Commentary: + +;; + +;;; Code: + +(require 'make-mode) + +;; config_include_HEADERS -> _DEFINES + +(defconst omk-target-keywords-regex + "\\<\\(\\(lib\\|shared\\)_LIBRARIES\\|\\(bin\\|test\\|utils\\)_PROGRAMS\\)\\>") + +(defconst omk-target-specific-keywords + '(SOURCES LIBS CFLAGS CXXFLAGS CPPFLAGS GEN_SOURCES)) + +(defconst omk-keywords + '("lib_LOADLIBES" "LOADLIBES" "INCLUDES" "DEFS" "LN_HEADERS" "SUBDIRS" + "ALL_OMK_SUBDIRS" "AUTOMATIC_SUBDIRS" + "default_CONFIG" "LOCAL_CONFIG_H" "config_include_HEADERS")) + +(defun omk-match-keywords (bound) + (re-search-forward (concat "\\<\\(" (mapconcat 'identity omk-keywords "\\|") "\\)\\>") bound t)) + +(defun omk-get-targets () + (save-excursion + (save-match-data + (goto-char (point-min)) + (loop while + (re-search-forward + (concat omk-target-keywords-regex "[ \t]*\\(?:!=\\|[*:+]?[:?]?=\\)") + nil t) + append + (loop while (re-search-forward "[^ \t]+" (line-end-position) t) + collect (match-string 0)))))) +(defun omk-match-target-specific-keywords (bound) + (let ((targets (omk-get-targets))) ; This is not very effective + (re-search-forward + (concat "\\<\\(" (mapconcat 'identity targets "\\|") "\\)_" + "\\(" (mapconcat 'symbol-name omk-target-specific-keywords "\\|") + "\\)\\>") + bound t))) + +(defconst omk-font-lock-keywords + `((,omk-target-keywords-regex . font-lock-keyword-face) + ("\\<\\(nobase_\\|rename_\\)?include_HEADERS\\>" . font-lock-keyword-face) + (omk-match-keywords . font-lock-keyword-face) + (omk-match-target-specific-keywords . font-lock-keyword-face) + ,@makefile-gmake-font-lock-keywords)) + +(defun omk-font-lock-extend-after-change-region (beg end ond-len) + (if (save-excursion + (save-match-data + (let ((endl (progn (goto-char end) (end-of-line)))) + (goto-char beg) + (beginning-of-line) + (re-search-forward omk-target-keywords-regex endl t)))) + (cons (point-min) (point-max)) + nil)) + +(define-derived-mode omk-mode makefile-gmake-mode "OMK" + "An adapted `makefile-gmake-mode' that know about OMK" + (setq font-lock-defaults + `(omk-font-lock-keywords ,@(cdr font-lock-defaults))) + (setq font-lock-extend-after-change-region-function 'omk-font-lock-extend-after-change-region)) + +(add-to-list 'auto-mode-alist '("\\.omk$" . omk-mode)) + +(provide 'omk-mode) +;;; omk-mode.el ends here -- 2.39.2