⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 herosoft.dsm

📁 在实地址模式访问4g内存,对了解操作系统底层的人有帮助
💻 DSM
📖 第 1 页 / 共 4 页
字号:
' Place the given strOperator (of nLen REAL characters)
' between spaces (if needed)
sub FixOperator(strOperator, nLen)
	dim strLastPos, strFind

	strLastPos = InitializePosition

	' Add one space between the operator
	while ActiveDocument.Selection.FindText("[A-Z,a-z,0-9,\),_,\]]" & _
			strOperator & "[A-Z,a-z,0-9,\(,_,\*,"",',&]", dsMatchRegExp) and _
			GetCurrentPosition(strLastPos)

		' Check if we're inside a comment or between quotes
		ActiveDocument.Selection.CharLeft
		if not ShouldIgnore then

			' Repeat the search since ShouldIgnore puts the cursor at the
			' beginning of the line
			ActiveDocument.Selection.FindText "[A-Z,a-z,0-9,\),_,\]]" & _
					strOperator & "[A-Z,a-z,0-9,\(,_,\*,"",',&]", dsMatchRegExp

			ActiveDocument.Selection.CharLeft
			ActiveDocument.Selection.CharRight
			ActiveDocument.Selection = " "
			MoveByColumns nLen
			ActiveDocument.Selection = " "

		end if
	wend

	strLastPos = InitializePosition

	' Fix any C++ "operator" member functions which were broken above
	while ActiveDocument.Selection.FindText("operator " & strOperator & " ", _
		dsMatchRegExp) and GetCurrentPosition(strLastPos)

		' Check if we're inside a comment or between quotes
		if not ShouldIgnore then

			' Repeat the search since ShouldIgnore puts the cursor at the
			' beginning of the line
			ActiveDocument.Selection.FindText "operator " & strOperator & " ", _
												dsMatchRegExp
			ActiveDocument.Selection.CharRight
			ActiveDocument.Selection.Backspace
			MoveByColumns -nLen
			ActiveDocument.Selection.Backspace

		end if
	wend

end sub

' Fix < operator without altering template<T> code and operator <<
function FixLessThanOperator()
	dim strLastPos, strFound, strTemplate

	strLastPos = InitializePosition

	while ActiveDocument.Selection.FindText("^.*[^ <]<.", dsMatchRegExp) and _
		GetCurrentPosition(strLastPos)

		' Check if we're inside a comment or between quotes
		if not ShouldIgnore then

			' Repeat the search since ShouldIgnore puts the cursor at the
			' beginning of the line
			ActiveDocument.Selection.FindText "^.*[^ <]<.", dsMatchRegExp

			strFound = ActiveDocument.Selection

			' Fix the left side
			strFound = Left(strFound, Len(strFound) - 2) & " " & _
						Right(strFound, 2)
			ActiveDocument.Selection = strFound

			' Fix the right side
			strTemplate = Right(strFound, 11)
			if  (Left(strTemplate, 8) <> "template") and _
				(Right(strFound, 1) <> " ") and _
				(Right(strFound, 1) <> "=") and _
				(Right(strFound, 1) <> "<") and _
				(Right(strFound, 1) <> ">")then
				ActiveDocument.Selection.CharLeft
				ActiveDocument.Selection = " "
			end if

		end if
	wend

end function

' Append a space after the given strOperator (if it needs it)
sub AppendSpace(strOperator)
	dim strLastPos

	strLastPos = InitializePosition

	while ActiveDocument.Selection.FindText(strOperator & _
		"[A-Z,a-z,0-9,\(,\-,_,\*,"",',&]", dsMatchRegExp) and _
		GetCurrentPosition(strLastPos)

		' Check if we're inside a comment or between quotes
		ActiveDocument.Selection.CharLeft
		if not ShouldIgnore then

			ActiveDocument.Selection.FindText strOperator & _
					"[A-Z,a-z,0-9,\(,\-,_,\*,"",',&]", dsMatchRegExp

			ActiveDocument.Selection.CharLeft
			MoveByColumns Len(strOperator)
			ActiveDocument.Selection = " "

		end if
	wend

end sub

' Fix tabbing within function blocks (surrounded by braces)
function TabifyMatchingBraces()
	dim strLastPos, cBeforeBrace

	strLastPos = InitializePosition

	while ActiveDocument.Selection.FindText("{") and _
			GetCurrentPosition(strLastPos)

		' Check if we're inside a comment or between quotes
		if not ShouldIgnore then

			' Repeat the action since ShouldIgnore puts the cursor at the
			' beginning of the line
			ActiveDocument.Selection.FindText "{"

			' Go to matching brace and reformat tabs
			ExecuteCommand "GoToMatchBraceExtend"
			ActiveDocument.Selection.SmartFormat

			cBeforeBrace = Mid(ActiveDocument.Selection, _
				Len(ActiveDocument.Selection) - 1, 1)

			' If SmartFormat indents the block (by mistake), unindent it
			if (cBeforeBrace = vbTab or cBeforeBrace = " ") then
				ActiveDocument.Selection.Unindent
			end if
		end if
	wend

