Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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...
commit 8e6844035a8f5a7e19325c59e39b886cd0427488 1 parent b09d5da
Mark Hepburn authored
Showing with 19 additions and 8 deletions.
  1. +19 −8 tags-view.el
27 tags-view.el
View
@@ -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
applicable.")
+(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 ()
Please sign in to comment.
Something went wrong with that request. Please try again.