Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Search for ctags files recursively by default.

Summary:
Search for ctags files recursively by default.
  • Loading branch information...
commit ddb8db728c78648d4037cca2262b3c1d70ca6501 1 parent 6c749f7
Aran Donohue authored adonohue committed
Showing with 50 additions and 29 deletions.
  1. +28 −18 src/__init__.py
  2. +22 −11 src/ctags.py
View
46 src/__init__.py
@@ -6,6 +6,7 @@
from threading import Thread
import ansicolor as clr
import cmd_util as cu
+import ctags
import ConfigParser
import os
import re
@@ -296,19 +297,32 @@ def __init__(self, phpsh_state):
self.phpsh_state = phpsh_state
def run(self):
try:
- import ctags
- self.phpsh_state.ctags = ctags.Ctags()
- try:
- self.phpsh_state.function_signatures = \
- ctags.CtagsFunctionSignatures().function_signatures
- except Exception, e:
- self.phpsh_state.function_signatures = {}
- print self.phpsh_state.clr_err + \
- "Problem loading function signatures" + \
- self.phpsh_state.clr_default
+ tags_file_path = None
+ try:
+ tags_file_path = ctags.find_tags_file()
+ except ctags.CantFindTagsFile, e:
+ return
+
+ print self.phpsh_state.clr_cmd + \
+ "Loading ctags (in background)" + \
+ self.phpsh_state.clr_default
+ self.phpsh_state.ctags = ctags.Ctags(tags_file_path)
+ try:
+ self.phpsh_state.function_signatures = \
+ ctags.CtagsFunctionSignatures().function_signatures
+ except Exception, e:
+ self.phpsh_state.function_signatures = {}
+ print self.phpsh_state.clr_err + \
+ "Problem loading function signatures" + \
+ self.phpsh_state.clr_default
except Exception, e:
- print self.phpsh_state.clr_err + \
- "Problem loading ctags" + self.phpsh_state.clr_default
+ if tags_file_path:
+ path = tags_file_path
+ else:
+ path = ""
+ print self.phpsh_state.clr_err + \
+ "Problem loading ctags %(path)s\n(%(e)s)\n" % locals() + \
+ self.phpsh_state.clr_default
class PhpshState:
"""This doesn't perfectly encapsulate state (e.g. the readline module has
@@ -438,12 +452,8 @@ def __init__(self, cmd_incs, do_color, do_echo, codebase_mode,
# ctags integration
self.ctags = None
- if do_ctags and os.path.isfile("tags"):
- print self.clr_cmd + \
- "Loading ctags (in background)" + \
- self.clr_default
- load_ctags = LoadCtags(self)
- load_ctags.start()
+ if do_ctags:
+ LoadCtags(self).start()
else:
self.function_signatures = {}
View
33 src/ctags.py
@@ -23,19 +23,30 @@ def __init__(self, tags_file_path=None):
self.tags_root = os.path.dirname(tags_file_path)
self.function_signatures = parse_function_signatures(tags_file_path)
-def find_tags_file(dir=None, tags_file_name="tags"):
+def find_tags_file(directory=None, tags_file_name="tags"):
"""looks for a file in the current or given directory and
- all parent directories of that directory up until the root"""
- file_in_dir = lambda d: d + os.path.sep + tags_file_name
- if not dir:
- dir = os.getcwd()
- while not os.path.isfile(file_in_dir(dir)):
- dir = os.path.normpath(dir)
- if dir == os.path.sep:
- raise CantFindTagsFile
- dir += os.path.sep + os.path.pardir
+ all parent directories of that directory up until some directory
+ that is in PHPSH_CEILING_DIRECTORIES or the root. Directories
+ in PHPSH_CEILING_DIRECTORIES are not checked. The root is checked
+ unless it is in PHPSH_CEILING_DIRECTORIES. If the provided directory
+ is in PHPSH_CEILING_DIRECTORIES, it will be checked."""
+
+ ceiling_config = os.environ.get("PHPSH_CEILING_DIRECTORIES", "")
+ ceiling_directories = filter(bool, ceiling_config.split(os.pathsep))
+
+ if not directory:
+ directory = os.environ.get("PWD") or os.getcwd()
- return file_in_dir(os.path.normpath(dir))
+ while True:
+ tags_path = os.path.join(directory, tags_file_name)
+ if os.path.isfile(tags_path):
+ return tags_path
+
+ next_search_dir = os.path.dirname(directory)
+ if next_search_dir == directory or \
+ next_search_dir in ceiling_directories:
+ raise CantFindTagsFile
+ directory = next_search_dir
def parse_tags_file(tags_file_path):
"""parses a tags file generated by ctags,
Please sign in to comment.
Something went wrong with that request. Please try again.