Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Mostly done now; operations completed (albeit, not tested for gtags y…

…et), and seems mostly complete. Should probably tidy up a bit with customisation groups, etc, and of course a readme.
  • Loading branch information...
commit fc8a452fea9804dfde6598dc26a21cea267b75b1 1 parent a4516ee
Mark Hepburn authored September 14, 2009

Showing 1 changed file with 63 additions and 17 deletions. Show diff stats Hide diff stats

  1. 80  tags-view.el
80  tags-view.el
@@ -29,14 +29,21 @@
29 29
 ;;; repeatedly to pop back up the stack, but this would lose your
30 30
 ;;; current location.  This module allows you to view the path taken,
31 31
 ;;; and if desired to jump immediately back to any intermediate
32  
-;;; location.
  32
+;;; location, delete any extranous locations, etc.
33 33
 
34 34
 ;;; I don't think this exists, but I haven't looked too hard -- I'd
35 35
 ;;; like the practice of writing something to completion for emacs for
36  
-;;; once!
37  
-
38  
-;;; TODO:
39  
-;;; * manipulation of the tags list (deletion, etc)
  36
+;;; once, before realising someone else has already provided it!
  37
+;;; Update: ok, I went looking, and of course it exists:
  38
+;;; http://www.emacswiki.org/emacs/EtagsStack
  39
+;;; I'd like to think this offers a little bit different; it supports
  40
+;;; gtags as well out of the box and in theory at least can be
  41
+;;; extended to others, and it offers a few more operations on the
  42
+;;; chronological trace.  Of course, if you need any of that is up to
  43
+;;; you :)
  44
+
  45
+;;; Bugs: Most probably.  The gtags backend in particular really
  46
+;;; hasn't copped much testing yet.
40 47
 
41 48
 ;;; Code:
42 49
 
@@ -61,9 +68,11 @@
61 68
 
62 69
 (defvar tv-backend-list
63 70
   '((etags
64  
-     (get-tags-list . tv-get-tags-list-for-etags))
  71
+     (get-tags-list . tv-get-tags-list-for-etags)
  72
+     (clear-tag . tv-delete-tag-for-etags))
65 73
     (gtags
66  
-     (get-tags-list . tv-get-tags-list-for-gtags)))
  74
+     (get-tags-list . tv-get-tags-list-for-gtags)
  75
+     (clear-tag . tv-delete-tag-for-gtags)))
67 76
   "Assoc list keyed by the symbol returned by
68 77
   `tv-determine-backend', whose values are also assoc lists
69 78
   mapping the functionality keys to functions implementing that
@@ -173,7 +182,7 @@ Argument is a marker that will be displayed, along with
173 182
     (insert (tv-get-lines-with-context pb tv-context-lines) "\n")
174 183
     (let ((o (make-overlay beg (point))))
175 184
       (overlay-put o 'mouse-face 'highlight)
176  
-      (overlay-put o 'tv-ring-posn posn)
  185
+      (overlay-put o 'tv-stack-posn posn)
177 186
       (overlay-put o 'tv-buffer (tv--pb-buffer pb))
178 187
       (overlay-put o 'tv-point (tv--pb-point pb)))))
179 188
 
@@ -200,19 +209,54 @@ Argument is a marker that will be displayed, along with
200 209
         (buffer-substring start end)))))
201 210
 
202 211
 ;;; to implement; different methods of operating on the current selection:
203  
-(defun tv-display-tag-other-window ())
  212
+
  213
+(defmacro with-tag-info (locn args &rest body)
  214
+  "Macro to facilitate writing tag-stack operations.  First
  215
+  argument is the location (point) in the buffer, the second is
  216
+  an \"argument list\" of buffer, position, and stack position,
  217
+  all taken from the tag under point, and the remainder is the
  218
+  body.  The arg-list args will be bound within the body to the
  219
+  values corresponding to the tag under point."
  220
+  (declare (indent 2))
  221
+  (let ((o (gensym "tv-overlay-")))
  222
+    `(let* ((,o (or (car-safe (overlays-at ,locn))
  223
+                    (car (overlays-at (next-overlay-change ,locn)))))
  224
+            (,(car   args) (overlay-get ,o 'tv-buffer))
  225
+            (,(cadr  args) (overlay-get ,o 'tv-point))
  226
+            (,(caddr args) (overlay-get ,o 'tv-stack-posn)))
  227
+       ,@body)))
  228
+
  229
+(defun tv-display-tag-other-window (location)
  230
+  (interactive "d")
  231
+  (with-tag-info location (buf posn stack)
  232
+    (let ((tags-win (selected-window)))
  233
+      (with-current-buffer (pop-to-buffer buf)
  234
+        (goto-char posn)
  235
+        (recenter))
  236
+      (select-window tags-win))))
204 237
 (defun tv-jump-to-tag-and-quit (location)
205 238
   (interactive "d")
206  
-  (let* ((o (or (car-safe (overlays-at location))
207  
-                (car (overlays-at (next-overlay-change location)))))
208  
-         (buf    (overlay-get o 'tv-buffer))
209  
-         (posn   (overlay-get o 'tv-point)))
  239
+  (with-tag-info location (buf posn stack)
210 240
     (switch-to-buffer buf)
211 241
     (goto-char posn)
212 242
     (delete-other-windows)))
213  
-(defun tv-clear-tag-at-point ())
214  
-
215  
-;;; Navigation:
  243
+(defun tv-delete-tag-at-point (location)
  244
+  (interactive "d")
  245
+  (with-tag-info location (buf posn stack-pos)
  246
+    (tv--call-fn-for-backend 'clear-tag (tv-determine-backend) stack-pos)
  247
+    ;; redraw:
  248
+    (tv-view-history)))
  249
+;;; implementations:
  250
+(defun tv-delete-tag-for-etags (stack-position)
  251
+  (ring-remove tags-location-ring stack-position))
  252
+(defun tv-delete-tag-for-gtags (stack-position)
  253
+  (labels
  254
+      ((delete-nth (n lst)
  255
+                   (setcdr (nthcdr (1- n) lst) (nthcdr (1+ n) lst))))
  256
+    (delete-nth stack-position gtags-point-stack)
  257
+    (delete-nth stack-position gtags-buffer-stack)))
  258
+
  259
+;;; Navigation (mostly borrowed from browse-kill-ring):
216 260
 (defun tv-next-tag (&optional arg)
217 261
   "Move point forward to the next tag.  Optional numeric argument
218 262
   moves forward that many tags."
@@ -267,7 +311,9 @@ Argument is a marker that will be displayed, along with
267 311
     (define-key km "k"    'tv-previous-tag)
268 312
 
269 313
     ;; operation:
270  
-    (define-key km "\C-m"  'tv-jump-to-tag-and-quit)
  314
+    (define-key km "\C-m" 'tv-jump-to-tag-and-quit)
  315
+    (define-key km "o"    'tv-display-tag-other-window)
  316
+    (define-key km "d"    'tv-delete-tag-at-point)
271 317
 
272 318
     ;; cleanup:
273 319
     (define-key km "q"    'delete-window)))

0 notes on commit fc8a452

Please sign in to comment.
Something went wrong with that request. Please try again.