Skip to content

Instantly share code, notes, and snippets.

@RobTrew
Created November 16, 2012 13:11
Show Gist options
  • Save RobTrew/4087248 to your computer and use it in GitHub Desktop.
Save RobTrew/4087248 to your computer and use it in GitHub Desktop.
Mark the selected FoldingText line as a heading (or deepen its heading level) – simple script for keyboard assignment
-- Change first selected node to heading,
-- or deepen level if already heading
-- DEV 1.1 Script
property pstrType : "heading"
on run
tell application "FoldingText"
-- CHECK THAT THERE IS A DOCUMENT
set lstDocs to documents
if length of lstDocs < 1 then return
-- READ THE ID TYPE AND LEVEL OF THE SELECTION
tell item 1 of lstDocs
set {strID, strType, lngLevel} to {|id|, |type|, level} of item 1 of ¬
(read nodes at path nodePath of (read selection))
-- DECIDE WHETHER TO CHANGE TYPE OR DEEPEN THE EXISTING LEVEL
if strType ≠ pstrType then
set recChanges to {|type|:pstrType}
else
set recChanges to {level:lngLevel + 1}
end if
-- AND MAKE THE CHANGE
update nodes at ids {strID} with changes recChanges
end tell
end tell
end run
@RobTrew
Copy link
Author

RobTrew commented Nov 16, 2012

Simple script for keyboard assignment

Function

Quickly flags the selected line as a header (rather than moving to start of line, removing any existing list or comment formatting and typing #).
If the selected line is already a header, it deepens the heading level (adds a further #).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment