diff options
Diffstat (limited to 'edit.py')
-rw-r--r-- | edit.py | 20 |
1 files changed, 15 insertions, 5 deletions
@@ -21,12 +21,18 @@ import shlex import subprocess import weechat - FILE = "" FENCED = False -def weechat_config_dir(): +def xdg_cache_dir(): + return os.path.expanduser(os.environ.get("XDG_CACHE_HOME", "~/..cache/")) + + +def weechat_cache_dir(): + cache_dir = os.path.join(xdg_cache_dir(), "weechat") + if os.path.exists(cache_dir): + return cache_dir return os.path.expanduser(os.environ.get("WEECHAT_HOME", "~/.weechat/")) @@ -61,8 +67,12 @@ def read_file(buf): try: with open(FILE) as f: text = f.read() - if FENCED: - text = "```\n" + text.strip() + "\n```" + + if text[-1] == "\n": + text = text[:-1] # remove trailing newline if exists. + if FENCED: + text = "```\n" + text + "\n```" + weechat.buffer_set(buf, "input", text) weechat.buffer_set(buf, "input_pos", str(len(text))) @@ -107,7 +117,7 @@ def edit(data, buf, args, fenced=False): global FILE, FENCED - FILE = os.path.join(weechat_config_dir(), "message." + ("md" if not args else args)) + FILE = os.path.join(weechat_cache_dir(), "message." + ("md" if not args else args)) FENCED = fenced |