-
Notifications
You must be signed in to change notification settings - Fork 0
/
taglist.patch
390 lines (353 loc) · 15 KB
/
taglist.patch
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
--- C:\Users\g00280886\Desktop\taglist-master\taglist.el 2015-12-29 23:32:18.000000000 +0800
+++ D:\emacs\share\emacs\site-lisp\taglist-master\taglist.el 2017-05-25 17:37:20.000000000 +0800
@@ -81,12 +81,13 @@
;;; Code:
(require 'cl)
+(require 'imenu-list)
;; ================================== My STRING utils ========================
(defun taglist-string-without-last (string n)
"This function truncates from the STRING last N characters."
(substring string 0 (max 0(- (length string) n))))
(defun taglist-string-ends-with (string end)
@@ -103,13 +104,15 @@
("C" . ("H"))
("H" . ("C" "CPP" "CC"))
("cc" . ("h" "hpp")))
"This variable defines possible switches for `taglist-switch-h-cpp' function.
Its format is list of (from . (to1 to2 to3...)) elements. From and toN are
strings which are extentions of the files.")
-
+(defvar tag-list--last-location nil
+ "Location from which last `tag-list-update' was done.
+Used to avoid updating if the point didn't move.")
;;;###autoload
(defun taglist-switch-h-cpp ()
"Switch header and body file according to `taglist-header-switches' var.
The current buffer's file name extention is searched in
`taglist-header-switches' variable to find out extention for file's counterpart,
for example *.hpp <--> *.cpp."
@@ -161,14 +164,15 @@
(defvar taglist-current-major-mode nil
"current major mode")
(defface taglist-tag-type
'((((class color))
- (:foreground "blue" :height 1.2))
- (t (:weight bold)))
+ (:foreground "blue" :height 1.0))
+ ;; (t (:weight bold))
+ )
"Regexp matching the text identifying the file in `taglist-mode'."
:group 'taglist)
(defvar taglist-tag-type-face 'taglist-tag-type)
(defvar taglist-tag-type-re
@@ -187,12 +191,13 @@
;; TODO: maintain the list by ctags --list-maps and
;; https://github.com/github/linguist/blob/master/lib/linguist/languages.yml
;; format: (<file name pattern> <detected language>)
(defvar taglist-filename-to-language-alist
'(
+ ("\\.lua\\'" . "lua")
("\\.i\\'" . "c")
("\\.lex\\'" . "c")
("\\.[ch]\\'" . "c")
("\\.x[bp]m\\'" . "c")
("\\.xs\\'" . "c")
("\\.h$" . "c++")
@@ -279,12 +284,13 @@
;; major mode name map to language
;; (add-to-list 'taglist-major-to-language-alist '("<lang>-mode" "<lang>"))
;; format: (<major mode> <detected language>)
(defvar taglist-major-to-language-alist
`(
+ ("lua-mode" "lua")
("emacs-lisp-mode" "lisp")
("lisp-mode" "lisp")
("c-mode" "c")
("c++-mode" "c++")
;; rust is support at https://github.com/universal-ctags
("rst-mode" "rst")
@@ -342,17 +348,17 @@
;; beta language
("beta" "BETA;f:fragment;s:slot;v:pattern")
;; c language
("c" "C;c:classes;d:macro definitions;g:enumeration names;\
n:namespaces;s:structure names;t:typedefs;\
-u:union names;v:variable definitions;f:function definitions")
+u:union names;v:variable definitions;f:function definitions;p:function prototype")
;; c++ language
("c++" "C++;n:namespace;v:variable;d:macro;t:typedef;\
-c:class;g:enum;s:struct;u:union;f:function")
+c:class;g:enum;s:struct;u:union;f:function;p:function prototype")
;; c# language
("cs" "C#;d:macro;t:typedef;n:namespace;c:class;E:event;\
g:enum;s:struct;i:interface;p:properties;m:method")
;; cobol language
@@ -731,45 +737,98 @@
"--format=2"
"--excmd=number"
"--fields=nks"
"--sort=no"
(concat "--language-force=" ctags-language)
(concat "--" ctags-language "-kinds=" ctags-lang-kinds)
+ (if (or (equal ctags-language "C")
+ (equal ctags-language "C++"))
+ (concat "--" ctags-language "-kinds=+px")
+ "")
taglist-tmp-file
)))
"\n" t)
(insert (concat "Warnning: " (buffer-name taglist-source-code-buffer) " doesn't exist on your disk, you should save it first!\n"))
nil)))
;; e.g. tagline = main /path/to/src/ip46.c 38;" f line:38
(defun taglist-convert-to-elements (tagline)
"Convert tagline to a tag(tag-name tag-line tag-type) "
(let ((elements (split-string tagline "\t" t)))
(list (car elements) (string-to-number (nth 2 elements)) (nth 3 elements))))
-(defun taglist-jump-to-tag ()
+
+(defun taglist-jump-to-tag-by-event (event)
+ "Jump to a tag, corresponding the current line in tag buffer.
+When called standing on a line of tag list, it closes the list
+buffer and sets the point to a tag, corresponding the line."
+ (interactive "e")
+ (switch-to-buffer (get-buffer tag-list-buffer-name) t)
+ (let ((tag-record (nth (1- (line-number-at-pos (posn-point (event-end event)))) taglist-actual-tags)))
+
+ (if (and tag-record (= 0 (taglist-line tag-record)))
+ (setq tag-record (nth (line-number-at-pos (posn-point (event-end event))) taglist-actual-tags)))
+
+ (if (and tag-record (taglist-line tag-record))
+ (progn
+ ;; (kill-buffer (current-buffer))
+
+ (switch-to-buffer taglist-source-code-buffer t)
+
+ (taglist-goto-line (taglist-line tag-record))
+
+ (recenter)
+
+ (with-current-buffer (current-buffer)
+ (set-buffer (get-buffer tag-list-buffer-name))
+ (unless (eq taglist-search-string "")
+ ;; (with-selected-window (get-buffer-window (get-buffer tag-list-buffer-name))
+ (setq taglist-search-string "")
+ (taglist-search-string-updated)
+ (taglist-highlight-current-tag)
+ ))
+ )
+ (message "The line does not contain tag description!"))))
+
+(defun taglist-jump-to-tag-preview()
+ (interactive)
+ (taglist-jump-to-tag t)
+ )
+(defun taglist-jump-to-tag (&optional preview)
"Jump to a tag, corresponding the current line in tag buffer.
When called standing on a line of tag list, it closes the list
buffer and sets the point to a tag, corresponding the line."
(interactive)
(let ((tag-record (nth (1- (line-number-at-pos)) taglist-actual-tags)))
(if (and tag-record (= 0 (taglist-line tag-record)))
(setq tag-record (nth (line-number-at-pos) taglist-actual-tags)))
(if (and tag-record (taglist-line tag-record))
(progn
- (kill-buffer (current-buffer))
+ ;; (kill-buffer (current-buffer))
(switch-to-buffer taglist-source-code-buffer t)
(taglist-goto-line (taglist-line tag-record))
- (recenter))
- (message "The line does not contain tag description!"))))
+ (recenter)
+
+ (with-current-buffer (current-buffer)
+ (set-buffer (get-buffer tag-list-buffer-name))
+ (unless (eq taglist-search-string "")
+ ;; (with-selected-window (get-buffer-window (get-buffer tag-list-buffer-name))
+ (setq taglist-search-string "")
+ (taglist-search-string-updated)
+ (taglist-highlight-current-tag)
+ ))
+ (if preview
+ (select-window (get-buffer-window (get-buffer tag-list-buffer-name)) t))
+ )
+ (message "The line does not contain tag description!"))))
(defun taglist-matches-all (string substrings)
"Return non-nil if STRING contain each of SUBSTRINGS as a substring."
(reduce (lambda (prev part) (and prev (string-match part string))) substrings :initial-value t))
(defstruct taglist
@@ -894,14 +953,15 @@
(define-key map (char-to-string key) (taglist-make-key-function key)))
(defun taglist-escape ()
"Kill tag list buffer."
(interactive)
(kill-buffer (current-buffer))
- (delete-file taglist-tmp-file)
- (switch-to-buffer taglist-source-code-buffer))
+ ;; (delete-file taglist-tmp-file)
+ (switch-to-buffer taglist-source-code-buffer)
+ (tag-list-stop-timer))
(defvar taglist-mode-map
(let ((map (make-sparse-keymap)))
(suppress-keymap map)
(do ((k (string-to-char "a") (+ 1 k))) ((> k (string-to-char "z")))
(define-key
@@ -925,19 +985,23 @@
(taglist-make-key-function k)))
(taglist-key-itself map (string-to-char " "))
(taglist-key-itself map (string-to-char "_"))
(define-key map (kbd "<RET>") 'taglist-jump-to-tag)
+ (define-key map (kbd "<tab>") 'taglist-jump-to-tag-preview)
+
+ (define-key map [mouse-2] 'taglist-jump-to-tag-by-event)
+ (define-key map [mouse-3] 'taglist-jump-to-tag-by-event)
(define-key map (kbd "<backspace>") 'taglist-backspace-pressed)
;; Cause M-v doesn't work!!!
;; (define-key map (kbd "<ESC>") 'taglist-escape)
(define-key map (kbd "C-q") 'taglist-escape)
(define-key map (kbd "M-q") 'taglist-escape)
- (define-key map "\C-v" 'scroll-up)
- (define-key map "\M-v" 'scroll-down)
+ ;; (define-key map "\C-v" 'scroll-up)
+ ;; (define-key map "\M-v" 'scroll-down)
map)
"Keymap for `taglist-mode'.")
(defcustom ctags-executable-directory nil
"If non-nil the directory to search global executables."
:type '(choice (const :tag "Unset" nil) directory)
@@ -1059,15 +1123,104 @@
;; (message "found tag-line = %d" tag-line)
(let ((line (position-if
(lambda (item) (= tag-line (taglist-line item)))
taglist-actual-tags)))
(when line
- (taglist-goto-line (1+ line)))))
+ (unless (eq (line-number-at-pos) (+ 1 line))
+ (with-selected-window (get-buffer-window (get-buffer tag-list-buffer-name))
+ (taglist-goto-line (1+ line))
+ (hl-line-mode 1))
+ ))))
- (hl-line-mode))
+ ;; (hl-line-mode)
+ )
+
+(defconst tag-list-buffer-name "*TagList*"
+ "Name of the buffer that is used to display imenu entries.")
+
+(defun tag-list-install-display-buffer ()
+ "Install imenu-list display settings to `display-buffer-alist'."
+ (cl-pushnew `(,(concat "^" (regexp-quote tag-list-buffer-name) "$")
+ imenu-list-display-buffer)
+ display-buffer-alist
+ :test #'equal))
+(tag-list-install-display-buffer)
+(defvar tag-list--timer nil)
+
+(defun tag-list-start-timer ()
+ (tag-list-stop-timer)
+ (add-hook 'after-save-hook 'tag-list-update-after-save-safe)
+ (setq tag-list--timer
+ (run-with-idle-timer 1 t #'tag-list-update-safe)))
+
+(defun tag-list-stop-timer ()
+ (when tag-list--timer
+ (remove-hook 'after-save-hook 'tag-list-update-after-save-safe)
+ (cancel-timer tag-list--timer)
+ (setq tag-list--timer nil)))
+
+(defun tag-list-update-safe-for-ycmd (result)
+ (ignore-errors (tag-list-update)))
+(defun tag-list-update-safe ()
+ (ignore-errors (tag-list-update)))
+
+(defun tag-list-update ()
+ "Refresh taglist."
+ (if (or (minibufferp (current-buffer))
+ (string-equal "*" (substring (buffer-name) 0 1))
+ (eq major-mode 'dired-mode))
+ (error "Invalid buffer"))
+ (setq location (point-marker))
+ (unless (and tag-list--last-location
+ (marker-buffer tag-list--last-location)
+ (= location tag-list--last-location))
+ (setq tag-list--last-location location)
+ (unless (eq (current-buffer) (get-buffer tag-list-buffer-name))
+ (setq taglist-current-line (line-number-at-pos))
+ (if (eq taglist-source-code-buffer (current-buffer))
+ (progn
+ (with-current-buffer (current-buffer)
+ (set-buffer (get-buffer tag-list-buffer-name))
+ ;; (with-selected-window (get-buffer-window (get-buffer tag-list-buffer-name))
+ (taglist-highlight-current-tag))
+ )
+ (progn
+ (with-current-buffer (current-buffer)
+ (setq taglist-source-code-buffer (current-buffer))
+ ;; (setq taglist-tmp-file (make-temp-file "taglist."))
+ (setq taglist-tmp-file (buffer-file-name))
+ (setq taglist-current-major-mode major-mode)
+ ;; (write-region (point-min) (point-max) taglist-tmp-file)
+ (set-buffer (get-buffer tag-list-buffer-name))
+ ;; (with-selected-window (get-buffer-window (get-buffer tag-list-buffer-name))
+ (taglist-mode-init)))
+ ))))
+
+(defun tag-list-update-after-save-safe()
+ (ignore-errors (tag-list-update-after-save)))
+(defun tag-list-update-after-save ()
+ "Refresh taglist."
+ (if (or (minibufferp (current-buffer))
+ (string-equal "*" (substring (buffer-name) 0 1))
+ (eq major-mode 'dired-mode))
+ (error "Invalid buffer"))
+ (setq detected-language (taglist-detect-language))
+ (unless detected-language
+ (error "Unsupported buffer"))
+ (unless (eq (current-buffer) (get-buffer tag-list-buffer-name))
+ (setq taglist-current-line (line-number-at-pos))
+ (with-current-buffer (current-buffer)
+ (setq taglist-source-code-buffer (current-buffer))
+ ;; (setq taglist-tmp-file (make-temp-file "taglist."))
+ (setq taglist-tmp-file (buffer-file-name))
+ (setq taglist-current-major-mode major-mode)
+ ;; (write-region (point-min) (point-max) taglist-tmp-file)
+ (set-buffer (get-buffer tag-list-buffer-name))
+ ;; (with-selected-window (get-buffer-window (get-buffer tag-list-buffer-name))
+ (taglist-mode-init))))
;;;###autoload
(defun taglist-list-tags ()
"Show tag list of current buffer in a newly created buffer.
This function is recommended to be bound to some convinient hotkey."
(interactive)
@@ -1075,15 +1228,19 @@
(if (string= (taglist-ctags-variant) "emacs-ctags")
(error "taglist doesn't support emacs ctags, please install universal-ctags or exuberant-ctags!")
)
(setq taglist-source-code-buffer (current-buffer))
(setq taglist-current-line (line-number-at-pos))
(setq taglist-current-major-mode major-mode)
- (setq taglist-tmp-file (make-temp-file "taglist."))
- (write-region (point-min) (point-max) taglist-tmp-file)
- (switch-to-buffer (get-buffer-create (concat (buffer-name (current-buffer)) " tag list")) t)
+ (setq taglist-tmp-file (buffer-file-name))
+ ;; (setq taglist-tmp-file (make-temp-file "taglist."))
+ ;; (write-region (point-min) (point-max) taglist-tmp-file)
+ ;; (switch-to-buffer (get-buffer-create (concat (buffer-name (current-buffer)) " tag list")) t)
+ (pop-to-buffer (get-buffer-create tag-list-buffer-name))
+ (tag-list-start-timer)
+
(taglist-mode))
(defun taglist-mode-init ()
"Initialize tag list mode."
@@ -1093,12 +1250,13 @@
(make-local-variable 'taglist-all-tags)
;; subset of taglist-all-tags that contain taglist-search string in the name string
(make-local-variable 'taglist-actual-tags)
;; overlays used to highligh search string matches in tag names
(make-local-variable 'taglist-overlays)
(make-local-variable 'taglist-current-language)
+ (setq tag-list--last-location nil)
(set (make-local-variable 'font-lock-defaults) taglist-font-lock-defaults)
;; (message "current-line = %d" taglist-current-line)
(setq taglist-overlays nil)
(setq taglist-search-string "")
(setq taglist-all-tags