Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

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...
1 parent b09d5da commit 8e6844035a8f5a7e19325c59e39b886cd0427488 @markhepburn committed
Showing with 19 additions and 8 deletions.
  1. +19 −8 tags-view.el
27 tags-view.el
@@ -36,9 +36,7 @@
;;; once!
;;; TODO:
-;;; * support for gtags as well as etags
;;; * manipulation of the tags list (deletion, etc)
-;;; * autodetection of etags/gtags etc
;;; Code:
@@ -71,6 +69,16 @@
symbol indicating which backend should be used, or 'none if not
+(defvar tv-backend-list
+ '((etags
+ (get-tags-list . tv-get-tags-list-for-etags))
+ (gtags
+ (get-tags-list . tv-get-tags-list-for-gtags)))
+ "Assoc list keyed by the symbol returned by
+ `tv-determine-backend', whose values are also assoc lists
+ mapping the functionality keys to functions implementing that
+ functionality for that backend.")
;;; Use a datastructure containing point and buffer instead of
;;; markers, for backends such as gtags that don't use markers:
(defun tv--make-pb (point buffer) (cons point buffer))
@@ -106,13 +114,16 @@ etc."
(t (rec (file-name-directory (directory-file-name dir)))))))
(catch 'exit (rec working-dir)))))
+(defun tv--call-fn-for-backend (fn-sym backend &rest args)
+ (condition-case nil
+ (let* ((backend-list (cdr (assoc backend tv-backend-list)))
+ (impl (cdr (assoc fn-sym backend-list))))
+ (apply impl args))
+ (error
+ (error "Couldn't find implementation of %s for backend %s" fn-sym backend))))
(defun tv-get-tags-list ()
- (let* ((backend (tv-determine-backend))
- (backend-fn (intern (concat "tv-get-tags-list-for-"
- (symbol-name backend)))))
- (if (or (eq backend 'none) (not (fboundp backend-fn)))
- (error "Can't find a usable backend")
- (funcall backend-fn))))
+ (tv--call-fn-for-backend 'get-tags-list (tv-determine-backend)))
(defun tv-get-tags-list-for-etags ()
(mapcar 'tv--pb-from-marker (ring-elements tags-location-ring)))
(defun tv-get-tags-list-for-gtags ()

0 comments on commit 8e68440

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