aboutsummaryrefslogtreecommitdiffhomepage
path: root/phox/phox-tags.el
blob: c62fe331e6bcfbbf72afa2de6b795ab39e0af12b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
;; $State$ $Date$ $Revision$ 
;;--------------------------------------------------------------------------;;
;;--------------------------------------------------------------------------;;
;;                         gestion des TAGS
;;--------------------------------------------------------------------------;;

; sous xemacs, visit-tags-table n'a pas d'argument optionnel. Sous gnu emacs :

; Normally M-x visit-tags-table sets the global value of `tags-file-name'.
; With a prefix arg, set the buffer-local value instead.

; mieux vaut sous gnu emacs gérer la variable tags-table-list, qui
; n'existe pas sous xemacs.
; Sous xemacs il faut gérer la variable tag-table-alist qui n'existe pas
; sous gnu emacs.


(require 'etags)


(defun phox-tags-add-table(table)
  "add tags table"
  (interactive "D directory, location of a file named TAGS to add : ")
  (if (featurep 'xemacs)
      (let ((association (cons buffer-file-name table)))
	(if (member association tag-table-alist)
	    (message "%s already loaded." table)
	  (setq tag-table-alist (cons association tag-table-alist))))
					; gnu emacs
    (if (member table tags-table-list)
	(message "%s already loaded." table)
;    (make-local-variable 'tags-table-list) ; ne fonctionne pas
      (setq tags-table-list (cons table tags-table-list))
      )
    )
  )

(defun phox-tags-reset-table()
  "Set tags-table-list to nil."
  (interactive)
;  (make-local-variable 'tags-table-list)
  (if (featurep 'xemacs)
      (progn
	(setq tag-table-alist (remassoc buffer-file-name tag-table-alist)))
    (setq tags-table-list nil))
  )

(defun phox-tags-add-doc-table()
  "Add tags in text documentation."
  (interactive)
  (phox-tags-add-table (concat phox-doc-dir "/text/TAGS"))
  )

(defun phox-tags-add-lib-table()
  "Add tags in libraries."
  (interactive)
  (phox-tags-add-table (concat phox-lib-dir "/TAGS"))
  )
 
(defun phox-tags-add-local-table()
  "Add the tags table created with function phox-create-local-table."
  (interactive)
  (phox-tags-add-table (concat buffer-file-name "TAGS"))
  )

(defun phox-tags-create-local-table()
  "create table on local buffer"
  (interactive)
  (shell-command (concat phox-etags 
			 " -o " 
			 (file-name-nondirectory (buffer-file-name))
			 "TAGS "
			 (file-name-nondirectory (buffer-file-name))))
  )


(defun phox-complete-tag()
"Complete symbol using tags table. Works with FSF emacs.
 Problems with xemacs."
;; xemacs build a table for completion, tag-completion-table this table
;; donnot contains key words that use ".". There is a problem with
;; syntax-table. In xemacs you need to redefine
;; add-to-tag-completion-table, in order to add your file-type and
;; syntax-table. The modification is very simple, there should be an
;; hook for that.
;; 
(interactive)
(if (featurep 'xemacs)
     (tag-complete-symbol)
  (complete-tag)
  )
)

;; menu

(defvar phox-tags-menu
     '("Tags"
       ["create a tags table for local buffer" phox-tags-create-local-table t]
       ["------------------" nil nil]
       ["add table"               phox-tags-add-table       t]
       ["add local table"         phox-tags-add-local-table t]
       ["add table for libraries" phox-tags-add-lib-table   t]
       ["add table for text doc"  phox-tags-add-doc-table   t]
       ["reset tags table list"   phox-tags-reset-table     t]
       ["------------------" nil nil]
       ["Find theorem, definition ..." find-tag t]
       ["complete theorem, definition ..." phox-complete-tag t]
      )
"Phox menu for dealing with tags"
)

(provide 'phox-tags)