end function

' Since Microsoft's "SmartFormat" is not smart enough to indent case
' statements inside the switch body, we'll do it here.
' (Thanks to Jim Cooper)
function IndentSwitchBody()
	dim nSwitchLine, nFirstLine, nLastLine, strLastPos, iLine

	strLastPos = InitializePosition

	while ActiveDocument.Selection.FindText("switch", _
		dsMatchWord + dsMatchCase) and GetCurrentPosition(strLastPos)

		' Check if we're inside a comment or between quotes
		if not ShouldIgnore then

			nSwitchLine = ActiveDocument.Selection.CurrentLine

			' Now find the opening brace and make sure it's on the next line
			if ActiveDocument.Selection.FindText("{") and _
				not ShouldIgnore and _
				(ActiveDocument.Selection.CurrentLine = nSwitchLine + 1) then

				' Repeat the action since ShouldIgnore puts the cursor at the
				' beginning of the line
				ActiveDocument.Selection.FindText "{"

				' Find next line in file, since earlier code put '{' on
				' a line by itself
				nFirstLine = ActiveDocument.Selection.CurrentLine + 1

				' Go to matching brace and reformat tabs
				ExecuteCommand "GoToMatchBrace"

				' Find previous line in file, since earlier code put '}' on
				' line by itself
				nLastLine = ActiveDocument.Selection.CurrentLine

				' Move to the line after the opening brace
				ActiveDocument.Selection.GoToLine nFirstLine, 1

				' Select everything between the braces and indent it
				for iLine = nFirstLine to nLastLine - 1
					ActiveDocument.Selection.LineDown dsExtend
				next
				ActiveDocument.Selection.Indent
			end if
		end if
	wend
end function

' Remove any lines that are considered extraneous (usually blank ones).
function RemoveExtraneousLines()
	dim strLastPos, nCurrentLine, nCurrentColumn

	strLastPos = InitializePosition

	' Remove any blank lines that fall below any open braces ("{")
	while ActiveDocument.Selection.FindText("{") and _
			GetCurrentPosition(strLastPos)

		' Check if we're inside a comment or between quotes
		if not ShouldIgnore then
			' Repeat the action since ShouldIgnore puts the cursor at the
			' beginning of the line
			ActiveDocument.Selection.FindText "{"

		    nCurrentLine = ActiveDocument.Selection.CurrentLine
			nCurrentColumn = ActiveDocument.Selection.CurrentColumn

			ActiveDocument.Selection.LineDown

			' Cut any blank lines below the {
			do while true
				ActiveDocument.Selection.StartOfLine
				ActiveDocument.Selection.EndOfLine dsExtend

				if LTrimTabs(ActiveDocument.Selection) <> "" then
					exit do
				end if
				ExecuteCommand "LineCut"

				' Make sure we haven't hit the bottom of the file
				ActiveDocument.Selection.EndOfDocument
				if ActiveDocument.Selection.CurrentLine = nCurrentLine + 1 then
				    exit do
				end if
				ActiveDocument.Selection.MoveTo nCurrentLine + 1, 1
			loop

			ActiveDocument.Selection.MoveTo nCurrentLine, nCurrentColumn
		end if
	wend

	strLastPos = InitializePosition

	' Remove any blank lines right above any closing braces ("}")
	while ActiveDocument.Selection.FindText("}") and _
			GetCurrentPosition(strLastPos)

		' Check if we're inside a comment or between quotes
		if not ShouldIgnore then
			' Repeat the action since ShouldIgnore puts the cursor at the
			' beginning of the line
			ActiveDocument.Selection.FindText "}"
			ActiveDocument.Selection.CharLeft

			' Cut blank lines above the }
			do while true
				ActiveDocument.Selection.LineUp
				ActiveDocument.Selection.StartOfLine
				ActiveDocument.Selection.EndOfLine dsExtend

				if LTrimTabs(ActiveDocument.Selection) <> "" then

					if ActiveDocument.Selection.CurrentLine > 1 then
						ActiveDocument.Selection.LineDown
					end if

					ActiveDocument.Selection.StartOfLine
					ActiveDocument.Selection.FindText "}"
					strLastPos = ActiveDocument.Selection.CurrentLine & "," & _
								 ActiveDocument.Selection.CurrentColumn

					ActiveDocument.Selection.LineDown
					ActiveDocument.Selection.StartOfLine
					exit do
				end if
				ExecuteCommand "LineCut"
			loop
		end if
	wend

end function

' Remove all spaces and tabs found in the current selection
function RemoveSpacesInSelection
	dim iPos, ch, strNoSpaces

	for iPos = 1 to Len(ActiveDocument.Selection)
		ch = Mid(ActiveDocument.Selection, iPos, 1)
		if ch <> " " and ch <> vbTab then
			strNoSpaces = strNoSpaces + ch
		end if
	next

	ActiveDocument.Selection = strNoSpaces
end function

' Fix any code with exponential notation (ie. 3.4e-2) which was
' broken when the + and - operators were fixed above (by FixOperator).
function FixExponents

	while ActiveDocument.Selection.FindText("[0-9,\.]e [\+\!\-] [0-9]", _
			dsMatchRegExp)
		RemoveSpacesInSelection
	wend

end function

' Break any lines containing multiple statements (separated by semicolons)
function BreakLinesWithMultipleStatements()
	dim strLastPos, nCurrentLine

	strLastPos = InitializePosition

	' Search for multiple semicolons on the same line
	while ActiveDocument.Selection.FindText(";.+;", dsMatchRegExp) and _
		GetCurrentPosition(strLastPos)

		' Check if we're inside a comment or between quotes
		if not ShouldIgnore then
			' Repeat the action since ShouldIgnore puts the cursor at the
			' beginning of the line
			ActiveDocument.Selection.FindText ";.+;", dsMatchRegExp

			nCurrentLine = ActiveDocument.Selection.CurrentLine
			ActiveDocument.Selection.CharLeft
			ActiveDocument.Selection.StartOfLine dsFirstText, dsExtend

			' If found, check that the semicolons don't belong to a for loop
			if (InStr(1, ActiveDocument.Selection, "for&(", _
				vbTextCompare) > 0) then
				ActiveDocument.Selection.MoveTo nCurrentLine + 1, 1
			else
				ActiveDocument.Selection.CharRight
				ActiveDocument.Selection.CharRight
				ActiveDocument.Selection.NewLine
			end if
		end if
	wend

end function



Sub MakeSelectedCodeNicer()
'DESCRIPTION: Reformats the currently selected source code to look nicer.
' Written by Alvaro Mendez on 07/15/1999

	' Check if there's a valid selection
	if ActiveDocument.Selection = "" then
		exit sub
	end if

	' Copy the selection to the clipboard
	ActiveDocument.Selection.Copy

	' Open a new document and changed its language to C/C++
	' This is required for SmartIndent to work.
	Documents.Add "Text"
	'ExecuteCommand "Properties"
	ActiveDocument.Language = "C/C++"

	' Paste the selection into the document and run the macro
	ActiveDocument.Selection.Paste
	ExecuteCommand "MakeCodeNicer"

	' Select the resulting code and copy it to the clipboard
	ActiveDocument.Selection.SelectAll
	ActiveDocument.Selection.Copy

	' Close the new document (without saving it)
	ActiveWindow.Close dsSaveChangesNo

	' Paste the reformatted code back over the original selection
	ActiveDocument.Selection.Paste

End Sub


Sub	MakeEquAlign()

	' Check that the current document can be changed
	if ActiveDocument.ReadOnly then

		' If we're connected to SourceSafe, let it prompt for check out
		ActiveDocument.Selection = "a"
		ActiveDocument.Undo

		if ActiveDocument.ReadOnly then		' check again
			MsgBox "This macro cannot be executed on a read-only file.", _
					vbExclamation
			exit sub
		end if
	end if

	' Save current line so we can return to it at the end
	dim nLine
	nLine = ActiveDocument.Selection.CurrentLine
	
	Replace " = ",vbtab+"= "

	' Go back to where we were at the beginning
	ActiveDocument.Selection.GoToLine nLine

End Sub


Sub	MakeSelectedEquAlign()
	'使选中的代码的=号用TAB对正
	'

	' Check if there's a valid selection
	if ActiveDocument.Selection = "" then
		exit sub
	end if

	' Copy the selection to the clipboard
	ActiveDocument.Selection.Copy

	' Open a new document and changed its language to C/C++
	' This is required for SmartIndent to work.
	Documents.Add "Text"
	'ExecuteCommand "Properties"
	ActiveDocument.Language = "C/C++"

	' Paste the selection into the document and run the macro
	ActiveDocument.Selection.Paste
	ExecuteCommand "MakeEquAlign"

	' Select the resulting code and copy it to the clipboard
	ActiveDocument.Selection.SelectAll
	ActiveDocument.Selection.Copy

	' Close the new document (without saving it)
	ActiveWindow.Close dsSaveChangesNo

	' Paste the reformatted code back over the original selection
	ActiveDocument.Selection.Paste

End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -