Sounds like a job for Emacs!
Install Emacs through your distribution's package manager.
Emacs comes with Remember Mode, which does pretty much what you want. (Note that there's a lot of complication in the Emacs Wiki that you don't care about, because it's for older versions of Emacs. Remember Mode is bundled since Emacs 23.)
To start taking a note, run the following shell command:
emacsclient -a "" -e "(let ((pop-up-frame-alist \`((window-system . x) (display . \"$DISPLAY\") ,@pop-up-frame-alist))) (remember-other-frame))"
(Having just -e "(remember-other-frame)"
doesn't work if Emacs isn't already displaying a window due to a bad interaction between server mode and frame creation.)
You can add other frame parameters in that list, with the syntax (NAME . VALUE)
. For example, to set a smaller height:
emacsclient -a "" -e "(let ((pop-up-frame-alist \`((window-system . x) (display . \"$DISPLAY\") (height . 8) ,@pop-up-frame-alist))) (remember-other-frame))"
Bind that shell command to a key in your window manager or desktop environment; each has its own way of doing this, so I can't describe them all.
Emacs will start if it isn't already running, and a new Emacs window showing an empty file will pop up. When you've finished taking that note, press Ctrl+C twice. If you want to change that key binding, you can do it in your .emacs
, for example to use Ctrl+Return, use this code:
(require 'remember)
(define-key remember-mode-map [C-return] 'remember-finalize)
If you want to save some text from another application, copy it to the clipboard and run this command (which you may want to bind to a key as well):
emacsclient -a "" -c -e "(remember-clipboard)"
With this command, you need to press Ctrl+C twice, then close the window.
The notes are saved in the file ~/.notes
(each new note is appended to that file). A header containing **
followed by the current time is automatically added at the beginning of the note.
To browse the notes, just open ~/.notes
in your favorite text editor (such as Emacs).
If you want to save the notes to a different file, add a line like this to your ~/.emacs
:
(setq remember-data-file "/path/to/notes/file")
What Remember mode lacks out of the box is a really convenient way of deleting a single note. You can of course select the text and delete it. Here's a function to delete the current note, plus a bit of infrastructure to bind it to a key when browsing the notes file. Put this code in your ~/.emacs
.
(defun remember-current-note-extent ()
(save-match-data
(save-excursion
(end-of-line)
(let ((beg (search-backward (concat "\n" remember-leader-text))))
(forward-char)
(cons beg
(if (search-forward (concat "\n" remember-leader-text) nil t)
(- (point) 1 (length remember-leader-text))
(point-max)))))))
(defun remember-mark-current-note ()
(interactive "@")
(let ((bounds (remember-current-note-extent)))
(set-mark (car bounds))
(goto-char (cdr bounds))))
(defun remember-delete-current-note ()
(interactive "@*")
(let ((bounds (remember-current-note-extent)))
(delete-region (car bounds) (cdr bounds))))
(defvar remember-notes-mode-map
(let ((map (make-sparse-keymap)))
(define-key map "\C-c\C-d" 'remember-delete-current-note)
map)
"Keymap for Remember Notes mode.")
(define-derived-mode remember-notes-mode text-mode "Notes"
"Major mode to browse Remember notes.
\\{remember-notes-mode-map}"
(require 'remember))
(add-to-list 'auto-mode-alist '("/\\.notes\\'" . remember-notes-mode))