]> code.delx.au - gnu-emacs-elpa/blob - packages/ada-mode/ada-wisi-opentoken.el
Merge commit '0cda39255827f283e7578cd469ae42daad9556a2' from js2-mode
[gnu-emacs-elpa] / packages / ada-mode / ada-wisi-opentoken.el
1 ;; ada-wisi-opentoken.el --- An indentation function for ada-wisi that indents -*- lexical-binding:t -*-
2 ;; OpenTokengrammar statements nicely.
3
4 ;; Copyright (C) 2013-2015 Free Software Foundation, Inc.
5
6 ;; This file is part of GNU Emacs.
7
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.
12
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.
17
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/>.
20
21
22 ;;; Commentary:
23
24 ;; This is an example of a user-added indentation rule.
25 ;;
26 ;; In each file that declares OpenToken grammars, enable
27 ;; ada-indent-opentoken minor mode by adding this near the end of the
28 ;; file:
29 ;;
30 ;; Local Variables:
31 ;; eval: (ada-indent-opentoken-mode)
32 ;; End:
33
34 ;;; Code:
35
36 (require 'ada-mode)
37 (require 'wisi)
38
39 (defun ada-wisi-opentoken ()
40 "Return appropriate indentation (an integer column) for continuation lines in an OpenToken grammar statement."
41 ;; We don't do any checking to see if we actually are in an
42 ;; OpenToken grammar statement, since this rule should only be
43 ;; included in package specs that exist solely to define OpenToken
44 ;; grammar fragments.
45 (save-excursion
46 (let ((token-text (wisi-token-text (wisi-backward-token))))
47 (cond
48 ((equal token-text "<=")
49 (back-to-indentation)
50 (+ (current-column) ada-indent-broken))
51
52 ((member token-text '("+" "&"))
53 (while (not (equal "<=" (wisi-token-text (wisi-backward-token)))))
54 (back-to-indentation)
55 (+ (current-column) ada-indent-broken))
56 ))))
57
58 (defconst ada-wisi-opentoken-align
59 "Align rule for OpenToken grammar definitions."
60 '(ada-opentoken
61 (regexp . "[^=]\\(\\s-*\\)<=")
62 (valid . (lambda() (not (ada-in-comment-p))))
63 (modes . '(ada-mode))))
64
65 ;;;###autoload
66 (define-minor-mode ada-indent-opentoken-mode
67 "Minor mode for indenting grammar definitions for the OpenToken package.
68 Enable mode if ARG is positive"
69 :initial-value t
70 :lighter "OpenToken" ;; mode line
71
72 (if ada-indent-opentoken-mode
73 (progn
74 ;; This must be after ada-wisi-setup on ada-mode-hook, because
75 ;; ada-wisi-setup resets wisi-indent-calculate-functions
76 (add-to-list 'ada-align-rules ada-wisi-opentoken-align)
77 (add-to-list 'wisi-indent-calculate-functions 'ada-wisi-opentoken))
78
79 (setq ada-align-rules (delete ada-wisi-opentoken-align ada-align-rules))
80 (setq wisi-indent-calculate-functions (delete 'ada-wisi-opentoken wisi-indent-calculate-functions))
81 ))
82
83 (provide 'ada-wisi-opentoken)
84 ;; end of file