]> code.delx.au - gnu-emacs-elpa/blob - packages/ada-mode/ada-wisi-opentoken.el
Add ada-mode, wisi packages
[gnu-emacs-elpa] / packages / ada-mode / ada-wisi-opentoken.el
1 ;;; An indentation function for ada-wisi that indents OpenToken
2 ;;; grammar statements nicely.
3 ;;;
4 ;;; This is an example of a user-added indentation rule.
5 ;;
6 ;; In ~/.emacs (or project-specific config):
7 ;; (require 'ada-wisi-opentoken)
8 ;;
9 ;; In each file that declares OpenToken grammars:
10 ;;
11 ;; Local Variables:
12 ;; ada-indent-opentoken: t
13 ;; End:
14
15 (require 'ada-mode)
16 (require 'wisi)
17
18 (defcustom ada-indent-opentoken nil
19 "If non-nil, apply `ada-wisi-opentoken' indentation rule."
20 :type 'boolean
21 :group 'ada-indentation
22 :safe 'booleanp)
23 (make-variable-buffer-local 'ada-indent-opentoken)
24
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
30 ;; grammar fragments.
31 (when ada-indent-opentoken
32 (save-excursion
33 (let ((token-text (nth 1 (wisi-backward-token))))
34 (cond
35 ((equal token-text "<=")
36 (back-to-indentation)
37 (+ (current-column) ada-indent-broken))
38
39 ((member token-text '("+" "&"))
40 (while (not (equal "<=" (nth 1 (wisi-backward-token)))))
41 (back-to-indentation)
42 (+ (current-column) ada-indent-broken))
43 )))))
44
45 (defun ada-wisi-opentoken-setup ()
46 (add-to-list 'wisi-indent-calculate-functions 'ada-wisi-opentoken))
47
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)
51
52 (add-to-list 'ada-align-rules
53 '(ada-opentoken
54 (regexp . "[^=]\\(\\s-*\\)<=")
55 (valid . (lambda() (not (ada-in-comment-p))))
56 (modes . '(ada-mode))))
57
58 (provide 'ada-wisi-opentoken)
59 ;; end of file