comparison src/tag.c @ 649:8157079cea85

updated for version 7.0191
author vimboss
date Wed, 01 Feb 2006 21:47:16 +0000
parents 111509d2767a
children f1b013312711
comparison
equal deleted inserted replaced
648:9032e4668296 649:8157079cea85
120 * type == DT_FIRST: jump to first match of same tag 120 * type == DT_FIRST: jump to first match of same tag
121 * type == DT_LAST: jump to last match of same tag 121 * type == DT_LAST: jump to last match of same tag
122 * type == DT_SELECT: ":tselect [tag]", select tag from a list of all matches 122 * type == DT_SELECT: ":tselect [tag]", select tag from a list of all matches
123 * type == DT_JUMP: ":tjump [tag]", jump to tag or select tag from a list 123 * type == DT_JUMP: ":tjump [tag]", jump to tag or select tag from a list
124 * type == DT_CSCOPE: use cscope to find the tag 124 * type == DT_CSCOPE: use cscope to find the tag
125 * type == DT_LTAG: use location list for displaying tag matches
125 * type == DT_FREE: free cached matches 126 * type == DT_FREE: free cached matches
126 * 127 *
127 * for cscope, returns TRUE if we jumped to tag or aborted, FALSE otherwise 128 * for cscope, returns TRUE if we jumped to tag or aborted, FALSE otherwise
128 */ 129 */
129 int 130 int
213 #endif 214 #endif
214 use_tagstack = TRUE; 215 use_tagstack = TRUE;
215 216
216 /* new pattern, add to the tag stack */ 217 /* new pattern, add to the tag stack */
217 if (*tag && (type == DT_TAG || type == DT_SELECT || type == DT_JUMP 218 if (*tag && (type == DT_TAG || type == DT_SELECT || type == DT_JUMP
219 #ifdef FEAT_QUICKFIX
220 || type == DT_LTAG
221 #endif
218 #ifdef FEAT_CSCOPE 222 #ifdef FEAT_CSCOPE
219 || type == DT_CSCOPE 223 || type == DT_CSCOPE
220 #endif 224 #endif
221 )) 225 ))
222 { 226 {
407 cur_fnum = tagstack[tagstackidx].cur_fnum; 411 cur_fnum = tagstack[tagstackidx].cur_fnum;
408 } 412 }
409 switch (type) 413 switch (type)
410 { 414 {
411 case DT_FIRST: cur_match = count - 1; break; 415 case DT_FIRST: cur_match = count - 1; break;
416 #ifdef FEAT_QUICKFIX
417 case DT_LTAG: cur_match = 0; break;
418 #endif
412 case DT_SELECT: 419 case DT_SELECT:
413 case DT_JUMP: 420 case DT_JUMP:
414 #ifdef FEAT_CSCOPE 421 #ifdef FEAT_CSCOPE
415 case DT_CSCOPE: 422 case DT_CSCOPE:
416 #endif 423 #endif
746 break; 753 break;
747 } 754 }
748 } 755 }
749 ask_for_selection = TRUE; 756 ask_for_selection = TRUE;
750 } 757 }
758 #if defined(FEAT_QUICKFIX) && defined(FEAT_EVAL)
759 else
760 if (type == DT_LTAG)
761 {
762 list_T *list;
763 char_u tag_name[128 + 1];
764 char_u fname[MAXPATHL + 1];
765 char_u cmd[CMDBUFFSIZE + 1];
766
767 /*
768 * Add the matching tags to the location list for the current
769 * window.
770 */
771
772 list = list_alloc();
773 if (list == NULL)
774 goto end_do_tag;
775
776 for (i = 0; i < num_matches; ++i)
777 {
778 int len, cmd_len;
779 long lnum;
780 dict_T *dict;
781
782 parse_match(matches[i], &tagp);
783
784 /* Save the tag name */
785 len = tagp.tagname_end - tagp.tagname;
786 if (len > 128)
787 len = 128;
788 vim_strncpy(tag_name, tagp.tagname, len);
789 tag_name[len] = NUL;
790
791 /* Save the tag file name */
792 p = tag_full_fname(&tagp);
793 if (p == NULL)
794 continue;
795 STRCPY(fname, p);
796 vim_free(p);
797
798 /*
799 * Get the line number or the search pattern used to locate
800 * the tag.
801 */
802 lnum = 0;
803 if (isdigit(*tagp.command))
804 /* Line number is used to locate the tag */
805 lnum = atol((char *)tagp.command);
806 else
807 {
808 char_u *cmd_start, *cmd_end;
809
810 /* Search pattern is used to locate the tag */
811
812 /* Locate the end of the command */
813 cmd_start = tagp.command;
814 cmd_end = tagp.command_end;
815 if (cmd_end == NULL)
816 {
817 for (p = tagp.command;
818 *p && *p != '\r' && *p != '\n'; ++p)
819 ;
820 cmd_end = p;
821 }
822 /*
823 * Now, cmd_end points to the character after the
824 * command. Adjust it to point to the last
825 * character of the command.
826 */
827 cmd_end--;
828
829 /*
830 * Skip the '/' and '?' characters at the
831 * beginning and end of the search pattern.
832 */
833 if (*cmd_start == '/' || *cmd_start == '?')
834 cmd_start++;
835
836 if (*cmd_end == '/' || *cmd_end == '?')
837 cmd_end--;
838
839 len = 0;
840 cmd[0] = NUL;
841
842 /*
843 * If "^" is present in the tag search pattern, then
844 * copy it first.
845 */
846 if (*cmd_start == '^')
847 {
848 STRCPY(cmd, "^");
849 cmd_start++;
850 len++;
851 }
852
853 /*
854 * Precede the tag pattern with \V to make it very
855 * nomagic.
856 */
857 STRCAT(cmd, "\\V");
858 len += 2;
859
860 cmd_len = cmd_end - cmd_start + 1;
861 if (cmd_len > (CMDBUFFSIZE - 5))
862 cmd_len = CMDBUFFSIZE - 5;
863 STRNCAT(cmd, cmd_start, cmd_len);
864 len += cmd_len;
865
866 if (cmd[len - 1] == '$')
867 {
868 /*
869 * Replace '$' at the end of the search pattern
870 * with '\$'
871 */
872 cmd[len - 1] = '\\';
873 cmd[len] = '$';
874 len++;
875 }
876
877 cmd[len] = NUL;
878 }
879
880 if ((dict = dict_alloc()) == NULL)
881 continue;
882 if (list_append_dict(list, dict) == FAIL)
883 {
884 vim_free(dict);
885 continue;
886 }
887
888 dict_add_nr_str(dict, "text", 0L, tag_name);
889 dict_add_nr_str(dict, "filename", 0L, fname);
890 dict_add_nr_str(dict, "lnum", lnum, NULL);
891 if (lnum == 0)
892 dict_add_nr_str(dict, "pattern", 0L, cmd);
893 }
894
895 set_errorlist(curwin, list, ' ');
896
897 list_free(list);
898 }
899 #endif
751 900
752 if (ask_for_selection == TRUE) 901 if (ask_for_selection == TRUE)
753 { 902 {
754 /* 903 /*
755 * Ask to select a tag from the list. 904 * Ask to select a tag from the list.