From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,92c2ed8b1648aa50,start X-Google-Attributes: gid103376,public Path: g2news1.google.com!postnews1.google.com!not-for-mail From: rolf.ebert_nospam_@gmx.net (Rolf Ebert) Newsgroups: comp.lang.ada Subject: [Ann] Emacs major mode for editing GNAT project files Date: 2 Jun 2004 23:44:19 -0700 Organization: http://groups.google.com Message-ID: <46b8b50a.0406022244.16bed3aa@posting.google.com> NNTP-Posting-Host: 195.27.231.129 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1086245060 21528 127.0.0.1 (3 Jun 2004 06:44:20 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 3 Jun 2004 06:44:20 +0000 (UTC) Xref: g2news1.google.com comp.lang.ada:1055 Date: 2004-06-02T23:44:19-07:00 List-Id: Please see below an Emacs mode for editing GNAT project files ending in .gpr. It reuses almost all from the standard Ada-mode with the following differences: - add font-locking for "project" and "external" - correctly indent after a "project Foo is" It would have been shorter (in number of bytes) to integrate gpr support into ada-mode.el as a variant, but is was easier to write a new file. HTH Rolf ------------------------------------------ ;;; ada-gpr.el --- major-mode for editing GNAT project files ;; Copyright (C) 2004 Rolf Ebert ;; Author: Rolf Ebert ;; Keywords: languages ada ;; This file is not part of GNU Emacs. ;; ada-gpr 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 2, or (at your option) ;; any later version. ;; ada-gpr 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 GNU Emacs; see the file COPYING. If not, write to the ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, ;; Boston, MA 02111-1307, USA. (require 'ada-mode) ;; --------------------------------------------------- ;; support for font-lock.el ;; ---------------------------------------------------- (defvar ada-gpr-font-lock-keywords (progn ;; eval-when-compile (list ;; ;; keyword plus name. (list (concat "\\<\\(" "package\\|" "project\\|" "for" "\\)\\>[ \t]*" "\\(\\sw+\\(\\.\\sw*\\)*\\)?") '(1 font-lock-keyword-face) '(2 font-lock-function-name-face nil t)) ;; ;; Main keywords (list (concat "\\<" (regexp-opt '("case" "external" "is" "others" "renames" "type" "use" "when" "with") t) "\\>") '(1 font-lock-keyword-face)) ;; ;; Anything following end and not already fontified is a body name. '("\\<\\(end\\)\\>\\([ \t]+\\)?\\(\\(\\sw\\|[_.]\\)+\\)?" (1 font-lock-keyword-face) (3 font-lock-function-name-face nil t)) ;; )) "Default expressions to highlight in GNAT project file (gpr) mode.") ;;; (defun ada-gpr-mode () "Ada gpr mode is the major mode for editing GNAT project files." (interactive) (kill-all-local-variables) (set (make-local-variable 'require-final-newline) t) ;; Set the paragraph delimiters so that one can select a whole block ;; simply with M-h (set (make-local-variable 'paragraph-start) "[ \t\n\f]*$") (set (make-local-variable 'paragraph-separate) "[ \t\n\f]*$") ;; comment end must be set because it may hold a wrong value if ;; this buffer had been in another mode before. RE (set (make-local-variable 'comment-end) "") ;; used by autofill and indent-new-comment-line (set (make-local-variable 'comment-start-skip) "---*[ \t]*") ;; used by autofill to break a comment line and continue it on another line. ;; The reason we need this one is that the default behavior does not work ;; correctly with the definition of paragraph-start above when the comment ;; is right after a multi-line subprogram declaration (the comments are ;; aligned under the latest parameter, not under the declaration start). (set (make-local-variable 'comment-line-break-function) (lambda (&optional soft) (let ((fill-prefix nil)) (indent-new-comment-line soft)))) ;; use indenting from Ada, just add "project" (set (make-local-variable 'ada-subprog-start-re) (concat "\\<" (regexp-opt '("project" "package") t) "\\>")) (set (make-local-variable 'indent-line-function) 'ada-indent-current-function) (set (make-local-variable 'comment-column) 40) (set 'case-fold-search t) (set (make-local-variable 'fill-paragraph-function) 'ada-fill-comment-paragraph) ;; font-lock support : ;; We need to set some properties for XEmacs, and define some variables ;; for Emacs (if ada-xemacs ;; XEmacs (put 'ada-mode 'font-lock-defaults '(ada-gpr-font-lock-keywords nil t ((?\_ . "w") (?# . ".")) beginning-of-line)) ;; Emacs (set (make-local-variable 'font-lock-defaults) '(ada-gpr-font-lock-keywords nil t ((?\_ . "w") (?# . ".")) beginning-of-line (font-lock-syntactic-keywords . ada-font-lock-syntactic-keywords))) ) ;; Support for ispell : Check only comments (set (make-local-variable 'ispell-check-comments) 'exclusive) ;; Support for indent-new-comment-line (Especially for XEmacs) (setq comment-multi-line nil) (setq major-mode 'ada-gpr-mode mode-name "GNAT Project") ;; use the keybindings from Ada mode (use-local-map ada-mode-map) ;; (easy-menu-add ada-mode-menu ada-mode-map) ;; use Ada syntax table (set-syntax-table ada-mode-syntax-table) (if ada-clean-buffer-before-saving (progn ;; remove all spaces at the end of lines in the whole buffer. (add-hook 'local-write-file-hooks 'delete-trailing-whitespace) ;; convert all tabs to the correct number of spaces. (add-hook 'local-write-file-hooks (lambda () (untabify (point-min) (point-max)))))) (run-hooks 'ada-gpr-mode-hook) ;; To be run after the hook, in case the user modified ;; ada-fill-comment-prefix (make-local-variable 'comment-start) (if ada-fill-comment-prefix (set 'comment-start ada-fill-comment-prefix) (set 'comment-start "-- ")) ;; Run this after the hook to give the users a chance to activate ;; font-lock-mode (unless ada-xemacs (progn (ada-initialize-properties) (make-local-hook 'font-lock-mode-hook) (add-hook 'font-lock-mode-hook 'ada-deactivate-properties nil t))) (if ada-auto-case (ada-activate-keys-for-case))) ;;; set file extension (setq auto-mode-alist (cons '("\\.gpr\\'" . ada-gpr-mode) auto-mode-alist)) ;;; provide ourselves (provide 'ada-gpr-mode) ;;; ada-gpr.el ends here