1 ;;; An indentation function for ada-wisi that indents OpenToken
2 ;;; grammar statements nicely.
4 ;;; This is an example of a user-added indentation rule.
6 ;; In ~/.emacs (or project-specific config):
7 ;; (require 'ada-wisi-opentoken)
9 ;; In each file that declares OpenToken grammars:
12 ;; ada-indent-opentoken: t
18 (defcustom ada-indent-opentoken nil
19 "If non-nil, apply `ada-wisi-opentoken' indentation rule."
21 :group 'ada-indentation
23 (make-variable-buffer-local 'ada-indent-opentoken)
25 (defun ada-wisi-opentoken ()
26 "Return appropriate indentation (an integer column) for continuation lines in an OpenToken grammar statement."
27 ;; We don't do any checking to see if we actually are in an
28 ;; OpenToken grammar statement, since this rule should only be
29 ;; included in package specs that exist solely to define OpenToken
31 (when ada-indent-opentoken
33 (let ((token-text (nth 1 (wisi-backward-token))))
35 ((equal token-text "<=")
37 (+ (current-column) ada-indent-broken))
39 ((member token-text '("+" "&"))
40 (while (not (equal "<=" (nth 1 (wisi-backward-token)))))
42 (+ (current-column) ada-indent-broken))
45 (defun ada-wisi-opentoken-setup ()
46 (add-to-list 'wisi-indent-calculate-functions 'ada-wisi-opentoken))
48 ;; This must be after ada-wisi-setup on ada-mode-hook, because
49 ;; ada-wisi-setup resets wisi-indent-calculate-functions
50 (add-hook 'ada-mode-hook 'ada-wisi-opentoken-setup t)
52 (add-to-list 'ada-align-rules
54 (regexp . "[^=]\\(\\s-*\\)<=")
55 (valid . (lambda() (not (ada-in-comment-p))))
56 (modes . '(ada-mode))))
58 (provide 'ada-wisi-opentoken)