Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
deathaxe committed Jan 6, 2024
2 parents 96e8615 + babb1a9 commit 4776c2f
Show file tree
Hide file tree
Showing 10 changed files with 176 additions and 166 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: CI
on: [push, pull_request]

jobs:
tests:

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: 3.8
- name: Install Universal CTags
run: sudo apt-get install universal-ctags
- name: Install PyTest
run: pip install pytest
- name: Run PyTest
run: pytest .

1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.8
12 changes: 0 additions & 12 deletions .travis.yml

This file was deleted.

16 changes: 0 additions & 16 deletions Default.sublime-commands
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,12 @@
{
"caption": "CTags: Show Symbols (file)",
"command": "show_symbols",
"context": [
{
"key": "selector",
"match_all": true,
"operand": "source -source.css",
"operator": "equal"
}
]
},
{
"caption": "CTags: Show Symbols (all)",
"command": "show_symbols",
"args": {
"type": "multi"
},
"context": [
{
"key": "selector",
"match_all": true,
"operand": "source -source.css",
"operator": "equal"
}
]
}
]
23 changes: 3 additions & 20 deletions Main.sublime-menu
Original file line number Diff line number Diff line change
Expand Up @@ -22,39 +22,22 @@
"command": "rebuild_tags"
},
{
"caption": "Show Symbols (file)",
"command": "show_symbols",
"context": [
{
"key": "selector",
"match_all": true,
"operand": "source -source.css",
"operator": "equal"
}
]
},
{
"caption": "Show Symbols (all)",
"command": "show_symbols",
//"arg_comment": "TODO",
"args": {
"type": "multi"
},
"caption": "Show Symbols (all)",
"command": "show_symbols",
"context": [
{
"key": "selector",
"match_all": true,
"operand": "source -source.css",
"operator": "equal"
}
]
}
]
}
]
},
{
"caption": "Preferences",
"mnemonic": "n",
"id": "preferences",
"children":
[
Expand Down
15 changes: 6 additions & 9 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@
CTags
=====

.. image:: https://travis-ci.org/SublimeText/CTags.svg?branch=development
:target: https://travis-ci.org/SublimeText/CTags
.. image:: https://github.com/SublimeText/CTags/actions/workflows/ci.yaml/badge.svg

About
=====

This `Sublime Text 2/3`_ package provides support for working with tags
This `Sublime Text`_ package provides support for working with tags
generated by `Exuberant CTags`_

.. _Sublime Text 2/3: http://sublimetext.com/
.. _Sublime Text: http://sublimetext.com/
.. _Exuberant CTags: http://ctags.sourceforge.net/

The ctags command is searched for on the system PATH. It works by doing a
Expand All @@ -25,11 +24,9 @@ See this `forum thread`_ for a bit of historical background on the Sublime Text
Installation
============

The easiest way to install this plugin, is to use the `Package Control`_
plugin, by `Will Bond`_
The easiest way to install this plugin, is to use the `Package Control`_ .

.. _Package Control: http://wbond.net/sublime_packages/package_control/
.. _Will Bond: http://wbond.net/
.. _Package Control: http://packagecontrol.io/

Alternatively, the plugin can be installed manually using one of the following
methods.
Expand Down Expand Up @@ -159,7 +156,7 @@ can be edited like any other ``.sublime-settings`` file

or::

"command" : "C:\Users\<username>\Downloads\CTags\ctag.exe"
"command" : "C:\\Users\\<username>\\Downloads\\CTags\\ctag.exe"

The rest of the options are fairly self explanatory.

Expand Down
76 changes: 54 additions & 22 deletions ctags.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,31 +341,51 @@ def resort_ctags(tag_file):
If not exists, create an empty array and store in the
dictionary with the file name as key
Save the line to this list
Create a new ``[tagfile]_sorted_by_file`` file
Create a new ``tagfile`` file
For each key in the sorted dictionary
For each line in the list indicated by the key
Split the line on tab character
Remove the prepending ``.\`` from the ``file_name`` part of
Remove the prepending ``.`` from the ``file_name`` part of
the tag
Join the line again and write the ``sorted_by_file`` file
:param tag_file: The location of the tagfile to be sorted
:returns: None
"""
keys = {}
meta = []
symbols = []
tmp_file = tag_file + '.tmp'

with codecs.open(tag_file, encoding='utf-8', errors='replace') as file_:
for line in file_:
keys.setdefault(line.split('\t')[FILENAME], []).append(line)
if line.startswith('!_TAG'):
meta.append(line)
continue

# read all valid symbol tags, which contain at least
# symbol name and containing file and build a list of tuples
split = line.split('\t')
if len(split) > FILENAME:
symbols.append((split[FILENAME], split))

# sort inplace to save some RAM with large .tags files
meta.sort()
symbols.sort()

with codecs.open(tag_file+'_sorted_by_file', 'w', encoding='utf-8',
with codecs.open(tmp_file, 'w', encoding='utf-8',
errors='replace') as file_:
for k in sorted(keys):
for line in keys[k]:
split = line.split('\t')
split[FILENAME] = split[FILENAME].lstrip('.\\')
file_.write('\t'.join(split))

# write sourted metadata
file_.writelines(meta)

# followed by sorted list of symbols
for _, split in symbols:
split[FILENAME] = split[FILENAME].lstrip('.\\')
file_.write('\t'.join(split))

os.remove(tag_file)
os.rename(tmp_file, tag_file)

#
# Models
Expand Down Expand Up @@ -393,16 +413,26 @@ def __init__(self, line, column=0):
self.column = column

def __lt__(self, other):
return self.line.split('\t')[self.column] < other
try:
return self.key < other
except IndexError:
return False

def __gt__(self, other):
return self.line.split('\t')[self.column] > other
try:
return self.key > other
except IndexError:
return False

def __getitem__(self, index):
return self.line.split('\t')[index]
return self.line.split('\t', self.column + 1)[index]

def __len__(self):
return len(self.line.split('\t'))
return self.line.count('\t') + 1

@property
def key(self):
return self[self.column]

class TagFile(object):
"""
Expand Down Expand Up @@ -443,6 +473,8 @@ def __getitem__(self, index):
result = self.mapped.readline() # get a complete line

result = result.strip()
if not result:
raise IndexError("Invalid tag at index %d." % index)

return Tag(result, self.column)

Expand Down Expand Up @@ -476,7 +508,7 @@ def open(self):
"""
Open file.
"""
self.file_o = codecs.open(self.path, 'r+b', encoding='ascii')
self.file_o = codecs.open(self.path, 'r+b', encoding='utf-8')
self.mapped = mmap.mmap(self.file_o.fileno(), 0,
access=mmap.ACCESS_READ)

Expand All @@ -500,20 +532,21 @@ def search(self, exact_match=True, *tags):
if not tags:
while self.mapped.tell() < self.mapped.size():
result = Tag(self.mapped.readline().strip(), self.column)
yield(result)
if result.line:
yield result
return

for key in tags:
left_index = bisect.bisect_left(self, key)
if exact_match:
result = self[left_index]
while result.line and result[result.column] == key:
yield(result)
yield result
result = Tag(self.mapped.readline().strip(), self.column)
else:
result = self[left_index]
while result.line and result[result.column].startswith(key):
yield(result)
yield result
result = Tag(self.mapped.readline().strip(), self.column)

def search_by_suffix(self, suffix):
Expand All @@ -529,10 +562,9 @@ def search_by_suffix(self, suffix):
:returns: matching tags
"""
for line in self.file_o:
if line.split('\t')[self.column].endswith(suffix):
yield Tag(line)
else:
continue
tag = Tag(line, self.column)
if tag.key.endswith(suffix):
yield tag

def tag_class(self):
"""
Expand Down
Loading

0 comments on commit 4776c2f

Please sign in to comment.