Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Switching from using markers as the basic data type to a custom one (…

…just a cons cell) containing the point location and buffer for each visited tag.
  • Loading branch information...
commit b09d5dad295590ea0caa3c50816ebef77740c001 1 parent 293f6ca
Mark Hepburn authored September 14, 2009

Showing 1 changed file with 40 additions and 33 deletions. Show diff stats Hide diff stats

  1. 73  tags-view.el
73  tags-view.el
@@ -71,6 +71,14 @@
71 71
   symbol indicating which backend should be used, or 'none if not
72 72
   applicable.")
73 73
 
  74
+;;; Use a datastructure containing point and buffer instead of
  75
+;;; markers, for backends such as gtags that don't use markers:
  76
+(defun tv--make-pb (point buffer) (cons point buffer))
  77
+(defun tv--pb-from-marker (marker)
  78
+  (tv--make-pb (marker-position marker) (marker-buffer marker)))
  79
+(defun tv--pb-point  (pb) (car pb))
  80
+(defun tv--pb-buffer (pb) (cdr pb))
  81
+
74 82
 (defun tv-determine-backend ()
75 83
   "Returns a symbol indicating which backend should be used (eg,
76 84
   'etags, 'gtags, etc)."
@@ -98,17 +106,17 @@ etc."
98 106
                (t (rec (file-name-directory (directory-file-name dir)))))))
