Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Tree: 82f63ec2a6
Fetching contributors…

Cannot retrieve contributors at this time

104 lines (92 sloc) 3.213 kB
;;; nb.el --- Nota Bene, a quick note-taking tool for Emacs
(defun nb-rename-buffer-accordingly ()
(unless (zerop (buffer-size))
(let* ((first-line (save-excursion
(goto-char (point-min))
(buffer-substring (point-min) (point))))
(new-name (concat (file-name-directory (buffer-file-name))
"[^a-z0-9.-]" "-" first-line))))
(unless (equal (buffer-file-name) new-name)
(let ((backup-by-copying nil)
(buffer-backed-up nil))
(set-visited-file-name new-name)))))
(defun nb-remove-empty-files ()
(when (zerop (buffer-size))
(delete-file (buffer-file-name))
(message "Removed empty note %s" (buffer-file-name))))
(defun nb-new-note ()
(switch-to-buffer "*new note*")
(set-visited-file-name "~/NB/.new")
(rename-buffer "*new note*")
(nb-mode 1)
(set-buffer-modified-p nil))
(defun nb (terms)
(interactive "MSearch terms: ")
(let ((output (shell-command-to-string (concat "nb " terms))))
(if (zerop (length output))
(message "Nothing found.")
(insert terms)
(insert "\n\n")
(set-buffer-modified-p nil))
(switch-to-buffer "*nb-search*")
(setq buffer-read-only nil)
(delete-region (point-min) (point-max))
(insert output)
(goto-char (point-min))
(setq buffer-read-only t)
(if (= 2 (length (split-string output "\n")))
;; only one hit
(defun nb-make-links ()
(goto-char (point-min))
(while (not (eobp))
(when (looking-at "\\S-")
(skip-syntax-forward "^-")
(let ((button (make-button (point-at-bol) (point))))
(button-put button 'action #'nb-find-note)
(button-put button 'file
(concat "~/NB/"
(buffer-substring (point-at-bol) (point))))
(defun nb-find-note (button)
(find-file (button-get button 'file))
(nb-mode 1))
(defun nb-find-at-point ()
(if (save-excursion
(re-search-backward "\\[\\[\\|\\]\\]" (point-at-bol) t)
(looking-at "\\[\\[\\(.*?\\)\\]\\]"))
(nb (match-string 1))
(insert "\n")))
(defun nb-find-at-mouse (event)
(interactive "e")
(if (save-excursion
(set-buffer (window-buffer
(posn-window (event-start event))))
(goto-char (posn-point (event-start event)))
(re-search-backward "\\[\\[\\|\\]\\]" (point-at-bol) t)
(looking-at "\\[\\[\\(.*?\\)\\]\\]"))
(nb (match-string 1))
(mouse-set-mark event)))
(define-minor-mode nb-mode
"Minor mode for quick note taking."
" NB"
(add-hook 'before-save-hook 'nb-rename-buffer-accordingly t t)
(add-hook 'after-save-hook 'nb-remove-empty-files t t))
(define-key nb-mode-map [return] 'nb-find-at-point)
(define-key nb-mode-map [mouse-1] 'nb-find-at-mouse)
(provide 'nb)
Jump to Line
Something went wrong with that request. Please try again.