Skip to content

Commit

Permalink
Adding a symbol-based generic backend, plus sample implementation (in…
Browse files Browse the repository at this point in the history
… theory, allows the user to add their own backends by customising tv-backend-list and tv-determine-backend-function)
  • Loading branch information
markhepburn committed Sep 14, 2009
1 parent b09d5da commit 8e68440
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions tags-view.el
Expand Up @@ -36,9 +36,7 @@
;;; once! ;;; once!


;;; TODO: ;;; TODO:
;;; * support for gtags as well as etags
;;; * manipulation of the tags list (deletion, etc) ;;; * manipulation of the tags list (deletion, etc)
;;; * autodetection of etags/gtags etc


;;; Code: ;;; Code:


Expand Down Expand Up @@ -71,6 +69,16 @@
symbol indicating which backend should be used, or 'none if not symbol indicating which backend should be used, or 'none if not
applicable.") 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 ;;; Use a datastructure containing point and buffer instead of
;;; markers, for backends such as gtags that don't use markers: ;;; markers, for backends such as gtags that don't use markers:
(defun tv--make-pb (point buffer) (cons point buffer)) (defun tv--make-pb (point buffer) (cons point buffer))
Expand Down Expand Up @@ -106,13 +114,16 @@ etc."
(t (rec (file-name-directory (directory-file-name dir))))))) (t (rec (file-name-directory (directory-file-name dir)))))))
(catch 'exit (rec working-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 () (defun tv-get-tags-list ()
(let* ((backend (tv-determine-backend)) (tv--call-fn-for-backend 'get-tags-list (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))))
(defun tv-get-tags-list-for-etags () (defun tv-get-tags-list-for-etags ()
(mapcar 'tv--pb-from-marker (ring-elements tags-location-ring))) (mapcar 'tv--pb-from-marker (ring-elements tags-location-ring)))
(defun tv-get-tags-list-for-gtags () (defun tv-get-tags-list-for-gtags ()
Expand Down

0 comments on commit 8e68440

Please sign in to comment.