Jef*_*ris 11 xcode metaprogramming
在emacs中,我有各种操作文本的功能.现在我正在使用xcode,我想我可以将emacs作为默认编辑器,但我想浏览obj-c对象等,所以我宁愿只为xcode实现我最常用的文本操作命令.
首先在我的列表中,我想要一个命令,将当前行的文本向上/向下移动一行,将光标保持在当前行.
在emacs中,这是:
(defun move-one-line-downward ()
"Move current line downward once."
(interactive)
(forward-line)
(transpose-lines 1)
(forward-line -1))
Run Code Online (Sandbox Code Playgroud)
如果我能在Python中编写一个可以在XCode中执行相同操作的脚本,我会感到最开心,但就我所知,我需要与AppleScript交谈才能做到这一点.
有人可以通过XCode告诉我如何做到这一点吗?
您可以通过Xcode的"用户脚本"来实现您想要做的事情 - 它有助于提供一对几乎可以满足您需求的脚本.(我在这里使用Xcode 3.2,但我认为这些也在3.1)
看看/Developer/Library/Xcode/User Scripts/; 那里有两个苹果,Move Line Up.scpt和Move Line Down.scpt.这是什么Move Line Up:
(*
To edit this script, choose Save As... and save it in your home directory, then re-add it to the User Scripts list.
*)
using terms from application "Xcode"
tell first text document
set {startLine, endLine} to selected paragraph range
if startLine > 1 then
set theText to (paragraphs startLine through endLine)
set theText to (theText as string)
delete (paragraphs startLine through endLine)
make new paragraph at beginning of paragraph (startLine - 1) with data theText
set selected paragraph range to {startLine - 1, endLine - 1}
else
beep 1
end if
end tell
end using terms from
Run Code Online (Sandbox Code Playgroud)
这些几乎可以做你想要的,除了他们之后选择整行; 我不是苹果专家,但你可能想存储selected character range.查看Xcode脚本字典(在AppleScript编辑器,文件 - >打开字典 - > Xcode中),找出可以操作的对象类型.
您可以使用脚本菜单中的"编辑用户脚本"菜单项将自己的脚本添加到Xcode; 并通过双击脚本菜单项的条目旁边的右侧列,为该窗口中的脚本分配快捷键.
您还可以在"用户脚本"菜单中使用shell脚本(perl,python,bash等),但这些脚本只处理选择或整个文件,因此对于向上或向下移动单行可能会有点重量级.
请在此处查看有关用户脚本的所有文档:http://developer.apple.com/mac/library/documentation/DeveloperTools/Conceptual/XcodeWorkspace/310-User_Scrips/user_scripts.html
我希望这有帮助!
| 归档时间: |
|
| 查看次数: |
5575 次 |
| 最近记录: |