我把绿色版的scite文本编辑器下载下来免安装使用。但是需要把自己的配置固化起来。因此我做了一些配置与程序都完全独立的便携版设置方法。
文件夹结构
./Portable/wscite577 # 父文件夹
├── LaunchSciTE.vbs
├── SciTEStartup.lua
├── SciTEUser.properties
├── timestamp.lua
├── wordcount.lua
└── wscite # scite绿色版的程序文件夹,同级目录下其他均为相关的个人配置文件
程序启动与配置目录的设定
通过LaunchSciTE.vbs脚本实现无命令行弹窗启动,同时为程序启动时定义独立的配置目录变量,将配置目录指向上面的父文件夹的路径。
LaunchSciTE.vbs
' ==================================================
' 无黑窗启动 SciTE 的 VBScript 脚本 (支持参数传递)
' ==================================================
' 创建一个用于操作系统的外壳对象
Set objShell = CreateObject("WScript.Shell")
' 定义 SciTE 的根目录,方便修改
Dim sciTeUserHome
sciTeUserHome = "C:\Users\admin\Portable\wscite577"
' 根据你自己的需要,定义 SciTE 的根目录,方便修改
' 相应的,你也需要根据你自己的需要做出修改,而不是沿用我们现在的
' 1. 设置环境变量 (这只对即将启动的SciTE进程有效)
' 这等同于批处理中的: set SciTE_USERHOME=...
objShell.Environment("Process")("SciTE_USERHOME") = sciTeUserHome
' 2. 设置工作目录
' 这等同于批处理中的: cd /d ...
Dim sciTeWorkDir
sciTeWorkDir = sciTeUserHome & "\wscite"
objShell.CurrentDirectory = sciTeWorkDir
' 3. 构建要执行的完整命令
' 首先,定义基础的可执行文件
Dim strCommand
strCommand = "SciTE.exe"
' 然后,检查是否有参数传递给本 VBScript 脚本
If WScript.Arguments.Count > 0 Then
' 如果有参数,就遍历所有传入的参数
Dim arg
For Each arg In WScript.Arguments
' 将每个参数用双引号包裹 (以正确处理带空格的路径),然后拼接到命令后面
' 例如,最终命令会变成: SciTE.exe "C:\My Documents\file.txt"
strCommand = strCommand & " " & """" & arg & """"
Next
End If
' 4. 运行构建好的完整命令 (带有参数的 SciTE.exe)
' 参数 "1" 表示以正常窗口大小显示
' 参数 "False" 表示脚本不用等待SciTE关闭,启动后立刻退出
objShell.Run strCommand, 1, False
' 释放对象
Set objShell = Nothing
基本设置与中文环境基础设置
通过SciTEUser.properties这一用户配置文件实现对scite的定制,在vbs里面设置了正确的配置目录后,site是可以启动时自动读取这里的配置文件的。
SciTEUser.properties
# changedbyuser
# code.page=65001
# changedbyuser
# character.set=134
font.base=font:!Monaco,size:12
# Global initialisation file for SciTE
# For Linux, place in $prefix/share/scite
# For Windows, place in same directory as SciTE.EXE (or Sc1.EXE)
# Documentation at http://www.scintilla.org/SciTEDoc.html
# Globals
# Window sizes and visibility
if PLAT_WIN
position.left=600
position.top=40
if PLAT_GTK
position.left=5
position.top=22
position.width=$(scale 600)
position.height=$(scale 800)
#position.maximize=1
#position.tile=1
#full.screen.hides.menu=1
#minimize.to.tray=1
#~split.vertical=1
#split.wide=1
#output.horizontal.size=200
#output.vertical.size=60
#output.initial.hide=1
#horizontal.scrollbar=0
#horizontal.scroll.width=10000
#horizontal.scroll.width.tracking=0
#output.horizontal.scrollbar=0
#output.horizontal.scroll.width=10000
#output.horizontal.scroll.width.tracking=0
#output.scroll=0
#error.select.line=1
#end.at.last.line=0
tabbar.visible=1
#tabbar.hide.one=1
#tabbar.hide.index=1
#tabbar.multiline=1
#toolbar.visible=1
#toolbar.usestockicons=1
#toolbar.large=1
#menubar.detachable=1
#undo.redo.lazy=1
undo.selection.history=1
#statusbar.visible=1
#fileselector.width=800
#fileselector.height=600
#fileselector.show.hidden=1
#magnification=-1
#output.magnification=-1
change.history=3
#~ indicator.reverted.to.origin.insertion=style:squiggle,colour:#40A0BF
#~ indicator.reverted.to.origin.deletion=style:point,colour:#40A0BF
#~ indicator.saved.insertion=style:squiggle,colour:#60A060
#~ indicator.saved.deletion=style:point,colour:#00A000
#~ indicator.modified.insertion=style:squiggle,colour:#A0A060
#~ indicator.modified.deletion=style:point,colour:#A0A000
#~ indicator.reverted.to.modified.insertion=style:squiggle,colour:#FF8000
#~ indicator.reverted.to.modified.deletion=style:point,colour:#FF8000
#~ marker.reverted.to.origin=style:leftrect,fore:#40A0BF,back:#40A0BF
#~ marker.saved=style:leftrect,fore:#00A000,back:#00A000
#~ marker.modified=style:leftrect,fore:#A0A000,back:#A0A000
#~ marker.reverted.to.modified=style:leftrect,fore:#FF8000,back:#FF8000
# Sizes and visibility in edit pane
line.margin.visible=1
line.margin.width=4
margin.width=$(scale 16)
fold.margin.width=$(scale 14)
#fold.margin.colour=#FF0000
#fold.margin.highlight.colour=#0000FF
#blank.margin.left=4
#blank.margin.right=4
#output.blank.margin.left=4
buffered.draw=0
#phases.draw=2
if PLAT_WIN
technology=1
#font.quality=3
#font.locale=zh-Hans
if PLAT_MAC
font.quality=3
# Element styles
#view.eol=1
#control.char.symbol=.
#representations=\x0D\x0A=\u20AA
caret.period=500
view.whitespace=0
view.indentation.whitespace=1
view.indentation.guides=1
view.indentation.examine=3
highlight.indentation.guides=1
#caret.fore=#FF0000
#caret.additional.fore=#FF00DF
#caret.additional.blinks=0
#caret.style=2
#caret.width=2
#caret.line.back=#FFFED83F
#caret.line.layer=1
#caret.line.frame=1
edge.column=200
edge.mode=0
edge.colour=#C0DCC0
braces.check=1
braces.sloppy=1
#selection.fore=#006000
selection.layer=2
if PLAT_WINNT
selection.back=#00000020
if PLAT_GTK
selection.back=#0000001E
selection.secondary.back=#00800010
if PLAT_MAC
selection.back=#00000020
selection.additional.back=#00000010
selection.inactive.back=#00000010
#selection.additional.fore=#0000A0
#selection.inactive.fore=#00A000
#selection.secondary.fore=#A00000
selection.always.visible=1
#selection.rectangular.switch.mouse=1
#selection.multiple=0
#selection.additional.typing=0
#selection.multipaste=0
#virtual.space=3
#rectangular.selection.modifier=8
#whitespace.fore=#FF0000
#whitespace.back=#FFF0F0
#whitespace.size=2
#error.marker.fore=#0000A0
#error.marker.back=#DADAFF
#error.inline=1
bookmark.fore=#BE0000
#bookmark.back=#FFFFA0
#bookmark.alpha=
#bookmark.stroke.width=200
#bookmark.symbol=3
#find.mark=#0000FF
#find.mark.indicator=style:compositionthick,colour:#FFB700,under
#highlight.current.word=1
#highlight.current.word.by.style=1
#highlight.current.word.colour=#00D040
#highlight.current.word.indicator=style:roundbox,colour:#0080FF,under,outlinealpha:140,fillalpha:80
filter.match.indicator=style:compositionthick,colour:#FFB700,under
#filter.match.back=#FFB00030
#filter.context=2
#hidden.line.colour=#00800040
#indicators.alpha=63
#indicators.under=1
# Scripting
ext.lua.startup.script=$(SciteUserHome)/SciTEStartup.lua
ext.lua.auto.reload=1
#ext.lua.reset=1
# Checking
are.you.sure=1
#are.you.sure.for.build=1
#save.all.for.build=1
#quit.on.close.last=1
#load.on.activate=1
#save.on.deactivate=1
#are.you.sure.on.reload=1
#save.on.timer=20
#reload.preserves.undo=1
#check.if.already.open=1
#temp.files.sync.load=1
default.file.ext=.cxx
#source.default.extensions=.h|.cxx|.bat
#title.full.path=1
#title.show.buffers=1
#pathbar.visible=1
#pathbar.selectable=1
#save.recent=1
#save.session=1
#load.session.always=1
#session.bookmarks=1
#session.folds=1
#save.position=1
#save.find=1
#open.dialog.in.file.directory=1
#strip.trailing.spaces=1
#ensure.final.line.end=1
#ensure.consistent.line.ends=1
#save.deletes.first=1
#save.check.modified.time=1
buffers=100
#buffers.zorder.switching=1
#api.*.cxx=d:\api\w.api
#locale.properties=locale.de.properties
#translation.missing=***
#read.only=1
#read.only.indicator=1
#background.open.size=20000
#background.save.size=20000
if PLAT_GTK
background.save.size=10000000
#max.file.size=1
file.size.large=100000000
file.size.no.styles=10000000
#lexilla.path=.
# Indentation
# changedbyuser
tabsize=4
indent.size=4
use.tabs=0
#indent.auto=1
indent.automatic=1
indent.opening=1
indent.closing=1
#tab.indents=0
#backspace.unindents=0
# Wrapping of long lines
wrap=1
#wrap.style=2
#cache.layout=3
#output.wrap=1
#output.cache.layout=3
threads.layout=16
#wrap.visual.flags=3
#wrap.visual.flags.location=3
#wrap.indent.mode=1
#wrap.visual.startindent=4
#idle.styling=1
#output.idle.styling=1
# Folding
# enable folding, and show lines below when collapsed.
fold=1
fold.compact=0
fold.flags=16
#fold.line.colour=#80800080
fold.symbols=1
#fold.fore=#000000
#fold.back=#808080
#fold.highlight=1
#fold.highlight.colour=#00C0C0
#fold.stroke.width=200
#fold.on.open=1
fold.comment=1
fold.preprocessor=1
# Find and Replace
# Internal search always available with recursive capability so use in preference to external tool
find.command=
# findstr is available on recent versions of Windows including 2000
#if PLAT_WIN
# find.command=findstr /n /s $(find.what) $(find.files)
#find.input=$(find.what)
#if PLAT_GTK
# find.command=grep --line-number "$(find.what)" $(find.files)
find.files=*.c *.cxx *.h
#find.in.files.close.on.find=0
#find.in.dot=1
#find.in.binary=1
#find.exclude=*.bak *.orig debug
#find.in.directory=
#find.close.on.find=0
#find.replace.matchcase=1
#find.replace.escapes=1
#find.replace.regexp=1
#find.replace.regexp.posix=1
#find.replace.regexp.cpp11=1
#find.replace.wrap=0
#find.replacewith.focus=0
#find.replace.advanced=1
find.use.strip=1
#find.strip.incremental=1
#find.indicator.incremental=style:compositionthick,colour:#FFB700,under
replace.use.strip=1
#replace.strip.incremental=1
#strip.button.height=24
#strip.shortcuts.enable=0
# Behaviour
#eol.mode=LF
eol.auto=1
clear.before.execute=0
#vc.home.key=1
#wrap.aware.home.end.keys=1
#autocompleteword.automatic=1
#autocomplete.choose.single=1
#autocomplete.*.fillups=([
#autocomplete.*.start.characters=.:
#autocomplete.*.typesep=!
#autocomplete.fore=#80FFA0
#autocomplete.back=#000000
#autocomplete.selected.fore=#00FF40
#autocomplete.selected.back=#006040
#autocomplete.visible.item.count=15
#autocomplete.multi=1
caret.policy.xslop=1
caret.policy.width=20
caret.policy.xstrict=0
caret.policy.xeven=0
caret.policy.xjumps=0
caret.policy.yslop=1
caret.policy.lines=1
caret.policy.ystrict=1
caret.policy.yeven=1
caret.policy.yjumps=0
#visible.policy.strict=1
#visible.policy.slop=1
#visible.policy.lines=4
#time.commands=1
#caret.sticky=1
#properties.directory.enable=1
#editor.config.enable=1
#save.path.suggestion=$(SciteUserHome)\note_$(TimeStamp).txt
# changed by user
# Status Bar
#~ statusbar.visible=1
#~ statusbar.number=4
#~ statusbar.text.1=\
#~ li=$(LineNumber) co=$(ColumnNumber) $(OverType) ($(EOLMode)) $(FileAttr)
#~ statusbar.text.2=\
#~ $(BufferLength) chars in $(NbOfLines) lines. Sel: $(SelLength) chars.
#~ statusbar.text.3=\
#~ Now is: Date=$(CurrentDate) Time=$(CurrentTime)
#~ statusbar.text.4=\
#~ $(FileNameExt) : $(FileDate) - $(FileTime) | $(FileAttr)
if PLAT_WIN
command.scite.help="file://$(SciteDefaultHome)\SciTEDoc.html"
command.scite.help.subsystem=2
if PLAT_GTK
command.scite.help=xdg-open "file://$(SciteDefaultHome)/SciTEDoc.html"
# Internationalisation
# Japanese input code page 932 and ShiftJIS character set 128
#code.page=932
#character.set=128
# Unicode
#code.page=65001
code.page=0
#character.set=204
#command.discover.properties=python /home/user/FileDetect.py "$(FilePath)"
#discover.properties=1
# Forward LC_CTYPE to setlocale which may affect language support.
#LC_CTYPE=en_US.UTF-8
if PLAT_GTK
output.code.page=65001
if PLAT_MAC
output.code.page=65001
#ime.interaction=1
#ime.autocomplete=1
#accessibility=0
# Export
#export.keep.ext=1
export.html.wysiwyg=1
#export.html.tabs=1
#export.html.folding=1
export.html.styleused=1
#export.html.title.fullpath=1
#export.rtf.tabs=1
#export.rtf.font.face=Arial
#export.rtf.font.size=9
#export.rtf.tabsize=8
#export.rtf.wysiwyg=0
#export.tex.title.fullpath=1
# Magnification (added to default screen font size)
export.pdf.magnification=0
# Font: Courier, Helvetica or Times (Courier line-wraps)
export.pdf.font=Helvetica
# Page size (in points): width, height
# E.g. Letter 612,792; A4 595,842; maximum 14400,14400
export.pdf.pagesize=595,842
# Margins (in points): left, right, top, bottom
export.pdf.margins=72,72,72,72
export.xml.collapse.spaces=1
export.xml.collapse.lines=1
# Define values for use in the imported properties files
chars.alpha=abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
chars.numeric=0123456789
chars.accented=???????a?????????????????????????????
# This is a better set for Russian:
#chars.accented=?a????????????????????????????????
# The open.filter setting is used in the file selector which has a menu of filters to apply
# to the types of files seen when opening.
# Gather all settings with "*source.patterns." prefix from all active .properties files
source.files=$(star *source.patterns.)
source.all.filter=All Source|$(source.files)|
# Each platform has a different idea of the most important filters
if PLAT_WIN
all.files=All Files (*.*)|*.*|
top.filters=$(source.all.filter)$(all.files)
if PLAT_GTK
all.files=All Files (*)|*|Hidden Files (.*)|.*|
top.filters=$(source.all.filter)$(all.files)
# As macOS only greys out filtered files, show all as default
if PLAT_MAC
all.files=All Files (*.*)|*.*|
top.filters=$(all.files)$(source.all.filter)
# Gather all settings with "*filter." prefix from all active .properties files
list.filters=$(star *filter.)
open.filter=$(top.filters)$(list.filters)
#save.filter=$(open.filter)
# Give symbolic names to the set of fonts used in the standard styles.
if PLAT_WIN
font.base=font:Verdana,size:9.4
font.small=font:Verdana,size:8
font.comment=font:Georgia,size:10.1
font.code.comment.box=$(font.comment)
font.code.comment.line=$(font.comment)
font.code.comment.doc=$(font.comment)
font.code.comment.nested=$(font.comment)
font.text=font:Times New Roman,size:11
font.text.comment=font:Verdana,size:9
font.embedded.base=font:Verdana,size:9
font.embedded.comment=font:Comic Sans MS,size:8
font.monospace=font:Consolas,size:8.9
font.monospace.small=font:Consolas,size:8
font.vbs=font:Candara,size:10
if PLAT_GTK
font.base=font:DejaVu Sans,size:9
font.small=font:DejaVu Sans,size:8
font.comment=font:DejaVu Serif,size:9
font.code.comment.box=$(font.comment)
font.code.comment.line=$(font.comment)
font.code.comment.doc=$(font.comment)
font.code.comment.nested=$(font.comment)
font.text=font:DejaVu Serif,size:10
font.text.comment=font:Serif,size:9
font.embedded.base=font:Serif,size:9
font.embedded.comment=font:Serif,size:9
font.monospace=font:DejaVu Sans Mono,size:9
font.monospace.small=font:DejaVu Sans Mono,size:8
font.vbs=font:DejaVu Sans Mono,size:9
if PLAT_MAC
font.base=font:Verdana,size:12
font.small=font:Verdana,size:10
font.comment=font:Georgia,size:13
font.code.comment.box=$(font.comment)
font.code.comment.line=$(font.comment)
font.code.comment.doc=$(font.comment)
font.code.comment.nested=$(font.comment)
font.text=font:Times New Roman,size:13
font.text.comment=font:Verdana,size:11
font.embedded.base=font:Verdana,size:11
font.embedded.comment=font:Comic Sans MS,size:10
font.monospace=font:Menlo,size:12
font.monospace.small=font:Menlo,size:10
font.vbs=font:Lucida Sans Unicode,size:12
font.js=$(font.comment)
font.monospaced.list=Consolas;Courier New;DejaVu Sans Mono;Menlo
# Give symbolic names to the set of colours used in the standard styles.
colour.code.comment.box=fore:#007F00
colour.code.comment.line=fore:#007F00
colour.code.comment.doc=fore:#3F703F
colour.code.comment.nested=fore:#A0C0A0
colour.text.comment=fore:#0000FF,back:#D0F0D0
colour.other.comment=fore:#007F00
colour.embedded.comment=back:#E0EEFF
colour.embedded.js=back:#F0F0FF
colour.notused=back:#FF0000
colour.number=fore:#007F7F
colour.keyword=fore:#00007F
colour.string=fore:#7F007F
colour.char=fore:#7F007F
colour.operator=fore:#000000
colour.preproc=fore:#7F7F00
colour.error=fore:#FFFF00,back:#FF0000
# To de-emphasize inactive code set traits.inactive
#traits.inactive=,back:#F0F0F0,eolfilled
traits.inactive=
# Global default styles for all languages
# Default
style.*.32=$(font.base)
# Line number
style.*.33=back:#E7E7E7,$(font.base)
# Brace highlight
style.*.34=fore:#0000FF,bold
# Brace incomplete highlight
style.*.35=fore:#FF0000,bold
# Control characters
style.*.36=
# Indentation guides
style.*.37=fore:#C0C0C0,back:#FFFFFF
# Printing
#print.colour.mode=1
print.magnification=-1
# Windows-only setup: left, right, top, bottom margins, in local units:
# hundredths of millimeters or thousandths of inches
print.margins=1500,1000,1000,1500
# Header/footer:
print.header.format=$(FileNameExt) -- Printed on $(CurrentDate), $(CurrentTime) -- Page $(CurrentPage)
print.footer.format=$(FilePath) -- File date: $(FileDate) -- File time: $(FileTime)
# Header/footer style
print.header.style=font:Arial,size:12,bold
print.footer.style=font:Arial Narrow,size:10,italics
# Experimental undocumented settings
#bidirectional=1
# Warnings - only works on Windows and needs to be pointed at files on machine
#if PLAT_WIN
# warning.findwrapped=100,E:\Windows\Media\SFX\Boing.wav
# warning.notfound=0,Effect.wav
# warning.wrongfile=0,Glass.wav
# warning.executeok=0,Fanfare.wav
# warning.executeko=100,GlassBreak.wav
# warning.nootherbookmark=100,Boing2.wav
#create.hidden.console=1
# Define the Lexer menu,
# Each item contains three parts: menu string | file extension | key
# The only keys allowed currently are based on F-keys and alphabetic keys and look like
# [Ctrl+][Shift+][Fn|a] such as F12 or Ctrl+Shift+D.
# A '&' may be placed before a letter to be used as an accelerator. This does not work on GTK+.
keyText=Shift+F11
keyMake=Ctrl+Shift+F11
keyHTML=F12
keyXML=Shift+F12
keyIndent=Ctrl+Shift+F12
# On macOS, F11 is used by Expose, F12 by Dashbard
if PLAT_MAC
os.x.home.end.keys=1
keyText=Shift+F13
keyMake=Ctrl+Shift+F13
keyHTML=Ctrl+Shift+F14
keyXML=Shift+F14
keyIndent=
# Gather all settings with "*language." prefix from all active .properties files
menu.language=$(star *language.)
# User defined key commands
user.shortcuts=\
Ctrl+Shift+V|IDM_PASTEANDDOWN|\
Ctrl+PageUp|IDM_PREVFILE|\
Ctrl+PageDown|IDM_NEXTFILE|
#KeypadPlus|IDM_EXPAND|\
#KeypadMinus|IDM_BLOCK_COMMENT|
#user.context.menu=\
#||\
#Next File|IDM_NEXTFILE|\
#Prev File|IDM_PREVFILE|
# To keep menus short, these .properties files are not loaded by default.
imports.exclude=abaqus ada asciidoc asl asn1 au3 ave avs baan blitzbasic bullant \
caml cil cmake cobol coffeescript csound d dataflex ecl eiffel erlang escript \
flagship forth fortran freebasic fsharp \
gap haskell hex hollywood inno kix latex lot lout \
maxima metapost mmixal modula3 nim nncrontab nsis \
opal oscript pov powerpro ps purebasic r raku rebol rust \
sas scriptol smalltalk sorcins spice specman \
tacl tal troff txt2tags verilog vhdl visualprolog
# The set of imports allowed can be set with
#imports.include=ave
# Import all the language specific properties files in this directory
import *
# ==================================================
# SciTE 中文环境完美配置
# ==================================================
# 1. 设置编码为 UTF-8 (核心)
code.page=65001
output.code.page=65001
utf8.bom=1
# 2. 设置高质量的编程字体 (推荐: 更纱黑体)
# 请确保你系统中已经安装了此字体
# font.base=font:Sarasa Term SC,size:11
# font.wide=font:Sarasa Term SC,size:11
# 3. 优化中文词语选择
word.characters=$(word.characters)一-龥
# ==================================================
#----------------------------------------------------------------#
# Output Pane Configuration (输出窗口配置)
#----------------------------------------------------------------#
# 将输出窗口置于下方 (0 = 上下分割, 1 = 左右分割)
# 0 = Horizontal split (editor above, output below)
# 1 = Vertical split (editor left, output right)
split.vertical=0
# 设置下方输出窗口的高度 (单位:像素)
# 您可以根据自己的屏幕和喜好调整这个数值,例如 150, 200, 250 等
output.vertical.size=200
# (可选) 如果您未来切换回左右分割 (split.vertical=1),这个属性将设置右侧输出窗口的宽度
# output.horizontal.size=300
#----------------------------------------------------------------#
# Status Bar Configuration (状态栏配置) - 分区单行最终版
#----------------------------------------------------------------#
# 确保状态栏可见
statusbar.visible=1
# 定义状态栏有 2个分区
statusbar.number=2
# 定义这 2 个分区的宽度 (单位:像素)
# 正数 = 固定宽度
# 负数 = 占据剩余的所有空间 (通常只用于最后一个分区)
statusbar.widths=200 -1
#-- 将文本内容分配到对应的分区 --#
# 第 1 分区 (宽度 120px): 核心光标信息
statusbar.text.1=\
Ln:$(LineNumber) Col:$(ColumnNumber) Sel:$(SelLength) | \
$(code.page) | $(EOLMode) | $(Language) | Zoom:$(ScaleFactor) | \
$(UserDefinedStats) | $(FileDate)-$(FileTime)
# 第 4 分区 (宽度 -1, 自动填充): 文件路径和状态
statusbar.text.2=\
$(FilePath) $(FileAttr)
# markdown语法高亮
# 导入 Markdown 语法配置
# 前面已经用*导入过了
# import markdown
# 将指定后缀文件关联到 Markdown 语法
file.patterns.markdown=*.md;*.mdx;*.markdown
中文等东亚文字的计数支持插件
通过SciTEStartup.lua进行插件的注册,注册方式见上面SciTEStartup.lua中的代码。
wordcount.lua
-- wordcount.lua (v2 - 改进版)
function UpdateWordCount()
-- 如果编辑器不存在或不可用,则直接返回
if not editor then return end
local text = editor:GetText()
if not text or text == "" then
props["UserDefinedStats"] = "Words: 0"
return
end
local cjk_count = 0
local western_word_count = 0
-- 1. 统计 CJK 字符 (Unicode 范围 u4e00-u9fa5 是常用汉字)
-- string.gmatch 在处理 UTF-8 时需要特殊模式
for char in text:gmatch("[\224-\239][\128-\191][\128-\191]") do
-- 这个模式匹配大多数3字节的UTF-8字符,包括CJK
cjk_count = cjk_count + 1
end
-- 2. 统计西文单词 (字母、数字、下划线、撇号构成)
-- 我们先将 CJK 字符替换为空格,避免干扰西文单词的识别
local western_text = text:gsub("[\224-\239][\128-\191][\128-\191]", " ")
for word in string.gmatch(western_text, "[%w']+") do
western_word_count = western_word_count + 1
end
-- 3. 合计总数并更新状态栏
local total_count = cjk_count + western_word_count
props["UserDefinedStats"] = "Words: " .. total_count
end
-- 注意:我们稍后会在主脚本中统一处理事件,所以这里可以先注释掉
-- function OnOpen() UpdateWordCount() end
-- function OnSave() UpdateWordCount() end
-- function OnUpdateUI() UpdateWordCount() en
时间戳插入插件
通过SciTEStartup.lua进行插件的注册,注册方式同上。
timestamp.lua
-- timestamp.lua
-- 这个函数会在保存文件时,在文件顶部插入或更新一个时间戳
function UpdateTimestampOnSave()
-- 检查文件是否是只读的
if editor.ReadOnly then return end
local firstLine = editor:GetLine(0)
local timestamp_prefix = "-- Last saved: " -- 你可以自定义这个前缀
-- 格式化当前时间
local new_timestamp = timestamp_prefix .. os.date("%Y-%m-%d %H:%M:%S")
editor:BeginUndoAction() -- 开始撤销操作,以便可以一次性撤销
if string.find(firstLine, timestamp_prefix, 1, true) then
-- 如果第一行已经是时间戳,则替换它
local target = {start = 0, ['end'] = string.len(firstLine)}
editor:TargetFromSelection()
editor:SetTargetRange(0, string.len(firstLine))
editor:ReplaceTarget(new_timestamp .. "\n")
else
-- 否则,在文件开头插入新的一行
editor:InsertText(0, new_timestamp .. "\n")
end
editor:EndUndoAction() -- 结束撤销操作
end