Textmate 片段在评论中添加文件名和路径?
我使用 Textmate 中的现有代码片段来减少创建控制器和模型的重复次数。该代码片段效果很好,但我想在每个文件的末尾添加注释。例如:
/* End of file filename.php */
/* Location: ./system/application/controllers/filename.php */
第一行很简单:
/* End of file ${TM_FILENAME} */
第二部分与 TM_FILEPATH 变量几乎一样简单:
/* Location: ./${TM_FILEPATH} */
问题是,我不希望返回整个文件路径,只返回“系统”(如果存在)或“应用程序”之后的任何内容如果不。例如,使用 TM_FILEPATH 返回:
/* Location: ./path/from/root/system/application/controllers/filename.php */
-or-
/* Location: ./path/from/root/application/controllers/filename.php */
...当我想要时:
/* Location: ./system/application/controllers/filename.php */
-or-
/* Location: ./application/controllers/filename.php */
我认为这将是一些正则表达式技巧,但我不知道如何实现。请问有什么建议吗?
更新:我刚刚找到了 TextMate 变量 TM_PROJECT_DIRECTORY,其中包含我想要从 TM_FILEPATH 中删除的信息(如果这会让事情变得更容易的话)。
因此,TM_FILEPATH 产生以下内容:
/path/from/root/system/application/controllers/filename.php
TM_PROJECT_DIRECTORY 产生以下内容:
/path/from/root
I'm using an existing snippet in Textmate to reduce the repetition of creating controllers and models. The snippet works great, but I'd love to add a comment to the end of each file. For example:
/* End of file filename.php */
/* Location: ./system/application/controllers/filename.php */
The first line is easy:
/* End of file ${TM_FILENAME} */
The second part is almost as easy with the TM_FILEPATH variable:
/* Location: ./${TM_FILEPATH} */
The problem is, I don't want the entire file path returned, just anything AFTER 'system' if it exists, or 'application' if not. For instance, using TM_FILEPATH returns this:
/* Location: ./path/from/root/system/application/controllers/filename.php */
-or-
/* Location: ./path/from/root/application/controllers/filename.php */
...when I want:
/* Location: ./system/application/controllers/filename.php */
-or-
/* Location: ./application/controllers/filename.php */
I assume it is going to be some regex trickery, but I have no idea how. Any suggestions please?
UPDATE: I just found the TextMate variable TM_PROJECT_DIRECTORY which contains the info that I want REMOVED from TM_FILEPATH if that makes things any easier.
So, whereas TM_FILEPATH produces this:
/path/from/root/system/application/controllers/filename.php
TM_PROJECT_DIRECTORY produces this:
/path/from/root
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不了解 Textmate,但是你可以使用 CI 常量 FCPATH 吗?这是文件的完整服务器路径。
I don't know about Textmate, but could you use the CI constant FCPATH? This is the full server path to the file.
我对控制器和模型使用两个不同的片段(因为语法相似,但有点不同;IE:每个控制器都需要一个索引函数,但模型不需要)。我只是按如下方式对它们进行硬编码...
控制器:
模型:
由于我总是将应用程序文件夹从系统文件夹中拉出,并将系统文件夹放在不同的目录中,所以效果很好。我还在应用程序上添加了一个制表符,以防万一我重命名了应用程序目录。
@TM_PROJECT_DIRECTORY:我认为只有当您将文件作为项目打开时,这才有效。我使用的是基于 Textmate 的电子文本编辑器,所以它可能有点不同。
希望这有帮助。
I use two different snippets for controllers and models (since the syntax is similar, but just a bit different; I.E.: every controller needs an index function, but models don't). I just hard code them as follows...
Controller:
Model:
Since I always pull the application folder out of the system folder, and put the system folder in a different directory, this works out great. I also added a tabstop on application, just in case I renamed the application directory.
@TM_PROJECT_DIRECTORY: I think this only works if you open your files as a project. I use e text editor, which is based on Textmate, so it might be a little bit different.
Hope this helps.
这是我想出的解决方案。我不知道这是否是最好的方法,但它似乎有效:
我会根据我的理解将其分解;)
Here is the solution I came up with. I have no idea if it is the best way, but it seams to work:
I'll break it down as much as I understand it ;)