From 23e8460713ee4f945aee490142c1444db1628e15 Mon Sep 17 00:00:00 2001 From: Simon Bugge Siggaard Date: Thu, 2 Apr 2020 10:31:03 +0200 Subject: [PATCH 1/4] remove old code --- Cask | 7 - features/add-new-tag.feature | 25 --- features/insert-tag.feature | 44 ----- .../step-definitions/graph-notes-steps.el | 46 ----- features/support/env.el | 43 ----- graph-notes-backlinks.el | 102 ----------- graph-notes.el | 162 ------------------ 7 files changed, 429 deletions(-) delete mode 100644 Cask delete mode 100644 features/add-new-tag.feature delete mode 100644 features/insert-tag.feature delete mode 100644 features/step-definitions/graph-notes-steps.el delete mode 100644 features/support/env.el delete mode 100644 graph-notes-backlinks.el delete mode 100644 graph-notes.el diff --git a/Cask b/Cask deleted file mode 100644 index e4ba1f8..0000000 --- a/Cask +++ /dev/null @@ -1,7 +0,0 @@ -(source melpa) - -(package "graph-notes" "0.0.1" "Graph Notes") - -(development - (depends-on "ecukes") - (depends-on "espuds")) diff --git a/features/add-new-tag.feature b/features/add-new-tag.feature deleted file mode 100644 index 513c6b5..0000000 --- a/features/add-new-tag.feature +++ /dev/null @@ -1,25 +0,0 @@ -Feature: Add new tag - In order to add a new tag - As a graph-notes user - I want to execute `graph-notes--create-new-tag' - - Scenario: Create new tag-file - Given A file-extension ".md" - When I execute "graph-notes--create-new-tag" with arg "test" - Then The file "test.md" should exist - - Scenario: Create new tag with default file-extension - When I execute "graph-notes--create-new-tag" with arg "test" - Then The file "test.org" should exist - - Scenario: List all tags - Given A tag "test" - When I execute "graph-notes--list-all-tags" - Then The tag "test" should be in the tags-list - - Scenario: Remove a tag - Given A file-extension ".md" - And A tag "test" - When I execute "graph-notes--remove-tag" with arg "test" - Then The tag "test" should not be in the tags-list - And The file "test.md" should not exist diff --git a/features/insert-tag.feature b/features/insert-tag.feature deleted file mode 100644 index 707038a..0000000 --- a/features/insert-tag.feature +++ /dev/null @@ -1,44 +0,0 @@ -Feature: Insert tag - In order to insert a new tag - As a graph-notes user - I want to execute `graph-notes-insert-tag' - - Scenario: Insert existing tag - Given A file-extension ".md" - And A tag "test" - And I am in buffer "insert-tag.org" - And I see the following text - """ - Insert tag here: - """ - - When I go to end of line - And I execute "graph-notes-insert-tag" with arg "test" - And I go to word "test" - - Then I should see the following text - """ - Insert tag here: test - """ - And Current point should have the button face - And The file "test.md" should exist - - Scenario: Insert non-existing tag - Given A file-extension ".md" - And I am in buffer "insert-tag.org" - And The buffer is empty - And I see the following text - """ - Insert tag here: - """ - - When I go to end of line - And I execute "graph-notes-insert-tag" with arg "test" - And I go to word "test" - - Then I should see the following text - """ - Insert tag here: test - """ - And Current point should have the button face - And The file "test.md" should exist diff --git a/features/step-definitions/graph-notes-steps.el b/features/step-definitions/graph-notes-steps.el deleted file mode 100644 index 08c516b..0000000 --- a/features/step-definitions/graph-notes-steps.el +++ /dev/null @@ -1,46 +0,0 @@ -;; -*- lexical-binding: t; -*- - -;; This file contains your project specific step definitions. All -;; files in this directory whose names end with "-steps.el" will be -;; loaded automatically by Ecukes. - -(Given "^A file-extension \"\\([^\"]+\\)\"$" - (lambda (extension) - (setq graph-notes-file-extension extension))) - -(Given "^A tag \"\\([^\"]+\\)\"$" - (lambda (tag) - (graph-notes--create-new-tag (s-lex-format "${tag}")))) - -(When "^I execute \"\\([^\"]+\\)\"$" - (lambda (command) - (funcall (intern command)))) - -(When "^I execute \"\\([^\"]+\\)\" with arg \"\\([^\"]+\\)\"$" - (lambda (command arg) - (funcall (intern command) (intern arg)))) - -(Then "^The file \"\\([^\"]+\\)\" should exist$" - (lambda (file) - (cl-assert - (f-exists? (s-lex-format "${graph-notes-base-directory}/${file}"))))) - -(Then "^The file \"\\([^\"]+\\)\" should not exist$" - (lambda (file) - (cl-assert (not (f-exists? file))))) - -(Then "^The tag \"\\([^\"]+\\)\" should be in the tags-list$" - (lambda (tag) - (cl-assert (member tag (graph-notes--list-all-tags))))) - -(Then "^The tag \"\\([^\"]+\\)\" should not be in the tags-list$" - (lambda (tag) - (cl-assert (not (member tag (graph-notes--list-all-tags)))))) - -(And "^I see the following text$" - (lambda (text) - (insert text))) - -(Then "^I should see the following text$" - (lambda (text) - (cl-assert (s-equals? (buffer-string) text)))) diff --git a/features/support/env.el b/features/support/env.el deleted file mode 100644 index 0b53e4f..0000000 --- a/features/support/env.el +++ /dev/null @@ -1,43 +0,0 @@ -(require 'f) - -(defvar graph-notes-support-path - (f-dirname load-file-name)) - -(defvar graph-notes-features-path - (f-parent graph-notes-support-path)) - -(defvar graph-notes-root-path - (f-parent graph-notes-features-path)) - -(add-to-list 'load-path graph-notes-root-path) - -;; Ensure that we don't load old byte-compiled versions -(let ((load-prefer-newer t)) - (require 'graph-notes) - (require 'espuds) - (require 'ert)) - -(Setup - ;; Before anything has been run - (unless (f-exists? "./test_base_directory/") - (f-mkdir "./test_base_directory/")) - (setq graph-notes-base-directory "./test_base_directory")) - -(Before - ;; Before each scenario is run - ) - -(After - ;; After each scenario is run - (setq graph-notes-file-extension graph-notes--default-file-extension) - (setq graph-notes--all-tags '()) - (unless (not (f-exists? "./test_base_directory/")) - (mapc - (lambda (file) (f-delete (f-full file))) - (f-files "./test_base_directory/")))) - -(Teardown - ;; After when everything has been run - (unless (not (f-exists? "./test_base_directory/")) - (f-delete "./test_base_directory/" t)) - (setq graph-notes-base-directory nil)) diff --git a/graph-notes-backlinks.el b/graph-notes-backlinks.el deleted file mode 100644 index 4186379..0000000 --- a/graph-notes-backlinks.el +++ /dev/null @@ -1,102 +0,0 @@ -;;; graph-notes-backlinks --- Code related to the backlinks buffer -*- lexical-binding: t; -*- - -;; Copyright © 2020 Simon Bugge Siggaard - -;; Author: Simon Bugge Siggaard -;; URL: https://github.com/buggaarde/graph-notes -;; Keywords: non-hierarchical, notes, note, notetaking, productivity, creativity -;; Version: 0.1 -;; Package-Requires: ((emacs "26.1") (dash "2.13") (f "0.17.2") (s "1.12.0") (emacsql "3.0.0") (emacsql-sqlite "1.0.0")) - -;; This file is NOT part of GNU Emacs. - -;; This program is free software; you can redistribute it and/or modify -;; it under the terms of the GNU General Public License as published by -;; the Free Software Foundation; either version 3, or (at your option) -;; any later version. -;; -;; This program is distributed in the hope that it will be useful, -;; but WITHOUT ANY WARRANTY; without even the implied warranty of -;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -;; GNU General Public License for more details. -;; -;; You should have received a copy of the GNU General Public License -;; along with GNU Emacs; see the file COPYING. If not, write to the -;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -;; Boston, MA 02110-1301, USA. - -;;; Commentary: - -;;; Code: -(require 's) - -(defvar graph-notes-backlinks--file-name-regex "\\(.*\\):[0-9]+:") -(defvar graph-notes-backlinks--linum-regex "^:\\([0-9]+\\):") - -(define-button-type 'graph-notes-backlinks--default-button - 'face 'default) - -(defun graph-notes-backlinks--create-links-buffer-from-grep (grep-buffer) - "Documentation. - -GREP-BUFFER is the buffer that contains the output of the grep" - (save-current-buffer - (let ((grep-button (with-current-buffer grep-buffer - (let* ((grep-button (lambda (tag-and-context) - (let* ((file-name - (nth 1 (s-match graph-notes-backlinks--file-name-regex tag-and-context))) - (raw-button-content - (s-replace file-name "" tag-and-context)) - (linenumber - (string-to-number - (nth 1 (s-match graph-notes-backlinks--linum-regex raw-button-content))))) - - (insert (propertize file-name 'font-lock-face 'bold)) - (insert "\n") - (insert-text-button - raw-button-content - 'type 'graph-notes-backlinks--default-button - 'action (lambda (button) - (progn - (find-file file-name) - (goto-char (point-min)) - (forward-line (1- linenumber)))) - - 'follow-link t - 'help-echo "Click to go to file") - - (insert "\n\n\n"))))) - grep-button))) - (grep-list (with-current-buffer grep-buffer - (s-split "\n--\n--\n" (buffer-string))))) - (erase-buffer) - (mapc grep-button grep-list)))) - -(defvar graph-notes-backlinks--font-locks nil "Test.") - -(setq graph-notes-backlinks--font-locks - '(((graph-notes-backlinks--tag-name-from-links-buffer) . (0 font-lock-constant-face)))) - -(defun graph-notes-backlinks--tag-name-from-links-buffer () - "All tag names are of the form `in-links'." - (s-chop-suffix ">" (cdr (s-split "<" (buffer-name))))) - -(defun graph-notes-backlinks--quit-and-kill-buffer () - "Both quit and kill the current buffer." - (interactive) - (kill-buffer-and-window)) - -(defvar graph-notes-backlinks-mode-map - (let ((map (make-sparse-keymap))) - (define-key map (kbd "q") 'graph-notes-backlinks--quit-and-kill-buffer) - map) - "The keymap for the graph-notes links buffer.") - -(define-derived-mode graph-notes-backlinks-mode fundamental-mode "backlinks" - "The major mode of the graph-notes links buffer. - -//{graph-notes-backlinks-mode-map}" - (setq font-lock-defaults '(graph-notes-backlinks--font-locks))) - -(provide 'graph-notes-backlinks) -;;; graph-notes-backlinks ends here diff --git a/graph-notes.el b/graph-notes.el deleted file mode 100644 index 580019f..0000000 --- a/graph-notes.el +++ /dev/null @@ -1,162 +0,0 @@ -;;; graph-notes.el --- Non-hierarchical note taking in Emacs -*- lexical-binding: t -*- - -;; Copyright © 2020 Simon Bugge Siggaard - -;; Author: Simon Bugge Siggaard -;; URL: https://github.com/buggaarde/graph-notes -;; Keywords: non-hierarchical, notes, note, notetaking, productivity, creativity -;; Version: 0.1 -;; Package-Requires: ((emacs "26.1") (dash "2.13") (f "0.17.2") (s "1.12.0") (emacsql "3.0.0") (emacsql-sqlite "1.0.0")) - -;; This file is NOT part of GNU Emacs. - -;; This program is free software; you can redistribute it and/or modify -;; it under the terms of the GNU General Public License as published by -;; the Free Software Foundation; either version 3, or (at your option) -;; any later version. -;; -;; This program is distributed in the hope that it will be useful, -;; but WITHOUT ANY WARRANTY; without even the implied warranty of -;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -;; GNU General Public License for more details. -;; -;; You should have received a copy of the GNU General Public License -;; along with GNU Emacs; see the file COPYING. If not, write to the -;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -;; Boston, MA 02110-1301, USA. - -;;; Commentary: - -;;; Code: -(require 'dash) -(require 'f) -(require 'graph-notes-db) -(require 's) - -;;;; Customizable Variables -(defgroup graph-notes nil - "Non-hierarchical note taking" - :prefix "graph-notes-" - :link '(url-link :tag "github" "https://github.com/buggaarde/graph-notes")) - -(require 'graph-notes-backlinks) - -(defvar graph-notes-db (emacsql-sqlite "~/graph-notes.db")) -(emacsql graph-notes-db [:create-table :if-not-exists tags $S1] graph-notes-db--tags-schema) -(emacsql graph-notes-db [:create-table :if-not-exists files $S1] graph-notes-db--files-schema) -(emacsql graph-notes-db [:create-table :if-not-exists file-tag $S1] graph-notes-db--file-tag-schema) -(emacsql graph-notes-db [:create-table :if-not-exists synonyms $S1] graph-notes-db--synonyms-schema) - -(defcustom graph-notes-directory (expand-file-name "~/graph-notes/") - "All files in this directory are part of the note graph." - :type 'directory - :set (lambda (symbol value) - "All files in the specified directory have graph-nodes-mode enabled." - (let ((directory (expand-file-name value))) - (remove-hook 'find-file-hook #'graph-notes--directory-hook) - ;; (remove-function after-focus-change-function - ;; #'graph-notes--rebuild-backlinks-hook) - - (defun graph-notes--directory-hook () - (when (string-match - (s-lex-format "${directory}.*") (buffer-file-name)) - (graph-notes-mode 1))) - - ;; (defun graph-notes--rebuild-backlinks-hook () - ;; (when (string-match - ;; (s-lex-format "${directory}.*") (buffer-file-name)) - ;; (message (buffer-name)) - ;; (graph-notes--grep-file-name-in-current-directory))) - - (add-hook 'find-file-hook #'graph-notes--directory-hook) - ;; (add-function :after after-focus-change-function - ;; #'graph-notes--rebuild-backlinks-hook) - - (setq symbol value))) - :group 'graph-notes) - -(defcustom graph-notes-file-extension ".org" - "All note files must have the same file ending." - :type 'string - :group 'graph-notes) - - -;;;; Core -(defvar graph-notes--all-tags '()) - -(define-button-type 'graph-notes--default-button - 'face 'default) - -(defun graph-notes-insert-tag (tag) - "Insert a tag and create the necessary files accordingly. - -TAG is the name of the tag inserted, as well as the name of the file created." - (interactive) - (progn - (graph-notes--create-new-tag - (s-lex-format "${tag}")) - (insert-text-button - (s-lex-format "${tag}") - 'face 'graph-notes--default-button))) - -(defun graph-notes--create-new-tag (tag) - "Create a new tag by adding to the graph-notes--all-tags list. -Also create a file with the appropriate name. - -TAG is the name of the tag." - (interactive) - (let ((raw-extension (s-chop-prefix "." graph-notes-file-extension))) - (f-touch (s-lex-format "${graph-notes-directory}/${tag}.${raw-extension}")) - (setq graph-notes--all-tags - (-concat graph-notes--all-tags `(,(s-lex-format "${tag}")))))) - -(defun graph-notes--list-all-tags () - "Return the list of all tags." - graph-notes--all-tags) - -(defun graph-notes--remove-tag (tag) - "Remove a tag. -TAG is the name of the tag." - (let ((raw-extension (s-chop-prefix "." graph-notes-file-extension))) - (setq graph-notes--all-tags (--remove (s-equals? it tag) graph-notes--all-tags)) - (f-delete (s-lex-format "${graph-notes-base-directory}/${tag}.${raw-extension}")))) - -(defun graph-notes--grep-file-name-in-current-directory () - "Display the result of a grep for the current file name (without extension) in a new buffer, and go to that buffer." - (interactive) - (let* ((content-buffer (buffer-name)) - (b-name (car (s-split "[.]" content-buffer))) - (backlinks-buffer - (get-buffer-create (s-lex-format "backlinks<${b-name}>"))) - (grep-buffer - (get-buffer-create (s-lex-format "grep:backlinks<${b-name}>"))) - (grep-string (with-temp-buffer - (shell-command - (s-lex-format "grep -nwrH -C1 --exclude-dir=.git \"${b-name}\" .") t) - (buffer-string)))) - - (with-current-buffer grep-buffer - (erase-buffer) - (insert grep-string)) - - (save-current-buffer - (with-current-buffer backlinks-buffer - (graph-notes-backlinks--create-links-buffer-from-grep grep-buffer content-buffer) - (beginning-of-buffer) - (graph-notes-backlinks-mode) - (visual-line-mode) - (pop-to-buffer backlinks-buffer))))) - -(defvar graph-notes-mode-map - (let ((map (make-sparse-keymap))) - (define-key map (kbd "C-c n l") 'graph-notes--grep-file-name-in-current-directory) - map)) - -(define-minor-mode graph-notes-mode - "Organize your notes in a graph" - :lighter " graph-notes" - :group 'graph-notes - :keymap graph-notes-mode-map) - -(provide 'graph-notes) -;;; graph-notes ends here From 63edb5aed387caabc3be7df4ef8a9d4da655945f Mon Sep 17 00:00:00 2001 From: Simon Bugge Siggaard Date: Thu, 2 Apr 2020 10:31:14 +0200 Subject: [PATCH 2/4] Add sqlite database backend --- graph-notes-db.el | 105 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 graph-notes-db.el diff --git a/graph-notes-db.el b/graph-notes-db.el new file mode 100644 index 0000000..d34897e --- /dev/null +++ b/graph-notes-db.el @@ -0,0 +1,105 @@ +;;; graph-notes-db --- The sqlite backend for graph notes -*- lexical-binding: t; -*- + +;; Copyright © 2020 Simon Bugge Siggaard + +;; Author: Simon Bugge Siggaard +;; URL: https://github.com/buggaarde/graph-notes +;; Keywords: non-hierarchical, notes, note, notetaking, productivity, creativity +;; Version: 0.1 +;; Package-Requires: ((emacs "26.1") (dash "2.13") (f "0.17.2") (s "1.12.0") (emacsql "3.0.0") (emacsql-sqlite "1.0.0")) + +;; This file is NOT part of GNU Emacs. + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation; either version 3, or (at your option) +;; any later version. +;; +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. +;; +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs; see the file COPYING. If not, write to the +;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +;; Boston, MA 02110-1301, USA. + +;;; Commentary: + +;;; Code: +(require 'emacsql) +(require 'emacsql-sqlite) + +;;;; Schemas: +(defvar graph-notes-db--tags-schema + '([(id integer :primary-key) + file-name]) + "The table containing all graph-note tags. + +The table also contains the name of the file representing the tag.") + +(defvar graph-notes-db--links-schema + '([(id integer :primary-key) + (from-tag-id integer) + (to-tag-id integer)] + (:foreign-key [from-tag-id] :references tags [id]) + (:foreign-key [to-tag-id] :references tags [id])) + "The table connects all links between tags.") + +(defvar graph-notes-db--synonyms-schema + '([(id integer :primary-key) + name + (tag-id integer)] + (:foreign-key [tag-id] :references tags [id])) + "The table associates string names with the more abstract foreign-key tag id.") + +;;;; Helper functions: +(defun graph-notes-db--backlinks-to-file (db file-name) + "Return all tags containing backlinks to tag given by file name. + +DB is the sqlite database. +FILE-NAME is the file name." + (emacsql db [:select [links.from-tag-id] + :from links + :inner-join tags + :on (= links.to-tag-id tags.id) + :where (= tags.file-name $r1)] + file-name)) + +(defun graph-notes-db--tags-in-file (db file-name) + "Return all tags in given file. + +DB is the sqlite database. +FILE-NAME is the file name." + (emacsql db [:select [links.to-tag-id] + :from links + :inner-join tags + :on (= links.from-tag-id tags.id) + :where (= tags.file-name $r1)] + file-name)) + +(defun graph-notes-db--tag-synonyms (db tag) + "Return all synonyms for the given tag. + +DB is the sqlite database. +TAG is the tag id." + (emacsql db [:select [synonyms.name] + :from synonyms + :inner-join tag + :on (= synonyms.tag-id tags.id) + :where (= tags.id $s1)] + tag)) + +(defun graph-notes-db--tag-id-from-file-name (db file-name) + "Return the id of the tag corresponding to the current file name. + +DB is the sqlite database. +FILE-NAME is the file name." + (emacsql db [:select [id] + :from tags + :where (= file-name $r1)] + file-name)) + +(provide 'graph-notes-db) +;;; graph-notes-db.el ends here From 0ce177ae458e9c33ea61e9de2df782903a2d9bcc Mon Sep 17 00:00:00 2001 From: Simon Bugge Siggaard Date: Thu, 2 Apr 2020 10:41:55 +0200 Subject: [PATCH 3/4] add passing test to check buttercup functionality --- test-graph-notes.el | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 test-graph-notes.el diff --git a/test-graph-notes.el b/test-graph-notes.el new file mode 100644 index 0000000..3385f8d --- /dev/null +++ b/test-graph-notes.el @@ -0,0 +1,5 @@ +(require 'buttercup) + +(describe "test" + (it "passes" + (:expect t :to-be t))) From 7e120eb3ad28a09ec152af3b3e6ceb6832d7195a Mon Sep 17 00:00:00 2001 From: Simon Bugge Siggaard Date: Thu, 2 Apr 2020 10:48:32 +0200 Subject: [PATCH 4/4] bump dependencies --- graph-notes-db.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/graph-notes-db.el b/graph-notes-db.el index d34897e..24c3600 100644 --- a/graph-notes-db.el +++ b/graph-notes-db.el @@ -6,7 +6,7 @@ ;; URL: https://github.com/buggaarde/graph-notes ;; Keywords: non-hierarchical, notes, note, notetaking, productivity, creativity ;; Version: 0.1 -;; Package-Requires: ((emacs "26.1") (dash "2.13") (f "0.17.2") (s "1.12.0") (emacsql "3.0.0") (emacsql-sqlite "1.0.0")) +;; Package-Requires: ((emacs "26.1") (buttercup "1.21") (dash "2.17") (f "0.20.0") (s "1.12.0") (emacsql "3.0.0") (emacsql-sqlite "1.0.0")) ;; This file is NOT part of GNU Emacs.