Skip to content

Commit 62af36c

Browse files
author
Micah Carrick
committed
Initial commit
0 parents  commit 62af36c

18 files changed

+630
-0
lines changed

README.markdown

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
Gedit Source Code Browser
2+
=========================
3+
4+
A source code class and function browser plugin for Gedit 3.
5+
6+
* Author: Micah Carrick
7+
* Version: 3.0.0
8+
* Date: 2011-05-06
9+
10+
This plugin will add a new tab to the side pane in the Gedit text editor which
11+
shows symbols (functions, classes, variables, etc.) for the active document.
12+
Clicking a symbol in the list wil jump to the line on which that symbol is
13+
defined.
14+
15+
See the [ctags supported languages](http://ctags.sourceforge.net/languages.html)
16+
for a list of the 41 programming languages supported by this plugin.
17+
18+
19+
Requirements
20+
------------
21+
22+
This plugins is for Gedit 3 and is **not compatible with Gedit 2.x**.
23+
24+
The Gedit Source Code Browser plugin uses
25+
[Exuberant Ctags](http://ctags.sourceforge.net/) to parse symbols
26+
out of source code. Exuberant Ctags is avaialable in the software repository for
27+
many distributions. To make sure you have ctags correctly installed, issue
28+
the following command:
29+
30+
ctags --version
31+
32+
Make sure that you see *Exuberant* Ctags in the version output.
33+
34+
35+
Installation
36+
------------
37+
38+
1. Download this repository by clicking the Downloads button at the top of the
39+
github page or issue the following command in a terminal:
40+
41+
git clone git://github.com/Quixotix/gedit-source-code-browser.git
42+
43+
2. Copy the file `sourcecodebrowser.plugin` and the folder `sourcecodebrowser` to
44+
`~/.local/share/gedit/plugins/`.
45+
46+
3. Restart Gedit.
47+
48+
4. Activate the plugin in Gedit by choosing 'Edit > Preferences', the selecting
49+
the 'Plugins' tab, and checking the box next to 'Soucre Code Browser'.
50+
51+
52+
Screenshots
53+
-----------
54+
55+
![Python code in Source Code Browser](http://www.micahcarrick.com/images/gedit-source-code-browser/python.png)
56+
57+
58+
Changes
59+
-------
60+
61+
62+
63+
Known Issues
64+
------------
65+
66+
* CSS is not supported. This issue is about ctags and not this plugin. You can
67+
[extend ctags](http://ctags.sourceforge.net/EXTENDING.html) to add support for
68+
any language you like. Many people have provided their fixes to on internet
69+
such as this [patch for CSS support](http://scie.nti.st/2006/12/22/how-to-add-css-support-to-ctags).
70+
71+
* PHP is supported, however, PHP5 classes are not well supported. This is again
72+
an issue with ctags. There are numerous fixes to be found onn the internet
73+
such as these
74+
[patches for better PHP5 support](http://www.jejik.com/articles/2008/11/patching_exuberant-ctags_for_better_php5_support_in_vim/).
75+
76+
* A configure dialog has not yet been implemented. Until the configuration dialog
77+
is added, a few settings are available for those who want to poke around in
78+
the code. The `__init__` method of the `SourceCodeBrowserPlugin` class contains
79+
a few properties that can be changed.
80+
81+
82+
BSD License
83+
-----------
84+
85+
Copyright (c) 2011, Micah Carrick
86+
All rights reserved.
87+
88+
Redistribution and use in source and binary forms, with or without modification,
89+
are permitted provided that the following conditions are met:
90+
91+
* Redistributions of source code must retain the above copyright notice, this
92+
list of conditions and the following disclaimer.
93+
94+
* Redistributions in binary form must reproduce the above copyright notice,
95+
this list of conditions and the following disclaimer in the documentation
96+
and/or other materials provided with the distribution.
97+
98+
* Neither the name of Quixotix Software, LLC nor the names of its
99+
contributors may be used to endorse or promote products derived from this
100+
software without specific prior written permission.
101+
102+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
103+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
104+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
105+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
106+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
107+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
108+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
109+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
110+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
111+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

sourcecodebrowser.plugin

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[Plugin]
2+
Loader=python
3+
Module=sourcecodebrowser
4+
IAge=3
5+
Name=Source Code Browser
6+
Description=A source code class and function browser for Gedit 3.
7+
Authors=Micah Carrick <[email protected]>
8+
Copyright=Copyright © 2011 Micah Carrick
9+
Website=https://github.com/Quixotix/gedit-source-code-browser
10+
Version=3.0.0

sourcecodebrowser/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import plugin
2+
from plugin import SourceCodeBrowserPlugin
3+

sourcecodebrowser/ctags.py

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
import os
2+
import subprocess
3+
import shlex
4+
5+
def get_ctags_version(executable=None):
6+
"""
7+
Return the text output from the --version option to ctags or None if ctags
8+
executable cannot be found. Use executable for custom ctags builds and/or
9+
path.
10+
"""
11+
args = shlex.split("ctags --version")
12+
try:
13+
p = subprocess.Popen(args, 0, shell=False, stdout=subprocess.PIPE, executable=executable)
14+
version = p.communicate()[0]
15+
except:
16+
version = None
17+
return version
18+
19+
class Tag(object):
20+
"""
21+
Represents a ctags "tag" found in some source code.
22+
"""
23+
def __init__(self, name):
24+
self.name = name
25+
self.file = None
26+
self.ex_command = None
27+
self.kind = None
28+
self.fields = {}
29+
30+
class Kind(object):
31+
"""
32+
Represents a ctags "kind" found in some source code such as "member" or
33+
"class".
34+
"""
35+
def __init__(self, name):
36+
self.name = name
37+
self.language = None
38+
39+
def group_name(self):
40+
"""
41+
Return the kind name as a group name. For example, 'variable' would
42+
be 'Variables'. Pluralization is complex but this method is not. It
43+
works more often than not.
44+
"""
45+
group = self.name
46+
47+
if self.name[-1] == 's':
48+
group += 'es'
49+
elif self.name[-1] == 'y':
50+
group = self.name[0:-1] + 'ies'
51+
else:
52+
group += 's'
53+
54+
return group.capitalize()
55+
56+
def icon_name(self):
57+
"""
58+
Return the icon name in the form of 'source-<kind>'.
59+
"""
60+
return 'source-' + self.name
61+
62+
class Parser(object):
63+
"""
64+
Ctags Parser
65+
66+
Parses the output of a ctags command into a list of tags and a dictionary
67+
of kinds.
68+
"""
69+
def has_kind(self, kind_name):
70+
"""
71+
Return true if kind_name is found in the list of kinds.
72+
"""
73+
if kind_name in self.kinds:
74+
return True
75+
else:
76+
return False
77+
78+
def __init__(self):
79+
self.tags = []
80+
self.kinds = {}
81+
self.tree = {}
82+
83+
def parse(self, command, executable=None):
84+
"""
85+
Parse ctags tags from the output of a ctags command. For example:
86+
ctags -n --fields=fiKmnsSzt -f - some_file.php
87+
"""
88+
args = shlex.split(command)
89+
p = subprocess.Popen(args, 0, shell=False, stdout=subprocess.PIPE, executable=executable)
90+
symbols = self._parse_text(p.communicate()[0])
91+
92+
def _parse_text(self, text):
93+
"""
94+
Parses ctags text which may have come from a TAG file or from raw output
95+
from a ctags command.
96+
"""
97+
for line in text.splitlines():
98+
name = None
99+
file = None
100+
ex_command = None
101+
kind = None
102+
for i, field in enumerate(line.split("\t")):
103+
if i == 0: tag = Tag(field)
104+
elif i == 1: tag.file = field
105+
elif i == 2: tag.ex_command = field
106+
elif i > 2:
107+
if ":" in field:
108+
key, value = field.split(":")
109+
tag.fields[key] = value
110+
if key == 'kind':
111+
kind = Kind(value)
112+
if not kind in self.kinds:
113+
self.kinds[value] = kind
114+
115+
if kind is not None:
116+
if 'language' in tag.fields:
117+
kind.language = tag.fields['language']
118+
tag.kind = kind
119+
120+
self.tags.append(tag)
121+
"""
122+
def get_tree(self):
123+
tree = {}
124+
for tag in self.tags:
125+
if 'class' in tag.fields:
126+
parent = tag.fields['class']
127+
if "." in parent:
128+
parents = parent.split(".")
129+
node = tree
130+
for p in parents:
131+
if not p in node:
132+
node[p] = {'tag':None, 'children':{}}
133+
node = node[p]
134+
print node
135+
node['tag'] = tag
136+
else:
137+
if not parent in self.tree:
138+
tree[parent] = {'tag':None, 'children':{}}
139+
tree[parent]['children'][tag.name] = {'tag':tag, 'children':{}}
140+
else:
141+
if tag.name in self.tree:
142+
tree[tag.name]['tag'] = tag
143+
else:
144+
tree[tag.name] = {'tag': tag, 'children':{}}
145+
return tree
146+
"""
147+
148+
830 Bytes
Loading
830 Bytes
Loading
424 Bytes
Loading
424 Bytes
Loading
604 Bytes
Loading
472 Bytes
Loading

0 commit comments

Comments
 (0)