1 ;;; ada-wisi-opentoken.el --- An indentation function for ada-wisi that indents OpenToken
2 ;; grammar statements nicely.
4 ;; Copyright (C) 2013 Free Software Foundation, Inc.
6 ;; This file is part of GNU Emacs.
8 ;; GNU Emacs is free software: you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation, either version 3 of the License, or
11 ;; (at your option) any later version.
13 ;; GNU Emacs is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
24 ;; This is an example of a user-added indentation rule.
26 ;; In ~/.emacs (or project-specific config):
27 ;; (require 'ada-wisi-opentoken)
29 ;; In each file that declares OpenToken grammars:
32 ;; ada-indent-opentoken: t
40 (defcustom ada-indent-opentoken nil
41 "If non-nil, apply `ada-wisi-opentoken' indentation rule."
43 :group 'ada-indentation
45 (make-variable-buffer-local 'ada-indent-opentoken)
47 (defun ada-wisi-opentoken ()
48 "Return appropriate indentation (an integer column) for continuation lines in an OpenToken grammar statement."
49 ;; We don't do any checking to see if we actually are in an
50 ;; OpenToken grammar statement, since this rule should only be
51 ;; included in package specs that exist solely to define OpenToken
53 (when ada-indent-opentoken
55 (let ((token-text (nth 1 (wisi-backward-token))))
57 ((equal token-text "<=")
59 (+ (current-column) ada-indent-broken))
61 ((member token-text '("+" "&"))
62 (while (not (equal "<=" (nth 1 (wisi-backward-token)))))
64 (+ (current-column) ada-indent-broken))
67 (defun ada-wisi-opentoken-setup ()
68 (add-to-list 'wisi-indent-calculate-functions 'ada-wisi-opentoken))
70 ;; This must be after ada-wisi-setup on ada-mode-hook, because
71 ;; ada-wisi-setup resets wisi-indent-calculate-functions
72 (add-hook 'ada-mode-hook 'ada-wisi-opentoken-setup t)
74 (add-to-list 'ada-align-rules
76 (regexp . "[^=]\\(\\s-*\\)<=")
77 (valid . (lambda() (not (ada-in-comment-p))))
78 (modes . '(ada-mode))))
80 (provide 'ada-wisi-opentoken)