在哪里存储以前打开的文件的最后一个光标位置

在哪里存储以前打开的文件的最后一个光标位置

本文介绍了sublime 在哪里存储以前打开的文件的最后一个光标位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 Sublime 编辑器中导出最后打开的文件(选项卡)列表和每个文件的最后一个光标位置.我可以轻松解析位于安装子路径中名为 Session.sublime_session 的会话文件:/Data/Local/(在 Windows 中),获取文件名.但是查看该文件,没有发现明显的行号.还是我错过了什么?

I would like to export a list of last opened files (tabs) and the last cursor position for each file, in Sublime editor. I can easily parse the session file called Session.sublime_session located in the installation sub-path: <install path>/Data/Local/ (in Windows), to get the file names. But looking in that file, there are no obvious line numbers to be found. Or did I miss something?

最后的光标位置存储在哪里?

更新

我现在看到它存储在名为 selection 的 JSON 字段中,并按进入缓冲区的字符数进行计数.

I now see that it is stored in the JSON field called selection, and is counted by number of characters into the buffer.

...
"selection":
    [
        [
            4353,
            4353
        ]
    ],
...

所以现在的问题变成了,我如何从中计算行号?

So the question now become, how can I calculate the line number from this?

也许通过编写一个在读取 X 个字节后计算 EOL (\ns) 的正则表达式.(如果使用不同的 EOL 或 usinf UTF-8 与 ASCII 会怎样?)

Perhaps by writing a regex that counts EOL's (\ns) after reading in X number of bytes. (What if were using different EOL's or usinf UTF-8 vs ASCII?)

推荐答案

这个 Unix SE 问题,我设法拼凑了一些效果很好的东西.但这取决于 jq(对于 Windows)和 (Cygwin) Bash.

With the great help from the answers in this Unix SE question, I managed to patch together something that works pretty good. But it depends on both jq (for windows) and (Cygwin) Bash.

jq-win64.exe -r '.windows[]|.groups[].sheets[]| "\(.file):\(.settings.selection[0][0])"' Session.sublime_session |sort | sed 's/^\/./\/cygdrive\L&\E/'

然后我以此为基础提取 EOL 的数量,并用它来确定每个文件的确切光标行号.

I then used this as a basis to extract the number of EOL's and used that to determine the exact cursor line number for each file.

提示:使用 head -c ;<文件>|wc -l.

这篇关于sublime 在哪里存储以前打开的文件的最后一个光标位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 10:53