-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathphp-tags.el
185 lines (162 loc) · 6.05 KB
/
php-tags.el
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
;;; php-tags.el --- Create and load tag files.
;; Version: 3.0
;; Created: 6-15-2009
;; Copyright © 2009 Brian Zwahr
;; Author(s):
;; Brian Zwahr <[email protected]>
;;; *****
;;; About
;;; *****
;; php-tags.el is a part of the php+-mode suite and is used for helping make
;; tags for php files and projects easier. It uses projects setup with
;; php-project.
;;; *****
;;; Usage
;;; *****
;; Requirements:
;; php-project
;; php-funcs
;; Use customize to set the tag-shell-command to your ctags
;; executable, the directory where you would like your ctags stored,
;; and the arguments to be used by ctags.
;;
;; Use php-create-tag-file (available in the php+-mode menu) to create a
;; tag file for the current project. When using php+-mode, tags are
;; automatically loaded when switching to a buffer of a php file
;; associated with a project.
;; *************************************************************************
;;; ************
;;; Requirements
;;; ************
(require 'etags)
(require 'php-project)
(require 'php-funcs)
;; ******
;; CUSTOM
;; ******
(defgroup php-tags nil
"Customizations for php-tags."
:group 'php)
(defcustom tag-shell-command "ctags"
"Shell command to execute for creating tags."
:group 'php-tags
:type 'string)
(defcustom php-tags-recursive t
"Whether the tagging should be recursive into the directory."
:group 'php-tags
:type 'boolean)
(defcustom php-tags-relative t
"Whether the tags should be relative."
:group 'php-tags
:type 'boolean)
(defcustom php-tags-totals nil
"Whether the tagging should include totals."
:group 'php-tags
:type 'boolean)
(defcustom php-tag-file-extensions (list ".php")
"File extensions to include when tagging."
:group 'php-tags
:type '(repeat :tag "File extension" (string)))
(defcustom php-tag-ignore-patterns (list "\.svn")
"File of directory patterns to ignore when tagging."
:group 'php-tags
:type '(repeat :tag "File extension" (string)))
(defcustom php-tag-arguments (list
"--PHP-kinds=cfid"
"--regex-PHP=\"/(abstract |final )class ([^ ]*)/\\1/c/\""
"--regex-PHP=\"/(public |static |final |abstract |protected |private )+function ([^ (]*)/\\2/f/\"")
"A list of arguments for the tag executable."
:group 'php-tags
:type '(repeat :tag "Argument" (string)))
;; *********
;; FUNCTIONS
;; *********
(defun load-tags ()
"Loads the proper tag file for the current buffer."
(interactive)
(when (php-project-buffer-project)
(let ((filename (php-project-tags-file)))
(when (and filename
(not (equal filename ""))
(not (equal tags-file-name filename))
(file-exists-p filename))
(setq tags-file-name nil)
(setq tags-table-list nil)
(visit-tags-table filename)))))
(defun create-tag-file (directory &optional add-dirs tags-file extra-dirs args)
"Creates a tag file named 'name' from the files in 'directory'. The tag file
is saved in 'php-tags-directory', which can be set in customize."
(interactive
(list (read-directory-name "Root directory: "
(second (split-string (pwd) " ")))))
(let ((file
(expand-file-name
(or tags-file
(read-file-name "Tag file: " directory "TAGS" 'confirm))))
(other-dirs (list))
cmd)
(when add-dirs
(add-to-list
'other-dirs
(read-directory-name "Extra directory to be parsed for the tags file: "))
(while (y-or-n-p "Add another directory to be parsed for the tags file? ")
(add-to-list
'other-dirs
(read-directory-name
"Extra directory to be parsed for the tags file: "))))
(setq cmd (concat "cd " (convert-standard-filename directory)
" && " (convert-standard-filename tag-shell-command)
" -e -f " (convert-standard-filename file)
" " args " . "
(when extra-dirs (mapconcat 'identity extra-dirs " "))
" "
(mapconcat 'identity other-dirs " ")))
(message cmd)
(make-directory (convert-standard-filename (file-name-directory file)) t)
(message "Creating tags file: %s" file)
(if (eq 0 (shell-command cmd))
(progn
(message "Created tags file: %s" file)
(when (y-or-n-p
(concat "Would you like to load the newly created tags file "
file " ? "))
(setq tags-completion-table nil)
(let ((tags-buffer (or (file-name-nondirectory file) "TAGS")))
(when (get-buffer tags-buffer)
(kill-buffer tags-buffer)))
(visit-tags-table file)))
(message "Tags creation failed. Check *Shell Command Output* buffer."))))
(defun php-create-tag-file (add-dirs)
(interactive "P")
(let ((args (concat (when php-tags-recursive " -R")
" --tag-relative=" (if php-tags-relative "yes" "no")
" --totals=" (if php-tags-totals "yes" "no")
" --langmap=php:"
(mapconcat 'identity php-tag-file-extensions "")
(mapconcat
(lambda (str)
(concat " --exclude=" (shell-quote-argument str)))
php-tag-ignore-patterns "")
" "
(mapconcat 'identity php-tag-arguments " "))))
(create-tag-file
(php-project-directory)
add-dirs
(php-project-tags-file)
(php-project-tags-directories)
args)))
(defun php-create-tag-file-with-dirs ()
"This function runs (php-create-tag-file) with a t argument to prompt for
directories to add."
(interactive)
(php-create-tag-file t))
(defun php-find-tag (tagname)
"Finds the tag name in the proper TAGS file."
(interactive (find-tag-interactive "Find tag: "))
(load-tags)
(find-tag tagname))
(defun php-tags-customize ()
"This functions opens the customize buffer for php-tags."
(interactive)
(customize-group "php-tags"))
(provide 'php-tags)