Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Adding a symbol-based generic backend, plus sample implementation (in…

… theory, allows the user to add their own backends by customising tv-backend-list and tv-determine-backend-function)
  • Loading branch information...
commit 8e6844035a8f5a7e19325c59e39b886cd0427488 1 parent b09d5da
Mark Hepburn authored September 14, 2009

Showing 1 changed file with 19 additions and 8 deletions. Show diff stats Hide diff stats

  1. 27  tags-view.el
27  tags-view.el
@@ -36,9 +36,7 @@
36 36
 ;;; once!
37 37
 
38 38
 ;;; TODO:
39  
-;;; * support for gtags as well as etags
40 39
 ;;; * manipulation of the tags list (deletion, etc)
41  
-;;; * autodetection of etags/gtags etc
42 40
 
43 41
 ;;; Code:
44 42
 
@@ -71,6 +69,16 @@
71 69
   symbol indicating which backend should be used, or 'none if not
72 70
   applicable.")
73 71
 
  72
+(defvar tv-backend-list
  73
+  '((etags
  74
+     (get-tags-list . tv-get-tags-list-for-etags))
  75
+    (gtags
  76
+     (get-tags-list . tv-get-tags-list-for-gtags)))
  77
+  "Assoc list keyed by the symbol returned by
  78
+  `tv-determine-backend', whose values are also assoc lists
  79
+  mapping the functionality keys to functions implementing that
  80
+  functionality for that backend.")
  81
+
74 82
 ;;; Use a datastructure containing point and buffer instead of
75 83
 ;;; markers, for backends such as gtags that don't use markers:
76 84
 (defun tv--make-pb (point buffer) (cons point buffer))
@@ -106,13 +114,16 @@ etc."
106 114
                (t (rec (file-name-directory (directory-file-name dir)))))))
107 115
       (catch 'exit (rec working-dir)))))
108 116
 
  117
+(defun tv--call-fn-for-backend (fn-sym backend &rest args)
  118
+  (condition-case nil
  119
+      (let* ((backend-list (cdr (assoc backend tv-backend-list)))
  120
+             (impl         (cdr (assoc fn-sym backend-list))))
  121
+        (apply impl args))
  122
+      (error
  123
+       (error "Couldn't find implementation of %s for backend %s" fn-sym backend))))
  124
+
109 125
 (defun tv-get-tags-list ()
110  
-  (let* ((backend (tv-determine-backend))
111  
-         (backend-fn (intern (concat "tv-get-tags-list-for-"
112  
-                                     (symbol-name backend)))))
113  
-    (if (or (eq backend 'none) (not (fboundp backend-fn)))
114  
-        (error "Can't find a usable backend")
115  
-      (funcall backend-fn))))
  126
+  (tv--call-fn-for-backend 'get-tags-list (tv-determine-backend)))
116 127
 (defun tv-get-tags-list-for-etags ()
117 128
   (mapcar 'tv--pb-from-marker (ring-elements tags-location-ring)))
118 129
 (defun tv-get-tags-list-for-gtags ()

0 notes on commit 8e68440

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