99 107
       (catch 'exit (rec working-dir)))))
100 108
 
101  
-(defun tv-get-tags-marker-list ()
  109
+(defun tv-get-tags-list ()
102 110
   (let* ((backend (tv-determine-backend))
103  
-         (backend-fn (intern (concat "tv-get-tags-marker-list-for-"
  111
+         (backend-fn (intern (concat "tv-get-tags-list-for-"
104 112
                                      (symbol-name backend)))))
105 113
     (if (or (eq backend 'none) (not (fboundp backend-fn)))
106 114
         (error "Can't find a usable backend")
107 115
       (funcall backend-fn))))
108  
-(defun tv-get-tags-marker-list-for-etags ()
109  
-  (copy-list (ring-elements tags-location-ring)))
110  
-(defun tv-get-tags-marker-list-for-gtags ()
111  
-  (let ((points-and-buffers (map 'list 'cons gtags-point-stack gtags-buffer-stack))
  116
+(defun tv-get-tags-list-for-etags ()
  117
+  (mapcar 'tv--pb-from-marker (ring-elements tags-location-ring)))
  118
+(defun tv-get-tags-list-for-gtags ()
  119
+  (let ((points-and-buffers (map 'list 'tv--make-pb gtags-point-stack gtags-buffer-stack))
112 120
         (gtags-markers nil))
113 121
     (dolist (pb points-and-buffers gtags-markers)
114 122
       (with-current-buffer (cdr pb)
@@ -130,16 +138,15 @@ etc).  The following options will be available:
130 138
     (let ((inhibit-read-only t))
131 139
       (erase-buffer))
132 140
     (tags-history-mode)
133  
-    (let ((tag-items (tv-get-tags-marker-list)))
  141
+    (let ((tag-items (tv-get-tags-list)))
134 142
       (tv-insert-items tag-items))
135 143
     (setq buffer-read-only t)
136 144
     (goto-char 0)))
137 145
 
138  
-(defun tv-what-line (marker)
139  
-  "Return the line number of a marker"
140  
-  (save-current-buffer
141  
-    (set-buffer (marker-buffer marker))
142  
-    (line-number-at-pos (marker-position marker))))
  146
+(defun tv-what-line (pb)
  147
+  "Return the line number of a point-buffer structure."
  148
+  (with-current-buffer (tv--pb-buffer pb)
  149
+    (line-number-at-pos (tv--pb-point pb))))
143 150
 
144 151
 (defun tv-insert-items (items &optional count)
145 152
   "Insert the formatted list of tags with context"
@@ -153,23 +160,24 @@ etc).  The following options will be available:
153 160
                   (insert tv-separator-string "\n"))
154 161
               (tv-insert-items (cdr items) (1+ count)))))))
155 162
 
156  
-(defun tv-insert-single-item (marker posn)
  163
+(defun tv-insert-single-item (pb posn)
157 164
   "Insert a single formatted item, including overlays etc.
158 165
 Argument is a marker that will be displayed, along with
159 166
 `tv-context-lines' of context, if non-zero."
160 167
   (let ((beg (point)))
161 168
     (insert (propertize (format "Buffer %s, line %d:\n"
162  
-                                (buffer-name (marker-buffer marker))
163  
-                                (tv-what-line marker))
  169
+                                (buffer-name (tv--pb-buffer pb))
  170
+                                (tv-what-line pb))
164 171
                         'face 'tv-header-face))
165  
-    (insert (tv-get-lines-with-context marker tv-context-lines) "\n")
  172
+    (insert (tv-get-lines-with-context pb tv-context-lines) "\n")
166 173
     (let ((o (make-overlay beg (point))))
167 174
       (overlay-put o 'mouse-face 'highlight)
168 175
       (overlay-put o 'tv-ring-posn posn)
169  
-      (overlay-put o 'tv-marker marker))))
  176
+      (overlay-put o 'tv-buffer (tv--pb-buffer pb))
  177
+      (overlay-put o 'tv-point (tv--pb-point pb)))))
170 178
 
171  
-(defun tv-get-lines-with-context (marker &optional num-context)
172  
-  "Grabs the line at the specified marker; if optional
  179
+(defun tv-get-lines-with-context (pb &optional num-context)
  180
+  "Grabs the line at the specified point-and-buffer; if optional
173 181
   num-context is specified, it will also grab that number of
174 182
   preceding and following lines, assuming sufficient lines exist.
175 183
   For example, if 2 context lines are specified, a total of 5
@@ -178,17 +186,17 @@ Argument is a marker that will be displayed, along with
178 186
   exist in either direction, as many as possible will be used."
179 187
   (unless num-context (setq num-context 0))
180 188
   (if (< num-context 0) (setq (num-context (- num-context))))
181  
-  (save-current-buffer
182  
-    (set-buffer (marker-buffer marker))
183  
-    (let (start end)
184  
-      (goto-char (marker-position marker))
185  
-      (forward-line (- num-context))
186  
-      (setq start (point))
187  
-      (goto-char (marker-position marker))
188  
-      (forward-line num-context)
189  
-      (end-of-line)
190  
-      (setq end (point))
191  
-      (buffer-substring start end))))
  189
+  (with-current-buffer (tv--pb-buffer pb)
  190
+    (save-excursion
  191
+      (let (start end)
  192
+        (goto-char (tv--pb-point pb))
  193
+        (forward-line (- num-context))
  194
+        (setq start (point))
  195
+        (goto-char (tv--pb-point pb))
  196
+        (forward-line num-context)
  197
+        (end-of-line)
  198
+        (setq end (point))
  199
+        (buffer-substring start end)))))
192 200
 
193 201
 ;;; to implement; different methods of operating on the current selection:
194 202
 (defun tv-display-tag-other-window ())
@@ -196,9 +204,8 @@ Argument is a marker that will be displayed, along with
196 204
   (interactive "d")
197 205
   (let* ((o (or (car-safe (overlays-at location))
198 206
                 (car (overlays-at (next-overlay-change location)))))
199  
-         (marker (overlay-get o 'tv-marker))
200  
-         (buf    (marker-buffer marker))
201  
-         (posn   (marker-position marker)))
  207
+         (buf    (overlay-get o 'tv-buffer))
  208
+         (posn   (overlay-get o 'tv-point)))
202 209
     (switch-to-buffer buf)
203 210
     (goto-char posn)
204 211
     (delete-other-windows)))

0 notes on commit b09d5da

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