1 ;;; semantic/senator.el --- SEmantic NAvigaTOR
3 ;; Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
4 ;; 2009, 2010, 2011 Free Software Foundation, Inc.
6 ;; Author: David Ponce <david@dponce.com>
8 ;; Created: 10 Nov 2000
11 ;; This file is part of GNU Emacs.
13 ;; GNU Emacs is free software: you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation, either version 3 of the License, or
16 ;; (at your option) any later version.
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
28 ;; This file defines some user commands for navigating between
29 ;; Semantic tags. This is a subset of the version of senator.el in
30 ;; the upstream CEDET package; the rest is incorporated into other
31 ;; parts of Semantic or Emacs.
37 (require 'semantic
/ctxt
)
38 (require 'semantic
/decorate
)
39 (require 'semantic
/format
)
41 (eval-when-compile (require 'semantic
/find
))
43 ;; (eval-when-compile (require 'hippie-exp))
45 (declare-function semantic-analyze-tag-references
"semantic/analyze/refs")
46 (declare-function semantic-analyze-refs-impl
"semantic/analyze/refs")
47 (declare-function semantic-analyze-find-tag
"semantic/analyze")
48 (declare-function semantic-analyze-tag-type
"semantic/analyze/fcn")
49 (declare-function semantic-tag-external-class
"semantic/sort")
50 (declare-function imenu--mouse-menu
"imenu")
58 (defcustom senator-step-at-tag-classes nil
59 "List of tag classes recognized by Senator's navigation commands.
60 A tag class is a symbol, such as `variable', `function', or `type'.
62 As a special exception, if the value is nil, Senator's navigation
63 commands recognize all tag classes."
65 :type
'(repeat (symbol)))
67 (make-variable-buffer-local 'senator-step-at-tag-classes
)
70 (defcustom senator-step-at-start-end-tag-classes nil
71 "List of tag classes at which Senator's navigation commands should stop.
72 A tag class is a symbol, such as `variable', `function', or `type'.
73 The navigation commands stop at the start and end of each tag
74 class in this list, provided the tag class is recognized (see
75 `senator-step-at-tag-classes').
77 As a special exception, if the value is nil, the navigation
78 commands stop at the beginning of every tag.
80 If t, the navigation commands stop at the start and end of any
83 :type
'(choice :tag
"Identifiers"
84 (repeat :menu-tag
"Symbols" (symbol))
85 (const :tag
"All" t
)))
87 (make-variable-buffer-local 'senator-step-at-start-end-tag-classes
)
89 (defcustom senator-highlight-found nil
90 "If non-nil, Senator commands momentarily highlight found tags."
93 (make-variable-buffer-local 'senator-highlight-found
)
96 (defface senator-momentary-highlight-face
97 '((((class color
) (background dark
))
98 (:background
"gray30"))
99 (((class color
) (background light
))
100 (:background
"gray70")))
101 "Face used to momentarily highlight tags."
102 :group
'semantic-faces
)
106 (defun senator-momentary-highlight-tag (tag)
107 "Momentarily highlight TAG.
108 Does nothing if `senator-highlight-found' is nil."
109 (and senator-highlight-found
110 (semantic-momentary-highlight-tag
111 tag
'senator-momentary-highlight-face
)))
113 (defun senator-step-at-start-end-p (tag)
114 "Return non-nil if must step at start and end of TAG."
116 (or (eq senator-step-at-start-end-tag-classes t
)
117 (memq (semantic-tag-class tag
)
118 senator-step-at-start-end-tag-classes
))))
120 (defun senator-skip-p (tag)
121 "Return non-nil if must skip TAG."
123 senator-step-at-tag-classes
124 (not (memq (semantic-tag-class tag
)
125 senator-step-at-tag-classes
))))
127 (defun senator-middle-of-tag-p (pos tag
)
128 "Return non-nil if POS is between start and end of TAG."
129 (and (> pos
(semantic-tag-start tag
))
130 (< pos
(semantic-tag-end tag
))))
132 (defun senator-step-at-parent (tag)
133 "Return TAG's outermost parent if must step at start/end of it.
134 Return nil otherwise."
136 (let (parent parents
)
137 (setq parents
(semantic-find-tag-by-overlay
138 (semantic-tag-start tag
)))
139 (while (and parents
(not parent
))
140 (setq parent
(car parents
)
141 parents
(cdr parents
))
142 (if (or (eq tag parent
)
143 (senator-skip-p parent
)
144 (not (senator-step-at-start-end-p parent
)))
148 (defun senator-previous-tag-or-parent (pos)
149 "Return the tag before POS or one of its parent where to step."
151 (while (and pos
(> pos
(point-min)) (not tag
))
152 (setq pos
(semantic-overlay-previous-change pos
))
154 ;; Get overlays at position
155 (setq ol
(semantic-overlays-at pos
))
156 ;; find the overlay that belongs to semantic
157 ;; and STARTS or ENDS at the found position.
158 (while (and ol
(not tag
))
159 (setq tag
(semantic-overlay-get (car ol
) 'semantic
))
160 (unless (and tag
(semantic-tag-p tag
)
161 (or (= (semantic-tag-start tag
) pos
)
162 (= (semantic-tag-end tag
) pos
)))
165 (or (senator-step-at-parent tag
) tag
)))
169 (defun senator-search-tag-name (tag)
170 "Search for TAG name in current buffer.
171 Limit the search to TAG bounds.
172 If found, set point to the end of the name, and return point. The
173 beginning of the name is at (match-beginning 0).
174 Return nil if not found, that is if TAG name doesn't come from the
176 (let ((name (semantic-tag-name tag
)))
177 (setq name
(if (string-match "\\`\\([^[]+\\)[[]" name
)
178 (match-string 1 name
)
180 (goto-char (semantic-tag-start tag
))
181 (when (re-search-forward (concat
182 ;; The tag name is expected to be
183 ;; between word delimiters, whitespaces,
185 "\\(\\<\\|\\s-+\\|\\s.\\)"
187 "\\(\\>\\|\\s-+\\|\\s.\\)")
188 (semantic-tag-end tag
)
190 (goto-char (match-beginning 0))
191 (search-forward name
))))
193 (defcustom senator-search-ignore-tag-classes
195 "List of ignored tag classes.
196 Tags of those classes are excluded from search."
198 :type
'(repeat (symbol :tag
"class")))
200 (defun senator-search-default-tag-filter (tag)
201 "Default function that filters searched tags.
202 Ignore tags of classes in `senator-search-ignore-tag-classes'"
203 (not (memq (semantic-tag-class tag
)
204 senator-search-ignore-tag-classes
)))
206 (defvar senator-search-tag-filter-functions
207 '(senator-search-default-tag-filter)
208 "List of functions to be called to filter searched tags.
209 Each function is passed a tag. If one of them returns nil, the tag is
210 excluded from the search.")
212 (defun senator-search (searcher text
&optional bound noerror count
)
213 "Use the SEARCHER function to search from point for TEXT in a tag name.
214 SEARCHER is typically the function `search-forward', `search-backward',
215 `word-search-forward', `word-search-backward', `re-search-forward', or
216 `re-search-backward'. See one of the above function to see how the
217 TEXT, BOUND, NOERROR, and COUNT arguments are interpreted."
218 (let* ((origin (point))
220 (step (cond ((> count
0) 1)
221 ((< count
0) (setq count
(- count
)) -
1)
223 found next sstart send tag tstart tend
)
225 (while (and (not found
)
226 (setq next
(funcall searcher text bound t step
)))
227 (setq sstart
(match-beginning 0)
231 (and (setq tag
(semantic-current-tag))
232 (run-hook-with-args-until-failure
233 'senator-search-tag-filter-functions tag
)
234 (setq tend
(senator-search-tag-name tag
))
235 (setq tstart
(match-beginning 0)
236 found
(and (>= sstart tstart
)
238 (zerop (setq count
(1- count
))))))
249 ;; Setup the returned value and the `match-data' or maybe fail!
250 (funcall searcher text send noerror step
)))
252 ;;; Navigation commands
255 (defun senator-next-tag ()
256 "Navigate to the next Semantic tag.
257 Return the tag or nil if at end of buffer."
260 (tag (semantic-current-tag))
263 (not (senator-skip-p tag
))
264 (senator-step-at-start-end-p tag
)
265 (or (= pos
(semantic-tag-start tag
))
266 (senator-middle-of-tag-p pos tag
)))
268 (if (setq tag
(senator-step-at-parent tag
))
270 (setq tag
(semantic-find-tag-by-overlay-next pos
))
271 (while (and tag
(senator-skip-p tag
))
272 (setq tag
(semantic-find-tag-by-overlay-next
273 (semantic-tag-start tag
))))))
276 (goto-char (point-max))
277 (message "End of buffer"))
278 (cond ((and (senator-step-at-start-end-p tag
)
279 (or (= pos
(semantic-tag-start tag
))
280 (senator-middle-of-tag-p pos tag
)))
282 (goto-char (semantic-tag-end tag
)))
285 (goto-char (semantic-tag-start tag
))))
286 (senator-momentary-highlight-tag tag
)
287 (message "%S: %s (%s)"
288 (semantic-tag-class tag
)
289 (semantic-tag-name tag
)
294 (defun senator-previous-tag ()
295 "Navigate to the previous Semantic tag.
296 Return the tag or nil if at beginning of buffer."
299 (tag (semantic-current-tag))
302 (not (senator-skip-p tag
))
303 (senator-step-at-start-end-p tag
)
304 (or (= pos
(semantic-tag-end tag
))
305 (senator-middle-of-tag-p pos tag
)))
307 (if (setq tag
(senator-step-at-parent tag
))
309 (setq tag
(senator-previous-tag-or-parent pos
))
310 (while (and tag
(senator-skip-p tag
))
311 (setq tag
(senator-previous-tag-or-parent
312 (semantic-tag-start tag
))))))
315 (goto-char (point-min))
316 (message "Beginning of buffer"))
317 (cond ((or (not (senator-step-at-start-end-p tag
))
318 (= pos
(semantic-tag-end tag
))
319 (senator-middle-of-tag-p pos tag
))
321 (goto-char (semantic-tag-start tag
)))
324 (goto-char (semantic-tag-end tag
))))
325 (senator-momentary-highlight-tag tag
)
326 (message "%S: %s (%s)"
327 (semantic-tag-class tag
)
328 (semantic-tag-name tag
)
334 (defun senator-search-forward (string &optional bound noerror count
)
335 "Search in tag names forward from point for STRING.
336 Set point to the end of the occurrence found, and return point.
337 See also the function `search-forward' for details on the BOUND,
338 NOERROR and COUNT arguments."
339 (interactive "sSemantic search: ")
340 (senator-search 'search-forward string bound noerror count
))
342 (defun senator-re-search-forward (regexp &optional bound noerror count
)
343 "Search in tag names forward from point for regular expression REGEXP.
344 Set point to the end of the occurrence found, and return point.
345 See also the function `re-search-forward' for details on the BOUND,
346 NOERROR and COUNT arguments."
347 (interactive "sSemantic regexp search: ")
348 (senator-search 're-search-forward regexp bound noerror count
))
350 (defun senator-word-search-forward (word &optional bound noerror count
)
351 "Search in tag names forward from point for WORD.
352 Set point to the end of the occurrence found, and return point.
353 See also the function `word-search-forward' for details on the BOUND,
354 NOERROR and COUNT arguments."
355 (interactive "sSemantic word search: ")
356 (senator-search 'word-search-forward word bound noerror count
))
358 (defun senator-search-backward (string &optional bound noerror count
)
359 "Search in tag names backward from point for STRING.
360 Set point to the beginning of the occurrence found, and return point.
361 See also the function `search-backward' for details on the BOUND,
362 NOERROR and COUNT arguments."
363 (interactive "sSemantic backward search: ")
364 (senator-search 'search-backward string bound noerror count
))
366 (defun senator-re-search-backward (regexp &optional bound noerror count
)
367 "Search in tag names backward from point for regular expression REGEXP.
368 Set point to the beginning of the occurrence found, and return point.
369 See also the function `re-search-backward' for details on the BOUND,
370 NOERROR and COUNT arguments."
371 (interactive "sSemantic backward regexp search: ")
372 (senator-search 're-search-backward regexp bound noerror count
))
374 (defun senator-word-search-backward (word &optional bound noerror count
)
375 "Search in tag names backward from point for WORD.
376 Set point to the beginning of the occurrence found, and return point.
377 See also the function `word-search-backward' for details on the BOUND,
378 NOERROR and COUNT arguments."
379 (interactive "sSemantic backward word search: ")
380 (senator-search 'word-search-backward word bound noerror count
))
382 ;;; Other useful search commands (minor mode menu)
384 (defvar senator-last-search-type nil
385 "Type of last non-incremental search command called.")
387 (defun senator-nonincremental-repeat-search-forward ()
388 "Search forward for the previous search string or regexp."
391 ((and (eq senator-last-search-type
'string
)
393 (senator-search-forward (car search-ring
)))
394 ((and (eq senator-last-search-type
'regexp
)
396 (senator-re-search-forward (car regexp-search-ring
)))
398 (error "No previous search"))))
400 (defun senator-nonincremental-repeat-search-backward ()
401 "Search backward for the previous search string or regexp."
404 ((and (eq senator-last-search-type
'string
)
406 (senator-search-backward (car search-ring
)))
407 ((and (eq senator-last-search-type
'regexp
)
409 (senator-re-search-backward (car regexp-search-ring
)))
411 (error "No previous search"))))
413 (defun senator-nonincremental-search-forward (string)
414 "Search for STRING nonincrementally."
415 (interactive "sSemantic search for string: ")
416 (setq senator-last-search-type
'string
)
417 (if (equal string
"")
418 (senator-search-forward (car search-ring
))
419 (isearch-update-ring string nil
)
420 (senator-search-forward string
)))
422 (defun senator-nonincremental-search-backward (string)
423 "Search backward for STRING nonincrementally."
424 (interactive "sSemantic search for string: ")
425 (setq senator-last-search-type
'string
)
426 (if (equal string
"")
427 (senator-search-backward (car search-ring
))
428 (isearch-update-ring string nil
)
429 (senator-search-backward string
)))
431 (defun senator-nonincremental-re-search-forward (string)
432 "Search for the regular expression STRING nonincrementally."
433 (interactive "sSemantic search for regexp: ")
434 (setq senator-last-search-type
'regexp
)
435 (if (equal string
"")
436 (senator-re-search-forward (car regexp-search-ring
))
437 (isearch-update-ring string t
)
438 (senator-re-search-forward string
)))
440 (defun senator-nonincremental-re-search-backward (string)
441 "Search backward for the regular expression STRING nonincrementally."
442 (interactive "sSemantic search for regexp: ")
443 (setq senator-last-search-type
'regexp
)
444 (if (equal string
"")
445 (senator-re-search-backward (car regexp-search-ring
))
446 (isearch-update-ring string t
)
447 (senator-re-search-backward string
)))
449 (defvar senator--search-filter nil
)
451 (defun senator-search-set-tag-class-filter (&optional classes
)
452 "In current buffer, limit search scope to tag CLASSES.
453 CLASSES is a list of tag class symbols or nil. If nil only global
454 filters in `senator-search-tag-filter-functions' remain active."
455 (interactive "sClasses: ")
463 (mapcar 'read
(split-string classes
)))
465 (signal 'wrong-type-argument
(list classes
)))
467 ;; Clear previous filter.
468 (remove-hook 'senator-search-tag-filter-functions
469 senator--search-filter t
)
470 (kill-local-variable 'senator--search-filter
)
472 (let ((tag (make-symbol "tag"))
473 (names (mapconcat 'symbol-name classes
"', `")))
474 (set (make-local-variable 'senator--search-filter
)
476 (memq (semantic-tag-class ,tag
) ',classes
)))
477 (add-hook 'senator-search-tag-filter-functions
478 senator--search-filter nil t
)
479 (message "Limit search to `%s' tags" names
))
480 (message "Default search filter restored")))
484 ;; Use new folding state. It might be wise to extend the idea
485 ;; of folding for hiding all but this, or show all children, etc.
487 (defun senator-fold-tag (&optional tag
)
488 "Fold the current TAG."
490 (semantic-set-tag-folded (or tag
(semantic-current-tag)) t
))
492 (defun senator-unfold-tag (&optional tag
)
493 "Fold the current TAG."
495 (semantic-set-tag-folded (or tag
(semantic-current-tag)) nil
))
497 (defun senator-fold-tag-toggle (&optional tag
)
498 "Fold the current TAG."
500 (let ((tag (or tag
(semantic-current-tag))))
501 (if (semantic-tag-folded-p tag
)
502 (senator-unfold-tag tag
)
503 (senator-fold-tag tag
))))
505 ;; @TODO - move this to some analyzer / refs tool
506 (define-overloadable-function semantic-up-reference
(tag)
507 "Return a tag that is referred to by TAG.
508 A \"reference\" could be any interesting feature of TAG.
509 In C++, a function may have a 'parent' which is non-local.
510 If that parent which is only a reference in the function tag
511 is found, we can jump to it.
512 Some tags such as includes have other reference features.")
515 (defun senator-go-to-up-reference (&optional tag
)
516 "Move up one reference from the current TAG.
517 A \"reference\" could be any interesting feature of TAG.
518 In C++, a function may have a 'parent' which is non-local.
519 If that parent which is only a reference in the function tag
520 is found, we can jump to it.
521 Some tags such as includes have other reference features."
523 (let ((result (semantic-up-reference (or tag
(semantic-current-tag)))))
525 (error "No up reference found")
529 ((semantic-tag-p result
)
530 (semantic-go-to-tag result
)
531 (switch-to-buffer (current-buffer))
532 (semantic-momentary-highlight-tag result
))
535 (switch-to-buffer result
)
536 (pulse-momentary-highlight-one-line (point)))
538 ((and (stringp result
) (file-exists-p result
))
540 (pulse-momentary-highlight-one-line (point)))
542 (error "Unknown result type from `semantic-up-reference'"))))))
544 (defun semantic-up-reference-default (tag)
545 "Return a tag that is referred to by TAG.
546 Makes C/C++ language like assumptions."
547 (cond ((semantic-tag-faux-p tag
)
548 ;; Faux tags should have a real tag in some other location.
549 (require 'semantic
/sort
)
550 (let ((options (semantic-tag-external-class tag
)))
551 ;; I should do something a little better than
556 ;; Include always point to another file.
557 ((eq (semantic-tag-class tag
) 'include
)
558 (let ((file (semantic-dependency-tag-file tag
)))
560 ((or (not file
) (not (file-exists-p file
)))
561 (error "Could not location include %s"
562 (semantic-tag-name tag
)))
563 ((get-file-buffer file
)
564 (get-file-buffer file
))
569 ;; Is there a parent of the function to jump to?
570 ((and (semantic-tag-of-class-p tag
'function
)
571 (semantic-tag-function-parent tag
))
572 (let* ((scope (semantic-calculate-scope (point))))
573 ;; @todo - it would be cool to ask the user which one if
575 (car (oref scope parents
))
578 ;; Is there a non-prototype version of the tag to jump to?
579 ((semantic-tag-get-attribute tag
:prototype-flag
)
580 (require 'semantic
/analyze
/refs
)
581 (let* ((sar (semantic-analyze-tag-references tag
)))
582 (car (semantic-analyze-refs-impl sar t
)))
585 ;; If this is a datatype, and we have superclasses
586 ((and (semantic-tag-of-class-p tag
'type
)
587 (semantic-tag-type-superclasses tag
))
588 (require 'semantic
/analyze
)
589 (let ((scope (semantic-calculate-scope (point)))
590 (parents (semantic-tag-type-superclasses tag
)))
591 (semantic-analyze-find-tag (car parents
) 'type scope
)))
593 ;; Get the data type, and try to find that.
594 ((semantic-tag-type tag
)
595 (require 'semantic
/analyze
)
596 (let ((scope (semantic-calculate-scope (point))))
597 (semantic-analyze-tag-type tag scope
))
601 (defvar senator-isearch-semantic-mode nil
602 "Non-nil if isearch does semantic search.
603 This is a buffer local variable.")
604 (make-variable-buffer-local 'senator-isearch-semantic-mode
)
606 (defun senator-beginning-of-defun (&optional arg
)
607 "Move backward to the beginning of a defun.
608 Use semantic tags to navigate.
609 ARG is the number of tags to navigate (not yet implemented)."
610 (semantic-fetch-tags)
611 (let* ((senator-highlight-found nil
)
612 ;; Step at beginning of next tag with class specified in
613 ;; `senator-step-at-tag-classes'.
614 (senator-step-at-start-end-tag-classes t
)
615 (tag (senator-previous-tag)))
617 (if (= (point) (semantic-tag-end tag
))
618 (goto-char (semantic-tag-start tag
)))
619 (beginning-of-line))))
621 (defun senator-end-of-defun (&optional arg
)
622 "Move forward to next end of defun.
623 Use semantic tags to navigate.
624 ARG is the number of tags to navigate (not yet implemented)."
625 (semantic-fetch-tags)
626 (let* ((senator-highlight-found nil
)
627 ;; Step at end of next tag with class specified in
628 ;; `senator-step-at-tag-classes'.
629 (senator-step-at-start-end-tag-classes t
)
630 (tag (senator-next-tag)))
632 (if (= (point) (semantic-tag-start tag
))
633 (goto-char (semantic-tag-end tag
)))
634 (skip-chars-forward " \t")
635 (if (looking-at "\\s<\\|\n")
638 (defun senator-narrow-to-defun ()
639 "Make text outside current defun invisible.
640 The defun visible is the one that contains point or follows point.
641 Use semantic tags to navigate."
643 (semantic-fetch-tags)
646 (senator-end-of-defun)
648 (senator-beginning-of-defun)
649 (narrow-to-region (point) end
))))
651 (defun senator-mark-defun ()
652 "Put mark at end of this defun, point at beginning.
653 The defun marked is the one that contains point or follows point.
654 Use semantic tags to navigate."
656 (let ((origin (point))
657 (end (progn (senator-end-of-defun) (point)))
658 (start (progn (senator-beginning-of-defun) (point))))
661 (goto-char end
) ;; end-of-defun
662 (push-mark (point) nil t
)
663 (goto-char start
) ;; beginning-of-defun
664 (re-search-backward "^\n" (- (point) 1) t
)))
668 ;; To copy a tag, means to put a tag definition into the tag
669 ;; ring. To kill a tag, put the tag into the tag ring AND put
670 ;; the body of the tag into the kill-ring.
672 ;; To retrieve a killed tag's text, use C-y (yank), but to retrieve
673 ;; the tag as a reference of some sort, use senator-yank-tag.
675 (defvar senator-tag-ring
(make-ring 20)
676 "Ring of tags for use with cut and paste.")
679 (defun senator-copy-tag ()
680 "Take the current tag, and place it in the tag ring."
682 (semantic-fetch-tags)
683 (let ((ft (semantic-obtain-foreign-tag)))
685 (ring-insert senator-tag-ring ft
)
686 (kill-ring-save (semantic-tag-start ft
) (semantic-tag-end ft
))
687 (when (called-interactively-p 'interactive
)
688 (message "Use C-y to yank text. \
689 Use `senator-yank-tag' for prototype insert.")))
693 (defun senator-kill-tag ()
694 "Take the current tag, place it in the tag ring, and kill it.
695 Killing the tag removes the text for that tag, and places it into
696 the kill ring. Retrieve that text with \\[yank]."
698 (let ((ct (senator-copy-tag))) ;; this handles the reparse for us.
699 (kill-region (semantic-tag-start ct
)
700 (semantic-tag-end ct
))
701 (when (called-interactively-p 'interactive
)
702 (message "Use C-y to yank text. \
703 Use `senator-yank-tag' for prototype insert."))))
706 (defun senator-yank-tag ()
707 "Yank a tag from the tag ring.
708 The form the tag takes is different depending on where it is being
711 (or (ring-empty-p senator-tag-ring
)
712 (let ((ft (ring-ref senator-tag-ring
0)))
713 (semantic-foreign-tag-check ft
)
714 (semantic-insert-foreign-tag ft
)
715 (when (called-interactively-p 'interactive
)
716 (message "Use C-y to recover the yank the text of %s."
717 (semantic-tag-name ft
))))))
720 (defun senator-copy-tag-to-register (register &optional kill-flag
)
721 "Copy the current tag into REGISTER.
722 Optional argument KILL-FLAG will delete the text of the tag to the
724 (interactive "cTag to register: \nP")
725 (semantic-fetch-tags)
726 (let ((ft (semantic-obtain-foreign-tag)))
728 (set-register register ft
)
730 (kill-region (semantic-tag-start ft
)
731 (semantic-tag-end ft
))))))
734 (defun senator-transpose-tags-up ()
735 "Transpose the current tag, and the preceding tag."
737 (semantic-fetch-tags)
738 (let* ((current-tag (semantic-current-tag))
739 (prev-tag (save-excursion
740 (goto-char (semantic-tag-start current-tag
))
741 (semantic-find-tag-by-overlay-prev)))
742 (ct-parent (semantic-find-tag-parent-by-overlay current-tag
))
743 (pt-parent (semantic-find-tag-parent-by-overlay prev-tag
)))
744 (if (not (eq ct-parent pt-parent
))
745 (error "Cannot transpose tags"))
746 (let ((txt (buffer-substring (semantic-tag-start current-tag
)
747 (semantic-tag-end current-tag
)))
748 (line (count-lines (semantic-tag-start current-tag
)
752 (delete-region (semantic-tag-start current-tag
)
753 (semantic-tag-end current-tag
))
755 (goto-char (semantic-tag-start prev-tag
))
756 (setq insert-point
(point))
758 (if (/= (current-column) 0)
761 (goto-char insert-point
)
766 (defun senator-transpose-tags-down ()
767 "Transpose the current tag, and the following tag."
769 (semantic-fetch-tags)
770 (let* ((current-tag (semantic-current-tag))
771 (next-tag (save-excursion
772 (goto-char (semantic-tag-end current-tag
))
773 (semantic-find-tag-by-overlay-next)))
774 (end-pt (point-marker))
776 (goto-char (semantic-tag-start next-tag
))
778 (senator-transpose-tags-up)
779 ;; I know that the above fcn deletes the next tag, so our pt marker
783 ;;; Using semantic search in isearch mode
785 (defun senator-lazy-highlight-update ()
786 "Force lazy highlight update."
787 (lazy-highlight-cleanup t
)
788 (set 'isearch-lazy-highlight-last-string nil
)
789 (setq isearch-adjusted t
)
792 ;; Recent versions of GNU Emacs allow to override the isearch search
793 ;; function for special needs, and avoid to advice the built-in search
795 (defun senator-isearch-search-fun ()
796 "Return the function to use for the search.
797 Use a senator search function when semantic isearch mode is enabled."
799 (concat (if senator-isearch-semantic-mode
802 (cond (isearch-word "word-")
803 (isearch-regexp "re-")
810 (defun senator-isearch-toggle-semantic-mode ()
811 "Toggle semantic searching on or off in isearch mode."
813 (setq senator-isearch-semantic-mode
814 (not senator-isearch-semantic-mode
))
816 ;; force lazy highlight update
817 (senator-lazy-highlight-update)
818 (message "Isearch semantic mode %s"
819 (if senator-isearch-semantic-mode
823 (defvar senator-old-isearch-search-fun nil
824 "Hold previous value of `isearch-search-fun-function'.")
826 (defun senator-isearch-mode-hook ()
827 "Isearch mode hook to setup semantic searching."
828 (if (and isearch-mode senator-isearch-semantic-mode
)
830 ;; When `senator-isearch-semantic-mode' is on save the
831 ;; previous `isearch-search-fun-function' and install the
833 (when (and (local-variable-p 'isearch-search-fun-function
)
834 (not (local-variable-p 'senator-old-isearch-search-fun
)))
835 (set (make-local-variable 'senator-old-isearch-search-fun
)
836 isearch-search-fun-function
))
837 (set (make-local-variable 'isearch-search-fun-function
)
838 'senator-isearch-search-fun
))
839 ;; When `senator-isearch-semantic-mode' is off restore the
840 ;; previous `isearch-search-fun-function'.
841 (when (eq isearch-search-fun-function
'senator-isearch-search-fun
)
842 (if (local-variable-p 'senator-old-isearch-search-fun
)
844 (set (make-local-variable 'isearch-search-fun-function
)
845 senator-old-isearch-search-fun
)
846 (kill-local-variable 'senator-old-isearch-search-fun
))
847 (kill-local-variable 'isearch-search-fun-function
)))))
849 ;; (add-hook 'isearch-mode-hook 'senator-isearch-mode-hook)
850 ;; (add-hook 'isearch-mode-end-hook 'senator-isearch-mode-hook)
852 ;; ;; Keyboard shortcut to toggle semantic search in isearch mode.
853 ;; (define-key isearch-mode-map
855 ;; 'senator-isearch-toggle-semantic-mode)
857 (provide 'semantic
/senator
)
860 ;; generated-autoload-file: "loaddefs.el"
861 ;; generated-autoload-load-name: "semantic/senator"
864 ;;; semantic/senator.el ends here