Skip to content

Instantly share code, notes, and snippets.

@opamp opamp/scratchnote.el

Last active Mar 14, 2016
What would you like to do?
;;;; scratchnote.el
;;; this code requires popwin.el
;;; configuration sample
;; (require 'scratchnote)
;; (global-set-key (kbd "C-c m") 'scratchnote-pop)
;; (scratchnote-restore)
;; (add-hook 'kill-emacs-hook 'scratchnote-save)
;;; code:
(defvar scratchnote-temprate "#+TITLE: scratchnote\n")
(defvar scratchnote-hook (list (lambda () (org-mode))))
(defvar scratchnote-filename (expand-file-name "~/"))
(defvar scratchnote-buffername "*scratchnote*")
(defvar scratchnote-buffer nil)
(defvar scratchnote-dont-save nil)
(defun scratchnote--buffer-init (&optional after)
(setf scratchnote-buffer (generate-new-buffer scratchnote-buffername))
(with-current-buffer scratchnote-buffer
(dolist (hook scratchnote-hook)
(funcall hook))
(dolist (p after)
(funcall p))))
(defun scratchnote (&optional no-switch)
(if (buffer-live-p scratchnote-buffer)
(switch-to-buffer scratchnote-buffer)
(list (lambda ()
(insert scratchnote-temprate)))))
(unless no-switch
(switch-to-buffer scratchnote-buffer)))
(defun scratchnote-save ()
(if (not (buffer-live-p scratchnote-buffer))
(message "scratchnote buffer is not living!")
(if (not scratchnote-dont-save)
(with-current-buffer scratchnote-buffer
(write-file scratchnote-filename))
(message "scratchnote is not saved because scratchnote-dont-save flag is ON"))))
(defun scratchnote-restore ()
(when (file-exists-p scratchnote-filename)
(unless (buffer-live-p scratchnote-buffer)
(with-current-buffer scratchnote-buffer
(insert (with-temp-buffer
(insert-file-contents scratchnote-filename)
(buffer-substring-no-properties (point-min) (point-max)))))))
(defun scratchnote-pop ()
(if (buffer-live-p scratchnote-buffer)
(popwin:popup-buffer scratchnote-buffer)
(scratchnote t)
(popwin:popup-buffer scratchnote-buffer)))
(defun scratchnote-dont-save ()
(setf scratchnote-dont-save t))
(defun scratchnote-do-save ()
(setf scratchnote-dont-save nil))
(defun scratchnote-clear ()
(with-current-buffer scratchnote-buffer
(insert scratchnote-temprate)))
(provide 'scratchnote)
;;; ends here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.