Sublime Forum

Why use CTags, while there is the built-in Sublime Text symbols?

#1

Why use CTags, while there is the built-in Sublime Text Symbols?

There is the package https://packagecontrol.io/packages/CTags, but there is also the http://docs.sublimetext.info/en/latest/reference/symbols.html.

So, we just use CTags when its has the languages support we need or we want to implement them on CTags instead of implementing the default Sublime Text Symbols navigation?

0 Likes

Trying to find plugin I used before
#2

I too would like to know what the point of CTags is, why people would use it over ST3’s built in symbol indexing - what advantages does it have? :wink:

The CTags website looks like something from the 90’s…

0 Likes

#3

By your description, that would be the Exuberant CTags website http://ctags.sourceforge.net/, which is not much supported, but nowadays there is the Universal CTags https://ctags.io/, which is supposed to be the Exuberant CTags's development continuation.

I think they use CTags because they come from another editors where they are used to CTags, them they would just to keep using they existing implementation/language support. But between them, could be those who does not know the Sublime Text Symbols and are using CTags because they just find out it before they find out about the Sublime Text built-in support for symbols.

0 Likes

#4

yes, that is the one linked to in the package’s readme

0 Likes

#5

This plugin was developed back on ST2 days, when you didn’t had Go To Symbol/Definition in project functionality.

See the announcement here, indexing was one of the major addition to ST3:

http://www.sublimetext.com/blog/articles/sublime-text-3-beta

3 Likes

#7

For me, because of laziness. I do not even want to read http://docs.sublimetext.info/en/latest/reference/symbols.html and write .tmPreferences files for myself since CTags is working.

The following things are what I ran into quite a long time ago and I re-tested them today after I saw this post.


Let’s say I create a ST project which has the following directory structure.

symbol_test/
├ app.php
â”” define.php

In define.php,

<?php
define('MY_CONSTANT', 'HELLO');

In app.php,

<?php
include 'define.php';
echo MY_CONSTANT; // this prints: HELLO

Okay, that’s our environment. Now, let’s work on our project.

  1. close all tabs
  2. open app.php
  3. Oh, what’s the value/definition of MY_CONSTANT?
    • Press F12 and nothing happens.
    • Press Ctrl+R and find nothing.
    • Press Ctrl+Shift+R and find nothing.
    • Try CTags, after tags are built, Ctrl+T, Ctrl+T and voila!

Let’s say I do not know there is a plugin named CTags. After reading the ST document, I write a simple .tmPreferences for PHP as below.

In Symbol List - Constants.tmPreferences,

<?xml version="1.0" encoding="UTF-8"?>
<plist version="1.0">
<dict>
	<key>name</key>
	<string>Symbols List: Constants</string>
	<key>scope</key>
	<string>constant.other.php, meta.string-contents.quoted.single.php</string>
	<key>settings</key>
	<dict>
		<key>showInSymbolList</key>
		<integer>1</integer>
		<key>showInIndexedSymbolList</key>
		<string>1</string>
	</dict>
</dict>
</plist>

Okay, now F12 works for me, cheers!

But

  • Should I maintain this .tmPreference for myself?
  • There is no special scope for MY_CONSTANT in define('MY_CONSTANT', 'HELLO');, using meta.string-contents.quoted.single.php as the capture scope would inject quite lots of crap into your symbol list. Maybe I should report this to ST official?

I am not saying ST cannot do what CTags can do. But how much effort people want to put with a comparison to just install CTags? You just cannot expect everyone dig into the issue like this.

I think most of users do not know what happened. They just try F12 and let it go. Where is the doc? What should I do to fix this? How many cases are just like this and I have to write my own .tmPreference? I do not care. Maybe just install CTags.

Actually, CTags is not omnipotent. I use both CTags and F12.

4 Likes

#8

You may fix if yourself on https://github.com/sublimehq/Packages#pull-requests
When I saw your scope for MY_CONSTANT on define('MY_CONSTANT', 'HELLO'); I got:

embedding.php text.html.basic meta.embedded.block.php source.php meta.function-call.php meta.group.php string.quoted.single.php meta.string-contents.quoted.single.php 

For clearness on the symbol list, and as the define is the as very specific function call for variable declaration, you may edit the PHP Source.sublime-syntax to include on the first argument a scope as meta.variable.definition.php. So, now you may change your symbol list to:

<string>constant.other.php, meta.variable.definition.php</string>

And got precise results. I am not programming on PHP now, but when I start, this will be one of the first things to do on the Sublime Text, if it is not already done until there.

0 Likes

#9

Everything is right, but a user will not do like this.

For clearness on the symbol list, and as the define is the as very specific function call for variable declaration, you may edit the PHP Source.sublime-syntax to include on the first argument a scope as meta.variable.definition.php. So, now you may change your symbol list to:

Nope, this implies you ask a user to maintain his/her own syntax def.

Eventually, all goes the ST official in this case.

0 Likes

#10

I was thinking about a good heart user, which will go to https://github.com/sublimehq/Packages#pull-requests and open pull request. For now I (as anyone else could) opened a issue on: https://github.com/sublimehq/Packages/issues/625

I just said it because you said:

I should rephrase that to:

I was thinking about a good heart user, which will go to https://github.com/sublimehq/Packages#pull-requests and open pull request, instead of keep this improvement just for himself. For now I (as anyone else could) opened a issue, so even users who does not know how to/cannot to do it, may contribute with ST point out what is wrong/missing for others able/willing to fix it. While that, of course, the user may use CTags for task as sublime text stills lacking better coverage.

1 Like

#11

No mean to dispute anything here and you are not the only one who wants to help ST. That’s all.
I am answering Why use CTags, while there is the built-in Sublime Text Symbols?.

0 Likes

#12

Sincerely, ST should make some important posts pinned.

  • Doc
  • Github repo
  • Frequently asked questions
  • etc…

Sorry, it looks like off-topic for this post now.

0 Likes

#13

I didn’t even know about this. I use ctags with a git hook to update.

If I don’t need this I will remove it, but honestly if I need to invest more than 15 minutes of time into sublime text symbols to replace a currently working solution I need a solid argument.

1 Like

#14

I cannot arg against ctags, because I never used it. But I can tell how is to work with the Built-in system.

It is like this, you use your syntax file for your language, and write a .tmPreference file like these (if it is not done yet). After that, sublime text will index all symbols, and you may navigate/browse by them like these two links shows you:

  1. https://github.com/SublimeTextIssues/Core/issues/1400
  2. https://github.com/SublimeTextIssues/Core/issues/1397

Basically, this is what the Built-in System symbols may do. Also, there is this: Underline all clickable text elements when pressed ctrl, there you may see the sublime-mousemap to allow you go to symbols by ctrl+mouse_click over their names.

Now I would like to ask, it could be equivalent/inferior/superior with ctags?

1 Like

#15

It seems to do what I am using ctags for, so I just removed the package and the git hook.

I just didn’t know about this yet. :grin:

1 Like

#16

I only miss the autocomplete across global symbols list :pensive:

0 Likes

#17

I can’t tell what exactly CTags does since I never used it, but I have the impression that it is also capable of providing context-aware completions, which ST’s completion system will likely never support natively due to having to do actual code analysis. That space is intentionally left for plugins to handle.

2 Likes

#18

Hi experts, can you help to know how to use F12 for local variables in C/C++? What I tried so far, I could navigate to global variables via F12. But local variables could not.
[Edit]
btw, I do not see any .tmPreferences files in my “~/.config/sublime-text-3” folder for Ubuntu installation. Do I need them? I see F12 works anyways for me.
Thanks a lot.

0 Likes