]> code.delx.au - gnu-emacs-elpa/blob - packages/ada-mode/ada-imenu.el
Merge commit '0cda39255827f283e7578cd469ae42daad9556a2' from js2-mode
[gnu-emacs-elpa] / packages / ada-mode / ada-imenu.el
1 ;;; ada-imenu.el - Ada mode interface to imenu for Ada Mode -*- lexical-binding:t -*-
2
3 ;; Copyright (C) 2012, 2013, 2015 Free Software Foundation, Inc.
4 ;;
5 ;; Author: Simon Wright <simon@pushface.org>
6 ;; Contributors: see ada-mode.el, and specifically Christian Egli
7 ;; <Christian.Egli@hcsd.hac.com> for ada-imenu-generic-expression
8 ;;
9 ;; This file is part of GNU Emacs.
10 ;;
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
15 ;;
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
20 ;;
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23 ;;
24 ;;; History: see ada_mode.el
25 ;;
26
27 (require 'ada-mode)
28 (require 'imenu)
29
30 (defconst ada--imenu-comment-re "\\([ \t]*--.*\\)?")
31
32 (defconst ada--imenu-subprogram-menu-re
33 (concat "^[ \t]*\\(overriding[ \t]*\\)?\\(procedure\\|function\\)[ \t\n]+"
34 "\\(\\(\\sw\\|_\\)+\\)[ \t\n]*\\([ \t\n]\\|([^)]+)"
35 ada--imenu-comment-re
36 "\\)[ \t\n]*"
37 "\\(return[ \t\n]+\\(\\sw\\|[_.]\\)+[ \t\n]*\\)?is[ \t\n]"))
38
39 (defvar ada--imenu-generic-expression
40 (list
41 (list nil ada--imenu-subprogram-menu-re 3)
42 (list "*Specs*"
43 (concat
44 "^[ \t]*\\(procedure\\|function\\)[ \t\n]+\\(\\(\\sw\\|_\\)+\\)"
45 "\\("
46 "\\(" ada--imenu-comment-re "[ \t\n]+\\|[ \t\n]*([^)]+)"
47 ada--imenu-comment-re "\\)";; parameter list or simple space
48 "\\([ \t\n]*return[ \t\n]+\\(\\sw\\|[_.]\\)+[ \t\n]*\\)?"
49 "\\)?;") 2)
50 '("*Tasks*" "^[ \t]*task[ \t]+\\(type[ \t]+\\)?\\(\\(body[ \t]+\\)?\\(\\sw\\|_\\)+\\)" 2)
51 '("*Type Defs*" "^[ \t]*\\(sub\\)?type[ \t]+\\(\\(\\sw\\|_\\)+\\)" 2)
52 '("*Protected*"
53 "^[ \t]*protected[ \t]+\\(type[ \t]+\\)?\\(\\(body[ \t]+\\)?\\(\\sw\\|_\\)+\\)" 2)
54 '("*Packages*" "^[ \t]*package[ \t]+\\(\\(body[ \t]+\\)?\\(\\sw\\|[_.]\\)+\\)" 1))
55 "Imenu generic expression for Ada mode.
56 See `imenu-generic-expression'. This variable will create several submenus for
57 each type of entity that can be found in an Ada file.")
58
59 (defun ada--imenu-mode ()
60 ;; In 4.01, these were called in 'ada-mode or required to be set in
61 ;; the user's .emacs.
62
63 (setq imenu-auto-rescan t)
64 (setq imenu-case-fold-search t)
65 (setq imenu-generic-expression ada--imenu-generic-expression)
66 (setq imenu-sort-function 'imenu--sort-by-name)
67 (setq imenu-use-markers nil)
68
69 (imenu-add-to-menubar "Entities")
70 )
71
72 ;; ada--imenu-mode does not depend on file local variables
73 (add-hook 'ada-mode-hook #'ada--imenu-mode)
74
75 (provide 'ada-imenu)
76
77 ;;; ada-imenu.el ends here