Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions Main.sublime-menu
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
[
{
"caption": "Preferences",
"mnemonic": "n",
"id": "preferences",
"children":
[
{
"caption": "Package Settings",
"mnemonic": "P",
"id": "package-settings",
"children":
[
{
"caption": "Scratchpad",
"children":
[
{
"command": "open_file",
"args": {
"file": "${packages}/Scratchpad/Scratchpad.sublime-settings"
},
"caption": "Settings – Default"
},
{
"command": "open_file",
"args": {
"file": "${packages}/User/Scratchpad.sublime-settings"
},
"caption": "Settings – User"
},
{ "caption": "-" }
]
}
]
}
]
}
]
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,29 @@ You can also type "Scratch Pad" in command panel(ctrl+shift+p) to edit the scrat

This will help you stay organized with all your notes, as it will allow you to easily search your file contents. The time-stamp is a very useful feature to organize your notes.

## Configuration

You can customize the location of the scratchpad file through the plugin settings:

1. Go to `Preferences → Package Settings → Scratchpad → Settings – User`
2. Add the following configuration:

```json
{
// Path to your scratchpad file
"scratchpad_path": "~/Documents/my_notes.txt"
}
```

### Supported Path Formats:
- **Absolute paths**: `/home/username/notes/scratchpad.txt`
- **Paths with tilde**: `~/Documents/scratchpad.txt`
- **Windows paths**: `C:\\Users\\username\\Documents\\scratchpad.txt`

If no custom path is specified, the scratchpad file will be created in the Sublime Text configuration directory (default behavior).

The plugin will automatically create the directory structure if it doesn't exist.

## Installation

You can install this plugin from package control. Once you have package control installed type
Expand Down
75 changes: 53 additions & 22 deletions Scratchpad.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from sublime_plugin import WindowCommand, TextCommand
from sublime import packages_path, run_command, ENCODED_POSITION
from sublime import packages_path, run_command, ENCODED_POSITION, load_settings, save_settings
from time import strftime
from os.path import isfile
from os.path import isfile, expanduser, join, dirname
import os

headerText = """
_____ _ _ _
Expand All @@ -15,30 +16,60 @@

"""

def get_scratchpad_file():
"""Get the scratchpad file path from settings or use default."""
settings = load_settings('Scratchpad.sublime-settings')

# Get custom path from settings
custom_path = settings.get('scratchpad_path')

if custom_path:
# Expand user home directory if present
custom_path = expanduser(custom_path)

# Ensure the directory exists
directory = dirname(custom_path)
if directory and not os.path.exists(directory):
try:
os.makedirs(directory)
except OSError:
# Fall back to default if directory creation fails
return packages_path()[:-8] + 'scratchpad.txt'

return custom_path
else:
# Use default location (Sublime Text config folder)
return packages_path()[:-8] + 'scratchpad.txt'

class OpenScratchpadCommand(WindowCommand):
def run(self):
scratchpadFile = packages_path()[:-8]+'scratchpad.txt'
checkAndFillEmpty(scratchpadFile)
self.window.open_file(scratchpadFile)
def run(self):
scratchpadFile = get_scratchpad_file()
checkAndFillEmpty(scratchpadFile)
self.window.open_file(scratchpadFile)

class ScratchpadCommand(WindowCommand):
def run(self):
scratchpadFile = packages_path()[:-8]+'scratchpad.txt'
global headerText
checkAndFillEmpty(scratchpadFile)
count = putTimeStamp(scratchpadFile)
self.window.open_file(scratchpadFile+':'+str(count+1), ENCODED_POSITION)
def run(self):
scratchpadFile = get_scratchpad_file()
global headerText
checkAndFillEmpty(scratchpadFile)
count = putTimeStamp(scratchpadFile)
self.window.open_file(scratchpadFile + ':' + str(count + 1), ENCODED_POSITION)

def checkAndFillEmpty(scratchpadFile):
global headerText
if not isfile(scratchpadFile):
with open(scratchpadFile, "a") as scratchFile:
scratchFile.write(headerText)
global headerText
if not isfile(scratchpadFile):
# Ensure directory exists
directory = dirname(scratchpadFile)
if directory and not os.path.exists(directory):
os.makedirs(directory)

with open(scratchpadFile, "a") as scratchFile:
scratchFile.write(headerText)

def putTimeStamp(scratchpadFile):
timeStamp = "\n\n" + strftime("%c") + " : " + "\n" +"========================" + "\n"
with open(scratchpadFile, "a") as scratchFile:
scratchFile.write(timeStamp)
with open(scratchpadFile) as scratchFile:
count = sum(1 for line in scratchFile)
return count
timeStamp = "\n\n" + strftime("%c") + " : " + "\n" + "========================" + "\n"
with open(scratchpadFile, "a") as scratchFile:
scratchFile.write(timeStamp)
with open(scratchpadFile) as scratchFile:
count = sum(1 for line in scratchFile)
return count
11 changes: 11 additions & 0 deletions Scratchpad.sublime-settings
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
// Path to the scratchpad file
// You can use absolute paths or paths with ~ for home directory
// If not specified, defaults to Sublime Text config folder
// Examples:
// "scratchpad_path": "~/Documents/scratchpad.txt"
// "scratchpad_path": "/home/username/notes/scratchpad.txt"
// "scratchpad_path": "C:\\Users\\username\\Documents\\scratchpad.txt"

"scratchpad_path": null
}