Last active
January 9, 2022 16:32
-
-
Save mixio/9d9a7cd873b931341e34042233b8ef7e to your computer and use it in GitHub Desktop.
Adds a p͇s͇e͇u͇d͇o͇ ͇u͇n͇d͇e͇r͇l͇i͇n͇e͇ ͇s͇t͇y͇l͇e͇ to BBEdit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* | |
README: | |
This scrit is a bit of a hack that takes advantage of Unicode combining | |
codepoints to create a p͇s͇e͇u͇d͇o͇ ͇u͇n͇d͇e͇r͇l͇i͇n͇e͇ ͇s͇t͇y͇l͇e͇. | |
It works by inserting the combining underline codepoint (U+0347 COMBINING EQUALS | |
SIGN BELOW) after each character of the selection, skipping linefeeds. | |
Applying the script on a selection will u͇n͇d͇e͇r͇l͇i͇n͇e͇ it. | |
Applying the script on a selection that already contains some u͇n͇d͇e͇r͇l͇i͇n͇e͇ | |
will remove all the selection's underlines. | |
Applying the script when all of the document is selected (after a "Select | |
All") will removes all the document underlines. | |
You can find / replace / mark the u͇n͇d͇e͇r͇l͇i͇n͇e͇d͇ ͇s͇e͇c͇t͇i͇o͇n͇s͇ with this regular | |
expression: | |
((?:(?:.\x{0347})+\n?)+) | |
WARNING: | |
1. This script adds extraneous Unicode combining codepoints to the | |
file. DO NOT USE IT IN CODE FILES –– unless it's in the comments. | |
2. Be aware that underlined text won't appear in standard searches | |
because of the inserted combining codepoints. | |
3. This script might have unexpected results if the file encoding is not UTF-8 | |
and Unix(LF) linefeed. | |
4. Applying an underline to text that contains multi-byte or composed code | |
points might have unexpected results. | |
5. The underline looks best with monospaced fonts (as does BBEdit) and | |
might not be perfectly aligned depending on the editor's text engine. | |
INSTALL: | |
Copy script to ~/Library/Application Support/BBEdit/Scripts/. | |
*) | |
try | |
set vCombiningUnderlineCharacter to «data utxt0347» as Unicode text | |
set vCombiningUnderline to "\\x{0347}" | |
tell application "BBEdit" | |
set vOptions to {search mode:grep, case sensitive:false, starting at top:true} | |
set vText to first text of first document of first window | |
set vDocumentLength to (vText's length) as integer | |
set vSelectionLength to (length of selection) as integer | |
if (vSelectionLength = vDocumentLength) or (selection's contents contains vCombiningUnderlineCharacter) then | |
-- Remove all underlines in selection. | |
replace vCombiningUnderline using "" searching in selection's text options vOptions | |
else | |
-- Add combining underline after each character of the selection, skipping linefeeds. | |
replace "([^\n])" using ("\\1" & vCombiningUnderline) searching in selection's text options vOptions | |
end if | |
end tell | |
on error aMessage | |
display alert aMessage as critical | |
end try |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment