Hi Eric,
Following my previous patch to senator.el to improve the robustness of
`senator-search-tag-name', here is another change to use a hook instead
of a simple variable to filter searched tags.
The advantage of using a hook is that it allows to have both buffer
local and global filters active at the same time in that order. I
provided a default global filter to ignore code and block
tags. Default ignored tag classes are customizable. The
`senator-search-set-tag-class-filter' command uses the new hook to add
a buffer local filter.
WDYT? If you agree with that change I can commit it.
Thanks.
David
2005-05-18 David Ponce <david@...>
* cedet/semantic/senator.el
(senator-search-ignore-tag-classes)
(senator--search-filter): New variables.
(senator-search-default-tag-filter): New function.
(senator-search-tag-filter): Remove.
(senator-search-tag-filter-functions): New hook.
(senator-search): Use it.
(senator-search-set-tag-class-filter): Likewise. Doc fix.
Index: senator.el
===================================================================
RCS file: /cvsroot/cedet/cedet/semantic/senator.el,v
retrieving revision 1.105
diff -c -r1.105 senator.el
*** senator.el 13 May 2005 08:07:46 -0000 1.105
--- senator.el 18 May 2005 06:37:03 -0000
***************
*** 471,481 ****
(goto-char (match-beginning 0))
(search-forward name))))
! (defcustom senator-search-tag-filter nil
! "*Function that filter searched tags.
! It is passed a tag and can return nil to exclude it from search."
:group 'senator
! :type 'function)
(defun senator-search (searcher text &optional bound noerror count)
"Use the SEARCHER function to search from point for TEXT in a tag name.
--- 471,494 ----
(goto-char (match-beginning 0))
(search-forward name))))
! (defcustom senator-search-ignore-tag-classes
! '(code block)
! "*List of ignored tag classes.
! Tags of those classes are excluded from search."
:group 'senator
! :type '(repeat (symbol :tag "class")))
!
! (defun senator-search-default-tag-filter (tag)
! "Default function that filters searched tags.
! Ignore tags of classes in `senator-search-ignore-tag-classes'"
! (not (memq (semantic-tag-class tag)
! senator-search-ignore-tag-classes)))
!
! (defvar senator-search-tag-filter-functions
! '(senator-search-default-tag-filter)
! "List of functions to be called to filter searched tags.
! Each function is passed a tag. If one of them returns nil, the tag is
! excluded from the search.")
(defun senator-search (searcher text &optional bound noerror count)
"Use the SEARCHER function to search from point for TEXT in a tag name.
***************
*** 497,504 ****
(if (= sstart send)
(setq found t)
(and (setq tag (semantic-current-tag))
! (or (null senator-search-tag-filter)
! (funcall senator-search-tag-filter tag))
(setq tend (senator-search-tag-name tag))
(setq tstart (match-beginning 0)
found (and (>= sstart tstart)
--- 510,517 ----
(if (= sstart send)
(setq found t)
(and (setq tag (semantic-current-tag))
! (run-hook-with-args-until-failure
! 'senator-search-tag-filter-functions tag)
(setq tend (senator-search-tag-name tag))
(setq tstart (match-beginning 0)
found (and (>= sstart tstart)
***************
*** 1125,1134 ****
(isearch-update-ring string t)
(senator-re-search-backward string)))
(defun senator-search-set-tag-class-filter (&optional classes)
"In current buffer, limit search scope to tag CLASSES.
! CLASSES is a list of tag class symbols or nil.
! If nil restore the global filter option `senator-search-tag-filter'."
(interactive "sClasses: ")
(setq classes
(cond
--- 1138,1149 ----
(isearch-update-ring string t)
(senator-re-search-backward string)))
+ (defvar senator--search-filter nil)
+
(defun senator-search-set-tag-class-filter (&optional classes)
"In current buffer, limit search scope to tag CLASSES.
! CLASSES is a list of tag class symbols or nil. If nil only global
! filters in `senator-search-tag-filter-functions' remain active."
(interactive "sClasses: ")
(setq classes
(cond
***************
*** 1141,1154 ****
(t
(signal 'wrong-type-argument (list classes)))
))
(if classes
(let ((tag (make-symbol "tag"))
(names (mapconcat 'symbol-name classes "', `")))
! (set (make-local-variable 'senator-search-tag-filter)
`(lambda (,tag)
(memq (semantic-tag-class ,tag) ',classes)))
(message "Limit search to `%s' tags" names))
- (kill-local-variable 'senator-search-tag-filter)
(message "Default search filter restored")))
;;;;
--- 1156,1176 ----
(t
(signal 'wrong-type-argument (list classes)))
))
+ ;; Clear previous filter.
+ (remove-hook 'senator-search-tag-filter-functions
+ senator--search-filter t)
+ (kill-local-variable 'senator--search-filter)
(if classes
(let ((tag (make-symbol "tag"))
(names (mapconcat 'symbol-name classes "', `")))
! (set (make-local-variable 'senator--search-filter)
`(lambda (,tag)
(memq (semantic-tag-class ,tag) ',classes)))
+ (semantic-make-local-hook
+ 'senator-search-tag-filter-functions)
+ (add-hook 'senator-search-tag-filter-functions
+ senator--search-filter nil t)
(message "Limit search to `%s' tags" names))
(message "Default search filter restored")))
;;;;
|